servo: Merge #16640 - Use FunctionKeyword for computed_value of timing function (from hiikezoe:timing-function); r=xidorn

<!-- Please describe your changes on the following line: -->
https://bugzilla.mozilla.org/show_bug.cgi?id=1358330

---
<!-- 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
- [X] These changes fix #15086

<!-- Either: -->
- [X] These changes do not require tests because mozilla-central has test cases.  There might be some test cases in servo tree.

Source-Repo: https://github.com/servo/servo
Source-Revision: 93a513c06fe6e889efc5a3a52a1509298a81bb3e

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : a3f6ea4aaf3e6e44803cf28f06a1eb7f95bea784
This commit is contained in:
Hiroyuki Ikezoe 2017-04-28 22:49:26 -05:00
parent 0ced305cb6
commit e207a805fc
3 changed files with 65 additions and 43 deletions

View File

@ -339,19 +339,24 @@ impl PropertyAnimation {
/// Update the given animation at a given point of progress.
pub fn update(&self, style: &mut ComputedValues, time: f64) {
let progress = match self.timing_function {
let timing_function = match self.timing_function {
TransitionTimingFunction::Keyword(keyword) =>
keyword.to_non_keyword_value(),
other => other,
};
let progress = match timing_function {
TransitionTimingFunction::CubicBezier(p1, p2) => {
// See `WebCore::AnimationBase::solveEpsilon(double)` in WebKit.
let epsilon = 1.0 / (200.0 * (self.duration.seconds() as f64));
Bezier::new(Point2D::new(p1.x as f64, p1.y as f64),
Point2D::new(p2.x as f64, p2.y as f64)).solve(time, epsilon)
}
},
TransitionTimingFunction::Steps(steps, StartEnd::Start) => {
(time * (steps as f64)).ceil() / (steps as f64)
}
},
TransitionTimingFunction::Steps(steps, StartEnd::End) => {
(time * (steps as f64)).floor() / (steps as f64)
}
},
TransitionTimingFunction::Frames(frames) => {
// https://drafts.csswg.org/css-timing/#frames-timing-functions
let mut out = (time * (frames as f64)).floor() / ((frames - 1) as f64);
@ -367,7 +372,10 @@ impl PropertyAnimation {
out = 1.0;
}
out
}
},
TransitionTimingFunction::Keyword(_) => {
panic!("Keyword function should not appear")
},
};
self.property.update(style, progress);

View File

