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

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

Issue 2456973002: [LayoutNG] Move ng_block_layout_algorithm to use constraint space builder. (Closed)
Patch Set: . Created 4 years, 1 month 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_box.h" 9 #include "core/layout/ng/ng_box.h"
10 #include "core/layout/ng/ng_fragment_builder.h" 10 #include "core/layout/ng/ng_fragment_builder.h"
11 #include "core/layout/ng/ng_layout_algorithm.h" 11 #include "core/layout/ng/ng_layout_algorithm.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 NGConstraintSpace; 17 class NGConstraintSpace;
18 class NGConstraintSpaceBuilder;
Gleb Lanbin 2016/10/27 22:30:06 can we just include a header here instead of using
ikilpatrick 2016/10/28 00:16:28 Done.
cbiesinger 2016/10/28 18:58:56 That sucks that they changed the style guide like
18 class NGPhysicalFragment; 19 class NGPhysicalFragment;
19 20
20 // A class for general block layout (e.g. a <div> with no special style). 21 // A class for general block layout (e.g. a <div> with no special style).
21 // Lays out the children in sequence. 22 // Lays out the children in sequence.
22 class CORE_EXPORT NGBlockLayoutAlgorithm : public NGLayoutAlgorithm { 23 class CORE_EXPORT NGBlockLayoutAlgorithm : public NGLayoutAlgorithm {
23 public: 24 public:
24 // Default constructor. 25 // Default constructor.
25 // @param style Style reference of the block that is being laid out. 26 // @param style Style reference of the block that is being laid out.
26 // @param first_child Our first child; the algorithm will use its NextSibling 27 // @param first_child Our first child; the algorithm will use its NextSibling
27 // method to access all the children. 28 // method to access all the children.
28 NGBlockLayoutAlgorithm(PassRefPtr<const ComputedStyle>, NGBox* first_child); 29 // @param space The constraint space which the algorithm should generate a
30 // fragment within.
31 NGBlockLayoutAlgorithm(PassRefPtr<const ComputedStyle>,
32 NGBox* first_child,
33 NGConstraintSpace* space);
29 34
30 // Actual layout implementation. Lays out the children in sequence within the 35 bool Layout(NGPhysicalFragment**) override;
31 // constraints given by the NGConstraintSpace. Returns a fragment with the
32 // resulting layout information.
33 // This function can not be const because for interruptible layout, we have
34 // to be able to store state information.
35 // Returns true when done; when this function returns false, it has to be
36 // called again. The out parameter will only be set when this function
37 // returns true. The same constraint space has to be passed each time.
38 bool Layout(const NGConstraintSpace*, NGPhysicalFragment**) override;
39 36
40 DECLARE_VIRTUAL_TRACE(); 37 DECLARE_VIRTUAL_TRACE();
41 38
42 private: 39 private:
40 bool LayoutCurrentChild();
41
43 // Computes collapsed margins for 2 adjoining blocks and updates the resultant 42 // Computes collapsed margins for 2 adjoining blocks and updates the resultant
44 // fragment's MarginStrut if needed. 43 // fragment's MarginStrut if needed.
45 // See https://www.w3.org/TR/CSS2/box.html#collapsing-margins 44 // See https://www.w3.org/TR/CSS2/box.html#collapsing-margins
46 // 45 //
47 // @param space Constraint space for the block.
48 // @param child_margins Margins information for the current child. 46 // @param child_margins Margins information for the current child.
49 // @param fragment Current child's fragment. 47 // @param fragment Current child's fragment.
50 // @return NGBoxStrut with margins block start/end. 48 // @return NGBoxStrut with margins block start/end.
51 NGBoxStrut CollapseMargins(const NGConstraintSpace& space, 49 NGBoxStrut CollapseMargins(const NGBoxStrut& child_margins,
52 const NGBoxStrut& child_margins,
53 const NGFragment& fragment); 50 const NGFragment& fragment);
54 51
55 // Calculates position of the in-flow block-level fragment that needs to be 52 // Calculates position of the in-flow block-level fragment that needs to be
56 // positioned relative to the current fragment that is being built. 53 // positioned relative to the current fragment that is being built.
57 // 54 //
58 // @param fragment Fragment that needs to be placed. 55 // @param fragment Fragment that needs to be placed.
59 // @param child_margins Margins information for the current child fragment. 56 // @param child_margins Margins information for the current child fragment.
60 // @param space Constraint space for the block.
61 // @return Position of the fragment in the parent's constraint space. 57 // @return Position of the fragment in the parent's constraint space.
62 NGLogicalOffset PositionFragment(const NGFragment& fragment, 58 NGLogicalOffset PositionFragment(const NGFragment& fragment,
63 const NGBoxStrut& child_margins, 59 const NGBoxStrut& child_margins);
64 const NGConstraintSpace& space);
65 60
66 // Calculates position of the float fragment that needs to be 61 // Calculates position of the float fragment that needs to be
67 // positioned relative to the current fragment that is being built. 62 // positioned relative to the current fragment that is being built.
68 // 63 //
69 // @param fragment Fragment that needs to be placed. 64 // @param fragment Fragment that needs to be placed.
70 // @param margins Margins information for the fragment. 65 // @param margins Margins information for the fragment.
71 // @return Position of the fragment in the parent's constraint space. 66 // @return Position of the fragment in the parent's constraint space.
72 NGLogicalOffset PositionFloatFragment(const NGFragment& fragment, 67 NGLogicalOffset PositionFloatFragment(const NGFragment& fragment,
73 const NGBoxStrut& margins); 68 const NGBoxStrut& margins);
74 69
75 // Updates block-{start|end} of the currently constructed fragment. 70 // Updates block-{start|end} of the currently constructed fragment.
76 // 71 //
77 // This method is supposed to be called on every child but it only updates 72 // This method is supposed to be called on every child but it only updates
78 // the block-start once (on the first non-zero height child fragment) and 73 // the block-start once (on the first non-zero height child fragment) and
79 // keeps updating block-end (on every non-zero height child). 74 // keeps updating block-end (on every non-zero height child).
80 void UpdateMarginStrut(const NGMarginStrut& from); 75 void UpdateMarginStrut(const NGMarginStrut& from);
81 76
82 bool LayoutCurrentChild(const NGConstraintSpace*); 77 // Creates a new constraint space for the current child. Should be called
78 // prior to performing layout on the next child.
79 //
80 // @return The constraint space for the child.
81 NGConstraintSpace* CreateConstraintSpaceForCurrentChild();
83 82
84 // Read-only Getters. 83 // Read-only Getters.
85 const ComputedStyle& Style() const { return *style_; } 84 const ComputedStyle& Style() const { return *style_; }
86 85
87 RefPtr<const ComputedStyle> style_;
88 Member<NGBox> first_child_;
89
90 enum State { kStateInit, kStateChildLayout, kStateFinalize }; 86 enum State { kStateInit, kStateChildLayout, kStateFinalize };
91 State state_; 87 State state_;
88
89 RefPtr<const ComputedStyle> style_;
90
91 Member<NGBox> first_child_;
92 Member<NGConstraintSpace> constraint_space_;
92 Member<NGFragmentBuilder> builder_; 93 Member<NGFragmentBuilder> builder_;
93 Member<NGConstraintSpace> constraint_space_for_children_; 94 Member<NGConstraintSpaceBuilder> space_builder_;
95 Member<NGConstraintSpace> space_for_current_child_;
94 Member<NGBox> current_child_; 96 Member<NGBox> current_child_;
97
95 NGBoxStrut border_and_padding_; 98 NGBoxStrut border_and_padding_;
96 LayoutUnit content_size_; 99 LayoutUnit content_size_;
97 LayoutUnit max_inline_size_; 100 LayoutUnit max_inline_size_;
98 // MarginStrut for the previous child. 101 // MarginStrut for the previous child.
99 NGMarginStrut prev_child_margin_strut_; 102 NGMarginStrut prev_child_margin_strut_;
100 // Whether the block-start was set for the currently built 103 // Whether the block-start was set for the currently built
101 // fragment's margin strut. 104 // fragment's margin strut.
102 bool is_fragment_margin_strut_block_start_updated_ : 1; 105 bool is_fragment_margin_strut_block_start_updated_ : 1;
103 }; 106 };
104 107
105 } // namespace blink 108 } // namespace blink
106 109
107 #endif // NGBlockLayoutAlgorithm_h 110 #endif // NGBlockLayoutAlgorithm_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698