Bug 1564549 - Add action forwarding macro. r=Jamie
authorEitan Isaacson <eitan@monotonous.org>
Mon, 23 Sep 2019 23:42:53 +0000
changeset 494797 ab7bb18bcca2fab4480af1a9d230c231b50d230e
parent 494796 e2ddce1acc62b1e1bf367a226b0cb64a8cec7e78
child 494798 83b8e1b49e1e2bd64cff30f52de828e8557a80b6
push id114131
push userdluca@mozilla.com
push dateThu, 26 Sep 2019 09:47:34 +0000
treeherdermozilla-inbound@1dc1a755079a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamie
bugs1564549
milestone71.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 1564549 - Add action forwarding macro. r=Jamie Differential Revision: https://phabricator.services.mozilla.com/D45597
accessible/android/SessionAccessibility.cpp
--- a/accessible/android/SessionAccessibility.cpp
+++ b/accessible/android/SessionAccessibility.cpp
@@ -26,16 +26,26 @@
 #  define AALOG(args...) \
     __android_log_print(ANDROID_LOG_INFO, "GeckoAccessibilityNative", ##args)
 #else
 #  define AALOG(args...) \
     do {                 \
     } while (0)
 #endif
 
+#define FORWARD_ACTION_TO_ACCESSIBLE(funcname, ...)         \
+  if (RootAccessibleWrap* rootAcc = GetRoot()) {            \
+    AccessibleWrap* acc = rootAcc->FindAccessibleById(aID); \
+    if (!acc) {                                             \
+      return;                                               \
+    }                                                       \
+                                                            \
+    acc->funcname(__VA_ARGS__);                             \
+  }
+
 template <>
 const char nsWindow::NativePtr<mozilla::a11y::SessionAccessibility>::sName[] =
     "SessionAccessibility";
 
 using namespace mozilla::a11y;
 
 class Settings final
     : public mozilla::java::SessionAccessibility::Settings::Natives<Settings> {
@@ -93,35 +103,21 @@ RootAccessibleWrap* SessionAccessibility
   if (!mWindow) {
     return nullptr;
   }
 
   return static_cast<RootAccessibleWrap*>(mWindow->GetRootAccessible());
 }
 
 void SessionAccessibility::SetText(int32_t aID, jni::String::Param aText) {
-  if (RootAccessibleWrap* rootAcc = GetRoot()) {
-    AccessibleWrap* acc = rootAcc->FindAccessibleById(aID);
-    if (!acc) {
-      return;
-    }
-
-    acc->SetTextContents(aText->ToString());
-  }
+  FORWARD_ACTION_TO_ACCESSIBLE(SetTextContents, aText->ToString());
 }
 
 void SessionAccessibility::Click(int32_t aID) {
-  if (RootAccessibleWrap* rootAcc = GetRoot()) {
-    AccessibleWrap* acc = rootAcc->FindAccessibleById(aID);
-    if (!acc) {
-      return;
-    }
-
-    acc->DoAction(0);
-  }
+  FORWARD_ACTION_TO_ACCESSIBLE(DoAction, 0);
 }
 
 SessionAccessibility* SessionAccessibility::GetInstanceFor(
     ProxyAccessible* aAccessible) {
   auto tab =
       static_cast<dom::BrowserParent*>(aAccessible->Document()->Manager());
   dom::Element* frame = tab->GetOwnerElement();
   MOZ_ASSERT(frame);
@@ -413,8 +409,10 @@ void SessionAccessibility::UpdateCachedB
     } else {
       infos->SetElement(i, acc->ToBundle(true));
     }
   }
 
   mSessionAccessibility->UpdateCachedBounds(infos);
   SendWindowContentChangedEvent();
 }
+
+#undef FORWARD_ACTION_TO_ACCESSIBLE
\ No newline at end of file