From c5c1c1b350a016acb02a389ac3e5737d039796e7 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sat, 10 Jun 2017 23:22:34 +0200 Subject: [PATCH] Classes/IDs case-sensitivity: get quirks mode from matching context. --- components/script/dom/element.rs | 12 ------------ components/script/dom/htmlcollection.rs | 10 +++------- components/script/layout_wrapper.rs | 11 ----------- components/selectors/matching.rs | 25 +++++++++++++------------ components/selectors/tree.rs | 5 ----- components/style/gecko/wrapper.rs | 4 ---- components/style/restyle_hints.rs | 4 ---- 7 files changed, 16 insertions(+), 55 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index ce848be5e17..ebeef51de89 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -345,8 +345,6 @@ impl RawLayoutElementHelpers for Element { } pub trait LayoutElementHelpers { - #[allow(unsafe_code)] - unsafe fn in_quirks_mode_document_for_layout(&self) -> bool; #[allow(unsafe_code)] unsafe fn has_class_for_layout(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool; #[allow(unsafe_code)] @@ -374,12 +372,6 @@ pub trait LayoutElementHelpers { } impl LayoutElementHelpers for LayoutJS { - #[allow(unsafe_code)] - #[inline] - unsafe fn in_quirks_mode_document_for_layout(&self) -> bool { - self.upcast::().owner_doc_for_layout().quirks_mode() == QuirksMode::Quirks - } - #[allow(unsafe_code)] #[inline] unsafe fn has_class_for_layout(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool { @@ -2514,10 +2506,6 @@ impl<'a> ::selectors::Element for Root { Element::has_class(&**self, name, case_sensitivity) } - fn in_quirks_mode_document(&self) -> bool { - document_from_node(&**self).quirks_mode() == QuirksMode::Quirks - } - fn is_html_element_in_html_document(&self) -> bool { self.html_element_in_html_document() } diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs index 7c3cad306c4..814ea766f53 100644 --- a/components/script/dom/htmlcollection.rs +++ b/components/script/dom/htmlcollection.rs @@ -15,10 +15,8 @@ use dom::node::{Node, document_from_node}; use dom::window::Window; use dom_struct::dom_struct; use html5ever::{LocalName, QualName}; -use selectors::attr::CaseSensitivity; use servo_atoms::Atom; use std::cell::Cell; -use style::context::QuirksMode; use style::str::split_html_space_chars; pub trait CollectionFilter : JSTraceable { @@ -201,11 +199,9 @@ impl HTMLCollection { } impl CollectionFilter for ClassNameFilter { fn filter(&self, elem: &Element, _root: &Node) -> bool { - let case_sensitivity = match document_from_node(elem).quirks_mode() { - QuirksMode::NoQuirks | - QuirksMode::LimitedQuirks => CaseSensitivity::CaseSensitive, - QuirksMode::Quirks => CaseSensitivity::AsciiCaseInsensitive, - }; + let case_sensitivity = document_from_node(elem) + .quirks_mode() + .classes_and_ids_case_sensitivity(); self.classes.iter().all(|class| elem.has_class(class, case_sensitivity)) } } diff --git a/components/script/layout_wrapper.rs b/components/script/layout_wrapper.rs index 7b4b450c63e..1d28242e926 100644 --- a/components/script/layout_wrapper.rs +++ b/components/script/layout_wrapper.rs @@ -802,12 +802,6 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> { } } - fn in_quirks_mode_document(&self) -> bool { - unsafe { - self.element.in_quirks_mode_document_for_layout() - } - } - fn is_html_element_in_html_document(&self) -> bool { unsafe { self.element.html_element_in_html_document_for_layout() @@ -1210,11 +1204,6 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> { true } - fn in_quirks_mode_document(&self) -> bool { - debug!("ServoThreadSafeLayoutElement::in_quirks_mode_document called"); - false - } - #[inline] fn get_local_name(&self) -> &LocalName { self.element.get_local_name() diff --git a/components/selectors/matching.rs b/components/selectors/matching.rs index ea78a80bbf0..6e8702433fc 100644 --- a/components/selectors/matching.rs +++ b/components/selectors/matching.rs @@ -113,6 +113,17 @@ pub enum QuirksMode { NoQuirks, } +impl QuirksMode { + #[inline] + pub fn classes_and_ids_case_sensitivity(self) -> CaseSensitivity { + match self { + QuirksMode::NoQuirks | + QuirksMode::LimitedQuirks => CaseSensitivity::CaseSensitive, + QuirksMode::Quirks => CaseSensitivity::AsciiCaseInsensitive, + } + } +} + /// Data associated with the matching process for a element. This context is /// used across many selectors for an element, so it's not appropriate for /// transient data that applies to only a single selector. @@ -667,20 +678,10 @@ fn matches_simple_selector( element.get_namespace() == ns.borrow() } Component::ID(ref id) => { - let case_sensitivity = if element.in_quirks_mode_document() { - CaseSensitivity::AsciiCaseInsensitive - } else { - CaseSensitivity::CaseSensitive - }; - element.has_id(id, case_sensitivity) + element.has_id(id, context.shared.quirks_mode.classes_and_ids_case_sensitivity()) } Component::Class(ref class) => { - let case_sensitivity = if element.in_quirks_mode_document() { - CaseSensitivity::AsciiCaseInsensitive - } else { - CaseSensitivity::CaseSensitive - }; - element.has_class(class, case_sensitivity) + element.has_class(class, context.shared.quirks_mode.classes_and_ids_case_sensitivity()) } Component::AttributeInNoNamespaceExists { ref local_name, ref local_name_lower } => { let is_html = element.is_html_element_in_html_document(); diff --git a/components/selectors/tree.rs b/components/selectors/tree.rs index 97114de031d..99c07c6bf3b 100644 --- a/components/selectors/tree.rs +++ b/components/selectors/tree.rs @@ -63,11 +63,6 @@ pub trait Element: Sized + Debug { /// Whether this element is a `link`. fn is_link(&self) -> bool; - /// Whether this element is in a document that is in quirks mode. - /// - /// https://dom.spec.whatwg.org/#concept-document-quirks - fn in_quirks_mode_document(&self) -> bool; - fn has_id(&self, id: &::Identifier, case_sensitivity: CaseSensitivity) diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index abebcd2691c..2ec79c36372 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -1592,10 +1592,6 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { self.get_state().intersects(NonTSPseudoClass::AnyLink.state_flag()) } - fn in_quirks_mode_document(&self) -> bool { - self.as_node().owner_doc().mCompatMode == structs::nsCompatibility::eCompatibility_NavQuirks - } - fn has_id(&self, id: &Atom, case_sensitivity: CaseSensitivity) -> bool { self.get_id().map_or(false, |atom| case_sensitivity.eq_atom(&atom, id)) } diff --git a/components/style/restyle_hints.rs b/components/style/restyle_hints.rs index 0461a9e1456..0bdfdd4039b 100644 --- a/components/style/restyle_hints.rs +++ b/components/style/restyle_hints.rs @@ -821,10 +821,6 @@ impl<'a, E> Element for ElementWrapper<'a, E> } } - fn in_quirks_mode_document(&self) -> bool { - self.element.in_quirks_mode_document() - } - fn has_id(&self, id: &Atom, case_sensitivity: CaseSensitivity) -> bool { match self.snapshot() { Some(snapshot) if snapshot.has_attrs() => {