Chromium Code Reviews| 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" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 // Overridden from IWindowManager: | 65 // Overridden from IWindowManager: |
| 66 virtual void CloseWindow(Id node_id) OVERRIDE; | 66 virtual void CloseWindow(Id node_id) OVERRIDE; |
| 67 virtual void ShowKeyboard(Id view_id, RectPtr bounds) OVERRIDE; | 67 virtual void ShowKeyboard(Id view_id, RectPtr bounds) OVERRIDE; |
| 68 virtual void HideKeyboard(Id view_id) OVERRIDE; | 68 virtual void HideKeyboard(Id view_id) OVERRIDE; |
| 69 | 69 |
| 70 WindowManager* window_manager_; | 70 WindowManager* window_manager_; |
| 71 | 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection); | 72 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 class NavigatorHost : public InterfaceImpl<navigation::NavigatorHost> { | 75 class NavigatorHost : public InterfaceImpl<mojo::NavigatorHost> { |
|
darin (slow to review)
2014/07/25 03:37:29
nit: class NavigatorHostImpl
| |
| 76 public: | 76 public: |
| 77 explicit NavigatorHost(WindowManager* window_manager) | 77 explicit NavigatorHost(WindowManager* window_manager) |
| 78 : window_manager_(window_manager) {} | 78 : window_manager_(window_manager) {} |
| 79 virtual ~NavigatorHost() { | 79 virtual ~NavigatorHost() { |
| 80 } | 80 } |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 virtual void DidNavigateLocally(uint32 source_node_id, | 83 virtual void DidNavigateLocally(uint32 source_node_id, |
| 84 const mojo::String& url) OVERRIDE; | 84 const mojo::String& url) OVERRIDE; |
| 85 virtual void RequestNavigate( | 85 virtual void RequestNavigate( |
| 86 uint32 source_node_id, | 86 uint32 source_node_id, |
| 87 navigation::Target target, | 87 Target target, |
| 88 navigation::NavigationDetailsPtr nav_details) OVERRIDE; | 88 NavigationDetailsPtr nav_details) OVERRIDE; |
| 89 WindowManager* window_manager_; | 89 WindowManager* window_manager_; |
| 90 | 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(NavigatorHost); | 91 DISALLOW_COPY_AND_ASSIGN(NavigatorHost); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 class KeyboardManager : public KeyboardClient, | 94 class KeyboardManager : public KeyboardClient, |
| 95 public NodeObserver { | 95 public NodeObserver { |
| 96 public: | 96 public: |
| 97 KeyboardManager() : view_manager_(NULL), node_(NULL) { | 97 KeyboardManager() : view_manager_(NULL), node_(NULL) { |
| 98 } | 98 } |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 } | 310 } |
| 311 | 311 |
| 312 // Overridden from DebugPanel::Delegate: | 312 // Overridden from DebugPanel::Delegate: |
| 313 virtual void CloseTopWindow() OVERRIDE { | 313 virtual void CloseTopWindow() OVERRIDE { |
| 314 if (!windows_.empty()) | 314 if (!windows_.empty()) |
| 315 CloseWindow(windows_.back()->id()); | 315 CloseWindow(windows_.back()->id()); |
| 316 } | 316 } |
| 317 | 317 |
| 318 virtual void RequestNavigate( | 318 virtual void RequestNavigate( |
| 319 uint32 source_node_id, | 319 uint32 source_node_id, |
| 320 navigation::Target target, | 320 Target target, |
| 321 navigation::NavigationDetailsPtr nav_details) OVERRIDE { | 321 NavigationDetailsPtr nav_details) OVERRIDE { |
| 322 launcher_->Launch(nav_details->url, | 322 launcher_->Launch(nav_details->url, |
| 323 base::Bind(&WindowManager::OnLaunch, | 323 base::Bind(&WindowManager::OnLaunch, |
| 324 base::Unretained(this), | 324 base::Unretained(this), |
| 325 source_node_id, | 325 source_node_id, |
| 326 target)); | 326 target)); |
| 327 } | 327 } |
| 328 | 328 |
| 329 private: | 329 private: |
| 330 // Overridden from ApplicationDelegate: | 330 // Overridden from ApplicationDelegate: |
| 331 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { | 331 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { |
| 332 app_ = app; | 332 app_ = app; |
| 333 app->ConnectToService("mojo:mojo_launcher", &launcher_); | 333 app->ConnectToService("mojo:mojo_launcher", &launcher_); |
| 334 views_init_.reset(new ViewsInit); | 334 views_init_.reset(new ViewsInit); |
| 335 } | 335 } |
| 336 | 336 |
| 337 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 337 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| 338 MOJO_OVERRIDE { | 338 MOJO_OVERRIDE { |
| 339 connection->AddService<IWindowManager>(this); | 339 connection->AddService<IWindowManager>(this); |
| 340 connection->AddService<navigation::NavigatorHost>(this); | 340 connection->AddService<mojo::NavigatorHost>(this); |
| 341 connection->AddService(&view_manager_client_factory_); | 341 connection->AddService(&view_manager_client_factory_); |
| 342 return true; | 342 return true; |
| 343 } | 343 } |
| 344 | 344 |
| 345 // Overridden from ViewManagerDelegate: | 345 // Overridden from ViewManagerDelegate: |
| 346 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { | 346 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { |
| 347 DCHECK(!view_manager_); | 347 DCHECK(!view_manager_); |
| 348 view_manager_ = view_manager; | 348 view_manager_ = view_manager; |
| 349 view_manager_->SetWindowManagerDelegate(this); | 349 view_manager_->SetWindowManagerDelegate(this); |
| 350 | 350 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 369 } | 369 } |
| 370 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { | 370 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { |
| 371 DCHECK_EQ(view_manager_, view_manager); | 371 DCHECK_EQ(view_manager_, view_manager); |
| 372 view_manager_ = NULL; | 372 view_manager_ = NULL; |
| 373 base::MessageLoop::current()->Quit(); | 373 base::MessageLoop::current()->Quit(); |
| 374 } | 374 } |
| 375 | 375 |
| 376 // Overridden from WindowManagerDelegate: | 376 // Overridden from WindowManagerDelegate: |
| 377 virtual void Embed(const String& url) OVERRIDE { | 377 virtual void Embed(const String& url) OVERRIDE { |
| 378 CreateWindow(url, | 378 CreateWindow(url, |
| 379 navigation::NavigationDetailsPtr().Pass(), | 379 NavigationDetailsPtr().Pass(), |
| 380 navigation::ResponseDetailsPtr().Pass()); | 380 ResponseDetailsPtr().Pass()); |
| 381 } | 381 } |
| 382 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE { | 382 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE { |
| 383 // TODO(beng): More sophisticated focus handling than this is required! | 383 // TODO(beng): More sophisticated focus handling than this is required! |
| 384 if (event->action == EVENT_TYPE_MOUSE_PRESSED && | 384 if (event->action == EVENT_TYPE_MOUSE_PRESSED && |
| 385 !IsDescendantOfKeyboard(target)) { | 385 !IsDescendantOfKeyboard(target)) { |
| 386 target->node()->SetFocus(); | 386 target->node()->SetFocus(); |
| 387 } | 387 } |
| 388 view_manager_->DispatchEvent(target, event.Pass()); | 388 view_manager_->DispatchEvent(target, event.Pass()); |
| 389 } | 389 } |
| 390 | 390 |
| 391 void OnLaunch( | 391 void OnLaunch( |
| 392 uint32 source_node_id, | 392 uint32 source_node_id, |
| 393 navigation::Target requested_target, | 393 Target requested_target, |
| 394 const mojo::String& handler_url, | 394 const mojo::String& handler_url, |
| 395 const mojo::String& view_url, | 395 const mojo::String& view_url, |
| 396 navigation::ResponseDetailsPtr response) { | 396 ResponseDetailsPtr response) { |
| 397 navigation::NavigationDetailsPtr nav_details( | 397 NavigationDetailsPtr nav_details(NavigationDetails::New()); |
| 398 navigation::NavigationDetails::New()); | |
| 399 nav_details->url = view_url; | 398 nav_details->url = view_url; |
| 400 | 399 |
| 401 navigation::Target target = debug_panel_->navigation_target(); | 400 Target target = debug_panel_->navigation_target(); |
| 402 if (target == navigation::TARGET_DEFAULT) { | 401 if (target == TARGET_DEFAULT) { |
| 403 if (requested_target != navigation::TARGET_DEFAULT) { | 402 if (requested_target != TARGET_DEFAULT) { |
| 404 target = requested_target; | 403 target = requested_target; |
| 405 } else { | 404 } else { |
| 406 // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin | 405 // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin |
| 407 // are different? | 406 // are different? |
| 408 target = navigation::TARGET_SOURCE_NODE; | 407 target = TARGET_SOURCE_NODE; |
| 409 } | 408 } |
| 410 } | 409 } |
| 411 | 410 |
| 412 Node* dest_node = NULL; | 411 Node* dest_node = NULL; |
| 413 if (target == navigation::TARGET_SOURCE_NODE) { | 412 if (target == TARGET_SOURCE_NODE) { |
| 414 Node* source_node = view_manager_->GetNodeById(source_node_id); | 413 Node* source_node = view_manager_->GetNodeById(source_node_id); |
| 415 bool app_initiated = std::find(windows_.begin(), windows_.end(), | 414 bool app_initiated = std::find(windows_.begin(), windows_.end(), |
| 416 source_node) != windows_.end(); | 415 source_node) != windows_.end(); |
| 417 if (app_initiated) | 416 if (app_initiated) |
| 418 dest_node = source_node; | 417 dest_node = source_node; |
| 419 else if (!windows_.empty()) | 418 else if (!windows_.empty()) |
| 420 dest_node = windows_.back(); | 419 dest_node = windows_.back(); |
| 421 } | 420 } |
| 422 | 421 |
| 423 if (dest_node) | 422 if (dest_node) |
| 424 Embed(dest_node, handler_url, nav_details.Pass(), response.Pass()); | 423 Embed(dest_node, handler_url, nav_details.Pass(), response.Pass()); |
| 425 else | 424 else |
| 426 CreateWindow(handler_url, nav_details.Pass(), response.Pass()); | 425 CreateWindow(handler_url, nav_details.Pass(), response.Pass()); |
| 427 } | 426 } |
| 428 | 427 |
| 429 // TODO(beng): proper layout manager!! | 428 // TODO(beng): proper layout manager!! |
| 430 Id CreateLauncherUI() { | 429 Id CreateLauncherUI() { |
| 431 navigation::NavigationDetailsPtr nav_details; | 430 NavigationDetailsPtr nav_details; |
| 432 navigation::ResponseDetailsPtr response; | 431 ResponseDetailsPtr response; |
| 433 Node* node = view_manager_->GetNodeById(content_node_id_); | 432 Node* node = view_manager_->GetNodeById(content_node_id_); |
| 434 gfx::Rect bounds = node->bounds(); | 433 gfx::Rect bounds = node->bounds(); |
| 435 bounds.Inset(kBorderInset, kBorderInset); | 434 bounds.Inset(kBorderInset, kBorderInset); |
| 436 bounds.set_height(kTextfieldHeight); | 435 bounds.set_height(kTextfieldHeight); |
| 437 launcher_ui_ = CreateChild(content_node_id_, "mojo:mojo_browser", bounds, | 436 launcher_ui_ = CreateChild(content_node_id_, "mojo:mojo_browser", bounds, |
| 438 nav_details.Pass(), response.Pass()); | 437 nav_details.Pass(), response.Pass()); |
| 439 return launcher_ui_->id(); | 438 return launcher_ui_->id(); |
| 440 } | 439 } |
| 441 | 440 |
| 442 void CreateWindow(const std::string& handler_url, | 441 void CreateWindow(const std::string& handler_url, |
| 443 navigation::NavigationDetailsPtr nav_details, | 442 NavigationDetailsPtr nav_details, |
| 444 navigation::ResponseDetailsPtr response) { | 443 ResponseDetailsPtr response) { |
| 445 Node* node = view_manager_->GetNodeById(content_node_id_); | 444 Node* node = view_manager_->GetNodeById(content_node_id_); |
| 446 gfx::Rect bounds(kBorderInset, | 445 gfx::Rect bounds(kBorderInset, |
| 447 2 * kBorderInset + kTextfieldHeight, | 446 2 * kBorderInset + kTextfieldHeight, |
| 448 node->bounds().width() - 3 * kBorderInset - | 447 node->bounds().width() - 3 * kBorderInset - |
| 449 kControlPanelWidth, | 448 kControlPanelWidth, |
| 450 node->bounds().height() - | 449 node->bounds().height() - |
| 451 (3 * kBorderInset + kTextfieldHeight)); | 450 (3 * kBorderInset + kTextfieldHeight)); |
| 452 if (!windows_.empty()) { | 451 if (!windows_.empty()) { |
| 453 gfx::Point position = windows_.back()->bounds().origin(); | 452 gfx::Point position = windows_.back()->bounds().origin(); |
| 454 position.Offset(35, 35); | 453 position.Offset(35, 35); |
| 455 bounds.set_origin(position); | 454 bounds.set_origin(position); |
| 456 } | 455 } |
| 457 windows_.push_back(CreateChild(content_node_id_, handler_url, bounds, | 456 windows_.push_back(CreateChild(content_node_id_, handler_url, bounds, |
| 458 nav_details.Pass(), response.Pass())); | 457 nav_details.Pass(), response.Pass())); |
| 459 } | 458 } |
| 460 | 459 |
| 461 Node* CreateChild(Id parent_id, | 460 Node* CreateChild(Id parent_id, |
| 462 const std::string& url, | 461 const std::string& url, |
| 463 const gfx::Rect& bounds, | 462 const gfx::Rect& bounds, |
| 464 navigation::NavigationDetailsPtr nav_details, | 463 NavigationDetailsPtr nav_details, |
| 465 navigation::ResponseDetailsPtr response) { | 464 ResponseDetailsPtr response) { |
| 466 Node* node = view_manager_->GetNodeById(parent_id); | 465 Node* node = view_manager_->GetNodeById(parent_id); |
| 467 Node* embedded = Node::Create(view_manager_); | 466 Node* embedded = Node::Create(view_manager_); |
| 468 node->AddChild(embedded); | 467 node->AddChild(embedded); |
| 469 embedded->SetBounds(bounds); | 468 embedded->SetBounds(bounds); |
| 470 Embed(embedded, url, nav_details.Pass(), response.Pass()); | 469 Embed(embedded, url, nav_details.Pass(), response.Pass()); |
| 471 embedded->SetFocus(); | 470 embedded->SetFocus(); |
| 472 return embedded; | 471 return embedded; |
| 473 } | 472 } |
| 474 | 473 |
| 475 void Embed(Node* node, const std::string& app_url, | 474 void Embed(Node* node, const std::string& app_url, |
| 476 navigation::NavigationDetailsPtr nav_details, | 475 NavigationDetailsPtr nav_details, |
| 477 navigation::ResponseDetailsPtr response) { | 476 ResponseDetailsPtr response) { |
| 478 node->Embed(app_url); | 477 node->Embed(app_url); |
| 479 if (nav_details) { | 478 if (nav_details) { |
| 480 navigation::NavigatorPtr navigator; | 479 NavigatorPtr navigator; |
| 481 app_->ConnectToService(app_url, &navigator); | 480 app_->ConnectToService(app_url, &navigator); |
| 482 navigator->Navigate(node->id(), nav_details.Pass(), response.Pass()); | 481 navigator->Navigate(node->id(), nav_details.Pass(), response.Pass()); |
| 483 } | 482 } |
| 484 } | 483 } |
| 485 | 484 |
| 486 bool IsDescendantOfKeyboard(View* target) { | 485 bool IsDescendantOfKeyboard(View* target) { |
| 487 return keyboard_manager_.get() && | 486 return keyboard_manager_.get() && |
| 488 keyboard_manager_->node()->Contains(target->node()); | 487 keyboard_manager_->node()->Contains(target->node()); |
| 489 } | 488 } |
| 490 | 489 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 501 root->bounds().height() - kBorderInset * 3 - | 500 root->bounds().height() - kBorderInset * 3 - |
| 502 kTextfieldHeight); | 501 kTextfieldHeight); |
| 503 node->SetBounds(bounds); | 502 node->SetBounds(bounds); |
| 504 | 503 |
| 505 debug_panel_ = new DebugPanel(this, node); | 504 debug_panel_ = new DebugPanel(this, node); |
| 506 return node->id(); | 505 return node->id(); |
| 507 } | 506 } |
| 508 | 507 |
| 509 scoped_ptr<ViewsInit> views_init_; | 508 scoped_ptr<ViewsInit> views_init_; |
| 510 DebugPanel* debug_panel_; | 509 DebugPanel* debug_panel_; |
| 511 launcher::LauncherPtr launcher_; | 510 LauncherPtr launcher_; |
| 512 Node* launcher_ui_; | 511 Node* launcher_ui_; |
| 513 std::vector<Node*> windows_; | 512 std::vector<Node*> windows_; |
| 514 ViewManager* view_manager_; | 513 ViewManager* view_manager_; |
| 515 ViewManagerClientFactory view_manager_client_factory_; | 514 ViewManagerClientFactory view_manager_client_factory_; |
| 516 scoped_ptr<RootLayoutManager> root_layout_manager_; | 515 scoped_ptr<RootLayoutManager> root_layout_manager_; |
| 517 | 516 |
| 518 // Id of the node most content is added to. The keyboard is NOT added here. | 517 // Id of the node most content is added to. The keyboard is NOT added here. |
| 519 Id content_node_id_; | 518 Id content_node_id_; |
| 520 | 519 |
| 521 scoped_ptr<KeyboardManager> keyboard_manager_; | 520 scoped_ptr<KeyboardManager> keyboard_manager_; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 536 window_manager_->HideKeyboard(node_id); | 535 window_manager_->HideKeyboard(node_id); |
| 537 } | 536 } |
| 538 | 537 |
| 539 void NavigatorHost::DidNavigateLocally(uint32 source_node_id, | 538 void NavigatorHost::DidNavigateLocally(uint32 source_node_id, |
| 540 const mojo::String& url) { | 539 const mojo::String& url) { |
| 541 window_manager_->DidNavigateLocally(source_node_id, url); | 540 window_manager_->DidNavigateLocally(source_node_id, url); |
| 542 } | 541 } |
| 543 | 542 |
| 544 void NavigatorHost::RequestNavigate( | 543 void NavigatorHost::RequestNavigate( |
| 545 uint32 source_node_id, | 544 uint32 source_node_id, |
| 546 navigation::Target target, | 545 Target target, |
| 547 navigation::NavigationDetailsPtr nav_details) { | 546 NavigationDetailsPtr nav_details) { |
| 548 window_manager_->RequestNavigate(source_node_id, target, nav_details.Pass()); | 547 window_manager_->RequestNavigate(source_node_id, target, nav_details.Pass()); |
| 549 } | 548 } |
| 550 | 549 |
| 551 } // namespace examples | 550 } // namespace examples |
| 552 | 551 |
| 553 // static | 552 // static |
| 554 ApplicationDelegate* ApplicationDelegate::Create() { | 553 ApplicationDelegate* ApplicationDelegate::Create() { |
| 555 return new examples::WindowManager; | 554 return new examples::WindowManager; |
| 556 } | 555 } |
| 557 | 556 |
| 558 } // namespace mojo | 557 } // namespace mojo |
| OLD | NEW |