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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 return IDC_ARROW; | 100 return IDC_ARROW; |
101 default: | 101 default: |
102 NOTREACHED(); | 102 NOTREACHED(); |
103 return IDC_ARROW; | 103 return IDC_ARROW; |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 } // namespace | 107 } // namespace |
108 | 108 |
109 // static | 109 // static |
110 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { | 110 RootWindowHost* RootWindowHost::Create(RootWindowHostDelegate* delegate, |
111 return new RootWindowHostWin(bounds); | 111 const gfx::Rect& bounds) { |
| 112 return new RootWindowHostWin(delegate, bounds); |
112 } | 113 } |
113 | 114 |
114 // static | 115 // static |
115 RootWindowHost* RootWindowHost::GetForAcceleratedWidget( | 116 RootWindowHost* RootWindowHost::GetForAcceleratedWidget( |
116 gfx::AcceleratedWidget accelerated_widget) { | 117 gfx::AcceleratedWidget accelerated_widget) { |
117 return reinterpret_cast<RootWindowHost*>( | 118 return reinterpret_cast<RootWindowHost*>( |
118 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostWinKey)); | 119 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostWinKey)); |
119 } | 120 } |
120 | 121 |
121 // static | 122 // static |
122 gfx::Size RootWindowHost::GetNativeScreenSize() { | 123 gfx::Size RootWindowHost::GetNativeScreenSize() { |
123 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), | 124 return gfx::Size(GetSystemMetrics(SM_CXSCREEN), |
124 GetSystemMetrics(SM_CYSCREEN)); | 125 GetSystemMetrics(SM_CYSCREEN)); |
125 } | 126 } |
126 | 127 |
127 RootWindowHostWin::RootWindowHostWin(const gfx::Rect& bounds) | 128 RootWindowHostWin::RootWindowHostWin(RootWindowHostDelegate* delegate, |
128 : root_window_(NULL), | 129 const gfx::Rect& bounds) |
| 130 : delegate_(delegate), |
129 fullscreen_(false), | 131 fullscreen_(false), |
130 has_capture_(false), | 132 has_capture_(false), |
131 saved_window_style_(0), | 133 saved_window_style_(0), |
132 saved_window_ex_style_(0) { | 134 saved_window_ex_style_(0) { |
133 Init(NULL, bounds); | 135 Init(NULL, bounds); |
134 SetWindowText(hwnd(), L"aura::RootWindow!"); | 136 SetWindowText(hwnd(), L"aura::RootWindow!"); |
135 prop_.reset(new ui::ViewProp(hwnd(), kRootWindowHostWinKey, this)); | 137 prop_.reset(new ui::ViewProp(hwnd(), kRootWindowHostWinKey, this)); |
136 } | 138 } |
137 | 139 |
138 RootWindowHostWin::~RootWindowHostWin() { | 140 RootWindowHostWin::~RootWindowHostWin() { |
139 DestroyWindow(hwnd()); | 141 DestroyWindow(hwnd()); |
140 } | 142 } |
141 | 143 |
142 void RootWindowHostWin::SetRootWindow(RootWindow* root_window) { | |
143 root_window_ = root_window; | |
144 } | |
145 | |
146 RootWindow* RootWindowHostWin::GetRootWindow() { | 144 RootWindow* RootWindowHostWin::GetRootWindow() { |
147 return root_window_; | 145 return delegate_->AsRootWindow(); |
148 } | 146 } |
149 | 147 |
150 gfx::AcceleratedWidget RootWindowHostWin::GetAcceleratedWidget() { | 148 gfx::AcceleratedWidget RootWindowHostWin::GetAcceleratedWidget() { |
151 return hwnd(); | 149 return hwnd(); |
152 } | 150 } |
153 | 151 |
154 void RootWindowHostWin::Show() { | 152 void RootWindowHostWin::Show() { |
155 ShowWindow(hwnd(), SW_SHOWNORMAL); | 153 ShowWindow(hwnd(), SW_SHOWNORMAL); |
156 } | 154 } |
157 | 155 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 void RootWindowHostWin::OnClose() { | 303 void RootWindowHostWin::OnClose() { |
306 // TODO: this obviously shouldn't be here. | 304 // TODO: this obviously shouldn't be here. |
307 MessageLoopForUI::current()->Quit(); | 305 MessageLoopForUI::current()->Quit(); |
308 } | 306 } |
309 | 307 |
310 LRESULT RootWindowHostWin::OnKeyEvent(UINT message, | 308 LRESULT RootWindowHostWin::OnKeyEvent(UINT message, |
311 WPARAM w_param, | 309 WPARAM w_param, |
312 LPARAM l_param) { | 310 LPARAM l_param) { |
313 MSG msg = { hwnd(), message, w_param, l_param }; | 311 MSG msg = { hwnd(), message, w_param, l_param }; |
314 KeyEvent keyev(msg, message == WM_CHAR); | 312 KeyEvent keyev(msg, message == WM_CHAR); |
315 SetMsgHandled(root_window_->DispatchKeyEvent(&keyev)); | 313 SetMsgHandled(delegate_->OnHostKeyEvent(&keyev)); |
316 return 0; | 314 return 0; |
317 } | 315 } |
318 | 316 |
319 LRESULT RootWindowHostWin::OnMouseRange(UINT message, | 317 LRESULT RootWindowHostWin::OnMouseRange(UINT message, |
320 WPARAM w_param, | 318 WPARAM w_param, |
321 LPARAM l_param) { | 319 LPARAM l_param) { |
322 MSG msg = { hwnd(), message, w_param, l_param, 0, | 320 MSG msg = { hwnd(), message, w_param, l_param, 0, |
323 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; | 321 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; |
324 MouseEvent event(msg); | 322 MouseEvent event(msg); |
325 bool handled = false; | 323 bool handled = false; |
326 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) | 324 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) |
327 handled = root_window_->DispatchMouseEvent(&event); | 325 handled = delegate_->OnHostMouseEvent(&event); |
328 SetMsgHandled(handled); | 326 SetMsgHandled(handled); |
329 return 0; | 327 return 0; |
330 } | 328 } |
331 | 329 |
332 LRESULT RootWindowHostWin::OnCaptureChanged(UINT message, | 330 LRESULT RootWindowHostWin::OnCaptureChanged(UINT message, |
333 WPARAM w_param, | 331 WPARAM w_param, |
334 LPARAM l_param) { | 332 LPARAM l_param) { |
335 if (has_capture_) { | 333 if (has_capture_) { |
336 has_capture_ = false; | 334 has_capture_ = false; |
337 Window* capture_window = client::GetCaptureWindow(root_window_); | 335 delegate_->OnHostLostCapture(); |
338 if (capture_window && capture_window->GetRootWindow() == root_window_) | |
339 capture_window->ReleaseCapture(); | |
340 } | 336 } |
341 return 0; | 337 return 0; |
342 } | 338 } |
343 | 339 |
344 void RootWindowHostWin::OnPaint(HDC dc) { | 340 void RootWindowHostWin::OnPaint(HDC dc) { |
345 root_window_->Draw(); | 341 delegate_->OnHostPaint(); |
346 ValidateRect(hwnd(), NULL); | 342 ValidateRect(hwnd(), NULL); |
347 } | 343 } |
348 | 344 |
349 void RootWindowHostWin::OnSize(UINT param, const CSize& size) { | 345 void RootWindowHostWin::OnSize(UINT param, const CSize& size) { |
350 // Minimizing resizes the window to 0x0 which causes our layout to go all | 346 // Minimizing resizes the window to 0x0 which causes our layout to go all |
351 // screwy, so we just ignore it. | 347 // screwy, so we just ignore it. |
352 if (param != SIZE_MINIMIZED) | 348 if (param != SIZE_MINIMIZED) |
353 root_window_->OnHostResized(gfx::Size(size.cx, size.cy)); | 349 delegate_->OnHostResized(gfx::Size(size.cx, size.cy)); |
354 } | 350 } |
355 | 351 |
356 } // namespace aura | 352 } // namespace aura |
OLD | NEW |