Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: chrome/browser/views/bookmark_bar_view.cc

Issue 197031: Fleshes out the tooltip implementation for views on Gtk. It doesn't... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/views/toolbar_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/bookmark_bar_view.h" 5 #include "chrome/browser/views/bookmark_bar_view.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "app/gfx/canvas.h" 9 #include "app/gfx/canvas.h"
10 #include "app/gfx/text_elider.h" 10 #include "app/gfx/text_elider.h"
(...skipping 25 matching lines...) Expand all
36 #include "grit/theme_resources.h" 36 #include "grit/theme_resources.h"
37 #include "skia/ext/skia_utils.h" 37 #include "skia/ext/skia_utils.h"
38 #include "views/controls/button/menu_button.h" 38 #include "views/controls/button/menu_button.h"
39 #include "views/controls/menu/menu_item_view.h" 39 #include "views/controls/menu/menu_item_view.h"
40 #include "views/drag_utils.h" 40 #include "views/drag_utils.h"
41 #include "views/view_constants.h" 41 #include "views/view_constants.h"
42 #include "views/widget/tooltip_manager.h" 42 #include "views/widget/tooltip_manager.h"
43 #include "views/widget/widget.h" 43 #include "views/widget/widget.h"
44 #include "views/window/window.h" 44 #include "views/window/window.h"
45 45
46 #if defined(OS_WIN)
47 #include "app/win_util.h"
48 #include "base/base_drag_source.h"
49 #endif
50
51 using views::CustomButton; 46 using views::CustomButton;
52 using views::DropTargetEvent; 47 using views::DropTargetEvent;
53 using views::MenuButton; 48 using views::MenuButton;
54 using views::MenuItemView; 49 using views::MenuItemView;
55 using views::View; 50 using views::View;
56 51
57 // How much we want the bookmark bar to overlap the toolbar when in its 52 // How much we want the bookmark bar to overlap the toolbar when in its
58 // 'always shown' mode. 53 // 'always shown' mode.
59 static const double kToolbarOverlap = 4.0; 54 static const double kToolbarOverlap = 4.0;
60 55
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 129
135 // Returns the tooltip text for the specified url and title. The returned 130 // Returns the tooltip text for the specified url and title. The returned
136 // text is clipped to fit within the bounds of the monitor. 131 // text is clipped to fit within the bounds of the monitor.
137 // 132 //
138 // Note that we adjust the direction of both the URL and the title based on the 133 // Note that we adjust the direction of both the URL and the title based on the
139 // locale so that pure LTR strings are displayed properly in RTL locales. 134 // locale so that pure LTR strings are displayed properly in RTL locales.
140 static std::wstring CreateToolTipForURLAndTitle(const gfx::Point& screen_loc, 135 static std::wstring CreateToolTipForURLAndTitle(const gfx::Point& screen_loc,
141 const GURL& url, 136 const GURL& url,
142 const std::wstring& title, 137 const std::wstring& title,
143 const std::wstring& languages) { 138 const std::wstring& languages) {
144 #if defined(OS_WIN) 139 int max_width = views::TooltipManager::GetMaxWidth(screen_loc.x(),
145 gfx::Rect monitor_bounds = win_util::GetMonitorBoundsForRect( 140 screen_loc.y());
146 gfx::Rect(screen_loc.x(), screen_loc.y(), 1, 1));
147 #else
148 gfx::Rect monitor_bounds(0, 0, 10000, 10000);
149 NOTIMPLEMENTED();
150 #endif
151 gfx::Font tt_font = views::TooltipManager::GetDefaultFont(); 141 gfx::Font tt_font = views::TooltipManager::GetDefaultFont();
152 std::wstring result; 142 std::wstring result;
153 143
154 // First the title. 144 // First the title.
155 if (!title.empty()) { 145 if (!title.empty()) {
156 std::wstring localized_title; 146 std::wstring localized_title;
157 if (l10n_util::AdjustStringForLocaleDirection(title, &localized_title)) 147 if (l10n_util::AdjustStringForLocaleDirection(title, &localized_title))
158 result.append(gfx::ElideText(localized_title, 148 result.append(gfx::ElideText(localized_title, tt_font, max_width));
159 tt_font,
160 monitor_bounds.width()));
161 else 149 else
162 result.append(gfx::ElideText(title, tt_font, monitor_bounds.width())); 150 result.append(gfx::ElideText(title, tt_font, max_width));
163 } 151 }
164 152
165 // Only show the URL if the url and title differ. 153 // Only show the URL if the url and title differ.
166 if (title != UTF8ToWide(url.spec())) { 154 if (title != UTF8ToWide(url.spec())) {
167 if (!result.empty()) 155 if (!result.empty())
168 result.append(views::TooltipManager::GetLineSeparator()); 156 result.append(views::TooltipManager::GetLineSeparator());
169 157
170 // We need to explicitly specify the directionality of the URL's text to 158 // We need to explicitly specify the directionality of the URL's text to
171 // make sure it is treated as an LTR string when the context is RTL. For 159 // make sure it is treated as an LTR string when the context is RTL. For
172 // example, the URL "http://www.yahoo.com/" appears as 160 // example, the URL "http://www.yahoo.com/" appears as
173 // "/http://www.yahoo.com" when rendered, as is, in an RTL context since 161 // "/http://www.yahoo.com" when rendered, as is, in an RTL context since
174 // the Unicode BiDi algorithm puts certain characters on the left by 162 // the Unicode BiDi algorithm puts certain characters on the left by
175 // default. 163 // default.
176 std::wstring elided_url(gfx::ElideUrl(url, 164 std::wstring elided_url(gfx::ElideUrl(url, tt_font, max_width, languages));
177 tt_font,
178 monitor_bounds.width(),
179 languages));
180 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) 165 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
181 l10n_util::WrapStringWithLTRFormatting(&elided_url); 166 l10n_util::WrapStringWithLTRFormatting(&elided_url);
182 result.append(elided_url); 167 result.append(elided_url);
183 } 168 }
184 return result; 169 return result;
185 } 170 }
186 171
187 // BookmarkButton ------------------------------------------------------------- 172 // BookmarkButton -------------------------------------------------------------
188 173
189 // Buttons used for the bookmarks on the bookmark bar. 174 // Buttons used for the bookmarks on the bookmark bar.
(...skipping 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 sync_error_button->SetTooltipText( 1709 sync_error_button->SetTooltipText(
1725 l10n_util::GetString(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC)); 1710 l10n_util::GetString(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC));
1726 sync_error_button->SetAccessibleName( 1711 sync_error_button->SetAccessibleName(
1727 l10n_util::GetString(IDS_ACCNAME_SYNC_ERROR_BUTTON)); 1712 l10n_util::GetString(IDS_ACCNAME_SYNC_ERROR_BUTTON));
1728 sync_error_button->SetIcon( 1713 sync_error_button->SetIcon(
1729 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); 1714 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING));
1730 return sync_error_button; 1715 return sync_error_button;
1731 } 1716 }
1732 #endif 1717 #endif
1733 1718
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/views/toolbar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698