Update rust-selectors

This commits updates rust-selectors to use the generic parser, and as
such it moves the element state into the style crate.
This commit is contained in:
Emilio Cobos Álvarez 2016-01-28 14:42:15 +01:00 committed by Anthony Ramine
parent 9baa59a6b4
commit a1c830f1c1
40 changed files with 342 additions and 252 deletions

View file

@ -61,7 +61,7 @@ fnv = "1.0"
bitflags = "0.3" bitflags = "0.3"
rustc-serialize = "0.3" rustc-serialize = "0.3"
libc = "0.2" libc = "0.2"
selectors = "0.2" selectors = "0.4.1"
smallvec = "0.1" smallvec = "0.1"
string_cache = "0.2" string_cache = "0.2"
euclid = {version = "0.4", features = ["plugins"]} euclid = {version = "0.4", features = ["plugins"]}

View file

@ -45,7 +45,7 @@ extern crate profile_traits;
extern crate rustc_serialize; extern crate rustc_serialize;
extern crate script; extern crate script;
extern crate script_traits; extern crate script_traits;
#[macro_use(state_pseudo_classes)] extern crate selectors; extern crate selectors;
extern crate serde; extern crate serde;
extern crate serde_json; extern crate serde_json;
extern crate smallvec; extern crate smallvec;

View file

