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_ACCELERATORS_EXIT_WARNING_HANDLER_H_ | 5 #ifndef ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_ |
6 #define ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_ | 6 #define ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
9 #include "base/timer.h" | 9 #include "base/timer.h" |
10 #include "ui/base/accelerators/accelerator.h" | |
10 | 11 |
11 namespace views { | 12 namespace views { |
12 class Widget; | 13 class Widget; |
13 } | 14 } |
14 | 15 |
15 namespace ash { | 16 namespace ash { |
16 | 17 |
17 // In order to avoid accidental exits when the user presses the exit | 18 // In order to avoid accidental exits when the user presses the exit |
18 // shortcut by mistake, we require the user to hold the shortcut for | 19 // shortcut by mistake, we require the user to hold the shortcut for |
19 // a period of time. During that time we show a popup informing the | 20 // a period of time. During that time we show a popup informing the |
20 // user of this. We exit only if the user holds the shortcut longer | 21 // user of this. We exit only if the user holds the shortcut longer |
21 // than this time limit. | 22 // than this time limit. |
22 // An expert user may quickly release and then press again (double press) | 23 // An expert user may double press the shortcut for immediate exit. |
23 // for immediate exit. The press, release and press must happen within | 24 // The double press must happen within the double press time limit. |
24 // the double press time limit. | 25 // Unless the user performs a double press, we show the ui until the |
25 // If the user releases (without double press) before the required hold | 26 // hold time limit has expired to avoid a short popup flash. |
26 // time, we will cancel the exit, but show the ui until the hold time limit | 27 // |
27 // has expired to avoid a short popup flash. | 28 // Notes: |
29 // | |
30 // The corresponding accelerator must be non-repeatable (see | |
31 // kNonrepeatableActions in accelerator_table.cc). Otherwise the "Double Press | |
32 // Exit" will be activated just by holding it down, i.e. probably every time. | |
28 // | 33 // |
29 // State Transition Diagrams: | 34 // State Transition Diagrams: |
30 // | 35 // |
31 // T1 - double press time limit (short) | 36 // T1 - double press time limit (short) |
32 // T2 - hold to exit time limit (long) | 37 // T2 - hold to exit time limit (long) |
33 // | 38 // |
34 // IDLE | 39 // IDLE |
35 // | Press | 40 // | Press |
36 // WAIT_FOR_QUICK_RELEASE action: show ui & start timers | 41 // WAIT_FOR_DOUBLE_PRESS action: show ui & start timers |
37 // | Release (DT < T1) | |
38 // WAIT_FOR_DOUBLE_PRESS | |
39 // | Press (DT < T1) | 42 // | Press (DT < T1) |
40 // EXITING action: hide ui, stop timers, exit | 43 // EXITING action: hide ui, stop timers, exit |
41 // | 44 // |
42 // IDLE | 45 // IDLE |
43 // | Press | 46 // | Press |
44 // WAIT_FOR_QUICK_RELEASE action: show ui & start timers | 47 // WAIT_FOR_DOUBLE_PRESS action: show ui & start timers |
45 // | T1 timer expires | 48 // | T1 timer expires |
46 // WAIT_FOR_LONG_HOLD | 49 // WAIT_FOR_LONG_HOLD |
47 // | T2 Timer exipres | 50 // | T2 Timer exipres and |
51 // | accelerator was held (matches current accelerator from context) | |
48 // EXITING action: hide ui, exit | 52 // EXITING action: hide ui, exit |
49 // | 53 // |
50 // IDLE | 54 // IDLE |
51 // | Press | 55 // | Press |
52 // WAIT_FOR_QUICK_RELEASE action: show ui & start timers | 56 // WAIT_FOR_DOUBLE_PRESS action: show ui & start timers |
53 // | T1 timer expiers | 57 // | T1 timer expires |
54 // WAIT_FOR_LONG_HOLD | 58 // WAIT_FOR_LONG_HOLD |
55 // | Release | 59 // | T2 Timer exipres and |
56 // CANCELED | 60 // | accelerator was not held |
57 // | T2 timer expires | |
58 // IDLE action: hide ui | 61 // IDLE action: hide ui |
59 // | 62 // |
60 // IDLE | 63 // IDLE |
61 // | Press | 64 // | Press |
62 // WAIT_FOR_QUICK_RELEASE action: show ui & start timers | 65 // WAIT_FOR_DOUBLE_PRESS action: show ui & start timers |
63 // | Release (DT < T1) | |
64 // WAIT_FOR_DOUBLE_PRESS | |
65 // | T1 timer expires | 66 // | T1 timer expires |
67 // WAIT_FOR_LONG_HOLD | |
68 // | Press | |
66 // CANCELED | 69 // CANCELED |
67 // | T2 timer expires | 70 // | T2 timer expires |
68 // IDLE action: hide ui | 71 // IDLE action: hide ui |
69 // | 72 // |
70 | 73 |
74 class AcceleratorControllerContext; | |
71 class AcceleratorControllerTest; | 75 class AcceleratorControllerTest; |
72 | 76 |
73 class ASH_EXPORT ExitWarningHandler { | 77 class ASH_EXPORT ExitWarningHandler { |
74 public: | 78 public: |
75 ExitWarningHandler(); | 79 explicit ExitWarningHandler(AcceleratorControllerContext* context); |
76 | 80 |
77 ~ExitWarningHandler(); | 81 ~ExitWarningHandler(); |
78 | 82 |
79 // Handles shortcut key press and release (Ctrl-Shift-Q). | 83 // Handles accelerator for exit (Ctrl-Shift-Q). |
80 void HandleExitKey(bool press); | 84 void HandleAccelerator(); |
81 | 85 |
82 private: | 86 private: |
83 friend class AcceleratorControllerTest; | 87 friend class AcceleratorControllerTest; |
84 | 88 |
85 enum State { | 89 enum State { |
86 IDLE, | 90 IDLE, |
87 WAIT_FOR_QUICK_RELEASE, | |
88 WAIT_FOR_DOUBLE_PRESS, | 91 WAIT_FOR_DOUBLE_PRESS, |
89 WAIT_FOR_LONG_HOLD, | 92 WAIT_FOR_LONG_HOLD, |
90 CANCELED, | 93 CANCELED, |
91 EXITING | 94 EXITING |
92 }; | 95 }; |
93 | 96 |
94 // Performs actions (see state diagram above) when the "double key | 97 // Performs actions (see state diagram above) when the "double key |
95 // press" time limit is exceeded. This is the shorter of the two | 98 // press" time limit is exceeded. This is the shorter of the two |
96 // time limits. | 99 // time limits. |
97 void Timer1Action(); | 100 void Timer1Action(); |
98 | 101 |
99 // Performs actions (see state diagram above) when the hold time | 102 // Performs actions (see state diagram above) when the hold time |
100 // limit is exceeded. See state diagram above. This is the longer | 103 // limit is exceeded. See state diagram above. This is the longer |
101 // of the two time limits. | 104 // of the two time limits. |
102 void Timer2Action(); | 105 void Timer2Action(); |
103 | 106 |
104 void StartTimers(); | 107 void StartTimers(); |
105 void CancelTimers(); | 108 void CancelTimers(); |
106 | 109 |
107 void Show(); | 110 void Show(); |
108 void Hide(); | 111 void Hide(); |
109 | 112 |
113 // AcceleratorControllerContext is used when a timer expires to test | |
114 // whether the user has held the accelerator key combination or has | |
115 // released (at least) one of the keys. | |
116 AcceleratorControllerContext* context_; | |
117 ui::Accelerator accelerator_; | |
sky
2013/05/17 19:22:11
Document accelerator_ too.
| |
110 State state_; | 118 State state_; |
111 views::Widget* widget_; // owned by |this|. | 119 views::Widget* widget_; // owned by |this|. |
112 base::OneShotTimer<ExitWarningHandler> timer1_; // short; double press | 120 base::OneShotTimer<ExitWarningHandler> timer1_; // short; double press |
113 base::OneShotTimer<ExitWarningHandler> timer2_; // long; hold to exit | 121 base::OneShotTimer<ExitWarningHandler> timer2_; // long; hold to exit |
114 | 122 |
115 // Flag to suppress starting the timers for testing. For test we | 123 // Flag to suppress starting the timers for testing. For test we |
116 // call TimerAction1() and TimerAction2() directly to simulate the | 124 // call TimerAction1() and TimerAction2() directly to simulate the |
117 // expiration of the timers. | 125 // expiration of the timers. |
118 bool stub_timers_for_test_; | 126 bool stub_timers_for_test_; |
119 | 127 |
120 DISALLOW_COPY_AND_ASSIGN(ExitWarningHandler); | 128 DISALLOW_COPY_AND_ASSIGN(ExitWarningHandler); |
121 }; | 129 }; |
122 | 130 |
123 } // namespace ash | 131 } // namespace ash |
124 | 132 |
125 #endif // ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_ | 133 #endif // ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_ |
126 | 134 |
OLD | NEW |