summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/ui/views/bookmark_bar_view.cc83
-rw-r--r--chrome/browser/ui/views/bookmark_bar_view.h11
-rw-r--r--chrome/browser/ui/views/bookmark_menu_controller_views.cc9
-rw-r--r--chrome/browser/ui/views/bookmark_menu_controller_views.h1
-rw-r--r--views/controls/menu/menu_delegate.h6
-rw-r--r--views/controls/menu/menu_item_view.cc11
6 files changed, 78 insertions, 43 deletions
diff --git a/chrome/browser/ui/views/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmark_bar_view.cc
index 5e76410..05b3dc3 100644
--- a/chrome/browser/ui/views/bookmark_bar_view.cc
+++ b/chrome/browser/ui/views/bookmark_bar_view.cc
@@ -126,46 +126,6 @@ static const int kSyncErrorButtonTag = 2;
namespace {
-// Returns the tooltip text for the specified url and title. The returned
-// text is clipped to fit within the bounds of the monitor.
-//
-// Note that we adjust the direction of both the URL and the title based on the
-// locale so that pure LTR strings are displayed properly in RTL locales.
-static std::wstring CreateToolTipForURLAndTitle(const gfx::Point& screen_loc,
- const GURL& url,
- const std::wstring& title,
- const std::wstring& languages) {
- int max_width = views::TooltipManager::GetMaxWidth(screen_loc.x(),
- screen_loc.y());
- gfx::Font tt_font = views::TooltipManager::GetDefaultFont();
- std::wstring result;
-
- // First the title.
- if (!title.empty()) {
- std::wstring localized_title = title;
- base::i18n::AdjustStringForLocaleDirection(&localized_title);
- result.append(UTF16ToWideHack(ui::ElideText(WideToUTF16Hack(
- localized_title), tt_font, max_width, false)));
- }
-
- // Only show the URL if the url and title differ.
- if (title != UTF8ToWide(url.spec())) {
- if (!result.empty())
- result.append(views::TooltipManager::GetLineSeparator());
-
- // We need to explicitly specify the directionality of the URL's text to
- // make sure it is treated as an LTR string when the context is RTL. For
- // example, the URL "http://www.yahoo.com/" appears as
- // "/http://www.yahoo.com" when rendered, as is, in an RTL context since
- // the Unicode BiDi algorithm puts certain characters on the left by
- // default.
- string16 elided_url(ui::ElideUrl(url, tt_font, max_width, languages));
- elided_url = base::i18n::GetDisplayStringInLTRDirectionality(elided_url);
- result.append(UTF16ToWideHack(elided_url));
- }
- return result;
-}
-
// BookmarkButton -------------------------------------------------------------
// Buttons used for the bookmarks on the bookmark bar.
@@ -192,8 +152,8 @@ class BookmarkButton : public views::TextButton {
bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip) {
gfx::Point location(p);
ConvertPointToScreen(this, &location);
- *tooltip = CreateToolTipForURLAndTitle(location, url_, text(),
- UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)));
+ *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle(location, url_,
+ text(), profile_);
return !tooltip->empty();
}
@@ -1582,6 +1542,45 @@ void BookmarkBarView::StopThrobbing(bool immediate) {
throbbing_view_ = NULL;
}
+// static
+std::wstring BookmarkBarView::CreateToolTipForURLAndTitle(
+ const gfx::Point& screen_loc,
+ const GURL& url,
+ const std::wstring& title,
+ Profile* profile) {
+ int max_width = views::TooltipManager::GetMaxWidth(screen_loc.x(),
+ screen_loc.y());
+ gfx::Font tt_font = views::TooltipManager::GetDefaultFont();
+ std::wstring result;
+
+ // First the title.
+ if (!title.empty()) {
+ std::wstring localized_title = title;
+ base::i18n::AdjustStringForLocaleDirection(&localized_title);
+ result.append(UTF16ToWideHack(ui::ElideText(WideToUTF16Hack(
+ localized_title), tt_font, max_width, false)));
+ }
+
+ // Only show the URL if the url and title differ.
+ if (title != UTF8ToWide(url.spec())) {
+ if (!result.empty())
+ result.append(views::TooltipManager::GetLineSeparator());
+
+ // We need to explicitly specify the directionality of the URL's text to
+ // make sure it is treated as an LTR string when the context is RTL. For
+ // example, the URL "http://www.yahoo.com/" appears as
+ // "/http://www.yahoo.com" when rendered, as is, in an RTL context since
+ // the Unicode BiDi algorithm puts certain characters on the left by
+ // default.
+ std::wstring languages =
+ UTF8ToWide(profile->GetPrefs()->GetString(prefs::kAcceptLanguages));
+ string16 elided_url(ui::ElideUrl(url, tt_font, max_width, languages));
+ elided_url = base::i18n::GetDisplayStringInLTRDirectionality(elided_url);
+ result.append(UTF16ToWideHack(elided_url));
+ }
+ return result;
+}
+
void BookmarkBarView::UpdateColors() {
// We don't always have a theme provider (ui tests, for example).
const ui::ThemeProvider* theme_provider = GetThemeProvider();
diff --git a/chrome/browser/ui/views/bookmark_bar_view.h b/chrome/browser/ui/views/bookmark_bar_view.h
index c02ed48..aa5c031 100644
--- a/chrome/browser/ui/views/bookmark_bar_view.h
+++ b/chrome/browser/ui/views/bookmark_bar_view.h
@@ -241,6 +241,17 @@ class BookmarkBarView : public DetachableToolbarView,
// bookmark bar model has.
int GetBookmarkButtonCount();
+ // Returns the tooltip text for the specified url and title. The returned
+ // text is clipped to fit within the bounds of the monitor.
+ //
+ // Note that we adjust the direction of both the URL and the title based on
+ // the locale so that pure LTR strings are displayed properly in RTL locales.
+ static std::wstring CreateToolTipForURLAndTitle(
+ const gfx::Point& screen_loc,
+ const GURL& url,
+ const std::wstring& title,
+ Profile* profile);
+
// If true we're running tests. This short circuits a couple of animations.
static bool testing_;
diff --git a/chrome/browser/ui/views/bookmark_menu_controller_views.cc b/chrome/browser/ui/views/bookmark_menu_controller_views.cc
index a114a8b..61af8fa 100644
--- a/chrome/browser/ui/views/bookmark_menu_controller_views.cc
+++ b/chrome/browser/ui/views/bookmark_menu_controller_views.cc
@@ -85,6 +85,15 @@ void BookmarkMenuController::Cancel() {
menu_->Cancel();
}
+std::wstring BookmarkMenuController::GetTooltipText(
+ int id, const gfx::Point& screen_loc) {
+ DCHECK(menu_id_to_node_map_.find(id) != menu_id_to_node_map_.end());
+
+ const BookmarkNode* node = menu_id_to_node_map_[id];
+ return BookmarkBarView::CreateToolTipForURLAndTitle(
+ screen_loc, node->GetURL(), UTF16ToWide(node->GetTitle()), profile_);
+}
+
bool BookmarkMenuController::IsTriggerableEvent(const views::MouseEvent& e) {
return event_utils::IsPossibleDispositionEvent(e);
}
diff --git a/chrome/browser/ui/views/bookmark_menu_controller_views.h b/chrome/browser/ui/views/bookmark_menu_controller_views.h
index 9efb847..861816f 100644
--- a/chrome/browser/ui/views/bookmark_menu_controller_views.h
+++ b/chrome/browser/ui/views/bookmark_menu_controller_views.h
@@ -85,6 +85,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver,
void set_observer(Observer* observer) { observer_ = observer; }
// MenuDelegate methods.
+ virtual std::wstring GetTooltipText(int id, const gfx::Point& p);
virtual bool IsTriggerableEvent(const views::MouseEvent& e);
virtual void ExecuteCommand(int id, int mouse_event_flags);
virtual bool GetDropFormats(
diff --git a/views/controls/menu/menu_delegate.h b/views/controls/menu/menu_delegate.h
index d0a42b3..d4f426f 100644
--- a/views/controls/menu/menu_delegate.h
+++ b/views/controls/menu/menu_delegate.h
@@ -58,6 +58,12 @@ class MenuDelegate : Controller {
return std::wstring();
}
+ // The tooltip shown for the menu item. This is invoked when the user
+ // hovers over the item, and no tooltip text has been set for that item.
+ virtual std::wstring GetTooltipText(int id, const gfx::Point& screen_loc) {
+ return std::wstring();
+ }
+
// If there is an accelerator for the menu item with id |id| it is set in
// |accelerator| and true is returned.
virtual bool GetAccelerator(int id, Accelerator* accelerator) {
diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc
index bbbc9b7..f555080 100644
--- a/views/controls/menu/menu_item_view.cc
+++ b/views/controls/menu/menu_item_view.cc
@@ -99,7 +99,16 @@ MenuItemView::~MenuItemView() {
bool MenuItemView::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) {
*tooltip = UTF16ToWideHack(tooltip_);
- return !tooltip_.empty();
+ if (!tooltip->empty())
+ return true;
+ if (GetType() != SEPARATOR) {
+ gfx::Point location(p);
+ ConvertPointToScreen(this, &location);
+ *tooltip = GetDelegate()->GetTooltipText(command_, location);
+ if (!tooltip->empty())
+ return true;
+ }
+ return false;
}
AccessibilityTypes::Role MenuItemView::GetAccessibleRole() {