OLD | NEW |
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.Point; | 9 import android.graphics.Point; |
10 import android.graphics.PointF; | 10 import android.graphics.PointF; |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 if (followCursor) { | 387 if (followCursor) { |
388 deltaX = -deltaX; | 388 deltaX = -deltaX; |
389 deltaY = -deltaY; | 389 deltaY = -deltaY; |
390 } | 390 } |
391 // Determine the center point from which to apply the delta. | 391 // Determine the center point from which to apply the delta. |
392 // For indirect input modes (i.e. trackpad), the view generally follows
the cursor. | 392 // For indirect input modes (i.e. trackpad), the view generally follows
the cursor. |
393 // For direct input modes (i.e. touch) the should track the user's motio
n. | 393 // For direct input modes (i.e. touch) the should track the user's motio
n. |
394 // If the user is dragging, then the viewport should always follow the u
ser's finger. | 394 // If the user is dragging, then the viewport should always follow the u
ser's finger. |
395 PointF newPos = mDesktopCanvas.moveViewportCenter(!followCursor, deltaX,
deltaY); | 395 PointF newPos = mDesktopCanvas.moveViewportCenter(!followCursor, deltaX,
deltaY); |
396 | 396 |
397 // If we are in an indirect mode or are in the middle of a drag operatio
n, then we want to | 397 // If we are in an indirect mode, then we want to keep the cursor center
ed, if possible, as |
398 // keep the cursor centered, if possible, as the viewport moves. | 398 // the viewport moves. |
399 if (followCursor) { | 399 if (mInputStrategy.isIndirectInputMode()) { |
400 moveCursor((int) newPos.x, (int) newPos.y); | 400 moveCursor((int) newPos.x, (int) newPos.y); |
401 } | 401 } |
402 | 402 |
403 mDesktopCanvas.repositionImage(true); | 403 mDesktopCanvas.repositionImage(true); |
404 } | 404 } |
405 | 405 |
406 /** Moves the cursor to the specified position on the screen. */ | 406 /** Moves the cursor to the specified position on the screen. */ |
407 private void moveCursorToScreenPoint(float screenX, float screenY) { | 407 private void moveCursorToScreenPoint(float screenX, float screenY) { |
408 float[] imagePoint = mapScreenPointToImagePoint(screenX, screenY); | 408 float[] imagePoint = mapScreenPointToImagePoint(screenX, screenY); |
409 moveCursor((int) imagePoint[0], (int) imagePoint[1]); | 409 moveCursor((int) imagePoint[0], (int) imagePoint[1]); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 } | 496 } |
497 | 497 |
498 float[] delta = {distanceX, distanceY}; | 498 float[] delta = {distanceX, distanceY}; |
499 synchronized (mRenderData) { | 499 synchronized (mRenderData) { |
500 Matrix canvasToImage = new Matrix(); | 500 Matrix canvasToImage = new Matrix(); |
501 mRenderData.transform.invert(canvasToImage); | 501 mRenderData.transform.invert(canvasToImage); |
502 canvasToImage.mapVectors(delta); | 502 canvasToImage.mapVectors(delta); |
503 } | 503 } |
504 | 504 |
505 moveViewportByOffset(delta[0], delta[1]); | 505 moveViewportByOffset(delta[0], delta[1]); |
| 506 if (!mInputStrategy.isIndirectInputMode() && mIsDragging) { |
| 507 // Ensure the cursor follows the user's finger when the user is
dragging under |
| 508 // direct input mode. |
| 509 moveCursorToScreenPoint(e2.getX(), e2.getY()); |
| 510 } |
506 return true; | 511 return true; |
507 } | 512 } |
508 | 513 |
509 /** | 514 /** |
510 * Called when a fling gesture is recognized. | 515 * Called when a fling gesture is recognized. |
511 */ | 516 */ |
512 @Override | 517 @Override |
513 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) { | 518 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) { |
514 if (mSuppressFling) { | 519 if (mSuppressFling) { |
515 return false; | 520 return false; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 synchronized (mRenderData) { | 652 synchronized (mRenderData) { |
648 imageWidth = (float) mRenderData.imageWidth + EPSILON; | 653 imageWidth = (float) mRenderData.imageWidth + EPSILON; |
649 imageHeight = (float) mRenderData.imageHeight + EPSILON; | 654 imageHeight = (float) mRenderData.imageHeight + EPSILON; |
650 } | 655 } |
651 | 656 |
652 return mappedPoints[0] < -EPSILON || mappedPoints[0] > imageWidth | 657 return mappedPoints[0] < -EPSILON || mappedPoints[0] > imageWidth |
653 || mappedPoints[1] < -EPSILON || mappedPoints[1] > imageHeig
ht; | 658 || mappedPoints[1] < -EPSILON || mappedPoints[1] > imageHeig
ht; |
654 } | 659 } |
655 } | 660 } |
656 } | 661 } |
OLD | NEW |