Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 5 | #include "mojo/services/view_manager/root_node_manager.h" |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 6 | #include "mojo/services/view_manager/window_tree_host_impl.h" |
Ben Murdoch | 4ad1aa4 | 2014-04-01 10:55:12 +0100 | [diff] [blame] | 7 | #include "mojo/public/c/gles2/gles2.h" |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 8 | #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 9 | #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 10 | #include "mojo/services/view_manager/context_factory_impl.h" |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 11 | #include "ui/aura/env.h" |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 12 | #include "ui/aura/layout_manager.h" |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 13 | #include "ui/aura/window.h" |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 14 | #include "ui/aura/window_event_dispatcher.h" |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 15 | #include "ui/compositor/compositor.h" |
| 16 | #include "ui/events/event.h" |
| 17 | #include "ui/events/event_constants.h" |
| 18 | #include "ui/gfx/geometry/insets.h" |
| 19 | #include "ui/gfx/geometry/rect.h" |
| 20 | |
| 21 | namespace mojo { |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 22 | namespace service { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 23 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 24 | // TODO(sky): nuke this. It shouldn't be static. |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 25 | // static |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 26 | ContextFactoryImpl* WindowTreeHostImpl::context_factory_ = NULL; |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 27 | |
| 28 | //////////////////////////////////////////////////////////////////////////////// |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 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 | //////////////////////////////////////////////////////////////////////////////// |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 66 | // WindowTreeHostImpl, public: |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 67 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 68 | WindowTreeHostImpl::WindowTreeHostImpl( |
Torne (Richard Coles) | 0de6073 | 2014-05-15 12:16:31 +0100 | [diff] [blame] | 69 | NativeViewportPtr viewport, |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 70 | const gfx::Rect& bounds, |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 71 | const Callback<void()>& compositor_created_callback, |
Torne (Richard Coles) | 6e8cce6 | 2014-08-19 13:00:08 +0100 | [diff] [blame^] | 72 | const Callback<void()>& native_viewport_closed_callback, |
| 73 | const Callback<void(EventPtr)>& event_received_callback) |
Torne (Richard Coles) | 0de6073 | 2014-05-15 12:16:31 +0100 | [diff] [blame] | 74 | : native_viewport_(viewport.Pass()), |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 75 | compositor_created_callback_(compositor_created_callback), |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 76 | native_viewport_closed_callback_(native_viewport_closed_callback), |
Torne (Richard Coles) | 6e8cce6 | 2014-08-19 13:00:08 +0100 | [diff] [blame^] | 77 | event_received_callback_(event_received_callback), |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 78 | bounds_(bounds) { |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 79 | native_viewport_.set_client(this); |
| 80 | native_viewport_->Create(Rect::From(bounds)); |
Torne (Richard Coles) | 0de6073 | 2014-05-15 12:16:31 +0100 | [diff] [blame] | 81 | |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 82 | MessagePipe pipe; |
| 83 | native_viewport_->CreateGLES2Context( |
| 84 | MakeRequest<CommandBuffer>(pipe.handle0.Pass())); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 85 | |
| 86 | // The ContextFactory must exist before any Compositors are created. |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 87 | if (context_factory_) { |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 88 | delete context_factory_; |
| 89 | context_factory_ = NULL; |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 90 | } |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 91 | context_factory_ = new ContextFactoryImpl(pipe.handle1.Pass()); |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 92 | aura::Env::GetInstance()->set_context_factory(context_factory_); |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 93 | |
| 94 | window()->SetLayoutManager(new RootLayoutManager()); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 97 | WindowTreeHostImpl::~WindowTreeHostImpl() { |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 98 | DestroyCompositor(); |
| 99 | DestroyDispatcher(); |
| 100 | } |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 101 | |
| 102 | //////////////////////////////////////////////////////////////////////////////// |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 103 | // WindowTreeHostImpl, aura::WindowTreeHost implementation: |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 104 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 105 | ui::EventSource* WindowTreeHostImpl::GetEventSource() { |
Bo Liu | 5c02ac1 | 2014-05-01 10:37:37 -0700 | [diff] [blame] | 106 | return this; |
| 107 | } |
| 108 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 109 | gfx::AcceleratedWidget WindowTreeHostImpl::GetAcceleratedWidget() { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 110 | NOTIMPLEMENTED() << "GetAcceleratedWidget"; |
| 111 | return gfx::kNullAcceleratedWidget; |
| 112 | } |
| 113 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 114 | void WindowTreeHostImpl::Show() { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 115 | window()->Show(); |
| 116 | native_viewport_->Show(); |
| 117 | } |
| 118 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 119 | void WindowTreeHostImpl::Hide() { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 120 | native_viewport_->Hide(); |
| 121 | window()->Hide(); |
| 122 | } |
| 123 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 124 | gfx::Rect WindowTreeHostImpl::GetBounds() const { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 125 | return bounds_; |
| 126 | } |
| 127 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 128 | void WindowTreeHostImpl::SetBounds(const gfx::Rect& bounds) { |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 129 | native_viewport_->SetBounds(Rect::From(bounds)); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 132 | gfx::Point WindowTreeHostImpl::GetLocationOnNativeScreen() const { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 133 | return gfx::Point(0, 0); |
| 134 | } |
| 135 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 136 | void WindowTreeHostImpl::SetCapture() { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 137 | NOTIMPLEMENTED(); |
| 138 | } |
| 139 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 140 | void WindowTreeHostImpl::ReleaseCapture() { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 141 | NOTIMPLEMENTED(); |
| 142 | } |
| 143 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 144 | void WindowTreeHostImpl::PostNativeEvent( |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 145 | const base::NativeEvent& native_event) { |
| 146 | NOTIMPLEMENTED(); |
| 147 | } |
| 148 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 149 | void WindowTreeHostImpl::SetCursorNative(gfx::NativeCursor cursor) { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 150 | NOTIMPLEMENTED(); |
| 151 | } |
| 152 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 153 | void WindowTreeHostImpl::MoveCursorToNative(const gfx::Point& location) { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 154 | NOTIMPLEMENTED(); |
| 155 | } |
| 156 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 157 | void WindowTreeHostImpl::OnCursorVisibilityChangedNative(bool show) { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 158 | NOTIMPLEMENTED(); |
| 159 | } |
| 160 | |
| 161 | //////////////////////////////////////////////////////////////////////////////// |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 162 | // WindowTreeHostImpl, ui::EventSource implementation: |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 163 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 164 | ui::EventProcessor* WindowTreeHostImpl::GetEventProcessor() { |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 165 | return dispatcher(); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | //////////////////////////////////////////////////////////////////////////////// |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 169 | // WindowTreeHostImpl, NativeViewportClient implementation: |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 170 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 171 | void WindowTreeHostImpl::OnCreated() { |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 172 | CreateCompositor(GetAcceleratedWidget()); |
| 173 | compositor_created_callback_.Run(); |
| 174 | } |
| 175 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 176 | void WindowTreeHostImpl::OnBoundsChanged(RectPtr bounds) { |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 177 | bounds_ = bounds.To<gfx::Rect>(); |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 178 | OnHostResized(bounds_.size()); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Ben Murdoch | 116680a | 2014-07-20 18:25:52 -0700 | [diff] [blame] | 181 | void WindowTreeHostImpl::OnDestroyed(const mojo::Callback<void()>& callback) { |
| 182 | DestroyCompositor(); |
| 183 | native_viewport_closed_callback_.Run(); |
| 184 | // TODO(beng): quit the message loop once we are on our own thread. |
| 185 | callback.Run(); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 188 | void WindowTreeHostImpl::OnEvent(EventPtr event, |
Ben Murdoch | e5d81f5 | 2014-04-03 12:29:45 +0100 | [diff] [blame] | 189 | const mojo::Callback<void()>& callback) { |
Torne (Richard Coles) | 6e8cce6 | 2014-08-19 13:00:08 +0100 | [diff] [blame^] | 190 | event_received_callback_.Run(event.Pass()); |
Ben Murdoch | e5d81f5 | 2014-04-03 12:29:45 +0100 | [diff] [blame] | 191 | callback.Run(); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 192 | }; |
| 193 | |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 194 | } // namespace service |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 195 | } // namespace mojo |