OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <windowsx.h> | 7 #include <windowsx.h> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "app/gfx/text_elider.h" | 10 #include "app/gfx/text_elider.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 if (next_index != text.size() && lines->size() < kMaxLines) | 45 if (next_index != text.size() && lines->size() < kMaxLines) |
46 lines->push_back(text.substr(index, text.size() - index)); | 46 lines->push_back(text.substr(index, text.size() - index)); |
47 } | 47 } |
48 | 48 |
49 // static | 49 // static |
50 int TooltipManager::GetTooltipHeight() { | 50 int TooltipManager::GetTooltipHeight() { |
51 DCHECK(tooltip_height_ > 0); | 51 DCHECK(tooltip_height_ > 0); |
52 return tooltip_height_; | 52 return tooltip_height_; |
53 } | 53 } |
54 | 54 |
55 static ChromeFont DetermineDefaultFont() { | 55 static gfx::Font DetermineDefaultFont() { |
56 HWND window = CreateWindowEx( | 56 HWND window = CreateWindowEx( |
57 WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(), | 57 WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(), |
58 TOOLTIPS_CLASS, NULL, 0 , 0, 0, 0, 0, NULL, NULL, NULL, NULL); | 58 TOOLTIPS_CLASS, NULL, 0 , 0, 0, 0, 0, NULL, NULL, NULL, NULL); |
59 HFONT hfont = reinterpret_cast<HFONT>(SendMessage(window, WM_GETFONT, 0, 0)); | 59 HFONT hfont = reinterpret_cast<HFONT>(SendMessage(window, WM_GETFONT, 0, 0)); |
60 ChromeFont font = hfont ? ChromeFont::CreateFont(hfont) : ChromeFont(); | 60 gfx::Font font = hfont ? gfx::Font::CreateFont(hfont) : gfx::Font(); |
61 DestroyWindow(window); | 61 DestroyWindow(window); |
62 return font; | 62 return font; |
63 } | 63 } |
64 | 64 |
65 // static | 65 // static |
66 ChromeFont TooltipManager::GetDefaultFont() { | 66 gfx::Font TooltipManager::GetDefaultFont() { |
67 static ChromeFont* font = NULL; | 67 static gfx::Font* font = NULL; |
68 if (!font) | 68 if (!font) |
69 font = new ChromeFont(DetermineDefaultFont()); | 69 font = new gfx::Font(DetermineDefaultFont()); |
70 return *font; | 70 return *font; |
71 } | 71 } |
72 | 72 |
73 // static | 73 // static |
74 const std::wstring& TooltipManager::GetLineSeparator() { | 74 const std::wstring& TooltipManager::GetLineSeparator() { |
75 static const std::wstring* separator = NULL; | 75 static const std::wstring* separator = NULL; |
76 if (!separator) | 76 if (!separator) |
77 separator = new std::wstring(L"\r\n"); | 77 separator = new std::wstring(L"\r\n"); |
78 return *separator; | 78 return *separator; |
79 } | 79 } |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 HFONT previous_font = static_cast<HFONT>(SelectObject(dc, hfont)); | 257 HFONT previous_font = static_cast<HFONT>(SelectObject(dc, hfont)); |
258 int last_map_mode = SetMapMode(dc, MM_TEXT); | 258 int last_map_mode = SetMapMode(dc, MM_TEXT); |
259 TEXTMETRIC font_metrics; | 259 TEXTMETRIC font_metrics; |
260 GetTextMetrics(dc, &font_metrics); | 260 GetTextMetrics(dc, &font_metrics); |
261 height = font_metrics.tmHeight; | 261 height = font_metrics.tmHeight; |
262 // To avoid the DC referencing font_handle_, select the previous font. | 262 // To avoid the DC referencing font_handle_, select the previous font. |
263 SelectObject(dc, previous_font); | 263 SelectObject(dc, previous_font); |
264 SetMapMode(dc, last_map_mode); | 264 SetMapMode(dc, last_map_mode); |
265 ReleaseDC(NULL, dc); | 265 ReleaseDC(NULL, dc); |
266 } else { | 266 } else { |
267 // Tooltip is using the system font. Use ChromeFont, which should pick | 267 // Tooltip is using the system font. Use gfx::Font, which should pick |
268 // up the system font. | 268 // up the system font. |
269 height = ChromeFont().height(); | 269 height = gfx::Font().height(); |
270 } | 270 } |
271 // Get the margins from the tooltip | 271 // Get the margins from the tooltip |
272 RECT tooltip_margin; | 272 RECT tooltip_margin; |
273 SendMessage(tooltip_hwnd_, TTM_GETMARGIN, 0, (LPARAM)&tooltip_margin); | 273 SendMessage(tooltip_hwnd_, TTM_GETMARGIN, 0, (LPARAM)&tooltip_margin); |
274 return height + tooltip_margin.top + tooltip_margin.bottom; | 274 return height + tooltip_margin.top + tooltip_margin.bottom; |
275 } | 275 } |
276 | 276 |
277 void TooltipManager::TrimTooltipToFit(std::wstring* text, | 277 void TooltipManager::TrimTooltipToFit(std::wstring* text, |
278 int* max_width, | 278 int* max_width, |
279 int* line_count, | 279 int* line_count, |
(...skipping 22 matching lines...) Expand all Loading... |
302 tooltip_margin.right; | 302 tooltip_margin.right; |
303 if (available_width <= 0) | 303 if (available_width <= 0) |
304 return; | 304 return; |
305 | 305 |
306 // Split the string. | 306 // Split the string. |
307 std::vector<std::wstring> lines; | 307 std::vector<std::wstring> lines; |
308 SplitTooltipString(*text, &lines); | 308 SplitTooltipString(*text, &lines); |
309 *line_count = static_cast<int>(lines.size()); | 309 *line_count = static_cast<int>(lines.size()); |
310 | 310 |
311 // Format each line to fit. | 311 // Format each line to fit. |
312 ChromeFont font = GetDefaultFont(); | 312 gfx::Font font = GetDefaultFont(); |
313 std::wstring result; | 313 std::wstring result; |
314 for (std::vector<std::wstring>::iterator i = lines.begin(); i != lines.end(); | 314 for (std::vector<std::wstring>::iterator i = lines.begin(); i != lines.end(); |
315 ++i) { | 315 ++i) { |
316 std::wstring elided_text = gfx::ElideText(*i, font, available_width); | 316 std::wstring elided_text = gfx::ElideText(*i, font, available_width); |
317 *max_width = std::max(*max_width, font.GetStringWidth(elided_text)); | 317 *max_width = std::max(*max_width, font.GetStringWidth(elided_text)); |
318 if (i == lines.begin() && i + 1 == lines.end()) { | 318 if (i == lines.begin() && i + 1 == lines.end()) { |
319 *text = elided_text; | 319 *text = elided_text; |
320 return; | 320 return; |
321 } | 321 } |
322 if (!result.empty()) | 322 if (!result.empty()) |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 keyboard_tooltip_hwnd_ = NULL; | 439 keyboard_tooltip_hwnd_ = NULL; |
440 } | 440 } |
441 } | 441 } |
442 | 442 |
443 void TooltipManager::DestroyKeyboardTooltipWindow(HWND window_to_destroy) { | 443 void TooltipManager::DestroyKeyboardTooltipWindow(HWND window_to_destroy) { |
444 if (keyboard_tooltip_hwnd_ == window_to_destroy) | 444 if (keyboard_tooltip_hwnd_ == window_to_destroy) |
445 HideKeyboardTooltip(); | 445 HideKeyboardTooltip(); |
446 } | 446 } |
447 | 447 |
448 } // namespace views | 448 } // namespace views |
OLD | NEW |