@ -19,7 +19,6 @@ use script::layout_interface::{ContentBoxResponse, ContentBoxesResponse, NodeGeo
use script::layout_interface::{HitTestResponse, LayoutRPC, MouseOverResponse, OffsetParentResponse}; use script::layout_interface::{HitTestResponse, LayoutRPC, MouseOverResponse, OffsetParentResponse};
use script::layout_interface::{ResolvedStyleResponse, ScriptLayoutChan}; use script::layout_interface::{ResolvedStyleResponse, ScriptLayoutChan};
use script_traits::LayoutMsg as ConstellationMsg; use script_traits::LayoutMsg as ConstellationMsg;
use selectors::parser::PseudoElement;
use sequential; use sequential;
use std::ops::Deref; use std::ops::Deref;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -27,6 +26,7 @@ use string_cache::Atom;
use style::computed_values; use style::computed_values;
use style::properties::longhands::{display, position}; use style::properties::longhands::{display, position};
use style::properties::style_structs; use style::properties::style_structs;
use style::selector_impl::PseudoElement;
use style::values::AuExtensionMethods; use style::values::AuExtensionMethods;
use util::cursor::Cursor; use util::cursor::Cursor;
use util::logical_geometry::WritingMode; use util::logical_geometry::WritingMode;

View file

@ -55,7 +55,6 @@ use script::dom::text::Text;
use script::layout_interface::TrustedNodeAddress; use script::layout_interface::TrustedNodeAddress;
use selectors::matching::DeclarationBlock; use selectors::matching::DeclarationBlock;
use selectors::parser::{AttrSelector, NamespaceConstraint}; use selectors::parser::{AttrSelector, NamespaceConstraint};
use selectors::states::*;
use smallvec::VecLike; use smallvec::VecLike;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cell::{Ref, RefCell, RefMut}; use std::cell::{Ref, RefCell, RefMut};
@ -67,9 +66,11 @@ use style::computed_values::content::ContentItem;
use style::computed_values::{content, display}; use style::computed_values::{content, display};
use style::data::PrivateStyleData; use style::data::PrivateStyleData;
use style::dom::{TDocument, TElement, TNode, UnsafeNode}; use style::dom::{TDocument, TElement, TNode, UnsafeNode};
use style::element_state::*;
use style::properties::ComputedValues; use style::properties::ComputedValues;
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
use style::restyle_hints::ElementSnapshot; use style::restyle_hints::ElementSnapshot;
use style::selector_impl::{NonTSPseudoClass, ServoSelectorImpl};
use url::Url; use url::Url;
use util::str::{is_whitespace, search_index}; use util::str::{is_whitespace, search_index};
@ -452,17 +453,9 @@ fn as_element<'le>(node: LayoutJS<Node>) -> Option<ServoLayoutElement<'le>> {
node.downcast().map(ServoLayoutElement::from_layout_js) node.downcast().map(ServoLayoutElement::from_layout_js)
} }
macro_rules! state_getter {
($(
$(#[$Flag_attr: meta])*
state $css: expr => $variant: ident / $method: ident /
$flag: ident = $value: expr,
)+) => {
$( fn $method(&self) -> bool { self.element.get_state_for_layout().contains($flag) } )+
}
}
impl<'le> ::selectors::Element for ServoLayoutElement<'le> { impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
type Impl = ServoSelectorImpl;
fn parent_element(&self) -> Option<ServoLayoutElement<'le>> { fn parent_element(&self) -> Option<ServoLayoutElement<'le>> {
unsafe { unsafe {
self.element.upcast().parent_node_ref().and_then(as_element) self.element.upcast().parent_node_ref().and_then(as_element)
@ -531,34 +524,40 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
self.element.namespace() self.element.namespace()
} }
fn is_link(&self) -> bool { fn match_non_ts_pseudo_class(&self, pseudo_class: NonTSPseudoClass) -> bool {
// FIXME: This is HTML only. match pseudo_class {
let node = self.as_node(); // https://github.com/servo/servo/issues/8718
match node.type_id() { NonTSPseudoClass::Link |
// https://html.spec.whatwg.org/multipage/#selector-link NonTSPseudoClass::AnyLink => unsafe {
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) | match self.as_node().type_id() {
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) | // https://html.spec.whatwg.org/multipage/#selector-link
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => { NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) |
unsafe { NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) |
(*self.element.unsafe_get()).get_attr_val_for_layout(&ns!(), &atom!("href")).is_some() NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) =>
(*self.element.unsafe_get()).get_attr_val_for_layout(&ns!(), &atom!("href")).is_some(),
_ => false,
} }
} },
_ => false, NonTSPseudoClass::Visited => false,
NonTSPseudoClass::ServoNonZeroBorder => unsafe {
match (*self.element.unsafe_get()).get_attr_for_layout(&ns!(), &atom!("border")) {
None | Some(&AttrValue::UInt(_, 0)) => false,
_ => true,
}
},
NonTSPseudoClass::Active |
NonTSPseudoClass::Focus |
NonTSPseudoClass::Hover |
NonTSPseudoClass::Enabled |
NonTSPseudoClass::Disabled |
NonTSPseudoClass::Checked |
NonTSPseudoClass::Indeterminate =>
self.element.get_state_for_layout().contains(pseudo_class.state_flag())
} }
} }
#[inline]
fn is_unvisited_link(&self) -> bool {
self.is_link()
}
#[inline]
fn is_visited_link(&self) -> bool {
false
}
state_pseudo_classes!(state_getter);
#[inline] #[inline]
fn get_id(&self) -> Option<Atom> { fn get_id(&self) -> Option<Atom> {
unsafe { unsafe {
@ -576,27 +575,14 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
#[inline(always)] #[inline(always)]
fn each_class<F>(&self, mut callback: F) where F: FnMut(&Atom) { fn each_class<F>(&self, mut callback: F) where F: FnMut(&Atom) {
unsafe { unsafe {
match self.element.get_classes_for_layout() { if let Some(ref classes) = self.element.get_classes_for_layout() {
None => {} for class in *classes {
Some(ref classes) => { callback(class)
for class in *classes {
callback(class)
}
} }
} }
} }
} }
#[inline]
fn has_servo_nonzero_border(&self) -> bool {
unsafe {
match (*self.element.unsafe_get()).get_attr_for_layout(&ns!(), &atom!("border")) {
None | Some(&AttrValue::UInt(_, 0)) => false,
_ => true,
}
}
}
fn match_attr<F>(&self, attr: &AttrSelector, test: F) -> bool where F: Fn(&str) -> bool { fn match_attr<F>(&self, attr: &AttrSelector, test: F) -> bool where F: Fn(&str) -> bool {
let name = if self.is_html_element_in_html_document() { let name = if self.is_html_element_in_html_document() {
&attr.lower_name &attr.lower_name

View file

@ -79,7 +79,7 @@ websocket = "0.14.0"
uuid = "0.1.16" uuid = "0.1.16"
smallvec = "0.1" smallvec = "0.1"
html5ever = { version = "0.4", features = ["unstable"] } html5ever = { version = "0.4", features = ["unstable"] }
selectors = "0.2" selectors = "0.4.1"
string_cache = { version = "0.2", features = ["unstable"] } string_cache = { version = "0.2", features = ["unstable"] }
euclid = {version = "0.4", features = ["plugins"]} euclid = {version = "0.4", features = ["plugins"]}
rand = "0.3" rand = "0.3"

View file

@ -65,8 +65,6 @@ use profile_traits::mem::ProfilerChan as MemProfilerChan;
use profile_traits::time::ProfilerChan as TimeProfilerChan; use profile_traits::time::ProfilerChan as TimeProfilerChan;
use script_thread::ScriptChan; use script_thread::ScriptChan;
use script_traits::{LayoutMsg, ScriptMsg, TimerEventId, TimerSource, UntrustedNodeAddress}; use script_traits::{LayoutMsg, ScriptMsg, TimerEventId, TimerSource, UntrustedNodeAddress};
use selectors::parser::PseudoElement;
use selectors::states::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::boxed::FnBox; use std::boxed::FnBox;
@ -84,8 +82,10 @@ use std::sync::atomic::AtomicBool;
use std::sync::mpsc::{Receiver, Sender}; use std::sync::mpsc::{Receiver, Sender};
use string_cache::{Atom, Namespace, QualName}; use string_cache::{Atom, Namespace, QualName};
use style::attr::{AttrIdentifier, AttrValue}; use style::attr::{AttrIdentifier, AttrValue};
use style::element_state::*;
use style::properties::PropertyDeclarationBlock; use style::properties::PropertyDeclarationBlock;
use style::restyle_hints::ElementSnapshot; use style::restyle_hints::ElementSnapshot;
use style::selector_impl::PseudoElement;
use style::values::specified::Length; use style::values::specified::Length;
use url::Url; use url::Url;
use util::str::{DOMString, LengthOrPercentageOrAuto}; use util::str::{DOMString, LengthOrPercentageOrAuto};

View file

@ -11,7 +11,6 @@ use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::element::{Element, StylePriority}; use dom::element::{Element, StylePriority};
use dom::node::{Node, NodeDamage, document_from_node, window_from_node}; use dom::node::{Node, NodeDamage, document_from_node, window_from_node};
use dom::window::Window; use dom::window::Window;
use selectors::parser::PseudoElement;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cell::Ref; use std::cell::Ref;
@ -19,6 +18,7 @@ use string_cache::Atom;
use style::error_reporting::ParseErrorReporter; use style::error_reporting::ParseErrorReporter;
use style::properties::{PropertyDeclaration, Shorthand}; use style::properties::{PropertyDeclaration, Shorthand};
use style::properties::{is_supported_property, parse_one_declaration}; use style::properties::{is_supported_property, parse_one_declaration};
use style::selector_impl::PseudoElement;
use util::str::{DOMString, str_join}; use util::str::{DOMString, str_join};
// http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface // http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface

View file

@ -68,7 +68,6 @@ use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks};
use selectors::matching::{DeclarationBlock, matches}; use selectors::matching::{DeclarationBlock, matches};
use selectors::matching::{common_style_affecting_attributes, rare_style_affecting_attributes}; use selectors::matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
use selectors::parser::{AttrSelector, NamespaceConstraint, parse_author_origin_selector_list_from_str}; use selectors::parser::{AttrSelector, NamespaceConstraint, parse_author_origin_selector_list_from_str};
use selectors::states::*;
use smallvec::VecLike; use smallvec::VecLike;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::borrow::Cow; use std::borrow::Cow;
@ -77,10 +76,12 @@ use std::default::Default;
use std::mem; use std::mem;
use std::sync::Arc; use std::sync::Arc;
use string_cache::{Atom, Namespace, QualName}; use string_cache::{Atom, Namespace, QualName};
use style::element_state::*;
use style::error_reporting::ParseErrorReporter; use style::error_reporting::ParseErrorReporter;
use style::properties::DeclaredValue; use style::properties::DeclaredValue;
use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size}; use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size};
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
use style::selector_impl::{NonTSPseudoClass, ServoSelectorImpl};
use style::values::CSSFloat; use style::values::CSSFloat;
use style::values::specified::{self, CSSColor, CSSRGBA, LengthOrPercentage}; use style::values::specified::{self, CSSColor, CSSRGBA, LengthOrPercentage};
use util::mem::HeapSizeOf; use util::mem::HeapSizeOf;
@ -1689,17 +1690,9 @@ impl VirtualMethods for Element {
} }
} }
macro_rules! state_getter {
($(
$(#[$Flag_attr: meta])*
state $css: expr => $variant: ident / $method: ident /
$flag: ident = $value: expr,
)+) => {
$( fn $method(&self) -> bool { Element::get_state(self).contains($flag) } )+
}
}
impl<'a> ::selectors::Element for Root<Element> { impl<'a> ::selectors::Element for Root<Element> {
type Impl = ServoSelectorImpl;
fn parent_element(&self) -> Option<Root<Element>> { fn parent_element(&self) -> Option<Root<Element>> {
self.upcast::<Node>().GetParentElement() self.upcast::<Node>().GetParentElement()
} }
@ -1734,46 +1727,52 @@ impl<'a> ::selectors::Element for Root<Element> {
}) })
} }
fn is_link(&self) -> bool {
// FIXME: This is HTML only.
let node = self.upcast::<Node>();
match node.type_id() {
// https://html.spec.whatwg.org/multipage/#selector-link
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
self.has_attribute(&atom!("href"))
},
_ => false,
}
}
#[inline]
fn is_unvisited_link(&self) -> bool {
self.is_link()
}
#[inline]
fn is_visited_link(&self) -> bool {
// https://github.com/servo/servo/issues/8718
false
}
fn get_local_name(&self) -> &Atom { fn get_local_name(&self) -> &Atom {
self.local_name() self.local_name()
} }
fn get_namespace(&self) -> &Namespace { fn get_namespace(&self) -> &Namespace {
self.namespace() self.namespace()
} }
state_pseudo_classes!(state_getter); fn match_non_ts_pseudo_class(&self, pseudo_class: NonTSPseudoClass) -> bool {
match pseudo_class {
// https://github.com/servo/servo/issues/8718
NonTSPseudoClass::Link |
NonTSPseudoClass::AnyLink => self.is_link(),
NonTSPseudoClass::Visited => false,
NonTSPseudoClass::ServoNonZeroBorder => {
match self.downcast::<HTMLTableElement>() {
None => false,
Some(this) => {
match this.get_border() {
None | Some(0) => false,
Some(_) => true,
}
}
}
},
NonTSPseudoClass::Active |
NonTSPseudoClass::Focus |
NonTSPseudoClass::Hover |
NonTSPseudoClass::Enabled |
NonTSPseudoClass::Disabled |
NonTSPseudoClass::Checked |
NonTSPseudoClass::Indeterminate =>
Element::get_state(self).contains(pseudo_class.state_flag()),
}
}
fn get_id(&self) -> Option<Atom> { fn get_id(&self) -> Option<Atom> {
self.id_attribute.borrow().clone() self.id_attribute.borrow().clone()
} }
fn has_class(&self, name: &Atom) -> bool { fn has_class(&self, name: &Atom) -> bool {
Element::has_class(&**self, name) Element::has_class(&**self, name)
} }
fn each_class<F>(&self, mut callback: F) fn each_class<F>(&self, mut callback: F)
where F: FnMut(&Atom) where F: FnMut(&Atom)
{ {
@ -1785,17 +1784,6 @@ impl<'a> ::selectors::Element for Root<Element> {
} }
} }
} }
fn has_servo_nonzero_border(&self) -> bool {
match self.downcast::<HTMLTableElement>() {
None => false,
Some(this) => {
match this.get_border() {
None | Some(0) => false,
Some(_) => true,
}
}
}
}
fn match_attr<F>(&self, attr: &AttrSelector, test: F) -> bool fn match_attr<F>(&self, attr: &AttrSelector, test: F) -> bool
where F: Fn(&str) -> bool where F: Fn(&str) -> bool
@ -1886,6 +1874,20 @@ impl Element {
} }
} }
fn is_link(&self) -> bool {
// FIXME: This is HTML only.
let node = self.upcast::<Node>();
match node.type_id() {
// https://html.spec.whatwg.org/multipage/#selector-link
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
self.has_attribute(&atom!("href"))
},
_ => false,
}
}
/// Please call this method *only* for real click events /// Please call this method *only* for real click events
/// ///
/// https://html.spec.whatwg.org/multipage/#run-authentic-click-activation-steps /// https://html.spec.whatwg.org/multipage/#run-authentic-click-activation-steps

