| 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" |
| 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_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/themes/theme_service.h" | 15 #include "chrome/browser/themes/theme_service.h" |
| 16 #include "chrome/browser/themes/theme_service_factory.h" | 16 #include "chrome/browser/themes/theme_service_factory.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/extensions/accelerator_priority.h" |
| 18 #include "chrome/browser/ui/view_ids.h" | 19 #include "chrome/browser/ui/view_ids.h" |
| 19 #include "chrome/browser/ui/views/frame/browser_view.h" | 20 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 20 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 21 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 21 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 22 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 22 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
| 23 #include "extensions/common/manifest_constants.h" | 24 #include "extensions/common/manifest_constants.h" |
| 24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 25 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
| 26 #include "ui/accessibility/ax_view_state.h" | 27 #include "ui/accessibility/ax_view_state.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 372 |
| 372 scoped_ptr<LabelButtonBorder> BrowserActionButton::CreateDefaultBorder() const { | 373 scoped_ptr<LabelButtonBorder> BrowserActionButton::CreateDefaultBorder() const { |
| 373 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); | 374 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); |
| 374 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, | 375 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, |
| 375 kBorderInset, kBorderInset)); | 376 kBorderInset, kBorderInset)); |
| 376 return border.Pass(); | 377 return border.Pass(); |
| 377 } | 378 } |
| 378 | 379 |
| 379 bool BrowserActionButton::AcceleratorPressed( | 380 bool BrowserActionButton::AcceleratorPressed( |
| 380 const ui::Accelerator& accelerator) { | 381 const ui::Accelerator& accelerator) { |
| 382 // Normal priority shortcuts must be handled via standard browser commands to |
| 383 // be processed at the proper time. |
| 384 if (GetAcceleratorPriority(accelerator, extension_) == |
| 385 ui::AcceleratorManager::kNormalPriority) |
| 386 return false; |
| 387 |
| 381 delegate_->OnBrowserActionExecuted(this); | 388 delegate_->OnBrowserActionExecuted(this); |
| 382 return true; | 389 return true; |
| 383 } | 390 } |
| 384 | 391 |
| 385 void BrowserActionButton::SetButtonPushed() { | 392 void BrowserActionButton::SetButtonPushed() { |
| 386 SetState(views::CustomButton::STATE_PRESSED); | 393 SetState(views::CustomButton::STATE_PRESSED); |
| 387 menu_visible_ = true; | 394 menu_visible_ = true; |
| 388 } | 395 } |
| 389 | 396 |
| 390 void BrowserActionButton::SetButtonNotPushed() { | 397 void BrowserActionButton::SetButtonNotPushed() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 417 extensions::CommandService::Get(browser_->profile()); | 424 extensions::CommandService::Get(browser_->profile()); |
| 418 extensions::Command browser_action_command; | 425 extensions::Command browser_action_command; |
| 419 if (command_service->GetBrowserActionCommand( | 426 if (command_service->GetBrowserActionCommand( |
| 420 extension_->id(), | 427 extension_->id(), |
| 421 extensions::CommandService::ACTIVE_ONLY, | 428 extensions::CommandService::ACTIVE_ONLY, |
| 422 &browser_action_command, | 429 &browser_action_command, |
| 423 NULL)) { | 430 NULL)) { |
| 424 keybinding_.reset(new ui::Accelerator( | 431 keybinding_.reset(new ui::Accelerator( |
| 425 browser_action_command.accelerator())); | 432 browser_action_command.accelerator())); |
| 426 GetFocusManager()->RegisterAccelerator( | 433 GetFocusManager()->RegisterAccelerator( |
| 427 *keybinding_.get(), ui::AcceleratorManager::kHighPriority, this); | 434 *keybinding_.get(), |
| 435 GetAcceleratorPriority(browser_action_command.accelerator(), |
| 436 extension_), |
| 437 this); |
| 428 } | 438 } |
| 429 } | 439 } |
| 430 | 440 |
| 431 void BrowserActionButton::MaybeUnregisterExtensionCommand(bool only_if_active) { | 441 void BrowserActionButton::MaybeUnregisterExtensionCommand(bool only_if_active) { |
| 432 if (!keybinding_.get() || !GetFocusManager()) | 442 if (!keybinding_.get() || !GetFocusManager()) |
| 433 return; | 443 return; |
| 434 | 444 |
| 435 extensions::CommandService* command_service = | 445 extensions::CommandService* command_service = |
| 436 extensions::CommandService::Get(browser_->profile()); | 446 extensions::CommandService::Get(browser_->profile()); |
| 437 | 447 |
| 438 extensions::Command browser_action_command; | 448 extensions::Command browser_action_command; |
| 439 if (!only_if_active || !command_service->GetBrowserActionCommand( | 449 if (!only_if_active || !command_service->GetBrowserActionCommand( |
| 440 extension_->id(), | 450 extension_->id(), |
| 441 extensions::CommandService::ACTIVE_ONLY, | 451 extensions::CommandService::ACTIVE_ONLY, |
| 442 &browser_action_command, | 452 &browser_action_command, |
| 443 NULL)) { | 453 NULL)) { |
| 444 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); | 454 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); |
| 445 keybinding_.reset(NULL); | 455 keybinding_.reset(NULL); |
| 446 } | 456 } |
| 447 } | 457 } |
| OLD | NEW |