Chromium Code Reviews| 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 "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" | 5 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/commands/command_service.h" | 7 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 8 #include "chrome/browser/extensions/extension_keybinding_registry.h" | 8 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/extensions/accelerator_priority.h" | 10 #include "chrome/browser/ui/extensions/accelerator_priority.h" |
| 11 #include "extensions/common/extension.h" | 11 #include "extensions/common/extension.h" |
| 12 #include "ui/views/event_monitor.h" | |
| 12 #include "ui/views/focus/focus_manager.h" | 13 #include "ui/views/focus/focus_manager.h" |
| 13 | 14 #include "ui/views/widget/widget.h" |
| 14 // static | |
| 15 void extensions::ExtensionKeybindingRegistry::SetShortcutHandlingSuspended( | |
| 16 bool suspended) { | |
| 17 views::FocusManager::set_shortcut_handling_suspended(suspended); | |
|
Finnur
2015/01/12 11:09:46
Isn't this the last remaining caller for FocusMana
Andre
2015/01/12 23:27:15
Ah yes, I forgot to remove this when I started ove
| |
| 18 } | |
| 19 | 15 |
| 20 ExtensionKeybindingRegistryViews::ExtensionKeybindingRegistryViews( | 16 ExtensionKeybindingRegistryViews::ExtensionKeybindingRegistryViews( |
| 21 Profile* profile, | 17 Profile* profile, |
| 22 views::FocusManager* focus_manager, | 18 views::Widget* widget, |
| 23 ExtensionFilter extension_filter, | 19 ExtensionFilter extension_filter, |
| 24 Delegate* delegate) | 20 Delegate* delegate) |
| 25 : ExtensionKeybindingRegistry(profile, extension_filter, delegate), | 21 : ExtensionKeybindingRegistry(profile, extension_filter, delegate), |
| 26 profile_(profile), | 22 profile_(profile), |
| 27 focus_manager_(focus_manager) { | 23 event_tap_( |
| 24 views::EventMonitor::CreateWindowMonitor(this, | |
| 25 widget->GetNativeWindow())), | |
| 26 focus_manager_(widget->GetFocusManager()) { | |
| 28 Init(); | 27 Init(); |
| 28 widget->AddObserver(this); | |
|
Finnur
2015/01/12 11:09:46
Shouldn't we remove this observer in the dtor?
Andre
2015/01/12 23:27:15
Done.
| |
| 29 } | 29 } |
| 30 | 30 |
| 31 ExtensionKeybindingRegistryViews::~ExtensionKeybindingRegistryViews() { | 31 ExtensionKeybindingRegistryViews::~ExtensionKeybindingRegistryViews() { |
| 32 focus_manager_->UnregisterAccelerators(this); | 32 focus_manager_->UnregisterAccelerators(this); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void ExtensionKeybindingRegistryViews::AddExtensionKeybinding( | 35 void ExtensionKeybindingRegistryViews::AddExtensionKeybinding( |
| 36 const extensions::Extension* extension, | 36 const extensions::Extension* extension, |
| 37 const std::string& command_name) { | 37 const std::string& command_name) { |
| 38 // This object only handles named commands, not browser/page actions. | 38 // This object only handles named commands, not browser/page actions. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 63 AddEventTarget(accelerator, extension->id(), iter->second.command_name()); | 63 AddEventTarget(accelerator, extension->id(), iter->second.command_name()); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybindingImpl( | 67 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybindingImpl( |
| 68 const ui::Accelerator& accelerator, | 68 const ui::Accelerator& accelerator, |
| 69 const std::string& command_name) { | 69 const std::string& command_name) { |
| 70 focus_manager_->UnregisterAccelerator(accelerator, this); | 70 focus_manager_->UnregisterAccelerator(accelerator, this); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void ExtensionKeybindingRegistryViews::OnWidgetDestroying( | |
| 74 views::Widget* widget) { | |
| 75 event_tap_.reset(); | |
| 76 } | |
| 77 | |
| 78 void ExtensionKeybindingRegistryViews::OnKeyEvent(ui::KeyEvent* event) { | |
| 79 if (IsShortcutHandlingSuspended()) { | |
| 80 ui::Accelerator accelerator(event->key_code(), event->flags()); | |
| 81 accelerator.set_type(event->type()); | |
| 82 accelerator.set_is_repeat(event->IsRepeat()); | |
| 83 if (focus_manager_->GetCurrentTargetForAccelerator(accelerator)) | |
| 84 event->SetHandled(); | |
|
Finnur
2015/01/12 11:09:46
Curious as to why we need to let some go unhandled
Andre
2015/01/12 23:27:15
SetHandled means we consume the event here to prev
Finnur
2015/01/13 11:16:00
You missed my point. I was asking why we don't cal
Andre
2015/01/14 01:38:26
The intention was that if shortcut handling is not
Finnur
2015/01/14 12:26:46
I think you are referring to the if statement on l
Andre
2015/01/14 21:24:55
Ah I see, sorry for the confusion.
The intent was
| |
| 85 } | |
| 86 } | |
| 87 | |
| 73 bool ExtensionKeybindingRegistryViews::AcceleratorPressed( | 88 bool ExtensionKeybindingRegistryViews::AcceleratorPressed( |
| 74 const ui::Accelerator& accelerator) { | 89 const ui::Accelerator& accelerator) { |
| 75 std::string extension_id, command_name; | 90 std::string extension_id, command_name; |
| 76 GetFirstTarget(accelerator, &extension_id, &command_name); | 91 GetFirstTarget(accelerator, &extension_id, &command_name); |
| 77 const ui::AcceleratorManager::HandlerPriority priority = | 92 const ui::AcceleratorManager::HandlerPriority priority = |
| 78 GetAcceleratorPriorityById(accelerator, extension_id, browser_context()); | 93 GetAcceleratorPriorityById(accelerator, extension_id, browser_context()); |
| 79 // Normal priority shortcuts must be handled via standard browser commands to | 94 // Normal priority shortcuts must be handled via standard browser commands to |
| 80 // be processed at the proper time. | 95 // be processed at the proper time. |
| 81 return (priority == ui::AcceleratorManager::kHighPriority) && | 96 return (priority == ui::AcceleratorManager::kHighPriority) && |
| 82 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); | 97 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); |
| 83 } | 98 } |
| 84 | 99 |
| 85 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { | 100 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { |
| 86 return true; | 101 return true; |
| 87 } | 102 } |
| OLD | NEW |