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_break_token.h" | |
| 7 #include "core/layout/ng/ng_block_node.h" | 8 #include "core/layout/ng/ng_block_node.h" |
| 8 #include "core/layout/ng/ng_break_token.h" | 9 #include "core/layout/ng/ng_break_token.h" |
| 9 #include "core/layout/ng/ng_fragment.h" | 10 #include "core/layout/ng/ng_fragment.h" |
| 10 #include "core/layout/ng/ng_physical_box_fragment.h" | 11 #include "core/layout/ng/ng_physical_box_fragment.h" |
| 11 #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" | |
| 12 | 14 |
| 13 namespace blink { | 15 namespace blink { |
| 14 | 16 |
| 15 // TODO(ikilpatrick): Make writing mode and direction be in the constructor. | 17 // TODO(ikilpatrick): Make writing mode and direction be in the constructor. |
| 16 NGFragmentBuilder::NGFragmentBuilder(NGPhysicalFragment::NGFragmentType type, | 18 NGFragmentBuilder::NGFragmentBuilder(NGPhysicalFragment::NGFragmentType type, |
| 17 NGLayoutInputNode* node) | 19 NGLayoutInputNode* node) |
| 18 : type_(type), | 20 : type_(type), |
| 19 writing_mode_(kHorizontalTopBottom), | 21 writing_mode_(kHorizontalTopBottom), |
| 20 direction_(TextDirection::kLtr), | 22 direction_(TextDirection::kLtr), |
| 21 node_(node) {} | 23 node_(node), |
| 24 did_break_(false) { | |
| 25 child_break_tokens_ = new HeapVector<Member<NGBreakToken>>(); | |
| 26 } | |
| 22 | 27 |
| 23 NGFragmentBuilder& NGFragmentBuilder::SetWritingMode( | 28 NGFragmentBuilder& NGFragmentBuilder::SetWritingMode( |
| 24 NGWritingMode writing_mode) { | 29 NGWritingMode writing_mode) { |
| 25 writing_mode_ = writing_mode; | 30 writing_mode_ = writing_mode; |
| 26 return *this; | 31 return *this; |
| 27 } | 32 } |
| 28 | 33 |
| 29 NGFragmentBuilder& NGFragmentBuilder::SetDirection(TextDirection direction) { | 34 NGFragmentBuilder& NGFragmentBuilder::SetDirection(TextDirection direction) { |
| 30 direction_ = direction; | 35 direction_ = direction; |
| 31 return *this; | 36 return *this; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 | 74 |
| 70 return AddChild(child->PhysicalFragment(), child_offset); | 75 return AddChild(child->PhysicalFragment(), child_offset); |
| 71 } | 76 } |
| 72 | 77 |
| 73 NGFragmentBuilder& NGFragmentBuilder::AddChild( | 78 NGFragmentBuilder& NGFragmentBuilder::AddChild( |
| 74 RefPtr<NGPhysicalFragment> child, | 79 RefPtr<NGPhysicalFragment> child, |
| 75 const NGLogicalOffset& child_offset) { | 80 const NGLogicalOffset& child_offset) { |
| 76 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox) | 81 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox) |
| 77 << "Only box fragments can have children"; | 82 << "Only box fragments can have children"; |
| 78 | 83 |
| 84 if (child->Type() == NGPhysicalBoxFragment::NGFragmentType::kFragmentBox && | |
|
Gleb Lanbin
2017/02/24 21:51:28
just
did_break_ = child->Type() ==
NGPhysicalBoxF
ikilpatrick
2017/02/25 00:57:22
Done.
| |
| 85 !child->BreakToken()->IsFinished()) { | |
| 86 // We have an unfinished child, we must produce an unfinished break token. | |
| 87 did_break_ = true; | |
| 88 } | |
| 89 | |
| 90 child_break_tokens_->push_back(child->BreakToken()); | |
| 79 children_.push_back(std::move(child)); | 91 children_.push_back(std::move(child)); |
| 80 offsets_.push_back(child_offset); | 92 offsets_.push_back(child_offset); |
| 81 | 93 |
| 82 return *this; | 94 return *this; |
| 83 } | 95 } |
| 84 | 96 |
| 85 NGFragmentBuilder& NGFragmentBuilder::AddFloatingObject( | 97 NGFragmentBuilder& NGFragmentBuilder::AddFloatingObject( |
| 86 NGFloatingObject* floating_object, | 98 NGFloatingObject* floating_object, |
| 87 const NGLogicalOffset& floating_object_offset) { | 99 const NGLogicalOffset& floating_object_offset) { |
| 88 positioned_floats_.push_back(floating_object); | 100 positioned_floats_.push_back(floating_object); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 out_of_flow_descendants_.add(descendant); | 162 out_of_flow_descendants_.add(descendant); |
| 151 out_of_flow_positions_.push_back(position); | 163 out_of_flow_positions_.push_back(position); |
| 152 return *this; | 164 return *this; |
| 153 } | 165 } |
| 154 | 166 |
| 155 RefPtr<NGLayoutResult> NGFragmentBuilder::ToBoxFragment() { | 167 RefPtr<NGLayoutResult> NGFragmentBuilder::ToBoxFragment() { |
| 156 // TODO(layout-ng): Support text fragments | 168 // TODO(layout-ng): Support text fragments |
| 157 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox); | 169 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox); |
| 158 DCHECK_EQ(offsets_.size(), children_.size()); | 170 DCHECK_EQ(offsets_.size(), children_.size()); |
| 159 | 171 |
| 160 auto* break_token = break_token_.get(); | |
| 161 break_token_ = nullptr; | |
| 162 | |
| 163 NGPhysicalSize physical_size = size_.ConvertToPhysical(writing_mode_); | 172 NGPhysicalSize physical_size = size_.ConvertToPhysical(writing_mode_); |
| 164 | 173 |
| 165 for (size_t i = 0; i < children_.size(); ++i) { | 174 for (size_t i = 0; i < children_.size(); ++i) { |
| 166 NGPhysicalFragment* child = children_[i].get(); | 175 NGPhysicalFragment* child = children_[i].get(); |
| 167 child->SetOffset(offsets_[i].ConvertToPhysical( | 176 child->SetOffset(offsets_[i].ConvertToPhysical( |
| 168 writing_mode_, direction_, physical_size, child->Size())); | 177 writing_mode_, direction_, physical_size, child->Size())); |
| 169 } | 178 } |
| 170 | 179 |
| 171 Vector<Persistent<NGFloatingObject>> positioned_floats; | 180 Vector<Persistent<NGFloatingObject>> positioned_floats; |
| 172 positioned_floats.reserveCapacity(positioned_floats_.size()); | 181 positioned_floats.reserveCapacity(positioned_floats_.size()); |
| 173 | 182 |
| 183 Persistent<NGBreakToken> break_token; | |
| 184 if (did_break_) { | |
| 185 break_token = | |
| 186 new NGBlockBreakToken(toNGBlockNode(node_.get()), used_block_size_, | |
| 187 *child_break_tokens_.get()); | |
| 188 } else { | |
| 189 break_token = new NGBlockBreakToken(node_.get()); | |
| 190 } | |
| 191 | |
| 174 for (size_t i = 0; i < positioned_floats_.size(); ++i) { | 192 for (size_t i = 0; i < positioned_floats_.size(); ++i) { |
| 175 Persistent<NGFloatingObject>& floating_object = positioned_floats_[i]; | 193 Persistent<NGFloatingObject>& floating_object = positioned_floats_[i]; |
| 176 NGPhysicalFragment* floating_fragment = floating_object->fragment.get(); | 194 NGPhysicalFragment* floating_fragment = floating_object->fragment.get(); |
| 177 floating_fragment->SetOffset(floating_object_offsets_[i].ConvertToPhysical( | 195 floating_fragment->SetOffset(floating_object_offsets_[i].ConvertToPhysical( |
| 178 writing_mode_, direction_, physical_size, floating_fragment->Size())); | 196 writing_mode_, direction_, physical_size, floating_fragment->Size())); |
| 179 positioned_floats.push_back(floating_object); | 197 positioned_floats.push_back(floating_object); |
| 180 } | 198 } |
| 181 | 199 |
| 182 RefPtr<NGPhysicalBoxFragment> fragment = adoptRef(new NGPhysicalBoxFragment( | 200 RefPtr<NGPhysicalBoxFragment> fragment = adoptRef(new NGPhysicalBoxFragment( |
| 183 node_->GetLayoutObject(), physical_size, | 201 node_->GetLayoutObject(), physical_size, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 200 Vector<Persistent<NGFloatingObject>> empty_unpositioned_floats; | 218 Vector<Persistent<NGFloatingObject>> empty_unpositioned_floats; |
| 201 Vector<Persistent<NGFloatingObject>> empty_positioned_floats; | 219 Vector<Persistent<NGFloatingObject>> empty_positioned_floats; |
| 202 | 220 |
| 203 return adoptRef(new NGPhysicalTextFragment( | 221 return adoptRef(new NGPhysicalTextFragment( |
| 204 node_->GetLayoutObject(), toNGInlineNode(node_), index, start_offset, | 222 node_->GetLayoutObject(), toNGInlineNode(node_), index, start_offset, |
| 205 end_offset, size_.ConvertToPhysical(writing_mode_), | 223 end_offset, size_.ConvertToPhysical(writing_mode_), |
| 206 overflow_.ConvertToPhysical(writing_mode_))); | 224 overflow_.ConvertToPhysical(writing_mode_))); |
| 207 } | 225 } |
| 208 | 226 |
| 209 } // namespace blink | 227 } // namespace blink |
| OLD | NEW |