blob: b0ffbad17452686af4bd277892b8b750238e9e6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "aura/desktop.h"
#include "aura/desktop_host.h"
#include "aura/root_window.h"
#include "aura/window.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "ui/gfx/compositor/compositor.h"
namespace aura {
// static
Desktop* Desktop::instance_ = NULL;
Desktop::Desktop()
: host_(aura::DesktopHost::Create(gfx::Rect(200, 200, 1024, 768))) {
compositor_ = ui::Compositor::Create(host_->GetAcceleratedWidget(),
host_->GetSize());
host_->SetDesktop(this);
DCHECK(compositor_.get());
window_.reset(new internal::RootWindow);
}
Desktop::~Desktop() {
}
void Desktop::Show() {
host_->Show();
}
void Desktop::SetSize(const gfx::Size& size) {
host_->SetSize(size);
}
void Desktop::Run() {
Show();
MessageLoop main_message_loop(MessageLoop::TYPE_UI);
MessageLoopForUI::current()->Run(host_);
}
void Desktop::Draw() {
compositor_->NotifyStart();
window_->DrawTree();
compositor_->NotifyEnd();
}
bool Desktop::OnMouseEvent(const MouseEvent& event) {
return window_->HandleMouseEvent(event);
}
bool Desktop::OnKeyEvent(const KeyEvent& event) {
return window_->HandleKeyEvent(event);
}
// static
Desktop* Desktop::GetInstance() {
if (!instance_) {
instance_ = new Desktop;
instance_->window_->Init();
}
return instance_;
}
} // namespace aura
|