diff options
Diffstat (limited to 'components/style/gecko/data.rs')
-rw-r--r-- | components/style/gecko/data.rs | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index dd4ae30a429..f4182d365e2 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -7,11 +7,10 @@ use animation::Animation; use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut}; use dom::OpaqueNode; -use euclid::size::TypedSize2D; -use gecko_bindings::bindings::RawGeckoPresContextBorrowed; use gecko_bindings::bindings::RawServoStyleSet; +use gecko_bindings::structs::RawGeckoPresContextOwned; use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI}; -use media_queries::{Device, MediaType}; +use media_queries::Device; use num_cpus; use parking_lot::RwLock; use properties::ComputedValues; @@ -21,7 +20,6 @@ use std::collections::HashMap; use std::env; use std::sync::Arc; use std::sync::mpsc::{Receiver, Sender, channel}; -use style_traits::ViewportPx; use stylesheets::Stylesheet; use stylist::Stylist; @@ -37,6 +35,9 @@ pub struct PerDocumentStyleDataImpl { /// Whether the stylesheets list above has changed since the last restyle. pub stylesheets_changed: bool, + /// Whether the device has changed since the last restyle. + pub device_changed: bool, + // FIXME(bholley): Hook these up to something. /// Unused. Will go away when we actually implement transitions and /// animations properly. @@ -57,9 +58,6 @@ pub struct PerDocumentStyleDataImpl { /// The number of threads of the work queue. pub num_threads: usize, - - /// Default computed values for this document. - pub default_computed_values: Arc<ComputedValues> } /// The data itself is an `AtomicRefCell`, which guarantees the proper semantics @@ -78,15 +76,8 @@ lazy_static! { impl PerDocumentStyleData { /// Create a dummy `PerDocumentStyleData`. - pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self { - // FIXME(bholley): Real window size. - let window_size: TypedSize2D<f32, ViewportPx> = TypedSize2D::new(800.0, 600.0); - let default_computed_values = ComputedValues::default_values(pres_context); - - // FIXME(bz): We're going to need to either update the computed values - // in the Stylist's Device or give the Stylist a new Device when our - // default_computed_values changes. - let device = Device::new(MediaType::Screen, window_size, &default_computed_values); + pub fn new(pres_context: RawGeckoPresContextOwned) -> Self { + let device = Device::new(pres_context); let (new_anims_sender, new_anims_receiver) = channel(); @@ -94,6 +85,7 @@ impl PerDocumentStyleData { stylist: Arc::new(Stylist::new(device)), stylesheets: vec![], stylesheets_changed: true, + device_changed: true, new_animations_sender: new_anims_sender, new_animations_receiver: new_anims_receiver, running_animations: Arc::new(RwLock::new(HashMap::new())), @@ -106,7 +98,6 @@ impl PerDocumentStyleData { rayon::ThreadPool::new(configuration).ok() }, num_threads: *NUM_THREADS, - default_computed_values: default_computed_values, })) } @@ -124,15 +115,30 @@ impl PerDocumentStyleData { impl PerDocumentStyleDataImpl { /// Recreate the style data if the stylesheets have changed. pub fn flush_stylesheets(&mut self) { - // The stylist wants to be flushed if either the stylesheets change or the - // device dimensions change. When we add support for media queries, we'll - // need to detect the latter case and trigger a flush as well. + let mut stylist = if self.device_changed || self.stylesheets_changed { + Some(Arc::get_mut(&mut self.stylist).unwrap()) + } else { + None + }; + + if self.device_changed { + Arc::get_mut(&mut stylist.as_mut().unwrap().device).unwrap().reset(); + self.device_changed = false; + // Force a stylesheet flush if the device has changed. + self.stylesheets_changed = true; + } + if self.stylesheets_changed { - let _ = Arc::get_mut(&mut self.stylist).unwrap() - .update(&self.stylesheets, None, true); + let _ = stylist.unwrap().update(&self.stylesheets, None, true); self.stylesheets_changed = false; } } + + /// Get the default computed values for this document. + pub fn default_computed_values(&self) -> &Arc<ComputedValues> { + debug_assert!(!self.device_changed, "A device flush was pending"); + self.stylist.device.default_values_arc() + } } unsafe impl HasFFI for PerDocumentStyleData { |