Chromium Code Reviews| 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/synthetic_touch_event_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 namespace { | |
| 12 bool g_jni_initialized = false; | |
| 13 | |
| 14 void RegisterNativesIfNeeded(JNIEnv* env) { | |
| 15 if (!g_jni_initialized) { | |
| 16 content::RegisterNativesImpl(env); | |
| 17 g_jni_initialized = true; | |
| 18 } | |
| 19 } | |
| 20 } // namespace | |
| 21 | |
| 22 namespace content { | |
| 23 | |
| 24 SyntheticTouchEventAndroid::SyntheticTouchEventAndroid( | |
| 25 ContentViewCoreImpl* content_view_core) | |
| 26 : env_(base::android::AttachCurrentThread()), | |
| 27 java_touch_event_(content_view_core->CreateSyntheticTouchEvent()) { | |
| 28 CHECK(! java_touch_event_.is_null()); | |
|
Dominik Grewe
2013/10/16 09:22:10
Nit: Remove whitespace between unary operator and
kouhei (in TOK)
2013/10/17 05:44:13
Done.
| |
| 29 RegisterNativesIfNeeded(env_); | |
| 30 } | |
| 31 | |
| 32 SyntheticTouchEventAndroid::~SyntheticTouchEventAndroid() { | |
| 33 } | |
| 34 | |
| 35 void SyntheticTouchEventAndroid::SetPointer(int index, int x, int y, int id) { | |
| 36 Java_SyntheticTouchEvent_setPointer(env_, java_touch_event_.obj(), | |
| 37 index, x, y, id); | |
| 38 } | |
| 39 | |
| 40 void SyntheticTouchEventAndroid::Inject(Action action, int pointer_count) { | |
| 41 Java_SyntheticTouchEvent_inject(env_, java_touch_event_.obj(), | |
| 42 static_cast<int>(action), pointer_count); | |
| 43 } | |
| 44 | |
| 45 void SyntheticTouchEventAndroid::InjectWebTouchEvent( | |
| 46 const WebKit::WebTouchEvent* web_touch) { | |
| 47 SyntheticTouchEventAndroid::Action action = | |
| 48 SyntheticTouchEventAndroid::ActionInvalid; | |
| 49 switch (web_touch->type) { | |
| 50 case WebKit::WebInputEvent::TouchStart: | |
| 51 action = SyntheticTouchEventAndroid::ActionStart; | |
| 52 break; | |
| 53 case WebKit::WebInputEvent::TouchMove: | |
| 54 action = SyntheticTouchEventAndroid::ActionMove; | |
| 55 break; | |
| 56 case WebKit::WebInputEvent::TouchCancel: | |
| 57 action = SyntheticTouchEventAndroid::ActionCancel; | |
| 58 break; | |
| 59 case WebKit::WebInputEvent::TouchEnd: | |
| 60 action = SyntheticTouchEventAndroid::ActionEnd; | |
| 61 break; | |
| 62 default: | |
| 63 NOTREACHED(); | |
| 64 } | |
| 65 const unsigned num_touches = web_touch->touchesLength; | |
| 66 for (unsigned i = 0; i < num_touches; ++ i) { | |
|
Dominik Grewe
2013/10/16 09:22:10
Nit: Same here, remove whitespace between '++' and
kouhei (in TOK)
2013/10/17 05:44:13
Done.
| |
| 67 const WebKit::WebTouchPoint* point = &web_touch->touches[i]; | |
| 68 SetPointer(i, point->position.x, point->position.y, point->id); | |
| 69 } | |
| 70 | |
| 71 Inject(action, num_touches); | |
| 72 } | |
| 73 | |
| 74 } // namespace content | |
| OLD | NEW |