⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243963 in webkit


Ignore:
Timestamp:
Apr 6, 2019, 7:25:36 PM (7 years ago)
Author:
Wenson Hsieh
Message:

Hide next and previous form control buttons when WKWebView is editable
https://bugs.webkit.org/show_bug.cgi?id=196672
<rdar://problem/35625321>

Reviewed by Tim Horton.

Source/WebKit:

Adopt new UIKit SPI to hide or show next and previous controls in the form accessory view when changing
editability.

Test: KeyboardInputTests.FormNavigationAssistantBarButtonItems

  • Platform/spi/ios/UIKitSPI.h:
  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _setEditable:]):

  • UIProcess/ios/WKContentViewInteraction.h:
  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView _updateAccessory]):
(-[WKContentView _didChangeWebViewEditability]):

Tools:

Add a new API test.

  • TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:

(-[TestWKWebView lastTrailingBarButtonGroup]):
(TestWebKitAPI::TEST):

  • TestWebKitAPI/ios/UIKitSPI.h:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r243962 r243963  
     12019-04-06  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Hide next and previous form control buttons when WKWebView is editable
     4        https://bugs.webkit.org/show_bug.cgi?id=196672
     5        <rdar://problem/35625321>
     6
     7        Reviewed by Tim Horton.
     8
     9        Adopt new UIKit SPI to hide or show next and previous controls in the form accessory view when changing
     10        editability.
     11
     12        Test: KeyboardInputTests.FormNavigationAssistantBarButtonItems
     13
     14        * Platform/spi/ios/UIKitSPI.h:
     15        * UIProcess/API/Cocoa/WKWebView.mm:
     16        (-[WKWebView _setEditable:]):
     17        * UIProcess/ios/WKContentViewInteraction.h:
     18        * UIProcess/ios/WKContentViewInteraction.mm:
     19        (-[WKContentView _updateAccessory]):
     20        (-[WKContentView _didChangeWebViewEditability]):
     21
    1222019-04-06  Antti Koivisto  <antti@apple.com>
    223
  • trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h

    r243370 r243963  
    11711171}
    11721172
     1173@interface UIWebFormAccessory (Staging_49666643)
     1174- (void)setNextPreviousItemsVisible:(BOOL)visible;
     1175@end
     1176
    11731177WTF_EXTERN_C_BEGIN
    11741178
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r243961 r243963  
    46064606- (void)_setEditable:(BOOL)editable
    46074607{
     4608    bool wasEditable = _page->isEditable();
    46084609    _page->setEditable(editable);
    46094610#if PLATFORM(MAC)
    46104611    if (editable)
    46114612        _impl->didBecomeEditable();
     4613#endif
     4614
     4615    if (wasEditable == editable)
     4616        return;
     4617
     4618#if PLATFORM(IOS_FAMILY)
     4619    [_contentView _didChangeWebViewEditability];
    46124620#endif
    46134621}
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r243808 r243963  
    448448- (void)_accessibilityClearSelection;
    449449- (WKFormInputSession *)_formInputSession;
     450- (void)_didChangeWebViewEditability;
    450451
    451452- (void)_requestDOMPasteAccessWithElementRect:(const WebCore::IntRect&)elementRect originIdentifier:(const String&)originIdentifier completionHandler:(CompletionHandler<void(WebCore::DOMPasteAccessResponse)>&&)completionHandler;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r243808 r243963  
    38123812    auto* accessoryView = self.formAccessoryView; // Creates one, if needed.
    38133813
     3814    if ([accessoryView respondsToSelector:@selector(setNextPreviousItemsVisible:)])
     3815        [accessoryView setNextPreviousItemsVisible:!_webView._editable];
     3816
    38143817    [accessoryView setNextEnabled:_focusedElementInformation.hasNextNode];
    38153818    [accessoryView setPreviousEnabled:_focusedElementInformation.hasPreviousNode];
     
    38493852{
    38503853    [self.inputDelegate selectionDidChange:self];
     3854}
     3855
     3856- (void)_didChangeWebViewEditability
     3857{
     3858    if ([_formAccessoryView respondsToSelector:@selector(setNextPreviousItemsVisible:)])
     3859        [_formAccessoryView setNextPreviousItemsVisible:!_webView._editable];
    38513860}
    38523861
  • trunk/Tools/ChangeLog

    r243961 r243963  
     12019-04-06  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Hide next and previous form control buttons when WKWebView is editable
     4        https://bugs.webkit.org/show_bug.cgi?id=196672
     5        <rdar://problem/35625321>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add a new API test.
     10
     11        * TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm:
     12        (-[TestWKWebView lastTrailingBarButtonGroup]):
     13        (TestWebKitAPI::TEST):
     14        * TestWebKitAPI/ios/UIKitSPI.h:
     15
    1162019-04-05  Yongjun Zhang  <yongjun_zhang@apple.com>
    217
  • trunk/Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm

    r243912 r243963  
    2828#if PLATFORM(IOS_FAMILY)
    2929
     30#import "IPadUserInterfaceSwizzler.h"
    3031#import "PlatformUtilities.h"
    3132#import "TestInputDelegate.h"
     
    141142}
    142143
     144- (UIBarButtonItemGroup *)lastTrailingBarButtonGroup
     145{
     146    return self.firstResponder.inputAssistantItem.trailingBarButtonGroups.lastObject;
     147}
     148
    143149@end
    144150
     
    167173
    168174namespace TestWebKitAPI {
     175
     176TEST(KeyboardInputTests, FormNavigationAssistantBarButtonItems)
     177{
     178    IPadUserInterfaceSwizzler iPadUserInterface;
     179
     180    auto inputDelegate = adoptNS([TestInputDelegate new]);
     181    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     182    [webView _setInputDelegate:inputDelegate.get()];
     183    [inputDelegate setFocusStartsInputSessionPolicyHandler:[&] (WKWebView *, id <_WKFocusedElementInfo>) -> _WKFocusStartsInputSessionPolicy {
     184        return _WKFocusStartsInputSessionPolicyAllow;
     185    }];
     186    [webView synchronouslyLoadHTMLString:@"<body contenteditable>"];
     187    [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.body.focus()"];
     188
     189    EXPECT_EQ(2U, [webView lastTrailingBarButtonGroup].barButtonItems.count);
     190    EXPECT_FALSE([webView lastTrailingBarButtonGroup].hidden);
     191
     192    if (![UIWebFormAccessory instancesRespondToSelector:@selector(setNextPreviousItemsVisible:)]) {
     193        // The rest of this test requires UIWebFormAccessory to be able to show or hide its next and previous items.
     194        return;
     195    }
     196
     197    [webView _setEditable:YES];
     198    EXPECT_TRUE([webView lastTrailingBarButtonGroup].hidden);
     199
     200    [webView _setEditable:NO];
     201    EXPECT_FALSE([webView lastTrailingBarButtonGroup].hidden);
     202}
    169203
    170204TEST(KeyboardInputTests, ModifyInputAssistantItemBarButtonGroups)
  • trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h

    r243519 r243963  
    3131
    3232#import <UIKit/UIApplication_Private.h>
     33#import <UIKit/UIBarButtonItemGroup_Private.h>
    3334#import <UIKit/UICalloutBar.h>
    3435#import <UIKit/UIKeyboard_Private.h>
     
    3940#import <UIKit/UIViewController_Private.h>
    4041#import <UIKit/UIWKTextInteractionAssistant.h>
     42#import <UIKit/UIWebFormAccessory.h>
    4143
    4244#if PLATFORM(IOS)
     
    8284- (BOOL)_shouldSuppressSelectionCommands;
    8385- (NSDictionary *)_autofillContext;
     86@end
     87
     88@interface UIWebFormAccessory : UIInputView
     89@end
     90
     91@interface UIBarButtonItemGroup ()
     92@property (nonatomic, readwrite, assign, getter=_isHidden, setter=_setHidden:) BOOL hidden;
    8493@end
    8594
     
    171180@end
    172181
     182@interface UIWebFormAccessory (Staging_49666643)
     183- (void)setNextPreviousItemsVisible:(BOOL)visible;
     184@end
     185
    173186#endif // PLATFORM(IOS_FAMILY)
Note: See TracChangeset for help on using the changeset viewer.