Skip to content
Permalink
Browse files
Support ::backdrop renderers on all elements
https://bugs.webkit.org/show_bug.cgi?id=248569
rdar://102833504

Reviewed by Darin Adler.

The fullscreen API needs to display ::backdrop pseudo elements for _all_ elements, with no exception.

- Add custom code in RenderBlock::nodeForHitTest to get correct handling for hit-testing
- Append backdrop renderers as children of RenderView, since not all individual renderers support children. RenderView is guaranteed to exist and it now centralizes all ::backdrop in one place.

* LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/modal-dialog-selection.html:
This was imported when we unprefixed -webkit-user-select, however this was reverted. The import script usually adds prefixes as necessary.
This didn't fail before, since the test selected nothing both with or without user-select.

* LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/modal-dialog-selection-expected.txt:
* LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/modal-dialog-selection-expected.txt: Added.
The new results are due to the hit-testing change, which now causes us to start a selection when we mousedown on the backdrop.
They pass properly on WebDriver, since the WKTR testdriver is incorrect, the mouse selection should start at the 3rd character, end at the 6th, not start outside of the backdrop.

* Source/WebCore/rendering/RenderBlock.cpp:
(WebCore::RenderBlock::nodeForHitTest const): Lookup associated renderer in top layer in case of ::backdrop to match behavior tested by backdrop-receives-element-events.html, common to other browsers.
* Source/WebCore/rendering/updating/RenderTreeUpdaterGeneratedContent.cpp:
(WebCore::RenderTreeUpdater::GeneratedContent::updateBackdropRenderer):

Canonical link: https://commits.webkit.org/257337@main
  • Loading branch information
nt1m committed Dec 4, 2022
1 parent ce269a3 commit fc7f34162f2456c11091af902071437be8911450
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
@@ -1,6 +1,6 @@
123456789A

FAIL By default, text inside a modal dialog can be selected assert_equals: expected "345678" but got ""
FAIL By default, text inside a modal dialog can be selected assert_equals: expected "345678" but got "123456789A"
PASS Clicking on backdrop doesn't select text
PASS 'user-select: none' prevents text from being selected

@@ -58,11 +58,11 @@
}, "Clicking on backdrop doesn't select text");

promise_test(async function() {
dialog.style.userSelect = "none";
dialog.style.webkitUserSelect = "none";

await selectSomeText();
assert_equals(getSelection().toString(), "");

dialog.style.userSelect = "";
dialog.style.webkitUserSelect = "";
}, "'user-select: none' prevents text from being selected");
</script>
@@ -0,0 +1,6 @@
123456789A

FAIL By default, text inside a modal dialog can be selected assert_equals: expected "345678" but got ""
PASS Clicking on backdrop doesn't select text
PASS 'user-select: none' prevents text from being selected

@@ -2033,6 +2033,19 @@ bool RenderBlock::isPointInOverflowControl(HitTestResult& result, const LayoutPo

Node* RenderBlock::nodeForHitTest() const
{
// If we're a ::backdrop pseudo-element, we should hit-test to the element that generated it.
// This matches the behavior that other browsers have.
if (style().styleType() == PseudoId::Backdrop) {
for (auto& element : document().topLayerElements()) {
if (!element->renderer())
continue;
ASSERT(element->renderer()->backdropRenderer());
if (element->renderer()->backdropRenderer() == this)
return element.ptr();
}
ASSERT_NOT_REACHED();
}

// If we are in the margins of block elements that are part of a
// continuation we're actually still inside the enclosing element
// that was split. Use the appropriate inner node.
@@ -175,9 +175,6 @@ void RenderTreeUpdater::GeneratedContent::updatePseudoElement(Element& current,

void RenderTreeUpdater::GeneratedContent::updateBackdropRenderer(RenderElement& renderer)
{
if (!renderer.canHaveGeneratedChildren())
return;

auto destroyBackdropIfNeeded = [&renderer, this]() {
if (WeakPtr backdropRenderer = renderer.backdropRenderer())
m_updater.m_builder.destroy(*backdropRenderer);
@@ -203,7 +200,7 @@ void RenderTreeUpdater::GeneratedContent::updateBackdropRenderer(RenderElement&
auto newBackdropRenderer = WebCore::createRenderer<RenderBlockFlow>(renderer.document(), WTFMove(newStyle));
newBackdropRenderer->initializeStyle();
renderer.setBackdropRenderer(*newBackdropRenderer.get());
m_updater.m_builder.attach(renderer, WTFMove(newBackdropRenderer), renderer.firstChild());
m_updater.m_builder.attach(renderer.view(), WTFMove(newBackdropRenderer));
}
}

0 comments on commit fc7f341

Please sign in to comment.