| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "services/native_viewport/native_viewport_impl.h" | 5 #include "services/native_viewport/native_viewport_impl.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "mojo/converters/geometry/geometry_type_converters.h" | 12 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 13 #include "mojo/converters/input_events/input_events_type_converters.h" | 13 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 14 #include "mojo/public/cpp/application/interface_factory.h" | 14 #include "mojo/public/cpp/application/interface_factory.h" |
| 15 #include "services/gles2/gpu_state.h" | 15 #include "services/gles2/gpu_state.h" |
| 16 #include "services/native_viewport/platform_viewport_headless.h" | 16 #include "services/native_viewport/platform_viewport_headless.h" |
| 17 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 18 | 18 |
| 19 namespace native_viewport { | 19 namespace native_viewport { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 bool IsRateLimitedEventType(ui::Event* event) { | 22 bool IsRateLimitedEventType(const mojo::EventPtr& event) { |
| 23 return event->type() == ui::ET_MOUSE_MOVED || | 23 return event->action == mojo::EVENT_TYPE_POINTER_MOVE; |
| 24 event->type() == ui::ET_MOUSE_DRAGGED || | |
| 25 event->type() == ui::ET_TOUCH_MOVED; | |
| 26 } | 24 } |
| 27 | 25 |
| 28 } // namespace | 26 } // namespace |
| 29 | 27 |
| 30 NativeViewportImpl::NativeViewportImpl( | 28 NativeViewportImpl::NativeViewportImpl( |
| 31 bool is_headless, | 29 bool is_headless, |
| 32 const scoped_refptr<gles2::GpuState>& gpu_state, | 30 const scoped_refptr<gles2::GpuState>& gpu_state, |
| 33 mojo::InterfaceRequest<mojo::NativeViewport> request) | 31 mojo::InterfaceRequest<mojo::NativeViewport> request) |
| 34 : is_headless_(is_headless), | 32 : is_headless_(is_headless), |
| 35 context_provider_(gpu_state), | 33 context_provider_(gpu_state), |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // where we don't know the actual size until the first OnMetricsChanged call. | 114 // where we don't know the actual size until the first OnMetricsChanged call. |
| 117 create_callback_.Run(metrics_.Clone()); | 115 create_callback_.Run(metrics_.Clone()); |
| 118 sent_metrics_ = true; | 116 sent_metrics_ = true; |
| 119 create_callback_.reset(); | 117 create_callback_.reset(); |
| 120 } | 118 } |
| 121 | 119 |
| 122 void NativeViewportImpl::OnAcceleratedWidgetDestroyed() { | 120 void NativeViewportImpl::OnAcceleratedWidgetDestroyed() { |
| 123 context_provider_.SetAcceleratedWidget(gfx::kNullAcceleratedWidget); | 121 context_provider_.SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| 124 } | 122 } |
| 125 | 123 |
| 126 bool NativeViewportImpl::OnEvent(ui::Event* ui_event) { | 124 bool NativeViewportImpl::OnEvent(mojo::EventPtr event) { |
| 127 if (!event_dispatcher_.get()) | 125 if (event.is_null() || !event_dispatcher_.get() || |
| 126 (waiting_for_event_ack_ && IsRateLimitedEventType(event))) { |
| 128 return false; | 127 return false; |
| 129 | |
| 130 // Must not return early before updating capture. | |
| 131 switch (ui_event->type()) { | |
| 132 case ui::ET_MOUSE_PRESSED: | |
| 133 case ui::ET_TOUCH_PRESSED: | |
| 134 platform_viewport_->SetCapture(); | |
| 135 break; | |
| 136 case ui::ET_MOUSE_RELEASED: | |
| 137 case ui::ET_TOUCH_RELEASED: | |
| 138 platform_viewport_->ReleaseCapture(); | |
| 139 break; | |
| 140 default: | |
| 141 break; | |
| 142 } | 128 } |
| 143 | 129 |
| 144 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) | |
| 145 return false; | |
| 146 | |
| 147 event_dispatcher_->OnEvent( | 130 event_dispatcher_->OnEvent( |
| 148 mojo::Event::From(*ui_event), | 131 event.Pass(), |
| 149 base::Bind(&NativeViewportImpl::AckEvent, weak_factory_.GetWeakPtr())); | 132 base::Bind(&NativeViewportImpl::AckEvent, weak_factory_.GetWeakPtr())); |
| 150 waiting_for_event_ack_ = true; | 133 waiting_for_event_ack_ = true; |
| 151 return false; | 134 return false; |
| 152 } | 135 } |
| 153 | 136 |
| 154 void NativeViewportImpl::OnDestroyed() { | 137 void NativeViewportImpl::OnDestroyed() { |
| 155 // This will signal a connection error and cause us to delete |this|. | 138 // This will signal a connection error and cause us to delete |this|. |
| 156 binding_.Close(); | 139 binding_.Close(); |
| 157 } | 140 } |
| 158 | 141 |
| 159 void NativeViewportImpl::OnConnectionError() { | 142 void NativeViewportImpl::OnConnectionError() { |
| 160 binding_.set_error_handler(nullptr); | 143 binding_.set_error_handler(nullptr); |
| 161 delete this; | 144 delete this; |
| 162 } | 145 } |
| 163 | 146 |
| 164 void NativeViewportImpl::AckEvent() { | 147 void NativeViewportImpl::AckEvent() { |
| 165 waiting_for_event_ack_ = false; | 148 waiting_for_event_ack_ = false; |
| 166 } | 149 } |
| 167 | 150 |
| 168 } // namespace native_viewport | 151 } // namespace native_viewport |
| OLD | NEW |