-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Selection API] Add composed range endpoints
We update Range API to support composed range. Previously, when setting the start/end range endpoints, if they are in different node trees, they will be collapsed. Now, if start/end are in different node trees, but same document, composed_range_ will be set to track those cross shadow tree endpoints. We update Selection::GetComposedRanges to use composed start and end to create a composed StaticRange. We fix Selection::GetComposedRanges to use IsShadowIncludingInclusiveAncestorOf for Rescoping and add a test. Change-Id: Ib46497382fb83809394499182b5c8e4ee08925b7 Bug: 40286116 Fixed: 335245347 Fixed: 355630554 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5744732 Reviewed-by: Mason Freed <masonf@chromium.org> Reviewed-by: Siye Liu <siliu@microsoft.com> Commit-Queue: Di Zhang <dizhangg@chromium.org> Cr-Commit-Position: refs/heads/main@{#1337611}
- Loading branch information
1 parent
7f4f309
commit 82f2066
Showing
3 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
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
81 changes: 81 additions & 0 deletions
81
shadow-dom/selection-getComposedRanges-collapsed.tentative.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,81 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<meta name="author" href="mailto:dizhangg@chromium.org"> | ||
<meta name="assert" content="Selection's getComposedRanges should return a sequence of static ranges"> | ||
<link rel="help" href="https://w3c.github.io/selection-api/#dom-selection-getcomposedranges"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<div id="container"> | ||
<div id="host1"> | ||
<template shadowrootmode=open>C</template> | ||
A - not slotted | ||
</div> | ||
<div id="host2"> | ||
<template shadowrootmode=open>D</template> | ||
<div id=b>B - not slotted</div> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
|
||
const c = host1.shadowRoot; | ||
const d = host2.shadowRoot; | ||
|
||
test(() => { | ||
const sel = getSelection(); | ||
sel.setBaseAndExtent(b, 0, c, 0); | ||
assert_equals(sel.getRangeAt(0).startContainer, b); | ||
assert_equals(sel.getRangeAt(0).startOffset, 0); | ||
assert_equals(sel.getRangeAt(0).endContainer, b); | ||
assert_equals(sel.getRangeAt(0).endOffset, 0); | ||
|
||
assert_equals(sel.getComposedRanges()[0].startContainer, b); | ||
assert_equals(sel.getComposedRanges()[0].startOffset, 0); | ||
assert_equals(sel.getComposedRanges()[0].endContainer, b); | ||
assert_equals(sel.getComposedRanges()[0].endOffset, 0); | ||
}, 'Setting the range to nodes that aren\'t in the same tree collapses both composed and non-composed ranges.'); | ||
|
||
test(() => { | ||
const sel = getSelection(); | ||
sel.setBaseAndExtent(c, 0, d, 0); | ||
|
||
assert_equals(sel.getRangeAt(0).startContainer, d); | ||
assert_equals(sel.getRangeAt(0).startOffset, 0); | ||
assert_equals(sel.getRangeAt(0).endContainer, d); | ||
assert_equals(sel.getRangeAt(0).endOffset, 0); | ||
|
||
assert_equals(sel.getComposedRanges()[0].startContainer, container); | ||
assert_equals(sel.getComposedRanges()[0].startOffset, 1); | ||
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(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(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); | ||
|
||
// Re-setting the same range should never change the output | ||
sel.setBaseAndExtent(c, 0, d, 0); | ||
assert_equals(sel.getRangeAt(0).startContainer, d); | ||
assert_equals(sel.getRangeAt(0).startOffset, 0); | ||
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); | ||
}, 'Setting the range to nodes in different shadow trees collapses ordinary ranges, but does not collapse composed ranges.'); | ||
</script> |
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