IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / renderer_host / input / synthetic_gesture_target_android.cc
blob6139f67635c181e98663643aec69fd9350d1aa7a
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
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/input/synthetic_gesture_target_android.h"
7 #include "content/browser/android/content_view_core_impl.h"
8 #include "content/browser/renderer_host/render_widget_host_impl.h"
9 #include "jni/TouchEventSynthesizer_jni.h"
10 #include "third_party/WebKit/public/web/WebInputEvent.h"
11 #include "ui/gfx/android/view_configuration.h"
12 #include "ui/gfx/screen.h"
14 using blink::WebTouchEvent;
16 namespace content {
18 SyntheticGestureTargetAndroid::SyntheticGestureTargetAndroid(
19 RenderWidgetHostImpl* host,
20 base::android::ScopedJavaLocalRef<jobject> touch_event_synthesizer)
21 : SyntheticGestureTargetBase(host),
22 touch_event_synthesizer_(touch_event_synthesizer) {
23 DCHECK(!touch_event_synthesizer_.is_null());
26 SyntheticGestureTargetAndroid::~SyntheticGestureTargetAndroid() {
29 bool SyntheticGestureTargetAndroid::RegisterTouchEventSynthesizer(JNIEnv* env) {
30 return RegisterNativesImpl(env);
33 void SyntheticGestureTargetAndroid::TouchSetPointer(
34 JNIEnv* env, int index, int x, int y, int id) {
35 Java_TouchEventSynthesizer_setPointer(env, touch_event_synthesizer_.obj(),
36 index, x, y, id);
39 void SyntheticGestureTargetAndroid::TouchInject(
40 JNIEnv* env, Action action, int pointer_count, long time_in_ms) {
41 Java_TouchEventSynthesizer_inject(env, touch_event_synthesizer_.obj(),
42 static_cast<int>(action), pointer_count,
43 time_in_ms);
46 void SyntheticGestureTargetAndroid::DispatchWebTouchEventToPlatform(
47 const blink::WebTouchEvent& web_touch, const ui::LatencyInfo&) {
48 JNIEnv* env = base::android::AttachCurrentThread();
50 SyntheticGestureTargetAndroid::Action action =
51 SyntheticGestureTargetAndroid::ActionInvalid;
52 switch (web_touch.type) {
53 case blink::WebInputEvent::TouchStart:
54 action = SyntheticGestureTargetAndroid::ActionStart;
55 break;
56 case blink::WebInputEvent::TouchMove:
57 action = SyntheticGestureTargetAndroid::ActionMove;
58 break;
59 case blink::WebInputEvent::TouchCancel:
60 action = SyntheticGestureTargetAndroid::ActionCancel;
61 break;
62 case blink::WebInputEvent::TouchEnd:
63 action = SyntheticGestureTargetAndroid::ActionEnd;
64 break;
65 default:
66 NOTREACHED();
68 const unsigned num_touches = web_touch.touchesLength;
69 for (unsigned i = 0; i < num_touches; ++i) {
70 const blink::WebTouchPoint* point = &web_touch.touches[i];
71 TouchSetPointer(env, i, point->position.x, point->position.y, point->id);
74 TouchInject(env, action, num_touches,
75 static_cast<long>(web_touch.timeStampSeconds * 1000.0));
78 SyntheticGestureParams::GestureSourceType
79 SyntheticGestureTargetAndroid::GetDefaultSyntheticGestureSourceType() const {
80 return SyntheticGestureParams::TOUCH_INPUT;
83 bool SyntheticGestureTargetAndroid::SupportsSyntheticGestureSourceType(
84 SyntheticGestureParams::GestureSourceType gesture_source_type) const {
85 return gesture_source_type == SyntheticGestureParams::TOUCH_INPUT;
88 int SyntheticGestureTargetAndroid::GetTouchSlopInDips() const {
89 float device_scale_factor =
90 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor();
91 return gfx::ViewConfiguration::GetTouchSlopInPixels() / device_scale_factor;
94 } // namespace content