blob: d2c9c0c0b9961c18d4bd7f5d27e01255e6acb99e [file] [log] [blame]
jamesr@google.com9f8b52b2011-02-16 00:53:36 +00001/*
2 * Copyright (C) 2011 Google Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 */
25
26#ifndef ScriptedAnimationController_h
27#define ScriptedAnimationController_h
28
kevino@webkit.org4e26c272011-02-17 20:24:52 +000029#if ENABLE(REQUEST_ANIMATION_FRAME)
jamesr@google.com9f8b52b2011-02-16 00:53:36 +000030#include "DOMTimeStamp.h"
cmarrin@apple.comd9dca742011-09-10 14:21:01 +000031#if USE(REQUEST_ANIMATION_FRAME_TIMER)
cmarrin@apple.com4386e022011-10-13 21:59:25 +000032#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
33#include "DisplayRefreshMonitor.h"
34#endif
cmarrin@apple.comd9dca742011-09-10 14:21:01 +000035#include "Timer.h"
36#endif
cmarrin@apple.com4386e022011-10-13 21:59:25 +000037#include "PlatformScreen.h"
jamesr@google.coma5d3c9e2011-12-09 01:33:41 +000038#include <wtf/RefCounted.h>
jamesr@google.com9f8b52b2011-02-16 00:53:36 +000039#include <wtf/RefPtr.h>
40#include <wtf/Vector.h>
41
42namespace WebCore {
43
44class Document;
45class Element;
46class RequestAnimationFrameCallback;
47
jamesr@google.coma5d3c9e2011-12-09 01:33:41 +000048class ScriptedAnimationController : public RefCounted<ScriptedAnimationController>
cmarrin@apple.com4386e022011-10-13 21:59:25 +000049#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
jamesr@google.coma5d3c9e2011-12-09 01:33:41 +000050 , public DisplayRefreshMonitorClient
cmarrin@apple.com4386e022011-10-13 21:59:25 +000051#endif
52{
jamesr@google.com9f8b52b2011-02-16 00:53:36 +000053public:
jamesr@google.coma5d3c9e2011-12-09 01:33:41 +000054 static PassRefPtr<ScriptedAnimationController> create(Document* document, PlatformDisplayID displayID)
jamesr@google.com9f8b52b2011-02-16 00:53:36 +000055 {
jamesr@google.coma5d3c9e2011-12-09 01:33:41 +000056 return adoptRef(new ScriptedAnimationController(document, displayID));
jamesr@google.com9f8b52b2011-02-16 00:53:36 +000057 }
jamesr@google.coma5d3c9e2011-12-09 01:33:41 +000058 ~ScriptedAnimationController();
59 void clearDocumentPointer() { m_document = 0; }
jamesr@google.com9f8b52b2011-02-16 00:53:36 +000060
61 typedef int CallbackId;
62
63 CallbackId registerCallback(PassRefPtr<RequestAnimationFrameCallback>, Element*);
64 void cancelCallback(CallbackId);
65 void serviceScriptedAnimations(DOMTimeStamp);
66
67 void suspend();
68 void resume();
69
cmarrin@apple.com4386e022011-10-13 21:59:25 +000070 void windowScreenDidChange(PlatformDisplayID);
71
jamesr@google.com9f8b52b2011-02-16 00:53:36 +000072private:
jamesr@google.coma5d3c9e2011-12-09 01:33:41 +000073 ScriptedAnimationController(Document*, PlatformDisplayID);
cmarrin@apple.comd9dca742011-09-10 14:21:01 +000074
jamesr@google.com9f8b52b2011-02-16 00:53:36 +000075 typedef Vector<RefPtr<RequestAnimationFrameCallback> > CallbackList;
76 CallbackList m_callbacks;
77
78 Document* m_document;
79 CallbackId m_nextCallbackId;
80 int m_suspendCount;
cmarrin@apple.comd9dca742011-09-10 14:21:01 +000081
82 void scheduleAnimation();
83
84#if USE(REQUEST_ANIMATION_FRAME_TIMER)
85 void animationTimerFired(Timer<ScriptedAnimationController>*);
86 Timer<ScriptedAnimationController> m_animationTimer;
87 double m_lastAnimationFrameTime;
cmarrin@apple.com4386e022011-10-13 21:59:25 +000088
89#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
90 // Override for DisplayRefreshMonitorClient
91 virtual void displayRefreshFired(double timestamp) { serviceScriptedAnimations(convertSecondsToDOMTimeStamp(timestamp)); }
92
93 bool m_useTimer;
94#endif
cmarrin@apple.comd9dca742011-09-10 14:21:01 +000095#endif
jamesr@google.com9f8b52b2011-02-16 00:53:36 +000096};
97
98}
99
kevino@webkit.org4e26c272011-02-17 20:24:52 +0000100#endif // ENABLE(REQUEST_ANIMATION_FRAME)
101
jamesr@google.com9f8b52b2011-02-16 00:53:36 +0000102#endif // ScriptedAnimationController_h
103