Auto merge of #15287 - hiikezoe:css-animation, r=heycam

Counter part of bug 1328787 - Stylo: Convert Servo's animation keyframes and store them into Gecko's keyframes

<!-- Please describe your changes on the following line: -->
Reviewed by @heycam, An exception is auto-generated bindgen stuff, I did not include it in patches on bugzilla.  The bindgen diff included in this PR was generated with  b5c94bad37.  It might be bit-rotted.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because gecko has test cases.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15287)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-01-28 21:24:04 -08:00 committed by GitHub
commit 0459e1a6dd
13 changed files with 7228 additions and 9083 deletions

View file

@ -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)">

View file

@ -665,3 +665,20 @@
}
% endif
</%def>
<%def name="alias_to_nscsspropertyid(alias)">
<%
if alias == "word-wrap":
return "nsCSSPropertyID_eCSSPropertyAlias_WordWrap"
return "nsCSSPropertyID::eCSSPropertyAlias_%s" % to_camel_case(alias)
%>
</%def>
<%def name="to_nscsspropertyid(ident)">
<%
if ident == "float":
ident = "float_"
return "nsCSSPropertyID::eCSSProperty_%s" % ident
%>
</%def>

View file

@ -2,9 +2,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
use app_units::Au;
use cssparser::{Color as CSSParserColor, Parser, RGBA};
use euclid::{Point2D, Size2D};
#[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSPropertyID;
use properties::{DeclaredValue, PropertyDeclaration};
use properties::longhands;
use properties::longhands::background_position_x::computed_value::T as BackgroundPositionX;
@ -19,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;
@ -101,6 +105,40 @@ impl ToCss for TransitionProperty {
}
}
/// Convert to nsCSSPropertyID.
#[cfg(feature = "gecko")]
#[allow(non_upper_case_globals)]
impl From<TransitionProperty> for nsCSSPropertyID {
fn from(transition_property: TransitionProperty) -> nsCSSPropertyID {
match transition_property {
% for prop in data.longhands:
% if prop.animatable:
TransitionProperty::${prop.camel_case}
=> ${helpers.to_nscsspropertyid(prop.ident)},
% endif
% endfor
TransitionProperty::All => nsCSSPropertyID::eCSSPropertyExtra_all_properties,
}
}
}
/// Convert to PropertyDeclarationId.
#[cfg(feature = "gecko")]
#[allow(non_upper_case_globals)]
impl<'a> From<TransitionProperty> 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)]

View file

@ -830,7 +830,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
animatable="False",
extra_prefixes="moz webkit"
spec="https://drafts.csswg.org/css-animations/#propdef-animation-timing-function",
allowed_in_keyframe_block="False">
allowed_in_keyframe_block="True">
pub use properties::longhands::transition_timing_function::single_value::computed_value;
pub use properties::longhands::transition_timing_function::single_value::get_initial_value;
pub use properties::longhands::transition_timing_function::single_value::get_initial_specified_value;

View file

@ -737,16 +737,6 @@ enum StaticId {
Shorthand(ShorthandId),
}
include!(concat!(env!("OUT_DIR"), "/static_ids.rs"));
<%
def alias_to_nscsspropertyid(alias):
if alias == "word-wrap":
return "nsCSSPropertyID_eCSSPropertyAlias_WordWrap"
return "nsCSSPropertyID::eCSSPropertyAlias_%s" % to_camel_case(alias)
def to_nscsspropertyid(ident):
if ident == "float":
ident = "float_"
return "nsCSSPropertyID::eCSSProperty_%s" % ident
%>
impl PropertyId {
/// Returns a given property from the string `s`.
///
@ -771,21 +761,21 @@ impl PropertyId {
use gecko_bindings::structs::*;
match id {
% for property in data.longhands:
${to_nscsspropertyid(property.ident)} => {
${helpers.to_nscsspropertyid(property.ident)} => {
Ok(PropertyId::Longhand(LonghandId::${property.camel_case}))
}
% for alias in property.alias:
${alias_to_nscsspropertyid(alias)} => {
${helpers.alias_to_nscsspropertyid(alias)} => {
Ok(PropertyId::Longhand(LonghandId::${property.camel_case}))
}
% endfor
% endfor
% for property in data.shorthands:
${to_nscsspropertyid(property.ident)} => {
${helpers.to_nscsspropertyid(property.ident)} => {
Ok(PropertyId::Shorthand(ShorthandId::${property.camel_case}))
}
% for alias in property.alias:
${alias_to_nscsspropertyid(alias)} => {
${helpers.alias_to_nscsspropertyid(alias)} => {
Ok(PropertyId::Shorthand(ShorthandId::${property.camel_case}))
}
% endfor
@ -804,14 +794,14 @@ impl PropertyId {
PropertyId::Longhand(id) => match id {
% for property in data.longhands:
LonghandId::${property.camel_case} => {
Ok(${to_nscsspropertyid(property.ident)})
Ok(${helpers.to_nscsspropertyid(property.ident)})
}
% endfor
},
PropertyId::Shorthand(id) => match id {
% for property in data.shorthands:
ShorthandId::${property.camel_case} => {
Ok(${to_nscsspropertyid(property.ident)})
Ok(${helpers.to_nscsspropertyid(property.ident)})
}
% endfor
},
@ -921,7 +911,7 @@ impl ToCss for PropertyDeclaration {
pref_ident = "float_"
%>
if structs::root::mozilla::SERVO_PREF_ENABLED_${pref_ident} {
let id = structs::${to_nscsspropertyid(property.ident)};
let id = structs::${helpers.to_nscsspropertyid(property.ident)};
let enabled = unsafe { bindings::Gecko_PropertyId_IsPrefEnabled(id) };
if !enabled {
return PropertyDeclarationParseResult::ExperimentalProperty