Changeset 251693 in webkit


Ignore:
Timestamp:
Oct 28, 2019 7:34:20 PM (4 years ago)
Author:
Wenson Hsieh
Message:

Replace InteractionInformationAtPosition.nodeAtPositionIsFocusedElement with an element context
https://bugs.webkit.org/show_bug.cgi?id=203498

Reviewed by Tim Horton.

Refactors InteractionInformationAtPosition, such that it doesn't need a special flag to indicate whether there
is a focused element at the position. This is a followup to webkit.org/b/203264; no new tests, as there should
be no change in behavior.

  • Shared/FocusedElementInformation.cpp:

(WebKit::FocusedElementInformation::encode const):
(WebKit::FocusedElementInformation::decode):

  • Shared/FocusedElementInformation.h:

Add an elementContext to FocusedElementInformation to represent the focused element; then, instead of checking
whether there is a focused element underneath the request position, simply check that the position information's
element context matches the FocusedElementInformation's element context.

Additionally, rename elementRect in FocusedElementInformation to interactionRect, to draw a distinction between
this rect and the new ElementContext's boundingRect.

  • Shared/ios/InteractionInformationAtPosition.h:
  • Shared/ios/InteractionInformationAtPosition.mm:

(WebKit::InteractionInformationAtPosition::encode const):
(WebKit::InteractionInformationAtPosition::decode):

Remove the nodeAtPositionIsFocusedElement flag.

  • UIProcess/ios/WKContentViewInteraction.mm:

(-[WKContentView _didGetTapHighlightForRequest:color:quads:topLeftRadius:topRightRadius:bottomLeftRadius:bottomRightRadius:nodeHasBuiltInClickHandling:]):
(-[WKContentView _zoomToRevealFocusedElement]):
(-[WKContentView _selectionClipRect]):
(-[WKContentView gestureRecognizerShouldBegin:]):
(-[WKContentView textInteractionGesture:shouldBeginAtPoint:]):

In various places that consult nodeAtPositionIsFocusedElement, instead check that the position information's
hit-tested element context is the same as the focused element, via FocusedElementInformation.

(-[WKContentView _didCommitLoadForMainFrame]):

Nuke the cached position information data upon navigation; without this tweak, we will fail when running several
iOS layout tests back-to-back, that tap in exactly the same location.

(rectToRevealWhenZoomingToFocusedElement):
(-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]):
(-[WKContentView _elementDidBlur]):
(-[WKContentView rectForFocusedFormControlView:]):
(-[WKContentView _didChangeFocusedElementRect:toRect:]): Deleted.

Remove code to invalidate cached position information when changing the focused element rect.

  • UIProcess/ios/forms/WKFormPopover.mm:

(-[WKRotatingPopover presentPopoverAnimated:]):

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::positionInformation):
(WebKit::WebPage::getFocusedElementInformation):

