diff options
-rw-r--r-- | chrome/browser/views/extensions/browser_action_overflow_menu_controller.cc | 17 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view.cc | 13 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view.h | 11 |
3 files changed, 34 insertions, 7 deletions
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 fb09339..85a233a 100644 --- a/chrome/browser/views/extensions/browser_action_overflow_menu_controller.cc +++ b/chrome/browser/views/extensions/browser_action_overflow_menu_controller.cc @@ -27,7 +27,7 @@ BrowserActionOverflowMenuController::BrowserActionOverflowMenuController( menu_.reset(new views::MenuItemView(this)); menu_->set_has_icons(true); - size_t command_id = 0; + size_t command_id = 1; // Menu id 0 is reserved, start with 1. for (size_t i = start_index; i < views_->size(); ++i) { BrowserActionView* view = (*views_)[i]; scoped_ptr<gfx::Canvas> canvas(view->GetIconWithBadge()); @@ -35,6 +35,13 @@ BrowserActionOverflowMenuController::BrowserActionOverflowMenuController( command_id, UTF8ToWide(view->button()->extension()->name()), canvas->ExtractBitmap()); + + // Set the tooltip for this item. + std::wstring tooltip = UTF8ToWide( + view->button()->extension()->browser_action()->GetTitle( + owner_->GetCurrentTabId())); + menu_->SetTooltip(tooltip, command_id); + ++command_id; } } @@ -72,7 +79,7 @@ void BrowserActionOverflowMenuController::CancelMenu() { } void BrowserActionOverflowMenuController::ExecuteCommand(int id) { - BrowserActionView* view = (*views_)[start_index_ + id]; + BrowserActionView* view = (*views_)[start_index_ + id - 1]; owner_->OnBrowserActionExecuted(view->button()); } @@ -80,7 +87,7 @@ bool BrowserActionOverflowMenuController::ShowContextMenu( views::MenuItemView* source, int id, int x, int y, bool is_mouse_gesture) { // This blocks until the user choses something or dismisses the menu. owner_->GetContextMenu()->Run( - (*views_)[start_index_ + id]->button()->extension(), + (*views_)[start_index_ + id - 1]->button()->extension(), gfx::Point(x, y)); // The user is done with the context menu, so we can close the underlying @@ -181,9 +188,9 @@ int BrowserActionOverflowMenuController::GetDragOperations( BrowserActionView* BrowserActionOverflowMenuController::ViewForId( int id, size_t* index) { - // The index of the view being dragged (GetCommand gives a 0-based index into + // The index of the view being dragged (GetCommand gives a 1-based index into // the overflow menu). - size_t view_index = owner_->VisibleBrowserActions() + id; + size_t view_index = owner_->VisibleBrowserActions() + id - 1; if (index) *index = view_index; return owner_->GetBrowserActionViewAt(view_index); diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc index 698502b..20ee28e 100644 --- a/views/controls/menu/menu_item_view.cc +++ b/views/controls/menu/menu_item_view.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -73,6 +73,11 @@ MenuItemView::~MenuItemView() { delete submenu_; } +bool MenuItemView::GetTooltipText(int x, int y, std::wstring* tooltip) { + *tooltip = tooltip_; + return !tooltip_.empty(); +} + void MenuItemView::RunMenuAt(gfx::NativeWindow parent, MenuButton* button, const gfx::Rect& bounds, @@ -164,6 +169,12 @@ void MenuItemView::SetSelected(bool selected) { SchedulePaint(); } +void MenuItemView::SetTooltip(const std::wstring& tooltip, int item_id) { + MenuItemView* item = GetMenuItemByID(item_id); + DCHECK(item); + item->tooltip_ = tooltip; +} + void MenuItemView::SetIcon(const SkBitmap& icon, int item_id) { MenuItemView* item = GetMenuItemByID(item_id); DCHECK(item); diff --git a/views/controls/menu/menu_item_view.h b/views/controls/menu/menu_item_view.h index 936ff1e..6caa09a 100644 --- a/views/controls/menu/menu_item_view.h +++ b/views/controls/menu/menu_item_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -71,6 +71,9 @@ class MenuItemView : public View { virtual ~MenuItemView(); + // Overridden from View: + virtual bool GetTooltipText(int x, int y, std::wstring* tooltip); + // Returns the preferred height of menu items. This is only valid when the // menu is about to be shown. static int pref_menu_height() { return pref_menu_height_; } @@ -178,6 +181,9 @@ class MenuItemView : public View { // Returns true if the item is selected. bool IsSelected() const { return selected_; } + // Sets the |tooltip| for a menu item view with |item_id| identifier. + void SetTooltip(const std::wstring& tooltip, int item_id); + // Sets the icon for the descendant identified by item_id. void SetIcon(const SkBitmap& icon, int item_id); @@ -321,6 +327,9 @@ class MenuItemView : public View { bool has_icons_; + // The tooltip to show on hover for this menu item. + std::wstring tooltip_; + // X-coordinate of where the label starts. static int label_start_; |