OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/layout/ng/ng_length_utils.h" |
| 6 |
| 7 #include "core/layout/ng/ng_constraint_space.h" |
| 8 #include "core/style/ComputedStyle.h" |
| 9 #include "platform/LayoutUnit.h" |
| 10 #include "platform/Length.h" |
| 11 |
| 12 namespace blink { |
| 13 // TODO(layout-ng): |
| 14 // - Handle border-box correctly |
| 15 // - positioned and/or replaced calculations |
| 16 // - Handle margins for fill-available and width: auto |
| 17 |
| 18 LayoutUnit resolveInlineLength(LengthResolveType type, |
| 19 const Length& length, |
| 20 const NGConstraintSpace& constraintSpace) { |
| 21 DCHECK(!length.isMaxSizeNone()); |
| 22 if (type == LengthResolveType::MinSize && length.isAuto()) |
| 23 return LayoutUnit(); |
| 24 // TODO(layout-ng): Handle min/max/fit-content |
| 25 return valueForLength(length, constraintSpace.inlineContainerSize()); |
| 26 } |
| 27 |
| 28 LayoutUnit resolveBlockLength(LengthResolveType type, |
| 29 const Length& length, |
| 30 const NGConstraintSpace& constraintSpace, |
| 31 LayoutUnit contentContribution) { |
| 32 DCHECK(!length.isMaxSizeNone()); |
| 33 if (type == LengthResolveType::MinSize && length.isAuto()) |
| 34 return LayoutUnit(); |
| 35 if (length.isAuto()) |
| 36 return contentContribution; |
| 37 if (length.isMinContent() || length.isMaxContent() || length.isFitContent()) |
| 38 return contentContribution; |
| 39 return valueForLength(length, constraintSpace.blockContainerSize()); |
| 40 } |
| 41 |
| 42 LayoutUnit computeInlineSizeForFragment( |
| 43 const NGConstraintSpace& constraintSpace, |
| 44 const ComputedStyle& style) { |
| 45 LayoutUnit extent = resolveInlineLength( |
| 46 LengthResolveType::ContentSize, style.logicalWidth(), constraintSpace); |
| 47 Length maxLength = style.logicalMaxWidth(); |
| 48 if (!maxLength.isMaxSizeNone()) { |
| 49 LayoutUnit max = resolveInlineLength(LengthResolveType::MaxSize, maxLength, |
| 50 constraintSpace); |
| 51 extent = std::min(extent, max); |
| 52 } |
| 53 LayoutUnit min = resolveInlineLength( |
| 54 LengthResolveType::MinSize, style.logicalMinWidth(), constraintSpace); |
| 55 extent = std::max(extent, min); |
| 56 if (style.boxSizing() == BoxSizingContentBox) { |
| 57 // TODO(layout-ng): Compute border/padding size and add it |
| 58 } |
| 59 return extent; |
| 60 } |
| 61 |
| 62 LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace, |
| 63 const ComputedStyle& style, |
| 64 LayoutUnit contentContribution) { |
| 65 LayoutUnit extent = |
| 66 resolveBlockLength(LengthResolveType::ContentSize, style.logicalHeight(), |
| 67 constraintSpace, contentContribution); |
| 68 Length maxLength = style.logicalMaxHeight(); |
| 69 if (!maxLength.isMaxSizeNone()) { |
| 70 LayoutUnit max = resolveBlockLength(LengthResolveType::MaxSize, maxLength, |
| 71 constraintSpace, contentContribution); |
| 72 extent = std::min(extent, max); |
| 73 } |
| 74 LayoutUnit min = |
| 75 resolveBlockLength(LengthResolveType::MinSize, style.logicalMinHeight(), |
| 76 constraintSpace, contentContribution); |
| 77 extent = std::max(extent, min); |
| 78 if (style.boxSizing() == BoxSizingContentBox) { |
| 79 // TODO(layout-ng): Compute border/padding size and add it |
| 80 } |
| 81 return extent; |
| 82 } |
| 83 |
| 84 } // namespace blink |
OLD | NEW |