OLD | NEW |
---|---|
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/accelerators/accelerator_controller.h" | 5 #include "ash/accelerators/accelerator_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 | 444 |
445 // Ignore accelerators invoked as repeated (while holding a key for a long | 445 // Ignore accelerators invoked as repeated (while holding a key for a long |
446 // time, if their handling is nonrepeatable. | 446 // time, if their handling is nonrepeatable. |
447 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && | 447 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && |
448 context_.repeated() && !gesture_event) { | 448 context_.repeated() && !gesture_event) { |
449 return true; | 449 return true; |
450 } | 450 } |
451 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. | 451 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. |
452 const ui::EventType previous_event_type = | 452 const ui::EventType previous_event_type = |
453 context_.previous_accelerator().type(); | 453 context_.previous_accelerator().type(); |
454 const ui::KeyboardCode previous_key_code = | |
sky
2012/11/27 02:01:53
nit: since you only need this in TOGGLE_APP_LIST,
danakj
2012/11/27 02:27:18
Done.
| |
455 context_.previous_accelerator().key_code(); | |
454 | 456 |
455 // You *MUST* return true when some action is performed. Otherwise, this | 457 // You *MUST* return true when some action is performed. Otherwise, this |
456 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent | 458 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent |
457 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. | 459 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. |
458 switch (action) { | 460 switch (action) { |
459 case CYCLE_BACKWARD_MRU: | 461 case CYCLE_BACKWARD_MRU: |
460 if (key_code == ui::VKEY_TAB && shell->delegate()) | 462 if (key_code == ui::VKEY_TAB && shell->delegate()) |
461 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_PREVWINDOW_TAB); | 463 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_PREVWINDOW_TAB); |
462 return HandleCycleWindowMRU(WindowCycleController::BACKWARD, | 464 return HandleCycleWindowMRU(WindowCycleController::BACKWARD, |
463 accelerator.IsAltDown()); | 465 accelerator.IsAltDown()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 return true; | 529 return true; |
528 case TAKE_PARTIAL_SCREENSHOT: | 530 case TAKE_PARTIAL_SCREENSHOT: |
529 if (screenshot_delegate_.get()) { | 531 if (screenshot_delegate_.get()) { |
530 ash::PartialScreenshotView::StartPartialScreenshot( | 532 ash::PartialScreenshotView::StartPartialScreenshot( |
531 screenshot_delegate_.get()); | 533 screenshot_delegate_.get()); |
532 } | 534 } |
533 // Return true to prevent propagation of the key event because | 535 // Return true to prevent propagation of the key event because |
534 // this key combination is reserved for partial screenshot. | 536 // this key combination is reserved for partial screenshot. |
535 return true; | 537 return true; |
536 case TOGGLE_APP_LIST: | 538 case TOGGLE_APP_LIST: |
539 if (accelerator.key_code() == ui::VKEY_LWIN) { | |
540 // For bindings on the Search key, activate the binding on press if the | |
541 // Search key is not acting as a modifier. Otherwise, activate it on | |
542 // release. | |
543 | |
544 bool search_as_function_key = | |
sky
2012/11/27 02:01:53
nit: if you're doing to use const like you did on
danakj
2012/11/27 02:27:18
Done.
| |
545 Shell::GetInstance()->delegate()->IsSearchKeyActingAsFunctionKey(); | |
546 bool type_pressed = accelerator.type() == ui::ET_KEY_PRESSED; | |
547 | |
548 if (!search_as_function_key && !type_pressed) | |
549 return false; | |
550 if (search_as_function_key && type_pressed) | |
551 return false; | |
552 if (search_as_function_key && | |
553 // If something else was pressed between the Search key (LWIN) | |
554 // being pressed and released, then ignore the release of the | |
555 // Search key. | |
556 (previous_event_type == ui::ET_KEY_RELEASED || | |
557 previous_key_code != ui::VKEY_LWIN)) { | |
558 return false; | |
559 } | |
560 } | |
537 if (key_code == ui::VKEY_LWIN && shell->delegate()) | 561 if (key_code == ui::VKEY_LWIN && shell->delegate()) |
538 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_SEARCH_LWIN); | 562 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_SEARCH_LWIN); |
539 // When spoken feedback is enabled, we should neither toggle the list nor | 563 // When spoken feedback is enabled, we should neither toggle the list nor |
540 // consume the key since Search+Shift is one of the shortcuts the a11y | 564 // consume the key since Search+Shift is one of the shortcuts the a11y |
541 // feature uses. crbug.com/132296 | 565 // feature uses. crbug.com/132296 |
542 DCHECK_EQ(ui::VKEY_LWIN, accelerator.key_code()); | 566 DCHECK_EQ(ui::VKEY_LWIN, accelerator.key_code()); |
543 if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled()) | 567 if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled()) |
544 return false; | 568 return false; |
545 ash::Shell::GetInstance()->ToggleAppList(); | 569 ash::Shell::GetInstance()->ToggleAppList(); |
546 return true; | 570 return true; |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
869 keyboard_brightness_control_delegate) { | 893 keyboard_brightness_control_delegate) { |
870 keyboard_brightness_control_delegate_ = | 894 keyboard_brightness_control_delegate_ = |
871 keyboard_brightness_control_delegate.Pass(); | 895 keyboard_brightness_control_delegate.Pass(); |
872 } | 896 } |
873 | 897 |
874 bool AcceleratorController::CanHandleAccelerators() const { | 898 bool AcceleratorController::CanHandleAccelerators() const { |
875 return true; | 899 return true; |
876 } | 900 } |
877 | 901 |
878 } // namespace ash | 902 } // namespace ash |
OLD | NEW |