| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/public/c/gles2/gles2.h" | |
| 6 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | |
| 7 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | |
| 8 #include "mojo/services/view_manager/connection_manager.h" | |
| 9 #include "mojo/services/view_manager/context_factory_impl.h" | |
| 10 #include "mojo/services/view_manager/window_tree_host_impl.h" | |
| 11 #include "ui/aura/env.h" | |
| 12 #include "ui/aura/layout_manager.h" | |
| 13 #include "ui/aura/window.h" | |
| 14 #include "ui/aura/window_event_dispatcher.h" | |
| 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 { | |
| 22 namespace service { | |
| 23 | |
| 24 // TODO(sky): nuke this. It shouldn't be static. | |
| 25 // static | |
| 26 ContextFactoryImpl* WindowTreeHostImpl::context_factory_ = NULL; | |
| 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 //////////////////////////////////////////////////////////////////////////////// | |
| 66 // WindowTreeHostImpl, public: | |
| 67 | |
| 68 WindowTreeHostImpl::WindowTreeHostImpl( | |
| 69 NativeViewportPtr viewport, | |
| 70 GpuPtr gpu_service, | |
| 71 const gfx::Rect& bounds, | |
| 72 const Callback<void()>& compositor_created_callback, | |
| 73 const Callback<void()>& native_viewport_closed_callback, | |
| 74 const Callback<void(EventPtr)>& event_received_callback) | |
| 75 : native_viewport_(viewport.Pass()), | |
| 76 gpu_service_(gpu_service.Pass()), | |
| 77 widget_(gfx::kNullAcceleratedWidget), | |
| 78 compositor_created_callback_(compositor_created_callback), | |
| 79 native_viewport_closed_callback_(native_viewport_closed_callback), | |
| 80 event_received_callback_(event_received_callback), | |
| 81 bounds_(bounds) { | |
| 82 native_viewport_.set_client(this); | |
| 83 native_viewport_->Create(Rect::From(bounds)); | |
| 84 native_viewport_->Show(); | |
| 85 | |
| 86 window()->SetLayoutManager(new RootLayoutManager()); | |
| 87 } | |
| 88 | |
| 89 WindowTreeHostImpl::~WindowTreeHostImpl() { | |
| 90 DestroyCompositor(); | |
| 91 DestroyDispatcher(); | |
| 92 delete context_factory_; | |
| 93 context_factory_ = NULL; | |
| 94 } | |
| 95 | |
| 96 //////////////////////////////////////////////////////////////////////////////// | |
| 97 // WindowTreeHostImpl, aura::WindowTreeHost implementation: | |
| 98 | |
| 99 ui::EventSource* WindowTreeHostImpl::GetEventSource() { | |
| 100 return this; | |
| 101 } | |
| 102 | |
| 103 gfx::AcceleratedWidget WindowTreeHostImpl::GetAcceleratedWidget() { | |
| 104 return widget_; | |
| 105 } | |
| 106 | |
| 107 void WindowTreeHostImpl::Show() { | |
| 108 window()->Show(); | |
| 109 } | |
| 110 | |
| 111 void WindowTreeHostImpl::Hide() { | |
| 112 native_viewport_->Hide(); | |
| 113 window()->Hide(); | |
| 114 } | |
| 115 | |
| 116 gfx::Rect WindowTreeHostImpl::GetBounds() const { | |
| 117 return bounds_; | |
| 118 } | |
| 119 | |
| 120 void WindowTreeHostImpl::SetBounds(const gfx::Rect& bounds) { | |
| 121 native_viewport_->SetBounds(Rect::From(bounds)); | |
| 122 } | |
| 123 | |
| 124 gfx::Point WindowTreeHostImpl::GetLocationOnNativeScreen() const { | |
| 125 return gfx::Point(0, 0); | |
| 126 } | |
| 127 | |
| 128 void WindowTreeHostImpl::SetCapture() { | |
| 129 NOTIMPLEMENTED(); | |
| 130 } | |
| 131 | |
| 132 void WindowTreeHostImpl::ReleaseCapture() { | |
| 133 NOTIMPLEMENTED(); | |
| 134 } | |
| 135 | |
| 136 void WindowTreeHostImpl::PostNativeEvent( | |
| 137 const base::NativeEvent& native_event) { | |
| 138 NOTIMPLEMENTED(); | |
| 139 } | |
| 140 | |
| 141 void WindowTreeHostImpl::SetCursorNative(gfx::NativeCursor cursor) { | |
| 142 NOTIMPLEMENTED(); | |
| 143 } | |
| 144 | |
| 145 void WindowTreeHostImpl::MoveCursorToNative(const gfx::Point& location) { | |
| 146 NOTIMPLEMENTED(); | |
| 147 } | |
| 148 | |
| 149 void WindowTreeHostImpl::OnCursorVisibilityChangedNative(bool show) { | |
| 150 NOTIMPLEMENTED(); | |
| 151 } | |
| 152 | |
| 153 //////////////////////////////////////////////////////////////////////////////// | |
| 154 // WindowTreeHostImpl, ui::EventSource implementation: | |
| 155 | |
| 156 ui::EventProcessor* WindowTreeHostImpl::GetEventProcessor() { | |
| 157 return dispatcher(); | |
| 158 } | |
| 159 | |
| 160 //////////////////////////////////////////////////////////////////////////////// | |
| 161 // WindowTreeHostImpl, NativeViewportClient implementation: | |
| 162 | |
| 163 void WindowTreeHostImpl::OnCreated(uint64_t native_viewport_id) { | |
| 164 CommandBufferPtr cb; | |
| 165 // TODO(jamesr): Output to a surface instead. | |
| 166 gpu_service_->CreateOnscreenGLES2Context( | |
| 167 native_viewport_id, Size::From(bounds_.size()), Get(&cb)); | |
| 168 widget_ = bit_cast<gfx::AcceleratedWidget>( | |
| 169 static_cast<uintptr_t>(native_viewport_id)); | |
| 170 | |
| 171 // The ContextFactory must exist before any Compositors are created. | |
| 172 if (context_factory_) { | |
| 173 delete context_factory_; | |
| 174 context_factory_ = NULL; | |
| 175 } | |
| 176 context_factory_ = new ContextFactoryImpl(cb.PassMessagePipe()); | |
| 177 aura::Env::GetInstance()->set_context_factory(context_factory_); | |
| 178 | |
| 179 CreateCompositor(gfx::kNullAcceleratedWidget); | |
| 180 compositor_created_callback_.Run(); | |
| 181 } | |
| 182 | |
| 183 void WindowTreeHostImpl::OnBoundsChanged(RectPtr bounds) { | |
| 184 bounds_ = bounds.To<gfx::Rect>(); | |
| 185 if (context_factory_) | |
| 186 OnHostResized(bounds_.size()); | |
| 187 } | |
| 188 | |
| 189 void WindowTreeHostImpl::OnDestroyed() { | |
| 190 DestroyCompositor(); | |
| 191 native_viewport_closed_callback_.Run(); | |
| 192 // TODO(beng): quit the message loop once we are on our own thread. | |
| 193 } | |
| 194 | |
| 195 void WindowTreeHostImpl::OnEvent(EventPtr event, | |
| 196 const mojo::Callback<void()>& callback) { | |
| 197 event_received_callback_.Run(event.Pass()); | |
| 198 callback.Run(); | |
| 199 }; | |
| 200 | |
| 201 } // namespace service | |
| 202 } // namespace mojo | |
| OLD | NEW |