Use traits for animation timing functions
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jan 2018 18:45:45 +0000 (18:45 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Jan 2018 18:45:45 +0000 (18:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181651

Patch by Antoine Quint <graouts@apple.com> on 2018-01-16
Reviewed by Dean Jackson.

Cleaning up Dean's previous patch as suggested by Darin's post-commit review comments. The
downcast function can match const automatically and it's a better style to put the * inside
the downcast call rather than outside.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::createTimingFunctionValue):
* platform/animation/TimingFunction.cpp:
(WebCore::operator<<):
(WebCore::TimingFunction::transformTime const):
* platform/animation/TimingFunction.h:
* platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm:
(WebCore::toCAMediaTimingFunction):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226976 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/platform/animation/TimingFunction.cpp
Source/WebCore/platform/animation/TimingFunction.h
Source/WebCore/platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm

index 27eedb2741d23ac7e5dd2cba367085954a97c194..6a3001f5c2a5f070aae58b44d6b968bfddc6e338 100644 (file)
@@ -1,3 +1,23 @@
+2018-01-16  Antoine Quint  <graouts@apple.com>
+
+        Use traits for animation timing functions
+        https://bugs.webkit.org/show_bug.cgi?id=181651
+
+        Reviewed by Dean Jackson.
+
+        Cleaning up Dean's previous patch as suggested by Darin's post-commit review comments. The
+        downcast function can match const automatically and it's a better style to put the * inside
+        the downcast call rather than outside.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::createTimingFunctionValue):
+        * platform/animation/TimingFunction.cpp:
+        (WebCore::operator<<):
+        (WebCore::TimingFunction::transformTime const):
+        * platform/animation/TimingFunction.h:
+        * platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm:
+        (WebCore::toCAMediaTimingFunction):
+
 2018-01-16  Philippe Normand  <pnormand@igalia.com>
 
         [GStreamer] Live streaming cleanups
