OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdio.h> | 5 #include <stdio.h> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" |
9 #include "mojo/application/application_runner_chromium.h" | 10 #include "mojo/application/application_runner_chromium.h" |
10 #include "mojo/aura/context_factory_mojo.h" | 11 #include "mojo/aura/context_factory_mojo.h" |
11 #include "mojo/aura/screen_mojo.h" | 12 #include "mojo/aura/screen_mojo.h" |
12 #include "mojo/aura/window_tree_host_mojo.h" | 13 #include "mojo/aura/window_tree_host_mojo.h" |
13 #include "mojo/aura/window_tree_host_mojo_delegate.h" | 14 #include "mojo/aura/window_tree_host_mojo_delegate.h" |
14 #include "mojo/public/c/system/main.h" | 15 #include "mojo/public/c/system/main.h" |
15 #include "mojo/public/cpp/application/application_connection.h" | 16 #include "mojo/public/cpp/application/application_connection.h" |
16 #include "mojo/public/cpp/application/application_delegate.h" | 17 #include "mojo/public/cpp/application/application_delegate.h" |
17 #include "mojo/public/cpp/application/application_impl.h" | 18 #include "mojo/public/cpp/application/application_impl.h" |
18 #include "mojo/public/cpp/system/core.h" | 19 #include "mojo/public/cpp/system/core.h" |
(...skipping 12 matching lines...) Expand all Loading... |
31 #include "ui/gfx/codec/png_codec.h" | 32 #include "ui/gfx/codec/png_codec.h" |
32 | 33 |
33 namespace examples { | 34 namespace examples { |
34 | 35 |
35 // Trivial WindowDelegate implementation that draws a colored background. | 36 // Trivial WindowDelegate implementation that draws a colored background. |
36 class DemoWindowDelegate : public aura::WindowDelegate { | 37 class DemoWindowDelegate : public aura::WindowDelegate { |
37 public: | 38 public: |
38 explicit DemoWindowDelegate(SkColor color) : color_(color) {} | 39 explicit DemoWindowDelegate(SkColor color) : color_(color) {} |
39 | 40 |
40 // Overridden from WindowDelegate: | 41 // Overridden from WindowDelegate: |
41 virtual gfx::Size GetMinimumSize() const OVERRIDE { | 42 virtual gfx::Size GetMinimumSize() const override { |
42 return gfx::Size(); | 43 return gfx::Size(); |
43 } | 44 } |
44 | 45 |
45 virtual gfx::Size GetMaximumSize() const OVERRIDE { | 46 virtual gfx::Size GetMaximumSize() const override { |
46 return gfx::Size(); | 47 return gfx::Size(); |
47 } | 48 } |
48 | 49 |
49 virtual void OnBoundsChanged(const gfx::Rect& old_bounds, | 50 virtual void OnBoundsChanged(const gfx::Rect& old_bounds, |
50 const gfx::Rect& new_bounds) OVERRIDE {} | 51 const gfx::Rect& new_bounds) override {} |
51 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { | 52 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) override { |
52 return gfx::kNullCursor; | 53 return gfx::kNullCursor; |
53 } | 54 } |
54 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { | 55 virtual int GetNonClientComponent(const gfx::Point& point) const override { |
55 return HTCAPTION; | 56 return HTCAPTION; |
56 } | 57 } |
57 virtual bool ShouldDescendIntoChildForEventHandling( | 58 virtual bool ShouldDescendIntoChildForEventHandling( |
58 aura::Window* child, | 59 aura::Window* child, |
59 const gfx::Point& location) OVERRIDE { | 60 const gfx::Point& location) override { |
60 return true; | 61 return true; |
61 } | 62 } |
62 virtual bool CanFocus() OVERRIDE { return true; } | 63 virtual bool CanFocus() override { return true; } |
63 virtual void OnCaptureLost() OVERRIDE {} | 64 virtual void OnCaptureLost() override {} |
64 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 65 virtual void OnPaint(gfx::Canvas* canvas) override { |
65 canvas->DrawColor(color_, SkXfermode::kSrc_Mode); | 66 canvas->DrawColor(color_, SkXfermode::kSrc_Mode); |
66 } | 67 } |
67 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {} | 68 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
68 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {} | 69 virtual void OnWindowDestroying(aura::Window* window) override {} |
69 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {} | 70 virtual void OnWindowDestroyed(aura::Window* window) override {} |
70 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {} | 71 virtual void OnWindowTargetVisibilityChanged(bool visible) override {} |
71 virtual bool HasHitTestMask() const OVERRIDE { return false; } | 72 virtual bool HasHitTestMask() const override { return false; } |
72 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} | 73 virtual void GetHitTestMask(gfx::Path* mask) const override {} |
73 | 74 |
74 private: | 75 private: |
75 const SkColor color_; | 76 const SkColor color_; |
76 | 77 |
77 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); | 78 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); |
78 }; | 79 }; |
79 | 80 |
80 class DemoWindowTreeClient : public aura::client::WindowTreeClient { | 81 class DemoWindowTreeClient : public aura::client::WindowTreeClient { |
81 public: | 82 public: |
82 explicit DemoWindowTreeClient(aura::Window* window) : window_(window) { | 83 explicit DemoWindowTreeClient(aura::Window* window) : window_(window) { |
83 aura::client::SetWindowTreeClient(window_, this); | 84 aura::client::SetWindowTreeClient(window_, this); |
84 } | 85 } |
85 | 86 |
86 virtual ~DemoWindowTreeClient() { | 87 virtual ~DemoWindowTreeClient() { |
87 aura::client::SetWindowTreeClient(window_, NULL); | 88 aura::client::SetWindowTreeClient(window_, NULL); |
88 } | 89 } |
89 | 90 |
90 // Overridden from aura::client::WindowTreeClient: | 91 // Overridden from aura::client::WindowTreeClient: |
91 virtual aura::Window* GetDefaultParent(aura::Window* context, | 92 virtual aura::Window* GetDefaultParent(aura::Window* context, |
92 aura::Window* window, | 93 aura::Window* window, |
93 const gfx::Rect& bounds) OVERRIDE { | 94 const gfx::Rect& bounds) override { |
94 if (!capture_client_) { | 95 if (!capture_client_) { |
95 capture_client_.reset( | 96 capture_client_.reset( |
96 new aura::client::DefaultCaptureClient(window_->GetRootWindow())); | 97 new aura::client::DefaultCaptureClient(window_->GetRootWindow())); |
97 } | 98 } |
98 return window_; | 99 return window_; |
99 } | 100 } |
100 | 101 |
101 private: | 102 private: |
102 aura::Window* window_; | 103 aura::Window* window_; |
103 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; | 104 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; |
104 | 105 |
105 DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient); | 106 DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient); |
106 }; | 107 }; |
107 | 108 |
108 class AuraDemo : public mojo::ApplicationDelegate, | 109 class AuraDemo : public mojo::ApplicationDelegate, |
109 public mojo::WindowTreeHostMojoDelegate, | 110 public mojo::WindowTreeHostMojoDelegate, |
110 public mojo::ViewManagerDelegate { | 111 public mojo::ViewManagerDelegate { |
111 public: | 112 public: |
112 AuraDemo() : window1_(NULL), window2_(NULL), window21_(NULL) {} | 113 AuraDemo() : window1_(NULL), window2_(NULL), window21_(NULL) {} |
113 virtual ~AuraDemo() {} | 114 virtual ~AuraDemo() {} |
114 | 115 |
115 private: | 116 private: |
116 // Overridden from ViewManagerDelegate: | 117 // Overridden from ViewManagerDelegate: |
117 virtual void OnEmbed( | 118 virtual void OnEmbed( |
118 mojo::ViewManager* view_manager, | 119 mojo::ViewManager* view_manager, |
119 mojo::View* root, | 120 mojo::View* root, |
120 mojo::ServiceProviderImpl* exported_services, | 121 mojo::ServiceProviderImpl* exported_services, |
121 scoped_ptr<mojo::ServiceProvider> imported_services) OVERRIDE { | 122 scoped_ptr<mojo::ServiceProvider> imported_services) override { |
122 // TODO(beng): this function could be called multiple times! | 123 // TODO(beng): this function could be called multiple times! |
123 root_ = root; | 124 root_ = root; |
124 | 125 |
125 window_tree_host_.reset(new mojo::WindowTreeHostMojo(root, this)); | 126 window_tree_host_.reset(new mojo::WindowTreeHostMojo(root, this)); |
126 window_tree_host_->InitHost(); | 127 window_tree_host_->InitHost(); |
127 | 128 |
128 window_tree_client_.reset( | 129 window_tree_client_.reset( |
129 new DemoWindowTreeClient(window_tree_host_->window())); | 130 new DemoWindowTreeClient(window_tree_host_->window())); |
130 | 131 |
131 delegate1_.reset(new DemoWindowDelegate(SK_ColorBLUE)); | 132 delegate1_.reset(new DemoWindowDelegate(SK_ColorBLUE)); |
(...skipping 13 matching lines...) Expand all Loading... |
145 delegate21_.reset(new DemoWindowDelegate(SK_ColorGREEN)); | 146 delegate21_.reset(new DemoWindowDelegate(SK_ColorGREEN)); |
146 window21_ = new aura::Window(delegate21_.get()); | 147 window21_ = new aura::Window(delegate21_.get()); |
147 window21_->Init(aura::WINDOW_LAYER_TEXTURED); | 148 window21_->Init(aura::WINDOW_LAYER_TEXTURED); |
148 window21_->SetBounds(gfx::Rect(10, 10, 50, 50)); | 149 window21_->SetBounds(gfx::Rect(10, 10, 50, 50)); |
149 window21_->Show(); | 150 window21_->Show(); |
150 window2_->AddChild(window21_); | 151 window2_->AddChild(window21_); |
151 | 152 |
152 window_tree_host_->Show(); | 153 window_tree_host_->Show(); |
153 } | 154 } |
154 virtual void OnViewManagerDisconnected( | 155 virtual void OnViewManagerDisconnected( |
155 mojo::ViewManager* view_manager) OVERRIDE { | 156 mojo::ViewManager* view_manager) override { |
156 base::MessageLoop::current()->Quit(); | 157 base::MessageLoop::current()->Quit(); |
157 } | 158 } |
158 | 159 |
159 // WindowTreeHostMojoDelegate: | 160 // WindowTreeHostMojoDelegate: |
160 virtual void CompositorContentsChanged(const SkBitmap& bitmap) OVERRIDE { | 161 virtual void CompositorContentsChanged(const SkBitmap& bitmap) override { |
161 root_->SetContents(bitmap); | 162 root_->SetContents(bitmap); |
162 } | 163 } |
163 | 164 |
164 virtual void Initialize(mojo::ApplicationImpl* app) override { | 165 virtual void Initialize(mojo::ApplicationImpl* app) override { |
165 view_manager_client_factory_.reset( | 166 view_manager_client_factory_.reset( |
166 new mojo::ViewManagerClientFactory(app->shell(), this)); | 167 new mojo::ViewManagerClientFactory(app->shell(), this)); |
167 aura::Env::CreateInstance(true); | 168 aura::Env::CreateInstance(true); |
168 context_factory_.reset(new mojo::ContextFactoryMojo); | 169 context_factory_.reset(new mojo::ContextFactoryMojo); |
169 aura::Env::GetInstance()->set_context_factory(context_factory_.get()); | 170 aura::Env::GetInstance()->set_context_factory(context_factory_.get()); |
170 screen_.reset(mojo::ScreenMojo::Create()); | 171 screen_.reset(mojo::ScreenMojo::Create()); |
(...skipping 28 matching lines...) Expand all Loading... |
199 | 200 |
200 DISALLOW_COPY_AND_ASSIGN(AuraDemo); | 201 DISALLOW_COPY_AND_ASSIGN(AuraDemo); |
201 }; | 202 }; |
202 | 203 |
203 } // namespace examples | 204 } // namespace examples |
204 | 205 |
205 MojoResult MojoMain(MojoHandle shell_handle) { | 206 MojoResult MojoMain(MojoHandle shell_handle) { |
206 mojo::ApplicationRunnerChromium runner(new examples::AuraDemo); | 207 mojo::ApplicationRunnerChromium runner(new examples::AuraDemo); |
207 return runner.Run(shell_handle); | 208 return runner.Run(shell_handle); |
208 } | 209 } |
OLD | NEW |