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