OLD | NEW |
| (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_COMMON_ACCELERATORS_EXIT_WARNING_HANDLER_H_ | |
6 #define ASH_COMMON_ACCELERATORS_EXIT_WARNING_HANDLER_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "ash/ash_export.h" | |
11 #include "base/macros.h" | |
12 #include "base/timer/timer.h" | |
13 #include "ui/base/accelerators/accelerator.h" | |
14 | |
15 namespace views { | |
16 class Widget; | |
17 } | |
18 | |
19 namespace ash { | |
20 | |
21 // In order to avoid accidental exits when the user presses the exit shortcut by | |
22 // mistake, we require that the user press it twice within a short period of | |
23 // time. During that time we show a popup informing the user of this. | |
24 // | |
25 // Notes: | |
26 // | |
27 // The corresponding accelerator must not be repeatable (see kRepeatableActions | |
28 // in accelerator_table.cc). Otherwise, the "Double Press Exit" will be | |
29 // activated just by holding it down, i.e. probably every time. | |
30 // | |
31 // State Transition Diagrams: | |
32 // | |
33 // IDLE | |
34 // | Press | |
35 // WAIT_FOR_DOUBLE_PRESS action: show ui & start timers | |
36 // | Press (before time limit ) | |
37 // EXITING action: hide ui, stop timer, exit | |
38 // | |
39 // IDLE | |
40 // | Press | |
41 // WAIT_FOR_DOUBLE_PRESS action: show ui & start timers | |
42 // | T timer expires | |
43 // IDLE action: hide ui | |
44 // | |
45 | |
46 class AcceleratorControllerTest; | |
47 | |
48 class ASH_EXPORT ExitWarningHandler { | |
49 public: | |
50 ExitWarningHandler(); | |
51 | |
52 ~ExitWarningHandler(); | |
53 | |
54 // Handles accelerator for exit (Ctrl-Shift-Q). | |
55 void HandleAccelerator(); | |
56 | |
57 private: | |
58 friend class AcceleratorControllerTest; | |
59 | |
60 enum State { IDLE, WAIT_FOR_DOUBLE_PRESS, EXITING }; | |
61 | |
62 // Performs actions when the time limit is exceeded. | |
63 void TimerAction(); | |
64 | |
65 void StartTimer(); | |
66 void CancelTimer(); | |
67 | |
68 void Show(); | |
69 void Hide(); | |
70 | |
71 State state_; | |
72 std::unique_ptr<views::Widget> widget_; | |
73 base::OneShotTimer timer_; | |
74 | |
75 // Flag to suppress starting the timer for testing. For test we call | |
76 // TimerAction() directly to simulate the expiration of the timer. | |
77 bool stub_timer_for_test_; | |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(ExitWarningHandler); | |
80 }; | |
81 | |
82 } // namespace ash | |
83 | |
84 #endif // ASH_COMMON_ACCELERATORS_EXIT_WARNING_HANDLER_H_ | |
OLD | NEW |