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

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

Issue 2438313003: [LayoutNG] Remove derived constraint spaces from opportunity iterator. (Closed)
Patch Set: rebase. 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/ng/ng_constraint_space.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_block_layout_algorithm.h" 5 #include "core/layout/ng/ng_block_layout_algorithm.h"
6 6
7 #include "core/layout/ng/ng_constraint_space.h" 7 #include "core/layout/ng/ng_constraint_space.h"
8 #include "core/layout/ng/ng_fragment_builder.h" 8 #include "core/layout/ng/ng_fragment_builder.h"
9 #include "core/layout/ng/ng_fragment.h" 9 #include "core/layout/ng/ng_fragment.h"
10 #include "core/layout/ng/ng_layout_opportunity_iterator.h" 10 #include "core/layout/ng/ng_layout_opportunity_iterator.h"
(...skipping 10 matching lines...) Expand all
21 const NGMarginStrut& curr_margin_strut) { 21 const NGMarginStrut& curr_margin_strut) {
22 return std::max(prev_margin_strut.margin_block_end, 22 return std::max(prev_margin_strut.margin_block_end,
23 curr_margin_strut.margin_block_start) - 23 curr_margin_strut.margin_block_start) -
24 std::max(prev_margin_strut.negative_margin_block_end.abs(), 24 std::max(prev_margin_strut.negative_margin_block_end.abs(),
25 curr_margin_strut.negative_margin_block_start.abs()); 25 curr_margin_strut.negative_margin_block_start.abs());
26 } 26 }
27 27
28 // Creates an exclusion from the fragment that will be placed in the provided 28 // Creates an exclusion from the fragment that will be placed in the provided
29 // layout opportunity. 29 // layout opportunity.
30 NGExclusion* CreateExclusion(const NGFragment& fragment, 30 NGExclusion* CreateExclusion(const NGFragment& fragment,
31 const NGConstraintSpace* opportunity, 31 const NGLogicalRect& opportunity,
Gleb Lanbin 2016/10/24 16:45:44 use NGLayoutOpportunity and below.
ikilpatrick 2016/10/24 17:09:19 Done.
32 LayoutUnit float_offset, 32 LayoutUnit float_offset,
33 NGBoxStrut margins) { 33 NGBoxStrut margins) {
34 LayoutUnit exclusion_top = opportunity->Offset().block_offset; 34 LayoutUnit exclusion_top = opportunity.offset.block_offset;
35 35
36 LayoutUnit exclusion_left = opportunity->Offset().inline_offset; 36 LayoutUnit exclusion_left = opportunity.offset.inline_offset;
37 exclusion_left += float_offset; 37 exclusion_left += float_offset;
38 38
39 LayoutUnit exclusion_bottom = exclusion_top + fragment.BlockSize(); 39 LayoutUnit exclusion_bottom = exclusion_top + fragment.BlockSize();
40 LayoutUnit exclusion_right = exclusion_left + fragment.InlineSize(); 40 LayoutUnit exclusion_right = exclusion_left + fragment.InlineSize();
41 41
42 // Adjust to child's margin. 42 // Adjust to child's margin.
43 exclusion_bottom += margins.BlockSum(); 43 exclusion_bottom += margins.BlockSum();
44 exclusion_right += margins.InlineSum(); 44 exclusion_right += margins.InlineSum();
45 45
46 return new NGExclusion(exclusion_top, exclusion_right, exclusion_bottom, 46 return new NGExclusion(exclusion_top, exclusion_right, exclusion_bottom,
47 exclusion_left); 47 exclusion_left);
48 } 48 }
49 49
50 // Finds a layout opportunity for the fragment. 50 // Finds a layout opportunity for the fragment.
51 // It iterates over all layout opportunities in the constraint space and returns 51 // It iterates over all layout opportunities in the constraint space and returns
52 // the first layout opportunity that is wider than the fragment or returns the 52 // the first layout opportunity that is wider than the fragment or returns the
53 // last one which is always the widest. 53 // last one which is always the widest.
54 // 54 //
55 // @param space Constraint space that is used to find layout opportunity for 55 // @param space Constraint space that is used to find layout opportunity for
56 // the fragment. 56 // the fragment.
57 // @param fragment Fragment that needs to be placed. 57 // @param fragment Fragment that needs to be placed.
58 // @return Layout opportunity for the fragment. 58 // @return Layout opportunity for the fragment.
59 const NGConstraintSpace* FindLayoutOpportunityForFragment( 59 const NGLogicalRect FindLayoutOpportunityForFragment(
60 const Member<NGConstraintSpace>& space, 60 const Member<NGConstraintSpace>& space,
61 const NGFragment& fragment) { 61 const NGFragment& fragment) {
62 NGLayoutOpportunityIterator* opportunity_iter = space->LayoutOpportunities(); 62 NGLayoutOpportunityIterator* opportunity_iter = space->LayoutOpportunities();
63 const NGConstraintSpace* opportunity = nullptr; 63 NGLogicalRect opportunity;
64 while (const NGConstraintSpace* opportunity_candidate = 64 NGLogicalRect opportunity_candidate = opportunity_iter->Next();
65 opportunity_iter->Next()) { 65
66 while (!opportunity_candidate.IsEmpty()) {
66 opportunity = opportunity_candidate; 67 opportunity = opportunity_candidate;
67 // Checking opportunity's block size is not necessary as a float cannot be 68 // Checking opportunity's block size is not necessary as a float cannot be
68 // positioned on top of another float inside of the same constraint space. 69 // positioned on top of another float inside of the same constraint space.
69 if (opportunity->Size().inline_size > fragment.InlineSize()) 70 if (opportunity.size.inline_size > fragment.InlineSize())
70 break; 71 break;
72
73 opportunity_candidate = opportunity_iter->Next();
71 } 74 }
75
72 return opportunity; 76 return opportunity;
73 } 77 }
74 78
75 // Calculates the logical offset for opportunity. 79 // Calculates the logical offset for opportunity.
76 NGLogicalOffset CalculateLogicalOffsetForOpportunity( 80 NGLogicalOffset CalculateLogicalOffsetForOpportunity(
77 const NGConstraintSpace* opportunity, 81 const NGLogicalRect& opportunity,
78 NGBoxStrut border_padding, 82 NGBoxStrut border_padding,
79 LayoutUnit float_offset, 83 LayoutUnit float_offset,
80 NGBoxStrut margins) { 84 NGBoxStrut margins) {
81 // TODO(layout-ng): create children_constraint_space with an offset for the 85 // TODO(layout-ng): create children_constraint_space with an offset for the
82 // border and padding. 86 // border and padding.
83 // Offset from parent's border/padding. 87 // Offset from parent's border/padding.
84 LayoutUnit inline_offset = border_padding.inline_start; 88 LayoutUnit inline_offset = border_padding.inline_start;
85 LayoutUnit block_offset = border_padding.block_start; 89 LayoutUnit block_offset = border_padding.block_start;
86 90
87 // Adjust to child's margin. 91 // Adjust to child's margin.
88 inline_offset += margins.inline_start; 92 inline_offset += margins.inline_start;
89 block_offset += margins.block_start; 93 block_offset += margins.block_start;
90 94
91 // Offset from the opportunity's block/inline start. 95 // Offset from the opportunity's block/inline start.
92 inline_offset += opportunity->Offset().inline_offset; 96 inline_offset += opportunity.offset.inline_offset;
93 block_offset += opportunity->Offset().block_offset; 97 block_offset += opportunity.offset.block_offset;
94 98
95 inline_offset += float_offset; 99 inline_offset += float_offset;
96 100
97 return NGLogicalOffset(inline_offset, block_offset); 101 return NGLogicalOffset(inline_offset, block_offset);
98 } 102 }
99 103
100 // Whether an in-flow block-level child creates a new formatting context. 104 // Whether an in-flow block-level child creates a new formatting context.
101 // 105 //
102 // This will *NOT* check the following cases: 106 // This will *NOT* check the following cases:
103 // - The child is out-of-flow, e.g. floating or abs-pos. 107 // - The child is out-of-flow, e.g. floating or abs-pos.
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 max_inline_size_, fragment.InlineSize() + child_margins.InlineSum() + 320 max_inline_size_, fragment.InlineSize() + child_margins.InlineSum() +
317 border_and_padding_.InlineSum()); 321 border_and_padding_.InlineSum());
318 return NGLogicalOffset(inline_offset, block_offset); 322 return NGLogicalOffset(inline_offset, block_offset);
319 } 323 }
320 324
321 NGLogicalOffset NGBlockLayoutAlgorithm::PositionFloatFragment( 325 NGLogicalOffset NGBlockLayoutAlgorithm::PositionFloatFragment(
322 const NGFragment& fragment, 326 const NGFragment& fragment,
323 NGBoxStrut margins) { 327 NGBoxStrut margins) {
324 // TODO(glebl@chromium.org): Support the top edge alignment rule. 328 // TODO(glebl@chromium.org): Support the top edge alignment rule.
325 // Find a layout opportunity that will fit our float. 329 // Find a layout opportunity that will fit our float.
326 const NGConstraintSpace* opportunity = FindLayoutOpportunityForFragment( 330 const NGLogicalRect opportunity = FindLayoutOpportunityForFragment(
327 constraint_space_for_children_, fragment); 331 constraint_space_for_children_, fragment);
328 DCHECK(opportunity) << "Opportunity is NULL but it shouldn't be"; 332 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be";
329 333
330 // Calculate the float offset if needed. 334 // Calculate the float offset if needed.
331 LayoutUnit float_offset; 335 LayoutUnit float_offset;
332 if (current_child_->Style()->floating() == EFloat::Right) { 336 if (current_child_->Style()->floating() == EFloat::Right) {
333 float_offset = opportunity->Size().inline_size - fragment.InlineSize(); 337 float_offset = opportunity.size.inline_size - fragment.InlineSize();
334 } 338 }
335 339
336 // Add the float as an exclusion. 340 // Add the float as an exclusion.
337 NGExclusion* exclusion = 341 NGExclusion* exclusion =
338 CreateExclusion(fragment, opportunity, float_offset, margins); 342 CreateExclusion(fragment, opportunity, float_offset, margins);
339 constraint_space_for_children_->AddExclusion(exclusion); 343 constraint_space_for_children_->AddExclusion(exclusion);
340 344
341 return CalculateLogicalOffsetForOpportunity(opportunity, border_and_padding_, 345 return CalculateLogicalOffsetForOpportunity(opportunity, border_and_padding_,
342 float_offset, margins); 346 float_offset, margins);
343 } 347 }
344 348
345 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) { 349 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) {
346 if (!is_fragment_margin_strut_block_start_updated_) { 350 if (!is_fragment_margin_strut_block_start_updated_) {
347 builder_->SetMarginStrutBlockStart(from); 351 builder_->SetMarginStrutBlockStart(from);
348 is_fragment_margin_strut_block_start_updated_ = true; 352 is_fragment_margin_strut_block_start_updated_ = true;
349 } 353 }
350 builder_->SetMarginStrutBlockEnd(from); 354 builder_->SetMarginStrutBlockEnd(from);
351 } 355 }
352 356
353 } // namespace blink 357 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/ng/ng_constraint_space.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698