OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "base/android/scoped_java_ref.h" | 5 #include "base/android/scoped_java_ref.h" |
| 6 #include "base/task_runner_util.h" |
6 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | 7 #include "chrome/browser/android/vr_shell/vr_input_manager.h" |
| 8 #include "content/public/browser/browser_thread.h" |
7 | 9 |
8 using blink::WebGestureEvent; | 10 using blink::WebGestureEvent; |
9 using blink::WebMouseEvent; | 11 using blink::WebMouseEvent; |
10 using blink::WebInputEvent; | 12 using blink::WebInputEvent; |
11 | 13 |
12 namespace vr_shell { | 14 namespace vr_shell { |
13 | 15 |
14 VrInputManager::VrInputManager(content::WebContents* web_contents) | 16 VrInputManager::VrInputManager(content::WebContents* web_contents) |
15 : web_contents_(web_contents) { | 17 : web_contents_(web_contents) { |
16 dpi_scale_ = 1; | 18 dpi_scale_ = 1; |
17 } | 19 } |
18 | 20 |
19 VrInputManager::~VrInputManager() {} | 21 VrInputManager::~VrInputManager() {} |
20 | 22 |
| 23 void VrInputManager::ProcessUpdatedGesture(VrGesture gesture) { |
| 24 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| 25 content::BrowserThread::PostTask( |
| 26 content::BrowserThread::UI, FROM_HERE, |
| 27 base::Bind(&VrInputManager::SendGesture, this, gesture)); |
| 28 } else { |
| 29 SendGesture(gesture); |
| 30 } |
| 31 } |
| 32 |
| 33 void VrInputManager::SendGesture(VrGesture gesture) { |
| 34 int64_t event_time = gesture.start_time; |
| 35 int64_t event_time_milliseconds = static_cast<int64_t>(event_time / 1000000); |
| 36 |
| 37 if (gesture.type == WebInputEvent::GestureScrollBegin || |
| 38 gesture.type == WebInputEvent::GestureScrollUpdate || |
| 39 gesture.type == WebInputEvent::GestureScrollEnd) { |
| 40 SendScrollEvent(event_time_milliseconds, 0.0f, 0.0f, |
| 41 gesture.details.scroll.delta.x, |
| 42 gesture.details.scroll.delta.y, gesture.type); |
| 43 } else if (gesture.type == WebInputEvent::GestureTap) { |
| 44 SendClickEvent(event_time_milliseconds, gesture.details.buttons.pos.x, |
| 45 gesture.details.buttons.pos.y); |
| 46 } else if (gesture.type == WebInputEvent::MouseMove) { |
| 47 SendMouseMoveEvent(event_time_milliseconds, gesture.details.move.delta.x, |
| 48 gesture.details.move.delta.y, gesture.details.move.type); |
| 49 } |
| 50 } |
| 51 |
21 void VrInputManager::ScrollBegin(int64_t time_ms, | 52 void VrInputManager::ScrollBegin(int64_t time_ms, |
22 float x, | 53 float x, |
23 float y, | 54 float y, |
24 float hintx, | 55 float hintx, |
25 float hinty, | 56 float hinty, |
26 bool target_viewport) { | 57 bool target_viewport) { |
27 WebGestureEvent event = | 58 WebGestureEvent event = |
28 MakeGestureEvent(WebInputEvent::GestureScrollBegin, time_ms, x, y); | 59 MakeGestureEvent(WebInputEvent::GestureScrollBegin, time_ms, x, y); |
29 event.data.scrollBegin.deltaXHint = hintx / dpi_scale_; | 60 event.data.scrollBegin.deltaXHint = hintx / dpi_scale_; |
30 event.data.scrollBegin.deltaYHint = hinty / dpi_scale_; | 61 event.data.scrollBegin.deltaYHint = hinty / dpi_scale_; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 232 } |
202 | 233 |
203 void VrInputManager::SendMouseEvent(const blink::WebMouseEvent& event) { | 234 void VrInputManager::SendMouseEvent(const blink::WebMouseEvent& event) { |
204 content::RenderWidgetHost* rwh = | 235 content::RenderWidgetHost* rwh = |
205 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost(); | 236 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost(); |
206 if (rwh) | 237 if (rwh) |
207 rwh->ForwardMouseEvent(event); | 238 rwh->ForwardMouseEvent(event); |
208 } | 239 } |
209 | 240 |
210 } // namespace vr_shell | 241 } // namespace vr_shell |
OLD | NEW |