Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(929)

Side by Side Diff: mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc

Issue 474883003: Move focus from the view manager to the window manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/public/cpp/view_manager/lib/view_manager_client_impl.h" 5 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h" 10 #include "base/stl_util.h"
10 #include "mojo/public/cpp/application/application_connection.h" 11 #include "mojo/public/cpp/application/application_connection.h"
11 #include "mojo/public/cpp/application/connect.h" 12 #include "mojo/public/cpp/application/connect.h"
12 #include "mojo/public/cpp/application/service_provider_impl.h" 13 #include "mojo/public/cpp/application/service_provider_impl.h"
13 #include "mojo/public/interfaces/application/service_provider.mojom.h" 14 #include "mojo/public/interfaces/application/service_provider.mojom.h"
14 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" 15 #include "mojo/services/public/cpp/view_manager/lib/view_private.h"
15 #include "mojo/services/public/cpp/view_manager/util.h" 16 #include "mojo/services/public/cpp/view_manager/util.h"
16 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 17 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
17 #include "mojo/services/public/cpp/view_manager/view_observer.h" 18 #include "mojo/services/public/cpp/view_manager/view_observer.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 110
110 result = MapBuffer( 111 result = MapBuffer(
111 handle->get(), 0, size, memory, MOJO_MAP_BUFFER_FLAG_NONE); 112 handle->get(), 0, size, memory, MOJO_MAP_BUFFER_FLAG_NONE);
112 if (result != MOJO_RESULT_OK) 113 if (result != MOJO_RESULT_OK)
113 return false; 114 return false;
114 DCHECK(*memory); 115 DCHECK(*memory);
115 116
116 return true; 117 return true;
117 } 118 }
118 119
119 ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate) 120 ViewManagerClientImpl::ViewManagerClientImpl(
121 ViewManagerDelegate* delegate,
122 ApplicationConnection* app_connection)
120 : connected_(false), 123 : connected_(false),
121 connection_id_(0), 124 connection_id_(0),
122 next_id_(1), 125 next_id_(1),
123 delegate_(delegate), 126 delegate_(delegate),
124 window_manager_delegate_(NULL) { 127 window_manager_delegate_(NULL) {
128 // TODO(beng): Come up with a better way of establishing a configuration for
129 // what the active window manager is.
130 std::string window_manager_url = "mojo:mojo_window_manager";
131 if (base::CommandLine::ForCurrentProcess()->HasSwitch("window-manager")) {
132 window_manager_url =
133 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
134 "window-manager");
135 }
136 app_connection->ConnectToService(window_manager_url, &window_manager_);
137 window_manager_.set_client(this);
125 } 138 }
126 139
127 ViewManagerClientImpl::~ViewManagerClientImpl() { 140 ViewManagerClientImpl::~ViewManagerClientImpl() {
128 std::vector<View*> non_owned; 141 std::vector<View*> non_owned;
129 while (!views_.empty()) { 142 while (!views_.empty()) {
130 IdToViewMap::iterator it = views_.begin(); 143 IdToViewMap::iterator it = views_.begin();
131 if (OwnsView(it->second->id())) { 144 if (OwnsView(it->second->id())) {
132 it->second->Destroy(); 145 it->second->Destroy();
133 } else { 146 } else {
134 non_owned.push_back(it->second); 147 non_owned.push_back(it->second);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 return; 214 return;
202 215
203 memcpy(memory, &data[0], data.size()); 216 memcpy(memory, &data[0], data.size());
204 217
205 service_->SetViewContents(view_id, duped.Pass(), 218 service_->SetViewContents(view_id, duped.Pass(),
206 static_cast<uint32_t>(data.size()), 219 static_cast<uint32_t>(data.size()),
207 ActionCompletedCallback()); 220 ActionCompletedCallback());
208 } 221 }
209 222
210 void ViewManagerClientImpl::SetFocus(Id view_id) { 223 void ViewManagerClientImpl::SetFocus(Id view_id) {
211 DCHECK(connected_); 224 window_manager_->FocusWindow(view_id, ActionCompletedCallback());
212 service_->SetFocus(view_id, ActionCompletedCallback());
213 } 225 }
214 226
215 void ViewManagerClientImpl::SetVisible(Id view_id, bool visible) { 227 void ViewManagerClientImpl::SetVisible(Id view_id, bool visible) {
216 DCHECK(connected_); 228 DCHECK(connected_);
217 service_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); 229 service_->SetViewVisibility(view_id, visible, ActionCompletedCallback());
218 } 230 }
219 231
220 void ViewManagerClientImpl::Embed(const String& url, Id view_id) { 232 void ViewManagerClientImpl::Embed(const String& url, Id view_id) {
221 ServiceProviderPtr sp; 233 ServiceProviderPtr sp;
222 BindToProxy(new ServiceProviderImpl, &sp); 234 BindToProxy(new ServiceProviderImpl, &sp);
(...skipping 19 matching lines...) Expand all
242 if (it != views_.end()) 254 if (it != views_.end())
243 views_.erase(it); 255 views_.erase(it);
244 } 256 }
245 257
246 //////////////////////////////////////////////////////////////////////////////// 258 ////////////////////////////////////////////////////////////////////////////////
247 // ViewManagerClientImpl, ViewManager implementation: 259 // ViewManagerClientImpl, ViewManager implementation:
248 260
249 void ViewManagerClientImpl::SetWindowManagerDelegate( 261 void ViewManagerClientImpl::SetWindowManagerDelegate(
250 WindowManagerDelegate* window_manager_delegate) { 262 WindowManagerDelegate* window_manager_delegate) {
251 CHECK(NULL != GetViewById(1)); 263 CHECK(NULL != GetViewById(1));
264 CHECK(!window_manager_delegate_);
252 window_manager_delegate_ = window_manager_delegate; 265 window_manager_delegate_ = window_manager_delegate;
253 } 266 }
254 267
255 void ViewManagerClientImpl::DispatchEvent(View* target, EventPtr event) { 268 void ViewManagerClientImpl::DispatchEvent(View* target, EventPtr event) {
256 CHECK(window_manager_delegate_); 269 CHECK(window_manager_delegate_);
257 service_->DispatchOnViewInputEvent(target->id(), event.Pass()); 270 service_->DispatchOnViewInputEvent(target->id(), event.Pass());
258 } 271 }
259 272
260 const std::string& ViewManagerClientImpl::GetEmbedderURL() const { 273 const std::string& ViewManagerClientImpl::GetEmbedderURL() const {
261 return creator_url_; 274 return creator_url_;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 const Callback<void()>& ack_callback) { 370 const Callback<void()>& ack_callback) {
358 View* view = GetViewById(view_id); 371 View* view = GetViewById(view_id);
359 if (view) { 372 if (view) {
360 FOR_EACH_OBSERVER(ViewObserver, 373 FOR_EACH_OBSERVER(ViewObserver,
361 *ViewPrivate(view).observers(), 374 *ViewPrivate(view).observers(),
362 OnViewInputEvent(view, event)); 375 OnViewInputEvent(view, event));
363 } 376 }
364 ack_callback.Run(); 377 ack_callback.Run();
365 } 378 }
366 379
367 void ViewManagerClientImpl::OnFocusChanged(Id gained_focus_id, 380 void ViewManagerClientImpl::Embed(
368 Id lost_focus_id) { 381 const String& url,
369 View* focused = GetViewById(gained_focus_id); 382 InterfaceRequest<ServiceProvider> service_provider) {
370 View* blurred = GetViewById(lost_focus_id); 383 window_manager_delegate_->Embed(url, service_provider.Pass());
384 }
385
386 void ViewManagerClientImpl::DispatchOnViewInputEvent(EventPtr event) {
387 if (window_manager_delegate_)
388 window_manager_delegate_->DispatchEvent(event.Pass());
389 }
390
391 ////////////////////////////////////////////////////////////////////////////////
392 // ViewManagerClientImpl, WindowManagerClient implementation:
393
394 void ViewManagerClientImpl::OnWindowManagerReady() {}
395
396 void ViewManagerClientImpl::OnCaptureChanged(Id old_capture_view_id,
397 Id new_capture_view_id) {}
398
399 void ViewManagerClientImpl::OnFocusChanged(Id old_focused_view_id,
400 Id new_focused_view_id) {
401 View* focused = GetViewById(new_focused_view_id);
402 View* blurred = GetViewById(old_focused_view_id);
371 if (blurred) { 403 if (blurred) {
372 FOR_EACH_OBSERVER(ViewObserver, 404 FOR_EACH_OBSERVER(ViewObserver,
373 *ViewPrivate(blurred).observers(), 405 *ViewPrivate(blurred).observers(),
374 OnViewFocusChanged(focused, blurred)); 406 OnViewFocusChanged(focused, blurred));
375 } 407 }
376 if (focused) { 408 if (focused) {
377 FOR_EACH_OBSERVER(ViewObserver, 409 FOR_EACH_OBSERVER(ViewObserver,
378 *ViewPrivate(focused).observers(), 410 *ViewPrivate(focused).observers(),
379 OnViewFocusChanged(focused, blurred)); 411 OnViewFocusChanged(focused, blurred));
380 } 412 }
381 } 413 }
382 414
383 void ViewManagerClientImpl::Embed( 415 void ViewManagerClientImpl::OnActiveWindowChanged(Id old_focused_window,
384 const String& url, 416 Id new_focused_window) {}
385 InterfaceRequest<ServiceProvider> service_provider) {
386 window_manager_delegate_->Embed(url, service_provider.Pass());
387 }
388
389 void ViewManagerClientImpl::DispatchOnViewInputEvent(Id view_id,
390 EventPtr event) {
391 if (window_manager_delegate_)
392 window_manager_delegate_->DispatchEvent(GetViewById(view_id), event.Pass());
393 }
394 417
395 //////////////////////////////////////////////////////////////////////////////// 418 ////////////////////////////////////////////////////////////////////////////////
396 // ViewManagerClientImpl, private: 419 // ViewManagerClientImpl, private:
397 420
398 void ViewManagerClientImpl::RemoveRoot(View* root) { 421 void ViewManagerClientImpl::RemoveRoot(View* root) {
399 std::vector<View*>::iterator it = 422 std::vector<View*>::iterator it =
400 std::find(roots_.begin(), roots_.end(), root); 423 std::find(roots_.begin(), roots_.end(), root);
401 if (it != roots_.end()) 424 if (it != roots_.end())
402 roots_.erase(it); 425 roots_.erase(it);
403 } 426 }
(...skipping 12 matching lines...) Expand all
416 base::Unretained(this)); 439 base::Unretained(this));
417 } 440 }
418 441
419 base::Callback<void(ErrorCode)> 442 base::Callback<void(ErrorCode)>
420 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { 443 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() {
421 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, 444 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode,
422 base::Unretained(this)); 445 base::Unretained(this));
423 } 446 }
424 447
425 } // namespace mojo 448 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698