Bug 918044 - Block layout requests while handling focus changes in TopSitesGridView (r=sriram)
authorLucas Rocha <lucasr@lucasr.org>
Wed, 16 Oct 2013 16:39:34 +0100
changeset 165751 0bc8a298c227e2dedc3f466ca9bda70fc040a583
parent 165750 51705bf54f7519b006e0e72b6c41bc3a899bb3cb
child 165752 60ff0c915b5c80f4085a5273693f74b3d74fc05c
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssriram
bugs918044
milestone27.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 918044 - Block layout requests while handling focus changes in TopSitesGridView (r=sriram)
mobile/android/base/home/TopSitesGridView.java
--- a/mobile/android/base/home/TopSitesGridView.java
+++ b/mobile/android/base/home/TopSitesGridView.java
@@ -10,16 +10,17 @@ import org.mozilla.gecko.ThumbnailHelper
 import org.mozilla.gecko.db.BrowserDB.TopSitesCursorWrapper;
 import org.mozilla.gecko.db.BrowserDB.URLColumns;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 import org.mozilla.gecko.util.StringUtils;
 
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.database.Cursor;
+import android.graphics.Rect;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.View;
 import android.widget.AbsListView;
 import android.widget.AdapterView;
 import android.widget.GridView;
 
@@ -59,16 +60,21 @@ public class TopSitesGridView extends Gr
     private OnUrlOpenListener mUrlOpenListener;
 
     // Pin site listener.
     private OnPinSiteListener mPinSiteListener;
 
     // Context menu info.
     private TopSitesGridContextMenuInfo mContextMenuInfo;
 
+    // Whether we're handling focus changes or not. This is used
+    // to avoid infinite re-layouts when using this GridView as
+    // a ListView header view (see bug 918044).
+    private boolean mIsHandlingFocusChange;
+
     public TopSitesGridView(Context context) {
         this(context, null);
     }
 
     public TopSitesGridView(Context context, AttributeSet attrs) {
         this(context, attrs, R.attr.topSitesGridViewStyle);
     }
 
@@ -77,16 +83,18 @@ public class TopSitesGridView extends Gr
         mMaxSites = getResources().getInteger(R.integer.number_of_top_sites);
         mNumColumns = getResources().getInteger(R.integer.number_of_top_sites_cols);
         setNumColumns(mNumColumns);
 
         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TopSitesGridView, defStyle, 0);
         mHorizontalSpacing = a.getDimensionPixelOffset(R.styleable.TopSitesGridView_android_horizontalSpacing, 0x00);
         mVerticalSpacing = a.getDimensionPixelOffset(R.styleable.TopSitesGridView_android_verticalSpacing, 0x00);
         a.recycle();
+
+        mIsHandlingFocusChange = false;
     }
 
     /**
      * {@inheritDoc}
      */
     @Override
     public void onAttachedToWindow() {
         super.onAttachedToWindow();
@@ -126,16 +134,30 @@ public class TopSitesGridView extends Gr
     @Override
     public void onDetachedFromWindow() {
         super.onDetachedFromWindow();
 
         mUrlOpenListener = null;
         mPinSiteListener = null;
     }
 
+    @Override
+    protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
+        mIsHandlingFocusChange = true;
+        super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
+        mIsHandlingFocusChange = false;
+    }
+
+    @Override
+    public void requestLayout() {
+        if (!mIsHandlingFocusChange) {
+            super.requestLayout();
+        }
+    }
+
     /**
      * {@inheritDoc}
      */
     @Override
     public int getColumnWidth() {
         // This method will be called from onMeasure() too.
         // It's better to use getMeasuredWidth(), as it is safe in this case.
         final int totalHorizontalSpacing = mNumColumns > 0 ? (mNumColumns - 1) * mHorizontalSpacing : 0;