Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1374)

Unified Diff: third_party/WebKit/Source/core/layout/ng/ng_line_box_fragment_builder.cc

Issue 2764753007: [LayoutNG] Add NGLineBoxFragment (Closed)
Patch Set: Rebase again as other CLs landed faster Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/ng/ng_line_box_fragment_builder.cc
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_line_box_fragment_builder.cc b/third_party/WebKit/Source/core/layout/ng/ng_line_box_fragment_builder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..28e675750c2ab6a228851322440a0c3f71146c4c
--- /dev/null
+++ b/third_party/WebKit/Source/core/layout/ng/ng_line_box_fragment_builder.cc
@@ -0,0 +1,70 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/layout/ng/ng_line_box_fragment_builder.h"
+
+#include "core/layout/ng/geometry/ng_logical_size.h"
+#include "core/layout/ng/ng_fragment.h"
+#include "core/layout/ng/ng_inline_node.h"
+#include "core/layout/ng/ng_physical_line_box_fragment.h"
+#include "platform/heap/Handle.h"
+
+namespace blink {
+
+NGLineBoxFragmentBuilder::NGLineBoxFragmentBuilder(NGInlineNode* node)
+ : direction_(TextDirection::kLtr), node_(node) {}
+
+NGLineBoxFragmentBuilder& NGLineBoxFragmentBuilder::SetDirection(
+ TextDirection direction) {
+ direction_ = direction;
+ return *this;
+}
+
+NGLineBoxFragmentBuilder& NGLineBoxFragmentBuilder::SetInlineSize(
+ LayoutUnit size) {
+ inline_size_ = size;
+ return *this;
+}
+
+NGLineBoxFragmentBuilder& NGLineBoxFragmentBuilder::AddChild(
+ RefPtr<NGPhysicalFragment> child,
+ const NGLogicalOffset& child_offset) {
+ children_.push_back(std::move(child));
+ offsets_.push_back(child_offset);
+
+ return *this;
+}
+
+void NGLineBoxFragmentBuilder::MoveChildrenInBlockDirection(LayoutUnit delta) {
+ for (auto& offset : offsets_)
+ offset.block_offset += delta;
+}
+
+void NGLineBoxFragmentBuilder::UniteMetrics(
+ const NGLineHeightMetrics& metrics) {
+ metrics_.Unite(metrics);
+}
+
+RefPtr<NGPhysicalLineBoxFragment>
+NGLineBoxFragmentBuilder::ToLineBoxFragment() {
+ DCHECK_EQ(offsets_.size(), children_.size());
+
+ NGWritingMode writing_mode(
+ FromPlatformWritingMode(node_->BlockStyle()->getWritingMode()));
+ NGPhysicalSize physical_size =
+ NGLogicalSize(inline_size_, Metrics().LineHeight())
+ .ConvertToPhysical(writing_mode);
+
+ for (size_t i = 0; i < children_.size(); ++i) {
+ NGPhysicalFragment* child = children_[i].get();
+ child->SetOffset(offsets_[i].ConvertToPhysical(
+ writing_mode, direction_, physical_size, child->Size()));
+ }
+
+ // TODO(kojii): Implement BreakToken.
+ return adoptRef(new NGPhysicalLineBoxFragment(physical_size, children_,
+ metrics_, nullptr));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698