Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: Source/core/svg/animation/SMILTimeContainer.cpp

Issue 802143002: AnimationPolicy setting is applied to SVG animation. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Move code to SMILTimeContainer and add LayoutTests Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 12 matching lines...) Expand all
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/svg/animation/SMILTimeContainer.h" 27 #include "core/svg/animation/SMILTimeContainer.h"
28 28
29 #include "core/animation/AnimationClock.h" 29 #include "core/animation/AnimationClock.h"
30 #include "core/animation/AnimationTimeline.h" 30 #include "core/animation/AnimationTimeline.h"
31 #include "core/dom/ElementTraversal.h" 31 #include "core/dom/ElementTraversal.h"
32 #include "core/frame/FrameView.h" 32 #include "core/frame/FrameView.h"
33 #include "core/frame/Settings.h"
33 #include "core/svg/SVGSVGElement.h" 34 #include "core/svg/SVGSVGElement.h"
34 #include "core/svg/animation/SVGSMILElement.h" 35 #include "core/svg/animation/SVGSMILElement.h"
35 36
36 namespace blink { 37 namespace blink {
37 38
38 static const double initialFrameDelay = 0.025; 39 static const double initialFrameDelay = 0.025;
40 static const double animationPolicyOnceDuration = 3.000;
39 41
40 #if !ENABLE(OILPAN) 42 #if !ENABLE(OILPAN)
41 // Every entry-point that calls updateAnimations() should instantiate a 43 // Every entry-point that calls updateAnimations() should instantiate a
42 // DiscardScope to prevent deletion of the ownerElement (and hence itself.) 44 // DiscardScope to prevent deletion of the ownerElement (and hence itself.)
43 class DiscardScope { 45 class DiscardScope {
44 public: 46 public:
45 explicit DiscardScope(SVGSVGElement& timeContainerOwner) : m_discardScopeEle ment(&timeContainerOwner) { } 47 explicit DiscardScope(SVGSVGElement& timeContainerOwner) : m_discardScopeEle ment(&timeContainerOwner) { }
46 48
47 private: 49 private:
48 RefPtr<SVGSVGElement> m_discardScopeElement; 50 RefPtr<SVGSVGElement> m_discardScopeElement;
49 }; 51 };
50 #endif 52 #endif
51 53
52 SMILTimeContainer::SMILTimeContainer(SVGSVGElement& owner) 54 SMILTimeContainer::SMILTimeContainer(SVGSVGElement& owner)
53 : m_beginTime(0) 55 : m_beginTime(0)
54 , m_pauseTime(0) 56 , m_pauseTime(0)
55 , m_resumeTime(0) 57 , m_resumeTime(0)
56 , m_accumulatedActiveTime(0) 58 , m_accumulatedActiveTime(0)
57 , m_presetStartTime(0) 59 , m_presetStartTime(0)
58 , m_frameSchedulingState(Idle) 60 , m_frameSchedulingState(Idle)
59 , m_documentOrderIndexesDirty(false) 61 , m_documentOrderIndexesDirty(false)
60 , m_wakeupTimer(this, &SMILTimeContainer::wakeupTimerFired) 62 , m_wakeupTimer(this, &SMILTimeContainer::wakeupTimerFired)
63 , m_animationPolicyOnceTimer(this, &SMILTimeContainer::animationPolicyOnceTi merFired)
61 , m_ownerSVGElement(owner) 64 , m_ownerSVGElement(owner)
62 #if ENABLE(ASSERT) 65 #if ENABLE(ASSERT)
63 , m_preventScheduledAnimationsChanges(false) 66 , m_preventScheduledAnimationsChanges(false)
64 #endif 67 #endif
65 { 68 {
66 } 69 }
67 70
68 SMILTimeContainer::~SMILTimeContainer() 71 SMILTimeContainer::~SMILTimeContainer()
69 { 72 {
70 cancelAnimationFrame(); 73 cancelAnimationFrame();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 159 }
157 160
158 bool SMILTimeContainer::isStarted() const 161 bool SMILTimeContainer::isStarted() const
159 { 162 {
160 return m_beginTime; 163 return m_beginTime;
161 } 164 }
162 165
163 void SMILTimeContainer::begin() 166 void SMILTimeContainer::begin()
164 { 167 {
165 RELEASE_ASSERT(!m_beginTime); 168 RELEASE_ASSERT(!m_beginTime);
169
170 if (document().settings()) {
171 ImageAnimationPolicy animationPolicy = document().settings()->imageAnima tionPolicy();
fs 2014/12/18 16:45:18 I'd suggest you move these two into a helper funct
je_julie(Not used) 2014/12/22 15:05:18 Done.
172 if (animationPolicy == ImageAnimationPolicyNoAnimation)
173 return;
fs 2014/12/18 16:45:18 I'm a bit worried that this will leave us in an in
je_julie(Not used) 2014/12/22 15:05:18 I updated new concept with considering DOM APIs.
174 // Repeating behavior is not well-defined for SMIL/SVG animations
175 // We define "once" as "play for animationPolicyOnceDuration seconds" he re instead.
176 if (animationPolicy == ImageAnimationPolicyAnimateOnce)
177 m_animationPolicyOnceTimer.startOneShot(animationPolicyOnceDuration, FROM_HERE);
fs 2014/12/18 16:45:18 I suppose this is one way to implement this. It ha
je_julie(Not used) 2014/12/22 15:05:18 Please check my new concept.
178 }
166 double now = currentTime(); 179 double now = currentTime();
167 180
168 // If 'm_presetStartTime' is set, the timeline was modified via setElapsed() before the document began. 181 // If 'm_presetStartTime' is set, the timeline was modified via setElapsed() before the document began.
169 // In this case pass on 'seekToTime=true' to updateAnimations(). 182 // In this case pass on 'seekToTime=true' to updateAnimations().
170 m_beginTime = now - m_presetStartTime; 183 m_beginTime = now - m_presetStartTime;
171 #if !ENABLE(OILPAN) 184 #if !ENABLE(OILPAN)
172 DiscardScope discardScope(m_ownerSVGElement); 185 DiscardScope discardScope(m_ownerSVGElement);
173 #endif 186 #endif
174 SMILTime earliestFireTime = updateAnimations(SMILTime(m_presetStartTime), m_ presetStartTime ? true : false); 187 SMILTime earliestFireTime = updateAnimations(SMILTime(m_presetStartTime), m_ presetStartTime ? true : false);
175 m_presetStartTime = 0; 188 m_presetStartTime = 0;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 227 }
215 228
216 void SMILTimeContainer::setElapsed(SMILTime time) 229 void SMILTimeContainer::setElapsed(SMILTime time)
217 { 230 {
218 // If the documment didn't begin yet, record a new start time, we'll seek to once its possible. 231 // If the documment didn't begin yet, record a new start time, we'll seek to once its possible.
219 if (!m_beginTime) { 232 if (!m_beginTime) {
220 m_presetStartTime = time.value(); 233 m_presetStartTime = time.value();
221 return; 234 return;
222 } 235 }
223 236
237 // If imageAnimationPolicy is 'once', animation is stopped at animationPolic yOnceDuration.
238 // setElapsed over animationPolicyOnceDuration is not allowed.
239 if (document().settings()) {
240 ImageAnimationPolicy animationPolicy = document().settings()->imageAnima tionPolicy();
241 if (animationPolicy == ImageAnimationPolicyAnimateOnce
242 && time.value() > animationPolicyOnceDuration)
243 time = SMILTime(animationPolicyOnceDuration);
fs 2014/12/18 16:45:18 Should be possible to simply do: time = std::min(
je_julie(Not used) 2014/12/22 15:05:18 Please check my new concept.
244 }
245
224 cancelAnimationFrame(); 246 cancelAnimationFrame();
225 247
226 double now = currentTime(); 248 double now = currentTime();
227 m_beginTime = now - time.value(); 249 m_beginTime = now - time.value();
228 m_resumeTime = 0; 250 m_resumeTime = 0;
229 if (m_pauseTime) { 251 if (m_pauseTime) {
230 m_pauseTime = now; 252 m_pauseTime = now;
231 m_accumulatedActiveTime = time.value(); 253 m_accumulatedActiveTime = time.value();
232 } else { 254 } else {
233 m_accumulatedActiveTime = 0; 255 m_accumulatedActiveTime = 0;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 if (m_frameSchedulingState == FutureAnimationFrame) { 310 if (m_frameSchedulingState == FutureAnimationFrame) {
289 ASSERT(isTimelineRunning()); 311 ASSERT(isTimelineRunning());
290 m_frameSchedulingState = Idle; 312 m_frameSchedulingState = Idle;
291 serviceOnNextFrame(); 313 serviceOnNextFrame();
292 } else { 314 } else {
293 m_frameSchedulingState = Idle; 315 m_frameSchedulingState = Idle;
294 updateAnimationsAndScheduleFrameIfNeeded(elapsed()); 316 updateAnimationsAndScheduleFrameIfNeeded(elapsed());
295 } 317 }
296 } 318 }
297 319
320 void SMILTimeContainer::animationPolicyOnceTimerFired(Timer<SMILTimeContainer>*)
321 {
322 cancelAnimationFrame();
fs 2014/12/18 16:45:18 I don't think is enough (see above about DOM metho
je_julie(Not used) 2014/12/22 15:05:18 I added new function for freeze.
323 }
324
298 void SMILTimeContainer::updateDocumentOrderIndexes() 325 void SMILTimeContainer::updateDocumentOrderIndexes()
299 { 326 {
300 unsigned timingElementCount = 0; 327 unsigned timingElementCount = 0;
301 for (SVGSMILElement& element : Traversal<SVGSMILElement>::descendantsOf(m_ow nerSVGElement)) 328 for (SVGSMILElement& element : Traversal<SVGSMILElement>::descendantsOf(m_ow nerSVGElement))
302 element.setDocumentOrderIndex(timingElementCount++); 329 element.setDocumentOrderIndex(timingElementCount++);
303 m_documentOrderIndexesDirty = false; 330 m_documentOrderIndexesDirty = false;
304 } 331 }
305 332
306 struct PriorityCompare { 333 struct PriorityCompare {
307 PriorityCompare(SMILTime elapsed) : m_elapsed(elapsed) {} 334 PriorityCompare(SMILTime elapsed) : m_elapsed(elapsed) {}
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 } 492 }
466 493
467 void SMILTimeContainer::trace(Visitor* visitor) 494 void SMILTimeContainer::trace(Visitor* visitor)
468 { 495 {
469 #if ENABLE(OILPAN) 496 #if ENABLE(OILPAN)
470 visitor->trace(m_scheduledAnimations); 497 visitor->trace(m_scheduledAnimations);
471 #endif 498 #endif
472 } 499 }
473 500
474 } 501 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698