Chromium Code Reviews| 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 Animation* getAnimationFromStyleByName(const RenderStyle* style, co nst AtomicString& name) | 69 static const Animation* getAnimationFromStyleByName(const RenderStyle* style, co nst 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() != Animation::I terationCountInfinite) | 87 if (m_animation->duration() && m_animation->iterationCount() != Animation::I terationCountInfinite) |
| 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 backIterIndex = 0; | |
|
apavlov
2013/04/30 13:16:11
This is making the algorithm a bit more complicate
| |
| 101 size_t firstIndex = 0; | |
| 102 size_t lastIndex = numKeyframes - 1; | |
| 103 size_t distance = numKeyframes; | |
| 104 | |
| 105 // Find keyframe that is closest to elapsed time. | |
| 106 while (distance > 1) { | |
| 107 currentIndex = (lastIndex + firstIndex) >> 1; | |
| 108 backIterIndex = currentIndex; | |
|
apavlov
2013/04/30 13:16:11
extra whitespace after '='
| |
| 109 float key = m_keyframes[currentIndex].key(); | |
| 110 distance = lastIndex - currentIndex; | |
| 111 | |
| 112 if (key < fractionalTime) { | |
| 113 if (distance < 2) | |
| 114 currentIndex++; | |
| 115 firstIndex = currentIndex; | |
| 116 } else { | |
| 117 if (distance < 2 && backIterIndex) | |
| 118 backIterIndex--; | |
| 119 lastIndex = currentIndex; | |
| 120 } | |
| 121 } | |
| 122 | |
| 98 int prevIndex = -1; | 123 int prevIndex = -1; |
| 99 int nextIndex = -1; | 124 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 | 125 |
| 105 if (!currKeyFrame.containsProperty(property)) | 126 // Interate forward to find next keyframe that is used to animate CSS proper ty. |
|
apavlov
2013/04/30 13:16:11
Interate -> Iterate
| |
| 106 continue; | 127 for (size_t i = currentIndex; i < numKeyframes; ++i) { |
| 107 | 128 const KeyframeValue& keyFrame = m_keyframes[i]; |
| 108 if (fractionalTime < currKeyFrame.key()) { | 129 if (keyFrame.key() > fractionalTime && keyFrame.containsProperty(propert y)) { |
| 109 nextIndex = i; | 130 nextIndex = i; |
| 110 break; | 131 break; |
| 111 } | 132 } |
| 112 | 133 } |
| 113 prevIndex = i; | 134 |
| 135 // Interate backward to find previous keyframe. | |
|
apavlov
2013/04/30 13:16:11
Ditto
| |
| 136 for (size_t i = backIterIndex; i < numKeyframes; --i) { | |
| 137 const KeyframeValue& keyFrame = m_keyframes[i]; | |
| 138 if (keyFrame.key() <= fractionalTime && keyFrame.containsProperty(proper ty)) { | |
| 139 prevIndex = i; | |
| 140 break; | |
| 141 } | |
| 114 } | 142 } |
| 115 | 143 |
| 116 double scale = 1; | 144 double scale = 1; |
| 117 double offset = 0; | 145 double offset = 0; |
| 118 | 146 |
| 119 if (prevIndex == -1) | 147 if (prevIndex == -1) |
| 120 prevIndex = 0; | 148 prevIndex = 0; |
| 121 | 149 |
| 122 if (nextIndex == -1) | 150 if (nextIndex == -1) |
| 123 nextIndex = m_keyframes.size() - 1; | 151 nextIndex = numKeyframes - 1; |
| 124 | 152 |
| 125 const KeyframeValue& prevKeyframe = m_keyframes[prevIndex]; | 153 const KeyframeValue& prevKeyframe = m_keyframes[prevIndex]; |
| 126 const KeyframeValue& nextKeyframe = m_keyframes[nextIndex]; | 154 const KeyframeValue& nextKeyframe = m_keyframes[nextIndex]; |
| 127 | 155 |
| 128 fromStyle = prevKeyframe.style(); | 156 fromStyle = prevKeyframe.style(); |
| 129 toStyle = nextKeyframe.style(); | 157 toStyle = nextKeyframe.style(); |
| 130 | 158 |
| 131 offset = prevKeyframe.key(); | 159 offset = prevKeyframe.key(); |
| 132 scale = 1.0 / (nextKeyframe.key() - prevKeyframe.key()); | 160 scale = 1.0 / (nextKeyframe.key() - prevKeyframe.key()); |
| 133 | 161 |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 | 467 |
| 440 if (acceleratedPropertiesOnly) { | 468 if (acceleratedPropertiesOnly) { |
| 441 bool isLooping; | 469 bool isLooping; |
| 442 getTimeToNextEvent(t, isLooping); | 470 getTimeToNextEvent(t, isLooping); |
| 443 } | 471 } |
| 444 | 472 |
| 445 return t; | 473 return t; |
| 446 } | 474 } |
| 447 | 475 |
| 448 } // namespace WebCore | 476 } // namespace WebCore |
| OLD | NEW |