Changeset 218144 in webkit


Ignore:
Timestamp:
Jun 12, 2017, 3:28:25 PM (9 years ago)
Author:
timothy_horton@apple.com
Message:

[iOS] Cmd-C doesn't copy text from WKWebView
https://bugs.webkit.org/show_bug.cgi?id=173277
<rdar://problem/32396742>

Reviewed by Dan Bernstein.

  • UIProcess/API/Cocoa/WKWebView.mm:
  • UIProcess/API/Cocoa/WKWebViewInternal.h:
  • UIProcess/ios/WKContentViewInteraction.h:
  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView _lookupForWebView:]):
(-[WKContentView _shareForWebView:]):
(-[WKContentView _addShortcutForWebView:]):
(-[WKContentView _promptForReplaceForWebView:]):
(-[WKContentView _transliterateChineseForWebView:]):
(-[WKContentView _reanalyzeForWebView:]):
(-[WKContentView replaceForWebView:]):
(-[WKContentView canPerformAction:withSender:]):
(-[WKContentView copyForWebView:]):
(-[WKContentView cutForWebView:]):
(-[WKContentView pasteForWebView:]):
(-[WKContentView selectForWebView:]):
(-[WKContentView selectAllForWebView:]):
(-[WKContentView toggleBoldfaceForWebView:]):
(-[WKContentView toggleItalicsForWebView:]):
(-[WKContentView toggleUnderlineForWebView:]):
(-[WKContentView _showTextStyleOptionsForWebView:]):
(-[WKContentView _defineForWebView:]):
(-[WKContentView _arrowKeyForWebView:]):
(-[WKContentView _lookup:]): Deleted.
(-[WKContentView _share:]): Deleted.
(-[WKContentView _addShortcut:]): Deleted.
(-[WKContentView _promptForReplace:]): Deleted.
(-[WKContentView _transliterateChinese:]): Deleted.
(-[WKContentView _reanalyze:]): Deleted.
(-[WKContentView replace:]): Deleted.
(-[WKContentView copy:]): Deleted.
(-[WKContentView cut:]): Deleted.
(-[WKContentView paste:]): Deleted.
(-[WKContentView select:]): Deleted.
(-[WKContentView selectAll:]): Deleted.
(-[WKContentView toggleBoldface:]): Deleted.
(-[WKContentView toggleItalics:]): Deleted.
(-[WKContentView toggleUnderline:]): Deleted.
(-[WKContentView _showTextStyleOptions:]): Deleted.
(-[WKContentView _define:]): Deleted.
(-[WKContentView _arrowKey:]): Deleted.
Similar to what r211897 did for canPerformAction, and other patches
have done for other selectors, forward methods for standard editing
commands from WKContentView up to WKWebView, and back down to WKContentView.

This is necessary because these are not treated as normal
responder-chain-respecting methods, so they do not bubble up the view tree.

In 211897, WKContentView (who is usually first responder and thus receives
the actions) stopped claiming to be able to perform these actions, depending
on this non-existent bubbling behavior to keep them working.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • Tests/WebKit2Cocoa/WKContentViewEditingActions.mm:

