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

Side by Side Diff: ui/aura_shell/shell_tooltip_manager.cc

Issue 8888037: Windows component build fix for aura. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: addressed comments Created 9 years 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
« no previous file with comments | « ui/aura/root_window.cc ('k') | ui/views/test/test_tooltip_client.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ui/aura_shell/shell_tooltip_manager.h" 5 #include "ui/aura_shell/shell_tooltip_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 30 matching lines...) Expand all
41 // FIXME: get cursor offset from actual cursor size. 41 // FIXME: get cursor offset from actual cursor size.
42 const int kCursorOffsetX = 10; 42 const int kCursorOffsetX = 10;
43 const int kCursorOffsetY = 15; 43 const int kCursorOffsetY = 15;
44 44
45 // Maximum number of characters we allow in a tooltip. 45 // Maximum number of characters we allow in a tooltip.
46 const size_t kMaxTooltipLength = 1024; 46 const size_t kMaxTooltipLength = 1024;
47 47
48 // Maximum number of lines we allow in the tooltip. 48 // Maximum number of lines we allow in the tooltip.
49 const size_t kMaxLines = 6; 49 const size_t kMaxLines = 6;
50 50
51 gfx::Font GetDefaultFont() {
52 // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure
53 // out a way to merge.
54 return ui::ResourceBundle::GetSharedInstance().GetFont(
55 ui::ResourceBundle::BaseFont);
56 }
57
58 int GetMaxWidth(int x, int y) {
59 // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure
60 // out a way to merge.
61 gfx::Rect monitor_bounds =
62 gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
63 return (monitor_bounds.width() + 1) / 2;
64 }
65
51 // Trims the tooltip to fit, setting |text| to the clipped result, 66 // Trims the tooltip to fit, setting |text| to the clipped result,
52 // |max_width| to the width (in pixels) of the clipped text and |line_count| 67 // |max_width| to the width (in pixels) of the clipped text and |line_count|
53 // to the number of lines of text in the tooltip. |x| and |y| give the 68 // to the number of lines of text in the tooltip. |x| and |y| give the
54 // location of the tooltip in screen coordinates. 69 // location of the tooltip in screen coordinates.
55 void TrimTooltipToFit(string16* text, 70 void TrimTooltipToFit(string16* text,
56 int* max_width, 71 int* max_width,
57 int* line_count, 72 int* line_count,
58 int x, 73 int x,
59 int y) { 74 int y) {
60 *max_width = 0; 75 *max_width = 0;
61 *line_count = 0; 76 *line_count = 0;
62 77
63 // Clamp the tooltip length to kMaxTooltipLength so that we don't 78 // Clamp the tooltip length to kMaxTooltipLength so that we don't
64 // accidentally DOS the user with a mega tooltip. 79 // accidentally DOS the user with a mega tooltip.
65 if (text->length() > kMaxTooltipLength) 80 if (text->length() > kMaxTooltipLength)
66 *text = text->substr(0, kMaxTooltipLength); 81 *text = text->substr(0, kMaxTooltipLength);
67 82
68 // Determine the available width for the tooltip. 83 // Determine the available width for the tooltip.
69 int available_width = aura::TooltipClient::GetMaxWidth(x, y); 84 int available_width = GetMaxWidth(x, y);
70 85
71 // Split the string into at most kMaxLines lines. 86 // Split the string into at most kMaxLines lines.
72 std::vector<string16> lines; 87 std::vector<string16> lines;
73 base::SplitString(*text, '\n', &lines); 88 base::SplitString(*text, '\n', &lines);
74 if (lines.size() > kMaxLines) 89 if (lines.size() > kMaxLines)
75 lines.resize(kMaxLines); 90 lines.resize(kMaxLines);
76 *line_count = static_cast<int>(lines.size()); 91 *line_count = static_cast<int>(lines.size());
77 92
78 // Format each line to fit. 93 // Format each line to fit.
79 gfx::Font font = aura::TooltipClient::GetDefaultFont(); 94 gfx::Font font = GetDefaultFont();
80 string16 result; 95 string16 result;
81 for (std::vector<string16>::iterator i = lines.begin(); i != lines.end(); 96 for (std::vector<string16>::iterator i = lines.begin(); i != lines.end();
82 ++i) { 97 ++i) {
83 string16 elided_text = ui::ElideText(*i, font, available_width, false); 98 string16 elided_text = ui::ElideText(*i, font, available_width, false);
84 *max_width = std::max(*max_width, font.GetStringWidth(elided_text)); 99 *max_width = std::max(*max_width, font.GetStringWidth(elided_text));
85 if (!result.empty()) 100 if (!result.empty())
86 result.push_back('\n'); 101 result.push_back('\n');
87 result.append(elided_text); 102 result.append(elided_text);
88 } 103 }
89 *text = result; 104 *text = result;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 string16 tooltip_text(tooltip_text_); 287 string16 tooltip_text(tooltip_text_);
273 gfx::Point widget_loc = curr_mouse_loc_; 288 gfx::Point widget_loc = curr_mouse_loc_;
274 widget_loc = widget_loc.Add(tooltip_window_->GetScreenBounds().origin()); 289 widget_loc = widget_loc.Add(tooltip_window_->GetScreenBounds().origin());
275 tooltip_->SetText(tooltip_text, widget_loc); 290 tooltip_->SetText(tooltip_text, widget_loc);
276 tooltip_->Show(); 291 tooltip_->Show();
277 } 292 }
278 } 293 }
279 } 294 }
280 295
281 } // namespace aura_shell 296 } // namespace aura_shell
282
283 namespace aura {
284
285 // static
286 gfx::Font TooltipClient::GetDefaultFont() {
287 return ui::ResourceBundle::GetSharedInstance().GetFont(
288 ui::ResourceBundle::BaseFont);
289 }
290
291 // static
292 int TooltipClient::GetMaxWidth(int x, int y) {
293 gfx::Rect monitor_bounds =
294 gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
295 return (monitor_bounds.width() + 1) / 2;
296 }
297
298 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/root_window.cc ('k') | ui/views/test/test_tooltip_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698