script: Fully implement DocumentOrShadowRoot#activeElement#43861
Conversation
|
|
||
| impl Node { | ||
| /// <https://dom.spec.whatwg.org/#concept-tree-root> | ||
| pub(crate) fn root(&self) -> DomRoot<Node> { |
There was a problem hiding this comment.
I am surprised we didn't have this before, but I don't remember what the method was. Also can't find it right now...
There was a problem hiding this comment.
There is also an Element::root_element(), but this returns the "document element" for the light tree, which isn't really in the specification and isn't what we need here.
There was a problem hiding this comment.
I'll use Node::GetRootNode as suggested by @simonwuelker below.
There was a problem hiding this comment.
Aah yes that's the one! Maybe add a link to the spec to that method so that we can find it.
| /// <https://dom.spec.whatwg.org/#concept-tree-root> | ||
| pub(crate) fn root(&self) -> DomRoot<Node> { | ||
| if self.is_in_a_document_tree() { | ||
| DomRoot::upcast(self.owner_document()) | ||
| } else { | ||
| self.inclusive_ancestors(ShadowIncluding::No) | ||
| .filter_map(DomRoot::downcast) | ||
| .last() | ||
| .expect("We know inclusive_ancestors will return `self` which is an element") | ||
| } | ||
| } |
There was a problem hiding this comment.
Node::GetRootNode(Default::default()) does the same, and its a bit more optimized, so please use that instead.
c706724 to
c06ef50
Compare
| if let Some(candidate) = DomRoot::downcast::<Element>(candidate.clone()) { | ||
| return Some(candidate); | ||
| } | ||
| assert_eq!(&*candidate, document.upcast::<Node>()); |
There was a problem hiding this comment.
| assert_eq!(&*candidate, document.upcast::<Node>()); | |
| assert!(candidate.is::<Document>()); |
`DocumentOrShadowRoot#activeElement` should return retarged results. What that means is that if the DOM anchor of the `Document`'s focused focusable area is within a shadow root, `Document#activeElement` should return the shadow host. This change implements that behavior, properly returning the `activeElement` from both `Document` and `ShadowRoot`. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
c06ef50 to
be1ddca
Compare
DocumentOrShadowRoot#activeElementshould return retargeted results.What that means is that if the DOM anchor of the
Document's focusedfocusable area is within a shadow root,
Document#activeElementshouldreturn the shadow host. This change implements that behavior, properly
returning the
activeElementfrom bothDocumentandShadowRoot.Testing: This causes a decent number of WPT tests and subtests to start
passing. One subtest starts to fail, because it uses the
autofocusattributewhich we do not yet support.