[webkit-changes] [WebKit/WebKit] 971fab: Toggling the spellcheck attribute on input element...

Aditya Keerthi noreply at github.com
Tue Dec 12 06:26:48 PST 2023


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

  Changed paths:
    A LayoutTests/editing/spelling/spellcheck-attribute-toggle-expected.html
    A LayoutTests/editing/spelling/spellcheck-attribute-toggle.html
    M Source/WebCore/dom/Document.h
    M Source/WebCore/html/HTMLElement.cpp
    M Source/WebCore/html/HTMLElement.h
    M Source/WebCore/html/HTMLTextFormControlElement.cpp
    M Source/WebCore/html/HTMLTextFormControlElement.h

  Log Message:
  -----------
  Toggling the spellcheck attribute on input elements doesn't toggle spelling markers
https://bugs.webkit.org/show_bug.cgi?id=265958
rdar://119269616

Reviewed by Wenson Hsieh.

Add or remove spelling and grammar markers from <input> and <textarea> if the
control has been focused at some point, and the spellcheck attribute is toggled.

General `contenteditable` are currently excluded from this behavior, since
storing additional information about whether an element has ever been focused
would be expensive. Additionally, the behavior this patch implements matches
Firefox exactly.

* LayoutTests/editing/spelling/spellcheck-attribute-toggle-expected.html: Added.
* LayoutTests/editing/spelling/spellcheck-attribute-toggle.html: Added.
* Source/WebCore/dom/Document.h:
(WebCore::Document::hasEverHadSelectionInsideTextFormControl const):
(WebCore::Document::setHasEverHadSelectionInsideTextFormControl):

Store a bit to indicate if a selection has ever been inside a text form control.
Since spellchecking can only occur if a selection has been made, this serves to
provide an optimization where changes to the spellcheck attribute do not perform
unnecessary tree walks when the page is first loaded, before any editing commands
have occured, and before a selection is made.

* Source/WebCore/html/HTMLElement.cpp:
(WebCore::HTMLElement::attributeChanged):
(WebCore::HTMLElement::effectiveSpellcheckAttributeChanged):

The effective value of the spellcheck attribute is determined by the nearest
ancestor if the element itself does not have the attribute specified. Perform
a descendant tree walk to find affected elements for a given attribute change.
Note the optimization described earlier to avoid unnecessary tree walks.

* Source/WebCore/html/HTMLElement.h:
* Source/WebCore/html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::selectionChanged):
(WebCore::HTMLTextFormControlElement::effectiveSpellcheckAttributeChanged):

Toggle markers only if the control has had a selection at some point.

* Source/WebCore/html/HTMLTextFormControlElement.h:

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




More information about the webkit-changes mailing list