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/native_viewport/native_viewport_service.h" | 5 #include "mojo/services/native_viewport/native_viewport_service.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "mojo/public/cpp/bindings/allocation_scope.h" | 10 #include "mojo/public/cpp/bindings/allocation_scope.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 } | 28 } |
29 | 29 |
30 class NativeViewportImpl | 30 class NativeViewportImpl |
31 : public ServiceConnection<mojo::NativeViewport, | 31 : public ServiceConnection<mojo::NativeViewport, |
32 NativeViewportImpl, | 32 NativeViewportImpl, |
33 shell::Context>, | 33 shell::Context>, |
34 public NativeViewportDelegate { | 34 public NativeViewportDelegate { |
35 public: | 35 public: |
36 NativeViewportImpl() | 36 NativeViewportImpl() |
37 : client_(NULL), | 37 : widget_(gfx::kNullAcceleratedWidget), |
38 widget_(gfx::kNullAcceleratedWidget), | |
39 waiting_for_event_ack_(false) {} | 38 waiting_for_event_ack_(false) {} |
40 virtual ~NativeViewportImpl() { | 39 virtual ~NativeViewportImpl() { |
41 // Destroy the NativeViewport early on as it may call us back during | 40 // Destroy the NativeViewport early on as it may call us back during |
42 // destruction and we want to be in a known state. | 41 // destruction and we want to be in a known state. |
43 native_viewport_.reset(); | 42 native_viewport_.reset(); |
44 } | 43 } |
45 | 44 |
46 virtual void SetClient(NativeViewportClient* client) OVERRIDE { | |
47 client_ = client; | |
48 } | |
49 | |
50 virtual void Create(const Rect& bounds) OVERRIDE { | 45 virtual void Create(const Rect& bounds) OVERRIDE { |
51 native_viewport_ = | 46 native_viewport_ = |
52 services::NativeViewport::Create(context(), this); | 47 services::NativeViewport::Create(context(), this); |
53 native_viewport_->Init(bounds); | 48 native_viewport_->Init(bounds); |
54 client_->OnCreated(); | 49 client()->OnCreated(); |
55 OnBoundsChanged(bounds); | 50 OnBoundsChanged(bounds); |
56 } | 51 } |
57 | 52 |
58 virtual void Show() OVERRIDE { | 53 virtual void Show() OVERRIDE { |
59 native_viewport_->Show(); | 54 native_viewport_->Show(); |
60 } | 55 } |
61 | 56 |
62 virtual void Hide() OVERRIDE { | 57 virtual void Hide() OVERRIDE { |
63 native_viewport_->Hide(); | 58 native_viewport_->Hide(); |
64 } | 59 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 touch_data.set_pointer_id(touch_event->touch_id()); | 141 touch_data.set_pointer_id(touch_event->touch_id()); |
147 event.set_touch_data(touch_data.Finish()); | 142 event.set_touch_data(touch_data.Finish()); |
148 } else if (ui_event->IsKeyEvent()) { | 143 } else if (ui_event->IsKeyEvent()) { |
149 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); | 144 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); |
150 KeyData::Builder key_data; | 145 KeyData::Builder key_data; |
151 key_data.set_key_code(key_event->key_code()); | 146 key_data.set_key_code(key_event->key_code()); |
152 key_data.set_is_char(key_event->is_char()); | 147 key_data.set_is_char(key_event->is_char()); |
153 event.set_key_data(key_data.Finish()); | 148 event.set_key_data(key_data.Finish()); |
154 } | 149 } |
155 | 150 |
156 client_->OnEvent(event.Finish(), | 151 client()->OnEvent(event.Finish(), |
157 base::Bind(&NativeViewportImpl::AckEvent, | 152 base::Bind(&NativeViewportImpl::AckEvent, |
158 base::Unretained(this))); | 153 base::Unretained(this))); |
159 waiting_for_event_ack_ = true; | 154 waiting_for_event_ack_ = true; |
160 return false; | 155 return false; |
161 } | 156 } |
162 | 157 |
163 virtual void OnAcceleratedWidgetAvailable( | 158 virtual void OnAcceleratedWidgetAvailable( |
164 gfx::AcceleratedWidget widget) OVERRIDE { | 159 gfx::AcceleratedWidget widget) OVERRIDE { |
165 widget_ = widget; | 160 widget_ = widget; |
166 CreateCommandBufferIfNeeded(); | 161 CreateCommandBufferIfNeeded(); |
167 } | 162 } |
168 | 163 |
169 virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE { | 164 virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE { |
170 CreateCommandBufferIfNeeded(); | 165 CreateCommandBufferIfNeeded(); |
171 AllocationScope scope; | 166 AllocationScope scope; |
172 client_->OnBoundsChanged(bounds); | 167 client()->OnBoundsChanged(bounds); |
173 } | 168 } |
174 | 169 |
175 virtual void OnDestroyed() OVERRIDE { | 170 virtual void OnDestroyed() OVERRIDE { |
176 command_buffer_.reset(); | 171 command_buffer_.reset(); |
177 client_->OnDestroyed(); | 172 client()->OnDestroyed(); |
178 base::MessageLoop::current()->Quit(); | 173 base::MessageLoop::current()->Quit(); |
179 } | 174 } |
180 | 175 |
181 private: | 176 private: |
182 NativeViewportClient* client_; | |
183 gfx::AcceleratedWidget widget_; | 177 gfx::AcceleratedWidget widget_; |
184 scoped_ptr<services::NativeViewport> native_viewport_; | 178 scoped_ptr<services::NativeViewport> native_viewport_; |
185 ScopedMessagePipeHandle command_buffer_handle_; | 179 ScopedMessagePipeHandle command_buffer_handle_; |
186 scoped_ptr<CommandBufferImpl> command_buffer_; | 180 scoped_ptr<CommandBufferImpl> command_buffer_; |
187 bool waiting_for_event_ack_; | 181 bool waiting_for_event_ack_; |
188 }; | 182 }; |
189 | 183 |
190 } // namespace services | 184 } // namespace services |
191 } // namespace mojo | 185 } // namespace mojo |
192 | 186 |
193 | 187 |
194 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* | 188 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* |
195 CreateNativeViewportService(mojo::shell::Context* context, | 189 CreateNativeViewportService(mojo::shell::Context* context, |
196 mojo::ScopedMessagePipeHandle shell_handle) { | 190 mojo::ScopedMessagePipeHandle shell_handle) { |
197 mojo::Application* app = new mojo::Application(shell_handle.Pass()); | 191 mojo::Application* app = new mojo::Application(shell_handle.Pass()); |
198 app->AddServiceConnector( | 192 app->AddServiceConnector( |
199 new mojo::ServiceConnector<mojo::services::NativeViewportImpl, | 193 new mojo::ServiceConnector<mojo::services::NativeViewportImpl, |
200 mojo::shell::Context>(context)); | 194 mojo::shell::Context>(context)); |
201 return app; | 195 return app; |
202 } | 196 } |
203 | 197 |
OLD | NEW |