Title: [272109] branches/safari-611-branch
Revision
272109
Author
[email protected]
Date
2021-01-29 21:41:22 -0800 (Fri, 29 Jan 2021)

Log Message

Cherry-pick r271459. rdar://problem/73473665

    [macOS] "Correct Spelling Automatically" menu items are inconsistent when autocorrect="off"
    https://bugs.webkit.org/show_bug.cgi?id=220598
    <rdar://problem/71713611>

    Reviewed by Tim Horton.

    Source/WebCore:

    Disable the context menu item to toggle automatic spelling correction, as well as the menu bar item to toggle
    automatic spelling correction, in the case where the autocorrect attribute is set to "off". See below for more
    details.

    Tests:  editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html
            DisableAutomaticSpellingCorrection.AutocorrectAttribute

    * editing/AlternativeTextController.cpp:
    (WebCore::AlternativeTextController::canEnableAutomaticSpellingCorrection const):

    Factor out logic for checking the `autocorrect` attribute into a separate helper function; this is used to
    determine whether or not we should enable both the context menu item and menu item in the menu bar.

    (WebCore::AlternativeTextController::isAutomaticSpellingCorrectionEnabled):
    * editing/AlternativeTextController.h:
    (WebCore::AlternativeTextController::UNLESS_ENABLED):
    * editing/Editor.cpp:
    (WebCore::Editor::canEnableAutomaticSpellingCorrection const):
    * editing/Editor.h:
    * page/ContextMenuController.cpp:
    (WebCore::ContextMenuController::checkOrEnableIfNeeded const):

    Source/WebKit:

    Plumb the new `canEnableAutomaticSpellingCorrection` flag through `EditorState` to the UI process, where we can
    consult it when validating user interface items (namely, the "Correct Spelling Automatically" menu item, which
    corresponds to the `-toggleAutomaticSpellingCorrection:` selector).

    * Shared/EditorState.cpp:
    (WebKit::EditorState::PostLayoutData::encode const):
    (WebKit::EditorState::PostLayoutData::decode):
    (WebKit::operator<<):
    * Shared/EditorState.h:
    * UIProcess/Cocoa/WebViewImpl.mm:
    (WebKit::WebViewImpl::validateUserInterfaceItem):
    * WebProcess/WebPage/mac/WebPageMac.mm:
    (WebKit::WebPage::getPlatformEditorState const):

    Tools:

    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
    * TestWebKitAPI/Tests/mac/DisableAutomaticSpellingCorrection.mm: Added.

    Add a new API test to verify that the `NSMenuItem` for toggling automatic spelling correction is invalid when
    editing inside a form control with autocorrect="off".

    * WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
    (WTR::getMenuItemEnabledCallback):

    Add the readonly `enabled` JS property on context menu items. See the new layout test,
    editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html, for more information.

    LayoutTests:

    Add a new API test to verify that the context menu item to toggle "Correct Spelling Automatically" is disabled
    when autocorrect="off".

    * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item-expected.txt: Added.
    * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html: Added.
    * platform/mac-wk1/TestExpectations:

    Disable the test in DumpRenderTree, due to lack of support for context menu testing in WebKit1.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271459 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-611-branch/LayoutTests/ChangeLog (272108 => 272109)


--- branches/safari-611-branch/LayoutTests/ChangeLog	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/LayoutTests/ChangeLog	2021-01-30 05:41:22 UTC (rev 272109)
@@ -1,5 +1,100 @@
 2021-01-29  Alan Coon  <[email protected]>
 
