Commit c3ecb724 authored by Koji Ishii's avatar Koji Ishii Committed by Chromium LUCI CQ

Remove NGPaintFragment from NGAbstractInlineTextBox

Bug: 1154531
Change-Id: I3050d4a098da0e5c6c99ff50dd1605aa08467fbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2592234Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837080}
parent 0f14f303
......@@ -9,10 +9,6 @@
#include "third_party/blink/renderer/core/layout/ng/inline/ng_fragment_items.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_break_token.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_cursor.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment_traversal.h"
#include "third_party/blink/renderer/platform/fonts/character_range.h"
#include "third_party/blink/renderer/platform/fonts/shaping/shape_result_buffer.h"
#include "third_party/blink/renderer/platform/fonts/shaping/shape_result_view.h"
......@@ -21,20 +17,16 @@ namespace blink {
namespace {
// Mapping from NGFragmentItem/NGPaintFragment to NGAbstractInlineTextBox
// TODO(yosin): Once we get rid of |NGPaintFragment|, we should not use
// template class for |NGAbstractInlineTextBoxCache|.
template <typename Fragment>
class NGAbstractInlineTextBoxCache final {
public:
static scoped_refptr<AbstractInlineTextBox> GetOrCreate(
const Fragment& fragment) {
const NGFragmentItem& fragment) {
if (!s_instance_)
s_instance_ = new NGAbstractInlineTextBoxCache();
return s_instance_->GetOrCreateInternal(fragment);
}
static void WillDestroy(const Fragment* fragment) {
static void WillDestroy(const NGFragmentItem* fragment) {
if (!s_instance_)
return;
s_instance_->WillDestroyInternal(fragment);
......@@ -42,7 +34,7 @@ class NGAbstractInlineTextBoxCache final {
private:
scoped_refptr<AbstractInlineTextBox> GetOrCreateInternal(
const Fragment& fragment) {
const NGFragmentItem& fragment) {
const auto it = map_.find(&fragment);
auto* const layout_text = To<LayoutText>(fragment.GetMutableLayoutObject());
if (it != map_.end()) {
......@@ -56,7 +48,7 @@ class NGAbstractInlineTextBoxCache final {
return obj;
}
void WillDestroyInternal(const Fragment* fragment) {
void WillDestroyInternal(const NGFragmentItem* fragment) {
const auto it = map_.find(fragment);
if (it == map_.end())
return;
......@@ -66,51 +58,29 @@ class NGAbstractInlineTextBoxCache final {
static NGAbstractInlineTextBoxCache* s_instance_;
HashMap<const Fragment*, scoped_refptr<AbstractInlineTextBox>> map_;
HashMap<const NGFragmentItem*, scoped_refptr<AbstractInlineTextBox>> map_;
};
template <typename Fragment>
NGAbstractInlineTextBoxCache<Fragment>*
NGAbstractInlineTextBoxCache<Fragment>::s_instance_ = nullptr;
NGAbstractInlineTextBoxCache* NGAbstractInlineTextBoxCache::s_instance_ =
nullptr;
} // namespace
scoped_refptr<AbstractInlineTextBox> NGAbstractInlineTextBox::GetOrCreate(
const NGInlineCursor& cursor) {
if (const NGPaintFragment* paint_fragment = cursor.CurrentPaintFragment()) {
return NGAbstractInlineTextBoxCache<NGPaintFragment>::GetOrCreate(
*paint_fragment);
}
if (const NGFragmentItem* fragment_item = cursor.CurrentItem()) {
return NGAbstractInlineTextBoxCache<NGFragmentItem>::GetOrCreate(
*fragment_item);
return NGAbstractInlineTextBoxCache::GetOrCreate(*fragment_item);
}
return nullptr;
}
void NGAbstractInlineTextBox::WillDestroy(const NGInlineCursor& cursor) {
if (const NGPaintFragment* paint_fragment = cursor.CurrentPaintFragment()) {
return NGAbstractInlineTextBoxCache<NGPaintFragment>::WillDestroy(
paint_fragment);
}
if (const NGFragmentItem* fragment_item = cursor.CurrentItem()) {
return NGAbstractInlineTextBoxCache<NGFragmentItem>::WillDestroy(
fragment_item);
return NGAbstractInlineTextBoxCache::WillDestroy(fragment_item);
}
NOTREACHED();
}
void NGAbstractInlineTextBox::WillDestroy(const NGPaintFragment* fragment) {
NGAbstractInlineTextBoxCache<NGPaintFragment>::WillDestroy(fragment);
}
NGAbstractInlineTextBox::NGAbstractInlineTextBox(
LineLayoutText line_layout_item,
const NGPaintFragment& fragment)
: AbstractInlineTextBox(line_layout_item), fragment_(&fragment) {
DCHECK(fragment_->PhysicalFragment().IsText()) << fragment_;
}
NGAbstractInlineTextBox::NGAbstractInlineTextBox(
LineLayoutText line_layout_item,
const NGFragmentItem& fragment_item)
......@@ -119,7 +89,7 @@ NGAbstractInlineTextBox::NGAbstractInlineTextBox(
}
NGAbstractInlineTextBox::~NGAbstractInlineTextBox() {
DCHECK(!fragment_);
DCHECK(!fragment_item_);
}
void NGAbstractInlineTextBox::Detach() {
......@@ -128,17 +98,14 @@ void NGAbstractInlineTextBox::Detach() {
cache->InlineTextBoxesUpdated(GetLineLayoutItem());
}
AbstractInlineTextBox::Detach();
fragment_ = nullptr;
fragment_item_ = nullptr;
}
NGInlineCursor NGAbstractInlineTextBox::GetCursor() const {
if (!fragment_item_)
return NGInlineCursor();
NGInlineCursor cursor;
if (RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled())
cursor.MoveTo(*fragment_item_);
else
cursor.MoveTo(*fragment_);
cursor.MoveTo(*fragment_item_);
DCHECK(!cursor.Current().GetLayoutObject()->NeedsLayout());
return cursor;
}
......@@ -156,10 +123,6 @@ String NGAbstractInlineTextBox::GetTextContent() const {
const NGInlineCursor& cursor = GetCursor();
if (cursor.Current().IsLayoutGeneratedText())
return cursor.Current().Text(cursor).ToString();
if (const NGPaintFragment* paint_fragment = cursor.CurrentPaintFragment()) {
return To<NGPhysicalTextFragment>(paint_fragment->PhysicalFragment())
.TextContent();
}
return cursor.Items().Text(cursor.Current().UsesFirstLineStyle());
}
......
......@@ -11,7 +11,6 @@ namespace blink {
class NGFragmentItem;
class NGInlineCursor;
class NGPaintFragment;
// The implementation of |AbstractInlineTextBox| for LayoutNG.
// See also |LegacyAbstractInlineTextBox| for legacy layout.
......@@ -22,13 +21,10 @@ class CORE_EXPORT NGAbstractInlineTextBox final : public AbstractInlineTextBox {
static scoped_refptr<AbstractInlineTextBox> GetOrCreate(
const NGInlineCursor& cursor);
static void WillDestroy(const NGInlineCursor& cursor);
static void WillDestroy(const NGPaintFragment* fragment);
friend class LayoutText;
public:
NGAbstractInlineTextBox(LineLayoutText line_layout_item,
const NGPaintFragment& fragment);
NGAbstractInlineTextBox(LineLayoutText line_layout_item,
const NGFragmentItem& fragment);
......@@ -55,10 +51,7 @@ class CORE_EXPORT NGAbstractInlineTextBox final : public AbstractInlineTextBox {
bool IsLineBreak() const final;
bool NeedsTrailingSpace() const final;
union {
const NGPaintFragment* fragment_;
const NGFragmentItem* fragment_item_;
};
const NGFragmentItem* fragment_item_;
};
} // 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