aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/selector_parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/style/selector_parser.rs')
-rw-r--r--components/style/selector_parser.rs40
1 files changed, 31 insertions, 9 deletions
diff --git a/components/style/selector_parser.rs b/components/style/selector_parser.rs
index b2d55c6551b..85ca80f7b4d 100644
--- a/components/style/selector_parser.rs
+++ b/components/style/selector_parser.rs
@@ -4,11 +4,17 @@
//! The pseudo-classes and pseudo-elements supported by the style system.
+use cssparser::Parser as CssParser;
use matching::{common_style_affecting_attributes, CommonStyleAffectingAttributeMode};
use selectors::Element;
-use selectors::parser::{AttrSelector, SelectorImpl};
+use selectors::parser::{AttrSelector, SelectorList};
+use stylesheets::{Origin, Namespaces};
-pub type AttrValue = <TheSelectorImpl as SelectorImpl>::AttrValue;
+pub type AttrValue = <TheSelectorImpl as ::selectors::SelectorImpl>::AttrValue;
+
+// FIXME remove
+pub use self::SelectorImpl as TheSelectorImpl;
+pub use self::SelectorImpl as ServoSelectorImpl;
#[cfg(feature = "servo")]
pub use servo::selector_parser::*;
@@ -17,12 +23,6 @@ pub use servo::selector_parser::*;
pub use gecko::selector_parser::*;
#[cfg(feature = "servo")]
-pub use servo::selector_parser::ServoSelectorImpl as TheSelectorImpl;
-
-#[cfg(feature = "gecko")]
-pub use gecko::selector_parser::GeckoSelectorImpl as TheSelectorImpl;
-
-#[cfg(feature = "servo")]
pub use servo::selector_parser::ServoElementSnapshot as Snapshot;
#[cfg(feature = "gecko")]
@@ -34,6 +34,28 @@ pub use servo::restyle_damage::ServoRestyleDamage as RestyleDamage;
#[cfg(feature = "gecko")]
pub use gecko::restyle_damage::GeckoRestyleDamage as RestyleDamage;
+#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
+pub struct SelectorParser<'a> {
+ pub stylesheet_origin: Origin,
+ pub namespaces: &'a Namespaces,
+}
+
+impl<'a> SelectorParser<'a> {
+ pub fn parse_author_origin_no_namespace(input: &str)
+ -> Result<SelectorList<SelectorImpl>, ()> {
+ let namespaces = Namespaces::default();
+ let parser = SelectorParser {
+ stylesheet_origin: Origin::Author,
+ namespaces: &namespaces,
+ };
+ SelectorList::parse(&parser, &mut CssParser::new(input))
+ }
+
+ pub fn in_user_agent_stylesheet(&self) -> bool {
+ matches!(self.stylesheet_origin, Origin::UserAgent)
+ }
+}
+
/// This function determines if a pseudo-element is eagerly cascaded or not.
///
/// Eagerly cascaded pseudo-elements are "normal" pseudo-elements (i.e.
@@ -85,7 +107,7 @@ pub trait ElementExt: Element<Impl=TheSelectorImpl> {
fn is_link(&self) -> bool;
}
-impl TheSelectorImpl {
+impl SelectorImpl {
#[inline]
pub fn each_eagerly_cascaded_pseudo_element<F>(mut fun: F)
where F: FnMut(PseudoElement)