Changeset 236691 in webkit


Ignore:
Timestamp:
Oct 1, 2018 1:59:19 PM (6 years ago)
Author:
Wenson Hsieh
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:]):

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r236690 r236691  
     12018-10-01  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] Add SPI to customize the input accessory view when focusing an element
     4        https://bugs.webkit.org/show_bug.cgi?id=190152
     5        <rdar://problem/42754975>
     6
     7        Reviewed by Dan Bernstein.
     8
     9        Adds SPI on WKFormInputSession to customize the input accessory view, alongside the input view. See below for
     10        more details.
     11
     12        Test: KeyboardInputTests.CustomInputViewAndInputAccessoryView
     13
     14        * UIProcess/API/Cocoa/_WKFormInputSession.h:
     15        * UIProcess/ios/WKContentViewInteraction.mm:
     16        (-[WKFormInputSession customInputAccessoryView]):
     17        (-[WKFormInputSession setCustomInputAccessoryView:]):
     18
     19        Reload input views when the custom input accessory view changes.
     20
     21        (-[WKContentView requiresAccessoryView]):
     22
     23        If a custom input accessory view is specified, return YES.
     24
     25        (-[WKContentView inputAccessoryView]):
     26
     27        Return the custom input accessory view if present, and fall back to the default web form accessory view.
     28
    1292018-10-01  Sihui Liu  <sihui_liu@apple.com>
    230
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKFormInputSession.h

    r235961 r236691  
    4242@property (nonatomic, copy) NSString *accessoryViewCustomButtonTitle;
    4343@property (nonatomic, strong) UIView *customInputView WK_API_AVAILABLE(ios(10.0));
     44@property (nonatomic, strong) UIView *customInputAccessoryView WK_API_AVAILABLE(ios(WK_IOS_TBA));
    4445@property (nonatomic, copy) NSArray<UITextSuggestion *> *suggestions WK_API_AVAILABLE(ios(10.0));
    4546@property (nonatomic) BOOL accessoryViewShouldNotShow WK_API_AVAILABLE(ios(10.0));
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r236669 r236691  
    294294    RetainPtr<WKFocusedElementInfo> _focusedElementInfo;
    295295    RetainPtr<UIView> _customInputView;
     296    RetainPtr<UIView> _customInputAccessoryView;
    296297    RetainPtr<NSArray<UITextSuggestion *>> _suggestions;
    297298    BOOL _accessoryViewShouldNotShow;
     
    381382
    382383    _customInputView = customInputView;
     384    [_contentView reloadInputViews];
     385}
     386
     387- (UIView *)customInputAccessoryView
     388{
     389    return _customInputAccessoryView.get();
     390}
     391
     392- (void)setCustomInputAccessoryView:(UIView *)customInputAccessoryView
     393{
     394    if (_customInputAccessoryView == customInputAccessoryView)
     395        return;
     396
     397    _customInputAccessoryView = customInputAccessoryView;
    383398    [_contentView reloadInputViews];
    384399}
     
    20902105        return NO;
    20912106
     2107    if ([_formInputSession customInputAccessoryView])
     2108        return YES;
     2109
    20922110    if (_assistedNodeInformation.inputMode == InputMode::None)
    20932111        return NO;
     
    21342152        return nil;
    21352153
    2136     return self.formAccessoryView;
     2154    return [_formInputSession customInputAccessoryView] ?: self.formAccessoryView;
    21372155}
    21382156
  • trunk/Tools/ChangeLog

    r236690 r236691  
     12018-10-01  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] Add SPI to customize the input accessory view when focusing an element
     4        https://bugs.webkit.org/show_bug.cgi?id=190152
     5        <rdar://problem/42754975>
     6
     7        Reviewed by Dan Bernstein.
     8
     9        Add an API test to verify that setting a custom input accessory view and custom input view on the form input
     10        session when focusing an element overrides the first responder's (i.e. WKContentView's) `-inputView` and
     11        `-inputAccessoryView`.
     12
     13        * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
     14        (webViewWithAutofocusedInput):
     15        (TestWebKitAPI::TEST):
     16        * TestWebKitAPI/Tests/ios/TestInputDelegate.h:
     17        * TestWebKitAPI/Tests/ios/TestInputDelegate.mm:
     18        (-[TestInputDelegate setWillStartInputSessionHandler:]):
     19        (-[TestInputDelegate willStartInputSessionHandler]):
     20        (-[TestInputDelegate _webView:willStartInputSession:]):
     21
    1222018-10-01  Sihui Liu  <sihui_liu@apple.com>
    223
  • trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm

    r235201 r236691  
    8888@end
    8989
    90 static RetainPtr<TestWKWebView> webViewWithAutofocusedInput()
     90static RetainPtr<TestWKWebView> webViewWithAutofocusedInput(const RetainPtr<TestInputDelegate>& inputDelegate)
    9191{
    9292    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
    93     auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
    9493
    9594    bool doneWaiting = false;
     
    106105}
    107106
     107static RetainPtr<TestWKWebView> webViewWithAutofocusedInput()
     108{
     109    auto inputDelegate = adoptNS([TestInputDelegate new]);
     110    return webViewWithAutofocusedInput(inputDelegate);
     111}
     112
    108113namespace TestWebKitAPI {
     114
     115TEST(KeyboardInputTests, CustomInputViewAndInputAccessoryView)
     116{
     117    auto inputView = adoptNS([[UIView alloc] init]);
     118    auto inputAccessoryView = adoptNS([[UIView alloc] init]);
     119    auto inputDelegate = adoptNS([TestInputDelegate new]);
     120    [inputDelegate setWillStartInputSessionHandler:[inputView, inputAccessoryView] (WKWebView *, id<_WKFormInputSession> session) {
     121        session.customInputView = inputView.get();
     122        session.customInputAccessoryView = inputAccessoryView.get();
     123    }];
     124
     125    auto webView = webViewWithAutofocusedInput(inputDelegate);
     126    EXPECT_EQ(inputView.get(), [webView firstResponder].inputView);
     127    EXPECT_EQ(inputAccessoryView.get(), [webView firstResponder].inputAccessoryView);
     128}
    109129
    110130TEST(KeyboardInputTests, CanHandleKeyEventInCompletionHandler)
  • trunk/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.h

    r234504 r236691  
    2929
    3030#import <WebKit/_WKFocusedElementInfo.h>
     31#import <WebKit/_WKFormInputSession.h>
    3132#import <WebKit/_WKInputDelegate.h>
    3233
     
    3536@interface TestInputDelegate : NSObject <_WKInputDelegate>
    3637@property (nonatomic, copy) _WKFocusStartsInputSessionPolicy (^focusStartsInputSessionPolicyHandler)(WKWebView *, id <_WKFocusedElementInfo>);
     38@property (nonatomic, copy) void (^willStartInputSessionHandler)(WKWebView *, id <_WKFormInputSession>);
    3739@end
    3840
  • trunk/Tools/TestWebKitAPI/Tests/ios/TestInputDelegate.mm

    r234504 r236691  
    3333@implementation TestInputDelegate {
    3434    BlockPtr<_WKFocusStartsInputSessionPolicy(WKWebView *, id <_WKFocusedElementInfo>)> _focusStartsInputSessionPolicyHandler;
     35    BlockPtr<void(WKWebView *, id <_WKFormInputSession>)> _willStartInputSessionHandler;
    3536}
    3637
     
    4546}
    4647
     48- (void)setWillStartInputSessionHandler:(void (^)(WKWebView *, id<_WKFormInputSession>))willStartInputSessionHandler
     49{
     50    _willStartInputSessionHandler = makeBlockPtr(willStartInputSessionHandler);
     51}
     52
     53- (void (^)(WKWebView *, id<_WKFormInputSession>))willStartInputSessionHandler
     54{
     55    return _willStartInputSessionHandler.get();
     56}
     57
    4758- (_WKFocusStartsInputSessionPolicy)_webView:(WKWebView *)webView decidePolicyForFocusedElement:(id <_WKFocusedElementInfo>)info
    4859{
     
    5061}
    5162
     63- (void)_webView:(WKWebView *)webView willStartInputSession:(id<_WKFormInputSession>)inputSession
     64{
     65    if (_willStartInputSessionHandler)
     66        _willStartInputSessionHandler(webView, inputSession);
     67}
     68
    5269@end
    5370
Note: See TracChangeset for help on using the changeset viewer.