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 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)) { |
|
sky
2012/08/13 23:48:37
Can you also add GetWidget() != NULL && button_ ==
yefimt
2012/08/13 23:56:08
Done.
| |
| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 | 225 |
| 225 context_menu_ = menu_runner_->GetMenu(); | 226 context_menu_ = menu_runner_->GetMenu(); |
| 226 gfx::Point screen_loc; | 227 gfx::Point screen_loc; |
| 227 views::View::ConvertPointToScreen(this, &screen_loc); | 228 views::View::ConvertPointToScreen(this, &screen_loc); |
| 228 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), | 229 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), |
| 229 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == | 230 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == |
| 230 views::MenuRunner::MENU_DELETED) { | 231 views::MenuRunner::MENU_DELETED) { |
| 231 return; | 232 return; |
| 232 } | 233 } |
| 233 | 234 |
| 234 menu_runner_.reset(); | |
|
sky
2012/08/13 23:48:37
This should stay.
yefimt
2012/08/13 23:56:08
Done, but I looked how other code does it and nobo
| |
| 235 SetButtonNotPushed(); | 235 SetButtonNotPushed(); |
| 236 context_menu_ = NULL; | 236 context_menu_ = NULL; |
| 237 } | 237 } |
| 238 | 238 |
| 239 void BrowserActionButton::OnImageLoaded(const gfx::Image& image, | 239 void BrowserActionButton::OnImageLoaded(const gfx::Image& image, |
| 240 const std::string& extension_id, | 240 const std::string& extension_id, |
| 241 int index) { | 241 int index) { |
| 242 browser_action_->CacheIcon(browser_action_->default_icon_path(), image); | 242 browser_action_->CacheIcon(browser_action_->default_icon_path(), image); |
| 243 | 243 |
| 244 // Call back to UpdateState() because a more specific icon might have been set | 244 // 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 | 445 |
| 446 extensions::Command browser_action_command; | 446 extensions::Command browser_action_command; |
| 447 if (!only_if_active || !command_service->GetBrowserActionCommand( | 447 if (!only_if_active || !command_service->GetBrowserActionCommand( |
| 448 extension_->id(), | 448 extension_->id(), |
| 449 extensions::CommandService::ACTIVE_ONLY, | 449 extensions::CommandService::ACTIVE_ONLY, |
| 450 &browser_action_command, | 450 &browser_action_command, |
| 451 NULL)) { | 451 NULL)) { |
| 452 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); | 452 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); |
| 453 } | 453 } |
| 454 } | 454 } |
| OLD | NEW |