| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/blink/web_animation_impl.h" | |
| 6 | |
| 7 #include "cc/animation/animation.h" | |
| 8 #include "cc/animation/animation_curve.h" | |
| 9 #include "cc/animation/animation_id_provider.h" | |
| 10 #include "cc/blink/web_filter_animation_curve_impl.h" | |
| 11 #include "cc/blink/web_float_animation_curve_impl.h" | |
| 12 #include "cc/blink/web_scroll_offset_animation_curve_impl.h" | |
| 13 #include "cc/blink/web_transform_animation_curve_impl.h" | |
| 14 #include "third_party/WebKit/public/platform/WebCompositorAnimationCurve.h" | |
| 15 | |
| 16 using cc::Animation; | |
| 17 using cc::AnimationIdProvider; | |
| 18 | |
| 19 using blink::WebCompositorAnimation; | |
| 20 using blink::WebCompositorAnimationCurve; | |
| 21 | |
| 22 namespace cc_blink { | |
| 23 | |
| 24 WebCompositorAnimationImpl::WebCompositorAnimationImpl( | |
| 25 const WebCompositorAnimationCurve& web_curve, | |
| 26 TargetProperty target_property, | |
| 27 int animation_id, | |
| 28 int group_id) { | |
| 29 if (!animation_id) | |
| 30 animation_id = AnimationIdProvider::NextAnimationId(); | |
| 31 if (!group_id) | |
| 32 group_id = AnimationIdProvider::NextGroupId(); | |
| 33 | |
| 34 WebCompositorAnimationCurve::AnimationCurveType curve_type = web_curve.type(); | |
| 35 scoped_ptr<cc::AnimationCurve> curve; | |
| 36 switch (curve_type) { | |
| 37 case WebCompositorAnimationCurve::AnimationCurveTypeFloat: { | |
| 38 const WebFloatAnimationCurveImpl* float_curve_impl = | |
| 39 static_cast<const WebFloatAnimationCurveImpl*>(&web_curve); | |
| 40 curve = float_curve_impl->CloneToAnimationCurve(); | |
| 41 break; | |
| 42 } | |
| 43 case WebCompositorAnimationCurve::AnimationCurveTypeTransform: { | |
| 44 const WebTransformAnimationCurveImpl* transform_curve_impl = | |
| 45 static_cast<const WebTransformAnimationCurveImpl*>(&web_curve); | |
| 46 curve = transform_curve_impl->CloneToAnimationCurve(); | |
| 47 break; | |
| 48 } | |
| 49 case WebCompositorAnimationCurve::AnimationCurveTypeFilter: { | |
| 50 const WebFilterAnimationCurveImpl* filter_curve_impl = | |
| 51 static_cast<const WebFilterAnimationCurveImpl*>(&web_curve); | |
| 52 curve = filter_curve_impl->CloneToAnimationCurve(); | |
| 53 break; | |
| 54 } | |
| 55 case WebCompositorAnimationCurve::AnimationCurveTypeScrollOffset: { | |
| 56 const WebScrollOffsetAnimationCurveImpl* scroll_curve_impl = | |
| 57 static_cast<const WebScrollOffsetAnimationCurveImpl*>(&web_curve); | |
| 58 curve = scroll_curve_impl->CloneToAnimationCurve(); | |
| 59 break; | |
| 60 } | |
| 61 } | |
| 62 animation_ = Animation::Create( | |
| 63 std::move(curve), animation_id, group_id, | |
| 64 static_cast<cc::Animation::TargetProperty>(target_property)); | |
| 65 } | |
| 66 | |
| 67 WebCompositorAnimationImpl::~WebCompositorAnimationImpl() { | |
| 68 } | |
| 69 | |
| 70 int WebCompositorAnimationImpl::id() { | |
| 71 return animation_->id(); | |
| 72 } | |
| 73 | |
| 74 int WebCompositorAnimationImpl::group() { | |
| 75 return animation_->group(); | |
| 76 } | |
| 77 | |
| 78 blink::WebCompositorAnimation::TargetProperty | |
| 79 WebCompositorAnimationImpl::targetProperty() const { | |
| 80 return static_cast<WebCompositorAnimationImpl::TargetProperty>( | |
| 81 animation_->target_property()); | |
| 82 } | |
| 83 | |
| 84 double WebCompositorAnimationImpl::iterations() const { | |
| 85 return animation_->iterations(); | |
| 86 } | |
| 87 | |
| 88 void WebCompositorAnimationImpl::setIterations(double n) { | |
| 89 animation_->set_iterations(n); | |
| 90 } | |
| 91 | |
| 92 double WebCompositorAnimationImpl::iterationStart() const { | |
| 93 return animation_->iteration_start(); | |
| 94 } | |
| 95 | |
| 96 void WebCompositorAnimationImpl::setIterationStart(double iteration_start) { | |
| 97 animation_->set_iteration_start(iteration_start); | |
| 98 } | |
| 99 | |
| 100 double WebCompositorAnimationImpl::startTime() const { | |
| 101 return (animation_->start_time() - base::TimeTicks()).InSecondsF(); | |
| 102 } | |
| 103 | |
| 104 void WebCompositorAnimationImpl::setStartTime(double monotonic_time) { | |
| 105 animation_->set_start_time(base::TimeTicks::FromInternalValue( | |
| 106 monotonic_time * base::Time::kMicrosecondsPerSecond)); | |
| 107 } | |
| 108 | |
| 109 double WebCompositorAnimationImpl::timeOffset() const { | |
| 110 return animation_->time_offset().InSecondsF(); | |
| 111 } | |
| 112 | |
| 113 void WebCompositorAnimationImpl::setTimeOffset(double monotonic_time) { | |
| 114 animation_->set_time_offset(base::TimeDelta::FromSecondsD(monotonic_time)); | |
| 115 } | |
| 116 | |
| 117 blink::WebCompositorAnimation::Direction WebCompositorAnimationImpl::direction() | |
| 118 const { | |
| 119 switch (animation_->direction()) { | |
| 120 case cc::Animation::DIRECTION_NORMAL: | |
| 121 return DirectionNormal; | |
| 122 case cc::Animation::DIRECTION_REVERSE: | |
| 123 return DirectionReverse; | |
| 124 case cc::Animation::DIRECTION_ALTERNATE: | |
| 125 return DirectionAlternate; | |
| 126 case cc::Animation::DIRECTION_ALTERNATE_REVERSE: | |
| 127 return DirectionAlternateReverse; | |
| 128 default: | |
| 129 NOTREACHED(); | |
| 130 } | |
| 131 return DirectionNormal; | |
| 132 } | |
| 133 | |
| 134 void WebCompositorAnimationImpl::setDirection(Direction direction) { | |
| 135 switch (direction) { | |
| 136 case DirectionNormal: | |
| 137 animation_->set_direction(cc::Animation::DIRECTION_NORMAL); | |
| 138 break; | |
| 139 case DirectionReverse: | |
| 140 animation_->set_direction(cc::Animation::DIRECTION_REVERSE); | |
| 141 break; | |
| 142 case DirectionAlternate: | |
| 143 animation_->set_direction(cc::Animation::DIRECTION_ALTERNATE); | |
| 144 break; | |
| 145 case DirectionAlternateReverse: | |
| 146 animation_->set_direction(cc::Animation::DIRECTION_ALTERNATE_REVERSE); | |
| 147 break; | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 double WebCompositorAnimationImpl::playbackRate() const { | |
| 152 return animation_->playback_rate(); | |
| 153 } | |
| 154 | |
| 155 void WebCompositorAnimationImpl::setPlaybackRate(double playback_rate) { | |
| 156 animation_->set_playback_rate(playback_rate); | |
| 157 } | |
| 158 | |
| 159 blink::WebCompositorAnimation::FillMode WebCompositorAnimationImpl::fillMode() | |
| 160 const { | |
| 161 switch (animation_->fill_mode()) { | |
| 162 case cc::Animation::FILL_MODE_NONE: | |
| 163 return FillModeNone; | |
| 164 case cc::Animation::FILL_MODE_FORWARDS: | |
| 165 return FillModeForwards; | |
| 166 case cc::Animation::FILL_MODE_BACKWARDS: | |
| 167 return FillModeBackwards; | |
| 168 case cc::Animation::FILL_MODE_BOTH: | |
| 169 return FillModeBoth; | |
| 170 default: | |
| 171 NOTREACHED(); | |
| 172 } | |
| 173 return FillModeNone; | |
| 174 } | |
| 175 | |
| 176 void WebCompositorAnimationImpl::setFillMode(FillMode fill_mode) { | |
| 177 switch (fill_mode) { | |
| 178 case FillModeNone: | |
| 179 animation_->set_fill_mode(cc::Animation::FILL_MODE_NONE); | |
| 180 break; | |
| 181 case FillModeForwards: | |
| 182 animation_->set_fill_mode(cc::Animation::FILL_MODE_FORWARDS); | |
| 183 break; | |
| 184 case FillModeBackwards: | |
| 185 animation_->set_fill_mode(cc::Animation::FILL_MODE_BACKWARDS); | |
| 186 break; | |
| 187 case FillModeBoth: | |
| 188 animation_->set_fill_mode(cc::Animation::FILL_MODE_BOTH); | |
| 189 break; | |
| 190 } | |
| 191 } | |
| 192 | |
| 193 scoped_ptr<cc::Animation> WebCompositorAnimationImpl::PassAnimation() { | |
| 194 animation_->set_needs_synchronized_start_time(true); | |
| 195 return std::move(animation_); | |
| 196 } | |
| 197 | |
| 198 } // namespace cc_blink | |
| OLD | NEW |