Backout 110075:81be299f5004 - Big regression on tabs tray
authorLucas Rocha <lucasr@mozilla.com>
Fri, 12 Oct 2012 13:47:53 +0100
changeset 110215 78918f4eb983d826174ad77d8b223540e310ac0e
parent 110214 2dbcd6d16b43f7aa2b7ba48e04cd3f8f303c04e5
child 110216 3044539fec87be189addde74159b93293c6301cb
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
bugs110075
milestone19.0a1
Backout 110075:81be299f5004 - Big regression on tabs tray
mobile/android/base/AboutHomeContent.java.in
mobile/android/base/BrowserApp.java
mobile/android/base/GeckoApp.java
mobile/android/base/GeckoViewsFactory.java
mobile/android/base/resources/layout-xlarge-v11/gecko_app.xml.in
mobile/android/base/resources/layout/gecko_app.xml.in
--- a/mobile/android/base/AboutHomeContent.java.in
+++ b/mobile/android/base/AboutHomeContent.java.in
@@ -89,16 +89,17 @@ public class AboutHomeContent extends Sc
 
     private AboutHomePromoBox mPromoBox;
     private AboutHomePromoBox.Type mPrelimPromoBoxType;
     protected AboutHomeSection mAddons;
     protected AboutHomeSection mLastTabs;
     protected AboutHomeSection mRemoteTabs;
 
     private View.OnClickListener mRemoteTabClickListener;
+    private OnInterceptTouchListener mOnInterceptTouchListener;
 
     public interface UriLoadCallback {
         public void callback(String uriSpec);
     }
 
     public interface VoidCallback {
         public void callback();
     }
@@ -341,16 +342,34 @@ public class AboutHomeContent extends Sc
             mTopSitesAdapter.notifyDataSetChanged();
 
         removeAllViews(); // We must remove the currently inflated view to allow for reinflation.
         inflate();
         mTopSitesGrid.setAdapter(mTopSitesAdapter); // mTopSitesGrid is a new instance (from loadTopSites()).
         update(AboutHomeContent.UpdateFlags.ALL); // Refresh all elements.
     }
 
+    @Override
+    public boolean onInterceptTouchEvent(MotionEvent event) {
+        if (mOnInterceptTouchListener != null && mOnInterceptTouchListener.onInterceptTouchEvent(this, event))
+            return true;
+        return super.onInterceptTouchEvent(event);
+    }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent event) {
+        if (mOnInterceptTouchListener != null && mOnInterceptTouchListener.onTouch(this, event))
+            return true;
+        return super.onTouchEvent(event);
+    }
+
+    public void setOnInterceptTouchListener(OnInterceptTouchListener listener) {
+        mOnInterceptTouchListener = listener;
+    }
+
     private String readFromZipFile(String filename) {
         ZipFile zip = null;
         String str = null;
         try {
             InputStream fileStream = null;
             File applicationPackage = new File(mActivity.getApplication().getPackageResourcePath());
             zip = new ZipFile(applicationPackage);
             if (zip == null)
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -19,26 +19,24 @@ import android.app.AlertDialog;
 import android.content.DialogInterface;
 import android.content.SharedPreferences;
 import android.content.Intent;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
-import android.graphics.Rect;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
-import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.animation.Interpolator;
 import android.widget.LinearLayout;
 import android.widget.Toast;
 
 import dalvik.system.DexClassLoader;
 
@@ -205,18 +203,16 @@ abstract public class BrowserApp extends
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         LinearLayout actionBar = (LinearLayout) getActionBarLayout();
         mMainLayout.addView(actionBar, 0);
 
-        ((GeckoApp.MainLayout) mMainLayout).setOnInterceptTouchListener(new HideTabsTouchListener());
-
         mBrowserToolbar = new BrowserToolbar(this);
         mBrowserToolbar.from(actionBar);
 
         if (mTabsPanel != null)
             mTabsPanel.setTabsLayoutChangeListener(this);
 
         mFindInPageBar = (FindInPageBar) findViewById(R.id.find_in_page);
 
@@ -674,72 +670,28 @@ abstract public class BrowserApp extends
                             Tabs.getInstance().loadUrl(url);
                         }
                     });
                     mAboutHomeContent.setLoadCompleteCallback(new AboutHomeContent.VoidCallback() {
                          public void callback() {
                              mAboutHomeStartupTimer.stop();
                          }
                     });
+                    mAboutHomeContent.setOnInterceptTouchListener(new ContentTouchListener());
                 } else {
                     mAboutHomeContent.update(EnumSet.of(AboutHomeContent.UpdateFlags.TOP_SITES,
                                                         AboutHomeContent.UpdateFlags.REMOTE_TABS));
                 }
                 mAboutHomeContent.setVisibility(View.VISIBLE);
             } else {
                 findViewById(R.id.abouthome_content).setVisibility(View.GONE);
             }
         } 
     }
 
