Changeset 271459 in webkit


Ignore:
Timestamp:
Jan 13, 2021 2:50:25 PM (18 months ago)
Author:
Wenson Hsieh
Message:

[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.

Location:
trunk
Files:
3 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r271454 r271459  
     12021-01-13  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] "Correct Spelling Automatically" menu items are inconsistent when autocorrect="off"
     4        https://bugs.webkit.org/show_bug.cgi?id=220598
     5        <rdar://problem/71713611>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add a new API test to verify that the context menu item to toggle "Correct Spelling Automatically" is disabled
     10        when autocorrect="off".
     11
     12        * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item-expected.txt: Added.
     13        * editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html: Added.
     14        * platform/mac-wk1/TestExpectations:
     15
     16        Disable the test in DumpRenderTree, due to lack of support for context menu testing in WebKit1.
     17
    1182021-01-13  Truitt Savell  <tsavell@apple.com>
    219
  • trunk/LayoutTests/platform/mac-wk1/TestExpectations

    r271324 r271459  
    290290# Fails with WebKit1 only.
    291291editing/secure-input/reset-state-on-navigation.html [ Failure ]
     292
     293# Context menu API is not exposed on DumpRenderTree.
     294editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html [ Skip ]
    292295
    293296http/tests/plugins/nounsupported-plugin.html [ Skip ]
  • trunk/Source/WebCore/ChangeLog

    r271452 r271459  
     12021-01-13  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] "Correct Spelling Automatically" menu items are inconsistent when autocorrect="off"
     4        https://bugs.webkit.org/show_bug.cgi?id=220598
     5        <rdar://problem/71713611>
     6
     7        Reviewed by Tim Horton.
     8
     9        Disable the context menu item to toggle automatic spelling correction, as well as the menu bar item to toggle
     10        automatic spelling correction, in the case where the autocorrect attribute is set to "off". See below for more
     11        details.
     12
     13        Tests:  editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html
     14                DisableAutomaticSpellingCorrection.AutocorrectAttribute
     15
     16        * editing/AlternativeTextController.cpp:
     17        (WebCore::AlternativeTextController::canEnableAutomaticSpellingCorrection const):
     18
     19        Factor out logic for checking the `autocorrect` attribute into a separate helper function; this is used to
     20        determine whether or not we should enable both the context menu item and menu item in the menu bar.
     21
     22        (WebCore::AlternativeTextController::isAutomaticSpellingCorrectionEnabled):
     23        * editing/AlternativeTextController.h:
     24        (WebCore::AlternativeTextController::UNLESS_ENABLED):
     25        * editing/Editor.cpp:
     26        (WebCore::Editor::canEnableAutomaticSpellingCorrection const):
     27        * editing/Editor.h:
     28        * page/ContextMenuController.cpp:
     29        (WebCore::ContextMenuController::checkOrEnableIfNeeded const):
     30
    1312021-01-13  Fujii Hironori  <Hironori.Fujii@sony.com>
    232
  • trunk/Source/WebCore/editing/AlternativeTextController.cpp

    r267363 r271459  
    336336}
    337337
    338 bool AlternativeTextController::isAutomaticSpellingCorrectionEnabled()
    339 {
    340     if (!editorClient() || !editorClient()->isAutomaticSpellingCorrectionEnabled())
    341         return false;
    342 
     338bool AlternativeTextController::canEnableAutomaticSpellingCorrection() const
     339{
    343340#if ENABLE(AUTOCORRECT)
    344341    auto position = m_document.selection().selection().start();
     
    355352
    356353    return true;
     354}
     355
     356bool AlternativeTextController::isAutomaticSpellingCorrectionEnabled()
     357{
     358    if (!editorClient() || !editorClient()->isAutomaticSpellingCorrectionEnabled())
     359        return false;
     360
     361    return canEnableAutomaticSpellingCorrection();
    357362}
    358363
  • trunk/Source/WebCore/editing/AlternativeTextController.h

    r264247 r271459  
    8787    bool isSpellingMarkerAllowed(const SimpleRange& misspellingRange) const UNLESS_ENABLED({ UNUSED_PARAM(misspellingRange); return true; })
    8888    bool isAutomaticSpellingCorrectionEnabled() UNLESS_ENABLED({ return false; })
     89    bool canEnableAutomaticSpellingCorrection() const UNLESS_ENABLED({ return false; })
    8990    bool shouldRemoveMarkersUponEditing();
    9091
  • trunk/Source/WebCore/editing/Editor.cpp

    r269888 r271459  
    17661766}
    17671767
     1768bool Editor::canEnableAutomaticSpellingCorrection() const
     1769{
     1770    return m_alternativeTextController->canEnableAutomaticSpellingCorrection();
     1771}
     1772
    17681773bool Editor::isAutomaticSpellingCorrectionEnabled()
    17691774{
  • trunk/Source/WebCore/editing/Editor.h

    r266557 r271459  
    512512    WEBCORE_EXPORT bool isAutomaticSpellingCorrectionEnabled();
    513513    WEBCORE_EXPORT void toggleAutomaticSpellingCorrection();
     514    WEBCORE_EXPORT bool canEnableAutomaticSpellingCorrection() const;
    514515#endif
    515516
  • trunk/Source/WebCore/page/ContextMenuController.cpp

    r270974 r271459  
    13251325        case ContextMenuItemTagCorrectSpellingAutomatically:
    13261326            shouldCheck = frame->editor().isAutomaticSpellingCorrectionEnabled();
     1327            shouldEnable = frame->editor().canEnableAutomaticSpellingCorrection();
    13271328            break;
    13281329        case ContextMenuItemTagSmartCopyPaste:
  • trunk/Source/WebKit/ChangeLog

    r271457 r271459  
     12021-01-13  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] "Correct Spelling Automatically" menu items are inconsistent when autocorrect="off"
     4        https://bugs.webkit.org/show_bug.cgi?id=220598
     5        <rdar://problem/71713611>
     6
     7        Reviewed by Tim Horton.
     8
     9        Plumb the new `canEnableAutomaticSpellingCorrection` flag through `EditorState` to the UI process, where we can
     10        consult it when validating user interface items (namely, the "Correct Spelling Automatically" menu item, which
     11        corresponds to the `-toggleAutomaticSpellingCorrection:` selector).
     12
     13        * Shared/EditorState.cpp:
     14        (WebKit::EditorState::PostLayoutData::encode const):
     15        (WebKit::EditorState::PostLayoutData::decode):
     16        (WebKit::operator<<):
     17        * Shared/EditorState.h:
     18        * UIProcess/Cocoa/WebViewImpl.mm:
     19        (WebKit::WebViewImpl::validateUserInterfaceItem):
     20        * WebProcess/WebPage/mac/WebPageMac.mm:
     21        (WebKit::WebPage::getPlatformEditorState const):
     22
    1232021-01-13  Alex Christensen  <achristensen@webkit.org>
    224
  • trunk/Source/WebKit/Shared/EditorState.cpp

    r266265 r271459  
    133133    encoder << paragraphContextForCandidateRequest;
    134134    encoder << stringForCandidateRequest;
     135    encoder << canEnableAutomaticSpellingCorrection;
    135136#endif
    136137#if PLATFORM(GTK) || PLATFORM(WPE)
     
    224225
    225226    if (!decoder.decode(result.stringForCandidateRequest))
     227        return false;
     228
     229    if (!decoder.decode(result.canEnableAutomaticSpellingCorrection))
    226230        return false;
    227231#endif
     
    339343    if (editorState.postLayoutData().stringForCandidateRequest.length())
    340344        ts.dumpProperty("stringForCandidateRequest", editorState.postLayoutData().stringForCandidateRequest);
     345    if (editorState.postLayoutData().canEnableAutomaticSpellingCorrection)
     346        ts.dumpProperty("canEnableAutomaticSpellingCorrection", editorState.postLayoutData().canEnableAutomaticSpellingCorrection);
    341347#endif
    342348
  • trunk/Source/WebKit/Shared/EditorState.h

    r266265 r271459  
    124124        String paragraphContextForCandidateRequest;
    125125        String stringForCandidateRequest;
     126        bool canEnableAutomaticSpellingCorrection { true };
    126127#endif
    127128#if PLATFORM(GTK) || PLATFORM(WPE)
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r271187 r271459  
    30643064
    30653065    if (action == @selector(toggleAutomaticSpellingCorrection:)) {
    3066         bool checked = TextChecker::state().isAutomaticSpellingCorrectionEnabled;
    3067         [menuItem(item) setState:checked ? NSControlStateValueOn : NSControlStateValueOff];
    3068         return m_page->editorState().isContentEditable;
     3066        auto& editorState = m_page->editorState();
     3067        bool enable = editorState.isContentEditable && (editorState.isMissingPostLayoutData || editorState.postLayoutData().canEnableAutomaticSpellingCorrection);
     3068        menuItem(item).state = TextChecker::state().isAutomaticSpellingCorrectionEnabled && enable ? NSControlStateValueOn : NSControlStateValueOff;
     3069        return enable;
    30693070    }
    30703071
  • trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm

    r271187 r271459  
    165165    postLayoutData.paragraphContextForCandidateRequest = contextRangeForCandidateRequest ? plainText(*contextRangeForCandidateRequest) : String();
    166166    postLayoutData.stringForCandidateRequest = frame.editor().stringForCandidateRequest();
     167    postLayoutData.canEnableAutomaticSpellingCorrection = frame.editor().canEnableAutomaticSpellingCorrection();
    167168
    168169    auto quads = RenderObject::absoluteTextQuads(*selectedRange);
  • trunk/Tools/ChangeLog

    r271455 r271459  
     12021-01-13  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] "Correct Spelling Automatically" menu items are inconsistent when autocorrect="off"
     4        https://bugs.webkit.org/show_bug.cgi?id=220598
     5        <rdar://problem/71713611>
     6
     7        Reviewed by Tim Horton.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/mac/DisableAutomaticSpellingCorrection.mm: Added.
     11
     12        Add a new API test to verify that the `NSMenuItem` for toggling automatic spelling correction is invalid when
     13        editing inside a form control with autocorrect="off".
     14
     15        * WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
     16        (WTR::getMenuItemEnabledCallback):
     17
     18        Add the readonly `enabled` JS property on context menu items. See the new layout test,
     19        editing/mac/spelling/disable-automatic-spelling-correction-context-menu-item.html, for more information.
     20
    1212021-01-13  Jonathan Bedard  <jbedard@apple.com>
    222
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r271414 r271459  
    11981198                F4D4F3B61E4E2BCB00BB2767 /* DragAndDropSimulatorIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B41E4E2BCB00BB2767 /* DragAndDropSimulatorIOS.mm */; };
    11991199                F4D4F3B91E4E36E400BB2767 /* DragAndDropTestsIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D4F3B71E4E36E400BB2767 /* DragAndDropTestsIOS.mm */; };
     1200                F4D5D69525AF8BE400205280 /* DisableAutomaticSpellingCorrection.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4D5D69425AF8BE400205280 /* DisableAutomaticSpellingCorrection.mm */; };
    12001201                F4D5E4E81F0C5D38008C1A49 /* dragstart-clear-selection.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4D5E4E71F0C5D27008C1A49 /* dragstart-clear-selection.html */; };
    12011202                F4D65DA81F5E4704009D8C27 /* selected-text-image-link-and-editable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4D65DA71F5E46C0009D8C27 /* selected-text-image-link-and-editable.html */; };
     
    29682969                F4D4F3B41E4E2BCB00BB2767 /* DragAndDropSimulatorIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragAndDropSimulatorIOS.mm; sourceTree = "<group>"; };
    29692970                F4D4F3B71E4E36E400BB2767 /* DragAndDropTestsIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragAndDropTestsIOS.mm; sourceTree = "<group>"; };
     2971                F4D5D69425AF8BE400205280 /* DisableAutomaticSpellingCorrection.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DisableAutomaticSpellingCorrection.mm; sourceTree = "<group>"; };
    29702972                F4D5E4E71F0C5D27008C1A49 /* dragstart-clear-selection.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "dragstart-clear-selection.html"; sourceTree = "<group>"; };
    29712973                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>"; };
     
    45064508                                E5AA8D1C25151CC60051CC45 /* DateInputTests.mm */,
    45074509                                939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */,
     4510                                F4D5D69425AF8BE400205280 /* DisableAutomaticSpellingCorrection.mm */,
    45084511                                37E1064A1697676400B78BD0 /* DOMHTMLTableCellCellAbove.mm */,
    45094512                                2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */,
     
    51955198                                7CCE7EEA1A411AE600447C4C /* DidNotHandleKeyDown.cpp in Sources */,
    51965199                                AD57AC211DA7465B00FF1BDE /* DidRemoveFrameFromHiearchyInPageCache.cpp in Sources */,
     5200                                F4D5D69525AF8BE400205280 /* DisableAutomaticSpellingCorrection.mm in Sources */,
     5201                                F4B0168325AE060F00E445C4 /* DisableSpellcheck.mm in Sources */,
    51975202                                FEC2A85424CE975F00ADBC35 /* DisallowVMEntry.cpp in Sources */,
    51985203                                F4094CC725545BD5003D73E3 /* DisplayListTests.cpp in Sources */,
     
    55215526                                7CCE7ED01A411A7E00447C4C /* StringByEvaluatingJavaScriptFromString.mm in Sources */,
    55225527                                7CCE7ED11A411A7E00447C4C /* StringTruncator.mm in Sources */,
    5523                                 F4B0168325AE060F00E445C4 /* DisableSpellcheck.mm in Sources */,
    55245528                                ECA680CE1E68CC0900731D20 /* StringUtilities.mm in Sources */,
    55255529                                CE4D5DE71F6743BA0072CFC6 /* StringWithDirection.cpp in Sources */,
     
    57055709                                374B7A611DF371CF00ACCB6C /* BundleEditingDelegatePlugIn.mm in Sources */,
    57065710                                7A89BB682331643A0042CB1E /* BundleFormDelegatePlugIn.mm in Sources */,
    5707                                 F4B0168425AE08F800E445C4 /* DisableSpellcheckPlugIn.mm in Sources */,
    57085711                                A13EBBB01B87436F00097110 /* BundleParametersPlugIn.mm in Sources */,
    57095712                                37A709AF1E3EA97E00CA5969 /* BundleRangeHandlePlugIn.mm in Sources */,
     
    57145717                                5C121E8D2410704900486F9B /* ContentWorldPlugIn.mm in Sources */,
    57155718                                CEA7F57D2089624B0078EF6E /* DidResignInputElementStrongPasswordAppearance.mm in Sources */,
     5719                                F4B0168425AE08F800E445C4 /* DisableSpellcheckPlugIn.mm in Sources */,
    57165720                                518EE51920A78CE500E024F3 /* DoubleDefersLoadingPlugin.mm in Sources */,
    57175721                                5CB5B3C21FFC55CF00C27BB0 /* FrameHandleSerialization.mm in Sources */,
  • trunk/Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp

    r270582 r271459  
    6868}
    6969
     70static JSValueRef getMenuItemEnabledCallback(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
     71{
     72    auto* privateData = static_cast<MenuItemPrivateData*>(JSObjectGetPrivate(object));
     73    return JSValueMakeBoolean(context, WKContextMenuItemGetEnabled(privateData->m_item.get()));
     74}
     75
    7076static JSClassRef getMenuItemClass();
    7177
     
    9197    { "title", getMenuItemTitleCallback, 0, kJSPropertyAttributeReadOnly },
    9298    { "children", getMenuItemChildrenCallback, 0, kJSPropertyAttributeReadOnly },
     99    { "enabled", getMenuItemEnabledCallback, 0, kJSPropertyAttributeReadOnly },
    93100    { 0, 0, 0, 0 }
    94101};
Note: See TracChangeset for help on using the changeset viewer.