mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Auto merge of #17228 - hiikezoe:shorthand-for-SMIL, r=birtles
Shorthand support for SMIL <!-- Please describe your changes on the following line: --> This is a PR for https://bugzilla.mozilla.org/show_bug.cgi?id=1358966 --- <!-- 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 <!-- Either: --> - [X] These changes do not require tests because it's for stylo <!-- 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/17228) <!-- Reviewable:end -->
This commit is contained in:
commit
094c2c73ec
7 changed files with 4295 additions and 4245 deletions
|
@ -19,8 +19,8 @@ use gecko_bindings::structs::RawGeckoKeyframeList;
|
|||
use gecko_bindings::structs::RawGeckoComputedKeyframeValuesList;
|
||||
use gecko_bindings::structs::RawGeckoFontFaceRuleList;
|
||||
use gecko_bindings::structs::RawGeckoNode;
|
||||
use gecko_bindings::structs::RawGeckoAnimationValueList;
|
||||
use gecko_bindings::structs::RawServoAnimationValue;
|
||||
use gecko_bindings::structs::RawGeckoServoAnimationValueList;
|
||||
use gecko_bindings::structs::RawServoDeclarationBlock;
|
||||
use gecko_bindings::structs::RawServoStyleRule;
|
||||
use gecko_bindings::structs::RawGeckoPresContext;
|
||||
|
@ -276,10 +276,6 @@ pub type RawGeckoAnimationPropertySegmentBorrowed<'a> = &'a RawGeckoAnimationPro
|
|||
pub type RawGeckoAnimationPropertySegmentBorrowedOrNull<'a> = Option<&'a RawGeckoAnimationPropertySegment>;
|
||||
pub type RawGeckoAnimationPropertySegmentBorrowedMut<'a> = &'a mut RawGeckoAnimationPropertySegment;
|
||||
pub type RawGeckoAnimationPropertySegmentBorrowedMutOrNull<'a> = Option<&'a mut RawGeckoAnimationPropertySegment>;
|
||||
pub type RawGeckoAnimationValueListBorrowed<'a> = &'a RawGeckoAnimationValueList;
|
||||
pub type RawGeckoAnimationValueListBorrowedOrNull<'a> = Option<&'a RawGeckoAnimationValueList>;
|
||||
pub type RawGeckoAnimationValueListBorrowedMut<'a> = &'a mut RawGeckoAnimationValueList;
|
||||
pub type RawGeckoAnimationValueListBorrowedMutOrNull<'a> = Option<&'a mut RawGeckoAnimationValueList>;
|
||||
pub type RawGeckoComputedTimingBorrowed<'a> = &'a RawGeckoComputedTiming;
|
||||
pub type RawGeckoComputedTimingBorrowedOrNull<'a> = Option<&'a RawGeckoComputedTiming>;
|
||||
pub type RawGeckoComputedTimingBorrowedMut<'a> = &'a mut RawGeckoComputedTiming;
|
||||
|
@ -304,6 +300,10 @@ pub type RawGeckoServoStyleRuleListBorrowed<'a> = &'a RawGeckoServoStyleRuleList
|
|||
pub type RawGeckoServoStyleRuleListBorrowedOrNull<'a> = Option<&'a RawGeckoServoStyleRuleList>;
|
||||
pub type RawGeckoServoStyleRuleListBorrowedMut<'a> = &'a mut RawGeckoServoStyleRuleList;
|
||||
pub type RawGeckoServoStyleRuleListBorrowedMutOrNull<'a> = Option<&'a mut RawGeckoServoStyleRuleList>;
|
||||
pub type RawGeckoServoAnimationValueListBorrowed<'a> = &'a RawGeckoServoAnimationValueList;
|
||||
pub type RawGeckoServoAnimationValueListBorrowedOrNull<'a> = Option<&'a RawGeckoServoAnimationValueList>;
|
||||
pub type RawGeckoServoAnimationValueListBorrowedMut<'a> = &'a mut RawGeckoServoAnimationValueList;
|
||||
pub type RawGeckoServoAnimationValueListBorrowedMutOrNull<'a> = Option<&'a mut RawGeckoServoAnimationValueList>;
|
||||
pub type ServoCssRulesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoCssRules>;
|
||||
pub type ServoCssRulesBorrowed<'a> = &'a ServoCssRules;
|
||||
pub type ServoCssRulesBorrowedOrNull<'a> = Option<&'a ServoCssRules>;
|
||||
|
@ -759,8 +759,6 @@ extern "C" {
|
|||
ServoComputedValuesBorrowedOrNull,
|
||||
aComputedValues:
|
||||
ServoComputedValuesBorrowedOrNull,
|
||||
aParentComputedValues:
|
||||
ServoComputedValuesBorrowedOrNull,
|
||||
aTasks: UpdateAnimationsTasks);
|
||||
}
|
||||
extern "C" {
|
||||
|
@ -2254,6 +2252,15 @@ extern "C" {
|
|||
progress: f64,
|
||||
result: *mut RawGeckoGfxMatrix4x4);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_GetAnimationValues(declarations:
|
||||
RawServoDeclarationBlockBorrowed,
|
||||
element: RawGeckoElementBorrowed,
|
||||
style: ServoComputedValuesBorrowed,
|
||||
style_set: RawServoStyleSetBorrowed,
|
||||
animation_values:
|
||||
RawGeckoServoAnimationValueListBorrowedMut);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_AnimationValues_Interpolate(from:
|
||||
RawServoAnimationValueBorrowed,
|
||||
|
@ -2298,6 +2305,13 @@ extern "C" {
|
|||
property: nsCSSPropertyID,
|
||||
buffer: *mut nsAString);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_Shorthand_AnimationValues_Serialize(shorthand_property:
|
||||
nsCSSPropertyID,
|
||||
values:
|
||||
RawGeckoServoAnimationValueListBorrowed,
|
||||
buffer: *mut nsAString);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_AnimationValue_GetOpacity(value:
|
||||
RawServoAnimationValueBorrowed)
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -874,20 +874,12 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
computed_data.as_ref().map(|d| d.styles().primary.values());
|
||||
let computed_values_opt =
|
||||
computed_values.map(|v| *HasArcFFI::arc_as_borrowed(v));
|
||||
let parent_element = self.parent_element();
|
||||
let parent_data =
|
||||
parent_element.as_ref().and_then(|e| e.borrow_data());
|
||||
let parent_values =
|
||||
parent_data.as_ref().map(|d| d.styles().primary.values());
|
||||
let parent_values_opt =
|
||||
parent_values.map(|v| *HasArcFFI::arc_as_borrowed(v));
|
||||
let before_change_values =
|
||||
before_change_style.as_ref().map(|v| *HasArcFFI::arc_as_borrowed(v));
|
||||
unsafe {
|
||||
Gecko_UpdateAnimations(self.0,
|
||||
before_change_values,
|
||||
computed_values_opt,
|
||||
parent_values_opt,
|
||||
tasks.bits());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use cssparser::{DeclarationListParser, parse_important};
|
|||
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter};
|
||||
use error_reporting::ParseErrorReporter;
|
||||
use parser::{PARSING_MODE_DEFAULT, ParsingMode, ParserContext, log_css_error};
|
||||
use properties::animated_properties::AnimationValue;
|
||||
use shared_lock::Locked;
|
||||
use std::fmt;
|
||||
use std::slice::Iter;
|
||||
|
@ -18,6 +19,7 @@ use style_traits::ToCss;
|
|||
use stylesheets::{CssRuleType, Origin, UrlExtraData};
|
||||
use stylesheets::{MallocSizeOf, MallocSizeOfFn};
|
||||
use super::*;
|
||||
use values::computed::Context;
|
||||
#[cfg(feature = "gecko")] use properties::animated_properties::AnimationValueMap;
|
||||
|
||||
/// The animation rules.
|
||||
|
@ -102,6 +104,55 @@ impl<'a> Iterator for PropertyDeclarationIterator<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Iterator for AnimationValue to be generated from PropertyDeclarationBlock.
|
||||
pub struct AnimationValueIterator<'a, 'cx, 'cx_a:'cx> {
|
||||
iter: Iter<'a, (PropertyDeclaration, Importance)>,
|
||||
context: &'cx mut Context<'cx_a>,
|
||||
default_values: &'a Arc<ComputedValues>,
|
||||
}
|
||||
|
||||
impl<'a, 'cx, 'cx_a:'cx> AnimationValueIterator<'a, 'cx, 'cx_a> {
|
||||
fn new(declarations: &'a PropertyDeclarationBlock,
|
||||
context: &'cx mut Context<'cx_a>,
|
||||
default_values: &'a Arc<ComputedValues>) -> AnimationValueIterator<'a, 'cx, 'cx_a> {
|
||||
AnimationValueIterator {
|
||||
iter: declarations.declarations().iter(),
|
||||
context: context,
|
||||
default_values: default_values,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'cx, 'cx_a:'cx> Iterator for AnimationValueIterator<'a, 'cx, 'cx_a> {
|
||||
type Item = (TransitionProperty, AnimationValue);
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
use properties::Importance;
|
||||
|
||||
loop {
|
||||
let next = self.iter.next();
|
||||
match next {
|
||||
Some(&(ref decl, importance)) => {
|
||||
if importance == Importance::Normal {
|
||||
let property = TransitionProperty::from_declaration(decl);
|
||||
let animation = AnimationValue::from_declaration(decl, &mut self.context,
|
||||
self.default_values);
|
||||
debug_assert!(property.is_none() == animation.is_none(),
|
||||
"The failure condition of TransitionProperty::from_declaration \
|
||||
and AnimationValue::from_declaration should be the same");
|
||||
// Skip the property if either ::from_declaration fails.
|
||||
match (property, animation) {
|
||||
(Some(p), Some(a)) => return Some((p, a)),
|
||||
(_, _) => {},
|
||||
}
|
||||
}
|
||||
},
|
||||
None => return None,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for PropertyDeclarationBlock {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.declarations.fmt(f)
|
||||
|
@ -148,6 +199,14 @@ impl PropertyDeclarationBlock {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return an iterator of (TransitionProperty, AnimationValue).
|
||||
pub fn to_animation_value_iter<'a, 'cx, 'cx_a:'cx>(&'a self,
|
||||
context: &'cx mut Context<'cx_a>,
|
||||
default_values: &'a Arc<ComputedValues>)
|
||||
-> AnimationValueIterator<'a, 'cx, 'cx_a> {
|
||||
AnimationValueIterator::new(self, context, default_values)
|
||||
}
|
||||
|
||||
/// Returns whether this block contains any declaration with `!important`.
|
||||
///
|
||||
/// This is based on the `important_count` counter,
|
||||
|
|
|
@ -199,6 +199,16 @@ pub fn nscsspropertyid_is_animatable(property: nsCSSPropertyID) -> bool {
|
|||
${helpers.to_nscsspropertyid(prop.ident)} => true,
|
||||
% endif
|
||||
% endfor
|
||||
% for prop in data.shorthands_except_all():
|
||||
<%
|
||||
animatable = "false"
|
||||
for sub in prop.sub_properties:
|
||||
if sub.animatable:
|
||||
animatable = "true"
|
||||
break
|
||||
%>
|
||||
${helpers.to_nscsspropertyid(prop.ident)} => ${animatable},
|
||||
% endfor
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,8 @@ use style::gecko_bindings::bindings::RawGeckoCSSPropertyIDListBorrowed;
|
|||
use style::gecko_bindings::bindings::RawGeckoComputedKeyframeValuesListBorrowedMut;
|
||||
use style::gecko_bindings::bindings::RawGeckoComputedTimingBorrowed;
|
||||
use style::gecko_bindings::bindings::RawGeckoFontFaceRuleListBorrowedMut;
|
||||
use style::gecko_bindings::bindings::RawGeckoServoAnimationValueListBorrowed;
|
||||
use style::gecko_bindings::bindings::RawGeckoServoAnimationValueListBorrowedMut;
|
||||
use style::gecko_bindings::bindings::RawGeckoServoStyleRuleListBorrowedMut;
|
||||
use style::gecko_bindings::bindings::RawServoAnimationValueBorrowed;
|
||||
use style::gecko_bindings::bindings::RawServoAnimationValueMapBorrowedMut;
|
||||
|
@ -89,7 +91,7 @@ use style::media_queries::{MediaList, parse_media_query_list};
|
|||
use style::parallel;
|
||||
use style::parser::{PARSING_MODE_DEFAULT, ParserContext};
|
||||
use style::properties::{CascadeFlags, ComputedValues, Importance, SourcePropertyDeclaration};
|
||||
use style::properties::{LonghandIdSet, PropertyDeclarationBlock, PropertyId, StyleBuilder};
|
||||
use style::properties::{LonghandIdSet, PropertyDeclaration, PropertyDeclarationBlock, PropertyId, StyleBuilder};
|
||||
use style::properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
|
||||
use style::properties::animated_properties::{Animatable, AnimationValue, TransitionProperty};
|
||||
use style::properties::parse_one_declaration_into;
|
||||
|
@ -556,7 +558,34 @@ pub extern "C" fn Servo_AnimationValue_Serialize(value: RawServoAnimationValueBo
|
|||
.single_value_to_css(&get_property_id_from_nscsspropertyid!(property, ()), &mut string);
|
||||
debug_assert!(rv.is_ok());
|
||||
|
||||
write!(unsafe { &mut *buffer }, "{}", string).expect("Failed to copy string");
|
||||
let buffer = unsafe { buffer.as_mut().unwrap() };
|
||||
buffer.assign_utf8(&string);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_Shorthand_AnimationValues_Serialize(shorthand_property: nsCSSPropertyID,
|
||||
values: RawGeckoServoAnimationValueListBorrowed,
|
||||
buffer: *mut nsAString)
|
||||
{
|
||||
let property_id = get_property_id_from_nscsspropertyid!(shorthand_property, ());
|
||||
let shorthand = match property_id.as_shorthand() {
|
||||
Ok(shorthand) => shorthand,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
// Convert RawServoAnimationValue(s) into a vector of PropertyDeclaration
|
||||
// so that we can use reference of the PropertyDeclaration without worrying
|
||||
// about its lifetime. (longhands_to_css() expects &PropertyDeclaration
|
||||
// iterator.)
|
||||
let declarations: Vec<PropertyDeclaration> =
|
||||
values.iter().map(|v| AnimationValue::as_arc(unsafe { &&*v.mRawPtr }).uncompute()).collect();
|
||||
|
||||
let mut string = String::new();
|
||||
let rv = shorthand.longhands_to_css(declarations.iter(), &mut string);
|
||||
if rv.is_ok() {
|
||||
let buffer = unsafe { buffer.as_mut().unwrap() };
|
||||
buffer.assign_utf8(&string);
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -1695,7 +1724,8 @@ pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
|
|||
let rv = decls.single_value_to_css(&property_id, &mut string);
|
||||
debug_assert!(rv.is_ok());
|
||||
|
||||
write!(unsafe { &mut *buffer }, "{}", string).expect("Failed to copy string");
|
||||
let buffer = unsafe { buffer.as_mut().unwrap() };
|
||||
buffer.assign_utf8(&string);
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1718,7 +1748,8 @@ pub extern "C" fn Servo_SerializeFontValueForCanvas(
|
|||
let rv = longhands.to_css_for_canvas(&mut string);
|
||||
debug_assert!(rv.is_ok());
|
||||
|
||||
write!(unsafe { &mut *buffer }, "{}", string).expect("Failed to copy string");
|
||||
let buffer = unsafe { buffer.as_mut().unwrap() };
|
||||
buffer.assign_utf8(&string);
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -2581,7 +2612,6 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis
|
|||
{
|
||||
use std::mem;
|
||||
use style::properties::LonghandIdSet;
|
||||
use style::properties::declaration_block::Importance;
|
||||
|
||||
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
|
@ -2616,28 +2646,7 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis
|
|||
let declarations = Locked::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||
let guard = declarations.read_with(&guard);
|
||||
|
||||
let anim_iter = guard.declarations()
|
||||
.iter()
|
||||
.filter_map(|&(ref decl, imp)| {
|
||||
if imp == Importance::Normal {
|
||||
let property = TransitionProperty::from_declaration(decl);
|
||||
let animation = AnimationValue::from_declaration(decl, &mut context,
|
||||
default_values);
|
||||
debug_assert!(property.is_none() == animation.is_none(),
|
||||
"The failure condition of TransitionProperty::from_declaration \
|
||||
and AnimationValue::from_declaration should be the same");
|
||||
// Skip the property if either ::from_declaration fails.
|
||||
if property.is_none() || animation.is_none() {
|
||||
None
|
||||
} else {
|
||||
Some((property.unwrap(), animation.unwrap()))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
|
||||
for anim in anim_iter {
|
||||
for anim in guard.to_animation_value_iter(&mut context, &default_values) {
|
||||
if !seen.has_transition_property_bit(&anim.0) {
|
||||
// This is safe since we immediately write to the uninitialized values.
|
||||
unsafe { animation_values.set_len((property_index + 1) as u32) };
|
||||
|
@ -2655,6 +2664,35 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis
|
|||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_GetAnimationValues(declarations: RawServoDeclarationBlockBorrowed,
|
||||
element: RawGeckoElementBorrowed,
|
||||
style: ServoComputedValuesBorrowed,
|
||||
raw_data: RawServoStyleSetBorrowed,
|
||||
animation_values: RawGeckoServoAnimationValueListBorrowedMut) {
|
||||
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let style = ComputedValues::as_arc(&style);
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
|
||||
let element = GeckoElement(element);
|
||||
let parent_element = element.inheritance_parent();
|
||||
let parent_data = parent_element.as_ref().and_then(|e| e.borrow_data());
|
||||
let parent_style = parent_data.as_ref().map(|d| d.styles().primary.values());
|
||||
|
||||
let mut context = create_context(&data, &metrics, style, &parent_style);
|
||||
|
||||
let default_values = data.default_computed_values();
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
|
||||
let declarations = Locked::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||
let guard = declarations.read_with(&guard);
|
||||
for (index, anim) in guard.to_animation_value_iter(&mut context, &default_values).enumerate() {
|
||||
unsafe { animation_values.set_len((index + 1) as u32) };
|
||||
animation_values[index].set_arc_leaky(Arc::new(anim.1));
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_AnimationValue_Compute(element: RawGeckoElementBorrowed,
|
||||
declarations: RawServoDeclarationBlockBorrowed,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue