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