View file

@ -20,10 +20,10 @@ use dom::node::{Node, UnbindContext, document_from_node, window_from_node};
use dom::nodelist::NodeList; use dom::nodelist::NodeList;
use dom::validitystate::ValidityState; use dom::validitystate::ValidityState;
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use selectors::states::*;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::cell::Cell; use std::cell::Cell;
use string_cache::Atom; use string_cache::Atom;
use style::element_state::*;
use util::str::DOMString; use util::str::DOMString;
#[derive(JSTraceable, PartialEq, Copy, Clone)] #[derive(JSTraceable, PartialEq, Copy, Clone)]

View file

@ -30,13 +30,13 @@ use dom::node::{Node, SEQUENTIALLY_FOCUSABLE};
use dom::node::{document_from_node, window_from_node}; use dom::node::{document_from_node, window_from_node};
use dom::nodelist::NodeList; use dom::nodelist::NodeList;
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use selectors::states::*;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::default::Default; use std::default::Default;
use std::intrinsics; use std::intrinsics;
use std::rc::Rc; use std::rc::Rc;
use string_cache::Atom; use string_cache::Atom;
use style::element_state::*;
use util::str::DOMString; use util::str::DOMString;
#[dom_struct] #[dom_struct]

View file

@ -16,8 +16,8 @@ use dom::htmllegendelement::HTMLLegendElement;
use dom::node::{Node, window_from_node}; use dom::node::{Node, window_from_node};
use dom::validitystate::ValidityState; use dom::validitystate::ValidityState;
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use selectors::states::*;
use string_cache::Atom; use string_cache::Atom;
use style::element_state::*;
use util::str::DOMString; use util::str::DOMString;
#[dom_struct] #[dom_struct]

View file

@ -32,10 +32,10 @@ use msg::constellation_msg::ConstellationChan;
use script_thread::ScriptThreadEventCategory::InputEvent; use script_thread::ScriptThreadEventCategory::InputEvent;
use script_thread::{CommonScriptMsg, Runnable}; use script_thread::{CommonScriptMsg, Runnable};
use script_traits::ScriptMsg as ConstellationMsg; use script_traits::ScriptMsg as ConstellationMsg;
use selectors::states::*;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cell::Cell; use std::cell::Cell;
use string_cache::Atom; use string_cache::Atom;
use style::element_state::*;
use textinput::KeyReaction::{DispatchInput, Nothing, RedrawSelection, TriggerDefaultAction}; use textinput::KeyReaction::{DispatchInput, Nothing, RedrawSelection, TriggerDefaultAction};
use textinput::Lines::Single; use textinput::Lines::Single;
use textinput::TextInput; use textinput::TextInput;

View file

@ -13,8 +13,8 @@ use dom::htmlelement::HTMLElement;
use dom::htmloptionelement::HTMLOptionElement; use dom::htmloptionelement::HTMLOptionElement;
use dom::node::Node; use dom::node::Node;
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use selectors::states::*;
use string_cache::Atom; use string_cache::Atom;
use style::element_state::*;
use util::str::DOMString; use util::str::DOMString;
#[dom_struct] #[dom_struct]

View file

@ -18,9 +18,9 @@ use dom::htmlselectelement::HTMLSelectElement;
use dom::node::{Node, UnbindContext}; use dom::node::{Node, UnbindContext};
use dom::text::Text; use dom::text::Text;
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use selectors::states::*;
use std::cell::Cell; use std::cell::Cell;
use string_cache::Atom; use string_cache::Atom;
use style::element_state::*;
use util::str::{DOMString, split_html_space_chars, str_join}; use util::str::{DOMString, split_html_space_chars, str_join};
#[dom_struct] #[dom_struct]

View file

@ -20,8 +20,8 @@ use dom::node::{Node, UnbindContext, window_from_node};
use dom::nodelist::NodeList; use dom::nodelist::NodeList;
use dom::validitystate::ValidityState; use dom::validitystate::ValidityState;
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use selectors::states::*;
use string_cache::Atom; use string_cache::Atom;
use style::element_state::*;
use util::str::DOMString; use util::str::DOMString;
#[dom_struct] #[dom_struct]

View file

@ -26,9 +26,9 @@ use dom::nodelist::NodeList;
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use msg::constellation_msg::ConstellationChan; use msg::constellation_msg::ConstellationChan;
use script_traits::ScriptMsg as ConstellationMsg; use script_traits::ScriptMsg as ConstellationMsg;
use selectors::states::*;
use std::cell::Cell; use std::cell::Cell;
use string_cache::Atom; use string_cache::Atom;
use style::element_state::*;
use textinput::{KeyReaction, Lines, TextInput}; use textinput::{KeyReaction, Lines, TextInput};
use util::str::DOMString; use util::str::DOMString;

View file

