Skip to content

Commit

Permalink
Classes/IDs case-sensitivity: get quirks mode from matching context.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jun 12, 2017
1 parent 5bccf98 commit c5c1c1b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 55 deletions.
12 changes: 0 additions & 12 deletions components/script/dom/element.rs
Expand Up @@ -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)]
Expand Down Expand Up @@ -374,12 +372,6 @@ pub trait LayoutElementHelpers {
}

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)]
#[inline]
unsafe fn has_class_for_layout(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
Expand Down Expand Up @@ -2514,10 +2506,6 @@ impl<'a> ::selectors::Element for Root<Element> {
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()
}
Expand Down
10 changes: 3 additions & 7 deletions components/script/dom/htmlcollection.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
}
Expand Down
11 changes: 0 additions & 11 deletions components/script/layout_wrapper.rs
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
25 changes: 13 additions & 12 deletions components/selectors/matching.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -667,20 +678,10 @@ fn matches_simple_selector<E, F>(
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();
Expand Down
5 changes: 0 additions & 5 deletions components/selectors/tree.rs
Expand Up @@ -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: &<Self::Impl as SelectorImpl>::Identifier,
case_sensitivity: CaseSensitivity)
Expand Down
4 changes: 0 additions & 4 deletions components/style/gecko/wrapper.rs
Expand Up @@ -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))
}
Expand Down
4 changes: 0 additions & 4 deletions components/style/restyle_hints.rs
Expand Up @@ -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() => {
Expand Down

0 comments on commit c5c1c1b

Please sign in to comment.