Changeset 246229 in webkit


Ignore:
Timestamp:
Jun 7, 2019 6:37:37 PM (5 years ago)
Author:
Wenson Hsieh
Message:

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.

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):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r246228 r246229  
     12019-06-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Allow clients to vend custom -inputView and -inputAccessoryView by overriding WKWebView methods
     4        https://bugs.webkit.org/show_bug.cgi?id=198631
     5        <rdar://problem/51505431>
     6
     7        Reviewed by Tim Horton.
     8
     9        Allow WKWebView API clients to override WKContentView's default input view and/or input accessory view by
     10        subclassing WKWebView and implementing -inputView or -inputAccessoryView.
     11
     12        * UIProcess/API/Cocoa/WKWebView.mm:
     13        (-[WKWebView inputAccessoryView]):
     14        (-[WKWebView inputView]):
     15        * UIProcess/ios/WKContentViewInteraction.h:
     16        * UIProcess/ios/WKContentViewInteraction.mm:
     17        (-[WKContentView inputView]):
     18        (-[WKContentView inputViewForWebView]):
     19        (-[WKContentView inputAccessoryView]):
     20        (-[WKContentView inputAccessoryViewForWebView]):
     21
    1222019-06-07  Tim Horton  <timothy_horton@apple.com>
    223
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r245993 r246229  
    45864586}
    45874587
     4588- (UIView *)inputAccessoryView
     4589{
     4590    return [_contentView inputAccessoryViewForWebView];
     4591}
     4592
     4593- (UIView *)inputView
     4594{
     4595    return [_contentView inputViewForWebView];
     4596}
     4597
    45884598#endif // PLATFORM(IOS_FAMILY)
    45894599
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r245998 r246229  
    384384@property (nonatomic, readonly) UIWebFormAccessory *formAccessoryView;
    385385@property (nonatomic, readonly) UITextInputAssistantItem *inputAssistantItemForWebView;
     386@property (nonatomic, readonly) UIView *inputViewForWebView;
     387@property (nonatomic, readonly) UIView *inputAccessoryViewForWebView;
    386388#if ENABLE(POINTER_EVENTS)
    387389@property (nonatomic, readonly) BOOL preventsPanningInXAxis;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r246226 r246229  
    17161716- (UIView *)inputView
    17171717{
     1718    return [_webView inputView];
     1719}
     1720
     1721- (UIView *)inputViewForWebView
     1722{
    17181723    if (!hasFocusedElement(_focusedElementInformation))
    17191724        return nil;
     
    25732578
    25742579- (UIView *)inputAccessoryView
     2580{
     2581    return [_webView inputAccessoryView];
     2582}
     2583
     2584- (UIView *)inputAccessoryViewForWebView
    25752585{
    25762586    if (![self requiresAccessoryView])
  • trunk/Tools/ChangeLog

    r246222 r246229  
     12019-06-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Allow clients to vend custom -inputView and -inputAccessoryView by overriding WKWebView methods
     4        https://bugs.webkit.org/show_bug.cgi?id=198631
     5        <rdar://problem/51505431>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add an API test that overrides -[WKWebView inputView] and -[WKWebView inputAccessoryView].
     10
     11        * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
     12        (-[CustomInputWebView initWithFrame:configuration:inputView:inputAccessoryView:]):
     13        (-[CustomInputWebView inputView]):
     14        (-[CustomInputWebView inputAccessoryView]):
     15        (TestWebKitAPI::TEST):
     16
    1172019-06-07  Daniel Bates  <dabates@apple.com>
    218
  • trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm

    r245338 r246229  
    149149@end
    150150
     151@interface CustomInputWebView : TestWKWebView
     152- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration inputView:(UIView *)inputView inputAccessoryView:(UIView *)inputAccessoryView;
     153@end
     154
     155@implementation CustomInputWebView {
     156    RetainPtr<UIView> _customInputView;
     157    RetainPtr<UIView> _customInputAccessoryView;
     158}
     159
     160- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration inputView:(UIView *)inputView inputAccessoryView:(UIView *)inputAccessoryView
     161{
     162    if (self = [super initWithFrame:frame configuration:configuration]) {
     163        _customInputView = inputView;
     164        _customInputAccessoryView = inputAccessoryView;
     165    }
     166    return self;
     167}
     168
     169- (UIView *)inputView
     170{
     171    return _customInputView.get();
     172}
     173
     174- (UIView *)inputAccessoryView
     175{
     176    return _customInputAccessoryView.get();
     177}
     178
     179@end
     180
    151181static RetainPtr<TestWKWebView> webViewWithAutofocusedInput(const RetainPtr<TestInputDelegate>& inputDelegate)
    152182{
     
    432462}
    433463
     464TEST(KeyboardInputTests, OverrideInputViewAndInputAccessoryView)
     465{
     466    auto inputView = adoptNS([[UIView alloc] init]);
     467    auto inputAccessoryView = adoptNS([[UIView alloc] init]);
     468    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     469    auto webView = adoptNS([[CustomInputWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 568) configuration:configuration.get() inputView:inputView.get() inputAccessoryView:inputAccessoryView.get()]);
     470    auto contentView = [webView textInputContentView];
     471
     472    EXPECT_EQ(inputAccessoryView.get(), [contentView inputAccessoryView]);
     473    EXPECT_EQ(inputView.get(), [contentView inputView]);
     474}
     475
    434476} // namespace TestWebKitAPI
    435477
Note: See TracChangeset for help on using the changeset viewer.