Bug 1303229: Get the proper viewport size for stylo. draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 11 Mar 2017 00:21:10 +0100
changeset 496955 8cf429366d66a6eea29dfa22262f888eea4955d4
parent 496768 a8d497b09753c91783b68c5805c64f34a2f39629
child 496956 6672d7aa343171d5066a934ad7ab2007ba8fa573
child 496983 c7e8bd94e211e4d345d1187914cde1369ac25f92
push id48756
push userbmo:emilio+bugs@crisal.io
push dateFri, 10 Mar 2017 23:35:13 +0000
bugs1303229
milestone55.0a1
Bug 1303229: Get the proper viewport size for stylo. At least until we support scrollbars properly, this size is going to be the correct one. I've left a TODO to grab the proper one once we support it. This allows to trivially test viewport units for now. MozReview-Commit-ID: JdaZ6WlZ2C6
servo/components/layout_thread/lib.rs
servo/components/style/animation.rs
servo/components/style/context.rs
servo/components/style/gecko/media_queries.rs
servo/components/style/matching.rs
servo/ports/geckolib/glue.rs
--- a/servo/components/layout_thread/lib.rs
+++ b/servo/components/layout_thread/lib.rs
@@ -498,17 +498,16 @@ impl LayoutThread {
                             rw_data: &LayoutThreadData,
                             request_images: bool)
                             -> LayoutContext {
         let thread_local_style_context_creation_data =
             ThreadLocalStyleContextCreationInfo::new(self.new_animations_sender.clone());
 
         LayoutContext {
             style_context: SharedStyleContext {
-                viewport_size: self.viewport_size.clone(),
                 stylist: rw_data.stylist.clone(),
                 running_animations: self.running_animations.clone(),
                 expired_animations: self.expired_animations.clone(),
                 error_reporter: self.error_reporter.clone(),
                 local_context_creation_data: Mutex::new(thread_local_style_context_creation_data),
                 timer: self.timer.clone(),
                 quirks_mode: self.quirks_mode.unwrap(),
                 // FIXME(bz): This isn't really right, but it's no more wrong
--- a/servo/components/style/animation.rs
+++ b/servo/components/style/animation.rs
@@ -421,17 +421,17 @@ fn compute_style_for_animation_step(cont
             debug_assert!(guard.declarations().iter()
                             .all(|&(_, importance)| importance == Importance::Normal));
 
             let iter = || {
                 guard.declarations().iter().rev().map(|&(ref decl, _importance)| decl)
             };
 
             let computed =
-                properties::apply_declarations(context.viewport_size,
+                properties::apply_declarations(context.viewport_size(),
                                                /* is_root = */ false,
                                                iter,
                                                previous_style,
                                                previous_style,
                                                &context.default_computed_values,
                                                /* cascade_info = */ None,
                                                context.error_reporter.clone(),
                                                /* Metrics provider */ None,
--- a/servo/components/style/context.rs
+++ b/servo/components/style/context.rs
@@ -57,19 +57,16 @@ pub enum QuirksMode {
     NoQuirks,
 }
 
 /// A shared style context.
 ///
 /// There's exactly one of these during a given restyle traversal, and it's
 /// shared among the worker threads.
 pub struct SharedStyleContext {
-    /// The current viewport size.
-    pub viewport_size: Size2D<Au>,
-
     /// The CSS selector stylist.
     pub stylist: Arc<Stylist>,
 
     /// The animations that are currently running.
     pub running_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation>>>>,
 
     /// The list of animations that have expired since the last style recalculation.
     pub expired_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation>>>>,
@@ -87,16 +84,23 @@ pub struct SharedStyleContext {
     /// The QuirksMode state which the document needs to be rendered with
     pub quirks_mode: QuirksMode,
 
     /// The default computed values to use for elements with no rules
     /// applying to them.
     pub default_computed_values: Arc<ComputedValues>,
 }
 
+impl SharedStyleContext {
+    /// Return a suitable viewport size in order to be used for viewport units.
+    pub fn viewport_size(&self) -> Size2D<Au> {
+        self.stylist.device.au_viewport_size()
+    }
+}
+
 /// Information about the current element being processed. We group this together
 /// into a single struct within ThreadLocalStyleContext so that we can instantiate
 /// and destroy it easily at the beginning and end of element processing.
 struct CurrentElementInfo {
     /// The element being processed. Currently we use an OpaqueNode since we only
     /// use this for identity checks, but we could use SendElement if there were
     /// a good reason to.
     element: OpaqueNode,
--- a/servo/components/style/gecko/media_queries.rs
+++ b/servo/components/style/gecko/media_queries.rs
@@ -89,20 +89,20 @@ impl Device {
         }
     }
 
     /// Returns the current viewport size in app units.
     pub fn au_viewport_size(&self) -> Size2D<Au> {
         self.viewport_override.as_ref().map(|v| {
             Size2D::new(Au::from_f32_px(v.size.width),
                         Au::from_f32_px(v.size.height))
-        }).unwrap_or_else(|| {
-            // TODO(emilio): Grab from pres context.
-            Size2D::new(Au::from_f32_px(1024.0),
-                        Au::from_f32_px(768.0))
+        }).unwrap_or_else(|| unsafe {
+            // TODO(emilio): Need to take into account scrollbars.
+            Size2D::new(Au((*self.pres_context).mVisibleArea.width),
+                        Au((*self.pres_context).mVisibleArea.height))
         })
     }
 }
 
 unsafe impl Sync for Device {}
 unsafe impl Send for Device {}
 
 /// A expression for gecko contains a reference to the media feature, the value
--- a/servo/components/style/matching.rs
+++ b/servo/components/style/matching.rs
@@ -535,17 +535,17 @@ trait PrivateMatchMethods: TElement {
                     p.is_multicol() ||
                     layout_parent_el.as_ref().unwrap().as_node().can_be_fragmented();
                 unsafe { self.as_node().set_can_be_fragmented(can_be_fragmented); }
             }
         }
 
         // Invoke the cascade algorithm.
         let values =
-            Arc::new(cascade(shared_context.viewport_size,
+            Arc::new(cascade(shared_context.viewport_size(),
                              rule_node,
                              inherited_values,
                              layout_parent_style,
                              &shared_context.default_computed_values,
                              Some(&mut cascade_info),
                              shared_context.error_reporter.clone(),
                              cascade_flags));
 
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -157,18 +157,16 @@ pub extern "C" fn Servo_Shutdown() -> ()
     gecko_properties::shutdown();
 }
 
 fn create_shared_context(per_doc_data: &PerDocumentStyleDataImpl) -> SharedStyleContext {
     let local_context_data =
         ThreadLocalStyleContextCreationInfo::new(per_doc_data.new_animations_sender.clone());
 
     SharedStyleContext {
-        // FIXME (bug 1303229): Use the actual viewport size here
-        viewport_size: Size2D::new(Au(0), Au(0)),
         stylist: per_doc_data.stylist.clone(),
         running_animations: per_doc_data.running_animations.clone(),
         expired_animations: per_doc_data.expired_animations.clone(),
         error_reporter: Box::new(StdoutErrorReporter),
         local_context_creation_data: Mutex::new(local_context_data),
         timer: Timer::new(),
         // FIXME Find the real QuirksMode information for this document
         quirks_mode: QuirksMode::NoQuirks,
@@ -1343,17 +1341,17 @@ pub extern "C" fn Servo_GetComputedKeyfr
     use style::values::computed::Context;
 
     let style = ComputedValues::as_arc(&style);
     let parent_style = parent_style.as_ref().map(|r| &**ComputedValues::as_arc(&r));
     let init = ComputedValues::default_values(pres_context);
 
     let context = Context {
         is_root_element: false,
-        // FIXME (bug 1303229): Use the actual viewport size here
+        // FIXME (bug 1303229): Use the actual viewport size here.
         viewport_size: Size2D::new(Au(0), Au(0)),
         inherited_style: parent_style.unwrap_or(&init),
         layout_parent_style: parent_style.unwrap_or(&init),
         style: (**style).clone(),
         font_metrics_provider: None,
     };
 
     for (index, keyframe) in keyframes.iter().enumerate() {