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

Side by Side Diff: ui/views/corewm/tooltip_win.cc

Issue 225403022: Fixed positioning of tooltips in multi monitor setups. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // This code only runs for non-metro, so GetNativeScreen() is fine.
81 const gfx::Point screen_point = gfx::win::DIPToScreenPoint(location_);
81 gfx::Display display( 82 gfx::Display display(
82 gfx::Screen::GetNativeScreen()->GetDisplayNearestPoint(location_)); 83 gfx::Screen::GetNativeScreen()->GetDisplayNearestPoint(screen_point));
83 84
84 DWORD tooltip_size = SendMessage(tooltip_hwnd_, TTM_GETBUBBLESIZE, 0, 85 DWORD tooltip_size = SendMessage(tooltip_hwnd_, TTM_GETBUBBLESIZE, 0,
85 reinterpret_cast<LPARAM>(&toolinfo_)); 86 reinterpret_cast<LPARAM>(&toolinfo_));
86 // 20 accounts for visible cursor size. I tried using SM_CYCURSOR but that's 87 // 20 accounts for visible cursor size. I tried using SM_CYCURSOR but that's
87 // way too big (32 on win7 default). 88 // way too big (32 on win7 default).
88 // TODO(sky): figure out the right way to determine offset. 89 // TODO(sky): figure out the right way to determine offset.
89 const int initial_y = location_.y(); 90 const int initial_y = location_.y();
90 gfx::Rect tooltip_bounds(location_.x(), initial_y + 20, 91 gfx::Rect tooltip_bounds(location_.x(), initial_y + 20,
91 LOWORD(tooltip_size), HIWORD(tooltip_size)); 92 LOWORD(tooltip_size), HIWORD(tooltip_size));
92 tooltip_bounds.AdjustToFit(display.work_area()); 93 tooltip_bounds.AdjustToFit(display.work_area());
sadrul 2014/04/10 16:18:36 Does |tooltip_bounds| need to be in screen coordin
Mateusz Szymański 2014/04/30 14:14:40 It's in DIP coordinates, notice the conversion in
93 if (tooltip_bounds.y() < initial_y) 94 if (tooltip_bounds.y() < initial_y)
94 tooltip_bounds.set_y(initial_y - tooltip_bounds.height() - 2); 95 tooltip_bounds.set_y(initial_y - tooltip_bounds.height() - 2);
95 96
96 // Convert the tooltip bounds to pixel coordinates. SetWindowPos works in 97 // Convert the tooltip bounds to pixel coordinates. SetWindowPos works in
97 // pixel coordinates. 98 // pixel coordinates.
98 tooltip_bounds = gfx::win::DIPToScreenRect(tooltip_bounds); 99 tooltip_bounds = gfx::win::DIPToScreenRect(tooltip_bounds);
sky 2014/04/10 23:07:21 Notice the conversion here too. Seems like it shou
99 SetWindowPos(tooltip_hwnd_, NULL, tooltip_bounds.x(), tooltip_bounds.y(), 0, 100 SetWindowPos(tooltip_hwnd_, NULL, tooltip_bounds.x(), tooltip_bounds.y(), 0,
100 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); 101 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
101 } 102 }
102 103
103 void TooltipWin::SetText(aura::Window* window, 104 void TooltipWin::SetText(aura::Window* window,
104 const base::string16& tooltip_text, 105 const base::string16& tooltip_text,
105 const gfx::Point& location) { 106 const gfx::Point& location) {
106 if (!EnsureTooltipWindow()) 107 if (!EnsureTooltipWindow())
107 return; 108 return;
108 109
109 // See comment in header for details on why |location_| is needed. 110 // See comment in header for details on why |location_| is needed.
110 location_ = location; 111 location_ = location;
111 112
112 // Without this we get a flicker of the tooltip appearing at 0x0. Not sure 113 // Without this we get a flicker of the tooltip appearing at 0x0. Not sure
113 // why. 114 // why.
114 SetWindowPos(tooltip_hwnd_, NULL, 0, 0, 0, 0, 115 SetWindowPos(tooltip_hwnd_, NULL, 0, 0, 0, 0,
115 SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | 116 SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE |
116 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); 117 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
117 118
118 base::string16 adjusted_text(tooltip_text); 119 base::string16 adjusted_text(tooltip_text);
119 base::i18n::AdjustStringForLocaleDirection(&adjusted_text); 120 base::i18n::AdjustStringForLocaleDirection(&adjusted_text);
120 toolinfo_.lpszText = const_cast<WCHAR*>(adjusted_text.c_str()); 121 toolinfo_.lpszText = const_cast<WCHAR*>(adjusted_text.c_str());
121 SendMessage(tooltip_hwnd_, TTM_SETTOOLINFO, 0, 122 SendMessage(tooltip_hwnd_, TTM_SETTOOLINFO, 0,
122 reinterpret_cast<LPARAM>(&toolinfo_)); 123 reinterpret_cast<LPARAM>(&toolinfo_));
123 124
124 // This code only runs for non-metro, so GetNativeScreen() is fine. 125 // This code only runs for non-metro, so GetNativeScreen() is fine.
126 const gfx::Point screen_point = gfx::win::DIPToScreenPoint(location_);
125 gfx::Display display( 127 gfx::Display display(
126 gfx::Screen::GetNativeScreen()->GetDisplayNearestPoint(location_)); 128 gfx::Screen::GetNativeScreen()->GetDisplayNearestPoint(screen_point));
127 const gfx::Rect monitor_bounds = display.bounds(); 129 const gfx::Rect monitor_bounds = display.bounds();
128 int max_width = (monitor_bounds.width() + 1) / 2; 130 int max_width = (monitor_bounds.width() + 1) / 2;
129 SendMessage(tooltip_hwnd_, TTM_SETMAXTIPWIDTH, 0, max_width); 131 SendMessage(tooltip_hwnd_, TTM_SETMAXTIPWIDTH, 0, max_width);
130 } 132 }
131 133
132 void TooltipWin::Show() { 134 void TooltipWin::Show() {
133 if (!EnsureTooltipWindow()) 135 if (!EnsureTooltipWindow())
134 return; 136 return;
135 137
136 SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE, 138 SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE,
137 TRUE, reinterpret_cast<LPARAM>(&toolinfo_)); 139 TRUE, reinterpret_cast<LPARAM>(&toolinfo_));
138 SetWindowPos(tooltip_hwnd_, HWND_TOPMOST, 0, 0, 0, 0, 140 SetWindowPos(tooltip_hwnd_, HWND_TOPMOST, 0, 0, 0, 0,
139 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE); 141 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE);
140 } 142 }
141 143
142 void TooltipWin::Hide() { 144 void TooltipWin::Hide() {
143 if (!tooltip_hwnd_) 145 if (!tooltip_hwnd_)
144 return; 146 return;
145 147
146 SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE, FALSE, 148 SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE, FALSE,
147 reinterpret_cast<LPARAM>(&toolinfo_)); 149 reinterpret_cast<LPARAM>(&toolinfo_));
148 } 150 }
149 151
150 bool TooltipWin::IsVisible() { 152 bool TooltipWin::IsVisible() {
151 return showing_; 153 return showing_;
152 } 154 }
153 155
154 } // namespace corewm 156 } // namespace corewm
155 } // namespace views 157 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698