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" | 11 #include "core/layout/ng/ng_column_mapper.h" |
12 #include "core/layout/ng/ng_fragment_builder.h" | 12 #include "core/layout/ng/ng_fragment_builder.h" |
13 #include "core/layout/ng/ng_layout_algorithm.h" | 13 #include "core/layout/ng/ng_layout_algorithm.h" |
14 #include "core/layout/ng/ng_units.h" | 14 #include "core/layout/ng/ng_units.h" |
15 #include "wtf/RefPtr.h" | 15 #include "wtf/RefPtr.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 class ComputedStyle; | 19 class ComputedStyle; |
20 class NGBlockBreakToken; | 20 class NGBlockBreakToken; |
21 class NGConstraintSpace; | 21 class NGConstraintSpace; |
22 class NGConstraintSpaceBuilder; | 22 class NGConstraintSpaceBuilder; |
23 class NGInlineNode; | 23 class NGInlineNode; |
24 class NGLayoutResult; | 24 class NGLayoutResult; |
25 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 node The input node to perform layout upon. | 31 // @param node The input node to perform layout upon. |
33 // @param space The constraint space which the algorithm should generate a | 32 // @param space The constraint space which the algorithm should generate a |
34 // fragment within. | 33 // fragment within. |
35 // @param break_token The break token from which the layout should start. | 34 // @param break_token The break token from which the layout should start. |
36 NGBlockLayoutAlgorithm(NGBlockNode* node, | 35 NGBlockLayoutAlgorithm(NGBlockNode* node, |
37 NGConstraintSpace* space, | 36 NGConstraintSpace* space, |
38 NGBreakToken* break_token = nullptr); | 37 NGBlockBreakToken* break_token = nullptr); |
39 | 38 |
40 Optional<MinAndMaxContentSizes> ComputeMinAndMaxContentSizes() const override; | 39 Optional<MinAndMaxContentSizes> ComputeMinAndMaxContentSizes() const override; |
41 RefPtr<NGLayoutResult> Layout() override; | 40 RefPtr<NGLayoutResult> Layout() override; |
42 | 41 |
43 private: | 42 private: |
44 NGBoxStrut CalculateMargins(const NGConstraintSpace& space, | 43 NGBoxStrut CalculateMargins(const NGConstraintSpace& space, |
45 const ComputedStyle& style); | 44 const ComputedStyle& style); |
46 | 45 |
47 // Creates a new constraint space for the current child. | 46 // Creates a new constraint space for the current child. |
48 NGConstraintSpace* CreateConstraintSpaceForCurrentChild(); | 47 NGConstraintSpace* CreateConstraintSpaceForCurrentChild(); |
49 void FinishCurrentChildLayout(RefPtr<NGLayoutResult>); | 48 void FinishCurrentChildLayout(RefPtr<NGLayoutResult>); |
50 | 49 |
51 // Layout inline children. | 50 // Layout inline children. |
52 void LayoutInlineChildren(NGInlineNode*); | 51 void LayoutInlineChildren(NGInlineNode*); |
53 | 52 |
54 // Proceed to the next sibling that still needs layout. | |
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 | 53 // Final adjusstments before fragment creation. We need to prevent the |
71 // fragment from crossing fragmentainer boundaries, and rather create a break | 54 // fragment from crossing fragmentainer boundaries, and rather create a break |
72 // token if we're out of space. | 55 // token if we're out of space. |
73 void FinalizeForFragmentation(); | 56 void FinalizeForFragmentation(); |
74 | 57 |
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 | 58 // Calculates logical offset for the current fragment using either |
98 // {@code content_size_} when the fragment doesn't know it's offset | 59 // {@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 | 60 // or {@code known_fragment_offset} if the fragment knows it's offset |
100 // @return Fragment's offset relative to the fragment's parent. | 61 // @return Fragment's offset relative to the fragment's parent. |
101 NGLogicalOffset CalculateLogicalOffset( | 62 NGLogicalOffset CalculateLogicalOffset( |
102 const WTF::Optional<NGLogicalOffset>& known_fragment_offset); | 63 const WTF::Optional<NGLogicalOffset>& known_fragment_offset); |
103 | 64 |
104 NGLogicalOffset GetChildSpaceOffset() const { | 65 NGLogicalOffset GetChildSpaceOffset() const { |
105 return NGLogicalOffset(border_and_padding_.inline_start, content_size_); | 66 return NGLogicalOffset(border_and_padding_.inline_start, content_size_); |
106 } | 67 } |
(...skipping 11 matching lines...) Expand all Loading... |
118 const NGConstraintSpace& CurrentChildConstraintSpace() const { | 79 const NGConstraintSpace& CurrentChildConstraintSpace() const { |
119 return *space_for_current_child_.get(); | 80 return *space_for_current_child_.get(); |
120 } | 81 } |
121 | 82 |
122 const ComputedStyle& Style() const { return node_->Style(); } | 83 const ComputedStyle& Style() const { return node_->Style(); } |
123 | 84 |
124 Persistent<NGBlockNode> node_; | 85 Persistent<NGBlockNode> node_; |
125 Persistent<NGConstraintSpace> constraint_space_; | 86 Persistent<NGConstraintSpace> constraint_space_; |
126 | 87 |
127 // The break token from which we are currently resuming layout. | 88 // The break token from which we are currently resuming layout. |
128 Persistent<NGBreakToken> break_token_; | 89 Persistent<NGBlockBreakToken> break_token_; |
129 | 90 |
130 std::unique_ptr<NGFragmentBuilder> builder_; | 91 std::unique_ptr<NGFragmentBuilder> builder_; |
131 Persistent<NGConstraintSpaceBuilder> space_builder_; | 92 Persistent<NGConstraintSpaceBuilder> space_builder_; |
132 Persistent<NGConstraintSpace> space_for_current_child_; | 93 Persistent<NGConstraintSpace> space_for_current_child_; |
133 Persistent<NGLayoutInputNode> current_child_; | 94 Persistent<NGLayoutInputNode> current_child_; |
134 | 95 |
135 // Mapper from the fragmented flow coordinate space coordinates to visual | |
136 // coordinates. Only set on fragmentation context roots, such as multicol | |
137 // containers. Keeps track of the current fragmentainer. | |
138 Persistent<NGColumnMapper> fragmentainer_mapper_; | |
139 | |
140 NGBoxStrut border_and_padding_; | 96 NGBoxStrut border_and_padding_; |
141 LayoutUnit content_size_; | 97 LayoutUnit content_size_; |
142 LayoutUnit max_inline_size_; | 98 LayoutUnit max_inline_size_; |
143 // MarginStrut for the previous child. | 99 // MarginStrut for the previous child. |
144 NGMarginStrut curr_margin_strut_; | 100 NGMarginStrut curr_margin_strut_; |
145 NGLogicalOffset bfc_offset_; | 101 NGLogicalOffset bfc_offset_; |
146 NGLogicalOffset curr_bfc_offset_; | 102 NGLogicalOffset curr_bfc_offset_; |
147 NGBoxStrut curr_child_margins_; | 103 NGBoxStrut curr_child_margins_; |
148 }; | 104 }; |
149 | 105 |
150 } // namespace blink | 106 } // namespace blink |
151 | 107 |
152 #endif // NGBlockLayoutAlgorithm_h | 108 #endif // NGBlockLayoutAlgorithm_h |
OLD | NEW |