Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Selection API] Change getComposedRanges() from rest parameter to a dictionary #47523

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dom/ranges/Range-isPointInRange-shadowdom.tentative.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

window.getSelection().setBaseAndExtent(start.firstChild, 3, end.firstChild, 3);

const composedRange = window.getSelection().getComposedRanges(shadowRoot)[0];
const composedRange = window.getSelection().getComposedRanges({ shadowRoots: [shadowRoot] })[0];
// Sanity check to make sure we have selected something across the shadow boundary.
assert_true(composedRange.startContainer == start.firstChild);
assert_true(composedRange.startOffset == 3);
Expand All @@ -40,7 +40,6 @@
}, "isPointInRange() test for collapsed selection");

test(function() {
assert_implements(window.getSelection().getComposedRanges, "GetComposedRanges is not supported");
const start = document.getElementById("start");
const shadowRoot = document.getElementById("host").shadowRoot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
assert_equals(sel.focusNode, outer.firstChild);
assert_equals(sel.focusOffset, 2);

const composedRange = sel.getComposedRanges(host.shadowRoot)[0];
const composedRange = sel.getComposedRanges({ shadowRoots: [host.shadowRoot] })[0];
assert_equals(composedRange.startContainer, slotted.firstChild);
assert_equals(composedRange.startOffset, 3);
assert_equals(composedRange.endContainer, outer.firstChild);
Expand Down
10 changes: 5 additions & 5 deletions shadow-dom/selection-collapse-and-extend.tentative.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
const textNode = shadowRoot.querySelector('p').firstChild;
getSelection().removeAllRanges();
getSelection().collapse(textNode, 5);
const ranges = getSelection().getComposedRanges(shadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, textNode);
assert_equals(ranges[0].startOffset, 5);
Expand All @@ -34,7 +34,7 @@
const textNode = shadowRoot.querySelector('p').firstChild;
getSelection().removeAllRanges();
getSelection().collapse(textNode, 5);
const ranges = getSelection().getComposedRanges(shadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 0);
}, 'collapse abort steps when called with a disconnected node inside a shadow tree');

Expand All @@ -46,10 +46,10 @@
const textNode = shadowRoot.querySelector('p').firstChild;
getSelection().removeAllRanges();
getSelection().collapse(textNode, 5);
let ranges = getSelection().getComposedRanges(shadowRoot);
let ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 1);
getSelection().extend(textNode, 11);
ranges = getSelection().getComposedRanges(shadowRoot);
ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, textNode);
assert_equals(ranges[0].startOffset, 5);
Expand All @@ -66,7 +66,7 @@
getSelection().removeAllRanges();
getSelection().collapse(container, 0);
getSelection().extend(textNode, 5);
const ranges = getSelection().getComposedRanges(shadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, container);
assert_equals(ranges[0].startOffset, 0);
Expand Down
32 changes: 16 additions & 16 deletions shadow-dom/selection-getComposedRanges-collapsed.tentative.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@
assert_equals(sel.getComposedRanges()[0].endContainer, container);
assert_equals(sel.getComposedRanges()[0].endOffset, 4);

assert_equals(sel.getComposedRanges(c)[0].startContainer, c);
assert_equals(sel.getComposedRanges(c)[0].startOffset, 0);
assert_equals(sel.getComposedRanges(c)[0].endContainer, container);
assert_equals(sel.getComposedRanges(c)[0].endOffset, 4);
assert_equals(sel.getComposedRanges({ shadowRoots: [c] })[0].startContainer, c);
assert_equals(sel.getComposedRanges({ shadowRoots: [c] })[0].startOffset, 0);
assert_equals(sel.getComposedRanges({ shadowRoots: [c] })[0].endContainer, container);
assert_equals(sel.getComposedRanges({ shadowRoots: [c] })[0].endOffset, 4);

assert_equals(sel.getComposedRanges(d)[0].startContainer, container);
assert_equals(sel.getComposedRanges(d)[0].startOffset, 1);
assert_equals(sel.getComposedRanges(d)[0].endContainer, d);
assert_equals(sel.getComposedRanges(d)[0].endOffset, 0);
assert_equals(sel.getComposedRanges({ shadowRoots: [d] })[0].startContainer, container);
assert_equals(sel.getComposedRanges({ shadowRoots: [d] })[0].startOffset, 1);
assert_equals(sel.getComposedRanges({ shadowRoots: [d] })[0].endContainer, d);
assert_equals(sel.getComposedRanges({ shadowRoots: [d] })[0].endOffset, 0);

