diff options
author | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2016-01-28 14:42:15 +0100 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2016-02-03 02:11:31 +0100 |
commit | a1c830f1c13d75186d8d1a759ed73a0eac433179 (patch) | |
tree | 3c76ce5a1f9f9926b9a532060581dc88d49a6b36 /components/style/selector_impl.rs | |
parent | 9baa59a6b4de338be6cd65851694785d786cf492 (diff) | |
download | servo-a1c830f1c13d75186d8d1a759ed73a0eac433179.tar.gz servo-a1c830f1c13d75186d8d1a759ed73a0eac433179.zip |
Update rust-selectors
This commits updates rust-selectors to use the generic parser, and as
such it moves the element state into the style crate.
Diffstat (limited to 'components/style/selector_impl.rs')
-rw-r--r-- | components/style/selector_impl.rs | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/components/style/selector_impl.rs b/components/style/selector_impl.rs new file mode 100644 index 00000000000..74f2bcde91b --- /dev/null +++ b/components/style/selector_impl.rs @@ -0,0 +1,91 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use element_state::ElementState; +use selectors::parser::{ParserContext, SelectorImpl}; + +#[derive(Clone, Debug, PartialEq, HeapSizeOf)] +pub enum PseudoElement { + Before, + After, +} + +#[derive(Clone, Debug, PartialEq, HeapSizeOf)] +pub enum NonTSPseudoClass { + AnyLink, + Link, + Visited, + Active, + Focus, + Hover, + Enabled, + Disabled, + Checked, + Indeterminate, + ServoNonZeroBorder, +} + +impl NonTSPseudoClass { + pub fn state_flag(&self) -> ElementState { + use element_state::*; + use self::NonTSPseudoClass::*; + match *self { + Active => IN_ACTIVE_STATE, + Focus => IN_FOCUS_STATE, + Hover => IN_HOVER_STATE, + Enabled => IN_ENABLED_STATE, + Disabled => IN_DISABLED_STATE, + Checked => IN_CHECKED_STATE, + Indeterminate => IN_INDETERMINATE_STATE, + + AnyLink | + Link | + Visited | + ServoNonZeroBorder => ElementState::empty(), + } + } +} + +#[derive(Clone, Debug, PartialEq, HeapSizeOf)] +pub struct ServoSelectorImpl; + +impl SelectorImpl for ServoSelectorImpl { + type PseudoElement = PseudoElement; + type NonTSPseudoClass = NonTSPseudoClass; + + fn parse_non_ts_pseudo_class(context: &ParserContext, + name: &str) -> Result<NonTSPseudoClass, ()> { + use self::NonTSPseudoClass::*; + let pseudo_class = match_ignore_ascii_case! { name, + "any-link" => AnyLink, + "link" => Link, + "visited" => Visited, + "active" => Active, + "focus" => Focus, + "hover" => Hover, + "enabled" => Enabled, + "disabled" => Disabled, + "checked" => Checked, + "indeterminate" => Indeterminate, + "-servo-nonzero-border" => { + if !context.in_user_agent_stylesheet { + return Err(()); + } + ServoNonZeroBorder + }, + _ => return Err(()) + }; + + Ok(pseudo_class) + } + + fn parse_pseudo_element(_context: &ParserContext, + name: &str) -> Result<PseudoElement, ()> { + use self::PseudoElement::*; + match_ignore_ascii_case! { name, + "before" => Ok(Before), + "after" => Ok(After), + _ => Err(()) + } + } +} |