summaryrefslogtreecommitdiffstats
path: root/ui/views/widget/tooltip_manager.cc
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-21 17:18:14 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-21 17:18:14 +0000
commitd57afa518d4ad5192b5a2d0f7227b2ddebd21ab9 (patch)
tree0f26ebcbcb4708db3b4520ba46929bc6a3727d1d /ui/views/widget/tooltip_manager.cc
parentc999f81499325506e3be3e373b1637bc3d71e85e (diff)
downloadchromium_src-d57afa518d4ad5192b5a2d0f7227b2ddebd21ab9.zip
chromium_src-d57afa518d4ad5192b5a2d0f7227b2ddebd21ab9.tar.gz
chromium_src-d57afa518d4ad5192b5a2d0f7227b2ddebd21ab9.tar.bz2
views: Move widget/ directory to ui/views.
BUG=104039 R=ben@chromium.org Review URL: http://codereview.chromium.org/8598031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110949 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/widget/tooltip_manager.cc')
-rw-r--r--ui/views/widget/tooltip_manager.cc63
1 files changed, 63 insertions, 0 deletions
diff --git a/ui/views/widget/tooltip_manager.cc b/ui/views/widget/tooltip_manager.cc
new file mode 100644
index 0000000..7f4d193
--- /dev/null
+++ b/ui/views/widget/tooltip_manager.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2011 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.
+
+#include "ui/views/widget/tooltip_manager.h"
+
+#include <vector>
+
+#include "base/string_split.h"
+#include "base/utf_string_conversions.h"
+#include "ui/base/text/text_elider.h"
+
+namespace {
+
+// Maximum number of characters we allow in a tooltip.
+const size_t kMaxTooltipLength = 1024;
+
+// Maximum number of lines we allow in the tooltip.
+const size_t kMaxLines = 6;
+
+} // namespace
+
+namespace views {
+
+// static
+void TooltipManager::TrimTooltipToFit(string16* text,
+ int* max_width,
+ int* line_count,
+ int x,
+ int y) {
+ *max_width = 0;
+ *line_count = 0;
+
+ // Clamp the tooltip length to kMaxTooltipLength so that we don't
+ // accidentally DOS the user with a mega tooltip.
+ if (text->length() > kMaxTooltipLength)
+ *text = text->substr(0, kMaxTooltipLength);
+
+ // Determine the available width for the tooltip.
+ int available_width = GetMaxWidth(x, y);
+
+ // Split the string into at most kMaxLines lines.
+ std::vector<string16> lines;
+ base::SplitString(*text, '\n', &lines);
+ if (lines.size() > kMaxLines)
+ lines.resize(kMaxLines);
+ *line_count = static_cast<int>(lines.size());
+
+ // Format each line to fit.
+ gfx::Font font = GetDefaultFont();
+ string16 result;
+ for (std::vector<string16>::iterator i = lines.begin(); i != lines.end();
+ ++i) {
+ string16 elided_text = ui::ElideText(*i, font, available_width, false);
+ *max_width = std::max(*max_width, font.GetStringWidth(elided_text));
+ if (!result.empty())
+ result.push_back('\n');
+ result.append(elided_text);
+ }
+ *text = result;
+}
+
+} // namespace views