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.app.ActionBar; | 7 import android.app.ActionBar; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
| 10 import android.graphics.Canvas; | 10 import android.graphics.Canvas; |
| 11 import android.graphics.Color; | 11 import android.graphics.Color; |
| 12 import android.graphics.Matrix; | 12 import android.graphics.Matrix; |
| 13 import android.graphics.Paint; | 13 import android.graphics.Paint; |
| 14 import android.graphics.Point; | |
| 14 import android.os.Bundle; | 15 import android.os.Bundle; |
| 15 import android.os.Looper; | 16 import android.os.Looper; |
| 16 import android.text.InputType; | 17 import android.text.InputType; |
| 17 import android.util.Log; | 18 import android.util.Log; |
| 18 import android.view.GestureDetector; | 19 import android.view.GestureDetector; |
| 19 import android.view.MotionEvent; | 20 import android.view.MotionEvent; |
| 20 import android.view.ScaleGestureDetector; | 21 import android.view.ScaleGestureDetector; |
| 21 import android.view.SurfaceHolder; | 22 import android.view.SurfaceHolder; |
| 22 import android.view.SurfaceView; | 23 import android.view.SurfaceView; |
| 23 import android.view.inputmethod.EditorInfo; | 24 import android.view.inputmethod.EditorInfo; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 | 61 |
| 61 private GestureDetector mScroller; | 62 private GestureDetector mScroller; |
| 62 private ScaleGestureDetector mZoomer; | 63 private ScaleGestureDetector mZoomer; |
| 63 | 64 |
| 64 /** Stores pan and zoom configuration and converts image coordinates to scre en coordinates. */ | 65 /** Stores pan and zoom configuration and converts image coordinates to scre en coordinates. */ |
| 65 private Matrix mTransform; | 66 private Matrix mTransform; |
| 66 | 67 |
| 67 private int mScreenWidth; | 68 private int mScreenWidth; |
| 68 private int mScreenHeight; | 69 private int mScreenHeight; |
| 69 | 70 |
| 71 /** | |
| 72 * Specifies the position, in image coordinates, at which the cursor image w ill be drawn. | |
| 73 * This will normally be at the location of the most recently injected motio n event. | |
| 74 */ | |
| 75 private Point mCursorPosition; | |
| 76 | |
| 70 /** Specifies the dimension by which the zoom level is being lower-bounded. */ | 77 /** Specifies the dimension by which the zoom level is being lower-bounded. */ |
| 71 private Constraint mConstraint; | 78 private Constraint mConstraint; |
| 72 | 79 |
| 73 /** Whether the dimension of constraint should be reckecked on the next aspe ct ratio change. */ | 80 /** Whether the dimension of constraint should be reckecked on the next aspe ct ratio change. */ |
| 74 private boolean mRecheckConstraint; | 81 private boolean mRecheckConstraint; |
| 75 | 82 |
| 76 /** Whether the right edge of the image was visible on-screen during the las t render. */ | 83 /** Whether the right edge of the image was visible on-screen during the las t render. */ |
| 77 private boolean mRightUsedToBeOut; | 84 private boolean mRightUsedToBeOut; |
| 78 | 85 |
| 79 /** Whether the bottom edge of the image was visible on-screen during the la st render. */ | 86 /** Whether the bottom edge of the image was visible on-screen during the la st render. */ |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 91 mActionBar = context.getActionBar(); | 98 mActionBar = context.getActionBar(); |
| 92 | 99 |
| 93 getHolder().addCallback(this); | 100 getHolder().addCallback(this); |
| 94 DesktopListener listener = new DesktopListener(); | 101 DesktopListener listener = new DesktopListener(); |
| 95 mScroller = new GestureDetector(context, listener, null, false); | 102 mScroller = new GestureDetector(context, listener, null, false); |
| 96 mZoomer = new ScaleGestureDetector(context, listener); | 103 mZoomer = new ScaleGestureDetector(context, listener); |
| 97 | 104 |
| 98 mTransform = new Matrix(); | 105 mTransform = new Matrix(); |
| 99 mScreenWidth = 0; | 106 mScreenWidth = 0; |
| 100 mScreenHeight = 0; | 107 mScreenHeight = 0; |
| 108 mCursorPosition = new Point(); | |
| 101 | 109 |
| 102 mConstraint = Constraint.UNDEFINED; | 110 mConstraint = Constraint.UNDEFINED; |
| 103 mRecheckConstraint = false; | 111 mRecheckConstraint = false; |
| 104 | 112 |
| 105 mRightUsedToBeOut = false; | 113 mRightUsedToBeOut = false; |
| 106 mBottomUsedToBeOut = false; | 114 mBottomUsedToBeOut = false; |
| 107 | 115 |
| 108 mMouseButton = BUTTON_UNDEFINED; | 116 mMouseButton = BUTTON_UNDEFINED; |
| 109 mMousePressed = false; | 117 mMousePressed = false; |
| 110 } | 118 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 } | 217 } |
| 210 | 218 |
| 211 mTransform.setValues(values); | 219 mTransform.setValues(values); |
| 212 } | 220 } |
| 213 | 221 |
| 214 canvas.setMatrix(mTransform); | 222 canvas.setMatrix(mTransform); |
| 215 } | 223 } |
| 216 | 224 |
| 217 canvas.drawColor(Color.BLACK); | 225 canvas.drawColor(Color.BLACK); |
| 218 canvas.drawBitmap(image, 0, 0, new Paint()); | 226 canvas.drawBitmap(image, 0, 0, new Paint()); |
| 227 Bitmap cursorBitmap = JniInterface.getCursorBitmap(); | |
| 228 if (cursorBitmap != null) { | |
| 229 Point hotspot = JniInterface.getCursorHotspot(); | |
| 230 canvas.drawBitmap(cursorBitmap, mCursorPosition.x - hotspot.x, | |
|
solb
2013/09/14 00:29:41
It might be good to synchronize this on mCursorPos
Lambros
2013/09/14 01:16:48
Good catch! Done.
| |
| 231 mCursorPosition.y - hotspot.y, new Paint()); | |
| 232 } | |
| 219 getHolder().unlockCanvasAndPost(canvas); | 233 getHolder().unlockCanvasAndPost(canvas); |
| 220 } | 234 } |
| 221 | 235 |
| 222 /** | 236 /** |
| 223 * Causes the next canvas redraw to perform a check for which screen dimensi on more tightly | 237 * Causes the next canvas redraw to perform a check for which screen dimensi on more tightly |
| 224 * constrains the view of the image. This should be called between the time that a screen size | 238 * constrains the view of the image. This should be called between the time that a screen size |
| 225 * change is requested and the time it actually occurs. If it is not called in such a case, the | 239 * change is requested and the time it actually occurs. If it is not called in such a case, the |
| 226 * screen will not be rearranged as aggressively (which is desirable when th e software keyboard | 240 * screen will not be rearranged as aggressively (which is desirable when th e software keyboard |
| 227 * appears in order to allow it to cover the image without forcing a resize) . | 241 * appears in order to allow it to cover the image without forcing a resize) . |
| 228 */ | 242 */ |
| 229 public void requestRecheckConstrainingDimension() { | 243 public void requestRecheckConstrainingDimension() { |
| 230 mRecheckConstraint = true; | 244 mRecheckConstraint = true; |
| 231 } | 245 } |
| 232 | 246 |
| 233 /** | 247 /** |
| 234 * Called after the canvas is initially created, then after every | 248 * Called after the canvas is initially created, then after every |
| 235 * subsequent resize, as when the display is rotated. | 249 * subsequent resize, as when the display is rotated. |
| 236 */ | 250 */ |
| 237 @Override | 251 @Override |
| 238 public void surfaceChanged( | 252 public void surfaceChanged( |
| 239 SurfaceHolder holder, int format, int width, int height) { | 253 SurfaceHolder holder, int format, int width, int height) { |
| 240 mActionBar.hide(); | 254 mActionBar.hide(); |
| 241 | 255 |
| 242 synchronized (mTransform) { | 256 synchronized (mTransform) { |
| 243 mScreenWidth = width; | 257 mScreenWidth = width; |
| 244 mScreenHeight = height; | 258 mScreenHeight = height; |
| 259 mCursorPosition.x = width / 2; | |
|
solb
2013/09/14 00:29:41
Synchronizing these on mTransform does no good, si
Lambros
2013/09/14 01:16:48
Done.
| |
| 260 mCursorPosition.y = height / 2; | |
| 245 | 261 |
| 246 if (mRecheckConstraint) { | 262 if (mRecheckConstraint) { |
| 247 mConstraint = Constraint.UNDEFINED; | 263 mConstraint = Constraint.UNDEFINED; |
| 248 mRecheckConstraint = false; | 264 mRecheckConstraint = false; |
| 249 } | 265 } |
| 250 } | 266 } |
| 251 | 267 |
| 252 if (!JniInterface.redrawGraphics()) { | 268 if (!JniInterface.redrawGraphics()) { |
| 253 JniInterface.provideRedrawCallback(this); | 269 JniInterface.provideRedrawCallback(this); |
| 254 } | 270 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 | 308 |
| 293 /** Called when a mouse action is made. */ | 309 /** Called when a mouse action is made. */ |
| 294 private void handleMouseMovement(float x, float y, int button, boolean press ed) { | 310 private void handleMouseMovement(float x, float y, int button, boolean press ed) { |
| 295 float[] coordinates = {x, y}; | 311 float[] coordinates = {x, y}; |
| 296 | 312 |
| 297 // Coordinates are relative to the canvas, but we need image coordinates . | 313 // Coordinates are relative to the canvas, but we need image coordinates . |
| 298 Matrix canvasToImage = new Matrix(); | 314 Matrix canvasToImage = new Matrix(); |
| 299 mTransform.invert(canvasToImage); | 315 mTransform.invert(canvasToImage); |
| 300 canvasToImage.mapPoints(coordinates); | 316 canvasToImage.mapPoints(coordinates); |
| 301 | 317 |
| 318 mCursorPosition.x = (int)coordinates[0]; | |
|
solb
2013/09/14 00:29:41
I think these two lines should also be synchronize
Lambros
2013/09/14 01:16:48
Done. I've also added a synchronize around mTransf
| |
| 319 mCursorPosition.y = (int)coordinates[1]; | |
| 320 | |
| 302 // Coordinates are now relative to the image, so transmit them to the ho st. | 321 // Coordinates are now relative to the image, so transmit them to the ho st. |
| 303 JniInterface.mouseAction((int)coordinates[0], (int)coordinates[1], butto n, pressed); | 322 JniInterface.mouseAction(mCursorPosition.x, mCursorPosition.y, button, p ressed); |
| 323 | |
| 324 // TODO(lambroslambrou): Optimize this to repaint only the areas covered by the old and new | |
| 325 // cursor positions. | |
| 326 JniInterface.redrawGraphics(); | |
| 304 } | 327 } |
| 305 | 328 |
| 306 /** | 329 /** |
| 307 * Called whenever the user attempts to touch the canvas. Forwards such | 330 * Called whenever the user attempts to touch the canvas. Forwards such |
| 308 * events to the appropriate gesture detector until one accepts them. | 331 * events to the appropriate gesture detector until one accepts them. |
| 309 */ | 332 */ |
| 310 @Override | 333 @Override |
| 311 public boolean onTouchEvent(MotionEvent event) { | 334 public boolean onTouchEvent(MotionEvent event) { |
| 312 if (event.getPointerCount() == 3) { | 335 if (event.getPointerCount() == 3) { |
| 313 mActionBar.show(); | 336 mActionBar.show(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 handleMouseMovement(x, y, mMouseButton, false); | 463 handleMouseMovement(x, y, mMouseButton, false); |
| 441 } | 464 } |
| 442 | 465 |
| 443 Log.i("mouse", "\tStarting right click"); | 466 Log.i("mouse", "\tStarting right click"); |
| 444 mMouseButton = BUTTON_RIGHT; | 467 mMouseButton = BUTTON_RIGHT; |
| 445 mMousePressed = true; | 468 mMousePressed = true; |
| 446 handleMouseMovement(x, y, mMouseButton, mMousePressed); | 469 handleMouseMovement(x, y, mMouseButton, mMousePressed); |
| 447 } | 470 } |
| 448 } | 471 } |
| 449 } | 472 } |
| OLD | NEW |