| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/browser_action_view.h" | 5 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/extensions/api/commands/command_service.h" | 9 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 10 #include "chrome/browser/extensions/extension_action.h" | 10 #include "chrome/browser/extensions/extension_action.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 const gfx::Point& point, | 181 const gfx::Point& point, |
| 182 ui::MenuSourceType source_type) { | 182 ui::MenuSourceType source_type) { |
| 183 if (!extension()->ShowConfigureContextMenus()) | 183 if (!extension()->ShowConfigureContextMenus()) |
| 184 return; | 184 return; |
| 185 | 185 |
| 186 SetButtonPushed(); | 186 SetButtonPushed(); |
| 187 | 187 |
| 188 // Reconstructs the menu every time because the menu's contents are dynamic. | 188 // Reconstructs the menu every time because the menu's contents are dynamic. |
| 189 scoped_refptr<ExtensionContextMenuModel> context_menu_contents( | 189 scoped_refptr<ExtensionContextMenuModel> context_menu_contents( |
| 190 new ExtensionContextMenuModel(extension(), browser_, delegate_)); | 190 new ExtensionContextMenuModel(extension(), browser_, delegate_)); |
| 191 menu_runner_.reset(new views::MenuRunner(context_menu_contents.get())); | |
| 192 | |
| 193 context_menu_ = menu_runner_->GetMenu(); | |
| 194 gfx::Point screen_loc; | 191 gfx::Point screen_loc; |
| 195 views::View::ConvertPointToScreen(this, &screen_loc); | 192 views::View::ConvertPointToScreen(this, &screen_loc); |
| 196 | 193 |
| 197 views::Widget* parent = NULL; | 194 views::Widget* parent = NULL; |
| 198 int run_types = views::MenuRunner::HAS_MNEMONICS | | 195 int run_types = views::MenuRunner::HAS_MNEMONICS | |
| 199 views::MenuRunner::CONTEXT_MENU; | 196 views::MenuRunner::CONTEXT_MENU; |
| 200 if (delegate_->ShownInsideMenu()) { | 197 if (delegate_->ShownInsideMenu()) { |
| 201 run_types |= views::MenuRunner::IS_NESTED; | 198 run_types |= views::MenuRunner::IS_NESTED; |
| 202 // RunMenuAt expects a nested menu to be parented by the same widget as the | 199 // RunMenuAt expects a nested menu to be parented by the same widget as the |
| 203 // already visible menu, in this case the Chrome menu. | 200 // already visible menu, in this case the Chrome menu. |
| 204 parent = BrowserView::GetBrowserViewForBrowser(browser_)->toolbar() | 201 parent = BrowserView::GetBrowserViewForBrowser(browser_)->toolbar() |
| 205 ->app_menu() | 202 ->app_menu() |
| 206 ->GetWidget(); | 203 ->GetWidget(); |
| 207 } else { | 204 } else { |
| 208 parent = GetWidget(); | 205 parent = GetWidget(); |
| 209 } | 206 } |
| 210 | 207 |
| 208 menu_runner_.reset( |
| 209 new views::MenuRunner(context_menu_contents.get(), run_types)); |
| 210 context_menu_ = menu_runner_->GetMenu(); |
| 211 |
| 211 if (menu_runner_->RunMenuAt(parent, | 212 if (menu_runner_->RunMenuAt(parent, |
| 212 NULL, | 213 NULL, |
| 213 gfx::Rect(screen_loc, size()), | 214 gfx::Rect(screen_loc, size()), |
| 214 views::MENU_ANCHOR_TOPLEFT, | 215 views::MENU_ANCHOR_TOPLEFT, |
| 215 source_type, | 216 source_type) == |
| 216 run_types) == | |
| 217 views::MenuRunner::MENU_DELETED) { | 217 views::MenuRunner::MENU_DELETED) { |
| 218 return; | 218 return; |
| 219 } | 219 } |
| 220 | 220 |
| 221 menu_runner_.reset(); | 221 menu_runner_.reset(); |
| 222 SetButtonNotPushed(); | 222 SetButtonNotPushed(); |
| 223 context_menu_ = NULL; | 223 context_menu_ = NULL; |
| 224 } | 224 } |
| 225 | 225 |
| 226 void BrowserActionButton::UpdateState() { | 226 void BrowserActionButton::UpdateState() { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 extensions::Command browser_action_command; | 448 extensions::Command browser_action_command; |
| 449 if (!only_if_active || !command_service->GetBrowserActionCommand( | 449 if (!only_if_active || !command_service->GetBrowserActionCommand( |
| 450 extension_->id(), | 450 extension_->id(), |
| 451 extensions::CommandService::ACTIVE_ONLY, | 451 extensions::CommandService::ACTIVE_ONLY, |
| 452 &browser_action_command, | 452 &browser_action_command, |
| 453 NULL)) { | 453 NULL)) { |
| 454 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); | 454 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); |
| 455 keybinding_.reset(NULL); | 455 keybinding_.reset(NULL); |
| 456 } | 456 } |
| 457 } | 457 } |
| OLD | NEW |