| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "mojo/examples/keyboard/keyboard.mojom.h" | 7 #include "mojo/examples/keyboard/keyboard.mojom.h" |
| 8 #include "mojo/examples/window_manager/debug_panel.h" | 8 #include "mojo/examples/window_manager/debug_panel.h" |
| 9 #include "mojo/examples/window_manager/window_manager.mojom.h" | 9 #include "mojo/examples/window_manager/window_manager.mojom.h" |
| 10 #include "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
| 11 #include "mojo/public/cpp/application/application_delegate.h" | 11 #include "mojo/public/cpp/application/application_delegate.h" |
| 12 #include "mojo/public/cpp/application/application_impl.h" | 12 #include "mojo/public/cpp/application/application_impl.h" |
| 13 #include "mojo/public/cpp/application/interface_factory_impl.h" | 13 #include "mojo/public/cpp/application/interface_factory_impl.h" |
| 14 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 14 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 15 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 15 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
| 16 #include "mojo/services/public/cpp/view_manager/view.h" | 16 #include "mojo/services/public/cpp/view_manager/view.h" |
| 17 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 17 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 18 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" | |
| 19 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 20 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 19 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 21 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" | 20 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" |
| 22 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" | 21 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" |
| 23 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" | 22 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" |
| 24 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 23 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
| 24 #include "mojo/services/window_manager/window_manager_app.h" |
| 25 #include "mojo/views/views_init.h" | 25 #include "mojo/views/views_init.h" |
| 26 #include "ui/aura/window.h" |
| 26 #include "ui/events/event.h" | 27 #include "ui/events/event.h" |
| 27 #include "ui/events/event_constants.h" | 28 #include "ui/events/event_constants.h" |
| 28 #include "ui/gfx/geometry/size_conversions.h" | 29 #include "ui/gfx/geometry/size_conversions.h" |
| 29 | 30 |
| 30 #if defined CreateWindow | 31 #if defined CreateWindow |
| 31 #undef CreateWindow | 32 #undef CreateWindow |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 namespace mojo { | 35 namespace mojo { |
| 35 namespace examples { | 36 namespace examples { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 const Id launcher_ui_view_id_; | 244 const Id launcher_ui_view_id_; |
| 244 const Id control_panel_view_id_; | 245 const Id control_panel_view_id_; |
| 245 | 246 |
| 246 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); | 247 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); |
| 247 }; | 248 }; |
| 248 | 249 |
| 249 class WindowManager | 250 class WindowManager |
| 250 : public ApplicationDelegate, | 251 : public ApplicationDelegate, |
| 251 public DebugPanel::Delegate, | 252 public DebugPanel::Delegate, |
| 252 public ViewManagerDelegate, | 253 public ViewManagerDelegate, |
| 253 public WindowManagerDelegate { | 254 public WindowManagerDelegate, |
| 255 public ui::EventHandler { |
| 254 public: | 256 public: |
| 255 WindowManager() | 257 WindowManager() |
| 256 : window_manager_factory_(this), | 258 : window_manager_factory_(this), |
| 257 navigator_host_factory_(this), | 259 navigator_host_factory_(this), |
| 258 launcher_ui_(NULL), | 260 launcher_ui_(NULL), |
| 259 view_manager_(NULL), | 261 view_manager_(NULL), |
| 260 view_manager_client_factory_(this), | 262 window_manager_app_(new WindowManagerApp(this, this)), |
| 261 app_(NULL) {} | 263 app_(NULL) {} |
| 262 | 264 |
| 263 virtual ~WindowManager() {} | 265 virtual ~WindowManager() { |
| 266 window_manager_app_->host()->window()->RemovePreTargetHandler(this); |
| 267 } |
| 264 | 268 |
| 265 void CloseWindow(Id view_id) { | 269 void CloseWindow(Id view_id) { |
| 266 View* view = view_manager_->GetViewById(view_id); | 270 View* view = view_manager_->GetViewById(view_id); |
| 267 DCHECK(view); | 271 DCHECK(view); |
| 268 std::vector<View*>::iterator iter = | 272 std::vector<View*>::iterator iter = |
| 269 std::find(windows_.begin(), windows_.end(), view); | 273 std::find(windows_.begin(), windows_.end(), view); |
| 270 DCHECK(iter != windows_.end()); | 274 DCHECK(iter != windows_.end()); |
| 271 windows_.erase(iter); | 275 windows_.erase(iter); |
| 272 view->Destroy(); | 276 view->Destroy(); |
| 273 } | 277 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 source_view_id, | 322 source_view_id, |
| 319 target)); | 323 target)); |
| 320 } | 324 } |
| 321 | 325 |
| 322 private: | 326 private: |
| 323 // Overridden from ApplicationDelegate: | 327 // Overridden from ApplicationDelegate: |
| 324 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { | 328 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { |
| 325 app_ = app; | 329 app_ = app; |
| 326 app->ConnectToService("mojo:mojo_launcher", &launcher_); | 330 app->ConnectToService("mojo:mojo_launcher", &launcher_); |
| 327 views_init_.reset(new ViewsInit); | 331 views_init_.reset(new ViewsInit); |
| 332 window_manager_app_->Initialize(app); |
| 328 } | 333 } |
| 329 | 334 |
| 330 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 335 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| 331 MOJO_OVERRIDE { | 336 MOJO_OVERRIDE { |
| 332 connection->AddService(&window_manager_factory_); | 337 connection->AddService(&window_manager_factory_); |
| 333 connection->AddService(&navigator_host_factory_); | 338 connection->AddService(&navigator_host_factory_); |
| 334 connection->AddService(&view_manager_client_factory_); | 339 window_manager_app_->ConfigureIncomingConnection(connection); |
| 335 return true; | 340 return true; |
| 336 } | 341 } |
| 337 | 342 |
| 338 // Overridden from ViewManagerDelegate: | 343 // Overridden from ViewManagerDelegate: |
| 339 virtual void OnEmbed(ViewManager* view_manager, | 344 virtual void OnEmbed(ViewManager* view_manager, |
| 340 View* root, | 345 View* root, |
| 341 ServiceProviderImpl* exported_services, | 346 ServiceProviderImpl* exported_services, |
| 342 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { | 347 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { |
| 343 DCHECK(!view_manager_); | 348 DCHECK(!view_manager_); |
| 344 view_manager_ = view_manager; | 349 view_manager_ = view_manager; |
| 345 view_manager_->SetWindowManagerDelegate(this); | |
| 346 | 350 |
| 347 View* view = View::Create(view_manager_); | 351 View* view = View::Create(view_manager_); |
| 348 root->AddChild(view); | 352 root->AddChild(view); |
| 349 view->SetBounds(gfx::Rect(root->bounds().size())); | 353 view->SetBounds(gfx::Rect(root->bounds().size())); |
| 350 content_view_id_ = view->id(); | 354 content_view_id_ = view->id(); |
| 351 | 355 |
| 352 root->SetColor(SK_ColorBLUE); | 356 root->SetColor(SK_ColorBLUE); |
| 353 | 357 |
| 354 Id launcher_ui_id = CreateLauncherUI(); | 358 Id launcher_ui_id = CreateLauncherUI(); |
| 355 Id control_panel_id = CreateControlPanel(view); | 359 Id control_panel_id = CreateControlPanel(view); |
| 356 | 360 |
| 357 root_layout_manager_.reset( | 361 root_layout_manager_.reset( |
| 358 new RootLayoutManager(view_manager, root, | 362 new RootLayoutManager(view_manager, root, |
| 359 content_view_id_, | 363 content_view_id_, |
| 360 launcher_ui_id, | 364 launcher_ui_id, |
| 361 control_panel_id)); | 365 control_panel_id)); |
| 362 root->AddObserver(root_layout_manager_.get()); | 366 root->AddObserver(root_layout_manager_.get()); |
| 367 |
| 368 window_manager_app_->host()->window()->AddPreTargetHandler(this); |
| 363 } | 369 } |
| 364 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { | 370 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { |
| 365 DCHECK_EQ(view_manager_, view_manager); | 371 DCHECK_EQ(view_manager_, view_manager); |
| 366 view_manager_ = NULL; | 372 view_manager_ = NULL; |
| 367 base::MessageLoop::current()->Quit(); | 373 base::MessageLoop::current()->Quit(); |
| 368 } | 374 } |
| 369 | 375 |
| 370 // Overridden from WindowManagerDelegate: | 376 // Overridden from WindowManagerDelegate: |
| 371 virtual void Embed( | 377 virtual void Embed( |
| 372 const String& url, | 378 const String& url, |
| 373 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { | 379 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { |
| 374 CreateWindow(url, | 380 CreateWindow(url, |
| 375 NavigationDetailsPtr().Pass(), | 381 NavigationDetailsPtr().Pass(), |
| 376 ResponseDetailsPtr().Pass()); | 382 ResponseDetailsPtr().Pass()); |
| 377 } | 383 } |
| 378 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE { | 384 virtual void DispatchEvent(EventPtr event) MOJO_OVERRIDE {} |
| 379 // TODO(beng): More sophisticated focus handling than this is required! | 385 |
| 380 if (event->action == EVENT_TYPE_MOUSE_PRESSED && | 386 // Overridden from ui::EventHandler: |
| 381 !IsDescendantOfKeyboard(target)) { | 387 virtual void OnEvent(ui::Event* event) OVERRIDE { |
| 382 target->SetFocus(); | 388 View* view = WindowManagerApp::GetViewForWindow( |
| 389 static_cast<aura::Window*>(event->target())); |
| 390 if (event->type() == ui::ET_MOUSE_PRESSED && |
| 391 !IsDescendantOfKeyboard(view)) { |
| 392 view->SetFocus(); |
| 383 } | 393 } |
| 384 view_manager_->DispatchEvent(target, event.Pass()); | |
| 385 } | 394 } |
| 386 | 395 |
| 387 void OnLaunch( | 396 void OnLaunch( |
| 388 uint32 source_view_id, | 397 uint32 source_view_id, |
| 389 Target requested_target, | 398 Target requested_target, |
| 390 const mojo::String& handler_url, | 399 const mojo::String& handler_url, |
| 391 const mojo::String& view_url, | 400 const mojo::String& view_url, |
| 392 ResponseDetailsPtr response) { | 401 ResponseDetailsPtr response) { |
| 393 // TODO(mpcomplete): This seems to be unused in favor of |response|. We | 402 // TODO(mpcomplete): This seems to be unused in favor of |response|. We |
| 394 // might need to use it (and fill it in properly, with method, etc) if we | 403 // might need to use it (and fill it in properly, with method, etc) if we |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 window_manager_factory_; | 515 window_manager_factory_; |
| 507 InterfaceFactoryImplWithContext<NavigatorHostImpl, WindowManager> | 516 InterfaceFactoryImplWithContext<NavigatorHostImpl, WindowManager> |
| 508 navigator_host_factory_; | 517 navigator_host_factory_; |
| 509 | 518 |
| 510 scoped_ptr<ViewsInit> views_init_; | 519 scoped_ptr<ViewsInit> views_init_; |
| 511 DebugPanel* debug_panel_; | 520 DebugPanel* debug_panel_; |
| 512 LauncherPtr launcher_; | 521 LauncherPtr launcher_; |
| 513 View* launcher_ui_; | 522 View* launcher_ui_; |
| 514 std::vector<View*> windows_; | 523 std::vector<View*> windows_; |
| 515 ViewManager* view_manager_; | 524 ViewManager* view_manager_; |
| 516 ViewManagerClientFactory view_manager_client_factory_; | |
| 517 scoped_ptr<RootLayoutManager> root_layout_manager_; | 525 scoped_ptr<RootLayoutManager> root_layout_manager_; |
| 518 | 526 |
| 527 scoped_ptr<WindowManagerApp> window_manager_app_; |
| 528 |
| 519 // Id of the view most content is added to. The keyboard is NOT added here. | 529 // Id of the view most content is added to. The keyboard is NOT added here. |
| 520 Id content_view_id_; | 530 Id content_view_id_; |
| 521 | 531 |
| 522 scoped_ptr<KeyboardManager> keyboard_manager_; | 532 scoped_ptr<KeyboardManager> keyboard_manager_; |
| 523 ApplicationImpl* app_; | 533 ApplicationImpl* app_; |
| 524 | 534 |
| 525 DISALLOW_COPY_AND_ASSIGN(WindowManager); | 535 DISALLOW_COPY_AND_ASSIGN(WindowManager); |
| 526 }; | 536 }; |
| 527 | 537 |
| 528 void WindowManagerConnection::CloseWindow(Id view_id) { | 538 void WindowManagerConnection::CloseWindow(Id view_id) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 550 } | 560 } |
| 551 | 561 |
| 552 } // namespace examples | 562 } // namespace examples |
| 553 | 563 |
| 554 // static | 564 // static |
| 555 ApplicationDelegate* ApplicationDelegate::Create() { | 565 ApplicationDelegate* ApplicationDelegate::Create() { |
| 556 return new examples::WindowManager; | 566 return new examples::WindowManager; |
| 557 } | 567 } |
| 558 | 568 |
| 559 } // namespace mojo | 569 } // namespace mojo |
| OLD | NEW |