| 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/c/system/main.h" | 10 #include "mojo/public/c/system/main.h" |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 // Overridden from DebugPanel::Delegate: | 311 // Overridden from DebugPanel::Delegate: |
| 312 virtual void CloseTopWindow() OVERRIDE { | 312 virtual void CloseTopWindow() OVERRIDE { |
| 313 if (!windows_.empty()) | 313 if (!windows_.empty()) |
| 314 CloseWindow(windows_.back()->id()); | 314 CloseWindow(windows_.back()->id()); |
| 315 } | 315 } |
| 316 | 316 |
| 317 virtual void RequestNavigate( | 317 virtual void RequestNavigate( |
| 318 uint32 source_view_id, | 318 uint32 source_view_id, |
| 319 Target target, | 319 Target target, |
| 320 NavigationDetailsPtr nav_details) OVERRIDE { | 320 NavigationDetailsPtr nav_details) OVERRIDE { |
| 321 launcher_->Launch(nav_details.Pass(), | 321 OnLaunch(source_view_id, target, nav_details->request->url); |
| 322 base::Bind(&WindowManager::OnLaunch, | |
| 323 base::Unretained(this), | |
| 324 source_view_id, | |
| 325 target)); | |
| 326 } | 322 } |
| 327 | 323 |
| 328 private: | 324 private: |
| 329 // Overridden from ApplicationDelegate: | 325 // Overridden from ApplicationDelegate: |
| 330 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { | 326 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { |
| 331 app_ = app; | 327 app_ = app; |
| 332 app->ConnectToService("mojo:mojo_launcher", &launcher_); | |
| 333 views_init_.reset(new ViewsInit); | 328 views_init_.reset(new ViewsInit); |
| 334 window_manager_app_->Initialize(app); | 329 window_manager_app_->Initialize(app); |
| 335 } | 330 } |
| 336 | 331 |
| 337 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 332 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| 338 MOJO_OVERRIDE { | 333 MOJO_OVERRIDE { |
| 339 connection->AddService(&window_manager_factory_); | 334 connection->AddService(&window_manager_factory_); |
| 340 connection->AddService(&navigator_host_factory_); | 335 connection->AddService(&navigator_host_factory_); |
| 341 window_manager_app_->ConfigureIncomingConnection(connection); | 336 window_manager_app_->ConfigureIncomingConnection(connection); |
| 342 return true; | 337 return true; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 372 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { | 367 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { |
| 373 DCHECK_EQ(view_manager_, view_manager); | 368 DCHECK_EQ(view_manager_, view_manager); |
| 374 view_manager_ = NULL; | 369 view_manager_ = NULL; |
| 375 base::MessageLoop::current()->Quit(); | 370 base::MessageLoop::current()->Quit(); |
| 376 } | 371 } |
| 377 | 372 |
| 378 // Overridden from WindowManagerDelegate: | 373 // Overridden from WindowManagerDelegate: |
| 379 virtual void Embed( | 374 virtual void Embed( |
| 380 const String& url, | 375 const String& url, |
| 381 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { | 376 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { |
| 382 CreateWindow(url, | 377 CreateWindow(url); |
| 383 NavigationDetailsPtr().Pass(), | |
| 384 ResponseDetailsPtr().Pass()); | |
| 385 } | 378 } |
| 386 virtual void DispatchEvent(EventPtr event) MOJO_OVERRIDE {} | 379 virtual void DispatchEvent(EventPtr event) MOJO_OVERRIDE {} |
| 387 | 380 |
| 388 // Overridden from ui::EventHandler: | 381 // Overridden from ui::EventHandler: |
| 389 virtual void OnEvent(ui::Event* event) OVERRIDE { | 382 virtual void OnEvent(ui::Event* event) OVERRIDE { |
| 390 View* view = WindowManagerApp::GetViewForWindow( | 383 View* view = WindowManagerApp::GetViewForWindow( |
| 391 static_cast<aura::Window*>(event->target())); | 384 static_cast<aura::Window*>(event->target())); |
| 392 if (event->type() == ui::ET_MOUSE_PRESSED && | 385 if (event->type() == ui::ET_MOUSE_PRESSED && |
| 393 !IsDescendantOfKeyboard(view)) { | 386 !IsDescendantOfKeyboard(view)) { |
| 394 view->SetFocus(); | 387 view->SetFocus(); |
| 395 } | 388 } |
| 396 } | 389 } |
| 397 | 390 |
| 398 void OnLaunch( | 391 void OnLaunch( |
| 399 uint32 source_view_id, | 392 uint32 source_view_id, |
| 400 Target requested_target, | 393 Target requested_target, |
| 401 const mojo::String& handler_url, | 394 const mojo::String& url) { |
| 402 const mojo::String& view_url, | |
| 403 ResponseDetailsPtr response) { | |
| 404 // TODO(mpcomplete): This seems to be unused in favor of |response|. We | |
| 405 // might need to use it (and fill it in properly, with method, etc) if we | |
| 406 // need to preserve that information. | |
| 407 NavigationDetailsPtr nav_details(NavigationDetails::New()); | |
| 408 nav_details->request->url = view_url; | |
| 409 | |
| 410 Target target = debug_panel_->navigation_target(); | 395 Target target = debug_panel_->navigation_target(); |
| 411 if (target == TARGET_DEFAULT) { | 396 if (target == TARGET_DEFAULT) { |
| 412 if (requested_target != TARGET_DEFAULT) { | 397 if (requested_target != TARGET_DEFAULT) { |
| 413 target = requested_target; | 398 target = requested_target; |
| 414 } else { | 399 } else { |
| 415 // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin | 400 // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin |
| 416 // are different? | 401 // are different? |
| 417 target = TARGET_SOURCE_NODE; | 402 target = TARGET_SOURCE_NODE; |
| 418 } | 403 } |
| 419 } | 404 } |
| 420 | 405 |
| 421 View* dest_view = NULL; | 406 View* dest_view = NULL; |
| 422 if (target == TARGET_SOURCE_NODE) { | 407 if (target == TARGET_SOURCE_NODE) { |
| 423 View* source_view = view_manager_->GetViewById(source_view_id); | 408 View* source_view = view_manager_->GetViewById(source_view_id); |
| 424 bool app_initiated = std::find(windows_.begin(), windows_.end(), | 409 bool app_initiated = std::find(windows_.begin(), windows_.end(), |
| 425 source_view) != windows_.end(); | 410 source_view) != windows_.end(); |
| 426 if (app_initiated) | 411 if (app_initiated) |
| 427 dest_view = source_view; | 412 dest_view = source_view; |
| 428 else if (!windows_.empty()) | 413 else if (!windows_.empty()) |
| 429 dest_view = windows_.back(); | 414 dest_view = windows_.back(); |
| 430 } | 415 } |
| 431 | 416 |
| 432 if (dest_view) | 417 if (dest_view) |
| 433 Embed(dest_view, handler_url, nav_details.Pass(), response.Pass()); | 418 dest_view->Embed(url); |
| 434 else | 419 else |
| 435 CreateWindow(handler_url, nav_details.Pass(), response.Pass()); | 420 CreateWindow(url); |
| 436 } | 421 } |
| 437 | 422 |
| 438 // TODO(beng): proper layout manager!! | 423 // TODO(beng): proper layout manager!! |
| 439 Id CreateLauncherUI() { | 424 Id CreateLauncherUI() { |
| 440 NavigationDetailsPtr nav_details; | 425 NavigationDetailsPtr nav_details; |
| 441 ResponseDetailsPtr response; | 426 ResponseDetailsPtr response; |
| 442 View* view = view_manager_->GetViewById(content_view_id_); | 427 View* view = view_manager_->GetViewById(content_view_id_); |
| 443 gfx::Rect bounds = view->bounds(); | 428 gfx::Rect bounds = view->bounds(); |
| 444 bounds.Inset(kBorderInset, kBorderInset); | 429 bounds.Inset(kBorderInset, kBorderInset); |
| 445 bounds.set_height(kTextfieldHeight); | 430 bounds.set_height(kTextfieldHeight); |
| 446 launcher_ui_ = CreateChild(content_view_id_, "mojo:mojo_browser", bounds, | 431 launcher_ui_ = CreateChild(content_view_id_, "mojo:mojo_browser", bounds); |
| 447 nav_details.Pass(), response.Pass()); | |
| 448 return launcher_ui_->id(); | 432 return launcher_ui_->id(); |
| 449 } | 433 } |
| 450 | 434 |
| 451 void CreateWindow(const std::string& handler_url, | 435 void CreateWindow(const std::string& url) { |
| 452 NavigationDetailsPtr nav_details, | |
| 453 ResponseDetailsPtr response) { | |
| 454 View* view = view_manager_->GetViewById(content_view_id_); | 436 View* view = view_manager_->GetViewById(content_view_id_); |
| 455 gfx::Rect bounds(kBorderInset, | 437 gfx::Rect bounds(kBorderInset, |
| 456 2 * kBorderInset + kTextfieldHeight, | 438 2 * kBorderInset + kTextfieldHeight, |
| 457 view->bounds().width() - 3 * kBorderInset - | 439 view->bounds().width() - 3 * kBorderInset - |
| 458 kControlPanelWidth, | 440 kControlPanelWidth, |
| 459 view->bounds().height() - | 441 view->bounds().height() - |
| 460 (3 * kBorderInset + kTextfieldHeight)); | 442 (3 * kBorderInset + kTextfieldHeight)); |
| 461 if (!windows_.empty()) { | 443 if (!windows_.empty()) { |
| 462 gfx::Point position = windows_.back()->bounds().origin(); | 444 gfx::Point position = windows_.back()->bounds().origin(); |
| 463 position.Offset(35, 35); | 445 position.Offset(35, 35); |
| 464 bounds.set_origin(position); | 446 bounds.set_origin(position); |
| 465 } | 447 } |
| 466 windows_.push_back(CreateChild(content_view_id_, handler_url, bounds, | 448 windows_.push_back(CreateChild(content_view_id_, url, bounds)); |
| 467 nav_details.Pass(), response.Pass())); | |
| 468 } | 449 } |
| 469 | 450 |
| 470 View* CreateChild(Id parent_id, | 451 View* CreateChild(Id parent_id, |
| 471 const std::string& url, | 452 const std::string& url, |
| 472 const gfx::Rect& bounds, | 453 const gfx::Rect& bounds) { |
| 473 NavigationDetailsPtr nav_details, | |
| 474 ResponseDetailsPtr response) { | |
| 475 View* view = view_manager_->GetViewById(parent_id); | 454 View* view = view_manager_->GetViewById(parent_id); |
| 476 View* embedded = View::Create(view_manager_); | 455 View* embedded = View::Create(view_manager_); |
| 477 view->AddChild(embedded); | 456 view->AddChild(embedded); |
| 478 embedded->SetBounds(bounds); | 457 embedded->SetBounds(bounds); |
| 479 Embed(embedded, url, nav_details.Pass(), response.Pass()); | 458 embedded->Embed(url); |
| 480 embedded->SetFocus(); | 459 embedded->SetFocus(); |
| 481 return embedded; | 460 return embedded; |
| 482 } | 461 } |
| 483 | 462 |
| 484 void Embed(View* view, const std::string& app_url, | |
| 485 NavigationDetailsPtr nav_details, | |
| 486 ResponseDetailsPtr response) { | |
| 487 view->Embed(app_url); | |
| 488 if (nav_details) { | |
| 489 NavigatorPtr navigator; | |
| 490 app_->ConnectToService(app_url, &navigator); | |
| 491 navigator->Navigate(view->id(), nav_details.Pass(), response.Pass()); | |
| 492 } | |
| 493 } | |
| 494 | |
| 495 bool IsDescendantOfKeyboard(View* target) { | 463 bool IsDescendantOfKeyboard(View* target) { |
| 496 return keyboard_manager_.get() && | 464 return keyboard_manager_.get() && |
| 497 keyboard_manager_->view()->Contains(target); | 465 keyboard_manager_->view()->Contains(target); |
| 498 } | 466 } |
| 499 | 467 |
| 500 Id CreateControlPanel(View* root) { | 468 Id CreateControlPanel(View* root) { |
| 501 View* view = View::Create(view_manager_); | 469 View* view = View::Create(view_manager_); |
| 502 root->AddChild(view); | 470 root->AddChild(view); |
| 503 | 471 |
| 504 gfx::Rect bounds(root->bounds().width() - kControlPanelWidth - | 472 gfx::Rect bounds(root->bounds().width() - kControlPanelWidth - |
| 505 kBorderInset, | 473 kBorderInset, |
| 506 kBorderInset * 2 + kTextfieldHeight, | 474 kBorderInset * 2 + kTextfieldHeight, |
| 507 kControlPanelWidth, | 475 kControlPanelWidth, |
| 508 root->bounds().height() - kBorderInset * 3 - | 476 root->bounds().height() - kBorderInset * 3 - |
| 509 kTextfieldHeight); | 477 kTextfieldHeight); |
| 510 view->SetBounds(bounds); | 478 view->SetBounds(bounds); |
| 511 | 479 |
| 512 debug_panel_ = new DebugPanel(this, view); | 480 debug_panel_ = new DebugPanel(this, view); |
| 513 return view->id(); | 481 return view->id(); |
| 514 } | 482 } |
| 515 | 483 |
| 516 InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager> | 484 InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager> |
| 517 window_manager_factory_; | 485 window_manager_factory_; |
| 518 InterfaceFactoryImplWithContext<NavigatorHostImpl, WindowManager> | 486 InterfaceFactoryImplWithContext<NavigatorHostImpl, WindowManager> |
| 519 navigator_host_factory_; | 487 navigator_host_factory_; |
| 520 | 488 |
| 521 scoped_ptr<ViewsInit> views_init_; | 489 scoped_ptr<ViewsInit> views_init_; |
| 522 DebugPanel* debug_panel_; | 490 DebugPanel* debug_panel_; |
| 523 LauncherPtr launcher_; | |
| 524 View* launcher_ui_; | 491 View* launcher_ui_; |
| 525 std::vector<View*> windows_; | 492 std::vector<View*> windows_; |
| 526 ViewManager* view_manager_; | 493 ViewManager* view_manager_; |
| 527 scoped_ptr<RootLayoutManager> root_layout_manager_; | 494 scoped_ptr<RootLayoutManager> root_layout_manager_; |
| 528 | 495 |
| 529 scoped_ptr<WindowManagerApp> window_manager_app_; | 496 scoped_ptr<WindowManagerApp> window_manager_app_; |
| 530 | 497 |
| 531 // Id of the view most content is added to. The keyboard is NOT added here. | 498 // Id of the view most content is added to. The keyboard is NOT added here. |
| 532 Id content_view_id_; | 499 Id content_view_id_; |
| 533 | 500 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 561 window_manager_->RequestNavigate(source_view_id, target, nav_details.Pass()); | 528 window_manager_->RequestNavigate(source_view_id, target, nav_details.Pass()); |
| 562 } | 529 } |
| 563 | 530 |
| 564 } // namespace examples | 531 } // namespace examples |
| 565 } // namespace mojo | 532 } // namespace mojo |
| 566 | 533 |
| 567 MojoResult MojoMain(MojoHandle shell_handle) { | 534 MojoResult MojoMain(MojoHandle shell_handle) { |
| 568 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); | 535 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); |
| 569 return runner.Run(shell_handle); | 536 return runner.Run(shell_handle); |
| 570 } | 537 } |
| OLD | NEW |