Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.h

Issue 2714803002: [LayoutNG] Allow block-flow layout to be fragmented using new approach. (Closed)
Patch Set: address comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
cbiesinger 2017/02/27 19:09:37 While you're touching the related code, do you wan
ikilpatrick 2017/02/27 19:29:34 Done.
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 // Updates the fragment's BFC offset if it's not already set. 65 // Updates the fragment's BFC offset if it's not already set.
105 void UpdateFragmentBfcOffset(const NGLogicalOffset& offset); 66 void UpdateFragmentBfcOffset(const NGLogicalOffset& offset);
106 67
(...skipping 14 matching lines...) Expand all
121 const NGConstraintSpace& CurrentChildConstraintSpace() const { 82 const NGConstraintSpace& CurrentChildConstraintSpace() const {
122 return *space_for_current_child_.get(); 83 return *space_for_current_child_.get();
123 } 84 }
124 85
125 const ComputedStyle& Style() const { return node_->Style(); } 86 const ComputedStyle& Style() const { return node_->Style(); }
126 87
127 Persistent<NGBlockNode> node_; 88 Persistent<NGBlockNode> node_;
128 Persistent<NGConstraintSpace> constraint_space_; 89 Persistent<NGConstraintSpace> constraint_space_;
129 90
130 // The break token from which we are currently resuming layout. 91 // The break token from which we are currently resuming layout.
131 Persistent<NGBreakToken> break_token_; 92 Persistent<NGBlockBreakToken> break_token_;
132 93
133 std::unique_ptr<NGFragmentBuilder> builder_; 94 std::unique_ptr<NGFragmentBuilder> builder_;
134 Persistent<NGConstraintSpaceBuilder> space_builder_; 95 Persistent<NGConstraintSpaceBuilder> space_builder_;
135 Persistent<NGConstraintSpace> space_for_current_child_; 96 Persistent<NGConstraintSpace> space_for_current_child_;
136 Persistent<NGLayoutInputNode> current_child_; 97 Persistent<NGLayoutInputNode> current_child_;
137 98
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_; 99 NGBoxStrut border_and_padding_;
144 LayoutUnit content_size_; 100 LayoutUnit content_size_;
145 LayoutUnit max_inline_size_; 101 LayoutUnit max_inline_size_;
146 // MarginStrut for the previous child. 102 // MarginStrut for the previous child.
147 NGMarginStrut curr_margin_strut_; 103 NGMarginStrut curr_margin_strut_;
148 NGLogicalOffset bfc_offset_; 104 NGLogicalOffset bfc_offset_;
149 NGLogicalOffset curr_bfc_offset_; 105 NGLogicalOffset curr_bfc_offset_;
150 NGBoxStrut curr_child_margins_; 106 NGBoxStrut curr_child_margins_;
151 }; 107 };
152 108
153 } // namespace blink 109 } // namespace blink
154 110
155 #endif // NGBlockLayoutAlgorithm_h 111 #endif // NGBlockLayoutAlgorithm_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698