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/dev_mode_bubble_controller.h" | 10 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 button_->set_owned_by_client(); | 56 button_->set_owned_by_client(); |
57 AddChildView(button_); | 57 AddChildView(button_); |
58 button_->UpdateState(); | 58 button_->UpdateState(); |
59 } | 59 } |
60 | 60 |
61 BrowserActionView::~BrowserActionView() { | 61 BrowserActionView::~BrowserActionView() { |
62 button_->Destroy(); | 62 button_->Destroy(); |
63 } | 63 } |
64 | 64 |
65 gfx::ImageSkia BrowserActionView::GetIconWithBadge() { | 65 gfx::ImageSkia BrowserActionView::GetIconWithBadge() { |
66 int tab_id = delegate_->GetCurrentTabId(); | 66 return button_->GetIconWithBadge(); |
67 | |
68 const ExtensionAction* action = | |
69 extensions::ExtensionActionManager::Get(browser_->profile())-> | |
70 GetBrowserAction(*button_->extension()); | |
71 gfx::Size spacing(0, ToolbarView::kVertSpacing); | |
72 gfx::ImageSkia icon = *button_->icon_factory().GetIcon(tab_id).ToImageSkia(); | |
73 if (!button_->IsEnabled(tab_id)) | |
74 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); | |
75 return action->GetIconWithBadge(icon, tab_id, spacing); | |
76 } | 67 } |
77 | 68 |
78 void BrowserActionView::Layout() { | 69 void BrowserActionView::Layout() { |
79 // We can't rely on button_->GetPreferredSize() here because that's not set | 70 // We can't rely on button_->GetPreferredSize() here because that's not set |
80 // correctly until the first call to | 71 // correctly until the first call to |
81 // BrowserActionsContainer::RefreshBrowserActionViews(), whereas this can be | 72 // BrowserActionsContainer::RefreshBrowserActionViews(), whereas this can be |
82 // called before that when the initial bounds are set (and then not after, | 73 // called before that when the initial bounds are set (and then not after, |
83 // since the bounds don't change). So instead of setting the height from the | 74 // since the bounds don't change). So instead of setting the height from the |
84 // button's preferred size, we use IconHeight(), since that's how big the | 75 // button's preferred size, we use IconHeight(), since that's how big the |
85 // button should be regardless of what it's displaying. | 76 // button should be regardless of what it's displaying. |
(...skipping 29 matching lines...) Expand all Loading... | |
115 BrowserActionView::Delegate* delegate) | 106 BrowserActionView::Delegate* delegate) |
116 : MenuButton(this, base::string16(), NULL, false), | 107 : MenuButton(this, base::string16(), NULL, false), |
117 browser_(browser), | 108 browser_(browser), |
118 browser_action_( | 109 browser_action_( |
119 extensions::ExtensionActionManager::Get(browser->profile())-> | 110 extensions::ExtensionActionManager::Get(browser->profile())-> |
120 GetBrowserAction(*extension)), | 111 GetBrowserAction(*extension)), |
121 extension_(extension), | 112 extension_(extension), |
122 icon_factory_(browser->profile(), extension, browser_action_, this), | 113 icon_factory_(browser->profile(), extension, browser_action_, this), |
123 delegate_(delegate), | 114 delegate_(delegate), |
124 context_menu_(NULL), | 115 context_menu_(NULL), |
125 called_registered_extension_command_(false) { | 116 called_registered_extension_command_(false), |
117 icon_observer_(NULL) { | |
126 SetBorder(views::Border::NullBorder()); | 118 SetBorder(views::Border::NullBorder()); |
127 set_alignment(TextButton::ALIGN_CENTER); | 119 set_alignment(TextButton::ALIGN_CENTER); |
128 set_context_menu_controller(this); | 120 set_context_menu_controller(this); |
129 | 121 |
130 // No UpdateState() here because View hierarchy not setup yet. Our parent | 122 // No UpdateState() here because View hierarchy not setup yet. Our parent |
131 // should call UpdateState() after creation. | 123 // should call UpdateState() after creation. |
132 | 124 |
133 content::NotificationSource notification_source = | 125 content::NotificationSource notification_source = |
134 content::Source<Profile>(browser_->profile()->GetOriginalProfile()); | 126 content::Source<Profile>(browser_->profile()->GetOriginalProfile()); |
135 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, | 127 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 UpdateState(); | 296 UpdateState(); |
305 break; | 297 break; |
306 default: | 298 default: |
307 NOTREACHED(); | 299 NOTREACHED(); |
308 break; | 300 break; |
309 } | 301 } |
310 } | 302 } |
311 | 303 |
312 void BrowserActionButton::OnIconUpdated() { | 304 void BrowserActionButton::OnIconUpdated() { |
313 UpdateState(); | 305 UpdateState(); |
306 if (icon_observer_) | |
307 icon_observer_->OnIconUpdated(GetIconWithBadge()); | |
314 } | 308 } |
315 | 309 |
316 bool BrowserActionButton::Activate() { | 310 bool BrowserActionButton::Activate() { |
317 if (!IsPopup()) | 311 if (!IsPopup()) |
318 return true; | 312 return true; |
319 | 313 |
320 delegate_->OnBrowserActionExecuted(this); | 314 delegate_->OnBrowserActionExecuted(this); |
321 | 315 |
322 // TODO(erikkay): Run a nested modal loop while the mouse is down to | 316 // TODO(erikkay): Run a nested modal loop while the mouse is down to |
323 // enable menu-like drag-select behavior. | 317 // enable menu-like drag-select behavior. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 extensions::Command browser_action_command; | 420 extensions::Command browser_action_command; |
427 if (!only_if_active || !command_service->GetBrowserActionCommand( | 421 if (!only_if_active || !command_service->GetBrowserActionCommand( |
428 extension_->id(), | 422 extension_->id(), |
429 extensions::CommandService::ACTIVE_ONLY, | 423 extensions::CommandService::ACTIVE_ONLY, |
430 &browser_action_command, | 424 &browser_action_command, |
431 NULL)) { | 425 NULL)) { |
432 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); | 426 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); |
433 keybinding_.reset(NULL); | 427 keybinding_.reset(NULL); |
434 } | 428 } |
435 } | 429 } |
430 | |
431 gfx::ImageSkia BrowserActionButton::GetIconWithBadge() { | |
432 int tab_id = delegate_->GetCurrentTabId(); | |
433 gfx::Size spacing(0, ToolbarView::kVertSpacing); | |
434 gfx::ImageSkia icon = *icon_factory_.GetIcon(tab_id).ToImageSkia(); | |
435 if (!IsEnabled(tab_id)) | |
436 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); | |
437 return browser_action_->GetIconWithBadge(icon, tab_id, spacing); | |
438 } | |
Finnur
2014/02/12 11:19:52
This function is declared above GetIconForTest() i
| |
OLD | NEW |