Chromium Code Reviews| Index: content/browser/renderer_host/input/content_gesture_provider.cc |
| diff --git a/content/browser/renderer_host/input/content_gesture_provider.cc b/content/browser/renderer_host/input/content_gesture_provider.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..866f6923049eb913644ec449d45e65a9850ba913 |
| --- /dev/null |
| +++ b/content/browser/renderer_host/input/content_gesture_provider.cc |
| @@ -0,0 +1,186 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/renderer_host/input/content_gesture_provider.h" |
| + |
| +#include "base/auto_reset.h" |
| +#include "base/logging.h" |
| +#include "ui/events/gesture_detection/gesture_config_helper.h" |
| +#include "ui/events/gesture_detection/gesture_event_params.h" |
| +#include "ui/events/gesture_detection/motion_event.h" |
| + |
| +using blink::WebGestureEvent; |
| +using blink::WebInputEvent; |
| + |
| +namespace content { |
| +namespace { |
| + |
| +WebGestureEvent CreateGesture(const ui::GestureEventParams& params, |
|
tdresser
2014/02/27 15:28:30
This seems to be the only method which should be A
jdduke (slow)
2014/02/27 17:40:29
Hmm, I guess I fail to see how this is Android spe
|
| + float scale) { |
| + WebGestureEvent gesture; |
| + gesture.x = params.x * scale; |
| + gesture.y = params.y * scale; |
| + gesture.timeStampSeconds = (params.time - base::TimeTicks()).InSecondsF(); |
| + gesture.sourceDevice = WebGestureEvent::Touchscreen; |
| + |
| + switch (params.type) { |
| + case ui::GESTURE_SHOW_PRESS: |
| + gesture.type = WebInputEvent::GestureShowPress; |
| + gesture.data.showPress.width = params.data.show_press.width * scale; |
| + gesture.data.showPress.width = params.data.show_press.width * scale; |
| + break; |
| + case ui::GESTURE_DOUBLE_TAP: |
| + gesture.type = WebInputEvent::GestureDoubleTap; |
| + break; |
| + case ui::GESTURE_SINGLE_TAP_CONFIRMED: |
| + gesture.type = WebInputEvent::GestureTap; |
| + gesture.data.tap.tapCount = params.data.tap.tap_count; |
| + gesture.data.tap.width = params.data.tap.width * scale; |
| + gesture.data.tap.height = params.data.tap.height * scale; |
| + break; |
| + case ui::GESTURE_SINGLE_TAP_UNCONFIRMED: |
| + gesture.type = WebInputEvent::GestureTapUnconfirmed; |
| + gesture.data.tap.tapCount = params.data.tap.tap_count; |
| + gesture.data.tap.width = params.data.tap.width * scale; |
| + gesture.data.tap.height = params.data.tap.height * scale; |
| + break; |
| + case ui::GESTURE_LONG_PRESS: |
| + gesture.type = WebInputEvent::GestureLongPress; |
| + gesture.data.longPress.width = params.data.long_press.width * scale; |
| + gesture.data.longPress.height = params.data.long_press.height * scale; |
| + break; |
| + case ui::GESTURE_LONG_TAP: |
| + gesture.type = WebInputEvent::GestureLongTap; |
| + gesture.data.longPress.width = params.data.long_press.width * scale; |
| + gesture.data.longPress.height = params.data.long_press.height * scale; |
| + break; |
| + case ui::GESTURE_SCROLL_BEGIN: |
| + gesture.type = WebInputEvent::GestureScrollBegin; |
| + gesture.data.scrollBegin.deltaXHint = |
| + params.data.scroll_begin.delta_x_hint * scale; |
| + gesture.data.scrollBegin.deltaYHint = |
| + params.data.scroll_begin.delta_y_hint * scale; |
| + break; |
| + case ui::GESTURE_SCROLL_UPDATE: |
| + gesture.type = WebInputEvent::GestureScrollUpdate; |
| + gesture.data.scrollUpdate.deltaX = |
| + params.data.scroll_update.delta_x * scale; |
| + gesture.data.scrollUpdate.deltaY = |
| + params.data.scroll_update.delta_y * scale; |
| + gesture.data.scrollUpdate.velocityX = |
| + params.data.scroll_update.velocity_x * scale; |
| + gesture.data.scrollUpdate.velocityY = |
| + params.data.scroll_update.velocity_y * scale; |
| + break; |
| + case ui::GESTURE_SCROLL_END: |
| + gesture.type = WebInputEvent::GestureScrollEnd; |
| + break; |
| + case ui::GESTURE_FLING_START: |
| + gesture.type = WebInputEvent::GestureFlingStart; |
| + gesture.data.flingStart.velocityX = |
| + params.data.fling_start.velocity_x * scale; |
| + gesture.data.flingStart.velocityY = |
| + params.data.fling_start.velocity_y * scale; |
| + break; |
| + case ui::GESTURE_FLING_CANCEL: |
| + gesture.type = WebInputEvent::GestureFlingCancel; |
| + break; |
| + case ui::GESTURE_PINCH_BEGIN: |
| + gesture.type = WebInputEvent::GesturePinchBegin; |
| + break; |
| + case ui::GESTURE_PINCH_UPDATE: |
| + gesture.type = WebInputEvent::GesturePinchUpdate; |
| + gesture.data.pinchUpdate.scale = params.data.pinch_update.scale; |
| + break; |
| + case ui::GESTURE_PINCH_END: |
| + gesture.type = WebInputEvent::GesturePinchEnd; |
| + break; |
| + case ui::GESTURE_TAP_CANCEL: |
| + gesture.type = WebInputEvent::GestureTapCancel; |
| + break; |
| + case ui::GESTURE_TAP_DOWN: |
| + gesture.type = WebInputEvent::GestureTapDown; |
| + gesture.data.tapDown.width = params.data.tap_down.width * scale; |
| + gesture.data.tapDown.height = params.data.tap_down.height * scale; |
| + break; |
| + } |
| + |
| + return gesture; |
| +} |
| + |
| +} // namespace |
| + |
| +ContentGestureProvider::ContentGestureProvider( |
| + ContentGestureProviderClient* client, |
| + float touch_to_gesture_scale) |
| + : client_(client), |
| + touch_to_gesture_scale_(touch_to_gesture_scale), |
| + gesture_provider_(ui::DefaultGestureProviderConfig(), this), |
| + gesture_filter_(this), |
| + handling_event_(false) {} |
| + |
| +bool ContentGestureProvider::OnTouchEvent(const ui::MotionEvent& event) { |
| + DCHECK(!handling_event_); |
| + base::AutoReset<bool> handling_event(&handling_event_, true); |
| + |
| + pending_gesture_packet_ = GestureEventPacket::FromTouch(event); |
| + |
| + if (!gesture_provider_.OnTouchEvent(event)) |
| + return false; |
| + |
| + TouchDispositionGestureFilter::PacketResult result = |
| + gesture_filter_.OnGestureEventPacket(pending_gesture_packet_); |
| + if (result != TouchDispositionGestureFilter::SUCCESS) { |
| + NOTREACHED() << "Invalid touch gesture sequence detected."; |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| +void ContentGestureProvider::OnTouchEventAck(InputEventAckState ack_state) { |
| + gesture_filter_.OnTouchEventAck(ack_state); |
| +} |
| + |
| +void ContentGestureProvider::ResetGestureDetectors() { |
| + gesture_provider_.ResetGestureDetectors(); |
| +} |
| + |
| +void ContentGestureProvider::CancelActiveTouchSequence() { |
| + gesture_provider_.CancelActiveTouchSequence(); |
| +} |
| + |
| +void ContentGestureProvider::UpdateMultiTouchSupport( |
| + bool support_multi_touch_zoom) { |
| + gesture_provider_.UpdateMultiTouchSupport(support_multi_touch_zoom); |
| +} |
| + |
| +void ContentGestureProvider::UpdateDoubleTapSupportForPlatform( |
| + bool support_double_tap) { |
| + gesture_provider_.UpdateDoubleTapSupportForPlatform(support_double_tap); |
| +} |
| + |
| +void ContentGestureProvider::UpdateDoubleTapSupportForPage( |
| + bool support_double_tap) { |
| + gesture_provider_.UpdateDoubleTapSupportForPage(support_double_tap); |
| +} |
| + |
| +void ContentGestureProvider::OnGestureEvent( |
| + const ui::GestureEventParams& params) { |
| + WebGestureEvent gesture(CreateGesture(params, touch_to_gesture_scale_)); |
| + if (handling_event_) { |
| + pending_gesture_packet_.Push(gesture); |
| + return; |
| + } |
| + |
| + gesture_filter_.OnGestureEventPacket( |
| + GestureEventPacket::FromTouchTimeout(gesture)); |
| +} |
| + |
| +void ContentGestureProvider::ForwardGestureEvent( |
| + const blink::WebGestureEvent& event) { |
| + client_->OnGestureEvent(event); |
| +} |
| + |
| +} // namespace content |