summaryrefslogtreecommitdiffstats
path: root/aura/demo/demo_main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'aura/demo/demo_main.cc')
-rw-r--r--aura/demo/demo_main.cc62
1 files changed, 42 insertions, 20 deletions
diff --git a/aura/demo/demo_main.cc b/aura/demo/demo_main.cc
index 09cfc29..e8ef169 100644
--- a/aura/demo/demo_main.cc
+++ b/aura/demo/demo_main.cc
@@ -3,12 +3,14 @@
// found in the LICENSE file.
#include "aura/desktop.h"
+#include "aura/desktop_host.h"
#include "aura/window.h"
#include "aura/window_delegate.h"
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/i18n/icu_util.h"
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
#include "third_party/skia/include/core/SkXfermode.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
@@ -18,21 +20,32 @@
namespace {
-// Trivial WindowDelegate implementation that draws a colored background.
+// Trivial WindowDelegate implementation that draws a blue background.
class DemoWindowDelegate : public aura::WindowDelegate {
public:
- explicit DemoWindowDelegate(SkColor color) : color_(color) {}
+ explicit DemoWindowDelegate(aura::Window* window, SkColor color);
- virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
- canvas->AsCanvasSkia()->drawColor(color_, SkXfermode::kSrc_Mode);
- }
+ virtual void OnPaint(const gfx::Rect& bounds) OVERRIDE;
private:
+ aura::Window* window_;
+
SkColor color_;
DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate);
};
+DemoWindowDelegate::DemoWindowDelegate(aura::Window* window, SkColor color)
+ : window_(window),
+ color_(color) {
+}
+
+void DemoWindowDelegate::OnPaint(const gfx::Rect& bounds) {
+ scoped_ptr<gfx::Canvas> canvas(
+ gfx::Canvas::CreateCanvas(bounds.width(), bounds.height(), false));
+ canvas->AsCanvasSkia()->drawColor(color_, SkXfermode::kSrc_Mode);
+ window_->SetCanvas(*canvas->AsCanvasSkia(), bounds.origin());
+}
} // namespace
@@ -50,34 +63,43 @@ int main(int argc, char** argv) {
base::MessagePumpX::DisableGtkMessagePump();
#endif
- aura::Desktop::GetInstance();
+ // Create the DesktopHost and Desktop.
+ scoped_ptr<aura::DesktopHost> host(
+ aura::DesktopHost::Create(gfx::Rect(200, 200, 1024, 768)));
+ aura::Desktop desktop(host->GetAcceleratedWidget(), host->GetSize());
+ host->SetDesktop(&desktop);
// Create a hierarchy of test windows.
- DemoWindowDelegate window_delegate1(SK_ColorBLUE);
- aura::Window window1(&window_delegate1);
+ aura::Window window1(&desktop);
window1.set_id(1);
- window1.Init();
window1.SetBounds(gfx::Rect(100, 100, 400, 400), 0);
window1.SetVisibility(aura::Window::VISIBILITY_SHOWN);
- window1.SetParent(NULL);
+ DemoWindowDelegate window_delegate1(&window1, SK_ColorBLUE);
+ window1.set_delegate(&window_delegate1);
+
+ desktop.window()->AddChild(&window1);
- DemoWindowDelegate window_delegate2(SK_ColorRED);
- aura::Window window2(&window_delegate2);
+ aura::Window window2(&desktop);
window2.set_id(2);
- window2.Init();
window2.SetBounds(gfx::Rect(200, 200, 350, 350), 0);
window2.SetVisibility(aura::Window::VISIBILITY_SHOWN);
- window2.SetParent(NULL);
+ DemoWindowDelegate window_delegate2(&window2, SK_ColorRED);
+ window2.set_delegate(&window_delegate2);
- DemoWindowDelegate window_delegate3(SK_ColorGREEN);
- aura::Window window3(&window_delegate3);
+ desktop.window()->AddChild(&window2);
+
+ aura::Window window3(&desktop);
window3.set_id(3);
- window3.Init();
window3.SetBounds(gfx::Rect(10, 10, 50, 50), 0);
window3.SetVisibility(aura::Window::VISIBILITY_SHOWN);
- window3.SetParent(&window2);
+ DemoWindowDelegate window_delegate3(&window3, SK_ColorGREEN);
+ window3.set_delegate(&window_delegate3);
+
+ window2.AddChild(&window3);
- aura::Desktop::GetInstance()->Run();
+ host->Show();
+
+ MessageLoop main_message_loop(MessageLoop::TYPE_UI);
+ MessageLoopForUI::current()->Run(host.get());
return 0;
}
-