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 <iostream> | 5 #include <iostream> |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "mojo/application/application_runner_chromium.h" | 8 #include "mojo/application/application_runner_chromium.h" |
9 #include "mojo/public/c/system/main.h" | 9 #include "mojo/public/c/system/main.h" |
10 #include "mojo/public/cpp/application/application_delegate.h" | 10 #include "mojo/public/cpp/application/application_delegate.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } // namespace | 54 } // namespace |
55 | 55 |
56 class SkyTester : public mojo::ApplicationDelegate, | 56 class SkyTester : public mojo::ApplicationDelegate, |
57 public mojo::ViewManagerDelegate, | 57 public mojo::ViewManagerDelegate, |
58 public window_manager::WindowManagerDelegate, | 58 public window_manager::WindowManagerDelegate, |
59 public mojo::ViewObserver, | 59 public mojo::ViewObserver, |
60 public TestRunnerClient { | 60 public TestRunnerClient { |
61 public: | 61 public: |
62 SkyTester() | 62 SkyTester() |
63 : window_manager_app_(new window_manager::WindowManagerApp(this, this)), | 63 : window_manager_app_(new window_manager::WindowManagerApp(this, this)), |
64 view_manager_(NULL), | |
65 root_(NULL), | 64 root_(NULL), |
66 content_(NULL), | 65 content_(NULL), |
67 weak_ptr_factory_(this) {} | 66 weak_ptr_factory_(this) {} |
68 virtual ~SkyTester() {} | 67 virtual ~SkyTester() {} |
69 | 68 |
70 private: | 69 private: |
71 // Overridden from mojo::ApplicationDelegate: | 70 // Overridden from mojo::ApplicationDelegate: |
72 virtual void Initialize(mojo::ApplicationImpl* impl) override { | 71 virtual void Initialize(mojo::ApplicationImpl* impl) override { |
73 window_manager_app_->Initialize(impl); | 72 window_manager_app_->Initialize(impl); |
74 | 73 |
75 if (impl->args().size() >= 2) | 74 if (impl->args().size() >= 2) |
76 url_from_args_ = impl->args()[1]; | 75 url_from_args_ = impl->args()[1]; |
77 } | 76 } |
78 virtual bool ConfigureIncomingConnection( | 77 virtual bool ConfigureIncomingConnection( |
79 mojo::ApplicationConnection* connection) override { | 78 mojo::ApplicationConnection* connection) override { |
80 window_manager_app_->ConfigureIncomingConnection(connection); | 79 window_manager_app_->ConfigureIncomingConnection(connection); |
81 if (test_runner_) | 80 if (test_runner_) |
82 connection->AddService(test_runner_->test_harness_factory()); | 81 connection->AddService(test_runner_->test_harness_factory()); |
83 return true; | 82 return true; |
84 } | 83 } |
85 | 84 |
86 // Overridden from mojo::ViewManagerDelegate: | 85 // Overridden from mojo::ViewManagerDelegate: |
87 virtual void OnEmbed( | 86 virtual void OnEmbed( |
88 mojo::ViewManager* view_manager, | |
89 mojo::View* root, | 87 mojo::View* root, |
90 mojo::ServiceProviderImpl* exported_services, | 88 mojo::ServiceProviderImpl* exported_services, |
91 scoped_ptr<mojo::ServiceProvider> remote_service_provider) override { | 89 scoped_ptr<mojo::ServiceProvider> remote_service_provider) override { |
92 view_manager_ = view_manager; | |
93 root_ = root; | 90 root_ = root; |
94 root_->AddObserver(this); | 91 root_->AddObserver(this); |
95 | 92 |
96 content_ = mojo::View::Create(view_manager_); | 93 content_ = mojo::View::Create(root->view_manager()); |
97 content_->SetBounds(root_->bounds()); | 94 content_->SetBounds(root_->bounds()); |
98 root_->AddChild(content_); | 95 root_->AddChild(content_); |
99 content_->SetVisible(true); | 96 content_->SetVisible(true); |
100 | 97 |
101 std::cout << "#READY\n"; | 98 std::cout << "#READY\n"; |
102 std::cout.flush(); | 99 std::cout.flush(); |
103 ScheduleRun(); | 100 ScheduleRun(); |
104 } | 101 } |
105 | 102 |
106 // Overridden from window_manager::WindowManagerDelegate: | 103 // Overridden from window_manager::WindowManagerDelegate: |
107 virtual void Embed( | 104 virtual void Embed( |
108 const mojo::String& url, | 105 const mojo::String& url, |
109 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider) override { | 106 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider) override { |
110 } | 107 } |
111 | 108 |
112 virtual void OnViewManagerDisconnected( | 109 virtual void OnViewManagerDisconnected( |
113 mojo::ViewManager* view_manager) override { | 110 mojo::ViewManager* view_manager) override { |
114 view_manager_ = NULL; | |
115 root_ = NULL; | 111 root_ = NULL; |
116 } | 112 } |
117 | 113 |
118 virtual void OnViewDestroyed(mojo::View* view) override { | 114 virtual void OnViewDestroyed(mojo::View* view) override { |
119 view->RemoveObserver(this); | 115 view->RemoveObserver(this); |
120 } | 116 } |
121 | 117 |
122 virtual void OnViewBoundsChanged(mojo::View* view, | 118 virtual void OnViewBoundsChanged(mojo::View* view, |
123 const mojo::Rect& old_bounds, | 119 const mojo::Rect& old_bounds, |
124 const mojo::Rect& new_bounds) override { | 120 const mojo::Rect& new_bounds) override { |
(...skipping 27 matching lines...) Expand all Loading... |
152 } | 148 } |
153 | 149 |
154 void DispatchInputEvent(mojo::EventPtr event) override { | 150 void DispatchInputEvent(mojo::EventPtr event) override { |
155 window_manager_app_->DispatchInputEventToView(content_, event.Pass()); | 151 window_manager_app_->DispatchInputEventToView(content_, event.Pass()); |
156 } | 152 } |
157 | 153 |
158 scoped_ptr<window_manager::WindowManagerApp> window_manager_app_; | 154 scoped_ptr<window_manager::WindowManagerApp> window_manager_app_; |
159 | 155 |
160 std::string url_from_args_; | 156 std::string url_from_args_; |
161 | 157 |
162 mojo::ViewManager* view_manager_; | |
163 mojo::View* root_; | 158 mojo::View* root_; |
164 mojo::View* content_; | 159 mojo::View* content_; |
165 | 160 |
166 scoped_ptr<TestRunner> test_runner_; | 161 scoped_ptr<TestRunner> test_runner_; |
167 | 162 |
168 base::WeakPtrFactory<SkyTester> weak_ptr_factory_; | 163 base::WeakPtrFactory<SkyTester> weak_ptr_factory_; |
169 | 164 |
170 DISALLOW_COPY_AND_ASSIGN(SkyTester); | 165 DISALLOW_COPY_AND_ASSIGN(SkyTester); |
171 }; | 166 }; |
172 | 167 |
173 } // namespace tester | 168 } // namespace tester |
174 } // namespace examples | 169 } // namespace examples |
175 | 170 |
176 MojoResult MojoMain(MojoHandle shell_handle) { | 171 MojoResult MojoMain(MojoHandle shell_handle) { |
177 mojo::ApplicationRunnerChromium runner(new sky::tester::SkyTester); | 172 mojo::ApplicationRunnerChromium runner(new sky::tester::SkyTester); |
178 return runner.Run(shell_handle); | 173 return runner.Run(shell_handle); |
179 } | 174 } |
OLD | NEW |