+        Cherry-pick r271459. rdar://problem/73473665
+
+    [macOS] "Correct Spelling Automatically" menu items are inconsistent when autocorrect="off"
+    https://bugs.webkit.org/show_bug.cgi?id=220598
+    <rdar://problem/71713611>
+    
+    Reviewed by Tim Horton.
+    
+    Source/WebCore:
+    
+    Disable the context menu item to toggle automatic spelling correction, as well as the menu bar item to toggle
+    automatic spelling correction, in the case where the autocorrect attribute is set to "off". See below for more
+    details.
+    
+    Tests:  editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html
+            DisableAutomaticSpellingCorrection.AutocorrectAttribute
+    
+    * editing/AlternativeTextController.cpp:
+    (WebCore::AlternativeTextController::canEnableAutomaticSpellingCorrection const):
+    
+    Factor out logic for checking the `autocorrect` attribute into a separate helper function; this is used to
+    determine whether or not we should enable both the context menu item and menu item in the menu bar.
+    
+    (WebCore::AlternativeTextController::isAutomaticSpellingCorrectionEnabled):
+    * editing/AlternativeTextController.h:
+    (WebCore::AlternativeTextController::UNLESS_ENABLED):
+    * editing/Editor.cpp:
+    (WebCore::Editor::canEnableAutomaticSpellingCorrection const):
+    * editing/Editor.h:
+    * page/ContextMenuController.cpp:
+    (WebCore::ContextMenuController::checkOrEnableIfNeeded const):
+    
+    Source/WebKit:
+    
+    Plumb the new `canEnableAutomaticSpellingCorrection` flag through `EditorState` to the UI process, where we can
+    consult it when validating user interface items (namely, the "Correct Spelling Automatically" menu item, which
+    corresponds to the `-toggleAutomaticSpellingCorrection:` selector).
+    
+    * Shared/EditorState.cpp:
+    (WebKit::EditorState::PostLayoutData::encode const):
+    (WebKit::EditorState::PostLayoutData::decode):
+    (WebKit::operator<<):
+    * Shared/EditorState.h:
+    * UIProcess/Cocoa/WebViewImpl.mm:
+    (WebKit::WebViewImpl::validateUserInterfaceItem):
+    * WebProcess/WebPage/mac/WebPageMac.mm:
+    (WebKit::WebPage::getPlatformEditorState const):
+    
+    Tools:
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/mac/DisableAutomaticSpellingCorrection.mm: Added.
+    
+    Add a new API test to verify that the `NSMenuItem` for toggling automatic spelling correction is invalid when
+    editing inside a form control with autocorrect="off".
+    
+    * WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
+    (WTR::getMenuItemEnabledCallback):
+    
+    Add the readonly `enabled` JS property on context menu items. See the new layout test,
+    editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html, for more information.
+    
+    LayoutTests:
+    
+    Add a new API test to verify that the context menu item to toggle "Correct Spelling Automatically" is disabled
+    when autocorrect="off".
+    
+    * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item-expected.txt: Added.
+    * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html: Added.
+    * platform/mac-wk1/TestExpectations:
+    
+    Disable the test in DumpRenderTree, due to lack of support for context menu testing in WebKit1.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-01-13  Wenson Hsieh  <[email protected]>
+
+            [macOS] "Correct Spelling Automatically" menu items are inconsistent when autocorrect="off"
+            https://bugs.webkit.org/show_bug.cgi?id=220598
+            <rdar://problem/71713611>
+
+            Reviewed by Tim Horton.
+
+            Add a new API test to verify that the context menu item to toggle "Correct Spelling Automatically" is disabled
+            when autocorrect="off".
+
+            * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item-expected.txt: Added.
+            * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html: Added.
+            * platform/mac-wk1/TestExpectations:
+
+            Disable the test in DumpRenderTree, due to lack of support for context menu testing in WebKit1.
+
+2021-01-29  Alan Coon  <[email protected]>
+
         Cherry-pick r271388. rdar://problem/73473676
 
     Safari 14 on 2x display renders NYS DMV page as blurry

Added: branches/safari-611-branch/LayoutTests/editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item-expected.txt (0 => 272109)


--- branches/safari-611-branch/LayoutTests/editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item-expected.txt	                        (rev 0)
+++ branches/safari-611-branch/LayoutTests/editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item-expected.txt	2021-01-30 05:41:22 UTC (rev 272109)
@@ -0,0 +1,13 @@
+
+
+Verifies that autocorrect='off' disables the 'Correct Spelling Automatically' context menu item on macOS. To manually test, check that the menu item is disabled when right clicking the top text field, but enabled when clicking the bottom text field.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS isSpellingCorrectionMenuItemEnabled(topInput) is false
+PASS isSpellingCorrectionMenuItemEnabled(bottomInput) is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: branches/safari-611-branch/LayoutTests/editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html (0 => 272109)


--- branches/safari-611-branch/LayoutTests/editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html	                        (rev 0)
+++ branches/safari-611-branch/LayoutTests/editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html	2021-01-30 05:41:22 UTC (rev 272109)
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+    <div><input id="top" autocorrect="off"></input></div>
+    <div><input id="bottom"></input></div>
+</body>
+<p id="description"></p>
+<p id="console"></p>
+</body>
+<script>
+function isSpellingCorrectionMenuItemEnabled(element)
+{
+    const elementRect = element.getBoundingClientRect();
+    eventSender.mouseMoveTo(elementRect.left + elementRect.width / 2, elementRect.top + elementRect.height / 2);
+
+    const spellingMenuItem = eventSender.contextClick().find(item => item.title === "Spelling and Grammar");
+    return spellingMenuItem.children.find(item => item.title === "Correct Spelling Automatically").enabled;
+}
+
+description("Verifies that autocorrect='off' disables the 'Correct Spelling Automatically' context menu item on macOS. To manually test, check that the menu item is disabled when right clicking the top text field, but enabled when clicking the bottom text field.");
+
+topInput = document.getElementById("top");
+bottomInput = document.getElementById("bottom");
+
+if (window.eventSender) {
+    shouldBeFalse("isSpellingCorrectionMenuItemEnabled(topInput)");
+    shouldBeTrue("isSpellingCorrectionMenuItemEnabled(bottomInput)");
+}
+</script>
+</html>

Modified: branches/safari-611-branch/LayoutTests/platform/mac-wk1/TestExpectations (272108 => 272109)


--- branches/safari-611-branch/LayoutTests/platform/mac-wk1/TestExpectations	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/LayoutTests/platform/mac-wk1/TestExpectations	2021-01-30 05:41:22 UTC (rev 272109)
@@ -290,6 +290,9 @@
 # Fails with WebKit1 only.
 editing/secure-input/reset-state-on-navigation.html [ Failure ]
 
+# Context menu API is not exposed on DumpRenderTree.
+editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html [ Skip ]
+
 http/tests/plugins/nounsupported-plugin.html [ Skip ]
 http/tests/plugins/supported-plugin-all-origin-visibility.html [ Skip ]
 http/tests/plugins/supported-plugin-origin-specific-visibility.html [ Skip ]

Modified: branches/safari-611-branch/Source/WebCore/ChangeLog (272108 => 272109)


