-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Remote Inspection] Make it possible to target ::before/::after pseud…
…o elements https://bugs.webkit.org/show_bug.cgi?id=271791 Reviewed by Megan Gardner. (...and also incorporates suggestions from Antti). Add support for targeting `::before` and `::after` pseudo elements, for visibility adjustment. See below for more details. * LayoutTests/fast/element-targeting/target-pseudo-elements-expected.html: Added. * LayoutTests/fast/element-targeting/target-pseudo-elements.html: Added. Add a new layout test to exercise the change (targeting both `after` and `before` pseudo elements). * Source/WebCore/Headers.cmake: Add a new WebCore header that just contains the new `VisibilityAdjustment` enum values. * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/dom/Element.cpp: (WebCore::Element::visibilityAdjustment const): (WebCore::Element::addVisibilityAdjustment): (WebCore::Element::isVisibilityAdjustmentRoot const): Deleted. (WebCore::Element::setIsVisibilityAdjustmentRoot): Deleted. Refactor this code — instead of having a single boolean flag that indicates whether the element is a visibility adjustment root, turn it into an OptionSet with up to 3 bits (subtree, `::before` pseudo element and `::after` pseudo element). * Source/WebCore/dom/Element.h: * Source/WebCore/dom/ElementRareData.cpp: * Source/WebCore/dom/ElementRareData.h: (WebCore::ElementRareData::visibilityAdjustment const): (WebCore::ElementRareData::addVisibilityAdjustment): (WebCore::ElementRareData::isVisibilityAdjustmentRoot const): Deleted. (WebCore::ElementRareData::setIsVisibilityAdjustmentRoot): Deleted. See above for more details — replace the single `isVisibilityAdjustmentRoot` flag with a new `OptionSet`. * Source/WebCore/dom/VisibilityAdjustment.h: Copied from Source/WebCore/page/ElementTargetingTypes.h. * Source/WebCore/page/ElementTargetingController.cpp: (WebCore::selectorsForTarget): (WebCore::targetedElementInfo): Teach this to emit `::before` and `::after` selectors for pseudo elements. (WebCore::isTargetCandidate): Teach this helper function to always consider rendered `::before` and `::after` pseudo elements to be candidates for target selection, since adjusting visibility for these elements is unlikely to adversely affect "main content" on the page. (WebCore::elementToAdjust): (WebCore::adjustmentToApply): (WebCore::adjustVisibilityIfNeeded): Split some of this functionality into multiple helper methods, to make it easier to determine how an element should be marked for visibility adjustment. In particular, for before and after pseudo elements, we mark the pseudo host element with `VisibilityAdjustment::{Before|After}Pseudo`, and for everything else, we mark the element subtree (i.e. the same as what we currently do). (WebCore::ElementTargetingController::adjustVisibility): (WebCore::ElementTargetingController::adjustVisibilityInRepeatedlyTargetedRegions): * Source/WebCore/page/ElementTargetingTypes.h: * Source/WebCore/style/StyleAdjuster.cpp: (WebCore::Style::Adjuster::adjust const): (WebCore::Style::Adjuster::adjustVisibilityForPseudoElement): Honor `VisibilityAdjustment::{BeforePseudo|AfterPseudo}` on the host element, by marking the corresponding pseudo element style with visibility adjustment. * Source/WebCore/style/StyleAdjuster.h: * Source/WebCore/style/StyleResolver.cpp: (WebCore::Style::Resolver::styleForPseudoElement): * Source/WebCore/style/StyleTreeResolver.cpp: (WebCore::Style::TreeResolver::resolveStartingStyle const): * Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in: * Source/WebKit/UIProcess/API/APITargetedElementInfo.h: * Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.h: * Source/WebKit/UIProcess/API/Cocoa/_WKTargetedElementInfo.mm: (-[_WKTargetedElementInfo isPseudoElement]): Add a new SPI property to surface whether or not the targeted element is a pseudo-element to the client. Canonical link: https://commits.webkit.org/276816@main
- Loading branch information
Showing
19 changed files
with
219 additions
and
22 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
LayoutTests/fast/element-targeting/target-pseudo-elements-expected.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] --> | ||
<html> | ||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
</head> | ||
<body>This test requires WebKitTestRunner</body> | ||
</html> |
46 changes: 46 additions & 0 deletions
46
LayoutTests/fast/element-targeting/target-pseudo-elements.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] --> | ||
<html> | ||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<script src="../../resources/ui-helper.js"></script> | ||
<style> | ||
body::after { | ||
top: 0; | ||
left: 0; | ||
z-index: 100; | ||
} | ||
|
||
body::before { | ||
bottom: 0; | ||
right: 0; | ||
z-index: 10; | ||
} | ||
|
||
body::before, body::after { | ||
position: fixed; | ||
display: block; | ||
content: " "; | ||
width: 128px; | ||
height: 128px; | ||
background-image: url(../images/resources/green-256x256.png); | ||
background-repeat: no-repeat; | ||
background-size: 128px 128px; | ||
} | ||
</style> | ||
</head> | ||
<body>This test requires WebKitTestRunner</body> | ||
<script> | ||
addEventListener("load", async event => { | ||
testRunner.waitUntilDone(); | ||
const firstSelector = await UIHelper.adjustVisibilityForFrontmostTarget(64, 64); | ||
const secondSelector = await UIHelper.adjustVisibilityForFrontmostTarget(innerWidth - 64, innerHeight - 64); | ||
|
||
if (firstSelector.toLowerCase() !== "body::after") | ||
document.writeln(`FAIL: first selector was ${firstSelector}`); | ||
|
||
if (secondSelector.toLowerCase() !== "body::before") | ||
document.writeln(`FAIL: second selector was ${secondSelector}`); | ||
testRunner.notifyDone(); | ||
}); | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
namespace WebCore { | ||
|
||
enum class VisibilityAdjustment : uint8_t { | ||
Subtree = 1 << 0, | ||
BeforePseudo = 1 << 1, | ||
AfterPseudo = 1 << 2, | ||
}; | ||
|
||
} // namespace WebCore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.