| 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/browser_action_view.h" | 5 #include "chrome/browser/ui/views/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/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_manager.h" | 10 #include "chrome/browser/extensions/extension_action_manager.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 void BrowserActionButton::GetAccessibleState(ui::AccessibleViewState* state) { | 168 void BrowserActionButton::GetAccessibleState(ui::AccessibleViewState* state) { |
| 169 views::MenuButton::GetAccessibleState(state); | 169 views::MenuButton::GetAccessibleState(state); |
| 170 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 170 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 171 } | 171 } |
| 172 | 172 |
| 173 void BrowserActionButton::ButtonPressed(views::Button* sender, | 173 void BrowserActionButton::ButtonPressed(views::Button* sender, |
| 174 const ui::Event& event) { | 174 const ui::Event& event) { |
| 175 delegate_->OnBrowserActionExecuted(this); | 175 delegate_->OnBrowserActionExecuted(this); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void BrowserActionButton::ShowContextMenuForView(View* source, | 178 void BrowserActionButton::ShowContextMenuForView( |
| 179 const gfx::Point& point) { | 179 View* source, |
| 180 const gfx::Point& point, |
| 181 ui::MenuSourceType source_type) { |
| 180 if (!extension()->ShowConfigureContextMenus()) | 182 if (!extension()->ShowConfigureContextMenus()) |
| 181 return; | 183 return; |
| 182 | 184 |
| 183 SetButtonPushed(); | 185 SetButtonPushed(); |
| 184 | 186 |
| 185 // Reconstructs the menu every time because the menu's contents are dynamic. | 187 // Reconstructs the menu every time because the menu's contents are dynamic. |
| 186 scoped_refptr<ExtensionContextMenuModel> context_menu_contents_( | 188 scoped_refptr<ExtensionContextMenuModel> context_menu_contents_( |
| 187 new ExtensionContextMenuModel(extension(), browser_, delegate_)); | 189 new ExtensionContextMenuModel(extension(), browser_, delegate_)); |
| 188 menu_runner_.reset(new views::MenuRunner(context_menu_contents_.get())); | 190 menu_runner_.reset(new views::MenuRunner(context_menu_contents_.get())); |
| 189 | 191 |
| 190 context_menu_ = menu_runner_->GetMenu(); | 192 context_menu_ = menu_runner_->GetMenu(); |
| 191 gfx::Point screen_loc; | 193 gfx::Point screen_loc; |
| 192 views::View::ConvertPointToScreen(this, &screen_loc); | 194 views::View::ConvertPointToScreen(this, &screen_loc); |
| 193 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), | 195 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), |
| 194 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS | | 196 views::MenuItemView::TOPLEFT, source_type, |
| 195 views::MenuRunner::CONTEXT_MENU) == | 197 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == |
| 196 views::MenuRunner::MENU_DELETED) { | 198 views::MenuRunner::MENU_DELETED) { |
| 197 return; | 199 return; |
| 198 } | 200 } |
| 199 | 201 |
| 200 menu_runner_.reset(); | 202 menu_runner_.reset(); |
| 201 SetButtonNotPushed(); | 203 SetButtonNotPushed(); |
| 202 context_menu_ = NULL; | 204 context_menu_ = NULL; |
| 203 } | 205 } |
| 204 | 206 |
| 205 void BrowserActionButton::UpdateState() { | 207 void BrowserActionButton::UpdateState() { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 bool BrowserActionButton::OnMousePressed(const ui::MouseEvent& event) { | 311 bool BrowserActionButton::OnMousePressed(const ui::MouseEvent& event) { |
| 310 if (!event.IsRightMouseButton()) { | 312 if (!event.IsRightMouseButton()) { |
| 311 return IsPopup() ? MenuButton::OnMousePressed(event) : | 313 return IsPopup() ? MenuButton::OnMousePressed(event) : |
| 312 TextButton::OnMousePressed(event); | 314 TextButton::OnMousePressed(event); |
| 313 } | 315 } |
| 314 | 316 |
| 315 if (!views::View::ShouldShowContextMenuOnMousePress()) { | 317 if (!views::View::ShouldShowContextMenuOnMousePress()) { |
| 316 // See comments in MenuButton::Activate() as to why this is needed. | 318 // See comments in MenuButton::Activate() as to why this is needed. |
| 317 SetMouseHandler(NULL); | 319 SetMouseHandler(NULL); |
| 318 | 320 |
| 319 ShowContextMenu(gfx::Point(), true); | 321 ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); |
| 320 } | 322 } |
| 321 return false; | 323 return false; |
| 322 } | 324 } |
| 323 | 325 |
| 324 void BrowserActionButton::OnMouseReleased(const ui::MouseEvent& event) { | 326 void BrowserActionButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 325 if (IsPopup() || context_menu_) { | 327 if (IsPopup() || context_menu_) { |
| 326 // TODO(erikkay) this never actually gets called (probably because of the | 328 // TODO(erikkay) this never actually gets called (probably because of the |
| 327 // loss of focus). | 329 // loss of focus). |
| 328 MenuButton::OnMouseReleased(event); | 330 MenuButton::OnMouseReleased(event); |
| 329 } else { | 331 } else { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 extensions::Command browser_action_command; | 405 extensions::Command browser_action_command; |
| 404 if (!only_if_active || !command_service->GetBrowserActionCommand( | 406 if (!only_if_active || !command_service->GetBrowserActionCommand( |
| 405 extension_->id(), | 407 extension_->id(), |
| 406 extensions::CommandService::ACTIVE_ONLY, | 408 extensions::CommandService::ACTIVE_ONLY, |
| 407 &browser_action_command, | 409 &browser_action_command, |
| 408 NULL)) { | 410 NULL)) { |
| 409 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); | 411 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); |
| 410 keybinding_.reset(NULL); | 412 keybinding_.reset(NULL); |
| 411 } | 413 } |
| 412 } | 414 } |
| OLD | NEW |