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

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: 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 27 matching lines...) Expand all
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()
77 : state_(IDLE), 78 : context_(NULL),
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::Init(AcceleratorControllerContext* context) {
sky 2013/05/17 14:53:16 Why not pass the context into the constructor?
sschmitz 2013/05/17 15:53:31 ExitWarningHandler and AcceleratorControllerContex
90 context_ = context;
91 }
92
93 void ExitWarningHandler::HandleAccelerator() {
94 if (!context_)
95 return;
88 switch (state_) { 96 switch (state_) {
89 case IDLE: 97 case IDLE:
90 if (press) { 98 state_ = WAIT_FOR_DOUBLE_PRESS;
91 state_ = WAIT_FOR_QUICK_RELEASE; 99 accelerator_ = context_->current_accelerator();
92 Show(); 100 Show();
93 StartTimers(); 101 StartTimers();
94 }
95 break;
96 case WAIT_FOR_QUICK_RELEASE:
97 if (!press)
98 state_ = WAIT_FOR_DOUBLE_PRESS;
99 break; 102 break;
100 case WAIT_FOR_DOUBLE_PRESS: 103 case WAIT_FOR_DOUBLE_PRESS:
101 if (press) { 104 state_ = EXITING;
102 state_ = EXITING; 105 CancelTimers();
103 CancelTimers(); 106 Hide();
104 Hide(); 107 Shell::GetInstance()->delegate()->Exit();
105 Shell::GetInstance()->delegate()->Exit();
106 }
107 break; 108 break;
108 case WAIT_FOR_LONG_HOLD: 109 case WAIT_FOR_LONG_HOLD:
109 if (!press) 110 state_ = CANCELED;
110 state_ = CANCELED;
111 break; 111 break;
112 case CANCELED: 112 case CANCELED:
113 case EXITING: 113 case EXITING:
114 break; 114 break;
115 default: 115 default:
116 NOTREACHED(); 116 NOTREACHED();
117 break; 117 break;
118 } 118 }
119 } 119 }
120 120
121 void ExitWarningHandler::Timer1Action() { 121 void ExitWarningHandler::Timer1Action() {
122 if (state_ == WAIT_FOR_QUICK_RELEASE) 122 if (state_ == WAIT_FOR_DOUBLE_PRESS)
123 state_ = WAIT_FOR_LONG_HOLD; 123 state_ = WAIT_FOR_LONG_HOLD;
124 else if (state_ == WAIT_FOR_DOUBLE_PRESS)
125 state_ = CANCELED;
126 } 124 }
127 125
128 void ExitWarningHandler::Timer2Action() { 126 void ExitWarningHandler::Timer2Action() {
127 Hide();
sky 2013/05/17 14:53:16 Doesn't this mean you're effectively waiting longe
sschmitz 2013/05/17 15:53:31 No. This is done by design. PM did not want a shor
129 if (state_ == CANCELED) { 128 if (state_ == CANCELED) {
130 state_ = IDLE; 129 state_ = IDLE;
131 Hide(); 130 } else if (state_ == WAIT_FOR_LONG_HOLD) {
132 } 131 if (accelerator_ == context_->current_accelerator()) {
133 else if (state_ == WAIT_FOR_LONG_HOLD) { 132 // We detect if the user has released any one of the keys that
134 state_ = EXITING; 133 // make up the shortcut by comparing "our" accelerator to the one
135 Hide(); 134 // from the current context and do not exit in that case.
136 Shell::GetInstance()->delegate()->Exit(); 135 state_ = EXITING;
136 Shell::GetInstance()->delegate()->Exit();
137 }
138 else {
139 state_ = IDLE;
140 }
137 } 141 }
138 } 142 }
139 143
140 void ExitWarningHandler::StartTimers() { 144 void ExitWarningHandler::StartTimers() {
141 if (stub_timers_for_test_) 145 if (stub_timers_for_test_)
142 return; 146 return;
143 timer1_.Start(FROM_HERE, 147 timer1_.Start(FROM_HERE,
144 base::TimeDelta::FromMilliseconds( 148 base::TimeDelta::FromMilliseconds(
145 kDoublePressTimeOutMilliseconds), 149 kDoublePressTimeOutMilliseconds),
146 this, 150 this,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 191 }
188 192
189 void ExitWarningHandler::Hide() { 193 void ExitWarningHandler::Hide() {
190 if (!widget_) 194 if (!widget_)
191 return; 195 return;
192 widget_->Close(); 196 widget_->Close();
193 widget_ = NULL; 197 widget_ = NULL;
194 } 198 }
195 199
196 } // namespace ash 200 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698