From 1e2f9a0186f982bedca6c5a029eeb017e5b6dda3 Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Tue, 21 Mar 2017 01:36:49 -0700 Subject: [PATCH] servo: Merge #16055 - stylo: Bug 1343153 - Use servo css-parser for ParseEasing (from BorisChiou:stylo/animation/parse_easing); r=emilio These patches fix [Bug 1343153](https://bugzilla.mozilla.org/show_bug.cgi?id=1343153). --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix Bug 1343153 - [X] These changes do not require tests because gecko has enough test cases for web animations. Source-Repo: https://github.com/servo/servo Source-Revision: 5a656cfa54c7c125b309721f587d591d515999c2 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 05696cc5a76eecf0ace9e8b8f137c067014ba070 --- servo/components/style/build_gecko.rs | 1 + .../style/gecko_bindings/bindings.rs | 12 ++++++- servo/ports/geckolib/glue.rs | 35 +++++++++++++++---- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/servo/components/style/build_gecko.rs b/servo/components/style/build_gecko.rs index 15a9d06dc023..6cb3c77a8a65 100644 --- a/servo/components/style/build_gecko.rs +++ b/servo/components/style/build_gecko.rs @@ -691,6 +691,7 @@ mod bindings { ]; let servo_borrow_types = [ "nsCSSValue", + "nsTimingFunction", "RawGeckoAnimationValueList", "RawGeckoKeyframeList", "RawGeckoComputedKeyframeValuesList", diff --git a/servo/components/style/gecko_bindings/bindings.rs b/servo/components/style/gecko_bindings/bindings.rs index a5addcee8d3c..b28183c6ab38 100644 --- a/servo/components/style/gecko_bindings/bindings.rs +++ b/servo/components/style/gecko_bindings/bindings.rs @@ -263,6 +263,10 @@ pub type nsCSSValueBorrowed<'a> = &'a nsCSSValue; pub type nsCSSValueBorrowedOrNull<'a> = Option<&'a nsCSSValue>; pub type nsCSSValueBorrowedMut<'a> = &'a mut nsCSSValue; pub type nsCSSValueBorrowedMutOrNull<'a> = Option<&'a mut nsCSSValue>; +pub type nsTimingFunctionBorrowed<'a> = &'a nsTimingFunction; +pub type nsTimingFunctionBorrowedOrNull<'a> = Option<&'a nsTimingFunction>; +pub type nsTimingFunctionBorrowedMut<'a> = &'a mut nsTimingFunction; +pub type nsTimingFunctionBorrowedMutOrNull<'a> = Option<&'a mut nsTimingFunction>; pub type RawGeckoAnimationValueListBorrowed<'a> = &'a RawGeckoAnimationValueList; pub type RawGeckoAnimationValueListBorrowedOrNull<'a> = Option<&'a RawGeckoAnimationValueList>; pub type RawGeckoAnimationValueListBorrowedMut<'a> = &'a mut RawGeckoAnimationValueList; @@ -1390,7 +1394,7 @@ extern "C" { pub fn Servo_StyleSet_FillKeyframesForName(set: RawServoStyleSetBorrowed, property: *const nsACString, timing_function: - *const nsTimingFunction, + nsTimingFunctionBorrowed, computed_values: ServoComputedValuesBorrowed, keyframe_list: @@ -1487,6 +1491,12 @@ extern "C" { data: *const GeckoParserExtraData) -> RawServoDeclarationBlockStrong; } +extern "C" { + pub fn Servo_ParseEasing(easing: *const nsAString, + base: *const nsACString, + data: *const GeckoParserExtraData, + output: nsTimingFunctionBorrowedMut) -> bool; +} extern "C" { pub fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeListBorrowed, diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index 253e724a3635..3216b65acdbf 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -48,6 +48,8 @@ use style::gecko_bindings::bindings::RawServoAnimationValueStrong; use style::gecko_bindings::bindings::RawServoImportRuleBorrowed; use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull; use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t; +use style::gecko_bindings::bindings::nsTimingFunctionBorrowed; +use style::gecko_bindings::bindings::nsTimingFunctionBorrowedMut; use style::gecko_bindings::structs; use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom, nsCSSPropertyID}; use style::gecko_bindings::structs::{ThreadSafePrincipalHolder, ThreadSafeURIHolder}; @@ -56,7 +58,6 @@ use style::gecko_bindings::structs::Loader; use style::gecko_bindings::structs::RawGeckoPresContextOwned; use style::gecko_bindings::structs::ServoStyleSheet; use style::gecko_bindings::structs::nsCSSValueSharedList; -use style::gecko_bindings::structs::nsTimingFunction; use style::gecko_bindings::structs::nsresult; use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, HasBoxFFI}; use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong}; @@ -790,6 +791,27 @@ pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const } } +#[no_mangle] +pub extern "C" fn Servo_ParseEasing(easing: *const nsAString, + base: *const nsACString, + data: *const structs::GeckoParserExtraData, + output: nsTimingFunctionBorrowedMut) + -> bool { + use style::properties::longhands::transition_timing_function; + + make_context!((base, data) => (base_url, extra_data)); + let reporter = StdoutErrorReporter; + let context = ParserContext::new_with_extra_data(Origin::Author, &base_url, &reporter, extra_data); + let easing = unsafe { (*easing).to_string() }; + match transition_timing_function::single_value::parse(&context, &mut Parser::new(&easing)) { + Ok(parsed_easing) => { + *output = parsed_easing.into(); + true + }, + Err(_) => false + } +} + #[no_mangle] pub extern "C" fn Servo_ParseStyleAttribute(data: *const nsACString, base: *const nsACString, @@ -1617,7 +1639,7 @@ pub extern "C" fn Servo_AssertTreeIsClean(root: RawGeckoElementBorrowed) { #[no_mangle] pub extern "C" fn Servo_StyleSet_FillKeyframesForName(raw_data: RawServoStyleSetBorrowed, name: *const nsACString, - timing_function: *const nsTimingFunction, + timing_function: nsTimingFunctionBorrowed, style: ServoComputedValuesBorrowed, keyframes: RawGeckoKeyframeListBorrowedMut) -> bool { use style::gecko_bindings::structs::Keyframe; @@ -1626,7 +1648,6 @@ pub extern "C" fn Servo_StyleSet_FillKeyframesForName(raw_data: RawServoStyleSet let data = PerDocumentStyleData::from_ffi(raw_data).borrow(); 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) { @@ -1637,13 +1658,13 @@ pub extern "C" fn Servo_StyleSet_FillKeyframesForName(raw_data: RawServoStyleSet let timing_function = if let Some(val) = step.get_animation_timing_function(&guard) { val.into() } else { - *style_timing_function + *timing_function }; let keyframe = unsafe { - Gecko_AnimationAppendKeyframe(keyframes, - step.start_percentage.0 as f32, - &timing_function) + Gecko_AnimationAppendKeyframe(keyframes, + step.start_percentage.0 as f32, + &timing_function) }; fn add_computed_property_value(keyframe: *mut Keyframe,