mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Remove some duplicated code for coordinated properties
Differential Revision: https://phabricator.services.mozilla.com/D167130
This commit is contained in:
parent
fe8cdbe328
commit
979637de7d
1 changed files with 30 additions and 120 deletions
|
@ -994,7 +994,7 @@ fn static_assert() {
|
|||
${impl_simple_copy('_moz_min_font_size_ratio', 'mMinFontSizeRatio')}
|
||||
</%self:impl_trait>
|
||||
|
||||
<%def name="impl_copy_animation_or_transition_value(type, ident, gecko_ffi_name)">
|
||||
<%def name="impl_coordinated_property_copy(type, ident, gecko_ffi_name)">
|
||||
#[allow(non_snake_case)]
|
||||
pub fn copy_${type}_${ident}_from(&mut self, other: &Self) {
|
||||
self.gecko.m${type.capitalize()}s.ensure_len(other.gecko.m${type.capitalize()}s.len());
|
||||
|
@ -1010,25 +1010,25 @@ fn static_assert() {
|
|||
ours.m${gecko_ffi_name} = others.m${gecko_ffi_name}.clone();
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn reset_${type}_${ident}(&mut self, other: &Self) {
|
||||
self.copy_${type}_${ident}_from(other)
|
||||
}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_animation_or_transition_count(type, ident, gecko_ffi_name)">
|
||||
<%def name="impl_coordinated_property_count(type, ident, gecko_ffi_name)">
|
||||
#[allow(non_snake_case)]
|
||||
pub fn ${type}_${ident}_count(&self) -> usize {
|
||||
self.gecko.m${type.capitalize()}${gecko_ffi_name}Count as usize
|
||||
}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_animation_or_transition_time_value(type, ident, gecko_ffi_name)">
|
||||
<%def name="impl_coordinated_property(type, ident, gecko_ffi_name)">
|
||||
#[allow(non_snake_case)]
|
||||
pub fn set_${type}_${ident}<I>(&mut self, v: I)
|
||||
where I: IntoIterator<Item = longhands::${type}_${ident}::computed_value::single_value::T>,
|
||||
I::IntoIter: ExactSizeIterator + Clone
|
||||
where
|
||||
I: IntoIterator<Item = longhands::${type}_${ident}::computed_value::single_value::T>,
|
||||
I::IntoIter: ExactSizeIterator + Clone
|
||||
{
|
||||
let v = v.into_iter();
|
||||
debug_assert_ne!(v.len(), 0);
|
||||
|
@ -1043,61 +1043,18 @@ fn static_assert() {
|
|||
#[allow(non_snake_case)]
|
||||
pub fn ${type}_${ident}_at(&self, index: usize)
|
||||
-> longhands::${type}_${ident}::computed_value::SingleComputedValue {
|
||||
self.gecko.m${type.capitalize()}s[index].m${gecko_ffi_name}
|
||||
self.gecko.m${type.capitalize()}s[index % self.${type}_${ident}_count()].m${gecko_ffi_name}.clone()
|
||||
}
|
||||
${impl_animation_or_transition_count(type, ident, gecko_ffi_name)}
|
||||
${impl_copy_animation_or_transition_value(type, ident, gecko_ffi_name)}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_animation_or_transition_timing_function(type)">
|
||||
pub fn set_${type}_timing_function<I>(&mut self, v: I)
|
||||
where I: IntoIterator<Item = longhands::${type}_timing_function::computed_value::single_value::T>,
|
||||
I::IntoIter: ExactSizeIterator + Clone
|
||||
{
|
||||
let v = v.into_iter();
|
||||
debug_assert_ne!(v.len(), 0);
|
||||
let input_len = v.len();
|
||||
self.gecko.m${type.capitalize()}s.ensure_len(input_len);
|
||||
|
||||
self.gecko.m${type.capitalize()}TimingFunctionCount = input_len as u32;
|
||||
for (gecko, servo) in self.gecko.m${type.capitalize()}s.iter_mut().take(input_len as usize).zip(v) {
|
||||
gecko.mTimingFunction = servo;
|
||||
}
|
||||
}
|
||||
${impl_animation_or_transition_count(type, 'timing_function', 'TimingFunction')}
|
||||
${impl_copy_animation_or_transition_value(type, 'timing_function', "TimingFunction")}
|
||||
pub fn ${type}_timing_function_at(&self, index: usize)
|
||||
-> longhands::${type}_timing_function::computed_value::SingleComputedValue {
|
||||
self.gecko.m${type.capitalize()}s[index].mTimingFunction.clone()
|
||||
}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_transition_time_value(ident, gecko_ffi_name)">
|
||||
${impl_animation_or_transition_time_value('transition', ident, gecko_ffi_name)}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_transition_count(ident, gecko_ffi_name)">
|
||||
${impl_animation_or_transition_count('transition', ident, gecko_ffi_name)}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_copy_animation_value(ident, gecko_ffi_name)">
|
||||
${impl_copy_animation_or_transition_value('animation', ident, gecko_ffi_name)}
|
||||
</%def>
|
||||
|
||||
|
||||
<%def name="impl_animation_count(ident, gecko_ffi_name)">
|
||||
${impl_animation_or_transition_count('animation', ident, gecko_ffi_name)}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_animation_time_value(ident, gecko_ffi_name)">
|
||||
${impl_animation_or_transition_time_value('animation', ident, gecko_ffi_name)}
|
||||
${impl_coordinated_property_copy(type, ident, gecko_ffi_name)}
|
||||
${impl_coordinated_property_count(type, ident, gecko_ffi_name)}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_animation_keyword(ident, gecko_ffi_name, keyword, cast_type='u8')">
|
||||
#[allow(non_snake_case)]
|
||||
pub fn set_animation_${ident}<I>(&mut self, v: I)
|
||||
where I: IntoIterator<Item = longhands::animation_${ident}::computed_value::single_value::T>,
|
||||
I::IntoIter: ExactSizeIterator + Clone
|
||||
where
|
||||
I: IntoIterator<Item = longhands::animation_${ident}::computed_value::single_value::T>,
|
||||
I::IntoIter: ExactSizeIterator + Clone
|
||||
{
|
||||
use crate::properties::longhands::animation_${ident}::single_value::computed_value::T as Keyword;
|
||||
|
||||
|
@ -1132,8 +1089,8 @@ fn static_assert() {
|
|||
% endif
|
||||
}
|
||||
}
|
||||
${impl_animation_count(ident, gecko_ffi_name)}
|
||||
${impl_copy_animation_value(ident, gecko_ffi_name)}
|
||||
${impl_coordinated_property_copy('animation', ident, gecko_ffi_name)}
|
||||
${impl_coordinated_property_count('animation', ident, gecko_ffi_name)}
|
||||
</%def>
|
||||
|
||||
<% skip_box_longhands= """display contain""" %>
|
||||
|
@ -1766,9 +1723,9 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask-
|
|||
transition-timing-function transition-property""" %>
|
||||
|
||||
<%self:impl_trait style_struct_name="UI" skip_longhands="${skip_ui_longhands}">
|
||||
${impl_transition_time_value('delay', 'Delay')}
|
||||
${impl_transition_time_value('duration', 'Duration')}
|
||||
${impl_animation_or_transition_timing_function('transition')}
|
||||
${impl_coordinated_property('transition', 'delay', 'Delay')}
|
||||
${impl_coordinated_property('transition', 'duration', 'Duration')}
|
||||
${impl_coordinated_property('transition', 'timing_function', 'TimingFunction')}
|
||||
|
||||
pub fn transition_combined_duration_at(&self, index: usize) -> Time {
|
||||
// https://drafts.csswg.org/css-transitions/#transition-combined-duration
|
||||
|
@ -1779,8 +1736,9 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask-
|
|||
}
|
||||
|
||||
pub fn set_transition_property<I>(&mut self, v: I)
|
||||
where I: IntoIterator<Item = longhands::transition_property::computed_value::single_value::T>,
|
||||
I::IntoIter: ExactSizeIterator
|
||||
where
|
||||
I: IntoIterator<Item = longhands::transition_property::computed_value::single_value::T>,
|
||||
I::IntoIter: ExactSizeIterator
|
||||
{
|
||||
use crate::gecko_bindings::structs::nsCSSPropertyID::eCSSPropertyExtra_no_properties;
|
||||
use crate::gecko_bindings::structs::nsCSSPropertyID::eCSSPropertyExtra_variable;
|
||||
|
@ -1884,7 +1842,7 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask-
|
|||
self.copy_transition_property_from(other)
|
||||
}
|
||||
|
||||
${impl_transition_count('property', 'Property')}
|
||||
${impl_coordinated_property_count('transition', 'property', 'Property')}
|
||||
|
||||
pub fn animations_equals(&self, other: &Self) -> bool {
|
||||
return self.gecko.mAnimationNameCount == other.gecko.mAnimationNameCount
|
||||
|
@ -1901,8 +1859,9 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask-
|
|||
}
|
||||
|
||||
pub fn set_animation_name<I>(&mut self, v: I)
|
||||
where I: IntoIterator<Item = longhands::animation_name::computed_value::single_value::T>,
|
||||
I::IntoIter: ExactSizeIterator
|
||||
where
|
||||
I: IntoIterator<Item = longhands::animation_name::computed_value::single_value::T>,
|
||||
I::IntoIter: ExactSizeIterator
|
||||
{
|
||||
let v = v.into_iter();
|
||||
debug_assert_ne!(v.len(), 0);
|
||||
|
@ -1930,11 +1889,9 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask-
|
|||
self.copy_animation_name_from(other)
|
||||
}
|
||||
|
||||
${impl_animation_count('name', 'Name')}
|
||||
|
||||
${impl_animation_time_value('delay', 'Delay')}
|
||||
${impl_animation_time_value('duration', 'Duration')}
|
||||
|
||||
${impl_coordinated_property_count('animation', 'name', 'Name')}
|
||||
${impl_coordinated_property('animation', 'delay', 'Delay')}
|
||||
${impl_coordinated_property('animation', 'duration', 'Duration')}
|
||||
${impl_animation_keyword('direction', 'Direction',
|
||||
data.longhands_by_name["animation-direction"].keyword)}
|
||||
${impl_animation_keyword('fill_mode', 'FillMode',
|
||||
|
@ -1943,56 +1900,9 @@ mask-mode mask-repeat mask-clip mask-origin mask-composite mask-position-x mask-
|
|||
data.longhands_by_name["animation-play-state"].keyword)}
|
||||
${impl_animation_keyword('composition', 'Composition',
|
||||
data.longhands_by_name["animation-composition"].keyword)}
|
||||
|
||||
pub fn set_animation_iteration_count<I>(&mut self, v: I)
|
||||
where
|
||||
I: IntoIterator<Item = values::computed::AnimationIterationCount>,
|
||||
I::IntoIter: ExactSizeIterator + Clone
|
||||
{
|
||||
let v = v.into_iter();
|
||||
|
||||
debug_assert_ne!(v.len(), 0);
|
||||
let input_len = v.len();
|
||||
self.gecko.mAnimations.ensure_len(input_len);
|
||||
|
||||
self.gecko.mAnimationIterationCountCount = input_len as u32;
|
||||
for (gecko, servo) in self.gecko.mAnimations.iter_mut().take(input_len as usize).zip(v) {
|
||||
gecko.mIterationCount = servo;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn animation_iteration_count_at(
|
||||
&self,
|
||||
index: usize,
|
||||
) -> values::computed::AnimationIterationCount {
|
||||
self.gecko.mAnimations[index].mIterationCount
|
||||
}
|
||||
|
||||
${impl_animation_count('iteration_count', 'IterationCount')}
|
||||
${impl_copy_animation_value('iteration_count', 'IterationCount')}
|
||||
${impl_animation_or_transition_timing_function('animation')}
|
||||
|
||||
pub fn set_animation_timeline<I>(&mut self, v: I)
|
||||
where
|
||||
I: IntoIterator<Item = longhands::animation_timeline::computed_value::single_value::T>,
|
||||
I::IntoIter: ExactSizeIterator
|
||||
{
|
||||
let v = v.into_iter();
|
||||
debug_assert_ne!(v.len(), 0);
|
||||
let input_len = v.len();
|
||||
self.gecko.mAnimations.ensure_len(input_len);
|
||||
|
||||
self.gecko.mAnimationTimelineCount = input_len as u32;
|
||||
for (gecko, servo) in self.gecko.mAnimations.iter_mut().take(input_len as usize).zip(v) {
|
||||
gecko.mTimeline = servo;
|
||||
}
|
||||
}
|
||||
pub fn animation_timeline_at(&self, index: usize) -> values::specified::box_::AnimationTimeline {
|
||||
self.gecko.mAnimations[index].mTimeline.clone()
|
||||
}
|
||||
${impl_animation_count('timeline', 'Timeline')}
|
||||
${impl_copy_animation_value('timeline', 'Timeline')}
|
||||
|
||||
${impl_coordinated_property('animation', 'iteration_count', 'IterationCount')}
|
||||
${impl_coordinated_property('animation', 'timeline', 'Timeline')}
|
||||
${impl_coordinated_property('animation', 'timing_function', 'TimingFunction')}
|
||||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="XUL">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue