From 5c70dfab01ed434c609177d1b3be4a8936f641d6 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 19 Jul 2016 17:40:14 +0200 Subject: [PATCH] Have a concrete SelectorImpl type everywhere in the style crate. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is conditionally compiled to one implementation or the other (Gecko or Servo) with `#[cfg(…)]`. --- components/layout/context.rs | 3 +- components/style/animation.rs | 42 ++++---- components/style/context.rs | 9 +- components/style/data.rs | 9 +- components/style/dom.rs | 13 +-- components/style/gecko_selector_impl.rs | 10 +- components/style/lib.rs | 2 +- components/style/matching.rs | 42 ++++---- components/style/restyle_hints.rs | 73 ++++++++++---- components/style/selector_impl.rs | 8 +- components/style/selector_matching.rs | 83 ++++++++-------- components/style/servo.rs | 9 +- components/style/servo_selector_impl.rs | 12 +-- components/style/stylesheets.rs | 127 +++++++++++------------- components/style/traversal.rs | 22 ++-- ports/geckolib/context.rs | 4 +- 16 files changed, 236 insertions(+), 232 deletions(-) diff --git a/components/layout/context.rs b/components/layout/context.rs index 9fed4959310..b81dfe09455 100644 --- a/components/layout/context.rs +++ b/components/layout/context.rs @@ -25,7 +25,6 @@ use std::hash::BuildHasherDefault; use std::rc::Rc; use std::sync::{Arc, Mutex, RwLock}; use style::context::{LocalStyleContext, StyleContext}; -use style::selector_impl::ServoSelectorImpl; use style::servo::SharedStyleContext; use url::Url; use util::opts; @@ -103,7 +102,7 @@ pub struct LayoutContext<'a> { cached_local_layout_context: Rc, } -impl<'a> StyleContext<'a, ServoSelectorImpl> for LayoutContext<'a> { +impl<'a> StyleContext<'a> for LayoutContext<'a> { fn shared_context(&self) -> &'a SharedStyleContext { &self.shared.style_context } diff --git a/components/style/animation.rs b/components/style/animation.rs index 73bdab66e0e..c9529f7b99f 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -16,7 +16,6 @@ use properties::longhands::animation_play_state::computed_value::AnimationPlaySt use properties::longhands::transition_timing_function::computed_value::StartEnd; use properties::longhands::transition_timing_function::computed_value::TransitionTimingFunction; use properties::{self, ComputedValues}; -use selector_impl::SelectorImplExt; use selectors::matching::DeclarationBlock; use std::sync::Arc; use std::sync::mpsc::Sender; @@ -339,11 +338,11 @@ impl PropertyAnimation { // // TODO(emilio): Take rid of this mutex splitting SharedLayoutContex into a // cloneable part and a non-cloneable part.. -pub fn start_transitions_if_applicable(new_animations_sender: &Sender, - node: OpaqueNode, - old_style: &ComputedValues, - new_style: &mut Arc) - -> bool { +pub fn start_transitions_if_applicable(new_animations_sender: &Sender, + node: OpaqueNode, + old_style: &ComputedValues, + new_style: &mut Arc) + -> bool { let mut had_animations = false; for i in 0..new_style.get_box().transition_property_count() { // Create any property animations, if applicable. @@ -372,11 +371,11 @@ pub fn start_transitions_if_applicable(new_animations_sen had_animations } -fn compute_style_for_animation_step(context: &SharedStyleContext, - step: &KeyframesStep, - previous_style: &ComputedValues, - style_from_cascade: &ComputedValues) - -> ComputedValues { +fn compute_style_for_animation_step(context: &SharedStyleContext, + step: &KeyframesStep, + previous_style: &ComputedValues, + style_from_cascade: &ComputedValues) + -> ComputedValues { match step.value { // TODO: avoiding this spurious clone might involve having to create // an Arc in the below (more common case). @@ -398,11 +397,11 @@ fn compute_style_for_animation_step(context: &SharedStyle } } -pub fn maybe_start_animations(context: &SharedStyleContext, - new_animations_sender: &Sender, - node: OpaqueNode, - new_style: &Arc) -> bool -{ +pub fn maybe_start_animations(context: &SharedStyleContext, + new_animations_sender: &Sender, + node: OpaqueNode, + new_style: &Arc) + -> bool { let mut had_animations = false; let box_style = new_style.get_box(); @@ -488,12 +487,11 @@ pub fn update_style_for_animation_frame(mut new_style: &mut Arc, } /// Updates a single animation and associated style based on the current time. /// If `damage` is provided, inserts the appropriate restyle damage. -pub fn update_style_for_animation(context: &SharedStyleContext, - animation: &Animation, - style: &mut Arc, - damage: Option<&mut Damage>) -where Impl: SelectorImplExt, - Damage: TRestyleDamage { +pub fn update_style_for_animation(context: &SharedStyleContext, + animation: &Animation, + style: &mut Arc, + damage: Option<&mut Damage>) +where Damage: TRestyleDamage { debug!("update_style_for_animation: entering"); debug_assert!(!animation.is_expired()); match *animation { diff --git a/components/style/context.rs b/components/style/context.rs index cfdd0628ea9..3515728b4cf 100644 --- a/components/style/context.rs +++ b/components/style/context.rs @@ -10,7 +10,6 @@ use dom::OpaqueNode; use error_reporting::ParseErrorReporter; use euclid::Size2D; use matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache}; -use selector_impl::SelectorImplExt; use selector_matching::Stylist; use std::cell::RefCell; use std::collections::HashMap; @@ -30,7 +29,7 @@ impl LocalStyleContextCreationInfo { } } -pub struct SharedStyleContext { +pub struct SharedStyleContext { /// The current viewport size. pub viewport_size: Size2D, @@ -38,7 +37,7 @@ pub struct SharedStyleContext { pub screen_size_changed: bool, /// The CSS selector stylist. - pub stylist: Arc>, + pub stylist: Arc, /// Starts at zero, and increased by one every time a layout completes. /// This can be used to easily check for invalid stale data. @@ -78,8 +77,8 @@ impl LocalStyleContext { } } -pub trait StyleContext<'a, Impl: SelectorImplExt> { - fn shared_context(&self) -> &'a SharedStyleContext; +pub trait StyleContext<'a> { + fn shared_context(&self) -> &'a SharedStyleContext; fn local_context(&self) -> &LocalStyleContext; } diff --git a/components/style/data.rs b/components/style/data.rs index 82ad8bc6f44..906848998fb 100644 --- a/components/style/data.rs +++ b/components/style/data.rs @@ -5,26 +5,25 @@ //! Per-node data used in style calculation. use properties::ComputedValues; -use selectors::parser::SelectorImpl; +use selector_impl::PseudoElement; use std::collections::HashMap; use std::hash::BuildHasherDefault; use std::sync::Arc; use std::sync::atomic::AtomicIsize; -pub struct PrivateStyleData { +pub struct PrivateStyleData { /// The results of CSS styling for this node. pub style: Option>, /// The results of CSS styling for each pseudo-element (if any). - pub per_pseudo: HashMap, + pub per_pseudo: HashMap, BuildHasherDefault<::fnv::FnvHasher>>, /// Information needed during parallel traversals. pub parallel: DomParallelInfo, } -impl PrivateStyleData - where Impl: SelectorImpl { +impl PrivateStyleData { pub fn new() -> Self { PrivateStyleData { style: None, diff --git a/components/style/dom.rs b/components/style/dom.rs index 8c4c68a2b64..ee40e8a8c3c 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -144,18 +144,15 @@ pub trait TNode : Sized + Copy + Clone { /// Borrows the PrivateStyleData without checks. #[inline(always)] - unsafe fn borrow_data_unchecked(&self) - -> Option<*const PrivateStyleData<::Impl>>; + unsafe fn borrow_data_unchecked(&self) -> Option<*const PrivateStyleData>; /// Borrows the PrivateStyleData immutably. Fails on a conflicting borrow. #[inline(always)] - fn borrow_data(&self) - -> Option::Impl>>>; + fn borrow_data(&self) -> Option>; /// Borrows the PrivateStyleData mutably. Fails on a conflicting borrow. #[inline(always)] - fn mutate_data(&self) - -> Option::Impl>>>; + fn mutate_data(&self) -> Option>; /// Get the description of how to account for recent style changes. fn restyle_damage(self) -> Self::ConcreteRestyleDamage; @@ -176,9 +173,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<::Impl>) - -> Ref> + fn style(&self, _context: &SharedStyleContext) -> Ref> where ::Impl: SelectorImplExt { 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 8a6418fe767..df8ea06ea52 100644 --- a/components/style/gecko_selector_impl.rs +++ b/components/style/gecko_selector_impl.rs @@ -7,13 +7,13 @@ use selector_impl::{PseudoElementCascadeType, SelectorImplExt}; use selectors::parser::{ParserContext, SelectorImpl}; use string_cache::Atom; -pub type Stylist = ::selector_matching::Stylist; -pub type Stylesheet = ::stylesheets::Stylesheet; -pub type SharedStyleContext = ::context::SharedStyleContext; -pub type PrivateStyleData = ::data::PrivateStyleData; +pub type Stylist = ::selector_matching::Stylist; +pub type Stylesheet = ::stylesheets::Stylesheet; +pub type SharedStyleContext = ::context::SharedStyleContext; +pub type PrivateStyleData = ::data::PrivateStyleData; pub type Animation = ::animation::Animation; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct GeckoSelectorImpl; #[derive(Clone, Debug, PartialEq, Eq, Hash)] diff --git a/components/style/lib.rs b/components/style/lib.rs index 5a3395f9d36..88144ec9dda 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -97,7 +97,7 @@ pub mod selector_impl; pub mod selector_matching; pub mod sequential; pub mod servo; -pub mod servo_selector_impl; +#[cfg(feature = "servo")] pub mod servo_selector_impl; pub mod sink; pub mod str; pub mod stylesheets; diff --git a/components/style/matching.rs b/components/style/matching.rs index 350e5921873..42320d2ecdd 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}; +use selector_impl::{ElementExt, SelectorImplExt, TheSelectorImpl, PseudoElement}; use selector_matching::{DeclarationBlock, Stylist}; use selectors::Element; use selectors::bloom::BloomFilter; @@ -48,9 +48,9 @@ fn create_common_style_affecting_attributes_from_element(element: & flags } -pub struct ApplicableDeclarations { +pub struct ApplicableDeclarations { pub normal: SmallVec<[DeclarationBlock; 16]>, - pub per_pseudo: HashMap, BuildHasherDefault<::fnv::FnvHasher>>, @@ -58,15 +58,15 @@ pub struct ApplicableDeclarations { pub normal_shareable: bool, } -impl ApplicableDeclarations { - pub fn new() -> ApplicableDeclarations { +impl ApplicableDeclarations { + pub fn new() -> Self { let mut applicable_declarations = ApplicableDeclarations { normal: SmallVec::new(), per_pseudo: HashMap::with_hasher(Default::default()), normal_shareable: false, }; - Impl::each_eagerly_cascaded_pseudo_element(|pseudo| { + TheSelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| { applicable_declarations.per_pseudo.insert(pseudo, vec![]); }); @@ -377,7 +377,7 @@ trait PrivateMatchMethods: TNode shareable: bool, animate_properties: bool) -> (Self::ConcreteRestyleDamage, Arc) - where Ctx: StyleContext<'a, ::Impl> { + where Ctx: StyleContext<'a> { let mut cacheable = true; let shared_context = context.shared_context(); if animate_properties { @@ -421,7 +421,7 @@ trait PrivateMatchMethods: TNode let new_animations_sender = &context.local_context().new_animations_sender; let this_opaque = self.opaque(); // Trigger any present animations if necessary. - let mut animations_started = animation::maybe_start_animations::<::Impl>( + let mut animations_started = animation::maybe_start_animations( &shared_context, new_animations_sender, this_opaque, @@ -431,7 +431,7 @@ trait PrivateMatchMethods: TNode // to its old value if it did trigger a transition. if let Some(ref style) = style { animations_started |= - animation::start_transitions_if_applicable::<::Impl>( + animation::start_transitions_if_applicable( new_animations_sender, this_opaque, &**style, @@ -455,7 +455,7 @@ trait PrivateMatchMethods: TNode } fn update_animations_for_cascade(&self, - context: &SharedStyleContext<::Impl>, + context: &SharedStyleContext, style: &mut Option<&mut Arc>) -> bool { let style = match *style { @@ -506,8 +506,8 @@ trait PrivateMatchMethods: TNode // See #12171 and the associated PR for an example where this // happened while debugging other release panic. if !running_animation.is_expired() { - animation::update_style_for_animation::::Impl>(context, running_animation, style, None); + animation::update_style_for_animation::( + context, running_animation, style, None); running_animation.mark_as_expired(); } } @@ -530,7 +530,7 @@ trait PrivateElementMatchMethods: TElement { Some(_) | None => return None, }; - let parent_data: Option<&PrivateStyleData<_>> = unsafe { + let parent_data: Option<&PrivateStyleData> = unsafe { parent_node.borrow_data_unchecked().map(|d| &*d) }; @@ -552,12 +552,11 @@ trait PrivateElementMatchMethods: TElement { impl PrivateElementMatchMethods for E {} -pub trait ElementMatchMethods : TElement - where Self::Impl: SelectorImplExt { +pub trait ElementMatchMethods : TElement { fn match_element(&self, - stylist: &Stylist, + stylist: &Stylist, parent_bf: Option<&BloomFilter>, - applicable_declarations: &mut ApplicableDeclarations) + applicable_declarations: &mut ApplicableDeclarations) -> bool { let style_attribute = self.style_attribute().as_ref(); @@ -567,7 +566,7 @@ pub trait ElementMatchMethods : TElement style_attribute, None, &mut applicable_declarations.normal); - Self::Impl::each_eagerly_cascaded_pseudo_element(|pseudo| { + TheSelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| { stylist.push_applicable_declarations(self, parent_bf, None, @@ -669,11 +668,8 @@ pub trait MatchMethods : TNode { unsafe fn cascade_node<'a, Ctx>(&self, context: &Ctx, parent: Option, - applicable_declarations: - &ApplicableDeclarations<::Impl>) - where ::Impl: SelectorImplExt, - Ctx: StyleContext<'a, ::Impl> - { + applicable_declarations: &ApplicableDeclarations) + where Ctx: StyleContext<'a> { // Get our parent's style. This must be unsafe so that we don't touch the parent's // borrow flags. // diff --git a/components/style/restyle_hints.rs b/components/style/restyle_hints.rs index cd9957322e4..3af92457d6b 100644 --- a/components/style/restyle_hints.rs +++ b/components/style/restyle_hints.rs @@ -6,10 +6,11 @@ use attr::{AttrIdentifier, AttrValue}; use element_state::*; -use selector_impl::SelectorImplExt; +use selector_impl::{SelectorImplExt, TheSelectorImpl, AttrString}; use selectors::matching::matches_compound_selector; use selectors::parser::{AttrSelector, Combinator, CompoundSelector, SelectorImpl, SimpleSelector}; use selectors::{Element, MatchAttrGeneric}; +#[cfg(feature = "gecko")] use selectors::MatchAttr; use std::clone::Clone; use std::sync::Arc; use string_cache::{Atom, BorrowedAtom, BorrowedNamespace, Namespace}; @@ -88,14 +89,14 @@ static EMPTY_SNAPSHOT: ElementSnapshot = ElementSnapshot { state: None, attrs: N // geckolib, but in the mean time we can just use the trait parameters to // specialize it to the Servo configuration. struct ElementWrapper<'a, E> - where E: Element, + where E: Element, E::Impl: SelectorImplExt { element: E, snapshot: &'a ElementSnapshot, } impl<'a, E> ElementWrapper<'a, E> - where E: Element, + where E: Element, E::Impl: SelectorImplExt { pub fn new(el: E) -> ElementWrapper<'a, E> { ElementWrapper { element: el, snapshot: &EMPTY_SNAPSHOT } @@ -108,7 +109,7 @@ impl<'a, E> ElementWrapper<'a, E> #[cfg(not(feature = "gecko"))] impl<'a, E> MatchAttrGeneric for ElementWrapper<'a, E> - where E: Element, + where E: Element, E: MatchAttrGeneric, E::Impl: SelectorImplExt { fn match_attr(&self, attr: &AttrSelector, test: F) -> bool @@ -129,18 +130,46 @@ impl<'a, E> MatchAttrGeneric for ElementWrapper<'a, E> } #[cfg(feature = "gecko")] -impl<'a, E> MatchAttrGeneric for ElementWrapper<'a, E> - where E: Element, - E: MatchAttrGeneric, +impl<'a, E> MatchAttr for ElementWrapper<'a, E> + where E: Element, E::Impl: SelectorImplExt { - fn match_attr(&self, _: &AttrSelector, _: F) -> bool - where F: Fn(&str) -> bool { + type AttrString = AttrString; + + fn match_attr_has(&self, _attr: &AttrSelector) -> bool { + panic!("Not implemented for Gecko - this system will need to be redesigned"); + } + + fn match_attr_equals(&self, _attr: &AttrSelector, _value: &Self::AttrString) -> bool { + panic!("Not implemented for Gecko - this system will need to be redesigned"); + } + + fn match_attr_equals_ignore_ascii_case(&self, _attr: &AttrSelector, _value: &Self::AttrString) -> bool { + panic!("Not implemented for Gecko - this system will need to be redesigned"); + } + + fn match_attr_includes(&self, _attr: &AttrSelector, _value: &Self::AttrString) -> bool { + panic!("Not implemented for Gecko - this system will need to be redesigned"); + } + + fn match_attr_dash(&self, _attr: &AttrSelector, _value: &Self::AttrString) -> bool { + panic!("Not implemented for Gecko - this system will need to be redesigned"); + } + + fn match_attr_prefix(&self, _attr: &AttrSelector, _value: &Self::AttrString) -> bool { + panic!("Not implemented for Gecko - this system will need to be redesigned"); + } + + fn match_attr_substring(&self, _attr: &AttrSelector, _value: &Self::AttrString) -> bool { + panic!("Not implemented for Gecko - this system will need to be redesigned"); + } + + fn match_attr_suffix(&self, _attr: &AttrSelector, _value: &Self::AttrString) -> bool { panic!("Not implemented for Gecko - this system will need to be redesigned"); } } impl<'a, E> Element for ElementWrapper<'a, E> - where E: Element, + where E: Element, E: MatchAttrGeneric, E::Impl: SelectorImplExt { type Impl = E::Impl; @@ -213,14 +242,14 @@ impl<'a, E> Element for ElementWrapper<'a, E> } } -fn selector_to_state(sel: &SimpleSelector) -> ElementState { +fn selector_to_state(sel: &SimpleSelector) -> ElementState { match *sel { - SimpleSelector::NonTSPseudoClass(ref pc) => Impl::pseudo_class_state_flag(pc), + SimpleSelector::NonTSPseudoClass(ref pc) => TheSelectorImpl::pseudo_class_state_flag(pc), _ => ElementState::empty(), } } -fn is_attr_selector(sel: &SimpleSelector) -> bool { +fn is_attr_selector(sel: &SimpleSelector) -> bool { match *sel { SimpleSelector::ID(_) | SimpleSelector::Class(_) | @@ -287,24 +316,24 @@ impl Sensitivities { // elements in the document. #[derive(Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -struct Dependency { - selector: Arc>, +struct Dependency { + selector: Arc>, combinator: Option, sensitivities: Sensitivities, } #[derive(Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -pub struct DependencySet { - deps: Vec>, +pub struct DependencySet { + deps: Vec, } -impl DependencySet { - pub fn new() -> DependencySet { +impl DependencySet { + pub fn new() -> Self { DependencySet { deps: Vec::new() } } - pub fn note_selector(&mut self, selector: Arc>) { + pub fn note_selector(&mut self, selector: Arc>) { let mut cur = selector; let mut combinator: Option = None; loop { @@ -338,10 +367,10 @@ impl DependencySet { } } -impl> DependencySet { +impl DependencySet { pub fn compute_hint(&self, el: &E, snapshot: &ElementSnapshot, current_state: ElementState) -> RestyleHint - where E: Element + Clone + MatchAttrGeneric { + where E: Element + Clone + MatchAttrGeneric { 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(); diff --git a/components/style/selector_impl.rs b/components/style/selector_impl.rs index 4148a3a9328..a95499092cf 100644 --- a/components/style/selector_impl.rs +++ b/components/style/selector_impl.rs @@ -10,6 +10,8 @@ use selectors::parser::SelectorImpl; use std::fmt::Debug; use stylesheets::Stylesheet; +pub type AttrString = ::AttrString; + #[cfg(feature = "servo")] pub use servo_selector_impl::ServoSelectorImpl; @@ -66,7 +68,7 @@ impl PseudoElementCascadeType { } } -pub trait ElementExt: Element { +pub trait ElementExt: Element::AttrString> { fn is_link(&self) -> bool; } @@ -102,7 +104,7 @@ pub trait SelectorImplExt : SelectorImpl + Clone + Debug + Sized + 'static { fn pseudo_class_state_flag(pc: &Self::NonTSPseudoClass) -> ElementState; - fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet]; + fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet]; - fn get_quirks_mode_stylesheet() -> Option<&'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 a07685b9dd4..1e87ade3f5f 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -11,11 +11,10 @@ use keyframes::KeyframesAnimation; use media_queries::{Device, MediaType}; use properties::{self, PropertyDeclaration, PropertyDeclarationBlock, ComputedValues}; use restyle_hints::{ElementSnapshot, RestyleHint, DependencySet}; -use selector_impl::SelectorImplExt; +use selector_impl::{SelectorImplExt, TheSelectorImpl, PseudoElement, AttrString}; use selectors::bloom::BloomFilter; use selectors::matching::DeclarationBlock as GenericDeclarationBlock; use selectors::matching::{Rule, SelectorMap}; -use selectors::parser::SelectorImpl; use selectors::{Element, MatchAttrGeneric}; use sink::Push; use smallvec::VecLike; @@ -47,7 +46,7 @@ pub type DeclarationBlock = GenericDeclarationBlock>; /// regular builds, or `GeckoSelectorImpl`, the implementation used in the /// geckolib port. #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -pub struct Stylist { +pub struct Stylist { /// Device that the stylist is currently evaluating against. pub device: Device, @@ -62,12 +61,12 @@ pub struct Stylist { /// The current selector maps, after evaluating media /// rules against the current device. - element_map: PerPseudoElementSelectorMap, + element_map: PerPseudoElementSelectorMap, /// The selector maps corresponding to a given pseudo-element /// (depending on the implementation) - pseudos_map: HashMap, + pseudos_map: HashMap>, /// A map with all the animations indexed by name. @@ -76,19 +75,19 @@ pub struct Stylist { /// Applicable declarations for a given non-eagerly cascaded pseudo-element. /// These are eagerly computed once, and then used to resolve the new /// computed values on the fly on layout. - precomputed_pseudo_element_decls: HashMap, BuildHasherDefault<::fnv::FnvHasher>>, rules_source_order: usize, /// Selector dependencies used to compute restyle hints. - state_deps: DependencySet, + state_deps: DependencySet, } -impl Stylist { +impl Stylist { #[inline] - pub fn new(device: Device) -> Stylist { + pub fn new(device: Device) -> Self { let mut stylist = Stylist { viewport_constraints: None, device: device, @@ -103,7 +102,7 @@ impl Stylist { state_deps: DependencySet::new(), }; - Impl::each_eagerly_cascaded_pseudo_element(|pseudo| { + TheSelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| { stylist.pseudos_map.insert(pseudo, PerPseudoElementSelectorMap::new()); }); @@ -112,9 +111,7 @@ impl Stylist { stylist } - pub fn update(&mut self, doc_stylesheets: &[Arc>], - stylesheets_changed: bool) -> bool - where Impl: 'static { + pub fn update(&mut self, doc_stylesheets: &[Arc], stylesheets_changed: bool) -> bool { if !(self.is_device_dirty || stylesheets_changed) { return false; } @@ -122,7 +119,7 @@ impl Stylist { self.element_map = PerPseudoElementSelectorMap::new(); self.pseudos_map = HashMap::with_hasher(Default::default()); self.animations = HashMap::with_hasher(Default::default()); - Impl::each_eagerly_cascaded_pseudo_element(|pseudo| { + TheSelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| { self.pseudos_map.insert(pseudo, PerPseudoElementSelectorMap::new()); }); @@ -130,12 +127,12 @@ impl Stylist { self.rules_source_order = 0; self.state_deps.clear(); - for ref stylesheet in Impl::get_user_or_user_agent_stylesheets().iter() { + for ref stylesheet in TheSelectorImpl::get_user_or_user_agent_stylesheets().iter() { self.add_stylesheet(&stylesheet); } if self.quirks_mode { - if let Some(s) = Impl::get_quirks_mode_stylesheet() { + if let Some(s) = TheSelectorImpl::get_quirks_mode_stylesheet() { self.add_stylesheet(s); } } @@ -148,7 +145,7 @@ impl Stylist { true } - fn add_stylesheet(&mut self, stylesheet: &Stylesheet) { + fn add_stylesheet(&mut self, stylesheet: &Stylesheet) { if !stylesheet.is_effective_for_device(&self.device) { return; } @@ -212,7 +209,7 @@ impl Stylist { } } - Impl::each_precomputed_pseudo_element(|pseudo| { + TheSelectorImpl::each_precomputed_pseudo_element(|pseudo| { // TODO: Consider not doing this and just getting the rules on the // fly. It should be a bit slower, but we'd take rid of the // extra field, and avoid this precomputation entirely. @@ -230,10 +227,10 @@ impl Stylist { /// Computes the style for a given "precomputed" pseudo-element, taking the /// universal rules and applying them. pub fn precomputed_values_for_pseudo(&self, - pseudo: &Impl::PseudoElement, + pseudo: &PseudoElement, parent: Option<&Arc>) -> Option> { - debug_assert!(Impl::pseudo_element_cascade_type(pseudo).is_precomputed()); + debug_assert!(TheSelectorImpl::pseudo_element_cascade_type(pseudo).is_precomputed()); if let Some(declarations) = self.precomputed_pseudo_element_decls.get(pseudo) { let (computed, _) = properties::cascade(self.device.au_viewport_size(), @@ -249,12 +246,12 @@ impl Stylist { pub fn lazily_compute_pseudo_element_style(&self, element: &E, - pseudo: &Impl::PseudoElement, + pseudo: &PseudoElement, parent: &Arc) -> Option> - where E: Element + + where E: Element + PresentationalHintsSynthetizer { - debug_assert!(Impl::pseudo_element_cascade_type(pseudo).is_lazy()); + debug_assert!(TheSelectorImpl::pseudo_element_cascade_type(pseudo).is_lazy()); if self.pseudos_map.get(pseudo).is_none() { return None; } @@ -277,7 +274,7 @@ impl Stylist { Some(Arc::new(computed)) } - pub fn set_device(&mut self, mut device: Device, stylesheets: &[Arc>]) { + pub fn set_device(&mut self, mut device: Device, stylesheets: &[Arc]) { let cascaded_rule = stylesheets.iter() .flat_map(|s| s.effective_rules(&self.device).viewport()) .cascade(); @@ -315,17 +312,18 @@ impl Stylist { element: &E, parent_bf: Option<&BloomFilter>, style_attribute: Option<&PropertyDeclarationBlock>, - pseudo_element: Option<&Impl::PseudoElement>, + pseudo_element: Option<&PseudoElement>, applicable_declarations: &mut V) -> bool - where E: Element + + where E: Element + PresentationalHintsSynthetizer, V: Push + VecLike { assert!(!self.is_device_dirty); assert!(style_attribute.is_none() || pseudo_element.is_none(), "Style attributes do not apply to pseudo-elements"); debug_assert!(pseudo_element.is_none() || - !Impl::pseudo_element_cascade_type(pseudo_element.as_ref().unwrap()).is_precomputed()); + !TheSelectorImpl::pseudo_element_cascade_type(pseudo_element.as_ref().unwrap()) + .is_precomputed()); let map = match pseudo_element { Some(ref pseudo) => self.pseudos_map.get(pseudo).unwrap(), @@ -402,9 +400,7 @@ impl Stylist { pub fn animations(&self) -> &HashMap { &self.animations } -} -impl> Stylist { pub fn compute_restyle_hint(&self, element: &E, snapshot: &ElementSnapshot, // NB: We need to pass current_state as an argument because @@ -413,7 +409,8 @@ impl> Stylist { // more expensive than getting it directly from the caller. current_state: ElementState) -> RestyleHint - where E: Element + Clone + MatchAttrGeneric { + where E: Element + + Clone + MatchAttrGeneric { self.state_deps.compute_hint(element, snapshot, current_state) } } @@ -421,18 +418,18 @@ impl> Stylist { /// Map that contains the CSS rules for a given origin. #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -struct PerOriginSelectorMap { +struct PerOriginSelectorMap { /// Rules that contains at least one property declararion with /// normal importance. - normal: SelectorMap, Impl>, + normal: SelectorMap, TheSelectorImpl>, /// Rules that contains at least one property declararion with /// !important. - important: SelectorMap, Impl>, + important: SelectorMap, TheSelectorImpl>, } -impl PerOriginSelectorMap { +impl PerOriginSelectorMap { #[inline] - fn new() -> PerOriginSelectorMap { + fn new() -> Self { PerOriginSelectorMap { normal: SelectorMap::new(), important: SelectorMap::new(), @@ -443,18 +440,18 @@ impl PerOriginSelectorMap { /// Map that contains the CSS rules for a specific PseudoElement /// (or lack of PseudoElement). #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -struct PerPseudoElementSelectorMap { +struct PerPseudoElementSelectorMap { /// Rules from user agent stylesheets - user_agent: PerOriginSelectorMap, + user_agent: PerOriginSelectorMap, /// Rules from author stylesheets - author: PerOriginSelectorMap, + author: PerOriginSelectorMap, /// Rules from user stylesheets - user: PerOriginSelectorMap, + user: PerOriginSelectorMap, } -impl PerPseudoElementSelectorMap { +impl PerPseudoElementSelectorMap { #[inline] - fn new() -> PerPseudoElementSelectorMap { + fn new() -> Self { PerPseudoElementSelectorMap { user_agent: PerOriginSelectorMap::new(), author: PerOriginSelectorMap::new(), @@ -463,7 +460,7 @@ impl PerPseudoElementSelectorMap { } #[inline] - fn borrow_for_origin(&mut self, origin: &Origin) -> &mut PerOriginSelectorMap { + fn borrow_for_origin(&mut self, origin: &Origin) -> &mut PerOriginSelectorMap { match *origin { Origin::UserAgent => &mut self.user_agent, Origin::Author => &mut self.author, diff --git a/components/style/servo.rs b/components/style/servo.rs index dd75275de70..b427d85db04 100644 --- a/components/style/servo.rs +++ b/components/style/servo.rs @@ -7,12 +7,11 @@ use animation; use context; use data; use selector_matching; -use servo_selector_impl::ServoSelectorImpl; use stylesheets; -pub type Stylesheet = stylesheets::Stylesheet; -pub type PrivateStyleData = data::PrivateStyleData; -pub type Stylist = selector_matching::Stylist; -pub type SharedStyleContext = context::SharedStyleContext; +pub type Stylesheet = stylesheets::Stylesheet; +pub type PrivateStyleData = data::PrivateStyleData; +pub type Stylist = selector_matching::Stylist; +pub type SharedStyleContext = context::SharedStyleContext; pub type LocalStyleContextCreationInfo = context::LocalStyleContextCreationInfo; pub type Animation = animation::Animation; diff --git a/components/style/servo_selector_impl.rs b/components/style/servo_selector_impl.rs index 6c7370e1455..d1fdaf0336c 100644 --- a/components/style/servo_selector_impl.rs +++ b/components/style/servo_selector_impl.rs @@ -5,7 +5,7 @@ use element_state::ElementState; use error_reporting::StdoutErrorReporter; use parser::ParserContextExtraData; -use selector_impl::{SelectorImplExt, ElementExt, PseudoElementCascadeType}; +use selector_impl::{SelectorImplExt, ElementExt, PseudoElementCascadeType, TheSelectorImpl}; use selectors::Element; use selectors::parser::{ParserContext, SelectorImpl}; use std::process; @@ -179,24 +179,24 @@ impl SelectorImplExt for ServoSelectorImpl { } #[inline] - fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet] { + fn get_user_or_user_agent_stylesheets() -> &'static [Stylesheet] { &*USER_OR_USER_AGENT_STYLESHEETS } #[inline] - fn get_quirks_mode_stylesheet() -> Option<&'static Stylesheet> { + fn get_quirks_mode_stylesheet() -> Option<&'static Stylesheet> { Some(&*QUIRKS_MODE_STYLESHEET) } } -impl> ElementExt for E { +impl> ElementExt for E { fn is_link(&self) -> bool { self.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink) } } lazy_static! { - pub static ref USER_OR_USER_AGENT_STYLESHEETS: Vec> = { + pub static ref USER_OR_USER_AGENT_STYLESHEETS: Vec = { let mut stylesheets = vec!(); // FIXME: presentational-hints.css should be at author origin with zero specificity. // (Does it make a difference?) @@ -229,7 +229,7 @@ lazy_static! { } lazy_static! { - pub static ref QUIRKS_MODE_STYLESHEET: Stylesheet = { + pub static ref QUIRKS_MODE_STYLESHEET: Stylesheet = { match read_resource_file("quirks-mode.css") { Ok(res) => { Stylesheet::from_bytes( diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index d371bf4144f..64751c35c82 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -13,11 +13,11 @@ use keyframes::{Keyframe, parse_keyframe_list}; use media_queries::{Device, MediaQueryList, parse_media_query_list}; use parser::{ParserContext, ParserContextExtraData, log_css_error}; use properties::{PropertyDeclarationBlock, parse_property_declaration_list}; -use selectors::parser::{Selector, SelectorImpl, parse_selector_list}; +use selector_impl::TheSelectorImpl; +use selectors::parser::{Selector, parse_selector_list}; use smallvec::SmallVec; use std::cell::Cell; use std::iter::Iterator; -use std::marker::PhantomData; use std::slice; use string_cache::{Atom, Namespace}; use url::Url; @@ -43,10 +43,10 @@ pub enum Origin { #[derive(Debug, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -pub struct Stylesheet { +pub struct Stylesheet { /// List of rules in the order they were found (important for /// cascading order) - pub rules: Vec>, + pub rules: Vec, /// List of media associated with the Stylesheet, if any. pub media: Option, pub origin: Origin, @@ -56,11 +56,11 @@ pub struct Stylesheet { #[derive(Debug, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -pub enum CSSRule { +pub enum CSSRule { Charset(String), Namespace(Option, Namespace), - Style(StyleRule), - Media(MediaRule), + Style(StyleRule), + Media(MediaRule), FontFace(FontFaceRule), Viewport(ViewportRule), Keyframes(KeyframesRule), @@ -76,13 +76,13 @@ pub struct KeyframesRule { #[derive(Debug, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -pub struct MediaRule { +pub struct MediaRule { pub media_queries: MediaQueryList, - pub rules: Vec>, + pub rules: Vec, } -impl MediaRule { +impl MediaRule { #[inline] pub fn evaluate(&self, device: &Device) -> bool { self.media_queries.evaluate(device) @@ -91,18 +91,18 @@ impl MediaRule { #[derive(Debug, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -pub struct StyleRule { - pub selectors: Vec>, +pub struct StyleRule { + pub selectors: Vec>, pub declarations: PropertyDeclarationBlock, } -impl Stylesheet { +impl Stylesheet { pub fn from_bytes_iter>>( input: I, base_url: Url, protocol_encoding_label: Option<&str>, environment_encoding: Option, origin: Origin, error_reporter: Box, - extra_data: ParserContextExtraData) -> Stylesheet { + extra_data: ParserContextExtraData) -> Stylesheet { let mut bytes = vec![]; // TODO: incremental decoding and tokenization/parsing for chunk in input { @@ -119,7 +119,7 @@ impl Stylesheet { environment_encoding: Option, origin: Origin, error_reporter: Box, extra_data: ParserContextExtraData) - -> Stylesheet { + -> Stylesheet { // TODO: bytes.as_slice could be bytes.container_as_bytes() let (string, _) = decode_stylesheet_bytes( bytes, protocol_encoding_label, environment_encoding); @@ -128,12 +128,11 @@ impl Stylesheet { pub fn from_str(css: &str, base_url: Url, origin: Origin, error_reporter: Box, - extra_data: ParserContextExtraData) -> Stylesheet { + extra_data: ParserContextExtraData) -> Stylesheet { let rule_parser = TopLevelRuleParser { context: ParserContext::new_with_extra_data(origin, &base_url, error_reporter.clone(), extra_data), state: Cell::new(State::Start), - _impl: PhantomData, }; let mut input = Parser::new(css); input.look_for_viewport_percentages(); @@ -189,7 +188,7 @@ impl Stylesheet { /// Return an iterator over all the rules within the style-sheet. #[inline] - pub fn rules(&self) -> Rules { + pub fn rules(&self) -> Rules { Rules::new(self.rules.iter(), None) } @@ -200,7 +199,7 @@ impl Stylesheet { /// nested rules will be skipped. Use `rules` if all rules need to be /// examined. #[inline] - pub fn effective_rules<'a>(&'a self, device: &'a Device) -> Rules<'a, Impl> { + pub fn effective_rules<'a>(&'a self, device: &'a Device) -> Rules<'a> { Rules::new(self.rules.iter(), Some(device)) } } @@ -209,25 +208,25 @@ impl Stylesheet { /// /// The iteration order is pre-order. Specifically, this implies that a /// conditional group rule will come before its nested rules. -pub struct Rules<'a, Impl: SelectorImpl + 'a> { +pub struct Rules<'a> { // 2 because normal case is likely to be just one level of nesting (@media) - stack: SmallVec<[slice::Iter<'a, CSSRule>; 2]>, + stack: SmallVec<[slice::Iter<'a, CSSRule>; 2]>, device: Option<&'a Device> } -impl<'a, Impl: SelectorImpl + 'a> Rules<'a, Impl> { - fn new(iter: slice::Iter<'a, CSSRule>, device: Option<&'a Device>) -> Rules<'a, Impl> { - let mut stack: SmallVec<[slice::Iter<'a, CSSRule>; 2]> = SmallVec::new(); +impl<'a> Rules<'a> { + fn new(iter: slice::Iter<'a, CSSRule>, device: Option<&'a Device>) -> Rules<'a> { + let mut stack: SmallVec<[slice::Iter<'a, CSSRule>; 2]> = SmallVec::new(); stack.push(iter); Rules { stack: stack, device: device } } } -impl<'a, Impl: SelectorImpl + 'a> Iterator for Rules<'a, Impl> { - type Item = &'a CSSRule; +impl<'a> Iterator for Rules<'a> { + type Item = &'a CSSRule; - fn next(&mut self) -> Option<&'a CSSRule> { + fn next(&mut self) -> Option<&'a CSSRule> { while !self.stack.is_empty() { let top = self.stack.len() - 1; while let Some(rule) = self.stack[top].next() { @@ -262,7 +261,6 @@ impl<'a, Impl: SelectorImpl + 'a> Iterator for Rules<'a, Impl> { pub mod rule_filter { //! Specific `CSSRule` variant iterators. - use selectors::parser::SelectorImpl; use std::marker::PhantomData; use super::super::font_face::FontFaceRule; use super::super::viewport::ViewportRule; @@ -277,8 +275,8 @@ pub mod rule_filter { _lifetime: PhantomData<&'a ()> } - impl<'a, I, Impl: SelectorImpl + 'a> $variant<'a, I> - where I: Iterator> { + impl<'a, I> $variant<'a, I> + where I: Iterator { #[inline] pub fn new(iter: I) -> $variant<'a, I> { $variant { @@ -288,8 +286,8 @@ pub mod rule_filter { } } - impl<'a, I, Impl: SelectorImpl + 'a> Iterator for $variant<'a, I> - where I: Iterator> { + impl<'a, I> Iterator for $variant<'a, I> + where I: Iterator { type Item = &'a $value; fn next(&mut self) -> Option<&'a $value> { @@ -310,15 +308,15 @@ pub mod rule_filter { } } - rule_filter!(Media -> MediaRule); - rule_filter!(Style -> StyleRule); + rule_filter!(Media -> MediaRule); + rule_filter!(Style -> StyleRule); rule_filter!(FontFace -> FontFaceRule); rule_filter!(Viewport -> ViewportRule); rule_filter!(Keyframes -> KeyframesRule); } /// Extension methods for `CSSRule` iterators. -pub trait CSSRuleIteratorExt<'a, Impl: SelectorImpl + 'a>: Iterator> + Sized { +pub trait CSSRuleIteratorExt<'a>: Iterator + Sized { /// Yield only @font-face rules. fn font_face(self) -> rule_filter::FontFace<'a, Self>; @@ -335,7 +333,7 @@ pub trait CSSRuleIteratorExt<'a, Impl: SelectorImpl + 'a>: Iterator rule_filter::Keyframes<'a, Self>; } -impl<'a, I, Impl: SelectorImpl + 'a> CSSRuleIteratorExt<'a, Impl> for I where I: Iterator> { +impl<'a, I> CSSRuleIteratorExt<'a> for I where I: Iterator { #[inline] fn font_face(self) -> rule_filter::FontFace<'a, I> { rule_filter::FontFace::new(self) @@ -362,12 +360,9 @@ impl<'a, I, Impl: SelectorImpl + 'a> CSSRuleIteratorExt<'a, Impl> for I where I: } } -fn parse_nested_rules(context: &ParserContext, input: &mut Parser) -> Vec> { +fn parse_nested_rules(context: &ParserContext, input: &mut Parser) -> Vec { let mut iter = RuleListParser::new_for_nested_rule(input, - NestedRuleParser { - context: context, - _impl: PhantomData - }); + NestedRuleParser { context: context }); let mut rules = Vec::new(); while let Some(result) = iter.next() { match result { @@ -383,10 +378,9 @@ fn parse_nested_rules(context: &ParserContext, input: &mut P } -struct TopLevelRuleParser<'a, Impl: SelectorImpl> { +struct TopLevelRuleParser<'a> { context: ParserContext<'a>, state: Cell, - _impl: PhantomData } #[derive(Eq, PartialEq, Ord, PartialOrd, Copy, Clone)] @@ -410,12 +404,12 @@ enum AtRulePrelude { } -impl<'a, Impl: SelectorImpl> AtRuleParser for TopLevelRuleParser<'a, Impl> { +impl<'a> AtRuleParser for TopLevelRuleParser<'a> { type Prelude = AtRulePrelude; - type AtRule = CSSRule; + type AtRule = CSSRule; fn parse_prelude(&self, name: &str, input: &mut Parser) - -> Result>, ()> { + -> Result, ()> { match_ignore_ascii_case! { name, "charset" => { if self.state.get() <= State::Start { @@ -451,46 +445,45 @@ impl<'a, Impl: SelectorImpl> AtRuleParser for TopLevelRuleParser<'a, Impl> { } self.state.set(State::Body); - AtRuleParser::parse_prelude(&NestedRuleParser { context: &self.context, _impl: PhantomData }, name, input) + AtRuleParser::parse_prelude(&NestedRuleParser { context: &self.context }, name, input) } #[inline] - fn parse_block(&self, prelude: AtRulePrelude, input: &mut Parser) -> Result, ()> { - AtRuleParser::parse_block(&NestedRuleParser { context: &self.context, _impl: PhantomData }, prelude, input) + fn parse_block(&self, prelude: AtRulePrelude, input: &mut Parser) -> Result { + AtRuleParser::parse_block(&NestedRuleParser { context: &self.context }, prelude, input) } } -impl<'a, Impl: SelectorImpl> QualifiedRuleParser for TopLevelRuleParser<'a, Impl> { - type Prelude = Vec>; - type QualifiedRule = CSSRule; +impl<'a> QualifiedRuleParser for TopLevelRuleParser<'a> { + type Prelude = Vec>; + type QualifiedRule = CSSRule; #[inline] - fn parse_prelude(&self, input: &mut Parser) -> Result>, ()> { + fn parse_prelude(&self, input: &mut Parser) -> Result>, ()> { self.state.set(State::Body); - QualifiedRuleParser::parse_prelude(&NestedRuleParser { context: &self.context, _impl: PhantomData }, input) + QualifiedRuleParser::parse_prelude(&NestedRuleParser { context: &self.context }, input) } #[inline] - fn parse_block(&self, prelude: Vec>, input: &mut Parser) -> Result, ()> { - QualifiedRuleParser::parse_block(&NestedRuleParser { context: &self.context, _impl: PhantomData }, + fn parse_block(&self, prelude: Vec>, input: &mut Parser) -> Result { + QualifiedRuleParser::parse_block(&NestedRuleParser { context: &self.context }, prelude, input) } } -struct NestedRuleParser<'a, 'b: 'a, Impl: SelectorImpl> { +struct NestedRuleParser<'a, 'b: 'a> { context: &'a ParserContext<'b>, - _impl: PhantomData, } -impl<'a, 'b, Impl: SelectorImpl> AtRuleParser for NestedRuleParser<'a, 'b, Impl> { +impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> { type Prelude = AtRulePrelude; - type AtRule = CSSRule; + type AtRule = CSSRule; fn parse_prelude(&self, name: &str, input: &mut Parser) - -> Result>, ()> { + -> Result, ()> { match_ignore_ascii_case! { name, "media" => { let media_queries = parse_media_query_list(input); @@ -519,7 +512,7 @@ impl<'a, 'b, Impl: SelectorImpl> AtRuleParser for NestedRuleParser<'a, 'b, Impl> } } - fn parse_block(&self, prelude: AtRulePrelude, input: &mut Parser) -> Result, ()> { + fn parse_block(&self, prelude: AtRulePrelude, input: &mut Parser) -> Result { match prelude { AtRulePrelude::FontFace => { parse_font_face_block(self.context, input).map(CSSRule::FontFace) @@ -543,15 +536,15 @@ impl<'a, 'b, Impl: SelectorImpl> AtRuleParser for NestedRuleParser<'a, 'b, Impl> } } -impl<'a, 'b, Impl: SelectorImpl> QualifiedRuleParser for NestedRuleParser<'a, 'b, Impl> { - type Prelude = Vec>; - type QualifiedRule = CSSRule; +impl<'a, 'b> QualifiedRuleParser for NestedRuleParser<'a, 'b> { + type Prelude = Vec>; + type QualifiedRule = CSSRule; - fn parse_prelude(&self, input: &mut Parser) -> Result>, ()> { + fn parse_prelude(&self, input: &mut Parser) -> Result>, ()> { parse_selector_list(&self.context.selector_context, input) } - fn parse_block(&self, prelude: Vec>, input: &mut Parser) -> Result, ()> { + fn parse_block(&self, prelude: Vec>, input: &mut Parser) -> Result { Ok(CSSRule::Style(StyleRule { selectors: prelude, declarations: parse_property_declaration_list(self.context, input) diff --git a/components/style/traversal.rs b/components/style/traversal.rs index a259ac403eb..76f8539c72f 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -46,11 +46,11 @@ thread_local!( /// /// If one does not exist, a new one will be made for you. If it is out of date, /// it will be cleared and reused. -fn take_thread_local_bloom_filter(parent_node: Option, - root: OpaqueNode, - context: &SharedStyleContext) - -> Box - where N: TNode { +fn take_thread_local_bloom_filter(parent_node: Option, + root: OpaqueNode, + context: &SharedStyleContext) + -> Box + where N: TNode { STYLE_BLOOM.with(|style_bloom| { match (parent_node, style_bloom.borrow_mut().take()) { // Root node. Needs new bloom filter. @@ -82,9 +82,8 @@ fn take_thread_local_bloom_filter(parent_node: Option< }) } -fn put_thread_local_bloom_filter(bf: Box, - unsafe_node: &UnsafeNode, - context: &SharedStyleContext) { +fn put_thread_local_bloom_filter(bf: Box, unsafe_node: &UnsafeNode, + context: &SharedStyleContext) { STYLE_BLOOM.with(move |style_bloom| { assert!(style_bloom.borrow().is_none(), "Putting into a never-taken thread-local bloom filter"); @@ -111,10 +110,9 @@ fn insert_ancestors_into_bloom_filter(bf: &mut Box, debug!("[{}] Inserted {} ancestors.", tid(), ancestors); } -pub fn remove_from_bloom_filter<'a, N, C, Impl>(context: &C, root: OpaqueNode, node: N) +pub fn remove_from_bloom_filter<'a, N, C>(context: &C, root: OpaqueNode, node: N) where N: TNode, - Impl: SelectorImplExt + 'a, - C: StyleContext<'a, Impl> + C: StyleContext<'a> { let unsafe_layout_node = node.to_unsafe(); @@ -158,7 +156,7 @@ pub fn recalc_style_at<'a, N, C>(context: &'a C, root: OpaqueNode, node: N) where N: TNode, - C: StyleContext<'a, ::Impl>, + C: StyleContext<'a>, ::Impl: SelectorImplExt + 'a { // Get the parent node. let parent_opt = match node.parent_node() { diff --git a/ports/geckolib/context.rs b/ports/geckolib/context.rs index 10e235abee7..1435c27c0a5 100644 --- a/ports/geckolib/context.rs +++ b/ports/geckolib/context.rs @@ -1,7 +1,7 @@ /* 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 selector_impl::{GeckoSelectorImpl, SharedStyleContext}; +use selector_impl::SharedStyleContext; use std::cell::RefCell; use std::rc::Rc; use style::context::{LocalStyleContext, StyleContext}; @@ -40,7 +40,7 @@ impl<'a> StandaloneStyleContext<'a> { } } -impl<'a> StyleContext<'a, GeckoSelectorImpl> for StandaloneStyleContext<'a> { +impl<'a> StyleContext<'a> for StandaloneStyleContext<'a> { fn shared_context(&self) -> &'a SharedStyleContext { &self.shared }