OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/desktop_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/desktop.h" | 12 #include "ui/aura/root_window.h" |
13 #include "ui/aura/event.h" | 13 #include "ui/aura/event.h" |
14 | 14 |
15 using std::max; | 15 using std::max; |
16 using std::min; | 16 using std::min; |
17 | 17 |
18 namespace aura { | 18 namespace aura { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const wchar_t* GetCursorId(gfx::NativeCursor native_cursor) { | 22 const wchar_t* GetCursorId(gfx::NativeCursor native_cursor) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return IDC_ARROW; | 95 return IDC_ARROW; |
96 default: | 96 default: |
97 NOTREACHED(); | 97 NOTREACHED(); |
98 return IDC_ARROW; | 98 return IDC_ARROW; |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 } // namespace | 102 } // namespace |
103 | 103 |
104 // static | 104 // static |
105 DesktopHost* DesktopHost::Create(const gfx::Rect& bounds) { | 105 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { |
106 return new DesktopHostWin(bounds); | 106 return new RootWindowHostWin(bounds); |
107 } | 107 } |
108 | 108 |
109 // static | 109 // static |
110 gfx::Size DesktopHost::GetNativeScreenSize() { | 110 gfx::Size RootWindowHost::GetNativeScreenSize() { |
111 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), | 111 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), |
112 GetSystemMetrics(SM_CYSCREEN)); | 112 GetSystemMetrics(SM_CYSCREEN)); |
113 } | 113 } |
114 | 114 |
115 DesktopHostWin::DesktopHostWin(const gfx::Rect& bounds) | 115 RootWindowHostWin::RootWindowHostWin(const gfx::Rect& bounds) |
116 : desktop_(NULL), | 116 : root_window_(NULL), |
117 fullscreen_(false), | 117 fullscreen_(false), |
118 saved_window_style_(0), | 118 saved_window_style_(0), |
119 saved_window_ex_style_(0) { | 119 saved_window_ex_style_(0) { |
120 Init(NULL, bounds); | 120 Init(NULL, bounds); |
121 SetWindowText(hwnd(), L"aura::Desktop!"); | 121 SetWindowText(hwnd(), L"aura::RootWindow!"); |
122 } | 122 } |
123 | 123 |
124 DesktopHostWin::~DesktopHostWin() { | 124 RootWindowHostWin::~RootWindowHostWin() { |
125 DestroyWindow(hwnd()); | 125 DestroyWindow(hwnd()); |
126 } | 126 } |
127 | 127 |
128 bool DesktopHostWin::Dispatch(const MSG& msg) { | 128 bool RootWindowHostWin::Dispatch(const MSG& msg) { |
129 TranslateMessage(&msg); | 129 TranslateMessage(&msg); |
130 DispatchMessage(&msg); | 130 DispatchMessage(&msg); |
131 return true; | 131 return true; |
132 } | 132 } |
133 | 133 |
134 void DesktopHostWin::SetDesktop(Desktop* desktop) { | 134 void RootWindowHostWin::SetRootWindow(RootWindow* root_window) { |
135 desktop_ = desktop; | 135 root_window_ = root_window; |
136 } | 136 } |
137 | 137 |
138 gfx::AcceleratedWidget DesktopHostWin::GetAcceleratedWidget() { | 138 gfx::AcceleratedWidget RootWindowHostWin::GetAcceleratedWidget() { |
139 return hwnd(); | 139 return hwnd(); |
140 } | 140 } |
141 | 141 |
142 void DesktopHostWin::Show() { | 142 void RootWindowHostWin::Show() { |
143 ShowWindow(hwnd(), SW_SHOWNORMAL); | 143 ShowWindow(hwnd(), SW_SHOWNORMAL); |
144 } | 144 } |
145 | 145 |
146 void DesktopHostWin::ToggleFullScreen() { | 146 void RootWindowHostWin::ToggleFullScreen() { |
147 gfx::Rect target_rect; | 147 gfx::Rect target_rect; |
148 if (!fullscreen_) { | 148 if (!fullscreen_) { |
149 fullscreen_ = true; | 149 fullscreen_ = true; |
150 saved_window_style_ = GetWindowLong(hwnd(), GWL_STYLE); | 150 saved_window_style_ = GetWindowLong(hwnd(), GWL_STYLE); |
151 saved_window_ex_style_ = GetWindowLong(hwnd(), GWL_EXSTYLE); | 151 saved_window_ex_style_ = GetWindowLong(hwnd(), GWL_EXSTYLE); |
152 GetWindowRect(hwnd(), &saved_window_rect_); | 152 GetWindowRect(hwnd(), &saved_window_rect_); |
153 SetWindowLong(hwnd(), GWL_STYLE, | 153 SetWindowLong(hwnd(), GWL_STYLE, |
154 saved_window_style_ & ~(WS_CAPTION | WS_THICKFRAME)); | 154 saved_window_style_ & ~(WS_CAPTION | WS_THICKFRAME)); |
155 SetWindowLong(hwnd(), GWL_EXSTYLE, | 155 SetWindowLong(hwnd(), GWL_EXSTYLE, |
156 saved_window_ex_style_ & ~(WS_EX_DLGMODALFRAME | | 156 saved_window_ex_style_ & ~(WS_EX_DLGMODALFRAME | |
(...skipping 11 matching lines...) Expand all Loading... |
168 } | 168 } |
169 SetWindowPos(hwnd(), | 169 SetWindowPos(hwnd(), |
170 NULL, | 170 NULL, |
171 target_rect.x(), | 171 target_rect.x(), |
172 target_rect.y(), | 172 target_rect.y(), |
173 target_rect.width(), | 173 target_rect.width(), |
174 target_rect.height(), | 174 target_rect.height(), |
175 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); | 175 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); |
176 } | 176 } |
177 | 177 |
178 gfx::Size DesktopHostWin::GetSize() const { | 178 gfx::Size RootWindowHostWin::GetSize() const { |
179 RECT r; | 179 RECT r; |
180 GetClientRect(hwnd(), &r); | 180 GetClientRect(hwnd(), &r); |
181 return gfx::Rect(r).size(); | 181 return gfx::Rect(r).size(); |
182 } | 182 } |
183 | 183 |
184 void DesktopHostWin::SetSize(const gfx::Size& size) { | 184 void RootWindowHostWin::SetSize(const gfx::Size& size) { |
185 if (fullscreen_) { | 185 if (fullscreen_) { |
186 saved_window_rect_.right = saved_window_rect_.left + size.width(); | 186 saved_window_rect_.right = saved_window_rect_.left + size.width(); |
187 saved_window_rect_.bottom = saved_window_rect_.top + size.height(); | 187 saved_window_rect_.bottom = saved_window_rect_.top + size.height(); |
188 return; | 188 return; |
189 } | 189 } |
190 RECT window_rect; | 190 RECT window_rect; |
191 window_rect.left = 0; | 191 window_rect.left = 0; |
192 window_rect.top = 0; | 192 window_rect.top = 0; |
193 window_rect.right = size.width(); | 193 window_rect.right = size.width(); |
194 window_rect.bottom = size.height(); | 194 window_rect.bottom = size.height(); |
195 AdjustWindowRectEx(&window_rect, | 195 AdjustWindowRectEx(&window_rect, |
196 GetWindowLong(hwnd(), GWL_STYLE), | 196 GetWindowLong(hwnd(), GWL_STYLE), |
197 FALSE, | 197 FALSE, |
198 GetWindowLong(hwnd(), GWL_EXSTYLE)); | 198 GetWindowLong(hwnd(), GWL_EXSTYLE)); |
199 SetWindowPos( | 199 SetWindowPos( |
200 hwnd(), | 200 hwnd(), |
201 NULL, | 201 NULL, |
202 0, | 202 0, |
203 0, | 203 0, |
204 window_rect.right - window_rect.left, | 204 window_rect.right - window_rect.left, |
205 window_rect.bottom - window_rect.top, | 205 window_rect.bottom - window_rect.top, |
206 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOREPOSITION); | 206 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOREPOSITION); |
207 } | 207 } |
208 | 208 |
209 gfx::Point DesktopHostWin::GetLocationOnNativeScreen() const { | 209 gfx::Point RootWindowHostWin::GetLocationOnNativeScreen() const { |
210 RECT r; | 210 RECT r; |
211 GetClientRect(hwnd(), &r); | 211 GetClientRect(hwnd(), &r); |
212 return gfx::Point(r.left, r.top); | 212 return gfx::Point(r.left, r.top); |
213 } | 213 } |
214 | 214 |
215 | 215 |
216 void DesktopHostWin::SetCursor(gfx::NativeCursor native_cursor) { | 216 void RootWindowHostWin::SetCursor(gfx::NativeCursor native_cursor) { |
217 // Custom web cursors are handled directly. | 217 // Custom web cursors are handled directly. |
218 if (native_cursor == kCursorCustom) | 218 if (native_cursor == kCursorCustom) |
219 return; | 219 return; |
220 const wchar_t* cursor_id = GetCursorId(native_cursor); | 220 const wchar_t* cursor_id = GetCursorId(native_cursor); |
221 // TODO(jamescook): Support for non-system cursors will require finding | 221 // TODO(jamescook): Support for non-system cursors will require finding |
222 // the appropriate module to pass to LoadCursor(). | 222 // the appropriate module to pass to LoadCursor(). |
223 ::SetCursor(LoadCursor(NULL, cursor_id)); | 223 ::SetCursor(LoadCursor(NULL, cursor_id)); |
224 } | 224 } |
225 | 225 |
226 gfx::Point DesktopHostWin::QueryMouseLocation() { | 226 gfx::Point RootWindowHostWin::QueryMouseLocation() { |
227 POINT pt; | 227 POINT pt; |
228 GetCursorPos(&pt); | 228 GetCursorPos(&pt); |
229 ScreenToClient(hwnd(), &pt); | 229 ScreenToClient(hwnd(), &pt); |
230 const gfx::Size size = GetSize(); | 230 const gfx::Size size = GetSize(); |
231 return gfx::Point(max(0, min(size.width(), static_cast<int>(pt.x))), | 231 return gfx::Point(max(0, min(size.width(), static_cast<int>(pt.x))), |
232 max(0, min(size.height(), static_cast<int>(pt.y)))); | 232 max(0, min(size.height(), static_cast<int>(pt.y)))); |
233 } | 233 } |
234 | 234 |
235 void DesktopHostWin::PostNativeEvent(const base::NativeEvent& native_event) { | 235 void RootWindowHostWin::PostNativeEvent(const base::NativeEvent& native_event) { |
236 ::PostMessage( | 236 ::PostMessage( |
237 hwnd(), native_event.message, native_event.wParam, native_event.lParam); | 237 hwnd(), native_event.message, native_event.wParam, native_event.lParam); |
238 } | 238 } |
239 | 239 |
240 void DesktopHostWin::OnClose() { | 240 void RootWindowHostWin::OnClose() { |
241 // TODO: this obviously shouldn't be here. | 241 // TODO: this obviously shouldn't be here. |
242 MessageLoopForUI::current()->Quit(); | 242 MessageLoopForUI::current()->Quit(); |
243 } | 243 } |
244 | 244 |
245 LRESULT DesktopHostWin::OnKeyEvent(UINT message, | 245 LRESULT RootWindowHostWin::OnKeyEvent(UINT message, |
246 WPARAM w_param, | 246 WPARAM w_param, |
247 LPARAM l_param) { | 247 LPARAM l_param) { |
248 MSG msg = { hwnd(), message, w_param, l_param }; | 248 MSG msg = { hwnd(), message, w_param, l_param }; |
249 KeyEvent keyev(msg, message == WM_CHAR); | 249 KeyEvent keyev(msg, message == WM_CHAR); |
250 SetMsgHandled(desktop_->DispatchKeyEvent(&keyev)); | 250 SetMsgHandled(root_window_->DispatchKeyEvent(&keyev)); |
251 return 0; | 251 return 0; |
252 } | 252 } |
253 | 253 |
254 LRESULT DesktopHostWin::OnMouseRange(UINT message, | 254 LRESULT RootWindowHostWin::OnMouseRange(UINT message, |
255 WPARAM w_param, | 255 WPARAM w_param, |
256 LPARAM l_param) { | 256 LPARAM l_param) { |
257 MSG msg = { hwnd(), message, w_param, l_param, 0, | 257 MSG msg = { hwnd(), message, w_param, l_param, 0, |
258 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; | 258 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; |
259 MouseEvent event(msg); | 259 MouseEvent event(msg); |
260 bool handled = false; | 260 bool handled = false; |
261 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) | 261 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) |
262 handled = desktop_->DispatchMouseEvent(&event); | 262 handled = root_window_->DispatchMouseEvent(&event); |
263 SetMsgHandled(handled); | 263 SetMsgHandled(handled); |
264 return 0; | 264 return 0; |
265 } | 265 } |
266 | 266 |
267 void DesktopHostWin::OnPaint(HDC dc) { | 267 void RootWindowHostWin::OnPaint(HDC dc) { |
268 desktop_->Draw(); | 268 root_window_->Draw(); |
269 ValidateRect(hwnd(), NULL); | 269 ValidateRect(hwnd(), NULL); |
270 } | 270 } |
271 | 271 |
272 void DesktopHostWin::OnSize(UINT param, const CSize& size) { | 272 void RootWindowHostWin::OnSize(UINT param, const CSize& size) { |
273 // Minimizing resizes the window to 0x0 which causes our layout to go all | 273 // Minimizing resizes the window to 0x0 which causes our layout to go all |
274 // screwy, so we just ignore it. | 274 // screwy, so we just ignore it. |
275 if (param != SIZE_MINIMIZED) | 275 if (param != SIZE_MINIMIZED) |
276 desktop_->OnHostResized(gfx::Size(size.cx, size.cy)); | 276 root_window_->OnHostResized(gfx::Size(size.cx, size.cy)); |
277 } | 277 } |
278 | 278 |
279 } // namespace aura | 279 } // namespace aura |
OLD | NEW |