| 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 : client_(NULL), | 35 : context_(context), |
| 36 client_(NULL), |
| 38 widget_(gfx::kNullAcceleratedWidget), | 37 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 |
| 45 virtual void OnConnectionError() OVERRIDE {} |
| 46 |
| 46 virtual void SetClient(NativeViewportClient* client) OVERRIDE { | 47 virtual void SetClient(NativeViewportClient* client) OVERRIDE { |
| 47 client_ = client; | 48 client_ = client; |
| 48 } | 49 } |
| 49 | 50 |
| 50 virtual void Create(const Rect& bounds) OVERRIDE { | 51 virtual void Create(const Rect& bounds) OVERRIDE { |
| 51 native_viewport_ = | 52 native_viewport_ = |
| 52 services::NativeViewport::Create(context(), this); | 53 services::NativeViewport::Create(context_, this); |
| 53 native_viewport_->Init(bounds); | 54 native_viewport_->Init(bounds); |
| 54 client_->OnCreated(); | 55 client_->OnCreated(); |
| 55 OnBoundsChanged(bounds); | 56 OnBoundsChanged(bounds); |
| 56 } | 57 } |
| 57 | 58 |
| 58 virtual void Show() OVERRIDE { | 59 virtual void Show() OVERRIDE { |
| 59 native_viewport_->Show(); | 60 native_viewport_->Show(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 virtual void Hide() OVERRIDE { | 63 virtual void Hide() OVERRIDE { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 client_->OnBoundsChanged(bounds); | 173 client_->OnBoundsChanged(bounds); |
| 173 } | 174 } |
| 174 | 175 |
| 175 virtual void OnDestroyed() OVERRIDE { | 176 virtual void OnDestroyed() OVERRIDE { |
| 176 command_buffer_.reset(); | 177 command_buffer_.reset(); |
| 177 client_->OnDestroyed(); | 178 client_->OnDestroyed(); |
| 178 base::MessageLoop::current()->Quit(); | 179 base::MessageLoop::current()->Quit(); |
| 179 } | 180 } |
| 180 | 181 |
| 181 private: | 182 private: |
| 183 shell::Context* context_; |
| 182 NativeViewportClient* client_; | 184 NativeViewportClient* client_; |
| 183 gfx::AcceleratedWidget widget_; | 185 gfx::AcceleratedWidget widget_; |
| 184 scoped_ptr<services::NativeViewport> native_viewport_; | 186 scoped_ptr<services::NativeViewport> native_viewport_; |
| 185 ScopedMessagePipeHandle command_buffer_handle_; | 187 ScopedMessagePipeHandle command_buffer_handle_; |
| 186 scoped_ptr<CommandBufferImpl> command_buffer_; | 188 scoped_ptr<CommandBufferImpl> command_buffer_; |
| 187 bool waiting_for_event_ack_; | 189 bool waiting_for_event_ack_; |
| 188 }; | 190 }; |
| 189 | 191 |
| 190 } // namespace services | 192 } // namespace services |
| 191 } // namespace mojo | 193 } // namespace mojo |
| 192 | 194 |
| 193 | 195 |
| 194 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* | 196 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* |
| 195 CreateNativeViewportService(mojo::shell::Context* context, | 197 CreateNativeViewportService(mojo::shell::Context* context, |
| 196 mojo::ScopedMessagePipeHandle shell_handle) { | 198 mojo::ScopedMessagePipeHandle shell_handle) { |
| 197 mojo::Application* app = new mojo::Application(shell_handle.Pass()); | 199 mojo::Application* app = new mojo::Application(shell_handle.Pass()); |
| 198 app->AddServiceConnector( | 200 app->AddService<mojo::services::NativeViewportImpl>(context); |
| 199 new mojo::ServiceConnector<mojo::services::NativeViewportImpl, | |
| 200 mojo::shell::Context>(context)); | |
| 201 return app; | 201 return app; |
| 202 } | 202 } |
| 203 | 203 |
| OLD | NEW |