Ignore:
Timestamp:
Jun 5, 2016, 9:56:38 PM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Add experimental support for spring based CSS animations
https://bugs.webkit.org/show_bug.cgi?id=158403

Patch by Sam Weinig <sam@webkit.org> on 2016-06-05
Reviewed by Dean Jackson.

Source/WebCore:

Adds experimental support for a new CSS animation timing function that uses
spring to model the time function. To use it you replace your normal timing
function, be it cubic-bezier or steps, with a new function called spring().
For instance, for a transition you would write:

transition-timing-function: spring(1 100 10 0);

The parameters are, in order:

  • Mass
  • Stiffness
  • Damping
  • Initial Velocity

Tests: animations/spring-computed-style.html

animations/spring-function.html
animations/spring-parsing.html

  • WebCore.xcodeproj/project.pbxproj:

Add new file.

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::createTimingFunctionValue):
Modernize and add support for the spring function.

  • css/CSSParser.cpp:

(WebCore::CSSParserContext::CSSParserContext):
(WebCore::operator==):
(WebCore::CSSParser::CSSParser):
(WebCore::CSSParser::parseTransformOriginShorthand):
(WebCore::CSSParser::isSpringTimingFunctionEnabled):
(WebCore::CSSParser::parseCubicBezierTimingFunctionValue):
(WebCore::CSSParser::parseSpringTimingFunctionValue):
(WebCore::CSSParser::parseAnimationTimingFunction):

  • css/CSSParser.h:
  • css/CSSParserMode.h:

Add parsing support for the spring() function.

  • css/CSSTimingFunctionValue.cpp:

(WebCore::CSSCubicBezierTimingFunctionValue::customCSSText):
(WebCore::CSSCubicBezierTimingFunctionValue::equals):
(WebCore::CSSStepsTimingFunctionValue::customCSSText):
(WebCore::CSSStepsTimingFunctionValue::equals):
(WebCore::CSSSpringTimingFunctionValue::customCSSText):
(WebCore::CSSSpringTimingFunctionValue::equals):

  • css/CSSTimingFunctionValue.h:

(WebCore::CSSSpringTimingFunctionValue::create):
(WebCore::CSSSpringTimingFunctionValue::mass):
(WebCore::CSSSpringTimingFunctionValue::stiffness):
(WebCore::CSSSpringTimingFunctionValue::damping):
(WebCore::CSSSpringTimingFunctionValue::initialVelocity):
(WebCore::CSSSpringTimingFunctionValue::CSSSpringTimingFunctionValue):
Modernize and add support for the spring function.

  • css/CSSToStyleMap.cpp:

(WebCore::CSSToStyleMap::mapAnimationTimingFunction):
Pipe the spring function into the animation.

  • css/CSSValue.cpp:

(WebCore::CSSValue::equals):
(WebCore::CSSValue::cssText):
(WebCore::CSSValue::destroy):

  • css/CSSValue.h:

(WebCore::CSSValue::isSpringTimingFunctionValue):
Add support for the spring function.

  • page/Settings.in:

Add a setting to control if the spring function is enabled.

  • page/animation/AnimationBase.cpp:

(WebCore::solveSpringFunction):
(WebCore::AnimationBase::progress):
Add support for solving the spring function. Since the spring requires time to be absolute,
get the real time by multiplying the ratio t, to the total duration.

  • platform/animation/TimingFunction.cpp:

(WebCore::operator<<):

  • platform/animation/TimingFunction.h:

(WebCore::TimingFunction::~TimingFunction):
(WebCore::TimingFunction::isSpringTimingFunction):
Add support for the spring timing function.

  • platform/graphics/SpringSolver.h: Added.

(WebCore::SpringSolver::SpringSolver):
(WebCore::SpringSolver::solve):
Add a Spring solver that matches the one in CoreAnimation.

  • platform/graphics/ca/GraphicsLayerCA.cpp:

(WebCore::GraphicsLayerCA::createAnimationFromKeyframes):
(WebCore::GraphicsLayerCA::appendToUncommittedAnimations):
(WebCore::GraphicsLayerCA::createBasicAnimation):
(WebCore::GraphicsLayerCA::createSpringAnimation):
(WebCore::GraphicsLayerCA::setupAnimation):

  • platform/graphics/ca/GraphicsLayerCA.h:

Map animations with spring timing functions to CASpringAnimations.

  • platform/graphics/ca/PlatformCAAnimation.cpp:

(WebCore::operator<<):
(WebCore::PlatformCAAnimation::isBasicAnimation):

  • platform/graphics/ca/PlatformCAAnimation.h:

