blob: e581b7d3febc23336b1ceffa172c1ba386243bc8 [file] [log] [blame]
[email protected]81585f32011-07-29 19:32:061// 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]a83f0f22011-08-23 15:39:158#include "aura/event.h"
[email protected]81585f32011-07-29 19:32:069#include "base/message_loop.h"
10
11namespace aura {
12
13// static
14DesktopHost* DesktopHost::Create(const gfx::Rect& bounds) {
15 return new DesktopHostWin(bounds);
16}
17
18DesktopHostWin::DesktopHostWin(const gfx::Rect& bounds) : desktop_(NULL) {
19 Init(NULL, bounds);
20}
21
22DesktopHostWin::~DesktopHostWin() {
23 DestroyWindow(hwnd());
24}
25
[email protected]711d8a82011-08-22 16:01:1926bool DesktopHostWin::Dispatch(const MSG& msg) {
[email protected]b2d2ee82011-08-22 17:25:0527 TranslateMessage(&msg);
28 DispatchMessage(&msg);
[email protected]711d8a82011-08-22 16:01:1929 return true;
30}
31
[email protected]81585f32011-07-29 19:32:0632void DesktopHostWin::SetDesktop(Desktop* desktop) {
33 desktop_ = desktop;
34}
35
36gfx::AcceleratedWidget DesktopHostWin::GetAcceleratedWidget() {
37 return hwnd();
38}
39
40void DesktopHostWin::Show() {
41 ShowWindow(hwnd(), SW_SHOWNORMAL);
42}
43
44gfx::Size DesktopHostWin::GetSize() {
45 RECT r;
46 GetClientRect(hwnd(), &r);
47 return gfx::Rect(r).size();
48}
49
50void DesktopHostWin::OnClose() {
51 // TODO: this obviously shouldn't be here.
52 MessageLoopForUI::current()->Quit();
53}
54
[email protected]a83f0f22011-08-23 15:39:1555LRESULT 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]81585f32011-07-29 19:32:0664void DesktopHostWin::OnPaint(HDC dc) {
65 if (desktop_)
66 desktop_->Draw();
67 ValidateRect(hwnd(), NULL);
68}
69
70} // namespace aura