[webkit-changes] [WebKit/WebKit] f8bb1d: Script-triggered hit testing should use `RenderSty...

Wenson Hsieh noreply at github.com
Wed Mar 27 16:41:53 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: f8bb1dc584498cbba4b6609c3e0ec6a115996ce2
      https://github.com/WebKit/WebKit/commit/f8bb1dc584498cbba4b6609c3e0ec6a115996ce2
  Author: Wenson Hsieh <wenson_hsieh at apple.com>
  Date:   2024-03-27 (Wed, 27 Mar 2024)

  Changed paths:
    M LayoutTests/fast/element-targeting/basic-element-targeting.html
    M Source/WebCore/Headers.cmake
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/accessibility/AXObjectCache.cpp
    M Source/WebCore/accessibility/AccessibilityNodeObject.cpp
    M Source/WebCore/accessibility/AccessibilityObject.cpp
    M Source/WebCore/dom/Document.cpp
    M Source/WebCore/dom/Document.h
    M Source/WebCore/dom/TreeScope.cpp
    M Source/WebCore/dom/TreeScope.h
    M Source/WebCore/editing/Editing.cpp
    M Source/WebCore/editing/FrameSelection.cpp
    M Source/WebCore/editing/VisibleUnits.cpp
    M Source/WebCore/editing/cocoa/DataDetection.mm
    M Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayBox.h
    M Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp
    M Source/WebCore/page/EventHandler.cpp
    M Source/WebCore/page/LocalFrame.cpp
    M Source/WebCore/rendering/HitTestRequest.h
    A Source/WebCore/rendering/HitTestSource.h
    M Source/WebCore/rendering/RenderBlock.cpp
    M Source/WebCore/rendering/RenderBlock.h
    M Source/WebCore/rendering/RenderBlockFlow.cpp
    M Source/WebCore/rendering/RenderBlockFlow.h
    M Source/WebCore/rendering/RenderBox.cpp
    M Source/WebCore/rendering/RenderBox.h
    M Source/WebCore/rendering/RenderElementInlines.h
    M Source/WebCore/rendering/RenderFileUploadControl.cpp
    M Source/WebCore/rendering/RenderFileUploadControl.h
    M Source/WebCore/rendering/RenderFragmentContainer.cpp
    M Source/WebCore/rendering/RenderFragmentContainer.h
    M Source/WebCore/rendering/RenderInline.cpp
    M Source/WebCore/rendering/RenderInline.h
    M Source/WebCore/rendering/RenderLineBreak.cpp
    M Source/WebCore/rendering/RenderLineBreak.h
    M Source/WebCore/rendering/RenderMultiColumnSet.cpp
    M Source/WebCore/rendering/RenderMultiColumnSet.h
    M Source/WebCore/rendering/RenderObject.cpp
    M Source/WebCore/rendering/RenderObject.h
    M Source/WebCore/rendering/RenderReplaced.cpp
    M Source/WebCore/rendering/RenderReplaced.h
    M Source/WebCore/rendering/RenderText.cpp
    M Source/WebCore/rendering/RenderText.h
    M Source/WebCore/rendering/style/RenderStyle.h
    M Source/WebCore/rendering/style/RenderStyleInlines.h
    M Source/WebCore/rendering/svg/RenderSVGImage.cpp
    M Source/WebCore/rendering/svg/RenderSVGInlineText.cpp
    M Source/WebCore/rendering/svg/RenderSVGInlineText.h
    M Source/WebCore/rendering/svg/RenderSVGShape.cpp
    M Source/WebCore/rendering/svg/RenderSVGText.cpp
    M Source/WebCore/rendering/svg/RenderSVGText.h
    M Source/WebCore/rendering/svg/SVGInlineTextBox.cpp
    M Source/WebCore/rendering/svg/legacy/LegacyRenderSVGImage.cpp
    M Source/WebCore/rendering/svg/legacy/LegacyRenderSVGShape.cpp
    M Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp
    M Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocumentGtk.cpp
    M Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
    M Source/WebKitLegacy/mac/DOM/DOMDocument.mm

  Log Message:
  -----------
  Script-triggered hit testing should use `RenderStyle::visibility()` instead of `usedVisibility`
https://bugs.webkit.org/show_bug.cgi?id=271413

Reviewed by Antti Koivisto and Anne van Kesteren.

Introduce a `HitTestSource` enum which indicates whether or not hit-testing was triggered by (or is
otherwise directly observable by) script running on the webpage, and plumb it through the following
programmatic hit-testing APIs:

• `DocumentOrShadowRoot.elementFromPoint()`
• `DocumentOrShadowRoot.elementsFromPoint()`
• `Document.caretRangeFromPoint()`

This allows programmatically-driven hit testing to ignore `usedVisibility()` styles, while allowing
user-triggered (or native-API-triggered) hit-testing to honor the used visibility. In short, the
presence of `HitTestSource::Script` means that we:

1.  Avoid honoring `usedVisibility()` when getting styles on `RenderStyle` directly, or...
2.  Ignore `usedVisibility()` when performing a hit-test that's triggered by script.

See below for more details.

* LayoutTests/fast/element-targeting/basic-element-targeting.html:

Augment an existing layout test to exercise this change.

* Source/WebCore/Headers.cmake:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::characterOffsetForPoint):
* Source/WebCore/accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::visiblePositionRangeForLine const):
* Source/WebCore/accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::visiblePositionForPoint const):

Explicitly pass in `HitTestSource::User` for all of these accessibility-related call sites.

* Source/WebCore/dom/Document.cpp:
(WebCore::Document::caretRangeFromPoint):
(WebCore::Document::caretPositionFromPoint):
* Source/WebCore/dom/Document.h:
* Source/WebCore/dom/Document.idl:
* Source/WebCore/dom/DocumentOrShadowRoot.idl:
* Source/WebCore/dom/TreeScope.cpp:
(WebCore::TreeScope::nodeFromPoint):
(WebCore::TreeScope::elementFromPoint):
(WebCore::TreeScope::elementsFromPoint):
* Source/WebCore/dom/TreeScope.h:

Introduce a `HitTestSource` argument for these three DOM APIs above, and plumb the source over to
the underlying `HitTestRequest`.

* Source/WebCore/editing/Editing.cpp:
(WebCore::closestEditablePositionInElementForAbsolutePoint):

Pass in `User` here, since this helper method is only used for user-triggered actions.

* Source/WebCore/editing/FrameSelection.cpp:
(WebCore::FrameSelection::contains const):
* Source/WebCore/editing/VisibleUnits.cpp:
(WebCore::previousLinePosition):
(WebCore::nextLinePosition):

Default to `HitTestSource::Script` for now, since these editing codepaths can be directly triggered
from script. In a future patch, we'll need to plumb this state down from bindings calls that trigger
this editing code — for instance, `Document.execCommand` and `DOMSelection.modify`.

* Source/WebCore/editing/cocoa/DataDetection.mm:
(WebCore::DataDetection::detectItemAroundHitTestResult):
* Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayBox.h:
(WebCore::InlineDisplay::Box::isVisibleIgnoringUsedVisibility const):
* Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::hitTest):
* Source/WebCore/page/EventHandler.cpp:
(WebCore::EventHandler::selectClosestWordFromHitTestResult):
(WebCore::EventHandler::selectClosestContextualWordFromHitTestResult):
(WebCore::EventHandler::selectClosestContextualWordOrLinkFromHitTestResult):
(WebCore::EventHandler::handleMousePressEventTripleClick):
(WebCore::EventHandler::handleMousePressEventSingleClick):
(WebCore::EventHandler::selectionExtentRespectingEditingBoundary):
(WebCore::EventHandler::updateSelectionForMouseDrag):
(WebCore::EventHandler::handleMouseReleaseEvent):

Pass in `User` in more places.

* Source/WebCore/page/LocalFrame.cpp:
(WebCore::LocalFrame::visiblePositionForPoint const):
* Source/WebCore/rendering/HitTestRequest.h:

Add a new `HitTestSource` member to `HitTestRequest` that indicates whether the hit test request is
directly invoked through `Script`, or if it's user-triggered. We use this flag to prefer specified
`visibility()` over `usedVisibility()` (effectively ignoring all visibility adjustment).

(WebCore::HitTestRequest::assertConsistentType):
(WebCore::HitTestRequest::HitTestRequest):
(WebCore::HitTestRequest::userTriggered const):
* Source/WebCore/rendering/HitTestSource.h: Added.
* Source/WebCore/rendering/RenderBlock.cpp:
(WebCore::positionForPointRespectingEditingBoundaries):
(WebCore::RenderBlock::positionForPointWithInlineChildren):
(WebCore::isChildHitTestCandidate):
(WebCore::RenderBlock::positionForPoint):
* Source/WebCore/rendering/RenderBlock.h:
* Source/WebCore/rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::positionForPointWithInlineChildren):
(WebCore::RenderBlockFlow::positionForPoint):
* Source/WebCore/rendering/RenderBlockFlow.h:
* Source/WebCore/rendering/RenderBox.cpp:
(WebCore::RenderBox::positionForPoint):
* Source/WebCore/rendering/RenderBox.h:
* Source/WebCore/rendering/RenderElementInlines.h:
(WebCore::RenderElement::visibleToHitTesting const):
* Source/WebCore/rendering/RenderFileUploadControl.cpp:
(WebCore::RenderFileUploadControl::positionForPoint):
* Source/WebCore/rendering/RenderFileUploadControl.h:
* Source/WebCore/rendering/RenderFragmentContainer.cpp:
(WebCore::RenderFragmentContainer::positionForPoint):
* Source/WebCore/rendering/RenderFragmentContainer.h:
* Source/WebCore/rendering/RenderInline.cpp:
(WebCore::RenderInline::positionForPoint):
* Source/WebCore/rendering/RenderInline.h:
* Source/WebCore/rendering/RenderLineBreak.cpp:
(WebCore::RenderLineBreak::positionForPoint):
* Source/WebCore/rendering/RenderLineBreak.h:
* Source/WebCore/rendering/RenderMultiColumnSet.cpp:
(WebCore::RenderMultiColumnSet::positionForPoint):
* Source/WebCore/rendering/RenderMultiColumnSet.h:
* Source/WebCore/rendering/RenderObject.cpp:
(WebCore::RenderObject::positionForPoint):
* Source/WebCore/rendering/RenderObject.h:

Plumb this new `HitTestRequest` flag through `RenderObject::positionForPoint()`, and propagate it
through all call sites and subclass implementations, recursively.

* Source/WebCore/rendering/RenderReplaced.cpp:
(WebCore::RenderReplaced::paint):
* Source/WebCore/rendering/RenderReplaced.h:
* Source/WebCore/rendering/RenderText.cpp:
(WebCore::RenderText::positionForPoint):
* Source/WebCore/rendering/RenderText.h:
* Source/WebCore/rendering/style/RenderStyle.h:
* Source/WebCore/rendering/style/RenderStyleInlines.h:
(WebCore::isVisibleToHitTesting):
* Source/WebCore/rendering/svg/RenderSVGImage.cpp:
(WebCore::RenderSVGImage::nodeAtPoint):
* Source/WebCore/rendering/svg/RenderSVGInlineText.cpp:
(WebCore::RenderSVGInlineText::positionForPoint):
* Source/WebCore/rendering/svg/RenderSVGInlineText.h:
* Source/WebCore/rendering/svg/RenderSVGShape.cpp:
(WebCore::RenderSVGShape::nodeAtPoint):
* Source/WebCore/rendering/svg/RenderSVGText.cpp:
(WebCore::RenderSVGText::nodeAtFloatPoint):
(WebCore::RenderSVGText::nodeAtPoint):
(WebCore::RenderSVGText::positionForPoint):
* Source/WebCore/rendering/svg/RenderSVGText.h:
* Source/WebCore/rendering/svg/SVGInlineTextBox.cpp:
(WebCore::SVGInlineTextBox::nodeAtPoint):
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGImage.cpp:
(WebCore::LegacyRenderSVGImage::nodeAtFloatPoint):
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGShape.cpp:
(WebCore::LegacyRenderSVGShape::nodeAtFloatPoint):
* Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp:
(WebKit::WebAutomationSessionProxy::computeElementLayout):
* Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocumentGtk.cpp:
(webkit_dom_document_element_from_point):
(webkit_dom_document_caret_range_from_point):
* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::selectionPositionInformation):
* Source/WebKitLegacy/mac/DOM/DOMDocument.mm:
(-[DOMDocument elementFromPoint:y:]):
(-[DOMDocument caretRangeFromPoint:y:]):

Canonical link: https://commits.webkit.org/276762@main



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list