Chromium Code Reviews| Index: mojo/services/view_manager/root_view_manager.cc |
| diff --git a/mojo/services/view_manager/root_view_manager.cc b/mojo/services/view_manager/root_view_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1ccf1e877ca3d44eee7ed6e7f28e801246ac8a50 |
| --- /dev/null |
| +++ b/mojo/services/view_manager/root_view_manager.cc |
| @@ -0,0 +1,139 @@ |
| +// 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. |
| + |
| +#include "mojo/services/view_manager/root_view_manager.h" |
| + |
| +#include "base/auto_reset.h" |
| +#include "mojo/aura/screen_mojo.h" |
| +#include "mojo/aura/window_tree_host_mojo.h" |
| +#include "mojo/public/cpp/bindings/allocation_scope.h" |
| +#include "mojo/public/interfaces/shell/shell.mojom.h" |
| +#include "mojo/services/view_manager/root_node_manager.h" |
| +#include "ui/aura/client/default_capture_client.h" |
| +#include "ui/aura/client/window_tree_client.h" |
| + |
| +#include "ui/aura/window.h" |
| +#include "ui/aura/window_delegate.h" |
| +#include "ui/base/hit_test.h" |
| +#include "ui/gfx/canvas.h" |
| + |
| +namespace mojo { |
| +namespace services { |
| +namespace view_manager { |
| + |
| +// Trivial WindowDelegate implementation that draws a colored background. |
| +class WindowDelegateImpl : public aura::WindowDelegate { |
|
Ben Goodger (Google)
2014/05/07 17:21:36
this doesn't appear to be used?
sky
2014/05/07 17:33:22
Done.
|
| + public: |
| + explicit WindowDelegateImpl(SkColor color) : color_(color) {} |
| + |
| + // Overridden from WindowDelegate: |
| + virtual gfx::Size GetMinimumSize() const OVERRIDE { |
| + return gfx::Size(); |
| + } |
| + |
| + virtual gfx::Size GetMaximumSize() const OVERRIDE { |
| + return gfx::Size(); |
| + } |
| + |
| + virtual void OnBoundsChanged(const gfx::Rect& old_bounds, |
| + const gfx::Rect& new_bounds) OVERRIDE {} |
| + virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { |
| + return gfx::kNullCursor; |
| + } |
| + virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { |
| + return HTCAPTION; |
| + } |
| + virtual bool ShouldDescendIntoChildForEventHandling( |
| + aura::Window* child, |
| + const gfx::Point& location) OVERRIDE { |
| + return true; |
| + } |
| + virtual bool CanFocus() OVERRIDE { return true; } |
| + virtual void OnCaptureLost() OVERRIDE {} |
| + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| + canvas->DrawColor(color_, SkXfermode::kSrc_Mode); |
| + } |
| + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {} |
| + virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {} |
| + virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {} |
| + virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {} |
| + virtual bool HasHitTestMask() const OVERRIDE { return false; } |
| + virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} |
| + |
| + private: |
| + SkColor color_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WindowDelegateImpl); |
| +}; |
| + |
| +class WindowTreeClientImpl : public aura::client::WindowTreeClient { |
| + public: |
| + explicit WindowTreeClientImpl(aura::Window* window) : window_(window) { |
| + aura::client::SetWindowTreeClient(window_, this); |
| + } |
| + |
| + virtual ~WindowTreeClientImpl() { |
| + aura::client::SetWindowTreeClient(window_, NULL); |
| + } |
| + |
| + // Overridden from aura::client::WindowTreeClient: |
| + virtual aura::Window* GetDefaultParent(aura::Window* context, |
| + aura::Window* window, |
| + const gfx::Rect& bounds) OVERRIDE { |
| + if (!capture_client_) { |
| + capture_client_.reset( |
| + new aura::client::DefaultCaptureClient(window_->GetRootWindow())); |
| + } |
| + return window_; |
| + } |
| + |
| + private: |
| + aura::Window* window_; |
| + |
| + scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WindowTreeClientImpl); |
| +}; |
| + |
| +RootViewManager::RootViewManager(Shell* shell, RootNodeManager* root_node) |
| + : shell_(shell), |
| + root_node_manager_(root_node), |
| + in_setup_(false) { |
| + screen_.reset(ScreenMojo::Create()); |
| + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); |
| + InterfacePipe<NativeViewport, AnyInterface> pipe; |
| + mojo::AllocationScope scope; |
| + shell_->Connect("mojo:mojo_native_viewport_service", |
| + pipe.handle_to_peer.Pass()); |
| + window_tree_host_.reset(new WindowTreeHostMojo( |
| + pipe.handle_to_self.Pass(), |
| + gfx::Rect(800, 600), |
| + base::Bind(&RootViewManager::OnCompositorCreated, |
| + base::Unretained(this)))); |
| +} |
| + |
| +RootViewManager::~RootViewManager() { |
| + window_tree_client_.reset(); |
| + window_tree_host_.reset(); |
| + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); |
| +} |
| + |
| +void RootViewManager::OnCompositorCreated() { |
| + base::AutoReset<bool> resetter(&in_setup_, true); |
| + window_tree_host_->InitHost(); |
| + |
| + aura::Window* root = root_node_manager_->root()->window(); |
| + window_tree_host_->window()->AddChild(root); |
| + root->SetBounds(gfx::Rect(window_tree_host_->window()->bounds().size())); |
| + root_node_manager_->root()->window()->Show(); |
| + |
| + window_tree_client_.reset( |
| + new WindowTreeClientImpl(window_tree_host_->window())); |
| + |
| + window_tree_host_->Show(); |
| +} |
| + |
| +} // namespace view_manager |
| +} // namespace services |
| +} // namespace mojo |