| 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 "chrome/browser/android/vr_shell/vr_input_manager.h" |   5 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | 
|   6  |   6  | 
|   7 #include "base/task_runner_util.h" |   7 #include "base/task_runner_util.h" | 
|   8 #include "content/public/browser/browser_thread.h" |   8 #include "content/public/browser/browser_thread.h" | 
|   9 #include "content/public/browser/render_widget_host.h" |   9 #include "content/public/browser/render_widget_host.h" | 
|  10 #include "content/public/browser/render_widget_host_view.h" |  10 #include "content/public/browser/render_widget_host_view.h" | 
|  11 #include "content/public/browser/web_contents.h" |  11 #include "content/public/browser/web_contents.h" | 
|  12  |  12  | 
|  13 using blink::WebGestureEvent; |  13 using blink::WebGestureEvent; | 
|  14 using blink::WebMouseEvent; |  14 using blink::WebMouseEvent; | 
|  15 using blink::WebInputEvent; |  15 using blink::WebInputEvent; | 
|  16  |  16  | 
|  17 namespace vr_shell { |  17 namespace vr_shell { | 
|  18  |  18  | 
|  19 namespace { |  19 namespace { | 
|  20 WebGestureEvent MakeGestureEvent(WebInputEvent::Type type, |  20 WebGestureEvent MakeGestureEvent(WebInputEvent::Type type, | 
|  21                                  double time, |  21                                  double time, | 
|  22                                  float x, |  22                                  float x, | 
|  23                                  float y) { |  23                                  float y) { | 
|  24   WebGestureEvent result; |  24   WebGestureEvent result(type, WebInputEvent::NoModifiers, time); | 
|  25   result.type = type; |  | 
|  26   result.x = x; |  25   result.x = x; | 
|  27   result.y = y; |  26   result.y = y; | 
|  28   result.timeStampSeconds = time; |  | 
|  29   result.sourceDevice = blink::WebGestureDeviceTouchpad; |  27   result.sourceDevice = blink::WebGestureDeviceTouchpad; | 
|  30   return result; |  28   return result; | 
|  31 } |  29 } | 
|  32 }  // namespace |  30 }  // namespace | 
|  33  |  31  | 
|  34 VrInputManager::VrInputManager(content::WebContents* web_contents) |  32 VrInputManager::VrInputManager(content::WebContents* web_contents) | 
|  35     : web_contents_(web_contents), |  33     : web_contents_(web_contents), | 
|  36       weak_ptr_factory_(this) { |  34       weak_ptr_factory_(this) { | 
|  37 } |  35 } | 
|  38  |  36  | 
|  39 VrInputManager::~VrInputManager() = default; |  37 VrInputManager::~VrInputManager() = default; | 
|  40  |  38  | 
|  41 base::WeakPtr<VrInputManager> VrInputManager::GetWeakPtr() { |  39 base::WeakPtr<VrInputManager> VrInputManager::GetWeakPtr() { | 
|  42   return weak_ptr_factory_.GetWeakPtr(); |  40   return weak_ptr_factory_.GetWeakPtr(); | 
|  43 } |  41 } | 
|  44  |  42  | 
|  45 void VrInputManager::ProcessUpdatedGesture( |  43 void VrInputManager::ProcessUpdatedGesture( | 
|  46     std::unique_ptr<blink::WebInputEvent> event) { |  44     std::unique_ptr<blink::WebInputEvent> event) { | 
|  47   if (WebInputEvent::isMouseEventType(event->type)) { |  45   if (WebInputEvent::isMouseEventType(event->type())) { | 
|  48     ForwardMouseEvent(static_cast<const blink::WebMouseEvent&>(*event)); |  46     ForwardMouseEvent(static_cast<const blink::WebMouseEvent&>(*event)); | 
|  49   } else { |  47   } else { | 
|  50     SendGesture(static_cast<const blink::WebGestureEvent&>(*event)); |  48     SendGesture(static_cast<const blink::WebGestureEvent&>(*event)); | 
|  51   } |  49   } | 
|  52 } |  50 } | 
|  53  |  51  | 
|  54 void VrInputManager::SendGesture(const WebGestureEvent& gesture) { |  52 void VrInputManager::SendGesture(const WebGestureEvent& gesture) { | 
|  55   if (gesture.type == WebGestureEvent::GestureTapDown) { |  53   if (gesture.type() == WebGestureEvent::GestureTapDown) { | 
|  56     ForwardGestureEvent(gesture); |  54     ForwardGestureEvent(gesture); | 
|  57  |  55  | 
|  58     // Generate and forward Tap |  56     // Generate and forward Tap | 
|  59     WebGestureEvent tap_event = |  57     WebGestureEvent tap_event = | 
|  60         MakeGestureEvent(WebInputEvent::GestureTap, gesture.timeStampSeconds, |  58         MakeGestureEvent(WebInputEvent::GestureTap, gesture.timeStampSeconds(), | 
|  61                          gesture.x, gesture.y); |  59                          gesture.x, gesture.y); | 
|  62     tap_event.data.tap.tapCount = 1; |  60     tap_event.data.tap.tapCount = 1; | 
|  63     ForwardGestureEvent(tap_event); |  61     ForwardGestureEvent(tap_event); | 
|  64   } else { |  62   } else { | 
|  65     ForwardGestureEvent(gesture); |  63     ForwardGestureEvent(gesture); | 
|  66   } |  64   } | 
|  67 } |  65 } | 
|  68  |  66  | 
|  69 void VrInputManager::ForwardGestureEvent( |  67 void VrInputManager::ForwardGestureEvent( | 
|  70     const blink::WebGestureEvent& gesture) { |  68     const blink::WebGestureEvent& gesture) { | 
|  71   if (!web_contents_->GetRenderWidgetHostView()) |  69   if (!web_contents_->GetRenderWidgetHostView()) | 
|  72     return; |  70     return; | 
|  73   content::RenderWidgetHost* rwh = |  71   content::RenderWidgetHost* rwh = | 
|  74       web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost(); |  72       web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost(); | 
|  75   if (rwh) |  73   if (rwh) | 
|  76     rwh->ForwardGestureEvent(gesture); |  74     rwh->ForwardGestureEvent(gesture); | 
|  77 } |  75 } | 
|  78  |  76  | 
|  79 void VrInputManager::ForwardMouseEvent( |  77 void VrInputManager::ForwardMouseEvent( | 
|  80     const blink::WebMouseEvent& mouse_event) { |  78     const blink::WebMouseEvent& mouse_event) { | 
|  81   if (!web_contents_->GetRenderWidgetHostView()) |  79   if (!web_contents_->GetRenderWidgetHostView()) | 
|  82       return; |  80       return; | 
|  83   content::RenderWidgetHost* rwh = |  81   content::RenderWidgetHost* rwh = | 
|  84       web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost(); |  82       web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost(); | 
|  85   if (rwh) |  83   if (rwh) | 
|  86     rwh->ForwardMouseEvent(mouse_event); |  84     rwh->ForwardMouseEvent(mouse_event); | 
|  87 } |  85 } | 
|  88  |  86  | 
|  89 }  // namespace vr_shell |  87 }  // namespace vr_shell | 
| OLD | NEW |