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 "ui/aura/root_window_host_win.h" | 5 #include "ui/aura/root_window_host_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "ui/aura/client/capture_client.h" | 12 #include "ui/aura/client/capture_client.h" |
13 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
14 #include "ui/base/cursor/cursor_loader_win.h" | 14 #include "ui/base/cursor/cursor_loader_win.h" |
15 #include "ui/base/events/event.h" | 15 #include "ui/base/events/event.h" |
16 #include "ui/base/view_prop.h" | 16 #include "ui/base/view_prop.h" |
| 17 #include "ui/gfx/display.h" |
| 18 #include "ui/gfx/screen.h" |
17 | 19 |
18 using std::max; | 20 using std::max; |
19 using std::min; | 21 using std::min; |
20 | 22 |
21 namespace aura { | 23 namespace aura { |
| 24 namespace { |
| 25 |
| 26 bool use_popup_as_root_window_for_test = false; |
| 27 |
| 28 } // namespace |
22 | 29 |
23 // static | 30 // static |
24 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { | 31 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { |
25 return new RootWindowHostWin(bounds); | 32 return new RootWindowHostWin(bounds); |
26 } | 33 } |
27 | 34 |
28 // static | 35 // static |
29 gfx::Size RootWindowHost::GetNativeScreenSize() { | 36 gfx::Size RootWindowHost::GetNativeScreenSize() { |
30 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), | 37 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), |
31 GetSystemMetrics(SM_CYSCREEN)); | 38 GetSystemMetrics(SM_CYSCREEN)); |
32 } | 39 } |
33 | 40 |
34 RootWindowHostWin::RootWindowHostWin(const gfx::Rect& bounds) | 41 RootWindowHostWin::RootWindowHostWin(const gfx::Rect& bounds) |
35 : delegate_(NULL), | 42 : delegate_(NULL), |
36 fullscreen_(false), | 43 fullscreen_(false), |
37 has_capture_(false), | 44 has_capture_(false), |
38 saved_window_style_(0), | 45 saved_window_style_(0), |
39 saved_window_ex_style_(0) { | 46 saved_window_ex_style_(0) { |
| 47 if (use_popup_as_root_window_for_test) |
| 48 set_window_style(WS_POPUP); |
40 Init(NULL, bounds); | 49 Init(NULL, bounds); |
41 SetWindowText(hwnd(), L"aura::RootWindow!"); | 50 SetWindowText(hwnd(), L"aura::RootWindow!"); |
42 } | 51 } |
43 | 52 |
44 RootWindowHostWin::~RootWindowHostWin() { | 53 RootWindowHostWin::~RootWindowHostWin() { |
45 DestroyWindow(hwnd()); | 54 DestroyWindow(hwnd()); |
46 } | 55 } |
47 | 56 |
48 void RootWindowHostWin::SetDelegate(RootWindowHostDelegate* delegate) { | 57 void RootWindowHostWin::SetDelegate(RootWindowHostDelegate* delegate) { |
49 delegate_ = delegate; | 58 delegate_ = delegate; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 window_rect.top = bounds.y(); | 123 window_rect.top = bounds.y(); |
115 window_rect.right = bounds.right() ; | 124 window_rect.right = bounds.right() ; |
116 window_rect.bottom = bounds.bottom(); | 125 window_rect.bottom = bounds.bottom(); |
117 AdjustWindowRectEx(&window_rect, | 126 AdjustWindowRectEx(&window_rect, |
118 GetWindowLong(hwnd(), GWL_STYLE), | 127 GetWindowLong(hwnd(), GWL_STYLE), |
119 FALSE, | 128 FALSE, |
120 GetWindowLong(hwnd(), GWL_EXSTYLE)); | 129 GetWindowLong(hwnd(), GWL_EXSTYLE)); |
121 SetWindowPos( | 130 SetWindowPos( |
122 hwnd(), | 131 hwnd(), |
123 NULL, | 132 NULL, |
124 0, | 133 window_rect.left, |
125 0, | 134 window_rect.top, |
126 window_rect.right - window_rect.left, | 135 window_rect.right - window_rect.left, |
127 window_rect.bottom - window_rect.top, | 136 window_rect.bottom - window_rect.top, |
128 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOREPOSITION); | 137 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOREPOSITION); |
| 138 |
| 139 // Explicity call OnHostResized when the scale has changed because |
| 140 // the window size may not have changed. |
| 141 float current_scale = delegate_->GetDeviceScaleFactor(); |
| 142 float new_scale = gfx::Screen::GetScreenFor(delegate_->AsRootWindow())-> |
| 143 GetDisplayNearestWindow(delegate_->AsRootWindow()).device_scale_factor(); |
| 144 if (current_scale != new_scale) |
| 145 delegate_->OnHostResized(bounds.size()); |
129 } | 146 } |
130 | 147 |
131 gfx::Point RootWindowHostWin::GetLocationOnNativeScreen() const { | 148 gfx::Point RootWindowHostWin::GetLocationOnNativeScreen() const { |
132 RECT r; | 149 RECT r; |
133 GetClientRect(hwnd(), &r); | 150 GetClientRect(hwnd(), &r); |
134 return gfx::Point(r.left, r.top); | 151 return gfx::Point(r.left, r.top); |
135 } | 152 } |
136 | 153 |
137 | 154 |
138 void RootWindowHostWin::SetCursor(gfx::NativeCursor native_cursor) { | 155 void RootWindowHostWin::SetCursor(gfx::NativeCursor native_cursor) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 ValidateRect(hwnd(), NULL); | 291 ValidateRect(hwnd(), NULL); |
275 } | 292 } |
276 | 293 |
277 void RootWindowHostWin::OnSize(UINT param, const CSize& size) { | 294 void RootWindowHostWin::OnSize(UINT param, const CSize& size) { |
278 // Minimizing resizes the window to 0x0 which causes our layout to go all | 295 // Minimizing resizes the window to 0x0 which causes our layout to go all |
279 // screwy, so we just ignore it. | 296 // screwy, so we just ignore it. |
280 if (param != SIZE_MINIMIZED) | 297 if (param != SIZE_MINIMIZED) |
281 delegate_->OnHostResized(gfx::Size(size.cx, size.cy)); | 298 delegate_->OnHostResized(gfx::Size(size.cx, size.cy)); |
282 } | 299 } |
283 | 300 |
| 301 namespace test { |
| 302 |
| 303 // static |
| 304 void SetUsePopupAsRootWindowForTest(bool use) { |
| 305 use_popup_as_root_window_for_test = use; |
| 306 } |
| 307 |
| 308 } // namespace test |
| 309 |
284 } // namespace aura | 310 } // namespace aura |
OLD | NEW |