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