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

Side by Side Diff: views/widget/tooltip_manager_win.cc

Issue 6995157: Disables tooltips if we can't create the tooltip window. I still don't (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improved comments Created 9 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « views/widget/tooltip_manager_win.h ('k') | no next file » | 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 "views/widget/tooltip_manager_win.h" 5 #include "views/widget/tooltip_manager_win.h"
6 6
7 #include <windowsx.h> 7 #include <windowsx.h>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 18 matching lines...) Expand all
29 // static 29 // static
30 int TooltipManager::GetTooltipHeight() { 30 int TooltipManager::GetTooltipHeight() {
31 DCHECK(tooltip_height_ > 0); 31 DCHECK(tooltip_height_ > 0);
32 return tooltip_height_; 32 return tooltip_height_;
33 } 33 }
34 34
35 static gfx::Font DetermineDefaultFont() { 35 static gfx::Font DetermineDefaultFont() {
36 HWND window = CreateWindowEx( 36 HWND window = CreateWindowEx(
37 WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(), 37 WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(),
38 TOOLTIPS_CLASS, NULL, 0 , 0, 0, 0, 0, NULL, NULL, NULL, NULL); 38 TOOLTIPS_CLASS, NULL, 0 , 0, 0, 0, 0, NULL, NULL, NULL, NULL);
39 ui::CheckWindowCreated(window); 39 if (!window)
40 return gfx::Font();
40 HFONT hfont = reinterpret_cast<HFONT>(SendMessage(window, WM_GETFONT, 0, 0)); 41 HFONT hfont = reinterpret_cast<HFONT>(SendMessage(window, WM_GETFONT, 0, 0));
41 gfx::Font font = hfont ? gfx::Font(hfont) : gfx::Font(); 42 gfx::Font font = hfont ? gfx::Font(hfont) : gfx::Font();
42 DestroyWindow(window); 43 DestroyWindow(window);
43 return font; 44 return font;
44 } 45 }
45 46
46 // static 47 // static
47 gfx::Font TooltipManager::GetDefaultFont() { 48 gfx::Font TooltipManager::GetDefaultFont() {
48 static gfx::Font* font = NULL; 49 static gfx::Font* font = NULL;
49 if (!font) 50 if (!font)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 Init(); 84 Init();
84 } 85 }
85 86
86 TooltipManagerWin::~TooltipManagerWin() { 87 TooltipManagerWin::~TooltipManagerWin() {
87 if (tooltip_hwnd_) 88 if (tooltip_hwnd_)
88 DestroyWindow(tooltip_hwnd_); 89 DestroyWindow(tooltip_hwnd_);
89 if (keyboard_tooltip_hwnd_) 90 if (keyboard_tooltip_hwnd_)
90 DestroyWindow(keyboard_tooltip_hwnd_); 91 DestroyWindow(keyboard_tooltip_hwnd_);
91 } 92 }
92 93
93 void TooltipManagerWin::Init() { 94 bool TooltipManagerWin::Init() {
94 // Create the tooltip control. 95 // Create the tooltip control.
95 tooltip_hwnd_ = CreateWindowEx( 96 tooltip_hwnd_ = CreateWindowEx(
96 WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(), 97 WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(),
97 TOOLTIPS_CLASS, NULL, TTS_NOPREFIX, 0, 0, 0, 0, 98 TOOLTIPS_CLASS, NULL, TTS_NOPREFIX, 0, 0, 0, 0,
98 GetParent(), NULL, NULL, NULL); 99 GetParent(), NULL, NULL, NULL);
99 ui::CheckWindowCreated(tooltip_hwnd_); 100 if (!tooltip_hwnd_)
101 return false;
100 102
101 l10n_util::AdjustUIFontForWindow(tooltip_hwnd_); 103 l10n_util::AdjustUIFontForWindow(tooltip_hwnd_);
102 104
103 // This effectively turns off clipping of tooltips. We need this otherwise 105 // This effectively turns off clipping of tooltips. We need this otherwise
104 // multi-line text (\r\n) won't work right. The size doesn't really matter 106 // multi-line text (\r\n) won't work right. The size doesn't really matter
105 // (just as long as its bigger than the monitor's width) as we clip to the 107 // (just as long as its bigger than the monitor's width) as we clip to the
106 // screen size before rendering. 108 // screen size before rendering.
107 SendMessage(tooltip_hwnd_, TTM_SETMAXTIPWIDTH, 0, 109 SendMessage(tooltip_hwnd_, TTM_SETMAXTIPWIDTH, 0,
108 std::numeric_limits<short>::max()); 110 std::numeric_limits<short>::max());
109 111
110 // Add one tool that is used for all tooltips. 112 // Add one tool that is used for all tooltips.
111 toolinfo_.cbSize = sizeof(toolinfo_); 113 toolinfo_.cbSize = sizeof(toolinfo_);
112 toolinfo_.uFlags = TTF_TRANSPARENT | TTF_IDISHWND; 114 toolinfo_.uFlags = TTF_TRANSPARENT | TTF_IDISHWND;
113 toolinfo_.hwnd = GetParent(); 115 toolinfo_.hwnd = GetParent();
114 toolinfo_.uId = reinterpret_cast<UINT_PTR>(GetParent()); 116 toolinfo_.uId = reinterpret_cast<UINT_PTR>(GetParent());
115 // Setting this tells windows to call GetParent() back (using a WM_NOTIFY 117 // Setting this tells windows to call GetParent() back (using a WM_NOTIFY
116 // message) for the actual tooltip contents. 118 // message) for the actual tooltip contents.
117 toolinfo_.lpszText = LPSTR_TEXTCALLBACK; 119 toolinfo_.lpszText = LPSTR_TEXTCALLBACK;
118 SetRectEmpty(&toolinfo_.rect); 120 SetRectEmpty(&toolinfo_.rect);
119 SendMessage(tooltip_hwnd_, TTM_ADDTOOL, 0, (LPARAM)&toolinfo_); 121 SendMessage(tooltip_hwnd_, TTM_ADDTOOL, 0, (LPARAM)&toolinfo_);
122 return true;
120 } 123 }
121 124
122 gfx::NativeView TooltipManagerWin::GetParent() { 125 gfx::NativeView TooltipManagerWin::GetParent() {
123 return widget_->GetNativeView(); 126 return widget_->GetNativeView();
124 } 127 }
125 128
126 void TooltipManagerWin::UpdateTooltip() { 129 void TooltipManagerWin::UpdateTooltip() {
127 // Set last_view_out_of_sync_ to indicate the view is currently out of sync. 130 // Set last_view_out_of_sync_ to indicate the view is currently out of sync.
128 // This doesn't update the view under the mouse immediately as it may cause 131 // This doesn't update the view under the mouse immediately as it may cause
129 // timing problems. 132 // timing problems.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 HideKeyboardTooltip(); 331 HideKeyboardTooltip();
329 std::wstring tooltip_text; 332 std::wstring tooltip_text;
330 if (!focused_view->GetTooltipText(gfx::Point(), &tooltip_text)) 333 if (!focused_view->GetTooltipText(gfx::Point(), &tooltip_text))
331 return; 334 return;
332 gfx::Rect focused_bounds = focused_view->bounds(); 335 gfx::Rect focused_bounds = focused_view->bounds();
333 gfx::Point screen_point; 336 gfx::Point screen_point;
334 focused_view->ConvertPointToScreen(focused_view, &screen_point); 337 focused_view->ConvertPointToScreen(focused_view, &screen_point);
335 keyboard_tooltip_hwnd_ = CreateWindowEx( 338 keyboard_tooltip_hwnd_ = CreateWindowEx(
336 WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(), 339 WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(),
337 TOOLTIPS_CLASS, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); 340 TOOLTIPS_CLASS, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
338 ui::CheckWindowCreated(keyboard_tooltip_hwnd_); 341 if (!keyboard_tooltip_hwnd_)
342 return;
343
339 SendMessage(keyboard_tooltip_hwnd_, TTM_SETMAXTIPWIDTH, 0, 344 SendMessage(keyboard_tooltip_hwnd_, TTM_SETMAXTIPWIDTH, 0,
340 std::numeric_limits<short>::max()); 345 std::numeric_limits<short>::max());
341 int tooltip_width; 346 int tooltip_width;
342 int line_count; 347 int line_count;
343 TrimTooltipToFit(&tooltip_text, &tooltip_width, &line_count, 348 TrimTooltipToFit(&tooltip_text, &tooltip_width, &line_count,
344 screen_point.x(), screen_point.y()); 349 screen_point.x(), screen_point.y());
345 TOOLINFO keyboard_toolinfo; 350 TOOLINFO keyboard_toolinfo;
346 memset(&keyboard_toolinfo, 0, sizeof(keyboard_toolinfo)); 351 memset(&keyboard_toolinfo, 0, sizeof(keyboard_toolinfo));
347 keyboard_toolinfo.cbSize = sizeof(keyboard_toolinfo); 352 keyboard_toolinfo.cbSize = sizeof(keyboard_toolinfo);
348 keyboard_toolinfo.hwnd = GetParent(); 353 keyboard_toolinfo.hwnd = GetParent();
(...skipping 29 matching lines...) Expand all
378 keyboard_tooltip_hwnd_ = NULL; 383 keyboard_tooltip_hwnd_ = NULL;
379 } 384 }
380 } 385 }
381 386
382 void TooltipManagerWin::DestroyKeyboardTooltipWindow(HWND window_to_destroy) { 387 void TooltipManagerWin::DestroyKeyboardTooltipWindow(HWND window_to_destroy) {
383 if (keyboard_tooltip_hwnd_ == window_to_destroy) 388 if (keyboard_tooltip_hwnd_ == window_to_destroy)
384 HideKeyboardTooltip(); 389 HideKeyboardTooltip();
385 } 390 }
386 391
387 } // namespace views 392 } // namespace views
OLDNEW
« no previous file with comments | « views/widget/tooltip_manager_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698