Skip to content

Commit 4dfee86

Browse files
sefeng211moz-wptsync-bot
authored andcommitted
Fix two more bugs in ShadowDOM Selection
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
1 parent fd41fbc commit 4dfee86

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<script src=/resources/testharness.js></script>
4+
<script src=/resources/testharnessreport.js></script>
5+
<div id="host">
6+
<span id="slotted">slotted</span>
7+
</div>
8+
<span id="outer">outer</span>
9+
<script>
10+
test(function(t) {
11+
const sel = window.getSelection();
12+
sel.setBaseAndExtent(slotted.firstChild, 3, outer.firstChild, 2);
13+
host.attachShadow({mode: "open"}).innerHTML = "<slot></slot><span>inner</span>";
14+
15+
assert_equals(sel.anchorNode, slotted.firstChild);
16+
assert_equals(sel.anchorOffset, 3);
17+
assert_equals(sel.focusNode, outer.firstChild);
18+
assert_equals(sel.focusOffset, 2);
19+
20+
const composedRange = sel.getComposedRanges(host.shadowRoot)[0];
21+
assert_equals(composedRange.startContainer, slotted.firstChild);
22+
assert_equals(composedRange.startOffset, 3);
23+
assert_equals(composedRange.endContainer, outer.firstChild);
24+
assert_equals(composedRange.endOffset, 2);
25+
26+
sel.empty();
27+
28+
assert_equals(sel.anchorNode, null);
29+
assert_equals(sel.anchorOffset, 0);
30+
assert_equals(sel.focusNode, null);
31+
assert_equals(sel.focusOffset, 0);
32+
}, "test to select a light DOM element and it becomes a slotted content after the selection");
33+
</script>

0 commit comments

Comments
 (0)