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

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: Removing the float comparison and making the logic for applying the cursor offset a bit cleaner 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;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (mAdjustViewportForSystemUi) {
139 // Adjust the cursor position to ensure it's visible when large Syst em UI (defined as
140 // 1/3 or more of the total screen size) is displayed. This is typi cally the Soft
141 // Keyboard. Without this change, it is difficult for users to enter text into edit
142 // controls which are located bottom of the screen and may not be ab le to view their
143 // cursor at all.
144 if (bottom > (mRenderData.screenHeight / 3)) {
145 // Center the cursor within the viewable area (not obscured by S ystem UI).
146 mCursorOffsetScreenY = (((float) mRenderData.screenHeight - bott om) / 2.0f);
147 } else {
148 mCursorOffsetScreenY = 0.0f;
149 }
150
151 // Apply the cursor offset.
152 setCursorPosition(mCursorPosition.x, mCursorPosition.y);
153 }
125 } 154 }
126 155
127 /** Called to indicate that no System UI is visible. */ 156 /** Called to indicate that no System UI is visible. */
128 public void clearSystemUiOffsets() { 157 public void clearSystemUiOffsets() {
158 mCursorOffsetScreenY = 0.0f;
129 mSystemUiScreenSize.setEmpty(); 159 mSystemUiScreenSize.setEmpty();
130 } 160 }
131 161
162 public void adjustViewportForSystemUi(boolean adjustViewportForSystemUi) {
163 mAdjustViewportForSystemUi = adjustViewportForSystemUi;
164 }
165
132 /** Resizes the image by zooming it such that the image is displayed without borders. */ 166 /** Resizes the image by zooming it such that the image is displayed without borders. */
133 public void resizeImageToFitScreen() { 167 public void resizeImageToFitScreen() {
134 // Protect against being called before the image has been initialized. 168 // Protect against being called before the image has been initialized.
135 if (mRenderData.imageWidth == 0 || mRenderData.imageHeight == 0) { 169 if (mRenderData.imageWidth == 0 || mRenderData.imageHeight == 0) {
136 return; 170 return;
137 } 171 }
138 172
139 float widthRatio = (float) mRenderData.screenWidth / mRenderData.imageWi dth; 173 float widthRatio = (float) mRenderData.screenWidth / mRenderData.imageWi dth;
140 float heightRatio = (float) mRenderData.screenHeight / mRenderData.image Height; 174 float heightRatio = (float) mRenderData.screenHeight / mRenderData.image Height;
141 float screenToImageScale = Math.max(widthRatio, heightRatio); 175 float screenToImageScale = Math.max(widthRatio, heightRatio);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 247
214 /** 248 /**
215 * Repositions the image by translating it (without affecting the zoom level ). 249 * Repositions the image by translating it (without affecting the zoom level ).
216 */ 250 */
217 private void repositionImage() { 251 private void repositionImage() {
218 // Map the current viewport position to screen coordinates and adjust th e image position. 252 // Map the current viewport position to screen coordinates and adjust th e image position.
219 float[] viewportPosition = {mViewportPosition.x, mViewportPosition.y}; 253 float[] viewportPosition = {mViewportPosition.x, mViewportPosition.y};
220 mRenderData.transform.mapPoints(viewportPosition); 254 mRenderData.transform.mapPoints(viewportPosition);
221 255
222 float viewportTransX = ((float) mRenderData.screenWidth / 2) - viewportP osition[0]; 256 float viewportTransX = ((float) mRenderData.screenWidth / 2) - viewportP osition[0];
223 float viewportTransY = ((float) mRenderData.screenHeight / 2) - viewport Position[1]; 257 float viewportTransY =
258 ((float) mRenderData.screenHeight / 2) - viewportPosition[1] - m CursorOffsetScreenY;
224 259
225 // Translate the image so the viewport center is displayed in the middle of the screen. 260 // Translate the image to move the viewport to the expected screen locat ion.
226 mRenderData.transform.postTranslate(viewportTransX, viewportTransY); 261 mRenderData.transform.postTranslate(viewportTransX, viewportTransY);
227 262
228 updateVisibleImagePadding(); 263 updateVisibleImagePadding();
229 264
230 mRenderStub.setTransformation(mRenderData.transform); 265 mRenderStub.setTransformation(mRenderData.transform);
231 } 266 }
232 267
233 /** 268 /**
234 * Updates the given point such that it refers to a coordinate within the bo unds provided. 269 * Updates the given point such that it refers to a coordinate within the bo unds provided.
235 * 270 *
(...skipping 20 matching lines...) Expand all
256 // Padding is additional space added to the image which is the larger va lue of: 291 // 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 292 // - Potential overlap of the System UI and image content
258 // - Actual amount of padding already being used 293 // - Actual amount of padding already being used
259 // 294 //
260 // By expanding the area, we allow the user to move the cursor 'under' t he System UI which 295 // 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 296 // 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 297 // 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. 298 // the desktop image from 'snapping' back to pre-System UI state.
264 RectF systemUiOverlap = getSystemUiOverlap(); 299 RectF systemUiOverlap = getSystemUiOverlap();
265 float[] padding = {Math.max(mVisibleImagePadding.left, systemUiOverlap.l eft), 300 float[] padding = {Math.max(mVisibleImagePadding.left, systemUiOverlap.l eft),
266 Math.max(mVisibleImagePadding.top, systemUiOverlap.top), 301 Math.max(mVisibleImagePadding.top + mCursorOffsetScreenY, system UiOverlap.top),
267 Math.max(mVisibleImagePadding.right, systemUiOverlap.right), 302 Math.max(mVisibleImagePadding.right, systemUiOverlap.right),
268 Math.max(mVisibleImagePadding.bottom, systemUiOverlap.bottom)}; 303 Math.max(mVisibleImagePadding.bottom - mCursorOffsetScreenY,
304 systemUiOverlap.bottom)};
269 Matrix screenToImage = new Matrix(); 305 Matrix screenToImage = new Matrix();
270 mRenderData.transform.invert(screenToImage); 306 mRenderData.transform.invert(screenToImage);
271 screenToImage.mapVectors(padding); 307 screenToImage.mapVectors(padding);
272 308
273 return new RectF(-padding[0], -padding[1], mRenderData.imageWidth + padd ing[2], 309 return new RectF(-padding[0], -padding[1], mRenderData.imageWidth + padd ing[2],
274 mRenderData.imageHeight + padding[3]); 310 mRenderData.imageHeight + padding[3]);
275 } 311 }
276 312
277 /** Returns a region which defines the set of valid viewport center values i n image space. */ 313 /** Returns a region which defines the set of valid viewport center values i n image space. */
278 private RectF getViewportBounds() { 314 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 354 * 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. 355 * desktop image below it. This is the maximum amount that could overlap, n ot the actual value.
320 */ 356 */
321 private RectF getSystemUiOverlap() { 357 private RectF getSystemUiOverlap() {
322 // letterBox padding represents the space added to the image to center i t on the screen. 358 // 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 359 // 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. 360 // between the System UI and the remote desktop image.
325 // Note: Ignore negative padding (clamp to 0) since that means no overla p exists. 361 // Note: Ignore negative padding (clamp to 0) since that means no overla p exists.
326 PointF letterboxPadding = getLetterboxPadding(); 362 PointF letterboxPadding = getLetterboxPadding();
327 return new RectF(Math.max(mSystemUiScreenSize.left - letterboxPadding.x, 0.0f), 363 return new RectF(Math.max(mSystemUiScreenSize.left - letterboxPadding.x, 0.0f),
328 Math.max(mSystemUiScreenSize.top - letterboxPadding.y, 0.0f), 364 Math.max(mSystemUiScreenSize.top - letterboxPadding.y + mCursorO ffsetScreenY, 0.0f),
329 Math.max(mSystemUiScreenSize.right - letterboxPadding.x, 0.0f), 365 Math.max(mSystemUiScreenSize.right - letterboxPadding.x, 0.0f),
330 Math.max(mSystemUiScreenSize.bottom - letterboxPadding.y, 0.0f)) ; 366 Math.max(mSystemUiScreenSize.bottom - letterboxPadding.y - mCurs orOffsetScreenY,
367 0.0f));
331 } 368 }
332 369
333 /** 370 /**
334 * Calculates the amount of padding visible on each edge of the desktop imag e. 371 * Calculates the amount of padding visible on each edge of the desktop imag e.
335 */ 372 */
336 private void updateVisibleImagePadding() { 373 private void updateVisibleImagePadding() {
337 PointF letterboxPadding = getLetterboxPadding(); 374 PointF letterboxPadding = getLetterboxPadding();
338 float[] imagePoints = {0.0f, 0.0f, mRenderData.imageWidth, mRenderData.i mageHeight}; 375 float[] imagePoints = {0.0f, 0.0f, mRenderData.imageWidth, mRenderData.i mageHeight};
339 mRenderData.transform.mapPoints(imagePoints); 376 mRenderData.transform.mapPoints(imagePoints);
340 377
341 mVisibleImagePadding.set(Math.max(imagePoints[0] - letterboxPadding.x, 0 .0f), 378 mVisibleImagePadding.set(Math.max(imagePoints[0] - letterboxPadding.x, 0 .0f),
342 Math.max(imagePoints[1] - letterboxPadding.y, 0.0f), 379 Math.max(imagePoints[1] - letterboxPadding.y, 0.0f),
343 Math.max(mRenderData.screenWidth - imagePoints[2] - letterboxPad ding.x, 0.0f), 380 Math.max(mRenderData.screenWidth - imagePoints[2] - letterboxPad ding.x, 0.0f),
344 Math.max(mRenderData.screenHeight - imagePoints[3] - letterboxPa dding.y, 0.0f)); 381 Math.max(mRenderData.screenHeight - imagePoints[3] - letterboxPa dding.y, 0.0f));
345 } 382 }
346 } 383 }
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