| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 @Override | 103 @Override |
| 104 protected void processAction(float deltaX, float deltaY) { | 104 protected void processAction(float deltaX, float deltaY) { |
| 105 float[] delta = {deltaX, deltaY}; | 105 float[] delta = {deltaX, deltaY}; |
| 106 synchronized (mRenderData) { | 106 synchronized (mRenderData) { |
| 107 Matrix canvasToImage = new Matrix(); | 107 Matrix canvasToImage = new Matrix(); |
| 108 mRenderData.transform.invert(canvasToImage); | 108 mRenderData.transform.invert(canvasToImage); |
| 109 canvasToImage.mapVectors(delta); | 109 canvasToImage.mapVectors(delta); |
| 110 } | 110 } |
| 111 | 111 |
| 112 moveViewportWithOffset(-delta[0], -delta[1]); | 112 moveViewportByOffset(-delta[0], -delta[1]); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * This class implements fling animation for scrolling | 117 * This class implements fling animation for scrolling |
| 118 */ | 118 */ |
| 119 private class ScrollAnimationJob extends FlingAnimationJob { | 119 private class ScrollAnimationJob extends FlingAnimationJob { |
| 120 public ScrollAnimationJob(Context context) { | 120 public ScrollAnimationJob(Context context) { |
| 121 super(context); | 121 super(context); |
| 122 } | 122 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 public void init(Desktop desktop, final InputEventSender injector) { | 226 public void init(Desktop desktop, final InputEventSender injector) { |
| 227 Preconditions.notNull(injector); | 227 Preconditions.notNull(injector); |
| 228 desktop.onInputModeChanged().add( | 228 desktop.onInputModeChanged().add( |
| 229 new Event.ParameterRunnable<InputModeChangedEventParameter>() { | 229 new Event.ParameterRunnable<InputModeChangedEventParameter>() { |
| 230 @Override | 230 @Override |
| 231 public void run(InputModeChangedEventParameter parameter) { | 231 public void run(InputModeChangedEventParameter parameter) { |
| 232 handleInputModeChanged(parameter, injector); | 232 handleInputModeChanged(parameter, injector); |
| 233 } | 233 } |
| 234 }); | 234 }); |
| 235 | 235 |
| 236 desktop.onSoftInputMethodVisibilityChanged().add( | 236 desktop.onSystemUiVisibilityChanged().add( |
| 237 new Event.ParameterRunnable<SoftInputMethodVisibilityChangedEven
tParameter>() { | 237 new Event.ParameterRunnable<SystemUiVisibilityChangedEventParame
ter>() { |
| 238 @Override | 238 @Override |
| 239 public void run(SoftInputMethodVisibilityChangedEventParamet
er parameter) { | 239 public void run(SystemUiVisibilityChangedEventParameter para
meter) { |
| 240 handleSoftInputMethodVisibilityChanged(parameter); | 240 handleSystemUiVisibilityChanged(parameter); |
| 241 } | 241 } |
| 242 }); | 242 }); |
| 243 } | 243 } |
| 244 | 244 |
| 245 private void attachViewEvents(DesktopViewInterface viewer) { | 245 private void attachViewEvents(DesktopViewInterface viewer) { |
| 246 viewer.onTouch().add(new Event.ParameterRunnable<TouchEventParameter>()
{ | 246 viewer.onTouch().add(new Event.ParameterRunnable<TouchEventParameter>()
{ |
| 247 @Override | 247 @Override |
| 248 public void run(TouchEventParameter parameter) { | 248 public void run(TouchEventParameter parameter) { |
| 249 parameter.handled = handleTouchEvent(parameter.event); | 249 parameter.handled = handleTouchEvent(parameter.event); |
| 250 } | 250 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 290 |
| 291 default: | 291 default: |
| 292 // Unreachable, but required by Google Java style and findbugs. | 292 // Unreachable, but required by Google Java style and findbugs. |
| 293 assert false : "Unreached"; | 293 assert false : "Unreached"; |
| 294 } | 294 } |
| 295 | 295 |
| 296 // Ensure the cursor state is updated appropriately. | 296 // Ensure the cursor state is updated appropriately. |
| 297 mViewer.cursorVisibilityChanged(); | 297 mViewer.cursorVisibilityChanged(); |
| 298 } | 298 } |
| 299 | 299 |
| 300 private void handleSoftInputMethodVisibilityChanged( | 300 private void handleSystemUiVisibilityChanged( |
| 301 SoftInputMethodVisibilityChangedEventParameter parameter) { | 301 SystemUiVisibilityChangedEventParameter parameter) { |
| 302 synchronized (mRenderData) { | 302 synchronized (mRenderData) { |
| 303 if (parameter.visible) { | 303 if (parameter.softInputMethodVisible) { |
| 304 mDesktopCanvas.setInputMethodOffsetValues( | 304 mDesktopCanvas.setSystemUiOffsetValues(parameter.left, parameter
.top, |
| 305 mRenderData.screenWidth - parameter.right, | 305 mRenderData.screenWidth - parameter.right, |
| 306 mRenderData.screenHeight - parameter.bottom); | 306 mRenderData.screenHeight - parameter.bottom); |
| 307 } else { | 307 } else { |
| 308 mDesktopCanvas.setInputMethodOffsetValues(0, 0); | 308 mDesktopCanvas.setSystemUiOffsetValues(0, 0, 0, 0); |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 | 311 |
| 312 mDesktopCanvas.repositionImage(true); | 312 mDesktopCanvas.repositionImage(true); |
| 313 } | 313 } |
| 314 | 314 |
| 315 private boolean handleTouchEvent(MotionEvent event) { | 315 private boolean handleTouchEvent(MotionEvent event) { |
| 316 // Give the underlying input strategy a chance to observe the current mo
tion event before | 316 // Give the underlying input strategy a chance to observe the current mo
tion event before |
| 317 // passing it to the gesture detectors. This allows the input strategy
to react to the | 317 // passing it to the gesture detectors. This allows the input strategy
to react to the |
| 318 // event or save the payload for use in recreating the gesture remotely. | 318 // event or save the payload for use in recreating the gesture remotely. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 367 |
| 368 private void setInputStrategy(InputStrategyInterface inputStrategy) { | 368 private void setInputStrategy(InputStrategyInterface inputStrategy) { |
| 369 // Since the rules for flinging differ between input modes, we want to s
top running the | 369 // 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. | 370 // current fling animation when the mode changes to prevent a wonky expe
rience. |
| 371 mCursorAnimationJob.abortAnimation(); | 371 mCursorAnimationJob.abortAnimation(); |
| 372 mScrollAnimationJob.abortAnimation(); | 372 mScrollAnimationJob.abortAnimation(); |
| 373 mInputStrategy = inputStrategy; | 373 mInputStrategy = inputStrategy; |
| 374 } | 374 } |
| 375 | 375 |
| 376 /** Moves the desired center of the viewport using the specified deltas. */ | 376 /** Moves the desired center of the viewport using the specified deltas. */ |
| 377 private void moveViewportWithOffset(float deltaX, float deltaY) { | 377 private void moveViewportByOffset(float deltaX, float deltaY) { |
| 378 // If we are in an indirect mode or are in the middle of a drag operatio
n, then we want to | 378 // If we are in an indirect mode or are in the middle of a drag operatio
n, then we want to |
| 379 // invert the direction of the operation (i.e. follow the motion of the
finger). | 379 // invert the direction of the operation (i.e. follow the motion of the
finger). |
| 380 if (mInputStrategy.isIndirectInputMode() || mIsDragging) { | 380 boolean followCursor = (mInputStrategy.isIndirectInputMode() || mIsDragg
ing); |
| 381 if (followCursor) { |
| 381 deltaX = -deltaX; | 382 deltaX = -deltaX; |
| 382 deltaY = -deltaY; | 383 deltaY = -deltaY; |
| 383 } | 384 } |
| 384 | |
| 385 // Determine the center point from which to apply the delta. | 385 // Determine the center point from which to apply the delta. |
| 386 // For indirect input modes (i.e. trackpad), the view generally follows
the cursor. | 386 // For indirect input modes (i.e. trackpad), the view generally follows
the cursor. |
| 387 // For direct input modes (i.e. touch) the should track the user's motio
n. | 387 // For direct input modes (i.e. touch) the should track the user's motio
n. |
| 388 // If the user is dragging, then the viewport should always follow the u
ser's finger. | 388 // If the user is dragging, then the viewport should always follow the u
ser's finger. |
| 389 PointF viewportPoint; | 389 PointF newPos = mDesktopCanvas.moveViewportCenter(!followCursor, deltaX,
deltaY); |
| 390 if (mInputStrategy.isIndirectInputMode() || mIsDragging) { | |
| 391 viewportPoint = mDesktopCanvas.getViewportPosition(); | |
| 392 } else { | |
| 393 PointF adjustedViewportSize = mDesktopCanvas.getViewportSize(); | |
| 394 synchronized (mRenderData) { | |
| 395 float[] viewportPosition = new float[] {(float) adjustedViewport
Size.x / 2, | |
| 396 (float) adjustedViewport
Size.y / 2}; | |
| 397 Matrix inverted = new Matrix(); | |
| 398 mRenderData.transform.invert(inverted); | |
| 399 inverted.mapPoints(viewportPosition); | |
| 400 viewportPoint = new PointF(viewportPosition[0], viewportPosition
[1]); | |
| 401 } | |
| 402 } | |
| 403 | |
| 404 // Constrain the coordinates to the image area. | |
| 405 float newX = viewportPoint.x + deltaX; | |
| 406 float newY = viewportPoint.y + deltaY; | |
| 407 synchronized (mRenderData) { | |
| 408 // Constrain viewport position to the image area. | |
| 409 if (newX < 0) { | |
| 410 newX = 0; | |
| 411 } else if (newX > mRenderData.imageWidth) { | |
| 412 newX = mRenderData.imageWidth; | |
| 413 } | |
| 414 | |
| 415 if (newY < 0) { | |
| 416 newY = 0; | |
| 417 } else if (newY > mRenderData.imageHeight) { | |
| 418 newY = mRenderData.imageHeight; | |
| 419 } | |
| 420 } | |
| 421 | |
| 422 moveViewport(newX, newY); | |
| 423 } | |
| 424 | |
| 425 /** Moves the desired center of the viewport to the specified position. */ | |
| 426 private void moveViewport(float newX, float newY) { | |
| 427 mDesktopCanvas.setViewportPosition(newX, newY); | |
| 428 | 390 |
| 429 // If we are in an indirect mode or are in the middle of a drag operatio
n, then we want to | 391 // If we are in an indirect mode or are in the middle of a drag operatio
n, then we want to |
| 430 // keep the cursor centered, if possible, as the viewport moves. | 392 // keep the cursor centered, if possible, as the viewport moves. |
| 431 if (mInputStrategy.isIndirectInputMode() || mIsDragging) { | 393 if (followCursor) { |
| 432 moveCursor((int) newX, (int) newY); | 394 moveCursor((int) newPos.x, (int) newPos.y); |
| 433 } | 395 } |
| 434 | 396 |
| 435 mDesktopCanvas.repositionImage(true); | 397 mDesktopCanvas.repositionImage(true); |
| 436 } | 398 } |
| 437 | 399 |
| 438 /** Moves the cursor to the specified position on the screen. */ | 400 /** Moves the cursor to the specified position on the screen. */ |
| 439 private void moveCursorToScreenPoint(float screenX, float screenY) { | 401 private void moveCursorToScreenPoint(float screenX, float screenY) { |
| 440 float[] mappedValues = {screenX, screenY}; | 402 float[] mappedValues = {screenX, screenY}; |
| 441 synchronized (mRenderData) { | 403 synchronized (mRenderData) { |
| 442 Matrix canvasToImage = new Matrix(); | 404 Matrix canvasToImage = new Matrix(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 return false; | 482 return false; |
| 521 } | 483 } |
| 522 | 484 |
| 523 float[] delta = {distanceX, distanceY}; | 485 float[] delta = {distanceX, distanceY}; |
| 524 synchronized (mRenderData) { | 486 synchronized (mRenderData) { |
| 525 Matrix canvasToImage = new Matrix(); | 487 Matrix canvasToImage = new Matrix(); |
| 526 mRenderData.transform.invert(canvasToImage); | 488 mRenderData.transform.invert(canvasToImage); |
| 527 canvasToImage.mapVectors(delta); | 489 canvasToImage.mapVectors(delta); |
| 528 } | 490 } |
| 529 | 491 |
| 530 moveViewportWithOffset(delta[0], delta[1]); | 492 moveViewportByOffset(delta[0], delta[1]); |
| 531 return true; | 493 return true; |
| 532 } | 494 } |
| 533 | 495 |
| 534 /** | 496 /** |
| 535 * Called when a fling gesture is recognized. | 497 * Called when a fling gesture is recognized. |
| 536 */ | 498 */ |
| 537 @Override | 499 @Override |
| 538 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) { | 500 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) { |
| 539 if (mSuppressFling) { | 501 if (mSuppressFling) { |
| 540 return false; | 502 return false; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 case 2: | 614 case 2: |
| 653 return InputStub.BUTTON_RIGHT; | 615 return InputStub.BUTTON_RIGHT; |
| 654 case 3: | 616 case 3: |
| 655 return InputStub.BUTTON_MIDDLE; | 617 return InputStub.BUTTON_MIDDLE; |
| 656 default: | 618 default: |
| 657 return InputStub.BUTTON_UNDEFINED; | 619 return InputStub.BUTTON_UNDEFINED; |
| 658 } | 620 } |
| 659 } | 621 } |
| 660 } | 622 } |
| 661 } | 623 } |
| OLD | NEW |