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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "examples/keyboard/keyboard.mojom.h" | 7 #include "examples/keyboard/keyboard.mojom.h" |
8 #include "examples/window_manager/debug_panel.h" | 8 #include "examples/window_manager/debug_panel.h" |
9 #include "examples/window_manager/window_manager.mojom.h" | 9 #include "examples/window_manager/window_manager.mojom.h" |
10 #include "mojo/application/application_runner_chromium.h" | 10 #include "mojo/application/application_runner_chromium.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 view_->parent()->RemoveObserver(this); | 92 view_->parent()->RemoveObserver(this); |
93 } | 93 } |
94 | 94 |
95 View* view() { return view_; } | 95 View* view() { return view_; } |
96 | 96 |
97 void Init(ApplicationImpl* application, | 97 void Init(ApplicationImpl* application, |
98 ViewManager* view_manager, | 98 ViewManager* view_manager, |
99 View* parent, | 99 View* parent, |
100 const Rect& bounds) { | 100 const Rect& bounds) { |
101 view_manager_ = view_manager; | 101 view_manager_ = view_manager; |
102 view_ = View::Create(view_manager); | 102 view_ = view_manager->CreateView(); |
103 view_->SetBounds(bounds); | 103 view_->SetBounds(bounds); |
104 parent->AddChild(view_); | 104 parent->AddChild(view_); |
105 view_->Embed("mojo:keyboard"); | 105 view_->Embed("mojo:keyboard"); |
106 application->ConnectToService("mojo:keyboard", &keyboard_service_); | 106 application->ConnectToService("mojo:keyboard", &keyboard_service_); |
107 keyboard_service_.set_client(this); | 107 keyboard_service_.set_client(this); |
108 parent->AddObserver(this); | 108 parent->AddObserver(this); |
109 } | 109 } |
110 | 110 |
111 void Show(Id view_id, const Rect& bounds) { | 111 void Show(Id view_id, const Rect& bounds) { |
112 keyboard_service_->SetTarget(view_id); | 112 keyboard_service_->SetTarget(view_id); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 return true; | 345 return true; |
346 } | 346 } |
347 | 347 |
348 // Overridden from ViewManagerDelegate: | 348 // Overridden from ViewManagerDelegate: |
349 virtual void OnEmbed(View* root, | 349 virtual void OnEmbed(View* root, |
350 ServiceProviderImpl* exported_services, | 350 ServiceProviderImpl* exported_services, |
351 scoped_ptr<ServiceProvider> imported_services) override { | 351 scoped_ptr<ServiceProvider> imported_services) override { |
352 DCHECK(!view_manager_); | 352 DCHECK(!view_manager_); |
353 view_manager_ = root->view_manager(); | 353 view_manager_ = root->view_manager(); |
354 | 354 |
355 View* view = View::Create(view_manager_); | 355 View* view = view_manager_->CreateView(); |
356 root->AddChild(view); | 356 root->AddChild(view); |
357 Rect rect; | 357 Rect rect; |
358 rect.width = root->bounds().width; | 358 rect.width = root->bounds().width; |
359 rect.height = root->bounds().height; | 359 rect.height = root->bounds().height; |
360 view->SetBounds(rect); | 360 view->SetBounds(rect); |
361 view->SetVisible(true); | 361 view->SetVisible(true); |
362 content_view_id_ = view->id(); | 362 content_view_id_ = view->id(); |
363 | 363 |
364 Id launcher_ui_id = CreateLauncherUI(); | 364 Id launcher_ui_id = CreateLauncherUI(); |
365 Id control_panel_id = CreateControlPanel(view); | 365 Id control_panel_id = CreateControlPanel(view); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 view->bounds().height - (3 * kBorderInset + kTextfieldHeight); | 455 view->bounds().height - (3 * kBorderInset + kTextfieldHeight); |
456 if (!windows_.empty()) { | 456 if (!windows_.empty()) { |
457 bounds.x = windows_.back()->view()->bounds().x + 35; | 457 bounds.x = windows_.back()->view()->bounds().x + 35; |
458 bounds.y = windows_.back()->view()->bounds().y + 35; | 458 bounds.y = windows_.back()->view()->bounds().y + 35; |
459 } | 459 } |
460 return CreateWindow(bounds); | 460 return CreateWindow(bounds); |
461 } | 461 } |
462 | 462 |
463 Window* CreateWindow(const Rect& bounds) { | 463 Window* CreateWindow(const Rect& bounds) { |
464 View* content = view_manager_->GetViewById(content_view_id_); | 464 View* content = view_manager_->GetViewById(content_view_id_); |
465 View* view = View::Create(view_manager_); | 465 View* view = view_manager_->CreateView(); |
466 content->AddChild(view); | 466 content->AddChild(view); |
467 view->SetBounds(bounds); | 467 view->SetBounds(bounds); |
468 view->SetVisible(true); | 468 view->SetVisible(true); |
469 view->SetFocus(); | 469 view->SetFocus(); |
470 return new Window(this, view); | 470 return new Window(this, view); |
471 } | 471 } |
472 | 472 |
473 bool IsDescendantOfKeyboard(View* target) { | 473 bool IsDescendantOfKeyboard(View* target) { |
474 return keyboard_manager_.get() && | 474 return keyboard_manager_.get() && |
475 keyboard_manager_->view()->Contains(target); | 475 keyboard_manager_->view()->Contains(target); |
476 } | 476 } |
477 | 477 |
478 Id CreateControlPanel(View* root) { | 478 Id CreateControlPanel(View* root) { |
479 View* view = View::Create(view_manager_); | 479 View* view = view_manager_->CreateView(); |
480 root->AddChild(view); | 480 root->AddChild(view); |
481 | 481 |
482 Rect bounds; | 482 Rect bounds; |
483 bounds.x = root->bounds().width - kControlPanelWidth - kBorderInset; | 483 bounds.x = root->bounds().width - kControlPanelWidth - kBorderInset; |
484 bounds.y = kBorderInset * 2 + kTextfieldHeight; | 484 bounds.y = kBorderInset * 2 + kTextfieldHeight; |
485 bounds.width = kControlPanelWidth; | 485 bounds.width = kControlPanelWidth; |
486 bounds.height = | 486 bounds.height = |
487 root->bounds().height - kBorderInset * 3 - kTextfieldHeight; | 487 root->bounds().height - kBorderInset * 3 - kTextfieldHeight; |
488 view->SetBounds(bounds); | 488 view->SetBounds(bounds); |
489 view->SetVisible(true); | 489 view->SetVisible(true); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 window_manager_->RequestNavigate(view_id_, target, request.Pass()); | 546 window_manager_->RequestNavigate(view_id_, target, request.Pass()); |
547 } | 547 } |
548 | 548 |
549 } // namespace examples | 549 } // namespace examples |
550 } // namespace mojo | 550 } // namespace mojo |
551 | 551 |
552 MojoResult MojoMain(MojoHandle shell_handle) { | 552 MojoResult MojoMain(MojoHandle shell_handle) { |
553 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); | 553 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); |
554 return runner.Run(shell_handle); | 554 return runner.Run(shell_handle); |
555 } | 555 } |
OLD | NEW |