Skip to content

Commit

Permalink
style: Generate StyleTimingFunction and drop ns_timing_function.rs.
Browse files Browse the repository at this point in the history
First, we generate StyleComputedTimingFunction by cbindgen from Rust, and use
it in nsTimingFunction, so we could copy it directly without handling
the different memory layout. However, we have to rewrite the
nsTimingFunction and mozilla::ComputedTimingFunction for this.

Second, the rust-bindgen seems cannot generate the correct generic members
from complex C++ templates, especially for the nested template struct,
(rust-lang/rust-bindgen#1429)
So we have to hide StyleTimingFunction to avoid the compilation errors.

Differential Revision: https://phabricator.services.mozilla.com/D9313
  • Loading branch information
BorisChiou authored and emilio committed Oct 28, 2018
1 parent 2bbcb5c commit 3723042
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 146 deletions.
2 changes: 2 additions & 0 deletions components/style/cbindgen.toml
Expand Up @@ -42,12 +42,14 @@ include = [
"StyleComputedFontStretchRange",
"StyleComputedFontStyleDescriptor",
"StyleComputedFontWeightRange",
"StyleComputedTimingFunction",
"StyleDisplay",
"StyleDisplayMode",
"StyleFillRule",
"StyleFontDisplay",
"StyleFontFaceSourceListComponent",
"StyleFontLanguageOverride",
"StyleTimingFunction",
"StylePathCommand",
"StyleUnicodeRange",
]
Expand Down
1 change: 0 additions & 1 deletion components/style/gecko_bindings/sugar/mod.rs
Expand Up @@ -12,7 +12,6 @@ pub mod ns_css_value;
mod ns_style_auto_array;
pub mod ns_style_coord;
mod ns_t_array;
mod ns_timing_function;
pub mod origin_flags;
pub mod ownership;
pub mod refptr;
Expand Down
139 changes: 0 additions & 139 deletions components/style/gecko_bindings/sugar/ns_timing_function.rs

This file was deleted.

12 changes: 8 additions & 4 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -2855,7 +2855,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_copy_animation_or_transition_value(type, ident, gecko_ffi_name, member=None)">
#[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());
Expand All @@ -2868,7 +2868,11 @@ fn static_assert() {
);

for (ours, others) in iter {
% if member:
ours.m${gecko_ffi_name}.${member} = others.m${gecko_ffi_name}.${member};
% else:
ours.m${gecko_ffi_name} = others.m${gecko_ffi_name};
% endif
}
}

Expand Down Expand Up @@ -2923,14 +2927,14 @@ fn static_assert() {

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.into();
gecko.mTimingFunction.mTiming = servo;
}
}
${impl_animation_or_transition_count(type, 'timing_function', 'TimingFunction')}
${impl_copy_animation_or_transition_value(type, 'timing_function', 'TimingFunction')}
${impl_copy_animation_or_transition_value(type, 'timing_function', "TimingFunction", "mTiming")}
pub fn ${type}_timing_function_at(&self, index: usize)
-> longhands::${type}_timing_function::computed_value::SingleComputedValue {
self.gecko.m${type.capitalize()}s[index].mTimingFunction.into()
self.gecko.m${type.capitalize()}s[index].mTimingFunction.mTiming
}
</%def>

Expand Down
7 changes: 5 additions & 2 deletions components/style/values/computed/easing.rs
Expand Up @@ -5,7 +5,10 @@
//! Computed types for CSS Easing functions.

use values::computed::{Integer, Number};
use values::generics::easing::TimingFunction as GenericTimingFunction;
use values::generics::easing;

/// A computed timing function.
pub type TimingFunction = GenericTimingFunction<Integer, Number>;
pub type ComputedTimingFunction = easing::TimingFunction<Integer, Number>;

/// An alias of the computed timing function.
pub type TimingFunction = ComputedTimingFunction;
3 changes: 3 additions & 0 deletions components/style/values/generics/easing.rs
Expand Up @@ -10,6 +10,7 @@ use values::CSSFloat;
/// A generic easing function.
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)]
#[value_info(ty = "TIMING_FUNCTION")]
#[repr(u8, C)]
pub enum TimingFunction<Integer, Number> {
/// `linear | ease | ease-in | ease-out | ease-in-out`
Keyword(TimingKeyword),
Expand Down Expand Up @@ -42,6 +43,7 @@ pub enum TimingFunction<Integer, Number> {
ToComputedValue,
ToCss,
)]
#[repr(u8)]
pub enum TimingKeyword {
Linear,
Ease,
Expand All @@ -53,6 +55,7 @@ pub enum TimingKeyword {
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToComputedValue, ToCss)]
#[repr(u8)]
pub enum StepPosition {
Start,
End,
Expand Down
24 changes: 24 additions & 0 deletions components/style/values/specified/easing.rs
Expand Up @@ -8,6 +8,7 @@ use cssparser::Parser;
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseErrorKind;
use style_traits::{ParseError, StyleParseErrorKind};
use values::computed::easing::TimingFunction as ComputedTimingFunction;
use values::generics::easing::{StepPosition, TimingKeyword};
use values::generics::easing::TimingFunction as GenericTimingFunction;
use values::specified::{Integer, Number};
Expand Down Expand Up @@ -71,3 +72,26 @@ impl Parse for TimingFunction {
})
}
}

// We need this for converting the specified TimingFunction into computed TimingFunction without
// Context (for some FFIs in glue.rs). In fact, we don't really need Context to get the computed
// value of TimingFunction.
impl TimingFunction {
/// Generate the ComputedTimingFunction without Context.
pub fn to_computed_value_without_context(&self) -> ComputedTimingFunction {
match *self {
GenericTimingFunction::Steps(steps, pos) => {
GenericTimingFunction::Steps(steps.value(), pos)
},
GenericTimingFunction::CubicBezier { x1, y1, x2, y2 } => {
GenericTimingFunction::CubicBezier {
x1: x1.get(),
y1: y1.get(),
x2: x2.get(),
y2: y2.get(),
}
},
GenericTimingFunction::Keyword(keyword) => GenericTimingFunction::Keyword(keyword),
}
}
}

0 comments on commit 3723042

Please sign in to comment.