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

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

Issue 507563002: Removes usage of aura::Window from Node (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: conditional Created 6 years, 4 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
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 "mojo/services/view_manager/root_view_manager.h" 5 #include "mojo/services/view_manager/root_view_manager.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/scoped_observer.h" 8 #include "base/scoped_observer.h"
9 #include "mojo/public/cpp/application/application_connection.h" 9 #include "mojo/public/cpp/application/application_connection.h"
10 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h" 10 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h"
11 #include "mojo/services/view_manager/root_node_manager.h" 11 #include "mojo/services/view_manager/root_node_manager.h"
12 #include "mojo/services/view_manager/root_view_manager_delegate.h" 12 #include "mojo/services/view_manager/root_view_manager_delegate.h"
13 #include "mojo/services/view_manager/screen_impl.h" 13 #include "mojo/services/view_manager/screen_impl.h"
14 #include "mojo/services/view_manager/window_tree_host_impl.h" 14 #include "mojo/services/view_manager/window_tree_host_impl.h"
15 #include "ui/aura/client/default_capture_client.h" 15 #include "ui/aura/client/default_capture_client.h"
16 #include "ui/aura/client/focus_client.h" 16 #include "ui/aura/client/focus_client.h"
17 #include "ui/aura/client/window_tree_client.h" 17 #include "ui/aura/client/window_tree_client.h"
18 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
19 #include "ui/aura/window_observer.h" 19 #include "ui/aura/window_delegate.h"
20 #include "ui/base/cursor/cursor.h"
21 #include "ui/base/hit_test.h"
22 #include "ui/compositor/layer.h"
23 #include "ui/gfx/canvas.h"
24 #include "ui/gfx/image/image_skia.h"
25 #include "ui/gfx/native_widget_types.h"
20 26
21 namespace mojo { 27 namespace mojo {
22 namespace service { 28 namespace service {
29 namespace {
30
31 gfx::Rect ConvertRectToRoot(const Node* node, const gfx::Rect& bounds) {
32 gfx::Point origin(bounds.origin());
33 while (node->parent()) {
34 origin += node->bounds().OffsetFromOrigin();
35 node = node->parent();
36 }
37 return gfx::Rect(origin, bounds.size());
38 }
39
40 void PaintNodeTree(gfx::Canvas* canvas,
41 const Node* node,
42 const gfx::Point& origin) {
43 if (!node->visible())
44 return;
45
46 canvas->DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(node->bitmap()),
47 origin.x(), origin.y());
48 std::vector<const Node*> children(node->GetChildren());
49 for (size_t i = 0; i < children.size(); ++i) {
50 PaintNodeTree(canvas, children[i],
51 origin + children[i]->bounds().OffsetFromOrigin());
52 }
53 }
54
55 } // namespace
56
57 class RootViewManager::RootWindowDelegateImpl : public aura::WindowDelegate {
58 public:
59 explicit RootWindowDelegateImpl(const Node* root_node)
60 : root_node_(root_node) {}
61 virtual ~RootWindowDelegateImpl() {}
62
63 // aura::WindowDelegate:
64 virtual gfx::Size GetMinimumSize() const OVERRIDE {
65 return gfx::Size();
66 }
67 virtual gfx::Size GetMaximumSize() const OVERRIDE {
68 return gfx::Size();
69 }
70 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
71 const gfx::Rect& new_bounds) OVERRIDE {
72 }
73 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
74 return gfx::kNullCursor;
75 }
76 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
77 return HTCAPTION;
78 }
79 virtual bool ShouldDescendIntoChildForEventHandling(
80 aura::Window* child,
81 const gfx::Point& location) OVERRIDE {
82 return true;
83 }
84 virtual bool CanFocus() OVERRIDE {
85 return true;
86 }
87 virtual void OnCaptureLost() OVERRIDE {
88 }
89 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
90 PaintNodeTree(canvas, root_node_, gfx::Point());
91 }
92 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {
93 }
94 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
95 }
96 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {
97 }
98 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {
99 }
100 virtual bool HasHitTestMask() const OVERRIDE {
101 return false;
102 }
103 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {
104 }
105
106 private:
107 const Node* root_node_;
108
109 DISALLOW_COPY_AND_ASSIGN(RootWindowDelegateImpl);
110 };
23 111
24 // TODO(sky): Remove once aura is removed from the service. 112 // TODO(sky): Remove once aura is removed from the service.
25 class FocusClientImpl : public aura::client::FocusClient { 113 class FocusClientImpl : public aura::client::FocusClient {
26 public: 114 public:
27 FocusClientImpl() {} 115 FocusClientImpl() {}
28 virtual ~FocusClientImpl() {} 116 virtual ~FocusClientImpl() {}
29 117
30 private: 118 private:
31 // Overridden from aura::client::FocusClient: 119 // Overridden from aura::client::FocusClient:
32 virtual void AddObserver( 120 virtual void AddObserver(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientImpl); 157 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientImpl);
70 }; 158 };
71 159
72 RootViewManager::RootViewManager( 160 RootViewManager::RootViewManager(
73 ApplicationConnection* app_connection, 161 ApplicationConnection* app_connection,
74 RootNodeManager* root_node, 162 RootNodeManager* root_node,
75 RootViewManagerDelegate* delegate, 163 RootViewManagerDelegate* delegate,
76 const Callback<void()>& native_viewport_closed_callback) 164 const Callback<void()>& native_viewport_closed_callback)
77 : delegate_(delegate), 165 : delegate_(delegate),
78 root_node_manager_(root_node), 166 root_node_manager_(root_node),
79 in_setup_(false) { 167 in_setup_(false),
168 root_window_(NULL) {
80 screen_.reset(ScreenImpl::Create()); 169 screen_.reset(ScreenImpl::Create());
81 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); 170 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
82 NativeViewportPtr viewport; 171 NativeViewportPtr viewport;
83 app_connection->ConnectToService( 172 app_connection->ConnectToService(
84 "mojo:mojo_native_viewport_service", &viewport); 173 "mojo:mojo_native_viewport_service", &viewport);
85 GpuPtr gpu_service; 174 GpuPtr gpu_service;
86 // TODO(jamesr): Should be mojo:mojo_gpu_service 175 // TODO(jamesr): Should be mojo:mojo_gpu_service
87 app_connection->ConnectToService("mojo:mojo_native_viewport_service", 176 app_connection->ConnectToService("mojo:mojo_native_viewport_service",
88 &gpu_service); 177 &gpu_service);
89 window_tree_host_.reset(new WindowTreeHostImpl( 178 window_tree_host_.reset(new WindowTreeHostImpl(
90 viewport.Pass(), 179 viewport.Pass(),
91 gpu_service.Pass(), 180 gpu_service.Pass(),
92 gfx::Rect(800, 600), 181 gfx::Rect(800, 600),
93 base::Bind(&RootViewManager::OnCompositorCreated, base::Unretained(this)), 182 base::Bind(&RootViewManager::OnCompositorCreated, base::Unretained(this)),
94 native_viewport_closed_callback, 183 native_viewport_closed_callback,
95 base::Bind(&RootNodeManager::DispatchNodeInputEventToWindowManager, 184 base::Bind(&RootNodeManager::DispatchNodeInputEventToWindowManager,
96 base::Unretained(root_node_manager_)))); 185 base::Unretained(root_node_manager_))));
97 } 186 }
98 187
99 RootViewManager::~RootViewManager() { 188 RootViewManager::~RootViewManager() {
100 window_tree_client_.reset(); 189 window_tree_client_.reset();
101 window_tree_host_.reset(); 190 window_tree_host_.reset();
102 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL); 191 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
103 } 192 }
104 193
194 void RootViewManager::SchedulePaint(const Node* node, const gfx::Rect& bounds) {
195 if (root_window_)
196 root_window_->SchedulePaintInRect(ConvertRectToRoot(node, bounds));
197 }
198
105 void RootViewManager::OnCompositorCreated() { 199 void RootViewManager::OnCompositorCreated() {
106 base::AutoReset<bool> resetter(&in_setup_, true); 200 base::AutoReset<bool> resetter(&in_setup_, true);
107 window_tree_host_->InitHost(); 201 window_tree_host_->InitHost();
108 202
109 aura::Window* root = root_node_manager_->root()->window(); 203 window_delegate_.reset(
110 window_tree_host_->window()->AddChild(root); 204 new RootWindowDelegateImpl(root_node_manager_->root()));
111 root->SetBounds(gfx::Rect(window_tree_host_->window()->bounds().size())); 205 root_window_ = new aura::Window(window_delegate_.get());
112 root_node_manager_->root()->window()->Show(); 206 root_window_->Init(aura::WINDOW_LAYER_TEXTURED);
207 root_window_->Show();
208 root_window_->SetBounds(
209 gfx::Rect(window_tree_host_->window()->bounds().size()));
210 window_tree_host_->window()->AddChild(root_window_);
211
212 root_node_manager_->root()->SetBounds(
213 gfx::Rect(window_tree_host_->window()->bounds().size()));
113 214
114 window_tree_client_.reset( 215 window_tree_client_.reset(
115 new WindowTreeClientImpl(window_tree_host_->window())); 216 new WindowTreeClientImpl(window_tree_host_->window()));
116 217
117 focus_client_.reset(new FocusClientImpl); 218 focus_client_.reset(new FocusClientImpl);
118 aura::client::SetFocusClient(window_tree_host_->window(), 219 aura::client::SetFocusClient(window_tree_host_->window(),
119 focus_client_.get()); 220 focus_client_.get());
120 221
121 window_tree_host_->Show(); 222 window_tree_host_->Show();
122 223
123 delegate_->OnRootViewManagerWindowTreeHostCreated(); 224 delegate_->OnRootViewManagerWindowTreeHostCreated();
124 } 225 }
125 226
126 } // namespace service 227 } // namespace service
127 } // namespace mojo 228 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698