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

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

Issue 2750153003: Move NGLayoutOpportunityTreeNode off Oilpan (Closed)
Patch Set: Created 3 years, 9 months 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 #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 14 matching lines...) Expand all
25 25
26 StringBuilder indent_builder; 26 StringBuilder indent_builder;
27 for (unsigned i = 0; i < indent; i++) 27 for (unsigned i = 0; i < indent; i++)
28 indent_builder.append("\t"); 28 indent_builder.append("\t");
29 29
30 if (node->IsLeafNode()) 30 if (node->IsLeafNode())
31 return; 31 return;
32 32
33 string_builder->append(indent_builder.toString()); 33 string_builder->append(indent_builder.toString());
34 string_builder->append("Left:\t"); 34 string_builder->append("Left:\t");
35 AppendNodeToString(node->left, string_builder, indent + 2); 35 AppendNodeToString(node->left.get(), string_builder, indent + 2);
36 string_builder->append(indent_builder.toString()); 36 string_builder->append(indent_builder.toString());
37 string_builder->append("Right:\t"); 37 string_builder->append("Right:\t");
38 AppendNodeToString(node->right, string_builder, indent + 2); 38 AppendNodeToString(node->right.get(), string_builder, indent + 2);
39 string_builder->append(indent_builder.toString()); 39 string_builder->append(indent_builder.toString());
40 string_builder->append("Bottom:\t"); 40 string_builder->append("Bottom:\t");
41 AppendNodeToString(node->bottom, string_builder, indent + 2); 41 AppendNodeToString(node->bottom.get(), string_builder, indent + 2);
42 } 42 }
43 43
44 // Collects all opportunities from leaves of Layout Opportunity spatial tree. 44 // Collects all opportunities from leaves of Layout Opportunity spatial tree.
45 void CollectAllOpportunities(const NGLayoutOpportunityTreeNode* node, 45 void CollectAllOpportunities(const NGLayoutOpportunityTreeNode* node,
46 NGLayoutOpportunities& opportunities) { 46 NGLayoutOpportunities& opportunities) {
47 if (!node) 47 if (!node)
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, opportunities); 51 CollectAllOpportunities(node->left.get(), opportunities);
52 CollectAllOpportunities(node->bottom, opportunities); 52 CollectAllOpportunities(node->bottom.get(), opportunities);
53 CollectAllOpportunities(node->right, 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 NGConstraintSpace& space,
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 = space.AvailableSize().block_size >= 0
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 opportunity.offset.block_offset = parent_opportunity.BlockStartOffset(); 154 opportunity.offset.block_offset = parent_opportunity.BlockStartOffset();
155 opportunity.size.inline_size = right_opportunity_inline_size; 155 opportunity.size.inline_size = right_opportunity_inline_size;
156 opportunity.size.block_size = parent_opportunity.BlockSize(); 156 opportunity.size.block_size = parent_opportunity.BlockSize();
157 return new NGLayoutOpportunityTreeNode(opportunity); 157 return new NGLayoutOpportunityTreeNode(opportunity);
158 } 158 }
159 return nullptr; 159 return nullptr;
160 } 160 }
161 161
162 void SplitNGLayoutOpportunityTreeNode(const NGLogicalRect& rect, 162 void SplitNGLayoutOpportunityTreeNode(const NGLogicalRect& rect,
163 NGLayoutOpportunityTreeNode* node) { 163 NGLayoutOpportunityTreeNode* node) {
164 node->left = CreateLeftNGLayoutOpportunityTreeNode(node, rect); 164 node->left.reset(CreateLeftNGLayoutOpportunityTreeNode(node, rect));
165 node->right = CreateRightNGLayoutOpportunityTreeNode(node, rect); 165 node->right.reset(CreateRightNGLayoutOpportunityTreeNode(node, rect));
166 node->bottom = CreateBottomNGLayoutOpportunityTreeNode(node, rect); 166 node->bottom.reset(CreateBottomNGLayoutOpportunityTreeNode(node, rect));
167 } 167 }
168 168
169 // Gets/Creates the "TOP" positioned constraint space by splitting 169 // Gets/Creates the "TOP" positioned constraint space by splitting
170 // the parent node with the exclusion. 170 // the parent node with the exclusion.
171 // 171 //
172 // @param parent_opportunity Parent opportunity that is being split. 172 // @param parent_opportunity Parent opportunity that is being split.
173 // @param exclusion Exclusion existed in the parent node constraint space. 173 // @param exclusion Exclusion existed in the parent node constraint space.
174 // @return New node or nullptr if the new block size == 0. 174 // @return New node or nullptr if the new block size == 0.
175 NGLayoutOpportunity GetTopSpace(const NGLayoutOpportunity& parent_opportunity, 175 NGLayoutOpportunity GetTopSpace(const NGLayoutOpportunity& parent_opportunity,
176 const NGLogicalRect& exclusion) { 176 const NGLogicalRect& exclusion) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 node->combined_exclusion = WTF::makeUnique<NGExclusion>(*exclusion); 215 node->combined_exclusion = WTF::makeUnique<NGExclusion>(*exclusion);
216 return; 216 return;
217 } 217 }
218 218
219 DCHECK(!node->exclusions.isEmpty()); 219 DCHECK(!node->exclusions.isEmpty());
220 220
221 if (node->combined_exclusion->MaybeCombineWith(*exclusion)) { 221 if (node->combined_exclusion->MaybeCombineWith(*exclusion)) {
222 SplitNGLayoutOpportunityTreeNode(node->combined_exclusion->rect, node); 222 SplitNGLayoutOpportunityTreeNode(node->combined_exclusion->rect, node);
223 node->exclusions.push_back(exclusion); 223 node->exclusions.push_back(exclusion);
224 } else { 224 } else {
225 InsertExclusion(node->left, exclusion, opportunities); 225 InsertExclusion(node->left.get(), exclusion, opportunities);
226 InsertExclusion(node->bottom, exclusion, opportunities); 226 InsertExclusion(node->bottom.get(), exclusion, opportunities);
227 InsertExclusion(node->right, exclusion, opportunities); 227 InsertExclusion(node->right.get(), exclusion, opportunities);
228 } 228 }
229 } 229 }
230 230
231 // Compares exclusions by their top position. 231 // Compares exclusions by their top position.
232 bool CompareNGExclusionsByTopAsc( 232 bool CompareNGExclusionsByTopAsc(
233 const std::unique_ptr<const NGExclusion>& lhs, 233 const std::unique_ptr<const NGExclusion>& lhs,
234 const std::unique_ptr<const NGExclusion>& rhs) { 234 const std::unique_ptr<const NGExclusion>& rhs) {
235 return rhs->rect.offset.block_offset > lhs->rect.offset.block_offset; 235 return rhs->rect.offset.block_offset > lhs->rect.offset.block_offset;
236 } 236 }
237 237
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 : constraint_space_(space), 281 : constraint_space_(space),
282 offset_(opt_offset ? opt_offset.value() : space->BfcOffset()) { 282 offset_(opt_offset ? opt_offset.value() : space->BfcOffset()) {
283 // TODO(chrome-layout-team): Combine exclusions that shadow each other. 283 // TODO(chrome-layout-team): Combine exclusions that shadow each other.
284 auto& exclusions = constraint_space_->Exclusions(); 284 auto& exclusions = constraint_space_->Exclusions();
285 DCHECK(std::is_sorted(exclusions->storage.begin(), exclusions->storage.end(), 285 DCHECK(std::is_sorted(exclusions->storage.begin(), exclusions->storage.end(),
286 &CompareNGExclusionsByTopAsc)) 286 &CompareNGExclusionsByTopAsc))
287 << "Exclusions are expected to be sorted by TOP"; 287 << "Exclusions are expected to be sorted by TOP";
288 288
289 NGLayoutOpportunity initial_opportunity = 289 NGLayoutOpportunity initial_opportunity =
290 CreateLayoutOpportunityFromConstraintSpace(*constraint_space_, Offset()); 290 CreateLayoutOpportunityFromConstraintSpace(*constraint_space_, Offset());
291 opportunity_tree_root_ = new NGLayoutOpportunityTreeNode(initial_opportunity); 291 opportunity_tree_root_.reset(
292 new NGLayoutOpportunityTreeNode(initial_opportunity));
292 293
293 if (opt_leader_point) { 294 if (opt_leader_point) {
294 const NGExclusion leader_exclusion = 295 const NGExclusion leader_exclusion =
295 ToLeaderExclusion(Offset(), opt_leader_point.value()); 296 ToLeaderExclusion(Offset(), opt_leader_point.value());
296 InsertExclusion(MutableOpportunityTreeRoot(), &leader_exclusion, 297 InsertExclusion(MutableOpportunityTreeRoot(), &leader_exclusion,
297 opportunities_); 298 opportunities_);
298 } 299 }
299 300
300 for (const auto& exclusion : exclusions->storage) { 301 for (const auto& exclusion : exclusions->storage) {
301 InsertExclusion(MutableOpportunityTreeRoot(), exclusion.get(), 302 InsertExclusion(MutableOpportunityTreeRoot(), exclusion.get(),
(...skipping 17 matching lines...) Expand all
319 #ifndef NDEBUG 320 #ifndef NDEBUG
320 void NGLayoutOpportunityIterator::ShowLayoutOpportunityTree() const { 321 void NGLayoutOpportunityIterator::ShowLayoutOpportunityTree() const {
321 StringBuilder string_builder; 322 StringBuilder string_builder;
322 string_builder.append("\n.:: LayoutOpportunity Tree ::.\n\nRoot Node: "); 323 string_builder.append("\n.:: LayoutOpportunity Tree ::.\n\nRoot Node: ");
323 AppendNodeToString(opportunity_tree_root_.get(), &string_builder); 324 AppendNodeToString(opportunity_tree_root_.get(), &string_builder);
324 fprintf(stderr, "%s\n", string_builder.toString().utf8().data()); 325 fprintf(stderr, "%s\n", string_builder.toString().utf8().data());
325 } 326 }
326 #endif 327 #endif
327 328
328 } // namespace blink 329 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698