Index: chrome/browser/android/vr_shell/vr_controller.cc |
diff --git a/chrome/browser/android/vr_shell/vr_controller.cc b/chrome/browser/android/vr_shell/vr_controller.cc |
index 96ce33ea41a4f3654793cb8e2e5aee01cf66ed2e..6a932bbeba881a4df5e0c0548e4276870f83ee7e 100644 |
--- a/chrome/browser/android/vr_shell/vr_controller.cc |
+++ b/chrome/browser/android/vr_shell/vr_controller.cc |
@@ -4,8 +4,6 @@ |
#include "chrome/browser/android/vr_shell/vr_controller.h" |
-#include <android/log.h> |
- |
#include <cmath> |
#include "third_party/WebKit/public/web/WebInputEvent.h" |
@@ -16,10 +14,6 @@ namespace vr_shell { |
namespace { |
-const GestureScroll kDefaultGestureScroll = {{0, 0}, 0, {0, 0}}; |
-const GestureButtonsChange kDefaultGestureButtonsChange = {{0, 0}, 0, 0}; |
-const GestureAngularMove kDefaultGestureAngularMove = {{0, 0, 0}, 0}; |
- |
constexpr float kDisplacementScaleFactor = 800.0f; |
// A slop represents a small rectangular region around the first touch point of |
@@ -129,18 +123,18 @@ void VrController::UpdateState() { |
} |
} |
-void VrController::Update(bool touch_up, |
- bool touch_down, |
- bool is_touching, |
- const gvr::Vec2f position, |
- int64_t timestamp) { |
+void VrController::Update() { |
CHECK(touch_info_ != nullptr) << "touch_info_ not initialized properly."; |
- touch_info_->touch_up = touch_up; |
- touch_info_->touch_down = touch_down; |
- touch_info_->is_touching = is_touching; |
+ gvr::Vec2f position; |
+ position.x = TouchPosX(); |
+ position.y = TouchPosY(); |
+ touch_info_->touch_up = IsTouchUp(); |
+ touch_info_->touch_down = IsTouchDown(); |
+ touch_info_->is_touching = IsTouching(); |
touch_info_->touch_point.position = position; |
Vector::ClampTouchpadPosition(&touch_info_->touch_point.position); |
- touch_info_->touch_point.timestamp = timestamp; |
+ touch_info_->touch_point.timestamp = |
+ gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; |
UpdateGestureFromTouchInfo(); |
} |
@@ -156,65 +150,36 @@ void VrController::Initialize(gvr_context* gvr_context) { |
controller_api_->Resume(); |
} |
-VrGesture VrController::DetectGesture() { |
- if (controller_state_.GetConnectionState() == gvr::kControllerConnected) { |
- gvr::Vec2f position; |
- position.x = TouchPosX(); |
- position.y = TouchPosY(); |
- Update(IsTouchUp(), IsTouchDown(), IsTouching(), position, |
- gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos); |
- if (GetGestureListSize() > 0 && |
- (GetGesturePtr(0)->type == WebInputEvent::GestureScrollBegin || |
- GetGesturePtr(0)->type == WebInputEvent::GestureScrollUpdate || |
- GetGesturePtr(0)->type == WebInputEvent::GestureScrollEnd)) { |
- switch (GetGesturePtr(0)->type) { |
- case WebInputEvent::GestureScrollBegin: |
- return VrGesture( |
- kDefaultGestureScroll, |
- gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos, |
- gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos, |
- GetGesturePtr(0)->displacement.x * kDisplacementScaleFactor, |
- GetGesturePtr(0)->displacement.y * kDisplacementScaleFactor, |
- WebInputEvent::GestureScrollBegin, Orientation()); |
- case WebInputEvent::GestureScrollUpdate: |
- return VrGesture( |
- kDefaultGestureScroll, |
- gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos, |
- gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos, |
- GetGesturePtr(0)->displacement.x * kDisplacementScaleFactor, |
- GetGesturePtr(0)->displacement.y * kDisplacementScaleFactor, |
- WebInputEvent::GestureScrollUpdate, Orientation()); |
- case WebInputEvent::GestureScrollEnd: |
- return VrGesture( |
- kDefaultGestureScroll, |
- gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos, |
- gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos, 0, 0, |
- WebInputEvent::GestureScrollEnd, Orientation()); |
- default: |
- LOG(ERROR) << "Unknown Gesture"; |
- return VrGesture(); |
- } |
- } |
+std::unique_ptr<VrGesture> VrController::DetectGesture() { |
+ gesture_.reset(new VrGesture()); |
cjgrant
2016/10/03 14:27:34
Maybe here, or in a future change, we should cut o
mthiesse
2016/10/03 15:39:15
Done.
|
+ if (controller_state_.GetConnectionState() != gvr::kControllerConnected) { |
+ return std::move(gesture_); |
+ } |
+ Update(); |
- if (IsButtonDown(gvr::kControllerButtonClick)) { |
- return VrGesture( |
- kDefaultGestureButtonsChange, |
- gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos, |
- gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos, 1, 0, |
- Orientation()); |
- } |
- return VrGesture(kDefaultGestureAngularMove, |
- gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos, |
- gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos, |
- Orientation()); |
+ if (gesture_.get()->type == WebInputEvent::GestureScrollBegin || |
+ gesture_.get()->type == WebInputEvent::GestureScrollUpdate || |
+ gesture_.get()->type == WebInputEvent::GestureScrollEnd) { |
+ return std::move(gesture_); |
+ } |
+ |
+ if (IsButtonDown(gvr::kControllerButtonClick)) { |
+ gesture_->type = WebInputEvent::GestureTap; |
+ gesture_->details.buttons.down = 1; |
+ gesture_->details.buttons.up = 0; |
+ gesture_->details.buttons.pos.x = 0; |
+ gesture_->details.buttons.pos.y = 0; |
+ return std::move(gesture_); |
} |
- return VrGesture(); |
+ |
+ return std::move(gesture_); |
} |
void VrController::UpdateGestureFromTouchInfo() { |
- // Clear the gesture list. |
- gesture_list_.clear(); |
- |
+ gesture_->start_time = |
+ gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; |
+ gesture_->end_time = |
+ gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; |
switch (state_) { |
// User has not put finger on touch pad. |
case WAITING: |
@@ -234,30 +199,6 @@ void VrController::UpdateGestureFromTouchInfo() { |
} |
} |
-const VrGesture* VrController::GetGesturePtr(const size_t index) { |
- CHECK(index < gesture_list_.size()) << "The gesture index exceeds the" |
- "size of gesture list."; |
- return const_cast<VrGesture*>(&gesture_list_[index]); |
-} |
- |
-void VrController::Update(const gvr_controller_state* controller_state) { |
- // Update touch information. |
- CHECK(touch_info_ != nullptr) << "touch_info_ not initialized properly."; |
- touch_info_->touch_up = gvr_controller_state_get_touch_up(controller_state); |
- touch_info_->touch_down = |
- gvr_controller_state_get_touch_down(controller_state); |
- touch_info_->is_touching = gvr_controller_state_is_touching(controller_state); |
- touch_info_->touch_point.position.x = |
- gvr_controller_state_get_touch_pos(controller_state).x; |
- touch_info_->touch_point.position.y = |
- gvr_controller_state_get_touch_pos(controller_state).y; |
- Vector::ClampTouchpadPosition(&(touch_info_->touch_point.position)); |
- touch_info_->touch_point.timestamp = |
- gvr_controller_state_get_last_touch_timestamp(controller_state); |
- |
- UpdateGestureFromTouchInfo(); |
-} |
- |
void VrController::HandleWaitingState() { |
// User puts finger on touch pad (or when the touch down for current gesture |
// is missed, initiate gesture from current touch point). |
@@ -281,10 +222,13 @@ void VrController::HandleDetectingState() { |
if (UpdateCurrentTouchpoint() && touch_info_->is_touching && |
!InSlop(touch_info_->touch_point.position)) { |
state_ = SCROLLING; |
- VrGesture gesture; |
- gesture.type = WebInputEvent::GestureScrollBegin; |
- UpdateGesture(&gesture); |
- gesture_list_.push_back(gesture); |
+ gesture_->type = WebInputEvent::GestureScrollBegin; |
+ UpdateGesture(gesture_.get()); |
+ gesture_->details.scroll.delta.x = |
+ gesture_->displacement.x * kDisplacementScaleFactor; |
+ gesture_->details.scroll.delta.y = |
+ gesture_->displacement.y * kDisplacementScaleFactor; |
+ gesture_->details.scroll.stop_fling = 0; |
} |
} |
@@ -292,18 +236,22 @@ void VrController::HandleScrollingState() { |
// Update current touch point. |
bool touch_position_changed = UpdateCurrentTouchpoint(); |
if (touch_info_->touch_up || !(touch_info_->is_touching)) { // gesture ends |
bshe
2016/10/03 12:09:23
nit: move comments to a new line
mthiesse
2016/10/03 15:39:15
Done.
|
- VrGesture scroll_end; |
- scroll_end.type = WebInputEvent::GestureScrollEnd; |
- UpdateGesture(&scroll_end); |
- gesture_list_.push_back(scroll_end); |
- |
+ gesture_->type = WebInputEvent::GestureScrollEnd; |
+ UpdateGesture(gesture_.get()); |
+ gesture_->details.scroll.delta.x = 0; |
+ gesture_->details.scroll.delta.y = 0; |
+ gesture_->details.scroll.stop_fling = 0; |
Reset(); |
} else if (touch_position_changed) { // User continues scrolling and there is |
bshe
2016/10/03 12:09:23
ditto
mthiesse
2016/10/03 15:39:15
Done.
|
// a change in touch position. |
- VrGesture scroll_update; |
- scroll_update.type = WebInputEvent::GestureScrollUpdate; |
- UpdateGesture(&scroll_update); |
- gesture_list_.push_back(scroll_update); |
+ gesture_->type = WebInputEvent::GestureScrollUpdate; |
+ UpdateGesture(gesture_.get()); |
+ gesture_->details.scroll.delta.x = |
+ gesture_->displacement.x * kDisplacementScaleFactor; |
+ gesture_->details.scroll.delta.y = |
+ gesture_->displacement.y * kDisplacementScaleFactor; |
+ gesture_->details.scroll.stop_fling = 0; |
+ UpdateGesture(gesture_.get()); |
} |
} |