OLD | NEW |
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 #include "core/layout/ng/ng_constraint_space.h" | 6 #include "core/layout/ng/ng_constraint_space.h" |
7 #include "core/layout/ng/ng_exclusion.h" | 7 #include "core/layout/ng/ng_exclusion.h" |
8 #include "wtf/NonCopyingSort.h" | 8 #include "wtf/NonCopyingSort.h" |
9 #include "wtf/text/StringBuilder.h" | 9 #include "wtf/text/StringBuilder.h" |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 return; | 48 return; |
49 if (node->IsLeafNode()) | 49 if (node->IsLeafNode()) |
50 opportunities.push_back(node->opportunity); | 50 opportunities.push_back(node->opportunity); |
51 CollectAllOpportunities(node->left.get(), opportunities); | 51 CollectAllOpportunities(node->left.get(), opportunities); |
52 CollectAllOpportunities(node->bottom.get(), opportunities); | 52 CollectAllOpportunities(node->bottom.get(), opportunities); |
53 CollectAllOpportunities(node->right.get(), opportunities); | 53 CollectAllOpportunities(node->right.get(), opportunities); |
54 } | 54 } |
55 | 55 |
56 // Creates layout opportunity from the provided space and the origin point. | 56 // Creates layout opportunity from the provided space and the origin point. |
57 NGLayoutOpportunity CreateLayoutOpportunityFromConstraintSpace( | 57 NGLayoutOpportunity CreateLayoutOpportunityFromConstraintSpace( |
58 const NGConstraintSpace& space, | 58 const NGLogicalSize& size, |
59 const NGLogicalOffset& origin_point) { | 59 const NGLogicalOffset& origin_point) { |
60 NGLayoutOpportunity opportunity; | 60 NGLayoutOpportunity opportunity; |
61 // TODO(glebl): Perhaps fix other methods (e.g IsContained) instead of using | 61 // TODO(glebl): Perhaps fix other methods (e.g IsContained) instead of using |
62 // INT_MAX here. | 62 // INT_MAX here. |
63 opportunity.size.block_size = space.AvailableSize().block_size >= 0 | 63 opportunity.size.block_size = |
64 ? space.AvailableSize().block_size | 64 size.block_size >= 0 ? size.block_size : LayoutUnit(INT_MAX); |
65 : LayoutUnit(INT_MAX); | 65 opportunity.size.inline_size = |
66 opportunity.size.inline_size = space.AvailableSize().inline_size >= 0 | 66 size.inline_size >= 0 ? size.inline_size : LayoutUnit(INT_MAX); |
67 ? space.AvailableSize().inline_size | |
68 : LayoutUnit(INT_MAX); | |
69 | 67 |
70 // adjust to the origin_point. | 68 // adjust to the origin_point. |
71 opportunity.offset += origin_point; | 69 opportunity.offset += origin_point; |
72 return opportunity; | 70 return opportunity; |
73 } | 71 } |
74 | 72 |
75 // Whether 2 edges overlap with each other. | 73 // Whether 2 edges overlap with each other. |
76 bool IsOverlapping(const NGEdge& edge1, const NGEdge& edge2) { | 74 bool IsOverlapping(const NGEdge& edge1, const NGEdge& edge2) { |
77 return std::max(edge1.start, edge2.start) <= std::min(edge1.end, edge2.end); | 75 return std::max(edge1.start, edge2.start) <= std::min(edge1.end, edge2.end); |
78 } | 76 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 NGExclusion leader_exclusion; | 267 NGExclusion leader_exclusion; |
270 leader_exclusion.rect.offset = origin_point; | 268 leader_exclusion.rect.offset = origin_point; |
271 leader_exclusion.rect.size = {inline_size, block_size}; | 269 leader_exclusion.rect.size = {inline_size, block_size}; |
272 return leader_exclusion; | 270 return leader_exclusion; |
273 } | 271 } |
274 | 272 |
275 } // namespace | 273 } // namespace |
276 | 274 |
277 NGLayoutOpportunityIterator::NGLayoutOpportunityIterator( | 275 NGLayoutOpportunityIterator::NGLayoutOpportunityIterator( |
278 const NGConstraintSpace* space, | 276 const NGConstraintSpace* space, |
| 277 const NGLogicalSize& available_size, |
279 const WTF::Optional<NGLogicalOffset>& opt_offset, | 278 const WTF::Optional<NGLogicalOffset>& opt_offset, |
280 const WTF::Optional<NGLogicalOffset>& opt_leader_point) | 279 const WTF::Optional<NGLogicalOffset>& opt_leader_point) |
281 : constraint_space_(space), | 280 : constraint_space_(space), |
282 offset_(opt_offset ? opt_offset.value() : space->BfcOffset()) { | 281 offset_(opt_offset ? opt_offset.value() : space->BfcOffset()) { |
283 // TODO(chrome-layout-team): Combine exclusions that shadow each other. | 282 // TODO(chrome-layout-team): Combine exclusions that shadow each other. |
284 auto& exclusions = constraint_space_->Exclusions(); | 283 auto& exclusions = constraint_space_->Exclusions(); |
285 DCHECK(std::is_sorted(exclusions->storage.begin(), exclusions->storage.end(), | 284 DCHECK(std::is_sorted(exclusions->storage.begin(), exclusions->storage.end(), |
286 &CompareNGExclusionsByTopAsc)) | 285 &CompareNGExclusionsByTopAsc)) |
287 << "Exclusions are expected to be sorted by TOP"; | 286 << "Exclusions are expected to be sorted by TOP"; |
288 | 287 |
289 NGLayoutOpportunity initial_opportunity = | 288 NGLayoutOpportunity initial_opportunity = |
290 CreateLayoutOpportunityFromConstraintSpace(*constraint_space_, Offset()); | 289 CreateLayoutOpportunityFromConstraintSpace(available_size, Offset()); |
291 opportunity_tree_root_.reset( | 290 opportunity_tree_root_.reset( |
292 new NGLayoutOpportunityTreeNode(initial_opportunity)); | 291 new NGLayoutOpportunityTreeNode(initial_opportunity)); |
293 | 292 |
294 if (opt_leader_point) { | 293 if (opt_leader_point) { |
295 const NGExclusion leader_exclusion = | 294 const NGExclusion leader_exclusion = |
296 ToLeaderExclusion(Offset(), opt_leader_point.value()); | 295 ToLeaderExclusion(Offset(), opt_leader_point.value()); |
297 InsertExclusion(MutableOpportunityTreeRoot(), &leader_exclusion, | 296 InsertExclusion(MutableOpportunityTreeRoot(), &leader_exclusion, |
298 opportunities_); | 297 opportunities_); |
299 } | 298 } |
300 | 299 |
(...skipping 19 matching lines...) Expand all Loading... |
320 #ifndef NDEBUG | 319 #ifndef NDEBUG |
321 void NGLayoutOpportunityIterator::ShowLayoutOpportunityTree() const { | 320 void NGLayoutOpportunityIterator::ShowLayoutOpportunityTree() const { |
322 StringBuilder string_builder; | 321 StringBuilder string_builder; |
323 string_builder.append("\n.:: LayoutOpportunity Tree ::.\n\nRoot Node: "); | 322 string_builder.append("\n.:: LayoutOpportunity Tree ::.\n\nRoot Node: "); |
324 AppendNodeToString(opportunity_tree_root_.get(), &string_builder); | 323 AppendNodeToString(opportunity_tree_root_.get(), &string_builder); |
325 fprintf(stderr, "%s\n", string_builder.toString().utf8().data()); | 324 fprintf(stderr, "%s\n", string_builder.toString().utf8().data()); |
326 } | 325 } |
327 #endif | 326 #endif |
328 | 327 |
329 } // namespace blink | 328 } // namespace blink |
OLD | NEW |