• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2014 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5//     You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//     See the License for the specific language governing permissions and
13// limitations under the License.
14
15(function(shared, scope, testing) {
16
17  function EffectTime(timing) {
18    var timeFraction = 0;
19    var activeDuration = shared.calculateActiveDuration(timing);
20    var effectTime = function(localTime) {
21      return shared.calculateIterationProgress(activeDuration, localTime, timing);
22    };
23    effectTime._totalDuration = timing.delay + activeDuration + timing.endDelay;
24    return effectTime;
25  }
26
27  scope.KeyframeEffect = function(target, effectInput, timingInput, id) {
28    var effectTime = EffectTime(shared.normalizeTimingInput(timingInput));
29    var interpolations = scope.convertEffectInput(effectInput);
30    var timeFraction;
31    var keyframeEffect = function() {
32      WEB_ANIMATIONS_TESTING && console.assert(typeof timeFraction !== 'undefined');
33      interpolations(target, timeFraction);
34    };
35    // Returns whether the keyframeEffect is in effect or not after the timing update.
36    keyframeEffect._update = function(localTime) {
37      timeFraction = effectTime(localTime);
38      return timeFraction !== null;
39    };
40    keyframeEffect._clear = function() {
41      interpolations(target, null);
42    };
43    keyframeEffect._hasSameTarget = function(otherTarget) {
44      return target === otherTarget;
45    };
46    keyframeEffect._target = target;
47    keyframeEffect._totalDuration = effectTime._totalDuration;
48    keyframeEffect._id = id;
49    return keyframeEffect;
50  };
51
52  if (WEB_ANIMATIONS_TESTING) {
53    testing.webAnimations1KeyframeEffect = scope.KeyframeEffect;
54    testing.effectTime = EffectTime;
55  }
56
57})(webAnimationsShared, webAnimations1, webAnimationsTesting);
58