Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(531)

Unified Diff: content/browser/renderer_host/input/motion_event_android.cc

Issue 181833003: [Android] Out with the Android GR, in with the new unified C++ GR (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/input/motion_event_android.cc
diff --git a/content/browser/renderer_host/input/motion_event_android.cc b/content/browser/renderer_host/input/motion_event_android.cc
index d5c3861134ffec4dd273083dc37322c5f637799f..7494d908fc1f3f39e59cc5b18f2265e8c79b9ec9 100644
--- a/content/browser/renderer_host/input/motion_event_android.cc
+++ b/content/browser/renderer_host/input/motion_event_android.cc
@@ -13,15 +13,40 @@ using namespace JNI_MotionEvent;
namespace content {
namespace {
-MotionEventAndroid::Action FromAndroidAction(int android_action) {
- switch (android_action) {
+int ToAndroidAction(MotionEventAndroid::Action action) {
+ switch (action) {
case MotionEventAndroid::ACTION_DOWN:
+ return ACTION_DOWN;
case MotionEventAndroid::ACTION_UP:
+ return ACTION_UP;
case MotionEventAndroid::ACTION_MOVE:
+ return ACTION_MOVE;
case MotionEventAndroid::ACTION_CANCEL:
+ return ACTION_CANCEL;
case MotionEventAndroid::ACTION_POINTER_DOWN:
+ return ACTION_POINTER_DOWN;
case MotionEventAndroid::ACTION_POINTER_UP:
- return static_cast<MotionEventAndroid::Action>(android_action);
+ return ACTION_POINTER_UP;
+ };
+ NOTREACHED() << "Invalid Android MotionEvent type for gesture detection: "
+ << action;
+ return ACTION_CANCEL;
+}
+
+MotionEventAndroid::Action FromAndroidAction(int android_action) {
+ switch (android_action) {
+ case ACTION_DOWN:
+ return MotionEventAndroid::ACTION_DOWN;
+ case ACTION_UP:
+ return MotionEventAndroid::ACTION_UP;
+ case ACTION_MOVE:
+ return MotionEventAndroid::ACTION_MOVE;
+ case ACTION_CANCEL:
+ return MotionEventAndroid::ACTION_CANCEL;
+ case ACTION_POINTER_DOWN:
+ return MotionEventAndroid::ACTION_POINTER_DOWN;
+ case ACTION_POINTER_UP:
+ return MotionEventAndroid::ACTION_POINTER_UP;
default:
NOTREACHED() << "Invalid Android MotionEvent type for gesture detection: "
<< android_action;
@@ -39,18 +64,36 @@ base::TimeTicks FromAndroidTime(int64 time_ms) {
} // namespace
-MotionEventAndroid::MotionEventAndroid(jobject event)
- : should_recycle_(false) {
- event_.Reset(AttachCurrentThread(), event);
+MotionEventAndroid::MotionEventAndroid(JNIEnv* env, jobject event, bool recycle)
+ : cached_time_(FromAndroidTime(Java_MotionEvent_getEventTime(env, event))),
+ cached_action_(FromAndroidAction(
+ Java_MotionEvent_getActionMasked(env, event))),
+ cached_pointer_count_(Java_MotionEvent_getPointerCount(env, event)),
+ cached_history_size_(Java_MotionEvent_getHistorySize(env, event)),
+ cached_action_index_(Java_MotionEvent_getActionIndex(env, event)),
+ cached_x_(Java_MotionEvent_getXF(env, event)),
+ cached_y_(Java_MotionEvent_getYF(env, event)),
+ should_recycle_(recycle) {
+ event_.Reset(env, event);
DCHECK(event_.obj());
}
-MotionEventAndroid::MotionEventAndroid(
- const base::android::ScopedJavaLocalRef<jobject>& event,
- bool should_recycle)
- : event_(event),
- should_recycle_(should_recycle) {
- DCHECK(event_.obj());
+MotionEventAndroid::MotionEventAndroid(const MotionEventAndroid& other,
+ bool clone)
+ : cached_time_(other.cached_time_),
+ cached_action_(other.cached_action_),
+ cached_pointer_count_(other.cached_pointer_count_),
+ cached_history_size_(other.cached_history_size_),
+ cached_action_index_(other.cached_action_index_),
+ cached_x_(other.cached_x_),
+ cached_y_(other.cached_y_),
+ should_recycle_(clone) {
+ // An event with a pending recycle should never be copied (only cloned).
+ DCHECK(clone || !other.should_recycle_);
+ if (clone)
+ event_.Reset(Obtain(other));
+ else
+ event_.Reset(other.event_);
}
MotionEventAndroid::~MotionEventAndroid() {
@@ -58,65 +101,52 @@ MotionEventAndroid::~MotionEventAndroid() {
Java_MotionEvent_recycle(AttachCurrentThread(), event_.obj());
}
-MotionEventAndroid::Action MotionEventAndroid::GetActionMasked() const {
- return FromAndroidAction(
- Java_MotionEvent_getActionMasked(AttachCurrentThread(), event_.obj()));
+MotionEventAndroid::Action MotionEventAndroid::GetAction() const {
+ return cached_action_;
}
-size_t MotionEventAndroid::GetActionIndex() const {
- return Java_MotionEvent_getActionIndex(AttachCurrentThread(), event_.obj());
+int MotionEventAndroid::GetActionIndex() const {
+ return cached_action_index_;
}
size_t MotionEventAndroid::GetPointerCount() const {
- return Java_MotionEvent_getPointerCount(AttachCurrentThread(), event_.obj());
+ return cached_pointer_count_;
}
int MotionEventAndroid::GetPointerId(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, cached_pointer_count_);
return Java_MotionEvent_getPointerId(
AttachCurrentThread(), event_.obj(), pointer_index);
}
-float MotionEventAndroid::GetPressure(size_t pointer_index) const {
- return Java_MotionEvent_getPressureF_I(
- AttachCurrentThread(), event_.obj(), pointer_index);
-}
-
float MotionEventAndroid::GetX(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, cached_pointer_count_);
+ if (pointer_index == 0)
+ return cached_x_;
return Java_MotionEvent_getXF_I(
AttachCurrentThread(), event_.obj(), pointer_index);
}
float MotionEventAndroid::GetY(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, cached_pointer_count_);
+ if (pointer_index == 0)
+ return cached_y_;
return Java_MotionEvent_getYF_I(
AttachCurrentThread(), event_.obj(), pointer_index);
}
float MotionEventAndroid::GetTouchMajor(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, cached_pointer_count_);
return Java_MotionEvent_getTouchMajorF_I(
AttachCurrentThread(), event_.obj(), pointer_index);
}
-float MotionEventAndroid::GetTouchMinor(size_t pointer_index) const {
- return Java_MotionEvent_getTouchMinorF_I(
- AttachCurrentThread(), event_.obj(), pointer_index);
-}
-
-float MotionEventAndroid::GetOrientation() const {
- return Java_MotionEvent_getOrientationF(AttachCurrentThread(), event_.obj());
-}
-
base::TimeTicks MotionEventAndroid::GetEventTime() const {
- return FromAndroidTime(
- Java_MotionEvent_getEventTime(AttachCurrentThread(), event_.obj()));
-}
-
-base::TimeTicks MotionEventAndroid::GetDownTime() const {
- return FromAndroidTime(
- Java_MotionEvent_getDownTime(AttachCurrentThread(), event_.obj()));
+ return cached_time_;
}
size_t MotionEventAndroid::GetHistorySize() const {
- return Java_MotionEvent_getHistorySize(AttachCurrentThread(), event_.obj());
+ return cached_history_size_;
}
base::TimeTicks MotionEventAndroid::GetHistoricalEventTime(
@@ -144,36 +174,66 @@ float MotionEventAndroid::GetHistoricalY(size_t pointer_index,
AttachCurrentThread(), event_.obj(), pointer_index, historical_index);
}
+scoped_ptr<ui::MotionEvent> MotionEventAndroid::Clone() const {
+ return scoped_ptr<MotionEvent>(new MotionEventAndroid(*this, true));
+}
+
+scoped_ptr<ui::MotionEvent> MotionEventAndroid::Cancel() const {
+ return scoped_ptr<MotionEvent>(new MotionEventAndroid(
+ AttachCurrentThread(),
+ Obtain(GetDownTime(),
+ GetEventTime(),
+ MotionEventAndroid::ACTION_CANCEL,
+ GetX(0),
+ GetY(0)).obj(),
+ true));
+}
+
+float MotionEventAndroid::GetPressure(size_t pointer_index) const {
+ return Java_MotionEvent_getPressureF_I(
+ AttachCurrentThread(), event_.obj(), pointer_index);
+}
+
+float MotionEventAndroid::GetTouchMinor(size_t pointer_index) const {
+ return Java_MotionEvent_getTouchMinorF_I(
+ AttachCurrentThread(), event_.obj(), pointer_index);
+}
+
+float MotionEventAndroid::GetOrientation() const {
+ return Java_MotionEvent_getOrientationF(AttachCurrentThread(), event_.obj());
+}
+
+base::TimeTicks MotionEventAndroid::GetDownTime() const {
+ return FromAndroidTime(
+ Java_MotionEvent_getDownTime(AttachCurrentThread(), event_.obj()));
+}
+
// static
bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) {
return JNI_MotionEvent::RegisterNativesImpl(env);
}
// static
-scoped_ptr<MotionEventAndroid> MotionEventAndroid::Obtain(
+base::android::ScopedJavaLocalRef<jobject> MotionEventAndroid::Obtain(
const MotionEventAndroid& event) {
- return make_scoped_ptr(new MotionEventAndroid(
- Java_MotionEvent_obtainAVME_AVME(AttachCurrentThread(),
- event.event_.obj()),
- true));
+ return Java_MotionEvent_obtainAVME_AVME(AttachCurrentThread(),
+ event.event_.obj());
}
// static
-scoped_ptr<MotionEventAndroid> MotionEventAndroid::Obtain(
+base::android::ScopedJavaLocalRef<jobject> MotionEventAndroid::Obtain(
base::TimeTicks down_time,
- base::TimeTicks event__time,
+ base::TimeTicks event_time,
Action action,
float x,
float y) {
- return make_scoped_ptr(new MotionEventAndroid(
- Java_MotionEvent_obtainAVME_J_J_I_F_F_I(AttachCurrentThread(),
- ToAndroidTime(down_time),
- ToAndroidTime(down_time),
- action,
- x,
- y,
- 0),
- true));
+ return Java_MotionEvent_obtainAVME_J_J_I_F_F_I(AttachCurrentThread(),
+ ToAndroidTime(down_time),
+ ToAndroidTime(event_time),
+ ToAndroidAction(action),
+ x,
+ y,
+ 0);
}
} // namespace content
« no previous file with comments | « content/browser/renderer_host/input/motion_event_android.h ('k') | content/browser/renderer_host/input/motion_event_web.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698