Bug 899394 - Prevent page from scrolling to top when bookmark is tapped. r=sriram
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 31 Jul 2013 15:38:38 -0700
changeset 143490 329abf307997308f1a1fd24645224907d12f6965
parent 143489 1cc7d733d8c11f8c54ee64f944eb6efe3d6f10ff
child 143491 41e8b95f56679783cd32962e30b537e9ce2b6350
push id25130
push userlrocha@mozilla.com
push dateWed, 21 Aug 2013 09:41:27 +0000
treeherdermozilla-central@b2486721572e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssriram
bugs899394
milestone25.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 899394 - Prevent page from scrolling to top when bookmark is tapped. r=sriram
mobile/android/base/home/HomePager.java
mobile/android/base/resources/layout/gecko_app.xml
--- a/mobile/android/base/home/HomePager.java
+++ b/mobile/android/base/home/HomePager.java
@@ -179,19 +179,18 @@ public class HomePager extends ViewPager
 
             mPages.remove(mTabs.get(position).page);
         }
     }
 
     @Override
     public boolean onInterceptTouchEvent(MotionEvent event) {
         if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
-            // XXX: When an adapter is empty (e.g. Reading List), there are no elements focusable
-            // in touch mode so instead of requestFocus() we use requestFocusFromTouch(). However,
-            // now we may be focusing an object whose focused state is potentially visible to the
-            // user but should not be (e.g. the background), so we clear the focus.
-            requestFocusFromTouch();
-            clearFocus();
+            // XXX: Drop the soft keyboard by stealing focus. Note that the HomePager (via XML
+            // attr) is focusable after its descendants allowing requestFocus to succeed and drop
+            // the soft keyboard even if there are no other focusable views on the screen (e.g.
+            // the Reading List is empty).
+            requestFocus();
         }
 
         return super.onInterceptTouchEvent(event);
     }
 }
--- a/mobile/android/base/resources/layout/gecko_app.xml
+++ b/mobile/android/base/resources/layout/gecko_app.xml
@@ -30,17 +30,19 @@
             <FrameLayout android:id="@+id/home_pager_container"
                          android:layout_width="fill_parent"
                          android:layout_height="fill_parent">
 
                 <org.mozilla.gecko.home.HomePager android:id="@+id/home_pager"
                                                   android:layout_width="fill_parent"
                                                   android:layout_height="fill_parent"
                                                   android:background="@android:color/white"
-                                                  android:visibility="gone">
+                                                  android:visibility="gone"
+                                                  android:focusableInTouchMode="true"
+                                                  android:descendantFocusability="afterDescendants">
 
                     <org.mozilla.gecko.home.HomePagerTabStrip android:layout_width="fill_parent"
                                                               android:layout_height="32dip"
                                                               android:layout_gravity="top"
                                                               android:gravity="bottom"
                                                               android:background="@color/background_light"
                                                               gecko:tabIndicatorColor="@color/text_color_highlight"
                                                               android:textAppearance="@style/TextAppearance.Widget.HomePagerTabStrip"/>