| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ | 5 #ifndef ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ |
| 6 #define ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ | 6 #define ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
| 11 #include "ash/sticky_keys/sticky_keys_state.h" | 11 #include "ash/sticky_keys/sticky_keys_state.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "ui/chromeos/events/event_rewriter.h" |
| 13 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
| 14 #include "ui/events/event_handler.h" | 15 #include "ui/events/event_handler.h" |
| 15 #include "ui/events/event_rewriter.h" | 16 #include "ui/events/event_rewriter.h" |
| 16 #include "ui/events/keycodes/keyboard_codes.h" | 17 #include "ui/events/keycodes/keyboard_codes.h" |
| 17 | 18 |
| 18 namespace ui { | 19 namespace ui { |
| 19 class Event; | 20 class Event; |
| 20 class KeyEvent; | 21 class KeyEvent; |
| 21 class MouseEvent; | 22 class MouseEvent; |
| 22 } // namespace ui | 23 } // namespace ui |
| (...skipping 29 matching lines...) Expand all Loading... |
| 52 // 6. Release 1 key : 1 Keyup event with Ctrl modifier. | 53 // 6. Release 1 key : 1 Keyup event with Ctrl modifier. |
| 53 // 7. Press 2 key : 2 Keydown event with Ctrl modifier. | 54 // 7. Press 2 key : 2 Keydown event with Ctrl modifier. |
| 54 // 8. Release 2 key : 2 Keyup event with Ctrl modifier. | 55 // 8. Release 2 key : 2 Keyup event with Ctrl modifier. |
| 55 // 9. Press Ctrl key : No event | 56 // 9. Press Ctrl key : No event |
| 56 // 10. Release Ctrl key: Ctrl Keyup | 57 // 10. Release Ctrl key: Ctrl Keyup |
| 57 // | 58 // |
| 58 // In the case of Chrome OS, StickyKeysController supports Shift,Alt,Ctrl | 59 // In the case of Chrome OS, StickyKeysController supports Shift,Alt,Ctrl |
| 59 // modifiers. Each handling or state is performed independently. | 60 // modifiers. Each handling or state is performed independently. |
| 60 // | 61 // |
| 61 // StickyKeysController is disabled by default. | 62 // StickyKeysController is disabled by default. |
| 62 class ASH_EXPORT StickyKeysController { | 63 class ASH_EXPORT StickyKeysController |
| 64 : public ui::chromeos::EventRewriter::StickyKeysController { |
| 63 public: | 65 public: |
| 64 StickyKeysController(); | 66 StickyKeysController(); |
| 65 virtual ~StickyKeysController(); | 67 ~StickyKeysController() override; |
| 66 | 68 |
| 67 // Activate sticky keys to intercept and modify incoming events. | 69 // Activate sticky keys to intercept and modify incoming events. |
| 68 void Enable(bool enabled); | 70 void Enable(bool enabled); |
| 69 | 71 |
| 70 void SetModifiersEnabled(bool mod3_enabled, bool altgr_enabled); | 72 void SetModifiersEnabled(bool mod3_enabled, bool altgr_enabled); |
| 71 | 73 |
| 72 // Returns the StickyKeyOverlay used by the controller. Ownership is not | 74 // Returns the StickyKeyOverlay used by the controller. Ownership is not |
| 73 // passed. | 75 // passed. |
| 74 StickyKeysOverlay* GetOverlayForTest(); | 76 StickyKeysOverlay* GetOverlayForTest(); |
| 75 | 77 |
| 76 // Handles keyboard event. Returns an |EventRewriteStatus|, and may | 78 // ui::chromeos::StickyKeysController: |
| 77 // modify |flags|: | |
| 78 // - Returns ui::EVENT_REWRITE_DISCARD, and leaves |flags| untouched, | |
| 79 // if the event is consumed (i.e. a sticky modifier press or release); | |
| 80 // - Returns ui::EVENT_REWRITE_REWRITTEN if the event needs to be modified | |
| 81 // according to the returned |flags| (i.e. a sticky-modified key); | |
| 82 // - Returns ui::EVENT_REWRITE_DISPATCH_ANOTHER if the event needs to be | |
| 83 // modified according to the returned |flags|, and there are delayed | |
| 84 // modifier-up events now to be retrieved using |NextDispatchEvent()| | |
| 85 // (i.e. a sticky-modified key that ends a sticky state); | |
| 86 // - Otherwise returns ui::EVENT_REWRITE_CONTINUE and leaves |flags| | |
| 87 // unchanged. | |
| 88 ui::EventRewriteStatus RewriteKeyEvent(const ui::KeyEvent& event, | 79 ui::EventRewriteStatus RewriteKeyEvent(const ui::KeyEvent& event, |
| 89 ui::KeyboardCode key_code, | 80 ui::KeyboardCode key_code, |
| 90 int* flags); | 81 int* flags) override; |
| 91 | |
| 92 // Handles mouse event. | |
| 93 ui::EventRewriteStatus RewriteMouseEvent(const ui::MouseEvent& event, | 82 ui::EventRewriteStatus RewriteMouseEvent(const ui::MouseEvent& event, |
| 94 int* flags); | 83 int* flags) override; |
| 95 | |
| 96 // Handles scroll event. | |
| 97 ui::EventRewriteStatus RewriteScrollEvent(const ui::ScrollEvent& event, | 84 ui::EventRewriteStatus RewriteScrollEvent(const ui::ScrollEvent& event, |
| 98 int* flags); | 85 int* flags) override; |
| 99 | |
| 100 // Obtains a pending modifier-up event. If the immediately previous | |
| 101 // call to |Rewrite...Event()| or |NextDispatchEvent()| returned | |
| 102 // ui::EVENT_REWRITE_DISPATCH_ANOTHER, this sets |new_event| and returns: | |
| 103 // - ui::EVENT_REWRITE_DISPATCH_ANOTHER if there is at least one more | |
| 104 // pending modifier-up event; | |
| 105 // - ui::EVENT_REWRITE_REWRITE if this is the last or only modifier-up event; | |
| 106 // Otherwise, there is no pending modifier-up event, and this function | |
| 107 // returns ui::EVENT_REWRITE_CONTINUE and sets |new_event| to NULL. | |
| 108 ui::EventRewriteStatus NextDispatchEvent( | 86 ui::EventRewriteStatus NextDispatchEvent( |
| 109 std::unique_ptr<ui::Event>* new_event); | 87 std::unique_ptr<ui::Event>* new_event) override; |
| 110 | 88 |
| 111 private: | 89 private: |
| 112 // Handles keyboard event. Returns true if Sticky key consumes keyboard event. | 90 // Handles keyboard event. Returns true if Sticky key consumes keyboard event. |
| 113 // Adds to |mod_down_flags| any flag to be added to the key event. | 91 // Adds to |mod_down_flags| any flag to be added to the key event. |
| 114 // Sets |released| if any modifier is to be released after the key event. | 92 // Sets |released| if any modifier is to be released after the key event. |
| 115 bool HandleKeyEvent(const ui::KeyEvent& event, | 93 bool HandleKeyEvent(const ui::KeyEvent& event, |
| 116 ui::KeyboardCode key_code, | 94 ui::KeyboardCode key_code, |
| 117 int* mod_down_flags, | 95 int* mod_down_flags, |
| 118 bool* released); | 96 bool* released); |
| 119 | 97 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 248 |
| 271 // The modifier up key event to be sent on non modifier key on ENABLED state. | 249 // The modifier up key event to be sent on non modifier key on ENABLED state. |
| 272 std::unique_ptr<ui::KeyEvent> modifier_up_event_; | 250 std::unique_ptr<ui::KeyEvent> modifier_up_event_; |
| 273 | 251 |
| 274 DISALLOW_COPY_AND_ASSIGN(StickyKeysHandler); | 252 DISALLOW_COPY_AND_ASSIGN(StickyKeysHandler); |
| 275 }; | 253 }; |
| 276 | 254 |
| 277 } // namespace ash | 255 } // namespace ash |
| 278 | 256 |
| 279 #endif // ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ | 257 #endif // ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ |
| OLD | NEW |