Allow clients to vend custom -inputView and -inputAccessoryView by overriding WKWebVi...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Jun 2019 01:37:37 +0000 (01:37 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Jun 2019 01:37:37 +0000 (01:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198631
<rdar://problem/51505431>

Reviewed by Tim Horton.

Source/WebKit:

Allow WKWebView API clients to override WKContentView's default input view and/or input accessory view by
subclassing WKWebView and implementing -inputView or -inputAccessoryView.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView inputAccessoryView]):
(-[WKWebView inputView]):
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView inputView]):
(-[WKContentView inputViewForWebView]):
(-[WKContentView inputAccessoryView]):
(-[WKContentView inputAccessoryViewForWebView]):

Tools:

Add an API test that overrides -[WKWebView inputView] and -[WKWebView inputAccessoryView].

* TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
(-[CustomInputWebView initWithFrame:configuration:inputView:inputAccessoryView:]):
(-[CustomInputWebView inputView]):
(-[CustomInputWebView inputAccessoryView]):
(TestWebKitAPI::TEST):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm

index cc5d87f..dd9bb5f 100644 (file)
@@ -1,3 +1,24 @@
+2019-06-07  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Allow clients to vend custom -inputView and -inputAccessoryView by overriding WKWebView methods
+        https://bugs.webkit.org/show_bug.cgi?id=198631
+        <rdar://problem/51505431>
+
+        Reviewed by Tim Horton.
+
+        Allow WKWebView API clients to override WKContentView's default input view and/or input accessory view by
+        subclassing WKWebView and implementing -inputView or -inputAccessoryView.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView inputAccessoryView]):
+        (-[WKWebView inputView]):
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView inputView]):
+        (-[WKContentView inputViewForWebView]):
+        (-[WKContentView inputAccessoryView]):
+        (-[WKContentView inputAccessoryViewForWebView]):
+
 2019-06-07  Tim Horton  <timothy_horton@apple.com>
 
         Disable focus rings on WKContentView for PLATFORM(IOSMAC)
index fe8ed88..fa221ba 100644 (file)
@@ -4585,6 +4585,16 @@ FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW)
         [_contentView _setTextColorForWebView:color sender:sender];
 }
 
+- (UIView *)inputAccessoryView
+{
+    return [_contentView inputAccessoryViewForWebView];
+}
+
+- (UIView *)inputView
+{
+    return [_contentView inputViewForWebView];
+}
+
 #endif // PLATFORM(IOS_FAMILY)
 
 - (BOOL)_isEditable
index e4bc469..6690cd1 100644 (file)
@@ -383,6 +383,8 @@ struct WKAutoCorrectionData {
 @property (nonatomic, readonly) const WebKit::FocusedElementInformation& focusedElementInformation;
 @property (nonatomic, readonly) UIWebFormAccessory *formAccessoryView;
 @property (nonatomic, readonly) UITextInputAssistantItem *inputAssistantItemForWebView;
+@property (nonatomic, readonly) UIView *inputViewForWebView;
+@property (nonatomic, readonly) UIView *inputAccessoryViewForWebView;
 #if ENABLE(POINTER_EVENTS)
 @property (nonatomic, readonly) BOOL preventsPanningInXAxis;
 @property (nonatomic, readonly) BOOL preventsPanningInYAxis;
index ead32b7..b3a49ee 100644 (file)
@@ -1715,6 +1715,11 @@ static NSValue *nsSizeForTapHighlightBorderRadius(WebCore::IntSize borderRadius,
 
 - (UIView *)inputView
 {
+    return [_webView inputView];
+}
+
+- (UIView *)inputViewForWebView
+{
     if (!hasFocusedElement(_focusedElementInformation))
         return nil;
 
@@ -2573,6 +2578,11 @@ static void cancelPotentialTapIfNecessary(WKContentView* contentView)
 
 - (UIView *)inputAccessoryView
 {
+    return [_webView inputAccessoryView];
+}
+
+- (UIView *)inputAccessoryViewForWebView
+{
     if (![self requiresAccessoryView])
         return nil;
 
index b47011d..71cef12 100644 (file)
@@ -1,3 +1,19 @@
+2019-06-07  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Allow clients to vend custom -inputView and -inputAccessoryView by overriding WKWebView methods
+        https://bugs.webkit.org/show_bug.cgi?id=198631
+        <rdar://problem/51505431>
+
+        Reviewed by Tim Horton.
+
+        Add an API test that overrides -[WKWebView inputView] and -[WKWebView inputAccessoryView].
+
+        * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
+        (-[CustomInputWebView initWithFrame:configuration:inputView:inputAccessoryView:]):
+        (-[CustomInputWebView inputView]):
+        (-[CustomInputWebView inputAccessoryView]):
+        (TestWebKitAPI::TEST):
+
 2019-06-07  Daniel Bates  <dabates@apple.com>
 
         [lldb-webkit] Pretty-print all kinds of Documents
index fe3b01d..6cba2aa 100644 (file)
@@ -148,6 +148,36 @@ static CGRect rounded(CGRect rect)
 
 @end
 
+@interface CustomInputWebView : TestWKWebView
+- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration inputView:(UIView *)inputView inputAccessoryView:(UIView *)inputAccessoryView;
+@end
+
+@implementation CustomInputWebView {
+    RetainPtr<UIView> _customInputView;
+    RetainPtr<UIView> _customInputAccessoryView;
+}
+
+- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration inputView:(UIView *)inputView inputAccessoryView:(UIView *)inputAccessoryView
+{
+    if (self = [super initWithFrame:frame configuration:configuration]) {
+        _customInputView = inputView;
+        _customInputAccessoryView = inputAccessoryView;
+    }
+    return self;
+}
+
+- (UIView *)inputView
+{
+    return _customInputView.get();
+}
+
+- (UIView *)inputAccessoryView
+{
+    return _customInputAccessoryView.get();
+}
+
+@end
+
 static RetainPtr<TestWKWebView> webViewWithAutofocusedInput(const RetainPtr<TestInputDelegate>& inputDelegate)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
@@ -431,6 +461,18 @@ TEST(KeyboardInputTests, KeyboardTypeForInput)
     }
 }
 
+TEST(KeyboardInputTests, OverrideInputViewAndInputAccessoryView)
+{
+    auto inputView = adoptNS([[UIView alloc] init]);
+    auto inputAccessoryView = adoptNS([[UIView alloc] init]);
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto webView = adoptNS([[CustomInputWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 568) configuration:configuration.get() inputView:inputView.get() inputAccessoryView:inputAccessoryView.get()]);
+    auto contentView = [webView textInputContentView];
+
+    EXPECT_EQ(inputAccessoryView.get(), [contentView inputAccessoryView]);
+    EXPECT_EQ(inputView.get(), [contentView inputView]);
+}
+
 } // namespace TestWebKitAPI
 
 #endif // PLATFORM(IOS_FAMILY)