Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Bug 827208: TouchDelegate for tabs button. [r=bnicholson] [a=akeybl]

  • Loading branch information...
commit d8b5cf43f64adab540a0d84b38f9b755f057d818 1 parent 3628f3a
Sriram Ramani authored February 27, 2013
14  mobile/android/base/BrowserToolbar.java
@@ -318,7 +318,9 @@ public void onClick(View view) {
318 318
                     mActivity.openOptionsMenu();
319 319
                 }
320 320
             });
  321
+        }
321 322
 
  323
+        if (!mActivity.isTablet()) {
322 324
             // Set a touch delegate to Tabs button, so the touch events on its tail
323 325
             // are passed to the menu button.
324 326
             mLayout.post(new Runnable() {
@@ -327,8 +329,16 @@ public void run() {
327 329
                     int height = mTabs.getHeight();
328 330
                     int width = mTabs.getWidth();
329 331
                     int tail = (width - height) / 2;
330  
-                    Rect bounds = new Rect(width - tail, 0, width, height);
331  
-                    mTabs.setTouchDelegate(new TailTouchDelegate(bounds, mMenu));
  332
+
  333
+                    Rect leftBounds = new Rect(0, 0, tail, height);
  334
+                    Rect rightBounds = new Rect(width - tail, 0, width, height);
  335
+
  336
+                    TailTouchDelegate delegate = new TailTouchDelegate(leftBounds, mAddressBarView);
  337
+
  338
+                    if (mHasSoftMenuButton)
  339
+                        delegate.add(rightBounds, mMenu);
  340
+
  341
+                    mTabs.setTouchDelegate(delegate);
332 342
                 }
333 343
             });
334 344
         }
33  mobile/android/base/TailTouchDelegate.java
@@ -10,20 +10,38 @@
10 10
 import android.view.MotionEvent;
11 11
 import android.view.View;
12 12
 
  13
+import java.util.ArrayList;
  14
+import java.util.List;
  15
+
13 16
 /**
14 17
  * A TouchDelegate to pass the events from one view to another.
15 18
  * Usually it's better to give half of the tail's width to the other 
16 19
  * view that is being overlapped.
17 20
  */
18 21
 public class TailTouchDelegate extends TouchDelegate {
  22
+    // List of delegates.
  23
+    private List<TouchDelegate> mDelegates;
  24
+
19 25
     /**
20  
-     * Creates a TailTouchDelegate for a view.
  26
+     * Creates an empty TailTouchDelegate for a view.
21 27
      *
22 28
      * @param bounds        The rectangular bounds on the view which should delegate events.
23 29
      * @param delegateView  The view that should get the delegated events.
24 30
      */
25 31
     public TailTouchDelegate(Rect bounds, View delegateView) {
26 32
         super(bounds, delegateView);
  33
+        mDelegates = new ArrayList<TouchDelegate>();
  34
+        mDelegates.add(new TouchDelegate(bounds, delegateView));
  35
+    }
  36
+
  37
+    /**
  38
+     * Adds an Android TouchDelegate for the view.
  39
+     *
  40
+     * @param bounds        The rectangular bounds on the view which should delegate events.
  41
+     * @param delegateView  The view that should get the delegated events.
  42
+     */
  43
+    public void add(Rect bounds, View delegateView) {
  44
+        mDelegates.add(new TouchDelegate(bounds, delegateView));
27 45
     }
28 46
 
29 47
     @Override 
@@ -31,14 +49,15 @@ public boolean onTouchEvent(MotionEvent event) {
31 49
         switch (event.getAction()) {
32 50
             case MotionEvent.ACTION_DOWN:
33 51
                 // Android bug 36445: Touch Delegation not reset on ACTION_DOWN.
34  
-                if (!super.onTouchEvent(event)) {
  52
+                for (TouchDelegate delegate : mDelegates) {
  53
+                    if (delegate.onTouchEvent(event))
  54
+                        return true;
  55
+
35 56
                     MotionEvent cancelEvent = MotionEvent.obtain(event);
36 57
                     cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
37  
-                    super.onTouchEvent(cancelEvent);
38  
-                    return false;
39  
-                 } else {
40  
-                    return true;
41  
-                 }
  58
+                    delegate.onTouchEvent(cancelEvent);
  59
+                }
  60
+                return false;
42 61
             default:
43 62
                 return super.onTouchEvent(event);
44 63
         }

0 notes on commit d8b5cf4

Please sign in to comment.
Something went wrong with that request. Please try again.