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

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

Issue 321563002: Support minimum gesture bounds in GestureProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 6 years, 6 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 c0f1721480eec0359c0b928d3516d983ceac0eb3..cf9c31fb3fcf760cf94b0aa0fc991aa410f5c11d 100644
--- a/content/browser/renderer_host/input/motion_event_android.cc
+++ b/content/browser/renderer_host/input/motion_event_android.cc
@@ -62,6 +62,18 @@ base::TimeTicks FromAndroidTime(int64 time_ms) {
return base::TimeTicks() + base::TimeDelta::FromMilliseconds(time_ms);
}
+float GetMinTouchMajorDipsForTool(int android_tool_type) {
+ switch (android_tool_type) {
+ case TOOL_TYPE_MOUSE:
+ case TOOL_TYPE_STYLUS:
+ return 0.f;
+ default:
+ // This value is somewhat arbitrarily chosen, but was used with success in
+ // the old gesture detection pipeline.
+ return 24.f;
+ };
+}
+
} // namespace
MotionEventAndroid::MotionEventAndroid(float pix_to_dip,
@@ -79,13 +91,15 @@ MotionEventAndroid::MotionEventAndroid(float pix_to_dip,
jint pointer_id_0,
jint pointer_id_1,
jfloat touch_major_0_pixels,
- jfloat touch_major_1_pixels)
+ jfloat touch_major_1_pixels,
+ jint tool_type)
: cached_time_(FromAndroidTime(time_ms)),
cached_action_(FromAndroidAction(android_action)),
cached_pointer_count_(pointer_count),
cached_history_size_(history_size),
cached_action_index_(action_index),
pix_to_dip_(pix_to_dip),
+ min_touch_major_dips_(GetMinTouchMajorDipsForTool(tool_type)),
should_recycle_(false) {
DCHECK_GT(pointer_count, 0);
DCHECK_GE(history_size, 0);
@@ -102,6 +116,7 @@ MotionEventAndroid::MotionEventAndroid(float pix_to_dip,
}
MotionEventAndroid::MotionEventAndroid(float pix_to_dip,
+ float min_touch_major_dips_,
JNIEnv* env,
jobject event)
: cached_time_(FromAndroidTime(Java_MotionEvent_getEventTime(env, event))),
@@ -111,6 +126,7 @@ MotionEventAndroid::MotionEventAndroid(float pix_to_dip,
cached_history_size_(Java_MotionEvent_getHistorySize(env, event)),
cached_action_index_(Java_MotionEvent_getActionIndex(env, event)),
pix_to_dip_(pix_to_dip),
+ min_touch_major_dips_(min_touch_major_dips_),
should_recycle_(true) {
event_.Reset(env, event);
DCHECK(event_.obj());
@@ -138,6 +154,7 @@ MotionEventAndroid::MotionEventAndroid(const MotionEventAndroid& other)
cached_history_size_(other.cached_history_size_),
cached_action_index_(other.cached_action_index_),
pix_to_dip_(other.pix_to_dip_),
+ min_touch_major_dips_(other.min_touch_major_dips_),
should_recycle_(true) {
DCHECK(event_.obj());
for (size_t i = 0; i < MAX_POINTERS_TO_CACHE; ++i) {
@@ -191,11 +208,7 @@ float MotionEventAndroid::GetY(size_t pointer_index) const {
}
float MotionEventAndroid::GetTouchMajor(size_t pointer_index) const {
- DCHECK_LT(pointer_index, cached_pointer_count_);
- if (pointer_index < MAX_POINTERS_TO_CACHE)
- return cached_touch_majors_[pointer_index];
- return ToDips(Java_MotionEvent_getTouchMajorF_I(
- AttachCurrentThread(), event_.obj(), pointer_index));
+ return std::max(min_touch_major_dips_, GetRawTouchMajor(pointer_index));
}
float MotionEventAndroid::GetPressure(size_t pointer_index) const {
@@ -221,8 +234,12 @@ base::TimeTicks MotionEventAndroid::GetHistoricalEventTime(
float MotionEventAndroid::GetHistoricalTouchMajor(
size_t pointer_index,
size_t historical_index) const {
- return ToDips(Java_MotionEvent_getHistoricalTouchMajorF_I_I(
- AttachCurrentThread(), event_.obj(), pointer_index, historical_index));
+ return std::max(min_touch_major_dips_,
+ ToDips(Java_MotionEvent_getHistoricalTouchMajorF_I_I(
+ AttachCurrentThread(),
+ event_.obj(),
+ pointer_index,
+ historical_index)));
}
float MotionEventAndroid::GetHistoricalX(size_t pointer_index,
@@ -248,6 +265,7 @@ scoped_ptr<ui::MotionEvent> MotionEventAndroid::Cancel() const {
gfx::ScalePoint(cached_positions_[0], 1.f / pix_to_dip_);
return scoped_ptr<MotionEvent>(
new MotionEventAndroid(pix_to_dip_,
+ min_touch_major_dips_,
AttachCurrentThread(),
Obtain(GetDownTime(),
GetEventTime(),
@@ -256,7 +274,15 @@ scoped_ptr<ui::MotionEvent> MotionEventAndroid::Cancel() const {
position_pixels.y()).obj()));
}
-float MotionEventAndroid::GetTouchMinor(size_t pointer_index) const {
+float MotionEventAndroid::GetRawTouchMajor(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, cached_pointer_count_);
+ if (pointer_index < MAX_POINTERS_TO_CACHE)
+ return cached_touch_majors_[pointer_index];
+ return ToDips(Java_MotionEvent_getTouchMajorF_I(
+ AttachCurrentThread(), event_.obj(), pointer_index));
+}
+
+float MotionEventAndroid::GetRawTouchMinor(size_t pointer_index) const {
return ToDips(Java_MotionEvent_getTouchMinorF_I(
AttachCurrentThread(), event_.obj(), pointer_index));
}

Powered by Google App Engine
This is Rietveld 408576698