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/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
11 #include "mojo/public/cpp/application/application_delegate.h" | 11 #include "mojo/public/cpp/application/application_delegate.h" |
12 #include "mojo/public/cpp/application/application_impl.h" | 12 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "mojo/public/cpp/application/interface_factory_impl.h" | 13 #include "mojo/public/cpp/application/interface_factory_impl.h" |
14 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 14 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
15 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 15 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
16 #include "mojo/services/public/cpp/view_manager/view.h" | 16 #include "mojo/services/public/cpp/view_manager/view.h" |
17 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 17 #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_delegate.h" | 18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
20 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 19 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
21 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" | 20 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" |
22 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" | 21 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" |
23 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" | 22 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" |
24 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 23 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
24 #include "mojo/services/window_manager/window_manager_app.h" | |
25 #include "mojo/views/views_init.h" | 25 #include "mojo/views/views_init.h" |
26 #include "ui/aura/window.h" | |
26 #include "ui/events/event.h" | 27 #include "ui/events/event.h" |
27 #include "ui/events/event_constants.h" | 28 #include "ui/events/event_constants.h" |
28 #include "ui/gfx/geometry/size_conversions.h" | 29 #include "ui/gfx/geometry/size_conversions.h" |
29 | 30 |
30 #if defined CreateWindow | 31 #if defined CreateWindow |
31 #undef CreateWindow | 32 #undef CreateWindow |
32 #endif | 33 #endif |
33 | 34 |
34 namespace mojo { | 35 namespace mojo { |
35 namespace examples { | 36 namespace examples { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 const Id launcher_ui_view_id_; | 244 const Id launcher_ui_view_id_; |
244 const Id control_panel_view_id_; | 245 const Id control_panel_view_id_; |
245 | 246 |
246 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); | 247 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); |
247 }; | 248 }; |
248 | 249 |
249 class WindowManager | 250 class WindowManager |
250 : public ApplicationDelegate, | 251 : public ApplicationDelegate, |
251 public DebugPanel::Delegate, | 252 public DebugPanel::Delegate, |
252 public ViewManagerDelegate, | 253 public ViewManagerDelegate, |
253 public WindowManagerDelegate { | 254 public WindowManagerDelegate, |
255 public ui::EventHandler { | |
254 public: | 256 public: |
255 WindowManager() | 257 WindowManager() |
256 : window_manager_factory_(this), | 258 : window_manager_factory_(this), |
257 navigator_host_factory_(this), | 259 navigator_host_factory_(this), |
258 launcher_ui_(NULL), | 260 launcher_ui_(NULL), |
259 view_manager_(NULL), | 261 view_manager_(NULL), |
260 view_manager_client_factory_(this), | 262 window_manager_app_(new WindowManagerApp(this, this)), |
261 app_(NULL) {} | 263 app_(NULL) {} |
262 | 264 |
263 virtual ~WindowManager() {} | 265 virtual ~WindowManager() {} |
264 | 266 |
265 void CloseWindow(Id view_id) { | 267 void CloseWindow(Id view_id) { |
266 View* view = view_manager_->GetViewById(view_id); | 268 View* view = view_manager_->GetViewById(view_id); |
267 DCHECK(view); | 269 DCHECK(view); |
268 std::vector<View*>::iterator iter = | 270 std::vector<View*>::iterator iter = |
269 std::find(windows_.begin(), windows_.end(), view); | 271 std::find(windows_.begin(), windows_.end(), view); |
270 DCHECK(iter != windows_.end()); | 272 DCHECK(iter != windows_.end()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 source_view_id, | 320 source_view_id, |
319 target)); | 321 target)); |
320 } | 322 } |
321 | 323 |
322 private: | 324 private: |
323 // Overridden from ApplicationDelegate: | 325 // Overridden from ApplicationDelegate: |
324 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { | 326 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { |
325 app_ = app; | 327 app_ = app; |
326 app->ConnectToService("mojo:mojo_launcher", &launcher_); | 328 app->ConnectToService("mojo:mojo_launcher", &launcher_); |
327 views_init_.reset(new ViewsInit); | 329 views_init_.reset(new ViewsInit); |
330 window_manager_app_->Initialize(app); | |
328 } | 331 } |
329 | 332 |
330 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 333 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
331 MOJO_OVERRIDE { | 334 MOJO_OVERRIDE { |
332 connection->AddService(&window_manager_factory_); | 335 connection->AddService(&window_manager_factory_); |
333 connection->AddService(&navigator_host_factory_); | 336 connection->AddService(&navigator_host_factory_); |
334 connection->AddService(&view_manager_client_factory_); | 337 window_manager_app_->ConfigureIncomingConnection(connection); |
335 return true; | 338 return true; |
336 } | 339 } |
337 | 340 |
338 // Overridden from ViewManagerDelegate: | 341 // Overridden from ViewManagerDelegate: |
339 virtual void OnEmbed(ViewManager* view_manager, | 342 virtual void OnEmbed(ViewManager* view_manager, |
340 View* root, | 343 View* root, |
341 ServiceProviderImpl* exported_services, | 344 ServiceProviderImpl* exported_services, |
342 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { | 345 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { |
343 DCHECK(!view_manager_); | 346 DCHECK(!view_manager_); |
344 view_manager_ = view_manager; | 347 view_manager_ = view_manager; |
345 view_manager_->SetWindowManagerDelegate(this); | |
346 | 348 |
347 View* view = View::Create(view_manager_); | 349 View* view = View::Create(view_manager_); |
348 root->AddChild(view); | 350 root->AddChild(view); |
349 view->SetBounds(gfx::Rect(root->bounds().size())); | 351 view->SetBounds(gfx::Rect(root->bounds().size())); |
350 content_view_id_ = view->id(); | 352 content_view_id_ = view->id(); |
351 | 353 |
352 root->SetColor(SK_ColorBLUE); | 354 root->SetColor(SK_ColorBLUE); |
353 | 355 |
354 Id launcher_ui_id = CreateLauncherUI(); | 356 Id launcher_ui_id = CreateLauncherUI(); |
355 Id control_panel_id = CreateControlPanel(view); | 357 Id control_panel_id = CreateControlPanel(view); |
356 | 358 |
357 root_layout_manager_.reset( | 359 root_layout_manager_.reset( |
358 new RootLayoutManager(view_manager, root, | 360 new RootLayoutManager(view_manager, root, |
359 content_view_id_, | 361 content_view_id_, |
360 launcher_ui_id, | 362 launcher_ui_id, |
361 control_panel_id)); | 363 control_panel_id)); |
362 root->AddObserver(root_layout_manager_.get()); | 364 root->AddObserver(root_layout_manager_.get()); |
365 | |
366 window_manager_app_->host()->window()->AddPreTargetHandler(this); | |
sky
2014/08/15 18:03:56
Do you need to remove the pre target handler at so
| |
363 } | 367 } |
364 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { | 368 virtual void OnViewManagerDisconnected(ViewManager* view_manager) OVERRIDE { |
365 DCHECK_EQ(view_manager_, view_manager); | 369 DCHECK_EQ(view_manager_, view_manager); |
366 view_manager_ = NULL; | 370 view_manager_ = NULL; |
367 base::MessageLoop::current()->Quit(); | 371 base::MessageLoop::current()->Quit(); |
368 } | 372 } |
369 | 373 |
370 // Overridden from WindowManagerDelegate: | 374 // Overridden from WindowManagerDelegate: |
371 virtual void Embed( | 375 virtual void Embed( |
372 const String& url, | 376 const String& url, |
373 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { | 377 InterfaceRequest<ServiceProvider> service_provider) OVERRIDE { |
374 CreateWindow(url, | 378 CreateWindow(url, |
375 NavigationDetailsPtr().Pass(), | 379 NavigationDetailsPtr().Pass(), |
376 ResponseDetailsPtr().Pass()); | 380 ResponseDetailsPtr().Pass()); |
377 } | 381 } |
378 virtual void DispatchEvent(View* target, EventPtr event) OVERRIDE { | 382 virtual void DispatchEvent(EventPtr event) MOJO_OVERRIDE {} |
379 // TODO(beng): More sophisticated focus handling than this is required! | 383 |
380 if (event->action == EVENT_TYPE_MOUSE_PRESSED && | 384 // Overridden from ui::EventHandler: |
381 !IsDescendantOfKeyboard(target)) { | 385 virtual void OnEvent(ui::Event* event) OVERRIDE { |
382 target->SetFocus(); | 386 View* view = WindowManagerApp::GetViewForWindow( |
387 static_cast<aura::Window*>(event->target())); | |
388 if (event->type() == ui::ET_MOUSE_PRESSED && | |
389 !IsDescendantOfKeyboard(view)) { | |
390 view->SetFocus(); | |
383 } | 391 } |
384 view_manager_->DispatchEvent(target, event.Pass()); | |
385 } | 392 } |
386 | 393 |
387 void OnLaunch( | 394 void OnLaunch( |
388 uint32 source_view_id, | 395 uint32 source_view_id, |
389 Target requested_target, | 396 Target requested_target, |
390 const mojo::String& handler_url, | 397 const mojo::String& handler_url, |
391 const mojo::String& view_url, | 398 const mojo::String& view_url, |
392 ResponseDetailsPtr response) { | 399 ResponseDetailsPtr response) { |
393 // TODO(mpcomplete): This seems to be unused in favor of |response|. We | 400 // TODO(mpcomplete): This seems to be unused in favor of |response|. We |
394 // might need to use it (and fill it in properly, with method, etc) if we | 401 // might need to use it (and fill it in properly, with method, etc) if we |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
506 window_manager_factory_; | 513 window_manager_factory_; |
507 InterfaceFactoryImplWithContext<NavigatorHostImpl, WindowManager> | 514 InterfaceFactoryImplWithContext<NavigatorHostImpl, WindowManager> |
508 navigator_host_factory_; | 515 navigator_host_factory_; |
509 | 516 |
510 scoped_ptr<ViewsInit> views_init_; | 517 scoped_ptr<ViewsInit> views_init_; |
511 DebugPanel* debug_panel_; | 518 DebugPanel* debug_panel_; |
512 LauncherPtr launcher_; | 519 LauncherPtr launcher_; |
513 View* launcher_ui_; | 520 View* launcher_ui_; |
514 std::vector<View*> windows_; | 521 std::vector<View*> windows_; |
515 ViewManager* view_manager_; | 522 ViewManager* view_manager_; |
516 ViewManagerClientFactory view_manager_client_factory_; | |
517 scoped_ptr<RootLayoutManager> root_layout_manager_; | 523 scoped_ptr<RootLayoutManager> root_layout_manager_; |
518 | 524 |
525 scoped_ptr<WindowManagerApp> window_manager_app_; | |
526 | |
519 // Id of the view most content is added to. The keyboard is NOT added here. | 527 // Id of the view most content is added to. The keyboard is NOT added here. |
520 Id content_view_id_; | 528 Id content_view_id_; |
521 | 529 |
522 scoped_ptr<KeyboardManager> keyboard_manager_; | 530 scoped_ptr<KeyboardManager> keyboard_manager_; |
523 ApplicationImpl* app_; | 531 ApplicationImpl* app_; |
524 | 532 |
525 DISALLOW_COPY_AND_ASSIGN(WindowManager); | 533 DISALLOW_COPY_AND_ASSIGN(WindowManager); |
526 }; | 534 }; |
527 | 535 |
528 void WindowManagerConnection::CloseWindow(Id view_id) { | 536 void WindowManagerConnection::CloseWindow(Id view_id) { |
(...skipping 21 matching lines...) Expand all Loading... | |
550 } | 558 } |
551 | 559 |
552 } // namespace examples | 560 } // namespace examples |
553 | 561 |
554 // static | 562 // static |
555 ApplicationDelegate* ApplicationDelegate::Create() { | 563 ApplicationDelegate* ApplicationDelegate::Create() { |
556 return new examples::WindowManager; | 564 return new examples::WindowManager; |
557 } | 565 } |
558 | 566 |
559 } // namespace mojo | 567 } // namespace mojo |
OLD | NEW |