| OLD | NEW |
| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/win/scoped_hdc.h" | 16 #include "base/win/scoped_hdc.h" |
| 17 #include "base/win/scoped_select_object.h" | 17 #include "base/win/scoped_select_object.h" |
| 18 #include "ui/base/l10n/l10n_util_win.h" | 18 #include "ui/base/l10n/l10n_util_win.h" |
| 19 #include "ui/base/win/dpi.h" |
| 19 #include "ui/base/win/hwnd_util.h" | 20 #include "ui/base/win/hwnd_util.h" |
| 20 #include "ui/base/win/scoped_set_map_mode.h" | 21 #include "ui/base/win/scoped_set_map_mode.h" |
| 21 #include "ui/gfx/font.h" | 22 #include "ui/gfx/font.h" |
| 22 #include "ui/gfx/screen.h" | 23 #include "ui/gfx/screen.h" |
| 23 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
| 24 #include "ui/views/widget/monitor_win.h" | 25 #include "ui/views/widget/monitor_win.h" |
| 25 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 26 | 27 |
| 27 namespace views { | 28 namespace views { |
| 28 | 29 |
| 29 static int tooltip_height_ = 0; | 30 static int tooltip_height_ = 0; |
| 30 | 31 |
| 31 // Default timeout for the tooltip displayed using keyboard. | 32 // Default timeout for the tooltip displayed using keyboard. |
| 32 // Timeout is mentioned in milliseconds. | 33 // Timeout is measured in milliseconds. |
| 33 static const int kDefaultTimeout = 4000; | 34 static const int kDefaultTimeout = 4000; |
| 34 | 35 |
| 35 // static | 36 // static |
| 36 int TooltipManager::GetTooltipHeight() { | 37 int TooltipManager::GetTooltipHeight() { |
| 37 DCHECK_GT(tooltip_height_, 0); | 38 DCHECK_GT(tooltip_height_, 0); |
| 38 return tooltip_height_; | 39 return tooltip_height_; |
| 39 } | 40 } |
| 40 | 41 |
| 41 static gfx::Font DetermineDefaultFont() { | 42 static gfx::Font DetermineDefaultFont() { |
| 42 HWND window = CreateWindowEx( | 43 HWND window = CreateWindowEx( |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 return 0; | 220 return 0; |
| 220 } | 221 } |
| 221 | 222 |
| 222 bool TooltipManagerWin::SetTooltipPosition(int text_x, int text_y) { | 223 bool TooltipManagerWin::SetTooltipPosition(int text_x, int text_y) { |
| 223 // NOTE: this really only tests that the y location fits on screen, but that | 224 // NOTE: this really only tests that the y location fits on screen, but that |
| 224 // is good enough for our usage. | 225 // is good enough for our usage. |
| 225 | 226 |
| 226 // Calculate the bounds the tooltip will get. | 227 // Calculate the bounds the tooltip will get. |
| 227 gfx::Point view_loc; | 228 gfx::Point view_loc; |
| 228 View::ConvertPointToScreen(last_tooltip_view_, &view_loc); | 229 View::ConvertPointToScreen(last_tooltip_view_, &view_loc); |
| 230 view_loc = ui::win::DIPToScreenPoint(view_loc); |
| 229 RECT bounds = { view_loc.x() + text_x, | 231 RECT bounds = { view_loc.x() + text_x, |
| 230 view_loc.y() + text_y, | 232 view_loc.y() + text_y, |
| 231 view_loc.x() + text_x + tooltip_width_, | 233 view_loc.x() + text_x + tooltip_width_, |
| 232 view_loc.y() + line_count_ * GetTooltipHeight() }; | 234 view_loc.y() + line_count_ * GetTooltipHeight() }; |
| 233 SendMessage(tooltip_hwnd_, TTM_ADJUSTRECT, TRUE, (LPARAM)&bounds); | 235 SendMessage(tooltip_hwnd_, TTM_ADJUSTRECT, TRUE, (LPARAM)&bounds); |
| 234 | 236 |
| 235 // Make sure the rectangle completely fits on the current monitor. If it | 237 // Make sure the rectangle completely fits on the current monitor. If it |
| 236 // doesn't, return false so that windows positions the tooltip at the | 238 // doesn't, return false so that windows positions the tooltip at the |
| 237 // default location. | 239 // default location. |
| 238 gfx::Rect monitor_bounds = | 240 gfx::Rect monitor_bounds = |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 SendMessage(tooltip_hwnd_, TTM_POP, 0, 0); | 293 SendMessage(tooltip_hwnd_, TTM_POP, 0, 0); |
| 292 if (has_tooltip_text && !new_tooltip_text.empty() && tooltip_showing_) { | 294 if (has_tooltip_text && !new_tooltip_text.empty() && tooltip_showing_) { |
| 293 // New text is valid, show the popup. | 295 // New text is valid, show the popup. |
| 294 SendMessage(tooltip_hwnd_, TTM_POPUP, 0, 0); | 296 SendMessage(tooltip_hwnd_, TTM_POPUP, 0, 0); |
| 295 } | 297 } |
| 296 } | 298 } |
| 297 } | 299 } |
| 298 } | 300 } |
| 299 | 301 |
| 300 void TooltipManagerWin::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) { | 302 void TooltipManagerWin::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) { |
| 301 gfx::Point mouse_pos(l_param); | 303 gfx::Point mouse_pos_in_pixels(l_param); |
| 304 gfx::Point mouse_pos = ui::win::ScreenToDIPPoint(mouse_pos_in_pixels); |
| 302 | 305 |
| 303 if (u_msg >= WM_NCMOUSEMOVE && u_msg <= WM_NCXBUTTONDBLCLK) { | 306 if (u_msg >= WM_NCMOUSEMOVE && u_msg <= WM_NCXBUTTONDBLCLK) { |
| 304 // NC message coordinates are in screen coordinates. | 307 // NC message coordinates are in screen coordinates. |
| 305 POINT temp = mouse_pos.ToPOINT(); | 308 POINT temp = mouse_pos_in_pixels.ToPOINT(); |
| 306 ::MapWindowPoints(HWND_DESKTOP, GetParent(), &temp, 1); | 309 ::MapWindowPoints(HWND_DESKTOP, GetParent(), &temp, 1); |
| 307 mouse_pos.SetPoint(temp.x, temp.y); | 310 mouse_pos_in_pixels.SetPoint(temp.x, temp.y); |
| 311 mouse_pos = ui::win::ScreenToDIPPoint(mouse_pos_in_pixels); |
| 308 } | 312 } |
| 309 | 313 |
| 310 if (u_msg != WM_MOUSEMOVE || last_mouse_pos_ != mouse_pos) { | 314 if (u_msg != WM_MOUSEMOVE || last_mouse_pos_ != mouse_pos) { |
| 311 last_mouse_pos_ = mouse_pos; | 315 last_mouse_pos_ = mouse_pos; |
| 312 HideKeyboardTooltip(); | 316 HideKeyboardTooltip(); |
| 313 UpdateTooltip(mouse_pos); | 317 UpdateTooltip(mouse_pos); |
| 314 } | 318 } |
| 315 // Forward the message onto the tooltip. | 319 // Forward the message onto the tooltip. |
| 316 MSG msg; | 320 MSG msg; |
| 317 msg.hwnd = GetParent(); | 321 msg.hwnd = GetParent(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 keyboard_tooltip_hwnd_ = NULL; | 390 keyboard_tooltip_hwnd_ = NULL; |
| 387 } | 391 } |
| 388 } | 392 } |
| 389 | 393 |
| 390 void TooltipManagerWin::DestroyKeyboardTooltipWindow(HWND window_to_destroy) { | 394 void TooltipManagerWin::DestroyKeyboardTooltipWindow(HWND window_to_destroy) { |
| 391 if (keyboard_tooltip_hwnd_ == window_to_destroy) | 395 if (keyboard_tooltip_hwnd_ == window_to_destroy) |
| 392 HideKeyboardTooltip(); | 396 HideKeyboardTooltip(); |
| 393 } | 397 } |
| 394 | 398 |
| 395 } // namespace views | 399 } // namespace views |
| OLD | NEW |