--- branches/safari-611-branch/Source/WebCore/ChangeLog	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Source/WebCore/ChangeLog	2021-01-30 05:41:22 UTC (rev 272109)
@@ -1,5 +1,113 @@
 2021-01-29  Alan Coon  <[email protected]>
 
+        Cherry-pick r271459. rdar://problem/73473665
+
+    [macOS] "Correct Spelling Automatically" menu items are inconsistent when autocorrect="off"
+    https://bugs.webkit.org/show_bug.cgi?id=220598
+    <rdar://problem/71713611>
+    
+    Reviewed by Tim Horton.
+    
+    Source/WebCore:
+    
+    Disable the context menu item to toggle automatic spelling correction, as well as the menu bar item to toggle
+    automatic spelling correction, in the case where the autocorrect attribute is set to "off". See below for more
+    details.
+    
+    Tests:  editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html
+            DisableAutomaticSpellingCorrection.AutocorrectAttribute
+    
+    * editing/AlternativeTextController.cpp:
+    (WebCore::AlternativeTextController::canEnableAutomaticSpellingCorrection const):
+    
+    Factor out logic for checking the `autocorrect` attribute into a separate helper function; this is used to
+    determine whether or not we should enable both the context menu item and menu item in the menu bar.
+    
+    (WebCore::AlternativeTextController::isAutomaticSpellingCorrectionEnabled):
+    * editing/AlternativeTextController.h:
+    (WebCore::AlternativeTextController::UNLESS_ENABLED):
+    * editing/Editor.cpp:
+    (WebCore::Editor::canEnableAutomaticSpellingCorrection const):
+    * editing/Editor.h:
+    * page/ContextMenuController.cpp:
+    (WebCore::ContextMenuController::checkOrEnableIfNeeded const):
+    
+    Source/WebKit:
+    
+    Plumb the new `canEnableAutomaticSpellingCorrection` flag through `EditorState` to the UI process, where we can
+    consult it when validating user interface items (namely, the "Correct Spelling Automatically" menu item, which
+    corresponds to the `-toggleAutomaticSpellingCorrection:` selector).
+    
+    * Shared/EditorState.cpp:
+    (WebKit::EditorState::PostLayoutData::encode const):
+    (WebKit::EditorState::PostLayoutData::decode):
+    (WebKit::operator<<):
+    * Shared/EditorState.h:
+    * UIProcess/Cocoa/WebViewImpl.mm:
+    (WebKit::WebViewImpl::validateUserInterfaceItem):
+    * WebProcess/WebPage/mac/WebPageMac.mm:
+    (WebKit::WebPage::getPlatformEditorState const):
+    
+    Tools:
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/mac/DisableAutomaticSpellingCorrection.mm: Added.
+    
+    Add a new API test to verify that the `NSMenuItem` for toggling automatic spelling correction is invalid when
+    editing inside a form control with autocorrect="off".
+    
+    * WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
+    (WTR::getMenuItemEnabledCallback):
+    
+    Add the readonly `enabled` JS property on context menu items. See the new layout test,
+    editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html, for more information.
+    
+    LayoutTests:
+    
+    Add a new API test to verify that the context menu item to toggle "Correct Spelling Automatically" is disabled
+    when autocorrect="off".
+    
+    * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item-expected.txt: Added.
+    * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html: Added.
+    * platform/mac-wk1/TestExpectations:
+    
+    Disable the test in DumpRenderTree, due to lack of support for context menu testing in WebKit1.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-01-13  Wenson Hsieh  <[email protected]>
+
+            [macOS] "Correct Spelling Automatically" menu items are inconsistent when autocorrect="off"
+            https://bugs.webkit.org/show_bug.cgi?id=220598
+            <rdar://problem/71713611>
+
+            Reviewed by Tim Horton.
+
+            Disable the context menu item to toggle automatic spelling correction, as well as the menu bar item to toggle
+            automatic spelling correction, in the case where the autocorrect attribute is set to "off". See below for more
+            details.
+
+            Tests:  editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html
+                    DisableAutomaticSpellingCorrection.AutocorrectAttribute
+
+            * editing/AlternativeTextController.cpp:
+            (WebCore::AlternativeTextController::canEnableAutomaticSpellingCorrection const):
+
+            Factor out logic for checking the `autocorrect` attribute into a separate helper function; this is used to
+            determine whether or not we should enable both the context menu item and menu item in the menu bar.
+
+            (WebCore::AlternativeTextController::isAutomaticSpellingCorrectionEnabled):
+            * editing/AlternativeTextController.h:
+            (WebCore::AlternativeTextController::UNLESS_ENABLED):
+            * editing/Editor.cpp:
+            (WebCore::Editor::canEnableAutomaticSpellingCorrection const):
+            * editing/Editor.h:
+            * page/ContextMenuController.cpp:
+            (WebCore::ContextMenuController::checkOrEnableIfNeeded const):
+
+2021-01-29  Alan Coon  <[email protected]>
+
         Cherry-pick r271414. rdar://problem/73473727
 
     REGRESSION (r265044): [macOS] Safari autocorrects text when typing in login field on amazon.com

Modified: branches/safari-611-branch/Source/WebCore/editing/AlternativeTextController.cpp (272108 => 272109)


--- branches/safari-611-branch/Source/WebCore/editing/AlternativeTextController.cpp	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Source/WebCore/editing/AlternativeTextController.cpp	2021-01-30 05:41:22 UTC (rev 272109)
@@ -335,11 +335,8 @@
     m_rangeWithAlternative = WTF::nullopt;
 }
 