Location:
trunk/Source/WebKit
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r251690 r251693  
     12019-10-28  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Replace InteractionInformationAtPosition.nodeAtPositionIsFocusedElement with an element context
     4        https://bugs.webkit.org/show_bug.cgi?id=203498
     5
     6        Reviewed by Tim Horton.
     7
     8        Refactors InteractionInformationAtPosition, such that it doesn't need a special flag to indicate whether there
     9        is a focused element at the position. This is a followup to webkit.org/b/203264; no new tests, as there should
     10        be no change in behavior.
     11
     12        * Shared/FocusedElementInformation.cpp:
     13        (WebKit::FocusedElementInformation::encode const):
     14        (WebKit::FocusedElementInformation::decode):
     15        * Shared/FocusedElementInformation.h:
     16
     17        Add an elementContext to FocusedElementInformation to represent the focused element; then, instead of checking
     18        whether there is a focused element underneath the request position, simply check that the position information's
     19        element context matches the FocusedElementInformation's element context.
     20
     21        Additionally, rename elementRect in FocusedElementInformation to interactionRect, to draw a distinction between
     22        this rect and the new ElementContext's boundingRect.
     23
     24        * Shared/ios/InteractionInformationAtPosition.h:
     25        * Shared/ios/InteractionInformationAtPosition.mm:
     26        (WebKit::InteractionInformationAtPosition::encode const):
     27        (WebKit::InteractionInformationAtPosition::decode):
     28
     29        Remove the nodeAtPositionIsFocusedElement flag.
     30
     31        * UIProcess/ios/WKContentViewInteraction.mm:
     32        (-[WKContentView _didGetTapHighlightForRequest:color:quads:topLeftRadius:topRightRadius:bottomLeftRadius:bottomRightRadius:nodeHasBuiltInClickHandling:]):
     33        (-[WKContentView _zoomToRevealFocusedElement]):
     34        (-[WKContentView _selectionClipRect]):
     35        (-[WKContentView gestureRecognizerShouldBegin:]):
     36        (-[WKContentView textInteractionGesture:shouldBeginAtPoint:]):
     37
     38        In various places that consult nodeAtPositionIsFocusedElement, instead check that the position information's
     39        hit-tested element context is the same as the focused element, via FocusedElementInformation.
     40
     41        (-[WKContentView _didCommitLoadForMainFrame]):
     42
     43        Nuke the cached position information data upon navigation; without this tweak, we will fail when running several
     44        iOS layout tests back-to-back, that tap in exactly the same location.
     45
     46        (rectToRevealWhenZoomingToFocusedElement):
     47        (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]):
     48        (-[WKContentView _elementDidBlur]):
     49        (-[WKContentView rectForFocusedFormControlView:]):
     50        (-[WKContentView _didChangeFocusedElementRect:toRect:]): Deleted.
     51
     52        Remove code to invalidate cached position information when changing the focused element rect.
     53
     54        * UIProcess/ios/forms/WKFormPopover.mm:
     55        (-[WKRotatingPopover presentPopoverAnimated:]):
     56        * WebProcess/WebPage/ios/WebPageIOS.mm:
     57        (WebKit::WebPage::positionInformation):
     58        (WebKit::WebPage::getFocusedElementInformation):
     59
    1602019-10-28  Adrian Perez de Castro  <aperez@igalia.com>
    261
  • trunk/Source/WebKit/Shared/FocusedElementInformation.cpp

    r250345 r251693  
    6464void FocusedElementInformation::encode(IPC::Encoder& encoder) const
    6565{
    66     encoder << elementRect;
     66    encoder << interactionRect;
     67    encoder << elementContext;
    6768    encoder << lastInteractionLocation;
    6869    encoder << minimumScaleFactor;
     
    114115bool FocusedElementInformation::decode(IPC::Decoder& decoder, FocusedElementInformation& result)
    115116{
    116     if (!decoder.decode(result.elementRect))
     117    if (!decoder.decode(result.interactionRect))
     118        return false;
     119
     120    if (!decoder.decode(result.elementContext))
    117121        return false;
    118122
  • trunk/Source/WebKit/Shared/FocusedElementInformation.h

    r250345 r251693  
    3030#include <WebCore/Autofill.h>
    3131#include <WebCore/Color.h>
     32#include <WebCore/ElementContext.h>
    3233#include <WebCore/GraphicsLayer.h>
    3334#include <WebCore/InputMode.h>
     
    9798
    9899struct FocusedElementInformation {
    99     WebCore::IntRect elementRect;
     100    WebCore::IntRect interactionRect;
     101    WebCore::ElementContext elementContext;
    100102    WebCore::IntPoint lastInteractionLocation;
    101103    double minimumScaleFactor { -INFINITY };
  • trunk/Source/WebKit/Shared/ios/InteractionInformationAtPosition.h

    r251388 r251693  
    5252
    5353    bool canBeValid { true };
    54     bool nodeAtPositionIsFocusedElement { false };
    5554    bool nodeAtPositionHasDoubleClickHandler { false };
    5655#if ENABLE(DATA_INTERACTION)
  • trunk/Source/WebKit/Shared/ios/InteractionInformationAtPosition.mm

    r250876 r251693  
    4545
    4646    encoder << canBeValid;
    47     encoder << nodeAtPositionIsFocusedElement;
    4847    encoder << nodeAtPositionHasDoubleClickHandler;
    4948#if ENABLE(DATA_INTERACTION)
     
    9796        return false;
    9897
    99     if (!decoder.decode(result.nodeAtPositionIsFocusedElement))
    100         return false;
    101 
    10298    if (!decoder.decode(result.nodeAtPositionHasDoubleClickHandler))
    10399        return false;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r251665 r251693  
    16971697        return;
    16981698
    1699     if (hasFocusedElement(_focusedElementInformation) && _positionInformation.nodeAtPositionIsFocusedElement)
     1699    if (hasFocusedElement(_focusedElementInformation) && _positionInformation.elementContext == _focusedElementInformation.elementContext)
    17001700        return;
    17011701
     
    18721872    // In case user scaling is force enabled, do not use that scaling when zooming in with an input field.
    18731873    // Zooming above the page's default scale factor should only happen when the user performs it.
    1874     [self _zoomToFocusRect:_focusedElementInformation.elementRect
     1874    [self _zoomToFocusRect:_focusedElementInformation.interactionRect
    18751875        selectionRect:_didAccessoryTabInitiateFocus ? WebCore::FloatRect() : rectToRevealWhenZoomingToFocusedElement(_focusedElementInformation, _page->editorState())
    18761876        insideFixed:_focusedElementInformation.insideFixedPosition
     
    19231923
    19241924    if (_page->waitingForPostLayoutEditorStateUpdateAfterFocusingElement())
    1925         return _focusedElementInformation.elementRect;
     1925        return _focusedElementInformation.interactionRect;
    19261926
    19271927    return _page->editorState().postLayoutData().focusedElementRect;
     
    22692269            if (![self ensurePositionInformationIsUpToDate:WebKit::InteractionInformationRequest(WebCore::roundedIntPoint(point))])
    22702270                return NO;
    2271             if (_positionInformation.nodeAtPositionIsFocusedElement)
     2271            if (_positionInformation.elementContext == _focusedElementInformation.elementContext)
    22722272                return NO;
    22732273        }
     
    23152315        if (hasFocusedElement(_focusedElementInformation)) {
    23162316            // Prevent the gesture if it is the same node.
    2317             if (_positionInformation.nodeAtPositionIsFocusedElement)
     2317            if (_positionInformation.elementContext == _focusedElementInformation.elementContext)
    23182318                return NO;
    23192319        } else {
     
    24502450    // If we're currently focusing an editable element, only allow the selection to move within that focused element.
    24512451    if (self.isFocusingElement)
    2452         return _positionInformation.nodeAtPositionIsFocusedElement;
     2452        return _positionInformation.elementContext == _focusedElementInformation.elementContext;
    24532453
    24542454    // If we're selecting something, don't activate highlight.
     
    41514151    [self _hideContextMenuHintContainer];
    41524152    [_webView _didCommitLoadForMainFrame];
     4153
     4154    _hasValidPositionInformation = NO;
     4155    _positionInformation = { };
    41534156}
    41544157
     
    54025405{
    54035406    WebCore::IntRect elementInteractionRect;
    5404     if (elementInfo.elementRect.contains(elementInfo.lastInteractionLocation))
     5407    if (elementInfo.interactionRect.contains(elementInfo.lastInteractionLocation))
    54055408        elementInteractionRect = { elementInfo.lastInteractionLocation, { 1, 1 } };
    54065409
     
    54245427        selectionBoundingRect = postLayoutData.caretRectAtStart;
    54255428
    5426     selectionBoundingRect.intersect(elementInfo.elementRect);
     5429    selectionBoundingRect.intersect(elementInfo.interactionRect);
    54275430    return selectionBoundingRect;
    54285431}
     
    55255528    // FIXME: We should remove this check when we manage to send ElementDidFocus from the WebProcess
    55265529    // only when it is truly time to show the keyboard.
    5527     if (_focusedElementInformation.elementType == information.elementType && _focusedElementInformation.elementRect == information.elementRect) {
     5530    if (_focusedElementInformation.elementType == information.elementType && _focusedElementInformation.interactionRect == information.interactionRect) {
    55285531        if (_inputPeripheral) {
    55295532            if (!self.isFirstResponder)
     
    55575560        [inputDelegate _webView:_webView willStartInputSession:_formInputSession.get()];
    55585561
    5559     auto previousElementRect = _isChangingFocus ? _focusedElementInformation.elementRect : WebCore::IntRect();
    55605562    BOOL isSelectable = mayContainSelectableText(information.elementType);
    55615563    BOOL editableChanged = [self setIsEditable:isSelectable];
     
    56045606   
    56055607    [_webView didStartFormControlInteraction];
    5606 
    5607     [self _didChangeFocusedElementRect:previousElementRect toRect:_focusedElementInformation.elementRect];
    56085608}
    56095609
     
    56295629
    56305630    BOOL editableChanged = [self setIsEditable:NO];
    5631     auto previousElementRect = _focusedElementInformation.elementRect;
    56325631    // FIXME: We should completely invalidate _focusedElementInformation here, instead of a subset of individual members.
    56335632    _focusedElementInformation.elementType = WebKit::InputType::None;
     
    56635662    }
    56645663
    5665     if (!_isChangingFocus) {
     5664    if (!_isChangingFocus)
    56665665        _didAccessoryTabInitiateFocus = NO;
    5667         [self _didChangeFocusedElementRect:previousElementRect toRect:WebCore::IntRect()];
    5668     }
    5669 }
    5670 
    5671 - (void)_didChangeFocusedElementRect:(const WebCore::IntRect&)previousRect toRect:(const WebCore::IntRect&)newRect
    5672 {
    5673     if (previousRect == newRect)
    5674         return;
    5675 
    5676     if (newRect.isEmpty() && !_positionInformation.nodeAtPositionIsFocusedElement)
    5677         return;
    5678 
    5679     // If the focused element rect changed, the cached position information's nodeAtPositionIsFocusedElement may be stale.
    5680     _hasValidPositionInformation = NO;
    5681     _positionInformation = { };
    56825666}
    56835667
     
    59905974- (CGRect)rectForFocusedFormControlView:(WKFocusedFormControlView *)view
    59915975{
    5992     return [self convertRect:_focusedElementInformation.elementRect toView:view];
     5976    return [self convertRect:_focusedElementInformation.interactionRect toView:view];
    59935977}
    59945978
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFormPopover.mm

    r247837 r251693  
    143143                                          animated:animated];
    144144    } else {
    145         CGRect boundingBoxOfDOMNode = _view.focusedElementInformation.elementRect;
     145        CGRect boundingBoxOfDOMNode = _view.focusedElementInformation.interactionRect;
    146146        [_popoverController presentPopoverFromRect:CGRectIntegral(boundingBoxOfDOMNode)
    147147                                            inView:_view
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r251445 r251693  
    27812781    auto* nodeRespondingToClickEvents = m_page->mainFrame().nodeRespondingToClickEvents(request.point, adjustedPoint);
    27822782
    2783     info.nodeAtPositionIsFocusedElement = nodeRespondingToClickEvents == m_focusedElement;
    27842783    info.adjustedPointForNodeRespondingToClickEvents = adjustedPoint;
    27852784    info.nodeAtPositionHasDoubleClickHandler = m_page->mainFrame().nodeRespondingToDoubleClickEvent(request.point, adjustedPoint);
     
    29062905
    29072906    information.lastInteractionLocation = m_lastInteractionLocation;
     2907    if (auto elementContext = contextForElement(*m_focusedElement))
     2908        information.elementContext = WTFMove(*elementContext);
    29082909
    29092910    if (auto* renderer = m_focusedElement->renderer()) {
    2910         information.elementRect = rootViewInteractionBoundsForElement(*m_focusedElement);
     2911        information.interactionRect = rootViewInteractionBoundsForElement(*m_focusedElement);
    29112912        information.nodeFontSize = renderer->style().fontDescription().computedSize();
    29122913
     
    29162917        information.isRTL = renderer->style().direction() == TextDirection::RTL;
    29172918    } else
    2918         information.elementRect = IntRect();
     2919        information.interactionRect = { };
    29192920
    29202921    if (is<HTMLElement>(m_focusedElement))
Note: See TracChangeset for help on using the changeset viewer.