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.
5 #ifndef ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_
6 #define ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_
8 #include "ash/ash_export.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/timer/timer.h"
11 #include "ui/base/accelerators/accelerator.h"
19 // In order to avoid accidental exits when the user presses the exit
20 // shortcut by mistake, we require the user press it twice within a
21 // period of time. During that time we show a popup informing the
26 // The corresponding accelerator must be non-repeatable (see
27 // kNonrepeatableActions in accelerator_table.cc). Otherwise the "Double Press
28 // Exit" will be activated just by holding it down, i.e. probably every time.
30 // State Transition Diagrams:
34 // WAIT_FOR_DOUBLE_PRESS action: show ui & start timers
35 // | Press (before time limit )
36 // EXITING action: hide ui, stop timer, exit
40 // WAIT_FOR_DOUBLE_PRESS action: show ui & start timers
42 // IDLE action: hide ui
45 class AcceleratorControllerTest
;
47 class ASH_EXPORT ExitWarningHandler
{
51 ~ExitWarningHandler();
53 // Handles accelerator for exit (Ctrl-Shift-Q).
54 void HandleAccelerator();
57 friend class AcceleratorControllerTest
;
61 WAIT_FOR_DOUBLE_PRESS
,
65 // Performs actions when the time limit is exceeded.
75 scoped_ptr
<views::Widget
> widget_
;
76 base::OneShotTimer
<ExitWarningHandler
> timer_
;
78 // Flag to suppress starting the timer for testing. For test we call
79 // TimerAction() directly to simulate the expiration of the timer.
80 bool stub_timer_for_test_
;
82 DISALLOW_COPY_AND_ASSIGN(ExitWarningHandler
);
87 #endif // ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_