Changeset 243808 in webkit


Ignore:
Timestamp:
Apr 3, 2019 10:06:04 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

[iOS] Should be able to dismiss picker or popover using the keyboard
https://bugs.webkit.org/show_bug.cgi?id=196272
<rdar://problem/48943170>

Patch by Daniel Bates <dabates@apple.com> on 2019-04-03
Reviewed by Wenson Hsieh.

Source/WebKit:

Intercept key events and route them to the current input peripheral (if we have one). Add a base key event handler
for all form peripherals that dismisses the accessory when either the Escape key is pressed or Command + . is pressed.
I will fix this issue for the file upload picker/popover in <https://bugs.webkit.org/show_bug.cgi?id=196287>.

  • SourcesCocoa.txt: Add file WKFormPeripheralBase.mm.
  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView endEditingAndUpdateFocusAppearanceWithReason]): Added.
(-[WKContentView resignFirstResponderForWebView]): Write in terms of -endEditingAndUpdateFocusAppearance.
(-[WKContentView inputView]): Code style nit while I am here; add an empty line to demarcate the "crazy"
code that the FIXME is referring to and should ideally be removed from the code that is sane to always do.
(-[WKContentView accessoryDone]): When the accessory is dismissed via the Done button (iPhone) or by pressing
Escape or Command + . using a hardware keyboard (iPhone or iPad) then end the current editing session, but
do not resign first responder status as the page activation state should not be changed.
(-[WKContentView _handleKeyUIEvent:]): Bring back this code when building with USE(UIKIT_KEYBOARD_ADDITIONS)
as we need to route key events to the input peripheral (if we have one). If the input peripheral handles it
then we're done: no need to let UIKit or WebKit handle it when building with USE(UIKIT_KEYBOARD_ADDITIONS),
respectively. If the input peripheral does not handle it then do what we do now.
(-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):
If the element is re-focused and we have an input peripheral then we want to ensure we are first responder,
reveal the focused element, update the accessory and tell the peripheral that editing has begun (again).
For all other element re-focusing where we don't have a peripheral do what we do now. Also, update _isEditable
to reflect whether the focused element contains selectable text. This is what UIKit wants to know when it queries
-isEditable. Now that we no longer blur the focused element on iPad when the popover is dismissed and keep the
peripheral until there is a focus change we need to ensure that we give the correct answer to UIKit on view
editability. Otherwise, UIKit thinks it needs to update the text selection state when a popup button is tapped
again (as part of its gesture recognizer logic) and this causes an assertion failure in UIKit after it calls back
into us to ask for selection details, which we correctly respond with the equivalent of "we have none" and is
not the answer UIKit expects since we told it we are editable. (Currently we manage to get away with telling UIKit
we are always editable because it is not possible to perform a selection operation when we have a popover open.
Closing the popover blurs the element, setting -isEditable to NO and deallocates the peripheral avoiding this issue).

  • UIProcess/ios/forms/WKFormColorControl.h:
  • UIProcess/ios/forms/WKFormColorControl.mm:

(-[WKColorPopover controlEndEditing]): Dismiss the popover.
(-[WKFormColorControl initWithView:]): Modified to call base class initializer.
(-[WKFormColorControl assistantView]): Deleted.
(-[WKFormColorControl beginEditing]): Deleted.
(-[WKFormColorControl endEditing]): Deleted.

  • UIProcess/ios/forms/WKFormInputControl.h:
  • UIProcess/ios/forms/WKFormInputControl.mm:

(-[WKFormInputControl initWithView:]): Modified to call base class initializer.
(-[WKFormInputControl dateTimePickerCalendarType]): Write in terms of self.control.
(-[WKDateTimePopover controlEndEditing]): Dismiss the popover and tell the controller that editing ended.
(-[WKFormInputControl beginEditing]): Deleted.
(-[WKFormInputControl endEditing]): Deleted.
(-[WKFormInputControl assistantView]): Deleted.

  • UIProcess/ios/forms/WKFormPeripheral.h:
  • UIProcess/ios/forms/WKFormPeripheralBase.h: Added.
  • UIProcess/ios/forms/WKFormPeripheralBase.mm: Added.

