OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_node_manager.h" |
5 #include "mojo/services/view_manager/window_tree_host_impl.h" | 6 #include "mojo/services/view_manager/window_tree_host_impl.h" |
6 | |
7 #include "mojo/public/c/gles2/gles2.h" | 7 #include "mojo/public/c/gles2/gles2.h" |
8 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 8 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
9 #include "mojo/services/view_manager/context_factory_impl.h" | 9 #include "mojo/services/view_manager/context_factory_impl.h" |
10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
| 11 #include "ui/aura/layout_manager.h" |
11 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
12 #include "ui/aura/window_event_dispatcher.h" | 13 #include "ui/aura/window_event_dispatcher.h" |
13 #include "ui/compositor/compositor.h" | 14 #include "ui/compositor/compositor.h" |
14 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
15 #include "ui/events/event_constants.h" | 16 #include "ui/events/event_constants.h" |
16 #include "ui/gfx/geometry/insets.h" | 17 #include "ui/gfx/geometry/insets.h" |
17 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
18 | 19 |
19 namespace mojo { | 20 namespace mojo { |
20 namespace view_manager { | 21 namespace view_manager { |
21 namespace service { | 22 namespace service { |
22 | 23 |
23 // TODO(sky): nuke this. It shouldn't be static. | 24 // TODO(sky): nuke this. It shouldn't be static. |
24 // static | 25 // static |
25 ContextFactoryImpl* WindowTreeHostImpl::context_factory_ = NULL; | 26 ContextFactoryImpl* WindowTreeHostImpl::context_factory_ = NULL; |
26 | 27 |
27 //////////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////////// |
| 29 // RootLayoutManager, layout management for the root window's (one) child |
| 30 |
| 31 class RootLayoutManager : public aura::LayoutManager { |
| 32 public: |
| 33 RootLayoutManager() : child_(NULL) {} |
| 34 |
| 35 // Overridden from aura::LayoutManager |
| 36 virtual void OnWindowResized() OVERRIDE; |
| 37 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; |
| 38 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
| 39 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} |
| 40 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 41 bool visible) OVERRIDE {} |
| 42 virtual void SetChildBounds(aura::Window* child, |
| 43 const gfx::Rect& requested_bounds) OVERRIDE; |
| 44 private: |
| 45 aura::Window* child_; |
| 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); |
| 48 }; |
| 49 |
| 50 void RootLayoutManager::OnWindowResized() { |
| 51 if (child_) |
| 52 child_->SetBounds(gfx::Rect(child_->parent()->bounds().size())); |
| 53 } |
| 54 |
| 55 void RootLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 56 DCHECK(!child_); |
| 57 child_ = child; |
| 58 } |
| 59 |
| 60 void RootLayoutManager::SetChildBounds(aura::Window* child, |
| 61 const gfx::Rect& requested_bounds) { |
| 62 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); |
| 63 } |
| 64 |
| 65 //////////////////////////////////////////////////////////////////////////////// |
28 // WindowTreeHostImpl, public: | 66 // WindowTreeHostImpl, public: |
29 | 67 |
30 WindowTreeHostImpl::WindowTreeHostImpl( | 68 WindowTreeHostImpl::WindowTreeHostImpl( |
31 NativeViewportPtr viewport, | 69 NativeViewportPtr viewport, |
32 const gfx::Rect& bounds, | 70 const gfx::Rect& bounds, |
33 const base::Callback<void()>& compositor_created_callback) | 71 const base::Callback<void()>& compositor_created_callback) |
34 : native_viewport_(viewport.Pass()), | 72 : native_viewport_(viewport.Pass()), |
35 compositor_created_callback_(compositor_created_callback), | 73 compositor_created_callback_(compositor_created_callback), |
36 bounds_(bounds) { | 74 bounds_(bounds) { |
37 native_viewport_.set_client(this); | 75 native_viewport_.set_client(this); |
38 native_viewport_->Create(Rect::From(bounds)); | 76 native_viewport_->Create(Rect::From(bounds)); |
39 | 77 |
40 MessagePipe pipe; | 78 MessagePipe pipe; |
41 native_viewport_->CreateGLES2Context( | 79 native_viewport_->CreateGLES2Context( |
42 MakeRequest<CommandBuffer>(pipe.handle0.Pass())); | 80 MakeRequest<CommandBuffer>(pipe.handle0.Pass())); |
43 | 81 |
44 // The ContextFactory must exist before any Compositors are created. | 82 // The ContextFactory must exist before any Compositors are created. |
45 if (context_factory_) { | 83 if (context_factory_) { |
46 delete context_factory_; | 84 delete context_factory_; |
47 context_factory_ = NULL; | 85 context_factory_ = NULL; |
48 } | 86 } |
49 context_factory_ = new ContextFactoryImpl(pipe.handle1.Pass()); | 87 context_factory_ = new ContextFactoryImpl(pipe.handle1.Pass()); |
50 aura::Env::GetInstance()->set_context_factory(context_factory_); | 88 aura::Env::GetInstance()->set_context_factory(context_factory_); |
| 89 |
| 90 window()->SetLayoutManager(new RootLayoutManager()); |
51 } | 91 } |
52 | 92 |
53 WindowTreeHostImpl::~WindowTreeHostImpl() { | 93 WindowTreeHostImpl::~WindowTreeHostImpl() { |
54 DestroyCompositor(); | 94 DestroyCompositor(); |
55 DestroyDispatcher(); | 95 DestroyDispatcher(); |
56 } | 96 } |
57 | 97 |
58 //////////////////////////////////////////////////////////////////////////////// | 98 //////////////////////////////////////////////////////////////////////////////// |
59 // WindowTreeHostImpl, aura::WindowTreeHost implementation: | 99 // WindowTreeHostImpl, aura::WindowTreeHost implementation: |
60 | 100 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 break; | 215 break; |
176 } | 216 } |
177 // TODO(beng): touch, etc. | 217 // TODO(beng): touch, etc. |
178 } | 218 } |
179 callback.Run(); | 219 callback.Run(); |
180 }; | 220 }; |
181 | 221 |
182 } // namespace service | 222 } // namespace service |
183 } // namespace view_manager | 223 } // namespace view_manager |
184 } // namespace mojo | 224 } // namespace mojo |
OLD | NEW |