window_manager_app.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// Copyright 2014 The Chromium Authors. All rights reserved.
245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// Use of this source code is governed by a BSD-style license that can be
345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// found in the LICENSE file.
445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "mojo/services/window_manager/window_manager_app.h"
645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "base/message_loop/message_loop.h"
845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "base/stl_util.h"
945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "mojo/aura/aura_init.h"
1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "mojo/aura/window_tree_host_mojo.h"
1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "mojo/public/cpp/application/application_connection.h"
1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "mojo/services/public/cpp/view_manager/node.h"
1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "mojo/services/public/cpp/view_manager/view_manager.h"
1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "ui/aura/window.h"
1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "ui/aura/window_property.h"
1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "ui/wm/core/capture_controller.h"
1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "ui/wm/core/focus_controller.h"
1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "ui/wm/core/focus_rules.h"
1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "ui/wm/public/activation_client.h"
2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgDECLARE_WINDOW_PROPERTY_TYPE(mojo::Node*);
2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgnamespace mojo {
2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgnamespace {
2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgDEFINE_WINDOW_PROPERTY_KEY(Node*, kNodeKey, NULL);
2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgId GetIdForWindow(aura::Window* window) {
2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  return window ? window->GetProperty(kNodeKey)->id() : 0;
3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgclass WMFocusRules : public wm::FocusRules {
3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org public:
3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  WMFocusRules() {}
3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  virtual ~WMFocusRules() {}
3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org private:
3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  // Overridden from wm::FocusRules:
3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  virtual bool IsToplevelWindow(aura::Window* window) const MOJO_OVERRIDE {
4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    return true;
4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  }
4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  virtual bool CanActivateWindow(aura::Window* window) const MOJO_OVERRIDE {
4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    return true;
4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  }
4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  virtual bool CanFocusWindow(aura::Window* window) const MOJO_OVERRIDE {
4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    return true;
4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  }
4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  virtual aura::Window* GetToplevelWindow(
4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org      aura::Window* window) const MOJO_OVERRIDE {
5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    return window;
5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  }
5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  virtual aura::Window* GetActivatableWindow(
5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org      aura::Window* window) const MOJO_OVERRIDE {
5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    return window;
5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  }
5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  virtual aura::Window* GetFocusableWindow(
5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org      aura::Window* window) const MOJO_OVERRIDE {
5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    return window;
5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  }
6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  virtual aura::Window* GetNextActivatableWindow(
6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org      aura::Window* ignore) const MOJO_OVERRIDE {
6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    return NULL;
6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  }
6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  DISALLOW_COPY_AND_ASSIGN(WMFocusRules);
6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org};
6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}  // namespace
6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org////////////////////////////////////////////////////////////////////////////////
7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// WindowManagerApp, public:
7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgWindowManagerApp::WindowManagerApp(ViewManagerDelegate* delegate)
7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    : window_manager_service_factory_(this),
7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org      wrapped_delegate_(delegate),
7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org      view_manager_(NULL),
7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org      view_manager_client_factory_(this),
7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org      root_(NULL) {
7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgWindowManagerApp::~WindowManagerApp() {
8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  // TODO(beng): Figure out if this should be done in
8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  //             OnViewManagerDisconnected().
8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  STLDeleteValues(&node_id_to_window_map_);
8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  if (focus_client_.get())
8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    focus_client_->RemoveObserver(this);
8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  if (activation_client_)
8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    activation_client_->RemoveObserver(this);
8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid WindowManagerApp::AddConnection(WindowManagerServiceImpl* connection) {
9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  DCHECK(connections_.find(connection) == connections_.end());
9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  connections_.insert(connection);
9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid WindowManagerApp::RemoveConnection(WindowManagerServiceImpl* connection) {
9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  DCHECK(connections_.find(connection) != connections_.end());
9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  connections_.erase(connection);
9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgId WindowManagerApp::OpenWindow() {
10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  Node* node = Node::Create(view_manager_);
10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  root_->AddChild(node);
10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  return node->id();
10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgId WindowManagerApp::OpenWindowWithURL(const String& url) {
10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  Node* node = Node::Create(view_manager_);
10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  root_->AddChild(node);
11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  node->Embed(url);
11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  return node->id();
11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid WindowManagerApp::SetCapture(Id node) {
11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  capture_client_->capture_client()->SetCapture(GetWindowForNodeId(node));
11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  // TODO(beng): notify connected clients that capture has changed, probably
11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  //             by implementing some capture-client observer.
11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid WindowManagerApp::FocusWindow(Id node) {
12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  aura::Window* window = GetWindowForNodeId(node);
12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  DCHECK(window);
12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  focus_client_->FocusWindow(window);
12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid WindowManagerApp::ActivateWindow(Id node) {
12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  aura::Window* window = GetWindowForNodeId(node);
12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  DCHECK(window);
12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  activation_client_->ActivateWindow(window);
13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
13245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgbool WindowManagerApp::IsReady() const {
13345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  return view_manager_ && root_;
13445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
13545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
13645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org////////////////////////////////////////////////////////////////////////////////
13745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// WindowManagerApp, ApplicationDelegate implementation:
13845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
13945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid WindowManagerApp::Initialize(ApplicationImpl* impl) {
14045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  aura_init_.reset(new AuraInit);
14145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
14245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
14345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgbool WindowManagerApp::ConfigureIncomingConnection(
14445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ApplicationConnection* connection) {
14545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  connection->AddService(&window_manager_service_factory_);
14645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  connection->AddService(&view_manager_client_factory_);
14745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  return true;
14845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
14945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
15045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org////////////////////////////////////////////////////////////////////////////////
15145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// WindowManagerApp, ViewManagerDelegate implementation:
15245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
15345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid WindowManagerApp::OnEmbed(ViewManager* view_manager, Node* root) {
15445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  DCHECK(!view_manager_ && !root_);
15545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  view_manager_ = view_manager;
15645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  root_ = root;
15745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  root_->AddObserver(this);
15845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
15945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  window_tree_host_.reset(new WindowTreeHostMojo(root_, this));
16045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
16145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  RegisterSubtree(root_->id(), window_tree_host_->window());
16245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
16345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  capture_client_.reset(
16445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org      new wm::ScopedCaptureClient(window_tree_host_->window()));
16545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  wm::FocusController* focus_controller =
16645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org      new wm::FocusController(new WMFocusRules);
16745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  activation_client_ = focus_controller;
16845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  focus_client_.reset(focus_controller);
16945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
17045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  focus_client_->AddObserver(this);
17145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  activation_client_->AddObserver(this);
17245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
17345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  if (wrapped_delegate_)
17445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    wrapped_delegate_->OnEmbed(view_manager, root);
17545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
17645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  for (Connections::const_iterator it = connections_.begin();
17745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org       it != connections_.end(); ++it) {
17845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    (*it)->NotifyReady();
17945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  }
18045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
18145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
18245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid WindowManagerApp::OnViewManagerDisconnected(
18345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ViewManager* view_manager) {
18445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  DCHECK_EQ(view_manager_, view_manager);
18545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  if (wrapped_delegate_)
18645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    wrapped_delegate_->OnViewManagerDisconnected(view_manager);
18745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  root_->RemoveObserver(this);
18845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  root_ = NULL;
18945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  view_manager_ = NULL;
19045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  base::MessageLoop::current()->Quit();
19145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
19245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
19345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org////////////////////////////////////////////////////////////////////////////////
19445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// WindowManagerApp, NodeObserver implementation:
19545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
19645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid WindowManagerApp::OnTreeChanged(
19745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    const NodeObserver::TreeChangeParams& params) {
19845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  DCHECK_EQ(params.receiver, root_);
19945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  DCHECK(params.old_parent || params.new_parent);
20045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  if (!params.target)
20145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    return;
20245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
20345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  if (params.new_parent) {
20445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    if (node_id_to_window_map_.find(params.target->id()) ==
20545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        node_id_to_window_map_.end()) {
20645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org      NodeIdToWindowMap::const_iterator it =
20745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org          node_id_to_window_map_.find(params.new_parent->id());
20845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org      DCHECK(it != node_id_to_window_map_.end());
20945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org      RegisterSubtree(params.target->id(), it->second);
21045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    }
21145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  } else if (params.old_parent) {
21245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    UnregisterSubtree(params.target->id());
21345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  }
21445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
21545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
21645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org////////////////////////////////////////////////////////////////////////////////
21745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// WindowManagerApp, WindowTreeHostMojoDelegate implementation:
21845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
21945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid WindowManagerApp::CompositorContentsChanged(const SkBitmap& bitmap) {
22045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  // We draw nothing.
22145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  NOTREACHED();
22245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
22345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
22445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org////////////////////////////////////////////////////////////////////////////////
22545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// WindowManagerApp, aura::client::FocusChangeObserver implementation:
22645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
22745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid WindowManagerApp::OnWindowFocused(aura::Window* gained_focus,
22845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                       aura::Window* lost_focus) {
22945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  for (Connections::const_iterator it = connections_.begin();
23045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org       it != connections_.end(); ++it) {
23145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    (*it)->NotifyNodeFocused(GetIdForWindow(gained_focus),
23245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                             GetIdForWindow(lost_focus));
23345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  }
23445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
23545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
23645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org////////////////////////////////////////////////////////////////////////////////
23745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// WindowManagerApp, aura::client::ActivationChangeObserver implementation:
23845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
23945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid WindowManagerApp::OnWindowActivated(aura::Window* gained_active,
24045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                         aura::Window* lost_active) {
24145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  for (Connections::const_iterator it = connections_.begin();
24245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org       it != connections_.end(); ++it) {
24345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    (*it)->NotifyWindowActivated(GetIdForWindow(gained_active),
24445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                 GetIdForWindow(lost_active));
24545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org  }
24645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}
24745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
24845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org////////////////////////////////////////////////////////////////////////////////
249// WindowManagerApp, private:
250
251aura::Window* WindowManagerApp::GetWindowForNodeId(
252    Id node) const {
253  NodeIdToWindowMap::const_iterator it = node_id_to_window_map_.find(node);
254  return it != node_id_to_window_map_.end() ? it->second : NULL;
255}
256
257void WindowManagerApp::RegisterSubtree(Id id,
258                                       aura::Window* parent) {
259  Node* node = view_manager_->GetNodeById(id);
260  DCHECK(node_id_to_window_map_.find(id) == node_id_to_window_map_.end());
261  aura::Window* window = new aura::Window(NULL);
262  window->SetProperty(kNodeKey, node);
263  parent->AddChild(window);
264  node_id_to_window_map_[id] = window;
265  Node::Children::const_iterator it = node->children().begin();
266  for (; it != node->children().end(); ++it)
267    RegisterSubtree((*it)->id(), window);
268}
269
270void WindowManagerApp::UnregisterSubtree(Id id) {
271  Node* node = view_manager_->GetNodeById(id);
272  NodeIdToWindowMap::iterator it = node_id_to_window_map_.find(id);
273  DCHECK(it != node_id_to_window_map_.end());
274  scoped_ptr<aura::Window> window(it->second);
275  node_id_to_window_map_.erase(it);
276  Node::Children::const_iterator child = node->children().begin();
277  for (; child != node->children().end(); ++child)
278    UnregisterSubtree((*child)->id());
279}
280
281}  // namespace mojo
282