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" |
(...skipping 59 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. | |
81 gfx::Point screen_point = gfx::win::DIPToScreenPoint(location_); | 80 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 |
89 const gfx::Display display( | 88 const gfx::Display display( |
90 gfx::Screen::GetNativeScreen()->GetDisplayNearestPoint(screen_point)); | 89 gfx::Screen::GetScreen()->GetDisplayNearestPoint(screen_point)); |
91 | 90 |
92 gfx::Rect tooltip_bounds(screen_point, size); | 91 gfx::Rect tooltip_bounds(screen_point, size); |
93 tooltip_bounds.AdjustToFit(gfx::win::DIPToScreenRect(display.work_area())); | 92 tooltip_bounds.AdjustToFit(gfx::win::DIPToScreenRect(display.work_area())); |
94 SetWindowPos(tooltip_hwnd_, NULL, tooltip_bounds.x(), tooltip_bounds.y(), 0, | 93 SetWindowPos(tooltip_hwnd_, NULL, tooltip_bounds.x(), tooltip_bounds.y(), 0, |
95 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); | 94 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); |
96 } | 95 } |
97 | 96 |
98 int TooltipWin::GetMaxWidth(const gfx::Point& location, | 97 int TooltipWin::GetMaxWidth(const gfx::Point& location) const { |
99 aura::Window* context) const { | |
100 // This code only runs for non-metro, so GetNativeScreen() is fine. | |
101 const gfx::Point screen_point = gfx::win::DIPToScreenPoint(location); | 98 const gfx::Point screen_point = gfx::win::DIPToScreenPoint(location); |
102 gfx::Display display( | 99 gfx::Display display( |
103 gfx::Screen::GetNativeScreen()->GetDisplayNearestPoint(screen_point)); | 100 gfx::Screen::GetScreen()->GetDisplayNearestPoint(screen_point)); |
104 const gfx::Rect monitor_bounds = display.bounds(); | 101 const gfx::Rect monitor_bounds = display.bounds(); |
105 return (monitor_bounds.width() + 1) / 2; | 102 return (monitor_bounds.width() + 1) / 2; |
106 } | 103 } |
107 | 104 |
108 void TooltipWin::SetText(aura::Window* window, | 105 void TooltipWin::SetText(aura::Window* window, |
109 const base::string16& tooltip_text, | 106 const base::string16& tooltip_text, |
110 const gfx::Point& location) { | 107 const gfx::Point& location) { |
111 if (!EnsureTooltipWindow()) | 108 if (!EnsureTooltipWindow()) |
112 return; | 109 return; |
113 | 110 |
114 // See comment in header for details on why |location_| is needed. | 111 // See comment in header for details on why |location_| is needed. |
115 location_ = location; | 112 location_ = location; |
116 | 113 |
117 // Without this we get a flicker of the tooltip appearing at 0x0. Not sure | 114 // Without this we get a flicker of the tooltip appearing at 0x0. Not sure |
118 // why. | 115 // why. |
119 SetWindowPos(tooltip_hwnd_, NULL, 0, 0, 0, 0, | 116 SetWindowPos(tooltip_hwnd_, NULL, 0, 0, 0, 0, |
120 SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | | 117 SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | |
121 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); | 118 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); |
122 | 119 |
123 base::string16 adjusted_text(tooltip_text); | 120 base::string16 adjusted_text(tooltip_text); |
124 base::i18n::AdjustStringForLocaleDirection(&adjusted_text); | 121 base::i18n::AdjustStringForLocaleDirection(&adjusted_text); |
125 toolinfo_.lpszText = const_cast<WCHAR*>(adjusted_text.c_str()); | 122 toolinfo_.lpszText = const_cast<WCHAR*>(adjusted_text.c_str()); |
126 SendMessage(tooltip_hwnd_, TTM_SETTOOLINFO, 0, | 123 SendMessage(tooltip_hwnd_, TTM_SETTOOLINFO, 0, |
127 reinterpret_cast<LPARAM>(&toolinfo_)); | 124 reinterpret_cast<LPARAM>(&toolinfo_)); |
128 | 125 |
129 int max_width = GetMaxWidth(location_, window); | 126 int max_width = GetMaxWidth(location_); |
130 SendMessage(tooltip_hwnd_, TTM_SETMAXTIPWIDTH, 0, max_width); | 127 SendMessage(tooltip_hwnd_, TTM_SETMAXTIPWIDTH, 0, max_width); |
131 } | 128 } |
132 | 129 |
133 void TooltipWin::Show() { | 130 void TooltipWin::Show() { |
134 if (!EnsureTooltipWindow()) | 131 if (!EnsureTooltipWindow()) |
135 return; | 132 return; |
136 | 133 |
137 SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE, | 134 SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE, |
138 TRUE, reinterpret_cast<LPARAM>(&toolinfo_)); | 135 TRUE, reinterpret_cast<LPARAM>(&toolinfo_)); |
139 SetWindowPos(tooltip_hwnd_, HWND_TOPMOST, 0, 0, 0, 0, | 136 SetWindowPos(tooltip_hwnd_, HWND_TOPMOST, 0, 0, 0, 0, |
140 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE); | 137 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE); |
141 } | 138 } |
142 | 139 |
143 void TooltipWin::Hide() { | 140 void TooltipWin::Hide() { |
144 if (!tooltip_hwnd_) | 141 if (!tooltip_hwnd_) |
145 return; | 142 return; |
146 | 143 |
147 SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE, FALSE, | 144 SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE, FALSE, |
148 reinterpret_cast<LPARAM>(&toolinfo_)); | 145 reinterpret_cast<LPARAM>(&toolinfo_)); |
149 } | 146 } |
150 | 147 |
151 bool TooltipWin::IsVisible() { | 148 bool TooltipWin::IsVisible() { |
152 return showing_; | 149 return showing_; |
153 } | 150 } |
154 | 151 |
155 } // namespace corewm | 152 } // namespace corewm |
156 } // namespace views | 153 } // namespace views |
OLD | NEW |