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 <vector> |
| 6 |
5 #include "mojo/application/application_runner_chromium.h" | 7 #include "mojo/application/application_runner_chromium.h" |
6 #include "mojo/examples/wm_flow/wm/frame_controller.h" | 8 #include "mojo/examples/wm_flow/wm/frame_controller.h" |
7 #include "mojo/public/c/system/main.h" | 9 #include "mojo/public/c/system/main.h" |
8 #include "mojo/public/cpp/application/application_delegate.h" | 10 #include "mojo/public/cpp/application/application_delegate.h" |
9 #include "mojo/public/cpp/application/application_impl.h" | 11 #include "mojo/public/cpp/application/application_impl.h" |
10 #include "mojo/public/cpp/application/service_provider_impl.h" | 12 #include "mojo/public/cpp/application/service_provider_impl.h" |
11 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 13 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
12 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 14 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
13 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 15 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
14 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" | 16 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" |
15 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" | 17 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h" |
16 #include "mojo/services/window_manager/window_manager_app.h" | 18 #include "mojo/services/window_manager/window_manager_app.h" |
17 #include "mojo/views/views_init.h" | 19 #include "mojo/views/views_init.h" |
| 20 #include "ui/aura/window.h" |
| 21 #include "ui/wm/core/focus_rules.h" |
| 22 #include "ui/wm/public/activation_client.h" |
18 | 23 |
19 namespace examples { | 24 namespace examples { |
20 | 25 |
| 26 namespace { |
| 27 |
| 28 class WMFocusRules : public wm::FocusRules { |
| 29 public: |
| 30 WMFocusRules(mojo::WindowManagerApp* window_manager_app, |
| 31 mojo::View* window_container) |
| 32 : window_container_(window_container), |
| 33 window_manager_app_(window_manager_app) {} |
| 34 virtual ~WMFocusRules() {} |
| 35 |
| 36 private: |
| 37 // Overridden from wm::FocusRules: |
| 38 virtual bool IsToplevelWindow(aura::Window* window) const MOJO_OVERRIDE { |
| 39 return mojo::WindowManagerApp::GetViewForWindow(window)->parent() == |
| 40 window_container_; |
| 41 } |
| 42 virtual bool CanActivateWindow(aura::Window* window) const MOJO_OVERRIDE { |
| 43 return mojo::WindowManagerApp::GetViewForWindow(window)->parent() == |
| 44 window_container_; |
| 45 } |
| 46 virtual bool CanFocusWindow(aura::Window* window) const MOJO_OVERRIDE { |
| 47 return true; |
| 48 } |
| 49 virtual aura::Window* GetToplevelWindow( |
| 50 aura::Window* window) const MOJO_OVERRIDE { |
| 51 mojo::View* view = mojo::WindowManagerApp::GetViewForWindow(window); |
| 52 while (view->parent() != window_container_) { |
| 53 view = view->parent(); |
| 54 // Unparented hierarchy, there is no "top level" window. |
| 55 if (!view) |
| 56 return NULL; |
| 57 } |
| 58 |
| 59 return window_manager_app_->GetWindowForViewId(view->id()); |
| 60 } |
| 61 virtual aura::Window* GetActivatableWindow( |
| 62 aura::Window* window) const MOJO_OVERRIDE { |
| 63 return GetToplevelWindow(window); |
| 64 } |
| 65 virtual aura::Window* GetFocusableWindow( |
| 66 aura::Window* window) const MOJO_OVERRIDE { |
| 67 return window; |
| 68 } |
| 69 virtual aura::Window* GetNextActivatableWindow( |
| 70 aura::Window* ignore) const MOJO_OVERRIDE { |
| 71 aura::Window* activatable = GetActivatableWindow(ignore); |
| 72 const aura::Window::Windows& children = activatable->parent()->children(); |
| 73 for (aura::Window::Windows::const_reverse_iterator it = children.rbegin(); |
| 74 it != children.rend(); ++it) { |
| 75 if (*it != ignore) |
| 76 return *it; |
| 77 } |
| 78 return NULL; |
| 79 } |
| 80 |
| 81 mojo::View* window_container_; |
| 82 mojo::WindowManagerApp* window_manager_app_; |
| 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(WMFocusRules); |
| 85 }; |
| 86 |
| 87 } // namespace |
| 88 |
21 class SimpleWM : public mojo::ApplicationDelegate, | 89 class SimpleWM : public mojo::ApplicationDelegate, |
22 public mojo::ViewManagerDelegate, | 90 public mojo::ViewManagerDelegate, |
23 public mojo::WindowManagerDelegate, | 91 public mojo::WindowManagerDelegate, |
24 public mojo::ViewObserver { | 92 public mojo::ViewObserver { |
25 public: | 93 public: |
26 SimpleWM() | 94 SimpleWM() |
27 : window_manager_app_(new mojo::WindowManagerApp(this, this)), | 95 : window_manager_app_(new mojo::WindowManagerApp(this, this)), |
28 view_manager_(NULL), | 96 view_manager_(NULL), |
29 root_(NULL), | 97 root_(NULL), |
30 window_container_(NULL), | 98 window_container_(NULL), |
(...skipping 17 matching lines...) Expand all Loading... |
48 mojo::View* root, | 116 mojo::View* root, |
49 mojo::ServiceProviderImpl* exported_services, | 117 mojo::ServiceProviderImpl* exported_services, |
50 scoped_ptr<mojo::ServiceProvider> remote_service_provider) MOJO_OVERRIDE { | 118 scoped_ptr<mojo::ServiceProvider> remote_service_provider) MOJO_OVERRIDE { |
51 view_manager_ = view_manager; | 119 view_manager_ = view_manager; |
52 root_ = root; | 120 root_ = root; |
53 | 121 |
54 window_container_ = mojo::View::Create(view_manager_); | 122 window_container_ = mojo::View::Create(view_manager_); |
55 window_container_->SetBounds(root_->bounds()); | 123 window_container_->SetBounds(root_->bounds()); |
56 root_->AddChild(window_container_); | 124 root_->AddChild(window_container_); |
57 | 125 |
| 126 window_manager_app_->InitFocus(new WMFocusRules(window_manager_app_.get(), |
| 127 window_container_)); |
58 } | 128 } |
59 virtual void OnViewManagerDisconnected( | 129 virtual void OnViewManagerDisconnected( |
60 mojo::ViewManager* view_manager) MOJO_OVERRIDE { | 130 mojo::ViewManager* view_manager) MOJO_OVERRIDE { |
61 view_manager_ = NULL; | 131 view_manager_ = NULL; |
62 root_ = NULL; | 132 root_ = NULL; |
63 } | 133 } |
64 | 134 |
65 // Overridden from mojo::WindowManagerDelegate: | 135 // Overridden from mojo::WindowManagerDelegate: |
66 virtual void Embed( | 136 virtual void Embed( |
67 const mojo::String& url, | 137 const mojo::String& url, |
(...skipping 30 matching lines...) Expand all Loading... |
98 first_child->Destroy(); | 168 first_child->Destroy(); |
99 view->Destroy(); | 169 view->Destroy(); |
100 next_window_origin_.Offset(-50, -50); | 170 next_window_origin_.Offset(-50, -50); |
101 } | 171 } |
102 | 172 |
103 mojo::View* CreateTopLevelWindow(mojo::View** app_view) { | 173 mojo::View* CreateTopLevelWindow(mojo::View** app_view) { |
104 mojo::View* frame_view = mojo::View::Create(view_manager_); | 174 mojo::View* frame_view = mojo::View::Create(view_manager_); |
105 frame_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400))); | 175 frame_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400))); |
106 next_window_origin_.Offset(50, 50); | 176 next_window_origin_.Offset(50, 50); |
107 | 177 |
108 new FrameController(frame_view, app_view); | 178 aura::client::ActivationClient* client = aura::client::GetActivationClient( |
| 179 window_manager_app_->host()->window()); |
| 180 new FrameController(frame_view, app_view, client, |
| 181 window_manager_app_.get()); |
109 return frame_view; | 182 return frame_view; |
110 } | 183 } |
111 | 184 |
112 scoped_ptr<mojo::WindowManagerApp> window_manager_app_; | 185 scoped_ptr<mojo::WindowManagerApp> window_manager_app_; |
113 | 186 |
114 mojo::ViewManager* view_manager_; | 187 mojo::ViewManager* view_manager_; |
115 mojo::View* root_; | 188 mojo::View* root_; |
116 mojo::View* window_container_; | 189 mojo::View* window_container_; |
117 | 190 |
118 gfx::Point next_window_origin_; | 191 gfx::Point next_window_origin_; |
119 | 192 |
120 DISALLOW_COPY_AND_ASSIGN(SimpleWM); | 193 DISALLOW_COPY_AND_ASSIGN(SimpleWM); |
121 }; | 194 }; |
122 | 195 |
123 } // namespace examples | 196 } // namespace examples |
124 | 197 |
125 MojoResult MojoMain(MojoHandle shell_handle) { | 198 MojoResult MojoMain(MojoHandle shell_handle) { |
126 mojo::ViewsInit views_init; | 199 mojo::ViewsInit views_init; |
127 mojo::ApplicationRunnerChromium runner(new examples::SimpleWM); | 200 mojo::ApplicationRunnerChromium runner(new examples::SimpleWM); |
128 return runner.Run(shell_handle); | 201 return runner.Run(shell_handle); |
129 } | 202 } |
OLD | NEW |