Chromium Code Reviews| Index: ash/sticky_keys/sticky_keys_controller.h |
| diff --git a/ash/sticky_keys/sticky_keys_controller.h b/ash/sticky_keys/sticky_keys_controller.h |
| index 89a196a986cf483708b531e975fa4d29b49ae9be..f921e84d1e5b55dd9241436299119f0df7097bd2 100644 |
| --- a/ash/sticky_keys/sticky_keys_controller.h |
| +++ b/ash/sticky_keys/sticky_keys_controller.h |
| @@ -10,6 +10,8 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "ui/events/event_constants.h" |
| #include "ui/events/event_handler.h" |
| +#include "ui/events/event_rewriter.h" |
| +#include "ui/events/keycodes/keyboard_codes.h" |
| namespace ui { |
| class Event; |
| @@ -59,7 +61,7 @@ class StickyKeysHandler; |
| // modifiers. Each handling or state is performed independently. |
| // |
| // StickyKeysController is disabled by default. |
| -class ASH_EXPORT StickyKeysController : public ui::EventHandler { |
| +class ASH_EXPORT StickyKeysController { |
| public: |
| StickyKeysController(); |
| virtual ~StickyKeysController(); |
| @@ -69,24 +71,57 @@ class ASH_EXPORT StickyKeysController : public ui::EventHandler { |
| void SetModifiersEnabled(bool mod3_enabled, bool altgr_enabled); |
| - // Overridden from ui::EventHandler: |
| - virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
| - virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
| - virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; |
| - |
| // Returns the StickyKeyOverlay used by the controller. Ownership is not |
| // passed. |
| StickyKeysOverlay* GetOverlayForTest(); |
| + // Handles keyboard event. Returns an |EventRewriteStatus|: |
| + // - ui::EVENT_REWRITE_DISCARD if the event is consumed (i.e. a sticky |
| + // modifier press or release); |
| + // - ui::EVENT_REWRITE_REWRITTEN if the event needs to be modified |
| + // according to the changes to |state|; |
|
Tim Song
2014/06/16 18:32:24
What does |state| refer to here? The StickyKeyStat
kpschoedel
2014/06/16 21:09:08
Should read |flags|; fixed.
|
| + // - ui::EVENT_REWRITE_DISPATCH_ANOTHER if there are delayed modifier-up |
| + // events now to be retrieved using |NextDispatchEvent()|; |
| + // - ui::EVENT_REWRITE_CONTINUE otherwise (no external action necessary). |
| + ui::EventRewriteStatus RewriteKeyEvent(const ui::KeyEvent& event, |
| + ui::KeyboardCode key_code, |
| + int* flags); |
| + |
| + // Handles mouse event. |
| + ui::EventRewriteStatus RewriteMouseEvent(const ui::MouseEvent& event, |
| + int* flags); |
| + |
| + // Handles scroll event. |
| + ui::EventRewriteStatus RewriteScrollEvent(const ui::ScrollEvent& event, |
| + int* flags); |
| + |
| + // Obtains a pending modifier-up event. Returns: |
| + // - ui::EVENT_REWRITE_DISPATCH_ANOTHER if there is at least one more |
| + // pending modifier-up event; |
| + // - ui::EVENT_REWRITE_REWRITE if this is the last or only modifier-up event; |
| + // - ui::EVENT_REWRITE_CONTINUE if there are no pending modifier-up events. |
|
Tim Song
2014/06/16 18:32:23
Mention that |new_event| will be null in this case
kpschoedel
2014/06/16 21:09:08
Done (borrowing from the corresponding comment in
|
| + ui::EventRewriteStatus NextDispatchEvent(scoped_ptr<ui::Event>* new_event); |
| + |
| private: |
| // Handles keyboard event. Returns true if Sticky key consumes keyboard event. |
| - bool HandleKeyEvent(ui::KeyEvent* event); |
| - |
| - // Handles mouse event. Returns true if sticky key consumes mouse event. |
| - bool HandleMouseEvent(ui::MouseEvent* event); |
| - |
| - // Handles scroll event. Returns true if sticky key consumes scroll event. |
| - bool HandleScrollEvent(ui::ScrollEvent* event); |
| + // Adds to |mod_down_flags| any flag to be added to the key event. |
| + // Adds to |mod_up_flags| any flag to be released after the key event. |
| + bool HandleKeyEvent(const ui::KeyEvent& event, |
| + ui::KeyboardCode key_code, |
| + int* mod_down_flags, |
| + int* mod_up_flags); |
| + |
| + // Handles mouse event. Returns true if Sticky key consumes keyboard event. |
| + // Adds to |mod_up_flags| any flag to be released after the key event. |
| + bool HandleMouseEvent(const ui::MouseEvent& event, |
| + int* mod_down_flags, |
| + int* mod_up_flags); |
| + |
| + // Handles scroll event. Returns true if Sticky key consumes keyboard event. |
| + // Adds to |mod_up_flags| any flag to be released after the key event. |
| + bool HandleScrollEvent(const ui::ScrollEvent& event, |
| + int* mod_down_flags, |
| + int* mod_up_flags); |
| // Updates the overlay UI with the current state of the sticky keys. |
| void UpdateOverlay(); |
| @@ -143,40 +178,38 @@ class ASH_EXPORT StickyKeysController : public ui::EventHandler { |
| // is modified. |
| class ASH_EXPORT StickyKeysHandler { |
| public: |
| - class StickyKeysHandlerDelegate { |
| - public: |
| - StickyKeysHandlerDelegate(); |
| - virtual ~StickyKeysHandlerDelegate(); |
| - |
| - // Dispatches keyboard event synchronously. |event| is an event that has |
| - // been previously dispatched. |
| - virtual void DispatchKeyEvent(ui::KeyEvent* event, |
| - aura::Window* target) = 0; |
| - |
| - // Dispatches mouse event synchronously. |event| is an event that has |
| - // been previously dispatched. |
| - virtual void DispatchMouseEvent(ui::MouseEvent* event, |
| - aura::Window* target) = 0; |
| - |
| - // Dispatches scroll event synchronously. |event| is an event that has |
| - // been previously dispatched. |
| - virtual void DispatchScrollEvent(ui::ScrollEvent* event, |
| - aura::Window* target) = 0; |
| - }; |
| - |
| - // This class takes an ownership of |delegate|. |
| - StickyKeysHandler(ui::EventFlags modifier_flag, |
| - StickyKeysHandlerDelegate* delegate); |
| + explicit StickyKeysHandler(ui::EventFlags modifier_flag); |
| ~StickyKeysHandler(); |
| - // Handles key event. Returns true if key is consumed. |
| - bool HandleKeyEvent(ui::KeyEvent* event); |
| + // Handles keyboard event. Returns true if Sticky key consumes keyboard event. |
| + // Sets its own modifier flag in |mod_down_flags| if it is active and needs |
| + // to be added to the event; sets its own modifier flag in |mod_up_flags| if |
| + // releasing it. |
| + bool HandleKeyEvent(const ui::KeyEvent& event, |
| + ui::KeyboardCode key_code, |
| + int* mod_down_flags, |
| + int* mod_up_flags); |
| - // Handles a mouse event. Returns true if mouse event is consumed. |
| - bool HandleMouseEvent(ui::MouseEvent* event); |
| + // Handles mouse event. Returns true if sticky key consumes mouse event. |
| + // Sets its own modifier flag in |mod_down_flags| if it is active and needs |
| + // to be added to the event; sets its own modifier flag in |mod_up_flags| if |
| + // releasing it. |
| + bool HandleMouseEvent(const ui::MouseEvent& event, |
| + int* mod_down_flags, |
| + int* mod_up_flags); |
| - // Handles a scroll event. Returns true if scroll event is consumed. |
| - bool HandleScrollEvent(ui::ScrollEvent* event); |
| + // Handles scroll event. Returns true if sticky key consumes scroll event. |
| + // Sets its own modifier flag in |mod_down_flags| if it is active and needs |
| + // to be added to the event; sets its own modifier flag in |mod_up_flags| if |
| + // releasing it. |
| + bool HandleScrollEvent(const ui::ScrollEvent& event, |
| + int* mod_down_flags, |
| + int* mod_up_flags); |
| + |
| + // Fetches a pending modifier-up event if one exists and the return |
| + // parameter |new_event| is available (i.e. not set). Returns the number |
| + // of pending events still remaining to be returned. |
| + int GetModifierUpEvent(scoped_ptr<ui::Event>* new_event); |
| // Returns current internal state. |
| StickyKeyState current_state() const { return current_state_; } |
| @@ -192,31 +225,27 @@ class ASH_EXPORT StickyKeysHandler { |
| OTHER_MODIFIER_UP, // The modifier key but not monitored key is up. |
| }; |
| - // Translates |event| to sticky keys event type. |
| - KeyEventType TranslateKeyEvent(ui::KeyEvent* event); |
| - |
| - // Handles key event in DISABLED state. |
| - bool HandleDisabledState(ui::KeyEvent* event); |
| + // Translates event type and key code to sticky keys event type. |
| + KeyEventType TranslateKeyEvent(ui::EventType type, ui::KeyboardCode key_code); |
| - // Handles key event in ENABLED state. |
| - bool HandleEnabledState(ui::KeyEvent* event); |
| + // Handles key event in DISABLED state. Returns true if sticky keys |
| + // consumes the keyboard event. |
| + bool HandleDisabledState(const ui::KeyEvent& event, |
| + ui::KeyboardCode key_code); |
| - // Handles key event in LOCKED state. |
| - bool HandleLockedState(ui::KeyEvent* event); |
| + // Handles key event in ENABLED state. Returns true if sticky keys |
| + // consumes the keyboard event. |
| + bool HandleEnabledState(const ui::KeyEvent& event, |
| + ui::KeyboardCode key_code, |
| + int* mod_down_flags, |
| + int* mod_up_flags); |
| - // Dispatches |event| to its target and then dispatch a key released event |
| - // for the modifier key. This function is required to ensure that the events |
| - // are sent in the correct order when disabling sticky key after a key/mouse |
| - // button press. |
| - void DispatchEventAndReleaseModifier(ui::Event* event); |
| - |
| - // Adds |modifier_flags_| to a native X11 event state mask. |
| - void AppendNativeEventMask(unsigned int* state); |
| - |
| - // Adds |modifier_flags_| into |event|. |
| - void AppendModifier(ui::KeyEvent* event); |
| - void AppendModifier(ui::MouseEvent* event); |
| - void AppendModifier(ui::ScrollEvent* event); |
| + // Handles key event in LOCKED state. Returns true if sticky keys |
| + // consumes the keyboard event. |
| + bool HandleLockedState(const ui::KeyEvent& event, |
| + ui::KeyboardCode key_code, |
| + int* mod_down_flags, |
| + int* mod_up_flags); |
| // The modifier flag to be monitored and appended to events. |
| const ui::EventFlags modifier_flag_; |
| @@ -224,9 +253,6 @@ class ASH_EXPORT StickyKeysHandler { |
| // The current sticky key status. |
| StickyKeyState current_state_; |
| - // True if the received key event is sent by StickyKeyHandler. |
| - bool event_from_myself_; |
| - |
| // True if we received the TARGET_MODIFIER_DOWN event while in the DISABLED |
| // state but before we receive the TARGET_MODIFIER_UP event. Normal |
| // shortcuts (eg. ctrl + t) during this time will prevent a transition to |
| @@ -241,8 +267,6 @@ class ASH_EXPORT StickyKeysHandler { |
| // The modifier up key event to be sent on non modifier key on ENABLED state. |
| scoped_ptr<ui::KeyEvent> modifier_up_event_; |
| - scoped_ptr<StickyKeysHandlerDelegate> delegate_; |
| - |
| DISALLOW_COPY_AND_ASSIGN(StickyKeysHandler); |
| }; |