Make the initial viewport size available to style::properties::cascade

This commit is contained in:
James Gilbertson 2015-03-05 01:38:44 -07:00
parent 67548a6244
commit 00785ecf63
3 changed files with 30 additions and 16 deletions

View file

@ -6,6 +6,7 @@
#![allow(unsafe_blocks)] #![allow(unsafe_blocks)]
use context::SharedLayoutContext;
use css::node_style::StyledNode; use css::node_style::StyledNode;
use incremental::{self, RestyleDamage}; use incremental::{self, RestyleDamage};
use util::{LayoutDataAccess, LayoutDataWrapper}; use util::{LayoutDataAccess, LayoutDataWrapper};
@ -391,6 +392,7 @@ pub trait MatchMethods {
-> StyleSharingResult; -> StyleSharingResult;
unsafe fn cascade_node(&self, unsafe fn cascade_node(&self,
layout_context: &SharedLayoutContext,
parent: Option<LayoutNode>, parent: Option<LayoutNode>,
applicable_declarations: &ApplicableDeclarations, applicable_declarations: &ApplicableDeclarations,
applicable_declarations_cache: &mut ApplicableDeclarationsCache); applicable_declarations_cache: &mut ApplicableDeclarationsCache);
@ -398,6 +400,7 @@ pub trait MatchMethods {
trait PrivateMatchMethods { trait PrivateMatchMethods {
fn cascade_node_pseudo_element(&self, fn cascade_node_pseudo_element(&self,
layout_context: &SharedLayoutContext,
parent_style: Option<&Arc<ComputedValues>>, parent_style: Option<&Arc<ComputedValues>>,
applicable_declarations: &[DeclarationBlock], applicable_declarations: &[DeclarationBlock],
style: &mut Option<Arc<ComputedValues>>, style: &mut Option<Arc<ComputedValues>>,
@ -414,6 +417,7 @@ trait PrivateMatchMethods {
impl<'ln> PrivateMatchMethods for LayoutNode<'ln> { impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
fn cascade_node_pseudo_element(&self, fn cascade_node_pseudo_element(&self,
layout_context: &SharedLayoutContext,
parent_style: Option<&Arc<ComputedValues>>, parent_style: Option<&Arc<ComputedValues>>,
applicable_declarations: &[DeclarationBlock], applicable_declarations: &[DeclarationBlock],
style: &mut Option<Arc<ComputedValues>>, style: &mut Option<Arc<ComputedValues>>,
@ -430,7 +434,8 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
None => None, None => None,
Some(ref style) => Some(&**style), 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, shareable,
Some(&***parent_style), Some(&***parent_style),
cached_computed_values); cached_computed_values);
@ -438,7 +443,8 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
this_style = Arc::new(the_style); this_style = Arc::new(the_style);
} }
None => { None => {
let (the_style, is_cacheable) = cascade(applicable_declarations, let (the_style, is_cacheable) = cascade(layout_context.screen_size,
applicable_declarations,
shareable, shareable,
None, None,
None); None);
@ -602,6 +608,7 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
} }
unsafe fn cascade_node(&self, unsafe fn cascade_node(&self,
layout_context: &SharedLayoutContext,
parent: Option<LayoutNode>, parent: Option<LayoutNode>,
applicable_declarations: &ApplicableDeclarations, applicable_declarations: &ApplicableDeclarations,
applicable_declarations_cache: &mut ApplicableDeclarationsCache) { applicable_declarations_cache: &mut ApplicableDeclarationsCache) {
@ -635,26 +642,29 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
} }
_ => { _ => {
let mut damage = self.cascade_node_pseudo_element( let mut damage = self.cascade_node_pseudo_element(
layout_context,
parent_style, parent_style,
applicable_declarations.normal.as_slice(), applicable_declarations.normal.as_slice(),
&mut layout_data.shared_data.style, &mut layout_data.shared_data.style,
applicable_declarations_cache, applicable_declarations_cache,
applicable_declarations.normal_shareable); applicable_declarations.normal_shareable);
if applicable_declarations.before.len() > 0 { if applicable_declarations.before.len() > 0 {
damage = damage | self.cascade_node_pseudo_element( damage = damage | self.cascade_node_pseudo_element(
Some(layout_data.shared_data.style.as_ref().unwrap()), layout_context,
&*applicable_declarations.before, Some(layout_data.shared_data.style.as_ref().unwrap()),
&mut layout_data.data.before_style, &*applicable_declarations.before,
applicable_declarations_cache, &mut layout_data.data.before_style,
false); applicable_declarations_cache,
false);
} }
if applicable_declarations.after.len() > 0 { if applicable_declarations.after.len() > 0 {
damage = damage | self.cascade_node_pseudo_element( damage = damage | self.cascade_node_pseudo_element(
Some(layout_data.shared_data.style.as_ref().unwrap()), layout_context,
&*applicable_declarations.after, Some(layout_data.shared_data.style.as_ref().unwrap()),
&mut layout_data.data.after_style, &*applicable_declarations.after,
applicable_declarations_cache, &mut layout_data.data.after_style,
false); applicable_declarations_cache,
false);
} }
layout_data.data.restyle_damage = damage; layout_data.data.restyle_damage = damage;
} }

View file

@ -176,7 +176,8 @@ impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
// Perform the CSS cascade. // Perform the CSS cascade.
unsafe { unsafe {
node.cascade_node(parent_opt, node.cascade_node(self.layout_context.shared,
parent_opt,
&applicable_declarations, &applicable_declarations,
self.layout_context.applicable_declarations_cache()); self.layout_context.applicable_declarations_cache());
} }

View file

@ -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 /// Performs the CSS cascade, computing new styles for an element from its parent style and
/// optionally a cached related style. The arguments are: /// 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. /// * `applicable_declarations`: The list of CSS rules that matched.
/// ///
/// * `shareable`: Whether the `ComputedValues` structure to be constructed should be considered /// * `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. /// this is ignored.
/// ///
/// Returns the computed values and a boolean indicating whether the result is cacheable. /// 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, shareable: bool,
parent_style: Option< &ComputedValues >, parent_style: Option< &ComputedValues >,
cached_style: Option< &ComputedValues >) cached_style: Option< &ComputedValues >)