-bool AlternativeTextController::isAutomaticSpellingCorrectionEnabled()
+bool AlternativeTextController::canEnableAutomaticSpellingCorrection() const
 {
-    if (!editorClient() || !editorClient()->isAutomaticSpellingCorrectionEnabled())
-        return false;
-
 #if ENABLE(AUTOCORRECT)
     auto position = m_document.selection().selection().start();
     if (auto editableRoot = position.rootEditableElement()) {
@@ -356,6 +353,14 @@
     return true;
 }
 
+bool AlternativeTextController::isAutomaticSpellingCorrectionEnabled()
+{
+    if (!editorClient() || !editorClient()->isAutomaticSpellingCorrectionEnabled())
+        return false;
+
+    return canEnableAutomaticSpellingCorrection();
+}
+
 FloatRect AlternativeTextController::rootViewRectForRange(const SimpleRange& range) const
 {
     auto* view = m_document.view();

Modified: branches/safari-611-branch/Source/WebCore/editing/AlternativeTextController.h (272108 => 272109)


--- branches/safari-611-branch/Source/WebCore/editing/AlternativeTextController.h	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Source/WebCore/editing/AlternativeTextController.h	2021-01-30 05:41:22 UTC (rev 272109)
@@ -86,6 +86,7 @@
     bool hasPendingCorrection() const UNLESS_ENABLED({ return false; })
     bool isSpellingMarkerAllowed(const SimpleRange& misspellingRange) const UNLESS_ENABLED({ UNUSED_PARAM(misspellingRange); return true; })
     bool isAutomaticSpellingCorrectionEnabled() UNLESS_ENABLED({ return false; })
+    bool canEnableAutomaticSpellingCorrection() const UNLESS_ENABLED({ return false; })
     bool shouldRemoveMarkersUponEditing();
 
     void recordAutocorrectionResponse(AutocorrectionResponse, const String& replacedString, const SimpleRange& replacementRange) UNLESS_ENABLED({ UNUSED_PARAM(replacedString); UNUSED_PARAM(replacementRange); })

Modified: branches/safari-611-branch/Source/WebCore/editing/Editor.cpp (272108 => 272109)


--- branches/safari-611-branch/Source/WebCore/editing/Editor.cpp	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Source/WebCore/editing/Editor.cpp	2021-01-30 05:41:22 UTC (rev 272109)
@@ -1765,6 +1765,11 @@
         client()->toggleAutomaticTextReplacement();
 }
 
+bool Editor::canEnableAutomaticSpellingCorrection() const
+{
+    return m_alternativeTextController->canEnableAutomaticSpellingCorrection();
+}
+
 bool Editor::isAutomaticSpellingCorrectionEnabled()
 {
     return m_alternativeTextController->isAutomaticSpellingCorrectionEnabled();

Modified: branches/safari-611-branch/Source/WebCore/editing/Editor.h (272108 => 272109)


--- branches/safari-611-branch/Source/WebCore/editing/Editor.h	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Source/WebCore/editing/Editor.h	2021-01-30 05:41:22 UTC (rev 272109)
@@ -511,6 +511,7 @@
     WEBCORE_EXPORT void toggleAutomaticTextReplacement();
     WEBCORE_EXPORT bool isAutomaticSpellingCorrectionEnabled();
     WEBCORE_EXPORT void toggleAutomaticSpellingCorrection();
+    WEBCORE_EXPORT bool canEnableAutomaticSpellingCorrection() const;
 #endif
 
     RefPtr<DocumentFragment> webContentFromPasteboard(Pasteboard&, const SimpleRange& context, bool allowPlainText, bool& chosePlainText);

Modified: branches/safari-611-branch/Source/WebCore/page/ContextMenuController.cpp (272108 => 272109)


--- branches/safari-611-branch/Source/WebCore/page/ContextMenuController.cpp	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Source/WebCore/page/ContextMenuController.cpp	2021-01-30 05:41:22 UTC (rev 272109)
@@ -1324,6 +1324,7 @@
             break;
         case ContextMenuItemTagCorrectSpellingAutomatically:
             shouldCheck = frame->editor().isAutomaticSpellingCorrectionEnabled();
+            shouldEnable = frame->editor().canEnableAutomaticSpellingCorrection();
             break;
         case ContextMenuItemTagSmartCopyPaste:
             shouldCheck = frame->editor().smartInsertDeleteEnabled();

Modified: branches/safari-611-branch/Source/WebKit/ChangeLog (272108 => 272109)


--- branches/safari-611-branch/Source/WebKit/ChangeLog	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Source/WebKit/ChangeLog	2021-01-30 05:41:22 UTC (rev 272109)
@@ -1,5 +1,105 @@
 2021-01-29  Alan Coon  <[email protected]>
 
+        Cherry-pick r271459. rdar://problem/73473665
+
+    [macOS] "Correct Spelling Automatically" menu items are inconsistent when autocorrect="off"
+    https://bugs.webkit.org/show_bug.cgi?id=220598
+    <rdar://problem/71713611>
+    
+    Reviewed by Tim Horton.
+    
+    Source/WebCore:
+    
+    Disable the context menu item to toggle automatic spelling correction, as well as the menu bar item to toggle
+    automatic spelling correction, in the case where the autocorrect attribute is set to "off". See below for more
+    details.
+    
+    Tests:  editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html
+            DisableAutomaticSpellingCorrection.AutocorrectAttribute
+    
+    * editing/AlternativeTextController.cpp:
+    (WebCore::AlternativeTextController::canEnableAutomaticSpellingCorrection const):
+    
+    Factor out logic for checking the `autocorrect` attribute into a separate helper function; this is used to
+    determine whether or not we should enable both the context menu item and menu item in the menu bar.
+    
+    (WebCore::AlternativeTextController::isAutomaticSpellingCorrectionEnabled):
+    * editing/AlternativeTextController.h:
+    (WebCore::AlternativeTextController::UNLESS_ENABLED):
+    * editing/Editor.cpp:
+    (WebCore::Editor::canEnableAutomaticSpellingCorrection const):
+    * editing/Editor.h:
+    * page/ContextMenuController.cpp:
+    (WebCore::ContextMenuController::checkOrEnableIfNeeded const):
+    
+    Source/WebKit:
+    
+    Plumb the new `canEnableAutomaticSpellingCorrection` flag through `EditorState` to the UI process, where we can
+    consult it when validating user interface items (namely, the "Correct Spelling Automatically" menu item, which
+    corresponds to the `-toggleAutomaticSpellingCorrection:` selector).
+    
+    * Shared/EditorState.cpp:
+    (WebKit::EditorState::PostLayoutData::encode const):
+    (WebKit::EditorState::PostLayoutData::decode):
+    (WebKit::operator<<):
+    * Shared/EditorState.h:
+    * UIProcess/Cocoa/WebViewImpl.mm:
+    (WebKit::WebViewImpl::validateUserInterfaceItem):
+    * WebProcess/WebPage/mac/WebPageMac.mm:
+    (WebKit::WebPage::getPlatformEditorState const):
+    
+    Tools:
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/mac/DisableAutomaticSpellingCorrection.mm: Added.
+    
+    Add a new API test to verify that the `NSMenuItem` for toggling automatic spelling correction is invalid when
+    editing inside a form control with autocorrect="off".
+    
+    * WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
+    (WTR::getMenuItemEnabledCallback):
+    
+    Add the readonly `enabled` JS property on context menu items. See the new layout test,
+    editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html, for more information.
+    
+    LayoutTests:
+    
+    Add a new API test to verify that the context menu item to toggle "Correct Spelling Automatically" is disabled
+    when autocorrect="off".
+    
+    * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item-expected.txt: Added.
+    * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html: Added.
+    * platform/mac-wk1/TestExpectations:
+    
+    Disable the test in DumpRenderTree, due to lack of support for context menu testing in WebKit1.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-01-13  Wenson Hsieh  <[email protected]>
+
+            [macOS] "Correct Spelling Automatically" menu items are inconsistent when autocorrect="off"
+            https://bugs.webkit.org/show_bug.cgi?id=220598
+            <rdar://problem/71713611>
+
+            Reviewed by Tim Horton.
+
+            Plumb the new `canEnableAutomaticSpellingCorrection` flag through `EditorState` to the UI process, where we can
+            consult it when validating user interface items (namely, the "Correct Spelling Automatically" menu item, which
+            corresponds to the `-toggleAutomaticSpellingCorrection:` selector).
+
+            * Shared/EditorState.cpp:
+            (WebKit::EditorState::PostLayoutData::encode const):
+            (WebKit::EditorState::PostLayoutData::decode):
+            (WebKit::operator<<):
+            * Shared/EditorState.h:
+            * UIProcess/Cocoa/WebViewImpl.mm:
+            (WebKit::WebViewImpl::validateUserInterfaceItem):
+            * WebProcess/WebPage/mac/WebPageMac.mm:
+            (WebKit::WebPage::getPlatformEditorState const):
+
+2021-01-29  Alan Coon  <[email protected]>
+
         Cherry-pick r271414. rdar://problem/73473727
 
     REGRESSION (r265044): [macOS] Safari autocorrects text when typing in login field on amazon.com

Modified: branches/safari-611-branch/Source/WebKit/Shared/EditorState.cpp (272108 => 272109)


--- branches/safari-611-branch/Source/WebKit/Shared/EditorState.cpp	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Source/WebKit/Shared/EditorState.cpp	2021-01-30 05:41:22 UTC (rev 272109)
@@ -132,6 +132,7 @@
     encoder << candidateRequestStartPosition;
     encoder << paragraphContextForCandidateRequest;
     encoder << stringForCandidateRequest;
+    encoder << canEnableAutomaticSpellingCorrection;
 #endif
 #if PLATFORM(GTK) || PLATFORM(WPE)
     encoder << surroundingContext;
@@ -224,6 +225,9 @@
 
     if (!decoder.decode(result.stringForCandidateRequest))
         return false;
+
+    if (!decoder.decode(result.canEnableAutomaticSpellingCorrection))
+        return false;
 #endif
 #if PLATFORM(GTK) || PLATFORM(WPE)
     if (!decoder.decode(result.surroundingContext))
@@ -338,6 +342,8 @@
         ts.dumpProperty("paragraphContextForCandidateRequest", editorState.postLayoutData().paragraphContextForCandidateRequest);
     if (editorState.postLayoutData().stringForCandidateRequest.length())
         ts.dumpProperty("stringForCandidateRequest", editorState.postLayoutData().stringForCandidateRequest);
+    if (editorState.postLayoutData().canEnableAutomaticSpellingCorrection)
+        ts.dumpProperty("canEnableAutomaticSpellingCorrection", editorState.postLayoutData().canEnableAutomaticSpellingCorrection);
 #endif
 
     if (editorState.postLayoutData().canCut)

Modified: branches/safari-611-branch/Source/WebKit/Shared/EditorState.h (272108 => 272109)


--- branches/safari-611-branch/Source/WebKit/Shared/EditorState.h	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Source/WebKit/Shared/EditorState.h	2021-01-30 05:41:22 UTC (rev 272109)
@@ -123,6 +123,7 @@
         uint64_t candidateRequestStartPosition { 0 };
         String paragraphContextForCandidateRequest;
         String stringForCandidateRequest;
+        bool canEnableAutomaticSpellingCorrection { true };
 #endif
 #if PLATFORM(GTK) || PLATFORM(WPE)
         String surroundingContext;

Modified: branches/safari-611-branch/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (272108 => 272109)


--- branches/safari-611-branch/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2021-01-30 05:41:22 UTC (rev 272109)
@@ -3063,9 +3063,10 @@
     }
 
     if (action == @selector(toggleAutomaticSpellingCorrection:)) {
-        bool checked = TextChecker::state().isAutomaticSpellingCorrectionEnabled;
-        [menuItem(item) setState:checked ? NSControlStateValueOn : NSControlStateValueOff];
-        return m_page->editorState().isContentEditable;
+        auto& editorState = m_page->editorState();
+        bool enable = editorState.isContentEditable && (editorState.isMissingPostLayoutData || editorState.postLayoutData().canEnableAutomaticSpellingCorrection);
+        menuItem(item).state = TextChecker::state().isAutomaticSpellingCorrectionEnabled && enable ? NSControlStateValueOn : NSControlStateValueOff;
+        return enable;
     }
 
     if (action == @selector(orderFrontSubstitutionsPanel:)) {

Modified: branches/safari-611-branch/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm (272108 => 272109)


--- branches/safari-611-branch/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm	2021-01-30 05:41:22 UTC (rev 272109)
@@ -164,6 +164,7 @@
     postLayoutData.selectedTextLength = characterCount({ *selectionStartBoundary, *selectionEnd });
     postLayoutData.paragraphContextForCandidateRequest = contextRangeForCandidateRequest ? plainText(*contextRangeForCandidateRequest) : String();
     postLayoutData.stringForCandidateRequest = frame.editor().stringForCandidateRequest();
+    postLayoutData.canEnableAutomaticSpellingCorrection = frame.editor().canEnableAutomaticSpellingCorrection();
 
     auto quads = RenderObject::absoluteTextQuads(*selectedRange);
     if (!quads.isEmpty())

Modified: branches/safari-611-branch/Tools/ChangeLog (272108 => 272109)


--- branches/safari-611-branch/Tools/ChangeLog	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Tools/ChangeLog	2021-01-30 05:41:22 UTC (rev 272109)
@@ -1,5 +1,103 @@
 2021-01-29  Alan Coon  <[email protected]>
 
+        Cherry-pick r271459. rdar://problem/73473665
+
+    [macOS] "Correct Spelling Automatically" menu items are inconsistent when autocorrect="off"
+    https://bugs.webkit.org/show_bug.cgi?id=220598
+    <rdar://problem/71713611>
+    
+    Reviewed by Tim Horton.
+    
+    Source/WebCore:
+    
+    Disable the context menu item to toggle automatic spelling correction, as well as the menu bar item to toggle
+    automatic spelling correction, in the case where the autocorrect attribute is set to "off". See below for more
+    details.
+    
+    Tests:  editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html
+            DisableAutomaticSpellingCorrection.AutocorrectAttribute
+    
+    * editing/AlternativeTextController.cpp:
+    (WebCore::AlternativeTextController::canEnableAutomaticSpellingCorrection const):
+    
+    Factor out logic for checking the `autocorrect` attribute into a separate helper function; this is used to
+    determine whether or not we should enable both the context menu item and menu item in the menu bar.
+    
+    (WebCore::AlternativeTextController::isAutomaticSpellingCorrectionEnabled):
+    * editing/AlternativeTextController.h:
+    (WebCore::AlternativeTextController::UNLESS_ENABLED):
+    * editing/Editor.cpp:
+    (WebCore::Editor::canEnableAutomaticSpellingCorrection const):
+    * editing/Editor.h:
+    * page/ContextMenuController.cpp:
+    (WebCore::ContextMenuController::checkOrEnableIfNeeded const):
+    
+    Source/WebKit:
+    
+    Plumb the new `canEnableAutomaticSpellingCorrection` flag through `EditorState` to the UI process, where we can
+    consult it when validating user interface items (namely, the "Correct Spelling Automatically" menu item, which
+    corresponds to the `-toggleAutomaticSpellingCorrection:` selector).
+    
+    * Shared/EditorState.cpp:
+    (WebKit::EditorState::PostLayoutData::encode const):
+    (WebKit::EditorState::PostLayoutData::decode):
+    (WebKit::operator<<):
+    * Shared/EditorState.h:
+    * UIProcess/Cocoa/WebViewImpl.mm:
+    (WebKit::WebViewImpl::validateUserInterfaceItem):
+    * WebProcess/WebPage/mac/WebPageMac.mm:
+    (WebKit::WebPage::getPlatformEditorState const):
+    
+    Tools:
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/mac/DisableAutomaticSpellingCorrection.mm: Added.
+    
+    Add a new API test to verify that the `NSMenuItem` for toggling automatic spelling correction is invalid when
+    editing inside a form control with autocorrect="off".
+    
+    * WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
+    (WTR::getMenuItemEnabledCallback):
+    
+    Add the readonly `enabled` JS property on context menu items. See the new layout test,
+    editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html, for more information.
+    
+    LayoutTests:
+    
+    Add a new API test to verify that the context menu item to toggle "Correct Spelling Automatically" is disabled
+    when autocorrect="off".
+    
+    * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item-expected.txt: Added.
+    * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html: Added.
+    * platform/mac-wk1/TestExpectations:
+    
+    Disable the test in DumpRenderTree, due to lack of support for context menu testing in WebKit1.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-01-13  Wenson Hsieh  <[email protected]>
+
+            [macOS] "Correct Spelling Automatically" menu items are inconsistent when autocorrect="off"
+            https://bugs.webkit.org/show_bug.cgi?id=220598
+            <rdar://problem/71713611>
+
+            Reviewed by Tim Horton.
+
+            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+            * TestWebKitAPI/Tests/mac/DisableAutomaticSpellingCorrection.mm: Added.
+
+            Add a new API test to verify that the `NSMenuItem` for toggling automatic spelling correction is invalid when
+            editing inside a form control with autocorrect="off".
+
+            * WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
+            (WTR::getMenuItemEnabledCallback):
+
+            Add the readonly `enabled` JS property on context menu items. See the new layout test,
+            editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html, for more information.
+
+2021-01-29  Alan Coon  <[email protected]>
+
         Cherry-pick r271414. rdar://problem/73473727
 
     REGRESSION (r265044): [macOS] Safari autocorrects text when typing in login field on amazon.com

Modified: branches/safari-611-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (272108 => 272109)


--- branches/safari-611-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-01-30 05:41:22 UTC (rev 272109)
@@ -1197,6 +1197,7 @@
 		F4D2986E20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D2986D20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm */; };
 		F4D4F3B61E4E2BCB00BB2767 /* DragAndDropSimulatorIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B41E4E2BCB00BB2767 /* DragAndDropSimulatorIOS.mm */; };
 		F4D4F3B91E4E36E400BB2767 /* DragAndDropTestsIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B71E4E36E400BB2767 /* DragAndDropTestsIOS.mm */; };
