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" | |
19 | 17 |
20 using std::max; | 18 using std::max; |
21 using std::min; | 19 using std::min; |
22 | 20 |
23 namespace aura { | 21 namespace aura { |
24 namespace { | |
25 | |
26 bool use_popup_as_root_window_for_test = false; | |
27 | |
28 } // namespace | |
29 | 22 |
30 // static | 23 // static |
31 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { | 24 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { |
32 return new RootWindowHostWin(bounds); | 25 return new RootWindowHostWin(bounds); |
33 } | 26 } |
34 | 27 |
35 // static | 28 // static |
36 gfx::Size RootWindowHost::GetNativeScreenSize() { | 29 gfx::Size RootWindowHost::GetNativeScreenSize() { |
37 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), | 30 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), |
38 GetSystemMetrics(SM_CYSCREEN)); | 31 GetSystemMetrics(SM_CYSCREEN)); |
39 } | 32 } |
40 | 33 |
41 RootWindowHostWin::RootWindowHostWin(const gfx::Rect& bounds) | 34 RootWindowHostWin::RootWindowHostWin(const gfx::Rect& bounds) |
42 : delegate_(NULL), | 35 : delegate_(NULL), |
43 fullscreen_(false), | 36 fullscreen_(false), |
44 has_capture_(false), | 37 has_capture_(false), |
45 saved_window_style_(0), | 38 saved_window_style_(0), |
46 saved_window_ex_style_(0) { | 39 saved_window_ex_style_(0) { |
47 if (use_popup_as_root_window_for_test) | |
48 set_window_style(WS_POPUP); | |
49 Init(NULL, bounds); | 40 Init(NULL, bounds); |
50 SetWindowText(hwnd(), L"aura::RootWindow!"); | 41 SetWindowText(hwnd(), L"aura::RootWindow!"); |
51 } | 42 } |
52 | 43 |
53 RootWindowHostWin::~RootWindowHostWin() { | 44 RootWindowHostWin::~RootWindowHostWin() { |
54 DestroyWindow(hwnd()); | 45 DestroyWindow(hwnd()); |
55 } | 46 } |
56 | 47 |
57 void RootWindowHostWin::SetDelegate(RootWindowHostDelegate* delegate) { | 48 void RootWindowHostWin::SetDelegate(RootWindowHostDelegate* delegate) { |
58 delegate_ = delegate; | 49 delegate_ = delegate; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 window_rect.top = bounds.y(); | 114 window_rect.top = bounds.y(); |
124 window_rect.right = bounds.right() ; | 115 window_rect.right = bounds.right() ; |
125 window_rect.bottom = bounds.bottom(); | 116 window_rect.bottom = bounds.bottom(); |
126 AdjustWindowRectEx(&window_rect, | 117 AdjustWindowRectEx(&window_rect, |
127 GetWindowLong(hwnd(), GWL_STYLE), | 118 GetWindowLong(hwnd(), GWL_STYLE), |
128 FALSE, | 119 FALSE, |
129 GetWindowLong(hwnd(), GWL_EXSTYLE)); | 120 GetWindowLong(hwnd(), GWL_EXSTYLE)); |
130 SetWindowPos( | 121 SetWindowPos( |
131 hwnd(), | 122 hwnd(), |
132 NULL, | 123 NULL, |
133 window_rect.left, | 124 0, |
134 window_rect.top, | 125 0, |
135 window_rect.right - window_rect.left, | 126 window_rect.right - window_rect.left, |
136 window_rect.bottom - window_rect.top, | 127 window_rect.bottom - window_rect.top, |
137 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOREPOSITION); | 128 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()); | |
146 } | 129 } |
147 | 130 |
148 gfx::Point RootWindowHostWin::GetLocationOnNativeScreen() const { | 131 gfx::Point RootWindowHostWin::GetLocationOnNativeScreen() const { |
149 RECT r; | 132 RECT r; |
150 GetClientRect(hwnd(), &r); | 133 GetClientRect(hwnd(), &r); |
151 return gfx::Point(r.left, r.top); | 134 return gfx::Point(r.left, r.top); |
152 } | 135 } |
153 | 136 |
154 | 137 |
155 void RootWindowHostWin::SetCursor(gfx::NativeCursor native_cursor) { | 138 void RootWindowHostWin::SetCursor(gfx::NativeCursor native_cursor) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 ValidateRect(hwnd(), NULL); | 274 ValidateRect(hwnd(), NULL); |
292 } | 275 } |
293 | 276 |
294 void RootWindowHostWin::OnSize(UINT param, const CSize& size) { | 277 void RootWindowHostWin::OnSize(UINT param, const CSize& size) { |
295 // Minimizing resizes the window to 0x0 which causes our layout to go all | 278 // Minimizing resizes the window to 0x0 which causes our layout to go all |
296 // screwy, so we just ignore it. | 279 // screwy, so we just ignore it. |
297 if (param != SIZE_MINIMIZED) | 280 if (param != SIZE_MINIMIZED) |
298 delegate_->OnHostResized(gfx::Size(size.cx, size.cy)); | 281 delegate_->OnHostResized(gfx::Size(size.cx, size.cy)); |
299 } | 282 } |
300 | 283 |
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 | |
310 } // namespace aura | 284 } // namespace aura |
OLD | NEW |