diff options
author | joedow <joedow@chromium.org> | 2015-12-08 18:48:56 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-09 02:49:54 +0000 |
commit | c13e8d6742737052e3d1655b68887170e4f40a6e (patch) | |
tree | dea298a7633485c410e99c1809666ad840194312 /remoting/android | |
parent | 75f9ba4267de856688905eddc6f1e27d7fa4ae05 (diff) | |
download | chromium_src-c13e8d6742737052e3d1655b68887170e4f40a6e.zip chromium_src-c13e8d6742737052e3d1655b68887170e4f40a6e.tar.gz chromium_src-c13e8d6742737052e3d1655b68887170e4f40a6e.tar.bz2 |
Adding getter/setter for RenderData cursor member.
This change was part of a larger refactoring and has been pulled out on
its own.
This change adds a getter/setter for the cursorPosition member of the
RenderData class. One reason for doing this is to encapsulate the
'cursorMoved' logic so it is done once (instead of duplicated at each
callsite) and the second is that the DesktopCanvas class uses a similar
set of methods for manipulating its 'cursor' member and so code which
called into both objects looked odd (one used a setter and the other a
raw member).
BUG=
Review URL: https://codereview.chromium.org/1507423002
Cr-Commit-Position: refs/heads/master@{#363951}
Diffstat (limited to 'remoting/android')
3 files changed, 43 insertions, 22 deletions
diff --git a/remoting/android/java/src/org/chromium/chromoting/DesktopView.java b/remoting/android/java/src/org/chromium/chromoting/DesktopView.java index 9638755..ec63fee 100644 --- a/remoting/android/java/src/org/chromium/chromoting/DesktopView.java +++ b/remoting/android/java/src/org/chromium/chromoting/DesktopView.java @@ -232,7 +232,7 @@ public class DesktopView extends SurfaceView implements DesktopViewInterface, } Canvas canvas; - int x, y; + Point cursorPosition; synchronized (mRenderData) { mRepaintPending = false; // Don't try to lock the canvas before it is ready, as the implementation of @@ -247,8 +247,7 @@ public class DesktopView extends SurfaceView implements DesktopViewInterface, return; } canvas.setMatrix(mRenderData.transform); - x = mRenderData.cursorPosition.x; - y = mRenderData.cursorPosition.y; + cursorPosition = mRenderData.getCursorPosition(); } canvas.drawColor(Color.BLACK); @@ -261,13 +260,14 @@ public class DesktopView extends SurfaceView implements DesktopViewInterface, synchronized (mRenderData) { scaleFactor = mRenderData.transform.mapRadius(1); } - mFeedbackAnimator.render(canvas, x, y, scaleFactor); + mFeedbackAnimator.render(canvas, cursorPosition.x, cursorPosition.y, scaleFactor); } Bitmap cursorBitmap = JniInterface.getCursorBitmap(); if (cursorBitmap != null) { Point hotspot = JniInterface.getCursorHotspot(); - canvas.drawBitmap(cursorBitmap, x - hotspot.x, y - hotspot.y, new Paint()); + canvas.drawBitmap(cursorBitmap, cursorPosition.x - hotspot.x, + cursorPosition.y - hotspot.y, new Paint()); } getHolder().unlockCanvasAndPost(canvas); diff --git a/remoting/android/java/src/org/chromium/chromoting/RenderData.java b/remoting/android/java/src/org/chromium/chromoting/RenderData.java index f161c9f..50d7217 100644 --- a/remoting/android/java/src/org/chromium/chromoting/RenderData.java +++ b/remoting/android/java/src/org/chromium/chromoting/RenderData.java @@ -24,5 +24,35 @@ public class RenderData { * Specifies the position, in image coordinates, at which the cursor image will be drawn. * This will normally be at the location of the most recently injected motion event. */ - public Point cursorPosition = new Point(); + private Point mCursorPosition = new Point(); + + /** + * Returns the position of the rendered cursor. + * + * @return A point representing the current position. + */ + public Point getCursorPosition() { + return new Point(mCursorPosition); + } + + /** + * Sets the position of the cursor which is used for rendering. + * + * @param newX The new value of the x coordinate. + * @param newY The new value of the y coordinate + * @return True if the cursor position has changed. + */ + public boolean setCursorPosition(int newX, int newY) { + boolean cursorMoved = false; + if (newX != mCursorPosition.x) { + mCursorPosition.x = newX; + cursorMoved = true; + } + if (newY != mCursorPosition.y) { + mCursorPosition.y = newY; + cursorMoved = true; + } + + return cursorMoved; + } } diff --git a/remoting/android/java/src/org/chromium/chromoting/TrackpadInputStrategy.java b/remoting/android/java/src/org/chromium/chromoting/TrackpadInputStrategy.java index edc9baf..93b1f22 100644 --- a/remoting/android/java/src/org/chromium/chromoting/TrackpadInputStrategy.java +++ b/remoting/android/java/src/org/chromium/chromoting/TrackpadInputStrategy.java @@ -4,6 +4,8 @@ package org.chromium.chromoting; +import android.graphics.Point; + import org.chromium.chromoting.jni.JniInterface; /** @@ -27,14 +29,12 @@ public class TrackpadInputStrategy implements InputStrategyInterface { @Override public void injectRemoteButtonEvent(int button, boolean pressed) { - int x; - int y; + Point cursorPosition; synchronized (mRenderData) { - x = mRenderData.cursorPosition.x; - y = mRenderData.cursorPosition.y; + cursorPosition = mRenderData.getCursorPosition(); } - injectRemoteButtonEvent(x, y, button, pressed); + injectRemoteButtonEvent(cursorPosition.x, cursorPosition.y, button, pressed); } @Override @@ -63,18 +63,9 @@ public class TrackpadInputStrategy implements InputStrategyInterface { } private void injectRemoteButtonEvent(int x, int y, int button, boolean pressed) { - boolean cursorMoved = false; + boolean cursorMoved; synchronized (mRenderData) { - // Test if the cursor actually moved, which requires repainting the cursor. This - // requires that |mRenderData.cursorPosition| was not assigned to beforehand. - if (x != mRenderData.cursorPosition.x) { - mRenderData.cursorPosition.x = x; - cursorMoved = true; - } - if (y != mRenderData.cursorPosition.y) { - mRenderData.cursorPosition.y = y; - cursorMoved = true; - } + cursorMoved = mRenderData.setCursorPosition(x, y); } if (button == TouchInputHandlerInterface.BUTTON_UNDEFINED && !cursorMoved) { |