| 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_break_token.h" | 7 #include "core/layout/ng/ng_block_break_token.h" |
| 8 #include "core/layout/ng/ng_block_node.h" | 8 #include "core/layout/ng/ng_block_node.h" |
| 9 #include "core/layout/ng/ng_break_token.h" | 9 #include "core/layout/ng/ng_break_token.h" |
| 10 #include "core/layout/ng/ng_fragment.h" | 10 #include "core/layout/ng/ng_fragment.h" |
| 11 #include "core/layout/ng/ng_physical_box_fragment.h" | 11 #include "core/layout/ng/ng_physical_box_fragment.h" |
| 12 #include "core/layout/ng/ng_physical_text_fragment.h" | 12 #include "core/layout/ng/ng_physical_text_fragment.h" |
| 13 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 // TODO(ikilpatrick): Make writing mode and direction be in the constructor. | 17 // TODO(ikilpatrick): Make writing mode and direction be in the constructor. |
| 18 NGFragmentBuilder::NGFragmentBuilder(NGPhysicalFragment::NGFragmentType type, | 18 NGFragmentBuilder::NGFragmentBuilder(NGPhysicalFragment::NGFragmentType type, |
| 19 NGLayoutInputNode* node) | 19 NGLayoutInputNode* node) |
| 20 : type_(type), | 20 : type_(type), |
| 21 writing_mode_(kHorizontalTopBottom), | 21 writing_mode_(kHorizontalTopBottom), |
| 22 direction_(TextDirection::kLtr), | 22 direction_(TextDirection::kLtr), |
| 23 node_(node), | 23 node_(node), |
| 24 did_break_(false) { | 24 did_break_(false) { |
| 25 child_break_tokens_ = new HeapVector<Member<NGBreakToken>>(); | |
| 26 } | 25 } |
| 27 | 26 |
| 28 NGFragmentBuilder& NGFragmentBuilder::SetWritingMode( | 27 NGFragmentBuilder& NGFragmentBuilder::SetWritingMode( |
| 29 NGWritingMode writing_mode) { | 28 NGWritingMode writing_mode) { |
| 30 writing_mode_ = writing_mode; | 29 writing_mode_ = writing_mode; |
| 31 return *this; | 30 return *this; |
| 32 } | 31 } |
| 33 | 32 |
| 34 NGFragmentBuilder& NGFragmentBuilder::SetDirection(TextDirection direction) { | 33 NGFragmentBuilder& NGFragmentBuilder::SetDirection(TextDirection direction) { |
| 35 direction_ = direction; | 34 direction_ = direction; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 76 |
| 78 NGFragmentBuilder& NGFragmentBuilder::AddChild( | 77 NGFragmentBuilder& NGFragmentBuilder::AddChild( |
| 79 RefPtr<NGPhysicalFragment> child, | 78 RefPtr<NGPhysicalFragment> child, |
| 80 const NGLogicalOffset& child_offset) { | 79 const NGLogicalOffset& child_offset) { |
| 81 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox) | 80 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox) |
| 82 << "Only box fragments can have children"; | 81 << "Only box fragments can have children"; |
| 83 | 82 |
| 84 // Update if we have fragmented in this flow. | 83 // Update if we have fragmented in this flow. |
| 85 did_break_ |= child->IsBox() && !child->BreakToken()->IsFinished(); | 84 did_break_ |= child->IsBox() && !child->BreakToken()->IsFinished(); |
| 86 | 85 |
| 87 child_break_tokens_->push_back(child->BreakToken()); | 86 child_break_tokens_.push_back(child->BreakToken()); |
| 88 children_.push_back(std::move(child)); | 87 children_.push_back(std::move(child)); |
| 89 offsets_.push_back(child_offset); | 88 offsets_.push_back(child_offset); |
| 90 | 89 |
| 91 return *this; | 90 return *this; |
| 92 } | 91 } |
| 93 | 92 |
| 94 NGFragmentBuilder& NGFragmentBuilder::AddFloatingObject( | 93 NGFragmentBuilder& NGFragmentBuilder::AddFloatingObject( |
| 95 NGFloatingObject* floating_object, | 94 NGFloatingObject* floating_object, |
| 96 const NGLogicalOffset& floating_object_offset) { | 95 const NGLogicalOffset& floating_object_offset) { |
| 97 positioned_floats_.push_back(floating_object); | 96 positioned_floats_.push_back(floating_object); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 169 |
| 171 for (size_t i = 0; i < children_.size(); ++i) { | 170 for (size_t i = 0; i < children_.size(); ++i) { |
| 172 NGPhysicalFragment* child = children_[i].get(); | 171 NGPhysicalFragment* child = children_[i].get(); |
| 173 child->SetOffset(offsets_[i].ConvertToPhysical( | 172 child->SetOffset(offsets_[i].ConvertToPhysical( |
| 174 writing_mode_, direction_, physical_size, child->Size())); | 173 writing_mode_, direction_, physical_size, child->Size())); |
| 175 } | 174 } |
| 176 | 175 |
| 177 Vector<Persistent<NGFloatingObject>> positioned_floats; | 176 Vector<Persistent<NGFloatingObject>> positioned_floats; |
| 178 positioned_floats.reserveCapacity(positioned_floats_.size()); | 177 positioned_floats.reserveCapacity(positioned_floats_.size()); |
| 179 | 178 |
| 180 Persistent<NGBreakToken> break_token; | 179 RefPtr<NGBreakToken> break_token; |
| 181 if (did_break_) { | 180 if (did_break_) { |
| 182 break_token = | 181 break_token = NGBlockBreakToken::create( |
| 183 new NGBlockBreakToken(toNGBlockNode(node_.get()), used_block_size_, | 182 toNGBlockNode(node_.get()), used_block_size_, child_break_tokens_); |
| 184 *child_break_tokens_.get()); | |
| 185 } else { | 183 } else { |
| 186 break_token = new NGBlockBreakToken(node_.get()); | 184 break_token = NGBlockBreakToken::create(node_.get()); |
| 187 } | 185 } |
| 188 | 186 |
| 189 for (size_t i = 0; i < positioned_floats_.size(); ++i) { | 187 for (size_t i = 0; i < positioned_floats_.size(); ++i) { |
| 190 Persistent<NGFloatingObject>& floating_object = positioned_floats_[i]; | 188 Persistent<NGFloatingObject>& floating_object = positioned_floats_[i]; |
| 191 NGPhysicalFragment* floating_fragment = floating_object->fragment.get(); | 189 NGPhysicalFragment* floating_fragment = floating_object->fragment.get(); |
| 192 floating_fragment->SetOffset(floating_object_offsets_[i].ConvertToPhysical( | 190 floating_fragment->SetOffset(floating_object_offsets_[i].ConvertToPhysical( |
| 193 writing_mode_, direction_, physical_size, floating_fragment->Size())); | 191 writing_mode_, direction_, physical_size, floating_fragment->Size())); |
| 194 positioned_floats.push_back(floating_object); | 192 positioned_floats.push_back(floating_object); |
| 195 } | 193 } |
| 196 | 194 |
| 197 RefPtr<NGPhysicalBoxFragment> fragment = adoptRef(new NGPhysicalBoxFragment( | 195 RefPtr<NGPhysicalBoxFragment> fragment = adoptRef(new NGPhysicalBoxFragment( |
| 198 node_->GetLayoutObject(), physical_size, | 196 node_->GetLayoutObject(), physical_size, |
| 199 overflow_.ConvertToPhysical(writing_mode_), children_, positioned_floats_, | 197 overflow_.ConvertToPhysical(writing_mode_), children_, positioned_floats_, |
| 200 bfc_offset_, end_margin_strut_, break_token)); | 198 bfc_offset_, end_margin_strut_, std::move(break_token))); |
| 201 | 199 |
| 202 return adoptRef( | 200 return adoptRef( |
| 203 new NGLayoutResult(std::move(fragment), out_of_flow_descendants_, | 201 new NGLayoutResult(std::move(fragment), out_of_flow_descendants_, |
| 204 out_of_flow_positions_, unpositioned_floats_)); | 202 out_of_flow_positions_, unpositioned_floats_)); |
| 205 } | 203 } |
| 206 | 204 |
| 207 RefPtr<NGPhysicalTextFragment> NGFragmentBuilder::ToTextFragment( | 205 RefPtr<NGPhysicalTextFragment> NGFragmentBuilder::ToTextFragment( |
| 208 unsigned index, | 206 unsigned index, |
| 209 unsigned start_offset, | 207 unsigned start_offset, |
| 210 unsigned end_offset) { | 208 unsigned end_offset) { |
| 211 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentText); | 209 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentText); |
| 212 DCHECK(children_.isEmpty()); | 210 DCHECK(children_.isEmpty()); |
| 213 DCHECK(offsets_.isEmpty()); | 211 DCHECK(offsets_.isEmpty()); |
| 214 | 212 |
| 215 Vector<Persistent<NGFloatingObject>> empty_unpositioned_floats; | 213 Vector<Persistent<NGFloatingObject>> empty_unpositioned_floats; |
| 216 Vector<Persistent<NGFloatingObject>> empty_positioned_floats; | 214 Vector<Persistent<NGFloatingObject>> empty_positioned_floats; |
| 217 | 215 |
| 218 return adoptRef(new NGPhysicalTextFragment( | 216 return adoptRef(new NGPhysicalTextFragment( |
| 219 node_->GetLayoutObject(), toNGInlineNode(node_), index, start_offset, | 217 node_->GetLayoutObject(), toNGInlineNode(node_), index, start_offset, |
| 220 end_offset, size_.ConvertToPhysical(writing_mode_), | 218 end_offset, size_.ConvertToPhysical(writing_mode_), |
| 221 overflow_.ConvertToPhysical(writing_mode_))); | 219 overflow_.ConvertToPhysical(writing_mode_))); |
| 222 } | 220 } |
| 223 | 221 |
| 224 } // namespace blink | 222 } // namespace blink |
| OLD | NEW |