(-[WKFormPeripheralBase initWithView:control:]): Take ownership of the passed WKFormControl.
(-[WKFormPeripheralBase beginEditing]): Turn around and tell the control.
(-[WKFormPeripheralBase endEditing]): Ditto.
(-[WKFormPeripheralBase assistantView]): Ditto.
(-[WKFormPeripheralBase control]): Return the control.
(-[WKFormPeripheralBase handleKeyEvent:]): Dismiss the accessory (in the same way we dismiss when the Done
button is pressed on iPhone) on keydown of the Escape key or when we receive a UIKeyInputEscape event (for
Command + .).

  • UIProcess/ios/forms/WKFormSelectControl.h:
  • UIProcess/ios/forms/WKFormSelectControl.mm:

(-[WKFormSelectControl initWithView:]): Modified to call base class initializer.
(-[WKFormSelectControl selectRow:inComponent:extendingSelection:]): Write in terms of self.control.
(-[WKFormSelectControl selectFormPopoverTitle]): Ditto.
(-[WKFormSelectControl assistantView]): Deleted.
(-[WKFormSelectControl beginEditing]): Deleted.
(-[WKFormSelectControl endEditing]): Deleted.

  • UIProcess/ios/forms/WKFormSelectPopover.mm:

(-[WKSelectPopover controlEndEditing]): Dismiss the popover.

  • WebKit.xcodeproj/project.pbxproj: Add files WKFormPeripheralBase.{h, mm}.

LayoutTests:

Add test to ensure that pressing Escape or Command + . dismisses a picker.

  • fast/forms/ios/dismiss-picker-using-keyboard-expected.txt: Added.
  • fast/forms/ios/dismiss-picker-using-keyboard.html: Added.