assert_equals(sel.getComposedRanges(c, d)[0].startContainer, c);
assert_equals(sel.getComposedRanges(c, d)[0].startOffset, 0);
assert_equals(sel.getComposedRanges(c, d)[0].endContainer, d);
assert_equals(sel.getComposedRanges(c, d)[0].endOffset, 0);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].startContainer, c);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].startOffset, 0);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].endContainer, d);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].endOffset, 0);

// Re-setting the same range should never change the output
sel.setBaseAndExtent(c, 0, d, 0);
Expand All @@ -73,9 +73,9 @@
assert_equals(sel.getRangeAt(0).endContainer, d);
assert_equals(sel.getRangeAt(0).endOffset, 0);

assert_equals(sel.getComposedRanges(c, d)[0].startContainer, c);
assert_equals(sel.getComposedRanges(c, d)[0].startOffset, 0);
assert_equals(sel.getComposedRanges(c, d)[0].endContainer, d);
assert_equals(sel.getComposedRanges(c, d)[0].endOffset, 0);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].startContainer, c);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].startOffset, 0);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].endContainer, d);
assert_equals(sel.getComposedRanges({ shadowRoots: [c, d] })[0].endOffset, 0);
}, 'Setting the range to nodes in different shadow trees collapses ordinary ranges, but does not collapse composed ranges.');
</script>
14 changes: 7 additions & 7 deletions shadow-dom/selection-getComposedRanges.tentative.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
container.innerHTML = 'hello, world';
getSelection().setBaseAndExtent(container.firstChild, 0, container.firstChild, 5);
try {
getSelection().getComposedRanges(container);
getSelection().getComposedRanges({ shadowRoots: [container] });
assert_unreached('executed without error; want error');
} catch (e) {
assert_equals(e.message, "Failed to execute 'getComposedRanges' on 'Selection': parameter 1 is not of type 'ShadowRoot'.");
assert_equals(e.message, "Failed to execute 'getComposedRanges' on 'Selection': Failed to read the 'shadowRoots' property from 'GetComposedRangesOptions': Failed to convert value to 'ShadowRoot'.");
}
}, 'getComposedRanges should fail if argument is not a shadow root');

Expand Down Expand Up @@ -53,7 +53,7 @@
const shadowRoot = host.attachShadow({mode: 'closed'});
shadowRoot.innerHTML = 'hello, world';
getSelection().setBaseAndExtent(shadowRoot.firstChild, 0, shadowRoot.firstChild, 5);
const ranges = getSelection().getComposedRanges(shadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, shadowRoot.firstChild);
assert_equals(ranges[0].startOffset, 0);
Expand Down Expand Up @@ -95,7 +95,7 @@
const shadowRoot = host.attachShadow({mode: 'closed'});
shadowRoot.innerHTML = 'hello, world';
getSelection().setBaseAndExtent(shadowRoot.firstChild, 7, container, 2);
const ranges = getSelection().getComposedRanges(shadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [shadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, shadowRoot.firstChild);
assert_equals(ranges[0].startOffset, 7);
Expand Down Expand Up @@ -129,7 +129,7 @@
const innerShadowRoot = innerHost.attachShadow({mode: 'closed'});
innerShadowRoot.innerHTML = 'some text';
getSelection().setBaseAndExtent(innerShadowRoot.firstChild, 5, innerShadowRoot.firstChild, 9);
const ranges = getSelection().getComposedRanges(innerShadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [innerShadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, innerShadowRoot.firstChild);
assert_equals(ranges[0].startOffset, 5);
Expand All @@ -146,7 +146,7 @@
const innerShadowRoot = innerHost.attachShadow({mode: 'closed'});
innerShadowRoot.innerHTML = 'some text';
getSelection().setBaseAndExtent(innerShadowRoot.firstChild, 5, innerShadowRoot.firstChild, 9);
const ranges = getSelection().getComposedRanges(outerShadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [outerShadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, outerShadowRoot);
assert_equals(ranges[0].startOffset, 0);
Expand All @@ -163,7 +163,7 @@
const innerShadowRoot = innerHost.attachShadow({mode: 'closed'});
innerShadowRoot.innerHTML = 'some text';
getSelection().setBaseAndExtent(container.firstChild, 0, outerShadowRoot, 0);
const ranges = getSelection().getComposedRanges(innerShadowRoot);
const ranges = getSelection().getComposedRanges({ shadowRoots: [innerShadowRoot] });
assert_equals(ranges.length, 1);
assert_equals(ranges[0].startContainer, container.firstChild, "A");
assert_equals(ranges[0].startOffset, 0, "B");
Expand Down