aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/layout/Cargo.toml2
-rw-r--r--components/layout_thread/Cargo.toml2
-rw-r--r--components/script/Cargo.toml2
-rw-r--r--components/script/dom/element.rs16
-rw-r--r--components/script/dom/node.rs13
-rw-r--r--components/script_layout_interface/Cargo.toml2
-rw-r--r--components/style/Cargo.toml2
-rw-r--r--components/style/gecko/selector_parser.rs38
-rw-r--r--components/style/parser.rs6
-rw-r--r--components/style/selector_parser.rs40
-rw-r--r--components/style/servo/selector_parser.rs59
-rw-r--r--components/style/stylesheets.rs104
-rw-r--r--ports/cef/Cargo.lock14
-rw-r--r--ports/geckolib/Cargo.lock10
-rw-r--r--ports/geckolib/Cargo.toml2
-rw-r--r--ports/servo/Cargo.lock16
-rw-r--r--tests/unit/style/Cargo.toml2
-rw-r--r--tests/unit/style/parsing/selectors.rs18
-rw-r--r--tests/unit/style/stylesheets.rs4
-rw-r--r--tests/unit/style/stylist.rs7
-rw-r--r--tests/unit/stylo/Cargo.toml2
21 files changed, 215 insertions, 146 deletions
diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml
index 49322a34086..8bb0bfc6d64 100644
--- a/components/layout/Cargo.toml
+++ b/components/layout/Cargo.toml
@@ -34,7 +34,7 @@ range = {path = "../range"}
rayon = "0.5"
script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
-selectors = "0.14"
+selectors = "0.15"
serde = "0.8"
serde_derive = "0.8"
serde_json = "0.8"
diff --git a/components/layout_thread/Cargo.toml b/components/layout_thread/Cargo.toml
index a75480d40bf..bdacae6d758 100644
--- a/components/layout_thread/Cargo.toml
+++ b/components/layout_thread/Cargo.toml
@@ -31,7 +31,7 @@ rayon = "0.5"
script = {path = "../script"}
script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
-selectors = "0.14"
+selectors = "0.15"
serde_derive = "0.8"
serde_json = "0.8"
servo_url = {path = "../url"}
diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml
index 07dde14ebe8..0b41c70a620 100644
--- a/components/script/Cargo.toml
+++ b/components/script/Cargo.toml
@@ -66,7 +66,7 @@ regex = "0.1.43"
rustc-serialize = "0.3"
script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
-selectors = "0.14"
+selectors = "0.15"
serde = "0.8"
servo_atoms = {path = "../atoms"}
servo_url = {path = "../url", features = ["servo"] }
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index f162a1b56a0..a725bc83f42 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -73,7 +73,7 @@ use html5ever_atoms::{Prefix, LocalName, Namespace, QualName};
use parking_lot::RwLock;
use selectors::matching::{ElementFlags, MatchingReason, matches};
use selectors::matching::{HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS};
-use selectors::parser::{AttrSelector, NamespaceConstraint, parse_author_origin_selector_list_from_str};
+use selectors::parser::{AttrSelector, NamespaceConstraint};
use servo_atoms::Atom;
use std::ascii::AsciiExt;
use std::borrow::Cow;
@@ -92,7 +92,7 @@ use style::properties::{DeclaredValue, Importance};
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
use style::properties::longhands::{background_image, border_spacing, font_family, font_size, overflow_x};
use style::restyle_hints::RESTYLE_SELF;
-use style::selector_parser::{NonTSPseudoClass, RestyleDamage, ServoSelectorImpl};
+use style::selector_parser::{NonTSPseudoClass, RestyleDamage, ServoSelectorImpl, SelectorParser};
use style::sink::Push;
use style::stylist::ApplicableDeclarationBlock;
use style::values::CSSFloat;
@@ -1885,10 +1885,10 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-matches
fn Matches(&self, selectors: DOMString) -> Fallible<bool> {
- match parse_author_origin_selector_list_from_str(&selectors) {
+ match SelectorParser::parse_author_origin_no_namespace(&selectors) {
Err(()) => Err(Error::Syntax),
- Ok(ref selectors) => {
- Ok(matches(selectors, &Root::from_ref(self), None, MatchingReason::Other))
+ Ok(selectors) => {
+ Ok(matches(&selectors.0, &Root::from_ref(self), None, MatchingReason::Other))
}
}
}
@@ -1900,13 +1900,13 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-closest
fn Closest(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
- match parse_author_origin_selector_list_from_str(&selectors) {
+ match SelectorParser::parse_author_origin_no_namespace(&selectors) {
Err(()) => Err(Error::Syntax),
- Ok(ref selectors) => {
+ Ok(selectors) => {
let root = self.upcast::<Node>();
for element in root.inclusive_ancestors() {
if let Some(element) = Root::downcast::<Element>(element) {
- if matches(selectors, &element, None, MatchingReason::Other) {
+ if matches(&selectors.0, &element, None, MatchingReason::Other) {
return Ok(Some(element));
}
}
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 251d459335e..b128a4506b6 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -72,7 +72,6 @@ use script_layout_interface::message::Msg;
use script_traits::UntrustedNodeAddress;
use selectors::matching::{MatchingReason, matches};
use selectors::parser::Selector;
-use selectors::parser::parse_author_origin_selector_list_from_str;
use servo_url::ServoUrl;
use std::borrow::ToOwned;
use std::cell::{Cell, UnsafeCell};
@@ -83,7 +82,7 @@ use std::mem;
use std::ops::Range;
use std::sync::Arc;
use style::dom::OpaqueNode;
-use style::selector_parser::ServoSelectorImpl;
+use style::selector_parser::{ServoSelectorImpl, SelectorParser};
use style::stylesheets::Stylesheet;
use style::thread_state;
use uuid::Uuid;
@@ -690,13 +689,13 @@ impl Node {
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
pub fn query_selector(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
// Step 1.
- match parse_author_origin_selector_list_from_str(&selectors) {
+ match SelectorParser::parse_author_origin_no_namespace(&selectors) {
// Step 2.
Err(()) => Err(Error::Syntax),
// Step 3.
- Ok(ref selectors) => {
+ Ok(selectors) => {
Ok(self.traverse_preorder().filter_map(Root::downcast).find(|element| {
- matches(selectors, element, None, MatchingReason::Other)
+ matches(&selectors.0, element, None, MatchingReason::Other)
}))
}
}
@@ -709,7 +708,7 @@ impl Node {
pub fn query_selector_iter(&self, selectors: DOMString)
-> Fallible<QuerySelectorIterator> {
// Step 1.
- match parse_author_origin_selector_list_from_str(&selectors) {
+ match SelectorParser::parse_author_origin_no_namespace(&selectors) {
// Step 2.
Err(()) => Err(Error::Syntax),
// Step 3.
@@ -717,7 +716,7 @@ impl Node {
let mut descendants = self.traverse_preorder();
// Skip the root of the tree.
assert!(&*descendants.next().unwrap() == self);
- Ok(QuerySelectorIterator::new(descendants, selectors))
+ Ok(QuerySelectorIterator::new(descendants, selectors.0))
}
}
}
diff --git a/components/script_layout_interface/Cargo.toml b/components/script_layout_interface/Cargo.toml
index 44b0a3c320d..8650fb7e025 100644
--- a/components/script_layout_interface/Cargo.toml
+++ b/components/script_layout_interface/Cargo.toml
@@ -28,7 +28,7 @@ plugins = {path = "../plugins"}
profile_traits = {path = "../profile_traits"}
range = {path = "../range"}
script_traits = {path = "../script_traits"}
-selectors = "0.14"
+selectors = "0.15"
servo_atoms = {path = "../atoms"}
servo_url = {path = "../url"}
style = {path = "../style"}
diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml
index 6b828ab89bb..5a1b854ca4d 100644
--- a/components/style/Cargo.toml
+++ b/components/style/Cargo.toml
@@ -44,7 +44,7 @@ quickersort = "2.0.0"
rand = "0.3"
rayon = "0.5"
rustc-serialize = "0.3"
-selectors = "0.14"
+selectors = "0.15"
serde = {version = "0.8", optional = true}
serde_derive = {version = "0.8", optional = true}
servo_atoms = {path = "../atoms", optional = true}
diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs
index 32125f0fa38..4cf6a64b9ea 100644
--- a/components/style/gecko/selector_parser.rs
+++ b/components/style/gecko/selector_parser.rs
@@ -4,14 +4,15 @@
use cssparser::ToCss;
use element_state::ElementState;
+use selector_parser::{SelectorParser, PseudoElementCascadeType};
use selector_parser::{attr_equals_selector_is_shareable, attr_exists_selector_is_shareable};
-use selector_parser::PseudoElementCascadeType;
-use selectors::parser::{AttrSelector, ParserContext, SelectorImpl};
+use selectors::parser::AttrSelector;
+use std::borrow::Cow;
use std::fmt;
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct GeckoSelectorImpl;
+// FIXME remove
+pub use self::SelectorImpl as GeckoSelectorImpl;
/// NOTE: The boolean field represents whether this element is an anonymous box.
///
@@ -161,7 +162,10 @@ impl NonTSPseudoClass {
}
}
-impl SelectorImpl for GeckoSelectorImpl {
+#[derive(Clone, Debug, PartialEq)]
+pub struct SelectorImpl;
+
+impl ::selectors::SelectorImpl for SelectorImpl {
type AttrValue = Atom;
type Identifier = Atom;
type ClassName = Atom;
@@ -182,11 +186,14 @@ impl SelectorImpl for GeckoSelectorImpl {
value: &Self::AttrValue) -> bool {
attr_equals_selector_is_shareable(attr_selector, value)
}
+}
- fn parse_non_ts_pseudo_class(_context: &ParserContext<Self>,
- name: &str) -> Result<NonTSPseudoClass, ()> {
+impl<'a> ::selectors::Parser for SelectorParser<'a> {
+ type Impl = SelectorImpl;
+
+ fn parse_non_ts_pseudo_class(&self, name: Cow<str>) -> Result<NonTSPseudoClass, ()> {
use self::NonTSPseudoClass::*;
- let pseudo_class = match_ignore_ascii_case! { name,
+ let pseudo_class = match_ignore_ascii_case! { &name,
"any-link" => AnyLink,
"link" => Link,
"visited" => Visited,
@@ -205,16 +212,23 @@ impl SelectorImpl for GeckoSelectorImpl {
Ok(pseudo_class)
}
- fn parse_pseudo_element(context: &ParserContext<Self>,
- name: &str) -> Result<PseudoElement, ()> {
- match PseudoElement::from_slice(name, context.in_user_agent_stylesheet) {
+ fn parse_pseudo_element(&self, name: Cow<str>) -> Result<PseudoElement, ()> {
+ match PseudoElement::from_slice(&name, self.in_user_agent_stylesheet()) {
Some(pseudo) => Ok(pseudo),
None => Err(()),
}
}
+
+ fn default_namespace(&self) -> Option<Namespace> {
+ self.namespaces.default.clone()
+ }
+
+ fn namespace_for_prefix(&self, prefix: &Atom) -> Option<Namespace> {
+ self.namespaces.prefixes.get(prefix).cloned()
+ }
}
-impl GeckoSelectorImpl {
+impl SelectorImpl {
#[inline]
pub fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType {
if Self::pseudo_is_before_or_after(pseudo) {
diff --git a/components/style/parser.rs b/components/style/parser.rs
index 61921a2cd30..c847e082ace 100644
--- a/components/style/parser.rs
+++ b/components/style/parser.rs
@@ -8,8 +8,6 @@ use cssparser::{Parser, SourcePosition};
use error_reporting::ParseErrorReporter;
#[cfg(feature = "gecko")]
use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
-use selector_parser::TheSelectorImpl;
-use selectors::parser::ParserContext as SelectorParserContext;
use servo_url::ServoUrl;
use stylesheets::Origin;
@@ -38,7 +36,6 @@ impl ParserContextExtraData {
pub struct ParserContext<'a> {
pub stylesheet_origin: Origin,
pub base_url: &'a ServoUrl,
- pub selector_context: SelectorParserContext<TheSelectorImpl>,
pub error_reporter: Box<ParseErrorReporter + Send>,
pub extra_data: ParserContextExtraData,
}
@@ -48,12 +45,9 @@ impl<'a> ParserContext<'a> {
error_reporter: Box<ParseErrorReporter + Send>,
extra_data: ParserContextExtraData)
-> ParserContext<'a> {
- let mut selector_context = SelectorParserContext::new();
- selector_context.in_user_agent_stylesheet = stylesheet_origin == Origin::UserAgent;
ParserContext {
stylesheet_origin: stylesheet_origin,
base_url: base_url,
- selector_context: selector_context,
error_reporter: error_reporter,
extra_data: extra_data,
}
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)
diff --git a/components/style/servo/selector_parser.rs b/components/style/servo/selector_parser.rs
index defdbf3b129..493710debfb 100644
--- a/components/style/servo/selector_parser.rs
+++ b/components/style/servo/selector_parser.rs
@@ -7,10 +7,11 @@ use attr::{AttrIdentifier, AttrValue};
use cssparser::ToCss;
use element_state::ElementState;
use restyle_hints::ElementSnapshot;
-use selector_parser::{ElementExt, PseudoElementCascadeType, TheSelectorImpl};
+use selector_parser::{ElementExt, PseudoElementCascadeType, SelectorParser};
use selector_parser::{attr_equals_selector_is_shareable, attr_exists_selector_is_shareable};
use selectors::{Element, MatchAttrGeneric};
-use selectors::parser::{AttrSelector, ParserContext, SelectorImpl};
+use selectors::parser::AttrSelector;
+use std::borrow::Cow;
use std::fmt;
/// NB: If you add to this list, be sure to update `each_pseudo_element` too.
@@ -150,9 +151,9 @@ impl NonTSPseudoClass {
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
-pub struct ServoSelectorImpl;
+pub struct SelectorImpl;
-impl SelectorImpl for ServoSelectorImpl {
+impl ::selectors::SelectorImpl for SelectorImpl {
type PseudoElement = PseudoElement;
type NonTSPseudoClass = NonTSPseudoClass;
@@ -173,11 +174,14 @@ impl SelectorImpl for ServoSelectorImpl {
value: &Self::AttrValue) -> bool {
attr_equals_selector_is_shareable(attr_selector, value)
}
+}
+
+impl<'a> ::selectors::Parser for SelectorParser<'a> {
+ type Impl = SelectorImpl;
- fn parse_non_ts_pseudo_class(context: &ParserContext<TheSelectorImpl>,
- name: &str) -> Result<NonTSPseudoClass, ()> {
+ fn parse_non_ts_pseudo_class(&self, name: Cow<str>) -> Result<NonTSPseudoClass, ()> {
use self::NonTSPseudoClass::*;
- let pseudo_class = match_ignore_ascii_case! { name,
+ let pseudo_class = match_ignore_ascii_case! { &name,
"any-link" => AnyLink,
"link" => Link,
"visited" => Visited,
@@ -193,7 +197,7 @@ impl SelectorImpl for ServoSelectorImpl {
"placeholder-shown" => PlaceholderShown,
"target" => Target,
"-servo-nonzero-border" => {
- if !context.in_user_agent_stylesheet {
+ if !self.in_user_agent_stylesheet() {
return Err(());
}
ServoNonZeroBorder
@@ -204,63 +208,62 @@ impl SelectorImpl for ServoSelectorImpl {
Ok(pseudo_class)
}
- fn parse_pseudo_element(context: &ParserContext<TheSelectorImpl>,
- name: &str) -> Result<PseudoElement, ()> {
+ fn parse_pseudo_element(&self, name: Cow<str>) -> Result<PseudoElement, ()> {
use self::PseudoElement::*;
- let pseudo_element = match_ignore_ascii_case! { name,
+ let pseudo_element = match_ignore_ascii_case! { &name,
"before" => Before,
"after" => After,
"selection" => Selection,
"-servo-details-summary" => {
- if !context.in_user_agent_stylesheet {
+ if !self.in_user_agent_stylesheet() {
return Err(())
}
DetailsSummary
},
"-servo-details-content" => {
- if !context.in_user_agent_stylesheet {
+ if !self.in_user_agent_stylesheet() {
return Err(())
}
DetailsContent
},
"-servo-input-text" => {
- if !context.in_user_agent_stylesheet {
+ if !self.in_user_agent_stylesheet() {
return Err(())
}
ServoInputText
},
"-servo-table-wrapper" => {
- if !context.in_user_agent_stylesheet {
+ if !self.in_user_agent_stylesheet() {
return Err(())
}
ServoTableWrapper
},
"-servo-anonymous-table-wrapper" => {
- if !context.in_user_agent_stylesheet {
+ if !self.in_user_agent_stylesheet() {
return Err(())
}
ServoAnonymousTableWrapper
},
"-servo-anonymous-table" => {
- if !context.in_user_agent_stylesheet {
+ if !self.in_user_agent_stylesheet() {
return Err(())
}
ServoAnonymousTable
},
"-servo-anonymous-table-row" => {
- if !context.in_user_agent_stylesheet {
+ if !self.in_user_agent_stylesheet() {
return Err(())
}
ServoAnonymousTableRow
},
"-servo-anonymous-table-cell" => {
- if !context.in_user_agent_stylesheet {
+ if !self.in_user_agent_stylesheet() {
return Err(())
}
ServoAnonymousTableCell
},
"-servo-anonymous-block" => {
- if !context.in_user_agent_stylesheet {
+ if !self.in_user_agent_stylesheet() {
return Err(())
}
ServoAnonymousBlock
@@ -270,9 +273,17 @@ impl SelectorImpl for ServoSelectorImpl {
Ok(pseudo_element)
}
+
+ fn default_namespace(&self) -> Option<Namespace> {
+ self.namespaces.default.clone()
+ }
+
+ fn namespace_for_prefix(&self, prefix: &Prefix) -> Option<Namespace> {
+ self.namespaces.prefixes.get(prefix).cloned()
+ }
}
-impl ServoSelectorImpl {
+impl SelectorImpl {
#[inline]
pub fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType {
pseudo.cascade_type()
@@ -368,9 +379,9 @@ impl ElementSnapshot for ServoElementSnapshot {
}
impl MatchAttrGeneric for ServoElementSnapshot {
- type Impl = ServoSelectorImpl;
+ type Impl = SelectorImpl;
- fn match_attr<F>(&self, attr: &AttrSelector<ServoSelectorImpl>, test: F) -> bool
+ fn match_attr<F>(&self, attr: &AttrSelector<SelectorImpl>, test: F) -> bool
where F: Fn(&str) -> bool
{
use selectors::parser::NamespaceConstraint;
@@ -383,7 +394,7 @@ impl MatchAttrGeneric for ServoElementSnapshot {
}
}
-impl<E: Element<Impl=TheSelectorImpl>> ElementExt for E {
+impl<E: Element<Impl=SelectorImpl>> ElementExt for E {
fn is_link(&self) -> bool {
self.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink)
}
diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs
index 5c264ab8e9d..d7a6485ce89 100644
--- a/components/style/stylesheets.rs
+++ b/components/style/stylesheets.rs
@@ -16,14 +16,15 @@ use media_queries::{Device, MediaList, parse_media_query_list};
use parking_lot::RwLock;
use parser::{ParserContext, ParserContextExtraData, log_css_error};
use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
-use selector_parser::TheSelectorImpl;
-use selectors::parser::{Selector, parse_selector_list};
+use selector_parser::{SelectorImpl, SelectorParser};
+use selectors::parser::{Selector, SelectorList};
use servo_url::ServoUrl;
use std::cell::Cell;
use std::fmt;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use style_traits::ToCss;
+use stylist::FnvHashMap;
use viewport::ViewportRule;
@@ -43,6 +44,13 @@ pub enum Origin {
User,
}
+#[derive(Default)]
+#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
+pub struct Namespaces {
+ pub default: Option<Namespace>,
+ pub prefixes: FnvHashMap<Prefix , Namespace>,
+}
+
#[derive(Debug, Clone)]
pub struct CssRules(pub Arc<RwLock<Vec<CssRule>>>);
@@ -188,7 +196,7 @@ impl ToCss for MediaRule {
#[derive(Debug)]
pub struct StyleRule {
- pub selectors: Vec<Selector<TheSelectorImpl>>,
+ pub selectors: Vec<Selector<SelectorImpl>>,
pub block: Arc<RwLock<PropertyDeclarationBlock>>,
}
@@ -246,7 +254,10 @@ impl Stylesheet {
pub fn from_str(css: &str, base_url: ServoUrl, origin: Origin, media: MediaList,
error_reporter: Box<ParseErrorReporter + Send>,
extra_data: ParserContextExtraData) -> Stylesheet {
+ let mut namespaces = Namespaces::default();
let rule_parser = TopLevelRuleParser {
+ stylesheet_origin: origin,
+ namespaces: &mut namespaces,
context: ParserContext::new_with_extra_data(origin, &base_url, error_reporter.clone(),
extra_data),
state: Cell::new(State::Start),
@@ -356,29 +367,23 @@ rule_filter! {
effective_keyframes_rules(Keyframes => KeyframesRule),
}
-fn parse_nested_rules(context: &ParserContext, input: &mut Parser) -> CssRules {
- let mut iter = RuleListParser::new_for_nested_rule(input,
- NestedRuleParser { context: context });
- let mut rules = Vec::new();
- while let Some(result) = iter.next() {
- match result {
- Ok(rule) => rules.push(rule),
- Err(range) => {
- let pos = range.start;
- let message = format!("Unsupported rule: '{}'", iter.input.slice(range));
- log_css_error(iter.input, pos, &*message, &context);
- }
- }
- }
- rules.into()
-}
-
-
struct TopLevelRuleParser<'a> {
+ stylesheet_origin: Origin,
+ namespaces: &'a mut Namespaces,
context: ParserContext<'a>,
state: Cell<State>,
}
+impl<'b> TopLevelRuleParser<'b> {
+ fn nested<'a: 'b>(&'a self) -> NestedRuleParser<'a, 'b> {
+ NestedRuleParser {
+ stylesheet_origin: self.stylesheet_origin,
+ context: &self.context,
+ namespaces: self.namespaces,
+ }
+ }
+}
+
#[derive(Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
enum State {
Start = 1,
@@ -425,11 +430,10 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
let opt_prefix = if let Ok(prefix) = prefix_result {
let prefix = Prefix::from(prefix);
- self.context.selector_context.namespace_prefixes.insert(
- prefix.clone(), url.clone());
+ self.namespaces.prefixes.insert(prefix.clone(), url.clone());
Some(prefix)
} else {
- self.context.selector_context.default_namespace = Some(url.clone());
+ self.namespaces.default = Some(url.clone());
None
};
@@ -450,39 +454,57 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
}
self.state.set(State::Body);
- AtRuleParser::parse_prelude(&mut NestedRuleParser { context: &self.context }, name, input)
+ AtRuleParser::parse_prelude(&mut self.nested(), name, input)
}
#[inline]
fn parse_block(&mut self, prelude: AtRulePrelude, input: &mut Parser) -> Result<CssRule, ()> {
- AtRuleParser::parse_block(&mut NestedRuleParser { context: &self.context }, prelude, input)
+ AtRuleParser::parse_block(&mut self.nested(), prelude, input)
}
}
impl<'a> QualifiedRuleParser for TopLevelRuleParser<'a> {
- type Prelude = Vec<Selector<TheSelectorImpl>>;
+ type Prelude = SelectorList<SelectorImpl>;
type QualifiedRule = CssRule;
#[inline]
- fn parse_prelude(&mut self, input: &mut Parser) -> Result<Vec<Selector<TheSelectorImpl>>, ()> {
+ fn parse_prelude(&mut self, input: &mut Parser) -> Result<SelectorList<SelectorImpl>, ()> {
self.state.set(State::Body);
- QualifiedRuleParser::parse_prelude(&mut NestedRuleParser { context: &self.context }, input)
+ QualifiedRuleParser::parse_prelude(&mut self.nested(), input)
}
#[inline]
- fn parse_block(&mut self, prelude: Vec<Selector<TheSelectorImpl>>, input: &mut Parser)
+ fn parse_block(&mut self, prelude: SelectorList<SelectorImpl>, input: &mut Parser)
-> Result<CssRule, ()> {
- QualifiedRuleParser::parse_block(&mut NestedRuleParser { context: &self.context },
- prelude, input)
+ QualifiedRuleParser::parse_block(&mut self.nested(), prelude, input)
}
}
-
+#[derive(Clone)] // shallow, relatively cheap clone
struct NestedRuleParser<'a, 'b: 'a> {
+ stylesheet_origin: Origin,
context: &'a ParserContext<'b>,
+ namespaces: &'b Namespaces,
}
+impl<'a, 'b> NestedRuleParser<'a, 'b> {
+ fn parse_nested_rules(&self, input: &mut Parser) -> CssRules {
+ let mut iter = RuleListParser::new_for_nested_rule(input, self.clone());
+ let mut rules = Vec::new();
+ while let Some(result) = iter.next() {
+ match result {
+ Ok(rule) => rules.push(rule),
+ Err(range) => {
+ let pos = range.start;
+ let message = format!("Unsupported rule: '{}'", iter.input.slice(range));
+ log_css_error(iter.input, pos, &*message, self.context);
+ }
+ }
+ }
+ rules.into()
+ }
+}
impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
type Prelude = AtRulePrelude;
@@ -528,7 +550,7 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
AtRulePrelude::Media(media_queries) => {
Ok(CssRule::Media(Arc::new(RwLock::new(MediaRule {
media_queries: media_queries,
- rules: parse_nested_rules(self.context, input),
+ rules: self.parse_nested_rules(input),
}))))
}
AtRulePrelude::Viewport => {
@@ -546,17 +568,21 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
}
impl<'a, 'b> QualifiedRuleParser for NestedRuleParser<'a, 'b> {
- type Prelude = Vec<Selector<TheSelectorImpl>>;
+ type Prelude = SelectorList<SelectorImpl>;
type QualifiedRule = CssRule;
- fn parse_prelude(&mut self, input: &mut Parser) -> Result<Vec<Selector<TheSelectorImpl>>, ()> {
- parse_selector_list(&self.context.selector_context, input)
+ fn parse_prelude(&mut self, input: &mut Parser) -> Result<SelectorList<SelectorImpl>, ()> {
+ let selector_parser = SelectorParser {
+ stylesheet_origin: self.stylesheet_origin,
+ namespaces: self.namespaces,
+ };
+ SelectorList::parse(&selector_parser, input)
}
- fn parse_block(&mut self, prelude: Vec<Selector<TheSelectorImpl>>, input: &mut Parser)
+ fn parse_block(&mut self, prelude: SelectorList<SelectorImpl>, input: &mut Parser)
-> Result<CssRule, ()> {
Ok(CssRule::Style(Arc::new(RwLock::new(StyleRule {
- selectors: prelude,
+ selectors: prelude.0,
block: Arc::new(RwLock::new(parse_property_declaration_list(self.context, input)))
}))))
}
diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock
index 9dc1bb20cd8..0d233488828 100644
--- a/ports/cef/Cargo.lock
+++ b/ports/cef/Cargo.lock
@@ -1158,7 +1158,7 @@ dependencies = [
"rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1",
"script_traits 0.0.1",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1198,7 +1198,7 @@ dependencies = [
"script 0.0.1",
"script_layout_interface 0.0.1",
"script_traits 0.0.1",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_url 0.0.1",
@@ -2019,7 +2019,7 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1",
"script_traits 0.0.1",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_atoms 0.0.1",
"servo_url 0.0.1",
@@ -2058,7 +2058,7 @@ dependencies = [
"profile_traits 0.0.1",
"range 0.0.1",
"script_traits 0.0.1",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_atoms 0.0.1",
"servo_url 0.0.1",
"style 0.0.1",
@@ -2097,7 +2097,7 @@ dependencies = [
[[package]]
name = "selectors"
-version = "0.14.0"
+version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2374,7 +2374,7 @@ dependencies = [
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_atoms 0.0.1",
@@ -3096,7 +3096,7 @@ dependencies = [
"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b"
"checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084"
"checksum scoped_threadpool 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3ef399c8893e8cb7aa9696e895427fab3a6bf265977bb96e126f24ddd2cda85a"
-"checksum selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f8d3498861f4486e7e1d5c56eabf2b0e461f92bcbf45a3ac30cae0f3d5cdd0"
+"checksum selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b127ac14249f6ce720277f6a163b3837706e9dc1ad4e2948db55f262f11a97"
"checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac"
"checksum serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "784e249221c84265caeb1e2fe48aeada86f67f5acb151bd3903c4585969e43f6"
"checksum serde_codegen 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "c3b932a3bb4d729e39aa04cc5e2f2ac70ba239a5a151d2dc9a1956fd6a2f7c15"
diff --git a/ports/geckolib/Cargo.lock b/ports/geckolib/Cargo.lock
index f5ca1875bc1..d6f099b173e 100644
--- a/ports/geckolib/Cargo.lock
+++ b/ports/geckolib/Cargo.lock
@@ -11,7 +11,7 @@ dependencies = [
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_url 0.0.1",
"style 0.0.1",
"style_traits 0.0.1",
@@ -319,7 +319,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "selectors"
-version = "0.14.0"
+version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -372,7 +372,7 @@ dependencies = [
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_url 0.0.1",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"style_traits 0.0.1",
@@ -406,7 +406,7 @@ dependencies = [
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_url 0.0.1",
"style 0.0.1",
"style_traits 0.0.1",
@@ -565,7 +565,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum regex 0.1.76 (registry+https://github.com/rust-lang/crates.io-index)" = "63b49f873f36ddc838d773972511e5fed2ef7350885af07d58e2f48ce8073dcd"
"checksum regex-syntax 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279401017ae31cf4e15344aa3f085d0e2e5c1e70067289ef906906fdbe92c8fd"
"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b"
-"checksum selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f8d3498861f4486e7e1d5c56eabf2b0e461f92bcbf45a3ac30cae0f3d5cdd0"
+"checksum selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b127ac14249f6ce720277f6a163b3837706e9dc1ad4e2948db55f262f11a97"
"checksum serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "784e249221c84265caeb1e2fe48aeada86f67f5acb151bd3903c4585969e43f6"
"checksum smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "fcc8d19212aacecf95e4a7a2179b26f7aeb9732a915cf01f05b0d3e044865410"
"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03"
diff --git a/ports/geckolib/Cargo.toml b/ports/geckolib/Cargo.toml
index 08533a64860..0df70bc465b 100644
--- a/ports/geckolib/Cargo.toml
+++ b/ports/geckolib/Cargo.toml
@@ -19,7 +19,7 @@ libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]}
num_cpus = "1.1.0"
parking_lot = "0.3"
-selectors = "0.14"
+selectors = "0.15"
servo_url = {path = "../../components/url"}
style = {path = "../../components/style", features = ["gecko"]}
style_traits = {path = "../../components/style_traits"}
diff --git a/ports/servo/Cargo.lock b/ports/servo/Cargo.lock
index 18f9097bdee..a208e972ce8 100644
--- a/ports/servo/Cargo.lock
+++ b/ports/servo/Cargo.lock
@@ -1237,7 +1237,7 @@ dependencies = [
"rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1",
"script_traits 0.0.1",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1284,7 +1284,7 @@ dependencies = [
"script 0.0.1",
"script_layout_interface 0.0.1",
"script_traits 0.0.1",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_url 0.0.1",
@@ -2169,7 +2169,7 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1",
"script_traits 0.0.1",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_atoms 0.0.1",
"servo_url 0.0.1",
@@ -2208,7 +2208,7 @@ dependencies = [
"profile_traits 0.0.1",
"range 0.0.1",
"script_traits 0.0.1",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_atoms 0.0.1",
"servo_url 0.0.1",
"style 0.0.1",
@@ -2257,7 +2257,7 @@ dependencies = [
[[package]]
name = "selectors"
-version = "0.14.0"
+version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2541,7 +2541,7 @@ dependencies = [
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_atoms 0.0.1",
@@ -2565,7 +2565,7 @@ dependencies = [
"owning_ref 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
- "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_atoms 0.0.1",
"servo_url 0.0.1",
"style 0.0.1",
@@ -3306,7 +3306,7 @@ dependencies = [
"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b"
"checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084"
"checksum scoped_threadpool 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3ef399c8893e8cb7aa9696e895427fab3a6bf265977bb96e126f24ddd2cda85a"
-"checksum selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f8d3498861f4486e7e1d5c56eabf2b0e461f92bcbf45a3ac30cae0f3d5cdd0"
+"checksum selectors 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b127ac14249f6ce720277f6a163b3837706e9dc1ad4e2948db55f262f11a97"
"checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac"
"checksum semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f"
"checksum serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "784e249221c84265caeb1e2fe48aeada86f67f5acb151bd3903c4585969e43f6"
diff --git a/tests/unit/style/Cargo.toml b/tests/unit/style/Cargo.toml
index 9ee0c5b17d6..3e75fa99a2c 100644
--- a/tests/unit/style/Cargo.toml
+++ b/tests/unit/style/Cargo.toml
@@ -16,7 +16,7 @@ euclid = "0.10.1"
owning_ref = "0.2.2"
parking_lot = "0.3"
rustc-serialize = "0.3"
-selectors = "0.14"
+selectors = "0.15"
html5ever-atoms = "0.1"
servo_atoms = {path = "../../../components/atoms"}
style = {path = "../../../components/style"}
diff --git a/tests/unit/style/parsing/selectors.rs b/tests/unit/style/parsing/selectors.rs
index 2c8f1800b98..8d45cd722f8 100644
--- a/tests/unit/style/parsing/selectors.rs
+++ b/tests/unit/style/parsing/selectors.rs
@@ -3,14 +3,18 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::{Parser, ToCss};
-use selectors::parser::{Selector, ParserContext, parse_selector_list};
-use style::selector_parser::TheSelectorImpl;
+use selectors::parser::SelectorList;
+use style::selector_parser::{TheSelectorImpl, SelectorParser};
+use style::stylesheets::{Origin, Namespaces};
-fn parse(input: &mut Parser) -> Result<Selector<TheSelectorImpl>, ()> {
- let mut context = ParserContext::new();
- context.in_user_agent_stylesheet = true;
- context.namespace_prefixes.insert("svg".into(), ns!(svg));
- parse_selector_list(&context, input).map(|mut vec| vec.pop().unwrap())
+fn parse(input: &mut Parser) -> Result<SelectorList<TheSelectorImpl>, ()> {
+ let mut ns = Namespaces::default();
+ ns.prefixes.insert("svg".into(), ns!(svg));
+ let parser = SelectorParser {
+ stylesheet_origin: Origin::UserAgent,
+ namespaces: &ns,
+ };
+ SelectorList::parse(&parser, input)
}
#[test]
diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs
index b61c0a0f9a1..8af9534ecc0 100644
--- a/tests/unit/style/stylesheets.rs
+++ b/tests/unit/style/stylesheets.rs
@@ -2,7 +2,7 @@
* 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 cssparser::{self, Parser, SourcePosition};
+use cssparser::{self, Parser as CssParser, SourcePosition};
use html5ever_atoms::{Namespace as NsAtom};
use media_queries::CSSErrorReporterTest;
use parking_lot::RwLock;
@@ -282,7 +282,7 @@ impl CSSInvalidErrorReporterTest {
}
impl ParseErrorReporter for CSSInvalidErrorReporterTest {
- fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str) {
+ fn report_error(&self, input: &mut CssParser, position: SourcePosition, message: &str) {
let location = input.source_location(position);
let errors = self.errors.clone();
diff --git a/tests/unit/style/stylist.rs b/tests/unit/style/stylist.rs
index a9d427b96dc..91072bba9e4 100644
--- a/tests/unit/style/stylist.rs
+++ b/tests/unit/style/stylist.rs
@@ -5,11 +5,12 @@
use cssparser::Parser;
use html5ever_atoms::LocalName;
use parking_lot::RwLock;
-use selectors::parser::{LocalName as LocalNameSelector, ParserContext, parse_selector_list};
+use selectors::parser::LocalName as LocalNameSelector;
use servo_atoms::Atom;
use std::sync::Arc;
use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, DeclaredValue};
use style::properties::{longhands, Importance};
+use style::selector_parser::SelectorParser;
use style::stylesheets::StyleRule;
use style::stylist::{Rule, SelectorMap};
use style::thread_state;
@@ -18,9 +19,7 @@ use style::thread_state;
/// Each sublist of the result contains the Rules for one StyleRule.
fn get_mock_rules(css_selectors: &[&str]) -> Vec<Vec<Rule>> {
css_selectors.iter().enumerate().map(|(i, selectors)| {
- let context = ParserContext::new();
- let selectors =
- parse_selector_list(&context, &mut Parser::new(*selectors)).unwrap();
+ let selectors = SelectorParser::parse_author_origin_no_namespace(selectors).unwrap().0;
let rule = Arc::new(RwLock::new(StyleRule {
selectors: selectors,
diff --git a/tests/unit/stylo/Cargo.toml b/tests/unit/stylo/Cargo.toml
index 796c351426d..1fd99d8230e 100644
--- a/tests/unit/stylo/Cargo.toml
+++ b/tests/unit/stylo/Cargo.toml
@@ -21,7 +21,7 @@ libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]}
num_cpus = "1.1.0"
parking_lot = "0.3"
-selectors = "0.14"
+selectors = "0.15"
servo_url = {path = "../../../components/url"}
style_traits = {path = "../../../components/style_traits"}
geckoservo = {path = "../../../ports/geckolib"}