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

Side by Side Diff: chrome/browser/android/vr_shell/vr_controller.cc

Issue 2533493002: VR: Fix click during scrolling (Closed)
Patch Set: Rebase + Address Comments Created 4 years 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/android/vr_shell/vr_shell.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 gesture->sourceDevice = blink::WebGestureDeviceTouchpad; 205 gesture->sourceDevice = blink::WebGestureDeviceTouchpad;
206 gesture_list.push_back(std::move(gesture)); 206 gesture_list.push_back(std::move(gesture));
207 207
208 if (gesture_list.back()->type == WebInputEvent::GestureScrollEnd) { 208 if (gesture_list.back()->type == WebInputEvent::GestureScrollEnd) {
209 std::unique_ptr<WebGestureEvent> fling(new WebGestureEvent()); 209 if (IsButtonDown(gvr::kControllerButtonClick)) {
210 fling->timeStampSeconds = gesture_list.back()->timeStampSeconds; 210 std::unique_ptr<WebGestureEvent> tap_down(new WebGestureEvent());
211 fling->sourceDevice = blink::WebGestureDeviceTouchpad; 211 tap_down->type = WebInputEvent::GestureTapDown;
212 fling->type = WebInputEvent::GestureFlingStart; 212 tap_down->timeStampSeconds = gesture_list.back()->timeStampSeconds;
213 if (IsHorizontalGesture()) { 213 tap_down->sourceDevice = blink::WebGestureDeviceTouchpad;
214 fling->data.flingStart.velocityX = 214 tap_down->data.tapDown.width = 0;
215 overall_velocity_.x * kDisplacementScaleFactor; 215 tap_down->data.tapDown.height = 0;
216 gesture_list.push_back(std::move(tap_down));
216 } else { 217 } else {
217 fling->data.flingStart.velocityY = 218 std::unique_ptr<WebGestureEvent> fling(new WebGestureEvent());
218 overall_velocity_.y * kDisplacementScaleFactor; 219 fling->timeStampSeconds = gesture_list.back()->timeStampSeconds;
220 fling->sourceDevice = blink::WebGestureDeviceTouchpad;
221 fling->type = WebInputEvent::GestureFlingStart;
222 if (IsHorizontalGesture()) {
223 fling->data.flingStart.velocityX =
224 overall_velocity_.x * kDisplacementScaleFactor;
225 } else {
226 fling->data.flingStart.velocityY =
227 overall_velocity_.y * kDisplacementScaleFactor;
228 }
229 gesture_list.push_back(std::move(fling));
219 } 230 }
220 gesture_list.push_back(std::move(fling));
221 Reset(); 231 Reset();
222 } 232 }
223 233
224 return gesture_list; 234 return gesture_list;
225 } 235 }
226 236
227 void VrController::UpdateGestureFromTouchInfo(WebGestureEvent* gesture) { 237 void VrController::UpdateGestureFromTouchInfo(WebGestureEvent* gesture) {
228 gesture->timeStampSeconds = 238 gesture->timeStampSeconds =
229 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); 239 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
230 switch (state_) { 240 switch (state_) {
(...skipping 30 matching lines...) Expand all
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
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
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/vr_shell/vr_shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698