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