+		F4D5D69525AF8BE400205280 /* DisableAutomaticSpellingCorrection.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D5D69425AF8BE400205280 /* DisableAutomaticSpellingCorrection.mm */; };
 		F4D5E4E81F0C5D38008C1A49 /* dragstart-clear-selection.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4D5E4E71F0C5D27008C1A49 /* dragstart-clear-selection.html */; };
 		F4D65DA81F5E4704009D8C27 /* selected-text-image-link-and-editable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4D65DA71F5E46C0009D8C27 /* selected-text-image-link-and-editable.html */; };
 		F4D9818F2196B920008230FC /* editable-nested-lists.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4D9818E2196B911008230FC /* editable-nested-lists.html */; };
@@ -2967,6 +2968,7 @@
 		F4D2986D20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RunScriptAfterDocumentLoad.mm; sourceTree = "<group>"; };
 		F4D4F3B41E4E2BCB00BB2767 /* DragAndDropSimulatorIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragAndDropSimulatorIOS.mm; sourceTree = "<group>"; };
 		F4D4F3B71E4E36E400BB2767 /* DragAndDropTestsIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragAndDropTestsIOS.mm; sourceTree = "<group>"; };
+		F4D5D69425AF8BE400205280 /* DisableAutomaticSpellingCorrection.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DisableAutomaticSpellingCorrection.mm; sourceTree = "<group>"; };
 		F4D5E4E71F0C5D27008C1A49 /* dragstart-clear-selection.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "dragstart-clear-selection.html"; sourceTree = "<group>"; };
 		F4D65DA71F5E46C0009D8C27 /* selected-text-image-link-and-editable.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "selected-text-image-link-and-editable.html"; sourceTree = "<group>"; };
 		F4D9818E2196B911008230FC /* editable-nested-lists.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "editable-nested-lists.html"; sourceTree = "<group>"; };
@@ -4505,6 +4507,7 @@
 				7AEAD47C1E20113800416EFE /* CrossPartitionFileSchemeAccess.mm */,
 				E5AA8D1C25151CC60051CC45 /* DateInputTests.mm */,
 				939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */,
