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 NGPhysicalFragment_h | 5 #ifndef NGPhysicalFragment_h |
6 #define NGPhysicalFragment_h | 6 #define NGPhysicalFragment_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "core/layout/ng/ng_units.h" | 9 #include "core/layout/ng/ng_units.h" |
10 #include "platform/LayoutUnit.h" | 10 #include "platform/LayoutUnit.h" |
11 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
12 #include "wtf/Vector.h" | 12 #include "wtf/Vector.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class LayoutObject; | 16 class LayoutObject; |
17 class NGBlockNode; | |
18 class NGBreakToken; | 17 class NGBreakToken; |
19 struct NGFloatingObject; | |
20 | 18 |
21 // The NGPhysicalFragment contains the output information from layout. The | 19 // The NGPhysicalFragment contains the output geometry from layout. The |
22 // fragment stores all of its information in the physical coordinate system for | 20 // fragment stores all of its information in the physical coordinate system for |
23 // use by paint, hit-testing etc. | 21 // use by paint, hit-testing etc. |
24 // | 22 // |
25 // The fragment keeps a pointer back to the LayoutObject which generated it. | 23 // The fragment keeps a pointer back to the LayoutObject which generated it. |
26 // Once we have transitioned fully to LayoutNG it should be a const pointer | 24 // Once we have transitioned fully to LayoutNG it should be a const pointer |
27 // such that paint/hit-testing/etc don't modify it. | 25 // such that paint/hit-testing/etc don't modify it. |
28 // | 26 // |
29 // Layout code should only access output layout information through the | 27 // Layout code should only access geometry information through the |
30 // NGFragmentBase classes which transforms information into the logical | 28 // NGFragment wrapper classes which transforms information into the logical |
31 // coordinate system. | 29 // coordinate system. |
32 class CORE_EXPORT NGPhysicalFragment : public RefCounted<NGPhysicalFragment> { | 30 class CORE_EXPORT NGPhysicalFragment : public RefCounted<NGPhysicalFragment> { |
33 public: | 31 public: |
34 enum NGFragmentType { kFragmentBox = 0, kFragmentText = 1 }; | 32 enum NGFragmentType { kFragmentBox = 0, kFragmentText = 1 }; |
35 | 33 |
36 NGFragmentType Type() const { return static_cast<NGFragmentType>(type_); } | 34 NGFragmentType Type() const { return static_cast<NGFragmentType>(type_); } |
37 | 35 |
38 // Override RefCounted's deref() to ensure operator delete is called on the | 36 // Override RefCounted's deref() to ensure operator delete is called on the |
39 // appropriate subclass type. | 37 // appropriate subclass type. |
40 void deref() const { | 38 void deref() const { |
(...skipping 29 matching lines...) Expand all Loading... |
70 void SetOffset(NGPhysicalOffset offset) { | 68 void SetOffset(NGPhysicalOffset offset) { |
71 DCHECK(!is_placed_); | 69 DCHECK(!is_placed_); |
72 offset_ = offset; | 70 offset_ = offset; |
73 is_placed_ = true; | 71 is_placed_ = true; |
74 } | 72 } |
75 | 73 |
76 NGBreakToken* BreakToken() const { return break_token_; } | 74 NGBreakToken* BreakToken() const { return break_token_; } |
77 | 75 |
78 LayoutObject* GetLayoutObject() const { return layout_object_; } | 76 LayoutObject* GetLayoutObject() const { return layout_object_; } |
79 | 77 |
80 const HeapLinkedHashSet<WeakMember<NGBlockNode>>& OutOfFlowDescendants() | |
81 const { | |
82 return out_of_flow_descendants_; | |
83 } | |
84 | |
85 const Vector<NGStaticPosition>& OutOfFlowPositions() const { | |
86 return out_of_flow_positions_; | |
87 } | |
88 | |
89 bool IsPlaced() const { return is_placed_; } | 78 bool IsPlaced() const { return is_placed_; } |
90 | 79 |
91 // List of floats that need to be positioned by the next in-flow child that | |
92 // can determine its position in space. | |
93 // Use case example where it may be needed: | |
94 // <div><float></div> | |
95 // <div style="margin-top: 10px; height: 20px"></div> | |
96 // The float cannot be positioned right away inside of the 1st div because | |
97 // the vertical position is not known at that moment. It will be known only | |
98 // after the 2nd div collapses its margin with its parent. | |
99 const Vector<Persistent<NGFloatingObject>>& UnpositionedFloats() const { | |
100 return unpositioned_floats_; | |
101 } | |
102 | |
103 // List of positioned float that need to be copied to the old layout tree. | |
104 // TODO(layout-ng): remove this once we change painting code to handle floats | |
105 // differently. | |
106 const Vector<Persistent<NGFloatingObject>>& PositionedFloats() const { | |
107 return positioned_floats_; | |
108 } | |
109 | |
110 protected: | 80 protected: |
111 NGPhysicalFragment(LayoutObject* layout_object, | 81 NGPhysicalFragment(LayoutObject* layout_object, |
112 NGPhysicalSize size, | 82 NGPhysicalSize size, |
113 NGPhysicalSize overflow, | 83 NGPhysicalSize overflow, |
114 NGFragmentType type, | 84 NGFragmentType type, |
115 PersistentHeapLinkedHashSet<WeakMember<NGBlockNode>>& | |
116 out_of_flow_descendants, | |
117 Vector<NGStaticPosition> out_of_flow_positions, | |
118 Vector<Persistent<NGFloatingObject>>& unpositioned_floats, | |
119 Vector<Persistent<NGFloatingObject>>& positioned_floats, | |
120 NGBreakToken* break_token = nullptr); | 85 NGBreakToken* break_token = nullptr); |
121 | 86 |
122 LayoutObject* layout_object_; | 87 LayoutObject* layout_object_; |
123 NGPhysicalSize size_; | 88 NGPhysicalSize size_; |
124 NGPhysicalSize overflow_; | 89 NGPhysicalSize overflow_; |
125 NGPhysicalOffset offset_; | 90 NGPhysicalOffset offset_; |
126 Persistent<NGBreakToken> break_token_; | 91 Persistent<NGBreakToken> break_token_; |
127 PersistentHeapLinkedHashSet<WeakMember<NGBlockNode>> out_of_flow_descendants_; | |
128 Vector<NGStaticPosition> out_of_flow_positions_; | |
129 Vector<Persistent<NGFloatingObject>> unpositioned_floats_; | |
130 Vector<Persistent<NGFloatingObject>> positioned_floats_; | |
131 | 92 |
132 unsigned type_ : 1; | 93 unsigned type_ : 1; |
133 unsigned is_placed_ : 1; | 94 unsigned is_placed_ : 1; |
134 | 95 |
135 private: | 96 private: |
136 void destroy() const; | 97 void destroy() const; |
137 }; | 98 }; |
138 | 99 |
139 } // namespace blink | 100 } // namespace blink |
140 | 101 |
141 #endif // NGPhysicalFragment_h | 102 #endif // NGPhysicalFragment_h |
OLD | NEW |