Skip to content

Commit

Permalink
Update selectors to 0.10, with ToCss serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Aug 18, 2016
1 parent 4e7c689 commit d690bd2
Show file tree
Hide file tree
Showing 20 changed files with 186 additions and 62 deletions.
2 changes: 1 addition & 1 deletion components/layout/Cargo.toml
Expand Up @@ -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"]}
Expand Down
2 changes: 1 addition & 1 deletion components/script/Cargo.toml
Expand Up @@ -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"]}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/element.rs
Expand Up @@ -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())
})
Expand Down
4 changes: 2 additions & 2 deletions components/script/layout_wrapper.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion components/script_layout_interface/Cargo.toml
Expand Up @@ -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"]}
Expand Down
32 changes: 16 additions & 16 deletions components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/style/Cargo.toml
Expand Up @@ -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"
Expand Down
37 changes: 35 additions & 2 deletions components/style/gecko_selector_impl.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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::*;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion components/style/restyle_hints.rs
Expand Up @@ -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()
}

Expand Down
46 changes: 43 additions & 3 deletions components/style/servo_selector_impl.rs
Expand Up @@ -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;
Expand All @@ -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};
Expand All @@ -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 {
Expand Down Expand Up @@ -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::*;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit d690bd2

Please sign in to comment.