Chromium Code Reviews| Index: ash/accelerators/exit_warning_handler.h |
| diff --git a/ash/accelerators/exit_warning_handler.h b/ash/accelerators/exit_warning_handler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f1a411101fec77c92d1beab7d0145ea07d9758bd |
| --- /dev/null |
| +++ b/ash/accelerators/exit_warning_handler.h |
| @@ -0,0 +1,126 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_ |
| +#define ASH_ACCELERATORS_EXIT_WARNING_HANDLER_H_ |
| + |
| +#include "ash/ash_export.h" |
| +#include "base/timer.h" |
| + |
| +namespace views { |
| +class Widget; |
| +} |
| + |
| +namespace ash { |
| + |
| +// In order to avoid accidental exits when the user presses the exit |
| +// shortcut by mistake, we require the user to hold the shortcut for |
| +// a period of time. During that time we show a popup informing the |
| +// user of this. We exit only if the user holds the shortcut longer |
| +// than this time limit. |
| +// An expert user may quickly release and then press again (double press) |
| +// for immediate exit. The press, release and press must happen within |
| +// the double press time limit. |
| +// If the user releases (without double press) before the required hold |
| +// time, we will cancel the exit, but show the ui until the hold time limit |
| +// has expired to avoid a short popup flash. |
| +// |
| +// State Transition Diagrams: |
| +// |
| +// T1 - double press time limit (short) |
| +// T2 - hold to exit time limit (long) |
| +// |
| +// IDLE |
| +// | Press |
| +// WAIT_FOR_QUICK_RELEASE action: show ui & start timers |
| +// | Release (DT < T1) |
| +// WAIT_FOR_DOUBLE_PRESS |
| +// | Press (DT < T1) |
| +// EXITING action: hide ui, stop timers, exit |
| +// |
| +// IDLE |
| +// | Press |
| +// WAIT_FOR_QUICK_RELEASE action: show ui & start timers |
| +// | T1 timer expires |
| +// WAIT_FOR_LONG_HOLD |
| +// | T2 Timer exipres |
| +// EXITING action: hide ui, exit |
| +// |
| +// IDLE |
| +// | Press |
| +// WAIT_FOR_QUICK_RELEASE action: show ui & start timers |
| +// | T1 timer expiers |
| +// WAIT_FOR_LONG_HOLD |
| +// | Release |
| +// CANCELED |
| +// | T2 timer expires |
| +// IDLE action: hide ui |
| +// |
| +// IDLE |
| +// | Press |
| +// WAIT_FOR_QUICK_RELEASE action: show ui & start timers |
| +// | Release (DT < T1) |
| +// WAIT_FOR_DOUBLE_PRESS |
| +// | T1 timer expires |
| +// CANCELED |
| +// | T2 timer expires |
| +// IDLE action: hide ui |
| +// |
| + |
| +class AcceleratorControllerTest; |
| + |
| +class ASH_EXPORT ExitWarningHandler { |
| + public: |
| + ExitWarningHandler(); |
| + |
| + ~ExitWarningHandler(); |
| + |
| + // Handles shortcut key press and release (Ctrl-Shift-Q). |
| + void HandleExitKey(bool press); |
| + |
| + private: |
| + friend class AcceleratorControllerTest; |
| + |
| + enum State { |
| + IDLE, |
| + WAIT_FOR_QUICK_RELEASE, |
| + WAIT_FOR_DOUBLE_PRESS, |
| + WAIT_FOR_LONG_HOLD, |
| + CANCELED, |
| + EXITING |
| + }; |
| + |
| + // Performs actions (see state diagram above) when the "double key |
| + // press" time limit is exceeded. This is the shorter of the two |
| + // time limits. |
| + void Timer1Action(); |
| + |
| + // Performs actions (see state diagram above) when the hold time |
| + // limit is exceeded. See state diagram above. This is the longer |
| + // of the two time limits. |
| + void Timer2Action(); |
| + |
| + void StartTimers(); |
| + void CancelTimers(); |
| + |
| + void Show(); |
| + void Hide(); |
| + |
| + // I/F for testing |
| + void StubTimersForTest() { stub_timers_for_test_ = true; } |
|
sky
2013/05/14 17:10:05
Is there a reason these needs to be exposed? Can't
sschmitz
2013/05/14 21:36:43
Done.
|
| + State state() const { return state_; } |
| + bool ui_shown() const { return !!widget_; } |
| + |
| + State state_; |
| + views::Widget* widget_; // owned by |this|. |
| + base::OneShotTimer<ExitWarningHandler> timer1_; // short; double press |
| + base::OneShotTimer<ExitWarningHandler> timer2_; // long; hold to exit |
| + bool stub_timers_for_test_; |
|
sky
2013/05/14 17:10:05
Document what this is.
sschmitz
2013/05/14 21:36:43
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(ExitWarningHandler); |
| +}; |
| + |
| +} |
| + |
| +#endif |
|
sky
2013/05/14 17:10:05
You need:
#endif // ASH_ACCELERATORS_EXIT_WARNING
sschmitz
2013/05/14 21:36:43
Done.
|