OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/win_util.h" | 9 #include "base/win_util.h" |
10 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" | 10 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 repeat_count, flags))) { | 300 repeat_count, flags))) { |
301 // This should not be processed as an accelerator. | 301 // This should not be processed as an accelerator. |
302 return true; | 302 return true; |
303 } | 303 } |
304 | 304 |
305 // Process keyboard accelerators. | 305 // Process keyboard accelerators. |
306 // We process accelerators here as we have no way of knowing if a HWND has | 306 // We process accelerators here as we have no way of knowing if a HWND has |
307 // really processed a key event. If the key combination matches an | 307 // really processed a key event. If the key combination matches an |
308 // accelerator, the accelerator is triggered, otherwise we forward the | 308 // accelerator, the accelerator is triggered, otherwise we forward the |
309 // event to the HWND. | 309 // event to the HWND. |
310 int modifiers = 0; | |
311 if (win_util::IsShiftPressed()) | |
312 modifiers |= Event::EF_SHIFT_DOWN; | |
313 if (win_util::IsCtrlPressed()) | |
314 modifiers |= Event::EF_CONTROL_DOWN; | |
315 if (win_util::IsAltPressed()) | |
316 modifiers |= Event::EF_ALT_DOWN; | |
317 Accelerator accelerator(Accelerator(static_cast<int>(virtual_key_code), | 310 Accelerator accelerator(Accelerator(static_cast<int>(virtual_key_code), |
318 win_util::IsShiftPressed(), | 311 win_util::IsShiftPressed(), |
319 win_util::IsCtrlPressed(), | 312 win_util::IsCtrlPressed(), |
320 win_util::IsAltPressed())); | 313 win_util::IsAltPressed())); |
321 if (ProcessAccelerator(accelerator, true)) { | 314 if (ProcessAccelerator(accelerator)) { |
322 // If a shortcut was activated for this keydown message, do not | 315 // If a shortcut was activated for this keydown message, do not |
323 // propagate the message further. | 316 // propagate the message further. |
324 return false; | 317 return false; |
325 } | 318 } |
326 return true; | 319 return true; |
327 } | 320 } |
328 | 321 |
329 bool FocusManager::OnPostActivate(HWND window, | 322 bool FocusManager::OnPostActivate(HWND window, |
330 int activation_state, | 323 int activation_state, |
331 int minimized_state) { | 324 int minimized_state) { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 void FocusManager::UnregisterAccelerators(AcceleratorTarget* target) { | 635 void FocusManager::UnregisterAccelerators(AcceleratorTarget* target) { |
643 for (AcceleratorMap::iterator iter = accelerators_.begin(); | 636 for (AcceleratorMap::iterator iter = accelerators_.begin(); |
644 iter != accelerators_.end();) { | 637 iter != accelerators_.end();) { |
645 if (iter->second == target) | 638 if (iter->second == target) |
646 accelerators_.erase(iter++); | 639 accelerators_.erase(iter++); |
647 else | 640 else |
648 ++iter; | 641 ++iter; |
649 } | 642 } |
650 } | 643 } |
651 | 644 |
652 bool FocusManager::ProcessAccelerator(const Accelerator& accelerator, | 645 bool FocusManager::ProcessAccelerator(const Accelerator& accelerator) { |
653 bool prioritary_accelerators_only) { | 646 FocusManager* focus_manager = this; |
654 if (!prioritary_accelerators_only || | 647 do { |
655 accelerator.IsCtrlDown() || accelerator.IsAltDown() || | 648 AcceleratorTarget* target = |
656 accelerator.GetKeyCode() == VK_ESCAPE || | 649 focus_manager->GetTargetForAccelerator(accelerator); |
657 accelerator.GetKeyCode() == VK_RETURN || | 650 if (target) { |
658 (accelerator.GetKeyCode() >= VK_F1 && | 651 // If there is focused view, we give it a chance to process that |
659 accelerator.GetKeyCode() <= VK_F24) || | 652 // accelerator. |
660 (accelerator.GetKeyCode() >= VK_BROWSER_BACK && | 653 if (!focused_view_ || |
661 accelerator.GetKeyCode() <= VK_BROWSER_HOME)) { | 654 !focused_view_->OverrideAccelerator(accelerator)) { |
662 FocusManager* focus_manager = this; | 655 if (target->AcceleratorPressed(accelerator)) |
663 do { | 656 return true; |
664 AcceleratorTarget* target = | |
665 focus_manager->GetTargetForAccelerator(accelerator); | |
666 if (target) { | |
667 // If there is focused view, we give it a chance to process that | |
668 // accelerator. | |
669 if (!focused_view_ || | |
670 !focused_view_->OverrideAccelerator(accelerator)) { | |
671 if (target->AcceleratorPressed(accelerator)) | |
672 return true; | |
673 } | |
674 } | 657 } |
| 658 } |
675 | 659 |
676 // When dealing with child windows that have their own FocusManager (such | 660 // When dealing with child windows that have their own FocusManager (such |
677 // as ConstrainedWindow), we still want the parent FocusManager to process | 661 // as ConstrainedWindow), we still want the parent FocusManager to process |
678 // the accelerator if the child window did not process it. | 662 // the accelerator if the child window did not process it. |
679 focus_manager = focus_manager->GetParentFocusManager(); | 663 focus_manager = focus_manager->GetParentFocusManager(); |
680 } while (focus_manager); | 664 } while (focus_manager); |
681 } | |
682 return false; | 665 return false; |
683 } | 666 } |
684 | 667 |
685 AcceleratorTarget* FocusManager::GetTargetForAccelerator( | 668 AcceleratorTarget* FocusManager::GetTargetForAccelerator( |
686 const Accelerator& accelerator) const { | 669 const Accelerator& accelerator) const { |
687 AcceleratorMap::const_iterator iter = accelerators_.find(accelerator); | 670 AcceleratorMap::const_iterator iter = accelerators_.find(accelerator); |
688 if (iter != accelerators_.end()) | 671 if (iter != accelerators_.end()) |
689 return iter->second; | 672 return iter->second; |
690 return NULL; | 673 return NULL; |
691 } | 674 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), | 711 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), |
729 listener); | 712 listener); |
730 if (place == focus_change_listeners_.end()) { | 713 if (place == focus_change_listeners_.end()) { |
731 NOTREACHED() << "Removing a listener that isn't registered."; | 714 NOTREACHED() << "Removing a listener that isn't registered."; |
732 return; | 715 return; |
733 } | 716 } |
734 focus_change_listeners_.erase(place); | 717 focus_change_listeners_.erase(place); |
735 } | 718 } |
736 | 719 |
737 } // namespace views | 720 } // namespace views |
OLD | NEW |