summaryrefslogtreecommitdiffstats
path: root/views/widget
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-01 22:44:36 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-01 22:44:36 +0000
commitd3d10af39b1e2f500474393db5479a492b985a4e (patch)
tree434df9224d4a8c55c4fd9d7cd515ed9e6153188d /views/widget
parent11c9ec9fd6f8f50c43f485b5ecb79a133b591bc8 (diff)
downloadchromium_src-d3d10af39b1e2f500474393db5479a492b985a4e.zip
chromium_src-d3d10af39b1e2f500474393db5479a492b985a4e.tar.gz
chromium_src-d3d10af39b1e2f500474393db5479a492b985a4e.tar.bz2
Fixes bug in views/gtk tooltips. Gtk wraps text in labels at
(screen_size + 1) / 2. I'm setting the max width of tooltips to match this else gtk can calculate more vertical white space than it ends up using. Simiarly when resetting the text in a label gtk doesn't reset wrap position. I'm forcing that by invoking set_max_width_chars. BUG=none TEST=none Review URL: http://codereview.chromium.org/454023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33494 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r--views/widget/tooltip_manager.cc11
-rw-r--r--views/widget/tooltip_manager_gtk.cc32
-rw-r--r--views/widget/tooltip_manager_win.cc11
3 files changed, 40 insertions, 14 deletions
diff --git a/views/widget/tooltip_manager.cc b/views/widget/tooltip_manager.cc
index 65f4cbc..32ac506 100644
--- a/views/widget/tooltip_manager.cc
+++ b/views/widget/tooltip_manager.cc
@@ -7,7 +7,6 @@
#include <vector>
#include "app/gfx/text_elider.h"
-#include "views/screen.h"
namespace views {
@@ -32,16 +31,6 @@ static void SplitTooltipString(const std::wstring& text,
}
// static
-int TooltipManager::GetMaxWidth(int x, int y) {
- gfx::Rect monitor_bounds =
- Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
- // Allow the tooltip to be almost as wide as the screen.
- // Otherwise, we would truncate important text, since we're not word-wrapping
- // the text onto multiple lines.
- return monitor_bounds.width() == 0 ? 800 : monitor_bounds.width() - 30;
-}
-
-// static
void TooltipManager::TrimTooltipToFit(std::wstring* text,
int* max_width,
int* line_count,
diff --git a/views/widget/tooltip_manager_gtk.cc b/views/widget/tooltip_manager_gtk.cc
index b1fae39..b425356 100644
--- a/views/widget/tooltip_manager_gtk.cc
+++ b/views/widget/tooltip_manager_gtk.cc
@@ -8,6 +8,8 @@
#include "base/logging.h"
#include "base/string_util.h"
#include "views/focus/focus_manager.h"
+#include "views/focus/focus_manager.h"
+#include "views/screen.h"
#include "views/widget/root_view.h"
#include "views/widget/widget_gtk.h"
@@ -60,6 +62,16 @@ const std::wstring& TooltipManager::GetLineSeparator() {
return *line_separator;
}
+// static
+int TooltipManager::GetMaxWidth(int x, int y) {
+ gfx::Rect monitor_bounds =
+ Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
+ // GtkLabel (gtk_label_ensure_layout) forces wrapping at this size. We mirror
+ // the size here otherwise tooltips wider than the size used by gtklabel end
+ // up with extraneous empty lines.
+ return monitor_bounds.width() == 0 ? 800 : (monitor_bounds.width() + 1) / 2;
+}
+
// Callback from gtk_container_foreach. If |*label_p| is NULL and |widget| is
// a GtkLabel, |*label_p| is set to |widget|. Used to find the first GtkLabel
// in a container.
@@ -77,15 +89,25 @@ static void LabelLocatorCallback(GtkWidget* widget,
// triggers continually hiding/showing the widget in that case.
static void AdjustLabel(GtkTooltip* tooltip) {
static const char kAdjustedLabelPropertyValue[] = "_adjusted_label_";
+ static const char kTooltipLabel[] = "_tooltip_label_";
gpointer adjusted_value = g_object_get_data(G_OBJECT(tooltip),
kAdjustedLabelPropertyValue);
- if (adjusted_value)
+ if (adjusted_value) {
+ gpointer label_ptr = g_object_get_data(G_OBJECT(tooltip), kTooltipLabel);
+ if (label_ptr) {
+ // Setting the text in a label doesn't force recalculating wrap position.
+ // We force recalculating wrap position by resetting the max width.
+ gtk_label_set_max_width_chars(reinterpret_cast<GtkLabel*>(label_ptr),
+ 2999);
+ gtk_label_set_max_width_chars(reinterpret_cast<GtkLabel*>(label_ptr),
+ 3000);
+ }
return;
+ }
adjusted_value = reinterpret_cast<gpointer>(1);
g_object_set_data(G_OBJECT(tooltip), kAdjustedLabelPropertyValue,
adjusted_value);
-
GtkWidget* parent;
{
// Create a label so that we can get the parent. The Tooltip ends up taking
@@ -101,8 +123,11 @@ static void AdjustLabel(GtkTooltip* tooltip) {
GtkLabel* real_label = NULL;
gtk_container_foreach(GTK_CONTAINER(parent), LabelLocatorCallback,
static_cast<gpointer>(&real_label));
- if (real_label)
+ if (real_label) {
gtk_label_set_max_width_chars(GTK_LABEL(real_label), 3000);
+ g_object_set_data(G_OBJECT(tooltip), kTooltipLabel,
+ reinterpret_cast<gpointer>(real_label));
+ }
}
}
@@ -157,6 +182,7 @@ bool TooltipManagerGtk::ShowTooltip(int x, int y, bool for_keyboard,
screen_loc.y());
gtk_tooltip_set_text(tooltip, WideToUTF8(text).c_str());
+
return true;
}
diff --git a/views/widget/tooltip_manager_win.cc b/views/widget/tooltip_manager_win.cc
index fed6c02..cee8248 100644
--- a/views/widget/tooltip_manager_win.cc
+++ b/views/widget/tooltip_manager_win.cc
@@ -13,6 +13,7 @@
#include "app/win_util.h"
#include "base/logging.h"
#include "base/message_loop.h"
+#include "views/screen.h"
#include "views/view.h"
#include "views/widget/root_view.h"
#include "views/widget/widget.h"
@@ -57,6 +58,16 @@ const std::wstring& TooltipManager::GetLineSeparator() {
return *separator;
}
+// static
+int TooltipManager::GetMaxWidth(int x, int y) {
+ gfx::Rect monitor_bounds =
+ Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
+ // Allow the tooltip to be almost as wide as the screen.
+ // Otherwise, we would truncate important text, since we're not word-wrapping
+ // the text onto multiple lines.
+ return monitor_bounds.width() == 0 ? 800 : monitor_bounds.width() - 30;
+}
+
TooltipManagerWin::TooltipManagerWin(Widget* widget)
: widget_(widget),
last_mouse_x_(-1),