Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 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 "jni/EventHandler_jni.h" | |
| 8 #include "ui/android/view_android.h" | |
| 9 #include "ui/android/view_client.h" | |
| 10 #include "ui/events/android/motion_event_android.h" | |
| 11 | |
| 12 namespace ui { | |
| 13 | |
| 14 using base::android::JavaParamRef; | |
| 15 using base::android::ScopedJavaLocalRef; | |
| 16 | |
| 17 EventHandler::EventHandler(ViewAndroid* view) : view_(view) {} | |
| 18 | |
| 19 EventHandler::~EventHandler() { | |
|
Khushal
2017/03/03 23:36:07
Clear the native ptr in java.
Jinsuk Kim
2017/03/06 04:07:33
Done.
| |
| 20 java_obj_.Reset(); | |
| 21 } | |
| 22 | |
| 23 ScopedJavaLocalRef<jobject> EventHandler::GetJavaObject() { | |
| 24 if (java_obj_.is_null()) { | |
| 25 java_obj_.Reset( | |
| 26 Java_EventHandler_create(base::android::AttachCurrentThread(), | |
| 27 reinterpret_cast<intptr_t>(this))); | |
| 28 } | |
| 29 return ScopedJavaLocalRef<jobject>(java_obj_); | |
| 30 } | |
| 31 | |
| 32 jboolean EventHandler::OnTouchEvent(JNIEnv* env, | |
| 33 const JavaParamRef<jobject>& obj, | |
| 34 const JavaParamRef<jobject>& motion_event, | |
| 35 jlong time_ms, | |
| 36 jint android_action, | |
| 37 jint pointer_count, | |
| 38 jint history_size, | |
| 39 jint action_index, | |
| 40 jfloat pos_x_0, | |
| 41 jfloat pos_y_0, | |
| 42 jfloat pos_x_1, | |
| 43 jfloat pos_y_1, | |
| 44 jint pointer_id_0, | |
| 45 jint pointer_id_1, | |
| 46 jfloat touch_major_0, | |
| 47 jfloat touch_major_1, | |
| 48 jfloat touch_minor_0, | |
| 49 jfloat touch_minor_1, | |
| 50 jfloat orientation_0, | |
| 51 jfloat orientation_1, | |
| 52 jfloat tilt_0, | |
| 53 jfloat tilt_1, | |
| 54 jfloat raw_pos_x, | |
| 55 jfloat raw_pos_y, | |
| 56 jint android_tool_type_0, | |
| 57 jint android_tool_type_1, | |
| 58 jint android_button_state, | |
| 59 jint android_meta_state, | |
| 60 jboolean is_touch_handle_event) { | |
| 61 ui::MotionEventAndroid::Pointer pointer0( | |
| 62 pointer_id_0, pos_x_0, pos_y_0, touch_major_0, touch_minor_0, | |
| 63 orientation_0, tilt_0, android_tool_type_0); | |
| 64 ui::MotionEventAndroid::Pointer pointer1( | |
| 65 pointer_id_1, pos_x_1, pos_y_1, touch_major_1, touch_minor_1, | |
| 66 orientation_1, tilt_1, android_tool_type_1); | |
| 67 ui::MotionEventAndroid event( | |
| 68 1.f / view_->GetDipScale(), env, motion_event.obj(), time_ms, | |
| 69 android_action, pointer_count, history_size, action_index, | |
| 70 0 /* action_button */, android_button_state, android_meta_state, | |
| 71 raw_pos_x - pos_x_0, raw_pos_y - pos_y_0, &pointer0, &pointer1); | |
| 72 return view_->OnTouchEvent(event, is_touch_handle_event); | |
| 73 } | |
| 74 | |
| 75 void EventHandler::OnMouseEvent(JNIEnv* env, | |
| 76 const JavaParamRef<jobject>& obj, | |
| 77 jlong time_ms, | |
| 78 jint android_action, | |
| 79 jfloat x, | |
| 80 jfloat y, | |
| 81 jint pointer_id, | |
| 82 jfloat orientation, | |
| 83 jfloat pressure, | |
| 84 jfloat tilt, | |
| 85 jint android_action_button, | |
| 86 jint android_button_state, | |
| 87 jint android_meta_state, | |
| 88 jint android_tool_type) { | |
| 89 // Construct a motion_event object minimally, only to convert the raw | |
| 90 // parameters to ui::MotionEvent values. Since we used only the cached values | |
| 91 // at index=0, it is okay to even pass a null event to the constructor. | |
| 92 ui::MotionEventAndroid::Pointer pointer( | |
| 93 pointer_id, x, y, 0.0f /* touch_major */, 0.0f /* touch_minor */, | |
| 94 orientation, tilt, android_tool_type); | |
| 95 ui::MotionEventAndroid event( | |
| 96 1.f / view_->GetDipScale(), env, nullptr /* event */, time_ms, | |
| 97 android_action, 1 /* pointer_count */, 0 /* history_size */, | |
| 98 0 /* action_index */, android_action_button, android_button_state, | |
| 99 android_meta_state, 0 /* raw_offset_x_pixels */, | |
| 100 0 /* raw_offset_y_pixels */, &pointer, nullptr); | |
| 101 view_->OnMouseEvent(event); | |
| 102 } | |
| 103 | |
| 104 bool RegisterEventHandler(JNIEnv* env) { | |
| 105 return RegisterNativesImpl(env); | |
| 106 } | |
| 107 | |
| 108 } // namespace ui | |
| OLD | NEW |