Replace the SelectorImplExt trait with inherent methods.

This commit is contained in:
Simon Sapin 2016-07-20 13:58:07 +02:00
parent 3b676bc85d
commit f419db834c
10 changed files with 37 additions and 70 deletions

View file

@ -13,7 +13,8 @@ use num_traits::ToPrimitive;
use std::ascii::AsciiExt;
use std::str::FromStr;
use str::{HTML_SPACE_CHARACTERS, read_exponent, read_fraction};
use str::{read_numbers, split_commas, split_html_space_chars, str_join};
use str::{read_numbers, split_commas, split_html_space_chars};
#[cfg(not(feature = "gecko"))] use str::str_join;
use string_cache::{Atom, Namespace};
use url::Url;
use values::specified::Length;

View file

@ -12,8 +12,7 @@ use element_state::ElementState;
use properties::{ComputedValues, PropertyDeclaration, PropertyDeclarationBlock};
use refcell::{Ref, RefMut};
use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint};
use selector_impl::{ElementExt, SelectorImplExt};
use selectors::Element;
use selector_impl::ElementExt;
use selectors::matching::DeclarationBlock;
use sink::Push;
use std::ops::BitOr;
@ -162,8 +161,7 @@ pub trait TNode : Sized + Copy + Clone {
/// Returns the style results for the given node. If CSS selector matching
/// has not yet been performed, fails.
fn style(&self, _context: &SharedStyleContext) -> Ref<Arc<ComputedValues>>
where <Self::ConcreteElement as Element>::Impl: SelectorImplExt {
fn style(&self, _context: &SharedStyleContext) -> Ref<Arc<ComputedValues>> {
Ref::map(self.borrow_data().unwrap(), |data| data.style.as_ref().unwrap())
}

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use element_state::ElementState;
use selector_impl::{PseudoElementCascadeType, SelectorImplExt};
use selector_impl::PseudoElementCascadeType;
use selectors::parser::{ParserContext, SelectorImpl};
use string_cache::Atom;
use stylesheets::Stylesheet;
@ -286,9 +286,9 @@ impl SelectorImpl for GeckoSelectorImpl {
}
}
impl SelectorImplExt for GeckoSelectorImpl {
impl GeckoSelectorImpl {
#[inline]
fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType {
pub fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType {
match *pseudo {
PseudoElement::Before |
PseudoElement::After => PseudoElementCascadeType::Eager,
@ -298,7 +298,7 @@ impl SelectorImplExt for GeckoSelectorImpl {
}
#[inline]
fn each_pseudo_element<F>(mut fun: F)
pub fn each_pseudo_element<F>(mut fun: F)
where F: FnMut(PseudoElement) {
use self::AnonBoxPseudoElement::*;
use self::PseudoElement::*;
@ -375,7 +375,7 @@ impl SelectorImplExt for GeckoSelectorImpl {
}
#[inline]
fn pseudo_is_before_or_after(pseudo: &PseudoElement) -> bool {
pub fn pseudo_is_before_or_after(pseudo: &PseudoElement) -> bool {
match *pseudo {
PseudoElement::Before |
PseudoElement::After => true,
@ -384,17 +384,17 @@ impl SelectorImplExt for GeckoSelectorImpl {
}
#[inline]
fn pseudo_class_state_flag(pc: &NonTSPseudoClass) -> ElementState {
pub fn pseudo_class_state_flag(pc: &NonTSPseudoClass) -> ElementState {
pc.state_flag()
}
#[inline]
fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet] {
pub fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet] {
&[]
}
#[inline]
fn get_quirks_mode_stylesheet() -> Option<&'static Stylesheet> {
pub fn get_quirks_mode_stylesheet() -> Option<&'static Stylesheet> {
None
}
}

View file

@ -13,7 +13,7 @@ use context::{StyleContext, SharedStyleContext};
use data::PrivateStyleData;
use dom::{TElement, TNode, TRestyleDamage};
use properties::{ComputedValues, PropertyDeclaration, cascade};
use selector_impl::{ElementExt, SelectorImplExt, TheSelectorImpl, PseudoElement};
use selector_impl::{ElementExt, TheSelectorImpl, PseudoElement};
use selector_matching::{DeclarationBlock, Stylist};
use selectors::Element;
use selectors::bloom::BloomFilter;
@ -361,8 +361,7 @@ pub enum StyleSharingResult<ConcreteRestyleDamage: TRestyleDamage> {
StyleWasShared(usize, ConcreteRestyleDamage),
}
trait PrivateMatchMethods: TNode
where <Self::ConcreteElement as Element>::Impl: SelectorImplExt {
trait PrivateMatchMethods: TNode {
/// Actually cascades style for a node or a pseudo-element of a node.
///
/// Note that animations only apply to nodes or ::before or ::after
@ -507,8 +506,7 @@ trait PrivateMatchMethods: TNode
}
}
impl<N: TNode> PrivateMatchMethods for N
where <N::ConcreteElement as Element>::Impl: SelectorImplExt {}
impl<N: TNode> PrivateMatchMethods for N {}
trait PrivateElementMatchMethods: TElement {
fn share_style_with_candidate_if_possible(&self,
@ -611,8 +609,7 @@ pub trait ElementMatchMethods : TElement {
}
}
impl<E: TElement> ElementMatchMethods for E
where E::Impl: SelectorImplExt {}
impl<E: TElement> ElementMatchMethods for E {}
pub trait MatchMethods : TNode {
// The below two functions are copy+paste because I can't figure out how to

View file

@ -5,9 +5,9 @@
//! Restyle hints: an optimization to avoid unnecessarily matching selectors.
use element_state::*;
use selector_impl::{ElementExt, SelectorImplExt, TheSelectorImpl, AttrString};
use selector_impl::{ElementExt, TheSelectorImpl, AttrString, NonTSPseudoClass};
use selectors::matching::matches_compound_selector;
use selectors::parser::{AttrSelector, Combinator, CompoundSelector, SelectorImpl, SimpleSelector};
use selectors::parser::{AttrSelector, Combinator, CompoundSelector, SimpleSelector};
use selectors::{Element, MatchAttr};
use std::clone::Clone;
use std::sync::Arc;
@ -177,13 +177,12 @@ impl<'a, E> MatchAttr for ElementWrapper<'a, E>
}
impl<'a, E> Element for ElementWrapper<'a, E>
where E: ElementExt<AttrString=AttrString>,
E::Impl: SelectorImplExt<AttrString=AttrString> {
type Impl = E::Impl;
where E: ElementExt<Impl=TheSelectorImpl, AttrString=AttrString>
{
type Impl = TheSelectorImpl;
fn match_non_ts_pseudo_class(&self,
pseudo_class: <Self::Impl as SelectorImpl>::NonTSPseudoClass) -> bool {
let flag = Self::Impl::pseudo_class_state_flag(&pseudo_class);
fn match_non_ts_pseudo_class(&self, pseudo_class: NonTSPseudoClass) -> bool {
let flag = TheSelectorImpl::pseudo_class_state_flag(&pseudo_class);
if flag == ElementState::empty() {
self.element.match_non_ts_pseudo_class(pseudo_class)
} else {

View file

@ -4,12 +4,9 @@
//! The pseudo-classes and pseudo-elements supported by the style system.
use element_state::ElementState;
use restyle_hints;
use selectors::Element;
use selectors::parser::SelectorImpl;
use std::fmt::Debug;
use stylesheets::Stylesheet;
pub type AttrString = <TheSelectorImpl as SelectorImpl>::AttrString;
@ -78,16 +75,9 @@ pub trait ElementExt: Element<Impl=TheSelectorImpl, AttrString=<TheSelectorImpl
fn is_link(&self) -> bool;
}
// NB: The `Clone` trait is here for convenience due to:
// https://github.com/rust-lang/rust/issues/26925
pub trait SelectorImplExt : SelectorImpl + Clone + Debug + Sized + 'static {
fn pseudo_element_cascade_type(pseudo: &Self::PseudoElement) -> PseudoElementCascadeType;
fn each_pseudo_element<F>(mut fun: F)
where F: FnMut(Self::PseudoElement);
impl TheSelectorImpl {
#[inline]
fn each_eagerly_cascaded_pseudo_element<F>(mut fun: F)
pub fn each_eagerly_cascaded_pseudo_element<F>(mut fun: F)
where F: FnMut(<Self as SelectorImpl>::PseudoElement) {
Self::each_pseudo_element(|pseudo| {
if Self::pseudo_element_cascade_type(&pseudo).is_eager() {
@ -97,7 +87,7 @@ pub trait SelectorImplExt : SelectorImpl + Clone + Debug + Sized + 'static {
}
#[inline]
fn each_precomputed_pseudo_element<F>(mut fun: F)
pub fn each_precomputed_pseudo_element<F>(mut fun: F)
where F: FnMut(<Self as SelectorImpl>::PseudoElement) {
Self::each_pseudo_element(|pseudo| {
if Self::pseudo_element_cascade_type(&pseudo).is_precomputed() {
@ -105,12 +95,4 @@ pub trait SelectorImplExt : SelectorImpl + Clone + Debug + Sized + 'static {
}
})
}
fn pseudo_is_before_or_after(pseudo: &Self::PseudoElement) -> bool;
fn pseudo_class_state_flag(pc: &Self::NonTSPseudoClass) -> ElementState;
fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet];
fn get_quirks_mode_stylesheet() -> Option<&'static Stylesheet>;
}

View file

@ -11,7 +11,7 @@ use keyframes::KeyframesAnimation;
use media_queries::{Device, MediaType};
use properties::{self, PropertyDeclaration, PropertyDeclarationBlock, ComputedValues};
use restyle_hints::{RestyleHint, DependencySet};
use selector_impl::{ElementExt, SelectorImplExt, TheSelectorImpl, PseudoElement, AttrString};
use selector_impl::{ElementExt, TheSelectorImpl, PseudoElement, AttrString};
use selectors::Element;
use selectors::bloom::BloomFilter;
use selectors::matching::DeclarationBlock as GenericDeclarationBlock;
@ -38,13 +38,6 @@ pub type DeclarationBlock = GenericDeclarationBlock<Vec<PropertyDeclaration>>;
///
/// This structure is effectively created once per pipeline, in the
/// LayoutThread corresponding to that pipeline.
///
/// The stylist is parameterized on `SelectorImplExt`, a trait that extends
/// `selectors::parser::SelectorImpl`, and that allows to customise what
/// pseudo-classes and pseudo-elements are parsed. This is actually either
/// `ServoSelectorImpl`, the implementation used by Servo's layout system in
/// regular builds, or `GeckoSelectorImpl`, the implementation used in the
/// geckolib port.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct Stylist {
/// Device that the stylist is currently evaluating against.

View file

@ -7,7 +7,7 @@ use element_state::ElementState;
use error_reporting::StdoutErrorReporter;
use parser::ParserContextExtraData;
use restyle_hints::ElementSnapshot;
use selector_impl::{SelectorImplExt, ElementExt, PseudoElementCascadeType, TheSelectorImpl};
use selector_impl::{ElementExt, PseudoElementCascadeType, TheSelectorImpl};
use selectors::parser::{AttrSelector, ParserContext, SelectorImpl};
use selectors::{Element, MatchAttrGeneric};
use std::process;
@ -158,14 +158,14 @@ impl SelectorImpl for ServoSelectorImpl {
}
}
impl SelectorImplExt for ServoSelectorImpl {
impl ServoSelectorImpl {
#[inline]
fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType {
pub fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType {
pseudo.cascade_type()
}
#[inline]
fn each_pseudo_element<F>(mut fun: F)
pub fn each_pseudo_element<F>(mut fun: F)
where F: FnMut(PseudoElement) {
fun(PseudoElement::Before);
fun(PseudoElement::After);
@ -175,22 +175,22 @@ impl SelectorImplExt for ServoSelectorImpl {
}
#[inline]
fn pseudo_class_state_flag(pc: &NonTSPseudoClass) -> ElementState {
pub fn pseudo_class_state_flag(pc: &NonTSPseudoClass) -> ElementState {
pc.state_flag()
}
#[inline]
fn pseudo_is_before_or_after(pseudo: &PseudoElement) -> bool {
pub fn pseudo_is_before_or_after(pseudo: &PseudoElement) -> bool {
pseudo.is_before_or_after()
}
#[inline]
fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet] {
pub fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet] {
&*USER_OR_USER_AGENT_STYLESHEETS
}
#[inline]
fn get_quirks_mode_stylesheet() -> Option<&'static Stylesheet> {
pub fn get_quirks_mode_stylesheet() -> Option<&'static Stylesheet> {
Some(&*QUIRKS_MODE_STYLESHEET)
}
}

View file

@ -8,8 +8,6 @@ use animation;
use context::{SharedStyleContext, StyleContext};
use dom::{OpaqueNode, TElement, TNode, TRestyleDamage, UnsafeNode};
use matching::{ApplicableDeclarations, ElementMatchMethods, MatchMethods, StyleSharingResult};
use selector_impl::SelectorImplExt;
use selectors::Element;
use selectors::bloom::BloomFilter;
use std::cell::RefCell;
use tid::tid;
@ -181,8 +179,7 @@ pub fn recalc_style_at<'a, N, C>(context: &'a C,
root: OpaqueNode,
node: N)
where N: TNode,
C: StyleContext<'a>,
<N::ConcreteElement as Element>::Impl: SelectorImplExt + 'a {
C: StyleContext<'a> {
// Get the parent node.
let parent_opt = match node.parent_node() {
Some(parent) if parent.is_element() => Some(parent),

View file

@ -31,7 +31,7 @@ use style::gecko_selector_impl::{GeckoSelectorImpl, PseudoElement};
use style::parallel;
use style::parser::ParserContextExtraData;
use style::properties::{ComputedValues, PropertyDeclarationBlock, parse_one_declaration};
use style::selector_impl::{SelectorImplExt, PseudoElementCascadeType};
use style::selector_impl::PseudoElementCascadeType;
use style::sequential;
use style::stylesheets::{Stylesheet, Origin};
use style::timer::Timer;