⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 286552 in webkit


Ignore:
Timestamp:
Dec 6, 2021, 11:00:25 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

[iOS] Allow WKWebView clients to override undoManager
https://bugs.webkit.org/show_bug.cgi?id=233297
<rdar://problem/85526549>

Patch by Matt Gilligan <matthew_gilligan@apple.com> on 2021-12-06
Reviewed by Wenson Hsieh.

Source/WebKit:

Move WKContentView's undoManager up the responder chain to WKWebView so web view
subclasses can customize the undo manager used when WKContentView is first responder.

Test: KeyboardInputTests.OverrideUndoManager

  • UIProcess/API/ios/WKWebViewIOS.mm:

(-[WKWebView undoManager]):
Return the undo manager provided by _contentView when it is current.

  • UIProcess/ios/WKContentView.h:
  • UIProcess/ios/WKContentView.mm:

(-[WKContentView undoManagerForWebView]):
Provide the view's undo manager via this property so that -undoManager will look up the
responder chain to WKWebView.

(-[WKContentView undoManager]): Deleted.

Tools:

  • TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:

(-[CustomUndoManagerWebView undoManager]):
(TestWebKitAPI::TEST):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r286549 r286552  
     12021-12-06  Matt Gilligan  <matthew_gilligan@apple.com>
     2
     3        [iOS] Allow WKWebView clients to override undoManager
     4        https://bugs.webkit.org/show_bug.cgi?id=233297
     5        <rdar://problem/85526549>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Move WKContentView's undoManager up the responder chain to WKWebView so web view
     10        subclasses can customize the undo manager used when WKContentView is first responder.
     11
     12        Test: KeyboardInputTests.OverrideUndoManager
     13
     14        * UIProcess/API/ios/WKWebViewIOS.mm:
     15        (-[WKWebView undoManager]):
     16        Return the undo manager provided by _contentView when it is current.
     17
     18        * UIProcess/ios/WKContentView.h:
     19        * UIProcess/ios/WKContentView.mm:
     20        (-[WKContentView undoManagerForWebView]):
     21        Provide the view's undo manager via this property so that -undoManager will look up the
     22        responder chain to WKWebView.
     23
     24        (-[WKContentView undoManager]): Deleted.
     25
    1262021-12-06  Lauro Moura  <lmoura@igalia.com>
    227
  • trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm

    r285424 r286552  
    319319}
    320320
     321- (NSUndoManager *)undoManager
     322{
     323    if (self._currentContentView == _contentView)
     324        return [_contentView undoManagerForWebView];
     325
     326    return [super undoManager];
     327}
     328
    321329FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW)
    322330
  • trunk/Source/WebKit/UIProcess/ios/WKContentView.h

    r280875 r286552  
    7272@property (nonatomic) BOOL sizeChangedSinceLastVisibleContentRectUpdate;
    7373@property (nonatomic, readonly) UIInterfaceOrientation interfaceOrientation;
     74@property (nonatomic, readonly) NSUndoManager *undoManagerForWebView;
    7475
    7576- (instancetype)initWithFrame:(CGRect)frame processPool:(NakedRef<WebKit::WebProcessPool>)processPool configuration:(Ref<API::PageConfiguration>&&)configuration webView:(WKWebView *)webView;
  • trunk/Source/WebKit/UIProcess/ios/WKContentView.mm

    r281610 r286552  
    563563}
    564564
    565 - (NSUndoManager *)undoManager
     565- (NSUndoManager *)undoManagerForWebView
    566566{
    567567    if (self.focusedElementInformation.shouldSynthesizeKeyEventsForEditing && self.hasHiddenContentEditable) {
  • trunk/Tools/ChangeLog

    r286547 r286552  
     12021-12-06  Matt Gilligan  <matthew_gilligan@apple.com>
     2
     3        [iOS] Allow WKWebView clients to override undoManager
     4        https://bugs.webkit.org/show_bug.cgi?id=233297
     5        <rdar://problem/85526549>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
     10        (-[CustomUndoManagerWebView undoManager]):
     11        (TestWebKitAPI::TEST):
     12
    1132021-12-06  Wenson Hsieh  <wenson_hsieh@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm

    r273759 r286552  
    4343
    4444@interface WKContentView ()
     45@property (nonatomic, readonly) NSUndoManager *undoManagerForWebView;
    4546- (BOOL)_shouldSimulateKeyboardInputOnTextInsertion;
    4647@end
     
    184185{
    185186    return _customInputAccessoryView.get();
     187}
     188
     189@end
     190
     191@interface CustomUndoManagerWebView : TestWKWebView
     192@property (nonatomic, strong) NSUndoManager *customUndoManager;
     193@end
     194
     195@implementation CustomUndoManagerWebView
     196
     197- (NSUndoManager *)undoManager
     198{
     199    return _customUndoManager ?: super.undoManager;
    186200}
    187201
     
    802816}
    803817
     818TEST(KeyboardInputTests, OverrideUndoManager)
     819{
     820    auto webView = adoptNS([[CustomUndoManagerWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     821    auto contentView = [webView wkContentView];
     822    EXPECT_EQ(contentView.undoManager, contentView.undoManagerForWebView);
     823
     824    auto undoManager = adoptNS([[NSUndoManager alloc] init]);
     825    [webView setCustomUndoManager:undoManager.get()];
     826    EXPECT_EQ(contentView.undoManager, undoManager);
     827}
     828
    804829} // namespace TestWebKitAPI
    805830
Note: See TracChangeset for help on using the changeset viewer.