Chromium Code Reviews| Index: chrome/browser/ui/views/browser_action_view.cc |
| diff --git a/chrome/browser/ui/views/browser_action_view.cc b/chrome/browser/ui/views/browser_action_view.cc |
| index 073d80ecd18bf62997aba32f48ff18d7913c87d3..100964ac1834cdc19925cbdd8dbe3611580e97fe 100644 |
| --- a/chrome/browser/ui/views/browser_action_view.cc |
| +++ b/chrome/browser/ui/views/browser_action_view.cc |
| @@ -10,6 +10,7 @@ |
| #include "chrome/browser/extensions/extension_context_menu_model.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/views/browser_actions_container.h" |
| +#include "chrome/browser/ui/views/browser_action_view.h" |
| #include "chrome/browser/ui/views/toolbar_view.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/extensions/extension.h" |
| @@ -30,14 +31,15 @@ using extensions::Extension; |
| // BrowserActionButton |
| BrowserActionButton::BrowserActionButton(const Extension* extension, |
| - BrowserActionsContainer* panel) |
| + BrowserActionView::Delegate* delegate) |
| : ALLOW_THIS_IN_INITIALIZER_LIST( |
| MenuButton(this, string16(), NULL, false)), |
| browser_action_(extension->browser_action()), |
| extension_(extension), |
| ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), |
| - panel_(panel), |
| - context_menu_(NULL) { |
| + delegate_(delegate), |
| + context_menu_(NULL), |
| + disable_tooltip_(false) { |
| set_border(NULL); |
| set_alignment(TextButton::ALIGN_CENTER); |
| @@ -48,10 +50,10 @@ BrowserActionButton::BrowserActionButton(const Extension* extension, |
| content::Source<ExtensionAction>(browser_action_)); |
| registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, |
| content::Source<Profile>( |
| - panel_->profile()->GetOriginalProfile())); |
| + delegate_->GetBrowser()->profile()->GetOriginalProfile())); |
| registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED, |
| content::Source<Profile>( |
| - panel_->profile()->GetOriginalProfile())); |
| + delegate_->GetBrowser()->profile()->GetOriginalProfile())); |
| } |
| void BrowserActionButton::Destroy() { |
| @@ -102,7 +104,7 @@ bool BrowserActionButton::CanHandleAccelerators() const { |
| void BrowserActionButton::ButtonPressed(views::Button* sender, |
| const views::Event& event) { |
| - panel_->OnBrowserActionExecuted(this); |
| + delegate_->OnBrowserActionExecuted(this); |
| } |
| void BrowserActionButton::OnImageLoaded(const gfx::Image& image, |
| @@ -117,7 +119,7 @@ void BrowserActionButton::OnImageLoaded(const gfx::Image& image, |
| } |
| void BrowserActionButton::UpdateState() { |
| - int tab_id = panel_->GetCurrentTabId(); |
| + int tab_id = delegate_->GetCurrentTabId(); |
| if (tab_id < 0) |
| return; |
| @@ -160,18 +162,19 @@ void BrowserActionButton::UpdateState() { |
| string16 name = UTF8ToUTF16(browser_action()->GetTitle(tab_id)); |
| if (name.empty()) |
| name = UTF8ToUTF16(extension()->name()); |
| + if (!disable_tooltip_) |
| SetTooltipText(name); |
|
Aaron Boodman
2012/07/02 22:41:34
!?
yefimt
2012/07/11 22:34:34
Done.
|
| SetAccessibleName(name); |
| parent()->SchedulePaint(); |
| } |
| bool BrowserActionButton::IsPopup() { |
| - int tab_id = panel_->GetCurrentTabId(); |
| + int tab_id = delegate_->GetCurrentTabId(); |
| return (tab_id < 0) ? false : browser_action_->HasPopup(tab_id); |
| } |
| GURL BrowserActionButton::GetPopupUrl() { |
| - int tab_id = panel_->GetCurrentTabId(); |
| + int tab_id = delegate_->GetCurrentTabId(); |
| return (tab_id < 0) ? GURL() : browser_action_->GetPopupUrl(tab_id); |
| } |
| @@ -183,7 +186,7 @@ void BrowserActionButton::Observe(int type, |
| UpdateState(); |
| // The browser action may have become visible/hidden so we need to make |
| // sure the state gets updated. |
| - panel_->OnBrowserActionVisibilityChanged(); |
| + delegate_->OnBrowserActionVisibilityChanged(); |
| break; |
| case chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED: |
| case chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED: { |
| @@ -210,7 +213,7 @@ bool BrowserActionButton::Activate() { |
| if (!IsPopup()) |
| return true; |
| - panel_->OnBrowserActionExecuted(this); |
| + delegate_->OnBrowserActionExecuted(this); |
| // TODO(erikkay): Run a nested modal loop while the mouse is down to |
| // enable menu-like drag-select behavior. |
| @@ -266,7 +269,7 @@ void BrowserActionButton::ShowContextMenu(const gfx::Point& p, |
| // Reconstructs the menu every time because the menu's contents are dynamic. |
| scoped_refptr<ExtensionContextMenuModel> context_menu_contents_( |
| - new ExtensionContextMenuModel(extension(), panel_->browser())); |
| + new ExtensionContextMenuModel(extension(), delegate_->GetBrowser())); |
| views::MenuModelAdapter menu_model_adapter(context_menu_contents_.get()); |
| views::MenuRunner menu_runner(menu_model_adapter.CreateMenu()); |
| @@ -284,7 +287,7 @@ void BrowserActionButton::ShowContextMenu(const gfx::Point& p, |
| bool BrowserActionButton::AcceleratorPressed( |
| const ui::Accelerator& accelerator) { |
| - panel_->OnBrowserActionExecuted(this); |
| + delegate_->OnBrowserActionExecuted(this); |
| return true; |
| } |
| @@ -298,13 +301,19 @@ void BrowserActionButton::SetButtonNotPushed() { |
| menu_visible_ = false; |
| } |
| +void BrowserActionButton::DisableTooltip(bool disable_tooltip) { |
|
Aaron Boodman
2012/07/02 22:41:34
If this method is going to accept a value, it shou
yefimt
2012/07/11 22:34:34
Renamed to SetTooltipDisabled(...)
On 2012/07/02
|
| + disable_tooltip_ = disable_tooltip; |
| + if (disable_tooltip_) |
| + SetTooltipText(string16()); |
|
Aaron Boodman
2012/07/02 22:41:34
Don't you need to reset it to the string in the ca
yefimt
2012/07/11 22:34:34
Done.
|
| +} |
| + |
| BrowserActionButton::~BrowserActionButton() { |
| } |
| void BrowserActionButton::MaybeRegisterExtensionCommand() { |
| extensions::CommandService* command_service = |
| extensions::CommandServiceFactory::GetForProfile( |
| - panel_->browser()->profile()); |
| + delegate_->GetBrowser()->profile()); |
| extensions::Command browser_action_command; |
| if (command_service->GetBrowserActionCommand( |
| extension_->id(), |
| @@ -313,18 +322,18 @@ void BrowserActionButton::MaybeRegisterExtensionCommand() { |
| NULL)) { |
| keybinding_.reset(new ui::Accelerator( |
| browser_action_command.accelerator())); |
| - panel_->GetFocusManager()->RegisterAccelerator( |
| + GetFocusManager()->RegisterAccelerator( |
| *keybinding_.get(), ui::AcceleratorManager::kHighPriority, this); |
| } |
| } |
| void BrowserActionButton::MaybeUnregisterExtensionCommand(bool only_if_active) { |
| - if (!keybinding_.get() || !panel_->GetFocusManager()) |
| + if (!keybinding_.get() || !GetFocusManager()) |
| return; |
| extensions::CommandService* command_service = |
| extensions::CommandServiceFactory::GetForProfile( |
| - panel_->browser()->profile()); |
| + delegate_->GetBrowser()->profile()); |
| extensions::Command browser_action_command; |
| if (!only_if_active || !command_service->GetBrowserActionCommand( |
| @@ -332,7 +341,7 @@ void BrowserActionButton::MaybeUnregisterExtensionCommand(bool only_if_active) { |
| extensions::CommandService::ACTIVE_ONLY, |
| &browser_action_command, |
| NULL)) { |
| - panel_->GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); |
| + GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); |
| } |
| } |
| @@ -341,10 +350,10 @@ void BrowserActionButton::MaybeUnregisterExtensionCommand(bool only_if_active) { |
| // BrowserActionView |
| BrowserActionView::BrowserActionView(const Extension* extension, |
| - BrowserActionsContainer* panel) |
| - : panel_(panel) { |
| - button_ = new BrowserActionButton(extension, panel); |
| - button_->set_drag_controller(panel_); |
| + BrowserActionView::Delegate* delegate) |
| + : delegate_(delegate) { |
| + button_ = new BrowserActionButton(extension, delegate_); |
| + button_->set_drag_controller(delegate_); |
| AddChildView(button_); |
| button_->UpdateState(); |
| } |
| @@ -355,7 +364,7 @@ BrowserActionView::~BrowserActionView() { |
| } |
| gfx::Canvas* BrowserActionView::GetIconWithBadge() { |
| - int tab_id = panel_->GetCurrentTabId(); |
| + int tab_id = delegate_->GetCurrentTabId(); |
| SkBitmap icon = button_->extension()->browser_action()->GetIcon(tab_id); |
| if (icon.isNull()) |
| @@ -379,7 +388,8 @@ void BrowserActionView::Layout() { |
| // since the bounds don't change). So instead of setting the height from the |
| // button's preferred size, we use IconHeight(), since that's how big the |
| // button should be regardless of what it's displaying. |
| - button_->SetBounds(0, ToolbarView::kVertSpacing, width(), |
| + gfx::Size size = delegate_->GetViewContentOffset(); |
|
Aaron Boodman
2012/07/02 22:41:34
offset?
yefimt
2012/07/11 22:34:34
I know it is coming back over and over:)
Button in
|
| + button_->SetBounds(size.width(), size.height(), width(), |
| BrowserActionsContainer::IconHeight()); |
| } |
| @@ -389,10 +399,15 @@ void BrowserActionView::GetAccessibleState(ui::AccessibleViewState* state) { |
| state->role = ui::AccessibilityTypes::ROLE_GROUPING; |
| } |
| +gfx::Size BrowserActionView::GetPreferredSize() { |
| + return gfx::Size(Extension::kBrowserActionIconMaxSize+10, // FIXME |
|
Aaron Boodman
2012/07/02 22:41:34
Fix before checking in.
yefimt
2012/07/11 22:34:34
Done.
|
| + Extension::kBrowserActionIconMaxSize+10); |
| +} |
| + |
| void BrowserActionView::PaintChildren(gfx::Canvas* canvas) { |
| View::PaintChildren(canvas); |
| ExtensionAction* action = button()->browser_action(); |
| - int tab_id = panel_->GetCurrentTabId(); |
| + int tab_id = delegate_->GetCurrentTabId(); |
| if (tab_id >= 0) |
| action->PaintBadge(canvas, gfx::Rect(width(), height()), tab_id); |
| } |