OSDN Git Service

Fix right click to context menu behavior of View.
authorJun Mukai <mukai@google.com>
Tue, 24 Mar 2015 01:26:12 +0000 (18:26 -0700)
committerJun Mukai <mukai@google.com>
Wed, 25 Mar 2015 00:24:10 +0000 (17:24 -0700)
When the View opens the context menu, the mouse-down event is
already handled. Therefore, the next ACTION_UP should be canceled,
otherwise, single right click shows the context menu and then
invokes the normal click actions.

Also, the right-down event should always be consumed regardless
of the context menu support. "the right click opens the context
menu on some views, but it behaves as a normal click on some
other views" would confuse users.

Bug: 19641497
Change-Id: Ibbc18fe641745cf42382129b81858d8f3d14768b

core/java/android/view/View.java

index f5de8e3..13ce616 100644 (file)
@@ -4813,10 +4813,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
      * @hide
      */
     protected boolean performButtonActionOnTouchDown(MotionEvent event) {
-        if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) {
-            if (showContextMenu(event.getX(), event.getY(), event.getMetaState())) {
-                return true;
-            }
+        if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE &&
+            (event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) {
+            showContextMenu(event.getX(), event.getY(), event.getMetaState());
+            mPrivateFlags |= PFLAG_CANCEL_NEXT_UP_EVENT;
+            return true;
         }
         return false;
     }