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

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

Issue 2816933003: Use Layout Opportunity Iterator to position new FC blocks. (Closed)
Patch Set: fix block-formatting-contexts-{005|007} Created 3 years, 8 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/geometry/ng_margin_strut.h" 9 #include "core/layout/ng/geometry/ng_margin_strut.h"
10 #include "core/layout/ng/ng_block_break_token.h" 10 #include "core/layout/ng/ng_block_break_token.h"
11 #include "core/layout/ng/ng_block_node.h" 11 #include "core/layout/ng/ng_block_node.h"
12 #include "core/layout/ng/ng_box_fragment.h"
12 #include "core/layout/ng/ng_constraint_space_builder.h" 13 #include "core/layout/ng/ng_constraint_space_builder.h"
13 #include "core/layout/ng/ng_layout_algorithm.h" 14 #include "core/layout/ng/ng_layout_algorithm.h"
14 #include "platform/wtf/RefPtr.h" 15 #include "platform/wtf/RefPtr.h"
15 16
16 namespace blink { 17 namespace blink {
17 18
18 class NGConstraintSpace; 19 class NGConstraintSpace;
19 class NGLayoutResult; 20 class NGLayoutResult;
20 21
21 // Updates the fragment's BFC offset if it's not already set. 22 // Updates the fragment's BFC offset if it's not already set.
22 void MaybeUpdateFragmentBfcOffset(const NGConstraintSpace&, 23 void MaybeUpdateFragmentBfcOffset(const NGConstraintSpace&,
23 const NGLogicalOffset&, 24 const NGLogicalOffset&,
24 NGFragmentBuilder* builder); 25 NGFragmentBuilder* builder);
25 26
27 // Positions pending floats starting from {@origin_block_offset} and relative
28 // to container's BFC offset.
29 void PositionPendingFloats(LayoutUnit origin_block_offset,
30 NGFragmentBuilder* container_builder,
31 NGConstraintSpace* space);
32
26 // A class for general block layout (e.g. a <div> with no special style). 33 // A class for general block layout (e.g. a <div> with no special style).
27 // Lays out the children in sequence. 34 // Lays out the children in sequence.
28 class CORE_EXPORT NGBlockLayoutAlgorithm 35 class CORE_EXPORT NGBlockLayoutAlgorithm
29 : public NGLayoutAlgorithm<NGBlockNode, NGBlockBreakToken> { 36 : public NGLayoutAlgorithm<NGBlockNode, NGBlockBreakToken> {
30 public: 37 public:
31 // Default constructor. 38 // Default constructor.
32 // @param node The input node to perform layout upon. 39 // @param node The input node to perform layout upon.
33 // @param space The constraint space which the algorithm should generate a 40 // @param space The constraint space which the algorithm should generate a
34 // fragment within. 41 // fragment within.
35 // @param break_token The break token from which the layout should start. 42 // @param break_token The break token from which the layout should start.
36 NGBlockLayoutAlgorithm(NGBlockNode* node, 43 NGBlockLayoutAlgorithm(NGBlockNode* node,
37 NGConstraintSpace* space, 44 NGConstraintSpace* space,
38 NGBlockBreakToken* break_token = nullptr); 45 NGBlockBreakToken* break_token = nullptr);
39 46
40 Optional<MinMaxContentSize> ComputeMinMaxContentSize() const override; 47 Optional<MinMaxContentSize> ComputeMinMaxContentSize() const override;
41 virtual RefPtr<NGLayoutResult> Layout() override; 48 virtual RefPtr<NGLayoutResult> Layout() override;
42 49
43 private: 50 private:
44 NGBoxStrut CalculateMargins(NGLayoutInputNode* child, 51 NGBoxStrut CalculateMargins(NGLayoutInputNode* child,
45 const NGConstraintSpace& space); 52 const NGConstraintSpace& space);
46 53
47 // Creates a new constraint space for the current child. 54 // Creates a new constraint space for the current child.
48 RefPtr<NGConstraintSpace> CreateConstraintSpaceForChild(NGLayoutInputNode*); 55 RefPtr<NGConstraintSpace> CreateConstraintSpaceForChild(
49 void PrepareChildLayout(NGLayoutInputNode*); 56 const NGLogicalOffset& child_bfc_offset,
50 void FinishChildLayout(NGLayoutInputNode*, 57 NGLayoutInputNode*);
51 NGConstraintSpace*, 58
52 RefPtr<NGLayoutResult>); 59 // @return Estimated BFC offset for the "to be layout" child.
60 NGLogicalOffset PrepareChildLayout(NGLayoutInputNode*);
61
62 void FinishChildLayout(const NGConstraintSpace*, NGLayoutResult*);
63
64 // Positions the fragment that establishes a new formatting context.
65 //
66 // This uses Layout Opportunity iterator to position the fragment.
67 // That's because an element that establishes a new block formatting context
68 // must not overlap the margin box of any floats in the same block formatting
69 // context as the element itself.
70 //
71 // So if necessary, we clear the new BFC by placing it below any preceding
72 // floats or place it adjacent to such floats if there is sufficient space.
73 //
74 // Example:
75 // <div id="container">
76 // <div id="float"></div>
77 // <div id="new-fc" style="margin-top: 20px;"></div>
78 // </div>
79 // 1) If #new-fc is small enough to fit the available space right from #float
80 // then it will be placed there and we collapse its margin.
81 // 2) If #new-fc is too big then we need to clear its position and place it
82 // below #float ignoring its vertical margin.
83 NGLogicalOffset PositionNewFc(const NGBoxFragment&,
84 const NGConstraintSpace& child_space);
85
86 // Positions the fragment that knows its BFC offset.
87 NGLogicalOffset PositionWithBfcOffset(const NGBoxFragment&);
88
89 // Positions using the parent BFC offset.
90 // Fragment doesn't know its offset but we can still calculate its BFC
91 // position because the parent fragment's BFC is known.
92 // Example:
93 // BFC Offset is known here because of the padding.
94 // <div style="padding: 1px">
95 // <div id="empty-div" style="margins: 1px"></div>
96 NGLogicalOffset PositionWithParentBfc();
97
98 void FinishFloatChildLayout(const ComputedStyle&,
99 const NGConstraintSpace&,
100 const NGLayoutResult*);
53 101
54 // Final adjustments before fragment creation. We need to prevent the 102 // Final adjustments before fragment creation. We need to prevent the
55 // fragment from crossing fragmentainer boundaries, and rather create a break 103 // fragment from crossing fragmentainer boundaries, and rather create a break
56 // token if we're out of space. 104 // token if we're out of space.
57 void FinalizeForFragmentation(); 105 void FinalizeForFragmentation();
58 106
59 // Calculates logical offset for the current fragment using either 107 // Calculates logical offset for the current fragment using either
60 // {@code content_size_} when the fragment doesn't know it's offset 108 // {@code content_size_} when the fragment doesn't know it's offset
61 // or {@code known_fragment_offset} if the fragment knows it's offset 109 // or {@code known_fragment_offset} if the fragment knows it's offset
62 // @return Fragment's offset relative to the fragment's parent. 110 // @return Fragment's offset relative to the fragment's parent.
63 NGLogicalOffset CalculateLogicalOffset( 111 NGLogicalOffset CalculateLogicalOffset(
64 const WTF::Optional<NGLogicalOffset>& known_fragment_offset); 112 const WTF::Optional<NGLogicalOffset>& known_fragment_offset);
65 113
66 NGConstraintSpaceBuilder space_builder_; 114 NGConstraintSpaceBuilder space_builder_;
67 115
68 NGBoxStrut border_and_padding_; 116 NGBoxStrut border_and_padding_;
69 LayoutUnit content_size_; 117 LayoutUnit content_size_;
70 LayoutUnit max_inline_size_; 118 LayoutUnit max_inline_size_;
71 // MarginStrut for the previous child. 119 // MarginStrut for the previous child.
72 NGMarginStrut curr_margin_strut_; 120 NGMarginStrut curr_margin_strut_;
73 NGLogicalOffset curr_bfc_offset_; 121 NGLogicalOffset curr_bfc_offset_;
74 NGBoxStrut curr_child_margins_; 122 NGBoxStrut curr_child_margins_;
75 }; 123 };
76 124
77 } // namespace blink 125 } // namespace blink
78 126
79 #endif // NGBlockLayoutAlgorithm_h 127 #endif // NGBlockLayoutAlgorithm_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698