OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/corewm/tooltip_win.h" | 5 #include "ui/views/corewm/tooltip_win.h" |
6 | 6 |
7 #include <winuser.h> | 7 #include <winuser.h> |
8 | 8 |
9 #include "base/debug/stack_trace.h" | 9 #include "base/debug/stack_trace.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "ui/base/l10n/l10n_util_win.h" | 12 #include "ui/base/l10n/l10n_util_win.h" |
13 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
14 #include "ui/gfx/screen.h" | 14 #include "ui/gfx/screen.h" |
15 #include "ui/gfx/win/dpi.h" | 15 #include "ui/gfx/screen_win.h" |
16 #include "ui/views/corewm/cursor_height_provider_win.h" | 16 #include "ui/views/corewm/cursor_height_provider_win.h" |
17 | 17 |
18 namespace views { | 18 namespace views { |
19 namespace corewm { | 19 namespace corewm { |
20 | 20 |
21 TooltipWin::TooltipWin(HWND parent) | 21 TooltipWin::TooltipWin(HWND parent) |
22 : parent_hwnd_(parent), | 22 : parent_hwnd_(parent), |
23 tooltip_hwnd_(NULL), | 23 tooltip_hwnd_(NULL), |
24 showing_(false) { | 24 showing_(false) { |
25 memset(&toolinfo_, 0, sizeof(toolinfo_)); | 25 memset(&toolinfo_, 0, sizeof(toolinfo_)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 | 71 |
72 l10n_util::AdjustUIFontForWindow(tooltip_hwnd_); | 72 l10n_util::AdjustUIFontForWindow(tooltip_hwnd_); |
73 | 73 |
74 SendMessage(tooltip_hwnd_, TTM_ADDTOOL, 0, | 74 SendMessage(tooltip_hwnd_, TTM_ADDTOOL, 0, |
75 reinterpret_cast<LPARAM>(&toolinfo_)); | 75 reinterpret_cast<LPARAM>(&toolinfo_)); |
76 return true; | 76 return true; |
77 } | 77 } |
78 | 78 |
79 void TooltipWin::PositionTooltip() { | 79 void TooltipWin::PositionTooltip() { |
80 // This code only runs for non-metro, so GetNativeScreen() is fine. | 80 gfx::Point screen_point = gfx::ScreenWin::DIPToScreenPoint(location_); |
81 gfx::Point screen_point = gfx::win::DIPToScreenPoint(location_); | |
82 const int cursoroffset = GetCurrentCursorVisibleHeight(); | 81 const int cursoroffset = GetCurrentCursorVisibleHeight(); |
83 screen_point.Offset(0, cursoroffset); | 82 screen_point.Offset(0, cursoroffset); |
84 | 83 |
85 DWORD tooltip_size = SendMessage(tooltip_hwnd_, TTM_GETBUBBLESIZE, 0, | 84 DWORD tooltip_size = SendMessage(tooltip_hwnd_, TTM_GETBUBBLESIZE, 0, |
86 reinterpret_cast<LPARAM>(&toolinfo_)); | 85 reinterpret_cast<LPARAM>(&toolinfo_)); |
87 const gfx::Size size(LOWORD(tooltip_size), HIWORD(tooltip_size)); | 86 const gfx::Size size(LOWORD(tooltip_size), HIWORD(tooltip_size)); |
88 | 87 |
| 88 // This code only runs for non-metro, so GetNativeScreen() is fine. |
89 const gfx::Display display( | 89 const gfx::Display display( |
90 gfx::Screen::GetNativeScreen()->GetDisplayNearestPoint(screen_point)); | 90 gfx::Screen::GetNativeScreen()->GetDisplayNearestPoint(location_)); |
91 | 91 |
92 gfx::Rect tooltip_bounds(screen_point, size); | 92 gfx::Rect tooltip_bounds(screen_point, size); |
93 tooltip_bounds.AdjustToFit(gfx::win::DIPToScreenRect(display.work_area())); | 93 tooltip_bounds.AdjustToFit( |
| 94 gfx::ScreenWin::DIPToScreenRect(parent_hwnd_, display.work_area())); |
94 SetWindowPos(tooltip_hwnd_, NULL, tooltip_bounds.x(), tooltip_bounds.y(), 0, | 95 SetWindowPos(tooltip_hwnd_, NULL, tooltip_bounds.x(), tooltip_bounds.y(), 0, |
95 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); | 96 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); |
96 } | 97 } |
97 | 98 |
98 int TooltipWin::GetMaxWidth(const gfx::Point& location, | 99 int TooltipWin::GetMaxWidth(const gfx::Point& location, |
99 aura::Window* context) const { | 100 aura::Window* context) const { |
100 // This code only runs for non-metro, so GetNativeScreen() is fine. | 101 // This code only runs for non-metro, so GetNativeScreen() is fine. |
101 const gfx::Point screen_point = gfx::win::DIPToScreenPoint(location); | 102 const gfx::Point screen_point = gfx::ScreenWin::DIPToScreenPoint(location); |
102 gfx::Display display( | 103 gfx::Display display( |
103 gfx::Screen::GetNativeScreen()->GetDisplayNearestPoint(screen_point)); | 104 gfx::Screen::GetNativeScreen()->GetDisplayNearestPoint(screen_point)); |
104 const gfx::Rect monitor_bounds = display.bounds(); | 105 const gfx::Rect monitor_bounds = display.bounds(); |
105 return (monitor_bounds.width() + 1) / 2; | 106 return (monitor_bounds.width() + 1) / 2; |
106 } | 107 } |
107 | 108 |
108 void TooltipWin::SetText(aura::Window* window, | 109 void TooltipWin::SetText(aura::Window* window, |
109 const base::string16& tooltip_text, | 110 const base::string16& tooltip_text, |
110 const gfx::Point& location) { | 111 const gfx::Point& location) { |
111 if (!EnsureTooltipWindow()) | 112 if (!EnsureTooltipWindow()) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE, FALSE, | 148 SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE, FALSE, |
148 reinterpret_cast<LPARAM>(&toolinfo_)); | 149 reinterpret_cast<LPARAM>(&toolinfo_)); |
149 } | 150 } |
150 | 151 |
151 bool TooltipWin::IsVisible() { | 152 bool TooltipWin::IsVisible() { |
152 return showing_; | 153 return showing_; |
153 } | 154 } |
154 | 155 |
155 } // namespace corewm | 156 } // namespace corewm |
156 } // namespace views | 157 } // namespace views |
OLD | NEW |