Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java

Issue 2103933002: Updating SystemUI visibility events in Adroid Client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/SystemUiVisibilityChangedEventParameter.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(-deltaX, -deltaY); 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
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // TODO (zijiehe): Move repaint control out of DesktopView. 297 // TODO (zijiehe): Move repaint control out of DesktopView.
298 if (mViewer instanceof DesktopView) { 298 if (mViewer instanceof DesktopView) {
299 ((DesktopView) mViewer).requestRepaint(); 299 ((DesktopView) mViewer).requestRepaint();
300 } 300 }
301 } 301 }
302 302
303 private void handleSoftInputMethodVisibilityChanged( 303 private void handleSystemUiVisibilityChanged(
304 SoftInputMethodVisibilityChangedEventParameter parameter) { 304 SystemUiVisibilityChangedEventParameter parameter) {
305 synchronized (mRenderData) { 305 synchronized (mRenderData) {
306 if (parameter.visible) { 306 if (parameter.systemUiVisible) {
307 mDesktopCanvas.setInputMethodOffsetValues( 307 mDesktopCanvas.setSystemUiOffsetValues(parameter.left, parameter .top,
308 mRenderData.screenWidth - parameter.right, 308 mRenderData.screenWidth - parameter.right,
309 mRenderData.screenHeight - parameter.bottom); 309 mRenderData.screenHeight - parameter.bottom);
310 } else { 310 } else {
311 mDesktopCanvas.setInputMethodOffsetValues(0, 0); 311 mDesktopCanvas.setSystemUiOffsetValues(0, 0, 0, 0);
312 } 312 }
313 } 313 }
314
315 mDesktopCanvas.repositionImage(true); 314 mDesktopCanvas.repositionImage(true);
316 } 315 }
317 316
318 private boolean handleTouchEvent(MotionEvent event) { 317 private boolean handleTouchEvent(MotionEvent event) {
319 // Give the underlying input strategy a chance to observe the current mo tion event before 318 // Give the underlying input strategy a chance to observe the current mo tion event before
320 // passing it to the gesture detectors. This allows the input strategy to react to the 319 // passing it to the gesture detectors. This allows the input strategy to react to the
321 // event or save the payload for use in recreating the gesture remotely. 320 // event or save the payload for use in recreating the gesture remotely.
322 mInputStrategy.onMotionEvent(event); 321 mInputStrategy.onMotionEvent(event);
323 322
324 // Avoid short-circuit logic evaluation - ensure all gesture detectors s ee all events so 323 // 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
370 369
371 private void setInputStrategy(InputStrategyInterface inputStrategy) { 370 private void setInputStrategy(InputStrategyInterface inputStrategy) {
372 // Since the rules for flinging differ between input modes, we want to s top running the 371 // Since the rules for flinging differ between input modes, we want to s top running the
373 // current fling animation when the mode changes to prevent a wonky expe rience. 372 // current fling animation when the mode changes to prevent a wonky expe rience.
374 mCursorAnimationJob.abortAnimation(); 373 mCursorAnimationJob.abortAnimation();
375 mScrollAnimationJob.abortAnimation(); 374 mScrollAnimationJob.abortAnimation();
376 mInputStrategy = inputStrategy; 375 mInputStrategy = inputStrategy;
377 } 376 }
378 377
379 /** Moves the desired center of the viewport using the specified deltas. */ 378 /** Moves the desired center of the viewport using the specified deltas. */
380 private void moveViewportWithOffset(float deltaX, float deltaY) { 379 private void moveViewportByOffset(float deltaX, float deltaY) {
381 // If we are in an indirect mode or are in the middle of a drag operatio n, then we want to 380 // If we are in an indirect mode or are in the middle of a drag operatio n, then we want to
382 // invert the direction of the operation (i.e. follow the motion of the finger). 381 // invert the direction of the operation (i.e. follow the motion of the finger).
383 if (mInputStrategy.isIndirectInputMode() || mIsDragging) { 382 boolean followCursor = (mInputStrategy.isIndirectInputMode() || mIsDragg ing);
383 if (followCursor) {
384 deltaX = -deltaX; 384 deltaX = -deltaX;
385 deltaY = -deltaY; 385 deltaY = -deltaY;
386 } 386 }
387
388 // Determine the center point from which to apply the delta. 387 // Determine the center point from which to apply the delta.
389 // For indirect input modes (i.e. trackpad), the view generally follows the cursor. 388 // For indirect input modes (i.e. trackpad), the view generally follows the cursor.
390 // For direct input modes (i.e. touch) the should track the user's motio n. 389 // For direct input modes (i.e. touch) the should track the user's motio n.
391 // If the user is dragging, then the viewport should always follow the u ser's finger. 390 // If the user is dragging, then the viewport should always follow the u ser's finger.
392 PointF viewportPoint; 391 PointF newPos = mDesktopCanvas.moveViewportCenter(!followCursor, deltaX, deltaY);
393 if (mInputStrategy.isIndirectInputMode() || mIsDragging) {
394 viewportPoint = mDesktopCanvas.getViewportPosition();
395 } else {
396 PointF adjustedViewportSize = mDesktopCanvas.getViewportSize();
397 synchronized (mRenderData) {
398 float[] viewportPosition = new float[] {(float) adjustedViewport Size.x / 2,
399 (float) adjustedViewport Size.y / 2};
400 Matrix inverted = new Matrix();
401 mRenderData.transform.invert(inverted);
402 inverted.mapPoints(viewportPosition);
403 viewportPoint = new PointF(viewportPosition[0], viewportPosition [1]);
404 }
405 }
406
407 // Constrain the coordinates to the image area.
408 float newX = viewportPoint.x + deltaX;
409 float newY = viewportPoint.y + deltaY;
410 synchronized (mRenderData) {
411 // Constrain viewport position to the image area.
412 if (newX < 0) {
413 newX = 0;
414 } else if (newX > mRenderData.imageWidth) {
415 newX = mRenderData.imageWidth;
416 }
417
418 if (newY < 0) {
419 newY = 0;
420 } else if (newY > mRenderData.imageHeight) {
421 newY = mRenderData.imageHeight;
422 }
423 }
424
425 moveViewport(newX, newY);
426 }
427
428 /** Moves the desired center of the viewport to the specified position. */
429 private void moveViewport(float newX, float newY) {
430 mDesktopCanvas.setViewportPosition(newX, newY);
431 392
432 // If we are in an indirect mode or are in the middle of a drag operatio n, then we want to 393 // If we are in an indirect mode or are in the middle of a drag operatio n, then we want to
433 // keep the cursor centered, if possible, as the viewport moves. 394 // keep the cursor centered, if possible, as the viewport moves.
434 if (mInputStrategy.isIndirectInputMode() || mIsDragging) { 395 if (followCursor) {
435 moveCursor((int) newX, (int) newY); 396 moveCursor((int) newPos.x, (int) newPos.y);
436 } 397 }
437 398
438 mDesktopCanvas.repositionImage(true); 399 mDesktopCanvas.repositionImage(true);
439 } 400 }
440 401
441 /** Moves the cursor to the specified position on the screen. */ 402 /** Moves the cursor to the specified position on the screen. */
442 private void moveCursorToScreenPoint(float screenX, float screenY) { 403 private void moveCursorToScreenPoint(float screenX, float screenY) {
443 float[] mappedValues = {screenX, screenY}; 404 float[] mappedValues = {screenX, screenY};
444 synchronized (mRenderData) { 405 synchronized (mRenderData) {
445 Matrix canvasToImage = new Matrix(); 406 Matrix canvasToImage = new Matrix();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 return false; 483 return false;
523 } 484 }
524 485
525 float[] delta = {distanceX, distanceY}; 486 float[] delta = {distanceX, distanceY};
526 synchronized (mRenderData) { 487 synchronized (mRenderData) {
527 Matrix canvasToImage = new Matrix(); 488 Matrix canvasToImage = new Matrix();
528 mRenderData.transform.invert(canvasToImage); 489 mRenderData.transform.invert(canvasToImage);
529 canvasToImage.mapVectors(delta); 490 canvasToImage.mapVectors(delta);
530 } 491 }
531 492
532 moveViewportWithOffset(delta[0], delta[1]); 493 moveViewportByOffset(delta[0], delta[1]);
533 return true; 494 return true;
534 } 495 }
535 496
536 /** 497 /**
537 * Called when a fling gesture is recognized. 498 * Called when a fling gesture is recognized.
538 */ 499 */
539 @Override 500 @Override
540 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 501 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
541 if (mSuppressFling) { 502 if (mSuppressFling) {
542 return false; 503 return false;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 case 2: 615 case 2:
655 return InputStub.BUTTON_RIGHT; 616 return InputStub.BUTTON_RIGHT;
656 case 3: 617 case 3:
657 return InputStub.BUTTON_MIDDLE; 618 return InputStub.BUTTON_MIDDLE;
658 default: 619 default:
659 return InputStub.BUTTON_UNDEFINED; 620 return InputStub.BUTTON_UNDEFINED;
660 } 621 }
661 } 622 }
662 } 623 }
663 } 624 }
OLDNEW
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/SystemUiVisibilityChangedEventParameter.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698