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

Changeset 264352 in webkit


Ignore:
Timestamp:
Jul 14, 2020, 10:55:57 AM (6 years ago)
Author:
dbates@webkit.org
Message:

[iOS] Sometimes unable to type Japanese on docs.google.com
​https://bugs.webkit.org/show_bug.cgi?id=214272
<rdar://problem/59449972>

Reviewed by Wenson Hsieh.

Tell the web process to restore the selection of the focused element when re-focusing it
on page activation.

When resigning first responder the text interaction assistant is deactivated and calls
back into WKContentView's -clearSelection, which clears the focused element and tells
the web process to clear the selection. Keep in mind that the focused element in the web
process is not changed. When the WKContentView subsequently becomes first responder the
web process messages the UI process to tell it to start assistance (aka focus) for focused
element. However the selection is not restored and thus the editor state the UI process
has, and is even sent up until there is a selection change, mismatches with the focused
element information it also has. To match Mac, key events are only passed to the input
manager if an editable element is focused (see <​https://bugs.webkit.org/show_bug.cgi?id=199122>).
So, key events are not passed to the input manager when in this state. To prevent this,
restore the selection of the focused element when the element is re-focused because the
page became active again.

Selection restoration is driven by the UI process (not the web process) because element re-
focusing may be denied by the embedding client. In this case, selection should not be restored
because UI assistance was not started. For the same reason, I do not restore it in -becomeFirstResponderForWebView.

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

(-[WKContentView cleanUpInteraction]):
(-[WKContentView _didCommitLoadForMainFrame]):
Clear out the flag. See below for more details.

(-[WKContentView handleKeyWebEvent:withCompletionHandler:]): Pass the key to the input manager
if the _treatAsContentEditableUntilNextEditorStateUpdate is YES.
(-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]):
If this request is a result of the page activating (aka focus activity change) into an editable field
(i.e. mayContainSelectableText() resturns YES) and assistance is not being suppressed then tell the web
process to restore the selection. As part of this I tell the text interaction assistant to activate even
though -becomeFirstResponderForWebView was called beforehand because -becomeFirstResponderForWebView only
activates it if there is a non-empty selection. (Note the page having an empty selection could have been
a result of -clearSelection having been called though the page could have done it programmatically as well).
I also set a new flag to YES and schedule a full editor state update to ensure this flag is cleared.
The flag is so that key events that come in between now and the next editor state update are passed to the
input manager.
(-[WKContentView _didUpdateEditorState]): Clear out the flag. See above for more details.

Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r264333 r264352  
     12020-07-14  Daniel Bates  <dabates@apple.com>
     2
     3        [iOS] Sometimes unable to type Japanese on docs.google.com
     4        https://bugs.webkit.org/show_bug.cgi?id=214272
     5        <rdar://problem/59449972>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Tell the web process to restore the selection of the focused element when re-focusing it
     10        on page activation.
     11
     12        When resigning first responder the text interaction assistant is deactivated and calls
     13        back into WKContentView's -clearSelection, which clears the focused element and tells
     14        the web process to clear the selection. Keep in mind that the focused element in the web
     15        process is not changed. When the WKContentView subsequently becomes first responder the
     16        web process messages the UI process to tell it to start assistance (aka focus) for focused
     17        element. However the selection is not restored and thus the editor state the UI process
     18        has, and is even sent up until there is a selection change, mismatches with the focused
     19        element information it also has. To match Mac, key events are only passed to the input
     20        manager if an editable element is focused (see <https://bugs.webkit.org/show_bug.cgi?id=199122>).
     21        So, key events are not passed to the input manager when in this state. To prevent this,
     22        restore the selection of the focused element when the element is re-focused because the
     23        page became active again.
     24
     25        Selection restoration is driven by the UI process (not the web process) because element re-
     26        focusing may be denied by the embedding client. In this case, selection should not be restored
     27        because UI assistance was not started. For the same reason, I do not restore it in -becomeFirstResponderForWebView.
     28
     29        * UIProcess/ios/WKContentViewInteraction.h:
     30        * UIProcess/ios/WKContentViewInteraction.mm:
     31        (-[WKContentView cleanUpInteraction]):
     32        (-[WKContentView _didCommitLoadForMainFrame]):
     33        Clear out the flag. See below for more details.
     34
     35        (-[WKContentView handleKeyWebEvent:withCompletionHandler:]): Pass the key to the input manager
     36        if the _treatAsContentEditableUntilNextEditorStateUpdate is YES.
     37        (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]):
     38        If this request is a result of the page activating (aka focus activity change) into an editable field
     39        (i.e. mayContainSelectableText() resturns YES) and assistance is not being suppressed then tell the web
     40        process to restore the selection. As part of this I tell the text interaction assistant to activate even
     41        though -becomeFirstResponderForWebView was called beforehand because -becomeFirstResponderForWebView only
     42        activates it if there is a non-empty selection. (Note the page having an empty selection could have been
     43        a result of -clearSelection having been called though the page could have done it programmatically as well).
     44        I also set a new flag to YES and schedule a full editor state update to ensure this flag is cleared.
     45        The flag is so that key events that come in between now and the next editor state update are passed to the
     46        input manager.
     47        (-[WKContentView _didUpdateEditorState]): Clear out the flag. See above for more details.
     48
    1492020-07-14  Fujii Hironori  <Hironori.Fujii@sony.com>
    250
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r264187 r264352  
    361361    BOOL _textInteractionDidChangeFocusedElement;
    362362    BOOL _textInteractionIsHappening;
     363    BOOL _treatAsContentEditableUntilNextEditorStateUpdate;
    363364    bool _isWaitingOnPositionInformation;
    364365
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r264205 r264352  
    936936    _textInteractionIsHappening = NO;
    937937
     938    _treatAsContentEditableUntilNextEditorStateUpdate = NO;
     939
    938940    if (_interactionViewsContainerView) {
    939941        [self.layer removeObserver:self forKeyPath:@"transform"];
    … …  
    43024304    _textInteractionDidChangeFocusedElement = NO;
    43034305    _textInteractionIsHappening = NO;
     4306    _treatAsContentEditableUntilNextEditorStateUpdate = NO;
    43044307    _hasValidPositionInformation = NO;
    43054308    _positionInformation = { };
    … …  
    53385341#if USE(UIKIT_KEYBOARD_ADDITIONS)
    53395342    auto* keyboard = [UIKeyboardImpl sharedInstance];
    5340     if (_page->editorState().isContentEditable && [keyboard respondsToSelector:@selector(handleKeyInputMethodCommandForCurrentEvent)] && [keyboard handleKeyInputMethodCommandForCurrentEvent]) {
     5343    if ((_page->editorState().isContentEditable || _treatAsContentEditableUntilNextEditorStateUpdate) && [keyboard respondsToSelector:@selector(handleKeyInputMethodCommandForCurrentEvent)] && [keyboard handleKeyInputMethodCommandForCurrentEvent]) {
    53415344        completionHandler(theEvent, YES);
    53425345        _page->handleKeyboardEvent(WebKit::NativeWebKeyboardEvent(theEvent, HandledByInputMethod::Yes));
    … …  
    59795982        [self becomeFirstResponder];
    59805983
     5984    if (!_suppressSelectionAssistantReasons && isSelectable && activityStateChanges.contains(WebCore::ActivityState::IsFocused)) {
     5985        _treatAsContentEditableUntilNextEditorStateUpdate = YES;
     5986        [_textInteractionAssistant activateSelection];
     5987        _page->restoreSelectionInFocusedEditableElement();
     5988        _page->scheduleFullEditorStateUpdate();
     5989    }
     5990
    59815991    _inputPeripheral = createInputPeripheralWithView(_focusedElementInformation.elementType, self);
    59825992
    … …  
    61856195    if (mayContainSelectableText(_focusedElementInformation.elementType))
    61866196        [self _zoomToRevealFocusedElement];
     6197
     6198    _treatAsContentEditableUntilNextEditorStateUpdate = NO;
    61876199}
    61886200
Note: See TracChangeset for help on using the changeset viewer.