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.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 Loading... |
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 401 } |
403 | 402 |
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() { |
| 411 if (mRenderData.imageWidth == 0 || mRenderData.imageHeight == 0 |
| 412 || mRenderData.screenWidth == 0 || mRenderData.screenHeight == 0
) { |
| 413 return; |
| 414 } |
| 415 |
412 mDesktopCanvas.resizeImageToFitScreen(); | 416 mDesktopCanvas.resizeImageToFitScreen(); |
413 | 417 |
| 418 moveCursorToScreenCenter(); |
| 419 } |
| 420 |
| 421 private void moveCursorToScreenCenter() { |
414 float screenCenterX = (float) mRenderData.screenWidth / 2; | 422 float screenCenterX = (float) mRenderData.screenWidth / 2; |
415 float screenCenterY = (float) mRenderData.screenHeight / 2; | 423 float screenCenterY = (float) mRenderData.screenHeight / 2; |
416 | 424 |
417 float[] imagePoint = mapScreenPointToImagePoint(screenCenterX, screenCen
terY); | 425 float[] imagePoint = mapScreenPointToImagePoint(screenCenterX, screenCen
terY); |
418 mDesktopCanvas.setViewportPosition(imagePoint[0], imagePoint[1]); | 426 mDesktopCanvas.setCursorPosition(imagePoint[0], imagePoint[1]); |
419 | 427 |
420 moveCursorToScreenPoint(screenCenterX, screenCenterY); | 428 moveCursorToScreenPoint(screenCenterX, screenCenterY); |
421 mDesktopCanvas.repositionImage(true); | |
422 } | 429 } |
423 | 430 |
424 private void setInputStrategy(InputStrategyInterface inputStrategy) { | 431 private void setInputStrategy(InputStrategyInterface inputStrategy) { |
425 // Since the rules for flinging differ between input modes, we want to s
top running the | 432 // 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. | 433 // current fling animation when the mode changes to prevent a wonky expe
rience. |
427 abortAnimation(); | 434 abortAnimation(); |
428 mInputStrategy = inputStrategy; | 435 mInputStrategy = inputStrategy; |
429 } | 436 } |
430 | 437 |
431 /** Moves the desired center of the viewport using the specified deltas. */ | 438 /** Moves the desired center of the viewport using the specified deltas. */ |
432 private void moveViewportByOffset(float deltaX, float deltaY) { | 439 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 | 440 // 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). | 441 // invert the direction of the operation (i.e. follow the motion of the
finger). |
435 boolean followCursor = (mInputStrategy.isIndirectInputMode() || mIsDragg
ing); | 442 boolean followCursor = (mInputStrategy.isIndirectInputMode() || mIsDragg
ing); |
436 if (followCursor) { | 443 if (followCursor) { |
437 deltaX = -deltaX; | 444 deltaX = -deltaX; |
438 deltaY = -deltaY; | 445 deltaY = -deltaY; |
439 } | 446 } |
| 447 |
440 // Determine the center point from which to apply the delta. | 448 // Determine the center point from which to apply the delta. |
441 // For indirect input modes (i.e. trackpad), the view generally follows
the cursor. | 449 // 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. | 450 // 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. | 451 // 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()) { | 452 if (mInputStrategy.isIndirectInputMode()) { |
449 moveCursor(newPos.x, newPos.y); | 453 PointF newCursorPos = mDesktopCanvas.moveCursorPosition(deltaX, delt
aY); |
| 454 moveCursor(newCursorPos.x, newCursorPos.y); |
| 455 } else { |
| 456 mDesktopCanvas.moveViewportCenter(deltaX, deltaY); |
450 } | 457 } |
451 | |
452 mDesktopCanvas.repositionImage(true); | |
453 } | 458 } |
454 | 459 |
455 /** Moves the cursor to the specified position on the screen. */ | 460 /** Moves the cursor to the specified position on the screen. */ |
456 private void moveCursorToScreenPoint(float screenX, float screenY) { | 461 private void moveCursorToScreenPoint(float screenX, float screenY) { |
457 float[] imagePoint = mapScreenPointToImagePoint(screenX, screenY); | 462 float[] imagePoint = mapScreenPointToImagePoint(screenX, screenY); |
458 moveCursor(imagePoint[0], imagePoint[1]); | 463 moveCursor(imagePoint[0], imagePoint[1]); |
459 } | 464 } |
460 | 465 |
461 /** Moves the cursor to the specified position on the remote host. */ | 466 /** Moves the cursor to the specified position on the remote host. */ |
462 private void moveCursor(float newX, float newY) { | 467 private void moveCursor(float newX, float newY) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 return true; | 591 return true; |
587 } | 592 } |
588 | 593 |
589 /** Called when the user is in the process of pinch-zooming. */ | 594 /** Called when the user is in the process of pinch-zooming. */ |
590 @Override | 595 @Override |
591 public boolean onScale(ScaleGestureDetector detector) { | 596 public boolean onScale(ScaleGestureDetector detector) { |
592 if (!mSwipePinchDetector.isPinching()) { | 597 if (!mSwipePinchDetector.isPinching()) { |
593 return false; | 598 return false; |
594 } | 599 } |
595 | 600 |
596 float scaleFactor = detector.getScaleFactor(); | 601 mDesktopCanvas.scaleAndRepositionImage(detector.getScaleFactor(), de
tector.getFocusX(), |
597 | 602 detector.getFocusY(), mInputStrategy.isIndirectInputMode()); |
598 mRenderData.transform.postScale( | |
599 scaleFactor, scaleFactor, detector.getFocusX(), detector.get
FocusY()); | |
600 | |
601 // For indirect input modes we want to zoom using the cursor as the
focal point, for | |
602 // direct modes we use the actual focal point of the gesture. | |
603 mDesktopCanvas.repositionImageWithZoom(mInputStrategy.isIndirectInpu
tMode()); | |
604 | 603 |
605 return true; | 604 return true; |
606 } | 605 } |
607 | 606 |
608 /** Called whenever a gesture starts. Always accepts the gesture so it i
sn't ignored. */ | 607 /** Called whenever a gesture starts. Always accepts the gesture so it i
sn't ignored. */ |
609 @Override | 608 @Override |
610 public boolean onDown(MotionEvent e) { | 609 public boolean onDown(MotionEvent e) { |
611 return true; | 610 return true; |
612 } | 611 } |
613 | 612 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 float[] mappedPoints = mapScreenPointToImagePoint(screenX, screenY); | 691 float[] mappedPoints = mapScreenPointToImagePoint(screenX, screenY); |
693 | 692 |
694 float imageWidth = (float) mRenderData.imageWidth + EPSILON; | 693 float imageWidth = (float) mRenderData.imageWidth + EPSILON; |
695 float imageHeight = (float) mRenderData.imageHeight + EPSILON; | 694 float imageHeight = (float) mRenderData.imageHeight + EPSILON; |
696 | 695 |
697 return mappedPoints[0] < -EPSILON || mappedPoints[0] > imageWidth | 696 return mappedPoints[0] < -EPSILON || mappedPoints[0] > imageWidth |
698 || mappedPoints[1] < -EPSILON || mappedPoints[1] > imageHeig
ht; | 697 || mappedPoints[1] < -EPSILON || mappedPoints[1] > imageHeig
ht; |
699 } | 698 } |
700 } | 699 } |
701 } | 700 } |
OLD | NEW |