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 5eb1a7c78a601292445a6b44c4be74221492257c..dfcb0b331022510d3459f4b17726951b5d16e209 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 |
@@ -43,6 +43,18 @@ |
return std::max(edge1.start, edge2.start) <= std::min(edge1.end, edge2.end); |
} |
+// Whether the exclusion is out of bounds of the LayoutNG constraint space. |
+bool IsExclusionWithinSpace(const NGLayoutOpportunity& opportunity, |
+ const NGExclusion& exclusion) { |
+ LayoutUnit left = opportunity.offset.inline_offset; |
+ LayoutUnit top = opportunity.offset.block_offset; |
+ LayoutUnit right = left + opportunity.size.inline_size; |
+ LayoutUnit bottom = top + opportunity.size.block_size; |
+ |
+ return !(exclusion.Right() <= left || exclusion.Bottom() <= top || |
+ exclusion.Left() >= right || exclusion.Top() >= bottom); |
+} |
+ |
// Creates the *BOTTOM* positioned Layout Opportunity tree node by splitting |
// the parent node with the exclusion. |
// |
@@ -51,18 +63,18 @@ |
// @return New node or nullptr if the new block size == 0. |
NGLayoutOpportunityTreeNode* CreateBottomNGLayoutOpportunityTreeNode( |
const NGLayoutOpportunityTreeNode* parent_node, |
- const NGLogicalRect& exclusion) { |
+ const NGExclusion& exclusion) { |
const NGLayoutOpportunity& parent_opportunity = parent_node->opportunity; |
- LayoutUnit bottom_opportunity_block_size = |
- parent_opportunity.BlockEndOffset() - exclusion.BlockEndOffset(); |
- if (bottom_opportunity_block_size > 0) { |
- NGLayoutOpportunity opportunity; |
- opportunity.offset.inline_offset = parent_opportunity.InlineStartOffset(); |
- opportunity.offset.block_offset = exclusion.BlockEndOffset(); |
- opportunity.size.inline_size = parent_opportunity.InlineSize(); |
- opportunity.size.block_size = bottom_opportunity_block_size; |
- NGEdge exclusion_edge = {/* start */ exclusion.InlineStartOffset(), |
- /* end */ exclusion.InlineEndOffset()}; |
+ LayoutUnit left = parent_opportunity.offset.inline_offset; |
+ LayoutUnit top = exclusion.Bottom(); |
+ LayoutUnit right = left + parent_opportunity.size.inline_size; |
+ LayoutUnit bottom = parent_opportunity.offset.block_offset + |
+ parent_opportunity.size.block_size; |
+ |
+ NGEdge exclusion_edge = {exclusion.Left(), exclusion.Right()}; |
+ LayoutUnit block_size = bottom - top; |
+ if (block_size > 0) { |
+ NGLayoutOpportunity opportunity(left, top, right - left, block_size); |
return new NGLayoutOpportunityTreeNode(opportunity, exclusion_edge); |
} |
return nullptr; |
@@ -77,21 +89,18 @@ |
// exclusion edge doesn't limit the new node's constraint space. |
NGLayoutOpportunityTreeNode* CreateLeftNGLayoutOpportunityTreeNode( |
const NGLayoutOpportunityTreeNode* parent_node, |
- const NGLogicalRect& exclusion) { |
+ const NGExclusion& exclusion) { |
const NGLayoutOpportunity& parent_opportunity = parent_node->opportunity; |
- |
- LayoutUnit left_opportunity_inline_size = |
- exclusion.InlineStartOffset() - parent_opportunity.InlineStartOffset(); |
- NGEdge node_edge = {/* start */ parent_opportunity.InlineStartOffset(), |
- /* end */ exclusion.InlineStartOffset()}; |
- |
- if (left_opportunity_inline_size > 0 && |
+ LayoutUnit left = parent_opportunity.offset.inline_offset; |
+ LayoutUnit top = parent_opportunity.offset.block_offset; |
+ LayoutUnit right = exclusion.Left(); |
+ LayoutUnit bottom = top + parent_opportunity.size.block_size; |
+ |
+ NGEdge node_edge = {left, right}; |
+ LayoutUnit inline_size = right - left; |
+ if (inline_size > 0 && |
IsOverlapping(parent_node->exclusion_edge, node_edge)) { |
- NGLayoutOpportunity opportunity; |
- opportunity.offset.inline_offset = parent_opportunity.InlineStartOffset(); |
- opportunity.offset.block_offset = parent_opportunity.BlockStartOffset(); |
- opportunity.size.inline_size = left_opportunity_inline_size; |
- opportunity.size.block_size = parent_opportunity.BlockSize(); |
+ NGLayoutOpportunity opportunity(left, top, inline_size, bottom - top); |
return new NGLayoutOpportunityTreeNode(opportunity); |
} |
return nullptr; |
@@ -106,20 +115,19 @@ |
// exclusion edge doesn't limit the new node's constraint space. |
NGLayoutOpportunityTreeNode* CreateRightNGLayoutOpportunityTreeNode( |
const NGLayoutOpportunityTreeNode* parent_node, |
- const NGLogicalRect& exclusion) { |
+ const NGExclusion& exclusion) { |
const NGLayoutOpportunity& parent_opportunity = parent_node->opportunity; |
- |
- NGEdge node_edge = {/* start */ exclusion.InlineEndOffset(), |
- /* end */ parent_opportunity.InlineEndOffset()}; |
- LayoutUnit right_opportunity_inline_size = |
- parent_opportunity.InlineEndOffset() - exclusion.InlineEndOffset(); |
- if (right_opportunity_inline_size > 0 && |
+ LayoutUnit left = exclusion.Right(); |
+ LayoutUnit top = parent_opportunity.offset.block_offset; |
+ LayoutUnit right = parent_opportunity.offset.inline_offset + |
+ parent_opportunity.size.inline_size; |
+ LayoutUnit bottom = top + parent_opportunity.size.block_size; |
+ |
+ NGEdge node_edge = {left, right}; |
+ LayoutUnit inline_size = right - left; |
+ if (inline_size > 0 && |
IsOverlapping(parent_node->exclusion_edge, node_edge)) { |
- NGLayoutOpportunity opportunity; |
- opportunity.offset.inline_offset = exclusion.InlineEndOffset(); |
- opportunity.offset.block_offset = parent_opportunity.BlockStartOffset(); |
- opportunity.size.inline_size = right_opportunity_inline_size; |
- opportunity.size.block_size = parent_opportunity.BlockSize(); |
+ NGLayoutOpportunity opportunity(left, top, inline_size, bottom - top); |
return new NGLayoutOpportunityTreeNode(opportunity); |
} |
return nullptr; |
@@ -128,34 +136,33 @@ |
// Gets/Creates the "TOP" positioned constraint space by splitting |
// the parent node with the exclusion. |
// |
-// @param parent_opportunity Parent opportunity that is being split. |
+// @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. |
-NGLayoutOpportunity GetTopSpace(const NGLayoutOpportunity& parent_opportunity, |
- const NGLogicalRect& exclusion) { |
- LayoutUnit top_opportunity_block_size = |
- exclusion.BlockStartOffset() - parent_opportunity.BlockStartOffset(); |
- if (top_opportunity_block_size > 0) { |
- NGLayoutOpportunity opportunity; |
- opportunity.offset.inline_offset = parent_opportunity.InlineStartOffset(); |
- opportunity.offset.block_offset = parent_opportunity.BlockStartOffset(); |
- opportunity.size.inline_size = parent_opportunity.InlineSize(); |
- opportunity.size.block_size = top_opportunity_block_size; |
- return opportunity; |
- } |
+NGLayoutOpportunity GetTopSpace(const NGLayoutOpportunity& 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 NGLayoutOpportunity(left, top, right - left, block_size); |
+ |
return NGLayoutOpportunity(); |
} |
// Inserts the exclusion into the Layout Opportunity tree. |
void InsertExclusion(NGLayoutOpportunityTreeNode* node, |
- const NGLogicalRect* exclusion, |
+ const NGExclusion* exclusion, |
NGLayoutOpportunities& opportunities) { |
// Base case: there is no node. |
if (!node) |
return; |
// Base case: exclusion is not in the node's constraint space. |
- if (!exclusion->IsContained(node->opportunity)) |
+ if (!IsExclusionWithinSpace(node->opportunity, *exclusion)) |
return; |
if (node->exclusion) { |
@@ -179,10 +186,9 @@ |
} |
// Compares exclusions by their top position. |
-bool CompareNGExclusionsByTopAsc( |
- const std::unique_ptr<const NGLogicalRect>& lhs, |
- const std::unique_ptr<const NGLogicalRect>& rhs) { |
- return rhs->offset.block_offset > lhs->offset.block_offset; |
+bool CompareNGExclusionsByTopAsc(const Member<const NGExclusion>& lhs, |
+ const Member<const NGExclusion>& rhs) { |
+ return rhs->Top() > lhs->Top(); |
} |
// Compares Layout Opportunities by Start Point. |
@@ -218,7 +224,7 @@ |
const NGLogicalOffset leader_point) |
: constraint_space_(space), leader_point_(leader_point) { |
// TODO(chrome-layout-team): Combine exclusions that shadow each other. |
- auto& exclusions = constraint_space_->PhysicalSpace()->Exclusions(); |
+ auto exclusions = constraint_space_->PhysicalSpace()->Exclusions(); |
DCHECK(std::is_sorted(exclusions.begin(), exclusions.end(), |
&CompareNGExclusionsByTopAsc)) |
<< "Exclusions are expected to be sorted by TOP"; |
@@ -227,9 +233,8 @@ |
CreateLayoutOpportunityFromConstraintSpace(*space, origin_point); |
opportunity_tree_root_ = new NGLayoutOpportunityTreeNode(initial_opportunity); |
- for (const auto& exclusion : exclusions) { |
- InsertExclusion(MutableOpportunityTreeRoot(), exclusion.get(), |
- opportunities_); |
+ for (const auto exclusion : exclusions) { |
+ InsertExclusion(MutableOpportunityTreeRoot(), exclusion, opportunities_); |
} |
CollectAllOpportunities(OpportunityTreeRoot(), opportunities_); |
std::sort(opportunities_.begin(), opportunities_.end(), |