Skip to content

Commit

Permalink
Make the initial viewport size available to style::properties::cascade
Browse files Browse the repository at this point in the history
  • Loading branch information
luniv committed Mar 5, 2015
1 parent 67548a6 commit 00785ec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
38 changes: 24 additions & 14 deletions components/layout/css/matching.rs
Expand Up @@ -6,6 +6,7 @@

#![allow(unsafe_blocks)]

use context::SharedLayoutContext;
use css::node_style::StyledNode;
use incremental::{self, RestyleDamage};
use util::{LayoutDataAccess, LayoutDataWrapper};
Expand Down Expand Up @@ -391,13 +392,15 @@ pub trait MatchMethods {
-> StyleSharingResult;

unsafe fn cascade_node(&self,
layout_context: &SharedLayoutContext,
parent: Option<LayoutNode>,
applicable_declarations: &ApplicableDeclarations,
applicable_declarations_cache: &mut ApplicableDeclarationsCache);
}

trait PrivateMatchMethods {
fn cascade_node_pseudo_element(&self,
layout_context: &SharedLayoutContext,
parent_style: Option<&Arc<ComputedValues>>,
applicable_declarations: &[DeclarationBlock],
style: &mut Option<Arc<ComputedValues>>,
Expand All @@ -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<ComputedValues>>,
applicable_declarations: &[DeclarationBlock],
style: &mut Option<Arc<ComputedValues>>,
Expand All @@ -430,15 +434,17 @@ 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);
cacheable = is_cacheable;
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);
Expand Down Expand Up @@ -602,6 +608,7 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
}

unsafe fn cascade_node(&self,
layout_context: &SharedLayoutContext,
parent: Option<LayoutNode>,
applicable_declarations: &ApplicableDeclarations,
applicable_declarations_cache: &mut ApplicableDeclarationsCache) {
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion components/layout/traversal.rs
Expand Up @@ -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());
}
Expand Down
5 changes: 4 additions & 1 deletion components/style/properties.mako.rs
Expand Up @@ -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
Expand All @@ -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<Vec<PropertyDeclaration>>],
pub fn cascade(viewport_size: Size2D<Au>,
applicable_declarations: &[DeclarationBlock<Vec<PropertyDeclaration>>],
shareable: bool,
parent_style: Option< &ComputedValues >,
cached_style: Option< &ComputedValues >)
Expand Down

0 comments on commit 00785ec

Please sign in to comment.