summaryrefslogtreecommitdiffstats
path: root/mojo/services/window_manager/window_manager_app.h
blob: 310dbcc97165ff673a1e970b7ed7cd42c9878235 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_
#define MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_

#include <set>

#include "base/memory/scoped_ptr.h"
#include "mojo/aura/window_tree_host_mojo_delegate.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/interface_factory_with_context.h"
#include "mojo/public/cpp/bindings/string.h"
#include "mojo/services/public/cpp/view_manager/node_observer.h"
#include "mojo/services/public/cpp/view_manager/types.h"
#include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
#include "mojo/services/window_manager/window_manager_service_impl.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/wm/public/activation_change_observer.h"

namespace aura {
namespace client {
class ActivationClient;
class FocusClient;
}
class Window;
}

namespace wm {
class ScopedCaptureClient;
}

namespace mojo {

class AuraInit;
class WindowManagerServiceImpl;
class WindowTreeHostMojo;

class WindowManagerApp
    : public ApplicationDelegate,
      public view_manager::ViewManagerDelegate,
      public view_manager::NodeObserver,
      public WindowTreeHostMojoDelegate,
      public aura::client::FocusChangeObserver,
      public aura::client::ActivationChangeObserver,
      public InterfaceFactoryWithContext<WindowManagerServiceImpl,
                                         WindowManagerApp> {
 public:
  explicit WindowManagerApp(view_manager::ViewManagerDelegate* delegate);
  virtual ~WindowManagerApp();

  void AddConnection(WindowManagerServiceImpl* connection);
  void RemoveConnection(WindowManagerServiceImpl* connection);

  view_manager::Id OpenWindow();
  view_manager::Id OpenWindowWithURL(const String& url);
  void SetCapture(view_manager::Id node);
  void FocusWindow(view_manager::Id node);
  void ActivateWindow(view_manager::Id node);

  bool IsReady() const;

  // Overridden from ApplicationDelegate:
  virtual void Initialize(ApplicationImpl* impl) MOJO_OVERRIDE;
  virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
      MOJO_OVERRIDE;

 private:
  typedef std::set<WindowManagerServiceImpl*> Connections;
  typedef std::map<view_manager::Id, aura::Window*> NodeIdToWindowMap;

  // Overridden from view_manager::ViewManagerDelegate:
  virtual void OnRootAdded(view_manager::ViewManager* view_manager,
                           view_manager::Node* root) MOJO_OVERRIDE;
  virtual void OnViewManagerDisconnected(
      view_manager::ViewManager* view_manager) MOJO_OVERRIDE;

  // Overridden from view_manager::NodeObserver:
  virtual void OnTreeChanged(
      const view_manager::NodeObserver::TreeChangeParams& params) MOJO_OVERRIDE;

  // Overridden from WindowTreeHostMojoDelegate:
  virtual void CompositorContentsChanged(const SkBitmap& bitmap) MOJO_OVERRIDE;

  // Overridden from aura::client::FocusChangeObserver:
  virtual void OnWindowFocused(aura::Window* gained_focus,
                               aura::Window* lost_focus) MOJO_OVERRIDE;

  // Overridden from aura::client::ActivationChangeObserver:
  virtual void OnWindowActivated(aura::Window* gained_active,
                                 aura::Window* lost_active) MOJO_OVERRIDE;

  aura::Window* GetWindowForNodeId(view_manager::Id node) const;

  // Creates an aura::Window for every node in the hierarchy beneath |id|,
  // and adds to the registry so that it can be retrieved later via
  // GetWindowForNodeId().
  // TODO(beng): perhaps Node should have a property bag.
  void RegisterSubtree(view_manager::Id id, aura::Window* parent);
  // Deletes the aura::Windows associated with the hierarchy beneath |id|,
  // and removes from the registry.
  void UnregisterSubtree(view_manager::Id id);

  view_manager::ViewManagerDelegate* wrapped_delegate_;

  view_manager::ViewManager* view_manager_;
  view_manager::ViewManagerClientFactory view_manager_client_factory_;
  view_manager::Node* root_;

  scoped_ptr<AuraInit> aura_init_;
  scoped_ptr<WindowTreeHostMojo> window_tree_host_;

  scoped_ptr<wm::ScopedCaptureClient> capture_client_;
  scoped_ptr<aura::client::FocusClient> focus_client_;
  aura::client::ActivationClient* activation_client_;

  Connections connections_;
  NodeIdToWindowMap node_id_to_window_map_;

  DISALLOW_COPY_AND_ASSIGN(WindowManagerApp);
};

}  // namespace mojo

#endif  // MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_