Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
|
David Trainor- moved to gerrit
2017/02/28 01:31:23
Is this file copy and paste from ContentViewCore?
Jinsuk Kim
2017/02/28 06:56:05
Yes |OnTouchEvent| and |OnMouseEvent| are being mo
| |
| 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 "ui/android/event_handler.h" | |
| 6 | |
| 7 #include "base/android/jni_android.h" | |
| 8 #include "base/metrics/histogram_macros.h" | |
| 9 #include "jni/EventHandler_jni.h" | |
| 10 #include "ui/android/view_android.h" | |
| 11 #include "ui/events/android/motion_event_android.h" | |
| 12 | |
| 13 namespace ui { | |
| 14 | |
| 15 using base::android::JavaParamRef; | |
| 16 using base::android::ScopedJavaLocalRef; | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 void RecordToolTypeForActionDown(const MotionEventAndroid& event) { | |
| 21 MotionEventAndroid::Action action = event.GetAction(); | |
| 22 if (action == MotionEventAndroid::ACTION_DOWN || | |
| 23 action == MotionEventAndroid::ACTION_POINTER_DOWN || | |
| 24 action == MotionEventAndroid::ACTION_BUTTON_PRESS) { | |
| 25 UMA_HISTOGRAM_ENUMERATION("Event.AndroidActionDown.ToolType", | |
| 26 event.GetToolType(0), | |
| 27 MotionEventAndroid::TOOL_TYPE_LAST + 1); | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 EventHandler* EventHandler::Create(ViewAndroid* view) { | |
| 34 return new EventHandler(view); | |
| 35 } | |
| 36 | |
| 37 EventHandler::EventHandler(ViewAndroid* view) | |
| 38 : view_(view), dip_scale_(view->GetDipScale()) {} | |
| 39 | |
| 40 ScopedJavaLocalRef<jobject> EventHandler::CreateJavaObject() { | |
| 41 return Java_EventHandler_create(base::android::AttachCurrentThread(), | |
| 42 reinterpret_cast<intptr_t>(this)); | |
| 43 } | |
| 44 | |
| 45 jboolean EventHandler::OnTouchEvent(JNIEnv* env, | |
| 46 const JavaParamRef<jobject>& obj, | |
| 47 const JavaParamRef<jobject>& motion_event, | |
| 48 jlong time_ms, | |
| 49 jint android_action, | |
| 50 jint pointer_count, | |
| 51 jint history_size, | |
| 52 jint action_index, | |
| 53 jfloat pos_x_0, | |
| 54 jfloat pos_y_0, | |
| 55 jfloat pos_x_1, | |
| 56 jfloat pos_y_1, | |
| 57 jint pointer_id_0, | |
| 58 jint pointer_id_1, | |
| 59 jfloat touch_major_0, | |
| 60 jfloat touch_major_1, | |
| 61 jfloat touch_minor_0, | |
| 62 jfloat touch_minor_1, | |
| 63 jfloat orientation_0, | |
| 64 jfloat orientation_1, | |
| 65 jfloat tilt_0, | |
| 66 jfloat tilt_1, | |
| 67 jfloat raw_pos_x, | |
| 68 jfloat raw_pos_y, | |
| 69 jint android_tool_type_0, | |
| 70 jint android_tool_type_1, | |
| 71 jint android_button_state, | |
| 72 jint android_meta_state, | |
| 73 jboolean is_touch_handle_event) { | |
| 74 MotionEventAndroid::Pointer pointer0( | |
| 75 pointer_id_0, pos_x_0, pos_y_0, touch_major_0, touch_minor_0, | |
| 76 orientation_0, tilt_0, android_tool_type_0); | |
| 77 MotionEventAndroid::Pointer pointer1( | |
| 78 pointer_id_1, pos_x_1, pos_y_1, touch_major_1, touch_minor_1, | |
| 79 orientation_1, tilt_1, android_tool_type_1); | |
| 80 MotionEventAndroid event(1.f / dip_scale_, env, motion_event.obj(), time_ms, | |
| 81 android_action, pointer_count, history_size, | |
| 82 action_index, android_button_state, | |
| 83 android_meta_state, raw_pos_x - pos_x_0, | |
| 84 raw_pos_y - pos_y_0, &pointer0, &pointer1); | |
| 85 | |
| 86 RecordToolTypeForActionDown(event); | |
| 87 return view_->OnTouchEvent(event, is_touch_handle_event); | |
| 88 } | |
| 89 | |
| 90 jboolean EventHandler::OnMouseEvent(JNIEnv* env, | |
| 91 const JavaParamRef<jobject>& obj, | |
| 92 jlong time_ms, | |
| 93 jint android_action, | |
| 94 jfloat x, | |
| 95 jfloat y, | |
| 96 jint pointer_id, | |
| 97 jfloat pressure, | |
| 98 jfloat orientation, | |
| 99 jfloat tilt, | |
| 100 jint android_action_button, | |
| 101 jint android_button_state, | |
| 102 jint android_meta_state, | |
| 103 jint android_tool_type) { | |
| 104 // Construct a motion_event object minimally, only to convert the raw | |
| 105 // parameters to ui::MotionEvent values. Since we used only the cached values | |
| 106 // at index=0, it is okay to even pass a null event to the constructor. | |
| 107 MotionEventAndroid::Pointer pointer0(pointer_id, x, y, 0.0f /* touch_major */, | |
| 108 0.0f /* touch_minor */, orientation, | |
| 109 tilt, android_tool_type); | |
| 110 | |
| 111 MotionEventAndroid event( | |
| 112 1.f / dip_scale_, env, nullptr /* event */, time_ms, android_action, | |
| 113 1 /* pointer_count */, 0 /* history_size */, 0 /* action_index */, | |
| 114 android_button_state, android_meta_state, 0 /* raw_offset_x_pixels */, | |
| 115 0 /* raw_offset_y_pixels */, &pointer0, nullptr); | |
| 116 | |
| 117 RecordToolTypeForActionDown(event); | |
| 118 return view_->OnMouseEvent(event, android_action_button); | |
| 119 } | |
| 120 | |
| 121 bool RegisterEventHandler(JNIEnv* env) { | |
| 122 return RegisterNativesImpl(env); | |
| 123 } | |
| 124 | |
| 125 } // namespace ui | |
| OLD | NEW |