Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/host/setup/win/host_configurer_window.h" | |
| 6 | |
| 7 #include <atlbase.h> | |
| 8 #include <atlstr.h> | |
| 9 #include <atlwin.h> | |
| 10 #include <windows.h> | |
| 11 | |
| 12 #include "base/run_loop.h" | |
| 13 #include "base/string16.h" | |
| 14 #include "remoting/host/setup/win/load_string_from_resource.h" | |
| 15 #include "remoting/host/setup/win/start_host_window.h" | |
| 16 | |
| 17 namespace remoting { | |
| 18 | |
| 19 HostConfigurerWindow::HostConfigurerWindow( | |
| 20 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | |
| 21 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | |
| 22 base::Closure quit) | |
| 23 : url_request_context_getter_(url_request_context_getter), | |
| 24 ui_task_runner_(ui_task_runner), | |
| 25 quit_(quit) { | |
| 26 } | |
| 27 | |
| 28 void HostConfigurerWindow::OnCancel(UINT code, int id, HWND control) { | |
| 29 Finish(); | |
| 30 } | |
| 31 | |
| 32 void HostConfigurerWindow::OnClose() { | |
| 33 Finish(); | |
| 34 } | |
| 35 | |
| 36 LRESULT HostConfigurerWindow::OnInitDialog(HWND wparam, LPARAM lparam) { | |
| 37 SetWindowText(LoadStringFromResource(IDS_TITLE)); | |
| 38 GetDlgItem(IDC_CHANGE_PIN).EnableWindow(FALSE); | |
|
alexeypa (please no reviews)
2012/10/15 18:48:55
nit: I'm not fun of zillions of UI calls none of t
simonmorris
2012/10/15 21:20:14
I've added comments indicating that it's acceptabl
| |
| 39 GetDlgItem(IDC_STOP_HOST).EnableWindow(FALSE); | |
| 40 PositionWindow(); | |
| 41 return TRUE; | |
| 42 } | |
| 43 | |
| 44 void HostConfigurerWindow::OnOk(UINT code, int id, HWND control) { | |
| 45 Finish(); | |
| 46 } | |
| 47 | |
| 48 void HostConfigurerWindow::OnStartHost(UINT code, int id, HWND control) { | |
| 49 StartHostWindow start_host_window(url_request_context_getter_, | |
| 50 ui_task_runner_); | |
| 51 start_host_window.DoModal(); | |
| 52 } | |
| 53 | |
| 54 void HostConfigurerWindow::PositionWindow() { | |
| 55 // Get the window dimensions. | |
| 56 RECT rect; | |
| 57 if (!GetWindowRect(&rect)) { | |
| 58 return; | |
| 59 } | |
| 60 | |
| 61 // Position against the owner window unless it is minimized or invisible. | |
| 62 HWND owner = ::GetWindow(m_hWnd, GW_OWNER); | |
| 63 if (owner != NULL) { | |
| 64 DWORD style = ::GetWindowLong(owner, GWL_STYLE); | |
| 65 if ((style & WS_MINIMIZE) != 0 || (style & WS_VISIBLE) == 0) { | |
| 66 owner = NULL; | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 // Make sure that the window will not end up split by a monitor's boundary. | |
| 71 RECT area_rect; | |
| 72 if (!::SystemParametersInfo(SPI_GETWORKAREA, NULL, &area_rect, NULL)) { | |
| 73 return; | |
| 74 } | |
| 75 | |
| 76 // On a multi-monitor system use the monitor where the owner window is shown. | |
| 77 RECT owner_rect = area_rect; | |
| 78 if (owner != NULL && ::GetWindowRect(owner, &owner_rect)) { | |
| 79 HMONITOR monitor = ::MonitorFromRect(&owner_rect, MONITOR_DEFAULTTONEAREST); | |
| 80 if (monitor != NULL) { | |
| 81 MONITORINFO monitor_info = {0}; | |
| 82 monitor_info.cbSize = sizeof(monitor_info); | |
| 83 if (::GetMonitorInfo(monitor, &monitor_info)) { | |
| 84 area_rect = monitor_info.rcWork; | |
| 85 } | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 LONG width = rect.right - rect.left; | |
| 90 LONG height = rect.bottom - rect.top; | |
| 91 // Avoid the center of the owner rectangle, because the host controller will | |
| 92 // put its confirmation window there. | |
| 93 LONG x = (3 * owner_rect.left + owner_rect.right) / 4 - (width / 2); | |
| 94 LONG y = (3 * owner_rect.top + owner_rect.bottom) / 4 - (height / 2); | |
| 95 | |
| 96 x = std::max(x, area_rect.left); | |
| 97 x = std::min(x, area_rect.right - width); | |
| 98 y = std::max(y, area_rect.top); | |
| 99 y = std::min(y, area_rect.bottom - width); | |
| 100 | |
| 101 SetWindowPos(NULL, x, y, -1, -1, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); | |
| 102 } | |
| 103 | |
| 104 void HostConfigurerWindow::Finish() { | |
| 105 DestroyWindow(); | |
|
alexeypa (please no reviews)
2012/10/15 18:48:55
DestroyWindow() should be called on the same threa
simonmorris
2012/10/15 21:20:14
Done.
| |
| 106 ui_task_runner_->PostTask(FROM_HERE, quit_); | |
|
alexeypa (please no reviews)
2012/10/15 18:48:55
This function is probably running on the UI thread
simonmorris
2012/10/15 21:20:14
Done.
| |
| 107 } | |
| 108 | |
| 109 } // namespace remoting | |
| OLD | NEW |