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 "mojo/services/window_manager/window_manager_app.h" | 5 #include "mojo/services/window_manager/window_manager_app.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "mojo/aura/aura_init.h" | 9 #include "mojo/aura/aura_init.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_impl.h" | 11 #include "mojo/public/cpp/application/application_impl.h" |
12 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 12 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
13 #include "mojo/services/public/cpp/view_manager/view.h" | 13 #include "mojo/services/public/cpp/view_manager/view.h" |
14 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 14 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/aura/window_delegate.h" | 16 #include "ui/aura/window_delegate.h" |
17 #include "ui/aura/window_property.h" | 17 #include "ui/aura/window_property.h" |
18 #include "ui/base/hit_test.h" | 18 #include "ui/base/hit_test.h" |
19 #include "ui/wm/core/capture_controller.h" | 19 #include "ui/wm/core/capture_controller.h" |
20 #include "ui/wm/core/focus_controller.h" | 20 #include "ui/wm/core/focus_controller.h" |
21 #include "ui/wm/core/focus_rules.h" | |
22 #include "ui/wm/public/activation_client.h" | 21 #include "ui/wm/public/activation_client.h" |
23 | 22 |
24 DECLARE_WINDOW_PROPERTY_TYPE(mojo::View*); | 23 DECLARE_WINDOW_PROPERTY_TYPE(mojo::View*); |
25 | 24 |
26 namespace mojo { | 25 namespace mojo { |
27 | 26 |
28 // The aura::Windows we use to track Views don't render, so we don't actually | 27 // The aura::Windows we use to track Views don't render, so we don't actually |
29 // need to supply a fully functional WindowDelegate. We do need to provide _a_ | 28 // need to supply a fully functional WindowDelegate. We do need to provide _a_ |
30 // delegate however, otherwise the event dispatcher won't dispatch events to | 29 // delegate however, otherwise the event dispatcher won't dispatch events to |
31 // these windows. (The aura WindowTargeter won't allow a delegate-less window | 30 // these windows. (The aura WindowTargeter won't allow a delegate-less window |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 }; | 64 }; |
66 | 65 |
67 namespace { | 66 namespace { |
68 | 67 |
69 DEFINE_WINDOW_PROPERTY_KEY(View*, kViewKey, NULL); | 68 DEFINE_WINDOW_PROPERTY_KEY(View*, kViewKey, NULL); |
70 | 69 |
71 Id GetIdForWindow(aura::Window* window) { | 70 Id GetIdForWindow(aura::Window* window) { |
72 return window ? WindowManagerApp::GetViewForWindow(window)->id() : 0; | 71 return window ? WindowManagerApp::GetViewForWindow(window)->id() : 0; |
73 } | 72 } |
74 | 73 |
75 class WMFocusRules : public wm::FocusRules { | |
76 public: | |
77 WMFocusRules() {} | |
78 virtual ~WMFocusRules() {} | |
79 | |
80 private: | |
81 // Overridden from wm::FocusRules: | |
82 virtual bool IsToplevelWindow(aura::Window* window) const MOJO_OVERRIDE { | |
83 return true; | |
84 } | |
85 virtual bool CanActivateWindow(aura::Window* window) const MOJO_OVERRIDE { | |
86 return true; | |
87 } | |
88 virtual bool CanFocusWindow(aura::Window* window) const MOJO_OVERRIDE { | |
89 return true; | |
90 } | |
91 virtual aura::Window* GetToplevelWindow( | |
92 aura::Window* window) const MOJO_OVERRIDE { | |
93 return window; | |
94 } | |
95 virtual aura::Window* GetActivatableWindow( | |
96 aura::Window* window) const MOJO_OVERRIDE { | |
97 return window; | |
98 } | |
99 virtual aura::Window* GetFocusableWindow( | |
100 aura::Window* window) const MOJO_OVERRIDE { | |
101 return window; | |
102 } | |
103 virtual aura::Window* GetNextActivatableWindow( | |
104 aura::Window* ignore) const MOJO_OVERRIDE { | |
105 return NULL; | |
106 } | |
107 | |
108 DISALLOW_COPY_AND_ASSIGN(WMFocusRules); | |
109 }; | |
110 | |
111 } // namespace | 74 } // namespace |
112 | 75 |
113 //////////////////////////////////////////////////////////////////////////////// | 76 //////////////////////////////////////////////////////////////////////////////// |
114 // WindowManagerApp, public: | 77 // WindowManagerApp, public: |
115 | 78 |
116 WindowManagerApp::WindowManagerApp( | 79 WindowManagerApp::WindowManagerApp( |
117 ViewManagerDelegate* view_manager_delegate, | 80 ViewManagerDelegate* view_manager_delegate, |
118 WindowManagerDelegate* window_manager_delegate) | 81 WindowManagerDelegate* window_manager_delegate) |
119 : window_manager_service_factory_(this), | 82 : window_manager_service_factory_(this), |
120 wrapped_view_manager_delegate_(view_manager_delegate), | 83 wrapped_view_manager_delegate_(view_manager_delegate), |
121 wrapped_window_manager_delegate_(window_manager_delegate), | 84 wrapped_window_manager_delegate_(window_manager_delegate), |
122 view_manager_(NULL), | 85 view_manager_(NULL), |
123 root_(NULL), | 86 root_(NULL), |
124 dummy_delegate_(new DummyDelegate) { | 87 dummy_delegate_(new DummyDelegate) { |
125 } | 88 } |
126 | 89 |
127 WindowManagerApp::~WindowManagerApp() {} | 90 WindowManagerApp::~WindowManagerApp() {} |
128 | 91 |
129 // static | 92 // static |
130 View* WindowManagerApp::GetViewForWindow(aura::Window* window) { | 93 View* WindowManagerApp::GetViewForWindow(aura::Window* window) { |
131 return window->GetProperty(kViewKey); | 94 return window->GetProperty(kViewKey); |
132 } | 95 } |
133 | 96 |
| 97 aura::Window* WindowManagerApp::GetWindowForViewId(Id view) { |
| 98 ViewIdToWindowMap::const_iterator it = view_id_to_window_map_.find(view); |
| 99 return it != view_id_to_window_map_.end() ? it->second : NULL; |
| 100 } |
| 101 |
134 void WindowManagerApp::AddConnection(WindowManagerServiceImpl* connection) { | 102 void WindowManagerApp::AddConnection(WindowManagerServiceImpl* connection) { |
135 DCHECK(connections_.find(connection) == connections_.end()); | 103 DCHECK(connections_.find(connection) == connections_.end()); |
136 connections_.insert(connection); | 104 connections_.insert(connection); |
137 } | 105 } |
138 | 106 |
139 void WindowManagerApp::RemoveConnection(WindowManagerServiceImpl* connection) { | 107 void WindowManagerApp::RemoveConnection(WindowManagerServiceImpl* connection) { |
140 DCHECK(connections_.find(connection) != connections_.end()); | 108 DCHECK(connections_.find(connection) != connections_.end()); |
141 connections_.erase(connection); | 109 connections_.erase(connection); |
142 } | 110 } |
143 | 111 |
(...skipping 12 matching lines...) Expand all Loading... |
156 void WindowManagerApp::ActivateWindow(Id view) { | 124 void WindowManagerApp::ActivateWindow(Id view) { |
157 aura::Window* window = GetWindowForViewId(view); | 125 aura::Window* window = GetWindowForViewId(view); |
158 DCHECK(window); | 126 DCHECK(window); |
159 activation_client_->ActivateWindow(window); | 127 activation_client_->ActivateWindow(window); |
160 } | 128 } |
161 | 129 |
162 bool WindowManagerApp::IsReady() const { | 130 bool WindowManagerApp::IsReady() const { |
163 return view_manager_ && root_; | 131 return view_manager_ && root_; |
164 } | 132 } |
165 | 133 |
| 134 void WindowManagerApp::InitFocus(wm::FocusRules* rules) { |
| 135 wm::FocusController* focus_controller = new wm::FocusController(rules); |
| 136 activation_client_ = focus_controller; |
| 137 focus_client_.reset(focus_controller); |
| 138 aura::client::SetFocusClient(window_tree_host_->window(), focus_controller); |
| 139 aura::client::SetActivationClient(window_tree_host_->window(), |
| 140 focus_controller); |
| 141 |
| 142 focus_client_->AddObserver(this); |
| 143 activation_client_->AddObserver(this); |
| 144 } |
| 145 |
166 //////////////////////////////////////////////////////////////////////////////// | 146 //////////////////////////////////////////////////////////////////////////////// |
167 // WindowManagerApp, ApplicationDelegate implementation: | 147 // WindowManagerApp, ApplicationDelegate implementation: |
168 | 148 |
169 void WindowManagerApp::Initialize(ApplicationImpl* impl) { | 149 void WindowManagerApp::Initialize(ApplicationImpl* impl) { |
170 aura_init_.reset(new AuraInit); | 150 aura_init_.reset(new AuraInit); |
171 view_manager_client_factory_.reset( | 151 view_manager_client_factory_.reset( |
172 new ViewManagerClientFactory(impl->shell(), this)); | 152 new ViewManagerClientFactory(impl->shell(), this)); |
173 } | 153 } |
174 | 154 |
175 bool WindowManagerApp::ConfigureIncomingConnection( | 155 bool WindowManagerApp::ConfigureIncomingConnection( |
(...skipping 16 matching lines...) Expand all Loading... |
192 root_ = root; | 172 root_ = root; |
193 | 173 |
194 window_tree_host_.reset(new WindowTreeHostMojo(root_, this)); | 174 window_tree_host_.reset(new WindowTreeHostMojo(root_, this)); |
195 window_tree_host_->window()->SetBounds(root->bounds()); | 175 window_tree_host_->window()->SetBounds(root->bounds()); |
196 window_tree_host_->window()->Show(); | 176 window_tree_host_->window()->Show(); |
197 | 177 |
198 RegisterSubtree(root_, window_tree_host_->window()); | 178 RegisterSubtree(root_, window_tree_host_->window()); |
199 | 179 |
200 capture_client_.reset( | 180 capture_client_.reset( |
201 new wm::ScopedCaptureClient(window_tree_host_->window())); | 181 new wm::ScopedCaptureClient(window_tree_host_->window())); |
202 wm::FocusController* focus_controller = | |
203 new wm::FocusController(new WMFocusRules); | |
204 activation_client_ = focus_controller; | |
205 focus_client_.reset(focus_controller); | |
206 aura::client::SetFocusClient(window_tree_host_->window(), focus_controller); | |
207 | |
208 focus_client_->AddObserver(this); | |
209 activation_client_->AddObserver(this); | |
210 | 182 |
211 if (wrapped_view_manager_delegate_) { | 183 if (wrapped_view_manager_delegate_) { |
212 wrapped_view_manager_delegate_->OnEmbed( | 184 wrapped_view_manager_delegate_->OnEmbed( |
213 view_manager, root, exported_services, imported_services.Pass()); | 185 view_manager, root, exported_services, imported_services.Pass()); |
214 } | 186 } |
215 | 187 |
216 for (Connections::const_iterator it = connections_.begin(); | 188 for (Connections::const_iterator it = connections_.begin(); |
217 it != connections_.end(); ++it) { | 189 it != connections_.end(); ++it) { |
218 (*it)->NotifyReady(); | 190 (*it)->NotifyReady(); |
219 } | 191 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 //////////////////////////////////////////////////////////////////////////////// | 292 //////////////////////////////////////////////////////////////////////////////// |
321 // WindowManagerApp, aura::client::ActivationChangeObserver implementation: | 293 // WindowManagerApp, aura::client::ActivationChangeObserver implementation: |
322 | 294 |
323 void WindowManagerApp::OnWindowActivated(aura::Window* gained_active, | 295 void WindowManagerApp::OnWindowActivated(aura::Window* gained_active, |
324 aura::Window* lost_active) { | 296 aura::Window* lost_active) { |
325 for (Connections::const_iterator it = connections_.begin(); | 297 for (Connections::const_iterator it = connections_.begin(); |
326 it != connections_.end(); ++it) { | 298 it != connections_.end(); ++it) { |
327 (*it)->NotifyWindowActivated(GetIdForWindow(gained_active), | 299 (*it)->NotifyWindowActivated(GetIdForWindow(gained_active), |
328 GetIdForWindow(lost_active)); | 300 GetIdForWindow(lost_active)); |
329 } | 301 } |
| 302 if (gained_active) { |
| 303 View* view = GetViewForWindow(gained_active); |
| 304 view->MoveToFront(); |
| 305 } |
330 } | 306 } |
331 | 307 |
332 //////////////////////////////////////////////////////////////////////////////// | 308 //////////////////////////////////////////////////////////////////////////////// |
333 // WindowManagerApp, private: | 309 // WindowManagerApp, private: |
334 | 310 |
335 aura::Window* WindowManagerApp::GetWindowForViewId(Id view) const { | |
336 ViewIdToWindowMap::const_iterator it = view_id_to_window_map_.find(view); | |
337 return it != view_id_to_window_map_.end() ? it->second : NULL; | |
338 } | |
339 | |
340 void WindowManagerApp::RegisterSubtree(View* view, aura::Window* parent) { | 311 void WindowManagerApp::RegisterSubtree(View* view, aura::Window* parent) { |
341 view->AddObserver(this); | 312 view->AddObserver(this); |
342 DCHECK(view_id_to_window_map_.find(view->id()) == | 313 DCHECK(view_id_to_window_map_.find(view->id()) == |
343 view_id_to_window_map_.end()); | 314 view_id_to_window_map_.end()); |
344 aura::Window* window = new aura::Window(dummy_delegate_.get()); | 315 aura::Window* window = new aura::Window(dummy_delegate_.get()); |
345 window->set_id(view->id()); | 316 window->set_id(view->id()); |
346 window->SetProperty(kViewKey, view); | 317 window->SetProperty(kViewKey, view); |
347 // All events pass through the root during dispatch, so we only need a handler | 318 // All events pass through the root during dispatch, so we only need a handler |
348 // installed there. | 319 // installed there. |
349 if (view == root_) | 320 if (view == root_) |
(...skipping 12 matching lines...) Expand all Loading... |
362 ViewIdToWindowMap::iterator it = view_id_to_window_map_.find(view->id()); | 333 ViewIdToWindowMap::iterator it = view_id_to_window_map_.find(view->id()); |
363 DCHECK(it != view_id_to_window_map_.end()); | 334 DCHECK(it != view_id_to_window_map_.end()); |
364 scoped_ptr<aura::Window> window(it->second); | 335 scoped_ptr<aura::Window> window(it->second); |
365 view_id_to_window_map_.erase(it); | 336 view_id_to_window_map_.erase(it); |
366 View::Children::const_iterator child = view->children().begin(); | 337 View::Children::const_iterator child = view->children().begin(); |
367 for (; child != view->children().end(); ++child) | 338 for (; child != view->children().end(); ++child) |
368 UnregisterSubtree(*child); | 339 UnregisterSubtree(*child); |
369 } | 340 } |
370 | 341 |
371 } // namespace mojo | 342 } // namespace mojo |
OLD | NEW |