Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(833)

Side by Side Diff: mojo/services/view_manager/root_view_manager.cc

Issue 267293004: Wires up view manager to an actual display (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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
16 #include "ui/aura/window.h"
17 #include "ui/aura/window_delegate.h"
18 #include "ui/base/hit_test.h"
19 #include "ui/gfx/canvas.h"
20
21 namespace mojo {
22 namespace services {
23 namespace view_manager {
24
25 // Trivial WindowDelegate implementation that draws a colored background.
26 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.
27 public:
28 explicit WindowDelegateImpl(SkColor color) : color_(color) {}
29
30 // Overridden from WindowDelegate:
31 virtual gfx::Size GetMinimumSize() const OVERRIDE {
32 return gfx::Size();
33 }
34
35 virtual gfx::Size GetMaximumSize() const OVERRIDE {
36 return gfx::Size();
37 }
38
39 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
40 const gfx::Rect& new_bounds) OVERRIDE {}
41 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
42 return gfx::kNullCursor;
43 }
44 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
45 return HTCAPTION;
46 }
47 virtual bool ShouldDescendIntoChildForEventHandling(
48 aura::Window* child,
49 const gfx::Point& location) OVERRIDE {
50 return true;
51 }
52 virtual bool CanFocus() OVERRIDE { return true; }
53 virtual void OnCaptureLost() OVERRIDE {}
54 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
55 canvas->DrawColor(color_, SkXfermode::kSrc_Mode);
56 }
57 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {}
58 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {}
59 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {}
60 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {}
61 virtual bool HasHitTestMask() const OVERRIDE { return false; }
62 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {}
63
64 private:
65 SkColor color_;
66
67 DISALLOW_COPY_AND_ASSIGN(WindowDelegateImpl);
68 };
69
70 class WindowTreeClientImpl : public aura::client::WindowTreeClient {
71 public:
72 explicit WindowTreeClientImpl(aura::Window* window) : window_(window) {
73 aura::client::SetWindowTreeClient(window_, this);
74 }
75
76 virtual ~WindowTreeClientImpl() {
77 aura::client::SetWindowTreeClient(window_, NULL);
78 }
79
80 // Overridden from aura::client::WindowTreeClient:
81 virtual aura::Window* GetDefaultParent(aura::Window* context,
82 aura::Window* window,
83 const gfx::Rect& bounds) OVERRIDE {
84 if (!capture_client_) {
85 capture_client_.reset(
86 new aura::client::DefaultCaptureClient(window_->GetRootWindow()));
87 }
88 return window_;
89 }
90
91 private:
92 aura::Window* window_;
93
94 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_;
95
96 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientImpl);
97 };
98
99 RootViewManager::RootViewManager(Shell* shell, RootNodeManager* root_node)
100 : shell_(shell),
101 root_node_manager_(root_node),
102 in_setup_(false) {
103 screen_.reset(ScreenMojo::Create());
104 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
105 InterfacePipe<NativeViewport, AnyInterface> pipe;
106 mojo::AllocationScope scope;
107 shell_->Connect("mojo:mojo_native_viewport_service",
108 pipe.handle_to_peer.Pass());
109 window_tree_host_.reset(new WindowTreeHostMojo(
110 pipe.handle_to_self.Pass(),
111 gfx::Rect(800, 600),
112 base::Bind(&RootViewManager::OnCompositorCreated,
113 base::Unretained(this))));
114 }
115
116 RootViewManager::~RootViewManager() {
117 window_tree_client_.reset();
118 window_tree_host_.reset();
119 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
120 }
121
122 void RootViewManager::OnCompositorCreated() {
123 base::AutoReset<bool> resetter(&in_setup_, true);
124 window_tree_host_->InitHost();
125
126 aura::Window* root = root_node_manager_->root()->window();
127 window_tree_host_->window()->AddChild(root);
128 root->SetBounds(gfx::Rect(window_tree_host_->window()->bounds().size()));
129 root_node_manager_->root()->window()->Show();
130
131 window_tree_client_.reset(
132 new WindowTreeClientImpl(window_tree_host_->window()));
133
134 window_tree_host_->Show();
135 }
136
137 } // namespace view_manager
138 } // namespace services
139 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698