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

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 comments 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.
(...skipping 16 matching lines...) Expand all
38 NGBlockBreakToken* break_token = nullptr); 39 NGBlockBreakToken* break_token = nullptr);
39 40
40 Optional<MinMaxContentSize> ComputeMinMaxContentSize() const override; 41 Optional<MinMaxContentSize> ComputeMinMaxContentSize() const override;
41 virtual RefPtr<NGLayoutResult> Layout() override; 42 virtual RefPtr<NGLayoutResult> Layout() override;
42 43
43 private: 44 private:
44 NGBoxStrut CalculateMargins(NGLayoutInputNode* child, 45 NGBoxStrut CalculateMargins(NGLayoutInputNode* child,
45 const NGConstraintSpace& space); 46 const NGConstraintSpace& space);
46 47
47 // Creates a new constraint space for the current child. 48 // Creates a new constraint space for the current child.
48 RefPtr<NGConstraintSpace> CreateConstraintSpaceForChild(NGLayoutInputNode*); 49 RefPtr<NGConstraintSpace> CreateConstraintSpaceForChild(
49 void PrepareChildLayout(NGLayoutInputNode*); 50 const NGLogicalOffset& child_bfc_offset,
50 void FinishChildLayout(NGLayoutInputNode*, 51 NGLayoutInputNode*);
51 NGConstraintSpace*, 52 NGLogicalOffset PrepareChildLayout(NGLayoutInputNode*);
cbiesinger 2017/04/18 19:36:43 This needs a comment about what this is returning
52 RefPtr<NGLayoutResult>); 53
54 void FinishChildLayout(const NGConstraintSpace*, NGLayoutResult*);
55
56 // Positions the fragment that establishes a new formatting context.
57 //
58 // This uses Layout Opportunity iterator to position the fragment.
59 // That's because an element that establishes a new block formatting context
60 // must not overlap the margin box of any floats in the same block formatting
61 // context as the element itself.
62 //
63 // So if necessary, we clear the new BFC by placing it below any preceding
64 // floats or place it adjacent to such floats if there is sufficient space.
65 //
66 // Example:
67 // <div id="container">
68 // <div id="float"></div>
69 // <div id="new-fc" style="margin-top: 20px;"></div>
70 // </div>
71 // 1) If #new-fc is small enough to fit the available space right from #float
72 // then it will be placed there and we collapse its margin.
73 // 2) If #new-fc is too big then we need to clear its position and place it
74 // below #float ignoring its vertical margin.
75 NGLogicalOffset PositionNewFc(const NGBoxFragment&,
76 const NGConstraintSpace& child_space);
77
78 // Positions the fragment that knows its BFC offset.
79 NGLogicalOffset PositionWithBfcOffset(const NGBoxFragment&);
80
81 // Positions using the parent BFC offset.
82 // Fragment doesn't know its offset but we can still calculate its BFC
83 // position because the parent fragment's BFC is known.
84 // Example:
85 // BFC Offset is known here because of the padding.
86 // <div style="padding: 1px">
87 // <div id="empty-div" style="margins: 1px"></div>
88 NGLogicalOffset PositionWithParentBfc();
89
90 void FinishFloatChildLayout(const ComputedStyle&,
91 const NGConstraintSpace&,
92 const NGLayoutResult*);
53 93
54 // Final adjustments before fragment creation. We need to prevent the 94 // Final adjustments before fragment creation. We need to prevent the
55 // fragment from crossing fragmentainer boundaries, and rather create a break 95 // fragment from crossing fragmentainer boundaries, and rather create a break
56 // token if we're out of space. 96 // token if we're out of space.
57 void FinalizeForFragmentation(); 97 void FinalizeForFragmentation();
58 98
59 // Calculates logical offset for the current fragment using either 99 // Calculates logical offset for the current fragment using either
60 // {@code content_size_} when the fragment doesn't know it's offset 100 // {@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 101 // or {@code known_fragment_offset} if the fragment knows it's offset
62 // @return Fragment's offset relative to the fragment's parent. 102 // @return Fragment's offset relative to the fragment's parent.
63 NGLogicalOffset CalculateLogicalOffset( 103 NGLogicalOffset CalculateLogicalOffset(
64 const WTF::Optional<NGLogicalOffset>& known_fragment_offset); 104 const WTF::Optional<NGLogicalOffset>& known_fragment_offset);
65 105
66 NGConstraintSpaceBuilder space_builder_; 106 NGConstraintSpaceBuilder space_builder_;
67 107
68 NGBoxStrut border_and_padding_; 108 NGBoxStrut border_and_padding_;
69 LayoutUnit content_size_; 109 LayoutUnit content_size_;
70 LayoutUnit max_inline_size_; 110 LayoutUnit max_inline_size_;
71 // MarginStrut for the previous child. 111 // MarginStrut for the previous child.
72 NGMarginStrut curr_margin_strut_; 112 NGMarginStrut curr_margin_strut_;
73 NGLogicalOffset curr_bfc_offset_; 113 NGLogicalOffset curr_bfc_offset_;
74 NGBoxStrut curr_child_margins_; 114 NGBoxStrut curr_child_margins_;
75 }; 115 };
76 116
77 } // namespace blink 117 } // namespace blink
78 118
79 #endif // NGBlockLayoutAlgorithm_h 119 #endif // NGBlockLayoutAlgorithm_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698