style: Add TNode::owner_doc.

This commit is contained in:
Emilio Cobos Álvarez 2017-10-26 13:03:02 +02:00
parent 4d4fa69018
commit bfa7cd7d9e
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
4 changed files with 28 additions and 19 deletions

View file

@ -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<ServoLayoutElement<'ln>> {
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()
}
}
}

View file

@ -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<Atom>;
fn style_attribute(&self) -> *const Option<Arc<Locked<PropertyDeclarationBlock>>>;
fn local_name(&self) -> &LocalName;
@ -781,11 +781,8 @@ impl LayoutElementHelpers for LayoutDom<Element> {
#[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::<Node>().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)]

View file

@ -166,6 +166,9 @@ pub trait TNode : Sized + Copy + Clone + Debug + NodeInfo + PartialEq {
/// Get this node's next sibling.
fn next_sibling(&self) -> Option<Self>;
/// 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<Self> {
DomChildren(self.first_child())

View file

@ -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<GeckoElement<'ln>> {
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<Self::ConcreteDocument> {
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::<structs::nsIDocument>()
}
@ -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 {