Title: [259091] trunk/Source/WebKit
Revision
259091
Author
dba...@webkit.org
Date
2020-03-26 16:10:36 -0700 (Thu, 26 Mar 2020)

Log Message

Rename -_isInteractingWithFocusedElement, add it to the header, and replace calls to hasFocusedElement() with it
https://bugs.webkit.org/show_bug.cgi?id=209623

Reviewed by Simon Fraser.

Rename -_isInteractingWithFocusedElement to -_hasFocusedElement. For now, standardize around
the convention of using -_hasFocusedElement instead of hasFocusedElement(_focusedElementInformation).

I think in the ideal world -_hasFocusedElement would not exist and instead -_elementDidBlur would
reset the state of _focusedElementInformation to what it was when a page is first loaded. I will
look to do this in a subsequent patch because it is risky. Doing so requires a careful audit of all
call sites that use _focusedElementInformation as they may have inadvertently depended on stale state.

While I am here, I added -_hasFocusedElement to WKContentViewInteraction.h so that I can make use
of it in the fix for <rdar://problem/60871807>.

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _didGetTapHighlightForRequest:color:quads:topLeftRadius:topRightRadius:bottomLeftRadius:bottomRightRadius:nodeHasBuiltInClickHandling:]):
(-[WKContentView inputViewForWebView]):
(-[WKContentView _selectionClipRect]):
(-[WKContentView gestureRecognizerShouldBegin:]):
(-[WKContentView canPerformActionForWebView:withSender:]):
(-[WKContentView _hasFocusedElement]):
(-[WKContentView changeSelectionWithGestureAt:withGesture:withState:withFlags:]):
(-[WKContentView selectPositionAtPoint:completionHandler:]):
(-[WKContentView selectPositionAtBoundary:inDirection:fromPoint:completionHandler:]):
(-[WKContentView selectTextWithGranularity:atPoint:completionHandler:]):
(-[WKContentView updateSelectionWithExtentPoint:completionHandler:]):
(-[WKContentView updateSelectionWithExtentPoint:withBoundary:completionHandler:]):
(-[WKContentView setSelectedTextRange:]):
(-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]):
(-[WKContentView _updateInputContextAfterBlurringAndRefocusingElement]):
(-[WKContentView _updateSelectionAssistantSuppressionState]):
(-[WKContentView _autofillContext]):
(hasFocusedElement): Deleted.
(-[WKContentView _isInteractingWithFocusedElement]): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (259090 => 259091)


--- trunk/Source/WebKit/ChangeLog	2020-03-26 23:09:59 UTC (rev 259090)
+++ trunk/Source/WebKit/ChangeLog	2020-03-26 23:10:36 UTC (rev 259091)
@@ -1,5 +1,45 @@
 2020-03-26  Daniel Bates  <daba...@apple.com>
 
+        Rename -_isInteractingWithFocusedElement, add it to the header, and replace calls to hasFocusedElement() with it
+        https://bugs.webkit.org/show_bug.cgi?id=209623
+
+        Reviewed by Simon Fraser.
+
+        Rename -_isInteractingWithFocusedElement to -_hasFocusedElement. For now, standardize around
+        the convention of using -_hasFocusedElement instead of hasFocusedElement(_focusedElementInformation).
+
+        I think in the ideal world -_hasFocusedElement would not exist and instead -_elementDidBlur would
+        reset the state of _focusedElementInformation to what it was when a page is first loaded. I will
+        look to do this in a subsequent patch because it is risky. Doing so requires a careful audit of all
+        call sites that use _focusedElementInformation as they may have inadvertently depended on stale state.
+
+        While I am here, I added -_hasFocusedElement to WKContentViewInteraction.h so that I can make use
+        of it in the fix for <rdar://problem/60871807>.
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _didGetTapHighlightForRequest:color:quads:topLeftRadius:topRightRadius:bottomLeftRadius:bottomRightRadius:nodeHasBuiltInClickHandling:]):
+        (-[WKContentView inputViewForWebView]):
+        (-[WKContentView _selectionClipRect]):
+        (-[WKContentView gestureRecognizerShouldBegin:]):
+        (-[WKContentView canPerformActionForWebView:withSender:]):
+        (-[WKContentView _hasFocusedElement]):
+        (-[WKContentView changeSelectionWithGestureAt:withGesture:withState:withFlags:]):
+        (-[WKContentView selectPositionAtPoint:completionHandler:]):
+        (-[WKContentView selectPositionAtBoundary:inDirection:fromPoint:completionHandler:]):
+        (-[WKContentView selectTextWithGranularity:atPoint:completionHandler:]):
+        (-[WKContentView updateSelectionWithExtentPoint:completionHandler:]):
+        (-[WKContentView updateSelectionWithExtentPoint:withBoundary:completionHandler:]):
+        (-[WKContentView setSelectedTextRange:]):
+        (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:]):
+        (-[WKContentView _updateInputContextAfterBlurringAndRefocusingElement]):
+        (-[WKContentView _updateSelectionAssistantSuppressionState]):
+        (-[WKContentView _autofillContext]):
+        (hasFocusedElement): Deleted.
+        (-[WKContentView _isInteractingWithFocusedElement]): Deleted.
+
+2020-03-26  Daniel Bates  <daba...@apple.com>
+
         Remove hitTestOrder from ElementContext as it is no longer need
         https://bugs.webkit.org/show_bug.cgi?id=209561
         <rdar://problem/60888305>

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (259090 => 259091)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2020-03-26 23:09:59 UTC (rev 259090)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2020-03-26 23:10:36 UTC (rev 259091)
@@ -453,6 +453,7 @@
 - (void)_startSuppressingSelectionAssistantForReason:(WebKit::SuppressSelectionAssistantReason)reason;
 - (void)_stopSuppressingSelectionAssistantForReason:(WebKit::SuppressSelectionAssistantReason)reason;
 
