From 00785ecf6316fd71f2b5399a48910b80e2fe1fa3 Mon Sep 17 00:00:00 2001 From: James Gilbertson Date: Thu, 5 Mar 2015 01:38:44 -0700 Subject: [PATCH] Make the initial viewport size available to style::properties::cascade --- components/layout/css/matching.rs | 38 ++++++++++++++++++----------- components/layout/traversal.rs | 3 ++- components/style/properties.mako.rs | 5 +++- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/components/layout/css/matching.rs b/components/layout/css/matching.rs index cc6147cce46..d76ee7ac5f8 100644 --- a/components/layout/css/matching.rs +++ b/components/layout/css/matching.rs @@ -6,6 +6,7 @@ #![allow(unsafe_blocks)] +use context::SharedLayoutContext; use css::node_style::StyledNode; use incremental::{self, RestyleDamage}; use util::{LayoutDataAccess, LayoutDataWrapper}; @@ -391,6 +392,7 @@ pub trait MatchMethods { -> StyleSharingResult; unsafe fn cascade_node(&self, + layout_context: &SharedLayoutContext, parent: Option, applicable_declarations: &ApplicableDeclarations, applicable_declarations_cache: &mut ApplicableDeclarationsCache); @@ -398,6 +400,7 @@ pub trait MatchMethods { trait PrivateMatchMethods { fn cascade_node_pseudo_element(&self, + layout_context: &SharedLayoutContext, parent_style: Option<&Arc>, applicable_declarations: &[DeclarationBlock], style: &mut Option>, @@ -414,6 +417,7 @@ trait PrivateMatchMethods { impl<'ln> PrivateMatchMethods for LayoutNode<'ln> { fn cascade_node_pseudo_element(&self, + layout_context: &SharedLayoutContext, parent_style: Option<&Arc>, applicable_declarations: &[DeclarationBlock], style: &mut Option>, @@ -430,7 +434,8 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> { None => None, Some(ref style) => Some(&**style), }; - let (the_style, is_cacheable) = cascade(applicable_declarations, + let (the_style, is_cacheable) = cascade(layout_context.screen_size, + applicable_declarations, shareable, Some(&***parent_style), cached_computed_values); @@ -438,7 +443,8 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> { this_style = Arc::new(the_style); } None => { - let (the_style, is_cacheable) = cascade(applicable_declarations, + let (the_style, is_cacheable) = cascade(layout_context.screen_size, + applicable_declarations, shareable, None, None); @@ -602,6 +608,7 @@ impl<'ln> MatchMethods for LayoutNode<'ln> { } unsafe fn cascade_node(&self, + layout_context: &SharedLayoutContext, parent: Option, applicable_declarations: &ApplicableDeclarations, applicable_declarations_cache: &mut ApplicableDeclarationsCache) { @@ -635,26 +642,29 @@ impl<'ln> MatchMethods for LayoutNode<'ln> { } _ => { let mut damage = self.cascade_node_pseudo_element( + layout_context, parent_style, applicable_declarations.normal.as_slice(), &mut layout_data.shared_data.style, applicable_declarations_cache, applicable_declarations.normal_shareable); if applicable_declarations.before.len() > 0 { - damage = damage | self.cascade_node_pseudo_element( - Some(layout_data.shared_data.style.as_ref().unwrap()), - &*applicable_declarations.before, - &mut layout_data.data.before_style, - applicable_declarations_cache, - false); + damage = damage | self.cascade_node_pseudo_element( + layout_context, + Some(layout_data.shared_data.style.as_ref().unwrap()), + &*applicable_declarations.before, + &mut layout_data.data.before_style, + applicable_declarations_cache, + false); } if applicable_declarations.after.len() > 0 { - damage = damage | self.cascade_node_pseudo_element( - Some(layout_data.shared_data.style.as_ref().unwrap()), - &*applicable_declarations.after, - &mut layout_data.data.after_style, - applicable_declarations_cache, - false); + damage = damage | self.cascade_node_pseudo_element( + layout_context, + Some(layout_data.shared_data.style.as_ref().unwrap()), + &*applicable_declarations.after, + &mut layout_data.data.after_style, + applicable_declarations_cache, + false); } layout_data.data.restyle_damage = damage; } diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index 2211cf2fcce..5e5138a4fae 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -176,7 +176,8 @@ impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> { // Perform the CSS cascade. unsafe { - node.cascade_node(parent_opt, + node.cascade_node(self.layout_context.shared, + parent_opt, &applicable_declarations, self.layout_context.applicable_declarations_cache()); } diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 5330de59a93..183f95553f2 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -3701,6 +3701,8 @@ fn cascade_with_cached_declarations(applicable_declarations: &[DeclarationBlock< /// Performs the CSS cascade, computing new styles for an element from its parent style and /// optionally a cached related style. The arguments are: /// +/// * `viewport_size`: The size of the initial viewport. +/// /// * `applicable_declarations`: The list of CSS rules that matched. /// /// * `shareable`: Whether the `ComputedValues` structure to be constructed should be considered @@ -3714,7 +3716,8 @@ fn cascade_with_cached_declarations(applicable_declarations: &[DeclarationBlock< /// this is ignored. /// /// Returns the computed values and a boolean indicating whether the result is cacheable. -pub fn cascade(applicable_declarations: &[DeclarationBlock>], +pub fn cascade(viewport_size: Size2D, + applicable_declarations: &[DeclarationBlock>], shareable: bool, parent_style: Option< &ComputedValues >, cached_style: Option< &ComputedValues >)