Bug 1525980 - Make announcement events work over IPC. r=Jamie

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Eitan Isaacson 2019-02-14 17:42:47 +00:00
parent baa769abf9
commit 773b9d611a
12 changed files with 108 additions and 7 deletions

View File

@ -914,6 +914,14 @@ nsresult Accessible::HandleAccEvent(AccEvent* aEvent) {
scrollingEvent->MaxScrollY());
break;
}
#if !defined(XP_WIN)
case nsIAccessibleEvent::EVENT_ANNOUNCEMENT: {
AccAnnouncementEvent* announcementEvent = downcast_accEvent(aEvent);
ipcDoc->SendAnnouncementEvent(id, announcementEvent->Announcement(),
announcementEvent->Priority());
break;
}
#endif
default:
ipcDoc->SendEvent(id, aEvent->GetEventType());
}

View File

@ -431,6 +431,35 @@ mozilla::ipc::IPCResult DocAccessibleParent::RecvScrollingEvent(
return IPC_OK();
}
#if !defined(XP_WIN)
mozilla::ipc::IPCResult DocAccessibleParent::RecvAnnouncementEvent(
const uint64_t& aID, const nsString& aAnnouncement,
const uint16_t& aPriority) {
ProxyAccessible* target = GetAccessible(aID);
if (!target) {
NS_ERROR("no proxy for event!");
return IPC_OK();
}
// XXX: A future patch will add platform support for this event type.
// Right now, we just need to support XPC for testing.
if (!nsCoreUtils::AccEventObserversExist()) {
return IPC_OK();
}
xpcAccessibleGeneric* xpcAcc = GetXPCAccessible(target);
xpcAccessibleDocument* doc = GetAccService()->GetXPCDocument(this);
RefPtr<xpcAccAnnouncementEvent> event = new xpcAccAnnouncementEvent(
nsIAccessibleEvent::EVENT_ANNOUNCEMENT, xpcAcc, doc, nullptr, false,
aAnnouncement, aPriority);
nsCoreUtils::DispatchAccEvent(std::move(event));
return IPC_OK();
}
#endif
mozilla::ipc::IPCResult DocAccessibleParent::RecvRoleChangedEvent(
const a11y::role& aRole) {
if (mShutdown) {

View File

@ -117,6 +117,12 @@ class DocAccessibleParent : public ProxyAccessible,
const uint32_t& aScrollY, const uint32_t& aMaxScrollX,
const uint32_t& aMaxScrollY) override;
#if !defined(XP_WIN)
virtual mozilla::ipc::IPCResult RecvAnnouncementEvent(
const uint64_t& aID, const nsString& aAnnouncement,
const uint16_t& aPriority) override;
#endif
mozilla::ipc::IPCResult RecvRoleChangedEvent(const a11y::role& aRole) final;
virtual mozilla::ipc::IPCResult RecvBindChildDoc(

View File

@ -68,6 +68,8 @@ int32_t GetLevelInternal();
void ScrollTo(uint32_t aScrollType);
void ScrollToPoint(uint32_t aScrollType, int32_t aX, int32_t aY);
void Announce(const nsString& aAnnouncement, uint16_t aPriority);
int32_t CaretLineNumber();
int32_t CaretOffset();
void SetCaretOffset(int32_t aOffset);

View File

@ -263,6 +263,17 @@ mozilla::ipc::IPCResult DocAccessibleChild::RecvScrollToPoint(
return IPC_OK();
}
mozilla::ipc::IPCResult DocAccessibleChild::RecvAnnounce(
const uint64_t& aID, const nsString& aAnnouncement,
const uint16_t& aPriority) {
Accessible* acc = IdToAccessible(aID);
if (acc) {
acc->Announce(aAnnouncement, aPriority);
}
return IPC_OK();
}
mozilla::ipc::IPCResult DocAccessibleChild::RecvCaretLineNumber(
const uint64_t& aID, int32_t* aLineNumber) {
HyperTextAccessible* acc = IdToHyperTextAccessible(aID);

View File

@ -93,6 +93,10 @@ class DocAccessibleChild : public DocAccessibleChildBase {
const int32_t& aX,
const int32_t& aY) override;
virtual mozilla::ipc::IPCResult RecvAnnounce(
const uint64_t& aID, const nsString& aAnnouncement,
const uint16_t& aPriority) override;
virtual mozilla::ipc::IPCResult RecvCaretLineNumber(
const uint64_t& aID, int32_t* aLineNumber) override;
virtual mozilla::ipc::IPCResult RecvCaretOffset(const uint64_t& aID,

View File

@ -97,6 +97,9 @@ parent:
async ScrollingEvent(uint64_t aID, uint64_t aType,
uint32_t aScrollX, uint32_t aScrollY,
uint32_t aMaxScrollX, uint32_t aMaxScrollY);
async AnnouncementEvent(uint64_t aID,
nsString aAnnouncement,
uint16_t aPriority);
/*
* Tell the parent document to bind the existing document as a new child
@ -134,6 +137,7 @@ child:
async ScrollTo(uint64_t aID, uint32_t aScrollType);
async ScrollToPoint(uint64_t aID, uint32_t aScrollType, int32_t aX,
int32_t aY);
async Announce(uint64_t aID, nsString aAnnouncement, uint16_t aPriority);
// AccessibleText

View File

@ -126,6 +126,11 @@ void ProxyAccessible::ScrollToPoint(uint32_t aScrollType, int32_t aX,
Unused << mDoc->SendScrollToPoint(mID, aScrollType, aX, aY);
}
void ProxyAccessible::Announce(const nsString& aAnnouncement,
uint16_t aPriority) {
Unused << mDoc->SendAnnounce(mID, aAnnouncement, aPriority);
}
int32_t ProxyAccessible::CaretLineNumber() {
int32_t line = -1;
Unused << mDoc->SendCaretOffset(mID, &line);

View File

@ -23,6 +23,8 @@ skip-if = (e10s && os == 'win') || (os == 'mac' && debug) # Bug 1338034, leaks #
[browser_caching_value.js]
# Events tests
[browser_events_announcement.js]
skip-if = e10s && os == 'win' # Bug 1288839
[browser_events_caretmove.js]
[browser_events_hide.js]
[browser_events_show.js]

View File

@ -0,0 +1,23 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
addAccessibleTask(`<p id="p">abc</p>`,
async function(browser, accDoc) {
let acc = findAccessibleChildByID(accDoc, "p");
let onAnnounce = waitForEvent(EVENT_ANNOUNCEMENT, acc);
acc.announce("please", nsIAccessibleAnnouncementEvent.POLITE);
let evt = await onAnnounce;
evt.QueryInterface(nsIAccessibleAnnouncementEvent);
is(evt.announcement, "please", "announcement matches.");
is(evt.priority, nsIAccessibleAnnouncementEvent.POLITE, "priority matches");
onAnnounce = waitForEvent(EVENT_ANNOUNCEMENT, acc);
acc.announce("do it", nsIAccessibleAnnouncementEvent.ASSERTIVE);
evt = await onAnnounce;
evt.QueryInterface(nsIAccessibleAnnouncementEvent);
is(evt.announcement, "do it", "announcement matches.");
is(evt.priority, nsIAccessibleAnnouncementEvent.ASSERTIVE, "priority matches");
});

View File

@ -9,15 +9,16 @@
/* import-globals-from shared-head.js */
/* import-globals-from ../mochitest/common.js */
/* exported EVENT_REORDER, EVENT_SCROLLING, EVENT_SCROLLING_END, EVENT_SHOW,
EVENT_TEXT_INSERTED, EVENT_TEXT_REMOVED,
EVENT_DOCUMENT_LOAD_COMPLETE, EVENT_HIDE, EVENT_TEXT_CARET_MOVED,
EVENT_DESCRIPTION_CHANGE, EVENT_NAME_CHANGE, EVENT_STATE_CHANGE,
EVENT_VALUE_CHANGE, EVENT_TEXT_VALUE_CHANGE, EVENT_FOCUS,
EVENT_DOCUMENT_RELOAD, EVENT_VIRTUALCURSOR_CHANGED,
/* exported EVENT_ANNOUNCEMENT, EVENT_REORDER, EVENT_SCROLLING,
EVENT_SCROLLING_END, EVENT_SHOW, EVENT_TEXT_INSERTED,
EVENT_TEXT_REMOVED, EVENT_DOCUMENT_LOAD_COMPLETE, EVENT_HIDE,
EVENT_TEXT_CARET_MOVED, EVENT_DESCRIPTION_CHANGE, EVENT_NAME_CHANGE,
EVENT_STATE_CHANGE, EVENT_VALUE_CHANGE, EVENT_TEXT_VALUE_CHANGE,
EVENT_FOCUS, EVENT_DOCUMENT_RELOAD, EVENT_VIRTUALCURSOR_CHANGED,
UnexpectedEvents, contentSpawnMutation, waitForEvent, waitForEvents,
waitForOrderedEvents */
const EVENT_ANNOUNCEMENT = nsIAccessibleEvent.EVENT_ANNOUNCEMENT;
const EVENT_DOCUMENT_LOAD_COMPLETE = nsIAccessibleEvent.EVENT_DOCUMENT_LOAD_COMPLETE;
const EVENT_HIDE = nsIAccessibleEvent.EVENT_HIDE;
const EVENT_REORDER = nsIAccessibleEvent.EVENT_REORDER;

View File

@ -760,10 +760,16 @@ xpcAccessible::ScrollToPoint(uint32_t aCoordinateType, int32_t aX, int32_t aY) {
NS_IMETHODIMP
xpcAccessible::Announce(const nsAString& aAnnouncement, uint16_t aPriority) {
if (IntlGeneric().IsProxy()) {
if (ProxyAccessible* proxy = IntlGeneric().AsProxy()) {
#if defined(XP_WIN)
return NS_ERROR_NOT_IMPLEMENTED;
#else
nsString announcement(aAnnouncement);
proxy->Announce(announcement, aPriority);
#endif
} else {
Intl()->Announce(aAnnouncement, aPriority);
}
return NS_OK;
}