diff --git a/third_party/blink/renderer/core/paint/ng/ng_highlight_painter.cc b/third_party/blink/renderer/core/paint/ng/ng_highlight_painter.cc index e699c9b8adb6b..29e0cc10c98fe 100644 --- a/third_party/blink/renderer/core/paint/ng/ng_highlight_painter.cc +++ b/third_party/blink/renderer/core/paint/ng/ng_highlight_painter.cc @@ -616,13 +616,13 @@ NGHighlightPainter::Case NGHighlightPainter::ComputePaintCase() const { // If there are only spelling and/or grammar highlights, and they use the // default style that only adds decorations without adding a background or // changing the text color, we don’t need the expense of overlay painting. - return spelling_ok && grammar_ok ? kFastSpellingGrammar : kOverlay; + return spelling_ok && grammar_ok ? kFastSpellingGrammar : kFastSpellingGrammar; } return kNoHighlights; } -void NGHighlightPainter::FastPaintSpellingGrammarDecorations() const { +void NGHighlightPainter::FastPaintSpellingGrammarDecorations() { DCHECK_EQ(paint_case_, kFastSpellingGrammar); DCHECK(fragment_item_.GetNode()); const auto& text_node = To(*fragment_item_.GetNode()); @@ -637,7 +637,7 @@ void NGHighlightPainter::FastPaintSpellingGrammarDecorations() const { void NGHighlightPainter::FastPaintSpellingGrammarDecorations( const Text& text_node, const StringView& text, - const DocumentMarkerVector& markers) const { + const DocumentMarkerVector& markers) { for (const DocumentMarker* marker : markers) { const unsigned marker_start_offset = GetTextContentOffset(text_node, marker->StartOffset()); @@ -658,17 +658,30 @@ void NGHighlightPainter::PaintOneSpellingGrammarDecoration( const DocumentMarker::MarkerType& marker_type, const StringView& text, unsigned paint_start_offset, - unsigned paint_end_offset) const { + unsigned paint_end_offset) { if (fragment_item_.GetNode()->GetDocument().Printing()) return; - DocumentMarkerPainter::PaintDocumentMarker( - paint_info_, box_origin_, style_, marker_type, - MarkerRectForForeground(fragment_item_, text, paint_start_offset, - paint_end_offset), - HighlightPaintingUtils::HighlightTextDecorationColor( - style_, node_, - marker_type == DocumentMarker::kSpelling ? kPseudoIdSpellingError - : kPseudoIdGrammarError)); + // DocumentMarkerPainter::PaintDocumentMarker( + // paint_info_, box_origin_, style_, marker_type, + // MarkerRectForForeground(fragment_item_, text, paint_start_offset, + // paint_end_offset), + // HighlightPaintingUtils::HighlightTextDecorationColor( + // style_, node_, + // marker_type == DocumentMarker::kSpelling ? kPseudoIdSpellingError + // : kPseudoIdGrammarError)); + absl::optional decoration_info{}; + auto style = HighlightPaintingUtils::HighlightPseudoStyle( + node_, style_, kPseudoIdSpellingError); + auto text_style = HighlightPaintingUtils::HighlightPaintingStyle( + node_->GetDocument(), style_, node_, kPseudoIdSpellingError, + originating_text_style_, paint_info_); + decoration_painter_.UpdateDecorationInfo(decoration_info, *style, text_style); + GraphicsContextStateSaver saver{paint_info_.context}; + ClipToPartDecorations({HighlightLayer{HighlightLayerType::kSpelling}, paint_start_offset, paint_end_offset}); + text_painter_.PaintDecorationsExceptLineThrough( + fragment_item_, paint_info_, *style, + text_style, *decoration_info, + TextDecorationLine::kSpellingError, decoration_rect_); } void NGHighlightPainter::PaintOriginatingText(const TextPaintStyle& text_style, diff --git a/third_party/blink/renderer/core/paint/ng/ng_highlight_painter.h b/third_party/blink/renderer/core/paint/ng/ng_highlight_painter.h index 1c828b9d2e533..2be310acdffdd 100644 --- a/third_party/blink/renderer/core/paint/ng/ng_highlight_painter.h +++ b/third_party/blink/renderer/core/paint/ng/ng_highlight_painter.h @@ -177,7 +177,7 @@ class CORE_EXPORT NGHighlightPainter { Case PaintCase() const; // PaintCase() == kFastSpellingGrammar only - void FastPaintSpellingGrammarDecorations() const; + void FastPaintSpellingGrammarDecorations(); // PaintCase() == kOverlay only void PaintOriginatingText(const TextPaintStyle&, DOMNodeId); @@ -211,11 +211,11 @@ class CORE_EXPORT NGHighlightPainter { void FastPaintSpellingGrammarDecorations( const Text& text_node, const StringView& text, - const DocumentMarkerVector& markers) const; + const DocumentMarkerVector& markers); void PaintOneSpellingGrammarDecoration(const DocumentMarker::MarkerType&, const StringView& text, unsigned paint_start_offset, - unsigned paint_end_offset) const; + unsigned paint_end_offset); void ClipToPartDecorations(const NGHighlightOverlay::HighlightPart&); void PaintDecorationsExceptLineThrough( const NGHighlightOverlay::HighlightPart&); diff --git a/third_party/blink/renderer/core/paint/text_decoration_info.cc b/third_party/blink/renderer/core/paint/text_decoration_info.cc index 04754b4eafb1d..6eca63e743cda 100644 --- a/third_party/blink/renderer/core/paint/text_decoration_info.cc +++ b/third_party/blink/renderer/core/paint/text_decoration_info.cc @@ -60,8 +60,7 @@ inline bool ShouldUseDecoratingBox(const ComputedStyle& style) { // find the decorating box. For example, |NGHighlightPainter| creates a // |kPseudoIdHighlight| pseudo style on the fly. const PseudoId pseudo_id = style.StyleType(); - if (pseudo_id == kPseudoIdSelection || pseudo_id == kPseudoIdTargetText || - pseudo_id == kPseudoIdHighlight) + if (IsHighlightPseudoElement(pseudo_id)) return false; return true; }