- Revision
- 236691
- Author
- wenson_hs...@apple.com
- Date
- 2018-10-01 13:59:19 -0700 (Mon, 01 Oct 2018)
Log Message
[iOS] Add SPI to customize the input accessory view when focusing an element
https://bugs.webkit.org/show_bug.cgi?id=190152
<rdar://problem/42754975>
Reviewed by Dan Bernstein.
Source/WebKit:
Adds SPI on WKFormInputSession to customize the input accessory view, alongside the input view. See below for
more details.
Test: KeyboardInputTests.CustomInputViewAndInputAccessoryView
* UIProcess/API/Cocoa/_WKFormInputSession.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKFormInputSession customInputAccessoryView]):
(-[WKFormInputSession setCustomInputAccessoryView:]):
Reload input views when the custom input accessory view changes.
(-[WKContentView requiresAccessoryView]):
If a custom input accessory view is specified, return YES.
(-[WKContentView inputAccessoryView]):
Return the custom input accessory view if present, and fall back to the default web form accessory view.
Tools:
Add an API test to verify that setting a custom input accessory view and custom input view on the form input
session when focusing an element overrides the first responder's (i.e. WKContentView's) `-inputView` and
`-inputAccessoryView`.
* TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
(webViewWithAutofocusedInput):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/ios/TestInputDelegate.h:
* TestWebKitAPI/Tests/ios/TestInputDelegate.mm:
(-[TestInputDelegate setWillStartInputSessionHandler:]):
(-[TestInputDelegate willStartInputSessionHandler]):
(-[TestInputDelegate _webView:willStartInputSession:]):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (236690 => 236691)
--- trunk/Source/WebKit/ChangeLog 2018-10-01 20:44:06 UTC (rev 236690)
+++ trunk/Source/WebKit/ChangeLog 2018-10-01 20:59:19 UTC (rev 236691)
@@ -1,3 +1,31 @@
+2018-10-01 Wenson Hsieh <wenson_hs...@apple.com>
+
+ [iOS] Add SPI to customize the input accessory view when focusing an element
+ https://bugs.webkit.org/show_bug.cgi?id=190152
+ <rdar://problem/42754975>
+
+ Reviewed by Dan Bernstein.
+
+ Adds SPI on WKFormInputSession to customize the input accessory view, alongside the input view. See below for
+ more details.
+
+ Test: KeyboardInputTests.CustomInputViewAndInputAccessoryView
+
+ * UIProcess/API/Cocoa/_WKFormInputSession.h:
+ * UIProcess/ios/WKContentViewInteraction.mm:
+ (-[WKFormInputSession customInputAccessoryView]):
+ (-[WKFormInputSession setCustomInputAccessoryView:]):
+
+ Reload input views when the custom input accessory view changes.
+
+ (-[WKContentView requiresAccessoryView]):
+
+ If a custom input accessory view is specified, return YES.
+
+ (-[WKContentView inputAccessoryView]):
+
+ Return the custom input accessory view if present, and fall back to the default web form accessory view.
+
2018-10-01 Sihui Liu <sihui_...@apple.com>
Remove StorageProcess
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKFormInputSession.h (236690 => 236691)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKFormInputSession.h 2018-10-01 20:44:06 UTC (rev 236690)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKFormInputSession.h 2018-10-01 20:59:19 UTC (rev 236691)
@@ -41,6 +41,7 @@
#if TARGET_OS_IPHONE
@property (nonatomic, copy) NSString *accessoryViewCustomButtonTitle;
@property (nonatomic, strong) UIView *customInputView WK_API_AVAILABLE(ios(10.0));
+@property (nonatomic, strong) UIView *customInputAccessoryView WK_API_AVAILABLE(ios(WK_IOS_TBA));
@property (nonatomic, copy) NSArray<UITextSuggestion *> *suggestions WK_API_AVAILABLE(ios(10.0));
@property (nonatomic) BOOL accessoryViewShouldNotShow WK_API_AVAILABLE(ios(10.0));
@property (nonatomic) BOOL forceSecureTextEntry WK_API_AVAILABLE(ios(10.0));
Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (236690 => 236691)
--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2018-10-01 20:44:06 UTC (rev 236690)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm 2018-10-01 20:59:19 UTC (rev 236691)
@@ -293,6 +293,7 @@
WeakObjCPtr<WKContentView> _contentView;
RetainPtr<WKFocusedElementInfo> _focusedElementInfo;
RetainPtr<UIView> _customInputView;
+ RetainPtr<UIView> _customInputAccessoryView;
RetainPtr<NSArray<UITextSuggestion *>> _suggestions;
BOOL _accessoryViewShouldNotShow;
BOOL _forceSecureTextEntry;
@@ -383,6 +384,20 @@
[_contentView reloadInputViews];
}
+- (UIView *)customInputAccessoryView
+{
+ return _customInputAccessoryView.get();
+}
+
+- (void)setCustomInputAccessoryView:(UIView *)customInputAccessoryView
+{
+ if (_customInputAccessoryView == customInputAccessoryView)
+ return;
+
+ _customInputAccessoryView = customInputAccessoryView;
+ [_contentView reloadInputViews];
+}
+
- (void)endEditing
{
if ([_customInputView conformsToProtocol:@protocol(WKFormControl)])
@@ -2089,6 +2104,9 @@
if ([_formInputSession accessoryViewShouldNotShow])
return NO;
+ if ([_formInputSession customInputAccessoryView])
+ return YES;
+
if (_assistedNodeInformation.inputMode == InputMode::None)
return NO;
@@ -2133,7 +2151,7 @@
if (![self requiresAccessoryView])
return nil;
- return self.formAccessoryView;
+ return [_formInputSession customInputAccessoryView] ?: self.formAccessoryView;
}
- (NSArray *)supportedPasteboardTypesForCurrentSelection
Modified: trunk/Tools/ChangeLog (236690 => 236691)
--- trunk/Tools/ChangeLog 2018-10-01 20:44:06 UTC (rev 236690)
+++ trunk/Tools/ChangeLog 2018-10-01 20:59:19 UTC (rev 236691)
@@ -1,3 +1,24 @@
+2018-10-01 Wenson Hsieh <wenson_hs...@apple.com>
+
+ [iOS] Add SPI to customize the input accessory view when focusing an element
+ https://bugs.webkit.org/show_bug.cgi?id=190152
+ <rdar://problem/42754975>
+
+ Reviewed by Dan Bernstein.
+
+ Add an API test to verify that setting a custom input accessory view and custom input view on the form input
+ session when focusing an element overrides the first responder's (i.e. WKContentView's) `-inputView` and
+ `-inputAccessoryView`.
+
+ * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
+ (webViewWithAutofocusedInput):
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/Tests/ios/TestInputDelegate.h:
+ * TestWebKitAPI/Tests/ios/TestInputDelegate.mm:
+ (-[TestInputDelegate setWillStartInputSessionHandler:]):
+ (-[TestInputDelegate willStartInputSessionHandler]):
+ (-[TestInputDelegate _webView:willStartInputSession:]):
+
2018-10-01 Sihui Liu <sihui_...@apple.com>
Remove StorageProcess
Modified: trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm (236690 => 236691)
--- trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm 2018-10-01 20:44:06 UTC (rev 236690)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm 2018-10-01 20:59:19 UTC (rev 236691)
@@ -87,10 +87,9 @@
@end
-static RetainPtr<TestWKWebView> webViewWithAutofocusedInput()
+static RetainPtr<TestWKWebView> webViewWithAutofocusedInput(const RetainPtr<TestInputDelegate>& inputDelegate)
{
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
- auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
bool doneWaiting = false;
[inputDelegate setFocusStartsInputSessionPolicyHandler:[&] (WKWebView *, id <_WKFocusedElementInfo>) -> _WKFocusStartsInputSessionPolicy {
@@ -105,8 +104,29 @@
return webView;
}
+static RetainPtr<TestWKWebView> webViewWithAutofocusedInput()
+{
+ auto inputDelegate = adoptNS([TestInputDelegate new]);
+ return webViewWithAutofocusedInput(inputDelegate);
+}
+
namespace TestWebKitAPI {
+TEST(KeyboardInputTests, CustomInputViewAndInputAccessoryView)
+{
+ auto inputView = adoptNS([[UIView alloc] init]);
+ auto inputAccessoryView = adoptNS([[UIView alloc] init]);
+ auto inputDelegate = adoptNS([TestInputDelegate new]);
+ [inputDelegate setWillStartInputSessionHandler:[inputView, inputAccessoryView] (WKWebView *, id<_WKFormInputSession> session) {
+ session.customInputView = inputView.get();
+ session.customInputAccessoryView = inputAccessoryView.get();
+ }];
+
+ auto webView = webViewWithAutofocusedInput(inputDelegate);
+ EXPECT_EQ(inputView.get(), [webView firstResponder].inputView);
+ EXPECT_EQ(inputAccessoryView.get(), [webView firstResponder].inputAccessoryView);
+}
+
TEST(KeyboardInputTests, CanHandleKeyEventInCompletionHandler)
{
auto webView = webViewWithAutofocusedInput();
Modified: trunk/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.h (236690 => 236691)
--- trunk/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.h 2018-10-01 20:44:06 UTC (rev 236690)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.h 2018-10-01 20:59:19 UTC (rev 236691)
@@ -28,6 +28,7 @@
#if WK_API_ENABLED && PLATFORM(IOS)
#import <WebKit/_WKFocusedElementInfo.h>
+#import <WebKit/_WKFormInputSession.h>
#import <WebKit/_WKInputDelegate.h>
@class WKWebView;
@@ -34,6 +35,7 @@
@interface TestInputDelegate : NSObject <_WKInputDelegate>
@property (nonatomic, copy) _WKFocusStartsInputSessionPolicy (^focusStartsInputSessionPolicyHandler)(WKWebView *, id <_WKFocusedElementInfo>);
+@property (nonatomic, copy) void (^willStartInputSessionHandler)(WKWebView *, id <_WKFormInputSession>);
@end
#endif
Modified: trunk/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.mm (236690 => 236691)
--- trunk/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.mm 2018-10-01 20:44:06 UTC (rev 236690)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.mm 2018-10-01 20:59:19 UTC (rev 236691)
@@ -32,6 +32,7 @@
@implementation TestInputDelegate {
BlockPtr<_WKFocusStartsInputSessionPolicy(WKWebView *, id <_WKFocusedElementInfo>)> _focusStartsInputSessionPolicyHandler;
+ BlockPtr<void(WKWebView *, id <_WKFormInputSession>)> _willStartInputSessionHandler;
}
- (void)setFocusStartsInputSessionPolicyHandler:(_WKFocusStartsInputSessionPolicy (^)(WKWebView *, id <_WKFocusedElementInfo>))handler
@@ -44,11 +45,27 @@
return _focusStartsInputSessionPolicyHandler.get();
}
+- (void)setWillStartInputSessionHandler:(void (^)(WKWebView *, id<_WKFormInputSession>))willStartInputSessionHandler
+{
+ _willStartInputSessionHandler = makeBlockPtr(willStartInputSessionHandler);
+}
+
+- (void (^)(WKWebView *, id<_WKFormInputSession>))willStartInputSessionHandler
+{
+ return _willStartInputSessionHandler.get();
+}
+
- (_WKFocusStartsInputSessionPolicy)_webView:(WKWebView *)webView decidePolicyForFocusedElement:(id <_WKFocusedElementInfo>)info
{
return self.focusStartsInputSessionPolicyHandler ? self.focusStartsInputSessionPolicyHandler(webView, info) : _WKFocusStartsInputSessionPolicyAuto;
}
+- (void)_webView:(WKWebView *)webView willStartInputSession:(id<_WKFormInputSession>)inputSession
+{
+ if (_willStartInputSessionHandler)
+ _willStartInputSessionHandler(webView, inputSession);
+}
+
@end
#endif // WK_API_ENABLED && PLATFORM(IOS)