@ -9,6 +9,7 @@ use properties::longhands::transition_timing_function::single_value::SpecifiedVa
use properties::longhands::transition_timing_function::single_value::computed_value::StartEnd;
use properties::longhands::transition_timing_function::single_value::computed_value::T as ComputedTimingFunction;
use std::mem;
use values::computed::ToComputedValue;
impl nsTimingFunction {
fn set_as_step(&mut self, function_type: nsTimingFunction_Type, steps: u32) {
@ -46,23 +47,7 @@ impl nsTimingFunction {
impl From<ComputedTimingFunction> for nsTimingFunction {
fn from(function: ComputedTimingFunction) -> nsTimingFunction {
let mut tf: nsTimingFunction = unsafe { mem::zeroed() };
match function {
ComputedTimingFunction::Steps(steps, StartEnd::Start) => {
tf.set_as_step(nsTimingFunction_Type::StepStart, steps);
},
ComputedTimingFunction::Steps(steps, StartEnd::End) => {
tf.set_as_step(nsTimingFunction_Type::StepEnd, steps);
},
ComputedTimingFunction::Frames(frames) => {
tf.set_as_frames(frames);
},
ComputedTimingFunction::CubicBezier(p1, p2) => {
tf.set_as_bezier(nsTimingFunction_Type::CubicBezier, p1, p2);
},
}
tf
SpecifiedTimingFunction::from_computed_value(&function).into()
}
}
@ -89,7 +74,7 @@ impl From<SpecifiedTimingFunction> for nsTimingFunction {
Point2D::new(p2.x.get(), p2.y.get()));
},
SpecifiedTimingFunction::Keyword(keyword) => {
match keyword.to_computed_value() {
match keyword.to_non_keyword_value() {
ComputedTimingFunction::CubicBezier(p1, p2) => {
match keyword {
FunctionKeyword::Ease => {
@ -120,7 +105,10 @@ impl From<SpecifiedTimingFunction> for nsTimingFunction {
},
ComputedTimingFunction::Frames(frames) => {
tf.set_as_frames(frames)
}
},
ComputedTimingFunction::Keyword(_) => {
panic!("Keyword function should not appear")
},
}
},
}
@ -145,11 +133,21 @@ impl From<nsTimingFunction> for ComputedTimingFunction {
ComputedTimingFunction::Frames(
unsafe { function.__bindgen_anon_1.__bindgen_anon_1.as_ref().mStepsOrFrames })
}
nsTimingFunction_Type::Ease |
nsTimingFunction_Type::Linear |
nsTimingFunction_Type::EaseIn |
nsTimingFunction_Type::EaseOut |
nsTimingFunction_Type::EaseInOut |
nsTimingFunction_Type::Ease => {
ComputedTimingFunction::Keyword(FunctionKeyword::Ease)
},
nsTimingFunction_Type::Linear => {
ComputedTimingFunction::Keyword(FunctionKeyword::Linear)
},
nsTimingFunction_Type::EaseIn => {
ComputedTimingFunction::Keyword(FunctionKeyword::EaseIn)
},
nsTimingFunction_Type::EaseOut => {
ComputedTimingFunction::Keyword(FunctionKeyword::EaseOut)
},
nsTimingFunction_Type::EaseInOut => {
ComputedTimingFunction::Keyword(FunctionKeyword::EaseInOut)
},
nsTimingFunction_Type::CubicBezier => {
ComputedTimingFunction::CubicBezier(
TypedPoint2D::new(unsafe { function.__bindgen_anon_1.mFunc.as_ref().mX1 },

View File

@ -502,6 +502,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
use parser::{Parse, ParserContext};
use std::fmt;
use style_traits::ToCss;
use super::FunctionKeyword;
use values::specified;
pub use super::parse;
@ -512,6 +513,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
CubicBezier(Point2D<f32>, Point2D<f32>),
Steps(u32, StartEnd),
Frames(u32),
Keyword(FunctionKeyword),
}
impl ToCss for T {
@ -538,6 +540,9 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
try!(frames.to_css(dest));
dest.write_str(")")
},
T::Keyword(keyword) => {
super::serialize_keyword(dest, keyword)
}
}
}
}
@ -651,6 +656,22 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
dest.write_str(")")
}
fn serialize_keyword<W>(dest: &mut W, keyword: FunctionKeyword) -> fmt::Result
where W: fmt::Write,
{
match keyword {
FunctionKeyword::StepStart => {
serialize_steps(dest, specified::Integer::new(1), StartEnd::Start)
},
FunctionKeyword::StepEnd => {
serialize_steps(dest, specified::Integer::new(1), StartEnd::End)
},
_ => {
keyword.to_css(dest)
},
}
}
// https://drafts.csswg.org/css-transitions/#serializing-a-timing-function
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
@ -675,17 +696,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
dest.write_str(")")
},
SpecifiedValue::Keyword(keyword) => {
match keyword {
FunctionKeyword::StepStart => {
serialize_steps(dest, specified::Integer::new(1), StartEnd::Start)
},
FunctionKeyword::StepEnd => {
serialize_steps(dest, specified::Integer::new(1), StartEnd::End)
},
_ => {
keyword.to_css(dest)
},
}
serialize_keyword(dest, keyword)
},
}
}
@ -708,7 +719,9 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
SpecifiedValue::Frames(frames) => {
computed_value::T::Frames(frames.to_computed_value(context) as u32)
},
SpecifiedValue::Keyword(keyword) => keyword.to_computed_value(),
SpecifiedValue::Keyword(keyword) => {
computed_value::T::Keyword(keyword)
},
}
}
#[inline]
@ -729,13 +742,16 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
let frames = frames as i32;
SpecifiedValue::Frames(specified::Integer::from_computed_value(&frames))
},
computed_value::T::Keyword(keyword) => {
SpecifiedValue::Keyword(keyword)
},
}
}
}
impl FunctionKeyword {
#[inline]
pub fn to_computed_value(&self) -> computed_value::T {
pub fn to_non_keyword_value(&self) -> computed_value::T {
match *self {
FunctionKeyword::Ease => ease(),
FunctionKeyword::Linear => linear(),
@ -753,7 +769,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
#[inline]
pub fn get_initial_value() -> computed_value::T {
ease()
computed_value::T::Keyword(FunctionKeyword::Ease)
}
#[inline]