Bug 1347476 - [RTL] Update TouchDelegate Rect for tab close button relatively, r=sebastian a=jcristau
authormaliu <max@mxli.us>
Thu, 16 Mar 2017 11:11:13 +0800
changeset 396430 1e504e2b22218ea1dabdae39d4b17c870389551b
parent 396429 6e7be87923b6f10aae7de08345239ab3ce7d6af9
child 396431 c4c3049f649ed4b79466f1c3bb62f4871aa619e7
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, jcristau
bugs1347476
milestone54.0
Bug 1347476 - [RTL] Update TouchDelegate Rect for tab close button relatively, r=sebastian a=jcristau MozReview-Commit-ID: 2ptzHWBVvUq
mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutItemView.java
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutItemView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayoutItemView.java
@@ -10,16 +10,17 @@ import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.widget.TabThumbnailWrapper;
 import org.mozilla.gecko.widget.TouchDelegateWithReset;
 import org.mozilla.gecko.widget.themed.ThemedRelativeLayout;
 
 import android.content.Context;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.support.v4.widget.TextViewCompat;
+import android.support.v7.widget.ViewUtils;
 import android.util.AttributeSet;
 import android.util.TypedValue;
 import android.view.View;
 import android.view.ViewTreeObserver;
 import android.widget.Checkable;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
@@ -104,29 +105,35 @@ public class TabsLayoutItemView extends 
             @Override
             public boolean onPreDraw() {
                 getViewTreeObserver().removeOnPreDrawListener(this);
 
                 // Ideally we want the close button hit area to be 40x40dp but we are constrained by the height of the parent, so
                 // we make it as tall as the parent view and 40dp across.
                 final int targetHitArea = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());;
 
-                final Rect hitRect = new Rect();
-                hitRect.top = 0;
-                hitRect.right = getWidth();
-                hitRect.left = getWidth() - targetHitArea;
-                hitRect.bottom = targetHitArea;
+                final Rect hitRect = getHitRectRelatively(targetHitArea);
 
                 setTouchDelegate(new TouchDelegateWithReset(hitRect, mCloseButton));
 
                 return true;
             }
         });
     }
 
+    private Rect getHitRectRelatively(int targetHitArea) {
+        final boolean isRtl = ViewUtils.isLayoutRtl(this);
+        final Rect hitRect = new Rect();
+        hitRect.top = 0;
+        hitRect.right = isRtl ? targetHitArea : getWidth();
+        hitRect.left = isRtl ? 0 : getWidth() - targetHitArea;
+        hitRect.bottom = targetHitArea;
+        return hitRect;
+    }
+
     protected void assignValues(Tab tab)  {
         if (tab == null) {
             return;
         }
 
         mTabId = tab.getId();
 
         setChecked(Tabs.getInstance().isSelectedTab(tab));