aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/selector_impl.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <ecoal95@gmail.com>2016-02-08 02:53:22 +0100
committerEmilio Cobos Álvarez <ecoal95@gmail.com>2016-02-13 16:05:14 +0100
commitdd503dfacb46c63702e4a4b49b85ca30df62a8df (patch)
tree81021ae722350d30583c718cff1aab22fe456db5 /components/style/selector_impl.rs
parenta164176876bb6abccf729eb5d6334e3c22230103 (diff)
downloadservo-dd503dfacb46c63702e4a4b49b85ca30df62a8df.tar.gz
servo-dd503dfacb46c63702e4a4b49b85ca30df62a8df.zip
Refactor style to be completely backend-independent
This commit refactors the style crate to be completely independent of the actual implementation and pseudo-elements supported. This also adds a gecko backend which introduces parsing for the anonymous box pseudo-elements[1], although there's still no way of querying them. https://mxr.mozilla.org/mozilla-central/source/layout/style/nsCSSAnonBoxList.h
Diffstat (limited to 'components/style/selector_impl.rs')
-rw-r--r--components/style/selector_impl.rs64
1 files changed, 57 insertions, 7 deletions
diff --git a/components/style/selector_impl.rs b/components/style/selector_impl.rs
index 74f2bcde91b..1aa2469b6f5 100644
--- a/components/style/selector_impl.rs
+++ b/components/style/selector_impl.rs
@@ -2,15 +2,33 @@
* 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 selector_matching::{USER_OR_USER_AGENT_STYLESHEETS, QUIRKS_MODE_STYLESHEET};
+use selectors::Element;
use selectors::parser::{ParserContext, SelectorImpl};
+use stylesheets::Stylesheet;
-#[derive(Clone, Debug, PartialEq, HeapSizeOf)]
+pub trait ElementExt: Element {
+ fn is_link(&self) -> bool;
+}
+
+pub trait SelectorImplExt : SelectorImpl + Sized {
+ fn each_eagerly_cascaded_pseudo_element<F>(mut fun: F)
+ where F: FnMut(<Self as SelectorImpl>::PseudoElement);
+
+ fn pseudo_class_state_flag(pc: &Self::NonTSPseudoClass) -> ElementState;
+
+ fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet<Self>];
+
+ fn get_quirks_mode_stylesheet() -> &'static Stylesheet<Self>;
+}
+
+#[derive(Clone, Debug, PartialEq, Eq, HeapSizeOf, Hash)]
pub enum PseudoElement {
Before,
After,
}
-#[derive(Clone, Debug, PartialEq, HeapSizeOf)]
+#[derive(Clone, Debug, PartialEq, Eq, HeapSizeOf, Hash)]
pub enum NonTSPseudoClass {
AnyLink,
Link,
@@ -82,10 +100,42 @@ impl SelectorImpl for ServoSelectorImpl {
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(())
- }
+ let pseudo_element = match_ignore_ascii_case! { name,
+ "before" => Before,
+ "after" => After,
+ _ => return Err(())
+ };
+
+ Ok(pseudo_element)
+ }
+}
+
+impl<E: Element<Impl=ServoSelectorImpl>> ElementExt for E {
+ fn is_link(&self) -> bool {
+ self.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink)
+ }
+}
+
+impl SelectorImplExt for ServoSelectorImpl {
+ #[inline]
+ fn each_eagerly_cascaded_pseudo_element<F>(mut fun: F)
+ where F: FnMut(PseudoElement) {
+ fun(PseudoElement::Before);
+ fun(PseudoElement::After);
+ }
+
+ #[inline]
+ fn pseudo_class_state_flag(pc: &NonTSPseudoClass) -> ElementState {
+ pc.state_flag()
+ }
+
+ #[inline]
+ fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet<Self>] {
+ &*USER_OR_USER_AGENT_STYLESHEETS
+ }
+
+ #[inline]
+ fn get_quirks_mode_stylesheet() -> &'static Stylesheet<Self> {
+ &*QUIRKS_MODE_STYLESHEET
}
}