| 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 "mojo/services/public/cpp/view_manager/view_manager.h" | 5 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "mojo/application_manager/application_manager.h" | 10 #include "mojo/application_manager/application_manager.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 current_run_loop->Quit(); | 41 current_run_loop->Quit(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 class ConnectApplicationLoader : public ApplicationLoader, | 44 class ConnectApplicationLoader : public ApplicationLoader, |
| 45 public ApplicationDelegate, | 45 public ApplicationDelegate, |
| 46 public ViewManagerDelegate { | 46 public ViewManagerDelegate { |
| 47 public: | 47 public: |
| 48 typedef base::Callback<void(ViewManager*, View*)> LoadedCallback; | 48 typedef base::Callback<void(ViewManager*, View*)> LoadedCallback; |
| 49 | 49 |
| 50 explicit ConnectApplicationLoader(const LoadedCallback& callback) | 50 explicit ConnectApplicationLoader(const LoadedCallback& callback) |
| 51 : callback_(callback), view_manager_client_factory_(this) {} | 51 : callback_(callback) {} |
| 52 virtual ~ConnectApplicationLoader() {} | 52 virtual ~ConnectApplicationLoader() {} |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 // Overridden from ApplicationDelegate: |
| 56 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { |
| 57 view_manager_client_factory_.reset( |
| 58 new ViewManagerClientFactory(app->shell(), this)); |
| 59 } |
| 60 |
| 55 // Overridden from ApplicationLoader: | 61 // Overridden from ApplicationLoader: |
| 56 virtual void Load(ApplicationManager* manager, | 62 virtual void Load(ApplicationManager* manager, |
| 57 const GURL& url, | 63 const GURL& url, |
| 58 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE { | 64 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE { |
| 59 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); | 65 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); |
| 60 if (!shell_handle.is_valid()) | 66 if (!shell_handle.is_valid()) |
| 61 return; | 67 return; |
| 62 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this, | 68 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this, |
| 63 shell_handle.Pass())); | 69 shell_handle.Pass())); |
| 64 apps_.push_back(app.release()); | 70 apps_.push_back(app.release()); |
| 65 } | 71 } |
| 66 | 72 |
| 67 virtual void OnApplicationError(ApplicationManager* manager, | 73 virtual void OnApplicationError(ApplicationManager* manager, |
| 68 const GURL& url) OVERRIDE {} | 74 const GURL& url) OVERRIDE {} |
| 69 | 75 |
| 70 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 76 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| 71 OVERRIDE { | 77 OVERRIDE { |
| 72 connection->AddService(&view_manager_client_factory_); | 78 connection->AddService(view_manager_client_factory_.get()); |
| 73 return true; | 79 return true; |
| 74 } | 80 } |
| 75 | 81 |
| 76 // Overridden from ViewManagerDelegate: | 82 // Overridden from ViewManagerDelegate: |
| 77 virtual void OnEmbed(ViewManager* view_manager, | 83 virtual void OnEmbed(ViewManager* view_manager, |
| 78 View* root, | 84 View* root, |
| 79 ServiceProviderImpl* exported_services, | 85 ServiceProviderImpl* exported_services, |
| 80 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { | 86 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { |
| 81 callback_.Run(view_manager, root); | 87 callback_.Run(view_manager, root); |
| 82 } | 88 } |
| 83 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {} | 89 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE {} |
| 84 | 90 |
| 85 ScopedVector<ApplicationImpl> apps_; | 91 ScopedVector<ApplicationImpl> apps_; |
| 86 LoadedCallback callback_; | 92 LoadedCallback callback_; |
| 87 ViewManagerClientFactory view_manager_client_factory_; | 93 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
| 88 | 94 |
| 89 DISALLOW_COPY_AND_ASSIGN(ConnectApplicationLoader); | 95 DISALLOW_COPY_AND_ASSIGN(ConnectApplicationLoader); |
| 90 }; | 96 }; |
| 91 | 97 |
| 92 class BoundsChangeObserver : public ViewObserver { | 98 class BoundsChangeObserver : public ViewObserver { |
| 93 public: | 99 public: |
| 94 explicit BoundsChangeObserver(View* view) : view_(view) {} | 100 explicit BoundsChangeObserver(View* view) : view_(view) {} |
| 95 virtual ~BoundsChangeObserver() {} | 101 virtual ~BoundsChangeObserver() {} |
| 96 | 102 |
| 97 private: | 103 private: |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 | 527 |
| 522 // TODO(beng): tests for view event dispatcher. | 528 // TODO(beng): tests for view event dispatcher. |
| 523 // - verify that we see events for all views. | 529 // - verify that we see events for all views. |
| 524 | 530 |
| 525 // TODO(beng): tests for focus: | 531 // TODO(beng): tests for focus: |
| 526 // - focus between two views known to a connection | 532 // - focus between two views known to a connection |
| 527 // - focus between views unknown to one of the connections. | 533 // - focus between views unknown to one of the connections. |
| 528 // - focus between views unknown to either connection. | 534 // - focus between views unknown to either connection. |
| 529 | 535 |
| 530 } // namespace mojo | 536 } // namespace mojo |
| OLD | NEW |