OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/layout/ng/ng_line_box_fragment_builder.h" |
| 6 |
| 7 #include "core/layout/ng/geometry/ng_logical_size.h" |
| 8 #include "core/layout/ng/ng_fragment.h" |
| 9 #include "core/layout/ng/ng_inline_node.h" |
| 10 #include "core/layout/ng/ng_physical_line_box_fragment.h" |
| 11 #include "platform/heap/Handle.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 NGLineBoxFragmentBuilder::NGLineBoxFragmentBuilder(NGInlineNode* node) |
| 16 : direction_(TextDirection::kLtr), node_(node) {} |
| 17 |
| 18 NGLineBoxFragmentBuilder& NGLineBoxFragmentBuilder::SetDirection( |
| 19 TextDirection direction) { |
| 20 direction_ = direction; |
| 21 return *this; |
| 22 } |
| 23 |
| 24 NGLineBoxFragmentBuilder& NGLineBoxFragmentBuilder::SetInlineSize( |
| 25 LayoutUnit size) { |
| 26 inline_size_ = size; |
| 27 return *this; |
| 28 } |
| 29 |
| 30 NGLineBoxFragmentBuilder& NGLineBoxFragmentBuilder::AddChild( |
| 31 RefPtr<NGPhysicalFragment> child, |
| 32 const NGLogicalOffset& child_offset) { |
| 33 children_.push_back(std::move(child)); |
| 34 offsets_.push_back(child_offset); |
| 35 |
| 36 return *this; |
| 37 } |
| 38 |
| 39 void NGLineBoxFragmentBuilder::MoveChildrenInBlockDirection(LayoutUnit delta) { |
| 40 for (auto& offset : offsets_) |
| 41 offset.block_offset += delta; |
| 42 } |
| 43 |
| 44 void NGLineBoxFragmentBuilder::UniteMetrics( |
| 45 const NGLineHeightMetrics& metrics) { |
| 46 metrics_.Unite(metrics); |
| 47 } |
| 48 |
| 49 RefPtr<NGPhysicalLineBoxFragment> |
| 50 NGLineBoxFragmentBuilder::ToLineBoxFragment() { |
| 51 DCHECK_EQ(offsets_.size(), children_.size()); |
| 52 |
| 53 NGWritingMode writing_mode( |
| 54 FromPlatformWritingMode(node_->BlockStyle()->getWritingMode())); |
| 55 NGPhysicalSize physical_size = |
| 56 NGLogicalSize(inline_size_, Metrics().LineHeight()) |
| 57 .ConvertToPhysical(writing_mode); |
| 58 |
| 59 for (size_t i = 0; i < children_.size(); ++i) { |
| 60 NGPhysicalFragment* child = children_[i].get(); |
| 61 child->SetOffset(offsets_[i].ConvertToPhysical( |
| 62 writing_mode, direction_, physical_size, child->Size())); |
| 63 } |
| 64 |
| 65 // TODO(kojii): Implement BreakToken. |
| 66 return adoptRef(new NGPhysicalLineBoxFragment(physical_size, children_, |
| 67 metrics_, nullptr)); |
| 68 } |
| 69 |
| 70 } // namespace blink |
OLD | NEW |