index d0b11336d536767de5aa933c99db055b58362305..7b3ff32f0e9ed3158cc829b0aa550bd88b20d6e0 100644 (file)
@@ -1542,7 +1542,7 @@ static Ref<CSSValue> createTimingFunctionValue(const TimingFunction& timingFunct
 {
     switch (timingFunction.type()) {
     case TimingFunction::CubicBezierFunction: {
-        auto& function = downcast<const CubicBezierTimingFunction>(timingFunction);
+        auto& function = downcast<CubicBezierTimingFunction>(timingFunction);
         if (function.timingFunctionPreset() != CubicBezierTimingFunction::Custom) {
             CSSValueID valueId = CSSValueInvalid;
             switch (function.timingFunctionPreset()) {
@@ -1565,15 +1565,15 @@ static Ref<CSSValue> createTimingFunctionValue(const TimingFunction& timingFunct
         return CSSCubicBezierTimingFunctionValue::create(function.x1(), function.y1(), function.x2(), function.y2());
     }
     case TimingFunction::StepsFunction: {
-        auto& function = downcast<const StepsTimingFunction>(timingFunction);
+        auto& function = downcast<StepsTimingFunction>(timingFunction);
         return CSSStepsTimingFunctionValue::create(function.numberOfSteps(), function.stepAtStart());
     }
     case TimingFunction::FramesFunction: {
-        auto& function = downcast<const FramesTimingFunction>(timingFunction);
+        auto& function = downcast<FramesTimingFunction>(timingFunction);
         return CSSFramesTimingFunctionValue::create(function.numberOfFrames());
     }
     case TimingFunction::SpringFunction: {
-        auto& function = downcast<const SpringTimingFunction>(timingFunction);
+        auto& function = downcast<SpringTimingFunction>(timingFunction);
         return CSSSpringTimingFunctionValue::create(function.mass(), function.stiffness(), function.damping(), function.initialVelocity());
     }
     default:
index d4d73cff32110506b1023759158fbedf3f7f352b..507543ce4a2c66270e631118aabe1735c57432a3 100644 (file)
@@ -39,22 +39,22 @@ TextStream& operator<<(TextStream& ts, const TimingFunction& timingFunction)
         ts << "linear";
         break;
     case TimingFunction::CubicBezierFunction: {
-        auto& function = static_cast<const CubicBezierTimingFunction&>(timingFunction);
+        auto& function = downcast<CubicBezierTimingFunction>(timingFunction);
         ts << "cubic-bezier(" << function.x1() << ", " << function.y1() << ", " <<  function.x2() << ", " << function.y2() << ")";
         break;
     }
     case TimingFunction::StepsFunction: {
-        auto& function = static_cast<const StepsTimingFunction&>(timingFunction);
+        auto& function = downcast<StepsTimingFunction>(timingFunction);
         ts << "steps(" << function.numberOfSteps() << ", " << (function.stepAtStart() ? "start" : "end") << ")";
         break;
     }
     case TimingFunction::FramesFunction: {
-        auto& function = static_cast<const FramesTimingFunction&>(timingFunction);
+        auto& function = downcast<FramesTimingFunction>(timingFunction);
         ts << "frames(" << function.numberOfFrames() << ")";
         break;
     }
     case TimingFunction::SpringFunction: {
-        auto& function = static_cast<const SpringTimingFunction&>(timingFunction);
+        auto& function = downcast<SpringTimingFunction>(timingFunction);
         ts << "spring(" << function.mass() << " " << function.stiffness() << " " <<  function.damping() << " " << function.initialVelocity() << ")";
         break;
     }
@@ -66,14 +66,14 @@ double TimingFunction::transformTime(double inputTime, double duration) const
 {
     switch (m_type) {
     case TimingFunction::CubicBezierFunction: {
-        auto& function = *downcast<const CubicBezierTimingFunction>(this);
+        auto& function = downcast<CubicBezierTimingFunction>(*this);
         // The epsilon value we pass to UnitBezier::solve given that the animation is going to run over |dur| seconds. The longer the
         // animation, the more precision we need in the timing function result to avoid ugly discontinuities.
         auto epsilon = 1.0 / (200.0 * duration);
         return UnitBezier(function.x1(), function.y1(), function.x2(), function.y2()).solve(inputTime, epsilon);
     }
     case TimingFunction::StepsFunction: {
-        auto& function = *downcast<const StepsTimingFunction>(this);
+        auto& function = downcast<StepsTimingFunction>(*this);
         auto numberOfSteps = function.numberOfSteps();
         if (function.stepAtStart())
             return std::min(1.0, (std::floor(numberOfSteps * inputTime) + 1) / numberOfSteps);
@@ -81,7 +81,7 @@ double TimingFunction::transformTime(double inputTime, double duration) const
     }
     case TimingFunction::FramesFunction: {
         // https://drafts.csswg.org/css-timing/#frames-timing-functions
-        auto& function = *downcast<const FramesTimingFunction>(this);
+        auto& function = downcast<FramesTimingFunction>(*this);
         auto numberOfFrames = function.numberOfFrames();
         ASSERT(numberOfFrames > 1);
         auto outputTime = std::floor(inputTime * numberOfFrames) / (numberOfFrames - 1);
@@ -90,7 +90,7 @@ double TimingFunction::transformTime(double inputTime, double duration) const
         return outputTime;
     }
     case TimingFunction::SpringFunction: {
-        auto& function = *downcast<const SpringTimingFunction>(this);
+        auto& function = downcast<SpringTimingFunction>(*this);
         return SpringSolver(function.mass(), function.stiffness(), function.damping(), function.initialVelocity()).solve(inputTime * duration);
     }
     case TimingFunction::LinearFunction:
index 1330bf8f5700b21e4ed1daee1af41ef2f07dd93a..527bcba83b8e5faddcbe9320970098515f756763 100644 (file)
@@ -123,7 +123,7 @@ public:
     {
         if (!is<CubicBezierTimingFunction>(other))
             return false;
-        auto& otherCubic = downcast<const CubicBezierTimingFunction>(other);
+        auto& otherCubic = downcast<CubicBezierTimingFunction>(other);
         if (m_timingFunctionPreset != otherCubic.m_timingFunctionPreset)
             return false;
         if (m_timingFunctionPreset != Custom)
@@ -196,7 +196,7 @@ public:
     {
         if (!is<StepsTimingFunction>(other))
             return false;
-        auto& otherSteps = downcast<const StepsTimingFunction>(other);
+        auto& otherSteps = downcast<StepsTimingFunction>(other);
         return m_steps == otherSteps.m_steps && m_stepAtStart == otherSteps.m_stepAtStart;
     }
     
@@ -238,7 +238,7 @@ public:
     {
         if (is<FramesTimingFunction>(other))
             return false;
-        auto& otherFrames = downcast<const FramesTimingFunction>(other);
+        auto& otherFrames = downcast<FramesTimingFunction>(other);
         return m_frames == otherFrames.m_frames;
     }
     
@@ -278,7 +278,7 @@ public:
     {
         if (!is<SpringTimingFunction>(other))
             return false;
-        auto& otherSpring = downcast<const SpringTimingFunction>(other);
+        auto& otherSpring = downcast<SpringTimingFunction>(other);
         return m_mass == otherSpring.m_mass && m_stiffness == otherSpring.m_stiffness && m_damping == otherSpring.m_damping && m_initialVelocity == otherSpring.m_initialVelocity;
     }
 
index 1e6ccea64b0736e8697bb6848cd7c59774cabde3..2af0342000b310ba11422ea9fa0855a83d71dbcb 100644 (file)
@@ -131,17 +131,17 @@ CAMediaTimingFunction* WebCore::toCAMediaTimingFunction(const TimingFunction* ti
     ASSERT(timingFunction);
     if (is<CubicBezierTimingFunction>(timingFunction)) {
         RefPtr<CubicBezierTimingFunction> reversed;
-        const CubicBezierTimingFunction* ctf = downcast<const CubicBezierTimingFunction>(timingFunction);
+        auto* function = downcast<CubicBezierTimingFunction>(timingFunction);
 
         if (reverse) {
-            reversed = ctf->createReversed();
-            ctf = reversed.get();
+            reversed = function->createReversed();
+            function = reversed.get();
         }
 
-        float x1 = static_cast<float>(ctf->x1());
-        float y1 = static_cast<float>(ctf->y1());
-        float x2 = static_cast<float>(ctf->x2());
-        float y2 = static_cast<float>(ctf->y2());
+        float x1 = static_cast<float>(function->x1());
+        float y1 = static_cast<float>(function->y1());
+        float x2 = static_cast<float>(function->x2());
+        float y2 = static_cast<float>(function->y2());
         return [CAMediaTimingFunction functionWithControlPoints: x1 : y1 : x2 : y2];
     }