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

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

Issue 2378303002: Adjust viewport center when in trackpad input mode. (Closed)
Patch Set: Merging with ToT Created 4 years, 2 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 | « no previous file | remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.graphics.Matrix; 7 import android.graphics.Matrix;
8 import android.graphics.PointF; 8 import android.graphics.PointF;
9 import android.graphics.Rect; 9 import android.graphics.Rect;
10 import android.graphics.RectF; 10 import android.graphics.RectF;
11 11
12 /** 12 /**
13 * This class is responsible for transforming the desktop image matrix. 13 * This class is responsible for transforming the desktop image matrix.
14 */ 14 */
15 public class DesktopCanvas { 15 public class DesktopCanvas {
16 /** 16 /**
17 * Maximum allowed zoom level - see {@link #scaleAndRepositionImage()}. 17 * Maximum allowed zoom level - see {@link #scaleAndRepositionImage()}.
18 */ 18 */
19 private static final float MAX_ZOOM_FACTOR = 100.0f; 19 private static final float MAX_ZOOM_FACTOR = 100.0f;
20 20
21 /** 21 /**
22 * Used to smoothly reduce the amount of padding while the user is zooming. 22 * Used to smoothly reduce the amount of padding while the user is zooming.
23 */ 23 */
24 private static final float PADDING_REDUCTION_FACTOR = 0.85f; 24 private static final float PADDING_REDUCTION_FACTOR = 0.85f;
25 25
26 private final RenderStub mRenderStub; 26 private final RenderStub mRenderStub;
27 private final RenderData mRenderData; 27 private final RenderData mRenderData;
28 28
29 /** 29 /**
30 * Represents the actual center of the viewport in image space. This value needs to be a pair 30 * Represents the actual center of the viewport in image space. This value needs to be a pair
Lambros 2016/10/05 01:35:54 It sounds like this is no longer accurate when mCu
joedow 2016/10/05 16:12:26 This is still accurate. When we manipulate the vi
31 * of floats so the desktop image can be positioned with sub-pixel accuracy for smoother panning 31 * of floats so the desktop image can be positioned with sub-pixel accuracy for smoother panning
32 * animations at high zoom levels. 32 * animations at high zoom levels.
33 */ 33 */
34 // TODO(joedow): See if we can collapse Viewport and Cursor position members . They were needed 34 // TODO(joedow): See if we can collapse Viewport and Cursor position members . They were needed
35 // in the past due to how we calculated the center positions but may not be needed now. 35 // in the past due to how we calculated the center positions but may not be needed now.
36 private PointF mViewportPosition = new PointF(); 36 private PointF mViewportPosition = new PointF();
37 37
38 /** 38 /**
39 * Represents the desired center of the viewport in image space. This value may not represent 39 * Represents the desired center of the viewport in image space. This value may not represent
40 * the actual center of the viewport as adjustments are made to ensure as mu ch of the desktop is 40 * the actual center of the viewport as adjustments are made to ensure as mu ch of the desktop is
(...skipping 10 matching lines...) Expand all
51 // TODO(joedow): Update usage of this member so it is a true Rect instead of a set of offsets. 51 // TODO(joedow): Update usage of this member so it is a true Rect instead of a set of offsets.
52 private Rect mSystemUiScreenSize = new Rect(); 52 private Rect mSystemUiScreenSize = new Rect();
53 53
54 /** 54 /**
55 * Represents the amount of padding, in screen pixels, added to each edge of the desktop image. 55 * Represents the amount of padding, in screen pixels, added to each edge of the desktop image.
56 * This extra space allows the user to reveal portions of the desktop image which are obscured 56 * This extra space allows the user to reveal portions of the desktop image which are obscured
57 * by System UI. 57 * by System UI.
58 */ 58 */
59 private RectF mVisibleImagePadding = new RectF(); 59 private RectF mVisibleImagePadding = new RectF();
60 60
61 /**
62 * Tracks whether to adjust the viewport to account for System UI. If false, the viewport
63 * center is the center of the screen. If true, then System UI offsets will be used to
64 * adjust the position of the viewport to ensure the cursor is visible.
65 */
66 private boolean mAdjustViewportForSystemUi = false;
67
68 /**
69 * Represents the amount of space, in pixels, to adjust the cursor center alo ng the y-axis.
70 */
71 private float mCursorOffsetScreenY = 0.0f;
72
61 public DesktopCanvas(RenderStub renderStub, RenderData renderData) { 73 public DesktopCanvas(RenderStub renderStub, RenderData renderData) {
62 mRenderStub = renderStub; 74 mRenderStub = renderStub;
63 mRenderData = renderData; 75 mRenderData = renderData;
64 } 76 }
65 77
66 /** 78 /**
67 * Sets the desired center position of the viewport (a.k.a. the cursor posit ion) and ensures 79 * Sets the desired center position of the viewport (a.k.a. the cursor posit ion) and ensures
68 * the viewport is updated to include the cursor within it. 80 * the viewport is updated to include the cursor within it.
69 * 81 *
70 * @param newX The new x coordinate value for the desired center position. 82 * @param newX The new x coordinate value for the desired center position.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 /** 127 /**
116 * Sets the offset values used to calculate the space used by System UI. 128 * Sets the offset values used to calculate the space used by System UI.
117 * 129 *
118 * @param left The space used by System UI on the left edge of the screen. 130 * @param left The space used by System UI on the left edge of the screen.
119 * @param top The space used by System UI on the top edge of the screen. 131 * @param top The space used by System UI on the top edge of the screen.
120 * @param right The space used by System UI on the right edge of the screen. 132 * @param right The space used by System UI on the right edge of the screen.
121 * @param bottom The space used by System UI on the bottom edge of the scree n. 133 * @param bottom The space used by System UI on the bottom edge of the scree n.
122 */ 134 */
123 public void setSystemUiOffsetValues(int left, int top, int right, int bottom ) { 135 public void setSystemUiOffsetValues(int left, int top, int right, int bottom ) {
124 mSystemUiScreenSize.set(left, top, right, bottom); 136 mSystemUiScreenSize.set(left, top, right, bottom);
137
138 // Adjust the cursor position to ensure it visible when large System UI (defined as 1/3 or
Lambros 2016/10/05 01:35:54 s/it/it is/
joedow 2016/10/05 16:12:26 Done.
139 // more of the total screen size) is displayed. This is typically the S oft Keyboard.
140 // Without this change, it is difficult for users to enter text into edi t controls which are
141 // located bottom of the screen and may not be able to view their cursor at all.
142 if (mAdjustViewportForSystemUi && bottom > (mRenderData.screenHeight / 3 )) {
143 // Center the cursor within the viewable area (not obscurred by Syst em UI).
Lambros 2016/10/05 01:35:54 obscured
joedow 2016/10/05 16:12:26 Done.
144 mCursorOffsetScreenY = (((float) mRenderData.screenHeight - bottom) / 2.0f);
145 } else {
146 mCursorOffsetScreenY = 0.0f;
147 }
148
149 if (mAdjustViewportForSystemUi) {
150 setCursorPosition(mCursorPosition.x, mCursorPosition.y);
Lambros 2016/10/05 01:35:54 This feels suspect. Why do you need this call only
joedow 2016/10/05 16:12:26 It only affects the case where the cursor offset c
151 }
125 } 152 }
126 153
127 /** Called to indicate that no System UI is visible. */ 154 /** Called to indicate that no System UI is visible. */
128 public void clearSystemUiOffsets() { 155 public void clearSystemUiOffsets() {
156 mCursorOffsetScreenY = 0.0f;
129 mSystemUiScreenSize.setEmpty(); 157 mSystemUiScreenSize.setEmpty();
130 } 158 }
131 159
160 public void adjustViewportForSystemUi(boolean adjustViewportForSystemUi) {
161 mAdjustViewportForSystemUi = adjustViewportForSystemUi;
162 }
163
132 /** Resizes the image by zooming it such that the image is displayed without borders. */ 164 /** Resizes the image by zooming it such that the image is displayed without borders. */
133 public void resizeImageToFitScreen() { 165 public void resizeImageToFitScreen() {
134 // Protect against being called before the image has been initialized. 166 // Protect against being called before the image has been initialized.
135 if (mRenderData.imageWidth == 0 || mRenderData.imageHeight == 0) { 167 if (mRenderData.imageWidth == 0 || mRenderData.imageHeight == 0) {
136 return; 168 return;
137 } 169 }
138 170
139 float widthRatio = (float) mRenderData.screenWidth / mRenderData.imageWi dth; 171 float widthRatio = (float) mRenderData.screenWidth / mRenderData.imageWi dth;
140 float heightRatio = (float) mRenderData.screenHeight / mRenderData.image Height; 172 float heightRatio = (float) mRenderData.screenHeight / mRenderData.image Height;
141 float screenToImageScale = Math.max(widthRatio, heightRatio); 173 float screenToImageScale = Math.max(widthRatio, heightRatio);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 245
214 /** 246 /**
215 * Repositions the image by translating it (without affecting the zoom level ). 247 * Repositions the image by translating it (without affecting the zoom level ).
216 */ 248 */
217 private void repositionImage() { 249 private void repositionImage() {
218 // Map the current viewport position to screen coordinates and adjust th e image position. 250 // Map the current viewport position to screen coordinates and adjust th e image position.
219 float[] viewportPosition = {mViewportPosition.x, mViewportPosition.y}; 251 float[] viewportPosition = {mViewportPosition.x, mViewportPosition.y};
220 mRenderData.transform.mapPoints(viewportPosition); 252 mRenderData.transform.mapPoints(viewportPosition);
221 253
222 float viewportTransX = ((float) mRenderData.screenWidth / 2) - viewportP osition[0]; 254 float viewportTransX = ((float) mRenderData.screenWidth / 2) - viewportP osition[0];
223 float viewportTransY = ((float) mRenderData.screenHeight / 2) - viewport Position[1]; 255 float viewportTransY =
256 ((float) mRenderData.screenHeight / 2) - viewportPosition[1] - m CursorOffsetScreenY;
224 257
225 // Translate the image so the viewport center is displayed in the middle of the screen. 258 // Translate the image so the viewport center is displayed in the middle of the screen.
Lambros 2016/10/05 01:35:54 I guess "middle of the screen" is no longer accura
joedow 2016/10/05 16:12:26 That's true, this comment should be updated.
226 mRenderData.transform.postTranslate(viewportTransX, viewportTransY); 259 mRenderData.transform.postTranslate(viewportTransX, viewportTransY);
227 260
228 updateVisibleImagePadding(); 261 updateVisibleImagePadding();
229 262
230 mRenderStub.setTransformation(mRenderData.transform); 263 mRenderStub.setTransformation(mRenderData.transform);
231 } 264 }
232 265
233 /** 266 /**
234 * Updates the given point such that it refers to a coordinate within the bo unds provided. 267 * Updates the given point such that it refers to a coordinate within the bo unds provided.
235 * 268 *
(...skipping 20 matching lines...) Expand all
256 // Padding is additional space added to the image which is the larger va lue of: 289 // Padding is additional space added to the image which is the larger va lue of:
257 // - Potential overlap of the System UI and image content 290 // - Potential overlap of the System UI and image content
258 // - Actual amount of padding already being used 291 // - Actual amount of padding already being used
259 // 292 //
260 // By expanding the area, we allow the user to move the cursor 'under' t he System UI which 293 // By expanding the area, we allow the user to move the cursor 'under' t he System UI which
261 // pulls the content out from under it and allows it to be visible. Onc e the System UI has 294 // pulls the content out from under it and allows it to be visible. Onc e the System UI has
262 // been dismissed or changes size, we use the actual padding value inste ad which prevents 295 // been dismissed or changes size, we use the actual padding value inste ad which prevents
263 // the desktop image from 'snapping' back to pre-System UI state. 296 // the desktop image from 'snapping' back to pre-System UI state.
264 RectF systemUiOverlap = getSystemUiOverlap(); 297 RectF systemUiOverlap = getSystemUiOverlap();
265 float[] padding = {Math.max(mVisibleImagePadding.left, systemUiOverlap.l eft), 298 float[] padding = {Math.max(mVisibleImagePadding.left, systemUiOverlap.l eft),
266 Math.max(mVisibleImagePadding.top, systemUiOverlap.top), 299 Math.max(mVisibleImagePadding.top + mCursorOffsetScreenY, system UiOverlap.top),
267 Math.max(mVisibleImagePadding.right, systemUiOverlap.right), 300 Math.max(mVisibleImagePadding.right, systemUiOverlap.right),
268 Math.max(mVisibleImagePadding.bottom, systemUiOverlap.bottom)}; 301 Math.max(mVisibleImagePadding.bottom - mCursorOffsetScreenY,
302 systemUiOverlap.bottom)};
269 Matrix screenToImage = new Matrix(); 303 Matrix screenToImage = new Matrix();
270 mRenderData.transform.invert(screenToImage); 304 mRenderData.transform.invert(screenToImage);
271 screenToImage.mapVectors(padding); 305 screenToImage.mapVectors(padding);
272 306
273 return new RectF(-padding[0], -padding[1], mRenderData.imageWidth + padd ing[2], 307 return new RectF(-padding[0], -padding[1], mRenderData.imageWidth + padd ing[2],
274 mRenderData.imageHeight + padding[3]); 308 mRenderData.imageHeight + padding[3]);
275 } 309 }
276 310
277 /** Returns a region which defines the set of valid viewport center values i n image space. */ 311 /** Returns a region which defines the set of valid viewport center values i n image space. */
278 private RectF getViewportBounds() { 312 private RectF getViewportBounds() {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 * Returns the amount of System UI along each edge of the screen which could overlap the remote 352 * Returns the amount of System UI along each edge of the screen which could overlap the remote
319 * desktop image below it. This is the maximum amount that could overlap, n ot the actual value. 353 * desktop image below it. This is the maximum amount that could overlap, n ot the actual value.
320 */ 354 */
321 private RectF getSystemUiOverlap() { 355 private RectF getSystemUiOverlap() {
322 // letterBox padding represents the space added to the image to center i t on the screen. 356 // letterBox padding represents the space added to the image to center i t on the screen.
323 // Since it does not contain any interactable UI, we ignore it when calc ulating the overlap 357 // Since it does not contain any interactable UI, we ignore it when calc ulating the overlap
324 // between the System UI and the remote desktop image. 358 // between the System UI and the remote desktop image.
325 // Note: Ignore negative padding (clamp to 0) since that means no overla p exists. 359 // Note: Ignore negative padding (clamp to 0) since that means no overla p exists.
326 PointF letterboxPadding = getLetterboxPadding(); 360 PointF letterboxPadding = getLetterboxPadding();
327 return new RectF(Math.max(mSystemUiScreenSize.left - letterboxPadding.x, 0.0f), 361 return new RectF(Math.max(mSystemUiScreenSize.left - letterboxPadding.x, 0.0f),
328 Math.max(mSystemUiScreenSize.top - letterboxPadding.y, 0.0f), 362 Math.max(mSystemUiScreenSize.top - letterboxPadding.y + mCursorO ffsetScreenY, 0.0f),
329 Math.max(mSystemUiScreenSize.right - letterboxPadding.x, 0.0f), 363 Math.max(mSystemUiScreenSize.right - letterboxPadding.x, 0.0f),
330 Math.max(mSystemUiScreenSize.bottom - letterboxPadding.y, 0.0f)) ; 364 Math.max(mSystemUiScreenSize.bottom - letterboxPadding.y - mCurs orOffsetScreenY,
365 0.0f));
331 } 366 }
332 367
333 /** 368 /**
334 * Calculates the amount of padding visible on each edge of the desktop imag e. 369 * Calculates the amount of padding visible on each edge of the desktop imag e.
335 */ 370 */
336 private void updateVisibleImagePadding() { 371 private void updateVisibleImagePadding() {
337 PointF letterboxPadding = getLetterboxPadding(); 372 PointF letterboxPadding = getLetterboxPadding();
338 float[] imagePoints = {0.0f, 0.0f, mRenderData.imageWidth, mRenderData.i mageHeight}; 373 float[] imagePoints = {0.0f, 0.0f, mRenderData.imageWidth, mRenderData.i mageHeight};
339 mRenderData.transform.mapPoints(imagePoints); 374 mRenderData.transform.mapPoints(imagePoints);
340 375
341 mVisibleImagePadding.set(Math.max(imagePoints[0] - letterboxPadding.x, 0 .0f), 376 mVisibleImagePadding.set(Math.max(imagePoints[0] - letterboxPadding.x, 0 .0f),
342 Math.max(imagePoints[1] - letterboxPadding.y, 0.0f), 377 Math.max(imagePoints[1] - letterboxPadding.y, 0.0f),
343 Math.max(mRenderData.screenWidth - imagePoints[2] - letterboxPad ding.x, 0.0f), 378 Math.max(mRenderData.screenWidth - imagePoints[2] - letterboxPad ding.x, 0.0f),
344 Math.max(mRenderData.screenHeight - imagePoints[3] - letterboxPa dding.y, 0.0f)); 379 Math.max(mRenderData.screenHeight - imagePoints[3] - letterboxPa dding.y, 0.0f));
345 } 380 }
346 } 381 }
OLDNEW
« no previous file with comments | « no previous file | remoting/android/java/src/org/chromium/chromoting/TouchInputHandler.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698