diff options
author | Xidorn Quan <me@upsuper.org> | 2017-05-16 09:47:26 +1000 |
---|---|---|
committer | Xidorn Quan <me@upsuper.org> | 2017-05-16 14:42:46 +1000 |
commit | 3e00a91e2010e5be5ed158a35e47330ee275837e (patch) | |
tree | 43f2192d735626a5e8a51511dea01d16571bdddc /components | |
parent | 0667287bf60683d444bfd8d7da6ddcf027c4d4f3 (diff) | |
download | servo-3e00a91e2010e5be5ed158a35e47330ee275837e.tar.gz servo-3e00a91e2010e5be5ed158a35e47330ee275837e.zip |
Enable querying counter-style rule on Servo backend.
Diffstat (limited to 'components')
-rw-r--r-- | components/style/gecko/data.rs | 8 | ||||
-rw-r--r-- | components/style/stylist.rs | 43 |
2 files changed, 39 insertions, 12 deletions
diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index bf71114da37..4108e073945 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -4,9 +4,11 @@ //! Data needed to style a Gecko document. +use Atom; use animation::Animation; use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut}; use dom::OpaqueNode; +use gecko::rules::{CounterStyleRule, FontFaceRule}; use gecko_bindings::bindings::RawServoStyleSet; use gecko_bindings::structs::RawGeckoPresContextOwned; use gecko_bindings::structs::nsIDocument; @@ -19,7 +21,7 @@ use std::collections::HashMap; use std::sync::mpsc::{Receiver, Sender, channel}; use stylearc::Arc; use stylesheet_set::StylesheetSet; -use stylesheets::{FontFaceRule, Origin}; +use stylesheets::Origin; use stylist::{ExtraStyleData, Stylist}; /// The container for data that a Servo-backed Gecko document needs to style @@ -47,6 +49,8 @@ pub struct PerDocumentStyleDataImpl { /// List of effective font face rules. pub font_faces: Vec<(Arc<Locked<FontFaceRule>>, Origin)>, + /// Map for effective counter style rules. + pub counter_styles: HashMap<Atom, Arc<Locked<CounterStyleRule>>>, } /// The data itself is an `AtomicRefCell`, which guarantees the proper semantics @@ -71,6 +75,7 @@ impl PerDocumentStyleData { running_animations: Arc::new(RwLock::new(HashMap::new())), expired_animations: Arc::new(RwLock::new(HashMap::new())), font_faces: vec![], + counter_styles: HashMap::new(), })) } @@ -103,6 +108,7 @@ impl PerDocumentStyleDataImpl { let mut extra_data = ExtraStyleData { font_faces: &mut self.font_faces, + counter_styles: &mut self.counter_styles, }; let author_style_disabled = self.stylesheets.author_style_disabled(); diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 5f64588d186..05ec01cc2bc 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -14,6 +14,8 @@ use dom::{AnimationRules, TElement}; use element_state::ElementState; use error_reporting::RustLogReporter; use font_metrics::FontMetricsProvider; +#[cfg(feature = "gecko")] +use gecko_bindings::structs::nsIAtom; use keyframes::KeyframesAnimation; use media_queries::Device; use pdqsort::sort_by; @@ -41,7 +43,10 @@ use std::hash::Hash; use std::marker::PhantomData; use style_traits::viewport::ViewportConstraints; use stylearc::Arc; -use stylesheets::{CssRule, FontFaceRule, Origin, StyleRule, Stylesheet, UserAgentStylesheets}; +#[cfg(feature = "gecko")] +use stylesheets::{CounterStyleRule, FontFaceRule}; +use stylesheets::{CssRule, Origin}; +use stylesheets::{StyleRule, Stylesheet, UserAgentStylesheets}; #[cfg(feature = "servo")] use stylesheets::NestedRulesResult; use thread_state; @@ -159,33 +164,44 @@ pub struct Stylist { /// This struct holds data which user of Stylist may want to extract /// from stylesheets which can be done at the same time as updating. +#[cfg(feature = "gecko")] pub struct ExtraStyleData<'a> { /// A list of effective font-face rules and their origin. - #[cfg(feature = "gecko")] pub font_faces: &'a mut Vec<(Arc<Locked<FontFaceRule>>, Origin)>, - - #[allow(missing_docs)] - #[cfg(feature = "servo")] - pub marker: PhantomData<&'a usize>, + /// A map of effective counter-style rules. + pub counter_styles: &'a mut HashMap<Atom, Arc<Locked<CounterStyleRule>>>, } #[cfg(feature = "gecko")] impl<'a> ExtraStyleData<'a> { - /// Clear the internal @font-face rule list. - fn clear_font_faces(&mut self) { + /// Clear the internal data. + fn clear(&mut self) { self.font_faces.clear(); + self.counter_styles.clear(); } /// Add the given @font-face rule. fn add_font_face(&mut self, rule: &Arc<Locked<FontFaceRule>>, origin: Origin) { self.font_faces.push((rule.clone(), origin)); } + + /// Add the given @counter-style rule. + fn add_counter_style(&mut self, guard: &SharedRwLockReadGuard, + rule: &Arc<Locked<CounterStyleRule>>) { + let name = rule.read_with(guard).mName.raw::<nsIAtom>().into(); + self.counter_styles.insert(name, rule.clone()); + } +} + +#[allow(missing_docs)] +#[cfg(feature = "servo")] +pub struct ExtraStyleData<'a> { + pub marker: PhantomData<&'a usize>, } #[cfg(feature = "servo")] impl<'a> ExtraStyleData<'a> { - fn clear_font_faces(&mut self) {} - fn add_font_face(&mut self, _: &Arc<Locked<FontFaceRule>>, _: Origin) {} + fn clear(&mut self) {} } impl Stylist { @@ -334,7 +350,7 @@ impl Stylist { self.pseudos_map.insert(pseudo, PerPseudoElementSelectorMap::new()); }); - extra_data.clear_font_faces(); + extra_data.clear(); if let Some(ua_stylesheets) = ua_stylesheets { for stylesheet in &ua_stylesheets.user_or_user_agent_stylesheets { @@ -434,9 +450,14 @@ impl Stylist { self.animations.insert(keyframes_rule.name.as_atom().clone(), animation); } } + #[cfg(feature = "gecko")] CssRule::FontFace(ref rule) => { extra_data.add_font_face(&rule, stylesheet.origin); } + #[cfg(feature = "gecko")] + CssRule::CounterStyle(ref rule) => { + extra_data.add_counter_style(guard, &rule); + } // We don't care about any other rule. _ => {} } |