| 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" |
| 11 #include "mojo/public/cpp/application/application_connection.h" | 11 #include "mojo/public/cpp/application/application_connection.h" |
| 12 #include "mojo/public/cpp/application/application_delegate.h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
| 13 #include "mojo/public/cpp/application/application_impl.h" | 13 #include "mojo/public/cpp/application/application_impl.h" |
| 14 #include "mojo/public/cpp/application/application_runner_chromium.h" | 14 #include "mojo/public/cpp/application/application_runner_chromium.h" |
| 15 #include "mojo/public/cpp/application/interface_factory_impl.h" | 15 #include "mojo/public/cpp/application/interface_factory_impl.h" |
| 16 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 16 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 17 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 17 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 18 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
| 18 #include "mojo/services/public/cpp/view_manager/view.h" | 19 #include "mojo/services/public/cpp/view_manager/view.h" |
| 19 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 20 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 21 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 21 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 22 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 22 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" | 23 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" |
| 23 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" | 24 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" |
| 24 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" | 25 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" |
| 25 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 26 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 virtual void ShowKeyboard(Id view_id, RectPtr bounds) OVERRIDE; | 60 virtual void ShowKeyboard(Id view_id, RectPtr bounds) OVERRIDE; |
| 60 virtual void HideKeyboard(Id view_id) OVERRIDE; | 61 virtual void HideKeyboard(Id view_id) OVERRIDE; |
| 61 | 62 |
| 62 WindowManager* window_manager_; | 63 WindowManager* window_manager_; |
| 63 | 64 |
| 64 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection); | 65 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection); |
| 65 }; | 66 }; |
| 66 | 67 |
| 67 class NavigatorHostImpl : public InterfaceImpl<NavigatorHost> { | 68 class NavigatorHostImpl : public InterfaceImpl<NavigatorHost> { |
| 68 public: | 69 public: |
| 69 explicit NavigatorHostImpl(WindowManager* window_manager) | 70 explicit NavigatorHostImpl(WindowManager* window_manager, Id view_id) |
| 70 : window_manager_(window_manager) {} | 71 : window_manager_(window_manager), view_id_(view_id) {} |
| 71 virtual ~NavigatorHostImpl() { | 72 virtual ~NavigatorHostImpl() { |
| 72 } | 73 } |
| 73 | 74 |
| 74 private: | 75 private: |
| 75 virtual void DidNavigateLocally(uint32 source_view_id, | 76 virtual void DidNavigateLocally(const mojo::String& url) OVERRIDE; |
| 76 const mojo::String& url) OVERRIDE; | |
| 77 virtual void RequestNavigate( | 77 virtual void RequestNavigate( |
| 78 uint32 source_view_id, | |
| 79 Target target, | 78 Target target, |
| 80 NavigationDetailsPtr nav_details) OVERRIDE; | 79 NavigationDetailsPtr nav_details) OVERRIDE; |
| 80 |
| 81 WindowManager* window_manager_; | 81 WindowManager* window_manager_; |
| 82 Id view_id_; |
| 82 | 83 |
| 83 DISALLOW_COPY_AND_ASSIGN(NavigatorHostImpl); | 84 DISALLOW_COPY_AND_ASSIGN(NavigatorHostImpl); |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 class KeyboardManager : public KeyboardClient, | 87 class KeyboardManager : public KeyboardClient, |
| 87 public ViewObserver { | 88 public ViewObserver { |
| 88 public: | 89 public: |
| 89 KeyboardManager() : view_manager_(NULL), view_(NULL) { | 90 KeyboardManager() : view_manager_(NULL), view_(NULL) { |
| 90 } | 91 } |
| 91 virtual ~KeyboardManager() { | 92 virtual ~KeyboardManager() { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 243 |
| 243 View* root_; | 244 View* root_; |
| 244 ViewManager* view_manager_; | 245 ViewManager* view_manager_; |
| 245 const Id content_view_id_; | 246 const Id content_view_id_; |
| 246 const Id launcher_ui_view_id_; | 247 const Id launcher_ui_view_id_; |
| 247 const Id control_panel_view_id_; | 248 const Id control_panel_view_id_; |
| 248 | 249 |
| 249 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); | 250 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); |
| 250 }; | 251 }; |
| 251 | 252 |
| 253 class Window : public InterfaceFactory<NavigatorHost> { |
| 254 public: |
| 255 Window(WindowManager* window_manager, View* view) |
| 256 : window_manager_(window_manager), view_(view) {} |
| 257 |
| 258 virtual ~Window() {} |
| 259 |
| 260 View* view() const { return view_; } |
| 261 |
| 262 void Embed(const std::string& url) { |
| 263 scoped_ptr<ServiceProviderImpl> service_provider_impl( |
| 264 new ServiceProviderImpl()); |
| 265 service_provider_impl->AddService<NavigatorHost>(this); |
| 266 view_->Embed(url, service_provider_impl.Pass()); |
| 267 } |
| 268 |
| 269 private: |
| 270 // InterfaceFactory<NavigatorHost> |
| 271 virtual void Create(ApplicationConnection* connection, |
| 272 InterfaceRequest<NavigatorHost> request) OVERRIDE { |
| 273 BindToRequest(new NavigatorHostImpl(window_manager_, view_->id()), |
| 274 &request); |
| 275 } |
| 276 |
| 277 WindowManager* window_manager_; |
| 278 View* view_; |
| 279 }; |
| 280 |
| 252 class WindowManager | 281 class WindowManager |
| 253 : public ApplicationDelegate, | 282 : public ApplicationDelegate, |
| 254 public DebugPanel::Delegate, | 283 public DebugPanel::Delegate, |
| 255 public ViewManagerDelegate, | 284 public ViewManagerDelegate, |
| 256 public WindowManagerDelegate, | 285 public WindowManagerDelegate, |
| 257 public ui::EventHandler { | 286 public ui::EventHandler { |
| 258 public: | 287 public: |
| 259 WindowManager() | 288 WindowManager() |
| 260 : window_manager_factory_(this), | 289 : window_manager_factory_(this), |
| 261 navigator_host_factory_(this), | |
| 262 launcher_ui_(NULL), | 290 launcher_ui_(NULL), |
| 263 view_manager_(NULL), | 291 view_manager_(NULL), |
| 264 window_manager_app_(new WindowManagerApp(this, this)), | 292 window_manager_app_(new WindowManagerApp(this, this)), |
| 265 app_(NULL) {} | 293 app_(NULL) {} |
| 266 | 294 |
| 267 virtual ~WindowManager() { | 295 virtual ~WindowManager() { |
| 268 // host() may be destroyed by the time we get here. | 296 // host() may be destroyed by the time we get here. |
| 269 // TODO: figure out a way to always cleanly remove handler. | 297 // TODO: figure out a way to always cleanly remove handler. |
| 270 if (window_manager_app_->host()) | 298 if (window_manager_app_->host()) |
| 271 window_manager_app_->host()->window()->RemovePreTargetHandler(this); | 299 window_manager_app_->host()->window()->RemovePreTargetHandler(this); |
| 272 } | 300 } |
| 273 | 301 |
| 274 void CloseWindow(Id view_id) { | 302 void CloseWindow(Id view_id) { |
| 275 View* view = view_manager_->GetViewById(view_id); | 303 WindowVector::iterator iter = GetWindowByViewId(view_id); |
| 276 DCHECK(view); | |
| 277 std::vector<View*>::iterator iter = | |
| 278 std::find(windows_.begin(), windows_.end(), view); | |
| 279 DCHECK(iter != windows_.end()); | 304 DCHECK(iter != windows_.end()); |
| 280 windows_.erase(iter); | 305 windows_.erase(iter); |
| 281 view->Destroy(); | 306 (*iter)->view()->Destroy(); |
| 282 } | 307 } |
| 283 | 308 |
| 284 void ShowKeyboard(Id view_id, const gfx::Rect& bounds) { | 309 void ShowKeyboard(Id view_id, const gfx::Rect& bounds) { |
| 285 // TODO: this needs to validate |view_id|. That is, it shouldn't assume | 310 // TODO: this needs to validate |view_id|. That is, it shouldn't assume |
| 286 // |view_id| is valid and it also needs to make sure the client that sent | 311 // |view_id| is valid and it also needs to make sure the client that sent |
| 287 // this really owns |view_id|. | 312 // this really owns |view_id|. |
| 288 // TODO: honor |bounds|. | 313 // TODO: honor |bounds|. |
| 289 if (!keyboard_manager_) { | 314 if (!keyboard_manager_) { |
| 290 keyboard_manager_.reset(new KeyboardManager); | 315 keyboard_manager_.reset(new KeyboardManager); |
| 291 View* parent = view_manager_->GetRoots().back(); | 316 View* parent = view_manager_->GetRoots().back(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 307 } | 332 } |
| 308 | 333 |
| 309 void DidNavigateLocally(uint32 source_view_id, const mojo::String& url) { | 334 void DidNavigateLocally(uint32 source_view_id, const mojo::String& url) { |
| 310 LOG(ERROR) << "DidNavigateLocally: source_view_id: " << source_view_id | 335 LOG(ERROR) << "DidNavigateLocally: source_view_id: " << source_view_id |
| 311 << " url: " << url.To<std::string>(); | 336 << " url: " << url.To<std::string>(); |
| 312 } | 337 } |
| 313 | 338 |
| 314 // Overridden from DebugPanel::Delegate: | 339 // Overridden from DebugPanel::Delegate: |
| 315 virtual void CloseTopWindow() OVERRIDE { | 340 virtual void CloseTopWindow() OVERRIDE { |
| 316 if (!windows_.empty()) | 341 if (!windows_.empty()) |
| 317 CloseWindow(windows_.back()->id()); | 342 CloseWindow(windows_.back()->view()->id()); |
| 318 } | 343 } |
| 319 | 344 |
| 320 virtual void RequestNavigate( | 345 virtual void RequestNavigate( |
| 321 uint32 source_view_id, | 346 uint32 source_view_id, |
| 322 Target target, | 347 Target target, |
| 323 NavigationDetailsPtr nav_details) OVERRIDE { | 348 NavigationDetailsPtr nav_details) OVERRIDE { |
| 324 OnLaunch(source_view_id, target, nav_details->request->url); | 349 OnLaunch(source_view_id, target, nav_details->request->url); |
| 325 } | 350 } |
| 326 | 351 |
| 327 private: | 352 private: |
| 353 typedef std::vector<Window*> WindowVector; |
| 354 |
| 328 // Overridden from ApplicationDelegate: | 355 // Overridden from ApplicationDelegate: |
| 329 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { | 356 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { |
| 330 app_ = app; | 357 app_ = app; |
| 331 views_init_.reset(new ViewsInit); | 358 views_init_.reset(new ViewsInit); |
| 332 window_manager_app_->Initialize(app); | 359 window_manager_app_->Initialize(app); |
| 333 } | 360 } |
| 334 | 361 |
| 335 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 362 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| 336 MOJO_OVERRIDE { | 363 MOJO_OVERRIDE { |
| 337 connection->AddService(&window_manager_factory_); | 364 connection->AddService(&window_manager_factory_); |
| 338 connection->AddService(&navigator_host_factory_); | |
| 339 window_manager_app_->ConfigureIncomingConnection(connection); | 365 window_manager_app_->ConfigureIncomingConnection(connection); |
| 340 return true; | 366 return true; |
| 341 } | 367 } |
| 342 | 368 |
| 343 // Overridden from ViewManagerDelegate: | 369 // Overridden from ViewManagerDelegate: |
| 344 virtual void OnEmbed(ViewManager* view_manager, | 370 virtual void OnEmbed(ViewManager* view_manager, |
| 345 View* root, | 371 View* root, |
| 346 ServiceProviderImpl* exported_services, | 372 ServiceProviderImpl* exported_services, |
| 347 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { | 373 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { |
| 348 DCHECK(!view_manager_); | 374 DCHECK(!view_manager_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 370 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { | 396 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { |
| 371 DCHECK_EQ(view_manager_, view_manager); | 397 DCHECK_EQ(view_manager_, view_manager); |
| 372 view_manager_ = NULL; | 398 view_manager_ = NULL; |
| 373 base::MessageLoop::current()->Quit(); | 399 base::MessageLoop::current()->Quit(); |
| 374 } | 400 } |
| 375 | 401 |
| 376 // Overridden from WindowManagerDelegate: | 402 // Overridden from WindowManagerDelegate: |
| 377 virtual void Embed( | 403 virtual void Embed( |
| 378 const String& url, | 404 const String& url, |
| 379 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { | 405 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { |
| 380 CreateWindow(url); | 406 const Id kInvalidSourceViewId = 0; |
| 407 OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url); |
| 381 } | 408 } |
| 382 virtual void DispatchEvent(EventPtr event) MOJO_OVERRIDE {} | 409 virtual void DispatchEvent(EventPtr event) MOJO_OVERRIDE {} |
| 383 | 410 |
| 384 // Overridden from ui::EventHandler: | 411 // Overridden from ui::EventHandler: |
| 385 virtual void OnEvent(ui::Event* event) OVERRIDE { | 412 virtual void OnEvent(ui::Event* event) OVERRIDE { |
| 386 View* view = WindowManagerApp::GetViewForWindow( | 413 View* view = WindowManagerApp::GetViewForWindow( |
| 387 static_cast<aura::Window*>(event->target())); | 414 static_cast<aura::Window*>(event->target())); |
| 388 if (event->type() == ui::ET_MOUSE_PRESSED && | 415 if (event->type() == ui::ET_MOUSE_PRESSED && |
| 389 !IsDescendantOfKeyboard(view)) { | 416 !IsDescendantOfKeyboard(view)) { |
| 390 view->SetFocus(); | 417 view->SetFocus(); |
| 391 } | 418 } |
| 392 } | 419 } |
| 393 | 420 |
| 394 void OnLaunch( | 421 void OnLaunch( |
| 395 uint32 source_view_id, | 422 uint32 source_view_id, |
| 396 Target requested_target, | 423 Target requested_target, |
| 397 const mojo::String& url) { | 424 const mojo::String& url) { |
| 398 Target target = debug_panel_->navigation_target(); | 425 Target target = debug_panel_->navigation_target(); |
| 399 if (target == TARGET_DEFAULT) { | 426 if (target == TARGET_DEFAULT) { |
| 400 if (requested_target != TARGET_DEFAULT) { | 427 if (requested_target != TARGET_DEFAULT) { |
| 401 target = requested_target; | 428 target = requested_target; |
| 402 } else { | 429 } else { |
| 403 // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin | 430 // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin |
| 404 // are different? | 431 // are different? |
| 405 target = TARGET_SOURCE_NODE; | 432 target = TARGET_SOURCE_NODE; |
| 406 } | 433 } |
| 407 } | 434 } |
| 408 | 435 |
| 409 View* dest_view = NULL; | 436 Window* dest_view = NULL; |
| 410 if (target == TARGET_SOURCE_NODE) { | 437 if (target == TARGET_SOURCE_NODE) { |
| 411 View* source_view = view_manager_->GetViewById(source_view_id); | 438 WindowVector::iterator source_view = GetWindowByViewId(source_view_id); |
| 412 bool app_initiated = std::find(windows_.begin(), windows_.end(), | 439 bool app_initiated = source_view != windows_.end(); |
| 413 source_view) != windows_.end(); | |
| 414 if (app_initiated) | 440 if (app_initiated) |
| 415 dest_view = source_view; | 441 dest_view = *source_view; |
| 416 else if (!windows_.empty()) | 442 else if (!windows_.empty()) |
| 417 dest_view = windows_.back(); | 443 dest_view = windows_.back(); |
| 418 } | 444 } |
| 419 | 445 |
| 420 if (dest_view) | 446 if (!dest_view) { |
| 421 dest_view->Embed(url); | 447 dest_view = CreateWindow(); |
| 422 else | 448 windows_.push_back(dest_view); |
| 423 CreateWindow(url); | 449 } |
| 450 |
| 451 dest_view->Embed(url); |
| 424 } | 452 } |
| 425 | 453 |
| 426 // TODO(beng): proper layout manager!! | 454 // TODO(beng): proper layout manager!! |
| 427 Id CreateLauncherUI() { | 455 Id CreateLauncherUI() { |
| 428 NavigationDetailsPtr nav_details; | 456 NavigationDetailsPtr nav_details; |
| 429 ResponseDetailsPtr response; | 457 ResponseDetailsPtr response; |
| 430 View* view = view_manager_->GetViewById(content_view_id_); | 458 View* view = view_manager_->GetViewById(content_view_id_); |
| 431 gfx::Rect bounds = view->bounds(); | 459 gfx::Rect bounds = view->bounds(); |
| 432 bounds.Inset(kBorderInset, kBorderInset); | 460 bounds.Inset(kBorderInset, kBorderInset); |
| 433 bounds.set_height(kTextfieldHeight); | 461 bounds.set_height(kTextfieldHeight); |
| 434 launcher_ui_ = CreateChild(content_view_id_, "mojo:mojo_browser", bounds); | 462 launcher_ui_ = CreateWindow(bounds); |
| 435 return launcher_ui_->id(); | 463 launcher_ui_->Embed("mojo:mojo_browser"); |
| 464 return launcher_ui_->view()->id(); |
| 436 } | 465 } |
| 437 | 466 |
| 438 void CreateWindow(const std::string& url) { | 467 Window* CreateWindow() { |
| 439 View* view = view_manager_->GetViewById(content_view_id_); | 468 View* view = view_manager_->GetViewById(content_view_id_); |
| 440 gfx::Rect bounds(kBorderInset, | 469 gfx::Rect bounds(kBorderInset, |
| 441 2 * kBorderInset + kTextfieldHeight, | 470 2 * kBorderInset + kTextfieldHeight, |
| 442 view->bounds().width() - 3 * kBorderInset - | 471 view->bounds().width() - 3 * kBorderInset - |
| 443 kControlPanelWidth, | 472 kControlPanelWidth, |
| 444 view->bounds().height() - | 473 view->bounds().height() - |
| 445 (3 * kBorderInset + kTextfieldHeight)); | 474 (3 * kBorderInset + kTextfieldHeight)); |
| 446 if (!windows_.empty()) { | 475 if (!windows_.empty()) { |
| 447 gfx::Point position = windows_.back()->bounds().origin(); | 476 gfx::Point position = windows_.back()->view()->bounds().origin(); |
| 448 position.Offset(35, 35); | 477 position.Offset(35, 35); |
| 449 bounds.set_origin(position); | 478 bounds.set_origin(position); |
| 450 } | 479 } |
| 451 windows_.push_back(CreateChild(content_view_id_, url, bounds)); | 480 return CreateWindow(bounds); |
| 452 } | 481 } |
| 453 | 482 |
| 454 View* CreateChild(Id parent_id, | 483 Window* CreateWindow(const gfx::Rect& bounds) { |
| 455 const std::string& url, | 484 View* content = view_manager_->GetViewById(content_view_id_); |
| 456 const gfx::Rect& bounds) { | 485 View* view = View::Create(view_manager_); |
| 457 View* view = view_manager_->GetViewById(parent_id); | 486 content->AddChild(view); |
| 458 View* embedded = View::Create(view_manager_); | 487 view->SetBounds(bounds); |
| 459 view->AddChild(embedded); | 488 view->SetFocus(); |
| 460 embedded->SetBounds(bounds); | 489 return new Window(this, view); |
| 461 embedded->Embed(url); | |
| 462 embedded->SetFocus(); | |
| 463 return embedded; | |
| 464 } | 490 } |
| 465 | 491 |
| 466 bool IsDescendantOfKeyboard(View* target) { | 492 bool IsDescendantOfKeyboard(View* target) { |
| 467 return keyboard_manager_.get() && | 493 return keyboard_manager_.get() && |
| 468 keyboard_manager_->view()->Contains(target); | 494 keyboard_manager_->view()->Contains(target); |
| 469 } | 495 } |
| 470 | 496 |
| 471 Id CreateControlPanel(View* root) { | 497 Id CreateControlPanel(View* root) { |
| 472 View* view = View::Create(view_manager_); | 498 View* view = View::Create(view_manager_); |
| 473 root->AddChild(view); | 499 root->AddChild(view); |
| 474 | 500 |
| 475 gfx::Rect bounds(root->bounds().width() - kControlPanelWidth - | 501 gfx::Rect bounds(root->bounds().width() - kControlPanelWidth - |
| 476 kBorderInset, | 502 kBorderInset, |
| 477 kBorderInset * 2 + kTextfieldHeight, | 503 kBorderInset * 2 + kTextfieldHeight, |
| 478 kControlPanelWidth, | 504 kControlPanelWidth, |
| 479 root->bounds().height() - kBorderInset * 3 - | 505 root->bounds().height() - kBorderInset * 3 - |
| 480 kTextfieldHeight); | 506 kTextfieldHeight); |
| 481 view->SetBounds(bounds); | 507 view->SetBounds(bounds); |
| 482 | 508 |
| 483 debug_panel_ = new DebugPanel(this, view); | 509 debug_panel_ = new DebugPanel(this, view); |
| 484 return view->id(); | 510 return view->id(); |
| 485 } | 511 } |
| 486 | 512 |
| 513 WindowVector::iterator GetWindowByViewId(Id view_id) { |
| 514 for (std::vector<Window*>::iterator iter = windows_.begin(); |
| 515 iter != windows_.end(); |
| 516 ++iter) { |
| 517 if ((*iter)->view()->id() == view_id) { |
| 518 return iter; |
| 519 } |
| 520 } |
| 521 return windows_.end(); |
| 522 } |
| 523 |
| 487 InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager> | 524 InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager> |
| 488 window_manager_factory_; | 525 window_manager_factory_; |
| 489 InterfaceFactoryImplWithContext<NavigatorHostImpl, WindowManager> | |
| 490 navigator_host_factory_; | |
| 491 | 526 |
| 492 scoped_ptr<ViewsInit> views_init_; | 527 scoped_ptr<ViewsInit> views_init_; |
| 493 DebugPanel* debug_panel_; | 528 DebugPanel* debug_panel_; |
| 494 View* launcher_ui_; | 529 Window* launcher_ui_; |
| 495 std::vector<View*> windows_; | 530 WindowVector windows_; |
| 496 ViewManager* view_manager_; | 531 ViewManager* view_manager_; |
| 497 scoped_ptr<RootLayoutManager> root_layout_manager_; | 532 scoped_ptr<RootLayoutManager> root_layout_manager_; |
| 498 | 533 |
| 499 scoped_ptr<WindowManagerApp> window_manager_app_; | 534 scoped_ptr<WindowManagerApp> window_manager_app_; |
| 500 | 535 |
| 501 // Id of the view most content is added to. The keyboard is NOT added here. | 536 // Id of the view most content is added to. The keyboard is NOT added here. |
| 502 Id content_view_id_; | 537 Id content_view_id_; |
| 503 | 538 |
| 504 scoped_ptr<KeyboardManager> keyboard_manager_; | 539 scoped_ptr<KeyboardManager> keyboard_manager_; |
| 505 ApplicationImpl* app_; | 540 ApplicationImpl* app_; |
| 506 | 541 |
| 507 DISALLOW_COPY_AND_ASSIGN(WindowManager); | 542 DISALLOW_COPY_AND_ASSIGN(WindowManager); |
| 508 }; | 543 }; |
| 509 | 544 |
| 510 void WindowManagerConnection::CloseWindow(Id view_id) { | 545 void WindowManagerConnection::CloseWindow(Id view_id) { |
| 511 window_manager_->CloseWindow(view_id); | 546 window_manager_->CloseWindow(view_id); |
| 512 } | 547 } |
| 513 | 548 |
| 514 void WindowManagerConnection::ShowKeyboard(Id view_id, RectPtr bounds) { | 549 void WindowManagerConnection::ShowKeyboard(Id view_id, RectPtr bounds) { |
| 515 window_manager_->ShowKeyboard(view_id, bounds.To<gfx::Rect>()); | 550 window_manager_->ShowKeyboard(view_id, bounds.To<gfx::Rect>()); |
| 516 } | 551 } |
| 517 | 552 |
| 518 void WindowManagerConnection::HideKeyboard(Id view_id) { | 553 void WindowManagerConnection::HideKeyboard(Id view_id) { |
| 519 window_manager_->HideKeyboard(view_id); | 554 window_manager_->HideKeyboard(view_id); |
| 520 } | 555 } |
| 521 | 556 |
| 522 void NavigatorHostImpl::DidNavigateLocally(uint32 source_view_id, | 557 void NavigatorHostImpl::DidNavigateLocally(const mojo::String& url) { |
| 523 const mojo::String& url) { | 558 window_manager_->DidNavigateLocally(view_id_, url); |
| 524 window_manager_->DidNavigateLocally(source_view_id, url); | |
| 525 } | 559 } |
| 526 | 560 |
| 527 void NavigatorHostImpl::RequestNavigate( | 561 void NavigatorHostImpl::RequestNavigate(Target target, |
| 528 uint32 source_view_id, | 562 NavigationDetailsPtr nav_details) { |
| 529 Target target, | 563 window_manager_->RequestNavigate(view_id_, target, nav_details.Pass()); |
| 530 NavigationDetailsPtr nav_details) { | |
| 531 window_manager_->RequestNavigate(source_view_id, target, nav_details.Pass()); | |
| 532 } | 564 } |
| 533 | 565 |
| 534 } // namespace examples | 566 } // namespace examples |
| 535 } // namespace mojo | 567 } // namespace mojo |
| 536 | 568 |
| 537 MojoResult MojoMain(MojoHandle shell_handle) { | 569 MojoResult MojoMain(MojoHandle shell_handle) { |
| 538 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); | 570 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); |
| 539 return runner.Run(shell_handle); | 571 return runner.Run(shell_handle); |
| 540 } | 572 } |
| OLD | NEW |