From 2bfa0f7a2d6fd9f494ad1288b13cdace881c82a8 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Sat, 28 Jan 2017 19:00:23 +0900 Subject: [PATCH] Bug 1328787 - Part 10: Set Keyframe.mPropertyValues for the case where keyframe is not specified. r=heycam --- components/style/properties/gecko.mako.rs | 25 +++++++++++++++++++ .../helpers/animated_properties.mako.rs | 18 +++++++++++++ ports/geckolib/glue.rs | 13 ++++++++-- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 7f26b5d1168..d11667737c4 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -51,11 +51,14 @@ use gecko::values::GeckoStyleCoordConvertible; use gecko::values::round_border_to_device_pixels; use logical_geometry::WritingMode; use properties::longhands; +use properties::{DeclaredValue, Importance, LonghandId}; +use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarationId}; use std::fmt::{self, Debug}; use std::mem::{transmute, zeroed}; use std::ptr; use std::sync::Arc; use std::cmp; +use values::computed::ToComputedValue; pub mod style_structs { % for style_struct in data.style_structs: @@ -154,6 +157,28 @@ impl ComputedValues { // FIXME(bholley): Implement this properly. #[inline] pub fn is_multicol(&self) -> bool { false } + + pub fn to_declaration_block(&self, property: PropertyDeclarationId) -> PropertyDeclarationBlock { + match property { + % for prop in data.longhands: + % if prop.animatable: + PropertyDeclarationId::Longhand(LonghandId::${prop.camel_case}) => { + PropertyDeclarationBlock { + declarations: vec![ + (PropertyDeclaration::${prop.camel_case}(DeclaredValue::Value( + longhands::${prop.ident}::SpecifiedValue::from_computed_value( + &self.get_${prop.style_struct.ident.strip("_")}().clone_${prop.ident}()))), + Importance::Normal) + ], + important_count: 0 + } + }, + % endif + % endfor + PropertyDeclarationId::Custom(_name) => unimplemented!(), + _ => unimplemented!() + } + } } <%def name="declare_style_struct(style_struct)"> diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 9b32c26c35b..51a0d2f10f5 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -22,6 +22,7 @@ use properties::longhands::box_shadow::single_value::computed_value::T as BoxSha use properties::longhands::vertical_align::computed_value::T as VerticalAlign; use properties::longhands::visibility::computed_value::T as Visibility; use properties::longhands::z_index::computed_value::T as ZIndex; +#[cfg(feature = "gecko")] use properties::{PropertyDeclarationId, LonghandId}; use std::cmp; use std::fmt; use style_traits::ToCss; @@ -121,6 +122,23 @@ impl From for nsCSSPropertyID { } } +/// Convert to PropertyDeclarationId. +#[cfg(feature = "gecko")] +#[allow(non_upper_case_globals)] +impl<'a> From for PropertyDeclarationId<'a> { + fn from(transition_property: TransitionProperty) -> PropertyDeclarationId<'a> { + match transition_property { + % for prop in data.longhands: + % if prop.animatable: + TransitionProperty::${prop.camel_case} + => PropertyDeclarationId::Longhand(LonghandId::${prop.camel_case}), + % endif + % endfor + TransitionProperty::All => panic!(), + } + } +} + /// An animated property interpolation between two computed values for that /// property. #[derive(Clone, Debug, PartialEq)] diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 069f6f6d6dc..5de30623403 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -1148,11 +1148,12 @@ pub extern "C" fn Servo_AssertTreeIsClean(root: RawGeckoElementBorrowed) { pub extern "C" fn Servo_StyleSet_FillKeyframesForName(raw_data: RawServoStyleSetBorrowed, name: *const nsACString, timing_function: *const nsTimingFunction, - _style: ServoComputedValuesBorrowed, + style: ServoComputedValuesBorrowed, keyframes: RawGeckoKeyframeListBorrowedMut) -> bool { let data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut(); let name = unsafe { Atom::from(name.as_ref().unwrap().as_str_unchecked()) }; let style_timing_function = unsafe { timing_function.as_ref().unwrap() }; + let style = ComputedValues::as_arc(&style); if let Some(ref animation) = data.stylist.animations().get(&name) { for step in &animation.steps { @@ -1171,7 +1172,15 @@ pub extern "C" fn Servo_StyleSet_FillKeyframesForName(raw_data: RawServoStyleSet match step.value { KeyframesStepValue::ComputedValues => { - unimplemented!(); + for (index, property) in animation.properties_changed.iter().enumerate() { + let block = style.to_declaration_block(property.clone().into()); + unsafe { + (*keyframe).mPropertyValues.set_len((index + 1) as u32); + (*keyframe).mPropertyValues[index].mProperty = property.clone().into(); + (*keyframe).mPropertyValues[index].mServoDeclarationBlock.set_arc_leaky( + Arc::new(RwLock::new(block))); + } + } }, KeyframesStepValue::Declarations { ref block } => { let guard = block.read();