Bug 1184937 - Hide cycling zoom button and set a default level of zoom in config. r=mcomella
authordominique vincent <domivinc@toitl.com>
Fri, 31 Jul 2015 08:42:50 +0200
changeset 287281 cc9121f8df37163afdca6c75e0f39fd0276cdd72
parent 287280 35238dc29bd80f5b77bc51f429f9505de20eb43f
child 287282 593ea7ab46e20a3486b3212e55d5fdd874585add
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1184937
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1184937 - Hide cycling zoom button and set a default level of zoom in config. r=mcomella
mobile/android/app/mobile.js
mobile/android/base/ZoomedView.java
mobile/android/base/resources/layout/zoomed_view.xml
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -410,17 +410,19 @@ pref("devtools.remote.usb.enabled", fals
 pref("devtools.remote.wifi.enabled", false);
 
 pref("font.size.inflation.minTwips", 0);
 
 // When true, zooming will be enabled on all sites, even ones that declare user-scalable=no.
 pref("browser.ui.zoom.force-user-scalable", false);
 
 pref("ui.zoomedview.disabled", false);
-pref("ui.zoomedview.limitReadableSize", 8);  // value in layer pixels
+pref("ui.zoomedview.limitReadableSize", 8); // value in layer pixels
+pref("ui.zoomedview.defaultZoomFactor", 2);
+pref("ui.zoomedview.simplified", true); // Do not display all the zoomed view controls
 
 pref("ui.touch.radius.enabled", false);
 pref("ui.touch.radius.leftmm", 3);
 pref("ui.touch.radius.topmm", 5);
 pref("ui.touch.radius.rightmm", 3);
 pref("ui.touch.radius.bottommm", 2);
 pref("ui.touch.radius.visitedWeight", 120);
 
--- a/mobile/android/base/ZoomedView.java
+++ b/mobile/android/base/ZoomedView.java
@@ -5,16 +5,17 @@
 
 package org.mozilla.gecko;
 
 import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
 import org.mozilla.gecko.gfx.LayerView;
 import org.mozilla.gecko.gfx.PanZoomController;
 import org.mozilla.gecko.gfx.PointUtils;
 import org.mozilla.gecko.mozglue.DirectBufferAllocator;
+import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.util.GeckoEventListener;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import org.json.JSONException;
 import org.json.JSONObject;
 
 import android.content.Context;
 import android.content.res.Resources;
@@ -46,27 +47,32 @@ import android.widget.TextView;
 
 import java.nio.ByteBuffer;
 import java.text.DecimalFormat;
 
 public class ZoomedView extends FrameLayout implements LayerView.OnMetricsChangedListener,
         LayerView.ZoomedViewListener, GeckoEventListener {
     private static final String LOGTAG = "Gecko" + ZoomedView.class.getSimpleName();
 
-    private static final float[] ZOOM_FACTORS_LIST = {2.0f, 3.0f, 1.5f};
+    private static final float[] ZOOM_FACTORS_LIST = {2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 1.5f};
     private static final int W_CAPTURED_VIEW_IN_PERCENT = 50;
     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 static final int OPENING_ANIMATION_DURATION_MS = 250;
     private static final int CLOSING_ANIMATION_DURATION_MS = 150;
     private static final float OVERSHOOT_INTERPOLATOR_TENSION = 1.5f;
 
     private float zoomFactor;
     private int currentZoomFactorIndex;
+    private boolean isSimplifiedUI;
+    private int defaultZoomFactor;
+    private int prefDefaultZoomFactorObserverId;
+    private int prefSimplifiedUIObserverId;
+
     private ImageView zoomedImageView;
     private LayerView layerView;
     private int viewWidth;
     private int viewHeight; // Only the zoomed view height, no toolbar, no shadow ...
     private int viewContainerWidth;
     private int viewContainerHeight; // Zoomed view height with toolbar and other elements like shadow, ...
     private int containterSize; // shadow, margin, ...
     private Point lastPosition;
@@ -208,78 +214,89 @@ public class ZoomedView extends FrameLay
     }
 
     public ZoomedView(Context context, AttributeSet attrs) {
         this(context, attrs, 0);
     }
 
     public ZoomedView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
+        isSimplifiedUI = true;
+        getPrefs();
+        currentZoomFactorIndex = 0;
         returnValue = new PointF();
         animationStart = new PointF();
-        currentZoomFactorIndex = 0;
-        zoomFactor = ZOOM_FACTORS_LIST[currentZoomFactorIndex];
         requestRenderRunnable = new Runnable() {
             @Override
             public void run() {
                 requestZoomedViewRender();
             }
         };
         touchListener = new ZoomedViewTouchListener();
         EventDispatcher.getInstance().registerGeckoThreadListener(this,
                 "Gesture:clusteredLinksClicked", "Window:Resize", "Content:LocationChange",
                 "Gesture:CloseZoomedView");
     }
 
     void destroy() {
+        PrefsHelper.removeObserver(prefDefaultZoomFactorObserverId);
+        PrefsHelper.removeObserver(prefSimplifiedUIObserverId);
         ThreadUtils.removeCallbacksFromUiThread(requestRenderRunnable);
         EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
                 "Gesture:clusteredLinksClicked", "Window:Resize", "Content:LocationChange",
                 "Gesture:CloseZoomedView");
     }
 
     // This method (onFinishInflate) is called only when the zoomed view class is used inside
     // an xml structure <org.mozilla.gecko.ZoomedView ...
     // It won't be called if the class is used from java code like "new  ZoomedView(context);"
     @Override
     protected void onFinishInflate() {
         super.onFinishInflate();
         closeButton = (ImageView) findViewById(R.id.dialog_close);
         changeZoomFactorButton = (TextView) findViewById(R.id.change_zoom_factor);
         zoomedImageView = (ImageView) findViewById(R.id.zoomed_image_view);
 
-        setTextInZoomFactorButton(ZOOM_FACTORS_LIST[0]);
+        setTextInZoomFactorButton(zoomFactor);
 
         toolbarHeight = getResources().getDimensionPixelSize(R.dimen.zoomed_view_toolbar_height);
         containterSize = getResources().getDimensionPixelSize(R.dimen.drawable_dropshadow_size);
         cornerRadius = getResources().getDimensionPixelSize(R.dimen.button_corner_radius);
 
         moveToolbar(true);
     }
 
     private void setListeners() {
         closeButton.setOnClickListener(new View.OnClickListener() {
             public void onClick(View view) {
                 stopZoomDisplay(true);
             }
         });
 
-        changeZoomFactorButton.setOnClickListener(new View.OnClickListener() {
-            public void onClick(View view) {
-                changeZoomFactor();
+        changeZoomFactorButton.setOnTouchListener(new  OnTouchListener() {
+            public boolean onTouch(View v, MotionEvent event) {
+
+                if (event.getAction() == MotionEvent.ACTION_UP) {
+                    if (event.getX() >= (changeZoomFactorButton.getLeft() + changeZoomFactorButton.getWidth() / 2)) {
+                        changeZoomFactor(true);
+                    } else {
+                        changeZoomFactor(false);
+                    }
+                }
+                return true;
             }
         });
 
         setOnTouchListener(touchListener);
     }
 
     private void removeListeners() {
         closeButton.setOnClickListener(null);
 
-        changeZoomFactorButton.setOnClickListener(null);
+        changeZoomFactorButton.setOnTouchListener(null);
 
         setOnTouchListener(null);
     }
     /*
      * Convert a click from ZoomedView. Return the position of the click in the
      * LayerView
      */
     private PointF getUnzoomedPositionFromPointInZoomedView(float x, float y) {
@@ -474,17 +491,57 @@ public class ZoomedView extends FrameLay
     private void shouldBlockUpdate(boolean shouldBlockUpdate) {
         stopUpdateView = shouldBlockUpdate;
     }
 
     private Bitmap.Config getBitmapConfig() {
         return (GeckoAppShell.getScreenDepth() == 24) ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
     }
 
-    private void startZoomDisplay(LayerView aLayerView, final int leftFromGecko, final int topFromGecko) {
+    private void getPrefs() {
+        prefSimplifiedUIObserverId = PrefsHelper.getPref("ui.zoomedview.simplified", new PrefsHelper.PrefHandlerBase() {
+            @Override
+            public void prefValue(String pref, boolean simplified) {
+                isSimplifiedUI = simplified;
+                if (simplified) {
+                    changeZoomFactorButton.setVisibility(View.INVISIBLE);
+                    zoomFactor = (float) defaultZoomFactor;
+                } else {
+                    zoomFactor = ZOOM_FACTORS_LIST[currentZoomFactorIndex];
+                    setTextInZoomFactorButton(zoomFactor);
+                    changeZoomFactorButton.setVisibility(View.VISIBLE);
+                }
+            }
+
+            @Override
+            public boolean isObserver() {
+                return true;
+            }
+        });
+
+        prefDefaultZoomFactorObserverId = PrefsHelper.getPref("ui.zoomedview.defaultZoomFactor", new PrefsHelper.PrefHandlerBase() {
+            @Override
+            public void prefValue(String pref, int defaultZoomFactorFromSettings) {
+                defaultZoomFactor = defaultZoomFactorFromSettings;
+                if (isSimplifiedUI) {
+                    zoomFactor = (float) defaultZoomFactor;
+                } else {
+                    zoomFactor = ZOOM_FACTORS_LIST[currentZoomFactorIndex];
+                    setTextInZoomFactorButton(zoomFactor);
+                }
+            }
+
+            @Override
+            public boolean isObserver() {
+                return true;
+            }
+        });
+    }
+
+private void startZoomDisplay(LayerView aLayerView, final int leftFromGecko, final int topFromGecko) {
         if (layerView == null) {
             layerView = aLayerView;
             layerView.addZoomedViewListener(this);
             layerView.setOnMetricsChangedZoomedViewportListener(this);
             ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
             setCapturedSize(metrics);
         }
         startTimeReRender = 0;
@@ -509,32 +566,36 @@ public class ZoomedView extends FrameLay
             if (layerView != null) {
                 layerView.setOnMetricsChangedZoomedViewportListener(null);
                 layerView.removeZoomedViewListener(this);
                 layerView = null;
             }
         }
     }
 
-    private void changeZoomFactor() {
-        if (currentZoomFactorIndex < ZOOM_FACTORS_LIST.length - 1) {
+    private void changeZoomFactor(boolean zoomIn) {
+        if (zoomIn && currentZoomFactorIndex < ZOOM_FACTORS_LIST.length - 1) {
             currentZoomFactorIndex++;
+        } else if (zoomIn && currentZoomFactorIndex >= ZOOM_FACTORS_LIST.length - 1) {
+            currentZoomFactorIndex = 0;
+        } else if (!zoomIn && currentZoomFactorIndex > 0) {
+            currentZoomFactorIndex--;
         } else {
-            currentZoomFactorIndex = 0;
+            currentZoomFactorIndex = ZOOM_FACTORS_LIST.length - 1;
         }
         zoomFactor = ZOOM_FACTORS_LIST[currentZoomFactorIndex];
 
         ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
         refreshZoomedViewSize(metrics);
         setTextInZoomFactorButton(zoomFactor);
     }
 
     private void setTextInZoomFactorButton(float zoom) {
         final String percentageValue = Integer.toString((int) (100*zoom));
-        changeZoomFactorButton.setText(getResources().getString(R.string.percent, percentageValue));
+        changeZoomFactorButton.setText("- " + getResources().getString(R.string.percent, percentageValue) + " +");
     }
 
     @Override
     public void handleMessage(final String event, final JSONObject message) {
         ThreadUtils.postToUiThread(new Runnable() {
             @Override
             public void run() {
                 try {
--- a/mobile/android/base/resources/layout/zoomed_view.xml
+++ b/mobile/android/base/resources/layout/zoomed_view.xml
@@ -15,25 +15,30 @@
     android:visibility="gone">
 
     <RelativeLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentLeft="true"
         android:layout_alignParentTop="true"
         android:background="@drawable/toolbar_grey_round">
+        <!--
+           Zoom factor button is invisible by default. Set ui.zoomedview.simplified to false
+           in order to display the button in the zoomed view tool bar
+        -->
         <TextView
             android:id="@+id/change_zoom_factor"
             android:layout_width="wrap_content"
             android:layout_height="@dimen/zoomed_view_toolbar_height"
             android:background="@android:color/transparent"
             android:padding="12dip"
             android:layout_alignLeft="@+id/zoomed_image_view"
             android:textSize="16sp"
-            android:textColor="@color/text_and_tabs_tray_grey"/>
+            android:textColor="@color/text_and_tabs_tray_grey"
+            android:visibility="invisible"/>
         <ImageView
             android:id="@+id/dialog_close"
             android:scaleType="center"
             android:layout_width="@dimen/zoomed_view_toolbar_height"
             android:layout_height="@dimen/zoomed_view_toolbar_height"
             android:layout_alignRight="@id/zoomed_image_view"
             android:src="@drawable/close_edit_mode_selector"/>
         <ImageView