| 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 #ifndef NGUnits_h | 5 #ifndef NGUnits_h |
| 6 #define NGUnits_h | 6 #define NGUnits_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/layout/ng/ng_direction.h" | 9 #include "core/layout/ng/ng_direction.h" |
| 10 #include "core/layout/ng/ng_writing_mode.h" | 10 #include "core/layout/ng/ng_writing_mode.h" |
| 11 #include "platform/LayoutUnit.h" | 11 #include "platform/LayoutUnit.h" |
| 12 #include "wtf/text/WTFString.h" | 12 #include "wtf/text/WTFString.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 class LayoutUnit; | 16 class LayoutUnit; |
| 17 struct NGPhysicalOffset; | 17 struct NGPhysicalOffset; |
| 18 struct NGPhysicalSize; | 18 struct NGPhysicalSize; |
| 19 | 19 |
| 20 struct NGLogicalSize { | 20 struct NGLogicalSize { |
| 21 NGLogicalSize() {} | 21 NGLogicalSize() {} |
| 22 NGLogicalSize(LayoutUnit inline_size, LayoutUnit block_size) | 22 NGLogicalSize(LayoutUnit inline_size, LayoutUnit block_size) |
| 23 : inline_size(inline_size), block_size(block_size) {} | 23 : inline_size(inline_size), block_size(block_size) {} |
| 24 | 24 |
| 25 LayoutUnit inline_size; | 25 LayoutUnit inline_size; |
| 26 LayoutUnit block_size; | 26 LayoutUnit block_size; |
| 27 | 27 |
| 28 NGPhysicalSize ConvertToPhysical(NGWritingMode mode) const; | 28 NGPhysicalSize ConvertToPhysical(NGWritingMode mode) const; |
| 29 bool operator==(const NGLogicalSize& other) const; | 29 bool operator==(const NGLogicalSize& other) const; |
| 30 | |
| 31 bool IsEmpty() const { | |
| 32 return inline_size == LayoutUnit() || block_size == LayoutUnit(); | |
| 33 } | |
| 34 }; | 30 }; |
| 35 | 31 |
| 36 // NGLogicalOffset is the position of a rect (typically a fragment) relative to | 32 // NGLogicalOffset is the position of a rect (typically a fragment) relative to |
| 37 // its parent rect in the logical coordinate system. | 33 // its parent rect in the logical coordinate system. |
| 38 struct NGLogicalOffset { | 34 struct NGLogicalOffset { |
| 39 NGLogicalOffset() {} | 35 NGLogicalOffset() {} |
| 40 NGLogicalOffset(LayoutUnit inline_offset, LayoutUnit block_offset) | 36 NGLogicalOffset(LayoutUnit inline_offset, LayoutUnit block_offset) |
| 41 : inline_offset(inline_offset), block_offset(block_offset) {} | 37 : inline_offset(inline_offset), block_offset(block_offset) {} |
| 42 | 38 |
| 43 LayoutUnit inline_offset; | 39 LayoutUnit inline_offset; |
| 44 LayoutUnit block_offset; | 40 LayoutUnit block_offset; |
| 45 | 41 |
| 46 // Converts a logical offset to a physical offset. See: | 42 // Converts a logical offset to a physical offset. See: |
| 47 // https://drafts.csswg.org/css-writing-modes-3/#logical-to-physical | 43 // https://drafts.csswg.org/css-writing-modes-3/#logical-to-physical |
| 48 // @param container_size the size of the rect (typically a fragment). | 44 // @param container_size the size of the rect (typically a fragment). |
| 49 // @param inner_size the size of the inner rect (typically a child fragment). | 45 // @param inner_size the size of the inner rect (typically a child fragment). |
| 50 CORE_EXPORT NGPhysicalOffset | 46 CORE_EXPORT NGPhysicalOffset |
| 51 ConvertToPhysical(NGWritingMode mode, | 47 ConvertToPhysical(NGWritingMode mode, |
| 52 NGDirection direction, | 48 NGDirection direction, |
| 53 NGPhysicalSize container_size, | 49 NGPhysicalSize container_size, |
| 54 NGPhysicalSize inner_size) const; | 50 NGPhysicalSize inner_size) const; |
| 55 bool operator==(const NGLogicalOffset& other) const; | 51 bool operator==(const NGLogicalOffset& other) const; |
| 56 | 52 |
| 57 NGLogicalOffset operator+(const NGLogicalOffset& other) const; | 53 NGLogicalOffset operator+(const NGLogicalOffset& other) const; |
| 58 | 54 |
| 59 NGLogicalOffset& operator+=(const NGLogicalOffset& other); | 55 NGLogicalOffset& operator+=(const NGLogicalOffset& other); |
| 60 | |
| 61 bool operator>(const NGLogicalOffset& other) const; | |
| 62 bool operator>=(const NGLogicalOffset& other) const; | |
| 63 | |
| 64 bool operator<(const NGLogicalOffset& other) const; | |
| 65 bool operator<=(const NGLogicalOffset& other) const; | |
| 66 | |
| 67 String ToString() const; | |
| 68 }; | 56 }; |
| 69 | 57 |
| 70 CORE_EXPORT inline std::ostream& operator<<(std::ostream& os, | |
| 71 const NGLogicalOffset& value) { | |
| 72 return os << value.ToString(); | |
| 73 } | |
| 74 | |
| 75 // NGPhysicalOffset is the position of a rect (typically a fragment) relative to | 58 // NGPhysicalOffset is the position of a rect (typically a fragment) relative to |
| 76 // its parent rect in the physical coordinate system. | 59 // its parent rect in the physical coordinate system. |
| 77 struct NGPhysicalOffset { | 60 struct NGPhysicalOffset { |
| 78 NGPhysicalOffset() {} | 61 NGPhysicalOffset() {} |
| 79 NGPhysicalOffset(LayoutUnit left, LayoutUnit top) : left(left), top(top) {} | 62 NGPhysicalOffset(LayoutUnit left, LayoutUnit top) : left(left), top(top) {} |
| 80 | 63 |
| 81 LayoutUnit left; | 64 LayoutUnit left; |
| 82 LayoutUnit top; | 65 LayoutUnit top; |
| 83 }; | 66 }; |
| 84 | 67 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 213 |
| 231 // Struct to represent a simple edge that has start and end. | 214 // Struct to represent a simple edge that has start and end. |
| 232 struct NGEdge { | 215 struct NGEdge { |
| 233 LayoutUnit start; | 216 LayoutUnit start; |
| 234 LayoutUnit end; | 217 LayoutUnit end; |
| 235 }; | 218 }; |
| 236 | 219 |
| 237 } // namespace blink | 220 } // namespace blink |
| 238 | 221 |
| 239 #endif // NGUnits_h | 222 #endif // NGUnits_h |
| OLD | NEW |