| 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 NGBreakToken; | 18 class NGBreakToken; |
| 19 class NGColumnMapper; |
| 18 class NGConstraintSpace; | 20 class NGConstraintSpace; |
| 19 class NGConstraintSpaceBuilder; | 21 class NGConstraintSpaceBuilder; |
| 20 class NGBoxFragment; | 22 class NGBoxFragment; |
| 21 class NGFragmentBuilder; | 23 class NGFragmentBuilder; |
| 22 class NGOutOfFlowLayoutPart; | 24 class NGOutOfFlowLayoutPart; |
| 23 class NGPhysicalFragment; | 25 class NGPhysicalFragment; |
| 24 | 26 |
| 25 // 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). |
| 26 // Lays out the children in sequence. | 28 // Lays out the children in sequence. |
| 27 class CORE_EXPORT NGBlockLayoutAlgorithm : public NGLayoutAlgorithm { | 29 class CORE_EXPORT NGBlockLayoutAlgorithm : public NGLayoutAlgorithm { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 43 NGLayoutAlgorithm**) override; | 45 NGLayoutAlgorithm**) override; |
| 44 | 46 |
| 45 DECLARE_VIRTUAL_TRACE(); | 47 DECLARE_VIRTUAL_TRACE(); |
| 46 | 48 |
| 47 private: | 49 private: |
| 48 // Creates a new constraint space for the current child. | 50 // Creates a new constraint space for the current child. |
| 49 NGConstraintSpace* CreateConstraintSpaceForCurrentChild() const; | 51 NGConstraintSpace* CreateConstraintSpaceForCurrentChild() const; |
| 50 void FinishCurrentChildLayout(NGFragment* fragment); | 52 void FinishCurrentChildLayout(NGFragment* fragment); |
| 51 bool LayoutOutOfFlowChild(); | 53 bool LayoutOutOfFlowChild(); |
| 52 | 54 |
| 55 // Proceed to the next sibling that still needs layout. |
| 56 // |
| 57 // @param child_fragment The newly created fragment for the current child. |
| 58 // @return true if we can continue to lay out, or false if we need to abort |
| 59 // due to a fragmentainer break. |
| 60 bool ProceedToNextUnfinishedSibling(NGPhysicalFragment* child_fragment); |
| 61 |
| 62 // Set a break token which contains enough information to be able to resume |
| 63 // layout in the next fragmentainer. |
| 64 void SetPendingBreakToken(NGBlockBreakToken*); |
| 65 |
| 66 // Check if we have a pending break token set. Once we have set a pending |
| 67 // break token, we cannot set another one. First we need to abort layout in |
| 68 // the current fragmentainer and resume in the next one. |
| 69 bool HasPendingBreakToken() const; |
| 70 |
| 71 // Final adjusstments before fragment creation. We need to prevent the |
| 72 // fragment from crossing fragmentainer boundaries, and rather create a break |
| 73 // token if we're out of space. |
| 74 void FinalizeForFragmentation(); |
| 75 |
| 76 // Return the break token, if any, at which we resumed layout after a |
| 77 // previous break. |
| 78 NGBlockBreakToken* CurrentBlockBreakToken() const; |
| 79 |
| 80 // Return the block offset of the previous break, in the fragmented flow |
| 81 // coordinate space, relatively to the start edge of this block. |
| 82 LayoutUnit PreviousBreakOffset() const; |
| 83 |
| 84 // Return the offset of the potential next break, in the fragmented flow |
| 85 // coordinate space, relatively to the start edge of this block. |
| 86 LayoutUnit NextBreakOffset() const; |
| 87 |
| 88 // Get the amount of block space left in the current fragmentainer for the |
| 89 // child that is about to be laid out. |
| 90 LayoutUnit SpaceAvailableForCurrentChild() const; |
| 91 |
| 92 LayoutUnit BorderEdgeForCurrentChild() const { |
| 93 // TODO(mstensho): Need to take care of margin collapsing somehow. We |
| 94 // should at least attempt to estimate what the top margin is going to be. |
| 95 return content_size_; |
| 96 } |
| 97 |
| 53 // Computes collapsed margins for 2 adjoining blocks and updates the resultant | 98 // Computes collapsed margins for 2 adjoining blocks and updates the resultant |
| 54 // fragment's MarginStrut if needed. | 99 // fragment's MarginStrut if needed. |
| 55 // See https://www.w3.org/TR/CSS2/box.html#collapsing-margins | 100 // See https://www.w3.org/TR/CSS2/box.html#collapsing-margins |
| 56 // | 101 // |
| 57 // @param child_margins Margins information for the current child. | 102 // @param child_margins Margins information for the current child. |
| 58 // @param fragment Current child's fragment. | 103 // @param fragment Current child's fragment. |
| 59 // @return NGBoxStrut with margins block start/end. | 104 // @return NGBoxStrut with margins block start/end. |
| 60 NGBoxStrut CollapseMargins(const NGBoxStrut& child_margins, | 105 NGBoxStrut CollapseMargins(const NGBoxStrut& child_margins, |
| 61 const NGBoxFragment& fragment); | 106 const NGBoxFragment& fragment); |
| 62 | 107 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 kStateOutOfFlowLayout, | 153 kStateOutOfFlowLayout, |
| 109 kStateFinalize | 154 kStateFinalize |
| 110 }; | 155 }; |
| 111 LayoutState layout_state_; | 156 LayoutState layout_state_; |
| 112 LayoutState compute_minmax_state_; | 157 LayoutState compute_minmax_state_; |
| 113 | 158 |
| 114 RefPtr<const ComputedStyle> style_; | 159 RefPtr<const ComputedStyle> style_; |
| 115 | 160 |
| 116 Member<NGBlockNode> first_child_; | 161 Member<NGBlockNode> first_child_; |
| 117 Member<NGConstraintSpace> constraint_space_; | 162 Member<NGConstraintSpace> constraint_space_; |
| 163 |
| 164 // The break token from which we are currently resuming layout. |
| 118 Member<NGBreakToken> break_token_; | 165 Member<NGBreakToken> break_token_; |
| 166 |
| 119 Member<NGFragmentBuilder> builder_; | 167 Member<NGFragmentBuilder> builder_; |
| 120 Member<NGConstraintSpaceBuilder> space_builder_; | 168 Member<NGConstraintSpaceBuilder> space_builder_; |
| 121 Member<NGConstraintSpace> space_for_current_child_; | 169 Member<NGConstraintSpace> space_for_current_child_; |
| 122 Member<NGBlockNode> current_child_; | 170 Member<NGBlockNode> current_child_; |
| 123 Member<NGBlockNode> current_minmax_child_; | 171 Member<NGBlockNode> current_minmax_child_; |
| 124 MinAndMaxContentSizes pending_minmax_sizes_; | 172 MinAndMaxContentSizes pending_minmax_sizes_; |
| 125 | 173 |
| 126 Member<NGOutOfFlowLayoutPart> out_of_flow_layout_; | 174 Member<NGOutOfFlowLayoutPart> out_of_flow_layout_; |
| 127 HeapLinkedHashSet<WeakMember<NGBlockNode>> out_of_flow_candidates_; | 175 HeapLinkedHashSet<WeakMember<NGBlockNode>> out_of_flow_candidates_; |
| 128 Vector<NGStaticPosition> out_of_flow_candidate_positions_; | 176 Vector<NGStaticPosition> out_of_flow_candidate_positions_; |
| 129 size_t out_of_flow_candidate_positions_index_; | 177 size_t out_of_flow_candidate_positions_index_; |
| 130 | 178 |
| 179 Member<NGColumnMapper> fragmentainer_mapper_; |
| 180 |
| 131 NGBoxStrut border_and_padding_; | 181 NGBoxStrut border_and_padding_; |
| 132 LayoutUnit content_size_; | 182 LayoutUnit content_size_; |
| 133 LayoutUnit max_inline_size_; | 183 LayoutUnit max_inline_size_; |
| 134 // MarginStrut for the previous child. | 184 // MarginStrut for the previous child. |
| 135 NGMarginStrut prev_child_margin_strut_; | 185 NGMarginStrut prev_child_margin_strut_; |
| 136 // Whether the block-start was set for the currently built | 186 // Whether the block-start was set for the currently built |
| 137 // fragment's margin strut. | 187 // fragment's margin strut. |
| 138 bool is_fragment_margin_strut_block_start_updated_ : 1; | 188 bool is_fragment_margin_strut_block_start_updated_ : 1; |
| 139 }; | 189 }; |
| 140 | 190 |
| 141 } // namespace blink | 191 } // namespace blink |
| 142 | 192 |
| 143 #endif // NGBlockLayoutAlgorithm_h | 193 #endif // NGBlockLayoutAlgorithm_h |
| OLD | NEW |