Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(707)

Side by Side Diff: mojo/examples/window_manager/window_manager.cc

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

Powered by Google App Engine
This is Rietveld 408576698