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

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

Issue 220063002: [Android] Use DIP coordinates with MotionEventAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes Created 6 years, 8 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.h
diff --git a/content/browser/renderer_host/input/motion_event_android.h b/content/browser/renderer_host/input/motion_event_android.h
index bcc9048f4f1c5965db8b8a60986b81b6108eb476..2b7f45f67eb12fa945f8e6235326a326c183ba0f 100644
--- a/content/browser/renderer_host/input/motion_event_android.h
+++ b/content/browser/renderer_host/input/motion_event_android.h
@@ -16,25 +16,28 @@
namespace content {
// Implementation of ui::MotionEvent wrapping a native Android MotionEvent.
+// All *input* coordinates are in device pixels (as with Android MotionEvent),
+// while all *output* coordinates are in DIPs (as with WebTouchEvent).
class MotionEventAndroid : public ui::MotionEvent {
public:
// Forcing the caller to provide all cached values upon construction
// eliminates the need to perform a JNI call to retrieve values individually.
- MotionEventAndroid(JNIEnv* env,
+ MotionEventAndroid(float pix_to_dip,
+ JNIEnv* env,
jobject event,
jlong time_ms,
jint android_action,
jint pointer_count,
jint history_size,
jint action_index,
- jfloat pos_x_0,
- jfloat pos_y_0,
- jfloat pos_x_1,
- jfloat pos_y_1,
+ jfloat pos_x_0_pixels,
+ jfloat pos_y_0_pixels,
+ jfloat pos_x_1_pixels,
+ jfloat pos_y_1_pixels,
jint pointer_id_0,
jint pointer_id_1,
- jfloat touch_major_0,
- jfloat touch_major_1);
+ jfloat touch_major_0_pixels,
+ jfloat touch_major_1_pixels);
virtual ~MotionEventAndroid();
// ui::MotionEvent methods.
@@ -77,15 +80,18 @@ class MotionEventAndroid : public ui::MotionEvent {
base::TimeTicks down_time,
base::TimeTicks event_time,
Action action,
- float x,
- float y);
+ float x_pixels,
+ float y_pixels);
private:
MotionEventAndroid();
- MotionEventAndroid(JNIEnv* env, jobject event);
+ MotionEventAndroid(float pix_to_dip, JNIEnv* env, jobject event);
MotionEventAndroid(const MotionEventAndroid&);
MotionEventAndroid& operator=(const MotionEventAndroid&);
+ float ToDips(float pixels) const;
+ gfx::PointF ToDips(const gfx::PointF& pixels) const;
+
// Cache pointer coords, id's and major lengths for the most common
// touch-related scenarios, i.e., scrolling and pinching. This prevents
// redundant JNI fetches for the same bits.
@@ -103,6 +109,10 @@ class MotionEventAndroid : public ui::MotionEvent {
int cached_pointer_ids_[MAX_POINTERS_TO_CACHE];
float cached_touch_majors_[MAX_POINTERS_TO_CACHE];
+ // Used to convert pixel coordinates from the Java-backed MotionEvent to
+ // DIP coordinates cached/returned by the MotionEventAndroid.
+ const float pix_to_dip_;
+
// Whether |event_| should be recycled on destruction. This will only be true
// for those events generated via |Obtain(...)|.
bool should_recycle_;
« no previous file with comments | « content/browser/android/content_view_core_impl.cc ('k') | content/browser/renderer_host/input/motion_event_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698