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 "mojo/application/application_runner_chromium.h" | 9 #include "mojo/application/application_runner_chromium.h" |
10 #include "mojo/aura/context_factory_mojo.h" | 10 #include "mojo/aura/context_factory_mojo.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.
h" | 23 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.
h" |
24 #include "ui/aura/client/default_capture_client.h" | 24 #include "ui/aura/client/default_capture_client.h" |
25 #include "ui/aura/client/window_tree_client.h" | 25 #include "ui/aura/client/window_tree_client.h" |
26 #include "ui/aura/env.h" | 26 #include "ui/aura/env.h" |
27 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
28 #include "ui/aura/window_delegate.h" | 28 #include "ui/aura/window_delegate.h" |
29 #include "ui/base/hit_test.h" | 29 #include "ui/base/hit_test.h" |
30 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
31 #include "ui/gfx/codec/png_codec.h" | 31 #include "ui/gfx/codec/png_codec.h" |
32 | 32 |
33 namespace mojo { | |
34 namespace examples { | 33 namespace examples { |
35 | 34 |
36 // Trivial WindowDelegate implementation that draws a colored background. | 35 // Trivial WindowDelegate implementation that draws a colored background. |
37 class DemoWindowDelegate : public aura::WindowDelegate { | 36 class DemoWindowDelegate : public aura::WindowDelegate { |
38 public: | 37 public: |
39 explicit DemoWindowDelegate(SkColor color) : color_(color) {} | 38 explicit DemoWindowDelegate(SkColor color) : color_(color) {} |
40 | 39 |
41 // Overridden from WindowDelegate: | 40 // Overridden from WindowDelegate: |
42 virtual gfx::Size GetMinimumSize() const OVERRIDE { | 41 virtual gfx::Size GetMinimumSize() const OVERRIDE { |
43 return gfx::Size(); | 42 return gfx::Size(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 return window_; | 98 return window_; |
100 } | 99 } |
101 | 100 |
102 private: | 101 private: |
103 aura::Window* window_; | 102 aura::Window* window_; |
104 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; | 103 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; |
105 | 104 |
106 DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient); | 105 DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient); |
107 }; | 106 }; |
108 | 107 |
109 class AuraDemo : public ApplicationDelegate, | 108 class AuraDemo : public mojo::ApplicationDelegate, |
110 public WindowTreeHostMojoDelegate, | 109 public mojo::WindowTreeHostMojoDelegate, |
111 public ViewManagerDelegate { | 110 public mojo::ViewManagerDelegate { |
112 public: | 111 public: |
113 AuraDemo() : window1_(NULL), window2_(NULL), window21_(NULL) {} | 112 AuraDemo() : window1_(NULL), window2_(NULL), window21_(NULL) {} |
114 virtual ~AuraDemo() {} | 113 virtual ~AuraDemo() {} |
115 | 114 |
116 private: | 115 private: |
117 // Overridden from ViewManagerDelegate: | 116 // Overridden from ViewManagerDelegate: |
118 virtual void OnEmbed(ViewManager* view_manager, | 117 virtual void OnEmbed( |
119 View* root, | 118 mojo::ViewManager* view_manager, |
120 ServiceProviderImpl* exported_services, | 119 mojo::View* root, |
121 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { | 120 mojo::ServiceProviderImpl* exported_services, |
| 121 scoped_ptr<mojo::ServiceProvider> imported_services) OVERRIDE { |
122 // TODO(beng): this function could be called multiple times! | 122 // TODO(beng): this function could be called multiple times! |
123 root_ = root; | 123 root_ = root; |
124 | 124 |
125 window_tree_host_.reset(new WindowTreeHostMojo(root, this)); | 125 window_tree_host_.reset(new mojo::WindowTreeHostMojo(root, this)); |
126 window_tree_host_->InitHost(); | 126 window_tree_host_->InitHost(); |
127 | 127 |
128 window_tree_client_.reset( | 128 window_tree_client_.reset( |
129 new DemoWindowTreeClient(window_tree_host_->window())); | 129 new DemoWindowTreeClient(window_tree_host_->window())); |
130 | 130 |
131 delegate1_.reset(new DemoWindowDelegate(SK_ColorBLUE)); | 131 delegate1_.reset(new DemoWindowDelegate(SK_ColorBLUE)); |
132 window1_ = new aura::Window(delegate1_.get()); | 132 window1_ = new aura::Window(delegate1_.get()); |
133 window1_->Init(aura::WINDOW_LAYER_TEXTURED); | 133 window1_->Init(aura::WINDOW_LAYER_TEXTURED); |
134 window1_->SetBounds(gfx::Rect(100, 100, 400, 400)); | 134 window1_->SetBounds(gfx::Rect(100, 100, 400, 400)); |
135 window1_->Show(); | 135 window1_->Show(); |
136 window_tree_host_->window()->AddChild(window1_); | 136 window_tree_host_->window()->AddChild(window1_); |
137 | 137 |
138 delegate2_.reset(new DemoWindowDelegate(SK_ColorRED)); | 138 delegate2_.reset(new DemoWindowDelegate(SK_ColorRED)); |
139 window2_ = new aura::Window(delegate2_.get()); | 139 window2_ = new aura::Window(delegate2_.get()); |
140 window2_->Init(aura::WINDOW_LAYER_TEXTURED); | 140 window2_->Init(aura::WINDOW_LAYER_TEXTURED); |
141 window2_->SetBounds(gfx::Rect(200, 200, 350, 350)); | 141 window2_->SetBounds(gfx::Rect(200, 200, 350, 350)); |
142 window2_->Show(); | 142 window2_->Show(); |
143 window_tree_host_->window()->AddChild(window2_); | 143 window_tree_host_->window()->AddChild(window2_); |
144 | 144 |
145 delegate21_.reset(new DemoWindowDelegate(SK_ColorGREEN)); | 145 delegate21_.reset(new DemoWindowDelegate(SK_ColorGREEN)); |
146 window21_ = new aura::Window(delegate21_.get()); | 146 window21_ = new aura::Window(delegate21_.get()); |
147 window21_->Init(aura::WINDOW_LAYER_TEXTURED); | 147 window21_->Init(aura::WINDOW_LAYER_TEXTURED); |
148 window21_->SetBounds(gfx::Rect(10, 10, 50, 50)); | 148 window21_->SetBounds(gfx::Rect(10, 10, 50, 50)); |
149 window21_->Show(); | 149 window21_->Show(); |
150 window2_->AddChild(window21_); | 150 window2_->AddChild(window21_); |
151 | 151 |
152 window_tree_host_->Show(); | 152 window_tree_host_->Show(); |
153 } | 153 } |
154 virtual void OnViewManagerDisconnected( | 154 virtual void OnViewManagerDisconnected( |
155 ViewManager* view_manager) OVERRIDE { | 155 mojo::ViewManager* view_manager) OVERRIDE { |
156 base::MessageLoop::current()->Quit(); | 156 base::MessageLoop::current()->Quit(); |
157 } | 157 } |
158 | 158 |
159 // WindowTreeHostMojoDelegate: | 159 // WindowTreeHostMojoDelegate: |
160 virtual void CompositorContentsChanged(const SkBitmap& bitmap) OVERRIDE { | 160 virtual void CompositorContentsChanged(const SkBitmap& bitmap) OVERRIDE { |
161 root_->SetContents(bitmap); | 161 root_->SetContents(bitmap); |
162 } | 162 } |
163 | 163 |
164 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { | 164 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { |
165 view_manager_client_factory_.reset( | 165 view_manager_client_factory_.reset( |
166 new ViewManagerClientFactory(app->shell(), this)); | 166 new mojo::ViewManagerClientFactory(app->shell(), this)); |
167 aura::Env::CreateInstance(true); | 167 aura::Env::CreateInstance(true); |
168 context_factory_.reset(new ContextFactoryMojo); | 168 context_factory_.reset(new mojo::ContextFactoryMojo); |
169 aura::Env::GetInstance()->set_context_factory(context_factory_.get()); | 169 aura::Env::GetInstance()->set_context_factory(context_factory_.get()); |
170 screen_.reset(ScreenMojo::Create()); | 170 screen_.reset(mojo::ScreenMojo::Create()); |
171 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); | 171 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); |
172 } | 172 } |
173 | 173 |
174 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 174 virtual bool ConfigureIncomingConnection( |
175 MOJO_OVERRIDE { | 175 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { |
176 connection->AddService(view_manager_client_factory_.get()); | 176 connection->AddService(view_manager_client_factory_.get()); |
177 return true; | 177 return true; |
178 } | 178 } |
179 | 179 |
180 scoped_ptr<DemoWindowTreeClient> window_tree_client_; | 180 scoped_ptr<DemoWindowTreeClient> window_tree_client_; |
181 | 181 |
182 scoped_ptr<ui::ContextFactory> context_factory_; | 182 scoped_ptr<ui::ContextFactory> context_factory_; |
183 | 183 |
184 scoped_ptr<ScreenMojo> screen_; | 184 scoped_ptr<mojo::ScreenMojo> screen_; |
185 | 185 |
186 scoped_ptr<DemoWindowDelegate> delegate1_; | 186 scoped_ptr<DemoWindowDelegate> delegate1_; |
187 scoped_ptr<DemoWindowDelegate> delegate2_; | 187 scoped_ptr<DemoWindowDelegate> delegate2_; |
188 scoped_ptr<DemoWindowDelegate> delegate21_; | 188 scoped_ptr<DemoWindowDelegate> delegate21_; |
189 | 189 |
190 aura::Window* window1_; | 190 aura::Window* window1_; |
191 aura::Window* window2_; | 191 aura::Window* window2_; |
192 aura::Window* window21_; | 192 aura::Window* window21_; |
193 | 193 |
194 View* root_; | 194 mojo::View* root_; |
195 | 195 |
196 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; | 196 scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_; |
197 | 197 |
198 scoped_ptr<aura::WindowTreeHost> window_tree_host_; | 198 scoped_ptr<aura::WindowTreeHost> window_tree_host_; |
199 | 199 |
200 DISALLOW_COPY_AND_ASSIGN(AuraDemo); | 200 DISALLOW_COPY_AND_ASSIGN(AuraDemo); |
201 }; | 201 }; |
202 | 202 |
203 } // namespace examples | 203 } // namespace examples |
204 } // namespace mojo | |
205 | 204 |
206 MojoResult MojoMain(MojoHandle shell_handle) { | 205 MojoResult MojoMain(MojoHandle shell_handle) { |
207 mojo::ApplicationRunnerChromium runner(new mojo::examples::AuraDemo); | 206 mojo::ApplicationRunnerChromium runner(new examples::AuraDemo); |
208 return runner.Run(shell_handle); | 207 return runner.Run(shell_handle); |
209 } | 208 } |
OLD | NEW |