OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/services/window_manager/window_manager_app.h" |
| 6 |
| 7 #include "base/message_loop/message_loop.h" |
| 8 #include "mojo/aura/aura_init.h" |
| 9 #include "mojo/aura/window_tree_host_mojo.h" |
| 10 #include "mojo/public/cpp/application/application_connection.h" |
| 11 #include "mojo/services/public/cpp/view_manager/node.h" |
| 12 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 13 #include "mojo/services/window_manager/window_manager_service_impl.h" |
| 14 #include "ui/wm/core/capture_controller.h" |
| 15 |
| 16 namespace mojo { |
| 17 |
| 18 //////////////////////////////////////////////////////////////////////////////// |
| 19 // WindowManagerApp, public: |
| 20 |
| 21 WindowManagerApp::WindowManagerApp() : view_manager_(NULL), root_(NULL) {} |
| 22 WindowManagerApp::~WindowManagerApp() {} |
| 23 |
| 24 void WindowManagerApp::AddConnection(WindowManagerServiceImpl* connection) { |
| 25 DCHECK(connections_.find(connection) == connections_.end()); |
| 26 connections_.insert(connection); |
| 27 } |
| 28 |
| 29 void WindowManagerApp::RemoveConnection(WindowManagerServiceImpl* connection) { |
| 30 DCHECK(connections_.find(connection) != connections_.end()); |
| 31 connections_.erase(connection); |
| 32 } |
| 33 |
| 34 view_manager::Id WindowManagerApp::OpenWindow() { |
| 35 view_manager::Node* node = view_manager::Node::Create(view_manager_); |
| 36 root_->AddChild(node); |
| 37 return node->id(); |
| 38 } |
| 39 |
| 40 void WindowManagerApp::SetCapture(view_manager::Id node) { |
| 41 capture_client_->capture_client()->SetCapture(GetWindowForNodeId(node)); |
| 42 // TODO(beng): notify connected clients that capture has changed, probably |
| 43 // by implementing some capture-client observer. |
| 44 } |
| 45 |
| 46 bool WindowManagerApp::IsReady() const { |
| 47 return view_manager_ && root_; |
| 48 } |
| 49 |
| 50 //////////////////////////////////////////////////////////////////////////////// |
| 51 // WindowManagerApp, ApplicationDelegate implementation: |
| 52 |
| 53 void WindowManagerApp::Initialize(ApplicationImpl* impl) { |
| 54 aura_init_.reset(new AuraInit); |
| 55 } |
| 56 |
| 57 bool WindowManagerApp::ConfigureIncomingConnection( |
| 58 ApplicationConnection* connection) { |
| 59 connection->AddService<WindowManagerServiceImpl>(this); |
| 60 view_manager::ViewManager::ConfigureIncomingConnection(connection, this); |
| 61 return true; |
| 62 } |
| 63 |
| 64 //////////////////////////////////////////////////////////////////////////////// |
| 65 // WindowManagerApp, view_manager::ViewManagerDelegate implementation: |
| 66 |
| 67 void WindowManagerApp::OnRootAdded(view_manager::ViewManager* view_manager, |
| 68 view_manager::Node* root) { |
| 69 DCHECK(!view_manager_ && !root_); |
| 70 view_manager_ = view_manager; |
| 71 root_ = root; |
| 72 |
| 73 window_tree_host_.reset(new WindowTreeHostMojo(root_, this)); |
| 74 |
| 75 capture_client_.reset( |
| 76 new wm::ScopedCaptureClient(window_tree_host_->window())); |
| 77 |
| 78 // TODO(beng): Create the universe. |
| 79 |
| 80 for (Connections::const_iterator it = connections_.begin(); |
| 81 it != connections_.end(); ++it) { |
| 82 (*it)->NotifyReady(); |
| 83 } |
| 84 } |
| 85 |
| 86 void WindowManagerApp::OnViewManagerDisconnected( |
| 87 view_manager::ViewManager* view_manager) { |
| 88 DCHECK_EQ(view_manager_, view_manager); |
| 89 view_manager_ = NULL; |
| 90 base::MessageLoop::current()->Quit(); |
| 91 } |
| 92 |
| 93 //////////////////////////////////////////////////////////////////////////////// |
| 94 // WindowManagerApp, WindowTreeHostMojoDelegate implementation: |
| 95 |
| 96 void WindowManagerApp::CompositorContentsChanged(const SkBitmap& bitmap) { |
| 97 // We draw nothing. |
| 98 NOTREACHED(); |
| 99 } |
| 100 |
| 101 //////////////////////////////////////////////////////////////////////////////// |
| 102 // WindowManagerApp, private: |
| 103 |
| 104 aura::Window* WindowManagerApp::GetWindowForNodeId( |
| 105 view_manager::Id node) const { |
| 106 NOTIMPLEMENTED(); |
| 107 return NULL; |
| 108 } |
| 109 |
| 110 //////////////////////////////////////////////////////////////////////////////// |
| 111 // ApplicationDelegate, public: |
| 112 |
| 113 // static |
| 114 ApplicationDelegate* ApplicationDelegate::Create() { |
| 115 return new WindowManagerApp; |
| 116 } |
| 117 |
| 118 } // namespace mojo |
OLD | NEW |