| 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.h" | |
| 6 | |
| 7 #include "aura/desktop_host.h" | |
| 8 #include "aura/root_window.h" | |
| 9 #include "aura/window.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/message_loop.h" | |
| 12 #include "ui/gfx/compositor/compositor.h" | |
| 13 #include "ui/gfx/compositor/layer.h" | |
| 14 | |
| 15 namespace aura { | |
| 16 | |
| 17 // static | |
| 18 Desktop* Desktop::instance_ = NULL; | |
| 19 | |
| 20 Desktop::Desktop() | |
| 21 : host_(aura::DesktopHost::Create(gfx::Rect(200, 200, 1024, 768))), | |
| 22 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_(this)) { | |
| 23 DCHECK(MessageLoopForUI::current()) | |
| 24 << "The UI message loop must be initialized first."; | |
| 25 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(), | |
| 26 host_->GetSize()); | |
| 27 host_->SetDesktop(this); | |
| 28 DCHECK(compositor_.get()); | |
| 29 window_.reset(new internal::RootWindow); | |
| 30 } | |
| 31 | |
| 32 Desktop::~Desktop() { | |
| 33 if (instance_ == this) | |
| 34 instance_ = NULL; | |
| 35 } | |
| 36 | |
| 37 void Desktop::Show() { | |
| 38 host_->Show(); | |
| 39 } | |
| 40 | |
| 41 void Desktop::SetSize(const gfx::Size& size) { | |
| 42 host_->SetSize(size); | |
| 43 } | |
| 44 | |
| 45 void Desktop::Run() { | |
| 46 Show(); | |
| 47 MessageLoopForUI::current()->Run(host_.get()); | |
| 48 } | |
| 49 | |
| 50 void Desktop::Draw() { | |
| 51 // Second pass renders the layers. | |
| 52 const bool force_clear = false; | |
| 53 compositor_->NotifyStart(force_clear); | |
| 54 window_->layer()->DrawTree(); | |
| 55 compositor_->NotifyEnd(); | |
| 56 } | |
| 57 | |
| 58 bool Desktop::OnMouseEvent(const MouseEvent& event) { | |
| 59 return window_->HandleMouseEvent(event); | |
| 60 } | |
| 61 | |
| 62 bool Desktop::OnKeyEvent(const KeyEvent& event) { | |
| 63 return window_->HandleKeyEvent(event); | |
| 64 } | |
| 65 | |
| 66 void Desktop::OnHostResized(const gfx::Size& size) { | |
| 67 gfx::Rect bounds(window_->bounds().origin(), size); | |
| 68 window_->SetBounds(bounds, 0); | |
| 69 compositor_->WidgetSizeChanged(size); | |
| 70 } | |
| 71 | |
| 72 void Desktop::ScheduleCompositorPaint() { | |
| 73 if (schedule_paint_.empty()) { | |
| 74 MessageLoop::current()->PostTask(FROM_HERE, | |
| 75 schedule_paint_.NewRunnableMethod(&Desktop::Draw)); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 // static | |
| 80 Desktop* Desktop::GetInstance() { | |
| 81 if (!instance_) { | |
| 82 instance_ = new Desktop; | |
| 83 instance_->window_->Init(); | |
| 84 } | |
| 85 return instance_; | |
| 86 } | |
| 87 | |
| 88 } // namespace aura | |
| OLD | NEW |