Bug 1126866 - Fix the text size in zoomed view. r=kats

This commit is contained in:
dominique vincent 2015-02-21 09:00:22 +01:00
Родитель e8a13aa143
Коммит 49ae0f2b89
1 изменённых файлов: 22 добавлений и 13 удалений

Просмотреть файл

@ -40,12 +40,13 @@ public class ZoomedView extends FrameLayout implements LayerView.OnMetricsChange
LayerView.ZoomedViewListener, GeckoEventListener {
private static final String LOGTAG = "Gecko" + ZoomedView.class.getSimpleName();
private static final int ZOOM_FACTOR = 2;
private static final int DEFAULT_ZOOM_FACTOR = 3;
private static final int W_CAPTURED_VIEW_IN_PERCENT = 80;
private static final int H_CAPTURED_VIEW_IN_PERCENT = 50;
private static final int MINIMUM_DELAY_BETWEEN_TWO_RENDER_CALLS_NS = 1000000;
private static final int DELAY_BEFORE_NEXT_RENDER_REQUEST_MS = 2000;
private int zoomFactor;
private ImageView zoomedImageView;
private LayerView layerView;
private int viewWidth;
@ -184,7 +185,7 @@ public class ZoomedView extends FrameLayout implements LayerView.OnMetricsChange
final float parentHeight = metrics.getHeight();
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
returnValue.x = (int) ((x / ZOOM_FACTOR) + // Conversion of the x offset inside the zoomed view (using the scale factor)
returnValue.x = (int) ((x / zoomFactor) + // Conversion of the x offset inside the zoomed view (using the scale factor)
offset.x + // The offset of the layerView
@ -192,17 +193,17 @@ public class ZoomedView extends FrameLayout implements LayerView.OnMetricsChange
* Minimum value for the left side of the zoomed view is 0
* and we return 0 after conversion
* Maximum value for the left side of the zoomed view is (parentWidth - offset.x - viewWidth)
* and we return (parentWidth - offset.x - (viewWidth / ZOOM_FACTOR)) after conversion.
* and we return (parentWidth - offset.x - (viewWidth / zoomFactor)) after conversion.
*/
(((float) params.leftMargin) - offset.x) *
((parentWidth - offset.x - (viewWidth / ZOOM_FACTOR)) /
((parentWidth - offset.x - (viewWidth / zoomFactor)) /
(parentWidth - offset.x - viewWidth)));
// Same comments here vertically
returnValue.y = (int) ((y / ZOOM_FACTOR) +
returnValue.y = (int) ((y / zoomFactor) +
offset.y +
(((float) params.topMargin) - offset.y) *
((parentHeight - offset.y - (viewHeight / ZOOM_FACTOR)) /
((parentHeight - offset.y - (viewHeight / zoomFactor)) /
(parentHeight - offset.y - viewHeight)));
return returnValue;
@ -219,7 +220,7 @@ public class ZoomedView extends FrameLayout implements LayerView.OnMetricsChange
final float parentWidth = metrics.getWidth();
final float parentHeight = metrics.getHeight();
returnValue.x = (int) ((((x - (viewWidth / (2 * ZOOM_FACTOR)))) / // Translation to get the left side position of the zoomed view
returnValue.x = (int) ((((x - (viewWidth / (2 * zoomFactor)))) / // Translation to get the left side position of the zoomed view
// centered on x (the value 2 to get the middle).
/* Conversion of the left side position of the zoomed view.
@ -228,14 +229,14 @@ public class ZoomedView extends FrameLayout implements LayerView.OnMetricsChange
* and not in a multiplication to convert the position from
* the LayerView to the ZoomedView.
*/
((parentWidth - offset.x - (viewWidth / ZOOM_FACTOR)) /
((parentWidth - offset.x - (viewWidth / zoomFactor)) /
(parentWidth - offset.x - viewWidth)))
+ offset.x); // The offset of the layerView
// Same comments here vertically
returnValue.y = (int) ((((y - (viewHeight / (2 * ZOOM_FACTOR)))) /
((parentHeight - offset.y - (viewHeight / ZOOM_FACTOR)) /
returnValue.y = (int) ((((y - (viewHeight / (2 * zoomFactor)))) /
((parentHeight - offset.y - (viewHeight / zoomFactor)) /
(parentHeight - offset.y - viewHeight)))
+ offset.y);
@ -296,8 +297,16 @@ public class ZoomedView extends FrameLayout implements LayerView.OnMetricsChange
private void setCapturedSize(ImmutableViewportMetrics metrics) {
float parentMinSize = Math.min(metrics.getWidth(), metrics.getHeight());
viewWidth = (int) (parentMinSize * W_CAPTURED_VIEW_IN_PERCENT / (ZOOM_FACTOR * 100.0)) * ZOOM_FACTOR;
viewHeight = (int) (parentMinSize * H_CAPTURED_VIEW_IN_PERCENT / (ZOOM_FACTOR * 100.0)) * ZOOM_FACTOR;
// For metrics.zoomFactor lower than 1, the zoom factor of the zoomed view is calculated
// to get always the same size for the content in the zoomed view.
// For metrics.zoomFactor greater than 1, the zoom factor is always set to the default
// value DEFAULT_ZOOM_FACTOR, thus the zoomed view is always a zoom of the normal view.
zoomFactor = Math.max(DEFAULT_ZOOM_FACTOR, (int) (DEFAULT_ZOOM_FACTOR / metrics.zoomFactor));
viewWidth = (int) (parentMinSize * W_CAPTURED_VIEW_IN_PERCENT / (zoomFactor * 100.0)) * zoomFactor;
viewHeight = (int) (parentMinSize * H_CAPTURED_VIEW_IN_PERCENT / (zoomFactor * 100.0)) * zoomFactor;
// Display in zoomedview is corrupted when width is an odd number
// More details about this issue here: bug 776906 comment 11
viewWidth &= ~0x1;
}
private void shouldBlockUpdate(boolean shouldBlockUpdate) {
@ -474,7 +483,7 @@ public class ZoomedView extends FrameLayout implements LayerView.OnMetricsChange
final int yPos = (int) (origin.y - offset.y) + lastPosition.y;
GeckoEvent e = GeckoEvent.createZoomedViewEvent(tabId, xPos, yPos, viewWidth,
viewHeight, ZOOM_FACTOR * metrics.zoomFactor, buffer);
viewHeight, zoomFactor * metrics.zoomFactor, buffer);
GeckoAppShell.sendEventToGecko(e);
}