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

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

View file

@ -65,8 +65,6 @@ use profile_traits::mem::ProfilerChan as MemProfilerChan;
use profile_traits::time::ProfilerChan as TimeProfilerChan;
use script_thread::ScriptChan;
use script_traits::{LayoutMsg, ScriptMsg, TimerEventId, TimerSource, UntrustedNodeAddress};
use selectors::parser::PseudoElement;
use selectors::states::*;
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use std::boxed::FnBox;
@ -84,8 +82,10 @@ use std::sync::atomic::AtomicBool;
use std::sync::mpsc::{Receiver, Sender};
use string_cache::{Atom, Namespace, QualName};
use style::attr::{AttrIdentifier, AttrValue};
use style::element_state::*;
use style::properties::PropertyDeclarationBlock;
use style::restyle_hints::ElementSnapshot;
use style::selector_impl::PseudoElement;
use style::values::specified::Length;
use url::Url;
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::node::{Node, NodeDamage, document_from_node, window_from_node};
use dom::window::Window;
use selectors::parser::PseudoElement;
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::cell::Ref;
@ -19,6 +18,7 @@ use string_cache::Atom;
use style::error_reporting::ParseErrorReporter;
use style::properties::{PropertyDeclaration, Shorthand};
use style::properties::{is_supported_property, parse_one_declaration};
use style::selector_impl::PseudoElement;
use util::str::{DOMString, str_join};
// 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::{common_style_affecting_attributes, rare_style_affecting_attributes};
use selectors::parser::{AttrSelector, NamespaceConstraint, parse_author_origin_selector_list_from_str};
use selectors::states::*;
use smallvec::VecLike;
use std::ascii::AsciiExt;
use std::borrow::Cow;
@ -77,10 +76,12 @@ use std::default::Default;
use std::mem;
use std::sync::Arc;
use string_cache::{Atom, Namespace, QualName};
use style::element_state::*;
use style::error_reporting::ParseErrorReporter;
use style::properties::DeclaredValue;
use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size};
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
use style::selector_impl::{NonTSPseudoClass, ServoSelectorImpl};
use style::values::CSSFloat;
use style::values::specified::{self, CSSColor, CSSRGBA, LengthOrPercentage};
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> {
type Impl = ServoSelectorImpl;
fn parent_element(&self) -> Option<Root<Element>> {
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 {
self.local_name()
}
fn get_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> {
self.id_attribute.borrow().clone()
}
fn has_class(&self, name: &Atom) -> bool {
Element::has_class(&**self, name)
}
fn each_class<F>(&self, mut callback: F)
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
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
///
/// 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::validitystate::ValidityState;
use dom::virtualmethods::VirtualMethods;
use selectors::states::*;
use std::ascii::AsciiExt;
use std::cell::Cell;
use string_cache::Atom;
use style::element_state::*;
use util::str::DOMString;
#[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::nodelist::NodeList;
use dom::virtualmethods::VirtualMethods;
use selectors::states::*;
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::default::Default;
use std::intrinsics;
use std::rc::Rc;
use string_cache::Atom;
use style::element_state::*;
use util::str::DOMString;
#[dom_struct]

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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