| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2012 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // Make sure to tell the renderer that we are ending. This will make sure an
y accelerated animations are removed. | 64 // Make sure to tell the renderer that we are ending. This will make sure an
y accelerated animations are removed. |
| 65 if (!postActive()) | 65 if (!postActive()) |
| 66 endAnimation(); | 66 endAnimation(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 static const CSSAnimationData* getAnimationFromStyleByName(const RenderStyle* st
yle, const AtomicString& name) | 69 static const CSSAnimationData* getAnimationFromStyleByName(const RenderStyle* st
yle, const AtomicString& name) |
| 70 { | 70 { |
| 71 if (!style->animations()) | 71 if (!style->animations()) |
| 72 return 0; | 72 return 0; |
| 73 | 73 |
| 74 for (size_t i = 0; i < style->animations()->size(); i++) { | 74 size_t animationCount = style->animations()->size(); |
| 75 for (size_t i = 0; i < animationCount; i++) { |
| 75 if (name == style->animations()->animation(i)->name()) | 76 if (name == style->animations()->animation(i)->name()) |
| 76 return style->animations()->animation(i); | 77 return style->animations()->animation(i); |
| 77 } | 78 } |
| 78 | 79 |
| 79 return 0; | 80 return 0; |
| 80 } | 81 } |
| 81 | 82 |
| 82 void KeyframeAnimation::fetchIntervalEndpointsForProperty(CSSPropertyID property
, const RenderStyle*& fromStyle, const RenderStyle*& toStyle, double& prog) cons
t | 83 void KeyframeAnimation::fetchIntervalEndpointsForProperty(CSSPropertyID property
, const RenderStyle*& fromStyle, const RenderStyle*& toStyle, double& prog) cons
t |
| 83 { | 84 { |
| 84 // Find the first key | 85 // Find the first key |
| 85 double elapsedTime = getElapsedTime(); | 86 double elapsedTime = getElapsedTime(); |
| 86 if (m_animation->duration() && m_animation->iterationCount() != CSSAnimation
Data::IterationCountInfinite) | 87 if (m_animation->duration() && m_animation->iterationCount() != CSSAnimation
Data::IterationCountInfinite) |
| 87 elapsedTime = min(elapsedTime, m_animation->duration() * m_animation->it
erationCount()); | 88 elapsedTime = min(elapsedTime, m_animation->duration() * m_animation->it
erationCount()); |
| 88 | 89 |
| 89 const double fractionalTime = this->fractionalTime(1, elapsedTime, 0); | 90 const double fractionalTime = this->fractionalTime(1, elapsedTime, 0); |
| 90 | 91 |
| 91 size_t numKeyframes = m_keyframes.size(); | 92 size_t numKeyframes = m_keyframes.size(); |
| 92 if (!numKeyframes) | 93 if (!numKeyframes) |
| 93 return; | 94 return; |
| 94 | 95 |
| 95 ASSERT(!m_keyframes[0].key()); | 96 ASSERT(!m_keyframes[0].key()); |
| 96 ASSERT(m_keyframes[m_keyframes.size() - 1].key() == 1); | 97 ASSERT(m_keyframes[m_keyframes.size() - 1].key() == 1); |
| 97 | 98 |
| 99 size_t currentIndex = 0; |
| 100 size_t firstIndex = 0; |
| 101 size_t lastIndex = numKeyframes - 1; |
| 102 size_t distance = numKeyframes; |
| 103 |
| 104 // Find keyframe that is closest to elapsed time. |
| 105 while (distance > 1) { |
| 106 currentIndex = (lastIndex + firstIndex) >> 1; |
| 107 float key = m_keyframes[currentIndex].key(); |
| 108 distance = lastIndex - currentIndex; |
| 109 |
| 110 if (key < fractionalTime) { |
| 111 if (distance < 2) |
| 112 currentIndex++; |
| 113 firstIndex = currentIndex; |
| 114 } else { |
| 115 lastIndex = currentIndex; |
| 116 } |
| 117 } |
| 118 |
| 98 int prevIndex = -1; | 119 int prevIndex = -1; |
| 99 int nextIndex = -1; | 120 int nextIndex = -1; |
| 100 | |
| 101 // FIXME: with a lot of keys, this linear search will be slow. We could bina
ry search. | |
| 102 for (size_t i = 0; i < numKeyframes; ++i) { | |
| 103 const KeyframeValue& currKeyFrame = m_keyframes[i]; | |
| 104 | 121 |
| 105 if (!currKeyFrame.containsProperty(property)) | 122 // Iterate forward to find next keyframe that is used to animate CSS propert
y. |
| 106 continue; | 123 for (size_t i = currentIndex; i < numKeyframes; ++i) { |
| 107 | 124 const KeyframeValue& keyFrame = m_keyframes[i]; |
| 108 if (fractionalTime < currKeyFrame.key()) { | 125 if (keyFrame.key() > fractionalTime && keyFrame.containsProperty(propert
y)) { |
| 109 nextIndex = i; | 126 nextIndex = i; |
| 110 break; | 127 break; |
| 111 } | 128 } |
| 112 | 129 } |
| 113 prevIndex = i; | 130 |
| 131 // Iterate backward to find previous keyframe. |
| 132 for (size_t i = currentIndex; i < numKeyframes; --i) { |
| 133 const KeyframeValue& keyFrame = m_keyframes[i]; |
| 134 if (keyFrame.key() <= fractionalTime && keyFrame.containsProperty(proper
ty)) { |
| 135 prevIndex = i; |
| 136 break; |
| 137 } |
| 114 } | 138 } |
| 115 | 139 |
| 116 double scale = 1; | 140 double scale = 1; |
| 117 double offset = 0; | 141 double offset = 0; |
| 118 | 142 |
| 119 if (prevIndex == -1) | 143 if (prevIndex == -1) |
| 120 prevIndex = 0; | 144 prevIndex = 0; |
| 121 | 145 |
| 122 if (nextIndex == -1) | 146 if (nextIndex == -1) |
| 123 nextIndex = m_keyframes.size() - 1; | 147 nextIndex = numKeyframes - 1; |
| 124 | 148 |
| 125 const KeyframeValue& prevKeyframe = m_keyframes[prevIndex]; | 149 const KeyframeValue& prevKeyframe = m_keyframes[prevIndex]; |
| 126 const KeyframeValue& nextKeyframe = m_keyframes[nextIndex]; | 150 const KeyframeValue& nextKeyframe = m_keyframes[nextIndex]; |
| 127 | 151 |
| 128 fromStyle = prevKeyframe.style(); | 152 fromStyle = prevKeyframe.style(); |
| 129 toStyle = nextKeyframe.style(); | 153 toStyle = nextKeyframe.style(); |
| 130 | 154 |
| 131 offset = prevKeyframe.key(); | 155 offset = prevKeyframe.key(); |
| 132 scale = 1.0 / (nextKeyframe.key() - prevKeyframe.key()); | 156 scale = 1.0 / (nextKeyframe.key() - prevKeyframe.key()); |
| 133 | 157 |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 463 |
| 440 if (acceleratedPropertiesOnly) { | 464 if (acceleratedPropertiesOnly) { |
| 441 bool isLooping; | 465 bool isLooping; |
| 442 getTimeToNextEvent(t, isLooping); | 466 getTimeToNextEvent(t, isLooping); |
| 443 } | 467 } |
| 444 | 468 |
| 445 return t; | 469 return t; |
| 446 } | 470 } |
| 447 | 471 |
| 448 } // namespace WebCore | 472 } // namespace WebCore |
| OLD | NEW |