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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "examples/keyboard/keyboard.mojom.h" | 7 #include "examples/keyboard/keyboard.mojom.h" |
8 #include "examples/window_manager/debug_panel.h" | 8 #include "examples/window_manager/debug_panel.h" |
9 #include "examples/window_manager/window_manager.mojom.h" | 9 #include "examples/window_manager/window_manager.mojom.h" |
10 #include "mojo/application/application_runner_chromium.h" | 10 #include "mojo/application/application_runner_chromium.h" |
11 #include "mojo/converters/geometry/geometry_type_converters.h" | 11 #include "mojo/converters/geometry/geometry_type_converters.h" |
12 #include "mojo/converters/input_events/input_events_type_converters.h" | 12 #include "mojo/converters/input_events/input_events_type_converters.h" |
13 #include "mojo/public/c/system/main.h" | 13 #include "mojo/public/c/system/main.h" |
14 #include "mojo/public/cpp/application/application_connection.h" | 14 #include "mojo/public/cpp/application/application_connection.h" |
15 #include "mojo/public/cpp/application/application_delegate.h" | 15 #include "mojo/public/cpp/application/application_delegate.h" |
16 #include "mojo/public/cpp/application/application_impl.h" | 16 #include "mojo/public/cpp/application/application_impl.h" |
17 #include "mojo/public/cpp/application/interface_factory_impl.h" | 17 #include "mojo/public/cpp/application/interface_factory_impl.h" |
18 #include "mojo/public/cpp/application/service_provider_impl.h" | 18 #include "mojo/public/cpp/application/service_provider_impl.h" |
19 #include "mojo/services/public/cpp/view_manager/view.h" | 19 #include "mojo/services/public/cpp/view_manager/view.h" |
20 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 20 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
21 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 21 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
22 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 22 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
23 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" | 23 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" |
24 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 24 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
| 25 #include "mojo/services/window_manager/basic_focus_rules.h" |
| 26 #include "mojo/services/window_manager/view_target.h" |
25 #include "mojo/services/window_manager/window_manager_app.h" | 27 #include "mojo/services/window_manager/window_manager_app.h" |
26 #include "mojo/services/window_manager/window_manager_delegate.h" | 28 #include "mojo/services/window_manager/window_manager_delegate.h" |
27 #include "mojo/views/views_init.h" | 29 #include "mojo/views/views_init.h" |
28 #include "ui/aura/window.h" | |
29 #include "ui/events/event.h" | 30 #include "ui/events/event.h" |
30 #include "ui/events/event_constants.h" | 31 #include "ui/events/event_constants.h" |
31 #include "ui/gfx/geometry/size_conversions.h" | 32 #include "ui/gfx/geometry/size_conversions.h" |
32 #include "ui/wm/core/focus_rules.h" | |
33 | 33 |
34 #if defined CreateWindow | 34 #if defined CreateWindow |
35 #undef CreateWindow | 35 #undef CreateWindow |
36 #endif | 36 #endif |
37 | 37 |
38 namespace mojo { | 38 namespace mojo { |
39 namespace examples { | 39 namespace examples { |
40 | 40 |
41 class WindowManager; | 41 class WindowManager; |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 const int kBorderInset = 25; | 45 const int kBorderInset = 25; |
46 const int kControlPanelWidth = 200; | 46 const int kControlPanelWidth = 200; |
47 const int kTextfieldHeight = 25; | 47 const int kTextfieldHeight = 25; |
48 | 48 |
49 class WMFocusRules : public wm::FocusRules { | |
50 public: | |
51 WMFocusRules(mojo::WindowManagerApp* window_manager_app, | |
52 mojo::View* window_container) | |
53 : window_container_(window_container), | |
54 window_manager_app_(window_manager_app) {} | |
55 virtual ~WMFocusRules() {} | |
56 | |
57 private: | |
58 // Overridden from wm::FocusRules: | |
59 virtual bool IsToplevelWindow(aura::Window* window) const override { | |
60 return mojo::WindowManagerApp::GetViewForWindow(window)->parent() == | |
61 window_container_; | |
62 } | |
63 virtual bool CanActivateWindow(aura::Window* window) const override { | |
64 return mojo::WindowManagerApp::GetViewForWindow(window)->parent() == | |
65 window_container_; | |
66 } | |
67 virtual bool CanFocusWindow(aura::Window* window) const override { | |
68 return true; | |
69 } | |
70 virtual aura::Window* GetToplevelWindow(aura::Window* window) const override { | |
71 mojo::View* view = mojo::WindowManagerApp::GetViewForWindow(window); | |
72 while (view->parent() != window_container_) { | |
73 view = view->parent(); | |
74 // Unparented hierarchy, there is no "top level" window. | |
75 if (!view) | |
76 return NULL; | |
77 } | |
78 | |
79 return window_manager_app_->GetWindowForViewId(view->id()); | |
80 } | |
81 virtual aura::Window* GetActivatableWindow( | |
82 aura::Window* window) const override { | |
83 return GetToplevelWindow(window); | |
84 } | |
85 virtual aura::Window* GetFocusableWindow( | |
86 aura::Window* window) const override { | |
87 return window; | |
88 } | |
89 virtual aura::Window* GetNextActivatableWindow( | |
90 aura::Window* ignore) const override { | |
91 aura::Window* activatable = GetActivatableWindow(ignore); | |
92 const aura::Window::Windows& children = activatable->parent()->children(); | |
93 for (aura::Window::Windows::const_reverse_iterator it = children.rbegin(); | |
94 it != children.rend(); ++it) { | |
95 if (*it != ignore) | |
96 return *it; | |
97 } | |
98 return NULL; | |
99 } | |
100 | |
101 mojo::View* window_container_; | |
102 mojo::WindowManagerApp* window_manager_app_; | |
103 | |
104 DISALLOW_COPY_AND_ASSIGN(WMFocusRules); | |
105 }; | |
106 | |
107 } // namespace | 49 } // namespace |
108 | 50 |
109 class WindowManagerConnection : public InterfaceImpl<IWindowManager> { | 51 class WindowManagerConnection : public InterfaceImpl<IWindowManager> { |
110 public: | 52 public: |
111 explicit WindowManagerConnection(WindowManager* window_manager) | 53 explicit WindowManagerConnection(WindowManager* window_manager) |
112 : window_manager_(window_manager) {} | 54 : window_manager_(window_manager) {} |
113 virtual ~WindowManagerConnection() {} | 55 virtual ~WindowManagerConnection() {} |
114 | 56 |
115 private: | 57 private: |
116 // Overridden from IWindowManager: | 58 // Overridden from IWindowManager: |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 : shell_(nullptr), | 263 : shell_(nullptr), |
322 window_manager_factory_(this), | 264 window_manager_factory_(this), |
323 launcher_ui_(NULL), | 265 launcher_ui_(NULL), |
324 view_manager_(NULL), | 266 view_manager_(NULL), |
325 window_manager_app_(new WindowManagerApp(this, this)), | 267 window_manager_app_(new WindowManagerApp(this, this)), |
326 app_(NULL) {} | 268 app_(NULL) {} |
327 | 269 |
328 virtual ~WindowManager() { | 270 virtual ~WindowManager() { |
329 // host() may be destroyed by the time we get here. | 271 // host() may be destroyed by the time we get here. |
330 // TODO: figure out a way to always cleanly remove handler. | 272 // TODO: figure out a way to always cleanly remove handler. |
331 if (window_manager_app_->host()) | 273 |
332 window_manager_app_->host()->window()->RemovePreTargetHandler(this); | 274 // TODO(erg): In the aura version, we removed ourselves from the |
| 275 // PreTargetHandler list here. We may need to do something analogous when |
| 276 // we get event handling without aura working. |
333 } | 277 } |
334 | 278 |
335 void CloseWindow(Id view_id) { | 279 void CloseWindow(Id view_id) { |
336 WindowVector::iterator iter = GetWindowByViewId(view_id); | 280 WindowVector::iterator iter = GetWindowByViewId(view_id); |
337 DCHECK(iter != windows_.end()); | 281 DCHECK(iter != windows_.end()); |
338 Window* window = *iter; | 282 Window* window = *iter; |
339 windows_.erase(iter); | 283 windows_.erase(iter); |
340 window->view()->Destroy(); | 284 window->view()->Destroy(); |
341 } | 285 } |
342 | 286 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 Id launcher_ui_id = CreateLauncherUI(); | 365 Id launcher_ui_id = CreateLauncherUI(); |
422 Id control_panel_id = CreateControlPanel(view); | 366 Id control_panel_id = CreateControlPanel(view); |
423 | 367 |
424 root_layout_manager_.reset( | 368 root_layout_manager_.reset( |
425 new RootLayoutManager(view_manager, root, | 369 new RootLayoutManager(view_manager, root, |
426 content_view_id_, | 370 content_view_id_, |
427 launcher_ui_id, | 371 launcher_ui_id, |
428 control_panel_id)); | 372 control_panel_id)); |
429 root->AddObserver(root_layout_manager_.get()); | 373 root->AddObserver(root_layout_manager_.get()); |
430 | 374 |
431 window_manager_app_->host()->window()->AddPreTargetHandler(this); | 375 // TODO(erg): In the aura version, we explicitly added ourselves as a |
| 376 // PreTargetHandler to the window() here. We probably have to do something |
| 377 // analogous here. |
432 | 378 |
433 window_manager_app_->InitFocus(new WMFocusRules(window_manager_app_.get(), | 379 window_manager_app_->InitFocus(scoped_ptr<mojo::FocusRules>( |
434 view)); | 380 new mojo::BasicFocusRules(window_manager_app_.get(), |
| 381 view))); |
435 } | 382 } |
436 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override { | 383 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override { |
437 DCHECK_EQ(view_manager_, view_manager); | 384 DCHECK_EQ(view_manager_, view_manager); |
438 view_manager_ = NULL; | 385 view_manager_ = NULL; |
439 base::MessageLoop::current()->Quit(); | 386 base::MessageLoop::current()->Quit(); |
440 } | 387 } |
441 | 388 |
442 // Overridden from WindowManagerDelegate: | 389 // Overridden from WindowManagerDelegate: |
443 virtual void Embed( | 390 virtual void Embed( |
444 const String& url, | 391 const String& url, |
445 InterfaceRequest<ServiceProvider> service_provider) override { | 392 InterfaceRequest<ServiceProvider> service_provider) override { |
446 const Id kInvalidSourceViewId = 0; | 393 const Id kInvalidSourceViewId = 0; |
447 OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url); | 394 OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url); |
448 } | 395 } |
449 | 396 |
450 // Overridden from ui::EventHandler: | 397 // Overridden from ui::EventHandler: |
451 virtual void OnEvent(ui::Event* event) override { | 398 virtual void OnEvent(ui::Event* event) override { |
452 View* view = WindowManagerApp::GetViewForWindow( | 399 View* view = WindowManagerApp::GetViewForViewTarget( |
453 static_cast<aura::Window*>(event->target())); | 400 static_cast<ViewTarget*>(event->target())); |
454 if (event->type() == ui::ET_MOUSE_PRESSED && | 401 if (event->type() == ui::ET_MOUSE_PRESSED && |
455 !IsDescendantOfKeyboard(view)) { | 402 !IsDescendantOfKeyboard(view)) { |
456 view->SetFocus(); | 403 view->SetFocus(); |
457 } | 404 } |
458 } | 405 } |
459 | 406 |
460 void OnLaunch(uint32 source_view_id, | 407 void OnLaunch(uint32 source_view_id, |
461 Target requested_target, | 408 Target requested_target, |
462 const mojo::String& url) { | 409 const mojo::String& url) { |
463 Target target = debug_panel_->navigation_target(); | 410 Target target = debug_panel_->navigation_target(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 window_manager_->RequestNavigate(view_id_, target, request.Pass()); | 548 window_manager_->RequestNavigate(view_id_, target, request.Pass()); |
602 } | 549 } |
603 | 550 |
604 } // namespace examples | 551 } // namespace examples |
605 } // namespace mojo | 552 } // namespace mojo |
606 | 553 |
607 MojoResult MojoMain(MojoHandle shell_handle) { | 554 MojoResult MojoMain(MojoHandle shell_handle) { |
608 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); | 555 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); |
609 return runner.Run(shell_handle); | 556 return runner.Run(shell_handle); |
610 } | 557 } |
OLD | NEW |