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 |
(...skipping 11 matching lines...) Expand all Loading... |
22 using std::min; | 22 using std::min; |
23 | 23 |
24 namespace aura { | 24 namespace aura { |
25 namespace { | 25 namespace { |
26 | 26 |
27 bool use_popup_as_root_window_for_test = false; | 27 bool use_popup_as_root_window_for_test = false; |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 // static | 31 // static |
32 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { | 32 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { |
33 return new RootWindowHostWin(bounds); | 33 return new WindowTreeHostWin(bounds); |
34 } | 34 } |
35 | 35 |
36 // static | 36 // static |
37 gfx::Size RootWindowHost::GetNativeScreenSize() { | 37 gfx::Size WindowTreeHost::GetNativeScreenSize() { |
38 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), | 38 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), |
39 GetSystemMetrics(SM_CYSCREEN)); | 39 GetSystemMetrics(SM_CYSCREEN)); |
40 } | 40 } |
41 | 41 |
42 RootWindowHostWin::RootWindowHostWin(const gfx::Rect& bounds) | 42 WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect& bounds) |
43 : fullscreen_(false), | 43 : fullscreen_(false), |
44 has_capture_(false), | 44 has_capture_(false), |
45 saved_window_style_(0), | 45 saved_window_style_(0), |
46 saved_window_ex_style_(0) { | 46 saved_window_ex_style_(0) { |
47 if (use_popup_as_root_window_for_test) | 47 if (use_popup_as_root_window_for_test) |
48 set_window_style(WS_POPUP); | 48 set_window_style(WS_POPUP); |
49 Init(NULL, bounds); | 49 Init(NULL, bounds); |
50 SetWindowText(hwnd(), L"aura::RootWindow!"); | 50 SetWindowText(hwnd(), L"aura::RootWindow!"); |
51 CreateCompositor(GetAcceleratedWidget()); | 51 CreateCompositor(GetAcceleratedWidget()); |
52 } | 52 } |
53 | 53 |
54 RootWindowHostWin::~RootWindowHostWin() { | 54 WindowTreeHostWin::~WindowTreeHostWin() { |
55 DestroyWindow(hwnd()); | 55 DestroyWindow(hwnd()); |
56 } | 56 } |
57 | 57 |
58 RootWindow* RootWindowHostWin::GetRootWindow() { | 58 RootWindow* WindowTreeHostWin::GetRootWindow() { |
59 return delegate_->AsRootWindow(); | 59 return delegate_->AsRootWindow(); |
60 } | 60 } |
61 | 61 |
62 gfx::AcceleratedWidget RootWindowHostWin::GetAcceleratedWidget() { | 62 gfx::AcceleratedWidget WindowTreeHostWin::GetAcceleratedWidget() { |
63 return hwnd(); | 63 return hwnd(); |
64 } | 64 } |
65 | 65 |
66 void RootWindowHostWin::Show() { | 66 void WindowTreeHostWin::Show() { |
67 ShowWindow(hwnd(), SW_SHOWNORMAL); | 67 ShowWindow(hwnd(), SW_SHOWNORMAL); |
68 } | 68 } |
69 | 69 |
70 void RootWindowHostWin::Hide() { | 70 void WindowTreeHostWin::Hide() { |
71 NOTIMPLEMENTED(); | 71 NOTIMPLEMENTED(); |
72 } | 72 } |
73 | 73 |
74 void RootWindowHostWin::ToggleFullScreen() { | 74 void WindowTreeHostWin::ToggleFullScreen() { |
75 gfx::Rect target_rect; | 75 gfx::Rect target_rect; |
76 if (!fullscreen_) { | 76 if (!fullscreen_) { |
77 fullscreen_ = true; | 77 fullscreen_ = true; |
78 saved_window_style_ = GetWindowLong(hwnd(), GWL_STYLE); | 78 saved_window_style_ = GetWindowLong(hwnd(), GWL_STYLE); |
79 saved_window_ex_style_ = GetWindowLong(hwnd(), GWL_EXSTYLE); | 79 saved_window_ex_style_ = GetWindowLong(hwnd(), GWL_EXSTYLE); |
80 GetWindowRect(hwnd(), &saved_window_rect_); | 80 GetWindowRect(hwnd(), &saved_window_rect_); |
81 SetWindowLong(hwnd(), GWL_STYLE, | 81 SetWindowLong(hwnd(), GWL_STYLE, |
82 saved_window_style_ & ~(WS_CAPTION | WS_THICKFRAME)); | 82 saved_window_style_ & ~(WS_CAPTION | WS_THICKFRAME)); |
83 SetWindowLong(hwnd(), GWL_EXSTYLE, | 83 SetWindowLong(hwnd(), GWL_EXSTYLE, |
84 saved_window_ex_style_ & ~(WS_EX_DLGMODALFRAME | | 84 saved_window_ex_style_ & ~(WS_EX_DLGMODALFRAME | |
(...skipping 11 matching lines...) Expand all Loading... |
96 } | 96 } |
97 SetWindowPos(hwnd(), | 97 SetWindowPos(hwnd(), |
98 NULL, | 98 NULL, |
99 target_rect.x(), | 99 target_rect.x(), |
100 target_rect.y(), | 100 target_rect.y(), |
101 target_rect.width(), | 101 target_rect.width(), |
102 target_rect.height(), | 102 target_rect.height(), |
103 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); | 103 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); |
104 } | 104 } |
105 | 105 |
106 gfx::Rect RootWindowHostWin::GetBounds() const { | 106 gfx::Rect WindowTreeHostWin::GetBounds() const { |
107 RECT r; | 107 RECT r; |
108 GetClientRect(hwnd(), &r); | 108 GetClientRect(hwnd(), &r); |
109 return gfx::Rect(r); | 109 return gfx::Rect(r); |
110 } | 110 } |
111 | 111 |
112 void RootWindowHostWin::SetBounds(const gfx::Rect& bounds) { | 112 void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) { |
113 if (fullscreen_) { | 113 if (fullscreen_) { |
114 saved_window_rect_.right = saved_window_rect_.left + bounds.width(); | 114 saved_window_rect_.right = saved_window_rect_.left + bounds.width(); |
115 saved_window_rect_.bottom = saved_window_rect_.top + bounds.height(); | 115 saved_window_rect_.bottom = saved_window_rect_.top + bounds.height(); |
116 return; | 116 return; |
117 } | 117 } |
118 RECT window_rect; | 118 RECT window_rect; |
119 window_rect.left = bounds.x(); | 119 window_rect.left = bounds.x(); |
120 window_rect.top = bounds.y(); | 120 window_rect.top = bounds.y(); |
121 window_rect.right = bounds.right() ; | 121 window_rect.right = bounds.right() ; |
122 window_rect.bottom = bounds.bottom(); | 122 window_rect.bottom = bounds.bottom(); |
(...skipping 13 matching lines...) Expand all Loading... |
136 // Explicity call NotifyHostResized when the scale has changed because | 136 // Explicity call NotifyHostResized when the scale has changed because |
137 // the window size may not have changed. | 137 // the window size may not have changed. |
138 float current_scale = compositor()->device_scale_factor(); | 138 float current_scale = compositor()->device_scale_factor(); |
139 float new_scale = gfx::Screen::GetScreenFor( | 139 float new_scale = gfx::Screen::GetScreenFor( |
140 delegate_->AsRootWindow()->window())->GetDisplayNearestWindow( | 140 delegate_->AsRootWindow()->window())->GetDisplayNearestWindow( |
141 delegate_->AsRootWindow()->window()).device_scale_factor(); | 141 delegate_->AsRootWindow()->window()).device_scale_factor(); |
142 if (current_scale != new_scale) | 142 if (current_scale != new_scale) |
143 NotifyHostResized(bounds.size()); | 143 NotifyHostResized(bounds.size()); |
144 } | 144 } |
145 | 145 |
146 gfx::Insets RootWindowHostWin::GetInsets() const { | 146 gfx::Insets WindowTreeHostWin::GetInsets() const { |
147 return gfx::Insets(); | 147 return gfx::Insets(); |
148 } | 148 } |
149 | 149 |
150 void RootWindowHostWin::SetInsets(const gfx::Insets& insets) { | 150 void WindowTreeHostWin::SetInsets(const gfx::Insets& insets) { |
151 } | 151 } |
152 | 152 |
153 gfx::Point RootWindowHostWin::GetLocationOnNativeScreen() const { | 153 gfx::Point WindowTreeHostWin::GetLocationOnNativeScreen() const { |
154 RECT r; | 154 RECT r; |
155 GetClientRect(hwnd(), &r); | 155 GetClientRect(hwnd(), &r); |
156 return gfx::Point(r.left, r.top); | 156 return gfx::Point(r.left, r.top); |
157 } | 157 } |
158 | 158 |
159 | 159 |
160 void RootWindowHostWin::SetCursor(gfx::NativeCursor native_cursor) { | 160 void WindowTreeHostWin::SetCursor(gfx::NativeCursor native_cursor) { |
161 // Custom web cursors are handled directly. | 161 // Custom web cursors are handled directly. |
162 if (native_cursor == ui::kCursorCustom) | 162 if (native_cursor == ui::kCursorCustom) |
163 return; | 163 return; |
164 | 164 |
165 ui::CursorLoaderWin cursor_loader; | 165 ui::CursorLoaderWin cursor_loader; |
166 cursor_loader.SetPlatformCursor(&native_cursor); | 166 cursor_loader.SetPlatformCursor(&native_cursor); |
167 ::SetCursor(native_cursor.platform()); | 167 ::SetCursor(native_cursor.platform()); |
168 } | 168 } |
169 | 169 |
170 void RootWindowHostWin::SetCapture() { | 170 void WindowTreeHostWin::SetCapture() { |
171 if (!has_capture_) { | 171 if (!has_capture_) { |
172 has_capture_ = true; | 172 has_capture_ = true; |
173 ::SetCapture(hwnd()); | 173 ::SetCapture(hwnd()); |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 void RootWindowHostWin::ReleaseCapture() { | 177 void WindowTreeHostWin::ReleaseCapture() { |
178 if (has_capture_) { | 178 if (has_capture_) { |
179 has_capture_ = false; | 179 has_capture_ = false; |
180 ::ReleaseCapture(); | 180 ::ReleaseCapture(); |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 bool RootWindowHostWin::QueryMouseLocation(gfx::Point* location_return) { | 184 bool WindowTreeHostWin::QueryMouseLocation(gfx::Point* location_return) { |
185 client::CursorClient* cursor_client = | 185 client::CursorClient* cursor_client = |
186 client::GetCursorClient(GetRootWindow()->window()); | 186 client::GetCursorClient(GetRootWindow()->window()); |
187 if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { | 187 if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { |
188 *location_return = gfx::Point(0, 0); | 188 *location_return = gfx::Point(0, 0); |
189 return false; | 189 return false; |
190 } | 190 } |
191 | 191 |
192 POINT pt; | 192 POINT pt; |
193 GetCursorPos(&pt); | 193 GetCursorPos(&pt); |
194 ScreenToClient(hwnd(), &pt); | 194 ScreenToClient(hwnd(), &pt); |
195 const gfx::Size size = GetBounds().size(); | 195 const gfx::Size size = GetBounds().size(); |
196 *location_return = | 196 *location_return = |
197 gfx::Point(max(0, min(size.width(), static_cast<int>(pt.x))), | 197 gfx::Point(max(0, min(size.width(), static_cast<int>(pt.x))), |
198 max(0, min(size.height(), static_cast<int>(pt.y)))); | 198 max(0, min(size.height(), static_cast<int>(pt.y)))); |
199 return (pt.x >= 0 && static_cast<int>(pt.x) < size.width() && | 199 return (pt.x >= 0 && static_cast<int>(pt.x) < size.width() && |
200 pt.y >= 0 && static_cast<int>(pt.y) < size.height()); | 200 pt.y >= 0 && static_cast<int>(pt.y) < size.height()); |
201 } | 201 } |
202 | 202 |
203 bool RootWindowHostWin::ConfineCursorToRootWindow() { | 203 bool WindowTreeHostWin::ConfineCursorToRootWindow() { |
204 RECT window_rect; | 204 RECT window_rect; |
205 GetWindowRect(hwnd(), &window_rect); | 205 GetWindowRect(hwnd(), &window_rect); |
206 return ClipCursor(&window_rect) != 0; | 206 return ClipCursor(&window_rect) != 0; |
207 } | 207 } |
208 | 208 |
209 void RootWindowHostWin::UnConfineCursor() { | 209 void WindowTreeHostWin::UnConfineCursor() { |
210 ClipCursor(NULL); | 210 ClipCursor(NULL); |
211 } | 211 } |
212 | 212 |
213 void RootWindowHostWin::OnCursorVisibilityChanged(bool show) { | 213 void WindowTreeHostWin::OnCursorVisibilityChanged(bool show) { |
214 NOTIMPLEMENTED(); | 214 NOTIMPLEMENTED(); |
215 } | 215 } |
216 | 216 |
217 void RootWindowHostWin::MoveCursorTo(const gfx::Point& location) { | 217 void WindowTreeHostWin::MoveCursorTo(const gfx::Point& location) { |
218 // Deliberately not implemented. | 218 // Deliberately not implemented. |
219 } | 219 } |
220 | 220 |
221 void RootWindowHostWin::PostNativeEvent(const base::NativeEvent& native_event) { | 221 void WindowTreeHostWin::PostNativeEvent(const base::NativeEvent& native_event) { |
222 ::PostMessage( | 222 ::PostMessage( |
223 hwnd(), native_event.message, native_event.wParam, native_event.lParam); | 223 hwnd(), native_event.message, native_event.wParam, native_event.lParam); |
224 } | 224 } |
225 | 225 |
226 void RootWindowHostWin::OnDeviceScaleFactorChanged( | 226 void WindowTreeHostWin::OnDeviceScaleFactorChanged( |
227 float device_scale_factor) { | 227 float device_scale_factor) { |
228 NOTIMPLEMENTED(); | 228 NOTIMPLEMENTED(); |
229 } | 229 } |
230 | 230 |
231 void RootWindowHostWin::PrepareForShutdown() { | 231 void WindowTreeHostWin::PrepareForShutdown() { |
232 NOTIMPLEMENTED(); | 232 NOTIMPLEMENTED(); |
233 } | 233 } |
234 | 234 |
235 void RootWindowHostWin::OnClose() { | 235 void WindowTreeHostWin::OnClose() { |
236 // TODO: this obviously shouldn't be here. | 236 // TODO: this obviously shouldn't be here. |
237 base::MessageLoopForUI::current()->Quit(); | 237 base::MessageLoopForUI::current()->Quit(); |
238 } | 238 } |
239 | 239 |
240 LRESULT RootWindowHostWin::OnKeyEvent(UINT message, | 240 LRESULT WindowTreeHostWin::OnKeyEvent(UINT message, |
241 WPARAM w_param, | 241 WPARAM w_param, |
242 LPARAM l_param) { | 242 LPARAM l_param) { |
243 MSG msg = { hwnd(), message, w_param, l_param }; | 243 MSG msg = { hwnd(), message, w_param, l_param }; |
244 ui::KeyEvent keyev(msg, message == WM_CHAR); | 244 ui::KeyEvent keyev(msg, message == WM_CHAR); |
245 SetMsgHandled(delegate_->OnHostKeyEvent(&keyev)); | 245 SetMsgHandled(delegate_->OnHostKeyEvent(&keyev)); |
246 return 0; | 246 return 0; |
247 } | 247 } |
248 | 248 |
249 LRESULT RootWindowHostWin::OnMouseRange(UINT message, | 249 LRESULT WindowTreeHostWin::OnMouseRange(UINT message, |
250 WPARAM w_param, | 250 WPARAM w_param, |
251 LPARAM l_param) { | 251 LPARAM l_param) { |
252 MSG msg = { hwnd(), message, w_param, l_param, 0, | 252 MSG msg = { hwnd(), message, w_param, l_param, 0, |
253 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; | 253 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; |
254 ui::MouseEvent event(msg); | 254 ui::MouseEvent event(msg); |
255 bool handled = false; | 255 bool handled = false; |
256 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) | 256 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) |
257 handled = delegate_->OnHostMouseEvent(&event); | 257 handled = delegate_->OnHostMouseEvent(&event); |
258 SetMsgHandled(handled); | 258 SetMsgHandled(handled); |
259 return 0; | 259 return 0; |
260 } | 260 } |
261 | 261 |
262 LRESULT RootWindowHostWin::OnCaptureChanged(UINT message, | 262 LRESULT WindowTreeHostWin::OnCaptureChanged(UINT message, |
263 WPARAM w_param, | 263 WPARAM w_param, |
264 LPARAM l_param) { | 264 LPARAM l_param) { |
265 if (has_capture_) { | 265 if (has_capture_) { |
266 has_capture_ = false; | 266 has_capture_ = false; |
267 delegate_->OnHostLostWindowCapture(); | 267 delegate_->OnHostLostWindowCapture(); |
268 } | 268 } |
269 return 0; | 269 return 0; |
270 } | 270 } |
271 | 271 |
272 LRESULT RootWindowHostWin::OnNCActivate(UINT message, | 272 LRESULT WindowTreeHostWin::OnNCActivate(UINT message, |
273 WPARAM w_param, | 273 WPARAM w_param, |
274 LPARAM l_param) { | 274 LPARAM l_param) { |
275 if (!!w_param) | 275 if (!!w_param) |
276 delegate_->OnHostActivated(); | 276 delegate_->OnHostActivated(); |
277 return DefWindowProc(hwnd(), message, w_param, l_param); | 277 return DefWindowProc(hwnd(), message, w_param, l_param); |
278 } | 278 } |
279 | 279 |
280 void RootWindowHostWin::OnMove(const CPoint& point) { | 280 void WindowTreeHostWin::OnMove(const CPoint& point) { |
281 if (delegate_) | 281 if (delegate_) |
282 delegate_->OnHostMoved(gfx::Point(point.x, point.y)); | 282 delegate_->OnHostMoved(gfx::Point(point.x, point.y)); |
283 } | 283 } |
284 | 284 |
285 void RootWindowHostWin::OnPaint(HDC dc) { | 285 void WindowTreeHostWin::OnPaint(HDC dc) { |
286 gfx::Rect damage_rect; | 286 gfx::Rect damage_rect; |
287 RECT update_rect = {0}; | 287 RECT update_rect = {0}; |
288 if (GetUpdateRect(hwnd(), &update_rect, FALSE)) | 288 if (GetUpdateRect(hwnd(), &update_rect, FALSE)) |
289 damage_rect = gfx::Rect(update_rect); | 289 damage_rect = gfx::Rect(update_rect); |
290 compositor()->ScheduleRedrawRect(damage_rect); | 290 compositor()->ScheduleRedrawRect(damage_rect); |
291 ValidateRect(hwnd(), NULL); | 291 ValidateRect(hwnd(), NULL); |
292 } | 292 } |
293 | 293 |
294 void RootWindowHostWin::OnSize(UINT param, const CSize& size) { | 294 void WindowTreeHostWin::OnSize(UINT param, const CSize& size) { |
295 // 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 |
296 // screwy, so we just ignore it. | 296 // screwy, so we just ignore it. |
297 if (delegate_ && param != SIZE_MINIMIZED) | 297 if (delegate_ && param != SIZE_MINIMIZED) |
298 NotifyHostResized(gfx::Size(size.cx, size.cy)); | 298 NotifyHostResized(gfx::Size(size.cx, size.cy)); |
299 } | 299 } |
300 | 300 |
301 namespace test { | 301 namespace test { |
302 | 302 |
303 // static | 303 // static |
304 void SetUsePopupAsRootWindowForTest(bool use) { | 304 void SetUsePopupAsRootWindowForTest(bool use) { |
305 use_popup_as_root_window_for_test = use; | 305 use_popup_as_root_window_for_test = use; |
306 } | 306 } |
307 | 307 |
308 } // namespace test | 308 } // namespace test |
309 | 309 |
310 } // namespace aura | 310 } // namespace aura |
OLD | NEW |