diff options
Diffstat (limited to 'mojo/services')
9 files changed, 106 insertions, 14 deletions
diff --git a/mojo/services/native_viewport/native_viewport.h b/mojo/services/native_viewport/native_viewport.h index 8597156..3c36c6c 100644 --- a/mojo/services/native_viewport/native_viewport.h +++ b/mojo/services/native_viewport/native_viewport.h @@ -41,6 +41,9 @@ class NativeViewport { virtual void Close() = 0; virtual gfx::Size GetSize() = 0; + virtual void SetCapture() = 0; + virtual void ReleaseCapture() = 0; + static scoped_ptr<NativeViewport> Create(shell::Context* context, NativeViewportDelegate* delegate); }; diff --git a/mojo/services/native_viewport/native_viewport.mojom b/mojo/services/native_viewport/native_viewport.mojom index aa7543b..d90bf7c 100644 --- a/mojo/services/native_viewport/native_viewport.mojom +++ b/mojo/services/native_viewport/native_viewport.mojom @@ -25,6 +25,7 @@ interface NativeViewport { void Open(); void Close(); void CreateGLES2Context(handle<message_pipe> gles2_client); + void AckEvent(Event event); }; [Peer=NativeViewport] diff --git a/mojo/services/native_viewport/native_viewport_android.cc b/mojo/services/native_viewport/native_viewport_android.cc index 1afd7bc..de24084 100644 --- a/mojo/services/native_viewport/native_viewport_android.cc +++ b/mojo/services/native_viewport/native_viewport_android.cc @@ -112,6 +112,14 @@ gfx::Size NativeViewportAndroid::GetSize() { return size_; } +void NativeViewportAndroid::SetCapture() { + NOTIMPLEMENTED(); +} + +void NativeViewportAndroid::ReleaseCapture() { + NOTIMPLEMENTED(); +} + //////////////////////////////////////////////////////////////////////////////// // NativeViewportAndroid, private: diff --git a/mojo/services/native_viewport/native_viewport_android.h b/mojo/services/native_viewport/native_viewport_android.h index 0858425..c456033 100644 --- a/mojo/services/native_viewport/native_viewport_android.h +++ b/mojo/services/native_viewport/native_viewport_android.h @@ -42,6 +42,8 @@ class NativeViewportAndroid : public NativeViewport { virtual void Init() OVERRIDE; virtual void Close() OVERRIDE; virtual gfx::Size GetSize() OVERRIDE; + virtual void SetCapture() OVERRIDE; + virtual void ReleaseCapture() OVERRIDE; void ReleaseWindow(); diff --git a/mojo/services/native_viewport/native_viewport_impl.cc b/mojo/services/native_viewport/native_viewport_impl.cc index 5b980c8..6d04ca4 100644 --- a/mojo/services/native_viewport/native_viewport_impl.cc +++ b/mojo/services/native_viewport/native_viewport_impl.cc @@ -5,17 +5,32 @@ #include "mojo/services/native_viewport/native_viewport_impl.h" #include "base/message_loop/message_loop.h" +#include "base/time/time.h" #include "mojo/services/gles2/gles2_impl.h" #include "mojo/services/native_viewport/native_viewport.h" #include "ui/events/event.h" namespace mojo { namespace services { +namespace { + +bool IsRateLimitedEventType(ui::Event* event) { + return event->type() == ui::ET_MOUSE_MOVED || + event->type() == ui::ET_MOUSE_DRAGGED || + event->type() == ui::ET_TOUCH_MOVED; +} + +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeViewportImpl, public: NativeViewportImpl::NativeViewportImpl(shell::Context* context, ScopedMessagePipeHandle pipe) : context_(context), widget_(gfx::kNullAcceleratedWidget), + waiting_for_event_ack_(false), + pending_event_timestamp_(0), client_(pipe.Pass()) { client_.SetPeer(this); } @@ -23,6 +38,9 @@ NativeViewportImpl::NativeViewportImpl(shell::Context* context, NativeViewportImpl::~NativeViewportImpl() { } +//////////////////////////////////////////////////////////////////////////////// +// NativeViewportImpl, NativeViewportStub overrides: + void NativeViewportImpl::Open() { native_viewport_ = services::NativeViewport::Create(context_, this); native_viewport_->Init(); @@ -40,18 +58,47 @@ void NativeViewportImpl::CreateGLES2Context( CreateGLES2ContextIfNeeded(); } -void NativeViewportImpl::CreateGLES2ContextIfNeeded() { - if (widget_ == gfx::kNullAcceleratedWidget || !gles2_) - return; - gles2_->CreateContext(widget_, native_viewport_->GetSize()); +void NativeViewportImpl::AckEvent(const Event& event) { + DCHECK_EQ(event.time_stamp(), pending_event_timestamp_); + waiting_for_event_ack_ = false; +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeViewportImpl, NativeViewportDelegate implementation: + +void NativeViewportImpl::OnResized(const gfx::Size& size) { +} + +void NativeViewportImpl::OnAcceleratedWidgetAvailable( + gfx::AcceleratedWidget widget) { + widget_ = widget; + CreateGLES2ContextIfNeeded(); } bool NativeViewportImpl::OnEvent(ui::Event* ui_event) { + // Must not return early before updating capture. + switch (ui_event->type()) { + case ui::ET_MOUSE_PRESSED: + case ui::ET_TOUCH_PRESSED: + native_viewport_->SetCapture(); + break; + case ui::ET_MOUSE_RELEASED: + case ui::ET_TOUCH_RELEASED: + native_viewport_->ReleaseCapture(); + break; + default: + break; + } + + if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) + return false; + AllocationScope scope; Event::Builder event; event.set_action(ui_event->type()); - event.set_time_stamp(ui_event->time_stamp().ToInternalValue()); + pending_event_timestamp_ = ui_event->time_stamp().ToInternalValue(); + event.set_time_stamp(pending_event_timestamp_); if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) { ui::LocatedEvent* located_event = static_cast<ui::LocatedEvent*>(ui_event); @@ -69,18 +116,10 @@ bool NativeViewportImpl::OnEvent(ui::Event* ui_event) { } client_->OnEvent(event.Finish()); + waiting_for_event_ack_ = true; return false; } -void NativeViewportImpl::OnAcceleratedWidgetAvailable( - gfx::AcceleratedWidget widget) { - widget_ = widget; - CreateGLES2ContextIfNeeded(); -} - -void NativeViewportImpl::OnResized(const gfx::Size& size) { -} - void NativeViewportImpl::OnDestroyed() { // TODO(beng): // Destroying |gles2_| on the shell thread here hits thread checker asserts. @@ -94,5 +133,14 @@ void NativeViewportImpl::OnDestroyed() { client_->OnDestroyed(); } +//////////////////////////////////////////////////////////////////////////////// +// NativeViewportImpl, private: + +void NativeViewportImpl::CreateGLES2ContextIfNeeded() { + if (widget_ == gfx::kNullAcceleratedWidget || !gles2_) + return; + gles2_->CreateContext(widget_, native_viewport_->GetSize()); +} + } // namespace services } // namespace mojo diff --git a/mojo/services/native_viewport/native_viewport_impl.h b/mojo/services/native_viewport/native_viewport_impl.h index fe9d821..5a97155 100644 --- a/mojo/services/native_viewport/native_viewport_impl.h +++ b/mojo/services/native_viewport/native_viewport_impl.h @@ -27,10 +27,12 @@ class NativeViewportImpl : public NativeViewportStub, ScopedMessagePipeHandle pipe); virtual ~NativeViewportImpl(); + // Overridden from NativeViewportStub: virtual void Open() OVERRIDE; virtual void Close() OVERRIDE; virtual void CreateGLES2Context( ScopedMessagePipeHandle gles2_client) OVERRIDE; + virtual void AckEvent(const Event& event) OVERRIDE; private: // Overridden from services::NativeViewportDelegate: @@ -46,6 +48,8 @@ class NativeViewportImpl : public NativeViewportStub, gfx::AcceleratedWidget widget_; scoped_ptr<services::NativeViewport> native_viewport_; scoped_ptr<GLES2Impl> gles2_; + bool waiting_for_event_ack_; + int64 pending_event_timestamp_; RemotePtr<NativeViewportClient> client_; diff --git a/mojo/services/native_viewport/native_viewport_mac.mm b/mojo/services/native_viewport/native_viewport_mac.mm index 74f55a9..be0080a 100644 --- a/mojo/services/native_viewport/native_viewport_mac.mm +++ b/mojo/services/native_viewport/native_viewport_mac.mm @@ -50,6 +50,14 @@ class NativeViewportMac : public NativeViewport { delegate_->OnDestroyed(); } + virtual void SetCapture() OVERRIDE { + NOTIMPLEMENTED(); + } + + virtual void ReleaseCapture() OVERRIDE { + NOTIMPLEMENTED(); + } + NativeViewportDelegate* delegate_; NSWindow* window_; gfx::Rect rect_; diff --git a/mojo/services/native_viewport/native_viewport_win.cc b/mojo/services/native_viewport/native_viewport_win.cc index 7bda7ab..668a6ab 100644 --- a/mojo/services/native_viewport/native_viewport_win.cc +++ b/mojo/services/native_viewport/native_viewport_win.cc @@ -39,6 +39,16 @@ class NativeViewportWin : public gfx::WindowImpl, DestroyWindow(hwnd()); } + virtual void SetCapture() OVERRIDE { + DCHECK(::GetCapture() != hwnd()); + ::SetCapture(hwnd()); + } + + virtual void ReleaseCapture() OVERRIDE { + if (::GetCapture() == hwnd()) + ::ReleaseCapture(); + } + BEGIN_MSG_MAP_EX(NativeViewportWin) MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) diff --git a/mojo/services/native_viewport/native_viewport_x11.cc b/mojo/services/native_viewport/native_viewport_x11.cc index 1941516..98a740a 100644 --- a/mojo/services/native_viewport/native_viewport_x11.cc +++ b/mojo/services/native_viewport/native_viewport_x11.cc @@ -65,6 +65,14 @@ class NativeViewportX11 : public NativeViewport, delegate_->OnDestroyed(); } + virtual void SetCapture() OVERRIDE { + NOTIMPLEMENTED(); + } + + virtual void ReleaseCapture() OVERRIDE { + NOTIMPLEMENTED(); + } + // Overridden from base::MessagePumpDispatcher: virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE { return true; |