Bug 1623402: Add ShowMenu to action names, perform action. r=eeejay
☠☠ backed out by 508ff70decaa ☠ ☠
authorMorgan Reschenberg <mreschenberg@mozilla.com>
Wed, 25 Mar 2020 22:10:27 +0000
changeset 520604 0bf2517f7a99083db29b355174565aa7b6348374
parent 520603 46ac4ee8eeb4ed694fd4e242631c9b7fb43285cc
child 520605 9de66850f37d43bb53046f1c17d63f871fb3a23f
push id37254
push usernerli@mozilla.com
push dateFri, 27 Mar 2020 04:48:07 +0000
treeherdermozilla-central@2d758b42bd73 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerseeejay
bugs1623402
milestone76.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 1623402: Add ShowMenu to action names, perform action. r=eeejay Depends on D67200 Differential Revision: https://phabricator.services.mozilla.com/D67409
accessible/mac/mozAccessible.mm
--- a/accessible/mac/mozAccessible.mm
+++ b/accessible/mac/mozAccessible.mm
@@ -15,16 +15,17 @@
 #include "Relation.h"
 #include "Role.h"
 #include "RootAccessible.h"
 #include "TableAccessible.h"
 #include "TableCellAccessible.h"
 #include "mozilla/a11y/PDocAccessible.h"
 #include "mozilla/dom/BrowserParent.h"
 #include "OuterDocAccessible.h"
+#include "nsChildView.h"
 
 #include "nsRect.h"
 #include "nsCocoaUtils.h"
 #include "nsCoord.h"
 #include "nsObjCExceptions.h"
 #include "nsWhitespaceTokenizer.h"
 #include <prdtoa.h>
 
@@ -513,18 +514,17 @@ static inline NSMutableArray* ConvertToN
     }
   }
 
   // Regardless of `count`, add actions that should be
   // performable on all accessibles. If we added a press
   // action, it will be first in the list. We append other
   // actions here to maintain that invariant.
   [actions addObject:NSAccessibilityScrollToVisibleAction];
-  // XXX(morgan): we should implement `show menu` as
-  // an "always performable" action. See bug 1623402.
+  [actions addObject:NSAccessibilityShowMenuAction];
 
   return actions;
 }
 
 - (NSString*)accessibilityActionDescription:(NSString*)action {
   // by default we return whatever the MacOS API know about.
   // if you have custom actions, override.
   return NSAccessibilityActionDescription(action);
@@ -579,16 +579,36 @@ static inline NSMutableArray* ConvertToN
   ProxyAccessible* proxy = [self getProxyAccessible];
 
   if ([action isEqualToString:NSAccessibilityScrollToVisibleAction]) {
     if (accWrap) {
       accWrap->ScrollTo(nsIAccessibleScrollType::SCROLL_TYPE_ANYWHERE);
     } else if (proxy) {
       proxy->ScrollTo(nsIAccessibleScrollType::SCROLL_TYPE_ANYWHERE);
     }
+  } else if ([action isEqualToString:NSAccessibilityShowMenuAction]) {
+    DesktopIntRect geckoRect;
+    id objOrView = nil;
+    if (accWrap) {
+      geckoRect = DesktopIntRect::FromUnknownRect(accWrap->Bounds());
+      objOrView =
+          GetObjectOrRepresentedView(GetNativeFromGeckoAccessible(accWrap->RootAccessible()));
+    } else if (proxy) {
+      geckoRect = DesktopIntRect::FromUnknownRect(proxy->Bounds());
+      objOrView = GetObjectOrRepresentedView(
+          GetNativeFromGeckoAccessible(proxy->OuterDocOfRemoteBrowser()->RootAccessible()));
+    }
+
+    NSRect cocoaRect =
+        NSMakeRect(geckoRect.x, geckoRect.YMost(), geckoRect.width, geckoRect.height);
+    LayoutDeviceIntPoint p =
+        LayoutDeviceIntPoint(NSToIntRound(NSMidX(cocoaRect)), NSToIntRound(NSMidY(cocoaRect)));
+    nsIWidget* widget = [objOrView widget];
+    widget->SynthesizeNativeMouseEvent(p, NSEventTypeRightMouseDown, 0, nullptr);
+
   } else {
     if (accWrap) {
       accWrap->DoAction(0);
     } else if (proxy) {
       proxy->DoAction(0);
     }
   }
 }