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

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

Issue 489493004: Update view manager to support content handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: png viewer works sorta Created 6 years, 4 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 | Annotate | Revision Log
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/cpp/application/application_connection.h" 10 #include "mojo/public/cpp/application/application_connection.h"
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // Overridden from DebugPanel::Delegate: 305 // Overridden from DebugPanel::Delegate:
306 virtual void CloseTopWindow() OVERRIDE { 306 virtual void CloseTopWindow() OVERRIDE {
307 if (!windows_.empty()) 307 if (!windows_.empty())
308 CloseWindow(windows_.back()->id()); 308 CloseWindow(windows_.back()->id());
309 } 309 }
310 310
311 virtual void RequestNavigate( 311 virtual void RequestNavigate(
312 uint32 source_view_id, 312 uint32 source_view_id,
313 Target target, 313 Target target,
314 NavigationDetailsPtr nav_details) OVERRIDE { 314 NavigationDetailsPtr nav_details) OVERRIDE {
315 launcher_->Launch(nav_details.Pass(), 315 OnLaunch(source_view_id, target, nav_details->request->url);
316 base::Bind(&WindowManager::OnLaunch,
317 base::Unretained(this),
318 source_view_id,
319 target));
320 } 316 }
321 317
322 private: 318 private:
323 // Overridden from ApplicationDelegate: 319 // Overridden from ApplicationDelegate:
324 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { 320 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
325 app_ = app; 321 app_ = app;
326 app->ConnectToService("mojo:mojo_launcher", &launcher_);
327 views_init_.reset(new ViewsInit); 322 views_init_.reset(new ViewsInit);
328 } 323 }
329 324
330 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) 325 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
331 MOJO_OVERRIDE { 326 MOJO_OVERRIDE {
332 connection->AddService(&window_manager_factory_); 327 connection->AddService(&window_manager_factory_);
333 connection->AddService(&navigator_host_factory_); 328 connection->AddService(&navigator_host_factory_);
334 connection->AddService(&view_manager_client_factory_); 329 connection->AddService(&view_manager_client_factory_);
335 return true; 330 return true;
336 } 331 }
(...skipping 27 matching lines...) Expand all
364 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { 359 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {
365 DCHECK_EQ(view_manager_, view_manager); 360 DCHECK_EQ(view_manager_, view_manager);
366 view_manager_ = NULL; 361 view_manager_ = NULL;
367 base::MessageLoop::current()->Quit(); 362 base::MessageLoop::current()->Quit();
368 } 363 }
369 364
370 // Overridden from WindowManagerDelegate: 365 // Overridden from WindowManagerDelegate:
371 virtual void Embed( 366 virtual void Embed(
372 const String& url, 367 const String& url,
373 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { 368 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE {
374 CreateWindow(url, 369 CreateWindow(url);
375 NavigationDetailsPtr().Pass(),
376 ResponseDetailsPtr().Pass());
377 } 370 }
378 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE { 371 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE {
379 // TODO(beng): More sophisticated focus handling than this is required! 372 // TODO(beng): More sophisticated focus handling than this is required!
380 if (event->action == EVENT_TYPE_MOUSE_PRESSED && 373 if (event->action == EVENT_TYPE_MOUSE_PRESSED &&
381 !IsDescendantOfKeyboard(target)) { 374 !IsDescendantOfKeyboard(target)) {
382 target->SetFocus(); 375 target->SetFocus();
383 } 376 }
384 view_manager_->DispatchEvent(target, event.Pass()); 377 view_manager_->DispatchEvent(target, event.Pass());
385 } 378 }
386 379
387 void OnLaunch( 380 void OnLaunch(
388 uint32 source_view_id, 381 uint32 source_view_id,
389 Target requested_target, 382 Target requested_target,
390 const mojo::String& handler_url, 383 const mojo::String& url) {
391 const mojo::String& view_url,
392 ResponseDetailsPtr response) {
393 // 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
395 // need to preserve that information.
396 NavigationDetailsPtr nav_details(NavigationDetails::New());
397 nav_details->request->url = view_url;
398
399 Target target = debug_panel_->navigation_target(); 384 Target target = debug_panel_->navigation_target();
400 if (target == TARGET_DEFAULT) { 385 if (target == TARGET_DEFAULT) {
401 if (requested_target != TARGET_DEFAULT) { 386 if (requested_target != TARGET_DEFAULT) {
402 target = requested_target; 387 target = requested_target;
403 } else { 388 } else {
404 // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin 389 // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin
405 // are different? 390 // are different?
406 target = TARGET_SOURCE_NODE; 391 target = TARGET_SOURCE_NODE;
407 } 392 }
408 } 393 }
409 394
410 View* dest_view = NULL; 395 View* dest_view = NULL;
411 if (target == TARGET_SOURCE_NODE) { 396 if (target == TARGET_SOURCE_NODE) {
412 View* source_view = view_manager_->GetViewById(source_view_id); 397 View* source_view = view_manager_->GetViewById(source_view_id);
413 bool app_initiated = std::find(windows_.begin(), windows_.end(), 398 bool app_initiated = std::find(windows_.begin(), windows_.end(),
414 source_view) != windows_.end(); 399 source_view) != windows_.end();
415 if (app_initiated) 400 if (app_initiated)
416 dest_view = source_view; 401 dest_view = source_view;
417 else if (!windows_.empty()) 402 else if (!windows_.empty())
418 dest_view = windows_.back(); 403 dest_view = windows_.back();
419 } 404 }
420 405
421 if (dest_view) 406 if (dest_view)
422 Embed(dest_view, handler_url, nav_details.Pass(), response.Pass()); 407 dest_view->Embed(url);
423 else 408 else
424 CreateWindow(handler_url, nav_details.Pass(), response.Pass()); 409 CreateWindow(url);
425 } 410 }
426 411
427 // TODO(beng): proper layout manager!! 412 // TODO(beng): proper layout manager!!
428 Id CreateLauncherUI() { 413 Id CreateLauncherUI() {
429 NavigationDetailsPtr nav_details; 414 NavigationDetailsPtr nav_details;
430 ResponseDetailsPtr response; 415 ResponseDetailsPtr response;
431 View* view = view_manager_->GetViewById(content_view_id_); 416 View* view = view_manager_->GetViewById(content_view_id_);
432 gfx::Rect bounds = view->bounds(); 417 gfx::Rect bounds = view->bounds();
433 bounds.Inset(kBorderInset, kBorderInset); 418 bounds.Inset(kBorderInset, kBorderInset);
434 bounds.set_height(kTextfieldHeight); 419 bounds.set_height(kTextfieldHeight);
435 launcher_ui_ = CreateChild(content_view_id_, "mojo:mojo_browser", bounds, 420 launcher_ui_ = CreateChild(content_view_id_, "mojo:mojo_browser", bounds);
436 nav_details.Pass(), response.Pass());
437 return launcher_ui_->id(); 421 return launcher_ui_->id();
438 } 422 }
439 423
440 void CreateWindow(const std::string& handler_url, 424 void CreateWindow(const std::string& url) {
441 NavigationDetailsPtr nav_details,
442 ResponseDetailsPtr response) {
443 View* view = view_manager_->GetViewById(content_view_id_); 425 View* view = view_manager_->GetViewById(content_view_id_);
444 gfx::Rect bounds(kBorderInset, 426 gfx::Rect bounds(kBorderInset,
445 2 * kBorderInset + kTextfieldHeight, 427 2 * kBorderInset + kTextfieldHeight,
446 view->bounds().width() - 3 * kBorderInset - 428 view->bounds().width() - 3 * kBorderInset -
447 kControlPanelWidth, 429 kControlPanelWidth,
448 view->bounds().height() - 430 view->bounds().height() -
449 (3 * kBorderInset + kTextfieldHeight)); 431 (3 * kBorderInset + kTextfieldHeight));
450 if (!windows_.empty()) { 432 if (!windows_.empty()) {
451 gfx::Point position = windows_.back()->bounds().origin(); 433 gfx::Point position = windows_.back()->bounds().origin();
452 position.Offset(35, 35); 434 position.Offset(35, 35);
453 bounds.set_origin(position); 435 bounds.set_origin(position);
454 } 436 }
455 windows_.push_back(CreateChild(content_view_id_, handler_url, bounds, 437 windows_.push_back(CreateChild(content_view_id_, url, bounds));
456 nav_details.Pass(), response.Pass()));
457 } 438 }
458 439
459 View* CreateChild(Id parent_id, 440 View* CreateChild(Id parent_id,
460 const std::string& url, 441 const std::string& url,
461 const gfx::Rect& bounds, 442 const gfx::Rect& bounds) {
462 NavigationDetailsPtr nav_details,
463 ResponseDetailsPtr response) {
464 View* view = view_manager_->GetViewById(parent_id); 443 View* view = view_manager_->GetViewById(parent_id);
465 View* embedded = View::Create(view_manager_); 444 View* embedded = View::Create(view_manager_);
466 view->AddChild(embedded); 445 view->AddChild(embedded);
467 embedded->SetBounds(bounds); 446 embedded->SetBounds(bounds);
468 Embed(embedded, url, nav_details.Pass(), response.Pass()); 447 embedded->Embed(url);
469 embedded->SetFocus(); 448 embedded->SetFocus();
470 return embedded; 449 return embedded;
471 } 450 }
472 451
473 void Embed(View* view, const std::string& app_url,
474 NavigationDetailsPtr nav_details,
475 ResponseDetailsPtr response) {
476 view->Embed(app_url);
477 if (nav_details) {
478 NavigatorPtr navigator;
479 app_->ConnectToService(app_url, &navigator);
480 navigator->Navigate(view->id(), nav_details.Pass(), response.Pass());
481 }
482 }
483
484 bool IsDescendantOfKeyboard(View* target) { 452 bool IsDescendantOfKeyboard(View* target) {
485 return keyboard_manager_.get() && 453 return keyboard_manager_.get() &&
486 keyboard_manager_->view()->Contains(target); 454 keyboard_manager_->view()->Contains(target);
487 } 455 }
488 456
489 Id CreateControlPanel(View* root) { 457 Id CreateControlPanel(View* root) {
490 View* view = View::Create(view_manager_); 458 View* view = View::Create(view_manager_);
491 root->AddChild(view); 459 root->AddChild(view);
492 460
493 gfx::Rect bounds(root->bounds().width() - kControlPanelWidth - 461 gfx::Rect bounds(root->bounds().width() - kControlPanelWidth -
494 kBorderInset, 462 kBorderInset,
495 kBorderInset * 2 + kTextfieldHeight, 463 kBorderInset * 2 + kTextfieldHeight,
496 kControlPanelWidth, 464 kControlPanelWidth,
497 root->bounds().height() - kBorderInset * 3 - 465 root->bounds().height() - kBorderInset * 3 -
498 kTextfieldHeight); 466 kTextfieldHeight);
499 view->SetBounds(bounds); 467 view->SetBounds(bounds);
500 468
501 debug_panel_ = new DebugPanel(this, view); 469 debug_panel_ = new DebugPanel(this, view);
502 return view->id(); 470 return view->id();
503 } 471 }
504 472
505 InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager> 473 InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager>
506 window_manager_factory_; 474 window_manager_factory_;
507 InterfaceFactoryImplWithContext<NavigatorHostImpl, WindowManager> 475 InterfaceFactoryImplWithContext<NavigatorHostImpl, WindowManager>
508 navigator_host_factory_; 476 navigator_host_factory_;
509 477
510 scoped_ptr<ViewsInit> views_init_; 478 scoped_ptr<ViewsInit> views_init_;
511 DebugPanel* debug_panel_; 479 DebugPanel* debug_panel_;
512 LauncherPtr launcher_;
513 View* launcher_ui_; 480 View* launcher_ui_;
514 std::vector<View*> windows_; 481 std::vector<View*> windows_;
515 ViewManager* view_manager_; 482 ViewManager* view_manager_;
516 ViewManagerClientFactory view_manager_client_factory_; 483 ViewManagerClientFactory view_manager_client_factory_;
517 scoped_ptr<RootLayoutManager> root_layout_manager_; 484 scoped_ptr<RootLayoutManager> root_layout_manager_;
518 485
519 // Id of the view most content is added to. The keyboard is NOT added here. 486 // Id of the view most content is added to. The keyboard is NOT added here.
520 Id content_view_id_; 487 Id content_view_id_;
521 488
522 scoped_ptr<KeyboardManager> keyboard_manager_; 489 scoped_ptr<KeyboardManager> keyboard_manager_;
(...skipping 27 matching lines...) Expand all
550 } 517 }
551 518
552 } // namespace examples 519 } // namespace examples
553 520
554 // static 521 // static
555 ApplicationDelegate* ApplicationDelegate::Create() { 522 ApplicationDelegate* ApplicationDelegate::Create() {
556 return new examples::WindowManager; 523 return new examples::WindowManager;
557 } 524 }
558 525
559 } // namespace mojo 526 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698