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

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

Issue 2426493003: [LayoutNG] Capitalize functions in ng_length_utils.h (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/ng/ng_box.cc » ('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_length_utils.h" 10 #include "core/layout/ng/ng_length_utils.h"
(...skipping 23 matching lines...) Expand all
34 state_(kStateInit), 34 state_(kStateInit),
35 is_fragment_margin_strut_block_start_updated_(false) { 35 is_fragment_margin_strut_block_start_updated_(false) {
36 DCHECK(style_); 36 DCHECK(style_);
37 } 37 }
38 38
39 bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space, 39 bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space,
40 NGPhysicalFragment** out) { 40 NGPhysicalFragment** out) {
41 switch (state_) { 41 switch (state_) {
42 case kStateInit: { 42 case kStateInit: {
43 border_and_padding_ = 43 border_and_padding_ =
44 computeBorders(*style_) + computePadding(*constraint_space, *style_); 44 ComputeBorders(*style_) + ComputePadding(*constraint_space, *style_);
45 45
46 LayoutUnit inline_size = 46 LayoutUnit inline_size =
47 computeInlineSizeForFragment(*constraint_space, *style_); 47 ComputeInlineSizeForFragment(*constraint_space, *style_);
48 LayoutUnit adjusted_inline_size = 48 LayoutUnit adjusted_inline_size =
49 inline_size - border_and_padding_.InlineSum(); 49 inline_size - border_and_padding_.InlineSum();
50 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of 50 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of
51 // -1? 51 // -1?
52 LayoutUnit block_size = computeBlockSizeForFragment( 52 LayoutUnit block_size = ComputeBlockSizeForFragment(
53 *constraint_space, *style_, NGSizeIndefinite); 53 *constraint_space, *style_, NGSizeIndefinite);
54 LayoutUnit adjusted_block_size(block_size); 54 LayoutUnit adjusted_block_size(block_size);
55 // Our calculated block-axis size may be indefinite at this point. 55 // Our calculated block-axis size may be indefinite at this point.
56 // If so, just leave the size as NGSizeIndefinite instead of subtracting 56 // If so, just leave the size as NGSizeIndefinite instead of subtracting
57 // borders and padding. 57 // borders and padding.
58 if (adjusted_block_size != NGSizeIndefinite) 58 if (adjusted_block_size != NGSizeIndefinite)
59 adjusted_block_size -= border_and_padding_.BlockSum(); 59 adjusted_block_size -= border_and_padding_.BlockSum();
60 constraint_space_for_children_ = new NGConstraintSpace( 60 constraint_space_for_children_ = new NGConstraintSpace(
61 FromPlatformWritingMode(style_->getWritingMode()), 61 FromPlatformWritingMode(style_->getWritingMode()),
62 FromPlatformDirection(style_->direction()), *constraint_space, 62 FromPlatformDirection(style_->direction()), *constraint_space,
63 NGLogicalSize(adjusted_inline_size, adjusted_block_size)); 63 NGLogicalSize(adjusted_inline_size, adjusted_block_size));
64 content_size_ = border_and_padding_.block_start; 64 content_size_ = border_and_padding_.block_start;
65 65
66 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox); 66 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox);
67 builder_->SetDirection(constraint_space->Direction()); 67 builder_->SetDirection(constraint_space->Direction());
68 builder_->SetWritingMode(constraint_space->WritingMode()); 68 builder_->SetWritingMode(constraint_space->WritingMode());
69 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); 69 builder_->SetInlineSize(inline_size).SetBlockSize(block_size);
70 current_child_ = first_child_; 70 current_child_ = first_child_;
71 state_ = kStateChildLayout; 71 state_ = kStateChildLayout;
72 return false; 72 return false;
73 } 73 }
74 case kStateChildLayout: { 74 case kStateChildLayout: {
75 if (current_child_) { 75 if (current_child_) {
76 NGFragment* fragment; 76 NGFragment* fragment;
77 if (!current_child_->Layout(constraint_space_for_children_, &fragment)) 77 if (!current_child_->Layout(constraint_space_for_children_, &fragment))
78 return false; 78 return false;
79 NGBoxStrut child_margins = computeMargins( 79 NGBoxStrut child_margins = ComputeMargins(
80 *constraint_space_for_children_, *current_child_->Style(), 80 *constraint_space_for_children_, *current_child_->Style(),
81 constraint_space_for_children_->WritingMode(), 81 constraint_space_for_children_->WritingMode(),
82 constraint_space_for_children_->Direction()); 82 constraint_space_for_children_->Direction());
83 ApplyAutoMargins(*constraint_space_for_children_, 83 ApplyAutoMargins(*constraint_space_for_children_,
84 *current_child_->Style(), *fragment, child_margins); 84 *current_child_->Style(), *fragment, child_margins);
85 85
86 const NGBoxStrut margins = 86 const NGBoxStrut margins =
87 CollapseMargins(*constraint_space, child_margins, *fragment); 87 CollapseMargins(*constraint_space, child_margins, *fragment);
88 88
89 // TODO(layout-ng): Support auto margins 89 // TODO(layout-ng): Support auto margins
(...skipping 11 matching lines...) Expand all
101 if (current_child_) 101 if (current_child_)
102 return false; 102 return false;
103 } 103 }
104 state_ = kStateFinalize; 104 state_ = kStateFinalize;
105 return false; 105 return false;
106 } 106 }
107 case kStateFinalize: { 107 case kStateFinalize: {
108 content_size_ += border_and_padding_.block_end; 108 content_size_ += border_and_padding_.block_end;
109 109
110 // Recompute the block-axis size now that we know our content size. 110 // Recompute the block-axis size now that we know our content size.
111 LayoutUnit block_size = computeBlockSizeForFragment( 111 LayoutUnit block_size = ComputeBlockSizeForFragment(
112 *constraint_space, *style_, content_size_); 112 *constraint_space, *style_, content_size_);
113 113
114 builder_->SetBlockSize(block_size) 114 builder_->SetBlockSize(block_size)
115 .SetInlineOverflow(max_inline_size_) 115 .SetInlineOverflow(max_inline_size_)
116 .SetBlockOverflow(content_size_); 116 .SetBlockOverflow(content_size_);
117 *out = builder_->ToFragment(); 117 *out = builder_->ToFragment();
118 state_ = kStateInit; 118 state_ = kStateInit;
119 return true; 119 return true;
120 } 120 }
121 }; 121 };
122 NOTREACHED(); 122 NOTREACHED();
123 *out = nullptr; 123 *out = nullptr;
124 return true; 124 return true;
125 } 125 }
126 126
127 NGBoxStrut NGBlockLayoutAlgorithm::CollapseMargins( 127 NGBoxStrut NGBlockLayoutAlgorithm::CollapseMargins(
128 const NGConstraintSpace& space, 128 const NGConstraintSpace& space,
129 const NGBoxStrut& margins, 129 const NGBoxStrut& margins,
130 const NGFragment& fragment) { 130 const NGFragment& fragment) {
131 bool is_zero_height_box = !fragment.BlockSize() && margins.IsEmpty() && 131 bool is_zero_height_box = !fragment.BlockSize() && margins.IsEmpty() &&
132 fragment.MarginStrut().IsEmpty(); 132 fragment.MarginStrut().IsEmpty();
133 // Create the current child's margin strut from its children's margin strut or 133 // Create the current child's margin strut from its children's margin strut or
134 // use margin strut from the the last non-empty child. 134 // use margin strut from the the last non-empty child.
135 NGMarginStrut curr_margin_strut = 135 NGMarginStrut curr_margin_strut =
136 is_zero_height_box ? prev_child_margin_strut_ : fragment.MarginStrut(); 136 is_zero_height_box ? prev_child_margin_strut_ : fragment.MarginStrut();
137 137
138 // Calculate borders and padding for the current child. 138 // Calculate borders and padding for the current child.
139 NGBoxStrut border_and_padding = 139 NGBoxStrut border_and_padding =
140 computeBorders(*current_child_->Style()) + 140 ComputeBorders(*current_child_->Style()) +
141 computePadding(space, *current_child_->Style()); 141 ComputePadding(space, *current_child_->Style());
142 142
143 // Collapse BLOCK-START margins if there is no padding or border between 143 // Collapse BLOCK-START margins if there is no padding or border between
144 // parent (current child) and its first in-flow child. 144 // parent (current child) and its first in-flow child.
145 if (border_and_padding.block_start) { 145 if (border_and_padding.block_start) {
146 curr_margin_strut.SetMarginBlockStart(margins.block_start); 146 curr_margin_strut.SetMarginBlockStart(margins.block_start);
147 } else { 147 } else {
148 curr_margin_strut.AppendMarginBlockStart(margins.block_start); 148 curr_margin_strut.AppendMarginBlockStart(margins.block_start);
149 } 149 }
150 150
151 // Collapse BLOCK-END margins if 151 // Collapse BLOCK-END margins if
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 193
194 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) { 194 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) {
195 if (!is_fragment_margin_strut_block_start_updated_) { 195 if (!is_fragment_margin_strut_block_start_updated_) {
196 builder_->SetMarginStrutBlockStart(from); 196 builder_->SetMarginStrutBlockStart(from);
197 is_fragment_margin_strut_block_start_updated_ = true; 197 is_fragment_margin_strut_block_start_updated_ = true;
198 } 198 }
199 builder_->SetMarginStrutBlockEnd(from); 199 builder_->SetMarginStrutBlockEnd(from);
200 } 200 }
201 201
202 } // namespace blink 202 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/ng/ng_box.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698