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

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

Issue 11030017: Add context to gfx::Screen calls in support of simultaneous desktop+ash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix some new gfx::Screen additions Created 8 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/views/widget/tooltip_manager_win.h" 5 #include "ui/views/widget/tooltip_manager_win.h"
6 6
7 #include <windowsx.h> 7 #include <windowsx.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 // static 53 // static
54 gfx::Font TooltipManager::GetDefaultFont() { 54 gfx::Font TooltipManager::GetDefaultFont() {
55 static gfx::Font* font = NULL; 55 static gfx::Font* font = NULL;
56 if (!font) 56 if (!font)
57 font = new gfx::Font(DetermineDefaultFont()); 57 font = new gfx::Font(DetermineDefaultFont());
58 return *font; 58 return *font;
59 } 59 }
60 60
61 // static 61 // static
62 int TooltipManager::GetMaxWidth(int x, int y) { 62 int TooltipManager::GetMaxWidth(int x, int y, gfx::NativeView context) {
63 gfx::Rect monitor_bounds = 63 gfx::Rect monitor_bounds =
64 gfx::Screen::GetDisplayNearestPoint(gfx::Point(x, y)).bounds(); 64 gfx::Screen::GetScreenFor(context)->GetDisplayNearestPoint(
65 gfx::Point(x, y)).bounds();
65 // Allow the tooltip to be almost as wide as the screen. 66 // Allow the tooltip to be almost as wide as the screen.
66 // Otherwise, we would truncate important text, since we're not word-wrapping 67 // Otherwise, we would truncate important text, since we're not word-wrapping
67 // the text onto multiple lines. 68 // the text onto multiple lines.
68 return monitor_bounds.width() == 0 ? 800 : monitor_bounds.width() - 30; 69 return monitor_bounds.width() == 0 ? 800 : monitor_bounds.width() - 30;
69 } 70 }
70 71
71 TooltipManagerWin::TooltipManagerWin(Widget* widget) 72 TooltipManagerWin::TooltipManagerWin(Widget* widget)
72 : widget_(widget), 73 : widget_(widget),
73 tooltip_hwnd_(NULL), 74 tooltip_hwnd_(NULL),
74 last_mouse_pos_(-1, -1), 75 last_mouse_pos_(-1, -1),
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 gfx::Point view_loc = last_mouse_pos_; 171 gfx::Point view_loc = last_mouse_pos_;
171 View::ConvertPointToTarget(widget_->GetRootView(), 172 View::ConvertPointToTarget(widget_->GetRootView(),
172 last_tooltip_view_, &view_loc); 173 last_tooltip_view_, &view_loc);
173 if (last_tooltip_view_->GetTooltipText(view_loc, &tooltip_text_) && 174 if (last_tooltip_view_->GetTooltipText(view_loc, &tooltip_text_) &&
174 !tooltip_text_.empty()) { 175 !tooltip_text_.empty()) {
175 // View has a valid tip, copy it into TOOLTIPINFO. 176 // View has a valid tip, copy it into TOOLTIPINFO.
176 clipped_text_ = tooltip_text_; 177 clipped_text_ = tooltip_text_;
177 gfx::Point screen_loc = last_mouse_pos_; 178 gfx::Point screen_loc = last_mouse_pos_;
178 View::ConvertPointToScreen(widget_->GetRootView(), &screen_loc); 179 View::ConvertPointToScreen(widget_->GetRootView(), &screen_loc);
179 TrimTooltipToFit(&clipped_text_, &tooltip_width_, &line_count_, 180 TrimTooltipToFit(&clipped_text_, &tooltip_width_, &line_count_,
180 screen_loc.x(), screen_loc.y()); 181 screen_loc.x(), screen_loc.y(),
182 widget_->GetNativeView());
181 // Adjust the clipped tooltip text for locale direction. 183 // Adjust the clipped tooltip text for locale direction.
182 base::i18n::AdjustStringForLocaleDirection(&clipped_text_); 184 base::i18n::AdjustStringForLocaleDirection(&clipped_text_);
183 tooltip_info->lpszText = const_cast<WCHAR*>(clipped_text_.c_str()); 185 tooltip_info->lpszText = const_cast<WCHAR*>(clipped_text_.c_str());
184 } else { 186 } else {
185 tooltip_text_.clear(); 187 tooltip_text_.clear();
186 } 188 }
187 } 189 }
188 *handled = true; 190 *handled = true;
189 return 0; 191 return 0;
190 } 192 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(), 337 WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(),
336 TOOLTIPS_CLASS, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); 338 TOOLTIPS_CLASS, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
337 if (!keyboard_tooltip_hwnd_) 339 if (!keyboard_tooltip_hwnd_)
338 return; 340 return;
339 341
340 SendMessage(keyboard_tooltip_hwnd_, TTM_SETMAXTIPWIDTH, 0, 342 SendMessage(keyboard_tooltip_hwnd_, TTM_SETMAXTIPWIDTH, 0,
341 std::numeric_limits<int16>::max()); 343 std::numeric_limits<int16>::max());
342 int tooltip_width; 344 int tooltip_width;
343 int line_count; 345 int line_count;
344 TrimTooltipToFit(&tooltip_text, &tooltip_width, &line_count, 346 TrimTooltipToFit(&tooltip_text, &tooltip_width, &line_count,
345 screen_point.x(), screen_point.y()); 347 screen_point.x(), screen_point.y(),
348 widget_->GetNativeView());
346 ReplaceSubstringsAfterOffset(&tooltip_text, 0, L"\n", L"\r\n"); 349 ReplaceSubstringsAfterOffset(&tooltip_text, 0, L"\n", L"\r\n");
347 TOOLINFO keyboard_toolinfo; 350 TOOLINFO keyboard_toolinfo;
348 memset(&keyboard_toolinfo, 0, sizeof(keyboard_toolinfo)); 351 memset(&keyboard_toolinfo, 0, sizeof(keyboard_toolinfo));
349 keyboard_toolinfo.cbSize = sizeof(keyboard_toolinfo); 352 keyboard_toolinfo.cbSize = sizeof(keyboard_toolinfo);
350 keyboard_toolinfo.hwnd = GetParent(); 353 keyboard_toolinfo.hwnd = GetParent();
351 keyboard_toolinfo.uFlags = TTF_TRACK | TTF_TRANSPARENT | TTF_IDISHWND; 354 keyboard_toolinfo.uFlags = TTF_TRACK | TTF_TRANSPARENT | TTF_IDISHWND;
352 keyboard_toolinfo.lpszText = const_cast<WCHAR*>(tooltip_text.c_str()); 355 keyboard_toolinfo.lpszText = const_cast<WCHAR*>(tooltip_text.c_str());
353 SendMessage(keyboard_tooltip_hwnd_, TTM_ADDTOOL, 0, 356 SendMessage(keyboard_tooltip_hwnd_, TTM_ADDTOOL, 0,
354 reinterpret_cast<LPARAM>(&keyboard_toolinfo)); 357 reinterpret_cast<LPARAM>(&keyboard_toolinfo));
355 SendMessage(keyboard_tooltip_hwnd_, TTM_TRACKACTIVATE, TRUE, 358 SendMessage(keyboard_tooltip_hwnd_, TTM_TRACKACTIVATE, TRUE,
(...skipping 25 matching lines...) Expand all
381 keyboard_tooltip_hwnd_ = NULL; 384 keyboard_tooltip_hwnd_ = NULL;
382 } 385 }
383 } 386 }
384 387
385 void TooltipManagerWin::DestroyKeyboardTooltipWindow(HWND window_to_destroy) { 388 void TooltipManagerWin::DestroyKeyboardTooltipWindow(HWND window_to_destroy) {
386 if (keyboard_tooltip_hwnd_ == window_to_destroy) 389 if (keyboard_tooltip_hwnd_ == window_to_destroy)
387 HideKeyboardTooltip(); 390 HideKeyboardTooltip();
388 } 391 }
389 392
390 } // namespace views 393 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698