[webkit-changes] [WebKit/WebKit] dea793: Add support for styling grammar and spelling errors

Aditya Keerthi noreply at github.com
Wed Dec 6 16:01:38 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: dea7937dec2bc7d25ea94641cb60bdf586f6526e
      https://github.com/WebKit/WebKit/commit/dea7937dec2bc7d25ea94641cb60bdf586f6526e
  Author: Aditya Keerthi <akeerthi at apple.com>
  Date:   2023-12-06 (Wed, 06 Dec 2023)

  Changed paths:
    A LayoutTests/editing/spelling/grammar-and-spelling-error-styling-expected.html
    A LayoutTests/editing/spelling/grammar-and-spelling-error-styling.html
    M Source/WebCore/rendering/MarkedText.cpp
    M Source/WebCore/rendering/RenderElement.cpp
    M Source/WebCore/rendering/RenderElement.h
    M Source/WebCore/rendering/RenderText.h
    M Source/WebCore/rendering/StyledMarkedText.cpp
    M Source/WebCore/rendering/TextBoxPainter.cpp
    M Source/WebCore/rendering/TextPaintStyle.cpp
    M Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h
    M Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
    M Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm

  Log Message:
  -----------
  Add support for styling grammar and spelling errors
https://bugs.webkit.org/show_bug.cgi?id=265879
rdar://119190841

Reviewed by Antti Koivisto.

Support the use of `::grammar-error` and `::spelling-error` to change the color,
background color, fill color, stroke color, and text decoration of grammar and
spelling errors.

Similar to `::highlight()`, support for `text-shadow` and `stroke-width` is
currently missing. To adhere to the spec, support for these properties should
be added for all highlight pseudo-elements in subsequent changes.

Spec: https://www.w3.org/TR/css-pseudo-4/#highlight-styling

* LayoutTests/editing/spelling/grammar-and-spelling-error-styling-expected.html: Added.
* LayoutTests/editing/spelling/grammar-and-spelling-error-styling.html: Added.
* Source/WebCore/rendering/MarkedText.cpp:
(WebCore::MarkedText::collectForDocumentMarkers):

Ensure grammar and spelling markers are collected for all paint phases, since
they are fully styleable.

* Source/WebCore/rendering/RenderElement.cpp:
(WebCore::RenderElement::textSegmentPseudoStyle const):

Factor out pseudo-element style retrieval for text nodes into a common method.

Additionally, use `getCachedPseudoStyle` rather than `getUncachedPseudoStyle`,
since `::selection`, `::grammar-error`, and `::spelling-error` do not take
additional parameters.

(WebCore::RenderElement::selectionColor const):
(WebCore::RenderElement::selectionPseudoStyle const):
(WebCore::RenderElement::selectionBackgroundColor const):
(WebCore::RenderElement::spellingErrorPseudoStyle const):
(WebCore::RenderElement::grammarErrorPseudoStyle const):
* Source/WebCore/rendering/RenderElement.h:

Update comment describing when to use `getCachedPseudoStyle` and `getUncachedPseudoStyle`
for accuracy.

* Source/WebCore/rendering/RenderText.h:
(WebCore::RenderText::selectionPseudoStyle const):
(WebCore::RenderText::spellingErrorPseudoStyle const):
(WebCore::RenderText::grammarErrorPseudoStyle const):
* Source/WebCore/rendering/StyledMarkedText.cpp:
(WebCore::computeStyleForPseudoElementStyle):

Factor out `StyledMarkedText` generation into a common method used by highlights
and the grammar and spelling pseudo elements.

(WebCore::resolveStyleForMarkedText):
* Source/WebCore/rendering/TextBoxPainter.cpp:
(WebCore::TextBoxPainter<TextBoxPath>::paintForegroundAndDecorations):

Detect text decorations when grammar and spelling pseudo styles are applied to
ensure the paint phase is not skipped.

(WebCore::TextBoxPainter<TextBoxPath>::paintPlatformDocumentMarkers):

Do not paint platform error underlines if a custom text decoration is specified
using the new pseudo-elements.

* Source/WebCore/rendering/TextPaintStyle.cpp:
(WebCore::computeTextSelectionPaintStyle):
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm:
(-[WKWebView _setGrammarCheckingEnabledForTesting:]):
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.h:
* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView setGrammarCheckingEnabled:]):
* Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm:
(WTR::TestController::cocoaResetStateToConsistentValues):

Always enable grammar checking for testing. Grammar checking is already enabled
by default on most Cocoa platforms other than older macOS.

Canonical link: https://commits.webkit.org/271643@main




More information about the webkit-changes mailing list