diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index c26b3a57315..aa039f593e2 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -187,6 +187,10 @@ impl<'ln> TNode for ServoLayoutNode<'ln> { } } + fn owner_doc(&self) -> Self::ConcreteDocument { + ServoLayoutDocument::from_layout_js(unsafe { self.node.owner_doc_for_layout() }) + } + fn traversal_parent(&self) -> Option> { self.parent_element() } @@ -778,7 +782,11 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> { fn is_html_element_in_html_document(&self) -> bool { unsafe { - self.element.html_element_in_html_document_for_layout() + if !self.element.is_html_element() { + return false; + } + + self.as_node().node.owner_doc_for_layout().is_html_document_for_layout() } } } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 66d18e1d0aa..13f2bf7ae78 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -446,7 +446,7 @@ pub trait LayoutElementHelpers { #[allow(unsafe_code)] unsafe fn get_rowspan(self) -> u32; #[allow(unsafe_code)] - unsafe fn html_element_in_html_document_for_layout(&self) -> bool; + unsafe fn is_html_element(&self) -> bool; fn id_attribute(&self) -> *const Option; fn style_attribute(&self) -> *const Option>>; fn local_name(&self) -> &LocalName; @@ -781,11 +781,8 @@ impl LayoutElementHelpers for LayoutDom { #[inline] #[allow(unsafe_code)] - unsafe fn html_element_in_html_document_for_layout(&self) -> bool { - if (*self.unsafe_get()).namespace != ns!(html) { - return false; - } - self.upcast::().owner_doc_for_layout().is_html_document_for_layout() + unsafe fn is_html_element(&self) -> bool { + (*self.unsafe_get()).namespace == ns!(html) } #[allow(unsafe_code)] diff --git a/components/style/dom.rs b/components/style/dom.rs index ff6ca9fa9d1..78e7199f5f2 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -166,6 +166,9 @@ pub trait TNode : Sized + Copy + Clone + Debug + NodeInfo + PartialEq { /// Get this node's next sibling. fn next_sibling(&self) -> Option; + /// Get the owner document of this node. + fn owner_doc(&self) -> Self::ConcreteDocument; + /// Iterate over the DOM children of a node. fn dom_children(&self) -> DomChildren { DomChildren(self.first_child()) diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 02c79b76799..058ccadc41c 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -175,7 +175,7 @@ impl<'ln> GeckoNode<'ln> { /// Owner document quirks mode getter. #[inline] pub fn owner_document_quirks_mode(&self) -> QuirksMode { - self.owner_doc().mCompatMode.into() + self.owner_doc().0.mCompatMode.into() } #[inline] @@ -183,11 +183,6 @@ impl<'ln> GeckoNode<'ln> { self.bool_flags() & (1u32 << flag as u32) != 0 } - fn owner_doc(&self) -> &'ln structs::nsIDocument { - debug_assert!(!self.node_info().mDocument.is_null()); - unsafe { &*self.node_info().mDocument } - } - /// WARNING: This logic is duplicated in Gecko's FlattenedTreeParentIsParent. /// Make sure to mirror any modifications in both places. fn flattened_tree_parent_is_parent(&self) -> bool { @@ -269,6 +264,12 @@ impl<'ln> TNode for GeckoNode<'ln> { unsafe { self.0.mNextSibling.as_ref().map(GeckoNode::from_content) } } + #[inline] + fn owner_doc(&self) -> Self::ConcreteDocument { + debug_assert!(!self.node_info().mDocument.is_null()); + GeckoDocument(unsafe { &*self.node_info().mDocument }) + } + fn traversal_parent(&self) -> Option> { self.flattened_tree_parent().and_then(|n| n.as_element()) } @@ -294,7 +295,7 @@ impl<'ln> TNode for GeckoNode<'ln> { #[inline] fn as_document(&self) -> Option { if self.is_document() { - Some(GeckoDocument(self.owner_doc())) + Some(self.owner_doc()) } else { None } @@ -625,7 +626,7 @@ impl<'le> GeckoElement<'le> { fn document_state(&self) -> DocumentState { let node = self.as_node(); unsafe { - let states = Gecko_DocumentState(node.owner_doc()); + let states = Gecko_DocumentState(node.owner_doc().0); DocumentState::from_bits_truncate(states) } } @@ -661,7 +662,7 @@ impl<'le> GeckoElement<'le> { #[inline] fn get_document_theme(&self) -> DocumentTheme { let node = self.as_node(); - unsafe { Gecko_GetDocumentLWTheme(node.owner_doc()) } + unsafe { Gecko_GetDocumentLWTheme(node.owner_doc().0) } } /// Owner document quirks mode getter. @@ -978,7 +979,7 @@ impl<'le> TElement for GeckoElement<'le> { } fn owner_doc_matches_for_testing(&self, device: &Device) -> bool { - self.as_node().owner_doc() as *const structs::nsIDocument == + self.as_node().owner_doc().0 as *const structs::nsIDocument == device.pres_context().mDocument.raw::() } @@ -1613,7 +1614,7 @@ impl<'le> TElement for GeckoElement<'le> { if self.get_local_name().as_ptr() == atom!("th").as_ptr() { hints.push(TH_RULE.clone()); } else if self.get_local_name().as_ptr() == atom!("table").as_ptr() && - self.as_node().owner_doc().mCompatMode == structs::nsCompatibility::eCompatibility_NavQuirks { + self.as_node().owner_doc().0.mCompatMode == structs::nsCompatibility::eCompatibility_NavQuirks { hints.push(TABLE_COLOR_RULE.clone()); } } @@ -2060,7 +2061,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { fn is_html_element_in_html_document(&self) -> bool { self.is_html_element() && - self.as_node().owner_doc().mType == structs::root::nsIDocument_Type::eHTML + self.as_node().owner_doc().0.mType == structs::root::nsIDocument_Type::eHTML } fn ignores_nth_child_selectors(&self) -> bool {