Changeset 227984 in webkit


Ignore:
Timestamp:
Feb 1, 2018 3:17:22 PM (6 years ago)
Author:
Wenson Hsieh
Message:

[Extra zoom mode] Implement basic support for interacting with text form controls
https://bugs.webkit.org/show_bug.cgi?id=182401
<rdar://problem/35143035>

Reviewed by Tim Horton.

Add UI support for interacting with and editing text form controls when extra zoom mode is enabled. See below
for more details.

  • UIProcess/API/Cocoa/WKWebViewConfiguration.mm:

(-[WKWebViewConfiguration init]):
(-[WKWebViewConfiguration encodeWithCoder:]):
(-[WKWebViewConfiguration initWithCoder:]):
(-[WKWebViewConfiguration copyWithZone:]):
(-[WKWebViewConfiguration _textInteractionGesturesEnabled]):
(-[WKWebViewConfiguration _setTextInteractionGesturesEnabled:]):
(-[WKWebViewConfiguration _longPressActionsEnabled]):
(-[WKWebViewConfiguration _setLongPressActionsEnabled:]):

Introduce two new web view configuration flags: textInteractionGesturesEnabled and longPressActionsEnabled.
The former determines whether text interaction gestures (i.e. text selection, moving the caret, showing UI for
IME, etc.) are enabled. The latter determines whether or not long press actions (i.e. touch callout, share
sheet, etc.) are enabled. These are disabled by default only in extra zoom mode.

  • UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::setTextAsync):

Add a way to set the text value of a currently edited text form control. This will either set the text value of
an input, a. la. autofill, or overwrite the contents of a contenteditable area by selecting everything and
inserting the given text.

  • UIProcess/WebPageProxy.h:

(WebKit::WebPageProxy::focusNextAssistedNode):

Add a default argument for the completion callback.

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

(-[WKContentView setupInteraction]):
(-[WKContentView _displayFormNodeInputView]):
(-[WKContentView _actionForLongPressFromPositionInformation:]):
(-[WKContentView hasSelectablePositionAtPoint:]):
(-[WKContentView pointIsNearMarkedText:]):
(-[WKContentView textInteractionGesture:shouldBeginAtPoint:]):
(-[WKContentView insertionPointColor]):

Respect the web view configuration flags above by bailing early from text interaction and long press action
sheet methods.

