Bug 1169701 - Fire native OS X accessibility events for proxied accessibles r=tbsaunde
authorLorien Hu <lorien@lorienhu.com>
Fri, 29 May 2015 13:50:26 -0400
changeset 247600 2a1df389a3edc9ecf84adf83613780239ba25816
parent 247599 63b1e449bedadff6b3dc6d37b834e23f066b3b4e
child 247601 55ada2f2d0074364fb2f6c3d1458cd6152a06aa0
push id60751
push userlhu@mozilla.com
push dateMon, 08 Jun 2015 14:42:58 +0000
treeherdermozilla-inbound@55ada2f2d007 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs1169701
milestone41.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 1169701 - Fire native OS X accessibility events for proxied accessibles r=tbsaunde
accessible/mac/AccessibleWrap.h
accessible/mac/AccessibleWrap.mm
accessible/mac/Platform.mm
--- a/accessible/mac/AccessibleWrap.h
+++ b/accessible/mac/AccessibleWrap.h
@@ -100,14 +100,20 @@ private:
   /**
    * We have created our native. This does not mean there is one.
    * This can never go back to false.
    * We need it because checking whether we need a native object cost time.
    */
   bool mNativeInited;  
 };
 
+#if defined(__OBJC__)
+  void FireNativeEvent(mozAccessible* aNativeAcc, uint32_t aEventType);
+#else
+  void FireNativeEvent(id aNativeAcc, uint32_t aEventType);
+#endif
+
 Class GetTypeFromRole(roles::Role aRole);
 
 } // namespace a11y
 } // namespace mozilla
 
 #endif
--- a/accessible/mac/AccessibleWrap.mm
+++ b/accessible/mac/AccessibleWrap.mm
@@ -107,28 +107,17 @@ AccessibleWrap::HandleAccEvent(AccEvent*
   Accessible* accessible = aEvent->GetAccessible();
   NS_ENSURE_STATE(accessible);
 
   mozAccessible *nativeAcc = nil;
   accessible->GetNativeInterface((void**)&nativeAcc);
   if (!nativeAcc)
     return NS_ERROR_FAILURE;
 
-  switch (eventType) {
-    case nsIAccessibleEvent::EVENT_FOCUS:
-      [nativeAcc didReceiveFocus];
-      break;
-    case nsIAccessibleEvent::EVENT_VALUE_CHANGE:
-      [nativeAcc valueDidChange];
-      break;
-    case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED:
-    case nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED:
-      [nativeAcc selectedTextDidChange];
-      break;
-  }
+  FireNativeEvent(nativeAcc, eventType);
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 void
 AccessibleWrap::InvalidateChildren()
@@ -229,16 +218,37 @@ AccessibleWrap::AncestorIsFlat()
       return true;
 
     parent = parent->Parent();
   }
   // no parent was flat
   return false;
 }
 
+void
+a11y::FireNativeEvent(mozAccessible* aNativeAcc, uint32_t aEventType)
+{
+  NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
+
+  switch (aEventType) {
+    case nsIAccessibleEvent::EVENT_FOCUS:
+      [aNativeAcc didReceiveFocus];
+      break;
+    case nsIAccessibleEvent::EVENT_VALUE_CHANGE:
+      [aNativeAcc valueDidChange];
+      break;
+    case nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED:
+    case nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED:
+      [aNativeAcc selectedTextDidChange];
+      break;
+  }
+
+  NS_OBJC_END_TRY_ABORT_BLOCK;
+}
+
 Class
 a11y::GetTypeFromRole(roles::Role aRole) 
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
 
   switch (aRole) {
     case roles::COMBOBOX:
     case roles::PUSHBUTTON:
--- a/accessible/mac/Platform.mm
+++ b/accessible/mac/Platform.mm
@@ -50,31 +50,49 @@ ProxyDestroyed(ProxyAccessible* aProxy)
   mozAccessible* wrapper =
     reinterpret_cast<mozAccessible*>(aProxy->GetWrapper());
   [wrapper expire];
   [wrapper release];
   aProxy->SetWrapper(0);
 }
 
 void
-ProxyEvent(ProxyAccessible*, uint32_t)
+ProxyEvent(ProxyAccessible* aProxy, uint32_t aEventType)
 {
+  // ignore everything but focus-changed, value-changed, caret and selection
+  // events for now.
+  if (aEventType != nsIAccessibleEvent::EVENT_FOCUS &&
+      aEventType != nsIAccessibleEvent::EVENT_VALUE_CHANGE &&
+      aEventType != nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED &&
+      aEventType != nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED)
+    return;
+
+  mozAccessible* wrapper =
+    reinterpret_cast<mozAccessible*>(aProxy->GetWrapper());
+  if (wrapper)
+    FireNativeEvent(wrapper, aEventType);
 }
 
 void
-ProxyStateChangeEvent(ProxyAccessible*, uint64_t, bool)
+ProxyStateChangeEvent(ProxyAccessible* aProxy, uint64_t, bool)
 {
+  // mac doesn't care about state change events
 }
 
 void
 ProxyCaretMoveEvent(ProxyAccessible* aTarget, int32_t aOffset)
 {
-}
+  mozAccessible* wrapper =
+    reinterpret_cast<mozAccessible*>(aTarget->GetWrapper());
+  if (wrapper)
+    [wrapper selectedTextDidChange];
 }
-}
+
+} // namespace a11y
+} // namespace mozilla
 
 @interface GeckoNSApplication(a11y)
 -(void)accessibilitySetValue:(id)value forAttribute:(NSString*)attribute;
 @end
 
 @implementation GeckoNSApplication(a11y)
 
 -(void)accessibilitySetValue:(id)value forAttribute:(NSString*)attribute