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

Side by Side Diff: ash/common/accelerators/accelerator_controller.cc

Issue 2751323002: Converts ui::Accelerator::type to an enum (Closed)
Patch Set: remove dcheck Created 3 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/accelerators/accelerator_controller.h" 5 #include "ash/common/accelerators/accelerator_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/accelerators/accelerator_commands.h" 9 #include "ash/common/accelerators/accelerator_commands.h"
10 #include "ash/common/accelerators/accelerator_controller_delegate.h" 10 #include "ash/common/accelerators/accelerator_controller_delegate.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 message_center::RichNotificationData(), 150 message_center::RichNotificationData(),
151 new DeprecatedAcceleratorNotificationDelegate)); 151 new DeprecatedAcceleratorNotificationDelegate));
152 message_center::MessageCenter::Get()->AddNotification( 152 message_center::MessageCenter::Get()->AddNotification(
153 std::move(notification)); 153 std::move(notification));
154 } 154 }
155 155
156 ui::Accelerator CreateAccelerator(ui::KeyboardCode keycode, 156 ui::Accelerator CreateAccelerator(ui::KeyboardCode keycode,
157 int modifiers, 157 int modifiers,
158 bool trigger_on_press) { 158 bool trigger_on_press) {
159 ui::Accelerator accelerator(keycode, modifiers); 159 ui::Accelerator accelerator(keycode, modifiers);
160 accelerator.set_type(trigger_on_press ? ui::ET_KEY_PRESSED 160 accelerator.set_key_state(trigger_on_press
161 : ui::ET_KEY_RELEASED); 161 ? ui::Accelerator::KeyState::PRESSED
162 : ui::Accelerator::KeyState::RELEASED);
162 return accelerator; 163 return accelerator;
163 } 164 }
164 165
165 void RecordUmaHistogram(const char* histogram_name, 166 void RecordUmaHistogram(const char* histogram_name,
166 DeprecatedAcceleratorUsage sample) { 167 DeprecatedAcceleratorUsage sample) {
167 auto* histogram = base::LinearHistogram::FactoryGet( 168 auto* histogram = base::LinearHistogram::FactoryGet(
168 histogram_name, 1, DEPRECATED_USAGE_COUNT, DEPRECATED_USAGE_COUNT + 1, 169 histogram_name, 1, DEPRECATED_USAGE_COUNT, DEPRECATED_USAGE_COUNT + 1,
169 base::HistogramBase::kUmaTargetedHistogramFlag); 170 base::HistogramBase::kUmaTargetedHistogramFlag);
170 histogram->Add(sample); 171 histogram->Add(sample);
171 } 172 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 WmShell::Get()->new_window_controller()->OpenFeedbackPage(); 277 WmShell::Get()->new_window_controller()->OpenFeedbackPage();
277 } 278 }
278 279
279 bool CanHandlePreviousIme(ImeControlDelegate* ime_control_delegate) { 280 bool CanHandlePreviousIme(ImeControlDelegate* ime_control_delegate) {
280 return ime_control_delegate && ime_control_delegate->CanCycleIme(); 281 return ime_control_delegate && ime_control_delegate->CanCycleIme();
281 } 282 }
282 283
283 void HandlePreviousIme(ImeControlDelegate* ime_control_delegate, 284 void HandlePreviousIme(ImeControlDelegate* ime_control_delegate,
284 const ui::Accelerator& accelerator) { 285 const ui::Accelerator& accelerator) {
285 base::RecordAction(UserMetricsAction("Accel_Previous_Ime")); 286 base::RecordAction(UserMetricsAction("Accel_Previous_Ime"));
286 if (accelerator.type() == ui::ET_KEY_PRESSED) 287 if (accelerator.key_state() == ui::Accelerator::KeyState::PRESSED)
287 ime_control_delegate->HandlePreviousIme(); 288 ime_control_delegate->HandlePreviousIme();
288 // Else: consume the Ctrl+Space ET_KEY_RELEASED event but do not do anything. 289 // Else: consume the Ctrl+Space ET_KEY_RELEASED event but do not do anything.
289 } 290 }
290 291
291 void HandleRestoreTab() { 292 void HandleRestoreTab() {
292 base::RecordAction(UserMetricsAction("Accel_Restore_Tab")); 293 base::RecordAction(UserMetricsAction("Accel_Restore_Tab"));
293 WmShell::Get()->new_window_controller()->RestoreTab(); 294 WmShell::Get()->new_window_controller()->RestoreTab();
294 } 295 }
295 296
296 // Rotate the active window. 297 // Rotate the active window.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 base::RecordAction(UserMetricsAction("Accel_Switch_Ime")); 363 base::RecordAction(UserMetricsAction("Accel_Switch_Ime"));
363 ime_control_delegate->HandleSwitchIme(accelerator); 364 ime_control_delegate->HandleSwitchIme(accelerator);
364 } 365 }
365 366
366 bool CanHandleToggleAppList(const ui::Accelerator& accelerator, 367 bool CanHandleToggleAppList(const ui::Accelerator& accelerator,
367 const ui::Accelerator& previous_accelerator) { 368 const ui::Accelerator& previous_accelerator) {
368 if (accelerator.key_code() == ui::VKEY_LWIN) { 369 if (accelerator.key_code() == ui::VKEY_LWIN) {
369 // If something else was pressed between the Search key (LWIN) 370 // If something else was pressed between the Search key (LWIN)
370 // being pressed and released, then ignore the release of the 371 // being pressed and released, then ignore the release of the
371 // Search key. 372 // Search key.
372 if (previous_accelerator.type() != ui::ET_KEY_PRESSED || 373 if (previous_accelerator.key_state() !=
374 ui::Accelerator::KeyState::PRESSED ||
373 previous_accelerator.key_code() != ui::VKEY_LWIN) { 375 previous_accelerator.key_code() != ui::VKEY_LWIN) {
374 return false; 376 return false;
375 } 377 }
376 378
377 // When spoken feedback is enabled, we should neither toggle the list nor 379 // When spoken feedback is enabled, we should neither toggle the list nor
378 // consume the key since Search+Shift is one of the shortcuts the a11y 380 // consume the key since Search+Shift is one of the shortcuts the a11y
379 // feature uses. crbug.com/132296 381 // feature uses. crbug.com/132296
380 if (Shell::GetInstance() 382 if (Shell::GetInstance()
381 ->accessibility_delegate() 383 ->accessibility_delegate()
382 ->IsSpokenFeedbackEnabled()) 384 ->IsSpokenFeedbackEnabled())
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 } 461 }
460 462
461 void HandleCrosh() { 463 void HandleCrosh() {
462 base::RecordAction(UserMetricsAction("Accel_Open_Crosh")); 464 base::RecordAction(UserMetricsAction("Accel_Open_Crosh"));
463 465
464 WmShell::Get()->new_window_controller()->OpenCrosh(); 466 WmShell::Get()->new_window_controller()->OpenCrosh();
465 } 467 }
466 468
467 bool CanHandleDisableCapsLock(const ui::Accelerator& previous_accelerator) { 469 bool CanHandleDisableCapsLock(const ui::Accelerator& previous_accelerator) {
468 ui::KeyboardCode previous_key_code = previous_accelerator.key_code(); 470 ui::KeyboardCode previous_key_code = previous_accelerator.key_code();
469 if (previous_accelerator.type() == ui::ET_KEY_RELEASED || 471 if (previous_accelerator.key_state() == ui::Accelerator::KeyState::RELEASED ||
470 (previous_key_code != ui::VKEY_LSHIFT && 472 (previous_key_code != ui::VKEY_LSHIFT &&
471 previous_key_code != ui::VKEY_SHIFT && 473 previous_key_code != ui::VKEY_SHIFT &&
472 previous_key_code != ui::VKEY_RSHIFT)) { 474 previous_key_code != ui::VKEY_RSHIFT)) {
473 // If something else was pressed between the Shift key being pressed 475 // If something else was pressed between the Shift key being pressed
474 // and released, then ignore the release of the Shift key. 476 // and released, then ignore the release of the Shift key.
475 return false; 477 return false;
476 } 478 }
477 chromeos::input_method::InputMethodManager* ime = 479 chromeos::input_method::InputMethodManager* ime =
478 chromeos::input_method::InputMethodManager::Get(); 480 chromeos::input_method::InputMethodManager::Get();
479 chromeos::input_method::ImeKeyboard* keyboard = 481 chromeos::input_method::ImeKeyboard* keyboard =
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 } 549 }
548 550
549 bool CanHandleToggleCapsLock(const ui::Accelerator& accelerator, 551 bool CanHandleToggleCapsLock(const ui::Accelerator& accelerator,
550 const ui::Accelerator& previous_accelerator) { 552 const ui::Accelerator& previous_accelerator) {
551 chromeos::input_method::InputMethodManager* ime = 553 chromeos::input_method::InputMethodManager* ime =
552 chromeos::input_method::InputMethodManager::Get(); 554 chromeos::input_method::InputMethodManager::Get();
553 555
554 // This shortcust is set to be trigger on release. Either the current 556 // This shortcust is set to be trigger on release. Either the current
555 // accelerator is a Search release or Alt release. 557 // accelerator is a Search release or Alt release.
556 if (accelerator.key_code() == ui::VKEY_LWIN && 558 if (accelerator.key_code() == ui::VKEY_LWIN &&
557 accelerator.type() == ui::ET_KEY_RELEASED) { 559 accelerator.key_state() == ui::Accelerator::KeyState::RELEASED) {
558 // The previous must be either an Alt press or Search press: 560 // The previous must be either an Alt press or Search press:
559 // 1. Press Alt, Press Search, Release Search, Release Alt. 561 // 1. Press Alt, Press Search, Release Search, Release Alt.
560 // 2. Press Search, Press Alt, Release Search, Release Alt. 562 // 2. Press Search, Press Alt, Release Search, Release Alt.
561 if (previous_accelerator.type() == ui::ET_KEY_PRESSED && 563 if (previous_accelerator.key_state() ==
564 ui::Accelerator::KeyState::PRESSED &&
562 (previous_accelerator.key_code() == ui::VKEY_LWIN || 565 (previous_accelerator.key_code() == ui::VKEY_LWIN ||
563 previous_accelerator.key_code() == ui::VKEY_MENU)) { 566 previous_accelerator.key_code() == ui::VKEY_MENU)) {
564 return ime && ime->GetImeKeyboard(); 567 return ime && ime->GetImeKeyboard();
565 } 568 }
566 } 569 }
567 570
568 // Alt release. 571 // Alt release.
569 if (accelerator.key_code() == ui::VKEY_MENU && 572 if (accelerator.key_code() == ui::VKEY_MENU &&
570 accelerator.type() == ui::ET_KEY_RELEASED) { 573 accelerator.key_state() == ui::Accelerator::KeyState::RELEASED) {
571 // The previous must be either an Alt press or Search press: 574 // The previous must be either an Alt press or Search press:
572 // 3. Press Alt, Press Search, Release Alt, Release Search. 575 // 3. Press Alt, Press Search, Release Alt, Release Search.
573 // 4. Press Search, Press Alt, Release Alt, Release Search. 576 // 4. Press Search, Press Alt, Release Alt, Release Search.
574 if (previous_accelerator.type() == ui::ET_KEY_PRESSED && 577 if (previous_accelerator.key_state() ==
578 ui::Accelerator::KeyState::PRESSED &&
575 (previous_accelerator.key_code() == ui::VKEY_LWIN || 579 (previous_accelerator.key_code() == ui::VKEY_LWIN ||
576 previous_accelerator.key_code() == ui::VKEY_MENU)) { 580 previous_accelerator.key_code() == ui::VKEY_MENU)) {
577 return ime && ime->GetImeKeyboard(); 581 return ime && ime->GetImeKeyboard();
578 } 582 }
579 } 583 }
580 584
581 return false; 585 return false;
582 } 586 }
583 587
584 void HandleToggleCapsLock() { 588 void HandleToggleCapsLock() {
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 data->uma_histogram_name, data->notification_message_id, 1291 data->uma_histogram_name, data->notification_message_id,
1288 data->old_shortcut_id, data->new_shortcut_id); 1292 data->old_shortcut_id, data->new_shortcut_id);
1289 1293
1290 if (!data->deprecated_enabled) 1294 if (!data->deprecated_enabled)
1291 return AcceleratorProcessingStatus::STOP; 1295 return AcceleratorProcessingStatus::STOP;
1292 1296
1293 return AcceleratorProcessingStatus::PROCEED; 1297 return AcceleratorProcessingStatus::PROCEED;
1294 } 1298 }
1295 1299
1296 } // namespace ash 1300 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698