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

Changeset 277316 in webkit


Ignore:
Timestamp:
May 10, 2021, 9:31:16 PM (5 years ago)
Author:
Wenson Hsieh
Message:

[macOS] Allow immediate action gestures to begin when force clicking text inside image overlays
https://bugs.webkit.org/show_bug.cgi?id=225600
<rdar://problem/77792365>

Reviewed by Tim Horton.

Source/WebCore:

Allow immediate action hit-testing to descend into image overlay content. Currently, this uses the
DisallowsUserAgentShadowContent hit-testing option, causing us to ignore image overlays (which exist inside
the UA shadow root). To fix this, we introduce a DisallowsUserAgentShadowContentExceptForImageOverlays option
that behaves like the existing DisallowsUserAgentShadowContent option, with the exception that we allow hit-
testing to pierce the UA shadow root to find nodes inside image overlays.

Tests: ImmediateActionTests.ImmediateActionOverText

ImmediateActionTests.ImmediateActionOverBody
ImmediateActionTests.ImmediateActionOverImageOverlay

  • page/EventHandler.cpp:

(WebCore::EventHandler::hitTestResultAtPoint const):

  • rendering/HitTestRequest.h:

Add support for the new hit-test option, which allows hit-testing to descend into image overlays (and is
intended to be mutually exclusive with the existing DisallowsUserAgentShadowContent option). Specifying both
options will lead to an assertion on debug builds, and DisallowsUserAgentShadowContent takes precedence on
release builds.

(WebCore::HitTestRequest::disallowsUserAgentShadowContentExceptForImageOverlays const):

  • rendering/HitTestResult.cpp:

(WebCore::HitTestResult::addNodeToListBasedTestResultCommon):

Source/WebCore/PAL:

  • pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h:

Source/WebKit:

Adopt the new hit-test option. See WebCore/ChangeLog for more details.

  • WebProcess/WebPage/mac/WebPageMac.mm:

(WebKit::WebPage::performImmediateActionHitTestAtLocation):
(WebKit::WebPage::lookupTextAtLocation):

Tools:

Add new API tests to exercise these changes by grabbing the immediate action NSGestureRecognizer from
WKWebView and calling into its delegate. This patch adds two basic immediate action tests by simulating the
immediate action over text and the body element, and includes a third test that installs an image overlay using
an injected internals object, and verifies that the immediate action in an image overlay matches that of
regular text on the page.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/mac/ImmediateActionTests.mm: Added.

(swizzledImmediateActionLocationInView):
(-[WKWebViewForTestingImmediateActions _immediateActionAnimationControllerForHitTestResult:withType:userData:]):
(-[WKWebViewForTestingImmediateActions immediateActionGesture]):
(-[WKWebViewForTestingImmediateActions simulateImmediateAction:]):
(TestWebKitAPI::TEST):

