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

Side by Side Diff: ash/accelerators/exit_warning_handler.h

Issue 14771027: Unify and change logout/sleep/lock shortcuts (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 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 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 ExitWarningHandler();
76 80
77 ~ExitWarningHandler(); 81 ~ExitWarningHandler();
78 82
79 // Handles shortcut key press and release (Ctrl-Shift-Q). 83 void Init(AcceleratorControllerContext* context);
80 void HandleExitKey(bool press); 84
85 // Handles accelerator for exit (Ctrl-Shift-Q).
86 void HandleAccelerator();
81 87
82 private: 88 private:
83 friend class AcceleratorControllerTest; 89 friend class AcceleratorControllerTest;
84 90
85 enum State { 91 enum State {
86 IDLE, 92 IDLE,
87 WAIT_FOR_QUICK_RELEASE,
88 WAIT_FOR_DOUBLE_PRESS, 93 WAIT_FOR_DOUBLE_PRESS,
89 WAIT_FOR_LONG_HOLD, 94 WAIT_FOR_LONG_HOLD,
90 CANCELED, 95 CANCELED,
91 EXITING 96 EXITING
92 }; 97 };
93 98
94 // Performs actions (see state diagram above) when the "double key 99 // Performs actions (see state diagram above) when the "double key
95 // press" time limit is exceeded. This is the shorter of the two 100 // press" time limit is exceeded. This is the shorter of the two
96 // time limits. 101 // time limits.
97 void Timer1Action(); 102 void Timer1Action();
98 103
99 // Performs actions (see state diagram above) when the hold time 104 // Performs actions (see state diagram above) when the hold time
100 // limit is exceeded. See state diagram above. This is the longer 105 // limit is exceeded. See state diagram above. This is the longer
101 // of the two time limits. 106 // of the two time limits.
102 void Timer2Action(); 107 void Timer2Action();
103 108
104 void StartTimers(); 109 void StartTimers();
105 void CancelTimers(); 110 void CancelTimers();
106 111
107 void Show(); 112 void Show();
108 void Hide(); 113 void Hide();
109 114
115 AcceleratorControllerContext* context_;
sky 2013/05/17 14:53:16 Documentation?
sschmitz 2013/05/17 15:53:31 Done.
116 ui::Accelerator accelerator_;
110 State state_; 117 State state_;
111 views::Widget* widget_; // owned by |this|. 118 views::Widget* widget_; // owned by |this|.
112 base::OneShotTimer<ExitWarningHandler> timer1_; // short; double press 119 base::OneShotTimer<ExitWarningHandler> timer1_; // short; double press
113 base::OneShotTimer<ExitWarningHandler> timer2_; // long; hold to exit 120 base::OneShotTimer<ExitWarningHandler> timer2_; // long; hold to exit
114 121
115 // Flag to suppress starting the timers for testing. For test we 122 // Flag to suppress starting the timers for testing. For test we
116 // call TimerAction1() and TimerAction2() directly to simulate the 123 // call TimerAction1() and TimerAction2() directly to simulate the
117 // expiration of the timers. 124 // expiration of the timers.
118 bool stub_timers_for_test_; 125 bool stub_timers_for_test_;
119 126
120 DISALLOW_COPY_AND_ASSIGN(ExitWarningHandler); 127 DISALLOW_COPY_AND_ASSIGN(ExitWarningHandler);
121 }; 128 };
122 129
123 } // namespace ash 130 } // namespace ash
124 131
125 #endif // ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_ 132 #endif // ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_
126 133
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698