[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 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" |
[email protected] | a83f0f2 | 2011-08-23 15:39:15 | [diff] [blame^] | 8 | #include "aura/event.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 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 | |
[email protected] | 711d8a8 | 2011-08-22 16:01:19 | [diff] [blame] | 26 | bool DesktopHostWin::Dispatch(const MSG& msg) { |
[email protected] | b2d2ee8 | 2011-08-22 17:25:05 | [diff] [blame] | 27 | TranslateMessage(&msg); |
| 28 | DispatchMessage(&msg); |
[email protected] | 711d8a8 | 2011-08-22 16:01:19 | [diff] [blame] | 29 | return true; |
| 30 | } |
| 31 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 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::OnClose() { |
| 51 | // TODO: this obviously shouldn't be here. |
| 52 | MessageLoopForUI::current()->Quit(); |
| 53 | } |
| 54 | |
[email protected] | a83f0f2 | 2011-08-23 15:39:15 | [diff] [blame^] | 55 | LRESULT DesktopHostWin::OnMouseRange(UINT message, |
| 56 | WPARAM w_param, |
| 57 | LPARAM l_param) { |
| 58 | MSG msg = { hwnd(), message, w_param, l_param, 0, |
| 59 | { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; |
| 60 | SetMsgHandled(desktop_->OnMouseEvent(MouseEvent(msg))); |
| 61 | return 0; |
| 62 | } |
| 63 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 64 | void DesktopHostWin::OnPaint(HDC dc) { |
| 65 | if (desktop_) |
| 66 | desktop_->Draw(); |
| 67 | ValidateRect(hwnd(), NULL); |
| 68 | } |
| 69 | |
| 70 | } // namespace aura |