Chromium Code Reviews| Index: third_party/WebKit/Source/platform/animation/WebCompositorAnimation.cpp |
| diff --git a/third_party/WebKit/Source/platform/animation/WebCompositorAnimation.cpp b/third_party/WebKit/Source/platform/animation/WebCompositorAnimation.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c64fbc035c0b8b535db589c8781bd54e17b3ecc8 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/animation/WebCompositorAnimation.cpp |
| @@ -0,0 +1,235 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "platform/animation/WebCompositorAnimation.h" |
| + |
| +#include "cc/animation/animation.h" |
| +#include "cc/animation/animation_curve.h" |
| +#include "cc/animation/animation_id_provider.h" |
| +#include "platform/animation/WebCompositorAnimationCurve.h" |
| +#include "platform/animation/WebFilterAnimationCurve.h" |
| +#include "platform/animation/WebFloatAnimationCurve.h" |
| +#include "platform/animation/WebScrollOffsetAnimationCurve.h" |
| +#include "platform/animation/WebTransformAnimationCurve.h" |
| + |
| +using cc::Animation; |
| +using cc::AnimationIdProvider; |
| + |
| +using blink::WebCompositorAnimation; |
| +using blink::WebCompositorAnimationCurve; |
| + |
| +namespace blink { |
| + |
| +#define STATIC_ASSERT_MATCHING_ENUM(expected, actual) \ |
|
esprehn
2016/01/28 03:40:39
we don't have a macro for this already?
loyso (OOO)
2016/01/28 07:10:08
No, we don't. I have moved this code 'as-is' from
|
| + static_assert(int(expected) == int(actual), "mismatching enums: " #expected) |
| + |
| +// Assert matching enums: TargetProperty |
| +STATIC_ASSERT_MATCHING_ENUM( |
| + blink::WebCompositorAnimation::TargetPropertyTransform, |
| + cc::Animation::TRANSFORM); |
| +STATIC_ASSERT_MATCHING_ENUM( |
| + blink::WebCompositorAnimation::TargetPropertyOpacity, |
| + cc::Animation::OPACITY); |
| +STATIC_ASSERT_MATCHING_ENUM(blink::WebCompositorAnimation::TargetPropertyFilter, |
| + cc::Animation::FILTER); |
| +STATIC_ASSERT_MATCHING_ENUM( |
| + blink::WebCompositorAnimation::TargetPropertyScrollOffset, |
| + cc::Animation::SCROLL_OFFSET); |
| + |
| + |
| +WebCompositorAnimation::WebCompositorAnimation( |
| + const WebCompositorAnimationCurve& webCurve, |
| + TargetProperty targetProperty, |
| + int animationId, |
| + int groupId) |
| +{ |
| + if (!animationId) |
| + animationId = AnimationIdProvider::NextAnimationId(); |
|
esprehn
2016/01/28 03:40:39
animationId || ...; works too I think?
loyso (OOO)
2016/01/28 07:10:08
It would work and it's the same in terms of genera
jbroman
2016/01/28 15:27:23
Drive-by: no it wouldn't (unlike JavaScript, in C+
|
| + if (!groupId) |
| + groupId = AnimationIdProvider::NextGroupId(); |
|
esprehn
2016/01/28 03:40:39
ditto
|
| + |
| + WebCompositorAnimationCurve::AnimationCurveType curveType = webCurve.type(); |
| + scoped_ptr<cc::AnimationCurve> curve; |
| + switch (curveType) { |
| + case WebCompositorAnimationCurve::AnimationCurveTypeFloat: { |
| + const blink::WebFloatAnimationCurve* floatCurve = static_cast<const blink::WebFloatAnimationCurve*>(&webCurve); |
| + curve = floatCurve->CloneToAnimationCurve(); |
| + break; |
| + } |
| + case WebCompositorAnimationCurve::AnimationCurveTypeTransform: { |
| + const blink::WebTransformAnimationCurve* transformCurve = static_cast<const blink::WebTransformAnimationCurve*>(&webCurve); |
| + curve = transformCurve->CloneToAnimationCurve(); |
| + break; |
| + } |
| + case WebCompositorAnimationCurve::AnimationCurveTypeFilter: { |
| + const blink::WebFilterAnimationCurve* filterCurve = static_cast<const blink::WebFilterAnimationCurve*>(&webCurve); |
| + curve = filterCurve->CloneToAnimationCurve(); |
| + break; |
| + } |
| + case WebCompositorAnimationCurve::AnimationCurveTypeScrollOffset: { |
| + const blink::WebScrollOffsetAnimationCurve* scrollCurve = static_cast<const blink::WebScrollOffsetAnimationCurve*>(&webCurve); |
| + curve = scrollCurve->CloneToAnimationCurve(); |
| + break; |
| + } |
| + } |
| + m_animation = Animation::Create( |
| + std::move(curve), animationId, groupId, |
| + static_cast<cc::Animation::TargetProperty>(targetProperty)); |
| +} |
| + |
| +WebCompositorAnimation::WebCompositorAnimation() {} |
| + |
| +WebCompositorAnimation::~WebCompositorAnimation() |
| +{ |
|
esprehn
2016/01/28 03:40:39
move braces up for consistency
loyso (OOO)
2016/01/28 07:10:08
Done.
|
| +} |
| + |
| +int WebCompositorAnimation::id() |
| +{ |
| + return m_animation->id(); |
| +} |
| + |
| +int WebCompositorAnimation::group() |
| +{ |
| + return m_animation->group(); |
| +} |
| + |
| +blink::WebCompositorAnimation::TargetProperty WebCompositorAnimation::targetProperty() const |
| +{ |
| + return static_cast<WebCompositorAnimation::TargetProperty>(m_animation->target_property()); |
| +} |
| + |
| +double WebCompositorAnimation::iterations() const |
| +{ |
| + return m_animation->iterations(); |
| +} |
| + |
| +void WebCompositorAnimation::setIterations(double n) |
| +{ |
| + m_animation->set_iterations(n); |
| +} |
| + |
| +double WebCompositorAnimation::iterationStart() const |
| +{ |
| + return m_animation->iteration_start(); |
| +} |
| + |
| +void WebCompositorAnimation::setIterationStart(double iterationStart) |
| +{ |
| + m_animation->set_iteration_start(iterationStart); |
| +} |
| + |
| +double WebCompositorAnimation::startTime() const |
| +{ |
| + return (m_animation->start_time() - base::TimeTicks()).InSecondsF(); |
| +} |
| + |
| +void WebCompositorAnimation::setStartTime(double monotonicTime) |
| +{ |
| + m_animation->set_start_time(base::TimeTicks::FromInternalValue( |
| + monotonicTime * base::Time::kMicrosecondsPerSecond)); |
| +} |
| + |
| +double WebCompositorAnimation::timeOffset() const |
| +{ |
| + return m_animation->time_offset().InSecondsF(); |
| +} |
| + |
| +void WebCompositorAnimation::setTimeOffset(double monotonicTime) |
| +{ |
| + m_animation->set_time_offset(base::TimeDelta::FromSecondsD(monotonicTime)); |
| +} |
| + |
| +blink::WebCompositorAnimation::Direction WebCompositorAnimation::direction() const |
| +{ |
| + switch (m_animation->direction()) { |
| + case cc::Animation::DIRECTION_NORMAL: |
| + return DirectionNormal; |
| + case cc::Animation::DIRECTION_REVERSE: |
| + return DirectionReverse; |
| + case cc::Animation::DIRECTION_ALTERNATE: |
| + return DirectionAlternate; |
| + case cc::Animation::DIRECTION_ALTERNATE_REVERSE: |
| + return DirectionAlternateReverse; |
| + default: |
| + NOTREACHED(); |
| + } |
| + return DirectionNormal; |
| +} |
| + |
| +void WebCompositorAnimation::setDirection(Direction direction) |
| +{ |
| + switch (direction) { |
| + case DirectionNormal: |
| + m_animation->set_direction(cc::Animation::DIRECTION_NORMAL); |
| + break; |
| + case DirectionReverse: |
| + m_animation->set_direction(cc::Animation::DIRECTION_REVERSE); |
| + break; |
| + case DirectionAlternate: |
| + m_animation->set_direction(cc::Animation::DIRECTION_ALTERNATE); |
| + break; |
| + case DirectionAlternateReverse: |
| + m_animation->set_direction(cc::Animation::DIRECTION_ALTERNATE_REVERSE); |
| + break; |
| + } |
| +} |
| + |
| +double WebCompositorAnimation::playbackRate() const |
| +{ |
| + return m_animation->playback_rate(); |
| +} |
| + |
| +void WebCompositorAnimation::setPlaybackRate(double playbackRate) |
| +{ |
| + m_animation->set_playback_rate(playbackRate); |
| +} |
| + |
| +blink::WebCompositorAnimation::FillMode WebCompositorAnimation::fillMode() const |
| +{ |
| + switch (m_animation->fill_mode()) { |
| + case cc::Animation::FILL_MODE_NONE: |
| + return FillModeNone; |
| + case cc::Animation::FILL_MODE_FORWARDS: |
| + return FillModeForwards; |
| + case cc::Animation::FILL_MODE_BACKWARDS: |
| + return FillModeBackwards; |
| + case cc::Animation::FILL_MODE_BOTH: |
| + return FillModeBoth; |
| + default: |
| + NOTREACHED(); |
| + } |
| + return FillModeNone; |
| +} |
| + |
| +void WebCompositorAnimation::setFillMode(FillMode fillMode) |
| +{ |
| + switch (fillMode) { |
| + case FillModeNone: |
| + m_animation->set_fill_mode(cc::Animation::FILL_MODE_NONE); |
| + break; |
|
esprehn
2016/01/28 03:40:40
we should make our enums parallel and just cast he
loyso (OOO)
2016/01/28 07:10:08
Yeah, that's supposed to be the next step (a separ
|
| + case FillModeForwards: |
| + m_animation->set_fill_mode(cc::Animation::FILL_MODE_FORWARDS); |
| + break; |
| + case FillModeBackwards: |
| + m_animation->set_fill_mode(cc::Animation::FILL_MODE_BACKWARDS); |
| + break; |
| + case FillModeBoth: |
| + m_animation->set_fill_mode(cc::Animation::FILL_MODE_BOTH); |
| + break; |
| + } |
| +} |
| + |
| +scoped_ptr<cc::Animation> WebCompositorAnimation::passAnimation() |
| +{ |
| + m_animation->set_needs_synchronized_start_time(true); |
| + return std::move(m_animation); |
| +} |
| + |
| +cc::Animation* WebCompositorAnimation::releaseCCAnimation() |
| +{ |
| + m_animation->set_needs_synchronized_start_time(true); |
|
esprehn
2016/01/28 03:40:39
why do both of these need to call set_needs_synchr
loyso (OOO)
2016/01/28 07:10:08
'passAnimation' was copied 'as-is'. I want to pres
|
| + return m_animation.release(); |
| +} |
| + |
| +} // namespace blink |