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

Unified Diff: chrome/browser/android/vr_shell/vr_shell.cc

Issue 2378903005: Implement controller handling in vr_shell.cc (Closed)
Patch Set: 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: chrome/browser/android/vr_shell/vr_shell.cc
diff --git a/chrome/browser/android/vr_shell/vr_shell.cc b/chrome/browser/android/vr_shell/vr_shell.cc
index 9e9b090a4b6aa4a9a5f82f0a0159b504a4301d1a..a5af42dcbcef822e1d6128d62364e40c4e5ff516 100644
--- a/chrome/browser/android/vr_shell/vr_shell.cc
+++ b/chrome/browser/android/vr_shell/vr_shell.cc
@@ -8,7 +8,10 @@
#include "chrome/browser/android/vr_shell/ui_scene.h"
#include "chrome/browser/android/vr_shell/vr_compositor.h"
+#include "chrome/browser/android/vr_shell/vr_controller.h"
+#include "chrome/browser/android/vr_shell/vr_controller.h"
cjgrant 2016/09/30 20:26:39 Duplicate include.
mthiesse 2016/10/03 16:30:13 Done.
#include "chrome/browser/android/vr_shell/vr_gl_util.h"
+#include "chrome/browser/android/vr_shell/vr_input_manager.h"
#include "chrome/browser/android/vr_shell/vr_math.h"
#include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
#include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
@@ -181,6 +184,10 @@ void VrShell::GvrInit(JNIEnv* env,
if (delegate_)
delegate_->OnVrShellReady(this);
+ controller_.reset(
+ new VrController(reinterpret_cast<gvr_context*>(native_gvr_api)));
+ content_input_manager_ = new VrInputManager(content_cvc_->GetWebContents());
+ ui_input_manager_ = new VrInputManager(ui_cvc_->GetWebContents());
}
void VrShell::InitializeGl(JNIEnv* env,
@@ -207,10 +214,24 @@ void VrShell::InitializeGl(JNIEnv* env,
}
void VrShell::UpdateController(const gvr::Vec3f& forward_vector) {
+ controller_->UpdateState();
+ std::unique_ptr<VrGesture> gesture = controller_->DetectGesture();
+
+ // TODO (asimjour) for now, scroll is sent to the main content.
bshe 2016/10/03 12:23:21 nit: s/TODO (asimjour)/TODO(asimjour):
mthiesse 2016/10/03 16:30:13 Done.
+ if (gesture->type == WebInputEvent::GestureScrollBegin ||
+ gesture->type == WebInputEvent::GestureScrollUpdate ||
+ gesture->type == WebInputEvent::GestureScrollEnd) {
+ content_input_manager_->ProcessUpdatedGesture(*gesture.get());
+ }
+
+ WebInputEvent::Type original_type = gesture->type;
+ controller_active_ = controller_->IsConnected();
cjgrant 2016/09/30 20:26:39 Rebase needed.
asimjour1 2016/10/03 15:54:38 It looks that controller_active_ is not needed. yo
mthiesse 2016/10/03 16:30:13 Acknowledged.
mthiesse 2016/10/03 16:30:13 Done.
if (!controller_active_) {
// No controller detected, set up a gaze cursor that tracks the
// forward direction.
controller_quat_ = GetRotationFromZAxis(forward_vector);
+ } else {
+ controller_quat_ = controller_->Orientation();
}
gvr::Mat4f mat = QuatToMatrix(controller_quat_);
@@ -237,9 +258,15 @@ void VrShell::UpdateController(const gvr::Vec3f& forward_vector) {
target_point_ = GetRayPoint(origin, forward, distance);
// Determine which UI element (if any) the cursor is pointing to.
+ int closest_element_index = -1;
float closest_element = std::numeric_limits<float>::infinity();
bshe 2016/10/03 12:23:21 nit: s/closest_element/closest_element_distance ?
mthiesse 2016/10/03 16:30:13 Done.
+ int pixel_x = 0;
+ int pixel_y = 0;
for (std::size_t i = 0; i < scene_.GetUiElements().size(); ++i) {
const ContentRectangle& plane = *scene_.GetUiElements()[i].get();
+ if (!plane.visible) {
+ continue;
+ }
float distance_to_plane = plane.GetRayDistance(origin, forward);
gvr::Vec3f plane_intersection_point =
GetRayPoint(origin, forward, distance_to_plane);
@@ -251,12 +278,71 @@ void VrShell::UpdateController(const gvr::Vec3f& forward_vector) {
if (distance_to_plane > 0 && distance_to_plane < closest_element) {
bool is_inside = x >= 0.0f && x < 1.0f && y >= 0.0f && y < 1.0f;
if (is_inside) {
+ closest_element_index = i;
closest_element = distance_to_plane;
+ pixel_x =
+ static_cast<int>(plane.copy_rect.width * x + plane.copy_rect.x);
+ pixel_y =
+ static_cast<int>(plane.copy_rect.height * y + plane.copy_rect.y);
+
target_point_ = plane_intersection_point;
target_element_ = &plane;
}
}
}
+ if (closest_element_index != current_ui_rect_ && current_ui_rect_ >= 0) {
+ // Send a move event indicating that the pointer moved off of an element.
+ gesture->type = WebInputEvent::MouseMove;
+ gesture->details.move.delta.x = 0;
+ gesture->details.move.delta.y = 0;
+ gesture->details.move.type = 2;
cjgrant 2016/09/30 20:26:39 Type should be an enum.
mthiesse 2016/10/03 16:30:13 Done.
+ if (current_ui_rect_ == 0) {
cjgrant 2016/09/30 20:26:39 kBrowserUiElementId
mthiesse 2016/10/03 16:30:13 Done.
+ content_input_manager_->ProcessUpdatedGesture(*gesture.get());
+ } else {
+ ui_input_manager_->ProcessUpdatedGesture(*gesture.get());
+ }
+ current_ui_rect_ = 1;
bshe 2016/10/03 12:23:21 why 1?
mthiesse 2016/10/03 16:30:12 Removed.
+ }
+
+ if (closest_element_index >= 0) {
+ if (current_ui_rect_ != closest_element_index) {
+ gesture->type = WebInputEvent::MouseMove;
+ gesture->details.move.delta.x = pixel_x;
+ gesture->details.move.delta.y = pixel_y;
+ gesture->details.move.type = 1;
cjgrant 2016/09/30 20:26:39 Enum here as well, and elsewhere.
mthiesse 2016/10/03 16:30:12 Done.
+ if (closest_element_index > 0) {
cjgrant 2016/09/30 20:26:39 != kBrowserUiElementId, here and elsewhere.
mthiesse 2016/10/03 16:30:13 Done.
+ ui_input_manager_->ProcessUpdatedGesture(*gesture.get());
+ } else {
+ content_input_manager_->ProcessUpdatedGesture(*gesture.get());
+ }
+ }
+ if (closest_element_index > 0) {
+ if (original_type == WebInputEvent::GestureTap) {
+ gesture->type = WebInputEvent::GestureTap;
+ gesture->details.buttons.pos.x = pixel_x;
+ gesture->details.buttons.pos.y = pixel_y;
+ ui_input_manager_->ProcessUpdatedGesture(*gesture.get());
+ }
+ gesture->type = WebInputEvent::MouseMove;
+ gesture->details.move.delta.x = pixel_x;
+ gesture->details.move.delta.y = pixel_y;
+ gesture->details.move.type = 0;
+ ui_input_manager_->ProcessUpdatedGesture(*gesture.get());
bshe 2016/10/03 12:23:21 it looks like line 320 - 330 is very similar to li
mthiesse 2016/10/03 16:30:13 Done.
+ } else {
+ if (original_type == WebInputEvent::GestureTap) {
+ gesture->type = WebInputEvent::GestureTap;
+ gesture->details.buttons.pos.x = pixel_x;
+ gesture->details.buttons.pos.y = pixel_y;
+ content_input_manager_->ProcessUpdatedGesture(*gesture.get());
+ }
+ gesture->type = WebInputEvent::MouseMove;
+ gesture->details.move.delta.x = pixel_x;
+ gesture->details.move.delta.y = pixel_y;
+ gesture->details.move.type = 0;
+ content_input_manager_->ProcessUpdatedGesture(*gesture.get());
+ }
+ current_ui_rect_ = closest_element_index;
+ }
}
void ApplyNeckModel(gvr::Mat4f& mat_forward) {
@@ -477,6 +563,7 @@ void VrShell::DrawWebVr() {
void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) {
if (gvr_api_ == nullptr)
return;
+ controller_->OnPause();
gvr_api_->PauseTracking();
}
@@ -486,6 +573,7 @@ void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) {
gvr_api_->RefreshViewerProfile();
gvr_api_->ResumeTracking();
+ controller_->OnResume();
}
base::WeakPtr<VrShell> VrShell::GetWeakPtr() {
« chrome/browser/android/vr_shell/vr_shell.h ('K') | « chrome/browser/android/vr_shell/vr_shell.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698