Chromium Code Reviews| 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_controller.h" | 5 #include "chrome/browser/android/vr_shell/vr_controller.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 } | 195 } |
| 196 UpdateTouchInfo(); | 196 UpdateTouchInfo(); |
| 197 UpdateGestureFromTouchInfo(gesture.get()); | 197 UpdateGestureFromTouchInfo(gesture.get()); |
| 198 | 198 |
| 199 if (gesture->type == WebInputEvent::Undefined && | 199 if (gesture->type == WebInputEvent::Undefined && |
| 200 IsButtonDown(gvr::kControllerButtonClick)) { | 200 IsButtonDown(gvr::kControllerButtonClick)) { |
| 201 gesture->type = WebInputEvent::GestureTapDown; | 201 gesture->type = WebInputEvent::GestureTapDown; |
| 202 gesture->data.tapDown.width = 0; | 202 gesture->data.tapDown.width = 0; |
| 203 gesture->data.tapDown.height = 0; | 203 gesture->data.tapDown.height = 0; |
| 204 } | 204 } |
| 205 | |
|
bshe
2016/11/28 21:52:36
nit: remove the empty line here.
asimjour1
2016/11/29 16:10:28
Done.
| |
| 205 gesture->sourceDevice = blink::WebGestureDeviceTouchpad; | 206 gesture->sourceDevice = blink::WebGestureDeviceTouchpad; |
| 206 gesture_list.push_back(std::move(gesture)); | 207 gesture_list.push_back(std::move(gesture)); |
| 207 | 208 |
| 208 if (gesture_list.back()->type == WebInputEvent::GestureScrollEnd) { | 209 if (state_ == SCROLLING && IsButtonDown(gvr::kControllerButtonClick)) { |
|
bshe
2016/11/28 21:52:36
nit: does it make sense to move this check into:
i
asimjour1
2016/11/29 16:10:28
Done.
| |
| 210 std::unique_ptr<WebGestureEvent> tap_down(new WebGestureEvent()); | |
| 211 tap_down->type = WebInputEvent::GestureTapDown; | |
| 212 tap_down->timeStampSeconds = gesture_list.back()->timeStampSeconds; | |
| 213 tap_down->sourceDevice = blink::WebGestureDeviceTouchpad; | |
| 214 tap_down->data.tapDown.width = 0; | |
| 215 tap_down->data.tapDown.height = 0; | |
| 216 gesture_list.push_back(std::move(tap_down)); | |
| 217 Reset(); | |
| 218 } else if (gesture_list.back()->type == WebInputEvent::GestureScrollEnd) { | |
| 209 std::unique_ptr<WebGestureEvent> fling(new WebGestureEvent()); | 219 std::unique_ptr<WebGestureEvent> fling(new WebGestureEvent()); |
| 210 fling->timeStampSeconds = gesture_list.back()->timeStampSeconds; | 220 fling->timeStampSeconds = gesture_list.back()->timeStampSeconds; |
| 211 fling->sourceDevice = blink::WebGestureDeviceTouchpad; | 221 fling->sourceDevice = blink::WebGestureDeviceTouchpad; |
| 212 fling->type = WebInputEvent::GestureFlingStart; | 222 fling->type = WebInputEvent::GestureFlingStart; |
| 213 if (IsHorizontalGesture()) { | 223 if (IsHorizontalGesture()) { |
| 214 fling->data.flingStart.velocityX = | 224 fling->data.flingStart.velocityX = |
| 215 overall_velocity_.x * kDisplacementScaleFactor; | 225 overall_velocity_.x * kDisplacementScaleFactor; |
| 216 } else { | 226 } else { |
| 217 fling->data.flingStart.velocityY = | 227 fling->data.flingStart.velocityY = |
| 218 overall_velocity_.y * kDisplacementScaleFactor; | 228 overall_velocity_.y * kDisplacementScaleFactor; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 } | 271 } |
| 262 } | 272 } |
| 263 | 273 |
| 264 void VrController::HandleDetectingState(WebGestureEvent* gesture) { | 274 void VrController::HandleDetectingState(WebGestureEvent* gesture) { |
| 265 // User lifts up finger from touch pad. | 275 // User lifts up finger from touch pad. |
| 266 if (touch_info_->touch_up || !(touch_info_->is_touching)) { | 276 if (touch_info_->touch_up || !(touch_info_->is_touching)) { |
| 267 Reset(); | 277 Reset(); |
| 268 return; | 278 return; |
| 269 } | 279 } |
| 270 | 280 |
| 271 // Touch position is changed and the touch point moves outside of slop. | 281 // Touch position is changed, the touch point moves outside of slop, |
| 282 // and the Controller's button is not down. | |
| 272 if (UpdateCurrentTouchpoint() && touch_info_->is_touching && | 283 if (UpdateCurrentTouchpoint() && touch_info_->is_touching && |
| 273 !InSlop(touch_info_->touch_point.position)) { | 284 !InSlop(touch_info_->touch_point.position) && |
| 285 !IsButtonDown(gvr::kControllerButtonClick)) { | |
| 274 state_ = SCROLLING; | 286 state_ = SCROLLING; |
| 275 gesture->type = WebInputEvent::GestureScrollBegin; | 287 gesture->type = WebInputEvent::GestureScrollBegin; |
| 276 UpdateGesture(gesture); | 288 UpdateGesture(gesture); |
| 277 gesture->data.scrollBegin.deltaXHint = | 289 gesture->data.scrollBegin.deltaXHint = |
| 278 displacement_.x * kDisplacementScaleFactor; | 290 displacement_.x * kDisplacementScaleFactor; |
| 279 gesture->data.scrollBegin.deltaYHint = | 291 gesture->data.scrollBegin.deltaYHint = |
| 280 displacement_.y * kDisplacementScaleFactor; | 292 displacement_.y * kDisplacementScaleFactor; |
| 281 } | 293 } |
| 282 } | 294 } |
| 283 | 295 |
| 284 void VrController::HandleScrollingState(WebGestureEvent* gesture) { | 296 void VrController::HandleScrollingState(WebGestureEvent* gesture) { |
| 285 // Update current touch point. | 297 // Update current touch point. |
| 286 bool touch_position_changed = UpdateCurrentTouchpoint(); | 298 bool touch_position_changed = UpdateCurrentTouchpoint(); |
| 287 if (touch_info_->touch_up || !(touch_info_->is_touching)) { | 299 if (touch_info_->touch_up || !(touch_info_->is_touching) || |
| 300 IsButtonDown(gvr::kControllerButtonClick)) { | |
| 288 // Gesture ends. | 301 // Gesture ends. |
| 289 gesture->type = WebInputEvent::GestureScrollEnd; | 302 gesture->type = WebInputEvent::GestureScrollEnd; |
| 290 UpdateGesture(gesture); | 303 UpdateGesture(gesture); |
| 291 } else if (touch_position_changed) { | 304 } else if (touch_position_changed) { |
| 292 // User continues scrolling and there is a change in touch position. | 305 // User continues scrolling and there is a change in touch position. |
| 293 gesture->type = WebInputEvent::GestureScrollUpdate; | 306 gesture->type = WebInputEvent::GestureScrollUpdate; |
| 294 UpdateGesture(gesture); | 307 UpdateGesture(gesture); |
| 295 if (IsHorizontalGesture()) { | 308 if (IsHorizontalGesture()) { |
| 296 gesture->data.scrollUpdate.deltaX = | 309 gesture->data.scrollUpdate.deltaX = |
| 297 displacement_.x * kDisplacementScaleFactor; | 310 displacement_.x * kDisplacementScaleFactor; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration); | 374 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration); |
| 362 | 375 |
| 363 float weight = duration / (kRC + duration); | 376 float weight = duration / (kRC + duration); |
| 364 | 377 |
| 365 overall_velocity_ = | 378 overall_velocity_ = |
| 366 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight), | 379 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight), |
| 367 Vector::ScalarMult(velocity, weight)); | 380 Vector::ScalarMult(velocity, weight)); |
| 368 } | 381 } |
| 369 | 382 |
| 370 } // namespace vr_shell | 383 } // namespace vr_shell |
| OLD | NEW |