Add a test ensuring that -copy on WKContentView will cause text to be copied.

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r218138 r218144  
     12017-06-12  Tim Horton  <timothy_horton@apple.com>
     2
     3        [iOS] Cmd-C doesn't copy text from WKWebView
     4        https://bugs.webkit.org/show_bug.cgi?id=173277
     5        <rdar://problem/32396742>
     6
     7        Reviewed by Dan Bernstein.
     8
     9        * UIProcess/API/Cocoa/WKWebView.mm:
     10        * UIProcess/API/Cocoa/WKWebViewInternal.h:
     11        * UIProcess/ios/WKContentViewInteraction.h:
     12        * UIProcess/ios/WKContentViewInteraction.mm:
     13        (-[WKContentView _lookupForWebView:]):
     14        (-[WKContentView _shareForWebView:]):
     15        (-[WKContentView _addShortcutForWebView:]):
     16        (-[WKContentView _promptForReplaceForWebView:]):
     17        (-[WKContentView _transliterateChineseForWebView:]):
     18        (-[WKContentView _reanalyzeForWebView:]):
     19        (-[WKContentView replaceForWebView:]):
     20        (-[WKContentView canPerformAction:withSender:]):
     21        (-[WKContentView copyForWebView:]):
     22        (-[WKContentView cutForWebView:]):
     23        (-[WKContentView pasteForWebView:]):
     24        (-[WKContentView selectForWebView:]):
     25        (-[WKContentView selectAllForWebView:]):
     26        (-[WKContentView toggleBoldfaceForWebView:]):
     27        (-[WKContentView toggleItalicsForWebView:]):
     28        (-[WKContentView toggleUnderlineForWebView:]):
     29        (-[WKContentView _showTextStyleOptionsForWebView:]):
     30        (-[WKContentView _defineForWebView:]):
     31        (-[WKContentView _arrowKeyForWebView:]):
     32        (-[WKContentView _lookup:]): Deleted.
     33        (-[WKContentView _share:]): Deleted.
     34        (-[WKContentView _addShortcut:]): Deleted.
     35        (-[WKContentView _promptForReplace:]): Deleted.
     36        (-[WKContentView _transliterateChinese:]): Deleted.
     37        (-[WKContentView _reanalyze:]): Deleted.
     38        (-[WKContentView replace:]): Deleted.
     39        (-[WKContentView copy:]): Deleted.
     40        (-[WKContentView cut:]): Deleted.
     41        (-[WKContentView paste:]): Deleted.
     42        (-[WKContentView select:]): Deleted.
     43        (-[WKContentView selectAll:]): Deleted.
     44        (-[WKContentView toggleBoldface:]): Deleted.
     45        (-[WKContentView toggleItalics:]): Deleted.
     46        (-[WKContentView toggleUnderline:]): Deleted.
     47        (-[WKContentView _showTextStyleOptions:]): Deleted.
     48        (-[WKContentView _define:]): Deleted.
     49        (-[WKContentView _arrowKey:]): Deleted.
     50        Similar to what r211897 did for canPerformAction, and other patches
     51        have done for other selectors, forward methods for standard editing
     52        commands from WKContentView up to WKWebView, and back down to WKContentView.
     53
     54        This is necessary because these are not treated as normal
     55        responder-chain-respecting methods, so they do not bubble up the view tree.
     56       
     57        In 211897, WKContentView (who is usually first responder and thus receives
     58        the actions) stopped claiming to be able to perform these actions, depending
     59        on this non-existent bubbling behavior to keep them working.
     60
    1612017-06-12  Chris Dumez  <cdumez@apple.com>
    262
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r217956 r218144  
    11501150}
    11511151
    1152 #define FOR_EACH_WKCONTENTVIEW_ACTION(M) \
    1153     M(_addShortcut) \
    1154     M(_arrowKey) \
    1155     M(_define) \
    1156     M(_lookup) \
    1157     M(_promptForReplace) \
    1158     M(_reanalyze) \
    1159     M(_share) \
    1160     M(_showTextStyleOptions) \
    1161     M(_transliterateChinese) \
    1162     M(copy) \
    1163     M(cut) \
    1164     M(paste) \
    1165     M(replace) \
    1166     M(select) \
    1167     M(selectAll) \
    1168     M(toggleBoldface) \
    1169     M(toggleItalics) \
    1170     M(toggleUnderline) \
    1171 
    11721152#define FORWARD_ACTION_TO_WKCONTENTVIEW(_action) \
    11731153    - (void)_action:(id)sender \
    11741154    { \
    11751155        if (self.usesStandardContentView) \
    1176             [_contentView _action:sender]; \
     1156            [_contentView _action ## ForWebView:sender]; \
    11771157    }
    11781158
     
    11931173    return [super canPerformAction:action withSender:sender];
    11941174}
    1195 
    1196 #undef FOR_EACH_WKCONTENTVIEW_ACTION
    11971175
    11981176static inline CGFloat floorToDevicePixel(CGFloat input, float deviceScaleFactor)
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h

    r216794 r218144  
    122122- (void)_didChangeAvoidsUnsafeArea:(BOOL)avoidsUnsafeArea;
    123123
     124- (void)_addShortcut:(id)sender;
     125- (void)_arrowKey:(id)sender;
     126- (void)_define:(id)sender;
     127- (void)_lookup:(id)sender;
     128- (void)_reanalyze:(id)sender;
     129- (void)_share:(id)sender;
     130- (void)_showTextStyleOptions:(id)sender;
     131- (void)_promptForReplace:(id)sender;
     132- (void)_transliterateChinese:(id)sender;
     133- (void)replace:(id)sender;
     134
    124135@property (nonatomic, readonly) WKPasswordView *_passwordView;
    125136
  • trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h

    r217580 r218144  
    9090typedef std::pair<WebKit::InteractionInformationRequest, InteractionInformationCallback> InteractionInformationRequestAndCallback;
    9191
     92#define FOR_EACH_WKCONTENTVIEW_ACTION(M) \
     93    M(_addShortcut) \
     94    M(_arrowKey) \
     95    M(_define) \
     96    M(_lookup) \
     97    M(_promptForReplace) \
     98    M(_reanalyze) \
     99    M(_share) \
     100    M(_showTextStyleOptions) \
     101    M(_transliterateChinese) \
     102    M(copy) \
     103    M(cut) \
     104    M(paste) \
     105    M(replace) \
     106    M(select) \
     107    M(selectAll) \
     108    M(toggleBoldface) \
     109    M(toggleItalics) \
     110    M(toggleUnderline)
     111
    92112namespace WebKit {
    93113
     
    237257- (BOOL)canPerformActionForWebView:(SEL)action withSender:(id)sender;
    238258
    239 - (void)_addShortcut:(id)sender;
    240 - (void)_arrowKey:(id)sender;
    241 - (void)_define:(id)sender;
    242 - (void)_lookup:(id)sender;
    243 - (void)_reanalyze:(id)sender;
    244 - (void)_share:(id)sender;
    245 - (void)_showTextStyleOptions:(id)sender;
    246 - (void)_promptForReplace:(id)sender;
    247 - (void)_transliterateChinese:(id)sender;
    248 - (void)replace:(id)sender;
     259#define DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW(_action) \
     260    - (void)_action ## ForWebView:(id)sender;
     261FOR_EACH_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW)
     262#undef DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW
    249263
    250264#if ENABLE(TOUCH_EVENTS)
  • trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

    r217580 r218144  
    19031903}
    19041904
    1905 - (void)_lookup:(id)sender
     1905#define FORWARD_ACTION_TO_WKWEBVIEW(_action) \
     1906    - (void)_action:(id)sender \
     1907    { \
     1908        [_webView _action:sender]; \
     1909    }
     1910
     1911FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKWEBVIEW)
     1912
     1913#undef FORWARD_ACTION_TO_WKWEBVIEW
     1914
     1915- (void)_lookupForWebView:(id)sender
    19061916{
    19071917    RetainPtr<WKContentView> view = self;
     
    19231933}
    19241934
    1925 - (void)_share:(id)sender
     1935- (void)_shareForWebView:(id)sender
    19261936{
    19271937    RetainPtr<WKContentView> view = self;
     
    19411951}
    19421952
    1943 - (void)_addShortcut:(id)sender
     1953- (void)_addShortcutForWebView:(id)sender
    19441954{
    19451955    if (_textSelectionAssistant)
     
    19691979}
    19701980
    1971 - (void)_promptForReplace:(id)sender
     1981- (void)_promptForReplaceForWebView:(id)sender
    19721982{
    19731983    const auto& wordAtSelection = _page->editorState().postLayoutData().wordAtSelection;
     
    19781988}
    19791989
    1980 - (void)_transliterateChinese:(id)sender
     1990- (void)_transliterateChineseForWebView:(id)sender
    19811991{
    19821992    [_textSelectionAssistant scheduleChineseTransliterationForText:_page->editorState().postLayoutData().wordAtSelection];
    19831993}
    19841994
    1985 - (void)_reanalyze:(id)sender
     1995- (void)_reanalyzeForWebView:(id)sender
    19861996{
    19871997    [_textSelectionAssistant scheduleReanalysis];
    19881998}
    19891999
    1990 - (void)replace:(id)sender
     2000- (void)replaceForWebView:(id)sender
    19912001{
    19922002    [[UIKeyboardImpl sharedInstance] replaceText:sender];
     
    20312041- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
    20322042{
    2033     return NO;
     2043    return [_webView canPerformAction:action withSender:sender];
    20342044}
    20352045
     
    21672177}
    21682178
    2169 - (void)copy:(id)sender
     2179- (void)copyForWebView:(id)sender
    21702180{
    21712181    _page->executeEditCommand(ASCIILiteral("copy"));
    21722182}
    21732183
    2174 - (void)cut:(id)sender
     2184- (void)cutForWebView:(id)sender
    21752185{
    21762186    _page->executeEditCommand(ASCIILiteral("cut"));
    21772187}
    21782188
    2179 - (void)paste:(id)sender
     2189- (void)pasteForWebView:(id)sender
    21802190{
    21812191    _page->executeEditCommand(ASCIILiteral("paste"));
    21822192}
    21832193
    2184 - (void)select:(id)sender
     2194- (void)selectForWebView:(id)sender
    21852195{
    21862196    [_textSelectionAssistant selectWord];
     
    21892199}
    21902200
    2191 - (void)selectAll:(id)sender
     2201- (void)selectAllForWebView:(id)sender
    21922202{
    21932203    [_textSelectionAssistant selectAll:sender];
     
    21952205}
    21962206
    2197 - (void)toggleBoldface:(id)sender
     2207- (void)toggleBoldfaceForWebView:(id)sender
    21982208{
    21992209    if (!_page->editorState().isContentRichlyEditable)
     
    22032213}
    22042214
    2205 - (void)toggleItalics:(id)sender
     2215- (void)toggleItalicsForWebView:(id)sender
    22062216{
    22072217    if (!_page->editorState().isContentRichlyEditable)
     
    22112221}
    22122222
    2213 - (void)toggleUnderline:(id)sender
     2223- (void)toggleUnderlineForWebView:(id)sender
    22142224{
    22152225    if (!_page->editorState().isContentRichlyEditable)
     
    22192229}
    22202230
    2221 - (void)_showTextStyleOptions:(id)sender
     2231- (void)_showTextStyleOptionsForWebView:(id)sender
    22222232{
    22232233    _showingTextStyleOptions = YES;
     
    22342244}
    22352245
    2236 - (void)_define:(id)sender
     2246- (void)_defineForWebView:(id)sender
    22372247{
    22382248    if ([[getMCProfileConnectionClass() sharedConnection] effectiveBoolValueForSetting:MCFeatureDefinitionLookupAllowed] == MCRestrictedBoolExplicitNo)
     
    28302840}
    28312841
    2832 - (void)_arrowKey:(id)sender
     2842- (void)_arrowKeyForWebView:(id)sender
    28332843{
    28342844    UIKeyCommand* command = sender;
  • trunk/Tools/ChangeLog

    r218129 r218144  
     12017-06-12  Tim Horton  <timothy_horton@apple.com>
     2
     3        [iOS] Cmd-C doesn't copy text from WKWebView
     4        https://bugs.webkit.org/show_bug.cgi?id=173277
     5        <rdar://problem/32396742>
     6
     7        Reviewed by Dan Bernstein.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * Tests/WebKit2Cocoa/WKContentViewEditingActions.mm:
     11        Add a test ensuring that -copy on WKContentView will cause text to be copied.
     12
    1132017-06-12  Jiewen Tan  <jiewen_tan@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r217867 r218144  
    6868                2D4CF8BD1D8360CC0001CE8D /* WKThumbnailView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D4CF8BC1D8360CC0001CE8D /* WKThumbnailView.mm */; };
    6969                2D51A0C71C8BF00C00765C45 /* DOMHTMLVideoElementWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */; };
     70                2D838B1F1EEF3A5C009B980E /* WKContentViewEditingActions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D838B1E1EEF3A5B009B980E /* WKContentViewEditingActions.mm */; };
    7071                2DB0232F1E4E871800707123 /* InteractionDeadlockAfterCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DB0232E1E4E871800707123 /* InteractionDeadlockAfterCrash.mm */; };
    7172                2DC4CF771D2D9DD800ECCC94 /* DataDetection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DC4CF761D2D9DD800ECCC94 /* DataDetection.mm */; };
     
    10001001                2D640B5417875DFF00BFAF99 /* ScrollPinningBehaviors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollPinningBehaviors.cpp; sourceTree = "<group>"; };
    10011002                2D8104CB1BEC13E70020DA46 /* FindInPage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FindInPage.mm; sourceTree = "<group>"; };
     1003                2D838B1E1EEF3A5B009B980E /* WKContentViewEditingActions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKContentViewEditingActions.mm; sourceTree = "<group>"; };
    10021004                2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ShrinkToFit.mm; sourceTree = "<group>"; };
    10031005                2DB0232E1E4E871800707123 /* InteractionDeadlockAfterCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InteractionDeadlockAfterCrash.mm; sourceTree = "<group>"; };
     
    18041806                                5C9E56841DF9143D00C9EE33 /* WebsitePolicies.mm */,
    18051807                                1F83571A1D3FFB0E00E3967B /* WKBackForwardList.mm */,
     1808                                2D838B1E1EEF3A5B009B980E /* WKContentViewEditingActions.mm */,
    18061809                                51D124971E763AF8002B2820 /* WKHTTPCookieStore.mm */,
    18071810                                375E0E151D66674400EFEC2C /* WKNSNumber.mm */,
     
    29142917                                46397B951DC2C850009A78AE /* DOMNode.mm in Sources */,
    29152918                                5198A2401EA7E59F008910B7 /* InitialWarmedProcessUsed.mm in Sources */,
     2919                                2D838B1F1EEF3A5C009B980E /* WKContentViewEditingActions.mm in Sources */,
    29162920                                7CCE7EBC1A411A7E00447C4C /* DOMNodeFromJSObject.mm in Sources */,
    29172921                                7CCE7EBD1A411A7E00447C4C /* DOMRangeOfString.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.