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 NGBlockLayoutAlgorithm_h | 5 #ifndef NGBlockLayoutAlgorithm_h |
6 #define NGBlockLayoutAlgorithm_h | 6 #define NGBlockLayoutAlgorithm_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "core/layout/ng/ng_block_node.h" | 9 #include "core/layout/ng/ng_block_node.h" |
10 #include "core/layout/ng/ng_layout_algorithm.h" | 10 #include "core/layout/ng/ng_layout_algorithm.h" |
11 #include "core/layout/ng/ng_units.h" | 11 #include "core/layout/ng/ng_units.h" |
12 #include "wtf/RefPtr.h" | 12 #include "wtf/RefPtr.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class ComputedStyle; | 16 class ComputedStyle; |
17 class NGBlockBreakToken; | 17 class NGBlockBreakToken; |
18 class NGBreakToken; | 18 class NGBreakToken; |
19 class NGColumnMapper; | 19 class NGColumnMapper; |
20 class NGConstraintSpace; | 20 class NGConstraintSpace; |
21 class NGConstraintSpaceBuilder; | 21 class NGConstraintSpaceBuilder; |
22 class NGBoxFragment; | |
23 class NGFragment; | 22 class NGFragment; |
24 class NGFragmentBuilder; | 23 class NGFragmentBuilder; |
25 class NGPhysicalFragment; | 24 class NGPhysicalFragment; |
26 | 25 |
27 // A class for general block layout (e.g. a <div> with no special style). | 26 // A class for general block layout (e.g. a <div> with no special style). |
28 // Lays out the children in sequence. | 27 // Lays out the children in sequence. |
29 class CORE_EXPORT NGBlockLayoutAlgorithm : public NGLayoutAlgorithm { | 28 class CORE_EXPORT NGBlockLayoutAlgorithm : public NGLayoutAlgorithm { |
30 public: | 29 public: |
31 // Default constructor. | 30 // Default constructor. |
32 // @param layout_object The layout object associated with this block. | 31 // @param layout_object The layout object associated with this block. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // Get the amount of block space left in the current fragmentainer for the | 90 // Get the amount of block space left in the current fragmentainer for the |
92 // child that is about to be laid out. | 91 // child that is about to be laid out. |
93 LayoutUnit SpaceAvailableForCurrentChild() const; | 92 LayoutUnit SpaceAvailableForCurrentChild() const; |
94 | 93 |
95 LayoutUnit BorderEdgeForCurrentChild() const { | 94 LayoutUnit BorderEdgeForCurrentChild() const { |
96 // TODO(mstensho): Need to take care of margin collapsing somehow. We | 95 // TODO(mstensho): Need to take care of margin collapsing somehow. We |
97 // should at least attempt to estimate what the top margin is going to be. | 96 // should at least attempt to estimate what the top margin is going to be. |
98 return content_size_; | 97 return content_size_; |
99 } | 98 } |
100 | 99 |
101 // Computes collapsed margins for 2 adjoining blocks and updates the resultant | 100 // Calculates relative position for the fragment that knows its offset. |
102 // fragment's MarginStrut if needed. | 101 NGLogicalOffset PositionFragmentWithKnownBfcOffset( |
103 // See https://www.w3.org/TR/CSS2/box.html#collapsing-margins | 102 const NGLogicalOffset& offset); |
104 // | |
105 // @param child_margins Margins information for the current child. | |
106 // @param fragment Current child's fragment. | |
107 // @return NGBoxStrut with margins block start/end. | |
108 NGBoxStrut CollapseMargins(const NGBoxStrut& child_margins, | |
109 const NGBoxFragment& fragment); | |
110 | |
111 // Calculates position of the in-flow block-level fragment that needs to be | |
112 // positioned relative to the current fragment that is being built. | |
113 // | |
114 // @param fragment Fragment that needs to be placed. | |
115 // @param child_margins Margins information for the current child fragment. | |
116 // @return Position of the fragment in the parent's constraint space. | |
117 NGLogicalOffset PositionFragment(const NGFragment& fragment, | |
118 const NGBoxStrut& child_margins); | |
119 | |
120 // Calculates position of the float fragment that needs to be | |
121 // positioned relative to the current fragment that is being built. | |
122 // | |
123 // @param fragment Fragment that needs to be placed. | |
124 // @param child_margins Margins information for the current child fragment. | |
125 // @return Position of the fragment in the parent's constraint space. | |
126 NGLogicalOffset PositionFloatFragment(const NGFragment& fragment, | |
127 const NGBoxStrut& child_margins); | |
128 | |
129 // Updates block-{start|end} of the currently constructed fragment. | |
130 // | |
131 // This method is supposed to be called on every child but it only updates | |
132 // the block-start once (on the first non-zero height child fragment) and | |
133 // keeps updating block-end (on every non-zero height child). | |
134 void UpdateMarginStrut(const NGDeprecatedMarginStrut& from); | |
135 | 103 |
136 NGLogicalOffset GetChildSpaceOffset() const { | 104 NGLogicalOffset GetChildSpaceOffset() const { |
137 return NGLogicalOffset(border_and_padding_.inline_start, content_size_); | 105 return NGLogicalOffset(border_and_padding_.inline_start, content_size_); |
138 } | 106 } |
139 | 107 |
140 // Read-only Getters. | 108 // Read-only Getters. |
141 const ComputedStyle& CurrentChildStyle() const { | 109 const ComputedStyle& CurrentChildStyle() const { |
142 DCHECK(current_child_); | 110 DCHECK(current_child_); |
143 return *current_child_->Style(); | 111 return *current_child_->Style(); |
144 } | 112 } |
(...skipping 23 matching lines...) Expand all Loading... |
168 | 136 |
169 // Mapper from the fragmented flow coordinate space coordinates to visual | 137 // Mapper from the fragmented flow coordinate space coordinates to visual |
170 // coordinates. Only set on fragmentation context roots, such as multicol | 138 // coordinates. Only set on fragmentation context roots, such as multicol |
171 // containers. Keeps track of the current fragmentainer. | 139 // containers. Keeps track of the current fragmentainer. |
172 Member<NGColumnMapper> fragmentainer_mapper_; | 140 Member<NGColumnMapper> fragmentainer_mapper_; |
173 | 141 |
174 NGBoxStrut border_and_padding_; | 142 NGBoxStrut border_and_padding_; |
175 LayoutUnit content_size_; | 143 LayoutUnit content_size_; |
176 LayoutUnit max_inline_size_; | 144 LayoutUnit max_inline_size_; |
177 // MarginStrut for the previous child. | 145 // MarginStrut for the previous child. |
178 NGDeprecatedMarginStrut prev_child_margin_strut_; | 146 NGMarginStrut curr_margin_strut_; |
179 // Whether the block-start was set for the currently built | 147 NGLogicalOffset bfc_offset_; |
180 // fragment's margin strut. | 148 NGLogicalOffset curr_bfc_offset_; |
181 bool is_fragment_margin_strut_block_start_updated_ : 1; | |
182 NGBoxStrut curr_child_margins_; | 149 NGBoxStrut curr_child_margins_; |
183 }; | 150 }; |
184 | 151 |
185 } // namespace blink | 152 } // namespace blink |
186 | 153 |
187 #endif // NGBlockLayoutAlgorithm_h | 154 #endif // NGBlockLayoutAlgorithm_h |
OLD | NEW |