OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "aura/desktop.h" | 5 #include "aura/desktop.h" |
| 6 #include "aura/desktop_host.h" |
6 #include "aura/window.h" | 7 #include "aura/window.h" |
7 #include "aura/window_delegate.h" | 8 #include "aura/window_delegate.h" |
8 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/i18n/icu_util.h" | 11 #include "base/i18n/icu_util.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop.h" |
12 #include "third_party/skia/include/core/SkXfermode.h" | 14 #include "third_party/skia/include/core/SkXfermode.h" |
13 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
14 #include "ui/base/ui_base_paths.h" | 16 #include "ui/base/ui_base_paths.h" |
15 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
16 #include "ui/gfx/canvas_skia.h" | 18 #include "ui/gfx/canvas_skia.h" |
17 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 // Trivial WindowDelegate implementation that draws a colored background. | 23 // Trivial WindowDelegate implementation that draws a blue background. |
22 class DemoWindowDelegate : public aura::WindowDelegate { | 24 class DemoWindowDelegate : public aura::WindowDelegate { |
23 public: | 25 public: |
24 explicit DemoWindowDelegate(SkColor color) : color_(color) {} | 26 explicit DemoWindowDelegate(aura::Window* window, SkColor color); |
25 | 27 |
26 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 28 virtual void OnPaint(const gfx::Rect& bounds) OVERRIDE; |
27 canvas->AsCanvasSkia()->drawColor(color_, SkXfermode::kSrc_Mode); | |
28 } | |
29 | 29 |
30 private: | 30 private: |
| 31 aura::Window* window_; |
| 32 |
31 SkColor color_; | 33 SkColor color_; |
32 | 34 |
33 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); | 35 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); |
34 }; | 36 }; |
35 | 37 |
| 38 DemoWindowDelegate::DemoWindowDelegate(aura::Window* window, SkColor color) |
| 39 : window_(window), |
| 40 color_(color) { |
| 41 } |
| 42 |
| 43 void DemoWindowDelegate::OnPaint(const gfx::Rect& bounds) { |
| 44 scoped_ptr<gfx::Canvas> canvas( |
| 45 gfx::Canvas::CreateCanvas(bounds.width(), bounds.height(), false)); |
| 46 canvas->AsCanvasSkia()->drawColor(color_, SkXfermode::kSrc_Mode); |
| 47 window_->SetCanvas(*canvas->AsCanvasSkia(), bounds.origin()); |
| 48 } |
36 | 49 |
37 } // namespace | 50 } // namespace |
38 | 51 |
39 int main(int argc, char** argv) { | 52 int main(int argc, char** argv) { |
40 CommandLine::Init(argc, argv); | 53 CommandLine::Init(argc, argv); |
41 | 54 |
42 // The exit manager is in charge of calling the dtors of singleton objects. | 55 // The exit manager is in charge of calling the dtors of singleton objects. |
43 base::AtExitManager exit_manager; | 56 base::AtExitManager exit_manager; |
44 | 57 |
45 ui::RegisterPathProvider(); | 58 ui::RegisterPathProvider(); |
46 icu_util::Initialize(); | 59 icu_util::Initialize(); |
47 ResourceBundle::InitSharedInstance("en-US"); | 60 ResourceBundle::InitSharedInstance("en-US"); |
48 | 61 |
49 #if defined(USE_X11) | 62 #if defined(USE_X11) |
50 base::MessagePumpX::DisableGtkMessagePump(); | 63 base::MessagePumpX::DisableGtkMessagePump(); |
51 #endif | 64 #endif |
52 | 65 |
53 aura::Desktop::GetInstance(); | 66 // Create the DesktopHost and Desktop. |
| 67 scoped_ptr<aura::DesktopHost> host( |
| 68 aura::DesktopHost::Create(gfx::Rect(200, 200, 1024, 768))); |
| 69 aura::Desktop desktop(host->GetAcceleratedWidget(), host->GetSize()); |
| 70 host->SetDesktop(&desktop); |
54 | 71 |
55 // Create a hierarchy of test windows. | 72 // Create a hierarchy of test windows. |
56 DemoWindowDelegate window_delegate1(SK_ColorBLUE); | 73 aura::Window window1(&desktop); |
57 aura::Window window1(&window_delegate1); | |
58 window1.set_id(1); | 74 window1.set_id(1); |
59 window1.Init(); | |
60 window1.SetBounds(gfx::Rect(100, 100, 400, 400), 0); | 75 window1.SetBounds(gfx::Rect(100, 100, 400, 400), 0); |
61 window1.SetVisibility(aura::Window::VISIBILITY_SHOWN); | 76 window1.SetVisibility(aura::Window::VISIBILITY_SHOWN); |
62 window1.SetParent(NULL); | 77 DemoWindowDelegate window_delegate1(&window1, SK_ColorBLUE); |
| 78 window1.set_delegate(&window_delegate1); |
63 | 79 |
64 DemoWindowDelegate window_delegate2(SK_ColorRED); | 80 desktop.window()->AddChild(&window1); |
65 aura::Window window2(&window_delegate2); | 81 |
| 82 aura::Window window2(&desktop); |
66 window2.set_id(2); | 83 window2.set_id(2); |
67 window2.Init(); | |
68 window2.SetBounds(gfx::Rect(200, 200, 350, 350), 0); | 84 window2.SetBounds(gfx::Rect(200, 200, 350, 350), 0); |
69 window2.SetVisibility(aura::Window::VISIBILITY_SHOWN); | 85 window2.SetVisibility(aura::Window::VISIBILITY_SHOWN); |
70 window2.SetParent(NULL); | 86 DemoWindowDelegate window_delegate2(&window2, SK_ColorRED); |
| 87 window2.set_delegate(&window_delegate2); |
71 | 88 |
72 DemoWindowDelegate window_delegate3(SK_ColorGREEN); | 89 desktop.window()->AddChild(&window2); |
73 aura::Window window3(&window_delegate3); | 90 |
| 91 aura::Window window3(&desktop); |
74 window3.set_id(3); | 92 window3.set_id(3); |
75 window3.Init(); | |
76 window3.SetBounds(gfx::Rect(10, 10, 50, 50), 0); | 93 window3.SetBounds(gfx::Rect(10, 10, 50, 50), 0); |
77 window3.SetVisibility(aura::Window::VISIBILITY_SHOWN); | 94 window3.SetVisibility(aura::Window::VISIBILITY_SHOWN); |
78 window3.SetParent(&window2); | 95 DemoWindowDelegate window_delegate3(&window3, SK_ColorGREEN); |
| 96 window3.set_delegate(&window_delegate3); |
79 | 97 |
80 aura::Desktop::GetInstance()->Run(); | 98 window2.AddChild(&window3); |
| 99 |
| 100 host->Show(); |
| 101 |
| 102 MessageLoop main_message_loop(MessageLoop::TYPE_UI); |
| 103 MessageLoopForUI::current()->Run(host.get()); |
81 return 0; | 104 return 0; |
82 } | 105 } |
83 | |
OLD | NEW |