Classes/IDs case-sensitivity: get quirks mode from matching context.

This commit is contained in:
Simon Sapin 2017-06-10 23:22:34 +02:00
parent 5bccf98aa4
commit c5c1c1b350
7 changed files with 16 additions and 55 deletions

View file

@ -345,8 +345,6 @@ impl RawLayoutElementHelpers for Element {
} }
pub trait LayoutElementHelpers { pub trait LayoutElementHelpers {
#[allow(unsafe_code)]
unsafe fn in_quirks_mode_document_for_layout(&self) -> bool;
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe fn has_class_for_layout(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool; unsafe fn has_class_for_layout(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool;
#[allow(unsafe_code)] #[allow(unsafe_code)]
@ -374,12 +372,6 @@ pub trait LayoutElementHelpers {
} }
impl LayoutElementHelpers for LayoutJS<Element> { impl LayoutElementHelpers for LayoutJS<Element> {
#[allow(unsafe_code)]
#[inline]
unsafe fn in_quirks_mode_document_for_layout(&self) -> bool {
self.upcast::<Node>().owner_doc_for_layout().quirks_mode() == QuirksMode::Quirks
}
#[allow(unsafe_code)] #[allow(unsafe_code)]
#[inline] #[inline]
unsafe fn has_class_for_layout(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool { unsafe fn has_class_for_layout(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
@ -2514,10 +2506,6 @@ impl<'a> ::selectors::Element for Root<Element> {
Element::has_class(&**self, name, case_sensitivity) 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 { fn is_html_element_in_html_document(&self) -> bool {
self.html_element_in_html_document() self.html_element_in_html_document()
} }

View file

@ -15,10 +15,8 @@ use dom::node::{Node, document_from_node};
use dom::window::Window; use dom::window::Window;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use html5ever::{LocalName, QualName}; use html5ever::{LocalName, QualName};
use selectors::attr::CaseSensitivity;
use servo_atoms::Atom; use servo_atoms::Atom;
use std::cell::Cell; use std::cell::Cell;
use style::context::QuirksMode;
use style::str::split_html_space_chars; use style::str::split_html_space_chars;
pub trait CollectionFilter : JSTraceable { pub trait CollectionFilter : JSTraceable {
@ -201,11 +199,9 @@ impl HTMLCollection {
} }
impl CollectionFilter for ClassNameFilter { impl CollectionFilter for ClassNameFilter {
fn filter(&self, elem: &Element, _root: &Node) -> bool { fn filter(&self, elem: &Element, _root: &Node) -> bool {
let case_sensitivity = match document_from_node(elem).quirks_mode() { let case_sensitivity = document_from_node(elem)
QuirksMode::NoQuirks | .quirks_mode()
QuirksMode::LimitedQuirks => CaseSensitivity::CaseSensitive, .classes_and_ids_case_sensitivity();
QuirksMode::Quirks => CaseSensitivity::AsciiCaseInsensitive,
};
self.classes.iter().all(|class| elem.has_class(class, case_sensitivity)) self.classes.iter().all(|class| elem.has_class(class, case_sensitivity))
} }
} }

View file

@ -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 { fn is_html_element_in_html_document(&self) -> bool {
unsafe { unsafe {
self.element.html_element_in_html_document_for_layout() self.element.html_element_in_html_document_for_layout()
@ -1210,11 +1204,6 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> {
true true
} }
fn in_quirks_mode_document(&self) -> bool {
debug!("ServoThreadSafeLayoutElement::in_quirks_mode_document called");
false
}
#[inline] #[inline]
fn get_local_name(&self) -> &LocalName { fn get_local_name(&self) -> &LocalName {
self.element.get_local_name() self.element.get_local_name()

View file

@ -113,6 +113,17 @@ pub enum QuirksMode {
NoQuirks, 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 /// 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 /// used across many selectors for an element, so it's not appropriate for
/// transient data that applies to only a single selector. /// transient data that applies to only a single selector.
@ -667,20 +678,10 @@ fn matches_simple_selector<E, F>(
element.get_namespace() == ns.borrow() element.get_namespace() == ns.borrow()
} }
Component::ID(ref id) => { Component::ID(ref id) => {
let case_sensitivity = if element.in_quirks_mode_document() { element.has_id(id, context.shared.quirks_mode.classes_and_ids_case_sensitivity())
CaseSensitivity::AsciiCaseInsensitive
} else {
CaseSensitivity::CaseSensitive
};
element.has_id(id, case_sensitivity)
} }
Component::Class(ref class) => { Component::Class(ref class) => {
let case_sensitivity = if element.in_quirks_mode_document() { element.has_class(class, context.shared.quirks_mode.classes_and_ids_case_sensitivity())
CaseSensitivity::AsciiCaseInsensitive
} else {
CaseSensitivity::CaseSensitive
};
element.has_class(class, case_sensitivity)
} }
Component::AttributeInNoNamespaceExists { ref local_name, ref local_name_lower } => { Component::AttributeInNoNamespaceExists { ref local_name, ref local_name_lower } => {
let is_html = element.is_html_element_in_html_document(); let is_html = element.is_html_element_in_html_document();

View file

@ -63,11 +63,6 @@ pub trait Element: Sized + Debug {
/// Whether this element is a `link`. /// Whether this element is a `link`.
fn is_link(&self) -> bool; 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, fn has_id(&self,
id: &<Self::Impl as SelectorImpl>::Identifier, id: &<Self::Impl as SelectorImpl>::Identifier,
case_sensitivity: CaseSensitivity) case_sensitivity: CaseSensitivity)

View file

@ -1592,10 +1592,6 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
self.get_state().intersects(NonTSPseudoClass::AnyLink.state_flag()) 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 { fn has_id(&self, id: &Atom, case_sensitivity: CaseSensitivity) -> bool {
self.get_id().map_or(false, |atom| case_sensitivity.eq_atom(&atom, id)) self.get_id().map_or(false, |atom| case_sensitivity.eq_atom(&atom, id))
} }

View file

@ -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 { fn has_id(&self, id: &Atom, case_sensitivity: CaseSensitivity) -> bool {
match self.snapshot() { match self.snapshot() {
Some(snapshot) if snapshot.has_attrs() => { Some(snapshot) if snapshot.has_attrs() => {