+				F4D5D69425AF8BE400205280 /* DisableAutomaticSpellingCorrection.mm */,
 				37E1064A1697676400B78BD0 /* DOMHTMLTableCellCellAbove.mm */,
 				2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */,
 				46397B941DC2C850009A78AE /* DOMNode.mm */,
@@ -5194,6 +5197,8 @@
 				7CCE7EE91A411AE600447C4C /* DidAssociateFormControls.cpp in Sources */,
 				7CCE7EEA1A411AE600447C4C /* DidNotHandleKeyDown.cpp in Sources */,
 				AD57AC211DA7465B00FF1BDE /* DidRemoveFrameFromHiearchyInPageCache.cpp in Sources */,
+				F4D5D69525AF8BE400205280 /* DisableAutomaticSpellingCorrection.mm in Sources */,
+				F4B0168325AE060F00E445C4 /* DisableSpellcheck.mm in Sources */,
 				FEC2A85424CE975F00ADBC35 /* DisallowVMEntry.cpp in Sources */,
 				F4094CC725545BD5003D73E3 /* DisplayListTests.cpp in Sources */,
 				F457275E25578D06007ACA34 /* DisplayListTestsCG.cpp in Sources */,
@@ -5520,7 +5525,6 @@
 				515BE1711D428E4B00DD7C68 /* StoreBlobThenDelete.mm in Sources */,
 				7CCE7ED01A411A7E00447C4C /* StringByEvaluatingJavaScriptFromString.mm in Sources */,
 				7CCE7ED11A411A7E00447C4C /* StringTruncator.mm in Sources */,
