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

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

Issue 14771027: Unify and change logout/sleep/lock shortcuts (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: update 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 #include "ash/accelerators/exit_warning_handler.h" 5 #include "ash/accelerators/exit_warning_handler.h"
6 6
7 #include "ash/accelerators/accelerator_controller.h"
7 #include "ash/shell.h" 8 #include "ash/shell.h"
8 #include "ash/shell_delegate.h" 9 #include "ash/shell_delegate.h"
9 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "base/time.h" 12 #include "base/time.h"
12 #include "base/timer.h" 13 #include "base/timer.h"
13 #include "grit/ash_strings.h" 14 #include "grit/ash_strings.h"
14 #include "ui/aura/root_window.h" 15 #include "ui/aura/root_window.h"
15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/canvas.h" 18 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/font.h" 19 #include "ui/gfx/font.h"
19 #include "ui/views/controls/label.h" 20 #include "ui/views/controls/label.h"
20 #include "ui/views/layout/fill_layout.h" 21 #include "ui/views/layout/fill_layout.h"
21 #include "ui/views/view.h" 22 #include "ui/views/view.h"
22 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
23 #include "ui/views/widget/widget_delegate.h" 24 #include "ui/views/widget/widget_delegate.h"
24 25
25 namespace ash { 26 namespace ash {
26 namespace { 27 namespace {
27 28
28 const int64 kDoublePressTimeOutMilliseconds = 300; 29 const int64 kDoublePressTimeOutMilliseconds = 300;
29 const int64 kHoldTimeOutMilliseconds = 1700; 30 const int64 kHoldTimeOutMilliseconds = 1000;
30 const SkColor kForegroundColor = 0xFFFFFFFF; 31 const SkColor kForegroundColor = 0xFFFFFFFF;
31 const SkColor kBackgroundColor = 0xE0808080; 32 const SkColor kBackgroundColor = 0xE0808080;
32 const int kHorizontalMarginAroundText = 100; 33 const int kHorizontalMarginAroundText = 100;
33 const int kVerticalMarginAroundText = 100; 34 const int kVerticalMarginAroundText = 100;
34 35
35 class ExitWarningWidgetDelegateView : public views::WidgetDelegateView { 36 class ExitWarningWidgetDelegateView : public views::WidgetDelegateView {
36 public: 37 public:
37 ExitWarningWidgetDelegateView() : text_width_(0), width_(0), height_(0) { 38 ExitWarningWidgetDelegateView() : text_width_(0), width_(0), height_(0) {
38 text_ = l10n_util::GetStringUTF16(IDS_ASH_EXIT_WARNING_POPUP_TEXT); 39 text_ = l10n_util::GetStringUTF16(IDS_ASH_EXIT_WARNING_POPUP_TEXT);
39 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 40 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
(...skipping 26 matching lines...) Expand all
66 gfx::Font font_; 67 gfx::Font font_;
67 int text_width_; 68 int text_width_;
68 int width_; 69 int width_;
69 int height_; 70 int height_;
70 71
71 DISALLOW_COPY_AND_ASSIGN(ExitWarningWidgetDelegateView); 72 DISALLOW_COPY_AND_ASSIGN(ExitWarningWidgetDelegateView);
72 }; 73 };
73 74
74 } // namespace 75 } // namespace
75 76
76 ExitWarningHandler::ExitWarningHandler() 77 ExitWarningHandler::ExitWarningHandler(AcceleratorControllerContext* context)
77 : state_(IDLE), 78 : context_(context),
78 widget_(NULL), 79 state_(IDLE),
79 stub_timers_for_test_(false) { 80 widget_(NULL),
81 stub_timers_for_test_(false) {
80 } 82 }
81 83
82 ExitWarningHandler::~ExitWarningHandler() { 84 ExitWarningHandler::~ExitWarningHandler() {
83 // Note: If a timer is outstanding, it is stopped in its destructor. 85 // Note: If a timer is outstanding, it is stopped in its destructor.
84 Hide(); 86 Hide();
85 } 87 }
86 88
87 void ExitWarningHandler::HandleExitKey(bool press) { 89 void ExitWarningHandler::HandleAccelerator() {
90 if (!context_)
91 return;
88 switch (state_) { 92 switch (state_) {
89 case IDLE: 93 case IDLE:
90 if (press) { 94 state_ = WAIT_FOR_DOUBLE_PRESS;
91 state_ = WAIT_FOR_QUICK_RELEASE; 95 accelerator_ = context_->current_accelerator();
92 Show(); 96 Show();
93 StartTimers(); 97 StartTimers();
94 }
95 break;
96 case WAIT_FOR_QUICK_RELEASE:
97 if (!press)
98 state_ = WAIT_FOR_DOUBLE_PRESS;
99 break; 98 break;
100 case WAIT_FOR_DOUBLE_PRESS: 99 case WAIT_FOR_DOUBLE_PRESS:
101 if (press) { 100 state_ = EXITING;
102 state_ = EXITING; 101 CancelTimers();
103 CancelTimers(); 102 Hide();
104 Hide(); 103 Shell::GetInstance()->delegate()->Exit();
105 Shell::GetInstance()->delegate()->Exit();
106 }
107 break; 104 break;
108 case WAIT_FOR_LONG_HOLD: 105 case WAIT_FOR_LONG_HOLD:
109 if (!press) 106 state_ = CANCELED;
110 state_ = CANCELED;
111 break; 107 break;
112 case CANCELED: 108 case CANCELED:
113 case EXITING: 109 case EXITING:
114 break; 110 break;
115 default: 111 default:
116 NOTREACHED(); 112 NOTREACHED();
117 break; 113 break;
118 } 114 }
119 } 115 }
120 116
121 void ExitWarningHandler::Timer1Action() { 117 void ExitWarningHandler::Timer1Action() {
122 if (state_ == WAIT_FOR_QUICK_RELEASE) 118 if (state_ == WAIT_FOR_DOUBLE_PRESS)
123 state_ = WAIT_FOR_LONG_HOLD; 119 state_ = WAIT_FOR_LONG_HOLD;
124 else if (state_ == WAIT_FOR_DOUBLE_PRESS)
125 state_ = CANCELED;
126 } 120 }
127 121
128 void ExitWarningHandler::Timer2Action() { 122 void ExitWarningHandler::Timer2Action() {
123 Hide();
129 if (state_ == CANCELED) { 124 if (state_ == CANCELED) {
130 state_ = IDLE; 125 state_ = IDLE;
131 Hide(); 126 } else if (state_ == WAIT_FOR_LONG_HOLD) {
132 } 127 if (accelerator_ == context_->current_accelerator()) {
133 else if (state_ == WAIT_FOR_LONG_HOLD) { 128 // We detect if the user has released any one of the keys that
134 state_ = EXITING; 129 // make up the shortcut by comparing "our" accelerator to the one
135 Hide(); 130 // from the current context and do not exit in that case.
136 Shell::GetInstance()->delegate()->Exit(); 131 state_ = EXITING;
132 Shell::GetInstance()->delegate()->Exit();
133 }
134 else {
135 state_ = IDLE;
136 }
137 } 137 }
138 } 138 }
139 139
140 void ExitWarningHandler::StartTimers() { 140 void ExitWarningHandler::StartTimers() {
141 if (stub_timers_for_test_) 141 if (stub_timers_for_test_)
142 return; 142 return;
143 timer1_.Start(FROM_HERE, 143 timer1_.Start(FROM_HERE,
144 base::TimeDelta::FromMilliseconds( 144 base::TimeDelta::FromMilliseconds(
145 kDoublePressTimeOutMilliseconds), 145 kDoublePressTimeOutMilliseconds),
146 this, 146 this,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 187 }
188 188
189 void ExitWarningHandler::Hide() { 189 void ExitWarningHandler::Hide() {
190 if (!widget_) 190 if (!widget_)
191 return; 191 return;
192 widget_->Close(); 192 widget_->Close();
193 widget_ = NULL; 193 widget_ = NULL;
194 } 194 }
195 195
196 } // namespace ash 196 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698