@ -63,6 +63,7 @@ use std::default::Default;
use std::iter::{self, FilterMap, Peekable}; use std::iter::{self, FilterMap, Peekable};
use std::mem; use std::mem;
use string_cache::{Atom, Namespace, QualName}; use string_cache::{Atom, Namespace, QualName};
use style::selector_impl::ServoSelectorImpl;
use util::str::DOMString; use util::str::DOMString;
use util::thread_state; use util::thread_state;
use uuid::Uuid; use uuid::Uuid;
@ -291,12 +292,12 @@ impl Node {
} }
pub struct QuerySelectorIterator { pub struct QuerySelectorIterator {
selectors: Vec<Selector>, selectors: Vec<Selector<ServoSelectorImpl>>,
iterator: TreeIterator, iterator: TreeIterator,
} }
impl<'a> QuerySelectorIterator { impl<'a> QuerySelectorIterator {
fn new(iter: TreeIterator, selectors: Vec<Selector>) fn new(iter: TreeIterator, selectors: Vec<Selector<ServoSelectorImpl>>)
-> QuerySelectorIterator { -> QuerySelectorIterator {
QuerySelectorIterator { QuerySelectorIterator {
selectors: selectors, selectors: selectors,

View file

@ -58,7 +58,6 @@ use script_thread::{HistoryTraversalThreadSource, FileReadingThreadSource, Senda
use script_thread::{ScriptChan, ScriptPort, MainThreadScriptChan, MainThreadScriptMsg, RunnableWrapper}; use script_thread::{ScriptChan, ScriptPort, MainThreadScriptChan, MainThreadScriptMsg, RunnableWrapper};
use script_traits::{DocumentState, MsDuration, ScriptToCompositorMsg, TimerEvent, TimerEventId}; use script_traits::{DocumentState, MsDuration, ScriptToCompositorMsg, TimerEvent, TimerEventId};
use script_traits::{MozBrowserEvent, ScriptMsg as ConstellationMsg, TimerEventRequest, TimerSource}; use script_traits::{MozBrowserEvent, ScriptMsg as ConstellationMsg, TimerEventRequest, TimerSource};
use selectors::parser::PseudoElement;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cell::Cell; use std::cell::Cell;
@ -74,6 +73,7 @@ use std::sync::mpsc::{Sender, channel};
use string_cache::Atom; use string_cache::Atom;
use style::context::ReflowGoal; use style::context::ReflowGoal;
use style::error_reporting::ParseErrorReporter; use style::error_reporting::ParseErrorReporter;
use style::selector_impl::PseudoElement;
use time; use time;
use timers::{ActiveTimers, IsInterval, ScheduledCallback, TimerCallback, TimerHandle}; use timers::{ActiveTimers, IsInterval, ScheduledCallback, TimerCallback, TimerHandle};
use url::Url; use url::Url;

View file

@ -18,12 +18,12 @@ use net_traits::image_cache_thread::ImageCacheThread;
use profile_traits::mem::ReportsChan; use profile_traits::mem::ReportsChan;
use script_traits::{ConstellationControlMsg, LayoutControlMsg, LayoutMsg as ConstellationMsg}; use script_traits::{ConstellationControlMsg, LayoutControlMsg, LayoutMsg as ConstellationMsg};
use script_traits::{OpaqueScriptLayoutChannel, UntrustedNodeAddress}; use script_traits::{OpaqueScriptLayoutChannel, UntrustedNodeAddress};
use selectors::parser::PseudoElement;
use std::any::Any; use std::any::Any;
use std::sync::Arc; use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender, channel}; use std::sync::mpsc::{Receiver, Sender, channel};
use string_cache::Atom; use string_cache::Atom;
use style::context::ReflowGoal; use style::context::ReflowGoal;
use style::selector_impl::PseudoElement;
use style::stylesheets::Stylesheet; use style::stylesheets::Stylesheet;
use url::Url; use url::Url;
use util::ipc::OptionalOpaqueIpcSender; use util::ipc::OptionalOpaqueIpcSender;

View file

@ -60,7 +60,7 @@ extern crate rand;
extern crate ref_slice; extern crate ref_slice;
extern crate rustc_serialize; extern crate rustc_serialize;
extern crate script_traits; extern crate script_traits;
#[macro_use(state_pseudo_classes)] extern crate selectors; extern crate selectors;
extern crate serde; extern crate serde;
extern crate smallvec; extern crate smallvec;
#[macro_use(atom, ns)] extern crate string_cache; #[macro_use(atom, ns)] extern crate string_cache;

View file

@ -971,7 +971,7 @@ dependencies = [
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"script 0.0.1", "script 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1530,7 +1530,7 @@ dependencies = [
"ref_slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ref_slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1579,7 +1579,7 @@ dependencies = [
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.2.3" version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1782,7 +1782,7 @@ dependencies = [
"num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1", "plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1802,7 +1802,7 @@ dependencies = [
"euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1", "msg 0.0.1",
"plugins 0.0.1", "plugins 0.0.1",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
"style_traits 0.0.1", "style_traits 0.0.1",
@ -1821,7 +1821,7 @@ dependencies = [
"num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1", "plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1977,7 +1977,7 @@ dependencies = [
"plugins 0.0.1", "plugins 0.0.1",
"rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -29,7 +29,7 @@ matches = "0.1"
bitflags = "0.3" bitflags = "0.3"
num = "0.1.24" num = "0.1.24"
lazy_static = "0.1.10" lazy_static = "0.1.10"
selectors = { version = "0.2", features = ["unstable"] } selectors = { version = "0.4.1", features = ["unstable"] }
smallvec = "0.1" smallvec = "0.1"
string_cache = "0.2" string_cache = "0.2"
euclid = {version = "0.4", features = ["plugins"]} euclid = {version = "0.4", features = ["plugins"]}

View file

@ -5,10 +5,11 @@
#![allow(unsafe_code)] #![allow(unsafe_code)]
use data::PrivateStyleData; use data::PrivateStyleData;
use element_state::ElementState;
use properties::{ComputedValues, PropertyDeclaration, PropertyDeclarationBlock}; use properties::{ComputedValues, PropertyDeclaration, PropertyDeclarationBlock};
use restyle_hints::{ElementSnapshot, RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint}; use restyle_hints::{ElementSnapshot, RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint};
use selector_impl::ServoSelectorImpl;
use selectors::matching::DeclarationBlock; use selectors::matching::DeclarationBlock;
use selectors::states::ElementState;
use smallvec::VecLike; use smallvec::VecLike;
use std::cell::{Ref, RefMut}; use std::cell::{Ref, RefMut};
use std::marker::PhantomData; use std::marker::PhantomData;
@ -185,7 +186,7 @@ pub trait TDocument<'ld> : Sized + Copy + Clone {
fn drain_modified_elements(&self) -> Vec<(Self::ConcreteElement, ElementSnapshot)>; fn drain_modified_elements(&self) -> Vec<(Self::ConcreteElement, ElementSnapshot)>;
} }
pub trait TElement<'le> : Sized + Copy + Clone + ::selectors::Element { pub trait TElement<'le> : Sized + Copy + Clone + ::selectors::Element<Impl=ServoSelectorImpl> {
type ConcreteNode: TNode<'le, ConcreteElement = Self, ConcreteDocument = Self::ConcreteDocument>; type ConcreteNode: TNode<'le, ConcreteElement = Self, ConcreteDocument = Self::ConcreteDocument>;
type ConcreteDocument: TDocument<'le, ConcreteNode = Self::ConcreteNode, ConcreteElement = Self>; type ConcreteDocument: TDocument<'le, ConcreteNode = Self::ConcreteNode, ConcreteElement = Self>;

View file

@ -0,0 +1,31 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
bitflags! {
#[doc = "Event-based element states."]
#[derive(HeapSizeOf)]
flags ElementState: u8 {
#[doc = "The mouse is down on this element. \
https://html.spec.whatwg.org/multipage/#selector-active \
FIXME(#7333): set/unset this when appropriate"]
const IN_ACTIVE_STATE = 0x01,
#[doc = "This element has focus. \
https://html.spec.whatwg.org/multipage/#selector-focus"]
const IN_FOCUS_STATE = 0x02,
#[doc = "The mouse is hovering over this element. \
https://html.spec.whatwg.org/multipage/#selector-hover"]
const IN_HOVER_STATE = 0x04,
#[doc = "Content is enabled (and can be disabled). \
http://www.whatwg.org/html/#selector-enabled"]
const IN_ENABLED_STATE = 0x08,
#[doc = "Content is disabled. \
http://www.whatwg.org/html/#selector-disabled"]
const IN_DISABLED_STATE = 0x10,
#[doc = "Content is checked. \
https://html.spec.whatwg.org/multipage/#selector-checked"]
const IN_CHECKED_STATE = 0x20,
#[doc = "https://html.spec.whatwg.org/multipage/#selector-indeterminate"]
const IN_INDETERMINATE_STATE = 0x40,
}
}

View file

@ -34,7 +34,7 @@ extern crate log;
extern crate matches; extern crate matches;
extern crate num; extern crate num;
extern crate rustc_serialize; extern crate rustc_serialize;
#[macro_use(state_pseudo_classes)] extern crate selectors; extern crate selectors;
extern crate serde; extern crate serde;
extern crate smallvec; extern crate smallvec;
#[macro_use(atom, ns)] extern crate string_cache; #[macro_use(atom, ns)] extern crate string_cache;
@ -50,6 +50,7 @@ pub mod context;
mod custom_properties; mod custom_properties;
pub mod data; pub mod data;
pub mod dom; pub mod dom;
pub mod element_state;
pub mod error_reporting; pub mod error_reporting;
pub mod font_face; pub mod font_face;
pub mod matching; pub mod matching;
@ -57,6 +58,7 @@ pub mod media_queries;
pub mod parallel; pub mod parallel;
pub mod parser; pub mod parser;
pub mod restyle_hints; pub mod restyle_hints;
pub mod selector_impl;
pub mod selector_matching; pub mod selector_matching;
pub mod sequential; pub mod sequential;
pub mod stylesheets; pub mod stylesheets;

View file

@ -9,12 +9,12 @@ use context::SharedStyleContext;
use data::PrivateStyleData; use data::PrivateStyleData;
use dom::{TElement, TNode, TRestyleDamage}; use dom::{TElement, TNode, TRestyleDamage};
use properties::{ComputedValues, PropertyDeclaration, cascade}; use properties::{ComputedValues, PropertyDeclaration, cascade};
use selector_impl::{NonTSPseudoClass, PseudoElement};
use selector_matching::{DeclarationBlock, Stylist}; use selector_matching::{DeclarationBlock, Stylist};
use selectors::Element; use selectors::Element;
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
use selectors::matching::{CommonStyleAffectingAttributeMode, CommonStyleAffectingAttributes}; use selectors::matching::{CommonStyleAffectingAttributeMode, CommonStyleAffectingAttributes};
use selectors::matching::{common_style_affecting_attributes, rare_style_affecting_attributes}; use selectors::matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
use selectors::parser::PseudoElement;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::slice::Iter; use std::slice::Iter;
@ -246,7 +246,7 @@ impl StyleSharingCandidate {
local_name: element.get_local_name().clone(), local_name: element.get_local_name().clone(),
class: element.get_attr(&ns!(), &atom!("class")) class: element.get_attr(&ns!(), &atom!("class"))
.map(|string| string.to_owned()), .map(|string| string.to_owned()),
link: element.is_link(), link: element.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink),
namespace: (*element.get_namespace()).clone(), namespace: (*element.get_namespace()).clone(),
common_style_affecting_attributes: common_style_affecting_attributes:
create_common_style_affecting_attributes_from_element::<'le, E>(&element) create_common_style_affecting_attributes_from_element::<'le, E>(&element)
@ -314,7 +314,7 @@ impl StyleSharingCandidate {
} }
} }
if element.is_link() != self.link { if element.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink) != self.link {
return false return false
} }

View file

@ -3,10 +3,11 @@
* 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 attr::{AttrIdentifier, AttrValue}; use attr::{AttrIdentifier, AttrValue};
use element_state::*;
use selector_impl::{NonTSPseudoClass, ServoSelectorImpl};
use selectors::Element; use selectors::Element;
use selectors::matching::matches_compound_selector; use selectors::matching::matches_compound_selector;
use selectors::parser::{AttrSelector, Combinator, CompoundSelector, NamespaceConstraint, SimpleSelector}; use selectors::parser::{AttrSelector, Combinator, CompoundSelector, NamespaceConstraint, SimpleSelector};
use selectors::states::*;
use std::clone::Clone; use std::clone::Clone;
use std::sync::Arc; use std::sync::Arc;
use string_cache::{Atom, Namespace}; use string_cache::{Atom, Namespace};
@ -92,24 +93,20 @@ impl<'a, E> ElementWrapper<'a, E> where E: Element {
} }
} }
macro_rules! snapshot_state_accessors { impl<'a, E> Element for ElementWrapper<'a, E> where E: Element<Impl=ServoSelectorImpl> {
($( type Impl = E::Impl;
$(#[$Flag_attr: meta])*
state $css: expr => $variant: ident / $method: ident / fn match_non_ts_pseudo_class(&self, pseudo_class: NonTSPseudoClass) -> bool {
$flag: ident = $value: expr, let flag = pseudo_class.state_flag();
)+) => { $( fn $method(&self) -> bool { if flag == ElementState::empty() {
match self.snapshot.state { self.element.match_non_ts_pseudo_class(pseudo_class)
Some(s) => s.contains($flag), } else {
None => self.element.$method() match self.snapshot.state {
Some(s) => s.contains(pseudo_class.state_flag()),
None => self.element.match_non_ts_pseudo_class(pseudo_class)
}
} }
} )+
} }
}
impl<'a, E> Element for ElementWrapper<'a, E> where E: Element {
// Implement the state accessors on Element to use the snapshot state if it exists.
state_pseudo_classes!(snapshot_state_accessors);
fn parent_element(&self) -> Option<Self> { fn parent_element(&self) -> Option<Self> {
self.element.parent_element().map(ElementWrapper::new) self.element.parent_element().map(ElementWrapper::new)
@ -168,15 +165,6 @@ impl<'a, E> Element for ElementWrapper<'a, E> where E: Element {
fn is_root(&self) -> bool { fn is_root(&self) -> bool {
self.element.is_root() self.element.is_root()
} }
fn is_link(&self) -> bool {
self.element.is_link()
}
fn is_visited_link(&self) -> bool {
self.element.is_visited_link()
}
fn is_unvisited_link(&self) -> bool {
self.element.is_unvisited_link()
}
fn each_class<F>(&self, mut callback: F) where F: FnMut(&Atom) { fn each_class<F>(&self, mut callback: F) where F: FnMut(&Atom) {
match self.snapshot.attrs { match self.snapshot.attrs {
Some(_) => { Some(_) => {
@ -189,24 +177,14 @@ impl<'a, E> Element for ElementWrapper<'a, E> where E: Element {
} }
} }
macro_rules! gen_selector_to_state { fn selector_to_state(sel: &SimpleSelector<ServoSelectorImpl>) -> ElementState {
($( match *sel {
$(#[$Flag_attr: meta])* SimpleSelector::NonTSPseudoClass(ref pc) => pc.state_flag(),
state $css: expr => $variant: ident / $method: ident / _ => ElementState::empty(),
$flag: ident = $value: expr,
)+) => {
fn selector_to_state(sel: &SimpleSelector) -> ElementState {
match *sel {
$( SimpleSelector::$variant => $flag, )+
_ => ElementState::empty(),
}
}
} }
} }
state_pseudo_classes!(gen_selector_to_state); fn is_attr_selector(sel: &SimpleSelector<ServoSelectorImpl>) -> bool {
fn is_attr_selector(sel: &SimpleSelector) -> bool {
match *sel { match *sel {
SimpleSelector::ID(_) | SimpleSelector::ID(_) |
SimpleSelector::Class(_) | SimpleSelector::Class(_) |
@ -272,7 +250,7 @@ impl Sensitivities {
// elements in the document. // elements in the document.
#[derive(Debug)] #[derive(Debug)]
struct Dependency { struct Dependency {
selector: Arc<CompoundSelector>, selector: Arc<CompoundSelector<ServoSelectorImpl>>,
combinator: Option<Combinator>, combinator: Option<Combinator>,
sensitivities: Sensitivities, sensitivities: Sensitivities,
} }
@ -288,7 +266,8 @@ impl DependencySet {
} }
pub fn compute_hint<E>(&self, el: &E, snapshot: &ElementSnapshot, current_state: ElementState) pub fn compute_hint<E>(&self, el: &E, snapshot: &ElementSnapshot, current_state: ElementState)
-> RestyleHint where E: Element, E: Clone { -> RestyleHint
where E: Element<Impl=ServoSelectorImpl> + Clone {
let state_changes = snapshot.state.map_or(ElementState::empty(), |old_state| current_state ^ old_state); let state_changes = snapshot.state.map_or(ElementState::empty(), |old_state| current_state ^ old_state);
let attrs_changed = snapshot.attrs.is_some(); let attrs_changed = snapshot.attrs.is_some();
let mut hint = RestyleHint::empty(); let mut hint = RestyleHint::empty();
@ -308,7 +287,7 @@ impl DependencySet {
hint hint
} }
pub fn note_selector(&mut self, selector: Arc<CompoundSelector>) { pub fn note_selector(&mut self, selector: Arc<CompoundSelector<ServoSelectorImpl>>) {
let mut cur = selector; let mut cur = selector;
let mut combinator: Option<Combinator> = None; let mut combinator: Option<Combinator> = None;
loop { loop {

View file

@ -0,0 +1,91 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use element_state::ElementState;
use selectors::parser::{ParserContext, SelectorImpl};
#[derive(Clone, Debug, PartialEq, HeapSizeOf)]
pub enum PseudoElement {
Before,
After,
}
#[derive(Clone, Debug, PartialEq, HeapSizeOf)]
pub enum NonTSPseudoClass {
AnyLink,
Link,
Visited,
Active,
Focus,
Hover,
Enabled,
Disabled,
Checked,
Indeterminate,
ServoNonZeroBorder,
}
impl NonTSPseudoClass {
pub fn state_flag(&self) -> ElementState {
use element_state::*;
use self::NonTSPseudoClass::*;
match *self {
Active => IN_ACTIVE_STATE,
Focus => IN_FOCUS_STATE,
Hover => IN_HOVER_STATE,
Enabled => IN_ENABLED_STATE,
Disabled => IN_DISABLED_STATE,
Checked => IN_CHECKED_STATE,
Indeterminate => IN_INDETERMINATE_STATE,
AnyLink |
Link |
Visited |
ServoNonZeroBorder => ElementState::empty(),
}
}
}
#[derive(Clone, Debug, PartialEq, HeapSizeOf)]
pub struct ServoSelectorImpl;
impl SelectorImpl for ServoSelectorImpl {
type PseudoElement = PseudoElement;
type NonTSPseudoClass = NonTSPseudoClass;
fn parse_non_ts_pseudo_class(context: &ParserContext,
name: &str) -> Result<NonTSPseudoClass, ()> {
use self::NonTSPseudoClass::*;
let pseudo_class = match_ignore_ascii_case! { name,
"any-link" => AnyLink,
"link" => Link,
"visited" => Visited,
"active" => Active,
"focus" => Focus,
"hover" => Hover,
"enabled" => Enabled,
"disabled" => Disabled,
"checked" => Checked,
"indeterminate" => Indeterminate,
"-servo-nonzero-border" => {
if !context.in_user_agent_stylesheet {
return Err(());
}
ServoNonZeroBorder
},
_ => return Err(())
};
Ok(pseudo_class)
}
fn parse_pseudo_element(_context: &ParserContext,
name: &str) -> Result<PseudoElement, ()> {
use self::PseudoElement::*;
match_ignore_ascii_case! { name,
"before" => Ok(Before),
"after" => Ok(After),
_ => Err(())
}
}
}

View file

@ -6,16 +6,16 @@
#![allow(unsafe_code)] #![allow(unsafe_code)]
use dom::TElement; use dom::TElement;
use element_state::*;
use error_reporting::{ParseErrorReporter, StdoutErrorReporter}; use error_reporting::{ParseErrorReporter, StdoutErrorReporter};
use media_queries::{Device, MediaType}; use media_queries::{Device, MediaType};
use properties::{PropertyDeclaration, PropertyDeclarationBlock}; use properties::{PropertyDeclaration, PropertyDeclarationBlock};
use restyle_hints::{ElementSnapshot, RestyleHint, DependencySet}; use restyle_hints::{ElementSnapshot, RestyleHint, DependencySet};
use selector_impl::{PseudoElement, ServoSelectorImpl};
use selectors::Element; use selectors::Element;
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
use selectors::matching::DeclarationBlock as GenericDeclarationBlock; use selectors::matching::DeclarationBlock as GenericDeclarationBlock;
use selectors::matching::{Rule, SelectorMap}; use selectors::matching::{Rule, SelectorMap};
use selectors::parser::PseudoElement;
use selectors::states::*;
use smallvec::VecLike; use smallvec::VecLike;
use std::process; use std::process;
use std::sync::Arc; use std::sync::Arc;
@ -216,7 +216,7 @@ impl Stylist {
// more expensive than getting it directly from the caller. // more expensive than getting it directly from the caller.
current_state: ElementState) current_state: ElementState)
-> RestyleHint -> RestyleHint
where E: Element + Clone { where E: Element<Impl=ServoSelectorImpl> + Clone {
self.state_deps.compute_hint(element, snapshot, current_state) self.state_deps.compute_hint(element, snapshot, current_state)
} }
@ -337,8 +337,8 @@ impl Stylist {
} }
struct PerOriginSelectorMap { struct PerOriginSelectorMap {
normal: SelectorMap<Vec<PropertyDeclaration>>, normal: SelectorMap<Vec<PropertyDeclaration>, ServoSelectorImpl>,
important: SelectorMap<Vec<PropertyDeclaration>>, important: SelectorMap<Vec<PropertyDeclaration>, ServoSelectorImpl>,
} }
impl PerOriginSelectorMap { impl PerOriginSelectorMap {

View file

@ -10,6 +10,7 @@ use font_face::{FontFaceRule, parse_font_face_block};
use media_queries::{Device, MediaQueryList, parse_media_query_list}; use media_queries::{Device, MediaQueryList, parse_media_query_list};
use parser::{ParserContext, log_css_error}; use parser::{ParserContext, log_css_error};
use properties::{PropertyDeclarationBlock, parse_property_declaration_list}; use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
use selector_impl::ServoSelectorImpl;
use selectors::parser::{Selector, parse_selector_list}; use selectors::parser::{Selector, parse_selector_list};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
@ -74,7 +75,7 @@ impl MediaRule {
#[derive(Debug, HeapSizeOf, PartialEq)] #[derive(Debug, HeapSizeOf, PartialEq)]
pub struct StyleRule { pub struct StyleRule {
pub selectors: Vec<Selector>, pub selectors: Vec<Selector<ServoSelectorImpl>>,
pub declarations: PropertyDeclarationBlock, pub declarations: PropertyDeclarationBlock,
} }
@ -408,17 +409,17 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
impl<'a> QualifiedRuleParser for TopLevelRuleParser<'a> { impl<'a> QualifiedRuleParser for TopLevelRuleParser<'a> {
type Prelude = Vec<Selector>; type Prelude = Vec<Selector<ServoSelectorImpl>>;
type QualifiedRule = CSSRule; type QualifiedRule = CSSRule;
#[inline] #[inline]
fn parse_prelude(&self, input: &mut Parser) -> Result<Vec<Selector>, ()> { fn parse_prelude(&self, input: &mut Parser) -> Result<Vec<Selector<ServoSelectorImpl>>, ()> {
self.state.set(State::Body); self.state.set(State::Body);
QualifiedRuleParser::parse_prelude(&NestedRuleParser { context: &self.context }, input) QualifiedRuleParser::parse_prelude(&NestedRuleParser { context: &self.context }, input)
} }
#[inline] #[inline]
fn parse_block(&self, prelude: Vec<Selector>, input: &mut Parser) -> Result<CSSRule, ()> { fn parse_block(&self, prelude: Vec<Selector<ServoSelectorImpl>>, input: &mut Parser) -> Result<CSSRule, ()> {
QualifiedRuleParser::parse_block(&NestedRuleParser { context: &self.context }, QualifiedRuleParser::parse_block(&NestedRuleParser { context: &self.context },
prelude, input) prelude, input)
} }
@ -475,14 +476,14 @@ 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>; type Prelude = Vec<Selector<ServoSelectorImpl>>;
type QualifiedRule = CSSRule; type QualifiedRule = CSSRule;
fn parse_prelude(&self, input: &mut Parser) -> Result<Vec<Selector>, ()> { fn parse_prelude(&self, input: &mut Parser) -> Result<Vec<Selector<ServoSelectorImpl>>, ()> {
parse_selector_list(&self.context.selector_context, input) parse_selector_list(&self.context.selector_context, input)
} }
fn parse_block(&self, prelude: Vec<Selector>, input: &mut Parser) -> Result<CSSRule, ()> { fn parse_block(&self, prelude: Vec<Selector<ServoSelectorImpl>>, input: &mut Parser) -> Result<CSSRule, ()> {
Ok(CSSRule::Style(StyleRule { Ok(CSSRule::Style(StyleRule {
selectors: prelude, selectors: prelude,
declarations: parse_property_declaration_list(self.context, input) declarations: parse_property_declaration_list(self.context, input)

View file

@ -20,7 +20,7 @@ log = "0.3"
lazy_static = "0.1.10" lazy_static = "0.1.10"
num = "0.1.24" num = "0.1.24"
rustc-serialize = "0.3" rustc-serialize = "0.3"
selectors = "0.2" selectors = "0.4.1"
serde = "0.6" serde = "0.6"
serde_macros = "0.6" serde_macros = "0.6"
url = "0.5.2" url = "0.5.2"

View file

@ -57,7 +57,7 @@ smallvec = "0.1"
num_cpus = "0.2.2" num_cpus = "0.2.2"
num = "0.1.24" num = "0.1.24"
euclid = {version = "0.4", features = ["plugins"]} euclid = {version = "0.4", features = ["plugins"]}
selectors = "0.2.3" selectors = "0.4.1"
serde = "0.6" serde = "0.6"
serde_macros = "0.6" serde_macros = "0.6"
string_cache = "0.2" string_cache = "0.2"

View file

@ -16,8 +16,7 @@ use libc::{c_void, size_t};
use logical_geometry::WritingMode; use logical_geometry::WritingMode;
use rand::OsRng; use rand::OsRng;
use range::Range; use range::Range;
use selectors::parser::{Combinator, CompoundSelector, PseudoElement, Selector, SimpleSelector}; use selectors::parser::{Combinator, CompoundSelector, Selector, SimpleSelector, SelectorImpl};
use selectors::states::ElementState;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::collections::{HashMap, LinkedList}; use std::collections::{HashMap, LinkedList};
use std::hash::{BuildHasher, Hash}; use std::hash::{BuildHasher, Hash};
@ -308,7 +307,9 @@ impl HeapSizeOf for () {
} }
} }
impl HeapSizeOf for Selector { impl<T: SelectorImpl> HeapSizeOf for Selector<T>
where T::NonTSPseudoClass: HeapSizeOf,
T::PseudoElement: HeapSizeOf {
fn heap_size_of_children(&self) -> usize { fn heap_size_of_children(&self) -> usize {
let &Selector { ref compound_selectors, ref pseudo_element, ref specificity } = self; let &Selector { ref compound_selectors, ref pseudo_element, ref specificity } = self;
compound_selectors.heap_size_of_children() + pseudo_element.heap_size_of_children() + compound_selectors.heap_size_of_children() + pseudo_element.heap_size_of_children() +
@ -316,23 +317,27 @@ impl HeapSizeOf for Selector {
} }
} }
impl HeapSizeOf for CompoundSelector { impl<T: SelectorImpl> HeapSizeOf for CompoundSelector<T>
where T::NonTSPseudoClass: HeapSizeOf {
fn heap_size_of_children(&self) -> usize { fn heap_size_of_children(&self) -> usize {
let &CompoundSelector { ref simple_selectors, ref next } = self; let &CompoundSelector { ref simple_selectors, ref next } = self;
simple_selectors.heap_size_of_children() + next.heap_size_of_children() simple_selectors.heap_size_of_children() + next.heap_size_of_children()
} }
} }
impl HeapSizeOf for SimpleSelector { impl<T: SelectorImpl> HeapSizeOf for SimpleSelector<T>
where T::NonTSPseudoClass: HeapSizeOf {
fn heap_size_of_children(&self) -> usize { fn heap_size_of_children(&self) -> usize {
match *self { match *self {
SimpleSelector::Negation(ref vec) => vec.heap_size_of_children(), SimpleSelector::Negation(ref vec) => vec.heap_size_of_children(),
SimpleSelector::AttrIncludes(_, ref str) | SimpleSelector::AttrPrefixMatch(_, ref str) | SimpleSelector::AttrIncludes(_, ref str) | SimpleSelector::AttrPrefixMatch(_, ref str) |
SimpleSelector::AttrSubstringMatch(_, ref str) | SimpleSelector::AttrSuffixMatch(_, ref str) SimpleSelector::AttrSubstringMatch(_, ref str) | SimpleSelector::AttrSuffixMatch(_, ref str)
=> str.heap_size_of_children(), => str.heap_size_of_children(),
SimpleSelector::AttrEqual(_, ref str, _) => str.heap_size_of_children(), SimpleSelector::AttrEqual(_, ref str, _) => str.heap_size_of_children(),
SimpleSelector::AttrDashMatch(_, ref first, ref second) => first.heap_size_of_children() SimpleSelector::AttrDashMatch(_, ref first, ref second)
+ second.heap_size_of_children(), => first.heap_size_of_children() + second.heap_size_of_children(),
SimpleSelector::NonTSPseudoClass(ref pseudo_class)
=> pseudo_class.heap_size_of_children(),
// All other types come down to Atom, enum or i32, all 0 // All other types come down to Atom, enum or i32, all 0
_ => 0 _ => 0
} }
@ -351,5 +356,5 @@ known_heap_size!(0, Au, WritingMode, CSSParserColor, RGBA, Cursor, Matrix4, Qual
known_heap_size!(0, PagePx, ViewportPx, OsRng); known_heap_size!(0, PagePx, ViewportPx, OsRng);
known_heap_size!(0, TokenSerializationType, LengthOrPercentageOrAuto); known_heap_size!(0, TokenSerializationType, LengthOrPercentageOrAuto);
known_heap_size!(0, ElementState, Combinator, PseudoElement, str); known_heap_size!(0, Combinator, str);
known_heap_size!(0, Uuid); known_heap_size!(0, Uuid);

12
ports/cef/Cargo.lock generated
View file

@ -930,7 +930,7 @@ dependencies = [
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"script 0.0.1", "script 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1454,7 +1454,7 @@ dependencies = [
"ref_slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ref_slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1494,7 +1494,7 @@ dependencies = [
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.2.3" version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1732,7 +1732,7 @@ dependencies = [
"num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1", "plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1754,7 +1754,7 @@ dependencies = [
"num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1", "plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1910,7 +1910,7 @@ dependencies = [
"plugins 0.0.1", "plugins 0.0.1",
"rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -9,7 +9,7 @@ dependencies = [
"libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
@ -312,7 +312,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.2.3" version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -383,7 +383,7 @@ dependencies = [
"num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1", "plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -405,7 +405,7 @@ dependencies = [
"num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1", "plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -465,7 +465,7 @@ dependencies = [
"plugins 0.0.1", "plugins 0.0.1",
"rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -16,7 +16,7 @@ euclid = {version = "0.4", features = ["plugins"]}
libc = "0.2" libc = "0.2"
log = "0.3" log = "0.3"
num_cpus = "0.2.2" num_cpus = "0.2.2"
selectors = "0.2" selectors = "0.4.1"
smallvec = "0.1" smallvec = "0.1"
string_cache = "0.2" string_cache = "0.2"
url = "0.5.2" url = "0.5.2"

View file

@ -13,7 +13,6 @@ extern crate cssparser;
extern crate euclid; extern crate euclid;
extern crate libc; extern crate libc;
extern crate num_cpus; extern crate num_cpus;
#[macro_use(state_pseudo_classes)]
extern crate selectors; extern crate selectors;
extern crate smallvec; extern crate smallvec;
#[macro_use(atom, ns)] #[macro_use(atom, ns)]

View file

@ -17,7 +17,6 @@ use bindings::{ServoNodeData};
use libc::uintptr_t; use libc::uintptr_t;
use selectors::matching::DeclarationBlock; use selectors::matching::DeclarationBlock;
use selectors::parser::{AttrSelector, NamespaceConstraint}; use selectors::parser::{AttrSelector, NamespaceConstraint};
use selectors::states::*;
use smallvec::VecLike; use smallvec::VecLike;
use std::cell::{Ref, RefCell, RefMut}; use std::cell::{Ref, RefCell, RefMut};
use std::marker::PhantomData; use std::marker::PhantomData;
@ -28,12 +27,14 @@ use std::sync::Arc;
use string_cache::{Atom, Namespace}; use string_cache::{Atom, Namespace};
use style::data::PrivateStyleData; use style::data::PrivateStyleData;
use style::dom::{OpaqueNode, TDocument, TElement, TNode, TRestyleDamage, UnsafeNode}; use style::dom::{OpaqueNode, TDocument, TElement, TNode, TRestyleDamage, UnsafeNode};
use style::element_state::ElementState;
#[allow(unused_imports)] // Used in commented-out code. #[allow(unused_imports)] // Used in commented-out code.
use style::error_reporting::StdoutErrorReporter; use style::error_reporting::StdoutErrorReporter;
use style::properties::{ComputedValues, PropertyDeclaration, PropertyDeclarationBlock}; use style::properties::{ComputedValues, PropertyDeclaration, PropertyDeclarationBlock};
#[allow(unused_imports)] // Used in commented-out code. #[allow(unused_imports)] // Used in commented-out code.
use style::properties::{parse_style_attribute}; use style::properties::{parse_style_attribute};
use style::restyle_hints::ElementSnapshot; use style::restyle_hints::ElementSnapshot;
use style::selector_impl::{NonTSPseudoClass, ServoSelectorImpl};
#[allow(unused_imports)] // Used in commented-out code. #[allow(unused_imports)] // Used in commented-out code.
use url::Url; use url::Url;
@ -351,17 +352,9 @@ impl<'le> TElement<'le> for GeckoElement<'le> {
} }
} }
macro_rules! state_getter {
($(
$(#[$Flag_attr: meta])*
state $css: expr => $variant: ident / $method: ident /
$flag: ident = $value: expr,
)+) => {
$( fn $method(&self) -> bool { self.get_state().contains($flag) } )+
}
}
impl<'le> ::selectors::Element for GeckoElement<'le> { impl<'le> ::selectors::Element for GeckoElement<'le> {
type Impl = ServoSelectorImpl;
fn parent_element(&self) -> Option<Self> { fn parent_element(&self) -> Option<Self> {
unimplemented!() unimplemented!()
} }
@ -412,26 +405,29 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
*/ */
} }
fn is_link(&self) -> bool { fn match_non_ts_pseudo_class(&self, pseudo_class: NonTSPseudoClass) -> bool {
unsafe { match pseudo_class {
Gecko_IsLink(self.element) != 0 // https://github.com/servo/servo/issues/8718
NonTSPseudoClass::Link => unsafe { Gecko_IsLink(self.element) != 0 },
NonTSPseudoClass::AnyLink => unsafe { Gecko_IsUnvisitedLink(self.element) != 0 },
NonTSPseudoClass::Visited => unsafe { Gecko_IsVisitedLink(self.element) != 0 },
NonTSPseudoClass::ServoNonZeroBorder => {
unimplemented!()
},
NonTSPseudoClass::Active |
NonTSPseudoClass::Focus |
NonTSPseudoClass::Hover |
NonTSPseudoClass::Enabled |
NonTSPseudoClass::Disabled |
NonTSPseudoClass::Checked |
NonTSPseudoClass::Indeterminate => {
self.get_state().contains(pseudo_class.state_flag())
},
} }
} }
fn is_unvisited_link(&self) -> bool {
unsafe {
Gecko_IsUnvisitedLink(self.element) != 0
}
}
fn is_visited_link(&self) -> bool {
unsafe {
Gecko_IsVisitedLink(self.element) != 0
}
}
state_pseudo_classes!(state_getter);
fn get_id(&self) -> Option<Atom> { fn get_id(&self) -> Option<Atom> {
// FIXME(bholley): Servo caches the id atom directly on the element to // FIXME(bholley): Servo caches the id atom directly on the element to
// make this blazing fast. Assuming that was a measured optimization, doing // make this blazing fast. Assuming that was a measured optimization, doing
@ -452,10 +448,6 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
} }
} }
fn has_servo_nonzero_border(&self) -> bool {
unimplemented!()
}
fn match_attr<F>(&self, attr: &AttrSelector, test: F) -> bool where F: Fn(&str) -> bool { fn match_attr<F>(&self, attr: &AttrSelector, test: F) -> bool where F: Fn(&str) -> bool {
// FIXME(bholley): This is copy-pasted from the servo wrapper's version. // FIXME(bholley): This is copy-pasted from the servo wrapper's version.
// We should find a way to share it. // We should find a way to share it.

12
ports/gonk/Cargo.lock generated
View file

@ -901,7 +901,7 @@ dependencies = [
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"script 0.0.1", "script 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1425,7 +1425,7 @@ dependencies = [
"ref_slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ref_slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1465,7 +1465,7 @@ dependencies = [
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.2.3" version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1701,7 +1701,7 @@ dependencies = [
"num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1", "plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1723,7 +1723,7 @@ dependencies = [
"num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1", "plugins 0.0.1",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1879,7 +1879,7 @@ dependencies = [
"plugins 0.0.1", "plugins 0.0.1",
"rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -27,6 +27,6 @@ path = "../../../components/util"
app_units = {version = "0.1", features = ["plugins"]} app_units = {version = "0.1", features = ["plugins"]}
url = "0.5.2" url = "0.5.2"
cssparser = "0.5" cssparser = "0.5"
selectors = "0.2" selectors = "0.4.1"
string_cache = "0.2" string_cache = "0.2"
euclid = {version = "0.4", features = ["plugins"]} euclid = {version = "0.4", features = ["plugins"]}