-				F4B0168325AE060F00E445C4 /* DisableSpellcheck.mm in Sources */,
 				ECA680CE1E68CC0900731D20 /* StringUtilities.mm in Sources */,
 				CE4D5DE71F6743BA0072CFC6 /* StringWithDirection.cpp in Sources */,
 				7CCE7ED21A411A7E00447C4C /* SubresourceErrorCrash.mm in Sources */,
@@ -5704,7 +5708,6 @@
 				5C4259462266A68A0039AA7A /* BasicProposedCredentialPlugIn.mm in Sources */,
 				374B7A611DF371CF00ACCB6C /* BundleEditingDelegatePlugIn.mm in Sources */,
 				7A89BB682331643A0042CB1E /* BundleFormDelegatePlugIn.mm in Sources */,
-				F4B0168425AE08F800E445C4 /* DisableSpellcheckPlugIn.mm in Sources */,
 				A13EBBB01B87436F00097110 /* BundleParametersPlugIn.mm in Sources */,
 				37A709AF1E3EA97E00CA5969 /* BundleRangeHandlePlugIn.mm in Sources */,
 				5C75716122124C5200B9E5AC /* BundleRetainPagePlugIn.mm in Sources */,
@@ -5713,6 +5716,7 @@
 				A14FC58B1B89927100D107EB /* ContentFilteringPlugIn.mm in Sources */,
 				5C121E8D2410704900486F9B /* ContentWorldPlugIn.mm in Sources */,
 				CEA7F57D2089624B0078EF6E /* DidResignInputElementStrongPasswordAppearance.mm in Sources */,
