Bug 1624729 - Notify observer service of mac accessibility events. r=morgan,yzen

Differential Revision: https://phabricator.services.mozilla.com/D68127

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Eitan Isaacson 2020-03-27 17:11:44 +00:00
Родитель 0ade2fd945
Коммит 14ca656c7f
4 изменённых файлов: 31 добавлений и 0 удалений

Просмотреть файл

@ -10,6 +10,7 @@
#include "Accessible-inl.h"
#include "nsAccUtils.h"
#include "xpcAccessibleMacInterface.h"
#include "nsIPersistentProperties2.h"
#include "DocAccessibleParent.h"
#include "Relation.h"
@ -1176,6 +1177,9 @@ struct RoleDescrComparator {
}
- (void)postNotification:(NSString*)notification {
// This sends events via nsIObserverService to be consumed by our mochitests.
xpcAccessibleMacInterface::FireEvent(self, notification);
if (gfxPlatform::IsHeadless()) {
// Using a headless toolkit for tests and whatnot, posting accessibility
// notification won't work.

Просмотреть файл

@ -52,6 +52,9 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
UNIFIED_SOURCES += [
'xpcAccessibleMacInterface.mm'
]
EXPORTS += [
'xpcAccessibleMacInterface.h',
]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
LOCAL_INCLUDES += [
'/accessible/android',

Просмотреть файл

@ -29,6 +29,11 @@ class xpcAccessibleMacInterface : public nsIAccessibleMacInterface {
NS_DECL_ISUPPORTS
NS_DECL_NSIACCESSIBLEMACINTERFACE
// This sends notifications via nsIObserverService to be consumed by our
// mochitests. aNativeObj is a NSAccessibility protocol object,
// and aNotification is a NSString.
static void FireEvent(id aNativeObj, id aNotification);
protected:
virtual ~xpcAccessibleMacInterface();

Просмотреть файл

@ -367,3 +367,22 @@ nsresult xpcAccessibleMacInterface::NSObjectToJsValue(id aObj, JSContext* aCx,
return NS_OK;
}
void xpcAccessibleMacInterface::FireEvent(id aNativeObj, id aNotification) {
if (nsCOMPtr<nsIObserverService> obsService = services::GetObserverService()) {
nsCOMPtr<nsISimpleEnumerator> observers;
// Get all observers for the mac event topic.
obsService->EnumerateObservers(NS_ACCESSIBLE_MAC_EVENT_TOPIC, getter_AddRefs(observers));
if (observers) {
bool hasObservers = false;
observers->HasMoreElements(&hasObservers);
// If we have observers, notify them.
if (hasObservers) {
nsCOMPtr<nsIAccessibleMacInterface> xpcIface = new xpcAccessibleMacInterface(aNativeObj);
nsAutoString notificationStr;
nsCocoaUtils::GetStringForNSString(aNotification, notificationStr);
obsService->NotifyObservers(xpcIface, NS_ACCESSIBLE_MAC_EVENT_TOPIC, notificationStr.get());
}
}
}
}