diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2016-08-18 14:25:24 +0200 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2016-08-18 14:46:24 +0200 |
commit | d690bd2382300c84f402b8c17ff7d633007ade03 (patch) | |
tree | f8c98308663787d9c4e6c0915643b0f036494227 /components | |
parent | 4e7c689a815198a51f96fdcac48a15eabf2157c0 (diff) | |
download | servo-d690bd2382300c84f402b8c17ff7d633007ade03.tar.gz servo-d690bd2382300c84f402b8c17ff7d633007ade03.zip |
Update selectors to 0.10, with ToCss serialization.
Diffstat (limited to 'components')
-rw-r--r-- | components/layout/Cargo.toml | 2 | ||||
-rw-r--r-- | components/script/Cargo.toml | 2 | ||||
-rw-r--r-- | components/script/dom/element.rs | 2 | ||||
-rw-r--r-- | components/script/layout_wrapper.rs | 4 | ||||
-rw-r--r-- | components/script_layout_interface/Cargo.toml | 2 | ||||
-rw-r--r-- | components/servo/Cargo.lock | 32 | ||||
-rw-r--r-- | components/style/Cargo.toml | 4 | ||||
-rw-r--r-- | components/style/gecko_selector_impl.rs | 37 | ||||
-rw-r--r-- | components/style/restyle_hints.rs | 2 | ||||
-rw-r--r-- | components/style/servo_selector_impl.rs | 46 |
10 files changed, 103 insertions, 30 deletions
diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml index 5ecfc91cf2c..417e7819d8b 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 135ead85732..ac1467fda00 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -65,7 +65,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 0e13d7bb742..a1371d5df56 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)", @@ -1968,8 +1968,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", @@ -2017,7 +2017,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)", @@ -2028,7 +2028,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]] @@ -2205,7 +2205,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)", @@ -2239,11 +2239,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)", @@ -2259,8 +2259,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)", @@ -2710,7 +2710,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 7002483e95b..3944d21f959 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 = String; + type NamespaceUrl = Namespace; + type BorrowedNamespaceUrl = WeakNamespace; type BorrowedLocalName = WeakAtom; type PseudoElement = PseudoElement; 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..c287823f2d5 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 = String; + 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)) } |