bburg@apple.com | 6fa0f90 | 2014-03-03 17:01:11 +0000 | [diff] [blame] | 1 | /* |
| 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.edu | 58098d5 | 2014-08-06 21:53:17 +0000 | [diff] [blame] | 34 | #include "ReplayingInputCursor.h" |
bburg@apple.com | 6fa0f90 | 2014-03-03 17:01:11 +0000 | [diff] [blame] | 35 | #include "Timer.h" |
| 36 | #include <wtf/Noncopyable.h> |
| 37 | #include <wtf/Vector.h> |
| 38 | #include <wtf/text/WTFString.h> |
| 39 | |
| 40 | namespace WebCore { |
| 41 | |
| 42 | class Page; |
bburg@apple.com | 6fa0f90 | 2014-03-03 17:01:11 +0000 | [diff] [blame] | 43 | |
| 44 | enum class DispatchSpeed { |
| 45 | RealTime, |
| 46 | FastForward, |
| 47 | }; |
| 48 | |
| 49 | class EventLoopInputDispatcherClient { |
| 50 | public: |
| 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 | |
| 59 | class EventLoopInputDispatcher { |
| 60 | WTF_MAKE_NONCOPYABLE(EventLoopInputDispatcher); |
| 61 | public: |
| 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.com | 3f511b0 | 2014-03-20 18:49:59 +0000 | [diff] [blame] | 69 | |
| 70 | bool isRunning() const { return m_running; } |
burg@cs.washington.edu | 094f785 | 2014-04-07 19:58:07 +0000 | [diff] [blame] | 71 | bool isDispatching() const { return m_dispatching; } |
bburg@apple.com | 6fa0f90 | 2014-03-03 17:01:11 +0000 | [diff] [blame] | 72 | private: |
| 73 | void dispatchInputSoon(); |
| 74 | void dispatchInput(); |
andersca@apple.com | 574a745 | 2014-11-21 20:10:13 +0000 | [diff] [blame] | 75 | void timerFired(); |
bburg@apple.com | 6fa0f90 | 2014-03-03 17:01:11 +0000 | [diff] [blame] | 76 | |
| 77 | Page& m_page; |
| 78 | EventLoopInputDispatcherClient* m_client; |
| 79 | ReplayingInputCursor& m_cursor; |
jer.noble@apple.com | 50862fe | 2014-11-06 23:06:03 +0000 | [diff] [blame] | 80 | Timer m_timer; |
bburg@apple.com | 6fa0f90 | 2014-03-03 17:01:11 +0000 | [diff] [blame] | 81 | |
burg@cs.washington.edu | 58098d5 | 2014-08-06 21:53:17 +0000 | [diff] [blame] | 82 | // This data is valid when an event loop input is presently dispatching. |
| 83 | EventLoopInputData m_currentWork; |
bburg@apple.com | 3f511b0 | 2014-03-20 18:49:59 +0000 | [diff] [blame] | 84 | // Whether the dispatcher is currently calling out to an inputs' dispatch() method. |
burg@cs.washington.edu | d35360f | 2015-01-16 22:13:08 +0000 | [diff] [blame] | 85 | bool m_dispatching {false}; |
bburg@apple.com | 3f511b0 | 2014-03-20 18:49:59 +0000 | [diff] [blame] | 86 | // Whether the dispatcher is waiting to dispatch or actively dispatching inputs. |
burg@cs.washington.edu | d35360f | 2015-01-16 22:13:08 +0000 | [diff] [blame] | 87 | bool m_running {false}; |
bburg@apple.com | 6fa0f90 | 2014-03-03 17:01:11 +0000 | [diff] [blame] | 88 | |
| 89 | DispatchSpeed m_speed; |
| 90 | // The time at which the last input dispatch() method was called. |
burg@cs.washington.edu | d35360f | 2015-01-16 22:13:08 +0000 | [diff] [blame] | 91 | double m_previousDispatchStartTime {0.0}; |
bburg@apple.com | 6fa0f90 | 2014-03-03 17:01:11 +0000 | [diff] [blame] | 92 | // The timestamp specified by the last dispatched input. |
burg@cs.washington.edu | d35360f | 2015-01-16 22:13:08 +0000 | [diff] [blame] | 93 | double m_previousInputTimestamp {0.0}; |
bburg@apple.com | 6fa0f90 | 2014-03-03 17:01:11 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | } // namespace WebCore |
| 97 | |
| 98 | #endif // ENABLE(WEB_REPLAY) |
| 99 | |
| 100 | #endif // EventLoopInputDispatcher_h |