| 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/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/i18n/icu_util.h" | 11 #include "base/i18n/icu_util.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "mojo/examples/aura_demo/demo_screen.h" | 14 #include "mojo/examples/aura_demo/demo_screen.h" |
| 15 #include "mojo/examples/aura_demo/root_window_host_mojo.h" | 15 #include "mojo/examples/aura_demo/root_window_host_mojo.h" |
| 16 #include "mojo/examples/compositor_app/compositor_host.h" | 16 #include "mojo/examples/compositor_app/compositor_host.h" |
| 17 #include "mojo/examples/compositor_app/gles2_client_impl.h" | 17 #include "mojo/examples/compositor_app/gles2_client_impl.h" |
| 18 #include "mojo/public/bindings/allocation_scope.h" | 18 #include "mojo/public/bindings/allocation_scope.h" |
| 19 #include "mojo/public/bindings/remote_ptr.h" | 19 #include "mojo/public/bindings/remote_ptr.h" |
| 20 #include "mojo/public/gles2/gles2_cpp.h" | 20 #include "mojo/public/gles2/gles2_cpp.h" |
| 21 #include "mojo/public/system/core.h" | 21 #include "mojo/public/system/core.h" |
| 22 #include "mojo/public/system/macros.h" | 22 #include "mojo/public/system/macros.h" |
| 23 #include "mojom/launcher.h" |
| 23 #include "mojom/native_viewport.h" | 24 #include "mojom/native_viewport.h" |
| 24 #include "mojom/shell.h" | 25 #include "mojom/shell.h" |
| 25 #include "ui/aura/client/aura_constants.h" | 26 #include "ui/aura/client/aura_constants.h" |
| 26 #include "ui/aura/client/default_activation_client.h" | 27 #include "ui/aura/client/default_activation_client.h" |
| 27 #include "ui/aura/client/default_capture_client.h" | 28 #include "ui/aura/client/default_capture_client.h" |
| 28 #include "ui/aura/client/window_tree_client.h" | 29 #include "ui/aura/client/window_tree_client.h" |
| 29 #include "ui/aura/env.h" | 30 #include "ui/aura/env.h" |
| 30 #include "ui/aura/root_window.h" | 31 #include "ui/aura/root_window.h" |
| 31 #include "ui/aura/test/test_focus_client.h" | 32 #include "ui/aura/test/test_focus_client.h" |
| 32 #include "ui/aura/window.h" | 33 #include "ui/aura/window.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 const gfx::Rect& bounds) OVERRIDE { | 134 const gfx::Rect& bounds) OVERRIDE { |
| 134 return window_; | 135 return window_; |
| 135 } | 136 } |
| 136 | 137 |
| 137 private: | 138 private: |
| 138 aura::Window* window_; | 139 aura::Window* window_; |
| 139 | 140 |
| 140 DISALLOW_COPY_AND_ASSIGN(LauncherWindowTreeClient); | 141 DISALLOW_COPY_AND_ASSIGN(LauncherWindowTreeClient); |
| 141 }; | 142 }; |
| 142 | 143 |
| 144 // Called when the user has submitted a URL by pressing Enter. |
| 145 class URLReceiver { |
| 146 public: |
| 147 virtual void OnURLEntered(const std::string& url_text) = 0; |
| 148 |
| 149 protected: |
| 150 virtual ~URLReceiver() {} |
| 151 }; |
| 152 |
| 143 class LauncherController : public views::TextfieldController { | 153 class LauncherController : public views::TextfieldController { |
| 144 public: | 154 public: |
| 145 LauncherController() {} | 155 explicit LauncherController(URLReceiver* url_receiver) |
| 156 : url_receiver_(url_receiver) {} |
| 146 | 157 |
| 147 void InitInWindow(aura::Window* parent) { | 158 void InitInWindow(aura::Window* parent) { |
| 148 views::Widget* widget = new views::Widget; | 159 views::Widget* widget = new views::Widget; |
| 149 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 160 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 150 params.parent = parent; | 161 params.parent = parent; |
| 151 params.bounds = parent->bounds(); | 162 params.bounds = parent->bounds(); |
| 152 params.can_activate = true; | 163 params.can_activate = true; |
| 153 widget->Init(params); | 164 widget->Init(params); |
| 154 | 165 |
| 155 views::View* container = new views::View; | 166 views::View* container = new views::View; |
| 156 container->set_background( | 167 container->set_background( |
| 157 views::Background::CreateSolidBackground(SK_ColorYELLOW)); | 168 views::Background::CreateSolidBackground(SK_ColorYELLOW)); |
| 158 container->SetBorder( | 169 container->SetBorder( |
| 159 views::Border::CreateEmptyBorder(10, 10, 10, 10)); | 170 views::Border::CreateEmptyBorder(10, 10, 10, 10)); |
| 160 container->SetLayoutManager(new views::FillLayout); | 171 container->SetLayoutManager(new views::FillLayout); |
| 161 widget->SetContentsView(container); | 172 widget->SetContentsView(container); |
| 162 | 173 |
| 163 views::Textfield* textfield = new views::Textfield; | 174 views::Textfield* textfield = new views::Textfield; |
| 164 textfield->set_controller(this); | 175 textfield->set_controller(this); |
| 165 container->AddChildView(textfield); | 176 container->AddChildView(textfield); |
| 177 textfield->RequestFocus(); |
| 166 | 178 |
| 167 container->Layout(); | 179 container->Layout(); |
| 168 | 180 |
| 169 widget->Show(); | 181 widget->Show(); |
| 170 } | 182 } |
| 171 | 183 |
| 172 private: | 184 private: |
| 173 // Overridden from views::TextfieldController: | 185 // Overridden from views::TextfieldController: |
| 174 virtual bool HandleKeyEvent(views::Textfield* sender, | 186 virtual bool HandleKeyEvent(views::Textfield* sender, |
| 175 const ui::KeyEvent& key_event) OVERRIDE { | 187 const ui::KeyEvent& key_event) OVERRIDE { |
| 176 if (key_event.key_code() == ui::VKEY_RETURN) { | 188 if (key_event.key_code() == ui::VKEY_RETURN) { |
| 177 GURL url(sender->text()); | 189 GURL url(sender->text()); |
| 178 printf("URL: %s\n", url.spec().c_str()); | 190 printf("Enter pressed with URL: %s\n", url.spec().c_str()); |
| 191 url_receiver_->OnURLEntered(url.spec()); |
| 179 } | 192 } |
| 180 return false; | 193 return false; |
| 181 } | 194 } |
| 182 | 195 |
| 196 URLReceiver* url_receiver_; |
| 197 |
| 183 DISALLOW_COPY_AND_ASSIGN(LauncherController); | 198 DISALLOW_COPY_AND_ASSIGN(LauncherController); |
| 184 }; | 199 }; |
| 185 | 200 |
| 186 class Launcher : public ShellClient { | 201 class LauncherImpl : public ShellClient, |
| 202 public Launcher, |
| 203 public URLReceiver { |
| 187 public: | 204 public: |
| 188 explicit Launcher(ScopedMessagePipeHandle shell_handle) | 205 explicit LauncherImpl(ScopedMessagePipeHandle shell_handle) |
| 189 : shell_(shell_handle.Pass(), this) { | 206 : launcher_controller_(this), |
| 207 shell_(shell_handle.Pass(), this), |
| 208 pending_show_(false) { |
| 190 screen_.reset(DemoScreen::Create()); | 209 screen_.reset(DemoScreen::Create()); |
| 191 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); | 210 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); |
| 192 | 211 |
| 193 ScopedMessagePipeHandle client_handle, native_viewport_handle; | 212 ScopedMessagePipeHandle client_handle, native_viewport_handle; |
| 194 CreateMessagePipe(&client_handle, &native_viewport_handle); | 213 CreateMessagePipe(&client_handle, &native_viewport_handle); |
| 195 root_window_host_.reset(new WindowTreeHostMojo( | 214 root_window_host_.reset(new WindowTreeHostMojo( |
| 196 native_viewport_handle.Pass(), gfx::Rect(50, 50, 450, 60), | 215 native_viewport_handle.Pass(), gfx::Rect(50, 50, 450, 60), |
| 197 base::Bind(&Launcher::HostContextCreated, base::Unretained(this)))); | 216 base::Bind(&LauncherImpl::HostContextCreated, base::Unretained(this)))); |
| 198 AllocationScope scope; | 217 AllocationScope scope; |
| 199 shell_->Connect("mojo:mojo_native_viewport_service", client_handle.Pass()); | 218 shell_->Connect("mojo:mojo_native_viewport_service", client_handle.Pass()); |
| 200 } | 219 } |
| 201 | 220 |
| 221 private: |
| 222 // Overridden from ShellClient: |
| 202 virtual void AcceptConnection(ScopedMessagePipeHandle handle) MOJO_OVERRIDE { | 223 virtual void AcceptConnection(ScopedMessagePipeHandle handle) MOJO_OVERRIDE { |
| 203 NOTREACHED() << "Launcher can't be connected to."; | 224 launcher_client_.reset(handle.Pass(), this); |
| 204 } | 225 } |
| 205 | 226 |
| 206 private: | 227 // Overridden from Launcher: |
| 228 virtual void Show() OVERRIDE { |
| 229 if (!root_window_.get()) { |
| 230 pending_show_ = true; |
| 231 return; |
| 232 } |
| 233 root_window_->host()->Show(); |
| 234 } |
| 235 virtual void Hide() OVERRIDE { |
| 236 root_window_->host()->Hide(); |
| 237 } |
| 238 |
| 239 // Overridden from URLReceiver: |
| 240 virtual void OnURLEntered(const std::string& url_text) { |
| 241 AllocationScope scope; |
| 242 launcher_client_->OnURLEntered(url_text); |
| 243 } |
| 244 |
| 207 void HostContextCreated() { | 245 void HostContextCreated() { |
| 208 aura::RootWindow::CreateParams params(gfx::Rect(450, 60)); | 246 aura::RootWindow::CreateParams params(gfx::Rect(450, 60)); |
| 209 params.host = root_window_host_.get(); | 247 params.host = root_window_host_.get(); |
| 210 root_window_.reset(new aura::RootWindow(params)); | 248 root_window_.reset(new aura::RootWindow(params)); |
| 211 root_window_host_->set_delegate(root_window_.get()); | 249 root_window_host_->set_delegate(root_window_.get()); |
| 212 root_window_->Init(); | 250 root_window_->Init(); |
| 213 root_window_->window()->SetBounds(gfx::Rect(450, 60)); | 251 root_window_->window()->SetBounds(gfx::Rect(450, 60)); |
| 214 | 252 |
| 215 focus_client_.reset(new aura::test::TestFocusClient()); | 253 focus_client_.reset(new aura::test::TestFocusClient()); |
| 216 aura::client::SetFocusClient(root_window_->window(), focus_client_.get()); | 254 aura::client::SetFocusClient(root_window_->window(), focus_client_.get()); |
| 217 activation_client_.reset( | 255 activation_client_.reset( |
| 218 new aura::client::DefaultActivationClient(root_window_->window())); | 256 new aura::client::DefaultActivationClient(root_window_->window())); |
| 219 capture_client_.reset( | 257 capture_client_.reset( |
| 220 new aura::client::DefaultCaptureClient(root_window_->window())); | 258 new aura::client::DefaultCaptureClient(root_window_->window())); |
| 221 ime_filter_.reset(new MinimalInputEventFilter(root_window_->window())); | 259 ime_filter_.reset(new MinimalInputEventFilter(root_window_->window())); |
| 222 | 260 |
| 223 window_tree_client_.reset( | 261 window_tree_client_.reset( |
| 224 new LauncherWindowTreeClient(root_window_->window())); | 262 new LauncherWindowTreeClient(root_window_->window())); |
| 225 | 263 |
| 226 launcher_controller_.InitInWindow(root_window_->window()); | 264 launcher_controller_.InitInWindow(root_window_->window()); |
| 227 | 265 |
| 228 root_window_->host()->Show(); | 266 if (pending_show_) { |
| 267 pending_show_ = false; |
| 268 Show(); |
| 269 } |
| 229 } | 270 } |
| 230 | 271 |
| 231 scoped_ptr<DemoScreen> screen_; | 272 scoped_ptr<DemoScreen> screen_; |
| 232 scoped_ptr<LauncherWindowTreeClient> window_tree_client_; | 273 scoped_ptr<LauncherWindowTreeClient> window_tree_client_; |
| 233 scoped_ptr<aura::client::DefaultActivationClient> activation_client_; | 274 scoped_ptr<aura::client::DefaultActivationClient> activation_client_; |
| 234 scoped_ptr<aura::client::FocusClient> focus_client_; | 275 scoped_ptr<aura::client::FocusClient> focus_client_; |
| 235 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; | 276 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; |
| 236 scoped_ptr<ui::EventHandler> ime_filter_; | 277 scoped_ptr<ui::EventHandler> ime_filter_; |
| 237 | 278 |
| 238 LauncherController launcher_controller_; | 279 LauncherController launcher_controller_; |
| 239 | 280 |
| 240 RemotePtr<Shell> shell_; | 281 RemotePtr<Shell> shell_; |
| 282 RemotePtr<LauncherClient> launcher_client_; |
| 241 scoped_ptr<WindowTreeHostMojo> root_window_host_; | 283 scoped_ptr<WindowTreeHostMojo> root_window_host_; |
| 242 scoped_ptr<aura::RootWindow> root_window_; | 284 scoped_ptr<aura::RootWindow> root_window_; |
| 285 |
| 286 bool pending_show_; |
| 243 }; | 287 }; |
| 244 | 288 |
| 245 } // namespace examples | 289 } // namespace examples |
| 246 } // namespace mojo | 290 } // namespace mojo |
| 247 | 291 |
| 248 extern "C" LAUNCHER_EXPORT MojoResult CDECL MojoMain( | 292 extern "C" LAUNCHER_EXPORT MojoResult CDECL MojoMain( |
| 249 MojoHandle shell_handle) { | 293 MojoHandle shell_handle) { |
| 250 CommandLine::Init(0, NULL); | 294 CommandLine::Init(0, NULL); |
| 251 base::AtExitManager at_exit; | 295 base::AtExitManager at_exit; |
| 252 base::i18n::InitializeICU(); | 296 base::i18n::InitializeICU(); |
| 253 | 297 |
| 254 base::FilePath pak_dir; | 298 base::FilePath pak_dir; |
| 255 PathService::Get(base::DIR_MODULE, &pak_dir); | 299 PathService::Get(base::DIR_MODULE, &pak_dir); |
| 256 base::FilePath pak_file; | 300 base::FilePath pak_file; |
| 257 pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak")); | 301 pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak")); |
| 258 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); | 302 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); |
| 259 | 303 |
| 260 base::MessageLoop loop; | 304 base::MessageLoop loop; |
| 261 mojo::GLES2Initializer gles2; | 305 mojo::GLES2Initializer gles2; |
| 262 | 306 |
| 263 // TODO(beng): This crashes in a DCHECK on X11 because this thread's | 307 // TODO(beng): This crashes in a DCHECK on X11 because this thread's |
| 264 // MessageLoop is not of TYPE_UI. I think we need a way to build | 308 // MessageLoop is not of TYPE_UI. I think we need a way to build |
| 265 // Aura that doesn't define platform-specific stuff. | 309 // Aura that doesn't define platform-specific stuff. |
| 266 aura::Env::CreateInstance(); | 310 aura::Env::CreateInstance(); |
| 267 mojo::examples::Launcher launcher( | 311 mojo::examples::LauncherImpl launcher( |
| 268 mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)).Pass()); | 312 mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)).Pass()); |
| 269 loop.Run(); | 313 loop.Run(); |
| 270 | 314 |
| 271 return MOJO_RESULT_OK; | 315 return MOJO_RESULT_OK; |
| 272 } | 316 } |
| OLD | NEW |