Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_MAGNIFIER_MAGNIFIER_KEY_SCROLLER_H_ | 5 #ifndef ASH_MAGNIFIER_MAGNIFIER_KEY_SCROLLER_H_ |
| 6 #define ASH_MAGNIFIER_MAGNIFIER_KEY_SCROLLER_H_ | 6 #define ASH_MAGNIFIER_MAGNIFIER_KEY_SCROLLER_H_ |
| 7 | 7 |
| 8 #include "ash/accelerators/key_hold_detector.h" | |
| 8 #include "ash/ash_export.h" | 9 #include "ash/ash_export.h" |
| 9 #include "ui/events/event_handler.h" | 10 #include "ui/events/event_handler.h" |
| 10 | 11 |
| 11 namespace ui { | 12 namespace ui { |
| 12 class KeyEvent; | 13 class KeyEvent; |
| 13 } | 14 } |
| 14 | 15 |
| 15 namespace ash { | 16 namespace ash { |
| 16 | 17 |
| 17 // This class implements the press and hold key-bindings (shift-arrow keys) | 18 // A KeyHoldDetector delegate to control control magnified screen. |
| 18 // to control magnified screen. | 19 class ASH_EXPORT MagnifierKeyScroller : public KeyHoldDetector::Delegate { |
| 19 class ASH_EXPORT MagnifierKeyScroller : public ui::EventHandler { | |
| 20 public: | 20 public: |
| 21 static bool IsEnabled(); | 21 static bool IsEnabled(); |
| 22 static void SetEnabled(bool enabled); | 22 static void SetEnabled(bool enabled); |
| 23 | 23 static ui::EventHandler* CreateHandler(); |
|
xiyuan
2014/02/14 01:50:21
Same here. Document the ownership of the returned
| |
| 24 MagnifierKeyScroller(); | |
| 25 virtual ~MagnifierKeyScroller(); | |
| 26 | |
| 27 // ui::EventHandler overrides: | |
| 28 virtual void OnKeyEvent(ui::KeyEvent* key_event) OVERRIDE; | |
| 29 | 24 |
| 30 // A scoped object to enable and disable the magnifier accelerator for test. | 25 // A scoped object to enable and disable the magnifier accelerator for test. |
| 31 class ScopedEnablerForTest { | 26 class ScopedEnablerForTest { |
| 32 public: | 27 public: |
| 33 ScopedEnablerForTest() { | 28 ScopedEnablerForTest() { |
| 34 SetEnabled(true); | 29 SetEnabled(true); |
| 35 } | 30 } |
| 36 ~ScopedEnablerForTest() { | 31 ~ScopedEnablerForTest() { |
| 37 SetEnabled(false); | 32 SetEnabled(false); |
| 38 } | 33 } |
| 39 | 34 |
| 40 private: | 35 private: |
| 41 DISALLOW_COPY_AND_ASSIGN(ScopedEnablerForTest); | 36 DISALLOW_COPY_AND_ASSIGN(ScopedEnablerForTest); |
| 42 }; | 37 }; |
| 43 | 38 |
| 44 private: | 39 private: |
| 45 // A state to keep track of one click and click and hold operation. | 40 // KeyHoldDetector overrides: |
| 46 // | 41 virtual bool ShouldProcessEvent(const ui::KeyEvent* event) const OVERRIDE; |
| 47 // One click: | 42 virtual bool IsStartEvent(const ui::KeyEvent* event) const OVERRIDE; |
| 48 // INITIAL --(first press)--> PRESSED --(release)--> INITIAL[SEND PRESS] | 43 virtual void OnKeyHold(const ui::KeyEvent* event) OVERRIDE; |
| 49 // | 44 virtual void OnKeyUnhold(const ui::KeyEvent* event) OVERRIDE; |
| 50 // Click and hold: | |
| 51 // INITIAL --(first press)--> PRESSED --(press)--> | |
| 52 // HOLD[scroll] --(press)--> HOLD[scroll] --(release)--> | |
| 53 // INITIAL[stop scroll] | |
| 54 enum State { | |
| 55 INITIAL, | |
| 56 PRESSED, | |
| 57 HOLD | |
| 58 }; | |
| 59 | 45 |
| 60 State state_; | 46 MagnifierKeyScroller(); |
| 47 virtual ~MagnifierKeyScroller(); | |
| 61 | 48 |
| 62 DISALLOW_COPY_AND_ASSIGN(MagnifierKeyScroller); | 49 DISALLOW_COPY_AND_ASSIGN(MagnifierKeyScroller); |
| 63 }; | 50 }; |
| 64 | 51 |
| 65 } // namespace ash | 52 } // namespace ash |
| 66 | 53 |
| 67 #endif // ASH_MAGNIFIER_MAGNIFIER_KEY_SCROLLER_H_ | 54 #endif // ASH_MAGNIFIER_MAGNIFIER_KEY_SCROLLER_H_ |
| OLD | NEW |