diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-05 03:34:54 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-05 03:34:54 +0000 |
commit | f106a756d10fbea1194123395be97c858b08dd95 (patch) | |
tree | 3e36c8758decec179a45b50c8b183accaa0a192e /chrome | |
parent | c3a54ae2c9ac8dc5d093cc192388fdf686971b46 (diff) | |
download | chromium_src-f106a756d10fbea1194123395be97c858b08dd95.zip chromium_src-f106a756d10fbea1194123395be97c858b08dd95.tar.gz chromium_src-f106a756d10fbea1194123395be97c858b08dd95.tar.bz2 |
Now showing the browser action image (including badge) when dragging and
showing the badge in the overflow menu.
BUG=26990
TEST=Browser actions in container/overflow should show image and badge and
also while dragging back and forth.
Review URL: http://codereview.chromium.org/575016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38174 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
3 files changed, 36 insertions, 9 deletions
diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc index 3cf808a..370b1ff 100644 --- a/chrome/browser/views/browser_actions_container.cc +++ b/chrome/browser/views/browser_actions_container.cc @@ -31,6 +31,7 @@ #include "third_party/skia/include/effects/SkGradientShader.h" #include "views/controls/button/menu_button.h" #include "views/controls/button/text_button.h" +#include "views/drag_utils.h" #include "views/window/window.h" #include "grit/theme_resources.h" @@ -274,6 +275,25 @@ BrowserActionView::BrowserActionView(Extension* extension, button_->UpdateState(); } +gfx::Canvas* BrowserActionView::GetIconWithBadge() { + int tab_id = panel_->GetCurrentTabId(); + + SkBitmap icon = button_->extension()->browser_action()->GetIcon(tab_id); + if (icon.isNull()) + icon = button_->default_icon(); + + gfx::Canvas* canvas = new gfx::Canvas(icon.width(), icon.height(), false); + canvas->DrawBitmapInt(icon, 0, 0); + + if (tab_id >= 0) { + gfx::Rect bounds = + gfx::Rect(icon.width(), icon.height() + kControlVertOffset); + button_->extension()->browser_action()->PaintBadge(canvas, bounds, tab_id); + } + + return canvas; +} + void BrowserActionView::Layout() { button_->SetBounds(0, kControlVertOffset, width(), kButtonSize); } @@ -832,7 +852,14 @@ void BrowserActionsContainer::WriteDragData( DCHECK(data); for (size_t i = 0; i < browser_action_views_.size(); ++i) { - if (browser_action_views_[i]->button() == sender) { + BrowserActionButton* button = browser_action_views_[i]->button(); + if (button == sender) { + // Set the dragging image for the icon. + scoped_ptr<gfx::Canvas> canvas( + browser_action_views_[i]->GetIconWithBadge()); + drag_utils::SetDragImageOnDataObject(*canvas, button->width(), + button->height(), press_x, press_y, data); + // Fill in the remaining info. BrowserActionDragData drag_data( browser_action_views_[i]->button()->extension()->id(), i); drag_data.Write(profile_, data); diff --git a/chrome/browser/views/browser_actions_container.h b/chrome/browser/views/browser_actions_container.h index 600c1eb..147b48b 100644 --- a/chrome/browser/views/browser_actions_container.h +++ b/chrome/browser/views/browser_actions_container.h @@ -133,6 +133,11 @@ class BrowserActionView : public views::View { BrowserActionView(Extension* extension, BrowserActionsContainer* panel); BrowserActionButton* button() { return button_; } + // Allocates a canvas object on the heap and draws into it the icon for the + // view as well as the badge (if any). Caller is responsible for deleting the + // returned object. + gfx::Canvas* GetIconWithBadge(); + private: virtual void Layout(); diff --git a/chrome/browser/views/extensions/browser_action_overflow_menu_controller.cc b/chrome/browser/views/extensions/browser_action_overflow_menu_controller.cc index b97cd2a..99e6858 100644 --- a/chrome/browser/views/extensions/browser_action_overflow_menu_controller.cc +++ b/chrome/browser/views/extensions/browser_action_overflow_menu_controller.cc @@ -4,6 +4,7 @@ #include "chrome/browser/views/extensions/browser_action_overflow_menu_controller.h" +#include "app/gfx/canvas.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -26,20 +27,14 @@ BrowserActionOverflowMenuController::BrowserActionOverflowMenuController( menu_.reset(new views::MenuItemView(this)); menu_->set_has_icons(true); - TabContents* tab = BrowserList::GetLastActive()->GetSelectedTabContents(); - int tab_id = tab->controller().session_id().id(); - size_t command_id = 0; for (size_t i = start_index; i < views_->size(); ++i) { BrowserActionView* view = (*views_)[i]; - SkBitmap icon = - view->button()->extension()->browser_action()->GetIcon(tab_id); - if (icon.isNull()) - icon = view->button()->default_icon(); + scoped_ptr<gfx::Canvas> canvas(view->GetIconWithBadge()); menu_->AppendMenuItemWithIcon( command_id, UTF8ToWide(view->button()->extension()->name()), - icon); + canvas->ExtractBitmap()); ++command_id; } } |