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 | |
312 mDesktopCanvas.repositionImage(true); | 311 mDesktopCanvas.repositionImage(true); |
313 } | 312 } |
314 | 313 |
315 private boolean handleTouchEvent(MotionEvent event) { | 314 private boolean handleTouchEvent(MotionEvent event) { |
316 // Give the underlying input strategy a chance to observe the current mo
tion event before | 315 // 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 | 316 // 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. | 317 // event or save the payload for use in recreating the gesture remotely. |
319 mInputStrategy.onMotionEvent(event); | 318 mInputStrategy.onMotionEvent(event); |
320 | 319 |
321 // Avoid short-circuit logic evaluation - ensure all gesture detectors s
ee all events so | 320 // Avoid short-circuit logic evaluation - ensure all gesture detectors s
ee all events so |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 366 |
368 private void setInputStrategy(InputStrategyInterface inputStrategy) { | 367 private void setInputStrategy(InputStrategyInterface inputStrategy) { |
369 // Since the rules for flinging differ between input modes, we want to s
top running the | 368 // 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. | 369 // current fling animation when the mode changes to prevent a wonky expe
rience. |
371 mCursorAnimationJob.abortAnimation(); | 370 mCursorAnimationJob.abortAnimation(); |
372 mScrollAnimationJob.abortAnimation(); | 371 mScrollAnimationJob.abortAnimation(); |
373 mInputStrategy = inputStrategy; | 372 mInputStrategy = inputStrategy; |
374 } | 373 } |
375 | 374 |
376 /** Moves the desired center of the viewport using the specified deltas. */ | 375 /** Moves the desired center of the viewport using the specified deltas. */ |
377 private void moveViewportWithOffset(float deltaX, float deltaY) { | 376 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 | 377 // 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). | 378 // invert the direction of the operation (i.e. follow the motion of the
finger). |
380 if (mInputStrategy.isIndirectInputMode() || mIsDragging) { | 379 boolean followCursor = (mInputStrategy.isIndirectInputMode() || mIsDragg
ing); |
| 380 if (followCursor) { |
381 deltaX = -deltaX; | 381 deltaX = -deltaX; |
382 deltaY = -deltaY; | 382 deltaY = -deltaY; |
383 } | 383 } |
384 | |
385 // Determine the center point from which to apply the delta. | 384 // Determine the center point from which to apply the delta. |
386 // For indirect input modes (i.e. trackpad), the view generally follows
the cursor. | 385 // 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. | 386 // 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. | 387 // If the user is dragging, then the viewport should always follow the u
ser's finger. |
389 PointF viewportPoint; | 388 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 | 389 |
429 // If we are in an indirect mode or are in the middle of a drag operatio
n, then we want to | 390 // 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. | 391 // keep the cursor centered, if possible, as the viewport moves. |
431 if (mInputStrategy.isIndirectInputMode() || mIsDragging) { | 392 if (followCursor) { |
432 moveCursor((int) newX, (int) newY); | 393 moveCursor((int) newPos.x, (int) newPos.y); |
433 } | 394 } |
434 | 395 |
435 mDesktopCanvas.repositionImage(true); | 396 mDesktopCanvas.repositionImage(true); |
436 } | 397 } |
437 | 398 |
438 /** Moves the cursor to the specified position on the screen. */ | 399 /** Moves the cursor to the specified position on the screen. */ |
439 private void moveCursorToScreenPoint(float screenX, float screenY) { | 400 private void moveCursorToScreenPoint(float screenX, float screenY) { |
440 float[] mappedValues = {screenX, screenY}; | 401 float[] mappedValues = {screenX, screenY}; |
441 synchronized (mRenderData) { | 402 synchronized (mRenderData) { |
442 Matrix canvasToImage = new Matrix(); | 403 Matrix canvasToImage = new Matrix(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 return false; | 481 return false; |
521 } | 482 } |
522 | 483 |
523 float[] delta = {distanceX, distanceY}; | 484 float[] delta = {distanceX, distanceY}; |
524 synchronized (mRenderData) { | 485 synchronized (mRenderData) { |
525 Matrix canvasToImage = new Matrix(); | 486 Matrix canvasToImage = new Matrix(); |
526 mRenderData.transform.invert(canvasToImage); | 487 mRenderData.transform.invert(canvasToImage); |
527 canvasToImage.mapVectors(delta); | 488 canvasToImage.mapVectors(delta); |
528 } | 489 } |
529 | 490 |
530 moveViewportWithOffset(delta[0], delta[1]); | 491 moveViewportByOffset(delta[0], delta[1]); |
531 return true; | 492 return true; |
532 } | 493 } |
533 | 494 |
534 /** | 495 /** |
535 * Called when a fling gesture is recognized. | 496 * Called when a fling gesture is recognized. |
536 */ | 497 */ |
537 @Override | 498 @Override |
538 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) { | 499 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) { |
539 if (mSuppressFling) { | 500 if (mSuppressFling) { |
540 return false; | 501 return false; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 case 2: | 613 case 2: |
653 return InputStub.BUTTON_RIGHT; | 614 return InputStub.BUTTON_RIGHT; |
654 case 3: | 615 case 3: |
655 return InputStub.BUTTON_MIDDLE; | 616 return InputStub.BUTTON_MIDDLE; |
656 default: | 617 default: |
657 return InputStub.BUTTON_UNDEFINED; | 618 return InputStub.BUTTON_UNDEFINED; |
658 } | 619 } |
659 } | 620 } |
660 } | 621 } |
661 } | 622 } |
OLD | NEW |