Fix the way the IS_CONNECTED flag is set

This commit is contained in:
Fernando Jiménez Moreno 2019-02-19 18:19:36 +01:00
parent 0d2f65baea
commit e66438de48
3 changed files with 13 additions and 16 deletions

View file

@ -14,7 +14,7 @@ use crate::dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods;
use crate::dom::bindings::codegen::Bindings::FunctionBinding::Function;
use crate::dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods;
use crate::dom::bindings::codegen::Bindings::NodeBinding::{GetRootNodeOptions, NodeMethods};
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use crate::dom::bindings::codegen::Bindings::ShadowRootBinding::ShadowRootBinding::ShadowRootMethods;
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use crate::dom::bindings::codegen::Bindings::WindowBinding::{ScrollBehavior, ScrollToOptions};
@ -2826,7 +2826,6 @@ impl VirtualMethods for Element {
let shadow_root = self.shadow_root.get().unwrap();
doc.unregister_shadow_root(&shadow_root);
let shadow_root = shadow_root.upcast::<Node>();
let shadow_root = shadow_root.upcast::<Node>();
shadow_root.set_flag(NodeFlags::IS_CONNECTED, false);
for node in shadow_root.children() {
node.set_flag(NodeFlags::IS_CONNECTED, false);
@ -3333,11 +3332,7 @@ impl Element {
/// <https://dom.spec.whatwg.org/#connected>
pub fn is_connected(&self) -> bool {
let node = self.upcast::<Node>();
let mut options = GetRootNodeOptions::empty();
options.composed = true; // shadow included.
let root = node.GetRootNode(&options);
root.is::<Document>()
self.upcast::<Node>().is_connected()
}
// https://html.spec.whatwg.org/multipage/#cannot-navigate

View file

@ -292,6 +292,7 @@ impl Node {
let parent_in_doc = self.is_in_doc();
let parent_in_shadow_tree = self.is_in_shadow_tree();
let parent_is_connected = self.is_connected();
for node in new_child.traverse_preorder(/* shadow including */ false) {
if parent_in_shadow_tree {
if let Some(shadow_root) = self.downcast::<ShadowRoot>() {
@ -300,18 +301,12 @@ impl Node {
node.set_owner_shadow_root(&*shadow_root);
}
}
let mut is_connected = parent_is_connected;
if !is_connected {
if let Some(element) = node.downcast::<Element>() {
is_connected = element.is_connected();
}
}
node.set_flag(NodeFlags::IS_IN_DOC, parent_in_doc);
node.set_flag(NodeFlags::IS_IN_SHADOW_TREE, parent_in_shadow_tree);
node.set_flag(NodeFlags::IS_CONNECTED, is_connected);
node.set_flag(NodeFlags::IS_CONNECTED, parent_is_connected);
// Out-of-document elements never have the descendants flag set.
debug_assert!(!node.get_flag(NodeFlags::HAS_DIRTY_DESCENDANTS));
vtable_for(&&*node).bind_to_tree(is_connected);
vtable_for(&&*node).bind_to_tree(parent_is_connected);
}
}
@ -1614,7 +1609,10 @@ impl Node {
#[allow(unrooted_must_root)]
pub fn new_document_node() -> Node {
Node::new_(NodeFlags::new() | NodeFlags::IS_IN_DOC, None)
Node::new_(
NodeFlags::new() | NodeFlags::IS_IN_DOC | NodeFlags::IS_CONNECTED,
None,
)
}
#[allow(unrooted_must_root)]

View file

@ -46,6 +46,10 @@ impl ShadowRoot {
document_fragment
.upcast::<Node>()
.set_flag(NodeFlags::IS_IN_SHADOW_TREE, true);
document_fragment.upcast::<Node>().set_flag(
NodeFlags::IS_CONNECTED,
host.upcast::<Node>().is_connected(),
);
ShadowRoot {
document_fragment,
document_or_shadow_root: DocumentOrShadowRoot::new(document.window()),