[webkit-changes] [WebKit/WebKit] 6cf874: [Remote Inspection] Automatically adjust visibilit...

Wenson Hsieh noreply at github.com
Tue Mar 26 14:02:42 PDT 2024


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

  Changed paths:
    A LayoutTests/fast/element-targeting/target-reinserted-elements-expected.html
    A LayoutTests/fast/element-targeting/target-reinserted-elements.html
    M LayoutTests/resources/ui-helper.js
    M Source/WebCore/Headers.cmake
    M Source/WebCore/Sources.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    R Source/WebCore/page/ElementTargeting.cpp
    R Source/WebCore/page/ElementTargeting.h
    A Source/WebCore/page/ElementTargetingController.cpp
    A Source/WebCore/page/ElementTargetingController.h
    M Source/WebCore/page/Page.cpp
    M Source/WebCore/page/Page.h
    M Source/WebKit/WebProcess/WebPage/WebPage.cpp

  Log Message:
  -----------
  [Remote Inspection] Automatically adjust visibility when repeatedly adjusting visibility for elements in the same area
https://bugs.webkit.org/show_bug.cgi?id=271676

Reviewed by Megan Gardner.

Add support for automatically adjusting visibility for elements in the viewport, under some very
specific circumstances:

1.  We've repeatedly (i.e. at least twice) adjusted visibility for an element in the the same place,
    relative to the viewport.

2.  This "repeated adjustment area" contains an out of flow element.

Under these circumstances, we'll automatically adjust the visibility of any out of flow element that
meets the criteria in (2). See comments below for more details.

* LayoutTests/fast/element-targeting/target-reinserted-elements-expected.html: Added.
* LayoutTests/fast/element-targeting/target-reinserted-elements.html: Added.
* LayoutTests/resources/ui-helper.js:

Add a new layout test to exercise this change.

(window.UIHelper.adjustVisibilityForFrontmostTarget):
(window.UIHelper):

For convenience, augment this static helper to take a single element as the first argument and hit-
test in the center of the element.

* Source/WebCore/Headers.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/page/ElementTargetingController.cpp: Renamed from Source/WebCore/page/ElementTargeting.cpp.

Rename `ElementTargeting.{h|cpp}` to `ElementTargetingController.{h|cpp}`, and pull the current
standalone utility functions into instance methods on the new controller class. This refactoring
allows us to modify and consult state (i.e., `Region`s that track previously-adjusted rects in
client coordinates) when automatically applying visibility adjustment (only when the criteria above
are met).

(WebCore::ElementTargetingController::ElementTargetingController):
(WebCore::elementAndAncestorsAreOnlyChildren):
(WebCore::querySelectorMatchesOneElement):
(WebCore::childIndexByType):
(WebCore::computeIDSelector):
(WebCore::computeClassSelector):
(WebCore::selectorForElementRecursive):
(WebCore::parentRelativeSelectorRecursive):
(WebCore::selectorsForTarget):
(WebCore::computeOffsetEdges):
(WebCore::collectChildFrameIdentifiers):
(WebCore::targetedElementInfo):
(WebCore::findOnlyMainElement):
(WebCore::isTargetCandidate):

Pull this lambda out into a static helper, for use in `adjustVisibilityInRepeatedlyTargetedRegions`.

(WebCore::ElementTargetingController::findTargets):
(WebCore::computeClientRect):
(WebCore::ElementTargetingController::adjustVisibility):

When performing visibility adjustment, keep track of `Region`s where we've previously performed
visibility adjustment (relative to client coordinates). If we adjust visibility for an element in
the same place again, add the intersecting rect to `m_repeatedAdjustmentClientRegion`, so that we'll
automatically apply visibility adjustment to any element that is contained within the same region
moving forward.

(WebCore::adjustRegionAfterViewportSizeChange):
(WebCore::ElementTargetingController::adjustVisibilityInRepeatedlyTargetedRegions):

Implement the main logic for automatically carrying out visibility adjustment. Here, we adjust
visibility for all out-of-flow elements that happen to be contained (in client coordinates) within
repeatedly targeted regions (which are tracked using `m_repeatedAdjustmentClientRegion`).

If the viewport size changes, we also adjust all rects in `m_adjustmentClientRegion` and
`m_repeatedAdjustmentClientRegion`, such that elements that are (likely) fixed near the top, left,
bottom, or right of the viewport will continue to be fixed to the same locations.

(WebCore::ElementTargetingController::resetAdjustmentRegions):
* Source/WebCore/page/ElementTargetingController.h: Renamed from Source/WebCore/page/ElementTargeting.h.
* Source/WebCore/page/Page.cpp:

Add a `ElementTargetingController` to `Page`, as well as a new rendering update step to apply
automatic visibility adjustments if necessary.

(WebCore::Page::Page):
(WebCore::Page::checkedElementTargetingController):
(WebCore::Page::didCommitLoad):

Reset `ElementTargetingController`'s adjustment regions when committing a load.

(WebCore::Page::updateRendering):
(WebCore::operator<<):
* Source/WebCore/page/Page.h:
(WebCore::Page::elementTargetingController):
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::requestTargetedElement):
(WebKit::WebPage::adjustVisibilityForTargetedElements):

Switch to the new instance methods on `ElementTargetingController`.

Canonical link: https://commits.webkit.org/276709@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