Home | History | Annotate | Download | only in window_manager
      1 
      2 // Copyright 2014 The Chromium Authors. All rights reserved.
      3 // Use of this source code is governed by a BSD-style license that can be
      4 // found in the LICENSE file.
      5 
      6 #include "mojo/services/window_manager/window_manager_service_impl.h"
      7 
      8 #include "mojo/services/window_manager/window_manager_app.h"
      9 
     10 namespace mojo {
     11 
     12 ////////////////////////////////////////////////////////////////////////////////
     13 // WindowManagerServiceImpl, public:
     14 
     15 WindowManagerServiceImpl::WindowManagerServiceImpl(
     16     WindowManagerApp* window_manager)
     17     : window_manager_(window_manager) {
     18   window_manager_->AddConnection(this);
     19 }
     20 
     21 WindowManagerServiceImpl::~WindowManagerServiceImpl() {
     22   window_manager_->RemoveConnection(this);
     23 }
     24 
     25 void WindowManagerServiceImpl::NotifyReady() {
     26   client()->OnWindowManagerReady();
     27 }
     28 
     29 void WindowManagerServiceImpl::NotifyViewFocused(Id new_focused_id,
     30                                                  Id old_focused_id) {
     31   client()->OnFocusChanged(old_focused_id, new_focused_id);
     32 }
     33 
     34 void WindowManagerServiceImpl::NotifyWindowActivated(Id new_active_id,
     35                                                      Id old_active_id) {
     36   client()->OnActiveWindowChanged(old_active_id, new_active_id);
     37 }
     38 
     39 ////////////////////////////////////////////////////////////////////////////////
     40 // WindowManagerServiceImpl, WindowManager implementation:
     41 
     42 void WindowManagerServiceImpl::SetCapture(
     43     Id view,
     44     const Callback<void(bool)>& callback) {
     45   bool success = window_manager_->IsReady();
     46   if (success)
     47     window_manager_->SetCapture(view);
     48   callback.Run(success);
     49 }
     50 
     51 void WindowManagerServiceImpl::FocusWindow(
     52     Id view,
     53     const Callback<void(bool)>& callback) {
     54   bool success = window_manager_->IsReady();
     55   if (success)
     56     window_manager_->FocusWindow(view);
     57   callback.Run(success);
     58 }
     59 
     60 void WindowManagerServiceImpl::ActivateWindow(
     61     Id view,
     62     const Callback<void(bool)>& callback) {
     63   bool success = window_manager_->IsReady();
     64   if (success)
     65     window_manager_->ActivateWindow(view);
     66   callback.Run(success);
     67 }
     68 
     69 ////////////////////////////////////////////////////////////////////////////////
     70 // WindowManagerServiceImpl, InterfaceImpl overrides:
     71 
     72 void WindowManagerServiceImpl::OnConnectionEstablished() {
     73   // If the connection was established prior to the window manager being
     74   // embedded by the view manager, |window_manager_|'s ViewManagerDelegate
     75   // impl will call NotifyReady() when it is.
     76   if (window_manager_->IsReady())
     77     NotifyReady();
     78 }
     79 
     80 }  // namespace mojo
     81