Bug 1396076 - Part 2 - Use the HoverDelegate for TabsLayoutItemView's close button. r=jwu
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 01 Sep 2017 20:12:52 +0200
changeset 429288 bc9e3b8c4100e8ea2a2f9d500a8decc3827cdec8
parent 429287 d57e40a922ee924bdf07609fbdb3328cea308bdd
child 429289 60f7b76c8f7f7d3c00a2f7be03aebe23b90b3ae2
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwu
bugs1396076
milestone57.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 1396076 - Part 2 - Use the HoverDelegate for TabsLayoutItemView's close button. r=jwu MozReview-Commit-ID: FU4KVwVgtWy
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
@@ -2,27 +2,29 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.tabs;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
+import org.mozilla.gecko.widget.HoverDelegateWithReset;
 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.MotionEvent;
 import android.view.View;
 import android.view.ViewTreeObserver;
 import android.widget.Checkable;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
 public class TabsLayoutItemView extends LinearLayout
@@ -31,16 +33,17 @@ public class TabsLayoutItemView extends 
     private static final int[] STATE_CHECKED = { android.R.attr.state_checked };
     private boolean mChecked;
 
     private int mTabId;
     private TextView mTitle;
     private TabsPanelThumbnailView mThumbnail;
     private ImageView mCloseButton;
     private TabThumbnailWrapper mThumbnailWrapper;
+    private HoverDelegateWithReset mHoverDelegate;
 
     public TabsLayoutItemView(Context context, AttributeSet attrs) {
         super(context, attrs);
     }
 
     @Override
     public int[] onCreateDrawableState(int extraSpace) {
         final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
@@ -108,32 +111,51 @@ public class TabsLayoutItemView extends 
 
                 // 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 = getHitRectRelatively(targetHitArea);
 
                 setTouchDelegate(new TouchDelegateWithReset(hitRect, mCloseButton));
+                setHoverDelegate(new HoverDelegateWithReset(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;
     }
 
+    /**
+     * Sets the HoverDelegate for this View.
+     */
+    public void setHoverDelegate(HoverDelegateWithReset delegate) {
+        mHoverDelegate = delegate;
+    }
+
+    @Override
+    public boolean onHoverEvent(MotionEvent event) {
+        if (mHoverDelegate != null) {
+            if (mHoverDelegate.onHoverEvent(event)) {
+                return true;
+            }
+        }
+
+        return super.onHoverEvent(event);
+    }
+
     protected void assignValues(Tab tab)  {
         if (tab == null) {
             return;
         }
 
         mTabId = tab.getId();
 
         setChecked(Tabs.getInstance().isSelectedTab(tab));