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_units.h" | 5 #include "core/layout/ng/ng_units.h" |
6 | 6 |
7 #include "core/layout/ng/ng_writing_mode.h" | 7 #include "core/layout/ng/ng_writing_mode.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
| 11 LayoutUnit MinAndMaxContentSizes::ShrinkToFit(LayoutUnit available_size) const { |
| 12 return std::min(max_content, std::max(min_content, available_size)); |
| 13 } |
| 14 |
11 NGPhysicalSize NGLogicalSize::ConvertToPhysical(NGWritingMode mode) const { | 15 NGPhysicalSize NGLogicalSize::ConvertToPhysical(NGWritingMode mode) const { |
12 return mode == HorizontalTopBottom ? NGPhysicalSize(inline_size, block_size) | 16 return mode == HorizontalTopBottom ? NGPhysicalSize(inline_size, block_size) |
13 : NGPhysicalSize(block_size, inline_size); | 17 : NGPhysicalSize(block_size, inline_size); |
14 } | 18 } |
15 | 19 |
16 bool NGLogicalSize::operator==(const NGLogicalSize& other) const { | 20 bool NGLogicalSize::operator==(const NGLogicalSize& other) const { |
17 return std::tie(other.inline_size, other.block_size) == | 21 return std::tie(other.inline_size, other.block_size) == |
18 std::tie(inline_size, block_size); | 22 std::tie(inline_size, block_size); |
19 } | 23 } |
20 | 24 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 bool NGBoxStrut::IsEmpty() const { | 136 bool NGBoxStrut::IsEmpty() const { |
133 return *this == NGBoxStrut(); | 137 return *this == NGBoxStrut(); |
134 } | 138 } |
135 | 139 |
136 bool NGBoxStrut::operator==(const NGBoxStrut& other) const { | 140 bool NGBoxStrut::operator==(const NGBoxStrut& other) const { |
137 return std::tie(other.inline_start, other.inline_end, other.block_start, | 141 return std::tie(other.inline_start, other.inline_end, other.block_start, |
138 other.block_end) == | 142 other.block_end) == |
139 std::tie(inline_start, inline_end, block_start, block_end); | 143 std::tie(inline_start, inline_end, block_start, block_end); |
140 } | 144 } |
141 | 145 |
| 146 // Converts physical dimensions to logical ones per |
| 147 // https://drafts.csswg.org/css-writing-modes-3/#logical-to-physical |
| 148 NGBoxStrut NGPhysicalBoxStrut::ConvertToLogical(NGWritingMode writing_mode, |
| 149 TextDirection direction) const { |
| 150 NGBoxStrut strut; |
| 151 switch (writing_mode) { |
| 152 case HorizontalTopBottom: |
| 153 strut = {left, right, top, bottom}; |
| 154 break; |
| 155 case VerticalRightLeft: |
| 156 case SidewaysRightLeft: |
| 157 strut = {top, bottom, right, left}; |
| 158 break; |
| 159 case VerticalLeftRight: |
| 160 strut = {top, bottom, left, right}; |
| 161 break; |
| 162 case SidewaysLeftRight: |
| 163 strut = {bottom, top, left, right}; |
| 164 break; |
| 165 } |
| 166 if (direction == RTL) |
| 167 std::swap(strut.inline_start, strut.inline_end); |
| 168 return strut; |
| 169 } |
| 170 |
142 LayoutUnit NGMarginStrut::BlockEndSum() const { | 171 LayoutUnit NGMarginStrut::BlockEndSum() const { |
143 return margin_block_end + negative_margin_block_end; | 172 return margin_block_end + negative_margin_block_end; |
144 } | 173 } |
145 | 174 |
146 void NGMarginStrut::AppendMarginBlockStart(const LayoutUnit& value) { | 175 void NGMarginStrut::AppendMarginBlockStart(const LayoutUnit& value) { |
147 if (value < 0) { | 176 if (value < 0) { |
148 negative_margin_block_start = | 177 negative_margin_block_start = |
149 -std::max(value.abs(), negative_margin_block_start.abs()); | 178 -std::max(value.abs(), negative_margin_block_start.abs()); |
150 } else { | 179 } else { |
151 margin_block_start = std::max(value, margin_block_start); | 180 margin_block_start = std::max(value, margin_block_start); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 219 |
191 bool NGMarginStrut::operator==(const NGMarginStrut& other) const { | 220 bool NGMarginStrut::operator==(const NGMarginStrut& other) const { |
192 return std::tie(other.margin_block_start, other.margin_block_end, | 221 return std::tie(other.margin_block_start, other.margin_block_end, |
193 other.negative_margin_block_start, | 222 other.negative_margin_block_start, |
194 other.negative_margin_block_end) == | 223 other.negative_margin_block_end) == |
195 std::tie(margin_block_start, margin_block_end, | 224 std::tie(margin_block_start, margin_block_end, |
196 negative_margin_block_start, negative_margin_block_end); | 225 negative_margin_block_start, negative_margin_block_end); |
197 } | 226 } |
198 | 227 |
199 } // namespace blink | 228 } // namespace blink |
OLD | NEW |