Skip to content

Commit

Permalink
Fix two more bugs in ShadowDOM Selection
Browse files Browse the repository at this point in the history
Bug #1: AbstractRange::(Mark|Unmark)Descendants should always use
the shadow tree of web-exposed shadow root, instead of using
light DOM elements of the host.

Bug #2: aRange could possibly create mCrossShadowBoundaryRange
first (due to boundaries are in different tree), and later
moves the boundaries to the same tree. When this happens, we
should remove mCrossShadowBoundaryRange and use the default
range to represent it.

Differential Revision: https://phabricator.services.mozilla.com/D207608

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1891783
gecko-commit: 0f54a84c32d1c22d71ff7307944b824639adbd6f
gecko-reviewers: jjaschke, smaug, dom-core
  • Loading branch information
sefeng211 authored and moz-wptsync-bot committed May 14, 2024
1 parent e40e7e0 commit e7895c2
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions selection/shadow-dom/select-later-become-slotted-content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!doctype html>
<meta charset=utf-8>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="host">
<span id="slotted">slotted</span>
</div>
<span id="outer">outer</span>
<script>
test(function(t) {
const sel = window.getSelection();
sel.setBaseAndExtent(slotted.firstChild, 3, outer.firstChild, 2);
host.attachShadow({mode: "open"}).innerHTML = "<slot></slot><span>inner</span>";

assert_equals(sel.anchorNode, slotted.firstChild);
assert_equals(sel.anchorOffset, 3);
assert_equals(sel.focusNode, outer.firstChild);
assert_equals(sel.focusOffset, 2);

const composedRange = sel.getComposedRanges(host.shadowRoot)[0];
assert_equals(composedRange.startContainer, slotted.firstChild);
assert_equals(composedRange.startOffset, 3);
assert_equals(composedRange.endContainer, outer.firstChild);
assert_equals(composedRange.endOffset, 2);

sel.empty();

assert_equals(sel.anchorNode, null);
assert_equals(sel.anchorOffset, 0);
assert_equals(sel.focusNode, null);
assert_equals(sel.focusOffset, 0);
}, "test to select a light DOM element and it becomes a slotted content after the selection");
</script>

0 comments on commit e7895c2

Please sign in to comment.