Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(675)

Unified Diff: third_party/WebKit/Source/core/layout/ng/ng_layout_opportunity_iterator.cc

Issue 2472583006: Add support of leader_point in NGLayoutOpportunityIterator. (Closed)
Patch Set: LayoutUnit(0) -> LayoutUnit() Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..01e6ba10222d43d1bfe00a2c9c8a49bdeaedf845 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
@@ -150,6 +150,10 @@ NGLayoutOpportunity GetTopSpace(const NGLayoutOpportunity& parent_opportunity,
void InsertExclusion(NGLayoutOpportunityTreeNode* node,
const NGLogicalRect* exclusion,
NGLayoutOpportunities& opportunities) {
+ // Base case: size of the exclusion is empty.
+ if (exclusion->size.IsEmpty())
+ return;
+
// Base case: there is no node.
if (!node)
return;
@@ -210,13 +214,39 @@ bool CompareNGLayoutOpportunitesByStartPoint(const NGLayoutOpportunity& lhs,
return rhs.size.inline_size < lhs.size.inline_size;
}
+void RunPreconditionChecks(const NGConstraintSpace& space,
+ const NGLogicalOffset& origin_point,
+ const NGLogicalOffset& leader_point) {
+ DCHECK_GE(origin_point, space.Offset())
+ << "Origin point" << origin_point
+ << " should lay below the constraint space's offset " << space.Offset();
+
+ DCHECK_GE(leader_point, space.Offset())
+ << "Leader point" << leader_point
+ << " should lay below the constraint space's offset " << space.Offset();
+}
+
+NGLogicalRect ToLeaderExclusion(const NGLogicalOffset& origin_point,
+ const NGLogicalOffset& leader_point) {
+ LayoutUnit inline_size =
+ leader_point.inline_offset - origin_point.inline_offset;
+ LayoutUnit block_size = leader_point.block_offset - origin_point.block_offset;
+
+ NGLogicalRect leader_exclusion;
+ leader_exclusion.offset = origin_point;
+ leader_exclusion.size = {inline_size, block_size};
+ return leader_exclusion;
+}
+
} // namespace
NGLayoutOpportunityIterator::NGLayoutOpportunityIterator(
NGConstraintSpace* space,
- const NGLogicalOffset origin_point,
- const NGLogicalOffset leader_point)
- : constraint_space_(space), leader_point_(leader_point) {
+ const NGLogicalOffset& origin_point,
+ const NGLogicalOffset& leader_point)
+ : constraint_space_(space) {
+ RunPreconditionChecks(*space, origin_point, leader_point);
+
// TODO(chrome-layout-team): Combine exclusions that shadow each other.
auto& exclusions = constraint_space_->PhysicalSpace()->Exclusions();
DCHECK(std::is_sorted(exclusions.begin(), exclusions.end(),
@@ -227,6 +257,11 @@ NGLayoutOpportunityIterator::NGLayoutOpportunityIterator(
CreateLayoutOpportunityFromConstraintSpace(*space, origin_point);
opportunity_tree_root_ = new NGLayoutOpportunityTreeNode(initial_opportunity);
+ const NGLogicalRect leader_exclusion =
+ ToLeaderExclusion(origin_point, leader_point);
+ InsertExclusion(MutableOpportunityTreeRoot(), &leader_exclusion,
+ opportunities_);
+
for (const auto& exclusion : exclusions) {
InsertExclusion(MutableOpportunityTreeRoot(), exclusion.get(),
opportunities_);

Powered by Google App Engine
This is Rietveld 408576698