| Index: content/browser/renderer_host/synthetic_touch_event_android.cc
|
| diff --git a/content/browser/renderer_host/synthetic_touch_event_android.cc b/content/browser/renderer_host/synthetic_touch_event_android.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..836adc93eb267dbe173af429a2630bb5daf6fef3
|
| --- /dev/null
|
| +++ b/content/browser/renderer_host/synthetic_touch_event_android.cc
|
| @@ -0,0 +1,97 @@
|
| +// Copyright 2013 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/synthetic_touch_event_android.h"
|
| +
|
| +#include "content/browser/android/content_view_core_impl.h"
|
| +#include "jni/SyntheticTouchEvent_jni.h"
|
| +#include "third_party/WebKit/public/web/WebInputEvent.h"
|
| +
|
| +namespace {
|
| +bool g_jni_initialized = false;
|
| +
|
| +void RegisterNativesIfNeeded(JNIEnv* env) {
|
| + if (!g_jni_initialized) {
|
| + content::RegisterNativesImpl(env);
|
| + g_jni_initialized = true;
|
| + }
|
| +}
|
| +} // namespace
|
| +
|
| +namespace content {
|
| +
|
| +SyntheticTouchEventAndroid::SyntheticTouchEventAndroid(
|
| + ContentViewCoreImpl* content_view_core)
|
| + : env_(base::android::AttachCurrentThread()),
|
| + java_touch_event_(content_view_core->CreateSyntheticTouchEvent()),
|
| + saved_down_time_(0) {
|
| + CHECK(! java_touch_event_.is_null());
|
| + RegisterNativesIfNeeded(env_);
|
| +}
|
| +
|
| +SyntheticTouchEventAndroid::~SyntheticTouchEventAndroid() {
|
| +}
|
| +
|
| +void SyntheticTouchEventAndroid::reset() {
|
| + Java_SyntheticTouchEvent_reset(env_, java_touch_event_.obj());
|
| +}
|
| +
|
| +long SyntheticTouchEventAndroid::GetCurrentTime() {
|
| + return Java_SyntheticTouchEvent_getCurrentTime(env_);
|
| +}
|
| +
|
| +void SyntheticTouchEventAndroid::SetDownTime(long downTime) {
|
| + Java_SyntheticTouchEvent_setDownTime(env_, java_touch_event_.obj(),
|
| + downTime);
|
| +}
|
| +
|
| +void SyntheticTouchEventAndroid::AddPointer(int x, int y, int id) {
|
| + Java_SyntheticTouchEvent_addPointer(env_, java_touch_event_.obj(), x, y, id);
|
| +}
|
| +
|
| +void SyntheticTouchEventAndroid::Inject(Action action) {
|
| + Java_SyntheticTouchEvent_inject(env_, java_touch_event_.obj(),
|
| + static_cast<int>(action));
|
| +}
|
| +
|
| +void SyntheticTouchEventAndroid::InjectWebTouchEvent(
|
| + const WebKit::WebTouchEvent* web_touch) {
|
| + reset();
|
| +
|
| + SyntheticTouchEventAndroid::Action action =
|
| + SyntheticTouchEventAndroid::ActionInvalid;
|
| + switch (web_touch->type) {
|
| + case WebKit::WebInputEvent::TouchStart:
|
| + action = SyntheticTouchEventAndroid::ActionStart;
|
| + saved_down_time_ = GetCurrentTime();
|
| + break;
|
| + case WebKit::WebInputEvent::TouchMove:
|
| + action = SyntheticTouchEventAndroid::ActionMove;
|
| + break;
|
| + case WebKit::WebInputEvent::TouchCancel:
|
| + action = SyntheticTouchEventAndroid::ActionCancel;
|
| + break;
|
| + case WebKit::WebInputEvent::TouchEnd:
|
| + action = SyntheticTouchEventAndroid::ActionEnd;
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| + DCHECK(saved_down_time_ > 0);
|
| + SetDownTime(saved_down_time_);
|
| +
|
| + const unsigned num_touches = web_touch->touchesLength;
|
| + for (unsigned i = 0; i < num_touches; ++ i) {
|
| + const WebKit::WebTouchPoint* point = &web_touch->touches[i];
|
| + AddPointer(point->position.x, point->position.y, point->id);
|
| + }
|
| +
|
| + Inject(action);
|
| +
|
| + if (web_touch->type == WebKit::WebInputEvent::TouchCancel ||
|
| + web_touch->type == WebKit::WebInputEvent::TouchEnd)
|
| + saved_down_time_ = 0;
|
| +}
|
| +
|
| +} // namespace content
|
|
|