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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 return true; | 303 return true; |
304 } | 304 } |
305 | 305 |
306 #endif // !defined(NDEBUG) | 306 #endif // !defined(NDEBUG) |
307 | 307 |
308 } // namespace | 308 } // namespace |
309 | 309 |
310 //////////////////////////////////////////////////////////////////////////////// | 310 //////////////////////////////////////////////////////////////////////////////// |
311 // AcceleratorControllerContext, public: | 311 // AcceleratorControllerContext, public: |
312 | 312 |
313 AcceleratorControllerContext::AcceleratorControllerContext() | 313 AcceleratorControllerContext::AcceleratorControllerContext() { |
314 : repeated_(false), | 314 current_accelerator_.set_type(ui::ET_UNKNOWN); |
315 previous_event_type_(ui::ET_UNKNOWN) { | 315 previous_accelerator_.set_type(ui::ET_UNKNOWN); |
316 } | 316 } |
317 | 317 |
318 void AcceleratorControllerContext::UpdateContext( | 318 void AcceleratorControllerContext::UpdateContext( |
319 const ui::Accelerator& accelerator) { | 319 const ui::Accelerator& accelerator) { |
320 const ui::Accelerator previous_accelerator = current_accelerator_; | 320 previous_accelerator_ = current_accelerator_; |
321 current_accelerator_ = accelerator; | 321 current_accelerator_ = accelerator; |
322 | |
323 // Compute contextual information. | |
324 repeated_ = previous_accelerator == current_accelerator_; | |
325 previous_event_type_ = previous_accelerator.type(); | |
326 } | 322 } |
327 | 323 |
328 //////////////////////////////////////////////////////////////////////////////// | 324 //////////////////////////////////////////////////////////////////////////////// |
329 // AcceleratorController, public: | 325 // AcceleratorController, public: |
330 | 326 |
331 AcceleratorController::AcceleratorController() | 327 AcceleratorController::AcceleratorController() |
332 : accelerator_manager_(new ui::AcceleratorManager) { | 328 : accelerator_manager_(new ui::AcceleratorManager) { |
333 Init(); | 329 Init(); |
334 } | 330 } |
335 | 331 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 // should never be suspended. | 433 // should never be suspended. |
438 const bool gesture_event = key_code == ui::VKEY_UNKNOWN; | 434 const bool gesture_event = key_code == ui::VKEY_UNKNOWN; |
439 | 435 |
440 // Ignore accelerators invoked as repeated (while holding a key for a long | 436 // Ignore accelerators invoked as repeated (while holding a key for a long |
441 // time, if their handling is nonrepeatable. | 437 // time, if their handling is nonrepeatable. |
442 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && | 438 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && |
443 context_.repeated() && !gesture_event) { | 439 context_.repeated() && !gesture_event) { |
444 return true; | 440 return true; |
445 } | 441 } |
446 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. | 442 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. |
447 const ui::EventType previous_event_type = context_.previous_event_type(); | 443 const ui::EventType previous_event_type = |
| 444 context_.previous_accelerator().type(); |
448 | 445 |
449 // You *MUST* return true when some action is performed. Otherwise, this | 446 // You *MUST* return true when some action is performed. Otherwise, this |
450 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent | 447 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent |
451 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. | 448 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. |
452 switch (action) { | 449 switch (action) { |
453 case CYCLE_BACKWARD_MRU: | 450 case CYCLE_BACKWARD_MRU: |
454 if (key_code == ui::VKEY_TAB && shell->delegate()) | 451 if (key_code == ui::VKEY_TAB && shell->delegate()) |
455 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_PREVWINDOW_TAB); | 452 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_PREVWINDOW_TAB); |
456 return HandleCycleWindowMRU(WindowCycleController::BACKWARD, | 453 return HandleCycleWindowMRU(WindowCycleController::BACKWARD, |
457 accelerator.IsAltDown()); | 454 accelerator.IsAltDown()); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 } | 607 } |
611 break; | 608 break; |
612 case SHOW_TASK_MANAGER: | 609 case SHOW_TASK_MANAGER: |
613 Shell::GetInstance()->delegate()->ShowTaskManager(); | 610 Shell::GetInstance()->delegate()->ShowTaskManager(); |
614 return true; | 611 return true; |
615 case NEXT_IME: | 612 case NEXT_IME: |
616 // This check is necessary e.g. not to process the Shift+Alt+ | 613 // This check is necessary e.g. not to process the Shift+Alt+ |
617 // ET_KEY_RELEASED accelerator for Chrome OS (see ash/accelerators/ | 614 // ET_KEY_RELEASED accelerator for Chrome OS (see ash/accelerators/ |
618 // accelerator_controller.cc) when Shift+Alt+Tab is pressed and then Tab | 615 // accelerator_controller.cc) when Shift+Alt+Tab is pressed and then Tab |
619 // is released. | 616 // is released. |
620 if (previous_event_type == ui::ET_KEY_RELEASED) { | 617 if (previous_event_type == ui::ET_KEY_RELEASED && |
| 618 // Workaround for crbug.com/139556. CJK IME users tend to press |
| 619 // Enter (or Space) and Shift+Alt almost at the same time to commit |
| 620 // an IME string and then switch from the IME to the English layout. |
| 621 // This workaround allows the user to trigger NEXT_IME even if the |
| 622 // user presses Shift+Alt before releasing Enter. |
| 623 // TODO(nona|mazda): Fix crbug.com/139556 in a cleaner way. |
| 624 context_.previous_accelerator().key_code() != ui::VKEY_RETURN && |
| 625 context_.previous_accelerator().key_code() != ui::VKEY_SPACE) { |
621 // We totally ignore this accelerator. | 626 // We totally ignore this accelerator. |
622 // TODO(mazda): Fix crbug.com/158217 | 627 // TODO(mazda): Fix crbug.com/158217 |
623 return false; | 628 return false; |
624 } | 629 } |
625 if (ime_control_delegate_.get()) | 630 if (ime_control_delegate_.get()) |
626 return ime_control_delegate_->HandleNextIme(); | 631 return ime_control_delegate_->HandleNextIme(); |
627 break; | 632 break; |
628 case PREVIOUS_IME: | 633 case PREVIOUS_IME: |
629 if (ime_control_delegate_.get()) | 634 if (ime_control_delegate_.get()) |
630 return ime_control_delegate_->HandlePreviousIme(); | 635 return ime_control_delegate_->HandlePreviousIme(); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 keyboard_brightness_control_delegate) { | 874 keyboard_brightness_control_delegate) { |
870 keyboard_brightness_control_delegate_ = | 875 keyboard_brightness_control_delegate_ = |
871 keyboard_brightness_control_delegate.Pass(); | 876 keyboard_brightness_control_delegate.Pass(); |
872 } | 877 } |
873 | 878 |
874 bool AcceleratorController::CanHandleAccelerators() const { | 879 bool AcceleratorController::CanHandleAccelerators() const { |
875 return true; | 880 return true; |
876 } | 881 } |
877 | 882 |
878 } // namespace ash | 883 } // namespace ash |
OLD | NEW |