Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/client/android/blimp_view.h" | 5 #include "blimp/client/android/blimp_view.h" |
| 6 | 6 |
| 7 #include "blimp/client/compositor/blimp_compositor_android.h" | 7 #include "blimp/client/compositor/blimp_compositor_android.h" |
| 8 #include "jni/BlimpView_jni.h" | 8 #include "jni/BlimpView_jni.h" |
| 9 #include "ui/events/android/motion_event_android.h" | |
| 10 #include "ui/events/blink/blink_event_util.h" | |
| 11 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" | |
| 9 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
| 13 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 10 | 14 |
| 11 namespace blimp { | 15 namespace blimp { |
| 12 | 16 |
| 13 // static | 17 // static |
| 14 static jlong Init(JNIEnv* env, | 18 static jlong Init(JNIEnv* env, |
| 15 const JavaParamRef<jobject>& jobj, | 19 const JavaParamRef<jobject>& jobj, |
| 16 jint real_width, | 20 jint real_width, |
| 17 jint real_height, | 21 jint real_height, |
| 18 jint width, | 22 jint width, |
| 19 jint height, | 23 jint height, |
| 20 jfloat dp_to_px) { | 24 jfloat dp_to_px) { |
| 21 return reinterpret_cast<intptr_t>( | 25 return reinterpret_cast<intptr_t>( |
| 22 new BlimpView(env, jobj, gfx::Size(real_width, real_height), | 26 new BlimpView(env, jobj, gfx::Size(real_width, real_height), |
| 23 gfx::Size(width, height), dp_to_px)); | 27 gfx::Size(width, height), dp_to_px)); |
| 24 } | 28 } |
| 25 | 29 |
| 26 // static | 30 // static |
| 27 bool BlimpView::RegisterJni(JNIEnv* env) { | 31 bool BlimpView::RegisterJni(JNIEnv* env) { |
| 28 return RegisterNativesImpl(env); | 32 return RegisterNativesImpl(env); |
| 29 } | 33 } |
| 30 | 34 |
| 31 BlimpView::BlimpView(JNIEnv* env, | 35 BlimpView::BlimpView(JNIEnv* env, |
| 32 const JavaParamRef<jobject>& jobj, | 36 const JavaParamRef<jobject>& jobj, |
| 33 const gfx::Size& real_size, | 37 const gfx::Size& real_size, |
| 34 const gfx::Size& size, | 38 const gfx::Size& size, |
| 35 float dp_to_px) | 39 float dp_to_px) |
| 36 : compositor_(BlimpCompositorAndroid::Create(real_size, size, dp_to_px)), | 40 : device_scale_factor_(dp_to_px), |
| 41 compositor_(BlimpCompositorAndroid::Create(real_size, size, dp_to_px)), | |
| 42 // TODO(khushalsagar): Verify if any default configurations need to be | |
| 43 // changed. | |
| 44 gesture_provider_(ui::GetGestureProviderConfig( | |
| 45 ui::GestureProviderConfigType::CURRENT_PLATFORM), this), | |
| 37 current_surface_format_(0) { | 46 current_surface_format_(0) { |
| 38 java_obj_.Reset(env, jobj); | 47 java_obj_.Reset(env, jobj); |
| 39 } | 48 } |
| 40 | 49 |
| 41 BlimpView::~BlimpView() {} | 50 BlimpView::~BlimpView() {} |
| 42 | 51 |
| 43 void BlimpView::Destroy(JNIEnv* env, jobject jobj) { | 52 void BlimpView::Destroy(JNIEnv* env, jobject jobj) { |
| 44 delete this; | 53 delete this; |
| 45 } | 54 } |
| 46 | 55 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 66 | 75 |
| 67 void BlimpView::OnSurfaceDestroyed(JNIEnv* env, jobject jobj) { | 76 void BlimpView::OnSurfaceDestroyed(JNIEnv* env, jobject jobj) { |
| 68 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; | 77 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; |
| 69 compositor_->SetSurface(env, 0 /** nullptr jobject */); | 78 compositor_->SetSurface(env, 0 /** nullptr jobject */); |
| 70 } | 79 } |
| 71 | 80 |
| 72 void BlimpView::SetVisibility(JNIEnv* env, jobject jobj, jboolean visible) { | 81 void BlimpView::SetVisibility(JNIEnv* env, jobject jobj, jboolean visible) { |
| 73 compositor_->SetVisible(visible); | 82 compositor_->SetVisible(visible); |
| 74 } | 83 } |
| 75 | 84 |
| 85 jboolean BlimpView::OnTouchEvent(JNIEnv* env, | |
| 86 jobject obj, | |
| 87 jobject motion_event, | |
| 88 jlong time_ms, | |
| 89 jint android_action, | |
| 90 jint pointer_count, | |
| 91 jint history_size, | |
| 92 jint action_index, | |
| 93 jfloat pos_x_0, | |
| 94 jfloat pos_y_0, | |
| 95 jfloat pos_x_1, | |
| 96 jfloat pos_y_1, | |
| 97 jint pointer_id_0, | |
| 98 jint pointer_id_1, | |
| 99 jfloat touch_major_0, | |
| 100 jfloat touch_major_1, | |
| 101 jfloat touch_minor_0, | |
| 102 jfloat touch_minor_1, | |
| 103 jfloat orientation_0, | |
| 104 jfloat orientation_1, | |
| 105 jfloat raw_pos_x, | |
| 106 jfloat raw_pos_y, | |
| 107 jint android_tool_type_0, | |
| 108 jint android_tool_type_1, | |
| 109 jint android_button_state, | |
| 110 jint android_meta_state) { | |
| 111 | |
| 112 ui::MotionEventAndroid::Pointer pointer0(pointer_id_0, | |
| 113 pos_x_0, | |
|
David Trainor- moved to gerrit
2015/11/02 16:55:30
fix indentation. Same for all other MotionEventAn
Khushal
2015/12/01 08:22:25
Done.
| |
| 114 pos_y_0, | |
| 115 touch_major_0, | |
| 116 touch_minor_0, | |
| 117 orientation_0, | |
| 118 android_tool_type_0); | |
| 119 ui::MotionEventAndroid::Pointer pointer1(pointer_id_1, | |
| 120 pos_x_1, | |
| 121 pos_y_1, | |
| 122 touch_major_1, | |
| 123 touch_minor_1, | |
| 124 orientation_1, | |
| 125 android_tool_type_1); | |
| 126 ui::MotionEventAndroid event(1.f / device_scale_factor_, | |
| 127 env, | |
| 128 motion_event, | |
| 129 time_ms, | |
| 130 android_action, | |
| 131 pointer_count, | |
| 132 history_size, | |
| 133 action_index, | |
| 134 android_button_state, | |
| 135 android_meta_state, | |
| 136 raw_pos_x - pos_x_0, | |
| 137 raw_pos_y - pos_y_0, | |
| 138 pointer0, | |
| 139 pointer1); | |
| 140 | |
| 141 ui::FilteredGestureProvider::TouchHandlingResult result = | |
| 142 gesture_provider_.OnTouchEvent(event); | |
| 143 if (!result.succeeded) | |
|
David Trainor- moved to gerrit
2015/11/02 16:55:30
indentation
Khushal
2015/12/01 08:22:25
Moved to BlimpInputManager.
| |
| 144 return false; | |
| 145 | |
| 146 blink::WebTouchEvent web_event = | |
| 147 ui::CreateWebTouchEventFromMotionEvent(event, result.did_generate_scroll); | |
| 148 | |
| 149 // Touch events are queued in the Gesture Provider until acknowledged to | |
| 150 // allow them to be consumed by the touch event handlers in blink which can | |
| 151 // prevent-default on the event. Since we currently do not support touch | |
| 152 // handlers the event is always acknowledged as not consumed. | |
| 153 // TODO(khushalsagar): Add support for touch events to blink. | |
|
David Trainor- moved to gerrit
2015/11/02 16:55:30
s/blink/blimp?
Khushal
2015/12/01 08:22:25
Moved to BlimpInputManager.
| |
| 154 gesture_provider_.OnTouchEventAck(web_event.uniqueTouchEventId, false); | |
| 155 | |
| 156 return true; | |
| 157 } | |
| 158 | |
| 159 void BlimpView::OnGestureEvent(const ui::GestureEventData& gesture) { | |
| 160 blink::WebGestureEvent web_gesture = | |
| 161 ui::CreateWebGestureEventFromGestureEventData(gesture); | |
| 162 // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to | |
| 163 // stop providing shift meta values to synthetic MotionEvents. This prevents | |
| 164 // unintended shift+click interpretation of all accessibility clicks. | |
| 165 // See crbug.com/443247. | |
| 166 if (web_gesture.type == blink::WebInputEvent::GestureTap && | |
| 167 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) { | |
| 168 web_gesture.modifiers = 0; | |
| 169 } | |
| 170 | |
| 171 // TODO(khushalsagar): Use the GestureEventQueue. | |
|
David Trainor- moved to gerrit
2015/11/02 16:55:30
TODO: Push the event to the compositor?
Khushal
2015/12/01 08:22:25
Done. Moved to BlimpInputManager.
| |
| 172 } | |
| 173 | |
| 76 } // namespace blimp | 174 } // namespace blimp |
| OLD | NEW |