OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SELECT_TO_SPEAK_EVENT_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SELECT_TO_SPEAK_EVENT_HANDLER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SELECT_TO_SPEAK_EVENT_HANDLER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SELECT_TO_SPEAK_EVENT_HANDLER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "ui/events/event_handler.h" | 11 #include "ui/events/event_handler.h" |
12 #include "ui/events/keycodes/keyboard_codes.h" | 12 #include "ui/events/keycodes/keyboard_codes.h" |
13 | 13 |
14 namespace chromeos { | 14 namespace chromeos { |
15 | 15 |
16 class SelectToSpeakForwardedEventDelegateForTesting { | |
17 public: | |
18 virtual void OnForwardEventToSelectToSpeakExtension( | |
19 const ui::MouseEvent& event) = 0; | |
20 }; | |
21 | |
22 // Intercepts mouse events while the Search key is held down, and sends | 16 // Intercepts mouse events while the Search key is held down, and sends |
23 // accessibility events to the Select-to-speak extension instead. | 17 // accessibility events to the Select-to-speak extension instead. |
24 class SelectToSpeakEventHandler : public ui::EventHandler { | 18 class SelectToSpeakEventHandler : public ui::EventHandler { |
25 public: | 19 public: |
26 SelectToSpeakEventHandler(); | 20 SelectToSpeakEventHandler(); |
27 ~SelectToSpeakEventHandler() override; | 21 ~SelectToSpeakEventHandler() override; |
28 | 22 |
29 // For testing, call the provided callback with any events that would have | |
30 // been forwarded to the Select-to-speak extension instead. | |
31 void CaptureForwardedEventsForTesting( | |
32 SelectToSpeakForwardedEventDelegateForTesting* delegate); | |
33 | |
34 private: | 23 private: |
35 // EventHandler: | 24 // EventHandler: |
36 void OnKeyEvent(ui::KeyEvent* event) override; | 25 void OnKeyEvent(ui::KeyEvent* event) override; |
37 void OnMouseEvent(ui::MouseEvent* event) override; | 26 void OnMouseEvent(ui::MouseEvent* event) override; |
38 | 27 |
39 void CancelEvent(ui::Event* event); | 28 void CancelEvent(ui::Event* event); |
| 29 void SendCancelAXEvent(); |
40 | 30 |
41 enum State { | 31 enum State { |
42 // Neither the Search key nor the mouse button are down. | 32 // Neither the Search key nor the mouse button are down. |
43 INACTIVE, | 33 INACTIVE, |
44 | 34 |
45 // The Search key is down but the mouse button is not. | 35 // The Search key is down but the mouse button is not. |
46 SEARCH_DOWN, | 36 SEARCH_DOWN, |
47 | 37 |
48 // The user held down Search and clicked the mouse button. We're capturing | 38 // The user held down Search and clicked the mouse button. We're capturing |
49 // all events from now on until either Search or the mouse button is | 39 // all events from now on until either Search or the mouse button is |
50 // released. | 40 // released. |
51 CAPTURING, | 41 CAPTURING, |
52 | 42 |
53 // The mouse was released, but Search is still held down. If the user | 43 // The mouse was released, but Search is still held down. If the user |
54 // clicks again, we'll go back to the state CAPTURING. This is different | 44 // clicks again, we'll go back to the state CAPTURING. This is different |
55 // than the state SEARCH_DOWN because we know the user clicked at least | 45 // than the state SEARCH_DOWN because we know the user clicked at least |
56 // once, so when Search is released we'll handle that event too, so as | 46 // once, so when Search is released we'll handle that event too, so as |
57 // to not trigger opening the Search UI. | 47 // to not trigger opening the Search UI. |
58 MOUSE_RELEASED, | 48 MOUSE_RELEASED, |
59 | 49 |
60 // The Search key was released while the mouse was still down, cancelling | 50 // The Search key was released while the mouse was still down, cancelling |
61 // the Select-to-Speak event. Stay in this mode until the mouse button | 51 // the Select-to-Speak event. Stay in this mode until the mouse button |
62 // is released, too. | 52 // is released, too. |
63 WAIT_FOR_MOUSE_RELEASE | 53 WAIT_FOR_MOUSE_RELEASE |
64 }; | 54 }; |
65 | 55 |
66 State state_ = INACTIVE; | 56 State state_ = INACTIVE; |
67 | 57 |
68 SelectToSpeakForwardedEventDelegateForTesting* event_delegate_for_testing_; | 58 // The set of keys that are currently down. Updated whenever a key is |
| 59 // pressed or released. |
| 60 std::set<ui::KeyboardCode> keys_currently_down_; |
| 61 // The set of keys that have been pressed together. Updated whenever a key |
| 62 // is pressed, and only cleared when all keys are released. |
| 63 std::set<ui::KeyboardCode> keys_pressed_together_; |
69 | 64 |
70 DISALLOW_COPY_AND_ASSIGN(SelectToSpeakEventHandler); | 65 DISALLOW_COPY_AND_ASSIGN(SelectToSpeakEventHandler); |
71 }; | 66 }; |
72 | 67 |
73 } // namespace chromeos | 68 } // namespace chromeos |
74 | 69 |
75 #endif // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SELECT_TO_SPEAK_EVENT_HANDLER_H
_ | 70 #endif // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SELECT_TO_SPEAK_EVENT_HANDLER_H
_ |
OLD | NEW |