| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "aura/desktop_host_win.h" | |
| 6 | |
| 7 #include "aura/desktop.h" | |
| 8 #include "aura/event.h" | |
| 9 #include "base/message_loop.h" | |
| 10 | |
| 11 namespace aura { | |
| 12 | |
| 13 // static | |
| 14 DesktopHost* DesktopHost::Create(const gfx::Rect& bounds) { | |
| 15 return new DesktopHostWin(bounds); | |
| 16 } | |
| 17 | |
| 18 DesktopHostWin::DesktopHostWin(const gfx::Rect& bounds) : desktop_(NULL) { | |
| 19 Init(NULL, bounds); | |
| 20 } | |
| 21 | |
| 22 DesktopHostWin::~DesktopHostWin() { | |
| 23 DestroyWindow(hwnd()); | |
| 24 } | |
| 25 | |
| 26 bool DesktopHostWin::Dispatch(const MSG& msg) { | |
| 27 TranslateMessage(&msg); | |
| 28 DispatchMessage(&msg); | |
| 29 return true; | |
| 30 } | |
| 31 | |
| 32 void DesktopHostWin::SetDesktop(Desktop* desktop) { | |
| 33 desktop_ = desktop; | |
| 34 } | |
| 35 | |
| 36 gfx::AcceleratedWidget DesktopHostWin::GetAcceleratedWidget() { | |
| 37 return hwnd(); | |
| 38 } | |
| 39 | |
| 40 void DesktopHostWin::Show() { | |
| 41 ShowWindow(hwnd(), SW_SHOWNORMAL); | |
| 42 } | |
| 43 | |
| 44 gfx::Size DesktopHostWin::GetSize() { | |
| 45 RECT r; | |
| 46 GetClientRect(hwnd(), &r); | |
| 47 return gfx::Rect(r).size(); | |
| 48 } | |
| 49 | |
| 50 void DesktopHostWin::SetSize(const gfx::Size& size) { | |
| 51 SetWindowPos( | |
| 52 hwnd(), | |
| 53 NULL, | |
| 54 0, | |
| 55 0, | |
| 56 size.width(), | |
| 57 size.height(), | |
| 58 SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOREPOSITION); | |
| 59 } | |
| 60 | |
| 61 void DesktopHostWin::OnClose() { | |
| 62 // TODO: this obviously shouldn't be here. | |
| 63 MessageLoopForUI::current()->Quit(); | |
| 64 } | |
| 65 | |
| 66 LRESULT DesktopHostWin::OnKeyEvent(UINT message, | |
| 67 WPARAM w_param, | |
| 68 LPARAM l_param) { | |
| 69 MSG msg = { hwnd(), message, w_param, l_param }; | |
| 70 SetMsgHandled(desktop_->OnKeyEvent(KeyEvent(msg))); | |
| 71 return 0; | |
| 72 } | |
| 73 | |
| 74 LRESULT DesktopHostWin::OnMouseRange(UINT message, | |
| 75 WPARAM w_param, | |
| 76 LPARAM l_param) { | |
| 77 MSG msg = { hwnd(), message, w_param, l_param, 0, | |
| 78 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; | |
| 79 MouseEvent event(msg); | |
| 80 bool handled = false; | |
| 81 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) | |
| 82 handled = desktop_->OnMouseEvent(event); | |
| 83 SetMsgHandled(handled); | |
| 84 return 0; | |
| 85 } | |
| 86 | |
| 87 void DesktopHostWin::OnPaint(HDC dc) { | |
| 88 desktop_->Draw(); | |
| 89 ValidateRect(hwnd(), NULL); | |
| 90 } | |
| 91 | |
| 92 void DesktopHostWin::OnSize(UINT param, const CSize& size) { | |
| 93 desktop_->OnHostResized(gfx::Size(size.cx, size.cy)); | |
| 94 } | |
| 95 | |
| 96 } // namespace aura | |
| OLD | NEW |