| 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/utf_string_conversions.h" | 7 #include "base/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/api/commands/command_service_factory.h" | 9 #include "chrome/browser/extensions/api/commands/command_service_factory.h" |
| 10 #include "chrome/browser/extensions/extension_context_menu_model.h" | 10 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 BrowserActionView::BrowserActionView(const Extension* extension, | 55 BrowserActionView::BrowserActionView(const Extension* extension, |
| 56 Browser* browser, | 56 Browser* browser, |
| 57 BrowserActionView::Delegate* delegate) | 57 BrowserActionView::Delegate* delegate) |
| 58 : browser_(browser), | 58 : browser_(browser), |
| 59 delegate_(delegate), | 59 delegate_(delegate), |
| 60 button_(NULL), | 60 button_(NULL), |
| 61 extension_(extension) { | 61 extension_(extension) { |
| 62 } | 62 } |
| 63 | 63 |
| 64 BrowserActionView::~BrowserActionView() { | 64 BrowserActionView::~BrowserActionView() { |
| 65 button_->Destroy(); |
| 65 } | 66 } |
| 66 | 67 |
| 67 gfx::Canvas* BrowserActionView::GetIconWithBadge() { | 68 gfx::Canvas* BrowserActionView::GetIconWithBadge() { |
| 68 int tab_id = delegate_->GetCurrentTabId(); | 69 int tab_id = delegate_->GetCurrentTabId(); |
| 69 | 70 |
| 70 SkBitmap icon = | 71 SkBitmap icon = |
| 71 *button_->extension()->browser_action()->GetIcon(tab_id).ToSkBitmap(); | 72 *button_->extension()->browser_action()->GetIcon(tab_id).ToSkBitmap(); |
| 72 | 73 |
| 73 // Dim the icon if our button is disabled. | 74 // Dim the icon if our button is disabled. |
| 74 if (!button_->IsEnabled(tab_id)) | 75 if (!button_->IsEnabled(tab_id)) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 92 // button's preferred size, we use IconHeight(), since that's how big the | 93 // button's preferred size, we use IconHeight(), since that's how big the |
| 93 // button should be regardless of what it's displaying. | 94 // button should be regardless of what it's displaying. |
| 94 gfx::Point offset = delegate_->GetViewContentOffset(); | 95 gfx::Point offset = delegate_->GetViewContentOffset(); |
| 95 button_->SetBounds(offset.x(), offset.y(), width() - offset.x(), | 96 button_->SetBounds(offset.x(), offset.y(), width() - offset.x(), |
| 96 BrowserActionsContainer::IconHeight()); | 97 BrowserActionsContainer::IconHeight()); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void BrowserActionView::ViewHierarchyChanged(bool is_add, | 100 void BrowserActionView::ViewHierarchyChanged(bool is_add, |
| 100 View* parent, | 101 View* parent, |
| 101 View* child) { | 102 View* child) { |
| 102 if (is_add && (child == this)) { | 103 if (is_add && (child == this) && (GetWidget() != NULL) && (button_ == NULL)) { |
| 103 button_ = new BrowserActionButton(extension_, browser_, delegate_); | 104 button_ = new BrowserActionButton(extension_, browser_, delegate_); |
| 104 button_->set_drag_controller(delegate_); | 105 button_->set_drag_controller(delegate_); |
| 105 | 106 button_->set_owned_by_client(); |
| 106 AddChildView(button_); | 107 AddChildView(button_); |
| 107 button_->UpdateState(); | 108 button_->UpdateState(); |
| 108 } | 109 } |
| 109 } | 110 } |
| 110 | 111 |
| 111 void BrowserActionView::GetAccessibleState(ui::AccessibleViewState* state) { | 112 void BrowserActionView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 112 state->name = l10n_util::GetStringUTF16( | 113 state->name = l10n_util::GetStringUTF16( |
| 113 IDS_ACCNAME_EXTENSIONS_BROWSER_ACTION); | 114 IDS_ACCNAME_EXTENSIONS_BROWSER_ACTION); |
| 114 state->role = ui::AccessibilityTypes::ROLE_GROUPING; | 115 state->role = ui::AccessibilityTypes::ROLE_GROUPING; |
| 115 } | 116 } |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 446 |
| 446 extensions::Command browser_action_command; | 447 extensions::Command browser_action_command; |
| 447 if (!only_if_active || !command_service->GetBrowserActionCommand( | 448 if (!only_if_active || !command_service->GetBrowserActionCommand( |
| 448 extension_->id(), | 449 extension_->id(), |
| 449 extensions::CommandService::ACTIVE_ONLY, | 450 extensions::CommandService::ACTIVE_ONLY, |
| 450 &browser_action_command, | 451 &browser_action_command, |
| 451 NULL)) { | 452 NULL)) { |
| 452 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); | 453 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); |
| 453 } | 454 } |
| 454 } | 455 } |
| OLD | NEW |