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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 resizeImageToFitScreen(); | 354 resizeImageToFitScreen(); |
355 } | 355 } |
356 | 356 |
357 private void resizeImageToFitScreen() { | 357 private void resizeImageToFitScreen() { |
358 mDesktopCanvas.resizeImageToFitScreen(); | 358 mDesktopCanvas.resizeImageToFitScreen(); |
359 float screenCenterX; | 359 float screenCenterX; |
360 float screenCenterY; | 360 float screenCenterY; |
361 synchronized (mRenderData) { | 361 synchronized (mRenderData) { |
362 screenCenterX = (float) mRenderData.screenWidth / 2; | 362 screenCenterX = (float) mRenderData.screenWidth / 2; |
363 screenCenterY = (float) mRenderData.screenHeight / 2; | 363 screenCenterY = (float) mRenderData.screenHeight / 2; |
364 | |
365 float[] imagePoint = mapScreenPointToImagePoint(screenCenterX, scree nCenterY); | |
366 mDesktopCanvas.setViewportPosition(imagePoint[0], imagePoint[1]); | |
364 } | 367 } |
365 moveCursorToScreenPoint(screenCenterX, screenCenterY); | 368 moveCursorToScreenPoint(screenCenterX, screenCenterY); |
369 mDesktopCanvas.repositionImage(true); | |
366 } | 370 } |
367 | 371 |
368 private void setInputStrategy(InputStrategyInterface inputStrategy) { | 372 private void setInputStrategy(InputStrategyInterface inputStrategy) { |
369 // Since the rules for flinging differ between input modes, we want to s top running the | 373 // Since the rules for flinging differ between input modes, we want to s top running the |
370 // current fling animation when the mode changes to prevent a wonky expe rience. | 374 // current fling animation when the mode changes to prevent a wonky expe rience. |
371 mCursorAnimationJob.abortAnimation(); | 375 mCursorAnimationJob.abortAnimation(); |
372 mScrollAnimationJob.abortAnimation(); | 376 mScrollAnimationJob.abortAnimation(); |
373 mInputStrategy = inputStrategy; | 377 mInputStrategy = inputStrategy; |
374 } | 378 } |
375 | 379 |
(...skipping 16 matching lines...) Expand all Loading... | |
392 // keep the cursor centered, if possible, as the viewport moves. | 396 // keep the cursor centered, if possible, as the viewport moves. |
393 if (followCursor) { | 397 if (followCursor) { |
394 moveCursor((int) newPos.x, (int) newPos.y); | 398 moveCursor((int) newPos.x, (int) newPos.y); |
395 } | 399 } |
396 | 400 |
397 mDesktopCanvas.repositionImage(true); | 401 mDesktopCanvas.repositionImage(true); |
398 } | 402 } |
399 | 403 |
400 /** Moves the cursor to the specified position on the screen. */ | 404 /** Moves the cursor to the specified position on the screen. */ |
401 private void moveCursorToScreenPoint(float screenX, float screenY) { | 405 private void moveCursorToScreenPoint(float screenX, float screenY) { |
402 float[] mappedValues = {screenX, screenY}; | 406 float[] imagePoint = mapScreenPointToImagePoint(screenX, screenY); |
403 synchronized (mRenderData) { | 407 moveCursor((int) imagePoint[0], (int) imagePoint[1]); |
404 Matrix canvasToImage = new Matrix(); | |
405 mRenderData.transform.invert(canvasToImage); | |
406 canvasToImage.mapPoints(mappedValues); | |
407 } | |
408 moveCursor((int) mappedValues[0], (int) mappedValues[1]); | |
409 } | 408 } |
410 | 409 |
411 /** Moves the cursor to the specified position on the remote host. */ | 410 /** Moves the cursor to the specified position on the remote host. */ |
412 private void moveCursor(int newX, int newY) { | 411 private void moveCursor(int newX, int newY) { |
413 synchronized (mRenderData) { | 412 synchronized (mRenderData) { |
414 boolean cursorMoved = mRenderData.setCursorPosition(newX, newY); | 413 boolean cursorMoved = mRenderData.setCursorPosition(newX, newY); |
415 if (cursorMoved) { | 414 if (cursorMoved) { |
416 mInputStrategy.injectCursorMoveEvent(newX, newY); | 415 mInputStrategy.injectCursorMoveEvent(newX, newY); |
417 } | 416 } |
418 } | 417 } |
(...skipping 11 matching lines...) Expand all Loading... | |
430 } else { | 429 } else { |
431 return false; | 430 return false; |
432 } | 431 } |
433 | 432 |
434 mSuppressCursorMovement = true; | 433 mSuppressCursorMovement = true; |
435 mSuppressFling = true; | 434 mSuppressFling = true; |
436 mSwipeCompleted = true; | 435 mSwipeCompleted = true; |
437 return true; | 436 return true; |
438 } | 437 } |
439 | 438 |
439 /** Translates a point in screen coordinates to a location on the desktop im age. */ | |
440 private float[] mapScreenPointToImagePoint(float screenX, float screenY) { | |
441 float[] mappedPoints = {screenX, screenY}; | |
442 Matrix screenToImage = new Matrix(); | |
443 synchronized (mRenderData) { | |
444 mRenderData.transform.invert(screenToImage); | |
445 } | |
446 screenToImage.mapPoints(mappedPoints); | |
447 | |
448 return mappedPoints; | |
449 } | |
450 | |
440 /** Responds to touch events filtered by the gesture detectors. */ | 451 /** Responds to touch events filtered by the gesture detectors. */ |
441 private class GestureListener extends GestureDetector.SimpleOnGestureListene r | 452 private class GestureListener extends GestureDetector.SimpleOnGestureListene r |
442 implements ScaleGestureDetector.OnScaleGestureListener, | 453 implements ScaleGestureDetector.OnScaleGestureListener, |
443 TapGestureDetector.OnTapListener { | 454 TapGestureDetector.OnTapListener { |
444 /** | 455 /** |
445 * Called when the user drags one or more fingers across the touchscreen . | 456 * Called when the user drags one or more fingers across the touchscreen . |
446 */ | 457 */ |
447 @Override | 458 @Override |
448 public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { | 459 public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { |
449 int pointerCount = e2.getPointerCount(); | 460 int pointerCount = e2.getPointerCount(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 | 574 |
564 /** Called when the user taps the screen with one or more fingers. */ | 575 /** Called when the user taps the screen with one or more fingers. */ |
565 @Override | 576 @Override |
566 public boolean onTap(int pointerCount, float x, float y) { | 577 public boolean onTap(int pointerCount, float x, float y) { |
567 int button = mouseButtonFromPointerCount(pointerCount); | 578 int button = mouseButtonFromPointerCount(pointerCount); |
568 if (button == InputStub.BUTTON_UNDEFINED) { | 579 if (button == InputStub.BUTTON_UNDEFINED) { |
569 return false; | 580 return false; |
570 } | 581 } |
571 | 582 |
572 if (!mInputStrategy.isIndirectInputMode()) { | 583 if (!mInputStrategy.isIndirectInputMode()) { |
573 if (!mapScreenPointToImage(x, y)) { | 584 if (screenPointLiesOutsideImageBoundary(x, y)) { |
574 return false; | 585 return false; |
575 } | 586 } |
576 moveCursorToScreenPoint(x, y); | 587 moveCursorToScreenPoint(x, y); |
577 } | 588 } |
578 | 589 |
579 if (mInputStrategy.onTap(button)) { | 590 if (mInputStrategy.onTap(button)) { |
580 Point pos; | 591 Point pos; |
581 synchronized (mRenderData) { | 592 synchronized (mRenderData) { |
582 pos = mRenderData.getCursorPosition(); | 593 pos = mRenderData.getCursorPosition(); |
583 } | 594 } |
584 mViewer.showInputFeedback(mInputStrategy.getShortPressFeedbackTy pe(), pos); | 595 mViewer.showInputFeedback(mInputStrategy.getShortPressFeedbackTy pe(), pos); |
585 } | 596 } |
586 return true; | 597 return true; |
587 } | 598 } |
588 | 599 |
589 /** Called when a long-press is triggered for one or more fingers. */ | 600 /** Called when a long-press is triggered for one or more fingers. */ |
590 @Override | 601 @Override |
591 public void onLongPress(int pointerCount, float x, float y) { | 602 public void onLongPress(int pointerCount, float x, float y) { |
592 int button = mouseButtonFromPointerCount(pointerCount); | 603 int button = mouseButtonFromPointerCount(pointerCount); |
593 if (button == InputStub.BUTTON_UNDEFINED) { | 604 if (button == InputStub.BUTTON_UNDEFINED) { |
594 return; | 605 return; |
595 } | 606 } |
596 | 607 |
597 if (!mInputStrategy.isIndirectInputMode()) { | 608 if (!mInputStrategy.isIndirectInputMode()) { |
598 if (!mapScreenPointToImage(x, y)) { | 609 if (screenPointLiesOutsideImageBoundary(x, y)) { |
599 return; | 610 return; |
600 } | 611 } |
601 moveCursorToScreenPoint(x, y); | 612 moveCursorToScreenPoint(x, y); |
602 } | 613 } |
603 | 614 |
604 if (mInputStrategy.onPressAndHold(button)) { | 615 if (mInputStrategy.onPressAndHold(button)) { |
605 Point pos; | 616 Point pos; |
606 synchronized (mRenderData) { | 617 synchronized (mRenderData) { |
607 pos = mRenderData.getCursorPosition(); | 618 pos = mRenderData.getCursorPosition(); |
608 } | 619 } |
(...skipping 10 matching lines...) Expand all Loading... | |
619 return InputStub.BUTTON_LEFT; | 630 return InputStub.BUTTON_LEFT; |
620 case 2: | 631 case 2: |
621 return InputStub.BUTTON_RIGHT; | 632 return InputStub.BUTTON_RIGHT; |
622 case 3: | 633 case 3: |
623 return InputStub.BUTTON_MIDDLE; | 634 return InputStub.BUTTON_MIDDLE; |
624 default: | 635 default: |
625 return InputStub.BUTTON_UNDEFINED; | 636 return InputStub.BUTTON_UNDEFINED; |
626 } | 637 } |
627 } | 638 } |
628 | 639 |
629 /** Verifies the given point maps to a valid location within the desktop image. */ | 640 /** Determines whether the given screen point lies outside the desktop i mage. */ |
630 private boolean mapScreenPointToImage(float screenX, float screenY) { | 641 private boolean screenPointLiesOutsideImageBoundary(float screenX, float screenY) { |
631 float[] mappedPoints = {screenX, screenY}; | 642 float[] mappedPoints = mapScreenPointToImagePoint(screenX, screenY); |
632 int imageWidth; | 643 int imageWidth; |
633 int imageHeight; | 644 int imageHeight; |
634 Matrix screenToImage = new Matrix(); | |
635 synchronized (mRenderData) { | 645 synchronized (mRenderData) { |
636 mRenderData.transform.invert(screenToImage); | |
637 imageWidth = mRenderData.imageWidth; | 646 imageWidth = mRenderData.imageWidth; |
638 imageHeight = mRenderData.imageHeight; | 647 imageHeight = mRenderData.imageHeight; |
639 } | 648 } |
640 screenToImage.mapPoints(mappedPoints); | |
641 | 649 |
642 return (mappedPoints[0] >= 0 && mappedPoints[0] <= imageWidth) | 650 return (mappedPoints[0] < 0 && mappedPoints[0] > imageWidth) |
Lambros
2016/07/14 21:11:08
The '&&'s should be ||, and the parentheses are no
joedow
2016/07/14 21:47:36
Oh geez, not sure why I didn't catch this in my te
| |
643 && (mappedPoints[1] >= 0 && mappedPoints[1] <= imageHeight); | 651 || (mappedPoints[1] < 0 && mappedPoints[1] > imageHeight); |
644 } | 652 } |
645 } | 653 } |
646 } | 654 } |
OLD | NEW |