mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
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:
parent
9baa59a6b4
commit
a1c830f1c1
40 changed files with 342 additions and 252 deletions
|
@ -3,10 +3,11 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use attr::{AttrIdentifier, AttrValue};
|
||||
use element_state::*;
|
||||
use selector_impl::{NonTSPseudoClass, ServoSelectorImpl};
|
||||
use selectors::Element;
|
||||
use selectors::matching::matches_compound_selector;
|
||||
use selectors::parser::{AttrSelector, Combinator, CompoundSelector, NamespaceConstraint, SimpleSelector};
|
||||
use selectors::states::*;
|
||||
use std::clone::Clone;
|
||||
use std::sync::Arc;
|
||||
use string_cache::{Atom, Namespace};
|
||||
|
@ -92,24 +93,20 @@ impl<'a, E> ElementWrapper<'a, E> where E: Element {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! snapshot_state_accessors {
|
||||
($(
|
||||
$(#[$Flag_attr: meta])*
|
||||
state $css: expr => $variant: ident / $method: ident /
|
||||
$flag: ident = $value: expr,
|
||||
)+) => { $( fn $method(&self) -> bool {
|
||||
match self.snapshot.state {
|
||||
Some(s) => s.contains($flag),
|
||||
None => self.element.$method()
|
||||
impl<'a, E> Element for ElementWrapper<'a, E> where E: Element<Impl=ServoSelectorImpl> {
|
||||
type Impl = E::Impl;
|
||||
|
||||
fn match_non_ts_pseudo_class(&self, pseudo_class: NonTSPseudoClass) -> bool {
|
||||
let flag = pseudo_class.state_flag();
|
||||
if flag == ElementState::empty() {
|
||||
self.element.match_non_ts_pseudo_class(pseudo_class)
|
||||
} else {
|
||||
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> {
|
||||
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 {
|
||||
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) {
|
||||
match self.snapshot.attrs {
|
||||
Some(_) => {
|
||||
|
@ -189,24 +177,14 @@ impl<'a, E> Element for ElementWrapper<'a, E> where E: Element {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! gen_selector_to_state {
|
||||
($(
|
||||
$(#[$Flag_attr: meta])*
|
||||
state $css: expr => $variant: ident / $method: ident /
|
||||
$flag: ident = $value: expr,
|
||||
)+) => {
|
||||
fn selector_to_state(sel: &SimpleSelector) -> ElementState {
|
||||
match *sel {
|
||||
$( SimpleSelector::$variant => $flag, )+
|
||||
_ => ElementState::empty(),
|
||||
}
|
||||
}
|
||||
fn selector_to_state(sel: &SimpleSelector<ServoSelectorImpl>) -> ElementState {
|
||||
match *sel {
|
||||
SimpleSelector::NonTSPseudoClass(ref pc) => pc.state_flag(),
|
||||
_ => ElementState::empty(),
|
||||
}
|
||||
}
|
||||
|
||||
state_pseudo_classes!(gen_selector_to_state);
|
||||
|
||||
fn is_attr_selector(sel: &SimpleSelector) -> bool {
|
||||
fn is_attr_selector(sel: &SimpleSelector<ServoSelectorImpl>) -> bool {
|
||||
match *sel {
|
||||
SimpleSelector::ID(_) |
|
||||
SimpleSelector::Class(_) |
|
||||
|
@ -272,7 +250,7 @@ impl Sensitivities {
|
|||
// elements in the document.
|
||||
#[derive(Debug)]
|
||||
struct Dependency {
|
||||
selector: Arc<CompoundSelector>,
|
||||
selector: Arc<CompoundSelector<ServoSelectorImpl>>,
|
||||
combinator: Option<Combinator>,
|
||||
sensitivities: Sensitivities,
|
||||
}
|
||||
|
@ -288,7 +266,8 @@ impl DependencySet {
|
|||
}
|
||||
|
||||
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 attrs_changed = snapshot.attrs.is_some();
|
||||
let mut hint = RestyleHint::empty();
|
||||
|
@ -308,7 +287,7 @@ impl DependencySet {
|
|||
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 combinator: Option<Combinator> = None;
|
||||
loop {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue