| 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 "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/browser_list.h" | 8 #include "chrome/browser/browser_list.h" |
| 9 #include "chrome/browser/extensions/extension_context_menu_model.h" | 9 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
| 11 #include "chrome/browser/tab_contents/tab_contents.h" | 11 #include "chrome/browser/tab_contents/tab_contents.h" |
| 12 #include "chrome/browser/views/browser_actions_container.h" | 12 #include "chrome/browser/views/browser_actions_container.h" |
| 13 #include "chrome/browser/views/extensions/browser_action_drag_data.h" | 13 #include "chrome/browser/views/extensions/browser_action_drag_data.h" |
| 14 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 15 #include "chrome/common/extensions/extension_action.h" | 15 #include "chrome/common/extensions/extension_action.h" |
| 16 #include "gfx/canvas_skia.h" | 16 #include "gfx/canvas.h" |
| 17 #include "views/controls/menu/menu_item_view.h" | 17 #include "views/controls/menu/menu_item_view.h" |
| 18 #include "views/controls/menu/menu_2.h" | 18 #include "views/controls/menu/menu_2.h" |
| 19 | 19 |
| 20 BrowserActionOverflowMenuController::BrowserActionOverflowMenuController( | 20 BrowserActionOverflowMenuController::BrowserActionOverflowMenuController( |
| 21 BrowserActionsContainer* owner, | 21 BrowserActionsContainer* owner, |
| 22 views::MenuButton* menu_button, | 22 views::MenuButton* menu_button, |
| 23 const std::vector<BrowserActionView*>& views, | 23 const std::vector<BrowserActionView*>& views, |
| 24 int start_index) | 24 int start_index) |
| 25 : owner_(owner), | 25 : owner_(owner), |
| 26 observer_(NULL), | 26 observer_(NULL), |
| 27 menu_button_(menu_button), | 27 menu_button_(menu_button), |
| 28 views_(&views), | 28 views_(&views), |
| 29 start_index_(start_index), | 29 start_index_(start_index), |
| 30 for_drop_(false) { | 30 for_drop_(false) { |
| 31 menu_.reset(new views::MenuItemView(this)); | 31 menu_.reset(new views::MenuItemView(this)); |
| 32 menu_->set_has_icons(true); | 32 menu_->set_has_icons(true); |
| 33 | 33 |
| 34 size_t command_id = 1; // Menu id 0 is reserved, start with 1. | 34 size_t command_id = 1; // Menu id 0 is reserved, start with 1. |
| 35 for (size_t i = start_index; i < views_->size(); ++i) { | 35 for (size_t i = start_index; i < views_->size(); ++i) { |
| 36 BrowserActionView* view = (*views_)[i]; | 36 BrowserActionView* view = (*views_)[i]; |
| 37 scoped_ptr<gfx::Canvas> canvas(view->GetIconWithBadge()); | 37 scoped_ptr<gfx::CanvasSkia> canvas(view->GetIconWithBadge()); |
| 38 menu_->AppendMenuItemWithIcon( | 38 menu_->AppendMenuItemWithIcon( |
| 39 command_id, | 39 command_id, |
| 40 UTF8ToWide(view->button()->extension()->name()), | 40 UTF8ToWide(view->button()->extension()->name()), |
| 41 canvas->AsCanvasSkia()->ExtractBitmap()); | 41 canvas->ExtractBitmap()); |
| 42 | 42 |
| 43 // Set the tooltip for this item. | 43 // Set the tooltip for this item. |
| 44 std::wstring tooltip = UTF8ToWide( | 44 std::wstring tooltip = UTF8ToWide( |
| 45 view->button()->extension()->browser_action()->GetTitle( | 45 view->button()->extension()->browser_action()->GetTitle( |
| 46 owner_->GetCurrentTabId())); | 46 owner_->GetCurrentTabId())); |
| 47 menu_->SetTooltip(tooltip, command_id); | 47 menu_->SetTooltip(tooltip, command_id); |
| 48 | 48 |
| 49 ++command_id; | 49 ++command_id; |
| 50 } | 50 } |
| 51 } | 51 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 200 |
| 201 BrowserActionView* BrowserActionOverflowMenuController::ViewForId( | 201 BrowserActionView* BrowserActionOverflowMenuController::ViewForId( |
| 202 int id, size_t* index) { | 202 int id, size_t* index) { |
| 203 // The index of the view being dragged (GetCommand gives a 1-based index into | 203 // The index of the view being dragged (GetCommand gives a 1-based index into |
| 204 // the overflow menu). | 204 // the overflow menu). |
| 205 size_t view_index = owner_->VisibleBrowserActions() + id - 1; | 205 size_t view_index = owner_->VisibleBrowserActions() + id - 1; |
| 206 if (index) | 206 if (index) |
| 207 *index = view_index; | 207 *index = view_index; |
| 208 return owner_->GetBrowserActionViewAt(view_index); | 208 return owner_->GetBrowserActionViewAt(view_index); |
| 209 } | 209 } |
| OLD | NEW |