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 10 matching lines...) Expand all Loading... |
21 | 21 |
22 bool IsRateLimitedEventType(ui::Event* event) { | 22 bool IsRateLimitedEventType(ui::Event* event) { |
23 return event->type() == ui::ET_MOUSE_MOVED || | 23 return event->type() == ui::ET_MOUSE_MOVED || |
24 event->type() == ui::ET_MOUSE_DRAGGED || | 24 event->type() == ui::ET_MOUSE_DRAGGED || |
25 event->type() == ui::ET_TOUCH_MOVED; | 25 event->type() == ui::ET_TOUCH_MOVED; |
26 } | 26 } |
27 | 27 |
28 } | 28 } |
29 | 29 |
30 class NativeViewportImpl | 30 class NativeViewportImpl |
31 : public ServiceConnection<mojo::NativeViewport, | 31 : public InterfaceImpl<mojo::NativeViewport>, |
32 NativeViewportImpl, | |
33 shell::Context>, | |
34 public NativeViewportDelegate { | 32 public NativeViewportDelegate { |
35 public: | 33 public: |
36 NativeViewportImpl() | 34 NativeViewportImpl(shell::Context* context) |
37 : widget_(gfx::kNullAcceleratedWidget), | 35 : context_(context), |
| 36 widget_(gfx::kNullAcceleratedWidget), |
38 waiting_for_event_ack_(false) {} | 37 waiting_for_event_ack_(false) {} |
39 virtual ~NativeViewportImpl() { | 38 virtual ~NativeViewportImpl() { |
40 // Destroy the NativeViewport early on as it may call us back during | 39 // Destroy the NativeViewport early on as it may call us back during |
41 // destruction and we want to be in a known state. | 40 // destruction and we want to be in a known state. |
42 native_viewport_.reset(); | 41 native_viewport_.reset(); |
43 } | 42 } |
44 | 43 |
| 44 virtual void OnConnectionError() OVERRIDE {} |
| 45 |
45 virtual void Create(const Rect& bounds) OVERRIDE { | 46 virtual void Create(const Rect& bounds) OVERRIDE { |
46 native_viewport_ = | 47 native_viewport_ = |
47 services::NativeViewport::Create(context(), this); | 48 services::NativeViewport::Create(context_, this); |
48 native_viewport_->Init(bounds); | 49 native_viewport_->Init(bounds); |
49 client()->OnCreated(); | 50 client()->OnCreated(); |
50 OnBoundsChanged(bounds); | 51 OnBoundsChanged(bounds); |
51 } | 52 } |
52 | 53 |
53 virtual void Show() OVERRIDE { | 54 virtual void Show() OVERRIDE { |
54 native_viewport_->Show(); | 55 native_viewport_->Show(); |
55 } | 56 } |
56 | 57 |
57 virtual void Hide() OVERRIDE { | 58 virtual void Hide() OVERRIDE { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 client()->OnBoundsChanged(bounds); | 168 client()->OnBoundsChanged(bounds); |
168 } | 169 } |
169 | 170 |
170 virtual void OnDestroyed() OVERRIDE { | 171 virtual void OnDestroyed() OVERRIDE { |
171 command_buffer_.reset(); | 172 command_buffer_.reset(); |
172 client()->OnDestroyed(); | 173 client()->OnDestroyed(); |
173 base::MessageLoop::current()->Quit(); | 174 base::MessageLoop::current()->Quit(); |
174 } | 175 } |
175 | 176 |
176 private: | 177 private: |
| 178 shell::Context* context_; |
177 gfx::AcceleratedWidget widget_; | 179 gfx::AcceleratedWidget widget_; |
178 scoped_ptr<services::NativeViewport> native_viewport_; | 180 scoped_ptr<services::NativeViewport> native_viewport_; |
179 ScopedMessagePipeHandle command_buffer_handle_; | 181 ScopedMessagePipeHandle command_buffer_handle_; |
180 scoped_ptr<CommandBufferImpl> command_buffer_; | 182 scoped_ptr<CommandBufferImpl> command_buffer_; |
181 bool waiting_for_event_ack_; | 183 bool waiting_for_event_ack_; |
182 }; | 184 }; |
183 | 185 |
184 } // namespace services | 186 } // namespace services |
185 } // namespace mojo | 187 } // namespace mojo |
186 | 188 |
187 | 189 |
188 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* | 190 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* |
189 CreateNativeViewportService(mojo::shell::Context* context, | 191 CreateNativeViewportService(mojo::shell::Context* context, |
190 mojo::ScopedMessagePipeHandle shell_handle) { | 192 mojo::ScopedMessagePipeHandle shell_handle) { |
191 mojo::Application* app = new mojo::Application(shell_handle.Pass()); | 193 mojo::Application* app = new mojo::Application(shell_handle.Pass()); |
192 app->AddServiceConnector( | 194 app->AddService<mojo::services::NativeViewportImpl>(context); |
193 new mojo::ServiceConnector<mojo::services::NativeViewportImpl, | |
194 mojo::shell::Context>(context)); | |
195 return app; | 195 return app; |
196 } | 196 } |
197 | 197 |
OLD | NEW |