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

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

Issue 14587007: Unify and change logout/sleep/lock shortcuts (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: review 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
« no previous file with comments | « ash/accelerators/accelerator_table.cc ('k') | ash/accelerators/exit_warning_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_
6 #define ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_
7
8 #include "ash/ash_export.h"
9 #include "base/timer.h"
10
11 namespace views {
12 class Widget;
13 }
14
15 namespace ash {
16
17 // 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 // 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 // than this time limit.
22 // An expert user may quickly release and then press again (double press)
23 // for immediate exit. The press, release and press must happen within
24 // the double press time limit.
25 // If the user releases (without double press) before the required hold
26 // time, we will cancel the exit, but show the ui until the hold time limit
27 // has expired to avoid a short popup flash.
28 //
29 // State Transition Diagrams:
30 //
31 // T1 - double press time limit (short)
32 // T2 - hold to exit time limit (long)
33 //
34 // IDLE
35 // | Press
36 // WAIT_FOR_QUICK_RELEASE action: show ui & start timers
37 // | Release (DT < T1)
38 // WAIT_FOR_DOUBLE_PRESS
39 // | Press (DT < T1)
40 // EXITING action: hide ui, stop timers, exit
41 //
42 // IDLE
43 // | Press
44 // WAIT_FOR_QUICK_RELEASE action: show ui & start timers
45 // | T1 timer expires
46 // WAIT_FOR_LONG_HOLD
47 // | T2 Timer exipres
48 // EXITING action: hide ui, exit
49 //
50 // IDLE
51 // | Press
52 // WAIT_FOR_QUICK_RELEASE action: show ui & start timers
53 // | T1 timer expiers
54 // WAIT_FOR_LONG_HOLD
55 // | Release
56 // CANCELED
57 // | T2 timer expires
58 // IDLE action: hide ui
59 //
60 // IDLE
61 // | Press
62 // WAIT_FOR_QUICK_RELEASE action: show ui & start timers
63 // | Release (DT < T1)
64 // WAIT_FOR_DOUBLE_PRESS
65 // | T1 timer expires
66 // CANCELED
67 // | T2 timer expires
68 // IDLE action: hide ui
69 //
70
71 class AcceleratorControllerTest;
72
73 class ASH_EXPORT ExitWarningHandler {
74 public:
75 ExitWarningHandler();
76
77 ~ExitWarningHandler();
78
79 // Handles shortcut key press and release (Ctrl-Shift-Q).
80 void HandleExitKey(bool press);
81
82 private:
83 friend class AcceleratorControllerTest;
84
85 enum State {
86 IDLE,
87 WAIT_FOR_QUICK_RELEASE,
88 WAIT_FOR_DOUBLE_PRESS,
89 WAIT_FOR_LONG_HOLD,
90 CANCELED,
91 EXITING
92 };
93
94 // Performs actions (see state diagram above) when the "double key
95 // press" time limit is exceeded. This is the shorter of the two
96 // time limits.
97 void Timer1Action();
98
99 // Performs actions (see state diagram above) when the hold time
100 // limit is exceeded. See state diagram above. This is the longer
101 // of the two time limits.
102 void Timer2Action();
103
104 void StartTimers();
105 void CancelTimers();
106
107 void Show();
108 void Hide();
109
110 State state_;
111 views::Widget* widget_; // owned by |this|.
112 base::OneShotTimer<ExitWarningHandler> timer1_; // short; double press
113 base::OneShotTimer<ExitWarningHandler> timer2_; // long; hold to exit
114
115 // Flag to suppress starting the timers for testing. For test we
116 // call TimerAction1() and TimerAction2() directly to simulate the
117 // expiration of the timers.
118 bool stub_timers_for_test_;
119
120 DISALLOW_COPY_AND_ASSIGN(ExitWarningHandler);
121 };
122
123 } // namespace ash
124
125 #endif // ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_
126
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_table.cc ('k') | ash/accelerators/exit_warning_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698