| OLD | NEW |
| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "mojo/examples/window_manager/window_manager.mojom.h" | 7 #include "mojo/examples/window_manager/window_manager.mojom.h" |
| 8 #include "mojo/public/cpp/application/application.h" | 8 #include "mojo/public/cpp/application/application.h" |
| 9 #include "mojo/services/public/cpp/view_manager/view.h" | 9 #include "mojo/services/public/cpp/view_manager/view.h" |
| 10 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 10 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 11 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 11 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 12 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 12 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 13 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" | 13 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" |
| 14 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
| 15 | 15 |
| 16 #if defined CreateWindow | 16 #if defined CreateWindow |
| 17 #undef CreateWindow | 17 #undef CreateWindow |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 using mojo::view_manager::TransportNodeId; | 20 using mojo::view_manager::Id; |
| 21 using mojo::view_manager::View; | 21 using mojo::view_manager::View; |
| 22 using mojo::view_manager::ViewManager; | 22 using mojo::view_manager::ViewManager; |
| 23 using mojo::view_manager::ViewManagerDelegate; | 23 using mojo::view_manager::ViewManagerDelegate; |
| 24 using mojo::view_manager::ViewObserver; | 24 using mojo::view_manager::ViewObserver; |
| 25 using mojo::view_manager::ViewTreeNode; | 25 using mojo::view_manager::ViewTreeNode; |
| 26 using mojo::view_manager::ViewTreeNodeObserver; | 26 using mojo::view_manager::ViewTreeNodeObserver; |
| 27 | 27 |
| 28 namespace mojo { | 28 namespace mojo { |
| 29 namespace examples { | 29 namespace examples { |
| 30 | 30 |
| 31 class WindowManager; | 31 class WindowManager; |
| 32 | 32 |
| 33 class WindowManagerConnection : public InterfaceImpl<IWindowManager> { | 33 class WindowManagerConnection : public InterfaceImpl<IWindowManager> { |
| 34 public: | 34 public: |
| 35 explicit WindowManagerConnection(WindowManager* window_manager) | 35 explicit WindowManagerConnection(WindowManager* window_manager) |
| 36 : window_manager_(window_manager) {} | 36 : window_manager_(window_manager) {} |
| 37 virtual ~WindowManagerConnection() {} | 37 virtual ~WindowManagerConnection() {} |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 // Overridden from IWindowManager: | 40 // Overridden from IWindowManager: |
| 41 virtual void CloseWindow(TransportNodeId node_id) OVERRIDE; | 41 virtual void CloseWindow(Id node_id) OVERRIDE; |
| 42 | 42 |
| 43 WindowManager* window_manager_; | 43 WindowManager* window_manager_; |
| 44 | 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection); | 45 DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection); |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 class WindowManager : public Application, | 48 class WindowManager : public Application, |
| 49 public ViewObserver, | 49 public ViewObserver, |
| 50 public ViewManagerDelegate { | 50 public ViewManagerDelegate { |
| 51 public: | 51 public: |
| 52 WindowManager() : view_manager_(NULL) {} | 52 WindowManager() : view_manager_(NULL) {} |
| 53 virtual ~WindowManager() {} | 53 virtual ~WindowManager() {} |
| 54 | 54 |
| 55 void CloseWindow(TransportNodeId node_id) { | 55 void CloseWindow(Id node_id) { |
| 56 ViewTreeNode* node = view_manager_->GetNodeById(node_id); | 56 ViewTreeNode* node = view_manager_->GetNodeById(node_id); |
| 57 DCHECK(node); | 57 DCHECK(node); |
| 58 node->Destroy(); | 58 node->Destroy(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 // Overridden from Application: | 62 // Overridden from Application: |
| 63 virtual void Initialize() MOJO_OVERRIDE { | 63 virtual void Initialize() MOJO_OVERRIDE { |
| 64 AddService<WindowManagerConnection>(this); | 64 AddService<WindowManagerConnection>(this); |
| 65 ViewManager::Create(this, this); | 65 ViewManager::Create(this, this); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 bounds.set_origin(position); | 102 bounds.set_origin(position); |
| 103 } | 103 } |
| 104 | 104 |
| 105 ViewTreeNode* embedded = ViewTreeNode::Create(view_manager_); | 105 ViewTreeNode* embedded = ViewTreeNode::Create(view_manager_); |
| 106 node->AddChild(embedded); | 106 node->AddChild(embedded); |
| 107 embedded->SetBounds(bounds); | 107 embedded->SetBounds(bounds); |
| 108 embedded->Embed(url); | 108 embedded->Embed(url); |
| 109 } | 109 } |
| 110 | 110 |
| 111 ViewManager* view_manager_; | 111 ViewManager* view_manager_; |
| 112 TransportNodeId parent_node_id_; | 112 Id parent_node_id_; |
| 113 | 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(WindowManager); | 114 DISALLOW_COPY_AND_ASSIGN(WindowManager); |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 void WindowManagerConnection::CloseWindow(TransportNodeId node_id) { | 117 void WindowManagerConnection::CloseWindow(Id node_id) { |
| 118 window_manager_->CloseWindow(node_id); | 118 window_manager_->CloseWindow(node_id); |
| 119 } | 119 } |
| 120 | 120 |
| 121 } // namespace examples | 121 } // namespace examples |
| 122 | 122 |
| 123 // static | 123 // static |
| 124 Application* Application::Create() { | 124 Application* Application::Create() { |
| 125 return new examples::WindowManager; | 125 return new examples::WindowManager; |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace mojo | 128 } // namespace mojo |
| OLD | NEW |