style: Introduce TDocument::is_html_element and TDocument::quirks_mode.

This allows some code to read a bit nicer, and stop passing down quirks mode to
querySelector / querySelectorAll.
This commit is contained in:
Emilio Cobos Álvarez 2017-10-26 13:20:10 +02:00
parent bfa7cd7d9e
commit dd5cd29a61
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
5 changed files with 38 additions and 26 deletions

View file

@ -22,7 +22,7 @@ use properties::{AnimationRules, ComputedValues, PropertyDeclarationBlock};
use rule_tree::CascadeLevel;
use selector_parser::{AttrValue, PseudoClassStringArg, PseudoElement, SelectorImpl};
use selectors::Element as SelectorsElement;
use selectors::matching::{ElementSelectorFlags, VisitedHandlingMode};
use selectors::matching::{ElementSelectorFlags, QuirksMode, VisitedHandlingMode};
use selectors::sink::Push;
use servo_arc::{Arc, ArcBorrow};
use shared_lock::Locked;
@ -140,6 +140,12 @@ pub trait TDocument : Sized + Copy + Clone {
/// Get this document as a `TNode`.
fn as_node(&self) -> Self::ConcreteNode;
/// Returns whether this document is an HTML document.
fn is_html_document(&self) -> bool;
/// Returns the quirks mode of this document.
fn quirks_mode(&self) -> QuirksMode;
}
/// The `TNode` trait. This is the main generic trait over which the style

View file

@ -6,7 +6,7 @@
//! and Gecko.
use context::QuirksMode;
use dom::{TElement, TNode};
use dom::{TDocument, TElement, TNode};
use invalidation::element::invalidator::{Invalidation, InvalidationProcessor, InvalidationVector};
use selectors::{Element, NthIndexCache, SelectorList};
use selectors::matching::{self, MatchingContext, MatchingMode};
@ -308,7 +308,6 @@ pub fn query_selector<E, Q>(
root: E::ConcreteNode,
selector_list: &SelectorList<E::Impl>,
results: &mut Q::Output,
quirks_mode: QuirksMode,
)
where
E: TElement,
@ -316,6 +315,7 @@ where
{
use invalidation::element::invalidator::TreeStyleInvalidator;
let quirks_mode = root.owner_doc().quirks_mode();
let fast_result = query_selector_fast::<E, Q>(
root,
selector_list,

View file

@ -102,6 +102,14 @@ impl<'ld> TDocument for GeckoDocument<'ld> {
fn as_node(&self) -> Self::ConcreteNode {
GeckoNode(&self.0._base)
}
fn is_html_document(&self) -> bool {
self.0.mType == structs::root::nsIDocument_Type::eHTML
}
fn quirks_mode(&self) -> QuirksMode {
self.0.mCompatMode.into()
}
}
/// A simple wrapper over a non-null Gecko node (`nsINode`) pointer.
@ -172,12 +180,6 @@ impl<'ln> GeckoNode<'ln> {
(self.0).mBoolFlags
}
/// Owner document quirks mode getter.
#[inline]
pub fn owner_document_quirks_mode(&self) -> QuirksMode {
self.owner_doc().0.mCompatMode.into()
}
#[inline]
fn get_bool_flag(&self, flag: nsINode_BooleanFlag) -> bool {
self.bool_flags() & (1u32 << flag as u32) != 0
@ -665,12 +667,6 @@ impl<'le> GeckoElement<'le> {
unsafe { Gecko_GetDocumentLWTheme(node.owner_doc().0) }
}
/// Owner document quirks mode getter.
#[inline]
pub fn owner_document_quirks_mode(&self) -> QuirksMode {
self.as_node().owner_document_quirks_mode()
}
/// Only safe to call on the main thread, with exclusive access to the element and
/// its ancestors.
/// This function is also called after display property changed for SMIL animation.
@ -1614,7 +1610,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().0.mCompatMode == structs::nsCompatibility::eCompatibility_NavQuirks {
self.as_node().owner_doc().quirks_mode() == QuirksMode::Quirks {
hints.push(TABLE_COLOR_RULE.clone());
}
}
@ -2061,7 +2057,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().0.mType == structs::root::nsIDocument_Type::eHTML
self.as_node().owner_doc().is_html_document()
}
fn ignores_nth_child_selectors(&self) -> bool {