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

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

Issue 2733133002: Combine 2 exclusions in Layout Opportunity Tree if they shadow each other (Closed)
Patch Set: delete unreachable return statement 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 6
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
11 namespace blink { 11 namespace blink {
12 namespace { 12 namespace {
13 13
14 void AppendNodeToString(const NGLayoutOpportunityTreeNode* node, 14 void AppendNodeToString(const NGLayoutOpportunityTreeNode* node,
15 StringBuilder* string_builder, 15 StringBuilder* string_builder,
16 unsigned indent = 0) { 16 unsigned indent = 0) {
17 DCHECK(string_builder); 17 DCHECK(string_builder);
18 if (!node) { 18 if (!node) {
19 string_builder->append("'null'\n"); 19 string_builder->append("'null'\n");
20 return; 20 return;
21 } 21 }
22 22
23 string_builder->append(node->ToString()); 23 string_builder->append(node->ToString());
24 string_builder->append("\n"); 24 string_builder->append("\n");
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->exclusion) 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, 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, 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");
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 NGLayoutOpportunity opportunity; 152 NGLayoutOpportunity opportunity;
153 opportunity.offset.inline_offset = exclusion.InlineEndOffset(); 153 opportunity.offset.inline_offset = exclusion.InlineEndOffset();
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,
163 NGLayoutOpportunityTreeNode* node) {
164 node->left = CreateLeftNGLayoutOpportunityTreeNode(node, rect);
165 node->right = CreateRightNGLayoutOpportunityTreeNode(node, rect);
166 node->bottom = CreateBottomNGLayoutOpportunityTreeNode(node, rect);
167 }
168
162 // Gets/Creates the "TOP" positioned constraint space by splitting 169 // Gets/Creates the "TOP" positioned constraint space by splitting
163 // the parent node with the exclusion. 170 // the parent node with the exclusion.
164 // 171 //
165 // @param parent_opportunity Parent opportunity that is being split. 172 // @param parent_opportunity Parent opportunity that is being split.
166 // @param exclusion Exclusion existed in the parent node constraint space. 173 // @param exclusion Exclusion existed in the parent node constraint space.
167 // @return New node or nullptr if the new block size == 0. 174 // @return New node or nullptr if the new block size == 0.
168 NGLayoutOpportunity GetTopSpace(const NGLayoutOpportunity& parent_opportunity, 175 NGLayoutOpportunity GetTopSpace(const NGLayoutOpportunity& parent_opportunity,
169 const NGLogicalRect& exclusion) { 176 const NGLogicalRect& exclusion) {
170 LayoutUnit top_opportunity_block_size = 177 LayoutUnit top_opportunity_block_size =
171 exclusion.BlockStartOffset() - parent_opportunity.BlockStartOffset(); 178 exclusion.BlockStartOffset() - parent_opportunity.BlockStartOffset();
(...skipping 17 matching lines...) Expand all
189 return; 196 return;
190 197
191 // Base case: there is no node. 198 // Base case: there is no node.
192 if (!node) 199 if (!node)
193 return; 200 return;
194 201
195 // Base case: exclusion is not in the node's constraint space. 202 // Base case: exclusion is not in the node's constraint space.
196 if (!exclusion->rect.IsContained(node->opportunity)) 203 if (!exclusion->rect.IsContained(node->opportunity))
197 return; 204 return;
198 205
199 if (node->exclusion) { 206 if (node->exclusions.isEmpty()) {
207 SplitNGLayoutOpportunityTreeNode(exclusion->rect, node);
208
209 NGLayoutOpportunity top_layout_opp =
210 GetTopSpace(node->opportunity, exclusion->rect);
211 if (!top_layout_opp.IsEmpty())
212 opportunities.push_back(top_layout_opp);
213
214 node->exclusions.push_back(exclusion);
215 node->combined_exclusion = WTF::makeUnique<NGExclusion>(*exclusion);
216 return;
217 }
218
219 DCHECK(!node->exclusions.isEmpty());
220
221 if (node->combined_exclusion->MaybeCombineWith(*exclusion)) {
222 SplitNGLayoutOpportunityTreeNode(node->combined_exclusion->rect, node);
223 node->exclusions.push_back(exclusion);
224 } else {
200 InsertExclusion(node->left, exclusion, opportunities); 225 InsertExclusion(node->left, exclusion, opportunities);
201 InsertExclusion(node->bottom, exclusion, opportunities); 226 InsertExclusion(node->bottom, exclusion, opportunities);
202 InsertExclusion(node->right, exclusion, opportunities); 227 InsertExclusion(node->right, exclusion, opportunities);
203 return;
204 } 228 }
205
206 // Split the current node.
207 node->left = CreateLeftNGLayoutOpportunityTreeNode(node, exclusion->rect);
208 node->right = CreateRightNGLayoutOpportunityTreeNode(node, exclusion->rect);
209 node->bottom = CreateBottomNGLayoutOpportunityTreeNode(node, exclusion->rect);
210
211 NGLayoutOpportunity top_layout_opp =
212 GetTopSpace(node->opportunity, exclusion->rect);
213 if (!top_layout_opp.IsEmpty())
214 opportunities.push_back(top_layout_opp);
215
216 node->exclusion = exclusion;
217 } 229 }
218 230
219 // Compares exclusions by their top position. 231 // Compares exclusions by their top position.
220 bool CompareNGExclusionsByTopAsc( 232 bool CompareNGExclusionsByTopAsc(
221 const std::unique_ptr<const NGExclusion>& lhs, 233 const std::unique_ptr<const NGExclusion>& lhs,
222 const std::unique_ptr<const NGExclusion>& rhs) { 234 const std::unique_ptr<const NGExclusion>& rhs) {
223 return rhs->rect.offset.block_offset > lhs->rect.offset.block_offset; 235 return rhs->rect.offset.block_offset > lhs->rect.offset.block_offset;
224 } 236 }
225 237
226 // Compares Layout Opportunities by Start Point. 238 // Compares Layout Opportunities by Start Point.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 #ifndef NDEBUG 321 #ifndef NDEBUG
310 void NGLayoutOpportunityIterator::ShowLayoutOpportunityTree() const { 322 void NGLayoutOpportunityIterator::ShowLayoutOpportunityTree() const {
311 StringBuilder string_builder; 323 StringBuilder string_builder;
312 string_builder.append("\n.:: LayoutOpportunity Tree ::.\n\nRoot Node: "); 324 string_builder.append("\n.:: LayoutOpportunity Tree ::.\n\nRoot Node: ");
313 AppendNodeToString(opportunity_tree_root_.get(), &string_builder); 325 AppendNodeToString(opportunity_tree_root_.get(), &string_builder);
314 fprintf(stderr, "%s\n", string_builder.toString().utf8().data()); 326 fprintf(stderr, "%s\n", string_builder.toString().utf8().data());
315 } 327 }
316 #endif 328 #endif
317 329
318 } // namespace blink 330 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698