| 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" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 LayoutUnit max = resolveInlineLength(constraintSpace, maxLength, | 71 LayoutUnit max = resolveInlineLength(constraintSpace, maxLength, |
| 72 LengthResolveType::MaxSize); | 72 LengthResolveType::MaxSize); |
| 73 extent = std::min(extent, max); | 73 extent = std::min(extent, max); |
| 74 } | 74 } |
| 75 | 75 |
| 76 LayoutUnit min = resolveInlineLength(constraintSpace, style.logicalMinWidth(), | 76 LayoutUnit min = resolveInlineLength(constraintSpace, style.logicalMinWidth(), |
| 77 LengthResolveType::MinSize); | 77 LengthResolveType::MinSize); |
| 78 extent = std::max(extent, min); | 78 extent = std::max(extent, min); |
| 79 | 79 |
| 80 if (style.boxSizing() == BoxSizingContentBox) { | 80 if (style.boxSizing() == BoxSizingContentBox) { |
| 81 // TODO(layout-ng): Compute border/padding size and add it | 81 extent += computeBorderAndPaddingInlineStart(constraintSpace, style); |
| 82 extent += computeBorderAndPaddingInlineEnd(constraintSpace, style); |
| 82 } | 83 } |
| 83 | 84 |
| 84 return extent; | 85 return extent; |
| 85 } | 86 } |
| 86 | 87 |
| 87 LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace, | 88 LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace, |
| 88 const ComputedStyle& style, | 89 const ComputedStyle& style, |
| 89 LayoutUnit contentSize) { | 90 LayoutUnit contentSize) { |
| 90 if (constraintSpace.FixedBlockSize()) | 91 if (constraintSpace.FixedBlockSize()) |
| 91 return constraintSpace.ContainerSize().block_size; | 92 return constraintSpace.ContainerSize().block_size; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 103 LayoutUnit max = resolveBlockLength(constraintSpace, maxLength, contentSize, | 104 LayoutUnit max = resolveBlockLength(constraintSpace, maxLength, contentSize, |
| 104 LengthResolveType::MaxSize); | 105 LengthResolveType::MaxSize); |
| 105 extent = std::min(extent, max); | 106 extent = std::min(extent, max); |
| 106 } | 107 } |
| 107 | 108 |
| 108 LayoutUnit min = resolveBlockLength(constraintSpace, style.logicalMinHeight(), | 109 LayoutUnit min = resolveBlockLength(constraintSpace, style.logicalMinHeight(), |
| 109 contentSize, LengthResolveType::MinSize); | 110 contentSize, LengthResolveType::MinSize); |
| 110 extent = std::max(extent, min); | 111 extent = std::max(extent, min); |
| 111 | 112 |
| 112 if (style.boxSizing() == BoxSizingContentBox) { | 113 if (style.boxSizing() == BoxSizingContentBox) { |
| 113 // TODO(layout-ng): Compute border/padding size and add it | 114 extent += computeBorderAndPaddingBlockStart(constraintSpace, style); |
| 115 extent += computeBorderAndPaddingBlockEnd(constraintSpace, style); |
| 114 } | 116 } |
| 115 | 117 |
| 116 return extent; | 118 return extent; |
| 117 } | 119 } |
| 118 | 120 |
| 121 LayoutUnit computeBorderAndPaddingBlockStart( |
| 122 const NGConstraintSpace& constraintSpace, |
| 123 const ComputedStyle& style) { |
| 124 // Percentages on block-direction padding are resolved against the containing |
| 125 // block *inline size* - hence the call to resolveInlineLength(). |
| 126 LayoutUnit padding = |
| 127 resolveInlineLength(constraintSpace, style.paddingBefore(), |
| 128 LengthResolveType::MarginBorderPaddingSize); |
| 129 return padding + LayoutUnit(style.borderBeforeWidth()); |
| 130 } |
| 131 |
| 132 LayoutUnit computeBorderAndPaddingBlockEnd( |
| 133 const NGConstraintSpace& constraintSpace, |
| 134 const ComputedStyle& style) { |
| 135 // Percentages on block-direction padding are resolved against the containing |
| 136 // block *inline size* - hence the call to resolveInlineLength(). |
| 137 LayoutUnit padding = |
| 138 resolveInlineLength(constraintSpace, style.paddingAfter(), |
| 139 LengthResolveType::MarginBorderPaddingSize); |
| 140 return padding + LayoutUnit(style.borderAfterWidth()); |
| 141 } |
| 142 |
| 143 LayoutUnit computeBorderAndPaddingInlineStart( |
| 144 const NGConstraintSpace& constraintSpace, |
| 145 const ComputedStyle& style) { |
| 146 LayoutUnit padding = |
| 147 resolveInlineLength(constraintSpace, style.paddingStart(), |
| 148 LengthResolveType::MarginBorderPaddingSize); |
| 149 return padding + LayoutUnit(style.borderStartWidth()); |
| 150 } |
| 151 |
| 152 LayoutUnit computeBorderAndPaddingInlineEnd( |
| 153 const NGConstraintSpace& constraintSpace, |
| 154 const ComputedStyle& style) { |
| 155 LayoutUnit padding = |
| 156 resolveInlineLength(constraintSpace, style.paddingEnd(), |
| 157 LengthResolveType::MarginBorderPaddingSize); |
| 158 return padding + LayoutUnit(style.borderEndWidth()); |
| 159 } |
| 160 |
| 119 NGBoxStrut computeMargins(const NGConstraintSpace& constraintSpace, | 161 NGBoxStrut computeMargins(const NGConstraintSpace& constraintSpace, |
| 120 const ComputedStyle& style) { | 162 const ComputedStyle& style) { |
| 121 // Margins always get computed relative to the inline size: | 163 // Margins always get computed relative to the inline size: |
| 122 // https://www.w3.org/TR/CSS2/box.html#value-def-margin-width | 164 // https://www.w3.org/TR/CSS2/box.html#value-def-margin-width |
| 123 NGBoxStrut margins; | 165 NGBoxStrut margins; |
| 124 margins.inline_start = | 166 margins.inline_start = |
| 125 resolveInlineLength(constraintSpace, style.marginStart(), | 167 resolveInlineLength(constraintSpace, style.marginStart(), |
| 126 LengthResolveType::MarginBorderPaddingSize); | 168 LengthResolveType::MarginBorderPaddingSize); |
| 127 margins.inline_end = | 169 margins.inline_end = |
| 128 resolveInlineLength(constraintSpace, style.marginEnd(), | 170 resolveInlineLength(constraintSpace, style.marginEnd(), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 159 padding.block_start = | 201 padding.block_start = |
| 160 resolveInlineLength(constraintSpace, style.paddingBefore(), | 202 resolveInlineLength(constraintSpace, style.paddingBefore(), |
| 161 LengthResolveType::MarginBorderPaddingSize); | 203 LengthResolveType::MarginBorderPaddingSize); |
| 162 padding.block_end = | 204 padding.block_end = |
| 163 resolveInlineLength(constraintSpace, style.paddingAfter(), | 205 resolveInlineLength(constraintSpace, style.paddingAfter(), |
| 164 LengthResolveType::MarginBorderPaddingSize); | 206 LengthResolveType::MarginBorderPaddingSize); |
| 165 return padding; | 207 return padding; |
| 166 } | 208 } |
| 167 | 209 |
| 168 } // namespace blink | 210 } // namespace blink |
| OLD | NEW |