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

Remove NGPaintFragment From NGTextFragmentPainter

The code to call |NGBoxFragmentPainter| was removed in r832702
<crrev.com/c/2567145> and <crrev.com/c/2586636>.

Bug: 1154531
Change-Id: I5f09a206dc15464bda98f577e0a26f3132039f6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586450Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836172}
parent ea4ddecc
......@@ -1677,19 +1677,7 @@ void NGBoxFragmentPainter::PaintAtomicInlineChild(const NGPaintFragment& child,
void NGBoxFragmentPainter::PaintTextChild(const NGPaintFragment& paint_fragment,
const PaintInfo& paint_info,
const PhysicalOffset& paint_offset) {
// Inline blocks should be painted by PaintAtomicInlineChild.
DCHECK(!paint_fragment.PhysicalFragment().IsAtomicInline());
// Only paint during the foreground/selection phases.
if (paint_info.phase != PaintPhase::kForeground &&
paint_info.phase != PaintPhase::kSelectionDragImage &&
paint_info.phase != PaintPhase::kTextClip &&
paint_info.phase != PaintPhase::kMask)
return;
NGTextPainterCursor cursor(paint_fragment);
NGTextFragmentPainter<NGTextPainterCursor> text_painter(cursor);
text_painter.Paint(paint_info, paint_offset);
NOTREACHED();
}
void NGBoxFragmentPainter::PaintTextItem(const NGInlineCursor& cursor,
......@@ -1717,7 +1705,7 @@ void NGBoxFragmentPainter::PaintTextItem(const NGInlineCursor& cursor,
ScopedDisplayItemFragment display_item_fragment(paint_info.context,
item.FragmentId());
NGTextFragmentPainter<NGInlineCursor> text_painter(cursor, parent_offset);
NGTextFragmentPainter text_painter(cursor, parent_offset);
text_painter.Paint(paint_info, paint_offset);
}
......
......@@ -23,7 +23,6 @@
#include "third_party/blink/renderer/core/paint/highlight_painting_utils.h"
#include "third_party/blink/renderer/core/paint/inline_text_box_painter.h"
#include "third_party/blink/renderer/core/paint/list_marker_painter.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/core/paint/ng/ng_text_painter.h"
#include "third_party/blink/renderer/core/paint/paint_info.h"
#include "third_party/blink/renderer/core/paint/text_painter_base.h"
......@@ -54,8 +53,6 @@ Color SelectionBackgroundColor(const Document& document,
return color;
}
// TODO(yosin): Remove |AsDisplayItemClient| once the transition to
// |NGFragmentItem| is done. http://crbug.com/982194
inline const DisplayItemClient& AsDisplayItemClient(
const NGInlineCursor& cursor,
bool for_selection) {
......@@ -67,12 +64,6 @@ inline const DisplayItemClient& AsDisplayItemClient(
return *cursor.Current().GetDisplayItemClient();
}
inline const DisplayItemClient& AsDisplayItemClient(
const NGTextPainterCursor& cursor,
bool for_selection) {
return cursor.PaintFragment();
}
inline PhysicalRect ComputeBoxRect(const NGInlineCursor& cursor,
const PhysicalOffset& paint_offset,
const PhysicalOffset& parent_offset) {
......@@ -85,17 +76,6 @@ inline PhysicalRect ComputeBoxRect(const NGInlineCursor& cursor,
return box_rect;
}
inline PhysicalRect ComputeBoxRect(const NGTextPainterCursor& cursor,
const PhysicalOffset& paint_offset,
const PhysicalOffset& parent_offset) {
PhysicalRect box_rect = cursor.PaintFragment().Rect();
// We round the y-axis to ensure consistent line heights.
PhysicalOffset adjusted_paint_offset(paint_offset.left,
LayoutUnit(paint_offset.top.Round()));
box_rect.offset += adjusted_paint_offset;
return box_rect;
}
inline const NGInlineCursor& InlineCursorForBlockFlow(
const NGInlineCursor& cursor,
base::Optional<NGInlineCursor>* storage) {
......@@ -106,83 +86,6 @@ inline const NGInlineCursor& InlineCursorForBlockFlow(
return **storage;
}
inline const NGInlineCursor& InlineCursorForBlockFlow(
const NGTextPainterCursor& cursor,
base::Optional<NGInlineCursor>* storage) {
if (*storage)
return **storage;
storage->emplace(cursor.RootPaintFragment());
(*storage)->MoveTo(cursor.PaintFragment());
return **storage;
}
// TODO(yosin): Remove |GetTextFragmentPaintInfo| once the transition to
// |NGFragmentItem| is done. http://crbug.com/982194
inline NGTextFragmentPaintInfo GetTextFragmentPaintInfo(
const NGInlineCursor& cursor) {
return cursor.CurrentItem()->TextPaintInfo(cursor.Items());
}
inline NGTextFragmentPaintInfo GetTextFragmentPaintInfo(
const NGTextPainterCursor& cursor) {
return cursor.CurrentItem()->PaintInfo();
}
// TODO(yosin): Remove |GetLineLeftAndRightForOffsets| once the transition to
// |NGFragmentItem| is done. http://crbug.com/982194
inline std::pair<LayoutUnit, LayoutUnit> GetLineLeftAndRightForOffsets(
const NGFragmentItem& text_item,
StringView text,
unsigned start_offset,
unsigned end_offset) {
return text_item.LineLeftAndRightForOffsets(text, start_offset, end_offset);
}
inline std::pair<LayoutUnit, LayoutUnit> GetLineLeftAndRightForOffsets(
const NGPhysicalTextFragment& text_fragment,
StringView text,
unsigned start_offset,
unsigned end_offset) {
return text_fragment.LineLeftAndRightForOffsets(start_offset, end_offset);
}
// TODO(yosin): Remove |ComputeLayoutSelectionStatus| once the transition to
// |NGFragmentItem| is done. http://crbug.com/982194
inline LayoutSelectionStatus ComputeLayoutSelectionStatus(
const NGInlineCursor& cursor) {
return cursor.Current()
.GetLayoutObject()
->GetFrame()
->Selection()
.ComputeLayoutSelectionStatus(cursor);
}
SelectionState ComputeSelectionState(const NGInlineCursor& cursor) {
return cursor.Current()
.GetLayoutObject()
->GetDocument()
.GetFrame()
->Selection()
.ComputeLayoutSelectionStateForCursor(cursor.Current());
}
// TODO(yosin): Remove |ComputeLocalRect| once the transition to
// |NGFragmentItem| is done. http://crbug.com/982194
inline PhysicalRect ComputeLocalRect(const NGFragmentItem& text_item,
StringView text,
unsigned start_offset,
unsigned end_offset) {
return text_item.LocalRect(text, start_offset, end_offset);
}
inline PhysicalRect ComputeLocalRect(
const NGPhysicalTextFragment& text_fragment,
StringView text,
unsigned start_offset,
unsigned end_offset) {
return text_fragment.LocalRect(start_offset, end_offset);
}
DocumentMarkerVector ComputeMarkersToPaint(Node* node, bool is_ellipsis) {
// TODO(yoichio): Handle first-letter
auto* text_node = DynamicTo<Text>(node);
......@@ -220,8 +123,7 @@ unsigned GetTextContentOffset(const Text& text, unsigned offset) {
// If "bar" is a TextFragment. That start(), end() {4, 7} correspond this
// offset. If a marker has StartOffset / EndOffset as {2, 6},
// ClampOffset returns{ 4,6 }, which represents "ba" on "foo_bar".
template <typename TextItem>
unsigned ClampOffset(unsigned offset, const TextItem& text_fragment) {
unsigned ClampOffset(unsigned offset, const NGFragmentItem& text_fragment) {
return std::min(std::max(offset, text_fragment.StartOffset()),
text_fragment.EndOffset());
}
......@@ -245,14 +147,13 @@ void PaintRect(GraphicsContext& context,
PaintRect(context, PhysicalRect(rect.offset + location, rect.size), color);
}
template <typename TextItem>
PhysicalRect MarkerRectForForeground(const TextItem& text_fragment,
PhysicalRect MarkerRectForForeground(const NGFragmentItem& text_fragment,
StringView text,
unsigned start_offset,
unsigned end_offset) {
LayoutUnit start_position, end_position;
std::tie(start_position, end_position) = GetLineLeftAndRightForOffsets(
text_fragment, text, start_offset, end_offset);
std::tie(start_position, end_position) =
text_fragment.LineLeftAndRightForOffsets(text, start_offset, end_offset);
const LayoutUnit height = text_fragment.Size()
.ConvertToLogical(static_cast<WritingMode>(
......@@ -262,9 +163,8 @@ PhysicalRect MarkerRectForForeground(const TextItem& text_fragment,
}
// Copied from InlineTextBoxPainter
template <typename TextItem>
void PaintDocumentMarkers(const PaintInfo& paint_info,
const TextItem& text_fragment,
const NGFragmentItem& text_fragment,
StringView text,
const DocumentMarkerVector& markers_to_paint,
const PhysicalOffset& box_origin,
......@@ -320,7 +220,7 @@ void PaintDocumentMarkers(const PaintInfo& paint_info,
document, style, node, kPseudoIdTargetText);
}
PaintRect(paint_info.context, PhysicalOffset(box_origin),
ComputeLocalRect(text_fragment, text, paint_start_offset,
text_fragment.LocalRect(text, paint_start_offset,
paint_end_offset),
color);
break;
......@@ -342,7 +242,7 @@ void PaintDocumentMarkers(const PaintInfo& paint_info,
const auto& styleable_marker = To<StyleableMarker>(*marker);
if (marker_paint_phase == DocumentMarkerPaintPhase::kBackground) {
PaintRect(paint_info.context, PhysicalOffset(box_origin),
ComputeLocalRect(text_fragment, text, paint_start_offset,
text_fragment.LocalRect(text, paint_start_offset,
paint_end_offset),
styleable_marker.BackgroundColor());
break;
......@@ -371,8 +271,18 @@ class SelectionPaintState {
public:
explicit SelectionPaintState(const NGInlineCursor& containing_block)
: selection_status_(ComputeLayoutSelectionStatus(containing_block)),
state_(ComputeSelectionState(containing_block)),
: SelectionPaintState(containing_block,
containing_block.Current()
.GetLayoutObject()
->GetDocument()
.GetFrame()
->Selection()) {}
explicit SelectionPaintState(const NGInlineCursor& containing_block,
const FrameSelection& frame_selection)
: selection_status_(
frame_selection.ComputeLayoutSelectionStatus(containing_block)),
state_(frame_selection.ComputeLayoutSelectionStateForCursor(
containing_block.Current())),
containing_block_(containing_block) {}
const LayoutSelectionStatus& Status() const { return selection_status_; }
......@@ -465,12 +375,11 @@ class SelectionPaintState {
bool paint_selected_text_separately_;
};
template <typename Cursor>
class SelectionBoundsRecorder {
STACK_ALLOCATED();
public:
SelectionBoundsRecorder(const Cursor& cursor,
SelectionBoundsRecorder(const NGInlineCursor& cursor,
SelectionPaintState& selection,
PaintController& paint_controller,
const PhysicalOffset& box_rect_offset)
......@@ -482,14 +391,13 @@ class SelectionBoundsRecorder {
~SelectionBoundsRecorder();
private:
const Cursor& cursor_;
const NGInlineCursor& cursor_;
SelectionPaintState& selection_;
PaintController& paint_controller_;
const PhysicalOffset& box_rect_offset_;
};
template <>
SelectionBoundsRecorder<NGInlineCursor>::~SelectionBoundsRecorder() {
SelectionBoundsRecorder::~SelectionBoundsRecorder() {
DCHECK(RuntimeEnabledFeatures::CompositeAfterPaintEnabled());
const FrameSelection& frame_selection =
......@@ -530,11 +438,6 @@ SelectionBoundsRecorder<NGInlineCursor>::~SelectionBoundsRecorder() {
paint_controller_.RecordSelection(start, end);
}
template <>
SelectionBoundsRecorder<NGTextPainterCursor>::~SelectionBoundsRecorder() {
NOTREACHED();
}
// Check if text-emphasis and ruby annotation text are on different sides.
// See InlineTextBox::GetEmphasisMarkPosition().
//
......@@ -566,19 +469,7 @@ bool ShouldPaintEmphasisMark(const ComputedStyle& style,
} // namespace
StringView NGTextPainterCursor::CurrentText() const {
return CurrentItem()->Text();
}
const NGPaintFragment& NGTextPainterCursor::RootPaintFragment() const {
if (!root_paint_fragment_)
root_paint_fragment_ = paint_fragment_.Root();
return *root_paint_fragment_;
}
template <typename Cursor>
void NGTextFragmentPainter<Cursor>::PaintSymbol(
const LayoutObject* layout_object,
void NGTextFragmentPainter::PaintSymbol(const LayoutObject* layout_object,
const ComputedStyle& style,
const PhysicalSize box_size,
const PaintInfo& paint_info,
......@@ -592,8 +483,7 @@ void NGTextFragmentPainter<Cursor>::PaintSymbol(
// This is copied from InlineTextBoxPainter::PaintSelection() but lacks of
// ltr, expanding new line wrap or so which uses InlineTextBox functions.
template <typename Cursor>
void NGTextFragmentPainter<Cursor>::Paint(const PaintInfo& paint_info,
void NGTextFragmentPainter::Paint(const PaintInfo& paint_info,
const PhysicalOffset& paint_offset) {
const auto& text_item = *cursor_.CurrentItem();
// We can skip painting if the fragment (including selection) is invisible.
......@@ -610,7 +500,7 @@ void NGTextFragmentPainter<Cursor>::Paint(const PaintInfo& paint_info,
return;
const NGTextFragmentPaintInfo& fragment_paint_info =
GetTextFragmentPaintInfo(cursor_);
cursor_.Current()->TextPaintInfo(cursor_.Items());
const LayoutObject* layout_object = text_item.GetLayoutObject();
const Document& document = layout_object->GetDocument();
const bool is_printing = document.Printing();
......@@ -651,7 +541,7 @@ void NGTextFragmentPainter<Cursor>::Paint(const PaintInfo& paint_info,
// Ensure the selection bounds are recorded on the paint chunk regardless of
// whether the diplay item that contains the actual selection painting is
// reused.
base::Optional<SelectionBoundsRecorder<Cursor>> selection_recorder;
base::Optional<SelectionBoundsRecorder> selection_recorder;
if (UNLIKELY(RuntimeEnabledFeatures::CompositeAfterPaintEnabled() &&
selection && paint_info.phase == PaintPhase::kForeground &&
!is_printing)) {
......@@ -816,7 +706,4 @@ void NGTextFragmentPainter<Cursor>::Paint(const PaintInfo& paint_info,
DocumentMarkerPaintPhase::kForeground, &text_painter);
}
template class NGTextFragmentPainter<NGTextPainterCursor>;
template class NGTextFragmentPainter<NGInlineCursor>;
} // namespace blink
......@@ -7,7 +7,6 @@
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_cursor.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/style/computed_style_constants.h"
#include "third_party/blink/renderer/platform/geometry/layout_rect.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
......@@ -17,7 +16,6 @@ namespace blink {
class ComputedStyle;
class DisplayItemClient;
class LayoutObject;
class NGPaintFragment;
class NGInlineCursor;
struct NGTextFragmentPaintInfo;
struct PaintInfo;
......@@ -25,41 +23,16 @@ struct PhysicalOffset;
struct PhysicalRect;
struct PhysicalSize;
// The helper class for templatize |NGTextFragmentPainter|.
// TODO(yosin): Remove |NGTextPainterCursor| once the transition to
// |NGFragmentItem| is done. http://crbug.com/982194
class NGTextPainterCursor {
STACK_ALLOCATED();
public:
explicit NGTextPainterCursor(const NGPaintFragment& paint_fragment)
: paint_fragment_(paint_fragment),
text_fragment_(
To<NGPhysicalTextFragment>(paint_fragment.PhysicalFragment())) {}
const NGPaintFragment& PaintFragment() const { return paint_fragment_; }
const NGPhysicalTextFragment* CurrentItem() const { return &text_fragment_; }
StringView CurrentText() const;
const NGPaintFragment& RootPaintFragment() const;
private:
const NGPaintFragment& paint_fragment_;
const NGPhysicalTextFragment& text_fragment_;
mutable const NGPaintFragment* root_paint_fragment_ = nullptr;
};
// Text fragment painter for LayoutNG. Operates on NGPhysicalTextFragments and
// handles clipping, selection, etc. Delegates to NGTextPainter to paint the
// Text fragment painter for LayoutNG. Operates on NGFragmentItem that IsText()
// and handles clipping, selection, etc. Delegates to NGTextPainter to paint the
// text itself.
// TODO(yosin): We should make |NGTextFragmentPainter| non-template class onnce
// we get rid of |NGPaintFragment|.
template <typename Cursor>
class NGTextFragmentPainter {
STACK_ALLOCATED();
public:
explicit NGTextFragmentPainter(const Cursor& cursor) : cursor_(cursor) {}
NGTextFragmentPainter(const Cursor& cursor,
explicit NGTextFragmentPainter(const NGInlineCursor& cursor)
: cursor_(cursor) {}
NGTextFragmentPainter(const NGInlineCursor& cursor,
const PhysicalOffset& parent_offset)
: cursor_(cursor), parent_offset_(parent_offset) {}
......@@ -83,14 +56,11 @@ class NGTextFragmentPainter {
const PaintInfo& paint_info,
const PhysicalOffset& paint_offset);
const Cursor& cursor_;
const NGInlineCursor& cursor_;
PhysicalOffset parent_offset_;
base::Optional<NGInlineCursor> inline_cursor_for_block_flow_;
};
extern template class NGTextFragmentPainter<NGTextPainterCursor>;
extern template class NGTextFragmentPainter<NGInlineCursor>;
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_PAINT_NG_NG_TEXT_FRAGMENT_PAINTER_H_
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