aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-08-19 13:01:29 -0500
committerGitHub <noreply@github.com>2016-08-19 13:01:29 -0500
commit07b217368f6f2ec35450edab9c6c29091aa16433 (patch)
tree9d42275ee344fa6b629b1fe64b12ea34d729955a
parentdbee1cb6721d63af7a791f1164f263c3adc95446 (diff)
parent6173e1d33957b8f3c560df562c1ea2ed36151381 (diff)
downloadservo-07b217368f6f2ec35450edab9c6c29091aa16433.tar.gz
servo-07b217368f6f2ec35450edab9c6c29091aa16433.zip
Auto merge of #12924 - servo:selectors-ser, r=nox
Update selectors to 0.10, with ToCss serialization. <!-- Please describe your changes on the following line: --> r? @emilio --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12924) <!-- Reviewable:end -->
-rw-r--r--components/layout/Cargo.toml2
-rw-r--r--components/script/Cargo.toml2
-rw-r--r--components/script/dom/element.rs2
-rw-r--r--components/script/layout_wrapper.rs4
-rw-r--r--components/script_layout_interface/Cargo.toml2
-rw-r--r--components/servo/Cargo.lock32
-rw-r--r--components/style/Cargo.toml4
-rw-r--r--components/style/gecko_selector_impl.rs37
-rw-r--r--components/style/properties/properties.mako.rs2
-rw-r--r--components/style/restyle_hints.rs2
-rw-r--r--components/style/servo_selector_impl.rs46
-rw-r--r--components/style/stylesheets.rs19
-rw-r--r--ports/cef/Cargo.lock28
-rw-r--r--ports/geckolib/Cargo.lock12
-rw-r--r--ports/geckolib/Cargo.toml2
-rw-r--r--ports/geckolib/string_cache/Cargo.toml2
-rw-r--r--ports/geckolib/string_cache/namespace.rs7
-rw-r--r--ports/geckolib/wrapper.rs2
-rw-r--r--tests/unit/style/Cargo.toml2
-rw-r--r--tests/unit/style/parsing/mod.rs4
-rw-r--r--tests/unit/style/parsing/selectors.rs22
-rw-r--r--tests/unit/style/stylesheets.rs37
22 files changed, 203 insertions, 69 deletions
diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml
index 5b6baf33845..0ac6e869864 100644
--- a/components/layout/Cargo.toml
+++ b/components/layout/Cargo.toml
@@ -33,7 +33,7 @@ range = {path = "../range"}
rustc-serialize = "0.3"
script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
-selectors = {version = "0.9", features = ["heap_size"]}
+selectors = {version = "0.10", features = ["heap_size"]}
serde_macros = "0.8"
smallvec = "0.1"
string_cache = {version = "0.2.23", features = ["heap_size"]}
diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml
index 91c7a7fd2f6..a2e8d3a28f8 100644
--- a/components/script/Cargo.toml
+++ b/components/script/Cargo.toml
@@ -62,7 +62,7 @@ regex = "0.1.43"
rustc-serialize = "0.3"
script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
-selectors = {version = "0.9", features = ["heap_size"]}
+selectors = {version = "0.10", features = ["heap_size"]}
serde = "0.8"
smallvec = "0.1"
string_cache = {version = "0.2.23", features = ["heap_size", "unstable"]}
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index f74f253aa78..860818c024c 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -2250,7 +2250,7 @@ impl<'a> ::selectors::MatchAttrGeneric for Root<Element> {
};
match attr.namespace {
NamespaceConstraint::Specific(ref ns) => {
- self.get_attribute(ns, local_name)
+ self.get_attribute(&ns.url, local_name)
.map_or(false, |attr| {
test(&attr.value())
})
diff --git a/components/script/layout_wrapper.rs b/components/script/layout_wrapper.rs
index 13fcdc41df9..cbf04b48e5b 100644
--- a/components/script/layout_wrapper.rs
+++ b/components/script/layout_wrapper.rs
@@ -483,7 +483,7 @@ impl<'le> ::selectors::MatchAttrGeneric for ServoLayoutElement<'le> {
};
match attr.namespace {
NamespaceConstraint::Specific(ref ns) => {
- self.get_attr(ns, name).map_or(false, |attr| test(attr))
+ self.get_attr(&ns.url, name).map_or(false, |attr| test(attr))
},
NamespaceConstraint::Any => {
let attrs = unsafe {
@@ -970,7 +970,7 @@ impl<'le> ::selectors::MatchAttrGeneric for ServoThreadSafeLayoutElement<'le> {
where F: Fn(&str) -> bool {
match attr.namespace {
NamespaceConstraint::Specific(ref ns) => {
- self.get_attr(ns, &attr.name).map_or(false, |attr| test(attr))
+ self.get_attr(&ns.url, &attr.name).map_or(false, |attr| test(attr))
},
NamespaceConstraint::Any => {
unsafe {
diff --git a/components/script_layout_interface/Cargo.toml b/components/script_layout_interface/Cargo.toml
index b2ec16ab3e6..bd4ac66f410 100644
--- a/components/script_layout_interface/Cargo.toml
+++ b/components/script_layout_interface/Cargo.toml
@@ -27,7 +27,7 @@ plugins = {path = "../plugins"}
profile_traits = {path = "../profile_traits"}
range = {path = "../range"}
script_traits = {path = "../script_traits"}
-selectors = {version = "0.9", features = ["heap_size"]}
+selectors = {version = "0.10", features = ["heap_size"]}
string_cache = {version = "0.2.23", features = ["heap_size"]}
style = {path = "../style"}
url = {version = "1.2", features = ["heap_size"]}
diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock
index 152277c7189..2b4bb06119a 100644
--- a/components/servo/Cargo.lock
+++ b/components/servo/Cargo.lock
@@ -790,7 +790,7 @@ dependencies = [
"servo-fontconfig 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"simd 0.1.0 (git+https://github.com/huonw/simd)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"style_traits 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -956,7 +956,7 @@ dependencies = [
"phf 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"tendril 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1162,10 +1162,10 @@ 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.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"style_traits 0.0.1",
"unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1931,10 +1931,10 @@ 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.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"tinyfiledialogs 0.1.0 (git+https://github.com/jdm/tinyfiledialogs)",
@@ -1967,8 +1967,8 @@ dependencies = [
"profile_traits 0.0.1",
"range 0.0.1",
"script_traits 0.0.1",
- "selectors 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
@@ -2016,7 +2016,7 @@ dependencies = [
[[package]]
name = "selectors"
-version = "0.9.0"
+version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2027,7 +2027,7 @@ dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"quickersort 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -2204,7 +2204,7 @@ dependencies = [
[[package]]
name = "string_cache"
-version = "0.2.23"
+version = "0.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2238,11 +2238,11 @@ dependencies = [
"plugins 0.0.1",
"rand 0.3.14 (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.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"style_traits 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2258,8 +2258,8 @@ dependencies = [
"cssparser 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.9.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.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"style_traits 0.0.1",
"url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2698,7 +2698,7 @@ dependencies = [
"phf 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"tendril 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml
index 91693e26069..000803d2777 100644
--- a/components/style/Cargo.toml
+++ b/components/style/Cargo.toml
@@ -38,11 +38,11 @@ num-traits = "0.1.32"
ordered-float = "0.2.2"
rand = "0.3"
rustc-serialize = "0.3"
-selectors = "0.9"
+selectors = "0.10.1"
serde = {version = "0.8", optional = true}
serde_macros = {version = "0.8", optional = true}
smallvec = "0.1"
-string_cache = {version = "0.2.23", features = ["heap_size"], optional = true}
+string_cache = {version = "0.2.24", features = ["heap_size"], optional = true}
style_traits = {path = "../style_traits"}
time = "0.1"
url = "1.2"
diff --git a/components/style/gecko_selector_impl.rs b/components/style/gecko_selector_impl.rs
index d78349af2aa..611e79eddcc 100644
--- a/components/style/gecko_selector_impl.rs
+++ b/components/style/gecko_selector_impl.rs
@@ -2,10 +2,12 @@
* 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::ToCss;
use element_state::ElementState;
use selector_impl::PseudoElementCascadeType;
use selector_impl::{attr_exists_selector_is_shareable, attr_equals_selector_is_shareable};
use selectors::parser::{ParserContext, SelectorImpl, AttrSelector};
+use std::fmt;
use string_cache::{Atom, WeakAtom, Namespace, WeakNamespace};
use stylesheets::Stylesheet;
@@ -93,6 +95,16 @@ impl PseudoElement {
}
}
+impl ToCss for PseudoElement {
+ fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
+ // FIXME: why does the atom contain one colon? Pseudo-element has two
+ debug_assert!(self.0.as_slice().starts_with(&[b':' as u16]) &&
+ !self.0.as_slice().starts_with(&[b':' as u16, b':' as u16]));
+ try!(dest.write_char(':'));
+ write!(dest, "{}", self.0)
+ }
+}
+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum NonTSPseudoClass {
AnyLink,
@@ -109,6 +121,26 @@ pub enum NonTSPseudoClass {
ReadOnly,
}
+impl ToCss for NonTSPseudoClass {
+ fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
+ use self::NonTSPseudoClass::*;
+ dest.write_str(match *self {
+ AnyLink => ":any-link",
+ Link => ":link",
+ Visited => ":visited",
+ Active => ":active",
+ Focus => ":focus",
+ Hover => ":hover",
+ Enabled => ":enabled",
+ Disabled => ":disabled",
+ Checked => ":checked",
+ Indeterminate => ":indeterminate",
+ ReadWrite => ":read-write",
+ ReadOnly => ":read-only",
+ })
+ }
+}
+
impl NonTSPseudoClass {
pub fn state_flag(&self) -> ElementState {
use element_state::*;
@@ -135,8 +167,9 @@ impl SelectorImpl for GeckoSelectorImpl {
type Identifier = Atom;
type ClassName = Atom;
type LocalName = Atom;
- type Namespace = Namespace;
- type BorrowedNamespace = WeakNamespace;
+ type NamespacePrefix = Atom;
+ type NamespaceUrl = Namespace;
+ type BorrowedNamespaceUrl = WeakNamespace;
type BorrowedLocalName = WeakAtom;
type PseudoElement = PseudoElement;
diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs
index 7b19126aeb6..aaf9ddfe88c 100644
--- a/components/style/properties/properties.mako.rs
+++ b/components/style/properties/properties.mako.rs
@@ -468,7 +468,7 @@ fn append_serialization<'a, W, I>(dest: &mut W,
return append_declaration_value(dest, appendable_value, is_important);
}
- write!(dest, "{}:", property_name);
+ try!(write!(dest, "{}:", property_name));
// for normal parsed values, add a space between key: and value
match &appendable_value {
diff --git a/components/style/restyle_hints.rs b/components/style/restyle_hints.rs
index e0688567550..a876dbf54cc 100644
--- a/components/style/restyle_hints.rs
+++ b/components/style/restyle_hints.rs
@@ -220,7 +220,7 @@ impl<'a, E> Element for ElementWrapper<'a, E>
self.element.get_local_name()
}
- fn get_namespace(&self) -> &<Self::Impl as SelectorImpl>::BorrowedNamespace {
+ fn get_namespace(&self) -> &<Self::Impl as SelectorImpl>::BorrowedNamespaceUrl {
self.element.get_namespace()
}
diff --git a/components/style/servo_selector_impl.rs b/components/style/servo_selector_impl.rs
index fab4315dd9f..f69b1cb9e12 100644
--- a/components/style/servo_selector_impl.rs
+++ b/components/style/servo_selector_impl.rs
@@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use attr::{AttrIdentifier, AttrValue};
+use cssparser::ToCss;
use element_state::ElementState;
use error_reporting::StdoutErrorReporter;
use parser::ParserContextExtraData;
@@ -11,6 +12,7 @@ use selector_impl::{ElementExt, PseudoElementCascadeType, TheSelectorImpl};
use selector_impl::{attr_exists_selector_is_shareable, attr_equals_selector_is_shareable};
use selectors::parser::{AttrSelector, ParserContext, SelectorImpl};
use selectors::{Element, MatchAttrGeneric};
+use std::fmt;
use std::process;
use string_cache::{Atom, Namespace};
use stylesheets::{Stylesheet, Origin};
@@ -28,6 +30,20 @@ pub enum PseudoElement {
DetailsContent,
}
+impl ToCss for PseudoElement {
+ fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
+ use self::PseudoElement::*;
+ dest.write_str(match *self {
+ Before => "::before",
+ After => "::after",
+ Selection => "::selection",
+ DetailsSummary => "::-servo-details-summary",
+ DetailsContent => "::-servo-details-content",
+ })
+ }
+}
+
+
impl PseudoElement {
#[inline]
pub fn is_before_or_after(&self) -> bool {
@@ -70,6 +86,29 @@ pub enum NonTSPseudoClass {
Target,
}
+impl ToCss for NonTSPseudoClass {
+ fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
+ use self::NonTSPseudoClass::*;
+ dest.write_str(match *self {
+ AnyLink => ":any-link",
+ Link => ":link",
+ Visited => ":visited",
+ Active => ":active",
+ Focus => ":focus",
+ Hover => ":hover",
+ Enabled => ":enabled",
+ Disabled => ":disabled",
+ Checked => ":checked",
+ Indeterminate => ":indeterminate",
+ ReadWrite => ":read-write",
+ ReadOnly => ":read-only",
+ PlaceholderShown => ":placeholder-shown",
+ Target => ":target",
+ ServoNonZeroBorder => ":-servo-nonzero-border",
+ })
+ }
+}
+
impl NonTSPseudoClass {
pub fn state_flag(&self) -> ElementState {
use element_state::*;
@@ -106,9 +145,10 @@ impl SelectorImpl for ServoSelectorImpl {
type Identifier = Atom;
type ClassName = Atom;
type LocalName = Atom;
- type Namespace = Namespace;
+ type NamespacePrefix = Atom;
+ type NamespaceUrl = Namespace;
type BorrowedLocalName = Atom;
- type BorrowedNamespace = Namespace;
+ type BorrowedNamespaceUrl = Namespace;
fn attr_exists_selector_is_shareable(attr_selector: &AttrSelector<Self>) -> bool {
attr_exists_selector_is_shareable(attr_selector)
@@ -283,7 +323,7 @@ impl MatchAttrGeneric for ServoElementSnapshot {
let html = self.is_html_element_in_html_document;
let local_name = if html { &attr.lower_name } else { &attr.name };
match attr.namespace {
- NamespaceConstraint::Specific(ref ns) => self.get_attr(ns, local_name),
+ NamespaceConstraint::Specific(ref ns) => self.get_attr(&ns.url, local_name),
NamespaceConstraint::Any => self.get_attr_ignore_ns(local_name),
}.map_or(false, |v| test(v))
}
diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs
index 25bb03174e0..8d234540adc 100644
--- a/components/style/stylesheets.rs
+++ b/components/style/stylesheets.rs
@@ -58,7 +58,11 @@ pub struct Stylesheet {
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum CSSRule {
Charset(String),
- Namespace(Option<String>, Namespace),
+ Namespace {
+ /// `None` for the default Namespace
+ prefix: Option<Atom>,
+ url: Namespace,
+ },
Style(StyleRule),
Media(MediaRule),
FontFace(FontFaceRule),
@@ -143,13 +147,13 @@ impl Stylesheet {
while let Some(result) = iter.next() {
match result {
Ok(rule) => {
- if let CSSRule::Namespace(ref prefix, ref namespace) = rule {
+ if let CSSRule::Namespace { ref prefix, ref url } = rule {
if let Some(prefix) = prefix.as_ref() {
iter.parser.context.selector_context.namespace_prefixes.insert(
- prefix.clone(), namespace.clone());
+ prefix.clone(), url.clone());
} else {
iter.parser.context.selector_context.default_namespace =
- Some(namespace.clone());
+ Some(url.clone());
}
}
@@ -435,9 +439,12 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
if self.state.get() <= State::Namespaces {
self.state.set(State::Namespaces);
- let prefix = input.try(|input| input.expect_ident()).ok().map(|p| p.into_owned());
+ let prefix = input.try(|input| input.expect_ident()).ok().map(|p| p.into());
let url = Namespace(Atom::from(try!(input.expect_url_or_string())));
- return Ok(AtRuleType::WithoutBlock(CSSRule::Namespace(prefix, url)))
+ return Ok(AtRuleType::WithoutBlock(CSSRule::Namespace {
+ prefix: prefix,
+ url: url,
+ }))
} else {
return Err(()) // "@namespace must be before any rule but @charset and @import"
}
diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock
index 5855f98d9e0..32456904fff 100644
--- a/ports/cef/Cargo.lock
+++ b/ports/cef/Cargo.lock
@@ -707,7 +707,7 @@ dependencies = [
"servo-fontconfig 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"simd 0.1.0 (git+https://github.com/huonw/simd)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"style_traits 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -864,7 +864,7 @@ dependencies = [
"phf 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"tendril 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1070,10 +1070,10 @@ 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.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"style_traits 0.0.1",
"unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1783,10 +1783,10 @@ 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.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"tinyfiledialogs 0.1.0 (git+https://github.com/jdm/tinyfiledialogs)",
@@ -1819,8 +1819,8 @@ dependencies = [
"profile_traits 0.0.1",
"range 0.0.1",
"script_traits 0.0.1",
- "selectors 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
@@ -1858,7 +1858,7 @@ dependencies = [
[[package]]
name = "selectors"
-version = "0.9.0"
+version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1869,7 +1869,7 @@ dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"quickersort 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -2087,7 +2087,7 @@ dependencies = [
[[package]]
name = "string_cache"
-version = "0.2.23"
+version = "0.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2121,11 +2121,11 @@ dependencies = [
"plugins 0.0.1",
"rand 0.3.14 (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.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"style_traits 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2558,7 +2558,7 @@ dependencies = [
"phf 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"tendril 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
diff --git a/ports/geckolib/Cargo.lock b/ports/geckolib/Cargo.lock
index 51fbc37f50b..a920fdf7118 100644
--- a/ports/geckolib/Cargo.lock
+++ b/ports/geckolib/Cargo.lock
@@ -11,7 +11,7 @@ dependencies = [
"libc 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
- "selectors 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"style_traits 0.0.1",
"url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -170,7 +170,7 @@ dependencies = [
"gecko_bindings 0.0.1",
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
- "selectors 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -311,7 +311,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "selectors"
-version = "0.9.0"
+version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -320,7 +320,7 @@ dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"quickersort 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "string_cache 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
+ "string_cache 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -335,7 +335,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "string_cache"
-version = "0.2.23"
+version = "0.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -367,7 +367,7 @@ dependencies = [
"ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (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.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "selectors 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"style_traits 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/ports/geckolib/Cargo.toml b/ports/geckolib/Cargo.toml
index 603d5d466ea..72eb2c7b0c5 100644
--- a/ports/geckolib/Cargo.toml
+++ b/ports/geckolib/Cargo.toml
@@ -19,7 +19,7 @@ lazy_static = "0.2"
libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]}
num_cpus = "0.2.2"
-selectors = "0.9"
+selectors = "0.10"
style = {path = "../../components/style", features = ["gecko"]}
style_traits = {path = "../../components/style_traits"}
url = "1.2"
diff --git a/ports/geckolib/string_cache/Cargo.toml b/ports/geckolib/string_cache/Cargo.toml
index 4fd3daf6dfa..6dd2d704896 100644
--- a/ports/geckolib/string_cache/Cargo.toml
+++ b/ports/geckolib/string_cache/Cargo.toml
@@ -14,5 +14,5 @@ cfg-if = "0.1.0"
gecko_bindings = {version = "0.0.1", path = "../gecko_bindings"}
heapsize = "0.3.5"
libc = "0.2"
-selectors = "0.9"
+selectors = "0.10"
serde = "0.8"
diff --git a/ports/geckolib/string_cache/namespace.rs b/ports/geckolib/string_cache/namespace.rs
index 6aadd0e3203..d3d57285b5a 100644
--- a/ports/geckolib/string_cache/namespace.rs
+++ b/ports/geckolib/string_cache/namespace.rs
@@ -5,6 +5,7 @@
use gecko_bindings::structs::nsIAtom;
use selectors::bloom::BloomHash;
use std::borrow::Borrow;
+use std::fmt;
use std::ops::Deref;
use {Atom, WeakAtom};
@@ -29,6 +30,12 @@ impl Deref for Namespace {
}
}
+impl fmt::Display for Namespace {
+ fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
+ self.0.fmt(w)
+ }
+}
+
impl Borrow<WeakNamespace> for Namespace {
#[inline]
fn borrow(&self) -> &WeakNamespace {
diff --git a/ports/geckolib/wrapper.rs b/ports/geckolib/wrapper.rs
index 5d35acf6ef7..860173820d6 100644
--- a/ports/geckolib/wrapper.rs
+++ b/ports/geckolib/wrapper.rs
@@ -587,7 +587,7 @@ impl AttrSelectorHelpers for AttrSelector<GeckoSelectorImpl> {
fn ns_or_null(&self) -> *mut nsIAtom {
match self.namespace {
NamespaceConstraint::Any => ptr::null_mut(),
- NamespaceConstraint::Specific(ref ns) => ns.0.as_ptr(),
+ NamespaceConstraint::Specific(ref ns) => ns.url.0.as_ptr(),
}
}
diff --git a/tests/unit/style/Cargo.toml b/tests/unit/style/Cargo.toml
index 333ccc2574a..22bdc1c86e4 100644
--- a/tests/unit/style/Cargo.toml
+++ b/tests/unit/style/Cargo.toml
@@ -14,7 +14,7 @@ app_units = "0.3"
cssparser = {version = "0.5.7", features = ["heap_size"]}
euclid = "0.9"
rustc-serialize = "0.3"
-selectors = {version = "0.9", features = ["heap_size"]}
+selectors = {version = "0.10", features = ["heap_size"]}
string_cache = {version = "0.2.23", features = ["heap_size"]}
style = {path = "../../../components/style"}
style_traits = {path = "../../../components/style_traits"}
diff --git a/tests/unit/style/parsing/mod.rs b/tests/unit/style/parsing/mod.rs
index c99032417ee..d0989d01582 100644
--- a/tests/unit/style/parsing/mod.rs
+++ b/tests/unit/style/parsing/mod.rs
@@ -15,6 +15,9 @@ fn parse<T, F: Fn(&mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()>
// This is a macro so that the file/line information
// is preserved in the panic
macro_rules! assert_roundtrip {
+ ($fun:expr, $string:expr) => {
+ assert_roundtrip!($fun, $string, $string);
+ };
($fun:expr, $input:expr, $output:expr) => {
let parsed = $crate::parsing::parse($fun, $input)
.expect(&format!("Failed to parse {}", $input));
@@ -31,3 +34,4 @@ macro_rules! assert_roundtrip {
mod basic_shape;
mod position;
+mod selectors;
diff --git a/tests/unit/style/parsing/selectors.rs b/tests/unit/style/parsing/selectors.rs
new file mode 100644
index 00000000000..abd1a3b5e9a
--- /dev/null
+++ b/tests/unit/style/parsing/selectors.rs
@@ -0,0 +1,22 @@
+/* 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 cssparser::Parser;
+use selectors::parser::{Selector, ParserContext, parse_selector_list};
+use style::selector_impl::TheSelectorImpl;
+
+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())
+}
+
+#[test]
+fn test_selectors() {
+ assert_roundtrip!(parse, "div");
+ assert_roundtrip!(parse, "svg|circle");
+ assert_roundtrip!(parse, "p:before", "p::before");
+ assert_roundtrip!(parse, "[border = \"0\"]:-servo-nonzero-border ~ ::-servo-details-summary");
+}
diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs
index b388416d803..a816c747876 100644
--- a/tests/unit/style/stylesheets.rs
+++ b/tests/unit/style/stylesheets.rs
@@ -8,7 +8,7 @@ use selectors::parser::*;
use std::borrow::ToOwned;
use std::sync::Arc;
use std::sync::Mutex;
-use string_cache::{Atom, Namespace};
+use string_cache::{Atom, Namespace as NsAtom};
use style::error_reporting::ParseErrorReporter;
use style::keyframes::{Keyframe, KeyframeSelector, KeyframePercentage};
use style::parser::ParserContextExtraData;
@@ -38,13 +38,19 @@ fn test_parse_stylesheet() {
media: None,
dirty_on_viewport_size_change: false,
rules: vec![
- CSSRule::Namespace(None, Namespace(Atom::from("http://www.w3.org/1999/xhtml"))),
+ CSSRule::Namespace {
+ prefix: None,
+ url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
+ },
CSSRule::Style(StyleRule {
selectors: vec![
Selector {
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: vec![
- SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))),
+ SimpleSelector::Namespace(Namespace {
+ prefix: None,
+ url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
+ }),
SimpleSelector::LocalName(LocalName {
name: atom!("input"),
lower_name: atom!("input"),
@@ -52,7 +58,10 @@ fn test_parse_stylesheet() {
SimpleSelector::AttrEqual(AttrSelector {
name: atom!("type"),
lower_name: atom!("type"),
- namespace: NamespaceConstraint::Specific(ns!()),
+ namespace: NamespaceConstraint::Specific(Namespace {
+ prefix: None,
+ url: ns!()
+ }),
}, "hidden".to_owned(), CaseSensitivity::CaseInsensitive)
],
next: None,
@@ -74,7 +83,10 @@ fn test_parse_stylesheet() {
Selector {
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: vec![
- SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))),
+ SimpleSelector::Namespace(Namespace {
+ prefix: None,
+ url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
+ }),
SimpleSelector::LocalName(LocalName {
name: atom!("html"),
lower_name: atom!("html"),
@@ -88,7 +100,10 @@ fn test_parse_stylesheet() {
Selector {
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: vec![
- SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))),
+ SimpleSelector::Namespace(Namespace {
+ prefix: None,
+ url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
+ }),
SimpleSelector::LocalName(LocalName {
name: atom!("body"),
lower_name: atom!("body"),
@@ -113,12 +128,18 @@ fn test_parse_stylesheet() {
Selector {
compound_selectors: Arc::new(CompoundSelector {
simple_selectors: vec![
- SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))),
+ SimpleSelector::Namespace(Namespace {
+ prefix: None,
+ url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
+ }),
SimpleSelector::Class(Atom::from("ok")),
],
next: Some((Arc::new(CompoundSelector {
simple_selectors: vec![
- SimpleSelector::Namespace(Namespace(Atom::from("http://www.w3.org/1999/xhtml"))),
+ SimpleSelector::Namespace(Namespace {
+ prefix: None,
+ url: NsAtom(Atom::from("http://www.w3.org/1999/xhtml"))
+ }),
SimpleSelector::ID(Atom::from("d1")),
],
next: None,