+- (BOOL)_hasFocusedElement;
 - (void)_zoomToRevealFocusedElement;
 
 - (void)cancelPointersForGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (259090 => 259091)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2020-03-26 23:09:59 UTC (rev 259090)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2020-03-26 23:10:36 UTC (rev 259091)
@@ -677,11 +677,6 @@
 
 @implementation WKContentView (WKInteraction)
 
-static inline bool hasFocusedElement(WebKit::FocusedElementInformation focusedElementInformation)
-{
-    return (focusedElementInformation.elementType != WebKit::InputType::None);
-}
-
 - (BOOL)preventsPanningInXAxis
 {
     return _preventsPanningInXAxis;
@@ -1768,7 +1763,7 @@
     if (!_isTapHighlightIDValid || _latestTapID != requestID)
         return;
 
-    if (hasFocusedElement(_focusedElementInformation) && _positionInformation.elementContext && _positionInformation.elementContext->isSameElement(_focusedElementInformation.elementContext))
+    if (self._hasFocusedElement && _positionInformation.elementContext && _positionInformation.elementContext->isSameElement(_focusedElementInformation.elementContext))
         return;
 
     _isTapHighlightIDValid = NO;
@@ -1960,7 +1955,7 @@
 
 - (UIView *)inputViewForWebView
 {
-    if (!hasFocusedElement(_focusedElementInformation))
+    if (!self._hasFocusedElement)
         return nil;
 
     if (_inputPeripheral) {
@@ -1990,7 +1985,7 @@
 
 - (CGRect)_selectionClipRect
 {
-    if (!hasFocusedElement(_focusedElementInformation))
+    if (!self._hasFocusedElement)
         return CGRectNull;
 
     if (_page->waitingForPostLayoutEditorStateUpdateAfterFocusingElement())
@@ -2360,7 +2355,7 @@
         || gestureRecognizer == _nonBlockingDoubleTapGestureRecognizer
         || gestureRecognizer == _twoFingerDoubleTapGestureRecognizer) {
 
-        if (hasFocusedElement(_focusedElementInformation)) {
+        if (self._hasFocusedElement) {
             // Request information about the position with sync message.
             // If the focused element is the same, prevent the gesture.
             if (![self ensurePositionInformationIsUpToDate:WebKit::InteractionInformationRequest(WebCore::roundedIntPoint(point))])
@@ -2374,7 +2369,7 @@
         if (isInterruptingDecelerationForScrollViewOrAncestor([_highlightLongPressGestureRecognizer lastTouchedScrollView]))
             return NO;
 
-        if (hasFocusedElement(_focusedElementInformation)) {
+        if (self._hasFocusedElement) {
             // This is a different element than the focused one.
             // Prevent the gesture if there is no node.
             // Allow the gesture if it is a node that wants highlight or if there is an action for it.
@@ -2409,7 +2404,7 @@
         if (![self ensurePositionInformationIsUpToDate:request])
             return NO;
 
-        if (hasFocusedElement(_focusedElementInformation)) {
+        if (self._hasFocusedElement) {
             // Prevent the gesture if it is the same node.
             if (_positionInformation.elementContext && _positionInformation.elementContext->isSameElement(_focusedElementInformation.elementContext))
                 return NO;
@@ -3271,9 +3266,9 @@
         return action == @selector(paste:);
 
     if (action == @selector(_nextAccessoryTab:))
-        return hasFocusedElement(_focusedElementInformation) && _focusedElementInformation.hasNextNode;
+        return self._hasFocusedElement && _focusedElementInformation.hasNextNode;
     if (action == @selector(_previousAccessoryTab:))
-        return hasFocusedElement(_focusedElementInformation) && _focusedElementInformation.hasPreviousNode;
+        return self._hasFocusedElement && _focusedElementInformation.hasPreviousNode;
 
     auto editorState = _page->editorState();
     if (action == @selector(_showTextStyleOptions:))
@@ -3864,9 +3859,9 @@
     [(UIWKTextInteractionAssistant *)[view interactionAssistant] selectionChangedWithTouchAt:(CGPoint)point withSelectionTouch:toUIWKSelectionTouch((WebKit::SelectionTouch)touch) withFlags:static_cast<UIWKSelectionFlags>(flags)];
 }
 
-- (BOOL)_isInteractingWithFocusedElement
+- (BOOL)_hasFocusedElement
 {
-    return hasFocusedElement(_focusedElementInformation);
+    return _focusedElementInformation.elementType != WebKit::InputType::None;
 }
 
 - (void)changeSelectionWithGestureAt:(CGPoint)point withGesture:(UIWKGestureType)gestureType withState:(UIGestureRecognizerState)state
@@ -3877,7 +3872,7 @@
 - (void)changeSelectionWithGestureAt:(CGPoint)point withGesture:(UIWKGestureType)gestureType withState:(UIGestureRecognizerState)state withFlags:(UIWKSelectionFlags)flags
 {
     _usingGestureForSelection = YES;
-    _page->selectWithGesture(WebCore::IntPoint(point), WebCore::CharacterGranularity, static_cast<uint32_t>(toGestureType(gestureType)), static_cast<uint32_t>(toGestureRecognizerState(state)), [self _isInteractingWithFocusedElement], [self, state, flags](const WebCore::IntPoint& point, uint32_t gestureType, uint32_t gestureState, uint32_t innerFlags, WebKit::CallbackBase::Error error) {
+    _page->selectWithGesture(WebCore::IntPoint(point), WebCore::CharacterGranularity, static_cast<uint32_t>(toGestureType(gestureType)), static_cast<uint32_t>(toGestureRecognizerState(state)), self._hasFocusedElement, [self, state, flags](const WebCore::IntPoint& point, uint32_t gestureType, uint32_t gestureState, uint32_t innerFlags, WebKit::CallbackBase::Error error) {
         selectionChangedWithGesture(self, point, gestureType, gestureState, flags | innerFlags, error);
         if (state == UIGestureRecognizerStateEnded || state == UIGestureRecognizerStateCancelled)
             _usingGestureForSelection = NO;
@@ -3996,7 +3991,7 @@
 
 - (void)selectPositionAtPoint:(CGPoint)point completionHandler:(void (^)(void))completionHandler
 {
-    [self _selectPositionAtPoint:point stayingWithinFocusedElement:[self _isInteractingWithFocusedElement] completionHandler:completionHandler];
+    [self _selectPositionAtPoint:point stayingWithinFocusedElement:self._hasFocusedElement completionHandler:completionHandler];
 }
 
 - (void)_selectPositionAtPoint:(CGPoint)point stayingWithinFocusedElement:(BOOL)stayingWithinFocusedElement completionHandler:(void (^)(void))completionHandler
@@ -4018,7 +4013,7 @@
     UIWKSelectionCompletionHandler selectionHandler = [completionHandler copy];
     RetainPtr<WKContentView> view = self;
     
-    _page->selectPositionAtBoundaryWithDirection(WebCore::IntPoint(point), toWKTextGranularity(granularity), toWKSelectionDirection(direction), [self _isInteractingWithFocusedElement], [view, selectionHandler](WebKit::CallbackBase::Error error) {
+    _page->selectPositionAtBoundaryWithDirection(WebCore::IntPoint(point), toWKTextGranularity(granularity), toWKSelectionDirection(direction), self._hasFocusedElement, [view, selectionHandler](WebKit::CallbackBase::Error error) {
         selectionHandler();
         view->_usingGestureForSelection = NO;
         [selectionHandler release];
@@ -4045,7 +4040,7 @@
     UIWKSelectionCompletionHandler selectionHandler = [completionHandler copy];
     RetainPtr<WKContentView> view = self;
 
-    _page->selectTextWithGranularityAtPoint(WebCore::IntPoint(point), toWKTextGranularity(granularity), [self _isInteractingWithFocusedElement], [view, selectionHandler](WebKit::CallbackBase::Error error) {
+    _page->selectTextWithGranularityAtPoint(WebCore::IntPoint(point), toWKTextGranularity(granularity), self._hasFocusedElement, [view, selectionHandler](WebKit::CallbackBase::Error error) {
         selectionHandler();
         view->_usingGestureForSelection = NO;
         --view->_suppressNonEditableSingleTapTextInteractionCount;
@@ -4068,7 +4063,7 @@
     UIWKSelectionWithDirectionCompletionHandler selectionHandler = [completionHandler copy];
     
     auto respectSelectionAnchor = self.interactionAssistant._wk_hasFloatingCursor ? WebKit::RespectSelectionAnchor::Yes : WebKit::RespectSelectionAnchor::No;
-    _page->updateSelectionWithExtentPoint(WebCore::IntPoint(point), self._isInteractingWithFocusedElement, respectSelectionAnchor, [selectionHandler](bool endIsMoving, WebKit::CallbackBase::Error error) {
+    _page->updateSelectionWithExtentPoint(WebCore::IntPoint(point), self._hasFocusedElement, respectSelectionAnchor, [selectionHandler](bool endIsMoving, WebKit::CallbackBase::Error error) {
         selectionHandler(endIsMoving);
         [selectionHandler release];
     });
@@ -4079,7 +4074,7 @@
     UIWKSelectionWithDirectionCompletionHandler selectionHandler = [completionHandler copy];
     
     ++_suppressNonEditableSingleTapTextInteractionCount;
-    _page->updateSelectionWithExtentPointAndBoundary(WebCore::IntPoint(point), toWKTextGranularity(granularity), [self _isInteractingWithFocusedElement], [selectionHandler, protectedSelf = retainPtr(self)] (bool endIsMoving, WebKit::CallbackBase::Error error) {
+    _page->updateSelectionWithExtentPointAndBoundary(WebCore::IntPoint(point), toWKTextGranularity(granularity), self._hasFocusedElement, [selectionHandler, protectedSelf = retainPtr(self)] (bool endIsMoving, WebKit::CallbackBase::Error error) {
         selectionHandler(endIsMoving);
         [selectionHandler release];
         --protectedSelf->_suppressNonEditableSingleTapTextInteractionCount;
@@ -4506,7 +4501,7 @@
     if (range)
         return;
 #if !PLATFORM(MACCATALYST)
-    if (!hasFocusedElement(_focusedElementInformation))
+    if (!self._hasFocusedElement)
         return;
 #endif
     [self clearSelection];
@@ -5676,7 +5671,7 @@
 
 - (void)_elementDidFocus:(const WebKit::FocusedElementInformation&)information userIsInteracting:(BOOL)userIsInteracting blurPreviousNode:(BOOL)blurPreviousNode activityStateChanges:(OptionSet<WebCore::ActivityState::Flag>)activityStateChanges userObject:(NSObject <NSSecureCoding> *)userObject
 {
-    SetForScope<BOOL> isChangingFocusForScope { _isChangingFocus, hasFocusedElement(_focusedElementInformation) };
+    SetForScope<BOOL> isChangingFocusForScope { _isChangingFocus, self._hasFocusedElement };
     SetForScope<BOOL> isFocusingElementWithKeyboardForScope { _isFocusingElementWithKeyboard, shouldShowKeyboardForElement(information) };
 
     auto inputViewUpdateDeferrer = std::exchange(_inputViewUpdateDeferrer, nullptr);
@@ -5901,7 +5896,7 @@
 
 - (void)_updateInputContextAfterBlurringAndRefocusingElement
 {
-    if (!hasFocusedElement(_focusedElementInformation) || !_suppressSelectionAssistantReasons)
+    if (!self._hasFocusedElement || !_suppressSelectionAssistantReasons)
         return;
 
     [UIKeyboardImpl.activeInstance updateForChangedSelection];
@@ -6364,7 +6359,7 @@
         if (postLayoutData.editableRootIsTransparentOrFullyClipped)
             editableRootIsTransparentOrFullyClipped = YES;
 
-        if (hasFocusedElement(_focusedElementInformation)) {
+        if (self._hasFocusedElement) {
             auto elementArea = postLayoutData.focusedElementRect.area<RecordOverflow>();
             if (!elementArea.hasOverflowed() && elementArea < minimumFocusedElementAreaForSuppressingSelectionAssistant)
                 focusedElementIsTooSmall = YES;
@@ -7412,7 +7407,7 @@
 - (NSDictionary *)_autofillContext
 {
     BOOL provideStrongPasswordAssistance = _focusRequiresStrongPasswordAssistance && _focusedElementInformation.elementType == WebKit::InputType::Password;
-    if (!hasFocusedElement(_focusedElementInformation) || (!_focusedElementInformation.acceptsAutofilledLoginCredentials && !provideStrongPasswordAssistance))
+    if (!self._hasFocusedElement || (!_focusedElementInformation.acceptsAutofilledLoginCredentials && !provideStrongPasswordAssistance))
         return nil;
 
     if (provideStrongPasswordAssistance)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to