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_break_token.h" | 10 #include "core/layout/ng/ng_break_token.h" |
11 #include "core/layout/ng/ng_column_mapper.h" | |
12 #include "core/layout/ng/ng_fragment_builder.h" | 11 #include "core/layout/ng/ng_fragment_builder.h" |
13 #include "core/layout/ng/ng_layout_algorithm.h" | 12 #include "core/layout/ng/ng_layout_algorithm.h" |
14 #include "core/layout/ng/ng_units.h" | 13 #include "core/layout/ng/ng_units.h" |
15 #include "wtf/RefPtr.h" | 14 #include "wtf/RefPtr.h" |
16 | 15 |
17 namespace blink { | 16 namespace blink { |
18 | 17 |
19 class ComputedStyle; | 18 class ComputedStyle; |
20 class NGBlockBreakToken; | 19 class NGBlockBreakToken; |
21 class NGConstraintSpace; | 20 class NGConstraintSpace; |
22 class NGConstraintSpaceBuilder; | 21 class NGConstraintSpaceBuilder; |
23 class NGInlineNode; | 22 class NGInlineNode; |
24 class NGLayoutResult; | 23 class NGLayoutResult; |
25 class NGPhysicalFragment; | |
26 | 24 |
27 // A class for general block layout (e.g. a <div> with no special style). | 25 // A class for general block layout (e.g. a <div> with no special style). |
28 // Lays out the children in sequence. | 26 // Lays out the children in sequence. |
29 class CORE_EXPORT NGBlockLayoutAlgorithm : public NGLayoutAlgorithm { | 27 class CORE_EXPORT NGBlockLayoutAlgorithm : public NGLayoutAlgorithm { |
30 public: | 28 public: |
31 // Default constructor. | 29 // Default constructor. |
32 // @param node The input node to perform layout upon. | 30 // @param node The input node to perform layout upon. |
33 // @param space The constraint space which the algorithm should generate a | 31 // @param space The constraint space which the algorithm should generate a |
34 // fragment within. | 32 // fragment within. |
35 // @param break_token The break token from which the layout should start. | 33 // @param break_token The break token from which the layout should start. |
36 NGBlockLayoutAlgorithm(NGBlockNode* node, | 34 NGBlockLayoutAlgorithm(NGBlockNode* node, |
37 NGConstraintSpace* space, | 35 NGConstraintSpace* space, |
38 NGBreakToken* break_token = nullptr); | 36 NGBlockBreakToken* break_token = nullptr); |
39 | 37 |
40 Optional<MinAndMaxContentSizes> ComputeMinAndMaxContentSizes() const override; | 38 Optional<MinAndMaxContentSizes> ComputeMinAndMaxContentSizes() const override; |
41 RefPtr<NGLayoutResult> Layout() override; | 39 RefPtr<NGLayoutResult> Layout() override; |
42 | 40 |
43 private: | 41 private: |
44 NGBoxStrut CalculateMargins(const NGConstraintSpace& space, | 42 NGBoxStrut CalculateMargins(const NGConstraintSpace& space, |
45 const ComputedStyle& style); | 43 const ComputedStyle& style); |
46 | 44 |
47 // Creates a new constraint space for the current child. | 45 // Creates a new constraint space for the current child. |
48 NGConstraintSpace* CreateConstraintSpaceForCurrentChild(); | 46 NGConstraintSpace* CreateConstraintSpaceForCurrentChild(); |
49 void FinishCurrentChildLayout(RefPtr<NGLayoutResult>); | 47 void FinishCurrentChildLayout(RefPtr<NGLayoutResult>); |
50 | 48 |
51 // Layout inline children. | 49 // Layout inline children. |
52 void LayoutInlineChildren(NGInlineNode*); | 50 void LayoutInlineChildren(NGInlineNode*); |
53 | 51 |
54 // Proceed to the next sibling that still needs layout. | 52 // Final adjustments before fragment creation. We need to prevent the |
55 // | |
56 // @param child_fragment The newly created fragment for the current child. | |
57 // @return true if we can continue to lay out, or false if we need to abort | |
58 // due to a fragmentainer break. | |
59 bool ProceedToNextUnfinishedSibling(NGPhysicalFragment* child_fragment); | |
60 | |
61 // Set a break token which contains enough information to be able to resume | |
62 // layout in the next fragmentainer. | |
63 void SetPendingBreakToken(NGBlockBreakToken*); | |
64 | |
65 // Check if we have a pending break token set. Once we have set a pending | |
66 // break token, we cannot set another one. First we need to abort layout in | |
67 // the current fragmentainer and resume in the next one. | |
68 bool HasPendingBreakToken() const; | |
69 | |
70 // Final adjusstments before fragment creation. We need to prevent the | |
71 // fragment from crossing fragmentainer boundaries, and rather create a break | 53 // fragment from crossing fragmentainer boundaries, and rather create a break |
72 // token if we're out of space. | 54 // token if we're out of space. |
73 void FinalizeForFragmentation(); | 55 void FinalizeForFragmentation(); |
74 | 56 |
75 // Return the break token, if any, at which we resumed layout after a | |
76 // previous break. | |
77 NGBlockBreakToken* CurrentBlockBreakToken() const; | |
78 | |
79 // Return the block offset of the previous break, in the fragmented flow | |
80 // coordinate space, relatively to the start edge of this block. | |
81 LayoutUnit PreviousBreakOffset() const; | |
82 | |
83 // Return the offset of the potential next break, in the fragmented flow | |
84 // coordinate space, relatively to the start edge of this block. | |
85 LayoutUnit NextBreakOffset() const; | |
86 | |
87 // Get the amount of block space left in the current fragmentainer for the | |
88 // child that is about to be laid out. | |
89 LayoutUnit SpaceAvailableForCurrentChild() const; | |
90 | |
91 LayoutUnit BorderEdgeForCurrentChild() const { | |
92 // TODO(mstensho): Need to take care of margin collapsing somehow. We | |
93 // should at least attempt to estimate what the top margin is going to be. | |
94 return content_size_; | |
95 } | |
96 | |
97 // Calculates logical offset for the current fragment using either | 57 // Calculates logical offset for the current fragment using either |
98 // {@code content_size_} when the fragment doesn't know it's offset | 58 // {@code content_size_} when the fragment doesn't know it's offset |
99 // or {@code known_fragment_offset} if the fragment knows it's offset | 59 // or {@code known_fragment_offset} if the fragment knows it's offset |
100 // @return Fragment's offset relative to the fragment's parent. | 60 // @return Fragment's offset relative to the fragment's parent. |
101 NGLogicalOffset CalculateLogicalOffset( | 61 NGLogicalOffset CalculateLogicalOffset( |
102 const WTF::Optional<NGLogicalOffset>& known_fragment_offset); | 62 const WTF::Optional<NGLogicalOffset>& known_fragment_offset); |
103 | 63 |
104 // Updates the fragment's BFC offset if it's not already set. | 64 // Updates the fragment's BFC offset if it's not already set. |
105 void UpdateFragmentBfcOffset(const NGLogicalOffset& offset); | 65 void UpdateFragmentBfcOffset(const NGLogicalOffset& offset); |
106 | 66 |
(...skipping 14 matching lines...) Expand all Loading... |
121 const NGConstraintSpace& CurrentChildConstraintSpace() const { | 81 const NGConstraintSpace& CurrentChildConstraintSpace() const { |
122 return *space_for_current_child_.get(); | 82 return *space_for_current_child_.get(); |
123 } | 83 } |
124 | 84 |
125 const ComputedStyle& Style() const { return node_->Style(); } | 85 const ComputedStyle& Style() const { return node_->Style(); } |
126 | 86 |
127 Persistent<NGBlockNode> node_; | 87 Persistent<NGBlockNode> node_; |
128 Persistent<NGConstraintSpace> constraint_space_; | 88 Persistent<NGConstraintSpace> constraint_space_; |
129 | 89 |
130 // The break token from which we are currently resuming layout. | 90 // The break token from which we are currently resuming layout. |
131 Persistent<NGBreakToken> break_token_; | 91 Persistent<NGBlockBreakToken> break_token_; |
132 | 92 |
133 std::unique_ptr<NGFragmentBuilder> builder_; | 93 std::unique_ptr<NGFragmentBuilder> builder_; |
134 Persistent<NGConstraintSpaceBuilder> space_builder_; | 94 Persistent<NGConstraintSpaceBuilder> space_builder_; |
135 Persistent<NGConstraintSpace> space_for_current_child_; | 95 Persistent<NGConstraintSpace> space_for_current_child_; |
136 Persistent<NGLayoutInputNode> current_child_; | 96 Persistent<NGLayoutInputNode> current_child_; |
137 | 97 |
138 // Mapper from the fragmented flow coordinate space coordinates to visual | |
139 // coordinates. Only set on fragmentation context roots, such as multicol | |
140 // containers. Keeps track of the current fragmentainer. | |
141 Persistent<NGColumnMapper> fragmentainer_mapper_; | |
142 | |
143 NGBoxStrut border_and_padding_; | 98 NGBoxStrut border_and_padding_; |
144 LayoutUnit content_size_; | 99 LayoutUnit content_size_; |
145 LayoutUnit max_inline_size_; | 100 LayoutUnit max_inline_size_; |
146 // MarginStrut for the previous child. | 101 // MarginStrut for the previous child. |
147 NGMarginStrut curr_margin_strut_; | 102 NGMarginStrut curr_margin_strut_; |
148 NGLogicalOffset bfc_offset_; | 103 NGLogicalOffset bfc_offset_; |
149 NGLogicalOffset curr_bfc_offset_; | 104 NGLogicalOffset curr_bfc_offset_; |
150 NGBoxStrut curr_child_margins_; | 105 NGBoxStrut curr_child_margins_; |
151 }; | 106 }; |
152 | 107 |
153 } // namespace blink | 108 } // namespace blink |
154 | 109 |
155 #endif // NGBlockLayoutAlgorithm_h | 110 #endif // NGBlockLayoutAlgorithm_h |
OLD | NEW |