Index: third_party/WebKit/Source/core/layout/ng/ng_layout_opportunity_iterator.cc |
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 76977630c2a784e71e646b72bf7d09017d55fd16..f17ae6f98588f0706148272dda4bc7c209a7cb99 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 |
@@ -17,7 +17,7 @@ void CollectAllOpportunities(const NGLayoutOpportunityTreeNode* node, |
if (!node) |
return; |
if (node->IsLeafNode()) |
- opportunities.append(node->space); |
+ opportunities.append(node->layout_area); |
CollectAllOpportunities(node->left, opportunities); |
CollectAllOpportunities(node->bottom, opportunities); |
CollectAllOpportunities(node->right, opportunities); |
@@ -29,12 +29,12 @@ bool IsOverlapping(const NGEdge& edge1, const NGEdge& edge2) { |
} |
// Whether the exclusion is out of bounds of the LayoutNG constraint space. |
-bool IsExclusionWithinSpace(const NGConstraintSpace& space, |
+bool IsExclusionWithinSpace(const NGLogicalRect& layout_area, |
Gleb Lanbin
2016/10/21 21:06:58
let's stick with "layout opportunity" name? i.e.
b
ikilpatrick
2016/10/21 21:45:27
Done.
|
const NGExclusion& exclusion) { |
- LayoutUnit left = space.Offset().inline_offset; |
- LayoutUnit top = space.Offset().block_offset; |
- LayoutUnit right = left + space.Size().inline_size; |
- LayoutUnit bottom = top + space.Size().block_size; |
+ LayoutUnit left = layout_area.offset.inline_offset; |
+ LayoutUnit top = layout_area.offset.block_offset; |
+ LayoutUnit right = left + layout_area.size.inline_size; |
+ LayoutUnit bottom = top + layout_area.size.block_size; |
return !(exclusion.Right() <= left || exclusion.Bottom() <= top || |
exclusion.Left() >= right || exclusion.Top() >= bottom); |
@@ -49,20 +49,18 @@ bool IsExclusionWithinSpace(const NGConstraintSpace& space, |
NGLayoutOpportunityTreeNode* CreateBottomNGLayoutOpportunityTreeNode( |
const NGLayoutOpportunityTreeNode* parent_node, |
const NGExclusion& exclusion) { |
- const NGConstraintSpace& parent_space = *parent_node->space; |
- LayoutUnit left = parent_space.Offset().inline_offset; |
+ const NGLogicalRect& parent_layout_area = parent_node->layout_area; |
Gleb Lanbin
2016/10/21 21:06:58
const NGLayoutOpportunity& parent_opportunity
ikilpatrick
2016/10/21 21:45:27
Done.
|
+ LayoutUnit left = parent_layout_area.offset.inline_offset; |
LayoutUnit top = exclusion.Bottom(); |
- LayoutUnit right = left + parent_space.Size().inline_size; |
- LayoutUnit bottom = |
- parent_space.Offset().block_offset + parent_space.Size().block_size; |
+ LayoutUnit right = left + parent_layout_area.size.inline_size; |
+ LayoutUnit bottom = parent_layout_area.offset.block_offset + |
+ parent_layout_area.size.block_size; |
NGEdge exclusion_edge = {exclusion.Left(), exclusion.Right()}; |
LayoutUnit block_size = bottom - top; |
if (block_size > 0) { |
- auto* space = |
- new NGConstraintSpace(parent_space, NGLogicalOffset(left, top), |
- NGLogicalSize(right - left, block_size)); |
- return new NGLayoutOpportunityTreeNode(space, exclusion_edge); |
+ NGLogicalRect layout_area(left, top, right - left, block_size); |
+ return new NGLayoutOpportunityTreeNode(layout_area, exclusion_edge); |
} |
return nullptr; |
} |
@@ -77,20 +75,18 @@ NGLayoutOpportunityTreeNode* CreateBottomNGLayoutOpportunityTreeNode( |
NGLayoutOpportunityTreeNode* CreateLeftNGLayoutOpportunityTreeNode( |
const NGLayoutOpportunityTreeNode* parent_node, |
const NGExclusion& exclusion) { |
- const NGConstraintSpace& parent_space = *parent_node->space; |
- LayoutUnit left = parent_space.Offset().inline_offset; |
- LayoutUnit top = parent_space.Offset().block_offset; |
+ const NGLogicalRect& parent_layout_area = parent_node->layout_area; |
+ LayoutUnit left = parent_layout_area.offset.inline_offset; |
+ LayoutUnit top = parent_layout_area.offset.block_offset; |
LayoutUnit right = exclusion.Left(); |
- LayoutUnit bottom = top + parent_space.Size().block_size; |
+ LayoutUnit bottom = top + parent_layout_area.size.block_size; |
NGEdge node_edge = {left, right}; |
LayoutUnit inline_size = right - left; |
if (inline_size > 0 && |
IsOverlapping(parent_node->exclusion_edge, node_edge)) { |
- auto* space = |
- new NGConstraintSpace(parent_space, NGLogicalOffset(left, top), |
- NGLogicalSize(inline_size, bottom - top)); |
- return new NGLayoutOpportunityTreeNode(space); |
+ NGLogicalRect layout_area(left, top, inline_size, bottom - top); |
+ return new NGLayoutOpportunityTreeNode(layout_area); |
} |
return nullptr; |
} |
@@ -105,21 +101,19 @@ NGLayoutOpportunityTreeNode* CreateLeftNGLayoutOpportunityTreeNode( |
NGLayoutOpportunityTreeNode* CreateRightNGLayoutOpportunityTreeNode( |
const NGLayoutOpportunityTreeNode* parent_node, |
const NGExclusion& exclusion) { |
- const NGConstraintSpace& parent_space = *parent_node->space; |
+ const NGLogicalRect& parent_layout_area = parent_node->layout_area; |
LayoutUnit left = exclusion.Right(); |
- LayoutUnit top = parent_space.Offset().block_offset; |
- LayoutUnit right = |
- parent_space.Offset().inline_offset + parent_space.Size().inline_size; |
- LayoutUnit bottom = top + parent_space.Size().block_size; |
+ LayoutUnit top = parent_layout_area.offset.block_offset; |
+ LayoutUnit right = parent_layout_area.offset.inline_offset + |
+ parent_layout_area.size.inline_size; |
+ LayoutUnit bottom = top + parent_layout_area.size.block_size; |
NGEdge node_edge = {left, right}; |
LayoutUnit inline_size = right - left; |
if (inline_size > 0 && |
IsOverlapping(parent_node->exclusion_edge, node_edge)) { |
- auto* space = |
- new NGConstraintSpace(parent_space, NGLogicalOffset(left, top), |
- NGLogicalSize(inline_size, bottom - top)); |
- return new NGLayoutOpportunityTreeNode(space); |
+ NGLogicalRect layout_area(left, top, inline_size, bottom - top); |
+ return new NGLayoutOpportunityTreeNode(layout_area); |
} |
return nullptr; |
} |
@@ -130,18 +124,18 @@ NGLayoutOpportunityTreeNode* CreateRightNGLayoutOpportunityTreeNode( |
// @param parent_node Node that needs to be split. |
// @param exclusion Exclusion existed in the parent node constraint space. |
// @return New node or nullptr if the new block size == 0. |
-NGConstraintSpace* GetTopSpace(const NGConstraintSpace& space, |
- const NGExclusion& exclusion) { |
- LayoutUnit left = space.Offset().inline_offset; |
- LayoutUnit top = space.Offset().block_offset; |
- LayoutUnit right = left + space.Size().inline_size; |
+NGLogicalRect GetTopSpace(const NGLogicalRect& rect, |
+ const NGExclusion& exclusion) { |
+ LayoutUnit left = rect.offset.inline_offset; |
+ LayoutUnit top = rect.offset.block_offset; |
+ LayoutUnit right = left + rect.size.inline_size; |
LayoutUnit bottom = exclusion.Top(); |
LayoutUnit block_size = bottom - top; |
if (block_size > 0) |
- return new NGConstraintSpace(space, NGLogicalOffset(left, top), |
- NGLogicalSize(right - left, block_size)); |
- return nullptr; |
+ return NGLogicalRect(left, top, right - left, block_size); |
+ |
+ return NGLogicalRect(); |
} |
// Inserts the exclusion into the Layout Opportunity tree. |
@@ -149,7 +143,7 @@ void InsertExclusion(NGLayoutOpportunityTreeNode* node, |
const NGExclusion* exclusion, |
NGLayoutOpportunities& opportunities) { |
// Base case: exclusion is not in the node's constraint space. |
- if (!IsExclusionWithinSpace(*node->space, *exclusion)) |
+ if (!IsExclusionWithinSpace(node->layout_area, *exclusion)) |
return; |
if (node->exclusion) { |
@@ -164,8 +158,10 @@ void InsertExclusion(NGLayoutOpportunityTreeNode* node, |
node->right = CreateRightNGLayoutOpportunityTreeNode(node, *exclusion); |
node->bottom = CreateBottomNGLayoutOpportunityTreeNode(node, *exclusion); |
- if (auto* topSpace = GetTopSpace(*node->space, *exclusion)) |
- opportunities.append(topSpace); |
+ NGLogicalRect top_layout_opp = GetTopSpace(node->layout_area, *exclusion); |
+ if (!top_layout_opp.IsEmpty()) |
+ opportunities.append(top_layout_opp); |
+ |
node->exclusion = exclusion; |
} |
@@ -178,27 +174,26 @@ bool CompareNGExclusionsByTopAsc(const Member<const NGExclusion>& lhs, |
// Compares Layout Opportunities by Start Point. |
// Start point is a TopLeft position from where inline content can potentially |
// start positioning itself. |
-bool CompareNGLayoutOpportunitesByStartPoint( |
- const Member<const NGLayoutOpportunity>& lhs, |
- const Member<const NGLayoutOpportunity>& rhs) { |
+bool CompareNGLayoutOpportunitesByStartPoint(const NGLogicalRect& lhs, |
+ const NGLogicalRect& rhs) { |
// sort by TOP. |
- if (rhs->Offset().block_offset > lhs->Offset().block_offset) { |
+ if (rhs.offset.block_offset > lhs.offset.block_offset) { |
return true; |
} |
- if (rhs->Offset().block_offset < lhs->Offset().block_offset) { |
+ if (rhs.offset.block_offset < lhs.offset.block_offset) { |
return false; |
} |
// TOP is the same -> Sort by LEFT |
- if (rhs->Offset().inline_offset > lhs->Offset().inline_offset) { |
+ if (rhs.offset.inline_offset > lhs.offset.inline_offset) { |
return true; |
} |
- if (rhs->Offset().inline_offset < lhs->Offset().inline_offset) { |
+ if (rhs.offset.inline_offset < lhs.offset.inline_offset) { |
return false; |
} |
// TOP and LEFT are the same -> Sort by width |
- return rhs->Size().inline_size < lhs->Size().inline_size; |
+ return rhs.size.inline_size < lhs.size.inline_size; |
} |
} // namespace |
@@ -214,7 +209,10 @@ NGLayoutOpportunityIterator::NGLayoutOpportunityIterator( |
&CompareNGExclusionsByTopAsc)) |
<< "Exclusions are expected to be sorted by TOP"; |
- opportunity_tree_root_ = new NGLayoutOpportunityTreeNode(space); |
+ opportunity_tree_root_ = new NGLayoutOpportunityTreeNode( |
+ NGLogicalRect(space->Offset().inline_offset, space->Offset().block_offset, |
+ space->Size().inline_size, space->Size().block_size)); |
+ |
for (const auto exclusion : exclusions) { |
InsertExclusion(opportunity_tree_root_, exclusion, opportunities_); |
} |
@@ -224,10 +222,10 @@ NGLayoutOpportunityIterator::NGLayoutOpportunityIterator( |
opportunity_iter_ = opportunities_.begin(); |
} |
-const NGConstraintSpace* NGLayoutOpportunityIterator::Next() { |
+const NGLogicalRect* NGLayoutOpportunityIterator::Next() { |
ikilpatrick
2016/10/21 20:24:10
?
Gleb Lanbin
2016/10/21 21:06:58
yes, this iterator needs to be fixed. you can just
|
if (opportunity_iter_ == opportunities_.end()) |
return nullptr; |
- auto* opportunity = opportunity_iter_->get(); |
+ auto* opportunity = opportunity_iter_; |
opportunity_iter_++; |
return opportunity; |
} |