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 "services/window_manager/window_manager_app.h" | 5 #include "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/converters/geometry/geometry_type_converters.h" | 9 #include "mojo/converters/geometry/geometry_type_converters.h" |
10 #include "mojo/converters/input_events/input_events_type_converters.h" | 10 #include "mojo/converters/input_events/input_events_type_converters.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_impl.h" | 12 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "mojo/public/interfaces/application/shell.mojom.h" | 13 #include "mojo/public/interfaces/application/shell.mojom.h" |
14 #include "mojo/services/view_manager/public/cpp/view.h" | 14 #include "mojo/services/view_manager/public/cpp/view.h" |
15 #include "mojo/services/view_manager/public/cpp/view_manager.h" | 15 #include "mojo/services/view_manager/public/cpp/view_manager.h" |
| 16 #include "services/window_manager/capture_controller.h" |
16 #include "services/window_manager/focus_controller.h" | 17 #include "services/window_manager/focus_controller.h" |
17 #include "services/window_manager/focus_rules.h" | 18 #include "services/window_manager/focus_rules.h" |
18 #include "services/window_manager/view_event_dispatcher.h" | 19 #include "services/window_manager/view_event_dispatcher.h" |
19 #include "services/window_manager/view_target.h" | 20 #include "services/window_manager/view_target.h" |
20 #include "services/window_manager/view_targeter.h" | 21 #include "services/window_manager/view_targeter.h" |
21 #include "services/window_manager/window_manager_delegate.h" | 22 #include "services/window_manager/window_manager_delegate.h" |
22 #include "ui/base/hit_test.h" | 23 #include "ui/base/hit_test.h" |
23 | 24 |
24 using mojo::ApplicationConnection; | 25 using mojo::ApplicationConnection; |
25 using mojo::Id; | 26 using mojo::Id; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 void WindowManagerApp::AddConnection(WindowManagerImpl* connection) { | 66 void WindowManagerApp::AddConnection(WindowManagerImpl* connection) { |
66 DCHECK(connections_.find(connection) == connections_.end()); | 67 DCHECK(connections_.find(connection) == connections_.end()); |
67 connections_.insert(connection); | 68 connections_.insert(connection); |
68 } | 69 } |
69 | 70 |
70 void WindowManagerApp::RemoveConnection(WindowManagerImpl* connection) { | 71 void WindowManagerApp::RemoveConnection(WindowManagerImpl* connection) { |
71 DCHECK(connections_.find(connection) != connections_.end()); | 72 DCHECK(connections_.find(connection) != connections_.end()); |
72 connections_.erase(connection); | 73 connections_.erase(connection); |
73 } | 74 } |
74 | 75 |
75 void WindowManagerApp::SetCapture(Id view) { | 76 void WindowManagerApp::SetCapture(Id view_id) { |
76 // TODO(erg): Capture. Another pile of worms that is mixed in here. | 77 View* view = view_manager_->GetViewById(view_id); |
77 | 78 DCHECK(view); |
78 // capture_client_->capture_client()->SetCapture(GetWindowForViewId(view)); | 79 capture_controller_->SetCapture(view); |
79 | |
80 // TODO(beng): notify connected clients that capture has changed, probably | |
81 // by implementing some capture-client observer. | |
82 } | 80 } |
83 | 81 |
84 void WindowManagerApp::FocusWindow(Id view_id) { | 82 void WindowManagerApp::FocusWindow(Id view_id) { |
85 View* view = view_manager_->GetViewById(view_id); | 83 View* view = view_manager_->GetViewById(view_id); |
86 DCHECK(view); | 84 DCHECK(view); |
87 focus_controller_->FocusView(view); | 85 focus_controller_->FocusView(view); |
88 } | 86 } |
89 | 87 |
90 void WindowManagerApp::ActivateWindow(Id view_id) { | 88 void WindowManagerApp::ActivateWindow(Id view_id) { |
91 View* view = view_manager_->GetViewById(view_id); | 89 View* view = view_manager_->GetViewById(view_id); |
92 DCHECK(view); | 90 DCHECK(view); |
93 focus_controller_->ActivateView(view); | 91 focus_controller_->ActivateView(view); |
94 } | 92 } |
95 | 93 |
96 bool WindowManagerApp::IsReady() const { | 94 bool WindowManagerApp::IsReady() const { |
97 return view_manager_ && root_; | 95 return view_manager_ && root_; |
98 } | 96 } |
99 | 97 |
100 void WindowManagerApp::InitFocus(scoped_ptr<FocusRules> rules) { | 98 void WindowManagerApp::InitFocus(scoped_ptr<FocusRules> rules) { |
| 99 DCHECK(root_); |
| 100 |
101 focus_controller_.reset(new FocusController(rules.Pass())); | 101 focus_controller_.reset(new FocusController(rules.Pass())); |
102 focus_controller_->AddObserver(this); | 102 focus_controller_->AddObserver(this); |
| 103 SetFocusController(root_, focus_controller_.get()); |
103 | 104 |
104 DCHECK(root_); | 105 capture_controller_.reset(new CaptureController); |
105 SetFocusController(root_, focus_controller_.get()); | 106 capture_controller_->AddObserver(this); |
| 107 SetCaptureController(root_, capture_controller_.get()); |
106 } | 108 } |
107 | 109 |
108 void WindowManagerApp::Embed( | 110 void WindowManagerApp::Embed( |
109 const mojo::String& url, | 111 const mojo::String& url, |
110 mojo::InterfaceRequest<ServiceProvider> service_provider) { | 112 mojo::InterfaceRequest<ServiceProvider> service_provider) { |
111 if (view_manager_) { | 113 if (view_manager_) { |
112 window_manager_delegate_->Embed(url, service_provider.Pass()); | 114 window_manager_delegate_->Embed(url, service_provider.Pass()); |
113 return; | 115 return; |
114 } | 116 } |
115 scoped_ptr<PendingEmbed> pending_embed(new PendingEmbed); | 117 scoped_ptr<PendingEmbed> pending_embed(new PendingEmbed); |
(...skipping 24 matching lines...) Expand all Loading... |
140 mojo::ServiceProviderImpl* exported_services, | 142 mojo::ServiceProviderImpl* exported_services, |
141 scoped_ptr<ServiceProvider> imported_services) { | 143 scoped_ptr<ServiceProvider> imported_services) { |
142 DCHECK(!view_manager_ && !root_); | 144 DCHECK(!view_manager_ && !root_); |
143 view_manager_ = view_manager; | 145 view_manager_ = view_manager; |
144 root_ = root; | 146 root_ = root; |
145 | 147 |
146 view_event_dispatcher_.reset(new ViewEventDispatcher); | 148 view_event_dispatcher_.reset(new ViewEventDispatcher); |
147 | 149 |
148 RegisterSubtree(root_); | 150 RegisterSubtree(root_); |
149 | 151 |
150 // TODO(erg): Also move the capture client over. | |
151 // | |
152 // capture_client_.reset( | |
153 // new wm::ScopedCaptureClient(window_tree_host_->window())); | |
154 | |
155 if (wrapped_view_manager_delegate_) { | 152 if (wrapped_view_manager_delegate_) { |
156 wrapped_view_manager_delegate_->OnEmbed( | 153 wrapped_view_manager_delegate_->OnEmbed( |
157 view_manager, root, exported_services, imported_services.Pass()); | 154 view_manager, root, exported_services, imported_services.Pass()); |
158 } | 155 } |
159 | 156 |
160 for (PendingEmbed* pending_embed : pending_embeds_) | 157 for (PendingEmbed* pending_embed : pending_embeds_) |
161 Embed(pending_embed->url, pending_embed->service_provider.Pass()); | 158 Embed(pending_embed->url, pending_embed->service_provider.Pass()); |
162 pending_embeds_.clear(); | 159 pending_embeds_.clear(); |
163 } | 160 } |
164 | 161 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 193 } |
197 | 194 |
198 void WindowManagerApp::OnViewDestroying(View* view) { | 195 void WindowManagerApp::OnViewDestroying(View* view) { |
199 if (view != root_) { | 196 if (view != root_) { |
200 Unregister(view); | 197 Unregister(view); |
201 return; | 198 return; |
202 } | 199 } |
203 root_ = nullptr; | 200 root_ = nullptr; |
204 if (focus_controller_) | 201 if (focus_controller_) |
205 focus_controller_->RemoveObserver(this); | 202 focus_controller_->RemoveObserver(this); |
| 203 if (capture_controller_) |
| 204 capture_controller_->RemoveObserver(this); |
206 } | 205 } |
207 | 206 |
208 //////////////////////////////////////////////////////////////////////////////// | 207 //////////////////////////////////////////////////////////////////////////////// |
209 // WindowManagerApp, ui::EventHandler implementation: | 208 // WindowManagerApp, ui::EventHandler implementation: |
210 | 209 |
211 void WindowManagerApp::OnEvent(ui::Event* event) { | 210 void WindowManagerApp::OnEvent(ui::Event* event) { |
212 if (!window_manager_client_) | 211 if (!window_manager_client_) |
213 return; | 212 return; |
214 | 213 |
215 View* view = static_cast<ViewTarget*>(event->target())->view(); | 214 View* view = static_cast<ViewTarget*>(event->target())->view(); |
(...skipping 24 matching lines...) Expand all Loading... |
240 for (Connections::const_iterator it = connections_.begin(); | 239 for (Connections::const_iterator it = connections_.begin(); |
241 it != connections_.end(); ++it) { | 240 it != connections_.end(); ++it) { |
242 (*it)->NotifyWindowActivated(GetIdForView(gained_active), | 241 (*it)->NotifyWindowActivated(GetIdForView(gained_active), |
243 GetIdForView(lost_active)); | 242 GetIdForView(lost_active)); |
244 } | 243 } |
245 if (gained_active) | 244 if (gained_active) |
246 gained_active->MoveToFront(); | 245 gained_active->MoveToFront(); |
247 } | 246 } |
248 | 247 |
249 //////////////////////////////////////////////////////////////////////////////// | 248 //////////////////////////////////////////////////////////////////////////////// |
| 249 // WindowManagerApp, mojo::CaptureControllerObserver implementation: |
| 250 |
| 251 void WindowManagerApp::OnCaptureChanged(View* gained_capture, |
| 252 View* lost_capture) { |
| 253 for (Connections::const_iterator it = connections_.begin(); |
| 254 it != connections_.end(); ++it) { |
| 255 (*it)->NotifyCaptureChanged(GetIdForView(gained_capture), |
| 256 GetIdForView(lost_capture)); |
| 257 } |
| 258 if (gained_capture) |
| 259 gained_capture->MoveToFront(); |
| 260 } |
| 261 |
| 262 //////////////////////////////////////////////////////////////////////////////// |
250 // WindowManagerApp, private: | 263 // WindowManagerApp, private: |
251 | 264 |
252 void WindowManagerApp::RegisterSubtree(View* view) { | 265 void WindowManagerApp::RegisterSubtree(View* view) { |
253 view->AddObserver(this); | 266 view->AddObserver(this); |
254 DCHECK(registered_view_id_set_.find(view->id()) == | 267 DCHECK(registered_view_id_set_.find(view->id()) == |
255 registered_view_id_set_.end()); | 268 registered_view_id_set_.end()); |
256 // All events pass through the root during dispatch, so we only need a handler | 269 // All events pass through the root during dispatch, so we only need a handler |
257 // installed there. | 270 // installed there. |
258 if (view == root_) { | 271 if (view == root_) { |
259 ViewTarget* target = ViewTarget::TargetFromView(view); | 272 ViewTarget* target = ViewTarget::TargetFromView(view); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 uint16_t connection_id, | 354 uint16_t connection_id, |
342 mojo::ScopedMessagePipeHandle window_manager_pipe) { | 355 mojo::ScopedMessagePipeHandle window_manager_pipe) { |
343 // TODO(sky): pass in |connection_id| for validation. | 356 // TODO(sky): pass in |connection_id| for validation. |
344 WindowManagerImpl* wm = new WindowManagerImpl(this, true); | 357 WindowManagerImpl* wm = new WindowManagerImpl(this, true); |
345 wm->Bind(window_manager_pipe.Pass()); | 358 wm->Bind(window_manager_pipe.Pass()); |
346 // WindowManagerImpl is deleted when the connection has an error, or from our | 359 // WindowManagerImpl is deleted when the connection has an error, or from our |
347 // destructor. | 360 // destructor. |
348 } | 361 } |
349 | 362 |
350 } // namespace window_manager | 363 } // namespace window_manager |
OLD | NEW |