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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/layout/ng/ng_layout_opportunity_iterator.h" 5 #include "core/layout/ng/ng_layout_opportunity_iterator.h"
6 6
7 #include "core/layout/ng/ng_physical_constraint_space.h" 7 #include "core/layout/ng/ng_physical_constraint_space.h"
8 #include "core/layout/ng/ng_units.h" 8 #include "core/layout/ng/ng_units.h"
9 #include "wtf/NonCopyingSort.h" 9 #include "wtf/NonCopyingSort.h"
10 10
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 opportunity.size.block_size = top_opportunity_block_size; 143 opportunity.size.block_size = top_opportunity_block_size;
144 return opportunity; 144 return opportunity;
145 } 145 }
146 return NGLayoutOpportunity(); 146 return NGLayoutOpportunity();
147 } 147 }
148 148
149 // Inserts the exclusion into the Layout Opportunity tree. 149 // Inserts the exclusion into the Layout Opportunity tree.
150 void InsertExclusion(NGLayoutOpportunityTreeNode* node, 150 void InsertExclusion(NGLayoutOpportunityTreeNode* node,
151 const NGLogicalRect* exclusion, 151 const NGLogicalRect* exclusion,
152 NGLayoutOpportunities& opportunities) { 152 NGLayoutOpportunities& opportunities) {
153 // Base case: size of the exclusion is empty.
154 if (exclusion->size.IsEmpty())
155 return;
156
153 // Base case: there is no node. 157 // Base case: there is no node.
154 if (!node) 158 if (!node)
155 return; 159 return;
156 160
157 // Base case: exclusion is not in the node's constraint space. 161 // Base case: exclusion is not in the node's constraint space.
158 if (!exclusion->IsContained(node->opportunity)) 162 if (!exclusion->IsContained(node->opportunity))
159 return; 163 return;
160 164
161 if (node->exclusion) { 165 if (node->exclusion) {
162 InsertExclusion(node->left, exclusion, opportunities); 166 InsertExclusion(node->left, exclusion, opportunities);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 return true; 207 return true;
204 } 208 }
205 if (rhs.offset.inline_offset < lhs.offset.inline_offset) { 209 if (rhs.offset.inline_offset < lhs.offset.inline_offset) {
206 return false; 210 return false;
207 } 211 }
208 212
209 // TOP and LEFT are the same -> Sort by width 213 // TOP and LEFT are the same -> Sort by width
210 return rhs.size.inline_size < lhs.size.inline_size; 214 return rhs.size.inline_size < lhs.size.inline_size;
211 } 215 }
212 216
217 void RunPreconditionChecks(const NGConstraintSpace& space,
218 const NGLogicalOffset& origin_point,
219 const NGLogicalOffset& leader_point) {
220 DCHECK_GE(origin_point, space.Offset())
221 << "Origin point" << origin_point
222 << " should lay below the constraint space's offset " << space.Offset();
223
224 DCHECK_GE(leader_point, space.Offset())
225 << "Leader point" << leader_point
226 << " should lay below the constraint space's offset " << space.Offset();
227 }
228
229 NGLogicalRect ToLeaderExclusion(const NGLogicalOffset& origin_point,
230 const NGLogicalOffset& leader_point) {
231 LayoutUnit inline_size =
232 leader_point.inline_offset - origin_point.inline_offset;
233 LayoutUnit block_size = leader_point.block_offset - origin_point.block_offset;
234
235 NGLogicalRect leader_exclusion;
236 leader_exclusion.offset = origin_point;
237 leader_exclusion.size = {inline_size, block_size};
238 return leader_exclusion;
239 }
240
213 } // namespace 241 } // namespace
214 242
215 NGLayoutOpportunityIterator::NGLayoutOpportunityIterator( 243 NGLayoutOpportunityIterator::NGLayoutOpportunityIterator(
216 NGConstraintSpace* space, 244 NGConstraintSpace* space,
217 const NGLogicalOffset origin_point, 245 const NGLogicalOffset& origin_point,
218 const NGLogicalOffset leader_point) 246 const NGLogicalOffset& leader_point)
219 : constraint_space_(space), leader_point_(leader_point) { 247 : constraint_space_(space) {
248 RunPreconditionChecks(*space, origin_point, leader_point);
249
220 // TODO(chrome-layout-team): Combine exclusions that shadow each other. 250 // TODO(chrome-layout-team): Combine exclusions that shadow each other.
221 auto& exclusions = constraint_space_->PhysicalSpace()->Exclusions(); 251 auto& exclusions = constraint_space_->PhysicalSpace()->Exclusions();
222 DCHECK(std::is_sorted(exclusions.begin(), exclusions.end(), 252 DCHECK(std::is_sorted(exclusions.begin(), exclusions.end(),
223 &CompareNGExclusionsByTopAsc)) 253 &CompareNGExclusionsByTopAsc))
224 << "Exclusions are expected to be sorted by TOP"; 254 << "Exclusions are expected to be sorted by TOP";
225 255
226 NGLayoutOpportunity initial_opportunity = 256 NGLayoutOpportunity initial_opportunity =
227 CreateLayoutOpportunityFromConstraintSpace(*space, origin_point); 257 CreateLayoutOpportunityFromConstraintSpace(*space, origin_point);
228 opportunity_tree_root_ = new NGLayoutOpportunityTreeNode(initial_opportunity); 258 opportunity_tree_root_ = new NGLayoutOpportunityTreeNode(initial_opportunity);
229 259
260 const NGLogicalRect leader_exclusion =
261 ToLeaderExclusion(origin_point, leader_point);
262 InsertExclusion(MutableOpportunityTreeRoot(), &leader_exclusion,
263 opportunities_);
264
230 for (const auto& exclusion : exclusions) { 265 for (const auto& exclusion : exclusions) {
231 InsertExclusion(MutableOpportunityTreeRoot(), exclusion.get(), 266 InsertExclusion(MutableOpportunityTreeRoot(), exclusion.get(),
232 opportunities_); 267 opportunities_);
233 } 268 }
234 CollectAllOpportunities(OpportunityTreeRoot(), opportunities_); 269 CollectAllOpportunities(OpportunityTreeRoot(), opportunities_);
235 std::sort(opportunities_.begin(), opportunities_.end(), 270 std::sort(opportunities_.begin(), opportunities_.end(),
236 &CompareNGLayoutOpportunitesByStartPoint); 271 &CompareNGLayoutOpportunitesByStartPoint);
237 272
238 opportunity_iter_ = opportunities_.begin(); 273 opportunity_iter_ = opportunities_.begin();
239 } 274 }
240 275
241 const NGLayoutOpportunity NGLayoutOpportunityIterator::Next() { 276 const NGLayoutOpportunity NGLayoutOpportunityIterator::Next() {
242 if (opportunity_iter_ == opportunities_.end()) 277 if (opportunity_iter_ == opportunities_.end())
243 return NGLayoutOpportunity(); 278 return NGLayoutOpportunity();
244 auto* opportunity = opportunity_iter_; 279 auto* opportunity = opportunity_iter_;
245 opportunity_iter_++; 280 opportunity_iter_++;
246 return NGLayoutOpportunity(*opportunity); 281 return NGLayoutOpportunity(*opportunity);
247 } 282 }
248 283
249 } // namespace blink 284 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698