+				F4B0168425AE08F800E445C4 /* DisableSpellcheckPlugIn.mm in Sources */,
 				518EE51920A78CE500E024F3 /* DoubleDefersLoadingPlugin.mm in Sources */,
 				5CB5B3C21FFC55CF00C27BB0 /* FrameHandleSerialization.mm in Sources */,
 				0E404A8C2166DE0A008271BA /* InjectedBundleNodeHandleIsSelectElement.mm in Sources */,

Added: branches/safari-611-branch/Tools/TestWebKitAPI/Tests/mac/DisableAutomaticSpellingCorrection.mm (0 => 272109)


--- branches/safari-611-branch/Tools/TestWebKitAPI/Tests/mac/DisableAutomaticSpellingCorrection.mm	                        (rev 0)
+++ branches/safari-611-branch/Tools/TestWebKitAPI/Tests/mac/DisableAutomaticSpellingCorrection.mm	2021-01-30 05:41:22 UTC (rev 272109)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import "TestWKWebView.h"
+#import <wtf/RetainPtr.h>
+
+TEST(DisableAutomaticSpellingCorrection, AutocorrectAttribute)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+    [webView synchronouslyLoadHTMLString:@"<body><input autocorrect='off' autofocus><input autocorrect='on'></body>"];
+    [webView waitForNextPresentationUpdate];
+
+    auto item = adoptNS([[NSMenuItem alloc] init]);
+    [item setAction:@selector(toggleAutomaticSpellingCorrection:)];
+    EXPECT_FALSE([webView validateUserInterfaceItem:item.get()]);
+
+    [webView stringByEvaluatingJavaScript:@"document.querySelector('input[autocorrect=on]').focus()"];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_TRUE([webView validateUserInterfaceItem:item.get()]);
+}

Modified: branches/safari-611-branch/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp (272108 => 272109)


--- branches/safari-611-branch/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp	2021-01-30 05:41:16 UTC (rev 272108)
+++ branches/safari-611-branch/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp	2021-01-30 05:41:22 UTC (rev 272109)
@@ -67,6 +67,12 @@
     return JSValueMakeString(context, toJS(wkTitle).get());
 }
 
+static JSValueRef getMenuItemEnabledCallback(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    auto* privateData = static_cast<MenuItemPrivateData*>(JSObjectGetPrivate(object));
+    return JSValueMakeBoolean(context, WKContextMenuItemGetEnabled(privateData->m_item.get()));
+}
+
 static JSClassRef getMenuItemClass();
 
 static JSValueRef getMenuItemChildrenCallback(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
@@ -90,6 +96,7 @@
 static JSStaticValue staticMenuItemValues[] = {
     { "title", getMenuItemTitleCallback, 0, kJSPropertyAttributeReadOnly },
     { "children", getMenuItemChildrenCallback, 0, kJSPropertyAttributeReadOnly },
+    { "enabled", getMenuItemEnabledCallback, 0, kJSPropertyAttributeReadOnly },
     { 0, 0, 0, 0 }
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to