Bug 1907464 - Clear the shadow-crossing selection when the ParentChainChanged notification is called on the common ancestor r=jjaschke,dom-core

It's unclear from the spec about where the new selection should be,
so we just clear the selection at the moment.

Differential Revision: https://phabricator.services.mozilla.com/D216572
This commit is contained in:
Sean Feng
2024-07-15 15:29:05 +00:00
parent b7e4c25991
commit ccff0abd17
4 changed files with 23 additions and 0 deletions

View File

@@ -243,4 +243,13 @@ void CrossShadowBoundaryRange::CharacterDataChanged(
mOwner); mOwner);
} }
} }
// DOM mutation for shadow-crossing selection is not specified.
// Spec issue: https://github.com/w3c/selection-api/issues/168
void CrossShadowBoundaryRange::ParentChainChanged(nsIContent* aContent) {
MOZ_ASSERT(mCommonAncestor == aContent,
"Wrong ParentChainChanged notification");
MOZ_ASSERT(mOwner);
mOwner->ResetCrossShadowBoundaryRange();
}
} // namespace mozilla::dom } // namespace mozilla::dom

View File

@@ -58,6 +58,7 @@ class CrossShadowBoundaryRange final : public StaticRange,
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED
private: private:
explicit CrossShadowBoundaryRange(nsINode* aNode, nsRange* aOwner) explicit CrossShadowBoundaryRange(nsINode* aNode, nsRange* aOwner)

View File

@@ -0,0 +1,12 @@
<script>
window.addEventListener("DOMContentLoaded", () => {
let sel = document.getSelection()
sel.setPosition(a.offsetParent.attachShadow({mode: "open"}), 0)
sel.extend(b, 0)
c.replaceWith("1")
document.documentElement.innerHTML = document.documentElement.innerHTML
})
</script>
<shadow id="a">
<style id="b"></style>
<font id="c">a</font>

View File

@@ -280,3 +280,4 @@ load 1890888.html
load 1890899.html load 1890899.html
load 1896225.html load 1896225.html
load 1897248.html load 1897248.html
load 1907464.html