Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: chrome/browser/chromeos/accessibility/select_to_speak_event_handler.h

Issue 2814213002: Refactor Select-to-speak so that mouse events are forwarded to the extension. (Closed)
Patch Set: closure Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
16 // Intercepts mouse events while the Search key is held down, and sends 22 // Intercepts mouse events while the Search key is held down, and sends
17 // accessibility events to the Select-to-speak extension instead. 23 // accessibility events to the Select-to-speak extension instead.
18 class SelectToSpeakEventHandler : public ui::EventHandler { 24 class SelectToSpeakEventHandler : public ui::EventHandler {
19 public: 25 public:
20 SelectToSpeakEventHandler(); 26 SelectToSpeakEventHandler();
21 ~SelectToSpeakEventHandler() override; 27 ~SelectToSpeakEventHandler() override;
22 28
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
23 private: 34 private:
24 // EventHandler: 35 // EventHandler:
25 void OnKeyEvent(ui::KeyEvent* event) override; 36 void OnKeyEvent(ui::KeyEvent* event) override;
26 void OnMouseEvent(ui::MouseEvent* event) override; 37 void OnMouseEvent(ui::MouseEvent* event) override;
27 38
28 void CancelEvent(ui::Event* event); 39 void CancelEvent(ui::Event* event);
29 void SendCancelAXEvent();
30 40
31 enum State { 41 enum State {
32 // Neither the Search key nor the mouse button are down. 42 // Neither the Search key nor the mouse button are down.
33 INACTIVE, 43 INACTIVE,
34 44
35 // The Search key is down but the mouse button is not. 45 // The Search key is down but the mouse button is not.
36 SEARCH_DOWN, 46 SEARCH_DOWN,
37 47
38 // The user held down Search and clicked the mouse button. We're capturing 48 // The user held down Search and clicked the mouse button. We're capturing
39 // all events from now on until either Search or the mouse button is 49 // all events from now on until either Search or the mouse button is
40 // released. 50 // released.
41 CAPTURING, 51 CAPTURING,
42 52
43 // The mouse was released, but Search is still held down. If the user 53 // The mouse was released, but Search is still held down. If the user
44 // clicks again, we'll go back to the state CAPTURING. This is different 54 // clicks again, we'll go back to the state CAPTURING. This is different
45 // than the state SEARCH_DOWN because we know the user clicked at least 55 // than the state SEARCH_DOWN because we know the user clicked at least
46 // once, so when Search is released we'll handle that event too, so as 56 // once, so when Search is released we'll handle that event too, so as
47 // to not trigger opening the Search UI. 57 // to not trigger opening the Search UI.
48 MOUSE_RELEASED, 58 MOUSE_RELEASED,
49 59
50 // The Search key was released while the mouse was still down, cancelling 60 // The Search key was released while the mouse was still down, cancelling
51 // the Select-to-Speak event. Stay in this mode until the mouse button 61 // the Select-to-Speak event. Stay in this mode until the mouse button
52 // is released, too. 62 // is released, too.
53 WAIT_FOR_MOUSE_RELEASE 63 WAIT_FOR_MOUSE_RELEASE
54 }; 64 };
55 65
56 State state_ = INACTIVE; 66 State state_ = INACTIVE;
57 67
58 // The set of keys that are currently down. Updated whenever a key is 68 SelectToSpeakForwardedEventDelegateForTesting* event_delegate_for_testing_;
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_;
64 69
65 DISALLOW_COPY_AND_ASSIGN(SelectToSpeakEventHandler); 70 DISALLOW_COPY_AND_ASSIGN(SelectToSpeakEventHandler);
66 }; 71 };
67 72
68 } // namespace chromeos 73 } // namespace chromeos
69 74
70 #endif // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SELECT_TO_SPEAK_EVENT_HANDLER_H _ 75 #endif // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SELECT_TO_SPEAK_EVENT_HANDLER_H _
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/BUILD.gn ('k') | chrome/browser/chromeos/accessibility/select_to_speak_event_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698