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/location_bar/page_action_image_view.h" | 5 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/api/commands/command_service.h" | 8 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 9 #include "chrome/browser/extensions/extension_action.h" | 9 #include "chrome/browser/extensions/extension_action.h" |
| 10 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 10 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
| 11 #include "chrome/browser/extensions/extension_action_manager.h" | 11 #include "chrome/browser/extensions/extension_action_manager.h" |
| 12 #include "chrome/browser/extensions/extension_context_menu_model.h" | 12 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 13 #include "chrome/browser/extensions/extension_tab_util.h" | 13 #include "chrome/browser/extensions/extension_tab_util.h" |
| 14 #include "chrome/browser/extensions/location_bar_controller.h" | 14 #include "chrome/browser/extensions/location_bar_controller.h" |
| 15 #include "chrome/browser/extensions/tab_helper.h" | 15 #include "chrome/browser/extensions/tab_helper.h" |
| 16 #include "chrome/browser/platform_util.h" | 16 #include "chrome/browser/platform_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/sessions/session_id.h" | 18 #include "chrome/browser/sessions/session_id.h" |
| 19 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
| 20 #include "chrome/browser/ui/extensions/accelerator_priority.h" | |
| 20 #include "chrome/browser/ui/views/frame/browser_view.h" | 21 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 21 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 22 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 22 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" | 23 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" |
| 23 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
| 24 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
| 25 #include "ui/accessibility/ax_view_state.h" | 26 #include "ui/accessibility/ax_view_state.h" |
| 26 #include "ui/events/event.h" | 27 #include "ui/events/event.h" |
| 27 #include "ui/gfx/canvas.h" | 28 #include "ui/gfx/canvas.h" |
| 28 #include "ui/gfx/image/image.h" | 29 #include "ui/gfx/image/image.h" |
| 29 #include "ui/views/controls/menu/menu_runner.h" | 30 #include "ui/views/controls/menu/menu_runner.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 58 extensions::Command page_action_command; | 59 extensions::Command page_action_command; |
| 59 if (command_service->GetPageActionCommand( | 60 if (command_service->GetPageActionCommand( |
| 60 extension->id(), | 61 extension->id(), |
| 61 extensions::CommandService::ACTIVE_ONLY, | 62 extensions::CommandService::ACTIVE_ONLY, |
| 62 &page_action_command, | 63 &page_action_command, |
| 63 NULL)) { | 64 NULL)) { |
| 64 page_action_keybinding_.reset( | 65 page_action_keybinding_.reset( |
| 65 new ui::Accelerator(page_action_command.accelerator())); | 66 new ui::Accelerator(page_action_command.accelerator())); |
| 66 owner_->GetFocusManager()->RegisterAccelerator( | 67 owner_->GetFocusManager()->RegisterAccelerator( |
| 67 *page_action_keybinding_.get(), | 68 *page_action_keybinding_.get(), |
| 68 ui::AcceleratorManager::kHighPriority, | 69 GetAcceleratorPriority(page_action_command.accelerator(), extension), |
| 69 this); | 70 this); |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 | 73 |
| 73 PageActionImageView::~PageActionImageView() { | 74 PageActionImageView::~PageActionImageView() { |
| 74 if (owner_->GetFocusManager()) { | 75 if (owner_->GetFocusManager()) { |
| 75 if (page_action_keybinding_.get()) { | 76 if (page_action_keybinding_.get()) { |
| 76 owner_->GetFocusManager()->UnregisterAccelerator( | 77 owner_->GetFocusManager()->UnregisterAccelerator( |
| 77 *page_action_keybinding_.get(), this); | 78 *page_action_keybinding_.get(), this); |
| 78 } | 79 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == | 171 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == |
| 171 views::MenuRunner::MENU_DELETED) { | 172 views::MenuRunner::MENU_DELETED) { |
| 172 return; | 173 return; |
| 173 } | 174 } |
| 174 } | 175 } |
| 175 | 176 |
| 176 bool PageActionImageView::AcceleratorPressed( | 177 bool PageActionImageView::AcceleratorPressed( |
| 177 const ui::Accelerator& accelerator) { | 178 const ui::Accelerator& accelerator) { |
| 178 DCHECK(visible()); // Should not have happened due to CanHandleAccelerator. | 179 DCHECK(visible()); // Should not have happened due to CanHandleAccelerator. |
| 179 | 180 |
| 181 // Normal priority shortcuts must be handled via the standard browser command | |
| 182 // processing to be effective. | |
| 183 if (GetAcceleratorPriorityById(accelerator, | |
|
Peter Kasting
2014/07/07 23:47:10
Nit: Shorter:
const ui::AcceleratorManager::Han
Mike Wittman
2014/07/08 19:29:01
Done, although requires an extra line for extensio
| |
| 184 page_action()->extension_id(), | |
| 185 owner_->profile()) == | |
| 186 ui::AcceleratorManager::kNormalPriority) | |
| 187 return false; | |
| 188 | |
| 180 ExecuteAction(ExtensionPopup::SHOW); | 189 ExecuteAction(ExtensionPopup::SHOW); |
| 181 return true; | 190 return true; |
| 182 } | 191 } |
| 183 | 192 |
| 184 bool PageActionImageView::CanHandleAccelerators() const { | 193 bool PageActionImageView::CanHandleAccelerators() const { |
| 185 // While visible, we don't handle accelerators and while so we also don't | 194 // While visible, we don't handle accelerators and while so we also don't |
| 186 // count as a priority accelerator handler. | 195 // count as a priority accelerator handler. |
| 187 return visible(); | 196 return visible(); |
| 188 } | 197 } |
| 189 | 198 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 | 262 |
| 254 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow, | 263 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow, |
| 255 show_action); | 264 show_action); |
| 256 popup_->GetWidget()->AddObserver(this); | 265 popup_->GetWidget()->AddObserver(this); |
| 257 } | 266 } |
| 258 | 267 |
| 259 void PageActionImageView::HidePopup() { | 268 void PageActionImageView::HidePopup() { |
| 260 if (popup_) | 269 if (popup_) |
| 261 popup_->GetWidget()->Close(); | 270 popup_->GetWidget()->Close(); |
| 262 } | 271 } |
| OLD | NEW |