OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_EVENT_RECORDER_H_ | 5 #ifndef BASE_EVENT_RECORDER_H_ |
6 #define BASE_EVENT_RECORDER_H_ | 6 #define BASE_EVENT_RECORDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
11 #endif | 11 #endif |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 | 13 |
| 14 class FilePath; |
| 15 |
14 namespace base { | 16 namespace base { |
15 | 17 |
16 // A class for recording and playing back keyboard and mouse input events. | 18 // A class for recording and playing back keyboard and mouse input events. |
17 // | 19 // |
18 // Note - if you record events, and the playback with the windows in | 20 // Note - if you record events, and the playback with the windows in |
19 // different sizes or positions, the playback will fail. When | 21 // different sizes or positions, the playback will fail. When |
20 // recording and playing, you should move the relevant windows | 22 // recording and playing, you should move the relevant windows |
21 // to constant sizes and locations. | 23 // to constant sizes and locations. |
22 // TODO(mbelshe) For now this is a singleton. I believe that this class | 24 // TODO(mbelshe) For now this is a singleton. I believe that this class |
23 // could be easily modified to: | 25 // could be easily modified to: |
24 // support two simultaneous recorders | 26 // support two simultaneous recorders |
25 // be playing back events while already recording events. | 27 // be playing back events while already recording events. |
26 // Why? Imagine if the product had a "record a macro" feature. | 28 // Why? Imagine if the product had a "record a macro" feature. |
27 // You might be recording globally, while recording or playing back | 29 // You might be recording globally, while recording or playing back |
28 // a macro. I don't think two playbacks make sense. | 30 // a macro. I don't think two playbacks make sense. |
29 class EventRecorder { | 31 class EventRecorder { |
30 public: | 32 public: |
31 // Get the singleton EventRecorder. | 33 // Get the singleton EventRecorder. |
32 // We can only handle one recorder/player at a time. | 34 // We can only handle one recorder/player at a time. |
33 static EventRecorder* current() { | 35 static EventRecorder* current() { |
34 if (!current_) | 36 if (!current_) |
35 current_ = new EventRecorder(); | 37 current_ = new EventRecorder(); |
36 return current_; | 38 return current_; |
37 } | 39 } |
38 | 40 |
39 // Starts recording events. | 41 // Starts recording events. |
40 // Will clobber the file if it already exists. | 42 // Will clobber the file if it already exists. |
41 // Returns true on success, or false if an error occurred. | 43 // Returns true on success, or false if an error occurred. |
42 bool StartRecording(const std::wstring& filename); | 44 bool StartRecording(const FilePath& filename); |
43 | 45 |
44 // Stops recording. | 46 // Stops recording. |
45 void StopRecording(); | 47 void StopRecording(); |
46 | 48 |
47 // Is the EventRecorder currently recording. | 49 // Is the EventRecorder currently recording. |
48 bool is_recording() const { return is_recording_; } | 50 bool is_recording() const { return is_recording_; } |
49 | 51 |
50 // Plays events previously recorded. | 52 // Plays events previously recorded. |
51 // Returns true on success, or false if an error occurred. | 53 // Returns true on success, or false if an error occurred. |
52 bool StartPlayback(const std::wstring& filename); | 54 bool StartPlayback(const FilePath& filename); |
53 | 55 |
54 // Stops playback. | 56 // Stops playback. |
55 void StopPlayback(); | 57 void StopPlayback(); |
56 | 58 |
57 // Is the EventRecorder currently playing. | 59 // Is the EventRecorder currently playing. |
58 bool is_playing() const { return is_playing_; } | 60 bool is_playing() const { return is_playing_; } |
59 | 61 |
60 #if defined(OS_WIN) | 62 #if defined(OS_WIN) |
61 // C-style callbacks for the EventRecorder. | 63 // C-style callbacks for the EventRecorder. |
62 // Used for internal purposes only. | 64 // Used for internal purposes only. |
(...skipping 28 matching lines...) Expand all Loading... |
91 #endif | 93 #endif |
92 int playback_first_msg_time_; | 94 int playback_first_msg_time_; |
93 int playback_start_time_; | 95 int playback_start_time_; |
94 | 96 |
95 DISALLOW_EVIL_CONSTRUCTORS(EventRecorder); | 97 DISALLOW_EVIL_CONSTRUCTORS(EventRecorder); |
96 }; | 98 }; |
97 | 99 |
98 } // namespace base | 100 } // namespace base |
99 | 101 |
100 #endif // BASE_EVENT_RECORDER_H_ | 102 #endif // BASE_EVENT_RECORDER_H_ |
OLD | NEW |