From 9f81209c0afcb72f576f4794c28c11520b35d7bb Mon Sep 17 00:00:00 2001 From: glebl Date: Thu, 2 Mar 2017 14:00:13 -0800 Subject: [PATCH] Change NGLayoutOpportunityIterator constructor to work with const CS. List of changes: 1) Resolve "const NGConstraintSpace" TODO in NGFloatingObject 2) Change NGLayoutOpportunityIterator to work with a const CS. BUG=635619 Review-Url: https://codereview.chromium.org/2732483002 Cr-Commit-Position: refs/heads/master@{#454392} --- .../layout/ng/ng_block_layout_algorithm.cc | 42 +++++++++---------- .../layout/ng/ng_block_layout_algorithm.h | 3 ++ .../core/layout/ng/ng_floating_object.h | 24 +++++------ .../ng/ng_layout_opportunity_iterator.cc | 2 +- .../ng/ng_layout_opportunity_iterator.h | 4 +- 5 files changed, 38 insertions(+), 37 deletions(-) diff --git a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc index d4bbc2b163a724..97501506925fa2 100644 --- a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc +++ b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc @@ -134,7 +134,7 @@ NGLogicalOffset AdjustToTopEdgeAlignmentRule(const NGConstraintSpace& space, // @param margins Margins of the fragment. // @return Layout opportunity for the fragment. const NGLayoutOpportunity FindLayoutOpportunityForFragment( - NGConstraintSpace* space, + const NGConstraintSpace* space, const NGFragment& fragment, const NGLogicalOffset& origin_point, const NGBoxStrut& margins) { @@ -186,8 +186,9 @@ NGLogicalOffset CalculateLogicalOffsetForOpportunity( // floating object that is requested to be positioned from {@code origin_point}. NGLogicalOffset PositionFloat(const NGLogicalOffset& origin_point, const NGLogicalOffset& from_offset, - NGFloatingObject* floating_object) { - NGConstraintSpace* float_space = floating_object->space.get(); + NGFloatingObject* floating_object, + NGConstraintSpace* new_parent_space) { + const auto* float_space = floating_object->space.get(); DCHECK(floating_object->fragment) << "Fragment cannot be null here"; // TODO(ikilpatrick): The writing mode switching here looks wrong. @@ -212,7 +213,7 @@ NGLogicalOffset PositionFloat(const NGLogicalOffset& origin_point, const NGExclusion exclusion = CreateExclusion( float_fragment, opportunity, float_offset, floating_object->margins, floating_object->exclusion_type); - float_space->AddExclusion(exclusion); + new_parent_space->AddExclusion(exclusion); return CalculateLogicalOffsetForOpportunity(opportunity, float_offset, from_offset, floating_object); @@ -234,13 +235,13 @@ void UpdateFloatingObjectLeftOffset( // Positions pending floats stored on the fragment builder starting from // {@code origin_point_block_offset}. void PositionPendingFloats(const LayoutUnit origin_point_block_offset, - const NGConstraintSpace& new_parent_space, + NGConstraintSpace* new_parent_space, NGFragmentBuilder* builder) { DCHECK(builder->BfcOffset()) << "Parent BFC offset should be known here"; LayoutUnit bfc_block_offset = builder->BfcOffset().value().block_offset; for (auto& floating_object : builder->UnpositionedFloats()) { - NGConstraintSpace* float_space = floating_object->space.get(); + const auto* float_space = floating_object->space.get(); const NGConstraintSpace* original_parent_space = floating_object->original_parent_space.get(); @@ -249,10 +250,10 @@ void PositionPendingFloats(const LayoutUnit origin_point_block_offset, NGLogicalOffset from_offset = { original_parent_space->BfcOffset().inline_offset, bfc_block_offset}; - NGLogicalOffset float_fragment_offset = - PositionFloat(origin_point, from_offset, floating_object); + NGLogicalOffset float_fragment_offset = PositionFloat( + origin_point, from_offset, floating_object, new_parent_space); builder->AddFloatingObject(floating_object, float_fragment_offset); - UpdateFloatingObjectLeftOffset(new_parent_space, floating_object, + UpdateFloatingObjectLeftOffset(*new_parent_space, floating_object, float_fragment_offset); } builder->MutableUnpositionedFloats().clear(); @@ -499,8 +500,8 @@ RefPtr NGBlockLayoutAlgorithm::Layout() { if (block_size) { curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); UpdateFragmentBfcOffset(curr_bfc_offset_); - PositionPendingFloats(curr_bfc_offset_.block_offset, ConstraintSpace(), - &builder_); + PositionPendingFloats(curr_bfc_offset_.block_offset, + MutableConstraintSpace(), &builder_); } // Margins collapsing: @@ -558,9 +559,8 @@ void NGBlockLayoutAlgorithm::FinishChildLayout( if (child->Type() == NGLayoutInputNode::kLegacyBlock && toNGBlockNode(child)->Style().isFloating()) { NGFloatingObject* floating_object = new NGFloatingObject( - layout_result->PhysicalFragment().get(), child_space, constraint_space_, - toNGBlockNode(child), toNGBlockNode(child)->Style(), - curr_child_margins_); + child_space, constraint_space_, toNGBlockNode(child)->Style(), + curr_child_margins_, layout_result->PhysicalFragment().get()); builder_.AddUnpositionedFloat(floating_object); // No need to postpone the positioning if we know the correct offset. if (builder_.BfcOffset()) { @@ -569,7 +569,7 @@ void NGBlockLayoutAlgorithm::FinishChildLayout( // Example:
//
origin_point.block_offset += curr_margin_strut_.Sum(); - PositionPendingFloats(origin_point.block_offset, ConstraintSpace(), + PositionPendingFloats(origin_point.block_offset, MutableConstraintSpace(), &builder_); } return; @@ -600,8 +600,8 @@ void NGBlockLayoutAlgorithm::FinishChildLayout( } if (bfc_offset) { UpdateFragmentBfcOffset(curr_bfc_offset_); - PositionPendingFloats(curr_bfc_offset_.block_offset, ConstraintSpace(), - &builder_); + PositionPendingFloats(curr_bfc_offset_.block_offset, + MutableConstraintSpace(), &builder_); } NGLogicalOffset logical_offset = CalculateLogicalOffset(bfc_offset); @@ -696,8 +696,8 @@ RefPtr NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( // Margins collapsing: Inline block. curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); UpdateFragmentBfcOffset(curr_bfc_offset_); - PositionPendingFloats(curr_bfc_offset_.block_offset, ConstraintSpace(), - &builder_); + PositionPendingFloats(curr_bfc_offset_.block_offset, + MutableConstraintSpace(), &builder_); curr_margin_strut_ = {}; return space_builder_.ToConstraintSpace( @@ -730,8 +730,8 @@ RefPtr NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( curr_margin_strut_ = NGMarginStrut(); curr_child_margins_.block_start = LayoutUnit(); } - PositionPendingFloats(curr_bfc_offset_.block_offset, ConstraintSpace(), - &builder_); + PositionPendingFloats(curr_bfc_offset_.block_offset, + MutableConstraintSpace(), &builder_); WTF::Optional clearance_offset = GetClearanceOffset(constraint_space_->Exclusions(), child_style); space_builder_.SetClearanceOffset(clearance_offset); diff --git a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.h b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.h index e4f05354564a00..505983a0dde825 100644 --- a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.h +++ b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.h @@ -76,6 +76,9 @@ class CORE_EXPORT NGBlockLayoutAlgorithm : public NGLayoutAlgorithm { const ComputedStyle& Style() const { return node_->Style(); } + // Mutable Getters. + NGConstraintSpace* MutableConstraintSpace() { return constraint_space_; } + Persistent node_; NGConstraintSpace* constraint_space_; diff --git a/third_party/WebKit/Source/core/layout/ng/ng_floating_object.h b/third_party/WebKit/Source/core/layout/ng/ng_floating_object.h index bfe7c0d32c8334..26a21fac9d3954 100644 --- a/third_party/WebKit/Source/core/layout/ng/ng_floating_object.h +++ b/third_party/WebKit/Source/core/layout/ng/ng_floating_object.h @@ -19,35 +19,34 @@ class NGPhysicalFragment; // Struct that keeps all information needed to position floats in LayoutNG. struct CORE_EXPORT NGFloatingObject : public GarbageCollectedFinalized { - NGFloatingObject(NGPhysicalFragment* fragment, - NGConstraintSpace* space, + NGFloatingObject(const NGConstraintSpace* space, const NGConstraintSpace* parent_space, - NGBlockNode* node, const ComputedStyle& style, - const NGBoxStrut& margins) - : fragment(fragment), - space(space), + const NGBoxStrut& margins, + NGPhysicalFragment* fragment) + : space(space), original_parent_space(parent_space), - node(node), - margins(margins) { + margins(margins), + fragment(fragment) { exclusion_type = NGExclusion::kFloatLeft; if (style.floating() == EFloat::kRight) exclusion_type = NGExclusion::kFloatRight; clear_type = style.clear(); } - RefPtr fragment; - // TODO(glebl): Constraint space should be const here. - RefPtr space; + // Original constraint space of the float. + RefPtr space; // Parent space is used so we can calculate the inline offset relative to // the original parent of this float. RefPtr original_parent_space; - Member node; + NGExclusion::Type exclusion_type; EClear clear_type; NGBoxStrut margins; + RefPtr fragment; + // In the case where a legacy FloatingObject is attached to not its own // parent, e.g. a float surrounded by a bunch of nested empty divs, // NG float fragment's LeftOffset() cannot be used as legacy FloatingObject's @@ -58,7 +57,6 @@ struct CORE_EXPORT NGFloatingObject LayoutUnit left_offset; DEFINE_INLINE_TRACE() { - visitor->trace(node); } }; diff --git a/third_party/WebKit/Source/core/layout/ng/ng_layout_opportunity_iterator.cc b/third_party/WebKit/Source/core/layout/ng/ng_layout_opportunity_iterator.cc index b9c30899959fa8..76961a9febfbb6 100644 --- a/third_party/WebKit/Source/core/layout/ng/ng_layout_opportunity_iterator.cc +++ b/third_party/WebKit/Source/core/layout/ng/ng_layout_opportunity_iterator.cc @@ -232,7 +232,7 @@ NGExclusion ToLeaderExclusion(const NGLogicalOffset& origin_point, } // namespace NGLayoutOpportunityIterator::NGLayoutOpportunityIterator( - NGConstraintSpace* space, + const NGConstraintSpace* space, const WTF::Optional& opt_origin_point, const WTF::Optional& opt_leader_point) : constraint_space_(space) { diff --git a/third_party/WebKit/Source/core/layout/ng/ng_layout_opportunity_iterator.h b/third_party/WebKit/Source/core/layout/ng/ng_layout_opportunity_iterator.h index 51e42062d14e1f..ea3d3fcbbdd1db 100644 --- a/third_party/WebKit/Source/core/layout/ng/ng_layout_opportunity_iterator.h +++ b/third_party/WebKit/Source/core/layout/ng/ng_layout_opportunity_iterator.h @@ -33,7 +33,7 @@ class CORE_EXPORT NGLayoutOpportunityIterator final { // which starts from 'origin'. This rectangle may // represent a text fragment for example. NGLayoutOpportunityIterator( - NGConstraintSpace* space, + const NGConstraintSpace* space, const WTF::Optional& opt_origin_point = WTF::nullopt, const WTF::Optional& opt_leader_point = WTF::nullopt); @@ -52,7 +52,7 @@ class CORE_EXPORT NGLayoutOpportunityIterator final { return opportunity_tree_root_.get(); } - NGConstraintSpace* constraint_space_; + const NGConstraintSpace* constraint_space_; NGLayoutOpportunities opportunities_; NGLayoutOpportunities::const_iterator opportunity_iter_;