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 #ifndef NGStaticPosition_h | |
6 #define NGStaticPosition_h | |
7 | |
8 #include "core/CoreExport.h" | |
9 #include "core/layout/ng/geometry/ng_physical_offset.h" | |
10 #include "core/layout/ng/ng_writing_mode.h" | |
11 #include "platform/LayoutUnit.h" | |
12 #include "platform/text/TextDirection.h" | |
13 | |
14 namespace blink { | |
15 | |
16 // Represents static position of an out of flow descendant. | |
17 struct CORE_EXPORT NGStaticPosition { | |
18 enum Type { kTopLeft, kTopRight, kBottomLeft, kBottomRight }; | |
19 | |
20 Type type; // Logical corner that corresponds to physical top left. | |
21 NGPhysicalOffset offset; | |
22 | |
23 // Creates a position with proper type wrt writing mode and direction. | |
24 static NGStaticPosition Create(NGWritingMode, | |
25 TextDirection, | |
26 NGPhysicalOffset); | |
27 // Left/Right/TopPosition functions map static position to | |
28 // left/right/top edge wrt container space. | |
29 // The function arguments are required to solve the equation: | |
30 // contaner_size = left + margin_left + width + margin_right + right | |
31 LayoutUnit LeftPosition(LayoutUnit container_size, | |
32 LayoutUnit width, | |
33 LayoutUnit margin_left, | |
34 LayoutUnit margin_right) const { | |
35 return GenericPosition(HasLeft(), offset.left, container_size, width, | |
36 margin_left, margin_right); | |
37 } | |
38 LayoutUnit RightPosition(LayoutUnit container_size, | |
39 LayoutUnit width, | |
40 LayoutUnit margin_left, | |
41 LayoutUnit margin_right) const { | |
42 return GenericPosition(!HasLeft(), offset.left, container_size, width, | |
43 margin_left, margin_right); | |
44 } | |
45 LayoutUnit TopPosition(LayoutUnit container_size, | |
46 LayoutUnit height, | |
47 LayoutUnit margin_top, | |
48 LayoutUnit margin_bottom) const { | |
49 return GenericPosition(HasTop(), offset.top, container_size, height, | |
50 margin_top, margin_bottom); | |
51 } | |
52 | |
53 private: | |
54 bool HasTop() const { return type == kTopLeft || type == kTopRight; } | |
55 bool HasLeft() const { return type == kTopLeft || type == kBottomLeft; } | |
56 LayoutUnit GenericPosition(bool position_matches, | |
57 LayoutUnit position, | |
58 LayoutUnit container_size, | |
59 LayoutUnit length, | |
60 LayoutUnit margin_start, | |
61 LayoutUnit margin_end) const { | |
62 DCHECK_GE(container_size, LayoutUnit()); | |
63 DCHECK_GE(length, LayoutUnit()); | |
64 if (position_matches) | |
65 return position; | |
66 else | |
67 return container_size - position - length - margin_start - margin_end; | |
68 } | |
69 }; | |
70 | |
71 } // namespace blink | |
72 | |
73 #endif // NGStaticPosition_h | |
OLD | NEW |