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