OLD | NEW |
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 "views/widget/tooltip_manager.h" | 5 #include "views/widget/tooltip_manager.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "app/gfx/text_elider.h" | 9 #include "app/gfx/text_elider.h" |
10 #include "views/screen.h" | 10 #include "views/screen.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 index = next_index + TooltipManager::GetLineSeparator().size(); | 28 index = next_index + TooltipManager::GetLineSeparator().size(); |
29 } | 29 } |
30 if (next_index != text.size() && lines->size() < kMaxLines) | 30 if (next_index != text.size() && lines->size() < kMaxLines) |
31 lines->push_back(text.substr(index, text.size() - index)); | 31 lines->push_back(text.substr(index, text.size() - index)); |
32 } | 32 } |
33 | 33 |
34 // static | 34 // static |
35 int TooltipManager::GetMaxWidth(int x, int y) { | 35 int TooltipManager::GetMaxWidth(int x, int y) { |
36 gfx::Rect monitor_bounds = | 36 gfx::Rect monitor_bounds = |
37 Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y)); | 37 Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y)); |
38 // We don't want the tooltip to get too big, otherwise it looks wrong. | 38 // Allow the tooltip to be almost as wide as the screen. |
39 return monitor_bounds.width() == 0 ? 400 : monitor_bounds.width() / 4; | 39 // Otherwise, we would truncate important text, since we're not word-wrapping |
| 40 // the text onto multiple lines. |
| 41 return monitor_bounds.width() == 0 ? 800 : monitor_bounds.width() - 30; |
40 } | 42 } |
41 | 43 |
42 // static | 44 // static |
43 void TooltipManager::TrimTooltipToFit(std::wstring* text, | 45 void TooltipManager::TrimTooltipToFit(std::wstring* text, |
44 int* max_width, | 46 int* max_width, |
45 int* line_count, | 47 int* line_count, |
46 int x, | 48 int x, |
47 int y) { | 49 int y) { |
48 *max_width = 0; | 50 *max_width = 0; |
49 *line_count = 0; | 51 *line_count = 0; |
(...skipping 23 matching lines...) Expand all Loading... |
73 return; | 75 return; |
74 } | 76 } |
75 if (!result.empty()) | 77 if (!result.empty()) |
76 result.append(GetLineSeparator()); | 78 result.append(GetLineSeparator()); |
77 result.append(elided_text); | 79 result.append(elided_text); |
78 } | 80 } |
79 *text = result; | 81 *text = result; |
80 } | 82 } |
81 | 83 |
82 } // namespace views | 84 } // namespace views |
OLD | NEW |