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

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

Issue 2346403002: [layoutng] Create correct constraint spaces for children (Closed)
Patch Set: fix assert failures Created 4 years, 3 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_length_utils.h" 5 #include "core/layout/ng/ng_length_utils.h"
6 6
7 #include "core/layout/ng/ng_constraint_space.h" 7 #include "core/layout/ng/ng_constraint_space.h"
8 #include "core/style/ComputedStyle.h" 8 #include "core/style/ComputedStyle.h"
9 #include "platform/LayoutUnit.h" 9 #include "platform/LayoutUnit.h"
10 #include "platform/Length.h" 10 #include "platform/Length.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // TODO(layout-ng): Handle min/max/fit-content 62 // TODO(layout-ng): Handle min/max/fit-content
63 DCHECK(!length.isMaxSizeNone()); 63 DCHECK(!length.isMaxSizeNone());
64 DCHECK_GE(constraintSpace.ContainerSize().inline_size, LayoutUnit()); 64 DCHECK_GE(constraintSpace.ContainerSize().inline_size, LayoutUnit());
65 65
66 if (type == LengthResolveType::MinSize && length.isAuto()) 66 if (type == LengthResolveType::MinSize && length.isAuto())
67 return LayoutUnit(); 67 return LayoutUnit();
68 68
69 if (type == LengthResolveType::MarginBorderPaddingSize && length.isAuto()) 69 if (type == LengthResolveType::MarginBorderPaddingSize && length.isAuto())
70 return LayoutUnit(); 70 return LayoutUnit();
71 71
72 // We don't need this when we're resolving margin/border/padding; skip
73 // computing it as an optimization and to simplify the code below.
74 NGBoxStrut border_and_padding;
75 if (type != LengthResolveType::MarginBorderPaddingSize) {
76 border_and_padding =
77 computeBorders(style) + computePadding(constraintSpace, style);
78 }
72 LayoutUnit container_size = constraintSpace.ContainerSize().inline_size; 79 LayoutUnit container_size = constraintSpace.ContainerSize().inline_size;
73 switch (length.type()) { 80 switch (length.type()) {
74 case Auto: 81 case Auto:
75 case FillAvailable: { 82 case FillAvailable: {
76 NGBoxStrut margins = 83 NGBoxStrut margins =
77 computeMargins(constraintSpace, style, 84 computeMargins(constraintSpace, style,
78 FromPlatformWritingMode(style.getWritingMode()), 85 FromPlatformWritingMode(style.getWritingMode()),
79 FromPlatformDirection(style.direction())); 86 FromPlatformDirection(style.direction()));
80 return container_size - margins.InlineSum(); 87 return std::max(border_and_padding.InlineSum(),
88 container_size - margins.InlineSum());
81 } 89 }
82 case Percent: 90 case Percent:
83 case Fixed: 91 case Fixed:
84 case Calculated: { 92 case Calculated: {
85 // TODO(layout-ng): adjust for border-box
86 LayoutUnit value = valueForLength(length, container_size); 93 LayoutUnit value = valueForLength(length, container_size);
87 if (style.boxSizing() == BoxSizingContentBox && 94 if (style.boxSizing() == BoxSizingContentBox) {
88 type != LengthResolveType::MarginBorderPaddingSize) {
89 NGBoxStrut border_and_padding =
90 computeBorders(style) + computePadding(constraintSpace, style);
91 value += border_and_padding.InlineSum(); 95 value += border_and_padding.InlineSum();
96 } else {
97 value = std::max(border_and_padding.InlineSum(), value);
92 } 98 }
93 return value; 99 return value;
94 } 100 }
95 case MinContent: 101 case MinContent:
96 case MaxContent: 102 case MaxContent:
97 case FitContent: 103 case FitContent:
98 // TODO(layout-ng): implement 104 // TODO(layout-ng): implement
99 return LayoutUnit(); 105 return border_and_padding.InlineSum();
100 case DeviceWidth: 106 case DeviceWidth:
101 case DeviceHeight: 107 case DeviceHeight:
102 case ExtendToZoom: 108 case ExtendToZoom:
103 NOTREACHED() << "These should only be used for viewport definitions"; 109 NOTREACHED() << "These should only be used for viewport definitions";
104 case MaxSizeNone: 110 case MaxSizeNone:
105 default: 111 default:
106 NOTREACHED(); 112 NOTREACHED();
107 return LayoutUnit(); 113 return border_and_padding.InlineSum();
108 } 114 }
109 } 115 }
110 116
111 LayoutUnit resolveBlockLength(const NGConstraintSpace& constraintSpace, 117 LayoutUnit resolveBlockLength(const NGConstraintSpace& constraintSpace,
112 const ComputedStyle& style, 118 const ComputedStyle& style,
113 const Length& length, 119 const Length& length,
114 LayoutUnit contentSize, 120 LayoutUnit contentSize,
115 LengthResolveType type) { 121 LengthResolveType type) {
116 DCHECK(!length.isMaxSizeNone()); 122 DCHECK(!length.isMaxSizeNone());
117 DCHECK(type != LengthResolveType::MarginBorderPaddingSize); 123 DCHECK(type != LengthResolveType::MarginBorderPaddingSize);
118 124
119 if (type == LengthResolveType::MinSize && length.isAuto()) 125 if (type == LengthResolveType::MinSize && length.isAuto())
120 return LayoutUnit(); 126 return LayoutUnit();
121 127
122 // Make sure that indefinite percentages resolve to NGSizeIndefinite, not to 128 // Make sure that indefinite percentages resolve to NGSizeIndefinite, not to
123 // a random negative number. 129 // a random negative number.
124 if (length.isPercentOrCalc() && 130 if (length.isPercentOrCalc() &&
125 constraintSpace.ContainerSize().block_size == NGSizeIndefinite) 131 constraintSpace.ContainerSize().block_size == NGSizeIndefinite)
126 return contentSize; 132 return contentSize;
127 133
134 // We don't need this when we're resolving margin/border/padding; skip
135 // computing it as an optimization and to simplify the code below.
136 NGBoxStrut border_and_padding;
137 if (type != LengthResolveType::MarginBorderPaddingSize) {
138 border_and_padding =
139 computeBorders(style) + computePadding(constraintSpace, style);
140 }
128 LayoutUnit container_size = constraintSpace.ContainerSize().block_size; 141 LayoutUnit container_size = constraintSpace.ContainerSize().block_size;
129 switch (length.type()) { 142 switch (length.type()) {
130 case FillAvailable: { 143 case FillAvailable: {
131 NGBoxStrut margins = 144 NGBoxStrut margins =
132 computeMargins(constraintSpace, style, 145 computeMargins(constraintSpace, style,
133 FromPlatformWritingMode(style.getWritingMode()), 146 FromPlatformWritingMode(style.getWritingMode()),
134 FromPlatformDirection(style.direction())); 147 FromPlatformDirection(style.direction()));
135 return container_size - margins.BlockSum(); 148 return std::max(border_and_padding.BlockSum(),
149 container_size - margins.BlockSum());
136 } 150 }
137 case Percent: 151 case Percent:
138 case Fixed: 152 case Fixed:
139 case Calculated: { 153 case Calculated: {
140 // TODO(layout-ng): adjust for border-box
141 LayoutUnit value = valueForLength(length, container_size); 154 LayoutUnit value = valueForLength(length, container_size);
142 if (style.boxSizing() == BoxSizingContentBox && 155 if (style.boxSizing() == BoxSizingContentBox) {
143 type != LengthResolveType::MarginBorderPaddingSize) {
144 NGBoxStrut border_and_padding =
145 computeBorders(style) + computePadding(constraintSpace, style);
146 value += border_and_padding.BlockSum(); 156 value += border_and_padding.BlockSum();
157 } else {
158 value = std::max(border_and_padding.BlockSum(), value);
147 } 159 }
148 return value; 160 return value;
149 } 161 }
150 case Auto: 162 case Auto:
151 case MinContent: 163 case MinContent:
152 case MaxContent: 164 case MaxContent:
153 case FitContent: 165 case FitContent:
166 // Due to how contentSize is calculated, it should always include border
167 // and padding.
168 if (contentSize != LayoutUnit(-1))
169 DCHECK_GE(contentSize, border_and_padding.BlockSum());
154 return contentSize; 170 return contentSize;
155 case DeviceWidth: 171 case DeviceWidth:
156 case DeviceHeight: 172 case DeviceHeight:
157 case ExtendToZoom: 173 case ExtendToZoom:
158 NOTREACHED() << "These should only be used for viewport definitions"; 174 NOTREACHED() << "These should only be used for viewport definitions";
159 case MaxSizeNone: 175 case MaxSizeNone:
160 default: 176 default:
161 NOTREACHED(); 177 NOTREACHED();
162 return LayoutUnit(); 178 return border_and_padding.BlockSum();
163 } 179 }
164 } 180 }
165 181
166 LayoutUnit computeInlineSizeForFragment( 182 LayoutUnit computeInlineSizeForFragment(
167 const NGConstraintSpace& constraintSpace, 183 const NGConstraintSpace& constraintSpace,
168 const ComputedStyle& style) { 184 const ComputedStyle& style) {
169 if (constraintSpace.FixedInlineSize()) 185 if (constraintSpace.FixedInlineSize())
170 return constraintSpace.ContainerSize().inline_size; 186 return constraintSpace.ContainerSize().inline_size;
171 187
172 LayoutUnit extent = 188 LayoutUnit extent =
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 padding.block_start = 277 padding.block_start =
262 resolveInlineLength(constraintSpace, style, style.paddingBefore(), 278 resolveInlineLength(constraintSpace, style, style.paddingBefore(),
263 LengthResolveType::MarginBorderPaddingSize); 279 LengthResolveType::MarginBorderPaddingSize);
264 padding.block_end = 280 padding.block_end =
265 resolveInlineLength(constraintSpace, style, style.paddingAfter(), 281 resolveInlineLength(constraintSpace, style, style.paddingAfter(),
266 LengthResolveType::MarginBorderPaddingSize); 282 LengthResolveType::MarginBorderPaddingSize);
267 return padding; 283 return padding;
268 } 284 }
269 285
270 } // namespace blink 286 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698