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

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

Issue 2274593002: [layoutng] Correctly resolve indefinite percentages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile error... 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/ng/ng_length_utils_test.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_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_margin_strut.h" 8 #include "core/layout/ng/ng_margin_strut.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 12
13 namespace blink { 13 namespace blink {
14 // TODO(layout-ng): 14 // TODO(layout-ng):
15 // - Handle border-box correctly 15 // - Handle border-box correctly
16 // - positioned and/or replaced calculations 16 // - positioned and/or replaced calculations
17 // - Handle margins for fill-available and width: auto 17 // - Handle margins for fill-available and width: auto
18 18
19 LayoutUnit resolveInlineLength(const NGConstraintSpace& constraintSpace, 19 LayoutUnit resolveInlineLength(const NGConstraintSpace& constraintSpace,
20 const Length& length, 20 const Length& length,
21 LengthResolveType type) { 21 LengthResolveType type) {
22 // TODO(layout-ng): Handle min/max/fit-content 22 // TODO(layout-ng): Handle min/max/fit-content
23 DCHECK(!length.isMaxSizeNone()); 23 DCHECK(!length.isMaxSizeNone());
24 DCHECK_NE(constraintSpace.ContainerSize().inlineSize, LayoutUnit(-1));
eae 2016/08/23 16:50:56 Can the length ever go negative? If not change thi
cbiesinger 2016/08/23 19:37:18 Done. I don't think size can ever go negative.
24 25
25 if (type == LengthResolveType::MinSize && length.isAuto()) 26 if (type == LengthResolveType::MinSize && length.isAuto())
26 return LayoutUnit(); 27 return LayoutUnit();
27 28
28 if (type == LengthResolveType::MarginSize && length.isAuto()) 29 if (type == LengthResolveType::MarginSize && length.isAuto())
29 return LayoutUnit(); 30 return LayoutUnit();
30 31
31 return valueForLength(length, constraintSpace.ContainerSize().inlineSize); 32 return valueForLength(length, constraintSpace.ContainerSize().inlineSize);
32 } 33 }
33 34
34 LayoutUnit resolveBlockLength(const NGConstraintSpace& constraintSpace, 35 LayoutUnit resolveBlockLength(const NGConstraintSpace& constraintSpace,
35 const Length& length, 36 const Length& length,
36 LayoutUnit contentSize, 37 LayoutUnit contentSize,
37 LengthResolveType type) { 38 LengthResolveType type) {
38 DCHECK(!length.isMaxSizeNone()); 39 DCHECK(!length.isMaxSizeNone());
39 DCHECK(type != LengthResolveType::MarginSize); 40 DCHECK(type != LengthResolveType::MarginSize);
40 41
41 if (type == LengthResolveType::MinSize && length.isAuto()) 42 if (type == LengthResolveType::MinSize && length.isAuto())
42 return LayoutUnit(); 43 return LayoutUnit();
43 44
44 if (length.isAuto()) 45 if (length.isAuto())
45 return contentSize; 46 return contentSize;
46 47
47 if (length.isMinContent() || length.isMaxContent() || length.isFitContent()) 48 if (length.isMinContent() || length.isMaxContent() || length.isFitContent())
48 return contentSize; 49 return contentSize;
49 50
51 // Make sure that indefinite percentages resolve to -1, not to a random
52 // negative number.
53 if (length.hasPercent() &&
54 constraintSpace.ContainerSize().blockSize == LayoutUnit(-1))
eae 2016/08/23 16:50:57 We might want to use a constant for infinite to im
cbiesinger 2016/08/23 19:37:18 OK. Adding NGSizeIndefinite. Using a #define to av
55 return contentSize;
56
50 return valueForLength(length, constraintSpace.ContainerSize().blockSize); 57 return valueForLength(length, constraintSpace.ContainerSize().blockSize);
51 } 58 }
52 59
53 LayoutUnit computeInlineSizeForFragment( 60 LayoutUnit computeInlineSizeForFragment(
54 const NGConstraintSpace& constraintSpace, 61 const NGConstraintSpace& constraintSpace,
55 const ComputedStyle& style) { 62 const ComputedStyle& style) {
56 if (constraintSpace.fixedInlineSize()) 63 if (constraintSpace.fixedInlineSize())
57 return constraintSpace.ContainerSize().inlineSize; 64 return constraintSpace.ContainerSize().inlineSize;
58 65
59 LayoutUnit extent = resolveInlineLength(constraintSpace, style.logicalWidth(), 66 LayoutUnit extent = resolveInlineLength(constraintSpace, style.logicalWidth(),
(...skipping 19 matching lines...) Expand all
79 86
80 LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace, 87 LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace,
81 const ComputedStyle& style, 88 const ComputedStyle& style,
82 LayoutUnit contentSize) { 89 LayoutUnit contentSize) {
83 if (constraintSpace.fixedBlockSize()) 90 if (constraintSpace.fixedBlockSize())
84 return constraintSpace.ContainerSize().blockSize; 91 return constraintSpace.ContainerSize().blockSize;
85 92
86 LayoutUnit extent = 93 LayoutUnit extent =
87 resolveBlockLength(constraintSpace, style.logicalHeight(), contentSize, 94 resolveBlockLength(constraintSpace, style.logicalHeight(), contentSize,
88 LengthResolveType::ContentSize); 95 LengthResolveType::ContentSize);
96 if (extent == LayoutUnit(-1)) {
97 DCHECK_EQ(contentSize, LayoutUnit(-1));
98 return extent;
99 }
100
89 Length maxLength = style.logicalMaxHeight(); 101 Length maxLength = style.logicalMaxHeight();
90
91 if (!maxLength.isMaxSizeNone()) { 102 if (!maxLength.isMaxSizeNone()) {
92 LayoutUnit max = resolveBlockLength(constraintSpace, maxLength, contentSize, 103 LayoutUnit max = resolveBlockLength(constraintSpace, maxLength, contentSize,
93 LengthResolveType::MaxSize); 104 LengthResolveType::MaxSize);
94 extent = std::min(extent, max); 105 extent = std::min(extent, max);
95 } 106 }
96 107
97 LayoutUnit min = resolveBlockLength(constraintSpace, style.logicalMinHeight(), 108 LayoutUnit min = resolveBlockLength(constraintSpace, style.logicalMinHeight(),
98 contentSize, LengthResolveType::MinSize); 109 contentSize, LengthResolveType::MinSize);
99 extent = std::max(extent, min); 110 extent = std::max(extent, min);
100 111
(...skipping 14 matching lines...) Expand all
115 margins.inlineEnd = resolveInlineLength(constraintSpace, style.marginEnd(), 126 margins.inlineEnd = resolveInlineLength(constraintSpace, style.marginEnd(),
116 LengthResolveType::MarginSize); 127 LengthResolveType::MarginSize);
117 margins.blockStart = resolveInlineLength( 128 margins.blockStart = resolveInlineLength(
118 constraintSpace, style.marginBefore(), LengthResolveType::MarginSize); 129 constraintSpace, style.marginBefore(), LengthResolveType::MarginSize);
119 margins.blockEnd = resolveInlineLength(constraintSpace, style.marginAfter(), 130 margins.blockEnd = resolveInlineLength(constraintSpace, style.marginAfter(),
120 LengthResolveType::MarginSize); 131 LengthResolveType::MarginSize);
121 return margins; 132 return margins;
122 } 133 }
123 134
124 } // namespace blink 135 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/ng/ng_length_utils_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698