blob: 41656d2d1c2eceda411a0f6f385b4208275731b2 [file] [log] [blame]
bburg@apple.com6fa0f902014-03-03 17:01:11 +00001/*
2 * Copyright (C) 2013 University of Washington. All rights reserved.
3 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef EventLoopInputDispatcher_h
29#define EventLoopInputDispatcher_h
30
31#if ENABLE(WEB_REPLAY)
32
33#include "EventLoopInput.h"
burg@cs.washington.edu58098d52014-08-06 21:53:17 +000034#include "ReplayingInputCursor.h"
bburg@apple.com6fa0f902014-03-03 17:01:11 +000035#include "Timer.h"
36#include <wtf/Noncopyable.h>
37#include <wtf/Vector.h>
38#include <wtf/text/WTFString.h>
39
40namespace WebCore {
41
42class Page;
bburg@apple.com6fa0f902014-03-03 17:01:11 +000043
44enum class DispatchSpeed {
45 RealTime,
46 FastForward,
47};
48
49class EventLoopInputDispatcherClient {
50public:
51 EventLoopInputDispatcherClient() { }
52 virtual ~EventLoopInputDispatcherClient() { }
53
54 virtual void willDispatchInput(const EventLoopInputBase&) =0;
55 virtual void didDispatchInput(const EventLoopInputBase&) =0;
56 virtual void didDispatchFinalInput() =0;
57};
58
59class EventLoopInputDispatcher {
60 WTF_MAKE_NONCOPYABLE(EventLoopInputDispatcher);
61public:
62 EventLoopInputDispatcher(Page&, ReplayingInputCursor&, EventLoopInputDispatcherClient*);
63
64 void run();
65 void pause();
66
67 void setDispatchSpeed(DispatchSpeed speed) { m_speed = speed; }
68 DispatchSpeed dispatchSpeed() const { return m_speed; }
bburg@apple.com3f511b02014-03-20 18:49:59 +000069
70 bool isRunning() const { return m_running; }
burg@cs.washington.edu094f7852014-04-07 19:58:07 +000071 bool isDispatching() const { return m_dispatching; }
bburg@apple.com6fa0f902014-03-03 17:01:11 +000072private:
73 void dispatchInputSoon();
74 void dispatchInput();
andersca@apple.com574a7452014-11-21 20:10:13 +000075 void timerFired();
bburg@apple.com6fa0f902014-03-03 17:01:11 +000076
77 Page& m_page;
78 EventLoopInputDispatcherClient* m_client;
79 ReplayingInputCursor& m_cursor;
jer.noble@apple.com50862fe2014-11-06 23:06:03 +000080 Timer m_timer;
bburg@apple.com6fa0f902014-03-03 17:01:11 +000081
burg@cs.washington.edu58098d52014-08-06 21:53:17 +000082 // This data is valid when an event loop input is presently dispatching.
83 EventLoopInputData m_currentWork;
bburg@apple.com3f511b02014-03-20 18:49:59 +000084 // Whether the dispatcher is currently calling out to an inputs' dispatch() method.
burg@cs.washington.edud35360f2015-01-16 22:13:08 +000085 bool m_dispatching {false};
bburg@apple.com3f511b02014-03-20 18:49:59 +000086 // Whether the dispatcher is waiting to dispatch or actively dispatching inputs.
burg@cs.washington.edud35360f2015-01-16 22:13:08 +000087 bool m_running {false};
bburg@apple.com6fa0f902014-03-03 17:01:11 +000088
89 DispatchSpeed m_speed;
90 // The time at which the last input dispatch() method was called.
burg@cs.washington.edud35360f2015-01-16 22:13:08 +000091 double m_previousDispatchStartTime {0.0};
bburg@apple.com6fa0f902014-03-03 17:01:11 +000092 // The timestamp specified by the last dispatched input.
burg@cs.washington.edud35360f2015-01-16 22:13:08 +000093 double m_previousInputTimestamp {0.0};
bburg@apple.com6fa0f902014-03-03 17:01:11 +000094};
95
96} // namespace WebCore
97
98#endif // ENABLE(WEB_REPLAY)
99
100#endif // EventLoopInputDispatcher_h