Auto merge of #14320 - servo:selectorsup, r=nox

Update to selectors 0.15

<!-- Please describe your changes on the following line: -->

---
<!-- 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: -->
- [ ] There are tests for these changes OR
- [x] 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/14320)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-11-22 10:44:03 -06:00 committed by GitHub
commit f37fc5ea5e
31 changed files with 292 additions and 246 deletions

View file

@ -34,7 +34,7 @@ range = {path = "../range"}
rayon = "0.5" rayon = "0.5"
script_layout_interface = {path = "../script_layout_interface"} script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"} script_traits = {path = "../script_traits"}
selectors = "0.14" selectors = "0.15"
serde = "0.8" serde = "0.8"
serde_derive = "0.8" serde_derive = "0.8"
serde_json = "0.8" serde_json = "0.8"

View file

@ -128,8 +128,8 @@ pub fn update_animation_state(constellation_chan: &IpcSender<ConstellationMsg>,
/// Recalculates style for a set of animations. This does *not* run with the DOM /// Recalculates style for a set of animations. This does *not* run with the DOM
/// lock held. /// lock held.
// NB: This is specific for ServoSelectorImpl, since the layout context and the // NB: This is specific for SelectorImpl, since the layout context and the
// flows are ServoSelectorImpl specific too. If that goes away at some point, // flows are SelectorImpl specific too. If that goes away at some point,
// this should be made generic. // this should be made generic.
pub fn recalc_style_for_animations(context: &SharedLayoutContext, pub fn recalc_style_for_animations(context: &SharedLayoutContext,
flow: &mut Flow, flow: &mut Flow,

View file

@ -31,7 +31,7 @@ rayon = "0.5"
script = {path = "../script"} script = {path = "../script"}
script_layout_interface = {path = "../script_layout_interface"} script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"} script_traits = {path = "../script_traits"}
selectors = "0.14" selectors = "0.15"
serde_derive = "0.8" serde_derive = "0.8"
serde_json = "0.8" serde_json = "0.8"
servo_url = {path = "../url"} servo_url = {path = "../url"}

View file

@ -66,7 +66,7 @@ regex = "0.1.43"
rustc-serialize = "0.3" rustc-serialize = "0.3"
script_layout_interface = {path = "../script_layout_interface"} script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"} script_traits = {path = "../script_traits"}
selectors = "0.14" selectors = "0.15"
serde = "0.8" serde = "0.8"
servo_atoms = {path = "../atoms"} servo_atoms = {path = "../atoms"}
servo_url = {path = "../url", features = ["servo"] } servo_url = {path = "../url", features = ["servo"] }

View file

@ -73,7 +73,7 @@ use html5ever_atoms::{Prefix, LocalName, Namespace, QualName};
use parking_lot::RwLock; use parking_lot::RwLock;
use selectors::matching::{ElementFlags, MatchingReason, matches}; use selectors::matching::{ElementFlags, MatchingReason, matches};
use selectors::matching::{HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS}; 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 servo_atoms::Atom;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::borrow::Cow; use std::borrow::Cow;
@ -92,7 +92,7 @@ use style::properties::{DeclaredValue, Importance};
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
use style::properties::longhands::{background_image, border_spacing, font_family, font_size, overflow_x}; use style::properties::longhands::{background_image, border_spacing, font_family, font_size, overflow_x};
use style::restyle_hints::RESTYLE_SELF; use style::restyle_hints::RESTYLE_SELF;
use style::selector_parser::{NonTSPseudoClass, RestyleDamage, ServoSelectorImpl}; use style::selector_parser::{NonTSPseudoClass, RestyleDamage, SelectorImpl, SelectorParser};
use style::sink::Push; use style::sink::Push;
use style::stylist::ApplicableDeclarationBlock; use style::stylist::ApplicableDeclarationBlock;
use style::values::CSSFloat; use style::values::CSSFloat;
@ -1885,10 +1885,10 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-matches // https://dom.spec.whatwg.org/#dom-element-matches
fn Matches(&self, selectors: DOMString) -> Fallible<bool> { 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), Err(()) => Err(Error::Syntax),
Ok(ref selectors) => { Ok(selectors) => {
Ok(matches(selectors, &Root::from_ref(self), None, MatchingReason::Other)) 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 // https://dom.spec.whatwg.org/#dom-element-closest
fn Closest(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> { 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), Err(()) => Err(Error::Syntax),
Ok(ref selectors) => { Ok(selectors) => {
let root = self.upcast::<Node>(); let root = self.upcast::<Node>();
for element in root.inclusive_ancestors() { for element in root.inclusive_ancestors() {
if let Some(element) = Root::downcast::<Element>(element) { 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)); return Ok(Some(element));
} }
} }
@ -2141,9 +2141,9 @@ impl VirtualMethods for Element {
} }
impl<'a> ::selectors::MatchAttrGeneric for Root<Element> { impl<'a> ::selectors::MatchAttrGeneric for Root<Element> {
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 where F: Fn(&str) -> bool
{ {
use ::selectors::Element; use ::selectors::Element;

View file

@ -71,8 +71,7 @@ use script_layout_interface::{LayoutElementType, LayoutNodeType, TrustedNodeAddr
use script_layout_interface::message::Msg; use script_layout_interface::message::Msg;
use script_traits::UntrustedNodeAddress; use script_traits::UntrustedNodeAddress;
use selectors::matching::{MatchingReason, matches}; use selectors::matching::{MatchingReason, matches};
use selectors::parser::Selector; use selectors::parser::SelectorList;
use selectors::parser::parse_author_origin_selector_list_from_str;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cell::{Cell, UnsafeCell}; use std::cell::{Cell, UnsafeCell};
@ -83,7 +82,7 @@ use std::mem;
use std::ops::Range; use std::ops::Range;
use std::sync::Arc; use std::sync::Arc;
use style::dom::OpaqueNode; use style::dom::OpaqueNode;
use style::selector_parser::ServoSelectorImpl; use style::selector_parser::{SelectorImpl, SelectorParser};
use style::stylesheets::Stylesheet; use style::stylesheets::Stylesheet;
use style::thread_state; use style::thread_state;
use uuid::Uuid; use uuid::Uuid;
@ -305,12 +304,12 @@ impl Node {
} }
pub struct QuerySelectorIterator { pub struct QuerySelectorIterator {
selectors: Vec<Selector<ServoSelectorImpl>>, selectors: SelectorList<SelectorImpl>,
iterator: TreeIterator, iterator: TreeIterator,
} }
impl<'a> QuerySelectorIterator { impl<'a> QuerySelectorIterator {
fn new(iter: TreeIterator, selectors: Vec<Selector<ServoSelectorImpl>>) fn new(iter: TreeIterator, selectors: SelectorList<SelectorImpl>)
-> QuerySelectorIterator { -> QuerySelectorIterator {
QuerySelectorIterator { QuerySelectorIterator {
selectors: selectors, selectors: selectors,
@ -323,7 +322,7 @@ impl<'a> Iterator for QuerySelectorIterator {
type Item = Root<Node>; type Item = Root<Node>;
fn next(&mut self) -> Option<Root<Node>> { fn next(&mut self) -> Option<Root<Node>> {
let selectors = &self.selectors; let selectors = &self.selectors.0;
// TODO(cgaebel): Is it worth it to build a bloom filter here // TODO(cgaebel): Is it worth it to build a bloom filter here
// (instead of passing `None`)? Probably. // (instead of passing `None`)? Probably.
self.iterator.by_ref().filter_map(|node| { self.iterator.by_ref().filter_map(|node| {
@ -690,13 +689,13 @@ impl Node {
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector // https://dom.spec.whatwg.org/#dom-parentnode-queryselector
pub fn query_selector(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> { pub fn query_selector(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
// Step 1. // Step 1.
match parse_author_origin_selector_list_from_str(&selectors) { match SelectorParser::parse_author_origin_no_namespace(&selectors) {
// Step 2. // Step 2.
Err(()) => Err(Error::Syntax), Err(()) => Err(Error::Syntax),
// Step 3. // Step 3.
Ok(ref selectors) => { Ok(selectors) => {
Ok(self.traverse_preorder().filter_map(Root::downcast).find(|element| { 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) pub fn query_selector_iter(&self, selectors: DOMString)
-> Fallible<QuerySelectorIterator> { -> Fallible<QuerySelectorIterator> {
// Step 1. // Step 1.
match parse_author_origin_selector_list_from_str(&selectors) { match SelectorParser::parse_author_origin_no_namespace(&selectors) {
// Step 2. // Step 2.
Err(()) => Err(Error::Syntax), Err(()) => Err(Error::Syntax),
// Step 3. // Step 3.

View file

@ -66,7 +66,7 @@ use style::dom::{LayoutIterator, NodeInfo, OpaqueNode, PresentationalHintsSynthe
use style::dom::UnsafeNode; use style::dom::UnsafeNode;
use style::element_state::*; use style::element_state::*;
use style::properties::{ComputedValues, PropertyDeclarationBlock}; use style::properties::{ComputedValues, PropertyDeclarationBlock};
use style::selector_parser::{NonTSPseudoClass, PseudoElement, RestyleDamage, ServoSelectorImpl}; use style::selector_parser::{NonTSPseudoClass, PseudoElement, RestyleDamage, SelectorImpl};
use style::sink::Push; use style::sink::Push;
use style::str::is_whitespace; use style::str::is_whitespace;
use style::stylist::ApplicableDeclarationBlock; use style::stylist::ApplicableDeclarationBlock;
@ -560,9 +560,9 @@ fn as_element<'le>(node: LayoutJS<Node>) -> Option<ServoLayoutElement<'le>> {
} }
impl<'le> ::selectors::MatchAttrGeneric for ServoLayoutElement<'le> { impl<'le> ::selectors::MatchAttrGeneric for ServoLayoutElement<'le> {
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 { where F: Fn(&str) -> bool {
use ::selectors::Element; use ::selectors::Element;
let name = if self.is_html_element_in_html_document() { let name = if self.is_html_element_in_html_document() {
@ -1097,9 +1097,9 @@ impl<'le> ThreadSafeLayoutElement for ServoThreadSafeLayoutElement<'le> {
/// Note that the element implementation is needed only for selector matching, /// Note that the element implementation is needed only for selector matching,
/// not for inheritance (styles are inherited appropiately). /// not for inheritance (styles are inherited appropiately).
impl<'le> ::selectors::MatchAttrGeneric for ServoThreadSafeLayoutElement<'le> { impl<'le> ::selectors::MatchAttrGeneric for ServoThreadSafeLayoutElement<'le> {
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 { where F: Fn(&str) -> bool {
match attr.namespace { match attr.namespace {
NamespaceConstraint::Specific(ref ns) => { NamespaceConstraint::Specific(ref ns) => {

View file

@ -28,7 +28,7 @@ plugins = {path = "../plugins"}
profile_traits = {path = "../profile_traits"} profile_traits = {path = "../profile_traits"}
range = {path = "../range"} range = {path = "../range"}
script_traits = {path = "../script_traits"} script_traits = {path = "../script_traits"}
selectors = "0.14" selectors = "0.15"
servo_atoms = {path = "../atoms"} servo_atoms = {path = "../atoms"}
servo_url = {path = "../url"} servo_url = {path = "../url"}
style = {path = "../style"} style = {path = "../style"}

View file

@ -22,7 +22,7 @@ use style::data::ElementData;
use style::dom::{LayoutIterator, NodeInfo, PresentationalHintsSynthetizer, TNode}; use style::dom::{LayoutIterator, NodeInfo, PresentationalHintsSynthetizer, TNode};
use style::dom::OpaqueNode; use style::dom::OpaqueNode;
use style::properties::ServoComputedValues; use style::properties::ServoComputedValues;
use style::selector_parser::{PseudoElement, PseudoElementCascadeType, RestyleDamage, ServoSelectorImpl}; use style::selector_parser::{PseudoElement, PseudoElementCascadeType, RestyleDamage, SelectorImpl};
#[derive(Copy, PartialEq, Clone, Debug)] #[derive(Copy, PartialEq, Clone, Debug)]
pub enum PseudoElementType<T> { pub enum PseudoElementType<T> {
@ -147,7 +147,7 @@ impl<ConcreteNode> Iterator for TreeIterator<ConcreteNode>
pub trait ThreadSafeLayoutNode: Clone + Copy + GetLayoutData + NodeInfo + PartialEq + Sized { pub trait ThreadSafeLayoutNode: Clone + Copy + GetLayoutData + NodeInfo + PartialEq + Sized {
type ConcreteThreadSafeLayoutElement: type ConcreteThreadSafeLayoutElement:
ThreadSafeLayoutElement<ConcreteThreadSafeLayoutNode = Self> ThreadSafeLayoutElement<ConcreteThreadSafeLayoutNode = Self>
+ ::selectors::Element<Impl=ServoSelectorImpl>; + ::selectors::Element<Impl=SelectorImpl>;
type ChildrenIterator: Iterator<Item = Self> + Sized; type ChildrenIterator: Iterator<Item = Self> + Sized;
/// Converts self into an `OpaqueNode`. /// Converts self into an `OpaqueNode`.
@ -271,7 +271,7 @@ pub trait DangerousThreadSafeLayoutNode: ThreadSafeLayoutNode {
} }
pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug + pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
::selectors::Element<Impl=ServoSelectorImpl> + ::selectors::Element<Impl=SelectorImpl> +
GetLayoutData + GetLayoutData +
PresentationalHintsSynthetizer { PresentationalHintsSynthetizer {
type ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode<ConcreteThreadSafeLayoutElement = Self>; type ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode<ConcreteThreadSafeLayoutElement = Self>;

View file

@ -44,7 +44,7 @@ quickersort = "2.0.0"
rand = "0.3" rand = "0.3"
rayon = "0.5" rayon = "0.5"
rustc-serialize = "0.3" rustc-serialize = "0.3"
selectors = "0.14" selectors = "0.15"
serde = {version = "0.8", optional = true} serde = {version = "0.8", optional = true}
serde_derive = {version = "0.8", optional = true} serde_derive = {version = "0.8", optional = true}
servo_atoms = {path = "../atoms", optional = true} servo_atoms = {path = "../atoms", optional = true}

View file

@ -4,15 +4,13 @@
use cssparser::ToCss; use cssparser::ToCss;
use element_state::ElementState; 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::{attr_equals_selector_is_shareable, attr_exists_selector_is_shareable};
use selector_parser::PseudoElementCascadeType; use selectors::parser::AttrSelector;
use selectors::parser::{AttrSelector, ParserContext, SelectorImpl}; use std::borrow::Cow;
use std::fmt; use std::fmt;
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace}; use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GeckoSelectorImpl;
/// NOTE: The boolean field represents whether this element is an anonymous box. /// NOTE: The boolean field represents whether this element is an anonymous box.
/// ///
/// This is just for convenience, instead of recomputing it. Also, note that /// This is just for convenience, instead of recomputing it. Also, note that
@ -161,7 +159,10 @@ impl NonTSPseudoClass {
} }
} }
impl SelectorImpl for GeckoSelectorImpl { #[derive(Clone, Debug, PartialEq)]
pub struct SelectorImpl;
impl ::selectors::SelectorImpl for SelectorImpl {
type AttrValue = Atom; type AttrValue = Atom;
type Identifier = Atom; type Identifier = Atom;
type ClassName = Atom; type ClassName = Atom;
@ -182,11 +183,14 @@ impl SelectorImpl for GeckoSelectorImpl {
value: &Self::AttrValue) -> bool { value: &Self::AttrValue) -> bool {
attr_equals_selector_is_shareable(attr_selector, value) attr_equals_selector_is_shareable(attr_selector, value)
} }
}
fn parse_non_ts_pseudo_class(_context: &ParserContext<Self>, impl<'a> ::selectors::Parser for SelectorParser<'a> {
name: &str) -> Result<NonTSPseudoClass, ()> { type Impl = SelectorImpl;
fn parse_non_ts_pseudo_class(&self, name: Cow<str>) -> Result<NonTSPseudoClass, ()> {
use self::NonTSPseudoClass::*; use self::NonTSPseudoClass::*;
let pseudo_class = match_ignore_ascii_case! { name, let pseudo_class = match_ignore_ascii_case! { &name,
"any-link" => AnyLink, "any-link" => AnyLink,
"link" => Link, "link" => Link,
"visited" => Visited, "visited" => Visited,
@ -205,16 +209,23 @@ impl SelectorImpl for GeckoSelectorImpl {
Ok(pseudo_class) Ok(pseudo_class)
} }
fn parse_pseudo_element(context: &ParserContext<Self>, fn parse_pseudo_element(&self, name: Cow<str>) -> Result<PseudoElement, ()> {
name: &str) -> Result<PseudoElement, ()> { match PseudoElement::from_slice(&name, self.in_user_agent_stylesheet()) {
match PseudoElement::from_slice(name, context.in_user_agent_stylesheet) {
Some(pseudo) => Ok(pseudo), Some(pseudo) => Ok(pseudo),
None => Err(()), 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] #[inline]
pub fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType { pub fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType {
if Self::pseudo_is_before_or_after(pseudo) { if Self::pseudo_is_before_or_after(pseudo) {

View file

@ -9,7 +9,7 @@ use gecko_bindings::bindings;
use gecko_bindings::structs::ServoElementSnapshot; use gecko_bindings::structs::ServoElementSnapshot;
use gecko_bindings::structs::ServoElementSnapshotFlags as Flags; use gecko_bindings::structs::ServoElementSnapshotFlags as Flags;
use restyle_hints::ElementSnapshot; use restyle_hints::ElementSnapshot;
use selector_parser::TheSelectorImpl; use selector_parser::SelectorImpl;
use selectors::parser::AttrSelector; use selectors::parser::AttrSelector;
use string_cache::Atom; use string_cache::Atom;
@ -36,9 +36,9 @@ impl GeckoElementSnapshot {
} }
impl ::selectors::MatchAttr for GeckoElementSnapshot { impl ::selectors::MatchAttr for GeckoElementSnapshot {
type Impl = TheSelectorImpl; type Impl = SelectorImpl;
fn match_attr_has(&self, attr: &AttrSelector<TheSelectorImpl>) -> bool { fn match_attr_has(&self, attr: &AttrSelector<SelectorImpl>) -> bool {
unsafe { unsafe {
bindings::Gecko_SnapshotHasAttr(self.0, bindings::Gecko_SnapshotHasAttr(self.0,
attr.ns_or_null(), attr.ns_or_null(),
@ -46,7 +46,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
} }
} }
fn match_attr_equals(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool { fn match_attr_equals(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
unsafe { unsafe {
bindings::Gecko_SnapshotAttrEquals(self.0, bindings::Gecko_SnapshotAttrEquals(self.0,
attr.ns_or_null(), attr.ns_or_null(),
@ -56,7 +56,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
} }
} }
fn match_attr_equals_ignore_ascii_case(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool { fn match_attr_equals_ignore_ascii_case(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
unsafe { unsafe {
bindings::Gecko_SnapshotAttrEquals(self.0, bindings::Gecko_SnapshotAttrEquals(self.0,
attr.ns_or_null(), attr.ns_or_null(),
@ -65,7 +65,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
/* ignoreCase = */ true) /* ignoreCase = */ true)
} }
} }
fn match_attr_includes(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool { fn match_attr_includes(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
unsafe { unsafe {
bindings::Gecko_SnapshotAttrIncludes(self.0, bindings::Gecko_SnapshotAttrIncludes(self.0,
attr.ns_or_null(), attr.ns_or_null(),
@ -73,7 +73,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
value.as_ptr()) value.as_ptr())
} }
} }
fn match_attr_dash(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool { fn match_attr_dash(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
unsafe { unsafe {
bindings::Gecko_SnapshotAttrDashEquals(self.0, bindings::Gecko_SnapshotAttrDashEquals(self.0,
attr.ns_or_null(), attr.ns_or_null(),
@ -81,7 +81,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
value.as_ptr()) value.as_ptr())
} }
} }
fn match_attr_prefix(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool { fn match_attr_prefix(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
unsafe { unsafe {
bindings::Gecko_SnapshotAttrHasPrefix(self.0, bindings::Gecko_SnapshotAttrHasPrefix(self.0,
attr.ns_or_null(), attr.ns_or_null(),
@ -89,7 +89,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
value.as_ptr()) value.as_ptr())
} }
} }
fn match_attr_substring(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool { fn match_attr_substring(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
unsafe { unsafe {
bindings::Gecko_SnapshotAttrHasSubstring(self.0, bindings::Gecko_SnapshotAttrHasSubstring(self.0,
attr.ns_or_null(), attr.ns_or_null(),
@ -97,7 +97,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
value.as_ptr()) value.as_ptr())
} }
} }
fn match_attr_suffix(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool { fn match_attr_suffix(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
unsafe { unsafe {
bindings::Gecko_SnapshotAttrHasSuffix(self.0, bindings::Gecko_SnapshotAttrHasSuffix(self.0,
attr.ns_or_null(), attr.ns_or_null(),

View file

@ -12,7 +12,7 @@ use dom::{OpaqueNode, PresentationalHintsSynthetizer};
use element_state::ElementState; use element_state::ElementState;
use error_reporting::StdoutErrorReporter; use error_reporting::StdoutErrorReporter;
use gecko::restyle_damage::GeckoRestyleDamage; use gecko::restyle_damage::GeckoRestyleDamage;
use gecko::selector_parser::{GeckoSelectorImpl, NonTSPseudoClass, PseudoElement}; use gecko::selector_parser::{SelectorImpl, NonTSPseudoClass, PseudoElement};
use gecko::snapshot_helpers; use gecko::snapshot_helpers;
use gecko_bindings::bindings; use gecko_bindings::bindings;
use gecko_bindings::bindings::{Gecko_DropStyleChildrenIterator, Gecko_MaybeCreateStyleChildrenIterator}; use gecko_bindings::bindings::{Gecko_DropStyleChildrenIterator, Gecko_MaybeCreateStyleChildrenIterator};
@ -532,7 +532,7 @@ pub trait AttrSelectorHelpers {
fn select_name(&self, is_html_element_in_html_document: bool) -> *mut nsIAtom; fn select_name(&self, is_html_element_in_html_document: bool) -> *mut nsIAtom;
} }
impl AttrSelectorHelpers for AttrSelector<GeckoSelectorImpl> { impl AttrSelectorHelpers for AttrSelector<SelectorImpl> {
fn ns_or_null(&self) -> *mut nsIAtom { fn ns_or_null(&self) -> *mut nsIAtom {
match self.namespace { match self.namespace {
NamespaceConstraint::Any => ptr::null_mut(), NamespaceConstraint::Any => ptr::null_mut(),
@ -550,7 +550,7 @@ impl AttrSelectorHelpers for AttrSelector<GeckoSelectorImpl> {
} }
impl<'le> ::selectors::MatchAttr for GeckoElement<'le> { impl<'le> ::selectors::MatchAttr for GeckoElement<'le> {
type Impl = GeckoSelectorImpl; type Impl = SelectorImpl;
fn match_attr_has(&self, attr: &AttrSelector<Self::Impl>) -> bool { fn match_attr_has(&self, attr: &AttrSelector<Self::Impl>) -> bool {
unsafe { unsafe {

View file

@ -17,7 +17,7 @@ use dom::{TElement, TNode, TRestyleDamage, UnsafeNode};
use properties::{CascadeFlags, ComputedValues, SHAREABLE, cascade}; use properties::{CascadeFlags, ComputedValues, SHAREABLE, cascade};
use properties::longhands::display::computed_value as display; use properties::longhands::display::computed_value as display;
use rule_tree::StrongRuleNode; use rule_tree::StrongRuleNode;
use selector_parser::{PseudoElement, RestyleDamage, TheSelectorImpl}; use selector_parser::{PseudoElement, RestyleDamage, SelectorImpl};
use selectors::MatchAttr; use selectors::MatchAttr;
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
use selectors::matching::{AFFECTED_BY_PSEUDO_ELEMENTS, MatchingReason, StyleRelations}; use selectors::matching::{AFFECTED_BY_PSEUDO_ELEMENTS, MatchingReason, StyleRelations};
@ -535,7 +535,7 @@ pub trait MatchMethods : TElement {
// Compute the pseudo rule nodes. // Compute the pseudo rule nodes.
let mut per_pseudo: PseudoRuleNodes = HashMap::with_hasher(Default::default()); let mut per_pseudo: PseudoRuleNodes = HashMap::with_hasher(Default::default());
TheSelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| { SelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| {
debug_assert!(applicable_declarations.is_empty()); debug_assert!(applicable_declarations.is_empty());
stylist.push_applicable_declarations(self, parent_bf, None, stylist.push_applicable_declarations(self, parent_bf, None,
Some(&pseudo.clone()), Some(&pseudo.clone()),

View file

@ -8,8 +8,6 @@ use cssparser::{Parser, SourcePosition};
use error_reporting::ParseErrorReporter; use error_reporting::ParseErrorReporter;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI}; use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
use selector_parser::TheSelectorImpl;
use selectors::parser::ParserContext as SelectorParserContext;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use stylesheets::Origin; use stylesheets::Origin;
@ -38,7 +36,6 @@ impl ParserContextExtraData {
pub struct ParserContext<'a> { pub struct ParserContext<'a> {
pub stylesheet_origin: Origin, pub stylesheet_origin: Origin,
pub base_url: &'a ServoUrl, pub base_url: &'a ServoUrl,
pub selector_context: SelectorParserContext<TheSelectorImpl>,
pub error_reporter: Box<ParseErrorReporter + Send>, pub error_reporter: Box<ParseErrorReporter + Send>,
pub extra_data: ParserContextExtraData, pub extra_data: ParserContextExtraData,
} }
@ -48,12 +45,9 @@ impl<'a> ParserContext<'a> {
error_reporter: Box<ParseErrorReporter + Send>, error_reporter: Box<ParseErrorReporter + Send>,
extra_data: ParserContextExtraData) extra_data: ParserContextExtraData)
-> ParserContext<'a> { -> ParserContext<'a> {
let mut selector_context = SelectorParserContext::new();
selector_context.in_user_agent_stylesheet = stylesheet_origin == Origin::UserAgent;
ParserContext { ParserContext {
stylesheet_origin: stylesheet_origin, stylesheet_origin: stylesheet_origin,
base_url: base_url, base_url: base_url,
selector_context: selector_context,
error_reporter: error_reporter, error_reporter: error_reporter,
extra_data: extra_data, extra_data: extra_data,
} }

View file

@ -8,11 +8,11 @@ use Atom;
use element_state::*; use element_state::*;
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
use heapsize::HeapSizeOf; use heapsize::HeapSizeOf;
use selector_parser::{AttrValue, ElementExt, NonTSPseudoClass, Snapshot, TheSelectorImpl}; use selector_parser::{AttrValue, ElementExt, NonTSPseudoClass, Snapshot, SelectorImpl};
use selectors::{Element, MatchAttr}; use selectors::{Element, MatchAttr};
use selectors::matching::{MatchingReason, StyleRelations}; use selectors::matching::{MatchingReason, StyleRelations};
use selectors::matching::matches_complex_selector; use selectors::matching::matches_complex_selector;
use selectors::parser::{AttrSelector, Combinator, ComplexSelector, SelectorImpl, SimpleSelector}; use selectors::parser::{AttrSelector, Combinator, ComplexSelector, SimpleSelector};
use std::clone::Clone; use std::clone::Clone;
use std::sync::Arc; use std::sync::Arc;
@ -60,7 +60,7 @@ impl HeapSizeOf for RestyleHint {
/// still need to take the ElementWrapper approach for attribute-dependent /// still need to take the ElementWrapper approach for attribute-dependent
/// style. So we do it the same both ways for now to reduce complexity, but it's /// style. So we do it the same both ways for now to reduce complexity, but it's
/// worth measuring the performance impact (if any) of the mStateMask approach. /// worth measuring the performance impact (if any) of the mStateMask approach.
pub trait ElementSnapshot : Sized + MatchAttr<Impl=TheSelectorImpl> { pub trait ElementSnapshot : Sized + MatchAttr<Impl=SelectorImpl> {
/// The state of the snapshot, if any. /// The state of the snapshot, if any.
fn state(&self) -> Option<ElementState>; fn state(&self) -> Option<ElementState>;
@ -103,9 +103,9 @@ impl<'a, E> ElementWrapper<'a, E>
impl<'a, E> MatchAttr for ElementWrapper<'a, E> impl<'a, E> MatchAttr for ElementWrapper<'a, E>
where E: ElementExt, where E: ElementExt,
{ {
type Impl = TheSelectorImpl; type Impl = SelectorImpl;
fn match_attr_has(&self, attr: &AttrSelector<TheSelectorImpl>) -> bool { fn match_attr_has(&self, attr: &AttrSelector<SelectorImpl>) -> bool {
match self.snapshot { match self.snapshot {
Some(snapshot) if snapshot.has_attrs() Some(snapshot) if snapshot.has_attrs()
=> snapshot.match_attr_has(attr), => snapshot.match_attr_has(attr),
@ -114,7 +114,7 @@ impl<'a, E> MatchAttr for ElementWrapper<'a, E>
} }
fn match_attr_equals(&self, fn match_attr_equals(&self,
attr: &AttrSelector<TheSelectorImpl>, attr: &AttrSelector<SelectorImpl>,
value: &AttrValue) -> bool { value: &AttrValue) -> bool {
match self.snapshot { match self.snapshot {
Some(snapshot) if snapshot.has_attrs() Some(snapshot) if snapshot.has_attrs()
@ -124,7 +124,7 @@ impl<'a, E> MatchAttr for ElementWrapper<'a, E>
} }
fn match_attr_equals_ignore_ascii_case(&self, fn match_attr_equals_ignore_ascii_case(&self,
attr: &AttrSelector<TheSelectorImpl>, attr: &AttrSelector<SelectorImpl>,
value: &AttrValue) -> bool { value: &AttrValue) -> bool {
match self.snapshot { match self.snapshot {
Some(snapshot) if snapshot.has_attrs() Some(snapshot) if snapshot.has_attrs()
@ -134,7 +134,7 @@ impl<'a, E> MatchAttr for ElementWrapper<'a, E>
} }
fn match_attr_includes(&self, fn match_attr_includes(&self,
attr: &AttrSelector<TheSelectorImpl>, attr: &AttrSelector<SelectorImpl>,
value: &AttrValue) -> bool { value: &AttrValue) -> bool {
match self.snapshot { match self.snapshot {
Some(snapshot) if snapshot.has_attrs() Some(snapshot) if snapshot.has_attrs()
@ -144,7 +144,7 @@ impl<'a, E> MatchAttr for ElementWrapper<'a, E>
} }
fn match_attr_dash(&self, fn match_attr_dash(&self,
attr: &AttrSelector<TheSelectorImpl>, attr: &AttrSelector<SelectorImpl>,
value: &AttrValue) -> bool { value: &AttrValue) -> bool {
match self.snapshot { match self.snapshot {
Some(snapshot) if snapshot.has_attrs() Some(snapshot) if snapshot.has_attrs()
@ -154,7 +154,7 @@ impl<'a, E> MatchAttr for ElementWrapper<'a, E>
} }
fn match_attr_prefix(&self, fn match_attr_prefix(&self,
attr: &AttrSelector<TheSelectorImpl>, attr: &AttrSelector<SelectorImpl>,
value: &AttrValue) -> bool { value: &AttrValue) -> bool {
match self.snapshot { match self.snapshot {
Some(snapshot) if snapshot.has_attrs() Some(snapshot) if snapshot.has_attrs()
@ -164,7 +164,7 @@ impl<'a, E> MatchAttr for ElementWrapper<'a, E>
} }
fn match_attr_substring(&self, fn match_attr_substring(&self,
attr: &AttrSelector<TheSelectorImpl>, attr: &AttrSelector<SelectorImpl>,
value: &AttrValue) -> bool { value: &AttrValue) -> bool {
match self.snapshot { match self.snapshot {
Some(snapshot) if snapshot.has_attrs() Some(snapshot) if snapshot.has_attrs()
@ -174,7 +174,7 @@ impl<'a, E> MatchAttr for ElementWrapper<'a, E>
} }
fn match_attr_suffix(&self, fn match_attr_suffix(&self,
attr: &AttrSelector<TheSelectorImpl>, attr: &AttrSelector<SelectorImpl>,
value: &AttrValue) -> bool { value: &AttrValue) -> bool {
match self.snapshot { match self.snapshot {
Some(snapshot) if snapshot.has_attrs() Some(snapshot) if snapshot.has_attrs()
@ -185,10 +185,10 @@ impl<'a, E> MatchAttr for ElementWrapper<'a, E>
} }
impl<'a, E> Element for ElementWrapper<'a, E> impl<'a, E> Element for ElementWrapper<'a, E>
where E: ElementExt<Impl=TheSelectorImpl> where E: ElementExt<Impl=SelectorImpl>
{ {
fn match_non_ts_pseudo_class(&self, pseudo_class: NonTSPseudoClass) -> bool { fn match_non_ts_pseudo_class(&self, pseudo_class: NonTSPseudoClass) -> bool {
let flag = TheSelectorImpl::pseudo_class_state_flag(&pseudo_class); let flag = SelectorImpl::pseudo_class_state_flag(&pseudo_class);
if flag == ElementState::empty() { if flag == ElementState::empty() {
self.element.match_non_ts_pseudo_class(pseudo_class) self.element.match_non_ts_pseudo_class(pseudo_class)
} else { } else {
@ -223,11 +223,11 @@ impl<'a, E> Element for ElementWrapper<'a, E>
self.element.is_html_element_in_html_document() self.element.is_html_element_in_html_document()
} }
fn get_local_name(&self) -> &<Self::Impl as SelectorImpl>::BorrowedLocalName { fn get_local_name(&self) -> &<Self::Impl as ::selectors::SelectorImpl>::BorrowedLocalName {
self.element.get_local_name() self.element.get_local_name()
} }
fn get_namespace(&self) -> &<Self::Impl as SelectorImpl>::BorrowedNamespaceUrl { fn get_namespace(&self) -> &<Self::Impl as ::selectors::SelectorImpl>::BorrowedNamespaceUrl {
self.element.get_namespace() self.element.get_namespace()
} }
@ -265,14 +265,14 @@ impl<'a, E> Element for ElementWrapper<'a, E>
} }
} }
fn selector_to_state(sel: &SimpleSelector<TheSelectorImpl>) -> ElementState { fn selector_to_state(sel: &SimpleSelector<SelectorImpl>) -> ElementState {
match *sel { match *sel {
SimpleSelector::NonTSPseudoClass(ref pc) => TheSelectorImpl::pseudo_class_state_flag(pc), SimpleSelector::NonTSPseudoClass(ref pc) => SelectorImpl::pseudo_class_state_flag(pc),
_ => ElementState::empty(), _ => ElementState::empty(),
} }
} }
fn is_attr_selector(sel: &SimpleSelector<TheSelectorImpl>) -> bool { fn is_attr_selector(sel: &SimpleSelector<SelectorImpl>) -> bool {
match *sel { match *sel {
SimpleSelector::ID(_) | SimpleSelector::ID(_) |
SimpleSelector::Class(_) | SimpleSelector::Class(_) |
@ -341,7 +341,7 @@ impl Sensitivities {
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
struct Dependency { struct Dependency {
#[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")]
selector: Arc<ComplexSelector<TheSelectorImpl>>, selector: Arc<ComplexSelector<SelectorImpl>>,
hint: RestyleHint, hint: RestyleHint,
sensitivities: Sensitivities, sensitivities: Sensitivities,
} }
@ -388,7 +388,7 @@ impl DependencySet {
self.common_deps.len() + self.attr_deps.len() + self.state_deps.len() self.common_deps.len() + self.attr_deps.len() + self.state_deps.len()
} }
pub fn note_selector(&mut self, selector: &Arc<ComplexSelector<TheSelectorImpl>>) { pub fn note_selector(&mut self, selector: &Arc<ComplexSelector<SelectorImpl>>) {
let mut cur = selector; let mut cur = selector;
let mut combinator: Option<Combinator> = None; let mut combinator: Option<Combinator> = None;
loop { loop {

View file

@ -4,11 +4,13 @@
//! The pseudo-classes and pseudo-elements supported by the style system. //! The pseudo-classes and pseudo-elements supported by the style system.
use cssparser::Parser as CssParser;
use matching::{common_style_affecting_attributes, CommonStyleAffectingAttributeMode}; use matching::{common_style_affecting_attributes, CommonStyleAffectingAttributeMode};
use selectors::Element; 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 = <SelectorImpl as ::selectors::SelectorImpl>::AttrValue;
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
pub use servo::selector_parser::*; pub use servo::selector_parser::*;
@ -16,12 +18,6 @@ pub use servo::selector_parser::*;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub use gecko::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")] #[cfg(feature = "servo")]
pub use servo::selector_parser::ServoElementSnapshot as Snapshot; pub use servo::selector_parser::ServoElementSnapshot as Snapshot;
@ -34,6 +30,28 @@ pub use servo::restyle_damage::ServoRestyleDamage as RestyleDamage;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub use gecko::restyle_damage::GeckoRestyleDamage as RestyleDamage; 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. /// This function determines if a pseudo-element is eagerly cascaded or not.
/// ///
/// Eagerly cascaded pseudo-elements are "normal" pseudo-elements (i.e. /// Eagerly cascaded pseudo-elements are "normal" pseudo-elements (i.e.
@ -81,11 +99,11 @@ impl PseudoElementCascadeType {
} }
} }
pub trait ElementExt: Element<Impl=TheSelectorImpl> { pub trait ElementExt: Element<Impl=SelectorImpl> {
fn is_link(&self) -> bool; fn is_link(&self) -> bool;
} }
impl TheSelectorImpl { impl SelectorImpl {
#[inline] #[inline]
pub fn each_eagerly_cascaded_pseudo_element<F>(mut fun: F) pub fn each_eagerly_cascaded_pseudo_element<F>(mut fun: F)
where F: FnMut(PseudoElement) where F: FnMut(PseudoElement)
@ -109,7 +127,7 @@ impl TheSelectorImpl {
} }
} }
pub fn attr_exists_selector_is_shareable(attr_selector: &AttrSelector<TheSelectorImpl>) -> bool { pub fn attr_exists_selector_is_shareable(attr_selector: &AttrSelector<SelectorImpl>) -> bool {
// NB(pcwalton): If you update this, remember to update the corresponding list in // NB(pcwalton): If you update this, remember to update the corresponding list in
// `can_share_style_with()` as well. // `can_share_style_with()` as well.
common_style_affecting_attributes().iter().any(|common_attr_info| { common_style_affecting_attributes().iter().any(|common_attr_info| {
@ -120,7 +138,7 @@ pub fn attr_exists_selector_is_shareable(attr_selector: &AttrSelector<TheSelecto
}) })
} }
pub fn attr_equals_selector_is_shareable(attr_selector: &AttrSelector<TheSelectorImpl>, pub fn attr_equals_selector_is_shareable(attr_selector: &AttrSelector<SelectorImpl>,
value: &AttrValue) -> bool { value: &AttrValue) -> bool {
// FIXME(pcwalton): Remove once we start actually supporting RTL text. This is in // FIXME(pcwalton): Remove once we start actually supporting RTL text. This is in
// here because the UA style otherwise disables all style sharing completely. // here because the UA style otherwise disables all style sharing completely.

View file

@ -7,10 +7,11 @@ use attr::{AttrIdentifier, AttrValue};
use cssparser::ToCss; use cssparser::ToCss;
use element_state::ElementState; use element_state::ElementState;
use restyle_hints::ElementSnapshot; 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 selector_parser::{attr_equals_selector_is_shareable, attr_exists_selector_is_shareable};
use selectors::{Element, MatchAttrGeneric}; use selectors::{Element, MatchAttrGeneric};
use selectors::parser::{AttrSelector, ParserContext, SelectorImpl}; use selectors::parser::AttrSelector;
use std::borrow::Cow;
use std::fmt; use std::fmt;
/// NB: If you add to this list, be sure to update `each_pseudo_element` too. /// 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)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[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 PseudoElement = PseudoElement;
type NonTSPseudoClass = NonTSPseudoClass; type NonTSPseudoClass = NonTSPseudoClass;
@ -173,11 +174,14 @@ impl SelectorImpl for ServoSelectorImpl {
value: &Self::AttrValue) -> bool { value: &Self::AttrValue) -> bool {
attr_equals_selector_is_shareable(attr_selector, value) attr_equals_selector_is_shareable(attr_selector, value)
} }
}
fn parse_non_ts_pseudo_class(context: &ParserContext<TheSelectorImpl>, impl<'a> ::selectors::Parser for SelectorParser<'a> {
name: &str) -> Result<NonTSPseudoClass, ()> { type Impl = SelectorImpl;
fn parse_non_ts_pseudo_class(&self, name: Cow<str>) -> Result<NonTSPseudoClass, ()> {
use self::NonTSPseudoClass::*; use self::NonTSPseudoClass::*;
let pseudo_class = match_ignore_ascii_case! { name, let pseudo_class = match_ignore_ascii_case! { &name,
"any-link" => AnyLink, "any-link" => AnyLink,
"link" => Link, "link" => Link,
"visited" => Visited, "visited" => Visited,
@ -193,7 +197,7 @@ impl SelectorImpl for ServoSelectorImpl {
"placeholder-shown" => PlaceholderShown, "placeholder-shown" => PlaceholderShown,
"target" => Target, "target" => Target,
"-servo-nonzero-border" => { "-servo-nonzero-border" => {
if !context.in_user_agent_stylesheet { if !self.in_user_agent_stylesheet() {
return Err(()); return Err(());
} }
ServoNonZeroBorder ServoNonZeroBorder
@ -204,63 +208,62 @@ impl SelectorImpl for ServoSelectorImpl {
Ok(pseudo_class) Ok(pseudo_class)
} }
fn parse_pseudo_element(context: &ParserContext<TheSelectorImpl>, fn parse_pseudo_element(&self, name: Cow<str>) -> Result<PseudoElement, ()> {
name: &str) -> Result<PseudoElement, ()> {
use self::PseudoElement::*; use self::PseudoElement::*;
let pseudo_element = match_ignore_ascii_case! { name, let pseudo_element = match_ignore_ascii_case! { &name,
"before" => Before, "before" => Before,
"after" => After, "after" => After,
"selection" => Selection, "selection" => Selection,
"-servo-details-summary" => { "-servo-details-summary" => {
if !context.in_user_agent_stylesheet { if !self.in_user_agent_stylesheet() {
return Err(()) return Err(())
} }
DetailsSummary DetailsSummary
}, },
"-servo-details-content" => { "-servo-details-content" => {
if !context.in_user_agent_stylesheet { if !self.in_user_agent_stylesheet() {
return Err(()) return Err(())
} }
DetailsContent DetailsContent
}, },
"-servo-input-text" => { "-servo-input-text" => {
if !context.in_user_agent_stylesheet { if !self.in_user_agent_stylesheet() {
return Err(()) return Err(())
} }
ServoInputText ServoInputText
}, },
"-servo-table-wrapper" => { "-servo-table-wrapper" => {
if !context.in_user_agent_stylesheet { if !self.in_user_agent_stylesheet() {
return Err(()) return Err(())
} }
ServoTableWrapper ServoTableWrapper
}, },
"-servo-anonymous-table-wrapper" => { "-servo-anonymous-table-wrapper" => {
if !context.in_user_agent_stylesheet { if !self.in_user_agent_stylesheet() {
return Err(()) return Err(())
} }
ServoAnonymousTableWrapper ServoAnonymousTableWrapper
}, },
"-servo-anonymous-table" => { "-servo-anonymous-table" => {
if !context.in_user_agent_stylesheet { if !self.in_user_agent_stylesheet() {
return Err(()) return Err(())
} }
ServoAnonymousTable ServoAnonymousTable
}, },
"-servo-anonymous-table-row" => { "-servo-anonymous-table-row" => {
if !context.in_user_agent_stylesheet { if !self.in_user_agent_stylesheet() {
return Err(()) return Err(())
} }
ServoAnonymousTableRow ServoAnonymousTableRow
}, },
"-servo-anonymous-table-cell" => { "-servo-anonymous-table-cell" => {
if !context.in_user_agent_stylesheet { if !self.in_user_agent_stylesheet() {
return Err(()) return Err(())
} }
ServoAnonymousTableCell ServoAnonymousTableCell
}, },
"-servo-anonymous-block" => { "-servo-anonymous-block" => {
if !context.in_user_agent_stylesheet { if !self.in_user_agent_stylesheet() {
return Err(()) return Err(())
} }
ServoAnonymousBlock ServoAnonymousBlock
@ -270,9 +273,17 @@ impl SelectorImpl for ServoSelectorImpl {
Ok(pseudo_element) 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] #[inline]
pub fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType { pub fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType {
pseudo.cascade_type() pseudo.cascade_type()
@ -368,9 +379,9 @@ impl ElementSnapshot for ServoElementSnapshot {
} }
impl MatchAttrGeneric 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 where F: Fn(&str) -> bool
{ {
use selectors::parser::NamespaceConstraint; 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 { fn is_link(&self) -> bool {
self.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink) self.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink)
} }

View file

@ -16,14 +16,15 @@ use media_queries::{Device, MediaList, parse_media_query_list};
use parking_lot::RwLock; use parking_lot::RwLock;
use parser::{ParserContext, ParserContextExtraData, log_css_error}; use parser::{ParserContext, ParserContextExtraData, log_css_error};
use properties::{PropertyDeclarationBlock, parse_property_declaration_list}; use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
use selector_parser::TheSelectorImpl; use selector_parser::{SelectorImpl, SelectorParser};
use selectors::parser::{Selector, parse_selector_list}; use selectors::parser::SelectorList;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::cell::Cell; use std::cell::Cell;
use std::fmt; use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use style_traits::ToCss; use style_traits::ToCss;
use stylist::FnvHashMap;
use viewport::ViewportRule; use viewport::ViewportRule;
@ -43,6 +44,13 @@ pub enum Origin {
User, User,
} }
#[derive(Default)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct Namespaces {
pub default: Option<Namespace>,
pub prefixes: FnvHashMap<Prefix , Namespace>,
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct CssRules(pub Arc<RwLock<Vec<CssRule>>>); pub struct CssRules(pub Arc<RwLock<Vec<CssRule>>>);
@ -188,30 +196,15 @@ impl ToCss for MediaRule {
#[derive(Debug)] #[derive(Debug)]
pub struct StyleRule { pub struct StyleRule {
pub selectors: Vec<Selector<TheSelectorImpl>>, pub selectors: SelectorList<SelectorImpl>,
pub block: Arc<RwLock<PropertyDeclarationBlock>>, pub block: Arc<RwLock<PropertyDeclarationBlock>>,
} }
impl StyleRule {
/// Serialize the group of selectors for this rule.
///
/// https://drafts.csswg.org/cssom/#serialize-a-group-of-selectors
pub fn selectors_to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let mut iter = self.selectors.iter();
try!(iter.next().unwrap().to_css(dest));
for selector in iter {
try!(write!(dest, ", "));
try!(selector.to_css(dest));
}
Ok(())
}
}
impl ToCss for StyleRule { impl ToCss for StyleRule {
// https://drafts.csswg.org/cssom/#serialize-a-css-rule CSSStyleRule // https://drafts.csswg.org/cssom/#serialize-a-css-rule CSSStyleRule
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
// Step 1 // Step 1
try!(self.selectors_to_css(dest)); try!(self.selectors.to_css(dest));
// Step 2 // Step 2
try!(dest.write_str(" { ")); try!(dest.write_str(" { "));
// Step 3 // Step 3
@ -246,7 +239,10 @@ impl Stylesheet {
pub fn from_str(css: &str, base_url: ServoUrl, origin: Origin, media: MediaList, pub fn from_str(css: &str, base_url: ServoUrl, origin: Origin, media: MediaList,
error_reporter: Box<ParseErrorReporter + Send>, error_reporter: Box<ParseErrorReporter + Send>,
extra_data: ParserContextExtraData) -> Stylesheet { extra_data: ParserContextExtraData) -> Stylesheet {
let mut namespaces = Namespaces::default();
let rule_parser = TopLevelRuleParser { let rule_parser = TopLevelRuleParser {
stylesheet_origin: origin,
namespaces: &mut namespaces,
context: ParserContext::new_with_extra_data(origin, &base_url, error_reporter.clone(), context: ParserContext::new_with_extra_data(origin, &base_url, error_reporter.clone(),
extra_data), extra_data),
state: Cell::new(State::Start), state: Cell::new(State::Start),
@ -356,29 +352,23 @@ rule_filter! {
effective_keyframes_rules(Keyframes => KeyframesRule), 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> { struct TopLevelRuleParser<'a> {
stylesheet_origin: Origin,
namespaces: &'a mut Namespaces,
context: ParserContext<'a>, context: ParserContext<'a>,
state: Cell<State>, 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)] #[derive(Eq, PartialEq, Ord, PartialOrd, Copy, Clone)]
enum State { enum State {
Start = 1, Start = 1,
@ -425,11 +415,10 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
let opt_prefix = if let Ok(prefix) = prefix_result { let opt_prefix = if let Ok(prefix) = prefix_result {
let prefix = Prefix::from(prefix); let prefix = Prefix::from(prefix);
self.context.selector_context.namespace_prefixes.insert( self.namespaces.prefixes.insert(prefix.clone(), url.clone());
prefix.clone(), url.clone());
Some(prefix) Some(prefix)
} else { } else {
self.context.selector_context.default_namespace = Some(url.clone()); self.namespaces.default = Some(url.clone());
None None
}; };
@ -450,39 +439,57 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
} }
self.state.set(State::Body); self.state.set(State::Body);
AtRuleParser::parse_prelude(&mut NestedRuleParser { context: &self.context }, name, input) AtRuleParser::parse_prelude(&mut self.nested(), name, input)
} }
#[inline] #[inline]
fn parse_block(&mut self, prelude: AtRulePrelude, input: &mut Parser) -> Result<CssRule, ()> { 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> { impl<'a> QualifiedRuleParser for TopLevelRuleParser<'a> {
type Prelude = Vec<Selector<TheSelectorImpl>>; type Prelude = SelectorList<SelectorImpl>;
type QualifiedRule = CssRule; type QualifiedRule = CssRule;
#[inline] #[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); self.state.set(State::Body);
QualifiedRuleParser::parse_prelude(&mut NestedRuleParser { context: &self.context }, input) QualifiedRuleParser::parse_prelude(&mut self.nested(), input)
} }
#[inline] #[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, ()> { -> Result<CssRule, ()> {
QualifiedRuleParser::parse_block(&mut NestedRuleParser { context: &self.context }, QualifiedRuleParser::parse_block(&mut self.nested(), prelude, input)
prelude, input)
} }
} }
#[derive(Clone)] // shallow, relatively cheap clone
struct NestedRuleParser<'a, 'b: 'a> { struct NestedRuleParser<'a, 'b: 'a> {
stylesheet_origin: Origin,
context: &'a ParserContext<'b>, 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> { impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
type Prelude = AtRulePrelude; type Prelude = AtRulePrelude;
@ -528,7 +535,7 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
AtRulePrelude::Media(media_queries) => { AtRulePrelude::Media(media_queries) => {
Ok(CssRule::Media(Arc::new(RwLock::new(MediaRule { Ok(CssRule::Media(Arc::new(RwLock::new(MediaRule {
media_queries: media_queries, media_queries: media_queries,
rules: parse_nested_rules(self.context, input), rules: self.parse_nested_rules(input),
})))) }))))
} }
AtRulePrelude::Viewport => { AtRulePrelude::Viewport => {
@ -546,14 +553,18 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
} }
impl<'a, 'b> QualifiedRuleParser for NestedRuleParser<'a, 'b> { impl<'a, 'b> QualifiedRuleParser for NestedRuleParser<'a, 'b> {
type Prelude = Vec<Selector<TheSelectorImpl>>; type Prelude = SelectorList<SelectorImpl>;
type QualifiedRule = CssRule; type QualifiedRule = CssRule;
fn parse_prelude(&mut self, input: &mut Parser) -> Result<Vec<Selector<TheSelectorImpl>>, ()> { fn parse_prelude(&mut self, input: &mut Parser) -> Result<SelectorList<SelectorImpl>, ()> {
parse_selector_list(&self.context.selector_context, input) 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, ()> { -> Result<CssRule, ()> {
Ok(CssRule::Style(Arc::new(RwLock::new(StyleRule { Ok(CssRule::Style(Arc::new(RwLock::new(StyleRule {
selectors: prelude, selectors: prelude,

View file

@ -16,7 +16,7 @@ use properties::{PropertyDeclaration, PropertyDeclarationBlock};
use quickersort::sort_by; use quickersort::sort_by;
use restyle_hints::{RestyleHint, DependencySet}; use restyle_hints::{RestyleHint, DependencySet};
use rule_tree::{RuleTree, StrongRuleNode, StyleSource}; use rule_tree::{RuleTree, StrongRuleNode, StyleSource};
use selector_parser::{ElementExt, TheSelectorImpl, PseudoElement, Snapshot}; use selector_parser::{ElementExt, SelectorImpl, PseudoElement, Snapshot};
use selectors::Element; use selectors::Element;
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
use selectors::matching::{AFFECTED_BY_STYLE_ATTRIBUTE, AFFECTED_BY_PRESENTATIONAL_HINTS}; use selectors::matching::{AFFECTED_BY_STYLE_ATTRIBUTE, AFFECTED_BY_PRESENTATIONAL_HINTS};
@ -89,12 +89,12 @@ pub struct Stylist {
/// Selectors in the page affecting siblings /// Selectors in the page affecting siblings
#[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")]
sibling_affecting_selectors: Vec<Selector<TheSelectorImpl>>, sibling_affecting_selectors: Vec<Selector<SelectorImpl>>,
/// Selectors in the page matching elements with non-common style-affecting /// Selectors in the page matching elements with non-common style-affecting
/// attributes. /// attributes.
#[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")]
non_common_style_affecting_attributes_selectors: Vec<Selector<TheSelectorImpl>>, non_common_style_affecting_attributes_selectors: Vec<Selector<SelectorImpl>>,
} }
impl Stylist { impl Stylist {
@ -119,7 +119,7 @@ impl Stylist {
non_common_style_affecting_attributes_selectors: vec![] non_common_style_affecting_attributes_selectors: vec![]
}; };
TheSelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| { SelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| {
stylist.pseudos_map.insert(pseudo, PerPseudoElementSelectorMap::new()); stylist.pseudos_map.insert(pseudo, PerPseudoElementSelectorMap::new());
}); });
@ -139,7 +139,7 @@ impl Stylist {
self.element_map = PerPseudoElementSelectorMap::new(); self.element_map = PerPseudoElementSelectorMap::new();
self.pseudos_map = Default::default(); self.pseudos_map = Default::default();
self.animations = Default::default(); self.animations = Default::default();
TheSelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| { SelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| {
self.pseudos_map.insert(pseudo, PerPseudoElementSelectorMap::new()); self.pseudos_map.insert(pseudo, PerPseudoElementSelectorMap::new());
}); });
@ -189,7 +189,7 @@ impl Stylist {
match *rule { match *rule {
CssRule::Style(ref style_rule) => { CssRule::Style(ref style_rule) => {
let guard = style_rule.read(); let guard = style_rule.read();
for selector in &guard.selectors { for selector in &guard.selectors.0 {
let map = if let Some(ref pseudo) = selector.pseudo_element { let map = if let Some(ref pseudo) = selector.pseudo_element {
pseudos_map pseudos_map
.entry(pseudo.clone()) .entry(pseudo.clone())
@ -208,7 +208,7 @@ impl Stylist {
} }
*rules_source_order += 1; *rules_source_order += 1;
for selector in &guard.selectors { for selector in &guard.selectors.0 {
state_deps.note_selector(&selector.complex_selector); state_deps.note_selector(&selector.complex_selector);
if selector.affects_siblings() { if selector.affects_siblings() {
sibling_affecting_selectors.push(selector.clone()); sibling_affecting_selectors.push(selector.clone());
@ -246,7 +246,7 @@ impl Stylist {
debug!(" - Got {} deps for style-hint calculation", debug!(" - Got {} deps for style-hint calculation",
state_deps.len()); state_deps.len());
TheSelectorImpl::each_precomputed_pseudo_element(|pseudo| { SelectorImpl::each_precomputed_pseudo_element(|pseudo| {
// TODO: Consider not doing this and just getting the rules on the // TODO: Consider not doing this and just getting the rules on the
// fly. It should be a bit slower, but we'd take rid of the // fly. It should be a bit slower, but we'd take rid of the
// extra field, and avoid this precomputation entirely. // extra field, and avoid this precomputation entirely.
@ -271,7 +271,7 @@ impl Stylist {
parent: Option<&Arc<ComputedValues>>, parent: Option<&Arc<ComputedValues>>,
inherit_all: bool) inherit_all: bool)
-> Option<(Arc<ComputedValues>, StrongRuleNode)> { -> Option<(Arc<ComputedValues>, StrongRuleNode)> {
debug_assert!(TheSelectorImpl::pseudo_element_cascade_type(pseudo).is_precomputed()); debug_assert!(SelectorImpl::pseudo_element_cascade_type(pseudo).is_precomputed());
if let Some(declarations) = self.precomputed_pseudo_element_decls.get(pseudo) { if let Some(declarations) = self.precomputed_pseudo_element_decls.get(pseudo) {
// FIXME(emilio): When we've taken rid of the cascade we can just // FIXME(emilio): When we've taken rid of the cascade we can just
// use into_iter. // use into_iter.
@ -330,11 +330,11 @@ impl Stylist {
pseudo: &PseudoElement, pseudo: &PseudoElement,
parent: &Arc<ComputedValues>) parent: &Arc<ComputedValues>)
-> Option<(Arc<ComputedValues>, StrongRuleNode)> -> Option<(Arc<ComputedValues>, StrongRuleNode)>
where E: Element<Impl=TheSelectorImpl> + where E: Element<Impl=SelectorImpl> +
fmt::Debug + fmt::Debug +
PresentationalHintsSynthetizer PresentationalHintsSynthetizer
{ {
debug_assert!(TheSelectorImpl::pseudo_element_cascade_type(pseudo).is_lazy()); debug_assert!(SelectorImpl::pseudo_element_cascade_type(pseudo).is_lazy());
if self.pseudos_map.get(pseudo).is_none() { if self.pseudos_map.get(pseudo).is_none() {
return None; return None;
} }
@ -418,7 +418,7 @@ impl Stylist {
pseudo_element: Option<&PseudoElement>, pseudo_element: Option<&PseudoElement>,
applicable_declarations: &mut V, applicable_declarations: &mut V,
reason: MatchingReason) -> StyleRelations reason: MatchingReason) -> StyleRelations
where E: Element<Impl=TheSelectorImpl> + where E: Element<Impl=SelectorImpl> +
fmt::Debug + fmt::Debug +
PresentationalHintsSynthetizer, PresentationalHintsSynthetizer,
V: Push<ApplicableDeclarationBlock> + VecLike<ApplicableDeclarationBlock> V: Push<ApplicableDeclarationBlock> + VecLike<ApplicableDeclarationBlock>
@ -427,7 +427,7 @@ impl Stylist {
debug_assert!(style_attribute.is_none() || pseudo_element.is_none(), debug_assert!(style_attribute.is_none() || pseudo_element.is_none(),
"Style attributes do not apply to pseudo-elements"); "Style attributes do not apply to pseudo-elements");
debug_assert!(pseudo_element.is_none() || debug_assert!(pseudo_element.is_none() ||
!TheSelectorImpl::pseudo_element_cascade_type(pseudo_element.as_ref().unwrap()) !SelectorImpl::pseudo_element_cascade_type(pseudo_element.as_ref().unwrap())
.is_precomputed()); .is_precomputed());
let map = match pseudo_element { let map = match pseudo_element {
@ -731,7 +731,7 @@ impl SelectorMap {
relations: &mut StyleRelations, relations: &mut StyleRelations,
reason: MatchingReason, reason: MatchingReason,
importance: Importance) importance: Importance)
where E: Element<Impl=TheSelectorImpl>, where E: Element<Impl=SelectorImpl>,
V: VecLike<ApplicableDeclarationBlock> V: VecLike<ApplicableDeclarationBlock>
{ {
if self.empty { if self.empty {
@ -831,7 +831,7 @@ impl SelectorMap {
relations: &mut StyleRelations, relations: &mut StyleRelations,
reason: MatchingReason, reason: MatchingReason,
importance: Importance) importance: Importance)
where E: Element<Impl=TheSelectorImpl>, where E: Element<Impl=SelectorImpl>,
Str: Borrow<BorrowedStr> + Eq + Hash, Str: Borrow<BorrowedStr> + Eq + Hash,
BorrowedStr: Eq + Hash, BorrowedStr: Eq + Hash,
Vector: VecLike<ApplicableDeclarationBlock> Vector: VecLike<ApplicableDeclarationBlock>
@ -856,7 +856,7 @@ impl SelectorMap {
relations: &mut StyleRelations, relations: &mut StyleRelations,
reason: MatchingReason, reason: MatchingReason,
importance: Importance) importance: Importance)
where E: Element<Impl=TheSelectorImpl>, where E: Element<Impl=SelectorImpl>,
V: VecLike<ApplicableDeclarationBlock> V: VecLike<ApplicableDeclarationBlock>
{ {
for rule in rules.iter() { for rule in rules.iter() {
@ -927,7 +927,7 @@ impl SelectorMap {
} }
/// Retrieve the name if it is a type selector, or None otherwise. /// Retrieve the name if it is a type selector, or None otherwise.
pub fn get_local_name(rule: &Rule) -> Option<LocalNameSelector<TheSelectorImpl>> { pub fn get_local_name(rule: &Rule) -> Option<LocalNameSelector<SelectorImpl>> {
for ss in &rule.selector.compound_selector { for ss in &rule.selector.compound_selector {
if let SimpleSelector::LocalName(ref n) = *ss { if let SimpleSelector::LocalName(ref n) = *ss {
return Some(LocalNameSelector { return Some(LocalNameSelector {
@ -948,7 +948,7 @@ pub struct Rule {
// that it matches. Selector contains an owned vector (through // that it matches. Selector contains an owned vector (through
// ComplexSelector) and we want to avoid the allocation. // ComplexSelector) and we want to avoid the allocation.
#[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")]
pub selector: Arc<ComplexSelector<TheSelectorImpl>>, pub selector: Arc<ComplexSelector<SelectorImpl>>,
#[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] #[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")]
pub style_rule: Arc<RwLock<StyleRule>>, pub style_rule: Arc<RwLock<StyleRule>>,
pub source_order: usize, pub source_order: usize,

View file

@ -20,7 +20,7 @@ Servo [extends][selector-impl-ext] that trait in order to allow a few more
things to be shared between Stylo and Servo. things to be shared between Stylo and Servo.
The main Servo implementation (the one that is used in regular builds) is The main Servo implementation (the one that is used in regular builds) is
[ServoSelectorImpl][servo-selector-impl]. [SelectorImpl][servo-selector-impl].
<a name="dom-glue"></a> <a name="dom-glue"></a>
## DOM glue ## DOM glue
@ -139,7 +139,7 @@ that you didn't find it here so it can be added :)
[stylo]: https://public.etherpad-mozilla.org/p/stylo [stylo]: https://public.etherpad-mozilla.org/p/stylo
[selector-impl]: http://doc.servo.org/selectors/parser/trait.SelectorImpl.html [selector-impl]: http://doc.servo.org/selectors/parser/trait.SelectorImpl.html
[selector-impl-ext]: http://doc.servo.org/style/selector_parser/trait.SelectorImplExt.html [selector-impl-ext]: http://doc.servo.org/style/selector_parser/trait.SelectorImplExt.html
[servo-selector-impl]: http://doc.servo.org/style/servo_selector_parser/struct.ServoSelectorImpl.html [servo-selector-impl]: http://doc.servo.org/style/servo_selector_parser/struct.SelectorImpl.html
[tree-structural-pseudo-classes]: https://www.w3.org/TR/selectors4/#structural-pseudos [tree-structural-pseudo-classes]: https://www.w3.org/TR/selectors4/#structural-pseudos
[style-dom-traits]: http://doc.servo.org/style/dom/index.html [style-dom-traits]: http://doc.servo.org/style/dom/index.html
[layout-wrapper]: http://doc.servo.org/layout/wrapper/index.html [layout-wrapper]: http://doc.servo.org/layout/wrapper/index.html

14
ports/cef/Cargo.lock generated
View file

@ -1158,7 +1158,7 @@ dependencies = [
"rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1", "script_layout_interface 0.0.1",
"script_traits 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 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_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)", "serde_json 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1198,7 +1198,7 @@ dependencies = [
"script 0.0.1", "script 0.0.1",
"script_layout_interface 0.0.1", "script_layout_interface 0.0.1",
"script_traits 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_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)", "serde_json 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_url 0.0.1", "servo_url 0.0.1",
@ -2019,7 +2019,7 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1", "script_layout_interface 0.0.1",
"script_traits 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 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_atoms 0.0.1", "servo_atoms 0.0.1",
"servo_url 0.0.1", "servo_url 0.0.1",
@ -2058,7 +2058,7 @@ dependencies = [
"profile_traits 0.0.1", "profile_traits 0.0.1",
"range 0.0.1", "range 0.0.1",
"script_traits 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_atoms 0.0.1",
"servo_url 0.0.1", "servo_url 0.0.1",
"style 0.0.1", "style 0.0.1",
@ -2097,7 +2097,7 @@ dependencies = [
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.14.0" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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 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_derive 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_atoms 0.0.1", "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-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 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 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.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 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" "checksum serde_codegen 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "c3b932a3bb4d729e39aa04cc5e2f2ac70ba239a5a151d2dc9a1956fd6a2f7c15"

View file

@ -11,7 +11,7 @@ dependencies = [
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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", "servo_url 0.0.1",
"style 0.0.1", "style 0.0.1",
"style_traits 0.0.1", "style_traits 0.0.1",
@ -319,7 +319,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.14.0" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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", "servo_url 0.0.1",
"smallvec 0.1.8 (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", "style_traits 0.0.1",
@ -406,7 +406,7 @@ dependencies = [
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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", "servo_url 0.0.1",
"style 0.0.1", "style 0.0.1",
"style_traits 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 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 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 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 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 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" "checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03"

View file

@ -19,7 +19,7 @@ libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]} log = {version = "0.3.5", features = ["release_max_level_info"]}
num_cpus = "1.1.0" num_cpus = "1.1.0"
parking_lot = "0.3" parking_lot = "0.3"
selectors = "0.14" selectors = "0.15"
servo_url = {path = "../../components/url"} servo_url = {path = "../../components/url"}
style = {path = "../../components/style", features = ["gecko"]} style = {path = "../../components/style", features = ["gecko"]}
style_traits = {path = "../../components/style_traits"} style_traits = {path = "../../components/style_traits"}

View file

@ -16,7 +16,7 @@ use style::context::{LocalStyleContextCreationInfo, ReflowGoal, SharedStyleConte
use style::dom::{NodeInfo, StylingMode, TElement, TNode}; use style::dom::{NodeInfo, StylingMode, TElement, TNode};
use style::error_reporting::StdoutErrorReporter; use style::error_reporting::StdoutErrorReporter;
use style::gecko::data::{NUM_THREADS, PerDocumentStyleData}; use style::gecko::data::{NUM_THREADS, PerDocumentStyleData};
use style::gecko::selector_parser::{GeckoSelectorImpl, PseudoElement}; use style::gecko::selector_parser::{SelectorImpl, PseudoElement};
use style::gecko::snapshot::GeckoElementSnapshot; use style::gecko::snapshot::GeckoElementSnapshot;
use style::gecko::traversal::RecalcStyleOnly; use style::gecko::traversal::RecalcStyleOnly;
use style::gecko::wrapper::{GeckoElement, GeckoNode}; use style::gecko::wrapper::{GeckoElement, GeckoNode};
@ -350,7 +350,7 @@ pub extern "C" fn Servo_ComputedValues_GetForPseudoElement(parent_style: ServoCo
let element = GeckoElement(match_element); let element = GeckoElement(match_element);
match GeckoSelectorImpl::pseudo_element_cascade_type(&pseudo) { match SelectorImpl::pseudo_element_cascade_type(&pseudo) {
PseudoElementCascadeType::Eager => { PseudoElementCascadeType::Eager => {
let maybe_computed = element.get_pseudo_style(&pseudo); let maybe_computed = element.get_pseudo_style(&pseudo);
maybe_computed.map_or_else(parent_or_null, FFIArcHelpers::into_strong) maybe_computed.map_or_else(parent_or_null, FFIArcHelpers::into_strong)

16
ports/servo/Cargo.lock generated
View file

@ -1237,7 +1237,7 @@ dependencies = [
"rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1", "script_layout_interface 0.0.1",
"script_traits 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 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_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)", "serde_json 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1284,7 +1284,7 @@ dependencies = [
"script 0.0.1", "script 0.0.1",
"script_layout_interface 0.0.1", "script_layout_interface 0.0.1",
"script_traits 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_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)", "serde_json 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_url 0.0.1", "servo_url 0.0.1",
@ -2169,7 +2169,7 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1", "script_layout_interface 0.0.1",
"script_traits 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 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_atoms 0.0.1", "servo_atoms 0.0.1",
"servo_url 0.0.1", "servo_url 0.0.1",
@ -2208,7 +2208,7 @@ dependencies = [
"profile_traits 0.0.1", "profile_traits 0.0.1",
"range 0.0.1", "range 0.0.1",
"script_traits 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_atoms 0.0.1",
"servo_url 0.0.1", "servo_url 0.0.1",
"style 0.0.1", "style 0.0.1",
@ -2257,7 +2257,7 @@ dependencies = [
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.14.0" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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 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_derive 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_atoms 0.0.1", "servo_atoms 0.0.1",
@ -2565,7 +2565,7 @@ dependencies = [
"owning_ref 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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_atoms 0.0.1",
"servo_url 0.0.1", "servo_url 0.0.1",
"style 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-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 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 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.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 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" "checksum serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)" = "784e249221c84265caeb1e2fe48aeada86f67f5acb151bd3903c4585969e43f6"

View file

@ -16,7 +16,7 @@ euclid = "0.10.1"
owning_ref = "0.2.2" owning_ref = "0.2.2"
parking_lot = "0.3" parking_lot = "0.3"
rustc-serialize = "0.3" rustc-serialize = "0.3"
selectors = "0.14" selectors = "0.15"
html5ever-atoms = "0.1" html5ever-atoms = "0.1"
servo_atoms = {path = "../../../components/atoms"} servo_atoms = {path = "../../../components/atoms"}
style = {path = "../../../components/style"} style = {path = "../../../components/style"}

View file

@ -3,14 +3,18 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::{Parser, ToCss}; use cssparser::{Parser, ToCss};
use selectors::parser::{Selector, ParserContext, parse_selector_list}; use selectors::parser::SelectorList;
use style::selector_parser::TheSelectorImpl; use style::selector_parser::{SelectorImpl, SelectorParser};
use style::stylesheets::{Origin, Namespaces};
fn parse(input: &mut Parser) -> Result<Selector<TheSelectorImpl>, ()> { fn parse(input: &mut Parser) -> Result<SelectorList<SelectorImpl>, ()> {
let mut context = ParserContext::new(); let mut ns = Namespaces::default();
context.in_user_agent_stylesheet = true; ns.prefixes.insert("svg".into(), ns!(svg));
context.namespace_prefixes.insert("svg".into(), ns!(svg)); let parser = SelectorParser {
parse_selector_list(&context, input).map(|mut vec| vec.pop().unwrap()) stylesheet_origin: Origin::UserAgent,
namespaces: &ns,
};
SelectorList::parse(&parser, input)
} }
#[test] #[test]

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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 html5ever_atoms::{Namespace as NsAtom};
use media_queries::CSSErrorReporterTest; use media_queries::CSSErrorReporterTest;
use parking_lot::RwLock; use parking_lot::RwLock;
@ -63,7 +63,7 @@ fn test_parse_stylesheet() {
url: NsAtom::from("http://www.w3.org/1999/xhtml") url: NsAtom::from("http://www.w3.org/1999/xhtml")
}))), }))),
CssRule::Style(Arc::new(RwLock::new(StyleRule { CssRule::Style(Arc::new(RwLock::new(StyleRule {
selectors: vec![ selectors: SelectorList(vec![
Selector { Selector {
complex_selector: Arc::new(ComplexSelector { complex_selector: Arc::new(ComplexSelector {
compound_selector: vec![ compound_selector: vec![
@ -89,7 +89,7 @@ fn test_parse_stylesheet() {
pseudo_element: None, pseudo_element: None,
specificity: (0 << 20) + (1 << 10) + (1 << 0), specificity: (0 << 20) + (1 << 10) + (1 << 0),
}, },
], ]),
block: Arc::new(RwLock::new(PropertyDeclarationBlock { block: Arc::new(RwLock::new(PropertyDeclarationBlock {
declarations: vec![ declarations: vec![
(PropertyDeclaration::Display(DeclaredValue::Value( (PropertyDeclaration::Display(DeclaredValue::Value(
@ -102,7 +102,7 @@ fn test_parse_stylesheet() {
})), })),
}))), }))),
CssRule::Style(Arc::new(RwLock::new(StyleRule { CssRule::Style(Arc::new(RwLock::new(StyleRule {
selectors: vec![ selectors: SelectorList(vec![
Selector { Selector {
complex_selector: Arc::new(ComplexSelector { complex_selector: Arc::new(ComplexSelector {
compound_selector: vec![ compound_selector: vec![
@ -137,7 +137,7 @@ fn test_parse_stylesheet() {
pseudo_element: None, pseudo_element: None,
specificity: (0 << 20) + (0 << 10) + (1 << 0), specificity: (0 << 20) + (0 << 10) + (1 << 0),
}, },
], ]),
block: Arc::new(RwLock::new(PropertyDeclarationBlock { block: Arc::new(RwLock::new(PropertyDeclarationBlock {
declarations: vec![ declarations: vec![
(PropertyDeclaration::Display(DeclaredValue::Value( (PropertyDeclaration::Display(DeclaredValue::Value(
@ -148,7 +148,7 @@ fn test_parse_stylesheet() {
})), })),
}))), }))),
CssRule::Style(Arc::new(RwLock::new(StyleRule { CssRule::Style(Arc::new(RwLock::new(StyleRule {
selectors: vec![ selectors: SelectorList(vec![
Selector { Selector {
complex_selector: Arc::new(ComplexSelector { complex_selector: Arc::new(ComplexSelector {
compound_selector: vec![ compound_selector: vec![
@ -172,7 +172,7 @@ fn test_parse_stylesheet() {
pseudo_element: None, pseudo_element: None,
specificity: (1 << 20) + (1 << 10) + (0 << 0), specificity: (1 << 20) + (1 << 10) + (0 << 0),
}, },
], ]),
block: Arc::new(RwLock::new(PropertyDeclarationBlock { block: Arc::new(RwLock::new(PropertyDeclarationBlock {
declarations: vec![ declarations: vec![
(PropertyDeclaration::BackgroundColor(DeclaredValue::Value( (PropertyDeclaration::BackgroundColor(DeclaredValue::Value(
@ -282,7 +282,7 @@ impl CSSInvalidErrorReporterTest {
} }
impl ParseErrorReporter for 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 location = input.source_location(position);
let errors = self.errors.clone(); let errors = self.errors.clone();

View file

@ -2,14 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::Parser;
use html5ever_atoms::LocalName; use html5ever_atoms::LocalName;
use parking_lot::RwLock; 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 servo_atoms::Atom;
use std::sync::Arc; use std::sync::Arc;
use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, DeclaredValue}; use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, DeclaredValue};
use style::properties::{longhands, Importance}; use style::properties::{longhands, Importance};
use style::selector_parser::SelectorParser;
use style::stylesheets::StyleRule; use style::stylesheets::StyleRule;
use style::stylist::{Rule, SelectorMap}; use style::stylist::{Rule, SelectorMap};
use style::thread_state; use style::thread_state;
@ -18,9 +18,7 @@ use style::thread_state;
/// Each sublist of the result contains the Rules for one StyleRule. /// Each sublist of the result contains the Rules for one StyleRule.
fn get_mock_rules(css_selectors: &[&str]) -> Vec<Vec<Rule>> { fn get_mock_rules(css_selectors: &[&str]) -> Vec<Vec<Rule>> {
css_selectors.iter().enumerate().map(|(i, selectors)| { css_selectors.iter().enumerate().map(|(i, selectors)| {
let context = ParserContext::new(); let selectors = SelectorParser::parse_author_origin_no_namespace(selectors).unwrap();
let selectors =
parse_selector_list(&context, &mut Parser::new(*selectors)).unwrap();
let rule = Arc::new(RwLock::new(StyleRule { let rule = Arc::new(RwLock::new(StyleRule {
selectors: selectors, selectors: selectors,
@ -35,7 +33,7 @@ fn get_mock_rules(css_selectors: &[&str]) -> Vec<Vec<Rule>> {
})); }));
let guard = rule.read(); let guard = rule.read();
guard.selectors.iter().map(|s| { guard.selectors.0.iter().map(|s| {
Rule { Rule {
selector: s.complex_selector.clone(), selector: s.complex_selector.clone(),
style_rule: rule.clone(), style_rule: rule.clone(),

View file

@ -21,7 +21,7 @@ libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]} log = {version = "0.3.5", features = ["release_max_level_info"]}
num_cpus = "1.1.0" num_cpus = "1.1.0"
parking_lot = "0.3" parking_lot = "0.3"
selectors = "0.14" selectors = "0.15"
servo_url = {path = "../../../components/url"} servo_url = {path = "../../../components/url"}
style_traits = {path = "../../../components/style_traits"} style_traits = {path = "../../../components/style_traits"}
geckoservo = {path = "../../../ports/geckolib"} geckoservo = {path = "../../../ports/geckolib"}