Commit f0d2d18e authored by Christian Biesinger's avatar Christian Biesinger Committed by Commit Bot

[layoutng] Inline some functions in layout/ng/inline

Change-Id: Icb6c6320895b75f2e085cc45c835d92f32c0be56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1538856
Auto-Submit: Christian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644895}
parent 9392e786
......@@ -31,10 +31,4 @@ NGInlineChildLayoutContext::BoxStatesIfValidForItemIndex(
return nullptr;
}
void NGInlineChildLayoutContext::SetItemIndex(const Vector<NGInlineItem>& items,
unsigned item_index) {
items_ = &items;
item_index_ = item_index;
}
} // namespace blink
......@@ -34,7 +34,10 @@ class NGInlineChildLayoutContext {
NGInlineLayoutStateStack* BoxStatesIfValidForItemIndex(
const Vector<NGInlineItem>& items,
unsigned item_index);
void SetItemIndex(const Vector<NGInlineItem>& items, unsigned item_index);
void SetItemIndex(const Vector<NGInlineItem>& items, unsigned item_index) {
items_ = &items;
item_index_ = item_index;
}
private:
base::Optional<NGInlineLayoutStateStack> box_states_;
......
......@@ -104,18 +104,6 @@ NGInlineItem::NGInlineItem(const NGInlineItem& other,
NGInlineItem::~NGInlineItem() = default;
bool NGInlineItem::ShouldCreateBoxFragment() const {
if (Type() == kOpenTag || Type() == kCloseTag)
return ToLayoutInline(layout_object_)->ShouldCreateBoxFragment();
DCHECK_EQ(Type(), kAtomicInline);
return false;
}
void NGInlineItem::SetShouldCreateBoxFragment() {
DCHECK(Type() == kOpenTag || Type() == kCloseTag);
ToLayoutInline(layout_object_)->SetShouldCreateBoxFragment();
}
void NGInlineItem::ComputeBoxProperties() {
DCHECK(!is_empty_item_);
......@@ -147,20 +135,6 @@ const char* NGInlineItem::NGInlineItemTypeToString(int val) const {
return kNGInlineItemTypeStrings[val];
}
RunSegmenter::RunSegmenterRange NGInlineItem::CreateRunSegmenterRange() const {
return NGInlineItemSegment::UnpackSegmentData(start_offset_, end_offset_,
segment_data_);
}
bool NGInlineItem::EqualsRunSegment(const NGInlineItem& other) const {
return segment_data_ == other.segment_data_;
}
void NGInlineItem::SetSegmentData(unsigned segment_data) {
DCHECK_EQ(Type(), NGInlineItem::kText);
segment_data_ = segment_data;
}
void NGInlineItem::SetSegmentData(const RunSegmenter::RunSegmenterRange& range,
Vector<NGInlineItem>* items) {
unsigned segment_data = NGInlineItemSegment::PackSegmentData(range);
......@@ -170,13 +144,6 @@ void NGInlineItem::SetSegmentData(const RunSegmenter::RunSegmenterRange& range,
}
}
void NGInlineItem::SetBidiLevel(UBiDiLevel level) {
// Invalidate ShapeResult because it depends on the resolved direction.
if (DirectionFromLevel(level) != DirectionFromLevel(bidi_level_))
shape_result_ = nullptr;
bidi_level_ = level;
}
// Set bidi level to a list of NGInlineItem from |index| to the item that ends
// with |end_offset|.
// If |end_offset| is mid of an item, the item is split to ensure each item has
......@@ -207,12 +174,6 @@ unsigned NGInlineItem::SetBidiLevel(Vector<NGInlineItem>& items,
return index + 1;
}
UBiDiLevel NGInlineItem::BidiLevelForReorder() const {
// List markers should not be reordered to protect it from being included into
// unclosed inline boxes.
return Type() != NGInlineItem::kListMarker ? BidiLevel() : 0;
}
String NGInlineItem::ToString() const {
return String::Format("NGInlineItem. Type: '%s'. LayoutObject: '%s'",
NGInlineItemTypeToString(Type()),
......@@ -236,45 +197,6 @@ void NGInlineItem::Split(Vector<NGInlineItem>& items,
items[index + 1].start_offset_ = offset;
}
void NGInlineItem::SetOffset(unsigned start, unsigned end) {
DCHECK_GE(end, start);
start_offset_ = start;
end_offset_ = end;
// Any modification to the offset will invalidate the shape result.
shape_result_ = nullptr;
}
void NGInlineItem::SetEndOffset(unsigned end_offset) {
DCHECK_GE(end_offset, start_offset_);
end_offset_ = end_offset;
// Any modification to the offset will invalidate the shape result.
shape_result_ = nullptr;
}
bool NGInlineItem::HasStartEdge() const {
DCHECK(Type() == kOpenTag || Type() == kCloseTag);
// TODO(kojii): Should use break token when NG has its own tree building.
return !GetLayoutObject()->IsInlineElementContinuation();
}
bool NGInlineItem::HasEndEdge() const {
DCHECK(Type() == kOpenTag || Type() == kCloseTag);
// TODO(kojii): Should use break token when NG has its own tree building.
return !GetLayoutObject()->IsLayoutInline() ||
!ToLayoutInline(GetLayoutObject())->Continuation();
}
void NGInlineItem::SetEndCollapseType(NGCollapseType type) {
DCHECK(Type() == NGInlineItem::kText || type == kOpaqueToCollapsing ||
(Type() == NGInlineItem::kControl && type == kCollapsible));
end_collapse_type_ = type;
}
void NGInlineItem::SetEndCollapseType(NGCollapseType type, bool is_newline) {
SetEndCollapseType(type);
is_end_collapsible_newline_ = is_newline;
}
const NGInlineItem& NGInlineItemsData::FindItemForTextOffset(
unsigned offset) const {
DCHECK_LT(offset, text_content.length());
......
......@@ -6,6 +6,7 @@
#define NGInlineItem_h
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/layout/layout_inline.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_item_segment.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_offset_mapping.h"
#include "third_party/blink/renderer/core/layout/ng/ng_style_variant.h"
......@@ -90,8 +91,16 @@ class CORE_EXPORT NGInlineItem {
// If this item should create a box fragment. Box fragments can be omitted for
// optimization if this is false.
bool ShouldCreateBoxFragment() const;
void SetShouldCreateBoxFragment();
bool ShouldCreateBoxFragment() const {
if (Type() == kOpenTag || Type() == kCloseTag)
return ToLayoutInline(layout_object_)->ShouldCreateBoxFragment();
DCHECK_EQ(Type(), kAtomicInline);
return false;
}
void SetShouldCreateBoxFragment() {
DCHECK(Type() == kOpenTag || Type() == kCloseTag);
ToLayoutInline(layout_object_)->SetShouldCreateBoxFragment();
}
unsigned StartOffset() const { return start_offset_; }
unsigned EndOffset() const { return end_offset_; }
......@@ -102,16 +111,40 @@ class CORE_EXPORT NGInlineItem {
// Resolved bidi level for the reordering algorithm. Certain items have
// artificial bidi level for the reordering algorithm without affecting its
// direction.
UBiDiLevel BidiLevelForReorder() const;
UBiDiLevel BidiLevelForReorder() const {
// List markers should not be reordered to protect it from being included
// into unclosed inline boxes.
return Type() != NGInlineItem::kListMarker ? BidiLevel() : 0;
}
const ComputedStyle* Style() const { return style_.get(); }
LayoutObject* GetLayoutObject() const { return layout_object_; }
void SetOffset(unsigned start, unsigned end);
void SetEndOffset(unsigned);
void SetOffset(unsigned start, unsigned end) {
DCHECK_GE(end, start);
start_offset_ = start;
end_offset_ = end;
// Any modification to the offset will invalidate the shape result.
shape_result_ = nullptr;
}
void SetEndOffset(unsigned end_offset) {
DCHECK_GE(end_offset, start_offset_);
end_offset_ = end_offset;
// Any modification to the offset will invalidate the shape result.
shape_result_ = nullptr;
}
bool HasStartEdge() const;
bool HasEndEdge() const;
bool HasStartEdge() const {
DCHECK(Type() == kOpenTag || Type() == kCloseTag);
// TODO(kojii): Should use break token when NG has its own tree building.
return !GetLayoutObject()->IsInlineElementContinuation();
}
bool HasEndEdge() const {
DCHECK(Type() == kOpenTag || Type() == kCloseTag);
// TODO(kojii): Should use break token when NG has its own tree building.
return !GetLayoutObject()->IsLayoutInline() ||
!ToLayoutInline(GetLayoutObject())->Continuation();
}
void SetStyleVariant(NGStyleVariant style_variant) {
style_variant_ = static_cast<unsigned>(style_variant);
......@@ -124,7 +157,11 @@ class CORE_EXPORT NGInlineItem {
NGCollapseType EndCollapseType() const {
return static_cast<NGCollapseType>(end_collapse_type_);
}
void SetEndCollapseType(NGCollapseType type);
void SetEndCollapseType(NGCollapseType type) {
DCHECK(Type() == NGInlineItem::kText || type == kOpaqueToCollapsing ||
(Type() == NGInlineItem::kControl && type == kCollapsible));
end_collapse_type_ = type;
}
// True if this item was generated (not in DOM).
// NGInlineItemsBuilder may generate break opportunitites to express the
......@@ -137,22 +174,38 @@ class CORE_EXPORT NGInlineItem {
// Whether the end collapsible space run contains a newline.
// Valid only when kCollapsible or kCollapsed.
bool IsEndCollapsibleNewline() const { return is_end_collapsible_newline_; }
void SetEndCollapseType(NGCollapseType type, bool is_newline);
void SetEndCollapseType(NGCollapseType type, bool is_newline) {
SetEndCollapseType(type);
is_end_collapsible_newline_ = is_newline;
}
static void Split(Vector<NGInlineItem>&, unsigned index, unsigned offset);
// RunSegmenter properties.
unsigned SegmentData() const { return segment_data_; }
void SetSegmentData(unsigned segment_data);
void SetSegmentData(unsigned segment_data) {
DCHECK_EQ(Type(), NGInlineItem::kText);
segment_data_ = segment_data;
}
static void SetSegmentData(const RunSegmenter::RunSegmenterRange& range,
Vector<NGInlineItem>* items);
RunSegmenter::RunSegmenterRange CreateRunSegmenterRange() const;
RunSegmenter::RunSegmenterRange CreateRunSegmenterRange() const {
return NGInlineItemSegment::UnpackSegmentData(start_offset_, end_offset_,
segment_data_);
}
// Whether the other item has the same RunSegmenter properties or not.
bool EqualsRunSegment(const NGInlineItem&) const;
bool EqualsRunSegment(const NGInlineItem& other) const {
return segment_data_ == other.segment_data_;
}
void SetBidiLevel(UBiDiLevel);
void SetBidiLevel(UBiDiLevel level) {
// Invalidate ShapeResult because it depends on the resolved direction.
if (DirectionFromLevel(level) != DirectionFromLevel(bidi_level_))
shape_result_ = nullptr;
bidi_level_ = level;
}
static unsigned SetBidiLevel(Vector<NGInlineItem>&,
unsigned index,
unsigned end_offset,
......
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