Commit 4e145f3c authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Add ShapeResult and orientation to NGPhysicalTextFragment

This patch adds ShapeResult and line orientation to
NGPhysicalTextFragment. These properties are not used today, but will be
used in LayoutNGPaintFragments.

Includes cleanup of functions that are no longer used.

BUG=636993
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_layout_ng

Change-Id: Id91f177e8d9d91914144ab138f37f25cd612be2f
Reviewed-on: https://chromium-review.googlesource.com/571883Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Emil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486953}
parent 97e40196
...@@ -33,9 +33,9 @@ struct NGPendingPositions { ...@@ -33,9 +33,9 @@ struct NGPendingPositions {
// require ancestor position or size. // require ancestor position or size.
// This is a transient object only while building line boxes in a block. // This is a transient object only while building line boxes in a block.
struct NGInlineBoxState { struct NGInlineBoxState {
unsigned fragment_start; unsigned fragment_start = 0;
const NGInlineItem* item; const NGInlineItem* item = nullptr;
const ComputedStyle* style; const ComputedStyle* style = nullptr;
// The united metrics for the current box. This includes all objects in this // The united metrics for the current box. This includes all objects in this
// box, including descendants, and adjusted by placement properties such as // box, including descendants, and adjusted by placement properties such as
......
...@@ -38,7 +38,7 @@ struct CORE_EXPORT NGInlineItemResult { ...@@ -38,7 +38,7 @@ struct CORE_EXPORT NGInlineItemResult {
// ShapeResult for text items. Maybe different from NGInlineItem if re-shape // ShapeResult for text items. Maybe different from NGInlineItem if re-shape
// is needed in the line breaker. // is needed in the line breaker.
RefPtr<ShapeResult> shape_result; RefPtr<const ShapeResult> shape_result;
// NGLayoutResult for atomic inline items. // NGLayoutResult for atomic inline items.
RefPtr<NGLayoutResult> layout_result; RefPtr<NGLayoutResult> layout_result;
......
...@@ -166,6 +166,7 @@ bool NGInlineLayoutAlgorithm::PlaceItems( ...@@ -166,6 +166,7 @@ bool NGInlineLayoutAlgorithm::PlaceItems(
box->AccumulateUsedFonts(item, item_result.start_offset, box->AccumulateUsedFonts(item, item_result.start_offset,
item_result.end_offset, baseline_type_); item_result.end_offset, baseline_type_);
} }
text_builder.SetShapeResult(std::move(item_result.shape_result));
RefPtr<NGPhysicalTextFragment> text_fragment = RefPtr<NGPhysicalTextFragment> text_fragment =
text_builder.ToTextFragment(item_result.item_index, text_builder.ToTextFragment(item_result.item_index,
item_result.start_offset, item_result.start_offset,
...@@ -177,7 +178,6 @@ bool NGInlineLayoutAlgorithm::PlaceItems( ...@@ -177,7 +178,6 @@ bool NGInlineLayoutAlgorithm::PlaceItems(
// influence the line height. // influence the line height.
// https://drafts.csswg.org/css2/visudet.html#line-height // https://drafts.csswg.org/css2/visudet.html#line-height
box->ComputeTextMetrics(*item.Style(), baseline_type_); box->ComputeTextMetrics(*item.Style(), baseline_type_);
text_builder.SetDirection(box->style->Direction());
if (ShouldCreateBoxFragment(item, item_result)) if (ShouldCreateBoxFragment(item, item_result))
box->SetNeedsBoxFragment(item_result.needs_box_when_empty); box->SetNeedsBoxFragment(item_result.needs_box_when_empty);
} else if (item.Type() == NGInlineItem::kCloseTag) { } else if (item.Type() == NGInlineItem::kCloseTag) {
...@@ -305,7 +305,6 @@ NGInlineBoxState* NGInlineLayoutAlgorithm::PlaceAtomicInline( ...@@ -305,7 +305,6 @@ NGInlineBoxState* NGInlineLayoutAlgorithm::PlaceAtomicInline(
// TODO(kojii): Try to eliminate the wrapping text fragment and use the // TODO(kojii): Try to eliminate the wrapping text fragment and use the
// |fragment| directly. Currently |CopyFragmentDataToLayoutBlockFlow| // |fragment| directly. Currently |CopyFragmentDataToLayoutBlockFlow|
// requires a text fragment. // requires a text fragment.
text_builder->SetDirection(style.Direction());
text_builder->SetSize({fragment.InlineSize(), metrics.LineHeight()}); text_builder->SetSize({fragment.InlineSize(), metrics.LineHeight()});
LayoutUnit line_top = item_result->margins.block_start - metrics.ascent; LayoutUnit line_top = item_result->margins.block_start - metrics.ascent;
RefPtr<NGPhysicalTextFragment> text_fragment = text_builder->ToTextFragment( RefPtr<NGPhysicalTextFragment> text_fragment = text_builder->ToTextFragment(
......
...@@ -236,6 +236,7 @@ NGLineBreaker::LineBreakState NGLineBreaker::HandleText( ...@@ -236,6 +236,7 @@ NGLineBreaker::LineBreakState NGLineBreaker::HandleText(
MoveToNextOf(item); MoveToNextOf(item);
if (auto_wrap_ && break_iterator_.IsBreakable(item.EndOffset())) if (auto_wrap_ && break_iterator_.IsBreakable(item.EndOffset()))
return LineBreakState::kIsBreakable; return LineBreakState::kIsBreakable;
item_result->shape_result = item.TextShapeResult();
item_result->prohibit_break_after = true; item_result->prohibit_break_after = true;
return LineBreakState::kNotBreakable; return LineBreakState::kNotBreakable;
} }
......
...@@ -13,6 +13,27 @@ ...@@ -13,6 +13,27 @@
namespace blink { namespace blink {
class ShapeResult;
// In CSS Writing Modes Levle 4, line orientation for layout and line
// orientation for paint are not always the same.
//
// Specifically, 'sideways-lr' typesets as if lines are horizontal flow, but
// rotates counterclockwise.
enum class NGLineOrientation {
// Lines are horizontal.
kHorizontal,
// Lines are vertical, rotated clockwise. Inside of the line, it may be
// typeset using vertical characteristics, horizontal characteristics, or
// mixed. Lines flow left to right, or right to left.
kClockWiseVertical,
// Lines are vertical, rotated counterclockwise. Inside of the line is typeset
// as if horizontal flow. Lines flow left to right.
kCounterClockWiseVertical
// When adding new values, ensure NGPhysicalTextFragment has enough bits.
};
class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment { class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment {
public: public:
NGPhysicalTextFragment(LayoutObject* layout_object, NGPhysicalTextFragment(LayoutObject* layout_object,
...@@ -20,21 +41,34 @@ class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment { ...@@ -20,21 +41,34 @@ class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment {
unsigned item_index, unsigned item_index,
unsigned start_offset, unsigned start_offset,
unsigned end_offset, unsigned end_offset,
NGPhysicalSize size) NGPhysicalSize size,
NGLineOrientation line_orientation,
RefPtr<const ShapeResult> shape_result)
: NGPhysicalFragment(layout_object, size, kFragmentText), : NGPhysicalFragment(layout_object, size, kFragmentText),
node_(node), node_(node),
item_index_(item_index), item_index_(item_index),
start_offset_(start_offset), start_offset_(start_offset),
end_offset_(end_offset) {} end_offset_(end_offset),
shape_result_(shape_result),
line_orientation_(static_cast<unsigned>(line_orientation)) {}
const NGInlineNode Node() const { return node_; } const NGInlineNode Node() const { return node_; }
StringView Text() const { return node_.Text(start_offset_, end_offset_); } StringView Text() const { return node_.Text(start_offset_, end_offset_); }
const ShapeResult* TextShapeResult() const { return shape_result_.Get(); }
// The range of NGLayoutInlineItem. // The range of NGLayoutInlineItem.
unsigned ItemIndex() const { return item_index_; } unsigned ItemIndex() const { return item_index_; }
unsigned StartOffset() const { return start_offset_; } unsigned StartOffset() const { return start_offset_; }
unsigned EndOffset() const { return end_offset_; } unsigned EndOffset() const { return end_offset_; }
NGLineOrientation LineOrientation() const {
return static_cast<NGLineOrientation>(line_orientation_);
}
bool IsHorizontal() const {
return LineOrientation() == NGLineOrientation::kHorizontal;
}
private: private:
// TODO(kojii): NGInlineNode is to access text content and NGLayoutInlineItem. // TODO(kojii): NGInlineNode is to access text content and NGLayoutInlineItem.
// Review if it's better to point them. // Review if it's better to point them.
...@@ -42,6 +76,10 @@ class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment { ...@@ -42,6 +76,10 @@ class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment {
unsigned item_index_; unsigned item_index_;
unsigned start_offset_; unsigned start_offset_;
unsigned end_offset_; unsigned end_offset_;
RefPtr<const ShapeResult> shape_result_;
unsigned line_orientation_ : 2; // NGLineOrientation
}; };
DEFINE_TYPE_CASTS(NGPhysicalTextFragment, DEFINE_TYPE_CASTS(NGPhysicalTextFragment,
......
...@@ -11,34 +11,49 @@ ...@@ -11,34 +11,49 @@
namespace blink { namespace blink {
NGTextFragmentBuilder::NGTextFragmentBuilder(NGInlineNode node) namespace {
: direction_(TextDirection::kLtr), node_(node) {}
NGLineOrientation ToLineOrientation(NGWritingMode writing_mode) {
NGTextFragmentBuilder& NGTextFragmentBuilder::SetDirection( switch (writing_mode) {
TextDirection direction) { case NGWritingMode::kHorizontalTopBottom:
direction_ = direction; return NGLineOrientation::kHorizontal;
return *this; case NGWritingMode::kVerticalRightLeft:
case NGWritingMode::kVerticalLeftRight:
case NGWritingMode::kSidewaysRightLeft:
return NGLineOrientation::kClockWiseVertical;
case NGWritingMode::kSidewaysLeftRight:
return NGLineOrientation::kCounterClockWiseVertical;
}
NOTREACHED();
return NGLineOrientation::kHorizontal;
} }
} // namespace
NGTextFragmentBuilder::NGTextFragmentBuilder(NGInlineNode node)
: node_(node),
writing_mode_(FromPlatformWritingMode(node_.Style().GetWritingMode())) {}
NGTextFragmentBuilder& NGTextFragmentBuilder::SetSize( NGTextFragmentBuilder& NGTextFragmentBuilder::SetSize(
const NGLogicalSize& size) { const NGLogicalSize& size) {
size_ = size; size_ = size;
return *this; return *this;
} }
void NGTextFragmentBuilder::UniteMetrics(const NGLineHeightMetrics& metrics) { NGTextFragmentBuilder& NGTextFragmentBuilder::SetShapeResult(
metrics_.Unite(metrics); RefPtr<const ShapeResult> shape_result) {
shape_result_ = shape_result;
return *this;
} }
RefPtr<NGPhysicalTextFragment> NGTextFragmentBuilder::ToTextFragment( RefPtr<NGPhysicalTextFragment> NGTextFragmentBuilder::ToTextFragment(
unsigned index, unsigned index,
unsigned start_offset, unsigned start_offset,
unsigned end_offset) { unsigned end_offset) {
NGWritingMode writing_mode(
FromPlatformWritingMode(node_.Style().GetWritingMode()));
return AdoptRef(new NGPhysicalTextFragment( return AdoptRef(new NGPhysicalTextFragment(
node_.GetLayoutObject(), node_, index, start_offset, end_offset, node_.GetLayoutObject(), node_, index, start_offset, end_offset,
size_.ConvertToPhysical(writing_mode))); size_.ConvertToPhysical(writing_mode_), ToLineOrientation(writing_mode_),
std::move(shape_result_)));
} }
} // namespace blink } // namespace blink
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
namespace blink { namespace blink {
class NGPhysicalTextFragment; class NGPhysicalTextFragment;
class ShapeResult;
class CORE_EXPORT NGTextFragmentBuilder final { class CORE_EXPORT NGTextFragmentBuilder final {
STACK_ALLOCATED(); STACK_ALLOCATED();
...@@ -21,12 +22,9 @@ class CORE_EXPORT NGTextFragmentBuilder final { ...@@ -21,12 +22,9 @@ class CORE_EXPORT NGTextFragmentBuilder final {
public: public:
NGTextFragmentBuilder(NGInlineNode); NGTextFragmentBuilder(NGInlineNode);
NGTextFragmentBuilder& SetDirection(TextDirection);
NGTextFragmentBuilder& SetSize(const NGLogicalSize&); NGTextFragmentBuilder& SetSize(const NGLogicalSize&);
void UniteMetrics(const NGLineHeightMetrics&); NGTextFragmentBuilder& SetShapeResult(RefPtr<const ShapeResult>);
const NGLineHeightMetrics& Metrics() const { return metrics_; }
// Creates the fragment. Can only be called once. // Creates the fragment. Can only be called once.
RefPtr<NGPhysicalTextFragment> ToTextFragment(unsigned index, RefPtr<NGPhysicalTextFragment> ToTextFragment(unsigned index,
...@@ -34,13 +32,13 @@ class CORE_EXPORT NGTextFragmentBuilder final { ...@@ -34,13 +32,13 @@ class CORE_EXPORT NGTextFragmentBuilder final {
unsigned end_offset); unsigned end_offset);
private: private:
TextDirection direction_;
NGInlineNode node_; NGInlineNode node_;
NGLogicalSize size_; NGLogicalSize size_;
NGLineHeightMetrics metrics_; RefPtr<const ShapeResult> shape_result_;
NGWritingMode writing_mode_;
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment