| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/extensions/browser_action_overflow_menu_controlle
r.h" | 5 #include "chrome/browser/views/extensions/browser_action_overflow_menu_controlle
r.h" |
| 6 | 6 |
| 7 #include "app/gfx/canvas.h" |
| 7 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
| 9 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
| 10 #include "chrome/browser/views/browser_actions_container.h" | 11 #include "chrome/browser/views/browser_actions_container.h" |
| 11 #include "chrome/browser/views/extensions/browser_action_drag_data.h" | 12 #include "chrome/browser/views/extensions/browser_action_drag_data.h" |
| 12 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
| 13 #include "views/controls/menu/menu_item_view.h" | 14 #include "views/controls/menu/menu_item_view.h" |
| 14 | 15 |
| 15 BrowserActionOverflowMenuController::BrowserActionOverflowMenuController( | 16 BrowserActionOverflowMenuController::BrowserActionOverflowMenuController( |
| 16 BrowserActionsContainer* owner, | 17 BrowserActionsContainer* owner, |
| 17 views::MenuButton* menu_button, | 18 views::MenuButton* menu_button, |
| 18 const std::vector<BrowserActionView*>& views, | 19 const std::vector<BrowserActionView*>& views, |
| 19 int start_index) | 20 int start_index) |
| 20 : owner_(owner), | 21 : owner_(owner), |
| 21 observer_(NULL), | 22 observer_(NULL), |
| 22 menu_button_(menu_button), | 23 menu_button_(menu_button), |
| 23 views_(&views), | 24 views_(&views), |
| 24 start_index_(start_index), | 25 start_index_(start_index), |
| 25 for_drop_(false) { | 26 for_drop_(false) { |
| 26 menu_.reset(new views::MenuItemView(this)); | 27 menu_.reset(new views::MenuItemView(this)); |
| 27 menu_->set_has_icons(true); | 28 menu_->set_has_icons(true); |
| 28 | 29 |
| 29 TabContents* tab = BrowserList::GetLastActive()->GetSelectedTabContents(); | |
| 30 int tab_id = tab->controller().session_id().id(); | |
| 31 | |
| 32 size_t command_id = 0; | 30 size_t command_id = 0; |
| 33 for (size_t i = start_index; i < views_->size(); ++i) { | 31 for (size_t i = start_index; i < views_->size(); ++i) { |
| 34 BrowserActionView* view = (*views_)[i]; | 32 BrowserActionView* view = (*views_)[i]; |
| 35 SkBitmap icon = | 33 scoped_ptr<gfx::Canvas> canvas(view->GetIconWithBadge()); |
| 36 view->button()->extension()->browser_action()->GetIcon(tab_id); | |
| 37 if (icon.isNull()) | |
| 38 icon = view->button()->default_icon(); | |
| 39 menu_->AppendMenuItemWithIcon( | 34 menu_->AppendMenuItemWithIcon( |
| 40 command_id, | 35 command_id, |
| 41 UTF8ToWide(view->button()->extension()->name()), | 36 UTF8ToWide(view->button()->extension()->name()), |
| 42 icon); | 37 canvas->ExtractBitmap()); |
| 43 ++command_id; | 38 ++command_id; |
| 44 } | 39 } |
| 45 } | 40 } |
| 46 | 41 |
| 47 BrowserActionOverflowMenuController::~BrowserActionOverflowMenuController() { | 42 BrowserActionOverflowMenuController::~BrowserActionOverflowMenuController() { |
| 48 if (observer_) | 43 if (observer_) |
| 49 observer_->NotifyMenuDeleted(this); | 44 observer_->NotifyMenuDeleted(this); |
| 50 } | 45 } |
| 51 | 46 |
| 52 bool BrowserActionOverflowMenuController::RunMenu(gfx::NativeWindow window, | 47 bool BrowserActionOverflowMenuController::RunMenu(gfx::NativeWindow window, |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 184 |
| 190 BrowserActionView* BrowserActionOverflowMenuController::ViewForId( | 185 BrowserActionView* BrowserActionOverflowMenuController::ViewForId( |
| 191 int id, size_t* index) { | 186 int id, size_t* index) { |
| 192 // The index of the view being dragged (GetCommand gives a 0-based index into | 187 // The index of the view being dragged (GetCommand gives a 0-based index into |
| 193 // the overflow menu). | 188 // the overflow menu). |
| 194 size_t view_index = owner_->VisibleBrowserActions() + id; | 189 size_t view_index = owner_->VisibleBrowserActions() + id; |
| 195 if (index) | 190 if (index) |
| 196 *index = view_index; | 191 *index = view_index; |
| 197 return owner_->GetBrowserActionViewAt(view_index); | 192 return owner_->GetBrowserActionViewAt(view_index); |
| 198 } | 193 } |
| OLD | NEW |