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 @@ ...@@ -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_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_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_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/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_buffer.h"
#include "third_party/blink/renderer/platform/fonts/shaping/shape_result_view.h" #include "third_party/blink/renderer/platform/fonts/shaping/shape_result_view.h"
...@@ -21,20 +17,16 @@ namespace blink { ...@@ -21,20 +17,16 @@ namespace blink {
namespace { 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 { class NGAbstractInlineTextBoxCache final {
public: public:
static scoped_refptr<AbstractInlineTextBox> GetOrCreate( static scoped_refptr<AbstractInlineTextBox> GetOrCreate(
const Fragment& fragment) { const NGFragmentItem& fragment) {
if (!s_instance_) if (!s_instance_)
s_instance_ = new NGAbstractInlineTextBoxCache(); s_instance_ = new NGAbstractInlineTextBoxCache();
return s_instance_->GetOrCreateInternal(fragment); return s_instance_->GetOrCreateInternal(fragment);
} }
static void WillDestroy(const Fragment* fragment) { static void WillDestroy(const NGFragmentItem* fragment) {
if (!s_instance_) if (!s_instance_)
return; return;
s_instance_->WillDestroyInternal(fragment); s_instance_->WillDestroyInternal(fragment);
...@@ -42,7 +34,7 @@ class NGAbstractInlineTextBoxCache final { ...@@ -42,7 +34,7 @@ class NGAbstractInlineTextBoxCache final {
private: private:
scoped_refptr<AbstractInlineTextBox> GetOrCreateInternal( scoped_refptr<AbstractInlineTextBox> GetOrCreateInternal(
const Fragment& fragment) { const NGFragmentItem& fragment) {
const auto it = map_.find(&fragment); const auto it = map_.find(&fragment);
auto* const layout_text = To<LayoutText>(fragment.GetMutableLayoutObject()); auto* const layout_text = To<LayoutText>(fragment.GetMutableLayoutObject());
if (it != map_.end()) { if (it != map_.end()) {
...@@ -56,7 +48,7 @@ class NGAbstractInlineTextBoxCache final { ...@@ -56,7 +48,7 @@ class NGAbstractInlineTextBoxCache final {
return obj; return obj;
} }
void WillDestroyInternal(const Fragment* fragment) { void WillDestroyInternal(const NGFragmentItem* fragment) {
const auto it = map_.find(fragment); const auto it = map_.find(fragment);
if (it == map_.end()) if (it == map_.end())
return; return;
...@@ -66,51 +58,29 @@ class NGAbstractInlineTextBoxCache final { ...@@ -66,51 +58,29 @@ class NGAbstractInlineTextBoxCache final {
static NGAbstractInlineTextBoxCache* s_instance_; static NGAbstractInlineTextBoxCache* s_instance_;
HashMap<const Fragment*, scoped_refptr<AbstractInlineTextBox>> map_; HashMap<const NGFragmentItem*, scoped_refptr<AbstractInlineTextBox>> map_;
}; };
template <typename Fragment> NGAbstractInlineTextBoxCache* NGAbstractInlineTextBoxCache::s_instance_ =
NGAbstractInlineTextBoxCache<Fragment>* nullptr;
NGAbstractInlineTextBoxCache<Fragment>::s_instance_ = nullptr;
} // namespace } // namespace
scoped_refptr<AbstractInlineTextBox> NGAbstractInlineTextBox::GetOrCreate( scoped_refptr<AbstractInlineTextBox> NGAbstractInlineTextBox::GetOrCreate(
const NGInlineCursor& cursor) { const NGInlineCursor& cursor) {
if (const NGPaintFragment* paint_fragment = cursor.CurrentPaintFragment()) {
return NGAbstractInlineTextBoxCache<NGPaintFragment>::GetOrCreate(
*paint_fragment);
}
if (const NGFragmentItem* fragment_item = cursor.CurrentItem()) { if (const NGFragmentItem* fragment_item = cursor.CurrentItem()) {
return NGAbstractInlineTextBoxCache<NGFragmentItem>::GetOrCreate( return NGAbstractInlineTextBoxCache::GetOrCreate(*fragment_item);
*fragment_item);
} }
return nullptr; return nullptr;
} }
void NGAbstractInlineTextBox::WillDestroy(const NGInlineCursor& cursor) { 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()) { if (const NGFragmentItem* fragment_item = cursor.CurrentItem()) {
return NGAbstractInlineTextBoxCache<NGFragmentItem>::WillDestroy( return NGAbstractInlineTextBoxCache::WillDestroy(fragment_item);
fragment_item);
} }
NOTREACHED(); 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( NGAbstractInlineTextBox::NGAbstractInlineTextBox(
LineLayoutText line_layout_item, LineLayoutText line_layout_item,
const NGFragmentItem& fragment_item) const NGFragmentItem& fragment_item)
...@@ -119,7 +89,7 @@ NGAbstractInlineTextBox::NGAbstractInlineTextBox( ...@@ -119,7 +89,7 @@ NGAbstractInlineTextBox::NGAbstractInlineTextBox(
} }
NGAbstractInlineTextBox::~NGAbstractInlineTextBox() { NGAbstractInlineTextBox::~NGAbstractInlineTextBox() {
DCHECK(!fragment_); DCHECK(!fragment_item_);
} }
void NGAbstractInlineTextBox::Detach() { void NGAbstractInlineTextBox::Detach() {
...@@ -128,17 +98,14 @@ void NGAbstractInlineTextBox::Detach() { ...@@ -128,17 +98,14 @@ void NGAbstractInlineTextBox::Detach() {
cache->InlineTextBoxesUpdated(GetLineLayoutItem()); cache->InlineTextBoxesUpdated(GetLineLayoutItem());
} }
AbstractInlineTextBox::Detach(); AbstractInlineTextBox::Detach();
fragment_ = nullptr; fragment_item_ = nullptr;
} }
NGInlineCursor NGAbstractInlineTextBox::GetCursor() const { NGInlineCursor NGAbstractInlineTextBox::GetCursor() const {
if (!fragment_item_) if (!fragment_item_)
return NGInlineCursor(); return NGInlineCursor();
NGInlineCursor cursor; NGInlineCursor cursor;
if (RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled())
cursor.MoveTo(*fragment_item_); cursor.MoveTo(*fragment_item_);
else
cursor.MoveTo(*fragment_);
DCHECK(!cursor.Current().GetLayoutObject()->NeedsLayout()); DCHECK(!cursor.Current().GetLayoutObject()->NeedsLayout());
return cursor; return cursor;
} }
...@@ -156,10 +123,6 @@ String NGAbstractInlineTextBox::GetTextContent() const { ...@@ -156,10 +123,6 @@ String NGAbstractInlineTextBox::GetTextContent() const {
const NGInlineCursor& cursor = GetCursor(); const NGInlineCursor& cursor = GetCursor();
if (cursor.Current().IsLayoutGeneratedText()) if (cursor.Current().IsLayoutGeneratedText())
return cursor.Current().Text(cursor).ToString(); 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()); return cursor.Items().Text(cursor.Current().UsesFirstLineStyle());
} }
......
...@@ -11,7 +11,6 @@ namespace blink { ...@@ -11,7 +11,6 @@ namespace blink {
class NGFragmentItem; class NGFragmentItem;
class NGInlineCursor; class NGInlineCursor;
class NGPaintFragment;
// The implementation of |AbstractInlineTextBox| for LayoutNG. // The implementation of |AbstractInlineTextBox| for LayoutNG.
// See also |LegacyAbstractInlineTextBox| for legacy layout. // See also |LegacyAbstractInlineTextBox| for legacy layout.
...@@ -22,13 +21,10 @@ class CORE_EXPORT NGAbstractInlineTextBox final : public AbstractInlineTextBox { ...@@ -22,13 +21,10 @@ class CORE_EXPORT NGAbstractInlineTextBox final : public AbstractInlineTextBox {
static scoped_refptr<AbstractInlineTextBox> GetOrCreate( static scoped_refptr<AbstractInlineTextBox> GetOrCreate(
const NGInlineCursor& cursor); const NGInlineCursor& cursor);
static void WillDestroy(const NGInlineCursor& cursor); static void WillDestroy(const NGInlineCursor& cursor);
static void WillDestroy(const NGPaintFragment* fragment);
friend class LayoutText; friend class LayoutText;
public: public:
NGAbstractInlineTextBox(LineLayoutText line_layout_item,
const NGPaintFragment& fragment);
NGAbstractInlineTextBox(LineLayoutText line_layout_item, NGAbstractInlineTextBox(LineLayoutText line_layout_item,
const NGFragmentItem& fragment); const NGFragmentItem& fragment);
...@@ -55,10 +51,7 @@ class CORE_EXPORT NGAbstractInlineTextBox final : public AbstractInlineTextBox { ...@@ -55,10 +51,7 @@ class CORE_EXPORT NGAbstractInlineTextBox final : public AbstractInlineTextBox {
bool IsLineBreak() const final; bool IsLineBreak() const final;
bool NeedsTrailingSpace() const final; bool NeedsTrailingSpace() const final;
union {
const NGPaintFragment* fragment_;
const NGFragmentItem* fragment_item_; const NGFragmentItem* fragment_item_;
};
}; };
} // 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