OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "content/browser/renderer_host/input/synthetic_gesture_target_android.h " | |
6 | |
7 #include "content/browser/android/content_view_core_impl.h" | |
8 #include "jni/SyntheticTouchEvent_jni.h" | |
9 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
10 | |
11 using WebKit::WebTouchEvent; | |
12 | |
13 namespace { | |
14 bool g_jni_initialized = false; | |
15 | |
16 void RegisterNativesIfNeeded(JNIEnv* env) { | |
17 if (!g_jni_initialized) { | |
18 content::RegisterNativesImpl(env); | |
19 g_jni_initialized = true; | |
20 } | |
21 } | |
22 } // namespace | |
23 | |
24 namespace content { | |
25 | |
26 SyntheticGestureTargetAndroid::SyntheticGestureTargetAndroid( | |
27 RenderWidgetHostViewAndroid* render_view) | |
28 : SyntheticGestureTargetBase(render_view), | |
29 env_(base::android::AttachCurrentThread()), | |
30 java_touch_event_( | |
31 render_view->content_view_core()->CreateSyntheticTouchEvent()) { | |
32 CHECK(!java_touch_event_.is_null()); | |
33 RegisterNativesIfNeeded(env_); | |
34 } | |
35 | |
36 SyntheticGestureTargetAndroid::~SyntheticGestureTargetAndroid() { | |
37 } | |
38 | |
39 void SyntheticGestureTargetAndroid::TouchSetPointer( | |
40 int index, int x, int y, int id) { | |
41 Java_SyntheticTouchEvent_setPointer(env_, java_touch_event_.obj(), | |
42 index, x, y, id); | |
43 } | |
44 | |
45 void SyntheticGestureTargetAndroid::TouchInject( | |
46 Action action, int pointer_count) { | |
47 Java_SyntheticTouchEvent_inject(env_, java_touch_event_.obj(), | |
48 static_cast<int>(action), pointer_count); | |
49 } | |
50 | |
51 void SyntheticGestureTargetAndroid::QueueWebTouchEventToPlatform( | |
52 const WebKit::WebTouchEvent& web_touch, const ui::LatencyInfo&) { | |
53 SyntheticGestureTargetAndroid::Action action = | |
jdduke (slow)
2013/10/28 15:59:47
Rather than storing |env_|, just attach here and h
kouhei (in TOK)
2013/10/30 03:18:35
Done.
| |
54 SyntheticGestureTargetAndroid::ActionInvalid; | |
55 switch (web_touch.type) { | |
56 case WebKit::WebInputEvent::TouchStart: | |
57 action = SyntheticGestureTargetAndroid::ActionStart; | |
58 break; | |
59 case WebKit::WebInputEvent::TouchMove: | |
60 action = SyntheticGestureTargetAndroid::ActionMove; | |
61 break; | |
62 case WebKit::WebInputEvent::TouchCancel: | |
63 action = SyntheticGestureTargetAndroid::ActionCancel; | |
64 break; | |
65 case WebKit::WebInputEvent::TouchEnd: | |
66 action = SyntheticGestureTargetAndroid::ActionEnd; | |
67 break; | |
68 default: | |
69 NOTREACHED(); | |
70 } | |
71 const unsigned num_touches = web_touch.touchesLength; | |
72 for (unsigned i = 0; i < num_touches; ++i) { | |
73 const WebKit::WebTouchPoint* point = &web_touch.touches[i]; | |
74 TouchSetPointer(i, point->position.x, point->position.y, point->id); | |
75 } | |
76 | |
77 TouchInject(action, num_touches); | |
78 } | |
79 | |
80 } // namespace content | |
OLD | NEW |