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.content.Context; | 7 import android.content.Context; |
8 import android.graphics.Matrix; | 8 import android.graphics.Matrix; |
9 import android.graphics.PointF; | 9 import android.graphics.PointF; |
10 import android.util.Log; | 10 import android.util.Log; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 float[] rectScreen = {0, 0, mRenderData.imageWidth, mRenderData.imag
eHeight}; | 107 float[] rectScreen = {0, 0, mRenderData.imageWidth, mRenderData.imag
eHeight}; |
108 mRenderData.transform.mapPoints(rectScreen); | 108 mRenderData.transform.mapPoints(rectScreen); |
109 | 109 |
110 float leftDelta = rectScreen[0]; | 110 float leftDelta = rectScreen[0]; |
111 float rightDelta = rectScreen[2] - mRenderData.screenWidth; | 111 float rightDelta = rectScreen[2] - mRenderData.screenWidth; |
112 float topDelta = rectScreen[1]; | 112 float topDelta = rectScreen[1]; |
113 float bottomDelta = rectScreen[3] - mRenderData.screenHeight; | 113 float bottomDelta = rectScreen[3] - mRenderData.screenHeight; |
114 float xAdjust = 0; | 114 float xAdjust = 0; |
115 float yAdjust = 0; | 115 float yAdjust = 0; |
116 | 116 |
117 if (leftDelta > 0 && rightDelta > 0) { | 117 if (rectScreen[2] - rectScreen[0] < mRenderData.screenWidth) { |
| 118 // Image is narrower than the screen, so center it. |
| 119 xAdjust = -(rightDelta + leftDelta) / 2; |
| 120 } else if (leftDelta > 0 && rightDelta > 0) { |
118 // Panning the image left will show more of it. | 121 // Panning the image left will show more of it. |
119 xAdjust = -Math.min(leftDelta, rightDelta); | 122 xAdjust = -Math.min(leftDelta, rightDelta); |
120 } else if (leftDelta < 0 && rightDelta < 0) { | 123 } else if (leftDelta < 0 && rightDelta < 0) { |
121 // Pan the image right. | 124 // Pan the image right. |
122 xAdjust = Math.min(-leftDelta, -rightDelta); | 125 xAdjust = Math.min(-leftDelta, -rightDelta); |
123 } | 126 } |
124 | 127 |
125 // Apply similar logic for yAdjust. | 128 // Apply similar logic for yAdjust. |
126 if (topDelta > 0 && bottomDelta > 0) { | 129 if (rectScreen[3] - rectScreen[1] < mRenderData.screenHeight) { |
| 130 yAdjust = -(bottomDelta + topDelta) / 2; |
| 131 } else if (topDelta > 0 && bottomDelta > 0) { |
127 yAdjust = -Math.min(topDelta, bottomDelta); | 132 yAdjust = -Math.min(topDelta, bottomDelta); |
128 } else if (topDelta < 0 && bottomDelta < 0) { | 133 } else if (topDelta < 0 && bottomDelta < 0) { |
129 yAdjust = Math.min(-topDelta, -bottomDelta); | 134 yAdjust = Math.min(-topDelta, -bottomDelta); |
130 } | 135 } |
131 | 136 |
132 mRenderData.transform.postTranslate(xAdjust, yAdjust); | 137 mRenderData.transform.postTranslate(xAdjust, yAdjust); |
133 } | 138 } |
134 mViewer.transformationChanged(); | 139 mViewer.transformationChanged(); |
135 } | 140 } |
136 | 141 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 return true; | 269 return true; |
265 } | 270 } |
266 | 271 |
267 /** Called when the user is done zooming. Defers to onScale()'s judgemen
t. */ | 272 /** Called when the user is done zooming. Defers to onScale()'s judgemen
t. */ |
268 @Override | 273 @Override |
269 public void onScaleEnd(ScaleGestureDetector detector) { | 274 public void onScaleEnd(ScaleGestureDetector detector) { |
270 onScale(detector); | 275 onScale(detector); |
271 } | 276 } |
272 } | 277 } |
273 } | 278 } |
OLD | NEW |