| 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 | |
| 7 #include "core/layout/ng/ng_constraint_space.h" | 6 #include "core/layout/ng/ng_constraint_space.h" |
| 8 #include "core/layout/ng/ng_exclusion.h" | 7 #include "core/layout/ng/ng_exclusion.h" |
| 9 #include "wtf/NonCopyingSort.h" | 8 #include "wtf/NonCopyingSort.h" |
| 10 #include "wtf/text/StringBuilder.h" | 9 #include "wtf/text/StringBuilder.h" |
| 11 | 10 |
| 12 namespace blink { | 11 namespace blink { |
| 13 namespace { | 12 namespace { |
| 14 | 13 |
| 15 void AppendNodeToString(const NGLayoutOpportunityTreeNode* node, | 14 void AppendNodeToString(const NGLayoutOpportunityTreeNode* node, |
| 16 StringBuilder* string_builder, | 15 StringBuilder* string_builder, |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 NGExclusion leader_exclusion; | 257 NGExclusion leader_exclusion; |
| 259 leader_exclusion.rect.offset = origin_point; | 258 leader_exclusion.rect.offset = origin_point; |
| 260 leader_exclusion.rect.size = {inline_size, block_size}; | 259 leader_exclusion.rect.size = {inline_size, block_size}; |
| 261 return leader_exclusion; | 260 return leader_exclusion; |
| 262 } | 261 } |
| 263 | 262 |
| 264 } // namespace | 263 } // namespace |
| 265 | 264 |
| 266 NGLayoutOpportunityIterator::NGLayoutOpportunityIterator( | 265 NGLayoutOpportunityIterator::NGLayoutOpportunityIterator( |
| 267 const NGConstraintSpace* space, | 266 const NGConstraintSpace* space, |
| 268 const WTF::Optional<NGLogicalOffset>& opt_origin_point, | 267 const WTF::Optional<NGLogicalOffset>& opt_offset, |
| 269 const WTF::Optional<NGLogicalOffset>& opt_leader_point) | 268 const WTF::Optional<NGLogicalOffset>& opt_leader_point) |
| 270 : constraint_space_(space) { | 269 : constraint_space_(space), |
| 270 offset_(opt_offset ? opt_offset.value() : space->BfcOffset()) { |
| 271 // TODO(chrome-layout-team): Combine exclusions that shadow each other. | 271 // TODO(chrome-layout-team): Combine exclusions that shadow each other. |
| 272 auto& exclusions = constraint_space_->Exclusions(); | 272 auto& exclusions = constraint_space_->Exclusions(); |
| 273 DCHECK(std::is_sorted(exclusions->storage.begin(), exclusions->storage.end(), | 273 DCHECK(std::is_sorted(exclusions->storage.begin(), exclusions->storage.end(), |
| 274 &CompareNGExclusionsByTopAsc)) | 274 &CompareNGExclusionsByTopAsc)) |
| 275 << "Exclusions are expected to be sorted by TOP"; | 275 << "Exclusions are expected to be sorted by TOP"; |
| 276 | 276 |
| 277 NGLogicalOffset origin_point = | |
| 278 opt_origin_point ? opt_origin_point.value() : NGLogicalOffset(); | |
| 279 NGLayoutOpportunity initial_opportunity = | 277 NGLayoutOpportunity initial_opportunity = |
| 280 CreateLayoutOpportunityFromConstraintSpace(*constraint_space_, | 278 CreateLayoutOpportunityFromConstraintSpace(*constraint_space_, Offset()); |
| 281 origin_point); | |
| 282 opportunity_tree_root_ = new NGLayoutOpportunityTreeNode(initial_opportunity); | 279 opportunity_tree_root_ = new NGLayoutOpportunityTreeNode(initial_opportunity); |
| 283 | 280 |
| 284 if (opt_leader_point) { | 281 if (opt_leader_point) { |
| 285 const NGExclusion leader_exclusion = | 282 const NGExclusion leader_exclusion = |
| 286 ToLeaderExclusion(origin_point, opt_leader_point.value()); | 283 ToLeaderExclusion(Offset(), opt_leader_point.value()); |
| 287 InsertExclusion(MutableOpportunityTreeRoot(), &leader_exclusion, | 284 InsertExclusion(MutableOpportunityTreeRoot(), &leader_exclusion, |
| 288 opportunities_); | 285 opportunities_); |
| 289 } | 286 } |
| 290 | 287 |
| 291 for (const auto& exclusion : exclusions->storage) { | 288 for (const auto& exclusion : exclusions->storage) { |
| 292 InsertExclusion(MutableOpportunityTreeRoot(), exclusion.get(), | 289 InsertExclusion(MutableOpportunityTreeRoot(), exclusion.get(), |
| 293 opportunities_); | 290 opportunities_); |
| 294 } | 291 } |
| 295 CollectAllOpportunities(OpportunityTreeRoot(), opportunities_); | 292 CollectAllOpportunities(OpportunityTreeRoot(), opportunities_); |
| 296 std::sort(opportunities_.begin(), opportunities_.end(), | 293 std::sort(opportunities_.begin(), opportunities_.end(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 310 #ifndef NDEBUG | 307 #ifndef NDEBUG |
| 311 void NGLayoutOpportunityIterator::ShowLayoutOpportunityTree() const { | 308 void NGLayoutOpportunityIterator::ShowLayoutOpportunityTree() const { |
| 312 StringBuilder string_builder; | 309 StringBuilder string_builder; |
| 313 string_builder.append("\n.:: LayoutOpportunity Tree ::.\n\nRoot Node: "); | 310 string_builder.append("\n.:: LayoutOpportunity Tree ::.\n\nRoot Node: "); |
| 314 AppendNodeToString(opportunity_tree_root_.get(), &string_builder); | 311 AppendNodeToString(opportunity_tree_root_.get(), &string_builder); |
| 315 fprintf(stderr, "%s\n", string_builder.toString().utf8().data()); | 312 fprintf(stderr, "%s\n", string_builder.toString().utf8().data()); |
| 316 } | 313 } |
| 317 #endif | 314 #endif |
| 318 | 315 |
| 319 } // namespace blink | 316 } // namespace blink |
| OLD | NEW |