-    private class HideTabsTouchListener implements OnInterceptTouchListener {
-        private boolean mIsHidingTabs = false;
-
-        @Override
-        public boolean onInterceptTouchEvent(View view, MotionEvent event) {
-            // Pre-Honeycomb Android needs to account for scroll state for the
-            // touched view otherwise tapping on an "empty" part of the view will
-            // still be considered a valid touch event.
-            if (Build.VERSION.SDK_INT < 11) {
-                Rect rect = new Rect();
-                view.getHitRect(rect);
-                rect.offset(-view.getScrollX(), -view.getScrollY());
-
-                int[] viewCoords = new int[2];
-                view.getLocationOnScreen(viewCoords);
-
-                int x = (int) event.getRawX() - viewCoords[0];
-                int y = (int) event.getRawY() - viewCoords[1];
-
-                if (!rect.contains(x, y))
-                    return false;
-            }
-
-            // If the tab tray is showing, hide the tab tray and don't send the event to content.
-            if (event.getActionMasked() == MotionEvent.ACTION_DOWN && autoHideTabs()) {
-                mIsHidingTabs = true;
-                return true;
-            }
-            return false;
-        }
-
-        @Override
-        public boolean onTouch(View view, MotionEvent event) {
-            if (mIsHidingTabs) {
-                // Keep consuming events until the gesture finishes.
-                int action = event.getActionMasked();
-                if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
-                    mIsHidingTabs = false;
-                }
-                return true;
-            }
-            return false;
-        }
-    }
-
     private void addAddonMenuItem(final int id, final String label, final String icon) {
         if (mMenu == null) {
             if (mAddonMenuItemsCache == null)
                 mAddonMenuItemsCache = new Vector<MenuItemInfo>();
 
             mAddonMenuItemsCache.add(new MenuItemInfo(id, label, icon));
             return;
         }
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -2534,29 +2534,27 @@ abstract public class GeckoApp
 
     public void notifyCheckUpdateResult(boolean result) {
         GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Update:CheckResult", result ? "true" : "false"));
     }
 
     protected void connectGeckoLayerClient() {
         mLayerView.getLayerClient().notifyGeckoReady();
 
-        mLayerView.getTouchEventHandler().setOnTouchListener(new OnInterceptTouchListener() {
+        mLayerView.getTouchEventHandler().setOnTouchListener(new ContentTouchListener() {
             private PointF initialPoint = null;
 
             @Override
-            public boolean onInterceptTouchEvent(View view, MotionEvent event) {
-                return false;
-            }
-
-            @Override
             public boolean onTouch(View view, MotionEvent event) {
                 if (event == null)
                     return true;
 
+                if (super.onTouch(view, event))
+                    return true;
+
                 int action = event.getAction();
                 PointF point = new PointF(event.getX(), event.getY());
                 if ((action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
                     initialPoint = point;
                 }
 
                 if (initialPoint != null && (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_MOVE) {
                     if (PointUtils.subtract(point, initialPoint).length() < PanZoomController.PAN_THRESHOLD) {
@@ -2569,40 +2567,40 @@ abstract public class GeckoApp
                 }
 
                 GeckoAppShell.sendEventToGecko(GeckoEvent.createMotionEvent(event));
                 return true;
             }
         });
     }
 
-    public static class MainLayout extends LinearLayout {
-        private OnInterceptTouchListener mOnInterceptTouchListener;
-
-        public MainLayout(Context context, AttributeSet attrs) {
-            super(context, attrs);
-            mOnInterceptTouchListener = null;
-        }
-
-        public void setOnInterceptTouchListener(OnInterceptTouchListener listener) {
-            mOnInterceptTouchListener = listener;
+    protected class ContentTouchListener implements OnInterceptTouchListener {
+        private boolean mIsHidingTabs = false;
+
+        @Override
+        public boolean onInterceptTouchEvent(View view, MotionEvent event) {
+            // If the tab tray is showing, hide the tab tray and don't send the event to content.
+            if (event.getActionMasked() == MotionEvent.ACTION_DOWN && autoHideTabs()) {
+                mIsHidingTabs = true;
+                return true;
+            }
+            return false;
         }
 
         @Override
-        public boolean onInterceptTouchEvent(MotionEvent event) {
-            if (mOnInterceptTouchListener != null && mOnInterceptTouchListener.onInterceptTouchEvent(this, event))
+        public boolean onTouch(View view, MotionEvent event) {
+            if (mIsHidingTabs) {
+                // Keep consuming events until the gesture finishes.
+                int action = event.getActionMasked();
+                if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
+                    mIsHidingTabs = false;
+                }
                 return true;
-            return super.onInterceptTouchEvent(event);
-        }
-
-        @Override
-        public boolean onTouchEvent(MotionEvent event) {
-            if (mOnInterceptTouchListener != null && mOnInterceptTouchListener.onTouch(this, event))
-                return true;
-            return super.onTouchEvent(event);
+            }
+            return false;
         }
     }
 
     public boolean linkerExtract() {
         return false;
     }
 
     private class FullScreenHolder extends FrameLayout {
--- a/mobile/android/base/GeckoViewsFactory.java
+++ b/mobile/android/base/GeckoViewsFactory.java
@@ -47,18 +47,16 @@ public final class GeckoViewsFactory imp
             else if (TextUtils.equals(viewName, "AboutHomeSection"))
                 return new AboutHomeSection(context, attrs);
             else if (TextUtils.equals(viewName, "AwesomeBarTabs"))
                 return new AwesomeBarTabs(context, attrs);
             else if (TextUtils.equals(viewName, "BrowserToolbarBackground"))
                 return new BrowserToolbarBackground(context, attrs);
             else if (TextUtils.equals(viewName, "FormAssistPopup"))
                 return new FormAssistPopup(context, attrs);
-            else if (TextUtils.equals(viewName, "GeckoApp$MainLayout"))
-                return new GeckoApp.MainLayout(context, attrs);
             else if (TextUtils.equals(viewName, "LinkTextView"))
                 return new LinkTextView(context, attrs);
             else if (TextUtils.equals(viewName, "FindInPageBar"))
                 return new FindInPageBar(context, attrs);
             else if (TextUtils.equals(viewName, "MenuButton"))
                 return new MenuButton(context, attrs);
             else if (TextUtils.equals(viewName, "TabsButton"))
                 return new TabsButton(context, attrs);
--- a/mobile/android/base/resources/layout-xlarge-v11/gecko_app.xml.in
+++ b/mobile/android/base/resources/layout-xlarge-v11/gecko_app.xml.in
@@ -10,19 +10,18 @@
                 android:layout_height="fill_parent">
 
    <org.mozilla.gecko.TabsPanel android:id="@+id/tabs_panel"
                                 android:layout_width="200dip"
                                 android:layout_height="fill_parent"
                                 android:background="@drawable/tabs_tray_bg_repeat"
                                 gecko:sidebar="true"/>
 
-   <view class="org.mozilla.gecko.GeckoApp$MainLayout"
-         android:id="@+id/main_layout"
-         style="@style/Screen.Transparent">
+   <LinearLayout android:id="@+id/main_layout"
+                 style="@style/Screen.Transparent">
  
         <!-- BrowserToolbar will be added dynamically -->
         
         <RelativeLayout android:id="@+id/gecko_layout"
                         android:layout_width="fill_parent"
                         android:layout_height="fill_parent"
                         android:layout_weight="1">
 
@@ -37,11 +36,11 @@
 
         <org.mozilla.gecko.FindInPageBar android:id="@+id/find_in_page"
                                          android:layout_width="fill_parent"
                                          android:layout_height="wrap_content"
                                          android:layout_gravity="bottom"
                                          style="@style/FindBar"
                                          android:visibility="gone"/>
 
-    </view>
+    </LinearLayout>
 
 </RelativeLayout>
--- a/mobile/android/base/resources/layout/gecko_app.xml.in
+++ b/mobile/android/base/resources/layout/gecko_app.xml.in
@@ -10,19 +10,18 @@
                 android:layout_height="fill_parent">
 
    <org.mozilla.gecko.TabsPanel android:id="@+id/tabs_panel"
                                 android:layout_width="fill_parent"
                                 android:layout_height="fill_parent"
                                 android:background="@drawable/tabs_tray_bg_repeat"
                                 gecko:sidebar="false"/>
 
-   <view class="org.mozilla.gecko.GeckoApp$MainLayout"
-         android:id="@+id/main_layout"
-         style="@style/Screen.Transparent">
+   <LinearLayout android:id="@+id/main_layout"
+                 style="@style/Screen.Transparent">
  
         <!-- BrowserToolbar will be added dynamically -->
 
         <RelativeLayout android:id="@+id/gecko_layout"
                         android:layout_width="fill_parent"
                         android:layout_height="fill_parent"
                         android:layout_weight="1">
 
@@ -37,11 +36,11 @@
 
         <org.mozilla.gecko.FindInPageBar android:id="@+id/find_in_page"
                                          android:layout_width="fill_parent"
                                          android:layout_height="wrap_content"
                                          android:layout_gravity="bottom"
                                          style="@style/FindBar"
                                          android:visibility="gone"/>
 
-    </view>
+    </LinearLayout>
 
 </RelativeLayout>