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 #include "core/layout/ng/ng_fragment_builder.h" | 5 #include "core/layout/ng/ng_fragment_builder.h" |
6 #include "core/layout/ng/ng_block_node.h" | 6 #include "core/layout/ng/ng_block_node.h" |
7 #include "core/style/ComputedStyle.h" | 7 #include "core/style/ComputedStyle.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... | |
37 overflow_.inline_size = size; | 37 overflow_.inline_size = size; |
38 return *this; | 38 return *this; |
39 } | 39 } |
40 | 40 |
41 NGFragmentBuilder& NGFragmentBuilder::SetBlockOverflow(LayoutUnit size) { | 41 NGFragmentBuilder& NGFragmentBuilder::SetBlockOverflow(LayoutUnit size) { |
42 overflow_.block_size = size; | 42 overflow_.block_size = size; |
43 return *this; | 43 return *this; |
44 } | 44 } |
45 | 45 |
46 NGFragmentBuilder& NGFragmentBuilder::AddChild(NGFragmentBase* child, | 46 NGFragmentBuilder& NGFragmentBuilder::AddChild(NGFragmentBase* child, |
47 NGLogicalOffset offset) { | 47 NGLogicalOffset child_offset) { |
48 DCHECK_EQ(type_, NGPhysicalFragmentBase::kFragmentBox) | 48 DCHECK_EQ(type_, NGPhysicalFragmentBase::kFragmentBox) |
49 << "Only box fragments can have children"; | 49 << "Only box fragments can have children"; |
50 children_.append(child->PhysicalFragment()); | 50 children_.append(child->PhysicalFragment()); |
51 offsets_.append(offset); | 51 offsets_.append(child_offset); |
52 // Collect child's out of flow descendants. | |
53 // TODO(atotic) All fragments can carry oof descendants. | |
54 // Therefore, oof descendants should move from NGPhysicalFragment to | |
55 // NGPhysicalFragmentBase | |
56 if (child->PhysicalFragment()->Type() == | |
57 NGPhysicalFragmentBase::kFragmentBox) { | |
58 const NGPhysicalFragment* physical_child = | |
59 static_cast<const NGPhysicalFragment*>(&*child->PhysicalFragment()); | |
60 Vector<NGCorner> oof_offsets = physical_child->OutOfFlowOffsets(); | |
ikilpatrick
2016/12/02 21:06:13
This is inducing a copy?
Vector<NGCorner>& oof_of
atotic
2016/12/02 22:19:37
done
| |
61 size_t oof_index = 0; | |
62 for (auto& oof_node : physical_child->OutOfFlowDescendants()) { | |
63 NGCorner oof_corner = oof_offsets[oof_index++]; | |
64 out_of_flow_descendant_candidates_.add(oof_node); | |
65 out_of_flow_candidate_placements_.append( | |
66 OutOfFlowPlacement{child_offset, oof_corner}); | |
67 } | |
68 } | |
52 return *this; | 69 return *this; |
53 } | 70 } |
54 | 71 |
72 NGFragmentBuilder& NGFragmentBuilder::AddOutOfFlowChildCandidate( | |
73 NGBlockNode* child, | |
74 NGLogicalOffset child_offset) { | |
75 out_of_flow_descendant_candidates_.add(child); | |
76 NGCorner child_corner = | |
77 NGCorner::Create(writing_mode_, direction_, NGPhysicalOffset()); | |
78 out_of_flow_candidate_placements_.append( | |
79 OutOfFlowPlacement{child_offset, child_corner}); | |
80 return *this; | |
81 } | |
82 | |
83 void NGFragmentBuilder::GetOutOfFlowDescendantCandidates( | |
84 WeakBoxList* descendants, | |
85 Vector<NGCorner>* descendant_corners) { | |
86 DCHECK(descendants->isEmpty()); | |
87 DCHECK(descendant_corners->isEmpty()); | |
88 | |
89 DCHECK_GE(size_.inline_size, LayoutUnit()); | |
90 DCHECK_GE(size_.block_size, LayoutUnit()); | |
91 NGPhysicalSize builder_physical_size{size_.ConvertToPhysical(writing_mode_)}; | |
92 | |
93 size_t placement_index = 0; | |
94 for (auto& oof_node : out_of_flow_descendant_candidates_) { | |
95 OutOfFlowPlacement oof_placement = | |
96 out_of_flow_candidate_placements_[placement_index++]; | |
97 | |
98 NGPhysicalOffset child_offset = | |
99 oof_placement.child_offset.ConvertToPhysical( | |
100 writing_mode_, direction_, builder_physical_size, NGPhysicalSize()); | |
101 | |
102 NGCorner builder_relative_corner; | |
103 builder_relative_corner.type = oof_placement.descendant_corner.type; | |
104 builder_relative_corner.offset = | |
105 child_offset + oof_placement.descendant_corner.offset; | |
106 descendants->add(oof_node); | |
107 descendant_corners->append(builder_relative_corner); | |
108 } | |
109 out_of_flow_descendant_candidates_.clear(); | |
110 out_of_flow_candidate_placements_.clear(); | |
111 } | |
112 | |
113 NGFragmentBuilder& NGFragmentBuilder::AddOutOfFlowDescendant( | |
114 NGBlockNode* descendant, | |
115 const NGCorner& corner) { | |
116 out_of_flow_descendants_.add(descendant); | |
117 out_of_flow_corners_.append(corner); | |
118 return *this; | |
119 } | |
120 | |
55 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockStart( | 121 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockStart( |
56 const NGMarginStrut& from) { | 122 const NGMarginStrut& from) { |
57 margin_strut_.margin_block_start = from.margin_block_start; | 123 margin_strut_.margin_block_start = from.margin_block_start; |
58 margin_strut_.negative_margin_block_start = from.negative_margin_block_start; | 124 margin_strut_.negative_margin_block_start = from.negative_margin_block_start; |
59 return *this; | 125 return *this; |
60 } | 126 } |
61 | 127 |
62 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockEnd( | 128 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockEnd( |
63 const NGMarginStrut& from) { | 129 const NGMarginStrut& from) { |
64 margin_strut_.margin_block_end = from.margin_block_end; | 130 margin_strut_.margin_block_end = from.margin_block_end; |
(...skipping 11 matching lines...) Expand all Loading... | |
76 children.reserveCapacity(children_.size()); | 142 children.reserveCapacity(children_.size()); |
77 | 143 |
78 for (size_t i = 0; i < children_.size(); ++i) { | 144 for (size_t i = 0; i < children_.size(); ++i) { |
79 NGPhysicalFragmentBase* child = children_[i].get(); | 145 NGPhysicalFragmentBase* child = children_[i].get(); |
80 child->SetOffset(offsets_[i].ConvertToPhysical( | 146 child->SetOffset(offsets_[i].ConvertToPhysical( |
81 writing_mode_, direction_, physical_size, child->Size())); | 147 writing_mode_, direction_, physical_size, child->Size())); |
82 children.append(child); | 148 children.append(child); |
83 } | 149 } |
84 return new NGPhysicalFragment( | 150 return new NGPhysicalFragment( |
85 physical_size, overflow_.ConvertToPhysical(writing_mode_), children, | 151 physical_size, overflow_.ConvertToPhysical(writing_mode_), children, |
86 out_of_flow_descendants_, out_of_flow_offsets_, margin_strut_); | 152 out_of_flow_descendants_, out_of_flow_corners_, margin_strut_); |
87 } | 153 } |
88 | 154 |
89 DEFINE_TRACE(NGFragmentBuilder) { | 155 DEFINE_TRACE(NGFragmentBuilder) { |
90 visitor->trace(children_); | 156 visitor->trace(children_); |
157 visitor->trace(out_of_flow_descendant_candidates_); | |
91 visitor->trace(out_of_flow_descendants_); | 158 visitor->trace(out_of_flow_descendants_); |
92 } | 159 } |
93 | 160 |
94 } // namespace blink | 161 } // namespace blink |
OLD | NEW |