(-[WKContentView _startAssistingKeyboard]):
(-[WKContentView _startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):

Add a flag indicating whether we are in the process of changing focus from one node to another. We use this to
decide whether or not we want to present the text input view controller right away, or just reload the focused
form control overlay. When we stop "assisting" a node, we also keep the focused form control overlay up if we're
only changing focus to another form control.

(-[WKContentView _stopAssistingNode]):
(-[WKContentView presentFocusedFormControlViewController:]):
(-[WKContentView dismissFocusedFormControlViewController:]):
(-[WKContentView shouldPresentTextInputViewController:]):
(-[WKContentView presentTextInputViewController:]):
(-[WKContentView dismissTextInputViewController:]):

Introduce helpers for managing presentation of the focused form control overlay and text input view controller.
All -present and -dismiss helpers here are idempotent. These view controllers are presented from the content
view's view controller for fullscreen presentation.

(-[WKContentView textInputController:didCommitText:]):
(-[WKContentView textInputController:didRequestDismissalWithAction:]):
(-[WKContentView focusedFormControlControllerDidSubmit:]):
(-[WKContentView focusedFormControlControllerDidCancel:]):
(-[WKContentView focusedFormControlControllerDidBeginEditing:]):
(-[WKContentView highlightedRectForFocusedFormControlController:inCoordinateSpace:]):
(-[WKContentView actionNameForFocusedFormControlController:]):
(-[WKContentView focusedFormControlControllerDidRequestNextNode:]):
(-[WKContentView focusedFormControlControllerDidRequestPreviousNode:]):
(-[WKContentView hasNextNodeForFocusedFormControlController:]):
(-[WKContentView hasPreviousNodeForFocusedFormControlController:]):

Implement delegate methods for the focused form control and text input view controllers. This mainly involves
straightforward plumbing of pieces of AssistedNodeInformation on the content view.

(-[WKContentView pointIsInAssistedNode:]): Deleted.

Remove a method that was still implemented only for binary compatibility with iOS 10.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::setTextAsync):

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:
Location:
trunk/Source/WebKit
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r227966 r227984  
     12018-02-01  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [Extra zoom mode] Implement basic support for interacting with text form controls
     4        https://bugs.webkit.org/show_bug.cgi?id=182401
     5        <rdar://problem/35143035>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add UI support for interacting with and editing text form controls when extra zoom mode is enabled. See below
     10        for more details.
     11
     12        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
     13        (-[WKWebViewConfiguration init]):
     14        (-[WKWebViewConfiguration encodeWithCoder:]):
     15        (-[WKWebViewConfiguration initWithCoder:]):
     16        (-[WKWebViewConfiguration copyWithZone:]):
     17        (-[WKWebViewConfiguration _textInteractionGesturesEnabled]):
     18        (-[WKWebViewConfiguration _setTextInteractionGesturesEnabled:]):
     19        (-[WKWebViewConfiguration _longPressActionsEnabled]):
     20        (-[WKWebViewConfiguration _setLongPressActionsEnabled:]):
     21
     22        Introduce two new web view configuration flags: `textInteractionGesturesEnabled` and `longPressActionsEnabled`.
     23        The former determines whether text interaction gestures (i.e. text selection, moving the caret, showing UI for
     24        IME, etc.) are enabled. The latter determines whether or not long press actions (i.e. touch callout, share
     25        sheet, etc.) are enabled. These are disabled by default only in extra zoom mode.
     26
     27        * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
     28        * UIProcess/WebPageProxy.cpp:
     29        (WebKit::WebPageProxy::setTextAsync):
     30
     31        Add a way to set the text value of a currently edited text form control. This will either set the text value of
     32        an input, a. la. autofill, or overwrite the contents of a contenteditable area by selecting everything and
     33        inserting the given text.
     34
     35        * UIProcess/WebPageProxy.h:
     36        (WebKit::WebPageProxy::focusNextAssistedNode):
     37
     38        Add a default argument for the completion callback.
     39
     40        * UIProcess/ios/WKContentViewInteraction.h:
     41        * UIProcess/ios/WKContentViewInteraction.mm:
     42        (-[WKContentView setupInteraction]):
     43        (-[WKContentView _displayFormNodeInputView]):
     44        (-[WKContentView _actionForLongPressFromPositionInformation:]):
     45        (-[WKContentView hasSelectablePositionAtPoint:]):
     46        (-[WKContentView pointIsNearMarkedText:]):
     47        (-[WKContentView textInteractionGesture:shouldBeginAtPoint:]):
     48        (-[WKContentView insertionPointColor]):
     49
     50        Respect the web view configuration flags above by bailing early from text interaction and long press action
     51        sheet methods.
     52
     53        (-[WKContentView _startAssistingKeyboard]):
     54        (-[WKContentView _startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):
     55
     56        Add a flag indicating whether we are in the process of changing focus from one node to another. We use this to
     57        decide whether or not we want to present the text input view controller right away, or just reload the focused
     58        form control overlay. When we stop "assisting" a node, we also keep the focused form control overlay up if we're
     59        only changing focus to another form control.
     60
     61        (-[WKContentView _stopAssistingNode]):
     62        (-[WKContentView presentFocusedFormControlViewController:]):
     63        (-[WKContentView dismissFocusedFormControlViewController:]):
     64        (-[WKContentView shouldPresentTextInputViewController:]):
     65        (-[WKContentView presentTextInputViewController:]):
     66        (-[WKContentView dismissTextInputViewController:]):
     67
     68        Introduce helpers for managing presentation of the focused form control overlay and text input view controller.
     69        All -present and -dismiss helpers here are idempotent. These view controllers are presented from the content
     70        view's view controller for fullscreen presentation.
     71
     72        (-[WKContentView textInputController:didCommitText:]):
     73        (-[WKContentView textInputController:didRequestDismissalWithAction:]):
     74        (-[WKContentView focusedFormControlControllerDidSubmit:]):
     75        (-[WKContentView focusedFormControlControllerDidCancel:]):
     76        (-[WKContentView focusedFormControlControllerDidBeginEditing:]):
     77        (-[WKContentView highlightedRectForFocusedFormControlController:inCoordinateSpace:]):
     78        (-[WKContentView actionNameForFocusedFormControlController:]):
     79        (-[WKContentView focusedFormControlControllerDidRequestNextNode:]):
     80        (-[WKContentView focusedFormControlControllerDidRequestPreviousNode:]):
     81        (-[WKContentView hasNextNodeForFocusedFormControlController:]):
     82        (-[WKContentView hasPreviousNodeForFocusedFormControlController:]):
     83
     84        Implement delegate methods for the focused form control and text input view controllers. This mainly involves
     85        straightforward plumbing of pieces of AssistedNodeInformation on the content view.
     86
     87        (-[WKContentView pointIsInAssistedNode:]): Deleted.
     88
     89        Remove a method that was still implemented only for binary compatibility with iOS 10.
     90
     91        * WebProcess/WebPage/WebPage.cpp:
     92        (WebKit::WebPage::setTextAsync):
     93        * WebProcess/WebPage/WebPage.h:
     94        * WebProcess/WebPage/WebPage.messages.in:
     95
    1962018-02-01  Carlos Garcia Campos  <cgarcia@igalia.com>
    297
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm

    r226353 r227984  
    131131    BOOL _allowsInlineMediaPlaybackAfterFullscreen;
    132132    _WKDragLiftDelay _dragLiftDelay;
     133    BOOL _textInteractionGesturesEnabled;
     134    BOOL _longPressActionsEnabled;
    133135#endif
    134136
     
    226228    _selectionGranularity = WKSelectionGranularityDynamic;
    227229    _dragLiftDelay = toDragLiftDelay([[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitDebugDragLiftDelay"]);
    228 #endif
     230#if ENABLE(EXTRA_ZOOM_MODE)
     231    _textInteractionGesturesEnabled = NO;
     232    _longPressActionsEnabled = NO;
     233#else
     234    _textInteractionGesturesEnabled = YES;
     235    _longPressActionsEnabled = YES;
     236#endif
     237#endif // PLATFORM(IOS)
    229238
    230239    _mediaContentTypesRequiringHardwareSupport = Settings::defaultMediaContentTypesRequiringHardwareSupport();
     
    266275    [coder encodeBool:self.ignoresViewportScaleLimits forKey:@"ignoresViewportScaleLimits"];
    267276    [coder encodeInteger:self._dragLiftDelay forKey:@"dragLiftDelay"];
     277    [coder encodeBool:self._textInteractionGesturesEnabled forKey:@"textInteractionGesturesEnabled"];
     278    [coder encodeBool:self._longPressActionsEnabled forKey:@"longPressActionsEnabled"];
    268279#else
    269280    [coder encodeInteger:self.userInterfaceDirectionPolicy forKey:@"userInterfaceDirectionPolicy"];
     
    294305    self.ignoresViewportScaleLimits = [coder decodeBoolForKey:@"ignoresViewportScaleLimits"];
    295306    self._dragLiftDelay = toDragLiftDelay([coder decodeIntegerForKey:@"dragLiftDelay"]);
     307    self._textInteractionGesturesEnabled = [coder decodeBoolForKey:@"textInteractionGesturesEnabled"];
     308    self._longPressActionsEnabled = [coder decodeBoolForKey:@"longPressActionsEnabled"];
    296309#else
    297310    auto userInterfaceDirectionPolicyCandidate = static_cast<WKUserInterfaceDirectionPolicy>([coder decodeIntegerForKey:@"userInterfaceDirectionPolicy"]);
     
    348361    configuration->_ignoresViewportScaleLimits = self->_ignoresViewportScaleLimits;
    349362    configuration->_dragLiftDelay = self->_dragLiftDelay;
     363    configuration->_textInteractionGesturesEnabled = self->_textInteractionGesturesEnabled;
     364    configuration->_longPressActionsEnabled = self->_longPressActionsEnabled;
    350365#endif
    351366#if PLATFORM(MAC)
     
    665680    _dragLiftDelay = dragLiftDelay;
    666681}
     682
     683- (BOOL)_textInteractionGesturesEnabled
     684{
     685    return _textInteractionGesturesEnabled;
     686}
     687
     688- (void)_setTextInteractionGesturesEnabled:(BOOL)enabled
     689{
     690    _textInteractionGesturesEnabled = enabled;
     691}
     692
     693- (BOOL)_longPressActionsEnabled
     694{
     695    return _longPressActionsEnabled;
     696}
     697
     698- (void)_setLongPressActionsEnabled:(BOOL)enabled
     699{
     700    _longPressActionsEnabled = enabled;
     701}
     702
     703
    667704#endif // PLATFORM(IOS)
    668705
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h

    r225765 r227984  
    7777@property (nonatomic, setter=_setAllowsInlineMediaPlaybackAfterFullscreen:) BOOL _allowsInlineMediaPlaybackAfterFullscreen  WK_API_AVAILABLE(ios(10.0));
    7878@property (nonatomic, setter=_setDragLiftDelay:) _WKDragLiftDelay _dragLiftDelay WK_API_AVAILABLE(ios(11.0));
     79@property (nonatomic, setter=_setTextInteractionGesturesEnabled:) BOOL _textInteractionGesturesEnabled WK_API_AVAILABLE(ios(WK_IOS_TBA));
     80@property (nonatomic, setter=_setLongPressActionsEnabled:) BOOL _longPressActionsEnabled WK_API_AVAILABLE(ios(WK_IOS_TBA));
    7981#else
    8082@property (nonatomic, setter=_setShowsURLsInToolTips:) BOOL _showsURLsInToolTips WK_API_AVAILABLE(macosx(10.12));
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r227927 r227984  
    65616561#if PLATFORM(COCOA)
    65626562
     6563void WebPageProxy::setTextAsync(const String& text)
     6564{
     6565    if (isValid())
     6566        process().send(Messages::WebPage::SetTextAsync(text), m_pageID);
     6567}
     6568
    65636569void WebPageProxy::insertTextAsync(const String& text, const EditingRange& replacementRange, bool registerUndoGroup, EditingRangeIsRelativeTo editingRangeIsRelativeTo, bool suppressSelectionUpdate)
    65646570{
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r227614 r227984  
    573573    void didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold);
    574574#endif
    575     void focusNextAssistedNode(bool isForward, WTF::Function<void (CallbackBase::Error)>&&);
     575    void focusNextAssistedNode(bool isForward, WTF::Function<void (CallbackBase::Error)>&& = [] (auto) { });
    576576    void setAssistedNodeValue(const String&);
    577577    void setAssistedNodeValueAsNumber(double);
     
    639639    LayerOrView* acceleratedCompositingRootLayer() const;
    640640
     641    void setTextAsync(const String&);
    641642    void insertTextAsync(const String& text, const EditingRange& replacementRange, bool registerUndoGroup = false, EditingRangeIsRelativeTo = EditingRangeIsRelativeTo::EditableRoot, bool suppressSelectionUpdate = false);
    642643    void getMarkedRangeAsync(WTF::Function<void (EditingRange, CallbackBase::Error)>&&);
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r227855 r227984  
    8484@class _UIWebHighlightLongPressGestureRecognizer;
    8585
    86 #if ENABLE(DATA_INTERACTION)
    87 @class _UITextDragCaretView;
     86#if ENABLE(EXTRA_ZOOM_MODE)
     87@class WKFocusedFormControlViewController;
     88@class WKTextInputViewController;
    8889#endif
    8990
     
    230231    BOOL _resigningFirstResponder;
    231232    BOOL _needsDeferredEndScrollingSelectionUpdate;
     233    BOOL _isChangingFocus;
    232234
    233235#if ENABLE(DATA_INTERACTION)
     
    239241    RetainPtr<UIView> _visibleContentViewSnapshot;
    240242    RetainPtr<_UITextDragCaretView> _editDropCaretView;
     243#endif
     244
     245#if ENABLE(EXTRA_ZOOM_MODE)
     246    RetainPtr<WKTextInputViewController> _textInputViewController;
     247    RetainPtr<WKFocusedFormControlViewController> _focusedFormControlViewController;
    241248#endif
    242249}
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r227855 r227984  
    4242#import "WKActionSheetAssistant.h"
    4343#import "WKError.h"
     44#import "WKFocusedFormControlViewController.h"
    4445#import "WKFormInputControl.h"
    4546#import "WKFormSelectControl.h"
     
    5051#import "WKPreviewActionItemInternal.h"
    5152#import "WKPreviewElementInfoInternal.h"
     53#import "WKTextInputViewController.h"
    5254#import "WKUIDelegatePrivate.h"
    5355#import "WKWebViewConfiguration.h"
     
    7173#import <WebCore/DataDetection.h>
    7274#import <WebCore/FloatQuad.h>
     75#import <WebCore/LocalizedStrings.h>
    7376#import <WebCore/NotImplemented.h>
    7477#import <WebCore/Pasteboard.h>
     
    116119
    117120@end
     121
     122#if ENABLE(EXTRA_ZOOM_MODE)
     123
     124@interface WKContentView (ExtraZoomMode) <WKTextFormControlViewControllerDelegate, WKFocusedFormControlViewControllerDelegate>
     125@end
     126
     127#endif
    118128
    119129using namespace WebCore;
     
    627637    _showDebugTapHighlightsForFastClicking = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitShowFastClickDebugTapHighlights"];
    628638    _needsDeferredEndScrollingSelectionUpdate = NO;
     639    _isChangingFocus = NO;
    629640}
    630641
     
    12061217    // Zooming above the page's default scale factor should only happen when the user performs it.
    12071218    [self _zoomToFocusRect:_assistedNodeInformation.elementRect
    1208              selectionRect:_didAccessoryTabInitiateFocus ? IntRect() : _assistedNodeInformation.selectionRect
    1209                insideFixed:_assistedNodeInformation.insideFixedPosition
    1210                   fontSize:_assistedNodeInformation.nodeFontSize
    1211               minimumScale:_assistedNodeInformation.minimumScaleFactor
    1212               maximumScale:_assistedNodeInformation.maximumScaleFactorIgnoringAlwaysScalable
    1213               allowScaling:(_assistedNodeInformation.allowsUserScalingIgnoringAlwaysScalable && !currentUserInterfaceIdiomIsPad())
    1214                forceScroll:[self requiresAccessoryView]];
     1219        selectionRect:_didAccessoryTabInitiateFocus ? IntRect() : _assistedNodeInformation.selectionRect
     1220        insideFixed:_assistedNodeInformation.insideFixedPosition
     1221        fontSize:_assistedNodeInformation.nodeFontSize
     1222        minimumScale:_assistedNodeInformation.minimumScaleFactor
     1223        maximumScale:_assistedNodeInformation.maximumScaleFactorIgnoringAlwaysScalable
     1224        allowScaling:_assistedNodeInformation.allowsUserScalingIgnoringAlwaysScalable && [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone
     1225        forceScroll:[self requiresAccessoryView]];
    12151226
    12161227    _didAccessoryTabInitiateFocus = NO;
     
    13241335- (SEL)_actionForLongPressFromPositionInformation:(const InteractionInformationAtPosition&)positionInformation
    13251336{
     1337    if (!_webView.configuration._longPressActionsEnabled)
     1338        return nil;
     1339
    13261340    if (!positionInformation.touchCalloutEnabled)
    13271341        return nil;
     
    15501564- (BOOL)hasSelectablePositionAtPoint:(CGPoint)point
    15511565{
     1566    if (!_webView.configuration._textInteractionGesturesEnabled)
     1567        return NO;
     1568
    15521569    if (_inspectorNodeSearchEnabled)
    15531570        return NO;
     
    15701587- (BOOL)pointIsNearMarkedText:(CGPoint)point
    15711588{
     1589    if (!_webView.configuration._textInteractionGesturesEnabled)
     1590        return NO;
     1591
    15721592    InteractionInformationRequest request(roundedIntPoint(point));
    15731593    if (![self ensurePositionInformationIsUpToDate:request])
     
    15751595    return _positionInformation.isNearMarkedText;
    15761596}
    1577 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 110000
    1578 - (BOOL)pointIsInAssistedNode:(CGPoint)point
    1579 {
    1580     // This method is still implemented for backwards compatibility with older UIKit versions.
    1581     return [self textInteractionGesture:UIWKGestureLoupe shouldBeginAtPoint:point];
    1582 }
    1583 #endif
    15841597
    15851598- (BOOL)textInteractionGesture:(UIWKGestureType)gesture shouldBeginAtPoint:(CGPoint)point
    15861599{
     1600    if (!_webView.configuration._textInteractionGesturesEnabled)
     1601        return NO;
     1602
    15871603    InteractionInformationRequest request(roundedIntPoint(point));
    15881604    if (![self ensurePositionInformationIsUpToDate:request])
     
    21042120- (UIColor *)insertionPointColor
    21052121{
     2122    if (!_webView.configuration._textInteractionGesturesEnabled)
     2123        return [UIColor clearColor];
     2124
    21062125    if (!_page->editorState().isMissingPostLayoutData) {
    21072126        WebCore::Color caretColor = _page->editorState().postLayoutData().caretColor;
     
    39043923{
    39053924    [self useSelectionAssistantWithGranularity:WKSelectionGranularityCharacter];
     3925
     3926#if ENABLE(EXTRA_ZOOM_MODE)
     3927    if (!_isChangingFocus && [self shouldPresentTextInputViewController:_assistedNodeInformation])
     3928        [self presentTextInputViewController:YES];
     3929#else
    39063930    [self reloadInputViews];
     3931#endif
    39073932}
    39083933
     
    39603985- (void)_startAssistingNode:(const AssistedNodeInformation&)information userIsInteracting:(BOOL)userIsInteracting blurPreviousNode:(BOOL)blurPreviousNode changingActivityState:(BOOL)changingActivityState userObject:(NSObject <NSSecureCoding> *)userObject
    39613986{
     3987    SetForScope<BOOL> isChangingFocusForScope { _isChangingFocus, _assistedNodeInformation.elementType != InputType::None };
    39623988    _inputViewUpdateDeferrer = nullptr;
    39633989
     
    39934019    _inputPeripheral = nil;
    39944020    _traits = nil;
     4021
     4022#if ENABLE(EXTRA_ZOOM_MODE)
     4023    [self presentFocusedFormControlViewController:NO];
     4024#endif
     4025
    39954026    if (![self isFirstResponder])
    39964027        [self becomeFirstResponder];
     
    40164047    [self _displayFormNodeInputView];
    40174048
     4049#if ENABLE(EXTRA_ZOOM_MODE)
     4050    if (_isChangingFocus)
     4051        [_focusedFormControlViewController reloadData:YES];
     4052#endif
     4053
    40184054    // _inputPeripheral has been initialized in inputView called by reloadInputViews.
    40194055    [_inputPeripheral beginEditing];
     
    40444080    [_webSelectionAssistant resignedFirstResponder];
    40454081
     4082#if ENABLE(EXTRA_ZOOM_MODE)
     4083    [self dismissTextInputViewController:YES];
     4084    if (!_isChangingFocus)
     4085        [self dismissFocusedFormControlViewController:[_focusedFormControlViewController isVisible]];
     4086#endif
     4087
    40464088    // The custom fixed position rect behavior is affected by -isAssistingNode, so if that changes we need to recompute rects.
    40474089    if (editableChanged)
     
    40504092    [_webView didEndFormControlInteraction];
    40514093}
     4094
     4095#if ENABLE(EXTRA_ZOOM_MODE)
     4096
     4097- (void)presentFocusedFormControlViewController:(BOOL)animated
     4098{
     4099    if (_focusedFormControlViewController)
     4100        return;
     4101
     4102    _focusedFormControlViewController = adoptNS([[WKFocusedFormControlViewController alloc] init]);
     4103    [_focusedFormControlViewController setDelegate:self];
     4104    [[UIViewController _viewControllerForFullScreenPresentationFromView:self] presentViewController:_focusedFormControlViewController.get() animated:animated completion:nil];
     4105}
     4106
     4107- (void)dismissFocusedFormControlViewController:(BOOL)animated
     4108{
     4109    if (!_focusedFormControlViewController)
     4110        return;
     4111
     4112    [_focusedFormControlViewController dismissViewControllerAnimated:animated completion:nil];
     4113    _focusedFormControlViewController = nil;
     4114}
     4115
     4116- (BOOL)shouldPresentTextInputViewController:(const AssistedNodeInformation&)info
     4117{
     4118    switch (info.elementType) {
     4119    case InputType::ContentEditable:
     4120    case InputType::Text:
     4121    case InputType::Password:
     4122    case InputType::TextArea:
     4123    case InputType::Search:
     4124    case InputType::Email:
     4125    case InputType::URL:
     4126        return true;
     4127    default:
     4128        return false;
     4129    }
     4130}
     4131
     4132- (void)presentTextInputViewController:(BOOL)animated
     4133{
     4134    if (_textInputViewController)
     4135        return;
     4136
     4137    _textInputViewController = adoptNS([[WKTextInputViewController alloc] initWithText:_assistedNodeInformation.value textSuggestions:@[ ]]);
     4138    [_textInputViewController setDelegate:self];
     4139    [_focusedFormControlViewController presentViewController:_textInputViewController.get() animated:animated completion:nil];
     4140}
     4141
     4142- (void)dismissTextInputViewController:(BOOL)animated
     4143{
     4144    if (!_textInputViewController)
     4145        return;
     4146
     4147    auto textInputViewController = WTFMove(_textInputViewController);
     4148    [textInputViewController dismissViewControllerAnimated:animated completion:nil];
     4149}
     4150
     4151- (void)textInputController:(WKTextFormControlViewController *)controller didCommitText:(NSString *)text
     4152{
     4153    // FIXME: Update cached AssistedNodeInformation state in the UI process.
     4154    _page->setTextAsync(text);
     4155}
     4156
     4157- (void)textInputController:(WKTextFormControlViewController *)controller didRequestDismissalWithAction:(WKFormControlAction)action
     4158{
     4159    if (action == WKFormControlActionCancel) {
     4160        _page->blurAssistedNode();
     4161        return;
     4162    }
     4163
     4164    if (_assistedNodeInformation.formAction.isEmpty() && !_assistedNodeInformation.hasNextNode && !_assistedNodeInformation.hasPreviousNode) {
     4165        // In this case, there's no point in collapsing down to the form control focus UI because there's nothing the user could potentially do
     4166        // besides dismiss the UI, so we just automatically dismiss the focused form control UI.
     4167        _page->blurAssistedNode();
     4168        return;
     4169    }
     4170
     4171    [_focusedFormControlViewController show:NO];
     4172    [self dismissTextInputViewController:YES];
     4173}
     4174
     4175- (void)focusedFormControlControllerDidSubmit:(WKFocusedFormControlViewController *)controller
     4176{
     4177    [self insertText:@"\n"];
     4178    _page->blurAssistedNode();
     4179}
     4180
     4181- (void)focusedFormControlControllerDidCancel:(WKFocusedFormControlViewController *)controller
     4182{
     4183    _page->blurAssistedNode();
     4184}
     4185
     4186- (void)focusedFormControlControllerDidBeginEditing:(WKFocusedFormControlViewController *)controller
     4187{
     4188    if ([self shouldPresentTextInputViewController:_assistedNodeInformation])
     4189        [self presentTextInputViewController:YES];
     4190}
     4191
     4192- (CGRect)highlightedRectForFocusedFormControlController:(WKFocusedFormControlViewController *)controller inCoordinateSpace:(id <UICoordinateSpace>)coordinateSpace
     4193{
     4194    return [self convertRect:_assistedNodeInformation.elementRect toCoordinateSpace:coordinateSpace];
     4195}
     4196
     4197- (NSString *)actionNameForFocusedFormControlController:(WKFocusedFormControlViewController *)controller
     4198{
     4199    if (_assistedNodeInformation.formAction.isEmpty())
     4200        return nil;
     4201
     4202    return _assistedNodeInformation.elementType == InputType::Search ? formControlSearchButtonTitle() : formControlGoButtonTitle();
     4203}
     4204
     4205- (void)focusedFormControlControllerDidRequestNextNode:(WKFocusedFormControlViewController *)controller
     4206{
     4207    if (_assistedNodeInformation.hasNextNode)
     4208        _page->focusNextAssistedNode(true);
     4209}
     4210
     4211- (void)focusedFormControlControllerDidRequestPreviousNode:(WKFocusedFormControlViewController *)controller
     4212{
     4213    if (_assistedNodeInformation.hasPreviousNode)
     4214        _page->focusNextAssistedNode(false);
     4215}
     4216
     4217- (BOOL)hasNextNodeForFocusedFormControlController:(WKFocusedFormControlViewController *)controller
     4218{
     4219    return _assistedNodeInformation.hasNextNode;
     4220}
     4221
     4222- (BOOL)hasPreviousNodeForFocusedFormControlController:(WKFocusedFormControlViewController *)controller
     4223{
     4224    return _assistedNodeInformation.hasPreviousNode;
     4225}
     4226
     4227#endif // ENABLE(EXTRA_ZOOM_MODE)
    40524228
    40534229- (void)_selectionChanged
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r227759 r227984  
    45914591#if PLATFORM(COCOA)
    45924592
     4593void WebPage::setTextAsync(const String& text)
     4594{
     4595    if (is<HTMLInputElement>(m_assistedNode.get())) {
     4596        downcast<HTMLInputElement>(*m_assistedNode).setValueForUser(text);
     4597        return;
     4598    }
     4599
     4600    auto frame = makeRef(m_page->focusController().focusedOrMainFrame());
     4601    if (!frame->selection().selection().isContentEditable())
     4602        return;
     4603
     4604    frame->selection().selectAll();
     4605    frame->editor().insertText(text, nullptr, TextEventInputKeyboard);
     4606}
     4607
    45934608void WebPage::insertTextAsync(const String& text, const EditingRange& replacementEditingRange, bool registerUndoGroup, uint32_t editingRangeIsRelativeTo, bool suppressSelectionUpdate)
    45944609{
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r227759 r227984  
    709709    void sendComplexTextInputToPlugin(uint64_t pluginComplexTextInputIdentifier, const String& textInput);
    710710
     711    void setTextAsync(const String&);
    711712    void insertTextAsync(const String& text, const EditingRange& replacementRange, bool registerUndoGroup = false, uint32_t editingRangeIsRelativeTo = (uint32_t)EditingRangeIsRelativeTo::EditableRoot, bool suppressSelectionUpdate = false);
    712713    void getMarkedRangeAsync(CallbackID);
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r227377 r227984  
    391391    AcceptsFirstMouse(int eventNumber, WebKit::WebMouseEvent event) -> (bool result)
    392392
     393    SetTextAsync(String text)
    393394    InsertTextAsync(String text, struct WebKit::EditingRange replacementRange, bool registerUndoGroup, uint32_t editingRangeIsRelativeTo, bool suppressSelectionUpdate)
    394395    GetMarkedRangeAsync(WebKit::CallbackID callbackID)
Note: See TracChangeset for help on using the changeset viewer.