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 NGConstraintSpace_h | |
6 #define NGConstraintSpace_h | |
7 | |
8 #include "core/CoreExport.h" | |
9 #include "platform/LayoutUnit.h" | |
10 #include "wtf/DoublyLinkedList.h" | |
11 | |
12 namespace blink { | |
13 | |
14 class NGConstraintSpace; | |
15 class NGDerivedConstraintSpace; | |
16 class NGExclusion; | |
17 class NGFragment; | |
18 class NGLayoutOpportunityIterator; | |
19 class LayoutBox; | |
20 | |
21 enum NGExclusionType { | |
22 NGClearNone = 0, | |
23 NGClearFloatLeft = 1, | |
24 NGClearFloatRight = 2, | |
25 NGClearFragment = 4 | |
26 }; | |
27 | |
28 enum NGFragmentationType { | |
29 FragmentNone, | |
30 FragmentPage, | |
31 FragmentColumn, | |
32 FragmentRegion | |
33 }; | |
34 | |
35 enum NGExclusionFlowType { | |
36 ExcludeNone, | |
37 ExcludeInlineFlow, | |
38 ExcludeInlineStart, | |
39 ExcludeInlineEnd, | |
40 ExcludeInlineBoth | |
41 }; | |
42 | |
43 class NGExclusion { | |
44 public: | |
45 NGExclusion(); | |
46 ~NGExclusion() { } | |
47 }; | |
48 | |
49 class CORE_EXPORT NGConstraintSpace { | |
50 public: | |
51 NGConstraintSpace(LayoutUnit inlineContainerSize, | |
52 LayoutUnit blockContainerSize); | |
53 ~NGConstraintSpace() { } | |
54 | |
55 // Constructs Layout NG constraint space from legacy layout object. | |
56 static NGConstraintSpace fromLayoutObject(const LayoutBox&); | |
57 | |
58 void addExclusion(const NGExclusion, unsigned options = 0); | |
59 void setOverflowTriggersScrollbar(bool inlineTriggers, | |
60 bool blockTriggers); | |
61 void setFixedSize(bool inlineFixed, bool blockFixed); | |
62 void setFragmentationType(NGFragmentationType); | |
63 | |
64 // Size of the container in each direction. Used for the following | |
65 // three cases: | |
66 // 1) Percentage resolution. | |
67 // 2) Resolving absolute positions of children. | |
68 // 3) Defining the threashold that triggers the presence of a | |
69 // scrollbar. Only applies if the corresponding scrollbarTrigger | |
70 // flag has been set for the direction. | |
71 LayoutUnit inlineContainerSize() const | |
72 { | |
73 return m_inlineContainerSize; | |
74 } | |
75 LayoutUnit blockContainerSize() const | |
76 { | |
77 return m_blockContainerSize; | |
78 } | |
79 | |
80 // Whether exceeding the containerSize triggers the presence of a | |
81 // scrollbar for the indicated direction. | |
82 // If exceeded the current layout should be aborted and invoked again | |
83 // with a constraint space modified to reserve space for a scrollbar. | |
84 bool inlineTriggersScrollbar() const | |
85 { | |
86 return m_inlineTriggersScrollbar; | |
87 } | |
88 bool blockTriggersScrollbar() const | |
89 { | |
90 return m_blockTriggersScrollbar; | |
91 } | |
92 | |
93 // Some layout modes “stretch” their children to a fixed size (e.g. flex, | |
94 // grid). These flags represented whether a layout needs to produce a | |
95 // fragment that satisfies a fixed constraint in the inline and block | |
96 // direction respectively. | |
97 bool fixedInlineSize() const { return m_fixedInlineSize; } | |
98 bool fixedBlockSize() const { return m_fixedBlockSize; } | |
99 | |
100 // If specified a layout should produce a Fragment which fragments at the | |
101 // blockSize if possible. | |
102 NGFragmentationType blockFragmentationType() const | |
103 { | |
104 return static_cast<NGFragmentationType>(m_blockFragmentationType); | |
105 } | |
106 | |
107 DoublyLinkedList<const NGExclusion> exclusions(unsigned options = 0) const; | |
108 | |
109 NGLayoutOpportunityIterator layoutOpportunities( | |
110 unsigned clear = NGClearNone, | |
111 NGExclusionFlowType avoid = ExcludeNone) const; | |
112 | |
113 // Modifies constraint space to account for a placed fragment. Depending on | |
114 // the shape of the fragment this will either modify the inline or block | |
115 // size, or add an exclusion. | |
116 void subtract(const NGFragment); | |
117 | |
118 private: | |
119 LayoutUnit m_inlineContainerSize; | |
120 LayoutUnit m_blockContainerSize; | |
121 | |
122 unsigned m_fixedInlineSize : 1; | |
123 unsigned m_fixedBlockSize : 1; | |
124 unsigned m_inlineTriggersScrollbar : 1; | |
125 unsigned m_blockTriggersScrollbar : 1; | |
126 unsigned m_blockFragmentationType : 2; | |
127 | |
128 DoublyLinkedList<const NGExclusion> m_exclusions; | |
129 }; | |
130 | |
131 | |
132 class CORE_EXPORT NGLayoutOpportunityIterator final { | |
133 public: | |
134 NGLayoutOpportunityIterator(const NGConstraintSpace* space, | |
135 unsigned clear, NGExclusionFlowType avoid) | |
136 : m_constraintSpace(space) | |
137 , m_clear(clear) | |
138 , m_avoid(avoid) { } | |
139 ~NGLayoutOpportunityIterator() { } | |
140 | |
141 const NGDerivedConstraintSpace* next(); | |
142 | |
143 private: | |
144 const NGConstraintSpace* m_constraintSpace; | |
145 unsigned m_clear; | |
146 NGExclusionFlowType m_avoid; | |
147 }; | |
148 | |
149 | |
150 class CORE_EXPORT NGDerivedConstraintSpace final : NGConstraintSpace { | |
151 public: | |
152 ~NGDerivedConstraintSpace(); | |
153 | |
154 LayoutUnit inlineOffset() const; | |
155 LayoutUnit blockOffset() const; | |
156 LayoutUnit inlineSize() const; | |
157 LayoutUnit blockSize() const; | |
158 | |
159 private: | |
160 NGDerivedConstraintSpace(); | |
161 | |
162 LayoutUnit m_inlineOffset; | |
163 LayoutUnit m_blockOffset; | |
164 LayoutUnit m_inlineSize; | |
165 LayoutUnit m_blockSize; | |
166 NGConstraintSpace* m_original; | |
167 }; | |
168 | |
169 } // namespace blink | |
170 | |
171 #endif // NGConstraintSpace_h | |
OLD | NEW |