From f419db834c9554ebb3e8a1b4af359f9da2c1d409 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 20 Jul 2016 13:58:07 +0200 Subject: [PATCH] Replace the SelectorImplExt trait with inherent methods. --- components/style/attr.rs | 3 ++- components/style/dom.rs | 6 ++---- components/style/gecko_selector_impl.rs | 16 ++++++++-------- components/style/matching.rs | 11 ++++------- components/style/restyle_hints.rs | 15 +++++++-------- components/style/selector_impl.rs | 24 +++--------------------- components/style/selector_matching.rs | 9 +-------- components/style/servo_selector_impl.rs | 16 ++++++++-------- components/style/traversal.rs | 5 +---- ports/geckolib/glue.rs | 2 +- 10 files changed, 37 insertions(+), 70 deletions(-) diff --git a/components/style/attr.rs b/components/style/attr.rs index fc741d61575..b62e001a4e1 100644 --- a/components/style/attr.rs +++ b/components/style/attr.rs @@ -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; diff --git a/components/style/dom.rs b/components/style/dom.rs index 3406cf2815e..510f139b401 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -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> - where ::Impl: SelectorImplExt { + fn style(&self, _context: &SharedStyleContext) -> Ref> { Ref::map(self.borrow_data().unwrap(), |data| data.style.as_ref().unwrap()) } diff --git a/components/style/gecko_selector_impl.rs b/components/style/gecko_selector_impl.rs index 5798222cb07..bb763bb11de 100644 --- a/components/style/gecko_selector_impl.rs +++ b/components/style/gecko_selector_impl.rs @@ -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(mut fun: F) + pub fn each_pseudo_element(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 } } diff --git a/components/style/matching.rs b/components/style/matching.rs index f8a7c0dc160..42613bf8ef4 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -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 { StyleWasShared(usize, ConcreteRestyleDamage), } -trait PrivateMatchMethods: TNode - where ::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 PrivateMatchMethods for N - where ::Impl: SelectorImplExt {} +impl PrivateMatchMethods for N {} trait PrivateElementMatchMethods: TElement { fn share_style_with_candidate_if_possible(&self, @@ -611,8 +609,7 @@ pub trait ElementMatchMethods : TElement { } } -impl ElementMatchMethods for E - where E::Impl: SelectorImplExt {} +impl ElementMatchMethods for E {} pub trait MatchMethods : TNode { // The below two functions are copy+paste because I can't figure out how to diff --git a/components/style/restyle_hints.rs b/components/style/restyle_hints.rs index 619aa22724b..b6f08262fe7 100644 --- a/components/style/restyle_hints.rs +++ b/components/style/restyle_hints.rs @@ -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, - E::Impl: SelectorImplExt { - type Impl = E::Impl; + where E: ElementExt +{ + type Impl = TheSelectorImpl; - fn match_non_ts_pseudo_class(&self, - pseudo_class: ::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 { diff --git a/components/style/selector_impl.rs b/components/style/selector_impl.rs index 923fdb7a75a..cf846d61f15 100644 --- a/components/style/selector_impl.rs +++ b/components/style/selector_impl.rs @@ -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 = ::AttrString; @@ -78,16 +75,9 @@ pub trait ElementExt: Element 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(mut fun: F) - where F: FnMut(Self::PseudoElement); - +impl TheSelectorImpl { #[inline] - fn each_eagerly_cascaded_pseudo_element(mut fun: F) + pub fn each_eagerly_cascaded_pseudo_element(mut fun: F) where F: FnMut(::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(mut fun: F) + pub fn each_precomputed_pseudo_element(mut fun: F) where F: FnMut(::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>; } diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index 5451bae28bf..3ed48f6107a 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -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>; /// /// 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. diff --git a/components/style/servo_selector_impl.rs b/components/style/servo_selector_impl.rs index 5904cc3a478..eb0e539fce4 100644 --- a/components/style/servo_selector_impl.rs +++ b/components/style/servo_selector_impl.rs @@ -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(mut fun: F) + pub fn each_pseudo_element(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) } } diff --git a/components/style/traversal.rs b/components/style/traversal.rs index e56db456dbf..ded29719397 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -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>, - ::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), diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 98932fb8efc..b183656be81 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -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;