(WebCore::PlatformCAAnimation::setActualStartTimeIfNeeded):
(WebCore::PlatformCAAnimation::PlatformCAAnimation):

  • platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm:

(WebCore::toCAMediaTimingFunction):
(PlatformCAAnimationCocoa::PlatformCAAnimationCocoa):
(PlatformCAAnimationCocoa::setTimingFunction):
(PlatformCAAnimationCocoa::copyTimingFunctionFrom):
(PlatformCAAnimationCocoa::setFromValue):
(PlatformCAAnimationCocoa::copyFromValueFrom):
(PlatformCAAnimationCocoa::setToValue):
(PlatformCAAnimationCocoa::copyToValueFrom):
Add a new type of PlatformCAAnimation, Spring, which is a sub-type of Basic.

Source/WebKit2:

  • Shared/WebCoreArgumentCoders.cpp:

(IPC::ArgumentCoder<StepsTimingFunction>::decode):
(IPC::ArgumentCoder<SpringTimingFunction>::encode):
(IPC::ArgumentCoder<SpringTimingFunction>::decode):
(IPC::ArgumentCoder<FloatPoint>::encode):

  • Shared/WebCoreArgumentCoders.h:
  • Shared/WebPreferencesDefinitions.h:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::updatePreferences):

  • WebProcess/WebPage/mac/PlatformCAAnimationRemote.mm:

(WebKit::PlatformCAAnimationRemote::Properties::encode):
(WebKit::PlatformCAAnimationRemote::Properties::decode):
(WebKit::addAnimationToLayer):
Pipe through support for the Spring animation.

LayoutTests:

  • animations/script-tests/spring-computed-style.js: Added.
  • animations/script-tests/spring-parsing.js: Added.
  • animations/spring-computed-style-expected.txt: Added.
  • animations/spring-computed-style.html: Added.
  • animations/spring-function-expected.txt: Added.
  • animations/spring-function.html: Added.
  • animations/spring-parsing-expected.txt: Added.
  • animations/spring-parsing.html: Added.

Add tests for the spring timing function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r201498 r201706  
    14991499    switch (timingFunction->type()) {
    15001500    case TimingFunction::CubicBezierFunction: {
    1501         const CubicBezierTimingFunction* bezierTimingFunction = static_cast<const CubicBezierTimingFunction*>(timingFunction);
    1502         if (bezierTimingFunction->timingFunctionPreset() != CubicBezierTimingFunction::Custom) {
     1501        auto& function = *static_cast<const CubicBezierTimingFunction*>(timingFunction);
     1502        if (function.timingFunctionPreset() != CubicBezierTimingFunction::Custom) {
    15031503            CSSValueID valueId = CSSValueInvalid;
    1504             switch (bezierTimingFunction->timingFunctionPreset()) {
     1504            switch (function.timingFunctionPreset()) {
    15051505            case CubicBezierTimingFunction::Ease:
    15061506                valueId = CSSValueEase;
     
    15131513                break;
    15141514            default:
    1515                 ASSERT(bezierTimingFunction->timingFunctionPreset() == CubicBezierTimingFunction::EaseInOut);
     1515                ASSERT(function.timingFunctionPreset() == CubicBezierTimingFunction::EaseInOut);
    15161516                valueId = CSSValueEaseInOut;
    15171517                break;
     
    15191519            return CSSValuePool::singleton().createIdentifierValue(valueId);
    15201520        }
    1521         return CSSCubicBezierTimingFunctionValue::create(bezierTimingFunction->x1(), bezierTimingFunction->y1(), bezierTimingFunction->x2(), bezierTimingFunction->y2());
     1521        return CSSCubicBezierTimingFunctionValue::create(function.x1(), function.y1(), function.x2(), function.y2());
    15221522    }
    15231523    case TimingFunction::StepsFunction: {
    1524         const StepsTimingFunction* stepsTimingFunction = static_cast<const StepsTimingFunction*>(timingFunction);
    1525         return CSSStepsTimingFunctionValue::create(stepsTimingFunction->numberOfSteps(), stepsTimingFunction->stepAtStart());
     1524        auto& function = *static_cast<const StepsTimingFunction*>(timingFunction);
     1525        return CSSStepsTimingFunctionValue::create(function.numberOfSteps(), function.stepAtStart());
     1526    }
     1527    case TimingFunction::SpringFunction: {
     1528        auto& function = *static_cast<const SpringTimingFunction*>(timingFunction);
     1529        return CSSSpringTimingFunctionValue::create(function.mass(), function.stiffness(), function.damping(), function.initialVelocity());
    15261530    }
    15271531    default:
Note: See TracChangeset for help on using the changeset viewer.