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 <stddef.h> | 5 #include <stddef.h> |
6 #include <windows.h> | 6 #include <windows.h> |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 border_pen_(CreatePen(PS_SOLID, 5, | 114 border_pen_(CreatePen(PS_SOLID, 5, |
115 RGB(0.13 * 255, 0.69 * 255, 0.11 * 255))) { | 115 RGB(0.13 * 255, 0.69 * 255, 0.11 * 255))) { |
116 } | 116 } |
117 | 117 |
118 DisconnectWindowWin::~DisconnectWindowWin() { | 118 DisconnectWindowWin::~DisconnectWindowWin() { |
119 EndDialog(); | 119 EndDialog(); |
120 } | 120 } |
121 | 121 |
122 void DisconnectWindowWin::Start( | 122 void DisconnectWindowWin::Start( |
123 const base::WeakPtr<ClientSessionControl>& client_session_control) { | 123 const base::WeakPtr<ClientSessionControl>& client_session_control) { |
124 DCHECK(CalledOnValidThread()); | 124 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
125 DCHECK(!client_session_control_); | 125 DCHECK(!client_session_control_); |
126 DCHECK(client_session_control); | 126 DCHECK(client_session_control); |
127 | 127 |
128 client_session_control_ = client_session_control; | 128 client_session_control_ = client_session_control; |
129 | 129 |
130 std::string client_jid = client_session_control_->client_jid(); | 130 std::string client_jid = client_session_control_->client_jid(); |
131 username_ = client_jid.substr(0, client_jid.find('/')); | 131 username_ = client_jid.substr(0, client_jid.find('/')); |
132 if (!BeginDialog()) | 132 if (!BeginDialog()) |
133 EndDialog(); | 133 EndDialog(); |
134 } | 134 } |
(...skipping 19 matching lines...) Expand all Loading... |
154 return reinterpret_cast<DisconnectWindowWin*>(self)->OnDialogMessage( | 154 return reinterpret_cast<DisconnectWindowWin*>(self)->OnDialogMessage( |
155 hwnd, message, wparam, lparam); | 155 hwnd, message, wparam, lparam); |
156 } | 156 } |
157 return FALSE; | 157 return FALSE; |
158 } | 158 } |
159 | 159 |
160 BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, | 160 BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, |
161 UINT message, | 161 UINT message, |
162 WPARAM wparam, | 162 WPARAM wparam, |
163 LPARAM lparam) { | 163 LPARAM lparam) { |
164 DCHECK(CalledOnValidThread()); | 164 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
165 | 165 |
166 switch (message) { | 166 switch (message) { |
167 // Ignore close messages. | 167 // Ignore close messages. |
168 case WM_CLOSE: | 168 case WM_CLOSE: |
169 return TRUE; | 169 return TRUE; |
170 | 170 |
171 // Handle the Disconnect button. | 171 // Handle the Disconnect button. |
172 case WM_COMMAND: | 172 case WM_COMMAND: |
173 switch (LOWORD(wparam)) { | 173 switch (LOWORD(wparam)) { |
174 case IDC_DISCONNECT: | 174 case IDC_DISCONNECT: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 kWindowBorderRadius, kWindowBorderRadius); | 221 kWindowBorderRadius, kWindowBorderRadius); |
222 } | 222 } |
223 EndPaint(hwnd_, &ps); | 223 EndPaint(hwnd_, &ps); |
224 return TRUE; | 224 return TRUE; |
225 } | 225 } |
226 } | 226 } |
227 return FALSE; | 227 return FALSE; |
228 } | 228 } |
229 | 229 |
230 bool DisconnectWindowWin::BeginDialog() { | 230 bool DisconnectWindowWin::BeginDialog() { |
231 DCHECK(CalledOnValidThread()); | 231 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
232 DCHECK(!hwnd_); | 232 DCHECK(!hwnd_); |
233 | 233 |
234 hwnd_ = | 234 hwnd_ = |
235 CreateDialogParam(CURRENT_MODULE(), MAKEINTRESOURCE(IDD_DISCONNECT), | 235 CreateDialogParam(CURRENT_MODULE(), MAKEINTRESOURCE(IDD_DISCONNECT), |
236 nullptr, DialogProc, reinterpret_cast<LPARAM>(this)); | 236 nullptr, DialogProc, reinterpret_cast<LPARAM>(this)); |
237 if (!hwnd_) | 237 if (!hwnd_) |
238 return false; | 238 return false; |
239 | 239 |
240 // Set up handler for Ctrl-Alt-Esc shortcut. | 240 // Set up handler for Ctrl-Alt-Esc shortcut. |
241 if (!has_hotkey_ && RegisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID, | 241 if (!has_hotkey_ && RegisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID, |
242 MOD_ALT | MOD_CONTROL, VK_ESCAPE)) { | 242 MOD_ALT | MOD_CONTROL, VK_ESCAPE)) { |
243 has_hotkey_ = true; | 243 has_hotkey_ = true; |
244 } | 244 } |
245 | 245 |
246 if (!SetStrings()) | 246 if (!SetStrings()) |
247 return false; | 247 return false; |
248 | 248 |
249 SetDialogPosition(); | 249 SetDialogPosition(); |
250 ShowWindow(hwnd_, SW_SHOW); | 250 ShowWindow(hwnd_, SW_SHOW); |
251 return IsWindowVisible(hwnd_) != FALSE; | 251 return IsWindowVisible(hwnd_) != FALSE; |
252 } | 252 } |
253 | 253 |
254 void DisconnectWindowWin::EndDialog() { | 254 void DisconnectWindowWin::EndDialog() { |
255 DCHECK(CalledOnValidThread()); | 255 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
256 | 256 |
257 if (has_hotkey_) { | 257 if (has_hotkey_) { |
258 UnregisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID); | 258 UnregisterHotKey(hwnd_, DISCONNECT_HOTKEY_ID); |
259 has_hotkey_ = false; | 259 has_hotkey_ = false; |
260 } | 260 } |
261 | 261 |
262 if (hwnd_) { | 262 if (hwnd_) { |
263 DestroyWindow(hwnd_); | 263 DestroyWindow(hwnd_); |
264 hwnd_ = nullptr; | 264 hwnd_ = nullptr; |
265 } | 265 } |
266 | 266 |
267 if (client_session_control_) | 267 if (client_session_control_) |
268 client_session_control_->DisconnectSession(protocol::OK); | 268 client_session_control_->DisconnectSession(protocol::OK); |
269 } | 269 } |
270 | 270 |
271 // Returns |control| rectangle in the dialog coordinates. | 271 // Returns |control| rectangle in the dialog coordinates. |
272 bool DisconnectWindowWin::GetControlRect(HWND control, RECT* rect) { | 272 bool DisconnectWindowWin::GetControlRect(HWND control, RECT* rect) { |
273 if (!GetWindowRect(control, rect)) | 273 if (!GetWindowRect(control, rect)) |
274 return false; | 274 return false; |
275 SetLastError(ERROR_SUCCESS); | 275 SetLastError(ERROR_SUCCESS); |
276 int result = MapWindowPoints(HWND_DESKTOP, hwnd_, | 276 int result = MapWindowPoints(HWND_DESKTOP, hwnd_, |
277 reinterpret_cast<LPPOINT>(rect), 2); | 277 reinterpret_cast<LPPOINT>(rect), 2); |
278 if (!result && GetLastError() != ERROR_SUCCESS) | 278 if (!result && GetLastError() != ERROR_SUCCESS) |
279 return false; | 279 return false; |
280 | 280 |
281 return true; | 281 return true; |
282 } | 282 } |
283 | 283 |
284 void DisconnectWindowWin::SetDialogPosition() { | 284 void DisconnectWindowWin::SetDialogPosition() { |
285 DCHECK(CalledOnValidThread()); | 285 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
286 | 286 |
287 // Try to center the window above the task-bar. If that fails, use the | 287 // Try to center the window above the task-bar. If that fails, use the |
288 // primary monitor. If that fails (very unlikely), use the default position. | 288 // primary monitor. If that fails (very unlikely), use the default position. |
289 HWND taskbar = FindWindow(kShellTrayWindowName, nullptr); | 289 HWND taskbar = FindWindow(kShellTrayWindowName, nullptr); |
290 HMONITOR monitor = MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY); | 290 HMONITOR monitor = MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY); |
291 MONITORINFO monitor_info = {sizeof(monitor_info)}; | 291 MONITORINFO monitor_info = {sizeof(monitor_info)}; |
292 RECT window_rect; | 292 RECT window_rect; |
293 if (GetMonitorInfo(monitor, &monitor_info) && | 293 if (GetMonitorInfo(monitor, &monitor_info) && |
294 GetWindowRect(hwnd_, &window_rect)) { | 294 GetWindowRect(hwnd_, &window_rect)) { |
295 int window_width = window_rect.right - window_rect.left; | 295 int window_width = window_rect.right - window_rect.left; |
296 int window_height = window_rect.bottom - window_rect.top; | 296 int window_height = window_rect.bottom - window_rect.top; |
297 int top = monitor_info.rcWork.bottom - window_height; | 297 int top = monitor_info.rcWork.bottom - window_height; |
298 int left = (monitor_info.rcWork.right + monitor_info.rcWork.left - | 298 int left = (monitor_info.rcWork.right + monitor_info.rcWork.left - |
299 window_width) / 2; | 299 window_width) / 2; |
300 SetWindowPos(hwnd_, nullptr, left, top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); | 300 SetWindowPos(hwnd_, nullptr, left, top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); |
301 } | 301 } |
302 } | 302 } |
303 | 303 |
304 bool DisconnectWindowWin::SetStrings() { | 304 bool DisconnectWindowWin::SetStrings() { |
305 DCHECK(CalledOnValidThread()); | 305 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
306 | 306 |
307 // Localize the disconnect button text and measure length of the old and new | 307 // Localize the disconnect button text and measure length of the old and new |
308 // labels. | 308 // labels. |
309 HWND hwnd_button = GetDlgItem(hwnd_, IDC_DISCONNECT); | 309 HWND hwnd_button = GetDlgItem(hwnd_, IDC_DISCONNECT); |
310 HWND hwnd_message = GetDlgItem(hwnd_, IDC_DISCONNECT_SHARINGWITH); | 310 HWND hwnd_message = GetDlgItem(hwnd_, IDC_DISCONNECT_SHARINGWITH); |
311 if (!hwnd_button || !hwnd_message) | 311 if (!hwnd_button || !hwnd_message) |
312 return false; | 312 return false; |
313 | 313 |
314 base::string16 button_text; | 314 base::string16 button_text; |
315 base::string16 message_text; | 315 base::string16 message_text; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 } | 394 } |
395 | 395 |
396 } // namespace | 396 } // namespace |
397 | 397 |
398 // static | 398 // static |
399 std::unique_ptr<HostWindow> HostWindow::CreateDisconnectWindow() { | 399 std::unique_ptr<HostWindow> HostWindow::CreateDisconnectWindow() { |
400 return base::MakeUnique<DisconnectWindowWin>(); | 400 return base::MakeUnique<DisconnectWindowWin>(); |
401 } | 401 } |
402 | 402 |
403 } // namespace remoting | 403 } // namespace remoting |
OLD | NEW |