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