OLD | NEW |
---|---|
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" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 // TODO(layout-ng): | 13 // TODO(layout-ng): |
14 // - Handle border-box correctly | 14 // - Handle border-box correctly |
15 // - positioned and/or replaced calculations | 15 // - positioned and/or replaced calculations |
16 // - Handle margins for fill-available and width: auto | 16 // - Handle margins for fill-available and width: auto |
17 | 17 |
18 LayoutUnit resolveInlineLength(LengthResolveType type, | 18 LayoutUnit resolveInlineLength(const NGConstraintSpace& constraintSpace, |
19 const Length& length, | 19 const Length& length, |
20 const NGConstraintSpace& constraintSpace) { | 20 LengthResolveType type) { |
21 // TODO(layout-ng): Handle min/max/fit-content | |
21 DCHECK(!length.isMaxSizeNone()); | 22 DCHECK(!length.isMaxSizeNone()); |
23 | |
22 if (type == LengthResolveType::MinSize && length.isAuto()) | 24 if (type == LengthResolveType::MinSize && length.isAuto()) |
23 return LayoutUnit(); | 25 return LayoutUnit(); |
24 // TODO(layout-ng): Handle min/max/fit-content | 26 |
25 return valueForLength(length, constraintSpace.inlineContainerSize()); | 27 return valueForLength(length, constraintSpace.inlineContainerSize()); |
26 } | 28 } |
27 | 29 |
28 LayoutUnit resolveBlockLength(LengthResolveType type, | 30 LayoutUnit resolveBlockLength(const NGConstraintSpace& constraintSpace, |
29 const Length& length, | 31 const Length& length, |
30 const NGConstraintSpace& constraintSpace, | 32 LayoutUnit contentSize, |
31 LayoutUnit contentContribution) { | 33 LengthResolveType type) { |
32 DCHECK(!length.isMaxSizeNone()); | 34 DCHECK(!length.isMaxSizeNone()); |
35 | |
33 if (type == LengthResolveType::MinSize && length.isAuto()) | 36 if (type == LengthResolveType::MinSize && length.isAuto()) |
34 return LayoutUnit(); | 37 return LayoutUnit(); |
38 | |
35 if (length.isAuto()) | 39 if (length.isAuto()) |
36 return contentContribution; | 40 return contentSize; |
41 | |
37 if (length.isMinContent() || length.isMaxContent() || length.isFitContent()) | 42 if (length.isMinContent() || length.isMaxContent() || length.isFitContent()) |
38 return contentContribution; | 43 return contentSize; |
44 | |
39 return valueForLength(length, constraintSpace.blockContainerSize()); | 45 return valueForLength(length, constraintSpace.blockContainerSize()); |
40 } | 46 } |
41 | 47 |
42 LayoutUnit computeInlineSizeForFragment( | 48 LayoutUnit computeInlineSizeForFragment( |
43 const NGConstraintSpace& constraintSpace, | 49 const NGConstraintSpace& constraintSpace, |
44 const ComputedStyle& style) { | 50 const ComputedStyle& style) { |
45 LayoutUnit extent = resolveInlineLength( | 51 if (constraintSpace.fixedInlineSize()) |
46 LengthResolveType::ContentSize, style.logicalWidth(), constraintSpace); | 52 return constraintSpace.inlineContainerSize(); |
cbiesinger
2016/08/11 20:41:56
Thanks!
| |
53 | |
54 LayoutUnit extent = resolveInlineLength(constraintSpace, style.logicalWidth(), | |
55 LengthResolveType::ContentSize); | |
56 | |
47 Length maxLength = style.logicalMaxWidth(); | 57 Length maxLength = style.logicalMaxWidth(); |
48 if (!maxLength.isMaxSizeNone()) { | 58 if (!maxLength.isMaxSizeNone()) { |
49 LayoutUnit max = resolveInlineLength(LengthResolveType::MaxSize, maxLength, | 59 LayoutUnit max = resolveInlineLength(constraintSpace, maxLength, |
50 constraintSpace); | 60 LengthResolveType::MaxSize); |
51 extent = std::min(extent, max); | 61 extent = std::min(extent, max); |
52 } | 62 } |
53 LayoutUnit min = resolveInlineLength( | 63 |
54 LengthResolveType::MinSize, style.logicalMinWidth(), constraintSpace); | 64 LayoutUnit min = resolveInlineLength(constraintSpace, style.logicalMinWidth(), |
65 LengthResolveType::MinSize); | |
55 extent = std::max(extent, min); | 66 extent = std::max(extent, min); |
67 | |
56 if (style.boxSizing() == BoxSizingContentBox) { | 68 if (style.boxSizing() == BoxSizingContentBox) { |
57 // TODO(layout-ng): Compute border/padding size and add it | 69 // TODO(layout-ng): Compute border/padding size and add it |
58 } | 70 } |
71 | |
59 return extent; | 72 return extent; |
60 } | 73 } |
61 | 74 |
62 LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace, | 75 LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace, |
63 const ComputedStyle& style, | 76 const ComputedStyle& style, |
64 LayoutUnit contentContribution) { | 77 LayoutUnit contentSize) { |
78 if (constraintSpace.fixedBlockSize()) | |
79 return constraintSpace.blockContainerSize(); | |
80 | |
65 LayoutUnit extent = | 81 LayoutUnit extent = |
66 resolveBlockLength(LengthResolveType::ContentSize, style.logicalHeight(), | 82 resolveBlockLength(constraintSpace, style.logicalHeight(), contentSize, |
67 constraintSpace, contentContribution); | 83 LengthResolveType::ContentSize); |
68 Length maxLength = style.logicalMaxHeight(); | 84 Length maxLength = style.logicalMaxHeight(); |
85 | |
69 if (!maxLength.isMaxSizeNone()) { | 86 if (!maxLength.isMaxSizeNone()) { |
70 LayoutUnit max = resolveBlockLength(LengthResolveType::MaxSize, maxLength, | 87 LayoutUnit max = resolveBlockLength(constraintSpace, maxLength, contentSize, |
71 constraintSpace, contentContribution); | 88 LengthResolveType::MaxSize); |
72 extent = std::min(extent, max); | 89 extent = std::min(extent, max); |
73 } | 90 } |
74 LayoutUnit min = | 91 |
75 resolveBlockLength(LengthResolveType::MinSize, style.logicalMinHeight(), | 92 LayoutUnit min = resolveBlockLength(constraintSpace, style.logicalMinHeight(), |
76 constraintSpace, contentContribution); | 93 contentSize, LengthResolveType::MinSize); |
77 extent = std::max(extent, min); | 94 extent = std::max(extent, min); |
95 | |
78 if (style.boxSizing() == BoxSizingContentBox) { | 96 if (style.boxSizing() == BoxSizingContentBox) { |
79 // TODO(layout-ng): Compute border/padding size and add it | 97 // TODO(layout-ng): Compute border/padding size and add it |
80 } | 98 } |
99 | |
81 return extent; | 100 return extent; |
82 } | 101 } |
83 | 102 |
84 } // namespace blink | 103 } // namespace blink |
OLD | NEW |