Skip to content

Commit

Permalink
Change NGLayoutOpportunityIterator constructor to work with const CS.
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
glebl authored and Commit bot committed Mar 2, 2017
1 parent fb7c75d commit 9f81209
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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();

Expand All @@ -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();
Expand Down Expand Up @@ -499,8 +500,8 @@ RefPtr<NGLayoutResult> 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:
Expand Down Expand Up @@ -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()) {
Expand All @@ -569,7 +569,7 @@ void NGBlockLayoutAlgorithm::FinishChildLayout(
// Example: <div style="margin-bottom: 20px"><float></div>
// <div style="margin-bottom: 30px"></div>
origin_point.block_offset += curr_margin_strut_.Sum();
PositionPendingFloats(origin_point.block_offset, ConstraintSpace(),
PositionPendingFloats(origin_point.block_offset, MutableConstraintSpace(),
&builder_);
}
return;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -696,8 +696,8 @@ RefPtr<NGConstraintSpace> 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(
Expand Down Expand Up @@ -730,8 +730,8 @@ RefPtr<NGConstraintSpace> 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<LayoutUnit> clearance_offset =
GetClearanceOffset(constraint_space_->Exclusions(), child_style);
space_builder_.SetClearanceOffset(clearance_offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NGBlockNode> node_;
NGConstraintSpace* constraint_space_;

Expand Down
24 changes: 11 additions & 13 deletions third_party/WebKit/Source/core/layout/ng/ng_floating_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,34 @@ class NGPhysicalFragment;
// Struct that keeps all information needed to position floats in LayoutNG.
struct CORE_EXPORT NGFloatingObject
: public GarbageCollectedFinalized<NGFloatingObject> {
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<NGPhysicalFragment> fragment;
// TODO(glebl): Constraint space should be const here.
RefPtr<NGConstraintSpace> space;
// Original constraint space of the float.
RefPtr<const NGConstraintSpace> space;

// Parent space is used so we can calculate the inline offset relative to
// the original parent of this float.
RefPtr<const NGConstraintSpace> original_parent_space;
Member<NGBlockNode> node;

NGExclusion::Type exclusion_type;
EClear clear_type;
NGBoxStrut margins;

RefPtr<NGPhysicalFragment> 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
Expand All @@ -58,7 +57,6 @@ struct CORE_EXPORT NGFloatingObject
LayoutUnit left_offset;

DEFINE_INLINE_TRACE() {
visitor->trace(node);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ NGExclusion ToLeaderExclusion(const NGLogicalOffset& origin_point,
} // namespace

NGLayoutOpportunityIterator::NGLayoutOpportunityIterator(
NGConstraintSpace* space,
const NGConstraintSpace* space,
const WTF::Optional<NGLogicalOffset>& opt_origin_point,
const WTF::Optional<NGLogicalOffset>& opt_leader_point)
: constraint_space_(space) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NGLogicalOffset>& opt_origin_point = WTF::nullopt,
const WTF::Optional<NGLogicalOffset>& opt_leader_point = WTF::nullopt);

Expand All @@ -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_;
Expand Down

0 comments on commit 9f81209

Please sign in to comment.