Bug 774209 - Don't make DoorHangerPopup focusable when it's not showing. r=sriram
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Sat, 08 Sep 2012 07:31:54 +0200
changeset 104642 ba75a6fd8ef549faee785e0eedd37fa6a785a586
parent 104641 928f0bc78bc5dc6694ba1bc17d014a2e1dbfa18f
child 104643 5bfebb616f9e678c8c3464de5e5254ff563405ba
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerssriram
bugs774209
milestone18.0a1
Bug 774209 - Don't make DoorHangerPopup focusable when it's not showing. r=sriram
mobile/android/base/DoorHangerPopup.java
--- a/mobile/android/base/DoorHangerPopup.java
+++ b/mobile/android/base/DoorHangerPopup.java
@@ -118,17 +118,16 @@ public class DoorHangerPopup extends Pop
                 updatePopup();
                 break;
         }
     }
 
     private void init() {
         setBackgroundDrawable(new BitmapDrawable());
         setOutsideTouchable(true);
-        setFocusable(true);
         setWindowLayoutMode(mActivity.isTablet() ? ViewGroup.LayoutParams.WRAP_CONTENT : ViewGroup.LayoutParams.FILL_PARENT,
             ViewGroup.LayoutParams.WRAP_CONTENT);
 
         LayoutInflater inflater = LayoutInflater.from(mActivity);
         RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.doorhangerpopup, null);
         mArrow = (ImageView) layout.findViewById(R.id.doorhanger_arrow);
         mContent = (LinearLayout) layout.findViewById(R.id.doorhanger_container);
         
@@ -242,16 +241,18 @@ public class DoorHangerPopup extends Pop
         }
 
         // On tablets, we need to position the popup so that the center of the arrow points to the
         // center of the anchor view. On phones the popup stretches across the entire screen, so the
         // arrow position is determined by its left margin.
         int offset = mActivity.isTablet() ? mAnchor.getWidth()/2 - mArrowWidth/2 -
                      ((RelativeLayout.LayoutParams) mArrow.getLayoutParams()).leftMargin : 0;
         showAsDropDown(mAnchor, offset, 0);
+        // Make the popup focusable for keyboard accessibility.
+        setFocusable(true);
     }
 
     private void fixBackgroundForFirst() {
         for (int i = 0; i < mContent.getChildCount(); i++) {
             DoorHanger dh = (DoorHanger) mContent.getChildAt(i);
             if (dh.getVisibility() == View.VISIBLE) {
                 dh.setBackgroundResource(R.drawable.doorhanger_bg);
                 break;
@@ -261,9 +262,17 @@ public class DoorHangerPopup extends Pop
 
     private void registerEventListener(String event) {
         GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
     }
 
     private void unregisterEventListener(String event) {
         GeckoAppShell.getEventDispatcher().unregisterEventListener(event, this);
     }
+
+    @Override
+    public void dismiss() {
+        // If the popup is focusable while it is hidden, we run into crashes
+        // on pre-ICS devices when the popup gets focus before it is shown.
+        setFocusable(false);
+        super.dismiss();
+    }
 }