Chromium Code Reviews| 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 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 | 563 |
| 564 /** Called when the user taps the screen with one or more fingers. */ | 564 /** Called when the user taps the screen with one or more fingers. */ |
| 565 @Override | 565 @Override |
| 566 public boolean onTap(int pointerCount, float x, float y) { | 566 public boolean onTap(int pointerCount, float x, float y) { |
| 567 int button = mouseButtonFromPointerCount(pointerCount); | 567 int button = mouseButtonFromPointerCount(pointerCount); |
| 568 if (button == InputStub.BUTTON_UNDEFINED) { | 568 if (button == InputStub.BUTTON_UNDEFINED) { |
| 569 return false; | 569 return false; |
| 570 } | 570 } |
| 571 | 571 |
| 572 if (!mInputStrategy.isIndirectInputMode()) { | 572 if (!mInputStrategy.isIndirectInputMode()) { |
| 573 if (!mapScreenPointToImage(x, y)) { | |
| 574 return false; | |
| 575 } | |
| 573 moveCursorToScreenPoint(x, y); | 576 moveCursorToScreenPoint(x, y); |
| 574 } | 577 } |
| 575 | 578 |
| 576 if (mInputStrategy.onTap(button)) { | 579 if (mInputStrategy.onTap(button)) { |
| 577 Point pos; | 580 Point pos; |
| 578 synchronized (mRenderData) { | 581 synchronized (mRenderData) { |
| 579 pos = mRenderData.getCursorPosition(); | 582 pos = mRenderData.getCursorPosition(); |
| 580 } | 583 } |
| 581 mViewer.showInputFeedback(mInputStrategy.getShortPressFeedbackTy pe(), pos); | 584 mViewer.showInputFeedback(mInputStrategy.getShortPressFeedbackTy pe(), pos); |
| 582 } | 585 } |
| 583 return true; | 586 return true; |
| 584 } | 587 } |
| 585 | 588 |
| 586 /** Called when a long-press is triggered for one or more fingers. */ | 589 /** Called when a long-press is triggered for one or more fingers. */ |
| 587 @Override | 590 @Override |
| 588 public void onLongPress(int pointerCount, float x, float y) { | 591 public void onLongPress(int pointerCount, float x, float y) { |
| 589 int button = mouseButtonFromPointerCount(pointerCount); | 592 int button = mouseButtonFromPointerCount(pointerCount); |
| 590 if (button == InputStub.BUTTON_UNDEFINED) { | 593 if (button == InputStub.BUTTON_UNDEFINED) { |
| 591 return; | 594 return; |
| 592 } | 595 } |
| 593 | 596 |
| 594 if (!mInputStrategy.isIndirectInputMode()) { | 597 if (!mInputStrategy.isIndirectInputMode()) { |
| 598 if (!mapScreenPointToImage(x, y)) { | |
| 599 return; | |
| 600 } | |
| 595 moveCursorToScreenPoint(x, y); | 601 moveCursorToScreenPoint(x, y); |
| 596 } | 602 } |
| 597 | 603 |
| 598 if (mInputStrategy.onPressAndHold(button)) { | 604 if (mInputStrategy.onPressAndHold(button)) { |
| 599 Point pos; | 605 Point pos; |
| 600 synchronized (mRenderData) { | 606 synchronized (mRenderData) { |
| 601 pos = mRenderData.getCursorPosition(); | 607 pos = mRenderData.getCursorPosition(); |
| 602 } | 608 } |
| 603 mViewer.showInputFeedback(mInputStrategy.getLongPressFeedbackTyp e(), pos); | 609 mViewer.showInputFeedback(mInputStrategy.getLongPressFeedbackTyp e(), pos); |
| 604 mSuppressFling = true; | 610 mSuppressFling = true; |
| 605 mIsDragging = true; | 611 mIsDragging = true; |
| 606 } | 612 } |
| 607 } | 613 } |
| 608 | 614 |
| 609 /** Maps the number of fingers in a tap or long-press gesture to a mouse -button. */ | 615 /** Maps the number of fingers in a tap or long-press gesture to a mouse -button. */ |
| 610 private int mouseButtonFromPointerCount(int pointerCount) { | 616 private int mouseButtonFromPointerCount(int pointerCount) { |
| 611 switch (pointerCount) { | 617 switch (pointerCount) { |
| 612 case 1: | 618 case 1: |
| 613 return InputStub.BUTTON_LEFT; | 619 return InputStub.BUTTON_LEFT; |
| 614 case 2: | 620 case 2: |
| 615 return InputStub.BUTTON_RIGHT; | 621 return InputStub.BUTTON_RIGHT; |
| 616 case 3: | 622 case 3: |
| 617 return InputStub.BUTTON_MIDDLE; | 623 return InputStub.BUTTON_MIDDLE; |
| 618 default: | 624 default: |
| 619 return InputStub.BUTTON_UNDEFINED; | 625 return InputStub.BUTTON_UNDEFINED; |
| 620 } | 626 } |
| 621 } | 627 } |
| 628 | |
| 629 /** Verifies the given point maps to a valid location within the desktop image. */ | |
| 630 private boolean mapScreenPointToImage(float screenX, float screenY) { | |
|
Lambros
2016/07/12 23:19:50
Looks like we have this logic a few times in this
joedow
2016/07/13 00:04:50
Ack. I was thinking this kind of functionality ma
| |
| 631 float[] mappedPoints = {screenX, screenY}; | |
| 632 int imageWidth; | |
| 633 int imageHeight; | |
| 634 Matrix screenToImage = new Matrix(); | |
| 635 synchronized (mRenderData) { | |
| 636 mRenderData.transform.invert(screenToImage); | |
| 637 imageWidth = mRenderData.imageWidth; | |
| 638 imageHeight = mRenderData.imageHeight; | |
| 639 } | |
| 640 screenToImage.mapPoints(mappedPoints); | |
| 641 | |
| 642 return (mappedPoints[0] >= 0 && mappedPoints[0] <= imageWidth) | |
|
Lambros
2016/07/12 23:19:50
Is it worth adding a little bit of slop margin her
joedow
2016/07/13 00:04:50
I considered that, but this method is only used wh
| |
| 643 && (mappedPoints[1] >= 0 && mappedPoints[1] <= imageHeight); | |
| 644 } | |
| 622 } | 645 } |
| 623 } | 646 } |
| OLD | NEW |