forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch adds NGLineBoxFragment, along with: - NGPhysicalLineBoxFragment - NGLineBoxFragmentBuilder - NGTextFragmentBuilder for consistency Part of code in NGLineBuilder was extracted to new classes, in preparation of renaming it to NGLineLayoutAlgorithm. NGFragment::Overflow was moved to NGBoxFragment, since neither text nor linebox has layout overflow. All types of fragments have ink overflow, but this is not included in this CL. Some of NGFragmentBuilders could be shared as super classes. This is not in this CL but to be discussed further. This patch moves one step towards computing baseline position from NGFragment, but its implementation is not included in this CL. BUG=636993 Review-Url: https://codereview.chromium.org/2764753007 Cr-Commit-Position: refs/heads/master@{#459446}
- Loading branch information
Showing
26 changed files
with
579 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
third_party/WebKit/Source/core/layout/ng/ng_line_box_fragment.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// 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.h" | ||
|
||
namespace blink {} // namespace blink |
30 changes: 30 additions & 0 deletions
30
third_party/WebKit/Source/core/layout/ng/ng_line_box_fragment.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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. | ||
|
||
#ifndef NGLineBoxFragment_h | ||
#define NGLineBoxFragment_h | ||
|
||
#include "core/CoreExport.h" | ||
#include "core/layout/ng/ng_fragment.h" | ||
#include "core/layout/ng/ng_physical_line_box_fragment.h" | ||
#include "core/layout/ng/ng_writing_mode.h" | ||
|
||
namespace blink { | ||
|
||
class CORE_EXPORT NGLineBoxFragment final : public NGFragment { | ||
public: | ||
NGLineBoxFragment(NGWritingMode writing_mode, | ||
const NGPhysicalLineBoxFragment* physical_fragment) | ||
: NGFragment(writing_mode, physical_fragment) {} | ||
}; | ||
|
||
DEFINE_TYPE_CASTS(NGLineBoxFragment, | ||
NGFragment, | ||
fragment, | ||
fragment->Type() == NGPhysicalFragment::kFragmentLineBox, | ||
fragment.Type() == NGPhysicalFragment::kFragmentLineBox); | ||
|
||
} // namespace blink | ||
|
||
#endif // NGLineBoxFragment_h |
70 changes: 70 additions & 0 deletions
70
third_party/WebKit/Source/core/layout/ng/ng_line_box_fragment_builder.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
57 changes: 57 additions & 0 deletions
57
third_party/WebKit/Source/core/layout/ng/ng_line_box_fragment_builder.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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. | ||
|
||
#ifndef NGLineBoxFragmentBuilder_h | ||
#define NGLineBoxFragmentBuilder_h | ||
|
||
#include "core/layout/ng/geometry/ng_logical_offset.h" | ||
#include "core/layout/ng/ng_line_height_metrics.h" | ||
#include "wtf/Allocator.h" | ||
|
||
namespace blink { | ||
|
||
class NGInlineNode; | ||
class NGPhysicalFragment; | ||
class NGPhysicalLineBoxFragment; | ||
|
||
class CORE_EXPORT NGLineBoxFragmentBuilder final { | ||
STACK_ALLOCATED(); | ||
|
||
public: | ||
NGLineBoxFragmentBuilder(NGInlineNode*); | ||
|
||
NGLineBoxFragmentBuilder& SetDirection(TextDirection); | ||
|
||
NGLineBoxFragmentBuilder& SetInlineSize(LayoutUnit); | ||
|
||
NGLineBoxFragmentBuilder& AddChild(RefPtr<NGPhysicalFragment>, | ||
const NGLogicalOffset&); | ||
void MoveChildrenInBlockDirection(LayoutUnit); | ||
|
||
const Vector<RefPtr<NGPhysicalFragment>>& Children() const { | ||
return children_; | ||
} | ||
|
||
void UniteMetrics(const NGLineHeightMetrics&); | ||
const NGLineHeightMetrics& Metrics() const { return metrics_; } | ||
|
||
// Creates the fragment. Can only be called once. | ||
RefPtr<NGPhysicalLineBoxFragment> ToLineBoxFragment(); | ||
|
||
private: | ||
TextDirection direction_; | ||
|
||
Persistent<NGInlineNode> node_; | ||
|
||
LayoutUnit inline_size_; | ||
|
||
Vector<RefPtr<NGPhysicalFragment>> children_; | ||
Vector<NGLogicalOffset> offsets_; | ||
|
||
NGLineHeightMetrics metrics_; | ||
}; | ||
|
||
} // namespace blink | ||
|
||
#endif // NGLineBoxFragmentBuilder |
Oops, something went wrong.