Location:
trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r277313 r277316  
     12021-05-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Allow immediate action gestures to begin when force clicking text inside image overlays
     4        https://bugs.webkit.org/show_bug.cgi?id=225600
     5        <rdar://problem/77792365>
     6
     7        Reviewed by Tim Horton.
     8
     9        Allow immediate action hit-testing to descend into image overlay content. Currently, this uses the
     10        `DisallowsUserAgentShadowContent` hit-testing option, causing us to ignore image overlays (which exist inside
     11        the UA shadow root). To fix this, we introduce a `DisallowsUserAgentShadowContentExceptForImageOverlays` option
     12        that behaves like the existing `DisallowsUserAgentShadowContent` option, with the exception that we allow hit-
     13        testing to pierce the UA shadow root to find nodes inside image overlays.
     14
     15        Tests:  ImmediateActionTests.ImmediateActionOverText
     16                ImmediateActionTests.ImmediateActionOverBody
     17                ImmediateActionTests.ImmediateActionOverImageOverlay
     18
     19        * page/EventHandler.cpp:
     20        (WebCore::EventHandler::hitTestResultAtPoint const):
     21        * rendering/HitTestRequest.h:
     22
     23        Add support for the new hit-test option, which allows hit-testing to descend into image overlays (and is
     24        intended to be mutually exclusive with the existing `DisallowsUserAgentShadowContent` option). Specifying both
     25        options will lead to an assertion on debug builds, and `DisallowsUserAgentShadowContent` takes precedence on
     26        release builds.
     27
     28        (WebCore::HitTestRequest::disallowsUserAgentShadowContentExceptForImageOverlays const):
     29        * rendering/HitTestResult.cpp:
     30        (WebCore::HitTestResult::addNodeToListBasedTestResultCommon):
     31
    1322021-05-10  Sam Weinig  <weinig@apple.com>
    233
  • trunk/Source/WebCore/PAL/ChangeLog

    r276828 r277316  
     12021-05-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Allow immediate action gestures to begin when force clicking text inside image overlays
     4        https://bugs.webkit.org/show_bug.cgi?id=225600
     5        <rdar://problem/77792365>
     6
     7        Reviewed by Tim Horton.
     8
     9        * pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h:
     10
    1112021-04-29  Jean-Yves Avenard  <jya@apple.com>
    212
  • trunk/Source/WebCore/PAL/pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h

    r220979 r277316  
    5757@interface NSImmediateActionGestureRecognizer : NSGestureRecognizer
    5858
     59@property (weak) id <NSImmediateActionGestureRecognizerDelegate> delegate;
    5960@property (strong) id<NSImmediateActionAnimationController> animationController;
    6061@property (readonly) CGFloat animationProgress;
  • trunk/Source/WebCore/page/EventHandler.cpp

    r277295 r277316  
    11911191        m_frame.document()->updateHoverActiveState(request, result.targetElement());
    11921192
    1193     if (request.disallowsUserAgentShadowContent())
     1193    auto innerNode = makeRefPtr(result.innerNode());
     1194    if (request.disallowsUserAgentShadowContent()
     1195        || (request.disallowsUserAgentShadowContentExceptForImageOverlays() && innerNode && !HTMLElement::isInsideImageOverlay(*innerNode)))
    11941196        result.setToNonUserAgentShadowAncestor();
    11951197
  • trunk/Source/WebCore/rendering/HitTestRequest.h

    r277295 r277316  
    4040        TouchEvent = 1 << 7,
    4141        DisallowUserAgentShadowContent = 1 << 8,
    42         AllowFrameScrollbars = 1 << 9,
    43         AllowChildFrameContent = 1 << 10,
    44         AllowVisibleChildFrameContentOnly = 1 << 11,
    45         ChildFrameHitTest = 1 << 12,
    46         AccessibilityHitTest = 1 << 13,
     42        DisallowUserAgentShadowContentExceptForImageOverlays = 1 << 9,
     43        AllowFrameScrollbars = 1 << 10,
     44        AllowChildFrameContent = 1 << 11,
     45        AllowVisibleChildFrameContentOnly = 1 << 12,
     46        ChildFrameHitTest = 1 << 13,
     47        AccessibilityHitTest = 1 << 14,
    4748        // Collect a list of nodes instead of just one. Used for elementsFromPoint and rect-based tests.
    48         CollectMultipleElements = 1 << 14,
     49        CollectMultipleElements = 1 << 15,
    4950        // When using list-based testing, continue hit testing even after a hit has been found.
    50         IncludeAllElementsUnderPoint = 1 << 15,
     51        IncludeAllElementsUnderPoint = 1 << 16,
    5152    };
    5253
     
    5455        : m_type { type }
    5556    {
     57        ASSERT(!type.containsAll({ Type::DisallowUserAgentShadowContentExceptForImageOverlays, Type::DisallowUserAgentShadowContent }));
    5658        ASSERT_IMPLIES(type.contains(Type::IncludeAllElementsUnderPoint), type.contains(Type::CollectMultipleElements));
    5759    }
     
    6769    bool mouseEvent() const { return !touchEvent(); }
    6870    bool disallowsUserAgentShadowContent() const { return m_type.contains(Type::DisallowUserAgentShadowContent); }
     71    bool disallowsUserAgentShadowContentExceptForImageOverlays() const { return m_type.contains(Type::DisallowUserAgentShadowContentExceptForImageOverlays); }
    6972    bool allowsFrameScrollbars() const { return m_type.contains(Type::AllowFrameScrollbars); }
    7073    bool allowsChildFrameContent() const { return m_type.contains(Type::AllowChildFrameContent); }
  • trunk/Source/WebCore/rendering/HitTestResult.cpp

    r275072 r277316  
    657657        return HitTestProgress::Continue;
    658658
    659     if (request.disallowsUserAgentShadowContent() && node->isInUserAgentShadowTree())
     659    if ((request.disallowsUserAgentShadowContent() && node->isInUserAgentShadowTree())
     660        || (request.disallowsUserAgentShadowContentExceptForImageOverlays() && !HTMLElement::isInsideImageOverlay(*node) && node->isInUserAgentShadowTree()))
    660661        node = node->document().ancestorNodeInThisScope(node);
    661662
  • trunk/Source/WebKit/ChangeLog

    r277313 r277316  
     12021-05-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Allow immediate action gestures to begin when force clicking text inside image overlays
     4        https://bugs.webkit.org/show_bug.cgi?id=225600
     5        <rdar://problem/77792365>
     6
     7        Reviewed by Tim Horton.
     8
     9        Adopt the new hit-test option. See WebCore/ChangeLog for more details.
     10
     11        * WebProcess/WebPage/mac/WebPageMac.mm:
     12        (WebKit::WebPage::performImmediateActionHitTestAtLocation):
     13        (WebKit::WebPage::lookupTextAtLocation):
     14
    1152021-05-10  Sam Weinig  <weinig@apple.com>
    216
  • trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm

    r277295 r277316  
    859859    }
    860860
    861     IntPoint locationInContentCoordinates = mainFrame.view()->rootViewToContents(roundedIntPoint(locationInViewCoordinates));
    862     constexpr OptionSet<HitTestRequest::Type> hitType { HitTestRequest::Type::ReadOnly, HitTestRequest::Type::Active, HitTestRequest::Type::DisallowUserAgentShadowContent, HitTestRequest::Type::AllowChildFrameContent };
    863     HitTestResult hitTestResult = mainFrame.eventHandler().hitTestResultAtPoint(locationInContentCoordinates, hitType);
     861    auto locationInContentCoordinates = mainFrame.view()->rootViewToContents(roundedIntPoint(locationInViewCoordinates));
     862    auto hitTestResult = mainFrame.eventHandler().hitTestResultAtPoint(locationInContentCoordinates, {
     863        HitTestRequest::Type::ReadOnly,
     864        HitTestRequest::Type::Active,
     865        HitTestRequest::Type::DisallowUserAgentShadowContentExceptForImageOverlays,
     866        HitTestRequest::Type::AllowChildFrameContent,
     867    });
    864868
    865869    bool immediateActionHitTestPreventsDefault = false;
     
    959963        return WTF::nullopt;
    960964
    961     auto point = roundedIntPoint(locationInViewCoordinates);
    962     constexpr OptionSet<HitTestRequest::Type> hitType { HitTestRequest::Type::ReadOnly, HitTestRequest::Type::Active, HitTestRequest::Type::DisallowUserAgentShadowContent, HitTestRequest::Type::AllowChildFrameContent };
    963     auto result = mainFrame.eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(point), hitType);
    964     return DictionaryLookup::rangeAtHitTestResult(result);
     965    return DictionaryLookup::rangeAtHitTestResult(mainFrame.eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(roundedIntPoint(locationInViewCoordinates)), {
     966        HitTestRequest::Type::ReadOnly,
     967        HitTestRequest::Type::Active,
     968        HitTestRequest::Type::DisallowUserAgentShadowContentExceptForImageOverlays,
     969        HitTestRequest::Type::AllowChildFrameContent,
     970    }));
    965971}
    966972
  • trunk/Tools/ChangeLog

    r277301 r277316  
     12021-05-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Allow immediate action gestures to begin when force clicking text inside image overlays
     4        https://bugs.webkit.org/show_bug.cgi?id=225600
     5        <rdar://problem/77792365>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add new API tests to exercise these changes by grabbing the immediate action `NSGestureRecognizer` from
     10        `WKWebView` and calling into its delegate. This patch adds two basic immediate action tests by simulating the
     11        immediate action over text and the body element, and includes a third test that installs an image overlay using
     12        an injected `internals` object, and verifies that the immediate action in an image overlay matches that of
     13        regular text on the page.
     14
     15        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     16        * TestWebKitAPI/Tests/mac/ImmediateActionTests.mm: Added.
     17        (swizzledImmediateActionLocationInView):
     18        (-[WKWebViewForTestingImmediateActions _immediateActionAnimationControllerForHitTestResult:withType:userData:]):
     19        (-[WKWebViewForTestingImmediateActions immediateActionGesture]):
     20        (-[WKWebViewForTestingImmediateActions simulateImmediateAction:]):
     21        (TestWebKitAPI::TEST):
     22
    1232021-05-10  Kate Cheney  <katherine_cheney@apple.com>
    224
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r277271 r277316  
    869869                93F56DA91E5F919D003EDE84 /* WKWebViewSnapshot.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93F56DA81E5F9181003EDE84 /* WKWebViewSnapshot.mm */; };
    870870                93F7E86F14DC8E5C00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */; };
     871                93FCDB34263631560046DD7D /* SortedArrayMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93FCDB33263631560046DD7D /* SortedArrayMap.cpp */; };
    871872                95095F20262FFFA50000D920 /* SampledPageTopColor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 95095F1F262FFFA50000D920 /* SampledPageTopColor.mm */; };
    872                 93FCDB34263631560046DD7D /* SortedArrayMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93FCDB33263631560046DD7D /* SortedArrayMap.cpp */; };
    873873                950E4CC1252E75240071659F /* iOSStylusSupport.mm in Sources */ = {isa = PBXBuildFile; fileRef = 950E4CC0252E75230071659F /* iOSStylusSupport.mm */; };
    874874                953ABB3525C0D682004C8B73 /* PageExtendedBackgroundColor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 953ABB3425C0D681004C8B73 /* PageExtendedBackgroundColor.mm */; };
     
    11801180                F4451C761EB8FD890020C5DA /* two-paragraph-contenteditable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4451C751EB8FD7C0020C5DA /* two-paragraph-contenteditable.html */; };
    11811181                F44A531121B8990300DBB99C /* InstanceMethodSwizzler.mm in Sources */ = {isa = PBXBuildFile; fileRef = F44A531021B8976900DBB99C /* InstanceMethodSwizzler.mm */; };
     1182                F44A9AF72649BBDD00E7CB16 /* ImmediateActionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F44A9AF62649BBDD00E7CB16 /* ImmediateActionTests.mm */; };
    11821183                F44C79FF20F9E8710014478C /* ParserYieldTokenTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F44C79FE20F9E8710014478C /* ParserYieldTokenTests.mm */; };
    11831184                F44C7A0020F9EEBF0014478C /* ParserYieldTokenPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = F44C79FB20F9E50C0014478C /* ParserYieldTokenPlugIn.mm */; };
     
    25662567                93F7E86B14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFrames.cpp; sourceTree = "<group>"; };
    25672568                93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp; sourceTree = "<group>"; };
     2569                93FCDB33263631560046DD7D /* SortedArrayMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SortedArrayMap.cpp; sourceTree = "<group>"; };
    25682570                95095F1F262FFFA50000D920 /* SampledPageTopColor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SampledPageTopColor.mm; sourceTree = "<group>"; };
    2569                 93FCDB33263631560046DD7D /* SortedArrayMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SortedArrayMap.cpp; sourceTree = "<group>"; };
    25702571                950E4CC0252E75230071659F /* iOSStylusSupport.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = iOSStylusSupport.mm; sourceTree = "<group>"; };
    25712572                953ABB3425C0D681004C8B73 /* PageExtendedBackgroundColor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PageExtendedBackgroundColor.mm; sourceTree = "<group>"; };
     
    29982999                F44A530F21B8976900DBB99C /* ClassMethodSwizzler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClassMethodSwizzler.h; path = ../TestRunnerShared/cocoa/ClassMethodSwizzler.h; sourceTree = "<group>"; };
    29993000                F44A531021B8976900DBB99C /* InstanceMethodSwizzler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = InstanceMethodSwizzler.mm; path = ../TestRunnerShared/cocoa/InstanceMethodSwizzler.mm; sourceTree = "<group>"; };
     3001                F44A9AF52649BBDD00E7CB16 /* ImmediateActionTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImmediateActionTests.h; sourceTree = "<group>"; };
     3002                F44A9AF62649BBDD00E7CB16 /* ImmediateActionTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ImmediateActionTests.mm; sourceTree = "<group>"; };
    30003003                F44C79FB20F9E50C0014478C /* ParserYieldTokenPlugIn.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ParserYieldTokenPlugIn.mm; sourceTree = "<group>"; };
    30013004                F44C79FD20F9E8710014478C /* ParserYieldTokenTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ParserYieldTokenTests.h; sourceTree = "<group>"; };
     
    46814684                                9B4F8FA3159D52B1002D9F94 /* HTMLCollectionNamedItem.mm */,
    46824685                                9B26FC6B159D061000CC3765 /* HTMLFormCollectionNamedItem.mm */,
     4686                                F44A9AF52649BBDD00E7CB16 /* ImmediateActionTests.h */,
     4687                                F44A9AF62649BBDD00E7CB16 /* ImmediateActionTests.mm */,
    46834688                                C507E8A614C6545B005D6B3B /* InspectorBar.mm */,
    46844689                                57F10D921C7E7B3800ECDF30 /* IsNavigationActionTrusted.mm */,
     
    54685473                                5110FCFA1E01CDB8006F8D0B /* IDBIndexUpgradeToV2.mm in Sources */,
    54695474                                93BCBC8323CC6F2A00CA2221 /* IDBObjectStoreInfoUpgradeToV2.mm in Sources */,
     5475                                F44A9AF72649BBDD00E7CB16 /* ImmediateActionTests.mm in Sources */,
    54705476                                49AEEF6D2407359D00C87E4C /* InAppBrowserPrivacy.mm in Sources */,
    54715477                                51A587861D273AA9004BA9AF /* IndexedDBDatabaseProcessKill.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.