DevTools: cut host and port from webSocketDebuggerUrl in addition to ws:// prefix
[chromium-blink-merge.git] / content / browser / renderer_host / input / synthetic_gesture_target_android.cc
blob836da7db49eba745a8ca5621bae54bc6b1fb4236
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/MotionEventSynthesizer_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::RegisterMotionEventSynthesizer(
30 JNIEnv* env) {
31 return RegisterNativesImpl(env);
34 void SyntheticGestureTargetAndroid::TouchSetPointer(
35 JNIEnv* env, int index, int x, int y, int id) {
36 TRACE_EVENT0("input", "SyntheticGestureTargetAndroid::TouchSetPointer");
37 Java_MotionEventSynthesizer_setPointer(env, touch_event_synthesizer_.obj(),
38 index, x, y, id);
41 void SyntheticGestureTargetAndroid::TouchSetScrollDeltas(
42 JNIEnv* env, int x, int y, int dx, int dy) {
43 TRACE_EVENT0("input", "SyntheticGestureTargetAndroid::TouchSetPointer");
44 Java_MotionEventSynthesizer_setScrollDeltas(
45 env, touch_event_synthesizer_.obj(), x, y, dx, dy);
48 void SyntheticGestureTargetAndroid::TouchInject(
49 JNIEnv* env, Action action, int pointer_count, int64 time_in_ms) {
50 TRACE_EVENT0("input", "SyntheticGestureTargetAndroid::TouchInject");
51 Java_MotionEventSynthesizer_inject(env, touch_event_synthesizer_.obj(),
52 static_cast<int>(action), pointer_count,
53 time_in_ms);
56 void SyntheticGestureTargetAndroid::DispatchWebTouchEventToPlatform(
57 const blink::WebTouchEvent& web_touch, const ui::LatencyInfo&) {
58 JNIEnv* env = base::android::AttachCurrentThread();
60 SyntheticGestureTargetAndroid::Action action =
61 SyntheticGestureTargetAndroid::ActionInvalid;
62 switch (web_touch.type) {
63 case blink::WebInputEvent::TouchStart:
64 action = SyntheticGestureTargetAndroid::ActionStart;
65 break;
66 case blink::WebInputEvent::TouchMove:
67 action = SyntheticGestureTargetAndroid::ActionMove;
68 break;
69 case blink::WebInputEvent::TouchCancel:
70 action = SyntheticGestureTargetAndroid::ActionCancel;
71 break;
72 case blink::WebInputEvent::TouchEnd:
73 action = SyntheticGestureTargetAndroid::ActionEnd;
74 break;
75 default:
76 NOTREACHED();
78 const unsigned num_touches = web_touch.touchesLength;
79 for (unsigned i = 0; i < num_touches; ++i) {
80 const blink::WebTouchPoint* point = &web_touch.touches[i];
81 TouchSetPointer(env, i, point->position.x, point->position.y, point->id);
84 TouchInject(env, action, num_touches,
85 static_cast<int64>(web_touch.timeStampSeconds * 1000.0));
88 void SyntheticGestureTargetAndroid::DispatchWebMouseWheelEventToPlatform(
89 const blink::WebMouseWheelEvent& web_wheel, const ui::LatencyInfo&) {
90 JNIEnv* env = base::android::AttachCurrentThread();
91 TouchSetScrollDeltas(env, web_wheel.x, web_wheel.y, web_wheel.deltaX,
92 web_wheel.deltaY);
93 Java_MotionEventSynthesizer_inject(
94 env, touch_event_synthesizer_.obj(),
95 static_cast<int>(SyntheticGestureTargetAndroid::ActionScroll),
96 1, static_cast<int64>(web_wheel.timeStampSeconds * 1000.0));
99 void SyntheticGestureTargetAndroid::DispatchWebMouseEventToPlatform(
100 const blink::WebMouseEvent& web_mouse, const ui::LatencyInfo&) {
101 CHECK(false);
104 SyntheticGestureParams::GestureSourceType
105 SyntheticGestureTargetAndroid::GetDefaultSyntheticGestureSourceType() const {
106 return SyntheticGestureParams::TOUCH_INPUT;
109 float SyntheticGestureTargetAndroid::GetTouchSlopInDips() const {
110 float device_scale_factor =
111 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor();
112 return gfx::ViewConfiguration::GetTouchSlopInPixels() / device_scale_factor;
115 float SyntheticGestureTargetAndroid::GetMinScalingSpanInDips() const {
116 float device_scale_factor =
117 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor();
118 return
119 gfx::ViewConfiguration::GetMinScalingSpanInPixels() / device_scale_factor;
122 } // namespace content