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 gfx::Rect bounds = child_->parent()->bounds(); | |
53 child_->SetBounds(gfx::Rect(0, 0, bounds.width(), bounds.height())); | |
54 } | |
55 } | |
56 | |
57 void RootLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | |
58 DCHECK(!child_); | |
59 child_ = child; | |
60 } | |
61 | |
62 void RootLayoutManager::SetChildBounds(aura::Window* child, | |
63 const gfx::Rect& requested_bounds) { | |
64 SetChildBoundsDirect(child, gfx::Rect(0, 0, | |
Ben Goodger (Google)
2014/07/08 22:08:07
You can replace the second param with this:
gfx::
| |
65 requested_bounds.width(), | |
66 requested_bounds.height())); | |
67 } | |
68 | |
69 //////////////////////////////////////////////////////////////////////////////// | |
28 // WindowTreeHostImpl, public: | 70 // WindowTreeHostImpl, public: |
29 | 71 |
30 WindowTreeHostImpl::WindowTreeHostImpl( | 72 WindowTreeHostImpl::WindowTreeHostImpl( |
31 NativeViewportPtr viewport, | 73 NativeViewportPtr viewport, |
32 const gfx::Rect& bounds, | 74 const gfx::Rect& bounds, |
33 const base::Callback<void()>& compositor_created_callback) | 75 const base::Callback<void()>& compositor_created_callback) |
34 : native_viewport_(viewport.Pass()), | 76 : native_viewport_(viewport.Pass()), |
35 compositor_created_callback_(compositor_created_callback), | 77 compositor_created_callback_(compositor_created_callback), |
36 bounds_(bounds) { | 78 bounds_(bounds) { |
37 native_viewport_.set_client(this); | 79 native_viewport_.set_client(this); |
38 native_viewport_->Create(Rect::From(bounds)); | 80 native_viewport_->Create(Rect::From(bounds)); |
39 | 81 |
40 MessagePipe pipe; | 82 MessagePipe pipe; |
41 native_viewport_->CreateGLES2Context( | 83 native_viewport_->CreateGLES2Context( |
42 MakeRequest<CommandBuffer>(pipe.handle0.Pass())); | 84 MakeRequest<CommandBuffer>(pipe.handle0.Pass())); |
43 | 85 |
44 // The ContextFactory must exist before any Compositors are created. | 86 // The ContextFactory must exist before any Compositors are created. |
45 if (context_factory_) { | 87 if (context_factory_) { |
46 delete context_factory_; | 88 delete context_factory_; |
47 context_factory_ = NULL; | 89 context_factory_ = NULL; |
48 } | 90 } |
49 context_factory_ = new ContextFactoryImpl(pipe.handle1.Pass()); | 91 context_factory_ = new ContextFactoryImpl(pipe.handle1.Pass()); |
50 aura::Env::GetInstance()->set_context_factory(context_factory_); | 92 aura::Env::GetInstance()->set_context_factory(context_factory_); |
93 | |
94 window()->SetLayoutManager(new RootLayoutManager()); | |
51 } | 95 } |
52 | 96 |
53 WindowTreeHostImpl::~WindowTreeHostImpl() { | 97 WindowTreeHostImpl::~WindowTreeHostImpl() { |
54 DestroyCompositor(); | 98 DestroyCompositor(); |
55 DestroyDispatcher(); | 99 DestroyDispatcher(); |
56 } | 100 } |
57 | 101 |
58 //////////////////////////////////////////////////////////////////////////////// | 102 //////////////////////////////////////////////////////////////////////////////// |
59 // WindowTreeHostImpl, aura::WindowTreeHost implementation: | 103 // WindowTreeHostImpl, aura::WindowTreeHost implementation: |
60 | 104 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 break; | 219 break; |
176 } | 220 } |
177 // TODO(beng): touch, etc. | 221 // TODO(beng): touch, etc. |
178 } | 222 } |
179 callback.Run(); | 223 callback.Run(); |
180 }; | 224 }; |
181 | 225 |
182 } // namespace service | 226 } // namespace service |
183 } // namespace view_manager | 227 } // namespace view_manager |
184 } // namespace mojo | 228 } // namespace mojo |
OLD | NEW |