Chromium Code Reviews| 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 | 6 |
| 7 #include "core/layout/ng/ng_block_node.h" | 7 #include "core/layout/ng/ng_block_node.h" |
| 8 #include "core/layout/ng/ng_break_token.h" | 8 #include "core/layout/ng/ng_break_token.h" |
| 9 #include "core/layout/ng/ng_fragment.h" | 9 #include "core/layout/ng/ng_fragment.h" |
| 10 #include "core/layout/ng/ng_physical_box_fragment.h" | 10 #include "core/layout/ng/ng_physical_box_fragment.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 overflow_.inline_size = size; | 45 overflow_.inline_size = size; |
| 46 return *this; | 46 return *this; |
| 47 } | 47 } |
| 48 | 48 |
| 49 NGFragmentBuilder& NGFragmentBuilder::SetBlockOverflow(LayoutUnit size) { | 49 NGFragmentBuilder& NGFragmentBuilder::SetBlockOverflow(LayoutUnit size) { |
| 50 overflow_.block_size = size; | 50 overflow_.block_size = size; |
| 51 return *this; | 51 return *this; |
| 52 } | 52 } |
| 53 | 53 |
| 54 NGFragmentBuilder& NGFragmentBuilder::AddChild( | 54 NGFragmentBuilder& NGFragmentBuilder::AddChild( |
| 55 RefPtr<NGPhysicalFragment> child, | 55 RefPtr<NGLayoutResult> child, |
| 56 const NGLogicalOffset& child_offset) { | 56 const NGLogicalOffset& child_offset) { |
| 57 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox) | 57 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox) |
| 58 << "Only box fragments can have children"; | 58 << "Only box fragments can have children"; |
| 59 | 59 |
| 60 // Collect child's out of flow descendants. | 60 // Collect child's out of flow descendants. |
| 61 const Vector<NGStaticPosition>& oof_positions = child->OutOfFlowPositions(); | 61 const Vector<NGStaticPosition>& oof_positions = child->OutOfFlowPositions(); |
| 62 size_t oof_index = 0; | 62 size_t oof_index = 0; |
| 63 for (auto& oof_node : child->OutOfFlowDescendants()) { | 63 for (auto& oof_node : child->OutOfFlowDescendants()) { |
| 64 NGStaticPosition oof_position = oof_positions[oof_index++]; | 64 NGStaticPosition oof_position = oof_positions[oof_index++]; |
| 65 out_of_flow_descendant_candidates_.add(oof_node); | 65 out_of_flow_descendant_candidates_.add(oof_node); |
| 66 out_of_flow_candidate_placements_.push_back( | 66 out_of_flow_candidate_placements_.push_back( |
| 67 OutOfFlowPlacement{child_offset, oof_position}); | 67 OutOfFlowPlacement{child_offset, oof_position}); |
| 68 } | 68 } |
| 69 | 69 |
| 70 children_.push_back(std::move(child)); | 70 return AddChild(child->PhysicalFragment(), child_offset); |
| 71 } | |
| 72 | |
| 73 NGFragmentBuilder& NGFragmentBuilder::AddChild( | |
| 74 RefPtr<NGPhysicalFragment> child, | |
| 75 const NGLogicalOffset& child_offset) { | |
| 76 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox) | |
| 77 << "Only box fragments can have children"; | |
| 78 | |
| 79 children_.push_back(child); | |
|
ikilpatrick
2017/02/21 22:26:02
std::move()?
cbiesinger
2017/02/22 18:09:00
Also fixed already
| |
| 71 offsets_.push_back(child_offset); | 80 offsets_.push_back(child_offset); |
| 72 | 81 |
| 73 return *this; | 82 return *this; |
| 74 } | 83 } |
| 75 | 84 |
| 76 NGFragmentBuilder& NGFragmentBuilder::AddFloatingObject( | 85 NGFragmentBuilder& NGFragmentBuilder::AddFloatingObject( |
| 77 NGFloatingObject* floating_object, | 86 NGFloatingObject* floating_object, |
| 78 const NGLogicalOffset& floating_object_offset) { | 87 const NGLogicalOffset& floating_object_offset) { |
| 79 positioned_floats_.push_back(floating_object); | 88 positioned_floats_.push_back(floating_object); |
| 80 floating_object_offsets_.push_back(floating_object_offset); | 89 floating_object_offsets_.push_back(floating_object_offset); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 } | 145 } |
| 137 | 146 |
| 138 NGFragmentBuilder& NGFragmentBuilder::AddOutOfFlowDescendant( | 147 NGFragmentBuilder& NGFragmentBuilder::AddOutOfFlowDescendant( |
| 139 NGBlockNode* descendant, | 148 NGBlockNode* descendant, |
| 140 const NGStaticPosition& position) { | 149 const NGStaticPosition& position) { |
| 141 out_of_flow_descendants_.add(descendant); | 150 out_of_flow_descendants_.add(descendant); |
| 142 out_of_flow_positions_.push_back(position); | 151 out_of_flow_positions_.push_back(position); |
| 143 return *this; | 152 return *this; |
| 144 } | 153 } |
| 145 | 154 |
| 146 RefPtr<NGPhysicalBoxFragment> NGFragmentBuilder::ToBoxFragment() { | 155 RefPtr<NGLayoutResult> NGFragmentBuilder::ToBoxFragment() { |
| 147 // TODO(layout-ng): Support text fragments | 156 // TODO(layout-ng): Support text fragments |
| 148 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox); | 157 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox); |
| 149 DCHECK_EQ(offsets_.size(), children_.size()); | 158 DCHECK_EQ(offsets_.size(), children_.size()); |
| 150 | 159 |
| 151 auto* break_token = break_token_.get(); | 160 auto* break_token = break_token_.get(); |
| 152 break_token_ = nullptr; | 161 break_token_ = nullptr; |
| 153 | 162 |
| 154 NGPhysicalSize physical_size = size_.ConvertToPhysical(writing_mode_); | 163 NGPhysicalSize physical_size = size_.ConvertToPhysical(writing_mode_); |
| 155 | 164 |
| 156 for (size_t i = 0; i < children_.size(); ++i) { | 165 for (size_t i = 0; i < children_.size(); ++i) { |
| 157 NGPhysicalFragment* child = children_[i].get(); | 166 NGPhysicalFragment* child = children_[i].get(); |
| 158 child->SetOffset(offsets_[i].ConvertToPhysical( | 167 child->SetOffset(offsets_[i].ConvertToPhysical( |
| 159 writing_mode_, direction_, physical_size, child->Size())); | 168 writing_mode_, direction_, physical_size, child->Size())); |
| 160 } | 169 } |
| 161 | 170 |
| 162 Vector<Persistent<NGFloatingObject>> positioned_floats; | 171 Vector<Persistent<NGFloatingObject>> positioned_floats; |
| 163 positioned_floats.reserveCapacity(positioned_floats_.size()); | 172 positioned_floats.reserveCapacity(positioned_floats_.size()); |
| 164 | 173 |
| 165 for (size_t i = 0; i < positioned_floats_.size(); ++i) { | 174 for (size_t i = 0; i < positioned_floats_.size(); ++i) { |
| 166 Persistent<NGFloatingObject>& floating_object = positioned_floats_[i]; | 175 Persistent<NGFloatingObject>& floating_object = positioned_floats_[i]; |
| 167 NGPhysicalFragment* floating_fragment = floating_object->fragment.get(); | 176 NGPhysicalFragment* floating_fragment = floating_object->fragment.get(); |
| 168 floating_fragment->SetOffset(floating_object_offsets_[i].ConvertToPhysical( | 177 floating_fragment->SetOffset(floating_object_offsets_[i].ConvertToPhysical( |
| 169 writing_mode_, direction_, physical_size, floating_fragment->Size())); | 178 writing_mode_, direction_, physical_size, floating_fragment->Size())); |
| 170 positioned_floats.push_back(floating_object); | 179 positioned_floats.push_back(floating_object); |
| 171 } | 180 } |
| 172 | 181 |
| 173 return adoptRef(new NGPhysicalBoxFragment( | 182 RefPtr<NGPhysicalBoxFragment> fragment = adoptRef(new NGPhysicalBoxFragment( |
| 174 layout_object_, physical_size, overflow_.ConvertToPhysical(writing_mode_), | 183 layout_object_, physical_size, overflow_.ConvertToPhysical(writing_mode_), |
| 175 children_, out_of_flow_descendants_, out_of_flow_positions_, | 184 children_, positioned_floats_, bfc_offset_, end_margin_strut_, |
| 176 unpositioned_floats_, positioned_floats_, bfc_offset_, end_margin_strut_, | |
| 177 break_token)); | 185 break_token)); |
| 186 | |
| 187 return adoptRef( | |
| 188 new NGLayoutResult(std::move(fragment), out_of_flow_descendants_, | |
| 189 out_of_flow_positions_, unpositioned_floats_)); | |
| 178 } | 190 } |
| 179 | 191 |
| 180 RefPtr<NGPhysicalTextFragment> NGFragmentBuilder::ToTextFragment( | 192 RefPtr<NGPhysicalTextFragment> NGFragmentBuilder::ToTextFragment( |
| 181 NGInlineNode* node, | 193 NGInlineNode* node, |
| 182 unsigned index, | 194 unsigned index, |
| 183 unsigned start_offset, | 195 unsigned start_offset, |
| 184 unsigned end_offset) { | 196 unsigned end_offset) { |
| 185 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentText); | 197 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentText); |
| 186 DCHECK(children_.isEmpty()); | 198 DCHECK(children_.isEmpty()); |
| 187 DCHECK(offsets_.isEmpty()); | 199 DCHECK(offsets_.isEmpty()); |
| 188 | 200 |
| 189 Vector<Persistent<NGFloatingObject>> empty_unpositioned_floats; | 201 Vector<Persistent<NGFloatingObject>> empty_unpositioned_floats; |
| 190 Vector<Persistent<NGFloatingObject>> empty_positioned_floats; | 202 Vector<Persistent<NGFloatingObject>> empty_positioned_floats; |
| 191 | 203 |
| 192 return adoptRef(new NGPhysicalTextFragment( | 204 return adoptRef(new NGPhysicalTextFragment( |
| 193 layout_object_, node, index, start_offset, end_offset, | 205 layout_object_, node, index, start_offset, end_offset, |
| 194 size_.ConvertToPhysical(writing_mode_), | 206 size_.ConvertToPhysical(writing_mode_), |
| 195 overflow_.ConvertToPhysical(writing_mode_), out_of_flow_descendants_, | 207 overflow_.ConvertToPhysical(writing_mode_))); |
| 196 out_of_flow_positions_, empty_unpositioned_floats, | |
| 197 empty_positioned_floats)); | |
| 198 } | 208 } |
| 199 | 209 |
| 200 } // namespace blink | 210 } // namespace blink |
| OLD | NEW |