| 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/view_manager/root_view_manager.h" | |
| 6 | |
| 7 #include "base/auto_reset.h" | |
| 8 #include "mojo/aura/screen_mojo.h" | |
| 9 #include "mojo/aura/window_tree_host_mojo.h" | |
| 10 #include "mojo/public/cpp/bindings/allocation_scope.h" | |
| 11 #include "mojo/public/interfaces/shell/shell.mojom.h" | |
| 12 #include "mojo/services/view_manager/root_node_manager.h" | |
| 13 #include "ui/aura/client/default_capture_client.h" | |
| 14 #include "ui/aura/client/window_tree_client.h" | |
| 15 #include "ui/aura/window.h" | |
| 16 | |
| 17 namespace mojo { | |
| 18 namespace services { | |
| 19 namespace view_manager { | |
| 20 | |
| 21 class WindowTreeClientImpl : public aura::client::WindowTreeClient { | |
| 22 public: | |
| 23 explicit WindowTreeClientImpl(aura::Window* window) : window_(window) { | |
| 24 aura::client::SetWindowTreeClient(window_, this); | |
| 25 } | |
| 26 | |
| 27 virtual ~WindowTreeClientImpl() { | |
| 28 aura::client::SetWindowTreeClient(window_, NULL); | |
| 29 } | |
| 30 | |
| 31 // Overridden from aura::client::WindowTreeClient: | |
| 32 virtual aura::Window* GetDefaultParent(aura::Window* context, | |
| 33 aura::Window* window, | |
| 34 const gfx::Rect& bounds) OVERRIDE { | |
| 35 if (!capture_client_) { | |
| 36 capture_client_.reset( | |
| 37 new aura::client::DefaultCaptureClient(window_->GetRootWindow())); | |
| 38 } | |
| 39 return window_; | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 aura::Window* window_; | |
| 44 | |
| 45 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; | |
| 46 | |
| 47 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientImpl); | |
| 48 }; | |
| 49 | |
| 50 RootViewManager::RootViewManager(Shell* shell, RootNodeManager* root_node) | |
| 51 : shell_(shell), | |
| 52 root_node_manager_(root_node), | |
| 53 in_setup_(false) { | |
| 54 screen_.reset(ScreenMojo::Create()); | |
| 55 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); | |
| 56 InterfacePipe<NativeViewport, AnyInterface> pipe; | |
| 57 mojo::AllocationScope scope; | |
| 58 shell_->Connect("mojo:mojo_native_viewport_service", | |
| 59 pipe.handle_to_peer.Pass()); | |
| 60 window_tree_host_.reset(new WindowTreeHostMojo( | |
| 61 pipe.handle_to_self.Pass(), | |
| 62 gfx::Rect(800, 600), | |
| 63 base::Bind(&RootViewManager::OnCompositorCreated, | |
| 64 base::Unretained(this)))); | |
| 65 } | |
| 66 | |
| 67 RootViewManager::~RootViewManager() { | |
| 68 window_tree_client_.reset(); | |
| 69 window_tree_host_.reset(); | |
| 70 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); | |
| 71 } | |
| 72 | |
| 73 void RootViewManager::OnCompositorCreated() { | |
| 74 base::AutoReset<bool> resetter(&in_setup_, true); | |
| 75 window_tree_host_->InitHost(); | |
| 76 | |
| 77 aura::Window* root = root_node_manager_->root()->window(); | |
| 78 window_tree_host_->window()->AddChild(root); | |
| 79 root->SetBounds(gfx::Rect(window_tree_host_->window()->bounds().size())); | |
| 80 root_node_manager_->root()->window()->Show(); | |
| 81 | |
| 82 window_tree_client_.reset( | |
| 83 new WindowTreeClientImpl(window_tree_host_->window())); | |
| 84 | |
| 85 window_tree_host_->Show(); | |
| 86 } | |
| 87 | |
| 88 } // namespace view_manager | |
| 89 } // namespace services | |
| 90 } // namespace mojo | |
| OLD | NEW |