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

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

Issue 2489953006: Utility routines for ng_units (Closed)
Patch Set: Added missing CORE_EXPORT 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_units.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_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/layout/ng/ng_fragment.h" 8 #include "core/layout/ng/ng_fragment.h"
9 #include "core/style/ComputedStyle.h" 9 #include "core/style/ComputedStyle.h"
10 #include "platform/LayoutUnit.h" 10 #include "platform/LayoutUnit.h"
11 #include "platform/Length.h" 11 #include "platform/Length.h"
12 #include "wtf/Optional.h" 12 #include "wtf/Optional.h"
13 13
14 namespace blink { 14 namespace blink {
15 // TODO(layout-ng): 15 // TODO(layout-ng):
16 // - positioned and/or replaced calculations 16 // - positioned and/or replaced calculations
17 // - Take scrollbars into account 17 // - Take scrollbars into account
18 18
19 namespace {
20
21 // Converts physical dimensions to logical ones per
22 // https://drafts.csswg.org/css-writing-modes-3/#logical-to-physical
23 // For now it's only used to calculate abstract values for margins.
24 NGBoxStrut ToLogicalDimensions(const NGPhysicalBoxStrut& physical_dim,
25 const NGWritingMode writing_mode,
26 const TextDirection direction) {
27 bool is_ltr = direction == LTR;
28 NGBoxStrut logical_dim;
29 switch (writing_mode) {
30 case VerticalRightLeft:
31 case SidewaysRightLeft:
32 logical_dim = {is_ltr ? physical_dim.top : physical_dim.bottom,
33 is_ltr ? physical_dim.bottom : physical_dim.top,
34 physical_dim.right, physical_dim.left};
35 break;
36 case VerticalLeftRight:
37 logical_dim = {is_ltr ? physical_dim.top : physical_dim.bottom,
38 is_ltr ? physical_dim.bottom : physical_dim.top,
39 physical_dim.left, physical_dim.right};
40 break;
41 case SidewaysLeftRight:
42 logical_dim = {is_ltr ? physical_dim.bottom : physical_dim.top,
43 is_ltr ? physical_dim.top : physical_dim.bottom,
44 physical_dim.left, physical_dim.right};
45 break;
46 default:
47 NOTREACHED();
48 /* FALLTHROUGH */
49 case HorizontalTopBottom:
50 logical_dim = {is_ltr ? physical_dim.left : physical_dim.right,
51 is_ltr ? physical_dim.right : physical_dim.left,
52 physical_dim.top, physical_dim.bottom};
53 break;
54 }
55 return logical_dim;
56 }
57
58 } // namespace
59
60 bool NeedMinAndMaxContentSizes(const ComputedStyle& style) { 19 bool NeedMinAndMaxContentSizes(const ComputedStyle& style) {
61 // TODO(layout-ng): In the future we may pass a shrink-to-fit flag through the 20 // TODO(layout-ng): In the future we may pass a shrink-to-fit flag through the
62 // constraint space; if so, this function needs to take a constraint space 21 // constraint space; if so, this function needs to take a constraint space
63 // as well to take that into account. 22 // as well to take that into account.
64 // This check is technically too broad (fill-available does not need intrinsic 23 // This check is technically too broad (fill-available does not need intrinsic
65 // size computation) but that's a rare case and only affects performance, not 24 // size computation) but that's a rare case and only affects performance, not
66 // correctness. 25 // correctness.
67 return style.logicalWidth().isIntrinsic() || 26 return style.logicalWidth().isIntrinsic() ||
68 style.logicalMinWidth().isIntrinsic() || 27 style.logicalMinWidth().isIntrinsic() ||
69 style.logicalMaxWidth().isIntrinsic(); 28 style.logicalMaxWidth().isIntrinsic();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // If the available space is infinite, fit-content resolves to 86 // If the available space is infinite, fit-content resolves to
128 // max-content. See css-sizing section 2.1. 87 // max-content. See css-sizing section 2.1.
129 value = min_and_max->max_content; 88 value = min_and_max->max_content;
130 } else { 89 } else {
131 NGBoxStrut margins = ComputeMargins( 90 NGBoxStrut margins = ComputeMargins(
132 constraintSpace, style, 91 constraintSpace, style,
133 FromPlatformWritingMode(style.getWritingMode()), style.direction()); 92 FromPlatformWritingMode(style.getWritingMode()), style.direction());
134 LayoutUnit fill_available = 93 LayoutUnit fill_available =
135 std::max(LayoutUnit(), available_size - margins.InlineSum() - 94 std::max(LayoutUnit(), available_size - margins.InlineSum() -
136 border_and_padding.InlineSum()); 95 border_and_padding.InlineSum());
137 value = std::min(min_and_max->max_content, 96 value = min_and_max->ShrinkToFit(fill_available);
138 std::max(min_and_max->min_content, fill_available));
139 } 97 }
140 return value + border_and_padding.InlineSum(); 98 return value + border_and_padding.InlineSum();
141 } 99 }
142 case DeviceWidth: 100 case DeviceWidth:
143 case DeviceHeight: 101 case DeviceHeight:
144 case ExtendToZoom: 102 case ExtendToZoom:
145 NOTREACHED() << "These should only be used for viewport definitions"; 103 NOTREACHED() << "These should only be used for viewport definitions";
146 case MaxSizeNone: 104 case MaxSizeNone:
147 default: 105 default:
148 NOTREACHED(); 106 NOTREACHED();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 LengthResolveType::MarginBorderPaddingSize); 242 LengthResolveType::MarginBorderPaddingSize);
285 physical_dim.right = ResolveInlineLength( 243 physical_dim.right = ResolveInlineLength(
286 constraintSpace, style, empty_sizes, style.marginRight(), 244 constraintSpace, style, empty_sizes, style.marginRight(),
287 LengthResolveType::MarginBorderPaddingSize); 245 LengthResolveType::MarginBorderPaddingSize);
288 physical_dim.top = ResolveInlineLength( 246 physical_dim.top = ResolveInlineLength(
289 constraintSpace, style, empty_sizes, style.marginTop(), 247 constraintSpace, style, empty_sizes, style.marginTop(),
290 LengthResolveType::MarginBorderPaddingSize); 248 LengthResolveType::MarginBorderPaddingSize);
291 physical_dim.bottom = ResolveInlineLength( 249 physical_dim.bottom = ResolveInlineLength(
292 constraintSpace, style, empty_sizes, style.marginBottom(), 250 constraintSpace, style, empty_sizes, style.marginBottom(),
293 LengthResolveType::MarginBorderPaddingSize); 251 LengthResolveType::MarginBorderPaddingSize);
294 return ToLogicalDimensions(physical_dim, writing_mode, direction); 252 return physical_dim.ConvertToLogical(writing_mode, direction);
295 } 253 }
296 254
297 NGBoxStrut ComputeBorders(const ComputedStyle& style) { 255 NGBoxStrut ComputeBorders(const ComputedStyle& style) {
298 NGBoxStrut borders; 256 NGBoxStrut borders;
299 borders.inline_start = LayoutUnit(style.borderStartWidth()); 257 borders.inline_start = LayoutUnit(style.borderStartWidth());
300 borders.inline_end = LayoutUnit(style.borderEndWidth()); 258 borders.inline_end = LayoutUnit(style.borderEndWidth());
301 borders.block_start = LayoutUnit(style.borderBeforeWidth()); 259 borders.block_start = LayoutUnit(style.borderBeforeWidth());
302 borders.block_end = LayoutUnit(style.borderAfterWidth()); 260 borders.block_end = LayoutUnit(style.borderAfterWidth());
303 return borders; 261 return borders;
304 } 262 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 margins->inline_start = available_space / 2; 297 margins->inline_start = available_space / 2;
340 margins->inline_end = available_space - margins->inline_start; 298 margins->inline_end = available_space - margins->inline_start;
341 } else if (style.marginStart().isAuto()) { 299 } else if (style.marginStart().isAuto()) {
342 margins->inline_start = available_space; 300 margins->inline_start = available_space;
343 } else if (style.marginEnd().isAuto()) { 301 } else if (style.marginEnd().isAuto()) {
344 margins->inline_end = available_space; 302 margins->inline_end = available_space;
345 } 303 }
346 } 304 }
347 305
348 } // namespace blink 306 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/ng/ng_units.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698