Title: [286552] trunk
Revision
286552
Author
commit-qu...@webkit.org
Date
2021-12-06 11:00:25 -0800 (Mon, 06 Dec 2021)

Log 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_gilli...@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):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (286551 => 286552)


--- trunk/Source/WebKit/ChangeLog	2021-12-06 18:49:35 UTC (rev 286551)
+++ trunk/Source/WebKit/ChangeLog	2021-12-06 19:00:25 UTC (rev 286552)
@@ -1,3 +1,28 @@
+2021-12-06  Matt Gilligan  <matthew_gilli...@apple.com>
+
+        [iOS] Allow WKWebView clients to override undoManager
+        https://bugs.webkit.org/show_bug.cgi?id=233297
+        <rdar://problem/85526549>
+
+        Reviewed by Wenson Hsieh.
+
+        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.
+
 2021-12-06  Lauro Moura  <lmo...@igalia.com>
 
         REGRESSION(r286535) [GTK] Fix clean builds after DerivedSources/WebKit2 move

Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm (286551 => 286552)


--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2021-12-06 18:49:35 UTC (rev 286551)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm	2021-12-06 19:00:25 UTC (rev 286552)
@@ -318,6 +318,14 @@
     return [super resignFirstResponder];
 }
 
+- (NSUndoManager *)undoManager
+{
+    if (self._currentContentView == _contentView)
+        return [_contentView undoManagerForWebView];
+
+    return [super undoManager];
+}
+
 FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW)
 
 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentView.h (286551 => 286552)


--- trunk/Source/WebKit/UIProcess/ios/WKContentView.h	2021-12-06 18:49:35 UTC (rev 286551)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentView.h	2021-12-06 19:00:25 UTC (rev 286552)
@@ -71,6 +71,7 @@
 @property (nonatomic, readonly, getter=isResigningFirstResponder) BOOL resigningFirstResponder;
 @property (nonatomic) BOOL sizeChangedSinceLastVisibleContentRectUpdate;
 @property (nonatomic, readonly) UIInterfaceOrientation interfaceOrientation;
+@property (nonatomic, readonly) NSUndoManager *undoManagerForWebView;
 
 - (instancetype)initWithFrame:(CGRect)frame processPool:(NakedRef<WebKit::WebProcessPool>)processPool configuration:(Ref<API::PageConfiguration>&&)configuration webView:(WKWebView *)webView;
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentView.mm (286551 => 286552)


--- trunk/Source/WebKit/UIProcess/ios/WKContentView.mm	2021-12-06 18:49:35 UTC (rev 286551)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentView.mm	2021-12-06 19:00:25 UTC (rev 286552)
@@ -562,7 +562,7 @@
     [self _didEndScrollingOrZooming];
 }
 
-- (NSUndoManager *)undoManager
+- (NSUndoManager *)undoManagerForWebView
 {
     if (self.focusedElementInformation.shouldSynthesizeKeyEventsForEditing && self.hasHiddenContentEditable) {
         if (!_quirkyUndoManager)

Modified: trunk/Tools/ChangeLog (286551 => 286552)


--- trunk/Tools/ChangeLog	2021-12-06 18:49:35 UTC (rev 286551)
+++ trunk/Tools/ChangeLog	2021-12-06 19:00:25 UTC (rev 286552)
@@ -1,3 +1,15 @@
+2021-12-06  Matt Gilligan  <matthew_gilli...@apple.com>
+
+        [iOS] Allow WKWebView clients to override undoManager
+        https://bugs.webkit.org/show_bug.cgi?id=233297
+        <rdar://problem/85526549>
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
+        (-[CustomUndoManagerWebView undoManager]):
+        (TestWebKitAPI::TEST):
+
 2021-12-06  Wenson Hsieh  <wenson_hs...@apple.com>
 
         [iOS] AppHighlights.AppHighlightCreateAndRestoreAndScroll is a flaky failure

Modified: trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm (286551 => 286552)


--- trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm	2021-12-06 18:49:35 UTC (rev 286551)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm	2021-12-06 19:00:25 UTC (rev 286552)
@@ -42,6 +42,7 @@
 #import <cmath>
 
 @interface WKContentView ()
+@property (nonatomic, readonly) NSUndoManager *undoManagerForWebView;
 - (BOOL)_shouldSimulateKeyboardInputOnTextInsertion;
 @end
 
@@ -187,6 +188,19 @@
 
 @end
 
+@interface CustomUndoManagerWebView : TestWKWebView
+@property (nonatomic, strong) NSUndoManager *customUndoManager;
+@end
+
+@implementation CustomUndoManagerWebView
+
+- (NSUndoManager *)undoManager
+{
+    return _customUndoManager ?: super.undoManager;
+}
+
+@end
+
 static RetainPtr<TestWKWebView> webViewWithAutofocusedInput(const RetainPtr<TestInputDelegate>& inputDelegate)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
@@ -801,6 +815,17 @@
     EXPECT_NS_EQUAL((@[@"keydown", @"beforeinput", @"input", @"keyup", @"change"]), [webView objectByEvaluatingJavaScript:@"firedEvents"]);
 }
 
+TEST(KeyboardInputTests, OverrideUndoManager)
+{
+    auto webView = adoptNS([[CustomUndoManagerWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    auto contentView = [webView wkContentView];
+    EXPECT_EQ(contentView.undoManager, contentView.undoManagerForWebView);
+
+    auto undoManager = adoptNS([[NSUndoManager alloc] init]);
+    [webView setCustomUndoManager:undoManager.get()];
+    EXPECT_EQ(contentView.undoManager, undoManager);
+}
+
 } // namespace TestWebKitAPI
 
 #endif // PLATFORM(IOS_FAMILY)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to