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

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java

Issue 2372663002: Separating cursor and viewport calculations in the desktop canvas (Closed)
Patch Set: Merging with ToT and doing some pre-review clean-up Created 4 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 package org.chromium.chromoting; 5 package org.chromium.chromoting;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.graphics.Matrix; 8 import android.graphics.Matrix;
9 import android.graphics.PointF; 9 import android.graphics.PointF;
10 import android.graphics.Rect; 10 import android.graphics.Rect;
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 parameter.hostCapability; 320 parameter.hostCapability;
321 // We need both input mode and host input capabilities to select the inp ut 321 // We need both input mode and host input capabilities to select the inp ut
322 // strategy. 322 // strategy.
323 if (!inputMode.isSet() || !hostTouchCapability.isSet()) { 323 if (!inputMode.isSet() || !hostTouchCapability.isSet()) {
324 return; 324 return;
325 } 325 }
326 326
327 switch (inputMode) { 327 switch (inputMode) {
328 case TRACKPAD: 328 case TRACKPAD:
329 setInputStrategy(new TrackpadInputStrategy(mRenderData, injector )); 329 setInputStrategy(new TrackpadInputStrategy(mRenderData, injector ));
330 moveCursorToScreenCenter();
330 break; 331 break;
331 332
332 case TOUCH: 333 case TOUCH:
333 if (hostTouchCapability.isSupported()) { 334 if (hostTouchCapability.isSupported()) {
334 setInputStrategy(new TouchInputStrategy(mRenderData, injecto r)); 335 setInputStrategy(new TouchInputStrategy(mRenderData, injecto r));
335 } else { 336 } else {
336 setInputStrategy( 337 setInputStrategy(
337 new SimulatedTouchInputStrategy(mRenderData, injecto r, mContext)); 338 new SimulatedTouchInputStrategy(mRenderData, injecto r, mContext));
338 } 339 }
339 break; 340 break;
340 341
341 default: 342 default:
342 // Unreachable, but required by Google Java style and findbugs. 343 // Unreachable, but required by Google Java style and findbugs.
343 assert false : "Unreached"; 344 assert false : "Unreached";
344 } 345 }
345 346
346 // Ensure the cursor state is updated appropriately. 347 // Ensure the cursor state is updated appropriately.
347 mRenderStub.setCursorVisibility(mRenderData.drawCursor); 348 mRenderStub.setCursorVisibility(mRenderData.drawCursor);
348 } 349 }
349 350
350 private void handleSystemUiVisibilityChanged( 351 private void handleSystemUiVisibilityChanged(
351 SystemUiVisibilityChangedEventParameter parameter) { 352 SystemUiVisibilityChangedEventParameter parameter) {
352 if (parameter.systemUiVisible) { 353 if (parameter.systemUiVisible) {
353 mDesktopCanvas.setSystemUiOffsetValues(parameter.left, parameter.top , 354 mDesktopCanvas.setSystemUiOffsetValues(parameter.left, parameter.top ,
354 mRenderData.screenWidth - parameter.right, 355 mRenderData.screenWidth - parameter.right,
355 mRenderData.screenHeight - parameter.bottom); 356 mRenderData.screenHeight - parameter.bottom);
356 } else { 357 } else {
357 mDesktopCanvas.clearSystemUiOffsets(); 358 mDesktopCanvas.clearSystemUiOffsets();
358 } 359 }
359
360 mDesktopCanvas.repositionImage(true);
361 } 360 }
362 361
363 private boolean handleTouchEvent(MotionEvent event) { 362 private boolean handleTouchEvent(MotionEvent event) {
364 // Give the underlying input strategy a chance to observe the current mo tion event before 363 // Give the underlying input strategy a chance to observe the current mo tion event before
365 // passing it to the gesture detectors. This allows the input strategy to react to the 364 // passing it to the gesture detectors. This allows the input strategy to react to the
366 // event or save the payload for use in recreating the gesture remotely. 365 // event or save the payload for use in recreating the gesture remotely.
367 mInputStrategy.onMotionEvent(event); 366 mInputStrategy.onMotionEvent(event);
368 367
369 // Avoid short-circuit logic evaluation - ensure all gesture detectors s ee all events so 368 // Avoid short-circuit logic evaluation - ensure all gesture detectors s ee all events so
370 // that they generate correct notifications. 369 // that they generate correct notifications.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 private void handleHostSizeChanged(int width, int height) { 403 private void handleHostSizeChanged(int width, int height) {
405 mRenderData.imageWidth = width; 404 mRenderData.imageWidth = width;
406 mRenderData.imageHeight = height; 405 mRenderData.imageHeight = height;
407 406
408 resizeImageToFitScreen(); 407 resizeImageToFitScreen();
409 } 408 }
410 409
411 private void resizeImageToFitScreen() { 410 private void resizeImageToFitScreen() {
412 mDesktopCanvas.resizeImageToFitScreen(); 411 mDesktopCanvas.resizeImageToFitScreen();
413 412
413 moveCursorToScreenCenter();
414
415 mDesktopCanvas.repositionImage();
416 }
417
418 private void moveCursorToScreenCenter() {
414 float screenCenterX = (float) mRenderData.screenWidth / 2; 419 float screenCenterX = (float) mRenderData.screenWidth / 2;
415 float screenCenterY = (float) mRenderData.screenHeight / 2; 420 float screenCenterY = (float) mRenderData.screenHeight / 2;
416 421
417 float[] imagePoint = mapScreenPointToImagePoint(screenCenterX, screenCen terY); 422 float[] imagePoint = mapScreenPointToImagePoint(screenCenterX, screenCen terY);
418 mDesktopCanvas.setViewportPosition(imagePoint[0], imagePoint[1]); 423 mDesktopCanvas.setViewportCenter(imagePoint[0], imagePoint[1]);
419 424
420 moveCursorToScreenPoint(screenCenterX, screenCenterY); 425 moveCursorToScreenPoint(screenCenterX, screenCenterY);
421 mDesktopCanvas.repositionImage(true);
422 } 426 }
423 427
424 private void setInputStrategy(InputStrategyInterface inputStrategy) { 428 private void setInputStrategy(InputStrategyInterface inputStrategy) {
425 // Since the rules for flinging differ between input modes, we want to s top running the 429 // Since the rules for flinging differ between input modes, we want to s top running the
426 // current fling animation when the mode changes to prevent a wonky expe rience. 430 // current fling animation when the mode changes to prevent a wonky expe rience.
427 abortAnimation(); 431 abortAnimation();
428 mInputStrategy = inputStrategy; 432 mInputStrategy = inputStrategy;
429 } 433 }
430 434
431 /** Moves the desired center of the viewport using the specified deltas. */ 435 /** Moves the desired center of the viewport using the specified deltas. */
432 private void moveViewportByOffset(float deltaX, float deltaY) { 436 private void moveViewportByOffset(float deltaX, float deltaY) {
433 // If we are in an indirect mode or are in the middle of a drag operatio n, then we want to 437 // If we are in an indirect mode or are in the middle of a drag operatio n, then we want to
434 // invert the direction of the operation (i.e. follow the motion of the finger). 438 // invert the direction of the operation (i.e. follow the motion of the finger).
435 boolean followCursor = (mInputStrategy.isIndirectInputMode() || mIsDragg ing); 439 boolean followCursor = (mInputStrategy.isIndirectInputMode() || mIsDragg ing);
436 if (followCursor) { 440 if (followCursor) {
437 deltaX = -deltaX; 441 deltaX = -deltaX;
438 deltaY = -deltaY; 442 deltaY = -deltaY;
439 } 443 }
444
440 // Determine the center point from which to apply the delta. 445 // Determine the center point from which to apply the delta.
441 // For indirect input modes (i.e. trackpad), the view generally follows the cursor. 446 // For indirect input modes (i.e. trackpad), the view generally follows the cursor.
442 // For direct input modes (i.e. touch) the should track the user's motio n. 447 // For direct input modes (i.e. touch) the should track the user's motio n.
443 // If the user is dragging, then the viewport should always follow the u ser's finger. 448 // If the user is dragging, then the viewport should always follow the u ser's finger.
444 PointF newPos = mDesktopCanvas.moveViewportCenter(!followCursor, deltaX, deltaY);
445
446 // If we are in an indirect mode, then we want to keep the cursor center ed, if possible, as
447 // the viewport moves.
448 if (mInputStrategy.isIndirectInputMode()) { 449 if (mInputStrategy.isIndirectInputMode()) {
449 moveCursor(newPos.x, newPos.y); 450 PointF newCursorPos = mDesktopCanvas.moveViewportWithCursor(deltaX, deltaY);
451 moveCursor(newCursorPos.x, newCursorPos.y);
452 } else {
453 mDesktopCanvas.moveViewportCenter(deltaX, deltaY);
450 } 454 }
451 455
452 mDesktopCanvas.repositionImage(true); 456 mDesktopCanvas.repositionImage();
453 } 457 }
454 458
455 /** Moves the cursor to the specified position on the screen. */ 459 /** Moves the cursor to the specified position on the screen. */
456 private void moveCursorToScreenPoint(float screenX, float screenY) { 460 private void moveCursorToScreenPoint(float screenX, float screenY) {
457 float[] imagePoint = mapScreenPointToImagePoint(screenX, screenY); 461 float[] imagePoint = mapScreenPointToImagePoint(screenX, screenY);
458 moveCursor(imagePoint[0], imagePoint[1]); 462 moveCursor(imagePoint[0], imagePoint[1]);
459 } 463 }
460 464
461 /** Moves the cursor to the specified position on the remote host. */ 465 /** Moves the cursor to the specified position on the remote host. */
462 private void moveCursor(float newX, float newY) { 466 private void moveCursor(float newX, float newY) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 float[] mappedPoints = mapScreenPointToImagePoint(screenX, screenY); 696 float[] mappedPoints = mapScreenPointToImagePoint(screenX, screenY);
693 697
694 float imageWidth = (float) mRenderData.imageWidth + EPSILON; 698 float imageWidth = (float) mRenderData.imageWidth + EPSILON;
695 float imageHeight = (float) mRenderData.imageHeight + EPSILON; 699 float imageHeight = (float) mRenderData.imageHeight + EPSILON;
696 700
697 return mappedPoints[0] < -EPSILON || mappedPoints[0] > imageWidth 701 return mappedPoints[0] < -EPSILON || mappedPoints[0] > imageWidth
698 || mappedPoints[1] < -EPSILON || mappedPoints[1] > imageHeig ht; 702 || mappedPoints[1] < -EPSILON || mappedPoints[1] > imageHeig ht;
699 } 703 }
700 } 704 }
701 } 705 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698