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/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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 return true; | 52 return true; |
| 53 } | 53 } |
| 54 | 54 |
| 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 button_ = new BrowserActionButton(extension_, browser_, delegate_); | |
| 63 button_->set_drag_controller(delegate_); | |
| 64 AddChildView(button_); | |
| 65 button_->UpdateState(); | |
| 62 } | 66 } |
| 63 | 67 |
| 64 BrowserActionView::~BrowserActionView() { | 68 BrowserActionView::~BrowserActionView() { |
| 69 RemoveChildView(button_); | |
| 70 button_->Destroy(); | |
|
sky
2012/08/10 19:01:27
Why does BrowserActionButton need a Destroy()? Can
yefimt
2012/08/10 19:27:05
It was the original code before my previous CL, so
| |
| 65 } | 71 } |
| 66 | 72 |
| 67 gfx::Canvas* BrowserActionView::GetIconWithBadge() { | 73 gfx::Canvas* BrowserActionView::GetIconWithBadge() { |
| 68 int tab_id = delegate_->GetCurrentTabId(); | 74 int tab_id = delegate_->GetCurrentTabId(); |
| 69 | 75 |
| 70 SkBitmap icon = | 76 SkBitmap icon = |
| 71 *button_->extension()->browser_action()->GetIcon(tab_id).ToSkBitmap(); | 77 *button_->extension()->browser_action()->GetIcon(tab_id).ToSkBitmap(); |
| 72 | 78 |
| 73 // Dim the icon if our button is disabled. | 79 // Dim the icon if our button is disabled. |
| 74 if (!button_->IsEnabled(tab_id)) | 80 if (!button_->IsEnabled(tab_id)) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 89 // BrowserActionsContainer::RefreshBrowserActionViews(), whereas this can be | 95 // BrowserActionsContainer::RefreshBrowserActionViews(), whereas this can be |
| 90 // called before that when the initial bounds are set (and then not after, | 96 // called before that when the initial bounds are set (and then not after, |
| 91 // since the bounds don't change). So instead of setting the height from the | 97 // since the bounds don't change). So instead of setting the height from the |
| 92 // button's preferred size, we use IconHeight(), since that's how big the | 98 // button's preferred size, we use IconHeight(), since that's how big the |
| 93 // button should be regardless of what it's displaying. | 99 // button should be regardless of what it's displaying. |
| 94 gfx::Point offset = delegate_->GetViewContentOffset(); | 100 gfx::Point offset = delegate_->GetViewContentOffset(); |
| 95 button_->SetBounds(offset.x(), offset.y(), width() - offset.x(), | 101 button_->SetBounds(offset.x(), offset.y(), width() - offset.x(), |
| 96 BrowserActionsContainer::IconHeight()); | 102 BrowserActionsContainer::IconHeight()); |
| 97 } | 103 } |
| 98 | 104 |
| 99 void BrowserActionView::ViewHierarchyChanged(bool is_add, | |
| 100 View* parent, | |
| 101 View* child) { | |
| 102 if (is_add && (child == this)) { | |
| 103 button_ = new BrowserActionButton(extension_, browser_, delegate_); | |
| 104 button_->set_drag_controller(delegate_); | |
| 105 | |
| 106 AddChildView(button_); | |
| 107 button_->UpdateState(); | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 void BrowserActionView::GetAccessibleState(ui::AccessibleViewState* state) { | 105 void BrowserActionView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 112 state->name = l10n_util::GetStringUTF16( | 106 state->name = l10n_util::GetStringUTF16( |
| 113 IDS_ACCNAME_EXTENSIONS_BROWSER_ACTION); | 107 IDS_ACCNAME_EXTENSIONS_BROWSER_ACTION); |
| 114 state->role = ui::AccessibilityTypes::ROLE_GROUPING; | 108 state->role = ui::AccessibilityTypes::ROLE_GROUPING; |
| 115 } | 109 } |
| 116 | 110 |
| 117 gfx::Size BrowserActionView::GetPreferredSize() { | 111 gfx::Size BrowserActionView::GetPreferredSize() { |
| 118 return gfx::Size(BrowserActionsContainer::IconWidth(false), | 112 return gfx::Size(BrowserActionsContainer::IconWidth(false), |
| 119 BrowserActionsContainer::IconHeight()); | 113 BrowserActionsContainer::IconHeight()); |
| 120 } | 114 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu())); | 217 menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu())); |
| 224 | 218 |
| 225 context_menu_ = menu_runner_->GetMenu(); | 219 context_menu_ = menu_runner_->GetMenu(); |
| 226 gfx::Point screen_loc; | 220 gfx::Point screen_loc; |
| 227 views::View::ConvertPointToScreen(this, &screen_loc); | 221 views::View::ConvertPointToScreen(this, &screen_loc); |
| 228 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), | 222 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), |
| 229 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == | 223 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == |
| 230 views::MenuRunner::MENU_DELETED) { | 224 views::MenuRunner::MENU_DELETED) { |
| 231 return; | 225 return; |
| 232 } | 226 } |
| 227 // BrowserActionButton could be deleted by this point, | |
| 228 // i.e. if user selected Disable from the menu. | |
| 233 | 229 |
| 234 menu_runner_.reset(); | |
|
sky
2012/08/10 19:01:27
Why are you removing this?
yefimt
2012/08/10 19:27:05
It is crashing here if BrowserActionButton is dele
| |
| 235 SetButtonNotPushed(); | 230 SetButtonNotPushed(); |
| 236 context_menu_ = NULL; | 231 context_menu_ = NULL; |
| 237 } | 232 } |
| 238 | 233 |
| 239 void BrowserActionButton::OnImageLoaded(const gfx::Image& image, | 234 void BrowserActionButton::OnImageLoaded(const gfx::Image& image, |
| 240 const std::string& extension_id, | 235 const std::string& extension_id, |
| 241 int index) { | 236 int index) { |
| 242 browser_action_->CacheIcon(browser_action_->default_icon_path(), image); | 237 browser_action_->CacheIcon(browser_action_->default_icon_path(), image); |
| 243 | 238 |
| 244 // Call back to UpdateState() because a more specific icon might have been set | 239 // Call back to UpdateState() because a more specific icon might have been set |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 | 440 |
| 446 extensions::Command browser_action_command; | 441 extensions::Command browser_action_command; |
| 447 if (!only_if_active || !command_service->GetBrowserActionCommand( | 442 if (!only_if_active || !command_service->GetBrowserActionCommand( |
| 448 extension_->id(), | 443 extension_->id(), |
| 449 extensions::CommandService::ACTIVE_ONLY, | 444 extensions::CommandService::ACTIVE_ONLY, |
| 450 &browser_action_command, | 445 &browser_action_command, |
| 451 NULL)) { | 446 NULL)) { |
| 452 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); | 447 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); |
| 453 } | 448 } |
| 454 } | 449 } |
| OLD | NEW |