Chromium Code Reviews| 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 "base/android/scoped_java_ref.h" | |
| 6 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | |
| 7 | |
| 8 using blink::WebGestureEvent; | |
| 9 using blink::WebMouseEvent; | |
| 10 using blink::WebInputEvent; | |
| 11 | |
| 12 namespace vr_shell { | |
| 13 | |
| 14 VrInputManager::VrInputManager(content::ContentViewCore* content_view_core) | |
|
boliu
2016/09/22 23:25:36
suggestion: build on to of WebContents, since CVC
asimjour
2016/09/23 16:58:21
Done.
| |
| 15 : content_view_core_(content_view_core) { | |
| 16 dpi_scale_ = 1; | |
| 17 } | |
| 18 | |
| 19 VrInputManager::~VrInputManager() {} | |
| 20 | |
| 21 void VrInputManager::ScrollBegin(long time_ms, | |
| 22 float x, | |
| 23 float y, | |
| 24 float hintx, | |
| 25 float hinty, | |
| 26 bool target_viewport) { | |
| 27 WebGestureEvent event = | |
| 28 MakeGestureEvent(WebInputEvent::GestureScrollBegin, time_ms, x, y); | |
| 29 event.data.scrollBegin.deltaXHint = hintx / dpi_scale(); | |
| 30 event.data.scrollBegin.deltaYHint = hinty / dpi_scale(); | |
| 31 event.data.scrollBegin.targetViewport = target_viewport; | |
| 32 | |
| 33 SendGestureEvent(event); | |
| 34 } | |
| 35 | |
| 36 void VrInputManager::ScrollEnd(long time_ms) { | |
| 37 WebGestureEvent event = | |
| 38 MakeGestureEvent(WebInputEvent::GestureScrollEnd, time_ms, 0, 0); | |
| 39 SendGestureEvent(event); | |
| 40 } | |
| 41 | |
| 42 void VrInputManager::ScrollBy(long time_ms, | |
| 43 float x, | |
| 44 float y, | |
| 45 float dx, | |
| 46 float dy) { | |
| 47 WebGestureEvent event = | |
| 48 MakeGestureEvent(WebInputEvent::GestureScrollUpdate, time_ms, x, y); | |
| 49 event.data.scrollUpdate.deltaX = -dx / dpi_scale(); | |
| 50 event.data.scrollUpdate.deltaY = -dy / dpi_scale(); | |
| 51 | |
| 52 SendGestureEvent(event); | |
| 53 } | |
| 54 | |
| 55 void VrInputManager::SendScrollEvent(long time_ms, | |
| 56 float x, | |
| 57 float y, | |
| 58 float dx, | |
| 59 float dy, | |
| 60 int type) { | |
| 61 float hinty = -dy; | |
| 62 float hintx = -dx; | |
| 63 bool target_viewport = false; | |
| 64 switch (type) { | |
| 65 case WebInputEvent::GestureScrollBegin: { | |
| 66 WebGestureEvent event_start = | |
| 67 MakeGestureEvent(WebInputEvent::GestureScrollBegin, time_ms, x, y); | |
| 68 event_start.data.scrollBegin.deltaXHint = hintx / dpi_scale(); | |
| 69 event_start.data.scrollBegin.deltaYHint = hinty / dpi_scale(); | |
| 70 event_start.data.scrollBegin.targetViewport = target_viewport; | |
| 71 SendGestureEvent(event_start); | |
| 72 break; | |
| 73 } | |
| 74 case WebInputEvent::GestureScrollUpdate: { | |
| 75 WebGestureEvent event = | |
| 76 MakeGestureEvent(WebInputEvent::GestureScrollUpdate, time_ms, x, y); | |
| 77 event.data.scrollUpdate.deltaX = -dx / dpi_scale(); | |
| 78 event.data.scrollUpdate.deltaY = -dy / dpi_scale(); | |
| 79 SendGestureEvent(event); | |
| 80 break; | |
| 81 } | |
| 82 case WebInputEvent::GestureScrollEnd: { | |
| 83 WebGestureEvent event_end = | |
| 84 MakeGestureEvent(WebInputEvent::GestureScrollEnd, time_ms, 0, 0); | |
| 85 SendGestureEvent(event_end); | |
| 86 break; | |
| 87 } | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 void VrInputManager::SendMouseMoveEvent(long time_ms, | |
| 92 float x, | |
| 93 float y, | |
| 94 int type) { | |
| 95 WebMouseEvent result; | |
| 96 | |
| 97 result.type = WebInputEvent::MouseMove; | |
| 98 result.pointerType = blink::WebPointerProperties::PointerType::Mouse; | |
| 99 result.x = x / dpi_scale(); | |
| 100 result.y = y / dpi_scale(); | |
| 101 result.windowX = x / dpi_scale(); | |
| 102 result.windowY = y / dpi_scale(); | |
| 103 result.timeStampSeconds = time_ms / 1000.0; | |
| 104 result.clickCount = 1; | |
| 105 result.modifiers = 0; | |
| 106 | |
| 107 if (type == 1) { | |
| 108 result.type = WebInputEvent::MouseEnter; | |
| 109 } else if (type == 2) { | |
| 110 result.type = WebInputEvent::MouseLeave; | |
| 111 } | |
| 112 result.button = WebMouseEvent::Button::NoButton; | |
| 113 | |
| 114 SendMouseEvent(result); | |
| 115 } | |
| 116 | |
| 117 void VrInputManager::SendClickEvent(long time_ms, float x, float y) { | |
| 118 WebGestureEvent tap_down_event = | |
| 119 MakeGestureEvent(WebInputEvent::GestureTapDown, time_ms, x, y); | |
| 120 tap_down_event.data.tap.tapCount = 1; | |
| 121 SendGestureEvent(tap_down_event); | |
| 122 | |
| 123 WebGestureEvent tap_event = | |
| 124 MakeGestureEvent(WebInputEvent::GestureTap, time_ms, x, y); | |
| 125 tap_event.data.tap.tapCount = 1; | |
| 126 SendGestureEvent(tap_event); | |
| 127 } | |
| 128 | |
| 129 void VrInputManager::PinchBegin(long time_ms, float x, float y) { | |
| 130 WebGestureEvent event = | |
| 131 MakeGestureEvent(WebInputEvent::GesturePinchBegin, time_ms, x, y); | |
| 132 SendGestureEvent(event); | |
| 133 } | |
| 134 | |
| 135 void VrInputManager::PinchEnd(long time_ms) { | |
| 136 WebGestureEvent event = | |
| 137 MakeGestureEvent(WebInputEvent::GesturePinchEnd, time_ms, 0, 0); | |
| 138 SendGestureEvent(event); | |
| 139 } | |
| 140 | |
| 141 void VrInputManager::PinchBy(long time_ms, | |
| 142 float anchor_x, | |
| 143 float anchor_y, | |
| 144 float delta) { | |
| 145 WebGestureEvent event = MakeGestureEvent(WebInputEvent::GesturePinchUpdate, | |
| 146 time_ms, anchor_x, anchor_y); | |
| 147 event.data.pinchUpdate.scale = delta; | |
| 148 | |
| 149 SendGestureEvent(event); | |
| 150 } | |
| 151 | |
| 152 void VrInputManager::SendPinchEvent(long time_ms, | |
| 153 float x, | |
| 154 float y, | |
| 155 float dz, | |
| 156 int type) { | |
| 157 switch (type) { | |
| 158 case WebInputEvent::GesturePinchBegin: { | |
| 159 WebGestureEvent event_start = | |
| 160 MakeGestureEvent(WebInputEvent::GesturePinchBegin, time_ms, x, y); | |
| 161 SendGestureEvent(event_start); | |
| 162 break; | |
| 163 } | |
| 164 case WebInputEvent::GesturePinchUpdate: { | |
| 165 WebGestureEvent event = | |
| 166 MakeGestureEvent(WebInputEvent::GesturePinchUpdate, time_ms, x, y); | |
| 167 event.data.pinchUpdate.scale = dz; | |
| 168 | |
| 169 SendGestureEvent(event); | |
| 170 break; | |
| 171 } | |
| 172 case WebInputEvent::GesturePinchEnd: { | |
| 173 WebGestureEvent event_end = | |
| 174 MakeGestureEvent(WebInputEvent::GesturePinchEnd, time_ms, 0, 0); | |
| 175 SendGestureEvent(event_end); | |
| 176 break; | |
| 177 } | |
| 178 } | |
| 179 } | |
| 180 | |
| 181 WebGestureEvent VrInputManager::MakeGestureEvent(WebInputEvent::Type type, | |
| 182 int64_t time_ms, | |
|
tdresser
2016/09/23 13:48:19
We're using long in some places, and int64_t in so
asimjour
2016/09/23 16:58:21
replaced long with int64_t
| |
| 183 float x, | |
| 184 float y) const { | |
| 185 WebGestureEvent result; | |
| 186 | |
| 187 result.type = type; | |
| 188 result.x = x / dpi_scale_; | |
| 189 result.y = y / dpi_scale_; | |
| 190 result.timeStampSeconds = time_ms / 1000.0; | |
| 191 result.sourceDevice = blink::WebGestureDeviceTouchscreen; | |
| 192 | |
| 193 return result; | |
| 194 } | |
| 195 | |
| 196 void VrInputManager::SendGestureEvent(const blink::WebGestureEvent& event) { | |
| 197 content::RenderWidgetHost* rwh = content_view_core_->GetWebContents() | |
| 198 ->GetRenderWidgetHostView() | |
| 199 ->GetRenderWidgetHost(); | |
| 200 if (rwh) | |
| 201 rwh->ForwardGestureEvent(event); | |
| 202 } | |
| 203 | |
| 204 void VrInputManager::SendMouseEvent(const blink::WebMouseEvent& event) { | |
| 205 content::RenderWidgetHost* rwh = content_view_core_->GetWebContents() | |
| 206 ->GetRenderWidgetHostView() | |
| 207 ->GetRenderWidgetHost(); | |
| 208 if (rwh) | |
| 209 rwh->ForwardMouseEvent(event); | |
| 210 } | |
| 211 | |
| 212 } // namespace vr_shell | |
| OLD | NEW |