| 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_writing_mode.h" | 9 #include "core/layout/ng/ng_writing_mode.h" |
| 10 #include "platform/LayoutUnit.h" | 10 #include "platform/LayoutUnit.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 LayoutUnit inline_size; | 38 LayoutUnit inline_size; |
| 39 LayoutUnit block_size; | 39 LayoutUnit block_size; |
| 40 | 40 |
| 41 NGPhysicalSize ConvertToPhysical(NGWritingMode mode) const; | 41 NGPhysicalSize ConvertToPhysical(NGWritingMode mode) const; |
| 42 bool operator==(const NGLogicalSize& other) const; | 42 bool operator==(const NGLogicalSize& other) const; |
| 43 | 43 |
| 44 bool IsEmpty() const { | 44 bool IsEmpty() const { |
| 45 return inline_size == LayoutUnit() || block_size == LayoutUnit(); | 45 return inline_size == LayoutUnit() || block_size == LayoutUnit(); |
| 46 } | 46 } |
| 47 |
| 48 private: |
| 49 friend class NGBlockLayoutAlgorithmTest; |
| 50 // Used in tests. |
| 51 NGLogicalSize(int inline_size, int block_size) |
| 52 : inline_size(LayoutUnit(inline_size)), |
| 53 block_size(LayoutUnit(block_size)) {} |
| 47 }; | 54 }; |
| 48 | 55 |
| 49 inline std::ostream& operator<<(std::ostream& stream, | 56 inline std::ostream& operator<<(std::ostream& stream, |
| 50 const NGLogicalSize& value) { | 57 const NGLogicalSize& value) { |
| 51 return stream << value.inline_size << "x" << value.block_size; | 58 return stream << value.inline_size << "x" << value.block_size; |
| 52 } | 59 } |
| 53 | 60 |
| 54 // NGLogicalOffset is the position of a rect (typically a fragment) relative to | 61 // NGLogicalOffset is the position of a rect (typically a fragment) relative to |
| 55 // its parent rect in the logical coordinate system. | 62 // its parent rect in the logical coordinate system. |
| 56 struct NGLogicalOffset { | 63 struct NGLogicalOffset { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 70 // @param inner_size the size of the inner rect (typically a child fragment). | 77 // @param inner_size the size of the inner rect (typically a child fragment). |
| 71 CORE_EXPORT NGPhysicalOffset | 78 CORE_EXPORT NGPhysicalOffset |
| 72 ConvertToPhysical(NGWritingMode, | 79 ConvertToPhysical(NGWritingMode, |
| 73 TextDirection, | 80 TextDirection, |
| 74 NGPhysicalSize outer_size, | 81 NGPhysicalSize outer_size, |
| 75 NGPhysicalSize inner_size) const; | 82 NGPhysicalSize inner_size) const; |
| 76 | 83 |
| 77 bool operator==(const NGLogicalOffset& other) const; | 84 bool operator==(const NGLogicalOffset& other) const; |
| 78 | 85 |
| 79 NGLogicalOffset operator+(const NGLogicalOffset& other) const; | 86 NGLogicalOffset operator+(const NGLogicalOffset& other) const; |
| 87 NGLogicalOffset& operator+=(const NGLogicalOffset& other); |
| 80 | 88 |
| 81 NGLogicalOffset& operator+=(const NGLogicalOffset& other); | 89 NGLogicalOffset operator-(const NGLogicalOffset& other) const; |
| 90 NGLogicalOffset& operator-=(const NGLogicalOffset& other); |
| 82 | 91 |
| 83 bool operator>(const NGLogicalOffset& other) const; | 92 bool operator>(const NGLogicalOffset& other) const; |
| 84 bool operator>=(const NGLogicalOffset& other) const; | 93 bool operator>=(const NGLogicalOffset& other) const; |
| 85 | 94 |
| 86 bool operator<(const NGLogicalOffset& other) const; | 95 bool operator<(const NGLogicalOffset& other) const; |
| 87 bool operator<=(const NGLogicalOffset& other) const; | 96 bool operator<=(const NGLogicalOffset& other) const; |
| 88 | 97 |
| 89 String ToString() const; | 98 String ToString() const; |
| 99 |
| 100 private: |
| 101 friend class NGBlockLayoutAlgorithmTest; |
| 102 // Used in tests. |
| 103 NGLogicalOffset(int inline_offset, int block_offset) |
| 104 : inline_offset(LayoutUnit(inline_offset)), |
| 105 block_offset(LayoutUnit(block_offset)) {} |
| 90 }; | 106 }; |
| 91 | 107 |
| 92 CORE_EXPORT inline std::ostream& operator<<(std::ostream& os, | 108 CORE_EXPORT inline std::ostream& operator<<(std::ostream& os, |
| 93 const NGLogicalOffset& value) { | 109 const NGLogicalOffset& value) { |
| 94 return os << value.ToString(); | 110 return os << value.ToString(); |
| 95 } | 111 } |
| 96 | 112 |
| 97 // NGPhysicalOffset is the position of a rect (typically a fragment) relative to | 113 // NGPhysicalOffset is the position of a rect (typically a fragment) relative to |
| 98 // its parent rect in the physical coordinate system. | 114 // its parent rect in the physical coordinate system. |
| 99 struct NGPhysicalOffset { | 115 struct NGPhysicalOffset { |
| 100 NGPhysicalOffset() {} | 116 NGPhysicalOffset() {} |
| 101 NGPhysicalOffset(LayoutUnit left, LayoutUnit top) : left(left), top(top) {} | 117 NGPhysicalOffset(LayoutUnit left, LayoutUnit top) : left(left), top(top) {} |
| 102 | 118 |
| 103 LayoutUnit left; | 119 LayoutUnit left; |
| 104 LayoutUnit top; | 120 LayoutUnit top; |
| 105 | 121 |
| 106 NGPhysicalOffset operator+(const NGPhysicalOffset& other) const; | 122 NGPhysicalOffset operator+(const NGPhysicalOffset& other) const; |
| 107 NGPhysicalOffset& operator+=(const NGPhysicalOffset& other); | 123 NGPhysicalOffset& operator+=(const NGPhysicalOffset& other); |
| 124 |
| 108 NGPhysicalOffset operator-(const NGPhysicalOffset& other) const; | 125 NGPhysicalOffset operator-(const NGPhysicalOffset& other) const; |
| 109 NGPhysicalOffset& operator-=(const NGPhysicalOffset& other); | 126 NGPhysicalOffset& operator-=(const NGPhysicalOffset& other); |
| 127 |
| 128 String ToString() const { |
| 129 return String::format("%dx%d", left.toInt(), top.toInt()); |
| 130 } |
| 110 }; | 131 }; |
| 111 | 132 |
| 112 struct NGPhysicalSize { | 133 struct NGPhysicalSize { |
| 113 NGPhysicalSize() {} | 134 NGPhysicalSize() {} |
| 114 NGPhysicalSize(LayoutUnit width, LayoutUnit height) | 135 NGPhysicalSize(LayoutUnit width, LayoutUnit height) |
| 115 : width(width), height(height) {} | 136 : width(width), height(height) {} |
| 116 | 137 |
| 117 LayoutUnit width; | 138 LayoutUnit width; |
| 118 LayoutUnit height; | 139 LayoutUnit height; |
| 119 | 140 |
| 120 NGLogicalSize ConvertToLogical(NGWritingMode mode) const; | 141 NGLogicalSize ConvertToLogical(NGWritingMode mode) const; |
| 121 | 142 |
| 143 bool operator==(const NGPhysicalSize& other) const; |
| 144 |
| 122 String ToString() const { | 145 String ToString() const { |
| 123 return String::format("%dx%d", width.toInt(), height.toInt()); | 146 return String::format("%dx%d", width.toInt(), height.toInt()); |
| 124 } | 147 } |
| 125 }; | 148 }; |
| 126 | 149 |
| 150 inline std::ostream& operator<<(std::ostream& stream, |
| 151 const NGPhysicalSize& value) { |
| 152 return stream << value.ToString(); |
| 153 } |
| 154 |
| 127 // NGPhysicalLocation is the position of a rect (typically a fragment) relative | 155 // NGPhysicalLocation is the position of a rect (typically a fragment) relative |
| 128 // to the root document. | 156 // to the root document. |
| 129 struct NGPhysicalLocation { | 157 struct NGPhysicalLocation { |
| 130 LayoutUnit left; | 158 LayoutUnit left; |
| 131 LayoutUnit top; | 159 LayoutUnit top; |
| 132 }; | 160 }; |
| 133 | 161 |
| 134 struct NGPhysicalRect { | 162 struct NGPhysicalRect { |
| 135 NGPhysicalOffset offset; | 163 NGPhysicalOffset offset; |
| 136 NGPhysicalSize size; | 164 NGPhysicalSize size; |
| 137 }; | 165 }; |
| 138 | 166 |
| 139 // TODO(glebl): move to a separate file in layout/ng/units. | 167 // TODO(glebl): move to a separate file in layout/ng/units. |
| 140 struct CORE_EXPORT NGLogicalRect { | 168 struct CORE_EXPORT NGLogicalRect { |
| 141 NGLogicalRect() {} | 169 NGLogicalRect() {} |
| 170 NGLogicalRect(const NGLogicalOffset& offset, const NGLogicalSize& size) |
| 171 : offset(offset), size(size) {} |
| 142 NGLogicalRect(LayoutUnit inline_offset, | 172 NGLogicalRect(LayoutUnit inline_offset, |
| 143 LayoutUnit block_offset, | 173 LayoutUnit block_offset, |
| 144 LayoutUnit inline_size, | 174 LayoutUnit inline_size, |
| 145 LayoutUnit block_size) | 175 LayoutUnit block_size) |
| 146 : offset(inline_offset, block_offset), size(inline_size, block_size) {} | 176 : offset(inline_offset, block_offset), size(inline_size, block_size) {} |
| 147 | 177 |
| 148 bool IsEmpty() const; | 178 bool IsEmpty() const; |
| 149 | 179 |
| 150 // Whether this rectangle is contained by the provided rectangle. | 180 // Whether this rectangle is contained by the provided rectangle. |
| 151 bool IsContained(const NGLogicalRect& other) const; | 181 bool IsContained(const NGLogicalRect& other) const; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 kFloatLeft = 1, | 220 kFloatLeft = 1, |
| 191 // Exclusion that is created by RIGHT float. | 221 // Exclusion that is created by RIGHT float. |
| 192 kFloatRight = 2 | 222 kFloatRight = 2 |
| 193 }; | 223 }; |
| 194 | 224 |
| 195 // Rectangle in logical coordinates the represents this exclusion. | 225 // Rectangle in logical coordinates the represents this exclusion. |
| 196 NGLogicalRect rect; | 226 NGLogicalRect rect; |
| 197 | 227 |
| 198 // Type of this exclusion. | 228 // Type of this exclusion. |
| 199 Type type; | 229 Type type; |
| 230 |
| 231 bool operator==(const NGExclusion& other) const; |
| 232 String ToString() const; |
| 200 }; | 233 }; |
| 201 | 234 |
| 235 inline std::ostream& operator<<(std::ostream& stream, |
| 236 const NGExclusion& value) { |
| 237 return stream << value.ToString(); |
| 238 } |
| 239 |
| 202 struct CORE_EXPORT NGExclusions { | 240 struct CORE_EXPORT NGExclusions { |
| 203 // Default constructor. | 241 // Default constructor. |
| 204 NGExclusions(); | 242 NGExclusions(); |
| 205 | 243 |
| 206 // Copy constructor. | 244 // Copy constructor. |
| 207 NGExclusions(const NGExclusions& other); | 245 NGExclusions(const NGExclusions& other); |
| 208 | 246 |
| 209 Vector<std::unique_ptr<const NGExclusion>> storage; | 247 Vector<std::unique_ptr<const NGExclusion>> storage; |
| 210 | 248 |
| 211 // Last left/right float exclusions are used to enforce the top edge alignment | 249 // Last left/right float exclusions are used to enforce the top edge alignment |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 299 |
| 262 NGBoxStrut operator+(const NGBoxStrut& other) { | 300 NGBoxStrut operator+(const NGBoxStrut& other) { |
| 263 NGBoxStrut result(*this); | 301 NGBoxStrut result(*this); |
| 264 result += other; | 302 result += other; |
| 265 return result; | 303 return result; |
| 266 } | 304 } |
| 267 | 305 |
| 268 bool operator==(const NGBoxStrut& other) const; | 306 bool operator==(const NGBoxStrut& other) const; |
| 269 | 307 |
| 270 String ToString() const { | 308 String ToString() const { |
| 271 return String::format("Inline (%d, %d) Block (%d, %d)", | 309 return String::format("Inline: (%d %d) Block: (%d %d)", |
| 272 inline_start.toInt(), inline_end.toInt(), | 310 inline_start.toInt(), inline_end.toInt(), |
| 273 block_start.toInt(), block_end.toInt()); | 311 block_start.toInt(), block_end.toInt()); |
| 274 } | 312 } |
| 275 }; | 313 }; |
| 276 | 314 |
| 277 inline std::ostream& operator<<(std::ostream& stream, const NGBoxStrut& value) { | 315 inline std::ostream& operator<<(std::ostream& stream, const NGBoxStrut& value) { |
| 278 return stream << value.ToString(); | 316 return stream << value.ToString(); |
| 279 } | 317 } |
| 280 | 318 |
| 281 // This struct is used for the margin collapsing calculation. | 319 // This struct is used for the margin collapsing calculation. |
| 282 struct CORE_EXPORT NGMarginStrut { | 320 // TODO(glebl): Deprecated. It's being replaced by NGMarginStrut |
| 321 struct CORE_EXPORT NGDeprecatedMarginStrut { |
| 283 LayoutUnit margin_block_start; | 322 LayoutUnit margin_block_start; |
| 284 LayoutUnit margin_block_end; | 323 LayoutUnit margin_block_end; |
| 285 | 324 |
| 286 LayoutUnit negative_margin_block_start; | 325 LayoutUnit negative_margin_block_start; |
| 287 LayoutUnit negative_margin_block_end; | 326 LayoutUnit negative_margin_block_end; |
| 288 | 327 |
| 289 LayoutUnit BlockEndSum() const; | 328 LayoutUnit BlockEndSum() const; |
| 290 | 329 |
| 291 void AppendMarginBlockStart(const LayoutUnit& value); | 330 void AppendMarginBlockStart(const LayoutUnit& value); |
| 292 void AppendMarginBlockEnd(const LayoutUnit& value); | 331 void AppendMarginBlockEnd(const LayoutUnit& value); |
| 293 void SetMarginBlockStart(const LayoutUnit& value); | 332 void SetMarginBlockStart(const LayoutUnit& value); |
| 294 void SetMarginBlockEnd(const LayoutUnit& value); | 333 void SetMarginBlockEnd(const LayoutUnit& value); |
| 295 | 334 |
| 296 bool IsEmpty() const; | 335 bool IsEmpty() const; |
| 297 | 336 |
| 298 String ToString() const; | 337 String ToString() const; |
| 299 | 338 |
| 339 bool operator==(const NGDeprecatedMarginStrut& other) const; |
| 340 }; |
| 341 |
| 342 // This struct is used for the margin collapsing calculation. |
| 343 struct CORE_EXPORT NGMarginStrut { |
| 344 LayoutUnit margin; |
| 345 LayoutUnit negative_margin; |
| 346 |
| 300 bool operator==(const NGMarginStrut& other) const; | 347 bool operator==(const NGMarginStrut& other) const; |
| 348 |
| 349 void Append(const LayoutUnit& value); |
| 350 |
| 351 LayoutUnit Collapse() const; |
| 352 |
| 353 String ToString() const; |
| 301 }; | 354 }; |
| 302 | 355 |
| 303 inline std::ostream& operator<<(std::ostream& stream, | 356 inline std::ostream& operator<<(std::ostream& stream, |
| 304 const NGMarginStrut& value) { | 357 const NGMarginStrut& value) { |
| 305 return stream << value.ToString(); | 358 return stream << value.ToString(); |
| 306 } | 359 } |
| 307 | 360 |
| 308 // Struct to represent a simple edge that has start and end. | 361 // Struct to represent a simple edge that has start and end. |
| 309 struct NGEdge { | 362 struct NGEdge { |
| 310 LayoutUnit start; | 363 LayoutUnit start; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 if (position_matches) | 415 if (position_matches) |
| 363 return position; | 416 return position; |
| 364 else | 417 else |
| 365 return container_size - position - length - margin_start - margin_end; | 418 return container_size - position - length - margin_start - margin_end; |
| 366 } | 419 } |
| 367 }; | 420 }; |
| 368 | 421 |
| 369 } // namespace blink | 422 } // namespace blink |
| 370 | 423 |
| 371 #endif // NGUnits_h | 424 #endif // NGUnits_h |
| OLD | NEW |