Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: content/browser/android/vr_input_manager_impl.cc

Issue 2350253004: Controller support for VrShell (Closed)
Patch Set: removed unused files Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/android/vr_input_manager_impl.cc
diff --git a/content/browser/android/vr_input_manager_impl.cc b/content/browser/android/vr_input_manager_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..12c189737a8e555bf8428ce034f3b006dfa22bea
--- /dev/null
+++ b/content/browser/android/vr_input_manager_impl.cc
@@ -0,0 +1,209 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/android/scoped_java_ref.h"
+#include "content/browser/android/gesture_event_type.h"
+#include "content/browser/android/vr_input_manager_impl.h"
+
+using blink::WebGestureEvent;
+using blink::WebMouseEvent;
+using blink::WebInputEvent;
+
+namespace content {
+
+VrInputManagerImpl::VrInputManagerImpl(ContentViewCore* content_view_core)
+ : content_view_core_impl_(
+ static_cast<ContentViewCoreImpl*>(content_view_core)) {
+ dpi_scale_ = 1;
+}
+
+// static
+VrInputManagerImpl* VrInputManagerImpl::FromContentViewCore(
+ ContentViewCore* content_view_core) {
+ return new VrInputManagerImpl(content_view_core);
+}
+
+// static
+VrInputManager* VrInputManager::FromContentViewCore(
+ ContentViewCore* content_view_core) {
+ return VrInputManagerImpl::FromContentViewCore(content_view_core);
+}
+
+VrInputManagerImpl::~VrInputManagerImpl() {}
+
+void VrInputManagerImpl::ScrollBegin(long time_ms,
+ float x,
+ float y,
+ float hintx,
+ float hinty,
+ bool target_viewport) {
+ WebGestureEvent event =
+ MakeGestureEvent(WebInputEvent::GestureScrollBegin, time_ms, x, y);
+ event.data.scrollBegin.deltaXHint = hintx / dpi_scale();
+ event.data.scrollBegin.deltaYHint = hinty / dpi_scale();
+ event.data.scrollBegin.targetViewport = target_viewport;
+
+ SendGestureEvent(event);
+}
+
+void VrInputManagerImpl::ScrollEnd(long time_ms) {
+ WebGestureEvent event =
+ MakeGestureEvent(WebInputEvent::GestureScrollEnd, time_ms, 0, 0);
+ SendGestureEvent(event);
+}
+
+void VrInputManagerImpl::ScrollBy(long time_ms,
+ float x,
+ float y,
+ float dx,
+ float dy) {
+ WebGestureEvent event =
+ MakeGestureEvent(WebInputEvent::GestureScrollUpdate, time_ms, x, y);
+ event.data.scrollUpdate.deltaX = -dx / dpi_scale();
+ event.data.scrollUpdate.deltaY = -dy / dpi_scale();
+
+ SendGestureEvent(event);
+}
+
+void VrInputManagerImpl::SendScrollEvent(long time_ms,
+ float x,
+ float y,
+ float dx,
+ float dy,
+ int type) {
+ float hinty = -dy;
+ float hintx = -dx;
+ bool target_viewport = false;
+ switch (type) {
+ case WebInputEvent::GestureScrollBegin: {
+ WebGestureEvent event_start =
+ MakeGestureEvent(WebInputEvent::GestureScrollBegin, time_ms, x, y);
+ event_start.data.scrollBegin.deltaXHint = hintx / dpi_scale();
+ event_start.data.scrollBegin.deltaYHint = hinty / dpi_scale();
+ event_start.data.scrollBegin.targetViewport = target_viewport;
+ SendGestureEvent(event_start);
+ break;
+ }
+ case WebInputEvent::GestureScrollUpdate: {
+ WebGestureEvent event =
+ MakeGestureEvent(WebInputEvent::GestureScrollUpdate, time_ms, x, y);
+ event.data.scrollUpdate.deltaX = -dx / dpi_scale();
+ event.data.scrollUpdate.deltaY = -dy / dpi_scale();
+ SendGestureEvent(event);
+ break;
+ }
+ case WebInputEvent::GestureScrollEnd: {
+ WebGestureEvent event_end =
+ MakeGestureEvent(WebInputEvent::GestureScrollEnd, time_ms, 0, 0);
+ SendGestureEvent(event_end);
+ break;
+ }
+ }
+}
+
+void VrInputManagerImpl::SendMouseMoveEvent(long time_ms,
+ float x,
+ float y,
+ int type) {
+ WebInputEvent::Type event_type = WebInputEvent::MouseMove;
+ if (type == 1) {
+ event_type = WebInputEvent::MouseEnter;
+ } else if (type == 2) {
+ event_type = WebInputEvent::MouseLeave;
+ }
+ WebMouseEvent event = WebMouseEventBuilder::Build(
+ event_type, blink::WebMouseEvent::Button::NoButton, time_ms / 1000.0,
+ x / dpi_scale(), y / dpi_scale(), 0, 1,
+ blink::WebPointerProperties::PointerType::Mouse);
+
+ SendMouseEvent(event);
+}
+
+void VrInputManagerImpl::SendClickEvent(long time_ms, float x, float y) {
+ WebGestureEvent tap_down_event =
+ MakeGestureEvent(WebInputEvent::GestureTapDown, time_ms, x, y);
+ tap_down_event.data.tap.tapCount = 1;
+ SendGestureEvent(tap_down_event);
+
+ WebGestureEvent tap_event =
+ MakeGestureEvent(WebInputEvent::GestureTap, time_ms, x, y);
+ tap_event.data.tap.tapCount = 1;
+ SendGestureEvent(tap_event);
+}
+
+void VrInputManagerImpl::PinchBegin(long time_ms, float x, float y) {
+ WebGestureEvent event =
+ MakeGestureEvent(WebInputEvent::GesturePinchBegin, time_ms, x, y);
+ SendGestureEvent(event);
+}
+
+void VrInputManagerImpl::PinchEnd(long time_ms) {
+ WebGestureEvent event =
+ MakeGestureEvent(WebInputEvent::GesturePinchEnd, time_ms, 0, 0);
+ SendGestureEvent(event);
+}
+
+void VrInputManagerImpl::PinchBy(long time_ms,
+ float anchor_x,
+ float anchor_y,
+ float delta) {
+ WebGestureEvent event = MakeGestureEvent(WebInputEvent::GesturePinchUpdate,
+ time_ms, anchor_x, anchor_y);
+ event.data.pinchUpdate.scale = delta;
+
+ SendGestureEvent(event);
+}
+
+void VrInputManagerImpl::SendPinchEvent(long time_ms,
+ float x,
+ float y,
+ float dz,
+ int type) {
+ switch (type) {
+ case WebInputEvent::GesturePinchBegin: {
+ WebGestureEvent event_start =
+ MakeGestureEvent(WebInputEvent::GesturePinchBegin, time_ms, x, y);
+ SendGestureEvent(event_start);
+ break;
+ }
+ case WebInputEvent::GesturePinchUpdate: {
+ WebGestureEvent event =
+ MakeGestureEvent(WebInputEvent::GesturePinchUpdate, time_ms, x, y);
+ event.data.pinchUpdate.scale = dz;
+
+ SendGestureEvent(event);
+ break;
+ }
+ case WebInputEvent::GesturePinchEnd: {
+ WebGestureEvent event_end =
+ MakeGestureEvent(WebInputEvent::GesturePinchEnd, time_ms, 0, 0);
+ SendGestureEvent(event_end);
+ break;
+ }
+ }
+}
+
+WebGestureEvent VrInputManagerImpl::MakeGestureEvent(WebInputEvent::Type type,
+ int64_t time_ms,
+ float x,
+ float y) const {
+ return WebGestureEventBuilder::Build(type, time_ms / 1000.0, x / dpi_scale_,
+ y / dpi_scale_);
+}
+
+void VrInputManagerImpl::SendGestureEvent(const blink::WebGestureEvent& event) {
+ RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
+ content_view_core_impl_->GetWebContents()->GetRenderWidgetHostView());
+ if (rwhv)
+ rwhv->SendGestureEvent(event);
+}
+
+void VrInputManagerImpl::SendMouseEvent(const blink::WebMouseEvent& event) {
+ RenderWidgetHostViewAndroid* rwhv = static_cast<RenderWidgetHostViewAndroid*>(
+ content_view_core_impl_->GetWebContents()->GetRenderWidgetHostView());
+ if (rwhv)
+ rwhv->SendMouseEvent(event);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698