| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/android/vr_shell/android_ui_gesture_target.h" | 5 #include "chrome/browser/android/vr_shell/android_ui_gesture_target.h" |
| 6 | 6 |
| 7 #include "jni/MotionEventSynthesizer_jni.h" | 7 #include "jni/MotionEventSynthesizer_jni.h" |
| 8 | 8 |
| 9 namespace vr_shell { | 9 namespace vr_shell { |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 Inject(env, Action::HoverEnter, gesture->TimeStampSeconds()); | 64 Inject(env, Action::HoverEnter, gesture->TimeStampSeconds()); |
| 65 break; | 65 break; |
| 66 case blink::WebMouseEvent::kMouseMove: | 66 case blink::WebMouseEvent::kMouseMove: |
| 67 SetPointer(env, mouse->PositionInWidget().x, mouse->PositionInWidget().y); | 67 SetPointer(env, mouse->PositionInWidget().x, mouse->PositionInWidget().y); |
| 68 Inject(env, Action::HoverMove, gesture->TimeStampSeconds()); | 68 Inject(env, Action::HoverMove, gesture->TimeStampSeconds()); |
| 69 break; | 69 break; |
| 70 case blink::WebMouseEvent::kMouseLeave: | 70 case blink::WebMouseEvent::kMouseLeave: |
| 71 SetPointer(env, mouse->PositionInWidget().x, mouse->PositionInWidget().y); | 71 SetPointer(env, mouse->PositionInWidget().x, mouse->PositionInWidget().y); |
| 72 Inject(env, Action::HoverExit, gesture->TimeStampSeconds()); | 72 Inject(env, Action::HoverExit, gesture->TimeStampSeconds()); |
| 73 break; | 73 break; |
| 74 case blink::WebMouseEvent::kMouseDown: |
| 75 // Mouse down events are translated into touch events on Android anyways, |
| 76 // so we can just send touch events. |
| 77 // We intentionally don't support long press or drags/swipes with mouse |
| 78 // input as this could trigger long press and open 2D popups. |
| 79 SetPointer(env, mouse->PositionInWidget().x, mouse->PositionInWidget().y); |
| 80 Inject(env, Action::Start, gesture->TimeStampSeconds()); |
| 81 Inject(env, Action::End, gesture->TimeStampSeconds()); |
| 82 break; |
| 83 case blink::WebMouseEvent::kMouseUp: |
| 84 // No need to do anything for mouseUp as mouseDown already handled up. |
| 85 break; |
| 74 default: | 86 default: |
| 75 NOTREACHED(); | 87 NOTREACHED() << "Unsupported event type sent to Android UI."; |
| 76 break; | 88 break; |
| 77 } | 89 } |
| 78 } | 90 } |
| 79 | 91 |
| 80 void AndroidUiGestureTarget::SetPointer(JNIEnv* env, int x, int y) { | 92 void AndroidUiGestureTarget::SetPointer(JNIEnv* env, int x, int y) { |
| 81 content::Java_MotionEventSynthesizer_setPointer(env, event_synthesizer_, 0, x, | 93 content::Java_MotionEventSynthesizer_setPointer(env, event_synthesizer_, 0, x, |
| 82 y, 0); | 94 y, 0); |
| 83 } | 95 } |
| 84 | 96 |
| 85 void AndroidUiGestureTarget::SetScrollDeltas(JNIEnv* env, | 97 void AndroidUiGestureTarget::SetScrollDeltas(JNIEnv* env, |
| 86 int x, | 98 int x, |
| 87 int y, | 99 int y, |
| 88 int dx, | 100 int dx, |
| 89 int dy) { | 101 int dy) { |
| 90 content::Java_MotionEventSynthesizer_setScrollDeltas(env, event_synthesizer_, | 102 content::Java_MotionEventSynthesizer_setScrollDeltas(env, event_synthesizer_, |
| 91 x, y, dx, dy); | 103 x, y, dx, dy); |
| 92 } | 104 } |
| 93 | 105 |
| 94 void AndroidUiGestureTarget::Inject(JNIEnv* env, | 106 void AndroidUiGestureTarget::Inject(JNIEnv* env, |
| 95 Action action, | 107 Action action, |
| 96 double time_in_seconds) { | 108 double time_in_seconds) { |
| 97 content::Java_MotionEventSynthesizer_inject( | 109 content::Java_MotionEventSynthesizer_inject( |
| 98 env, event_synthesizer_, static_cast<int>(action), 1, | 110 env, event_synthesizer_, static_cast<int>(action), 1, |
| 99 static_cast<int64_t>(time_in_seconds * 1000.0)); | 111 static_cast<int64_t>(time_in_seconds * 1000.0)); |
| 100 } | 112 } |
| 101 | 113 |
| 102 } // namespace vr_shell | 114 } // namespace vr_shell |
| OLD | NEW |