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

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

Issue 2694103006: Inject vr controller events into Android Native UI. (Closed)
Patch Set: Fix presubmit Created 3 years, 10 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 unified diff | Download patch
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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 break; 246 break;
247 // User has not started a gesture (by moving out of slop). 247 // User has not started a gesture (by moving out of slop).
248 case TOUCHING: 248 case TOUCHING:
249 HandleDetectingState(gesture); 249 HandleDetectingState(gesture);
250 break; 250 break;
251 // User is scrolling on touchpad 251 // User is scrolling on touchpad
252 case SCROLLING: 252 case SCROLLING:
253 HandleScrollingState(gesture); 253 HandleScrollingState(gesture);
254 break; 254 break;
255 default: 255 default:
256 LOG(ERROR) << "Wrong gesture detector state: " << state_; 256 NOTREACHED();
257 break; 257 break;
258 } 258 }
259 } 259 }
260 260
261 void VrController::HandleWaitingState(WebGestureEvent* gesture) { 261 void VrController::HandleWaitingState(WebGestureEvent* gesture) {
262 // User puts finger on touch pad (or when the touch down for current gesture 262 // User puts finger on touch pad (or when the touch down for current gesture
263 // is missed, initiate gesture from current touch point). 263 // is missed, initiate gesture from current touch point).
264 if (touch_info_->touch_down || touch_info_->is_touching) { 264 if (touch_info_->touch_down || touch_info_->is_touching) {
265 // update initial touchpoint 265 // update initial touchpoint
266 *init_touch_point_ = touch_info_->touch_point; 266 *init_touch_point_ = touch_info_->touch_point;
(...skipping 13 matching lines...) Expand all
280 return; 280 return;
281 } 281 }
282 282
283 // Touch position is changed, the touch point moves outside of slop, 283 // Touch position is changed, the touch point moves outside of slop,
284 // and the Controller's button is not down. 284 // and the Controller's button is not down.
285 if (touch_position_changed_ && touch_info_->is_touching && 285 if (touch_position_changed_ && touch_info_->is_touching &&
286 !InSlop(touch_info_->touch_point.position) && 286 !InSlop(touch_info_->touch_point.position) &&
287 !ButtonDownHappened(gvr::kControllerButtonClick)) { 287 !ButtonDownHappened(gvr::kControllerButtonClick)) {
288 state_ = SCROLLING; 288 state_ = SCROLLING;
289 gesture->setType(WebInputEvent::GestureScrollBegin); 289 gesture->setType(WebInputEvent::GestureScrollBegin);
290 UpdateGesture(gesture); 290 UpdateGestureParameters();
291 gesture->data.scrollBegin.deltaXHint = 291 gesture->data.scrollBegin.deltaXHint =
292 displacement_.x * kDisplacementScaleFactor; 292 displacement_.x * kDisplacementScaleFactor;
293 gesture->data.scrollBegin.deltaYHint = 293 gesture->data.scrollBegin.deltaYHint =
294 displacement_.y * kDisplacementScaleFactor; 294 displacement_.y * kDisplacementScaleFactor;
295 gesture->data.scrollBegin.deltaHintUnits =
296 blink::WebGestureEvent::ScrollUnits::PrecisePixels;
295 } 297 }
296 } 298 }
297 299
298 void VrController::HandleScrollingState(WebGestureEvent* gesture) { 300 void VrController::HandleScrollingState(WebGestureEvent* gesture) {
299 if (touch_info_->touch_up || !(touch_info_->is_touching) || 301 if (touch_info_->touch_up || !(touch_info_->is_touching) ||
300 ButtonDownHappened(gvr::kControllerButtonClick)) { 302 ButtonDownHappened(gvr::kControllerButtonClick)) {
301 // Gesture ends. 303 // Gesture ends.
302 gesture->setType(WebInputEvent::GestureScrollEnd); 304 gesture->setType(WebInputEvent::GestureScrollEnd);
303 UpdateGesture(gesture); 305 UpdateGestureParameters();
304 } else if (touch_position_changed_) { 306 } else if (touch_position_changed_) {
305 // User continues scrolling and there is a change in touch position. 307 // User continues scrolling and there is a change in touch position.
306 gesture->setType(WebInputEvent::GestureScrollUpdate); 308 gesture->setType(WebInputEvent::GestureScrollUpdate);
307 UpdateGesture(gesture); 309 UpdateGestureParameters();
308 if (IsHorizontalGesture()) { 310 if (IsHorizontalGesture()) {
309 gesture->data.scrollUpdate.deltaX = 311 gesture->data.scrollUpdate.deltaX =
310 displacement_.x * kDisplacementScaleFactor; 312 displacement_.x * kDisplacementScaleFactor;
311 } else { 313 } else {
312 gesture->data.scrollUpdate.deltaY = 314 gesture->data.scrollUpdate.deltaY =
313 displacement_.y * kDisplacementScaleFactor; 315 displacement_.y * kDisplacementScaleFactor;
314 } 316 }
315 last_velocity_ = overall_velocity_; 317 last_velocity_ = overall_velocity_;
316 } 318 }
317 } 319 }
(...skipping 15 matching lines...) Expand all
333 335
334 // Reset the pointers. 336 // Reset the pointers.
335 prev_touch_point_.reset(new TouchPoint); 337 prev_touch_point_.reset(new TouchPoint);
336 cur_touch_point_.reset(new TouchPoint); 338 cur_touch_point_.reset(new TouchPoint);
337 init_touch_point_.reset(new TouchPoint); 339 init_touch_point_.reset(new TouchPoint);
338 touch_info_.reset(new TouchInfo); 340 touch_info_.reset(new TouchInfo);
339 Vector::SetZero(&overall_velocity_); 341 Vector::SetZero(&overall_velocity_);
340 Vector::SetZero(&last_velocity_); 342 Vector::SetZero(&last_velocity_);
341 } 343 }
342 344
343 void VrController::UpdateGesture(WebGestureEvent* gesture) { 345 void VrController::UpdateGestureParameters() {
344 if (!gesture)
345 LOG(ERROR) << "The gesture pointer is not initiated properly.";
346 displacement_ = Vector::Subtract(touch_info_->touch_point.position, 346 displacement_ = Vector::Subtract(touch_info_->touch_point.position,
347 prev_touch_point_->position); 347 prev_touch_point_->position);
348 } 348 }
349 349
350 bool VrController::UpdateCurrentTouchpoint() { 350 bool VrController::UpdateCurrentTouchpoint() {
351 touch_info_->touch_up = TouchUpHappened(); 351 touch_info_->touch_up = TouchUpHappened();
352 touch_info_->touch_down = TouchDownHappened(); 352 touch_info_->touch_down = TouchDownHappened();
353 touch_info_->is_touching = IsTouching(); 353 touch_info_->is_touching = IsTouching();
354 touch_info_->touch_point.position.x = TouchPosX(); 354 touch_info_->touch_point.position.x = TouchPosX();
355 touch_info_->touch_point.position.y = TouchPosY(); 355 touch_info_->touch_point.position.y = TouchPosY();
(...skipping 30 matching lines...) Expand all
386 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration); 386 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration);
387 387
388 float weight = duration / (kRC + duration); 388 float weight = duration / (kRC + duration);
389 389
390 overall_velocity_ = 390 overall_velocity_ =
391 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight), 391 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight),
392 Vector::ScalarMult(velocity, weight)); 392 Vector::ScalarMult(velocity, weight));
393 } 393 }
394 394
395 } // namespace vr_shell 395 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_controller.h ('k') | chrome/browser/android/vr_shell/vr_shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698