Bug 795045 - Part 2: Don't round coordinates until they're used. r=wesj
authorBrian Nicholson <bnicholson@mozilla.com>
Tue, 18 Dec 2012 22:58:01 -0800
changeset 125611 9af5a57f905a
parent 125610 ffe29f6052f2
child 125612 7f3b0fc0e464
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs795045
milestone20.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 795045 - Part 2: Don't round coordinates until they're used. r=wesj
mobile/android/base/TextSelectionHandle.java
--- a/mobile/android/base/TextSelectionHandle.java
+++ b/mobile/android/base/TextSelectionHandle.java
@@ -24,22 +24,22 @@ class TextSelectionHandle extends ImageV
 
     private enum HandleType { START, MIDDLE, END }; 
 
     private final HandleType mHandleType;
     private final int mWidth;
     private final int mHeight;
     private final int mShadow;
 
-    private int mLeft;
-    private int mTop;
+    private float mLeft;
+    private float mTop;
     private boolean mIsRTL; 
     private PointF mGeckoPoint;
-    private int mTouchStartX;
-    private int mTouchStartY;
+    private float mTouchStartX;
+    private float mTouchStartY;
 
     private RelativeLayout.LayoutParams mLayoutParams;
 
     private static final int IMAGE_LEVEL_LTR = 0;
     private static final int IMAGE_LEVEL_RTL = 1;
 
     private GeckoApp mActivity;
 
@@ -64,18 +64,18 @@ class TextSelectionHandle extends ImageV
         mWidth = getResources().getDimensionPixelSize(R.dimen.text_selection_handle_width);
         mHeight = getResources().getDimensionPixelSize(R.dimen.text_selection_handle_height);
         mShadow = getResources().getDimensionPixelSize(R.dimen.text_selection_handle_shadow);
     }
 
     public boolean onTouch(View v, MotionEvent event) {
         switch (event.getActionMasked()) {
             case MotionEvent.ACTION_DOWN: {
-                mTouchStartX = Math.round(event.getX());
-                mTouchStartY = Math.round(event.getY());
+                mTouchStartX = event.getX();
+                mTouchStartY = event.getY();
                 break;
             }
             case MotionEvent.ACTION_UP: {
                 mTouchStartX = 0;
                 mTouchStartY = 0;
 
                 // Reposition handles to line up with ends of selection
                 JSONObject args = new JSONObject();
@@ -83,94 +83,94 @@ class TextSelectionHandle extends ImageV
                     args.put("handleType", mHandleType.toString());
                 } catch (Exception e) {
                     Log.e(LOGTAG, "Error building JSON arguments for TextSelection:Position");
                 }
                 GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("TextSelection:Position", args.toString()));
                 break;
             }
             case MotionEvent.ACTION_MOVE: {
-                move(Math.round(event.getX()), Math.round(event.getY()));
+                move(event.getX(), event.getY());
                 break;
             }
         }
         return true;
     }
 
-    private void move(int newX, int newY) {
+    private void move(float newX, float newY) {
         mLeft = mLeft + newX - mTouchStartX;
         mTop = mTop + newY - mTouchStartY;
 
         LayerView layerView = mActivity.getLayerView();
         if (layerView == null) {
             Log.e(LOGTAG, "Can't move selection because layerView is null");
             return;
         }
         // Send x coordinate on the right side of the start handle, left side of the end handle.
-        float left = (float) mLeft + adjustLeftForHandle();
+        float left = mLeft + adjustLeftForHandle();
 
-        PointF geckoPoint = new PointF(left, (float) mTop);
+        PointF geckoPoint = new PointF(left, mTop);
         geckoPoint = layerView.convertViewPointToLayerPoint(geckoPoint);
 
         JSONObject args = new JSONObject();
         try {
             args.put("handleType", mHandleType.toString());
-            args.put("x", Math.round(geckoPoint.x));
-            args.put("y", Math.round(geckoPoint.y));
+            args.put("x", (int) geckoPoint.x);
+            args.put("y", (int) geckoPoint.y);
         } catch (Exception e) {
             Log.e(LOGTAG, "Error building JSON arguments for TextSelection:Move");
         }
         GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("TextSelection:Move", args.toString()));
 
         setLayoutPosition();
     }
 
     void positionFromGecko(int left, int top, boolean rtl) {
         LayerView layerView = mActivity.getLayerView();
         if (layerView == null) {
             Log.e(LOGTAG, "Can't position handle because layerView is null");
             return;
         }
 
-        mGeckoPoint = new PointF((float) left, (float) top);
+        mGeckoPoint = new PointF(left, top);
         if (mIsRTL != rtl) {
             mIsRTL = rtl;
             setImageLevel(mIsRTL ? IMAGE_LEVEL_RTL : IMAGE_LEVEL_LTR);
         }
 
         ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
         repositionWithViewport(metrics.viewportRectLeft, metrics.viewportRectTop, metrics.zoomFactor);
     }
 
     void repositionWithViewport(float x, float y, float zoom) {
         PointF viewPoint = new PointF((mGeckoPoint.x * zoom) - x,
                                       (mGeckoPoint.y * zoom) - y);
 
-        mLeft = Math.round(viewPoint.x) - (int) adjustLeftForHandle();
-        mTop = Math.round(viewPoint.y);
+        mLeft = viewPoint.x - adjustLeftForHandle();
+        mTop = viewPoint.y;
 
         setLayoutPosition();
     }
 
     private float adjustLeftForHandle() {
         if (mHandleType.equals(HandleType.START))
             return mIsRTL ? mShadow : mWidth - mShadow;
         else if (mHandleType.equals(HandleType.MIDDLE))
-            return (float) ((mWidth - mShadow) / 2);
+            return (mWidth - mShadow) / 2;
         else
             return mIsRTL ? mWidth - mShadow : mShadow;
     }
 
     private void setLayoutPosition() {
         if (mLayoutParams == null) {
             mLayoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
             // Set negative right/bottom margins so that the handles can be dragged outside of
             // the content area (if they are dragged to the left/top, the dyanmic margins set
             // below will take care of that).
             mLayoutParams.rightMargin = 0 - mWidth;
             mLayoutParams.bottomMargin = 0 - mHeight;
         }
 
-        mLayoutParams.leftMargin = mLeft;
-        mLayoutParams.topMargin = mTop;
+        mLayoutParams.leftMargin = (int) mLeft;
+        mLayoutParams.topMargin = (int) mTop;
         setLayoutParams(mLayoutParams);
     }
 }