| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 "blimp/client/core/contents/android/blimp_view.h" | |
| 6 | |
| 7 #include "blimp/client/core/contents/blimp_contents_impl.h" | |
| 8 #include "jni/BlimpView_jni.h" | |
| 9 #include "ui/android/window_android.h" | |
| 10 #include "ui/events/android/motion_event_android.h" | |
| 11 | |
| 12 namespace blimp { | |
| 13 namespace client { | |
| 14 | |
| 15 // static | |
| 16 bool BlimpView::RegisterJni(JNIEnv* env) { | |
| 17 return RegisterNativesImpl(env); | |
| 18 } | |
| 19 | |
| 20 BlimpView::BlimpView(ui::WindowAndroid* window, | |
| 21 BlimpContentsViewImpl* blimp_contents_view) | |
| 22 : blimp_contents_view_(blimp_contents_view) { | |
| 23 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 24 java_obj_.Reset(env, | |
| 25 Java_BlimpView_create(env, reinterpret_cast<intptr_t>(this), | |
| 26 window->GetJavaObject()) | |
| 27 .obj()); | |
| 28 } | |
| 29 | |
| 30 BlimpView::~BlimpView() { | |
| 31 Java_BlimpView_clearNativePtr(base::android::AttachCurrentThread(), | |
| 32 java_obj_); | |
| 33 } | |
| 34 | |
| 35 base::android::ScopedJavaLocalRef<jobject> BlimpView::GetJavaObject() { | |
| 36 return base::android::ScopedJavaLocalRef<jobject>(java_obj_); | |
| 37 } | |
| 38 | |
| 39 base::android::ScopedJavaLocalRef<jobject> | |
| 40 BlimpView::CreateViewAndroidDelegate() { | |
| 41 return Java_BlimpView_createViewAndroidDelegate( | |
| 42 base::android::AttachCurrentThread(), java_obj_); | |
| 43 } | |
| 44 | |
| 45 void BlimpView::OnSizeChanged(JNIEnv* env, | |
| 46 const base::android::JavaParamRef<jobject>& jobj, | |
| 47 jint width, | |
| 48 jint height, | |
| 49 jfloat device_scale_factor_dp_to_px) { | |
| 50 blimp_contents_view_->SetSizeAndScale(gfx::Size(width, height), | |
| 51 device_scale_factor_dp_to_px); | |
| 52 } | |
| 53 | |
| 54 jboolean BlimpView::OnTouchEvent( | |
| 55 JNIEnv* env, | |
| 56 const base::android::JavaParamRef<jobject>& obj, | |
| 57 const base::android::JavaParamRef<jobject>& motion_event, | |
| 58 jlong time_ms, | |
| 59 jint android_action, | |
| 60 jint pointer_count, | |
| 61 jint history_size, | |
| 62 jint action_index, | |
| 63 jfloat pos_x_0, | |
| 64 jfloat pos_y_0, | |
| 65 jfloat pos_x_1, | |
| 66 jfloat pos_y_1, | |
| 67 jint pointer_id_0, | |
| 68 jint pointer_id_1, | |
| 69 jfloat touch_major_0, | |
| 70 jfloat touch_major_1, | |
| 71 jfloat touch_minor_0, | |
| 72 jfloat touch_minor_1, | |
| 73 jfloat orientation_0, | |
| 74 jfloat orientation_1, | |
| 75 jfloat tilt_0, | |
| 76 jfloat tilt_1, | |
| 77 jfloat raw_pos_x, | |
| 78 jfloat raw_pos_y, | |
| 79 jint android_tool_type_0, | |
| 80 jint android_tool_type_1, | |
| 81 jint android_button_state, | |
| 82 jint android_meta_state, | |
| 83 jfloat device_scale_factor_dp_to_px) { | |
| 84 ui::MotionEventAndroid::Pointer pointer0( | |
| 85 pointer_id_0, pos_x_0, pos_y_0, touch_major_0, touch_minor_0, | |
| 86 orientation_0, tilt_0, android_tool_type_0); | |
| 87 ui::MotionEventAndroid::Pointer pointer1( | |
| 88 pointer_id_1, pos_x_1, pos_y_1, touch_major_1, touch_minor_1, | |
| 89 orientation_1, tilt_1, android_tool_type_1); | |
| 90 ui::MotionEventAndroid event( | |
| 91 1.f / device_scale_factor_dp_to_px, env, motion_event, time_ms, | |
| 92 android_action, pointer_count, history_size, action_index, | |
| 93 android_button_state, android_meta_state, raw_pos_x - pos_x_0, | |
| 94 raw_pos_y - pos_y_0, &pointer0, &pointer1); | |
| 95 return blimp_contents_view_->OnTouchEvent(event); | |
| 96 } | |
| 97 | |
| 98 } // namespace client | |
| 99 } // namespace blimp | |
| OLD | NEW |