Location:
trunk
Files:
3 added
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r243807 r243808  
     12019-04-03  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Should be able to dismiss picker or popover using the keyboard
     4        https://bugs.webkit.org/show_bug.cgi?id=196272
     5        <rdar://problem/48943170>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Add test to ensure that pressing Escape or Command + . dismisses a picker.
     10
     11        * fast/forms/ios/dismiss-picker-using-keyboard-expected.txt: Added.
     12        * fast/forms/ios/dismiss-picker-using-keyboard.html: Added.
     13
    1142019-04-03  Sihui Liu  <sihui_liu@apple.com>
    215
  • trunk/Source/WebKit/ChangeLog

    r243806 r243808  
     12019-04-03  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Should be able to dismiss picker or popover using the keyboard
     4        https://bugs.webkit.org/show_bug.cgi?id=196272
     5        <rdar://problem/48943170>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Intercept key events and route them to the current input peripheral (if we have one). Add a base key event handler
     10        for all form peripherals that dismisses the accessory when either the Escape key is pressed or Command + . is pressed.
     11        I will fix this issue for the file upload picker/popover in <https://bugs.webkit.org/show_bug.cgi?id=196287>.
     12
     13        * SourcesCocoa.txt: Add file WKFormPeripheralBase.mm.
     14        * UIProcess/ios/WKContentViewInteraction.mm:
     15        (-[WKContentView endEditingAndUpdateFocusAppearanceWithReason]): Added.
     16        (-[WKContentView resignFirstResponderForWebView]): Write in terms of -endEditingAndUpdateFocusAppearance.
     17        (-[WKContentView inputView]): Code style nit while I am here; add an empty line to demarcate the "crazy"
     18        code that the FIXME is referring to and should ideally be removed from the code that is sane to always do.
     19        (-[WKContentView accessoryDone]): When the accessory is dismissed via the Done button (iPhone) or by pressing
     20        Escape or Command + . using a hardware keyboard (iPhone or iPad) then end the current editing session, but
     21        do not resign first responder status as the page activation state should not be changed.
     22        (-[WKContentView _handleKeyUIEvent:]): Bring back this code when building with USE(UIKIT_KEYBOARD_ADDITIONS)
     23        as we need to route key events to the input peripheral (if we have one). If the input peripheral handles it
     24        then we're done: no need to let UIKit or WebKit handle it when building with USE(UIKIT_KEYBOARD_ADDITIONS),
     25        respectively. If the input peripheral does not handle it then do what we do now.
     26        (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):
     27        If the element is re-focused and we have an input peripheral then we want to ensure we are first responder,
     28        reveal the focused element, update the accessory and tell the peripheral that editing has begun (again).
     29        For all other element re-focusing where we don't have a peripheral do what we do now. Also, update _isEditable
     30        to reflect whether the focused element contains selectable text. This is what UIKit wants to know when it queries
     31        -isEditable. Now that we no longer blur the focused element on iPad when the popover is dismissed and keep the
     32        peripheral until there is a focus change we need to ensure that we give the correct answer to UIKit on view
     33        editability. Otherwise, UIKit thinks it needs to update the text selection state when a popup button is tapped
     34        again (as part of its gesture recognizer logic) and this causes an assertion failure in UIKit after it calls back
     35        into us to ask for selection details, which we correctly respond with the equivalent of "we have none" and is
     36        not the answer UIKit expects since we told it we are editable. (Currently we manage to get away with telling UIKit
     37        we are always editable because it is not possible to perform a selection operation when we have a popover open.
     38        Closing the popover blurs the element, setting -isEditable to NO and deallocates the peripheral avoiding this issue).
     39        * UIProcess/ios/forms/WKFormColorControl.h:
     40        * UIProcess/ios/forms/WKFormColorControl.mm:
     41        (-[WKColorPopover controlEndEditing]): Dismiss the popover.
     42        (-[WKFormColorControl initWithView:]): Modified to call base class initializer.
     43        (-[WKFormColorControl assistantView]): Deleted.
     44        (-[WKFormColorControl beginEditing]): Deleted.
     45        (-[WKFormColorControl endEditing]): Deleted.
     46        * UIProcess/ios/forms/WKFormInputControl.h:
     47        * UIProcess/ios/forms/WKFormInputControl.mm:
     48        (-[WKFormInputControl initWithView:]): Modified to call base class initializer.
     49        (-[WKFormInputControl dateTimePickerCalendarType]): Write in terms of self.control.
     50        (-[WKDateTimePopover controlEndEditing]): Dismiss the popover and tell the controller that editing ended.
     51        (-[WKFormInputControl beginEditing]): Deleted.
     52        (-[WKFormInputControl endEditing]): Deleted.
     53        (-[WKFormInputControl assistantView]): Deleted.
     54        * UIProcess/ios/forms/WKFormPeripheral.h:
     55        * UIProcess/ios/forms/WKFormPeripheralBase.h: Added.
     56        * UIProcess/ios/forms/WKFormPeripheralBase.mm: Added.
     57        (-[WKFormPeripheralBase initWithView:control:]): Take ownership of the passed WKFormControl.
     58        (-[WKFormPeripheralBase beginEditing]): Turn around and tell the control.
     59        (-[WKFormPeripheralBase endEditing]): Ditto.
     60        (-[WKFormPeripheralBase assistantView]): Ditto.
     61        (-[WKFormPeripheralBase control]): Return the control.
     62        (-[WKFormPeripheralBase handleKeyEvent:]): Dismiss the accessory (in the same way we dismiss when the Done
     63        button is pressed on iPhone) on keydown of the Escape key or when we receive a UIKeyInputEscape event (for
     64        Command + .).
     65        * UIProcess/ios/forms/WKFormSelectControl.h:
     66        * UIProcess/ios/forms/WKFormSelectControl.mm:
     67        (-[WKFormSelectControl initWithView:]): Modified to call base class initializer.
     68        (-[WKFormSelectControl selectRow:inComponent:extendingSelection:]): Write in terms of self.control.
     69        (-[WKFormSelectControl selectFormPopoverTitle]): Ditto.
     70        (-[WKFormSelectControl assistantView]): Deleted.
     71        (-[WKFormSelectControl beginEditing]): Deleted.
     72        (-[WKFormSelectControl endEditing]): Deleted.
     73        * UIProcess/ios/forms/WKFormSelectPopover.mm:
     74        (-[WKSelectPopover controlEndEditing]): Dismiss the popover.
     75        * WebKit.xcodeproj/project.pbxproj: Add files WKFormPeripheralBase.{h, mm}.
     76
    1772019-04-03  Youenn Fablet  <youenn@apple.com>
    278
  • trunk/Source/WebKit/SourcesCocoa.txt

    r243726 r243808  
    368368UIProcess/ios/forms/WKFormColorPicker.mm
    369369UIProcess/ios/forms/WKFormInputControl.mm
     370UIProcess/ios/forms/WKFormPeripheralBase.mm
    370371UIProcess/ios/forms/WKFormPopover.mm
    371372UIProcess/ios/forms/WKFormSelectControl.mm
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r243523 r243808  
    313313    BOOL _becomingFirstResponder;
    314314    BOOL _resigningFirstResponder;
    315     BOOL _dismissingAccessory;
    316315    BOOL _needsDeferredEndScrollingSelectionUpdate;
    317316    BOOL _isChangingFocus;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r243713 r243808  
    11701170}
    11711171
    1172 - (BOOL)resignFirstResponderForWebView
    1173 {
    1174     // FIXME: Maybe we should call resignFirstResponder on the superclass
    1175     // and do nothing if the return value is NO.
    1176 
    1177     SetForScope<BOOL> resigningFirstResponderScope { _resigningFirstResponder, YES };
    1178 
     1172typedef NS_ENUM(NSInteger, EndEditingReason) {
     1173    EndEditingReasonAccessoryDone,
     1174    EndEditingReasonResigningFirstResponder,
     1175};
     1176
     1177- (void)endEditingAndUpdateFocusAppearanceWithReason:(EndEditingReason)reason
     1178{
    11791179    if (!_webView._retainingActiveFocusedState) {
    11801180        // We need to complete the editing operation before we blur the element.
    11811181        [self _endEditing];
    1182         if (_dismissingAccessory || _keyboardDidRequestDismissal)
     1182        if ((reason == EndEditingReasonAccessoryDone && !currentUserInterfaceIdiomIsPad()) || _keyboardDidRequestDismissal)
    11831183            _page->blurFocusedElement();
    11841184    }
     
    11861186    [self _cancelInteraction];
    11871187    [_textSelectionAssistant deactivateSelection];
    1188    
     1188
    11891189    [self _resetInputViewDeferral];
     1190}
     1191
     1192- (BOOL)resignFirstResponderForWebView
     1193{
     1194    // FIXME: Maybe we should call resignFirstResponder on the superclass
     1195    // and do nothing if the return value is NO.
     1196
     1197    SetForScope<BOOL> resigningFirstResponderScope { _resigningFirstResponder, YES };
     1198
     1199    [self endEditingAndUpdateFocusAppearanceWithReason:EndEditingReasonResigningFirstResponder];
    11901200
    11911201    // If the user explicitly dismissed the keyboard then we will lose first responder
     
    37593769- (void)accessoryDone
    37603770{
    3761     SetForScope<BOOL> dismissingAccessoryScope { _dismissingAccessory, YES };
    3762     [self resignFirstResponder];
     3771    [self endEditingAndUpdateFocusAppearanceWithReason:EndEditingReasonAccessoryDone];
     3772    _page->setIsShowingInputViewForFocusedElement(false);
    37633773}
    37643774
     
    43634373}
    43644374
    4365 #if !USE(UIKIT_KEYBOARD_ADDITIONS)
    43664375- (void)_handleKeyUIEvent:(::UIEvent *)event
    43674376{
    43684377    bool isHardwareKeyboardEvent = !!event._hidEvent;
    4369 
    43704378    // We only want to handle key event from the hardware keyboard when we are
    43714379    // first responder and we are not interacting with editable content.
    4372     if ([self isFirstResponder] && isHardwareKeyboardEvent && !_page->editorState().isContentEditable) {
     4380    if ([self isFirstResponder] && isHardwareKeyboardEvent && (_inputPeripheral || !_page->editorState().isContentEditable)) {
     4381        if ([_inputPeripheral respondsToSelector:@selector(handleKeyEvent:)]) {
     4382            if ([_inputPeripheral handleKeyEvent:event])
     4383                return;
     4384        }
     4385#if USE(UIKIT_KEYBOARD_ADDITIONS)
     4386        [super _handleKeyUIEvent:event];
     4387#else
    43734388        [self handleKeyEvent:event];
     4389#endif
    43744390        return;
    43754391    }
     
    43784394}
    43794395
     4396#if !USE(UIKIT_KEYBOARD_ADDITIONS)
    43804397- (void)handleKeyEvent:(::UIEvent *)event
    43814398{
     
    49704987    // FIXME: We should remove this check when we manage to send ElementDidFocus from the WebProcess
    49714988    // only when it is truly time to show the keyboard.
    4972     if (_focusedElementInformation.elementType == information.elementType && _focusedElementInformation.elementRect == information.elementRect)
    4973         return;
     4989    if (_focusedElementInformation.elementType == information.elementType && _focusedElementInformation.elementRect == information.elementRect) {
     4990        if (_inputPeripheral) {
     4991            if (!self.isFirstResponder)
     4992                [self becomeFirstResponder];
     4993            [self _zoomToRevealFocusedElement];
     4994            [self _updateAccessory];
     4995            [_inputPeripheral beginEditing];
     4996        }
     4997        return;
     4998    }
    49744999
    49755000    [_webView _resetFocusPreservationCount];
     
    49905015        [inputDelegate _webView:_webView willStartInputSession:_formInputSession.get()];
    49915016
    4992     BOOL editableChanged = [self setIsEditable:YES];
     5017    BOOL isSelectable = mayContainSelectableText(information.elementType);
     5018    BOOL editableChanged = [self setIsEditable:isSelectable];
    49935019    _focusedElementInformation = information;
    49945020    _traits = nil;
     
    50075033#endif
    50085034
    5009     if (mayContainSelectableText(_focusedElementInformation.elementType))
     5035    if (isSelectable)
    50105036        [self _showKeyboard];
    50115037
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFormColorControl.h

    r237266 r243808  
    2626#if ENABLE(INPUT_TYPE_COLOR) && PLATFORM(IOS_FAMILY)
    2727
    28 #import "WKFormPeripheral.h"
     28#import "WKFormPeripheralBase.h"
    2929
    3030@class WKContentView;
    3131
    32 @interface WKFormColorControl : NSObject<WKFormPeripheral>
     32@interface WKFormColorControl : WKFormPeripheralBase
    3333- (instancetype)initWithView:(WKContentView *)view;
    3434@end
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFormColorControl.mm

    r237266 r243808  
    8787- (void)controlEndEditing
    8888{
     89    [self dismissPopoverAnimated:NO];
    8990}
    9091
     
    9394#pragma mark - WKFormColorControl
    9495
    95 @implementation WKFormColorControl {
    96     RetainPtr<id<WKFormControl>> _control;
    97 }
     96@implementation WKFormColorControl
    9897
    9998- (instancetype)initWithView:(WKContentView *)view
    10099{
    101     if (!(self = [super init]))
    102         return nil;
    103 
     100    RetainPtr<NSObject <WKFormControl>> control;
    104101    if (currentUserInterfaceIdiomIsPad())
    105         _control = adoptNS([[WKColorPopover alloc] initWithView:view]);
     102        control = adoptNS([[WKColorPopover alloc] initWithView:view]);
    106103    else
    107         _control = adoptNS([[WKColorPicker alloc] initWithView:view]);
    108 
    109     return self;
    110 }
    111 
    112 - (UIView *)assistantView
    113 {
    114     return [_control controlView];
    115 }
    116 
    117 - (void)beginEditing
    118 {
    119     [_control controlBeginEditing];
    120 }
    121 
    122 - (void)endEditing
    123 {
    124     [_control controlEndEditing];
     104        control = adoptNS([[WKColorPicker alloc] initWithView:view]);
     105    return [super initWithView:view control:WTFMove(control)];
    125106}
    126107
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFormInputControl.h

    r237924 r243808  
    2626#if PLATFORM(IOS_FAMILY)
    2727
    28 #import "WKFormPeripheral.h"
     28#import "WKFormPeripheralBase.h"
    2929
    3030@class WKContentView;
    3131
    32 @interface WKFormInputControl : NSObject<WKFormPeripheral>
     32@interface WKFormInputControl : WKFormPeripheralBase
    3333- (instancetype)initWithView:(WKContentView *)view;
    3434@end
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFormInputControl.mm

    r241275 r243808  
    240240
    241241// WKFormInputControl
    242 @implementation WKFormInputControl {
    243     RetainPtr<NSObject <WKFormControl>> _control;
    244 }
     242@implementation WKFormInputControl
    245243
    246244- (instancetype)initWithView:(WKContentView *)view
    247245{
    248     if (!(self = [super init]))
    249         return nil;
    250 
    251246    UIDatePickerMode mode;
    252247
     
    255250        mode = UIDatePickerModeDate;
    256251        break;
    257 
    258252    case InputType::DateTimeLocal:
    259253        mode = UIDatePickerModeDateAndTime;
    260254        break;
    261 
    262255    case InputType::Time:
    263256        mode = UIDatePickerModeTime;
    264257        break;
    265 
    266258    case InputType::Month:
    267259        mode = (UIDatePickerMode)UIDatePickerModeYearAndMonth;
    268260        break;
    269 
    270261    default:
    271262        [self release];
     
    273264    }
    274265
     266    RetainPtr<NSObject <WKFormControl>> control;
    275267    if (currentUserInterfaceIdiomIsPad())
    276         _control = adoptNS([[WKDateTimePopover alloc] initWithView:view datePickerMode:mode]);
     268        control = adoptNS([[WKDateTimePopover alloc] initWithView:view datePickerMode:mode]);
    277269    else
    278         _control = adoptNS([[WKDateTimePicker alloc] initWithView:view datePickerMode:mode]);
    279 
    280     return self;
    281 
    282 }
    283 
    284 - (void)beginEditing
    285 {
    286     [_control controlBeginEditing];
    287 }
    288 
    289 - (void)endEditing
    290 {
    291     [_control controlEndEditing];
    292 }
    293 
    294 - (UIView *)assistantView
    295 {
    296     return [_control controlView];
     270        control = adoptNS([[WKDateTimePicker alloc] initWithView:view datePickerMode:mode]);
     271    return [super initWithView:view control:WTFMove(control)];
    297272}
    298273
     
    303278- (NSString *)dateTimePickerCalendarType
    304279{
    305     if ([_control isKindOfClass:WKDateTimePicker.class])
    306         return [(WKDateTimePicker *)_control.get() calendarType];
    307 
    308     if ([_control isKindOfClass:WKDateTimePopover.class])
    309         return [(WKDateTimePopover *)_control.get() calendarType];
    310 
     280    if ([self.control isKindOfClass:WKDateTimePicker.class])
     281        return [(WKDateTimePicker *)self.control calendarType];
     282    if ([self.control isKindOfClass:WKDateTimePopover.class])
     283        return [(WKDateTimePopover *)self.control calendarType];
    311284    return nil;
    312285}
     
    389362- (void)controlEndEditing
    390363{
     364    [self dismissPopoverAnimated:NO];
     365    [_viewController.get().innerControl controlEndEditing];
    391366}
    392367
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFormPeripheral.h

    r164760 r243808  
    2424 */
    2525
     26@class UIEvent;
    2627@class UIView;
    2728
     
    3031- (void)endEditing;
    3132- (UIView *)assistantView;
     33@optional
     34- (BOOL)handleKeyEvent:(UIEvent *)event;
    3235@end
    3336
     
    3639- (void)controlBeginEditing;
    3740- (void)controlEndEditing;
     41@optional
     42- (BOOL)controlHandleKeyEvent:(UIEvent *)event;
    3843@end
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFormPeripheralBase.h

    r243807 r243808  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727
    2828#import "WKFormPeripheral.h"
     29#import <wtf/Forward.h>
    2930
    3031@class WKContentView;
    3132
    32 @interface WKFormInputControl : NSObject<WKFormPeripheral>
    33 - (instancetype)initWithView:(WKContentView *)view;
     33@interface WKFormPeripheralBase : NSObject <WKFormPeripheral>
     34
     35- (instancetype)init NS_UNAVAILABLE;
     36- (instancetype)initWithView:(WKContentView *)view control:(RetainPtr<NSObject <WKFormControl>>&&)control NS_DESIGNATED_INITIALIZER;
     37
     38- (void)beginEditing;
     39- (void)endEditing;
     40- (UIView *)assistantView;
     41- (BOOL)handleKeyEvent:(UIEvent *)event;
     42
     43@property (nonatomic, readonly) WKContentView *view;
     44@property (nonatomic, readonly) NSObject <WKFormControl> *control;
     45@property (nonatomic, readonly, getter=isEditing) BOOL editing;
     46
    3447@end
    3548
    36 @interface WKFormInputControl (WKTesting)
    37 @property (nonatomic, readonly) NSString *dateTimePickerCalendarType;
    38 @end
    39 
    40 #endif // PLATFORM(IOS_FAMILY)
     49#endif
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFormSelectControl.h

    r239454 r243808  
    2828#import "FocusedElementInformation.h"
    2929#import "UIKitSPI.h"
    30 #import "WKFormPeripheral.h"
     30#import "WKFormPeripheralBase.h"
    3131#import "WKFormPopover.h"
    3232#import <UIKit/UIPickerView.h>
     
    3636@class WKContentView;
    3737
    38 @interface WKFormSelectControl : NSObject<WKFormPeripheral>
     38@interface WKFormSelectControl : WKFormPeripheralBase
    3939- (instancetype)initWithView:(WKContentView *)view;
    4040@end
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFormSelectControl.mm

    r239454 r243808  
    6666- (instancetype)initWithView:(WKContentView *)view
    6767{
    68     if (!(self = [super init]))
    69         return nil;
    70 
    7168    bool hasGroups = false;
    7269    for (size_t i = 0; i < view.focusedElementInformation.selectOptions.size(); ++i) {
     
    7774    }
    7875
     76    RetainPtr<NSObject <WKFormControl>> control;
    7977    if (currentUserInterfaceIdiomIsPad())
    80         _control = adoptNS([[WKSelectPopover alloc] initWithView:view hasGroups:hasGroups]);
     78        control = adoptNS([[WKSelectPopover alloc] initWithView:view hasGroups:hasGroups]);
    8179    else if (view.focusedElementInformation.isMultiSelect || hasGroups)
    82         _control = adoptNS([[WKMultipleSelectPicker alloc] initWithView:view]);
     80        control = adoptNS([[WKMultipleSelectPicker alloc] initWithView:view]);
    8381    else
    84         _control = adoptNS([[WKSelectSinglePicker alloc] initWithView:view]);
    85        
    86     return self;
    87 }
     82        control = adoptNS([[WKSelectSinglePicker alloc] initWithView:view]);
    8883
    89 - (UIView *)assistantView
    90 {
    91     return [_control controlView];
    92 }
    93 
    94 - (void)beginEditing
    95 {
    96     [_control controlBeginEditing];
    97 }
    98 
    99 - (void)endEditing
    100 {
    101     [_control controlEndEditing];
     84    return [super initWithView:view control:WTFMove(control)];
    10285}
    10386
     
    10891- (void)selectRow:(NSInteger)rowIndex inComponent:(NSInteger)componentIndex extendingSelection:(BOOL)extendingSelection
    10992{
    110     if ([_control respondsToSelector:@selector(selectRow:inComponent:extendingSelection:)])
    111         [id<WKSelectTesting>(_control.get()) selectRow:rowIndex inComponent:componentIndex extendingSelection:extendingSelection];
     93    if ([self.control respondsToSelector:@selector(selectRow:inComponent:extendingSelection:)])
     94        [id<WKSelectTesting>(self.control) selectRow:rowIndex inComponent:componentIndex extendingSelection:extendingSelection];
    11295}
    11396
    11497- (NSString *)selectFormPopoverTitle
    11598{
    116     if (![_control isKindOfClass:[WKSelectPopover class]])
     99    if (![self.control isKindOfClass:[WKSelectPopover class]])
    117100        return nil;
    118 
    119     return [(WKSelectPopover *)_control.get() tableViewController].title;
     101    return [(WKSelectPopover *)self.control tableViewController].title;
    120102}
    121103
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFormSelectPopover.mm

    r241734 r243808  
    3737#import <UIKit/UIPickerView.h>
    3838#import <WebCore/LocalizedStrings.h>
     39#import <pal/spi/cocoa/IOKitSPI.h>
    3940#import <wtf/RetainPtr.h>
    4041
     
    447448- (void)controlEndEditing
    448449{
     450    [self dismissPopoverAnimated:NO];
    449451}
    450452
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r243798 r243808  
    15901590                CE1A0BD71A48E6C60054EF74 /* TextInputSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1A0BD11A48E6C60054EF74 /* TextInputSPI.h */; };
    15911591                CE5B4C8821B73D870022E64F /* WKSyntheticFlagsChangedWebEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = CE5B4C8621B73D870022E64F /* WKSyntheticFlagsChangedWebEvent.h */; };
     1592                CE70EE5D22442BD000E0AF0F /* WKFormPeripheralBase.h in Headers */ = {isa = PBXBuildFile; fileRef = CE70EE5C22442BD000E0AF0F /* WKFormPeripheralBase.h */; };
    15921593                CEC8F9CB1FDF5870002635E7 /* WKWebProcessPlugInNodeHandlePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = CEC8F9CA1FDF5870002635E7 /* WKWebProcessPlugInNodeHandlePrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
    15931594                CEDA12E3152CD1B300D9E08D /* WebAlternativeTextClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CEDA12DE152CCAE800D9E08D /* WebAlternativeTextClient.h */; };
     
    44714472                CE5B4C8621B73D870022E64F /* WKSyntheticFlagsChangedWebEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WKSyntheticFlagsChangedWebEvent.h; path = ios/WKSyntheticFlagsChangedWebEvent.h; sourceTree = "<group>"; };
    44724473                CE5B4C8721B73D870022E64F /* WKSyntheticFlagsChangedWebEvent.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WKSyntheticFlagsChangedWebEvent.mm; path = ios/WKSyntheticFlagsChangedWebEvent.mm; sourceTree = "<group>"; };
     4474                CE70EE5A22442BB300E0AF0F /* WKFormPeripheralBase.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WKFormPeripheralBase.mm; path = ios/forms/WKFormPeripheralBase.mm; sourceTree = "<group>"; };
     4475                CE70EE5C22442BD000E0AF0F /* WKFormPeripheralBase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WKFormPeripheralBase.h; path = ios/forms/WKFormPeripheralBase.h; sourceTree = "<group>"; };
    44734476                CEC8F9CA1FDF5870002635E7 /* WKWebProcessPlugInNodeHandlePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKWebProcessPlugInNodeHandlePrivate.h; sourceTree = "<group>"; };
    44744477                CEDA12DE152CCAE800D9E08D /* WebAlternativeTextClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebAlternativeTextClient.h; sourceTree = "<group>"; };
     
    87328735                                C54256B018BEC18B00DE4179 /* WKFormInputControl.mm */,
    87338736                                C54256B118BEC18B00DE4179 /* WKFormPeripheral.h */,
     8737                                CE70EE5C22442BD000E0AF0F /* WKFormPeripheralBase.h */,
     8738                                CE70EE5A22442BB300E0AF0F /* WKFormPeripheralBase.mm */,
    87348739                                C54256B218BEC18B00DE4179 /* WKFormPopover.h */,
    87358740                                C54256B318BEC18B00DE4179 /* WKFormPopover.mm */,
     
    98569861                                C54256B518BEC18C00DE4179 /* WKFormInputControl.h in Headers */,
    98579862                                C54256B718BEC18C00DE4179 /* WKFormPeripheral.h in Headers */,
     9863                                CE70EE5D22442BD000E0AF0F /* WKFormPeripheralBase.h in Headers */,
    98589864                                C54256B818BEC18C00DE4179 /* WKFormPopover.h in Headers */,
    98599865                                C54256BA18BEC18C00DE4179 /* WKFormSelectControl.h in Headers */,
Note: See TracChangeset for help on using the changeset viewer.