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/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "mojo/common/common_type_converters.h" | 8 #include "mojo/common/common_type_converters.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/connect.h" |
15 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 16 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
16 #include "mojo/services/public/cpp/view_manager/view.h" | 17 #include "mojo/services/public/cpp/view_manager/view.h" |
17 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 18 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
18 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" | 19 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
19 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
20 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 21 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
21 #include "mojo/views/native_widget_view_manager.h" | 22 #include "mojo/views/native_widget_view_manager.h" |
22 #include "mojo/views/views_init.h" | 23 #include "mojo/views/views_init.h" |
23 #include "ui/aura/client/focus_client.h" | 24 #include "ui/aura/client/focus_client.h" |
24 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 if (root_) | 163 if (root_) |
163 root_->RemoveObserver(this); | 164 root_->RemoveObserver(this); |
164 } | 165 } |
165 | 166 |
166 private: | 167 private: |
167 // Overridden from ApplicationDelegate: | 168 // Overridden from ApplicationDelegate: |
168 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { | 169 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { |
169 view_manager_client_factory_.reset( | 170 view_manager_client_factory_.reset( |
170 new ViewManagerClientFactory(app->shell(), this)); | 171 new ViewManagerClientFactory(app->shell(), this)); |
171 views_init_.reset(new ViewsInit); | 172 views_init_.reset(new ViewsInit); |
172 app->ConnectToService("mojo:mojo_window_manager", &navigator_host_); | |
173 app->ConnectToService("mojo:mojo_window_manager", &window_manager_); | 173 app->ConnectToService("mojo:mojo_window_manager", &window_manager_); |
174 } | 174 } |
175 | 175 |
176 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 176 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
177 MOJO_OVERRIDE { | 177 MOJO_OVERRIDE { |
178 connection->AddService(view_manager_client_factory_.get()); | 178 connection->AddService(view_manager_client_factory_.get()); |
179 return true; | 179 return true; |
180 } | 180 } |
181 | 181 |
182 void CreateWidget(View* view) { | 182 void CreateWidget(View* view) { |
(...skipping 19 matching lines...) Expand all Loading... |
202 widget_->Show(); | 202 widget_->Show(); |
203 textfield->RequestFocus(); | 203 textfield->RequestFocus(); |
204 } | 204 } |
205 | 205 |
206 // ViewManagerDelegate: | 206 // ViewManagerDelegate: |
207 virtual void OnEmbed(ViewManager* view_manager, | 207 virtual void OnEmbed(ViewManager* view_manager, |
208 View* root, | 208 View* root, |
209 ServiceProviderImpl* exported_services, | 209 ServiceProviderImpl* exported_services, |
210 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { | 210 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { |
211 // TODO: deal with OnEmbed() being invoked multiple times. | 211 // TODO: deal with OnEmbed() being invoked multiple times. |
| 212 ConnectToService(imported_services.get(), &navigator_host_); |
212 view_manager_ = view_manager; | 213 view_manager_ = view_manager; |
213 root_ = root; | 214 root_ = root; |
214 root_->AddObserver(this); | 215 root_->AddObserver(this); |
215 root_->SetFocus(); | 216 root_->SetFocus(); |
216 CreateWidget(root_); | 217 CreateWidget(root_); |
217 } | 218 } |
218 virtual void OnViewManagerDisconnected( | 219 virtual void OnViewManagerDisconnected( |
219 ViewManager* view_manager) OVERRIDE { | 220 ViewManager* view_manager) OVERRIDE { |
220 DCHECK_EQ(view_manager_, view_manager); | 221 DCHECK_EQ(view_manager_, view_manager); |
221 view_manager_ = NULL; | 222 view_manager_ = NULL; |
222 base::MessageLoop::current()->Quit(); | 223 base::MessageLoop::current()->Quit(); |
223 } | 224 } |
224 | 225 |
225 // views::TextfieldController: | 226 // views::TextfieldController: |
226 virtual bool HandleKeyEvent(views::Textfield* sender, | 227 virtual bool HandleKeyEvent(views::Textfield* sender, |
227 const ui::KeyEvent& key_event) OVERRIDE { | 228 const ui::KeyEvent& key_event) OVERRIDE { |
228 if (key_event.key_code() == ui::VKEY_RETURN) { | 229 if (key_event.key_code() == ui::VKEY_RETURN) { |
229 GURL url(sender->text()); | 230 GURL url(sender->text()); |
230 printf("User entered this URL: %s\n", url.spec().c_str()); | 231 printf("User entered this URL: %s\n", url.spec().c_str()); |
231 NavigationDetailsPtr nav_details(NavigationDetails::New()); | 232 NavigationDetailsPtr nav_details(NavigationDetails::New()); |
232 nav_details->request->url = String::From(url); | 233 nav_details->request->url = String::From(url); |
233 navigator_host_->RequestNavigate(view_manager_->GetRoots().front()->id(), | 234 navigator_host_->RequestNavigate(TARGET_NEW_NODE, nav_details.Pass()); |
234 TARGET_NEW_NODE, | |
235 nav_details.Pass()); | |
236 } | 235 } |
237 return false; | 236 return false; |
238 } | 237 } |
239 | 238 |
240 // ViewObserver: | 239 // ViewObserver: |
241 virtual void OnViewFocusChanged(View* gained_focus, | 240 virtual void OnViewFocusChanged(View* gained_focus, |
242 View* lost_focus) OVERRIDE { | 241 View* lost_focus) OVERRIDE { |
243 aura::client::FocusClient* focus_client = | 242 aura::client::FocusClient* focus_client = |
244 aura::client::GetFocusClient(widget_->GetNativeView()); | 243 aura::client::GetFocusClient(widget_->GetNativeView()); |
245 if (lost_focus == root_) | 244 if (lost_focus == root_) |
(...skipping 19 matching lines...) Expand all Loading... |
265 DISALLOW_COPY_AND_ASSIGN(Browser); | 264 DISALLOW_COPY_AND_ASSIGN(Browser); |
266 }; | 265 }; |
267 | 266 |
268 } // namespace examples | 267 } // namespace examples |
269 } // namespace mojo | 268 } // namespace mojo |
270 | 269 |
271 MojoResult MojoMain(MojoHandle shell_handle) { | 270 MojoResult MojoMain(MojoHandle shell_handle) { |
272 mojo::ApplicationRunnerChromium runner(new mojo::examples::Browser); | 271 mojo::ApplicationRunnerChromium runner(new mojo::examples::Browser); |
273 return runner.Run(shell_handle); | 272 return runner.Run(shell_handle); |
274 } | 273 } |
OLD | NEW |