Files
palemoon27/accessible/generic/RootAccessible.cpp
T
roytam1 8a0a002cf2 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1148708: Add missing 'override' annotations in DocAccessibleChild.h. rs=ehsan (d606358545)
- Bug 1210408 - make nsMaiInterfaceAction work with proxies, r=tbsaunde (f7c819c6ae)
- Bug 1210407 - teach nsMaiInterfaceTable to use proxies, r=tbsaunde (4ca4f10b5f)
- bug 1185157 make sure we don't send an event to a destroyed ipc document r=billm (23acf53f75)
- bug 1214864 - make SetCarretOffset() async r=davidb (e3079e9b2d)
- missing of Bug 1139972 - IPC Proxy for charAt, r=tbsaunde (e9593ed752)
- bug 1191598 - Pass MOZ_CURRENT_PROJECT in environment when running post-build automation steps for universal mac builds. r=gps (fc342c6ced)
- Bug 1164596 - Add mach android-emulator command; r=ahal (afeb9b27d1)
- Bug 1223149 - Add basic usage documentation for mach build; r=glandium (bfb802d175)
- Bug 1182301 - Improve 'mach build' notifications. r=gps (2c65a122d1)
- Bug 1184696 - Add clobber targets to |mach clobber|; Ability to clobber compiled python files, r=gps (35d8be292e)
- Bug 1117958 - Allow any debugging options to the run or gtest mach subcommands to automatically enable debugging. r=gps (32f986af4b)
- Bug 1180081 - Properly rebuild gtest/libxul before running gtests. r=gps (80db9a3d49)
- Bug 1171647, part 1 - Define a new function to convert the mode to a string. r=njn (61ad16f5ba)
- Bug 1171647, part 2 - Remove redundant assertion for dark matter mode. r=njn (b5ac9519f3)
- Bug 1058178, part 1 - Implement DMD heap scanning mode. r=njn (60e1079536)
- Bug 1058178, part 2 - Implement address clamping analysis for DMD scan logs. r=njn (45c0326b93)
- Bug 1102388 - Fix DMD static constructor ordering dependency. r=mccr8 (59b87897a1)
- Bug 1128705 - Don't redefine PAGE_SIZE in DMD if it's already defined. r=erahm (49216348ee)
- Bug 1179042 - Add a script for analyzing memory blocks using a heap scan DMD log. r=njn DONTBUILD (1c08d2d66e)
- Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat (1c999d139b)
- Bug 1158772 - fix non-idiomatic memset call in nsDeque.cpp; r=erahm (de6b555245)
- Bug 1199400 - Part 1: Use CheckedInt when growing nsDeque capacity. r=froydnj (dfdf6814a3)
- Bug 1199400 - Part 0: Remove unused nsDequeIterator. r=froydnj (38d69d7f47)
- Bug 1199400 - Part 2: Add tests for possible nsDeque corner cases. r=froydnj (931baff195)
- Bug 1201997 - Part 1 - Converted compiled test to gtest for nsDeque class. Added tests to test untested methods. r=froydn (e893916651)
- Bug 1201997 - Part 2 - Removing unused methods from the nsDeque class. r=froydn (41595a90ac)
- Bug 1201997 - Part 3 - Make internally used methods private. r=froydn (8cd3afd96f)
- Bug 1201997 - Part 4 - Change size and offset variables to size_t.r=froydn (73eabc8d60)
- Bug 1215140 P1 Add an nsIConsoleReportCollector interface to support navigation channel logging. r=bz (8a41535e2b)
- Bug 1215140 P2 Make HttpBaseChannel implement nsIConsoleReportCollector. r=bz (75fca301f2)
- Bug 1197679 - If nsUnknownDecoder is involved in e10s DivertToParent can break. r=jduell (5d94a12504)
- Bug 1178991 - smartptr for http converter r=hurley (8e7fbc8443)
- bug 366559 - patch 2, fix nsHTTPCompressConv indentation r=bagder (ba762da587)
- bug 366559 - patch 3, fix nsHTTPCompressConv bracing style r=bagder (54195ab451)
- bits of  bug 366559 - patch 7, content-encoding brotli for http (f0b4051022)
- Bug 1205112 - Make PushEvent.data nullable. r=mt,smaug (775db32856)
- Bug 1193414 - SharedWorkers thread should be kept alive also when the SharedWorker object is CCed, r=khuey (b77ea8125c)
- Bug 1206520: Add about:config prefs to enable throwing on asm.js validation failures; r=bz (c42126665d)
- Bug 1193414 - Telemetry for SharedWorker spawning. r=bkelly (77984b7bcc)
- Bug 1205676 - Enable WPT service-worker/unregister-then-register-new-script.https.html in e10s, r=nsm (ec24939cf6)
- Bug 1193133 - Throw when calling postMessage from a Service Worker dom object with no global. r=bkelly (526dcacfab)
- Bug 1181871 P1 Only enforce Cache Context shared data destruction on target thread after init. r=ehsan (cdbf3ed3a8)
- Bug 1181871 P2 Fix ServiceWorkerManager usage of stack-based ErrorResult. r=ehsan (c449195d90)
- minor cleanup and missing bit of 1198230 (02f459db05)
- Bug 1143717 - Implement the ServiceWorkerMessageEvent interface. r=baku (027b3465f2)
- fix misspatch (708eee4e84)
- Bug 1188545 - Disentangle service workers from shared workers and refactor event dispatching code into a separate class. r=nsm,mrbkap (fb5b5341c9)
- Bug 1205228 - Change PackagedAppVerifier to notify the verification result asynchronously. r=valentin. (9edda0fa00)
- Bug 1178518 - Packaged App Utils. r=valentin (f60f3b7a93)
- Bug 1213150 - Part 1: Add a nsContentUtils::IsNonSubresourceRequest helper; r=jdm (b509cc3cc9)
- Bug 1213150 - Part 2: Rework ShouldPrepareForIntercept() in terms of subresource requests; r=jdm (2e92fe8780)
- Bug 1213150 - Part 3: Remove nsIInterceptedChannel.isNavigation; r=jdm (becf1cc12f)
- Bug 1213150 follow-up: fix build bustage (8d73d6ca73)
- Bug 1198394 - Part 1: Allow interception of HSTS upgraded connections in non-e10s mode; r=mcmanus (f504c5be08)
- Bug 1198394 - Part 2: Add a test for interception of HSTS upgraded connections; r=jdm (054e984eef)
- Bug 1187011 - Don't allow response body with null body status. r=bkelly (b1860741d1)
- missing bit of 1140788 (29d319712e)
- Bug 1213436 - Reject core dumps with node IDs that don't fit in an IEEE 754 double; r=sfink (3c1f6fdda0)
- Bug 1211006 - Add Debugger.Source.prototype.canonicalId; r=ejpbruel (eef7b79fce)
- Bug 1199218 - Implement JS::ubi::Node::size for js::LazyScript referents; r=sfink (098a48d240)
- Bug 1220031 - Add JS::ubi::Node::scriptFilename; r=sfink (6b824ae680)
- Bug 1143575. Remove unused MediaQueue::Empty. r=cpearce (de737f3433)
- Bug 1209933 - Make sure all parent runtime pointers are the topmost parent, r=billm. (fe824d967d)
- Bug 1197012 - Fix ThrowTypeError in Notification. r=mccr8 (0b1a097526)
- Bug 1197893 - Check the number of arguments for ThrowTypeError() and ThrowRangeError() at compile time. r=peterv (d98c7d78a0)
- Bug 1142083 - Add test for IDN Unicode domain redirect. r=mcmanus (0c8961fe17)
- Bug 1187159 - Add mochitest for loading packaged apps (iframe+fetch+mozapp) r=jduell (ce90ea561b)
- Bug 1186290 - Notify TabParent to switch process when loading a signed package. r=honzab, r=kanru. (c58a14554a)
- fix (15e2df75eb)
- Bug 1206124 P1 Fix "same-origin" CORS credentials in FetchDriver. r=ehsan (fae1bb6ab3)
- Bug 1206124 P2 Test fetch() with credentials and redirects. r=ehsan (ffc6254112)
- Bug 1211751: Remove nsIChannelEventSink-forwarding from EventSource and FetchDriver. It's never needed. r=smaug (adafe5737a)
- Bug 1212433 Fail fetch() calls that require preflight and also redirect. r=sicking a=abillings (c0d6742b9e)
- Bug 1193128 - Fix base64 decoding when fetching data URIs. r=baku (80bafa291a)
- Bug 1195167 part 1: Let necko handle all protocols. r=bkelly (bb932b0ada)
- Bug 1195167 part 2: Remove redundant aCORSFlag argument and instead use mCORSFlagEverSet. r=bkelly (beadafcad0)
- Bug 1195167 part 3: Remove more scheme-specific handling from FetchDriver. r=bkelly (d00b38db9e)
- Bug 1195167 part 4: Remove FetchDriver::BasicFetch since it is empty. r=bkelly (c5ed097267)
- Bug 1210413 P2 Test CORS credentials on cross-origin redirects. r=sicking a=dveditz (b4eeb8aac0)
- Bug 1210413 P1 Propagate new channel load flags from child to parent on redirect. r=jduell a=dveditz (8b329af4fa)
- Bug 1195167 part 5: Make FetchDriver use AsyncOpen2. r=bkelly (cc217c4cc1)
- Bug 1195167 part 6: Some code simplification since necko handles fetch recursion. r=bkelly (f3b6da2262)
- Bug 1195167: Followup to fix test which I forgot to change (81e7439a2e)
- Bug 1215746: Remove RequestMode::Cors_with_forced_preflight. r=bkelly (0336e812b6)
- Bug 1211000: Move CORS preflight logic from nsCORSListenerProxy to nsCORSPreflightListener. r=ehsan (bf2f71cf22)
- missing bit of Bug 1211443 - Drop scheduled update if decoder initialization isn't done yet. r=jya (f6bc074e33)
- Bug 1182571: Fix nsILoadInfo->GetContentPolicyType API to be less ambigious. Audit and fix all users of it. r=ckerschb (5af6fa7442)
- fix (e40c8e7625)
- Bug 1173811 - Part 1: Propagate the response URL to intercepted channels when necessary (non-e10s). r=mayhemer,bkelly (26f4f13c28)
- Bug 1173811 - Part 2: Propagate the response URL to intercepted channels when necessary (e10s). r=mayhemer,bkelly (a603fe1df2)
- Bug 1154309 - Add New Resource Timing Fields r=bz,hurley (1d14eb6bef)
- Bug 1175685 - add OriginAttribute to LoadInfo. r=jonas, r=ckerschb, r=michal (a5d18bb637)
- Bug 1175685 - add OriginAttribute to LoadInfo. r=jonas, r=ckerschb, r=michal (fb07d2c8aa)
- Bug 1212904 P1 Add a LoadTainting enumeration. r=jduell (a1db8a3e99)
- Bug 1212904 P2 Add LoadTainting information to nsILoadInfo. r=jduell (2482e5e334)
- Bug 1221151 - use [infallible] in nsILoadInfo.idl instead of manual %{C++ blocks; r=jduell (aae73129b6)
- Bug 1045891 - CSP 2 child-src implementation r=ckerschb (792920aeb9)
- Bug 1219931 - CSP: Don't allow removing a policy (r=sicking) (9daaab4186)
- Bug 1208661 - Dump client-side layer textures. r=BenWa (1f2d17d515)
2022-10-17 11:08:37 +08:00

719 lines
22 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "RootAccessible.h"
#include "mozilla/ArrayUtils.h"
#define CreateEvent CreateEventA
#include "nsIDOMDocument.h"
#include "Accessible-inl.h"
#include "DocAccessible-inl.h"
#include "nsAccessibilityService.h"
#include "nsAccUtils.h"
#include "nsCoreUtils.h"
#include "nsEventShell.h"
#include "Relation.h"
#include "Role.h"
#include "States.h"
#ifdef MOZ_XUL
#include "XULTreeAccessible.h"
#endif
#include "mozilla/dom/Element.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeOwner.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/EventTarget.h"
#include "nsIDOMCustomEvent.h"
#include "nsIDOMXULMultSelectCntrlEl.h"
#include "nsIDocument.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIPropertyBag2.h"
#include "nsIServiceManager.h"
#include "nsPIDOMWindow.h"
#include "nsIWebBrowserChrome.h"
#include "nsReadableUtils.h"
#include "nsFocusManager.h"
#ifdef MOZ_XUL
#include "nsIXULDocument.h"
#include "nsIXULWindow.h"
#endif
using namespace mozilla;
using namespace mozilla::a11y;
using namespace mozilla::dom;
////////////////////////////////////////////////////////////////////////////////
// nsISupports
NS_IMPL_ISUPPORTS_INHERITED0(RootAccessible, DocAccessible)
////////////////////////////////////////////////////////////////////////////////
// Constructor/destructor
RootAccessible::
RootAccessible(nsIDocument* aDocument, nsIContent* aRootContent,
nsIPresShell* aPresShell) :
DocAccessibleWrap(aDocument, aRootContent, aPresShell)
{
mType = eRootType;
}
RootAccessible::~RootAccessible()
{
}
////////////////////////////////////////////////////////////////////////////////
// Accessible
ENameValueFlag
RootAccessible::Name(nsString& aName)
{
aName.Truncate();
if (mRoleMapEntry) {
Accessible::Name(aName);
if (!aName.IsEmpty())
return eNameOK;
}
mDocumentNode->GetTitle(aName);
return eNameOK;
}
role
RootAccessible::NativeRole()
{
// If it's a <dialog> or <wizard>, use roles::DIALOG instead
dom::Element* rootElm = mDocumentNode->GetRootElement();
if (rootElm && rootElm->IsAnyOfXULElements(nsGkAtoms::dialog,
nsGkAtoms::wizard))
return roles::DIALOG;
return DocAccessibleWrap::NativeRole();
}
// RootAccessible protected member
#ifdef MOZ_XUL
uint32_t
RootAccessible::GetChromeFlags()
{
// Return the flag set for the top level window as defined
// by nsIWebBrowserChrome::CHROME_WINDOW_[FLAGNAME]
// Not simple: nsIXULWindow is not just a QI from nsIDOMWindow
nsCOMPtr<nsIDocShell> docShell = nsCoreUtils::GetDocShellFor(mDocumentNode);
NS_ENSURE_TRUE(docShell, 0);
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
docShell->GetTreeOwner(getter_AddRefs(treeOwner));
NS_ENSURE_TRUE(treeOwner, 0);
nsCOMPtr<nsIXULWindow> xulWin(do_GetInterface(treeOwner));
if (!xulWin) {
return 0;
}
uint32_t chromeFlags;
xulWin->GetChromeFlags(&chromeFlags);
return chromeFlags;
}
#endif
uint64_t
RootAccessible::NativeState()
{
uint64_t state = DocAccessibleWrap::NativeState();
if (state & states::DEFUNCT)
return state;
#ifdef MOZ_XUL
uint32_t chromeFlags = GetChromeFlags();
if (chromeFlags & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE)
state |= states::SIZEABLE;
// If it has a titlebar it's movable
// XXX unless it's minimized or maximized, but not sure
// how to detect that
if (chromeFlags & nsIWebBrowserChrome::CHROME_TITLEBAR)
state |= states::MOVEABLE;
if (chromeFlags & nsIWebBrowserChrome::CHROME_MODAL)
state |= states::MODAL;
#endif
nsFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm && fm->GetActiveWindow() == mDocumentNode->GetWindow())
state |= states::ACTIVE;
return state;
}
const char* const kEventTypes[] = {
#ifdef DEBUG_DRAGDROPSTART
// Capture mouse over events and fire fake DRAGDROPSTART event to simplify
// debugging a11y objects with event viewers.
"mouseover",
#endif
// Fired when list or tree selection changes.
"select",
// Fired when value changes immediately, wether or not focused changed.
"ValueChange",
"AlertActive",
"TreeRowCountChanged",
"TreeInvalidated",
// add ourself as a OpenStateChange listener (custom event fired in tree.xml)
"OpenStateChange",
// add ourself as a CheckboxStateChange listener (custom event fired in HTMLInputElement.cpp)
"CheckboxStateChange",
// add ourself as a RadioStateChange Listener ( custom event fired in in HTMLInputElement.cpp & radio.xml)
"RadioStateChange",
"popupshown",
"popuphiding",
"DOMMenuInactive",
"DOMMenuItemActive",
"DOMMenuItemInactive",
"DOMMenuBarActive",
"DOMMenuBarInactive"
};
nsresult
RootAccessible::AddEventListeners()
{
// EventTarget interface allows to register event listeners to
// receive untrusted events (synthetic events generated by untrusted code).
// For example, XBL bindings implementations for elements that are hosted in
// non chrome document fire untrusted events.
nsCOMPtr<EventTarget> nstarget = mDocumentNode;
if (nstarget) {
for (const char* const* e = kEventTypes,
* const* e_end = ArrayEnd(kEventTypes);
e < e_end; ++e) {
nsresult rv = nstarget->AddEventListener(NS_ConvertASCIItoUTF16(*e),
this, true, true, 2);
NS_ENSURE_SUCCESS(rv, rv);
}
}
return DocAccessible::AddEventListeners();
}
nsresult
RootAccessible::RemoveEventListeners()
{
nsCOMPtr<EventTarget> target = mDocumentNode;
if (target) {
for (const char* const* e = kEventTypes,
* const* e_end = ArrayEnd(kEventTypes);
e < e_end; ++e) {
nsresult rv = target->RemoveEventListener(NS_ConvertASCIItoUTF16(*e), this, true);
NS_ENSURE_SUCCESS(rv, rv);
}
}
// Do this before removing clearing caret accessible, so that it can use
// shutdown the caret accessible's selection listener
DocAccessible::RemoveEventListeners();
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// public
void
RootAccessible::DocumentActivated(DocAccessible* aDocument)
{
}
////////////////////////////////////////////////////////////////////////////////
// nsIDOMEventListener
NS_IMETHODIMP
RootAccessible::HandleEvent(nsIDOMEvent* aDOMEvent)
{
MOZ_ASSERT(aDOMEvent);
Event* event = aDOMEvent->InternalDOMEvent();
nsCOMPtr<nsINode> origTargetNode = do_QueryInterface(event->GetOriginalTarget());
if (!origTargetNode)
return NS_OK;
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eDOMEvents)) {
nsAutoString eventType;
aDOMEvent->GetType(eventType);
logging::DOMEvent("handled", origTargetNode, eventType);
}
#endif
DocAccessible* document =
GetAccService()->GetDocAccessible(origTargetNode->OwnerDoc());
if (document) {
// Root accessible exists longer than any of its descendant documents so
// that we are guaranteed notification is processed before root accessible
// is destroyed.
document->HandleNotification<RootAccessible, nsIDOMEvent>
(this, &RootAccessible::ProcessDOMEvent, aDOMEvent);
}
return NS_OK;
}
// RootAccessible protected
void
RootAccessible::ProcessDOMEvent(nsIDOMEvent* aDOMEvent)
{
MOZ_ASSERT(aDOMEvent);
Event* event = aDOMEvent->InternalDOMEvent();
nsCOMPtr<nsINode> origTargetNode = do_QueryInterface(event->GetOriginalTarget());
nsAutoString eventType;
aDOMEvent->GetType(eventType);
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eDOMEvents))
logging::DOMEvent("processed", origTargetNode, eventType);
#endif
if (eventType.EqualsLiteral("popuphiding")) {
HandlePopupHidingEvent(origTargetNode);
return;
}
DocAccessible* targetDocument = GetAccService()->
GetDocAccessible(origTargetNode->OwnerDoc());
NS_ASSERTION(targetDocument, "No document while accessible is in document?!");
Accessible* accessible =
targetDocument->GetAccessibleOrContainer(origTargetNode);
if (!accessible)
return;
#ifdef MOZ_XUL
XULTreeAccessible* treeAcc = accessible->AsXULTree();
if (treeAcc) {
if (eventType.EqualsLiteral("TreeRowCountChanged")) {
HandleTreeRowCountChangedEvent(aDOMEvent, treeAcc);
return;
}
if (eventType.EqualsLiteral("TreeInvalidated")) {
HandleTreeInvalidatedEvent(aDOMEvent, treeAcc);
return;
}
}
#endif
if (eventType.EqualsLiteral("RadioStateChange")) {
uint64_t state = accessible->State();
bool isEnabled = (state & (states::CHECKED | states::SELECTED)) != 0;
if (accessible->NeedsDOMUIEvent()) {
RefPtr<AccEvent> accEvent =
new AccStateChangeEvent(accessible, states::CHECKED, isEnabled);
nsEventShell::FireEvent(accEvent);
}
if (isEnabled) {
FocusMgr()->ActiveItemChanged(accessible);
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("RadioStateChange", accessible);
#endif
}
return;
}
if (eventType.EqualsLiteral("CheckboxStateChange")) {
if (accessible->NeedsDOMUIEvent()) {
uint64_t state = accessible->State();
bool isEnabled = !!(state & states::CHECKED);
RefPtr<AccEvent> accEvent =
new AccStateChangeEvent(accessible, states::CHECKED, isEnabled);
nsEventShell::FireEvent(accEvent);
}
return;
}
Accessible* treeItemAcc = nullptr;
#ifdef MOZ_XUL
// If it's a tree element, need the currently selected item.
if (treeAcc) {
treeItemAcc = accessible->CurrentItem();
if (treeItemAcc)
accessible = treeItemAcc;
}
if (treeItemAcc && eventType.EqualsLiteral("OpenStateChange")) {
uint64_t state = accessible->State();
bool isEnabled = (state & states::EXPANDED) != 0;
RefPtr<AccEvent> accEvent =
new AccStateChangeEvent(accessible, states::EXPANDED, isEnabled);
nsEventShell::FireEvent(accEvent);
return;
}
nsINode* targetNode = accessible->GetNode();
if (treeItemAcc && eventType.EqualsLiteral("select")) {
// XXX: We shouldn't be based on DOM select event which doesn't provide us
// any context info. We should integrate into nsTreeSelection instead.
// If multiselect tree, we should fire selectionadd or selection removed
if (FocusMgr()->HasDOMFocus(targetNode)) {
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSel =
do_QueryInterface(targetNode);
nsAutoString selType;
multiSel->GetSelType(selType);
if (selType.IsEmpty() || !selType.EqualsLiteral("single")) {
// XXX: We need to fire EVENT_SELECTION_ADD and EVENT_SELECTION_REMOVE
// for each tree item. Perhaps each tree item will need to cache its
// selection state and fire an event after a DOM "select" event when
// that state changes. XULTreeAccessible::UpdateTreeSelection();
nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_SELECTION_WITHIN,
accessible);
return;
}
RefPtr<AccSelChangeEvent> selChangeEvent =
new AccSelChangeEvent(treeAcc, treeItemAcc,
AccSelChangeEvent::eSelectionAdd);
nsEventShell::FireEvent(selChangeEvent);
return;
}
}
else
#endif
if (eventType.EqualsLiteral("AlertActive")) {
nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_ALERT, accessible);
}
else if (eventType.EqualsLiteral("popupshown")) {
HandlePopupShownEvent(accessible);
}
else if (eventType.EqualsLiteral("DOMMenuInactive")) {
if (accessible->Role() == roles::MENUPOPUP) {
nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_END,
accessible);
}
}
else if (eventType.EqualsLiteral("DOMMenuItemActive")) {
FocusMgr()->ActiveItemChanged(accessible);
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("DOMMenuItemActive", accessible);
#endif
}
else if (eventType.EqualsLiteral("DOMMenuItemInactive")) {
// Process DOMMenuItemInactive event for autocomplete only because this is
// unique widget that may acquire focus from autocomplete popup while popup
// stays open and has no active item. In case of XUL tree autocomplete
// popup this event is fired for tree accessible.
Accessible* widget =
accessible->IsWidget() ? accessible : accessible->ContainerWidget();
if (widget && widget->IsAutoCompletePopup()) {
FocusMgr()->ActiveItemChanged(nullptr);
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("DOMMenuItemInactive", accessible);
#endif
}
}
else if (eventType.EqualsLiteral("DOMMenuBarActive")) { // Always from user input
nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_MENU_START,
accessible, eFromUserInput);
// Notify of active item change when menubar gets active and if it has
// current item. This is a case of mouseover (set current menuitem) and
// mouse click (activate the menubar). If menubar doesn't have current item
// (can be a case of menubar activation from keyboard) then ignore this
// notification because later we'll receive DOMMenuItemActive event after
// current menuitem is set.
Accessible* activeItem = accessible->CurrentItem();
if (activeItem) {
FocusMgr()->ActiveItemChanged(activeItem);
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("DOMMenuBarActive", accessible);
#endif
}
}
else if (eventType.EqualsLiteral("DOMMenuBarInactive")) { // Always from user input
nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_MENU_END,
accessible, eFromUserInput);
FocusMgr()->ActiveItemChanged(nullptr);
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("DOMMenuBarInactive", accessible);
#endif
}
else if (accessible->NeedsDOMUIEvent() &&
eventType.EqualsLiteral("ValueChange")) {
targetDocument->FireDelayedEvent(nsIAccessibleEvent::EVENT_VALUE_CHANGE,
accessible);
}
#ifdef DEBUG_DRAGDROPSTART
else if (eventType.EqualsLiteral("mouseover")) {
nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_DRAGDROP_START,
accessible);
}
#endif
}
////////////////////////////////////////////////////////////////////////////////
// Accessible
void
RootAccessible::Shutdown()
{
// Called manually or by Accessible::LastRelease()
if (!PresShell())
return; // Already shutdown
DocAccessibleWrap::Shutdown();
}
Relation
RootAccessible::RelationByType(RelationType aType)
{
if (!mDocumentNode || aType != RelationType::EMBEDS)
return DocAccessibleWrap::RelationByType(aType);
nsIDOMWindow* rootWindow = mDocumentNode->GetWindow();
if (rootWindow) {
nsCOMPtr<nsIDOMWindow> contentWindow;
rootWindow->GetContent(getter_AddRefs(contentWindow));
if (contentWindow) {
nsCOMPtr<nsIDOMDocument> contentDOMDocument;
contentWindow->GetDocument(getter_AddRefs(contentDOMDocument));
nsCOMPtr<nsIDocument> contentDocumentNode =
do_QueryInterface(contentDOMDocument);
if (contentDocumentNode) {
DocAccessible* contentDocument =
GetAccService()->GetDocAccessible(contentDocumentNode);
if (contentDocument)
return Relation(contentDocument);
}
}
}
return Relation();
}
////////////////////////////////////////////////////////////////////////////////
// Protected members
void
RootAccessible::HandlePopupShownEvent(Accessible* aAccessible)
{
roles::Role role = aAccessible->Role();
if (role == roles::MENUPOPUP) {
// Don't fire menupopup events for combobox and autocomplete lists.
nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_START,
aAccessible);
return;
}
if (role == roles::TOOLTIP) {
// There is a single <xul:tooltip> node which Mozilla moves around.
// The accessible for it stays the same no matter where it moves.
// AT's expect to get an EVENT_SHOW for the tooltip.
// In event callback the tooltip's accessible will be ready.
nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_SHOW, aAccessible);
return;
}
if (role == roles::COMBOBOX_LIST) {
// Fire expanded state change event for comboboxes and autocompeletes.
Accessible* combobox = aAccessible->Parent();
if (!combobox)
return;
roles::Role comboboxRole = combobox->Role();
if (comboboxRole == roles::COMBOBOX ||
comboboxRole == roles::AUTOCOMPLETE) {
RefPtr<AccEvent> event =
new AccStateChangeEvent(combobox, states::EXPANDED, true);
if (event)
nsEventShell::FireEvent(event);
}
}
}
void
RootAccessible::HandlePopupHidingEvent(nsINode* aPopupNode)
{
// Get popup accessible. There are cases when popup element isn't accessible
// but an underlying widget is and behaves like popup, an example is
// autocomplete popups.
DocAccessible* document = nsAccUtils::GetDocAccessibleFor(aPopupNode);
if (!document)
return;
Accessible* popup = document->GetAccessible(aPopupNode);
if (!popup) {
Accessible* popupContainer = document->GetContainerAccessible(aPopupNode);
if (!popupContainer)
return;
uint32_t childCount = popupContainer->ChildCount();
for (uint32_t idx = 0; idx < childCount; idx++) {
Accessible* child = popupContainer->GetChildAt(idx);
if (child->IsAutoCompletePopup()) {
popup = child;
break;
}
}
// No popup no events. Focus is managed by DOM. This is a case for
// menupopups of menus on Linux since there are no accessible for popups.
if (!popup)
return;
}
// In case of autocompletes and comboboxes fire state change event for
// expanded state. Note, HTML form autocomplete isn't a subject of state
// change event because they aren't autocompletes strictly speaking.
// When popup closes (except nested popups and menus) then fire focus event to
// where it was. The focus event is expected even if popup didn't take a focus.
static const uint32_t kNotifyOfFocus = 1;
static const uint32_t kNotifyOfState = 2;
uint32_t notifyOf = 0;
// HTML select is target of popuphidding event. Otherwise get container
// widget. No container widget means this is either tooltip or menupopup.
// No events in the former case.
Accessible* widget = nullptr;
if (popup->IsCombobox()) {
widget = popup;
} else {
widget = popup->ContainerWidget();
if (!widget) {
if (!popup->IsMenuPopup())
return;
widget = popup;
}
}
if (popup->IsAutoCompletePopup()) {
// No focus event for autocomplete because it's managed by
// DOMMenuItemInactive events.
if (widget->IsAutoComplete())
notifyOf = kNotifyOfState;
} else if (widget->IsCombobox()) {
// Fire focus for active combobox, otherwise the focus is managed by DOM
// focus notifications. Always fire state change event.
if (widget->IsActiveWidget())
notifyOf = kNotifyOfFocus;
notifyOf |= kNotifyOfState;
} else if (widget->IsMenuButton()) {
// Can be a part of autocomplete.
Accessible* compositeWidget = widget->ContainerWidget();
if (compositeWidget && compositeWidget->IsAutoComplete()) {
widget = compositeWidget;
notifyOf = kNotifyOfState;
}
// Autocomplete (like searchbar) can be inactive when popup hiddens
notifyOf |= kNotifyOfFocus;
} else if (widget == popup) {
// Top level context menus and alerts.
// Ignore submenus and menubar. When submenu is closed then sumbenu
// container menuitem takes a focus via DOMMenuItemActive notification.
// For menubars processing we listen DOMMenubarActive/Inactive
// notifications.
notifyOf = kNotifyOfFocus;
}
// Restore focus to where it was.
if (notifyOf & kNotifyOfFocus) {
FocusMgr()->ActiveItemChanged(nullptr);
#ifdef A11Y_LOG
if (logging::IsEnabled(logging::eFocus))
logging::ActiveItemChangeCausedBy("popuphiding", popup);
#endif
}
// Fire expanded state change event.
if (notifyOf & kNotifyOfState) {
RefPtr<AccEvent> event =
new AccStateChangeEvent(widget, states::EXPANDED, false);
document->FireDelayedEvent(event);
}
}
#ifdef MOZ_XUL
void
RootAccessible::HandleTreeRowCountChangedEvent(nsIDOMEvent* aEvent,
XULTreeAccessible* aAccessible)
{
nsCOMPtr<nsIDOMCustomEvent> customEvent(do_QueryInterface(aEvent));
if (!customEvent)
return;
nsCOMPtr<nsIVariant> detailVariant;
customEvent->GetDetail(getter_AddRefs(detailVariant));
if (!detailVariant)
return;
nsCOMPtr<nsISupports> supports;
detailVariant->GetAsISupports(getter_AddRefs(supports));
nsCOMPtr<nsIPropertyBag2> propBag(do_QueryInterface(supports));
if (!propBag)
return;
nsresult rv;
int32_t index, count;
rv = propBag->GetPropertyAsInt32(NS_LITERAL_STRING("index"), &index);
if (NS_FAILED(rv))
return;
rv = propBag->GetPropertyAsInt32(NS_LITERAL_STRING("count"), &count);
if (NS_FAILED(rv))
return;
aAccessible->InvalidateCache(index, count);
}
void
RootAccessible::HandleTreeInvalidatedEvent(nsIDOMEvent* aEvent,
XULTreeAccessible* aAccessible)
{
nsCOMPtr<nsIDOMCustomEvent> customEvent(do_QueryInterface(aEvent));
if (!customEvent)
return;
nsCOMPtr<nsIVariant> detailVariant;
customEvent->GetDetail(getter_AddRefs(detailVariant));
if (!detailVariant)
return;
nsCOMPtr<nsISupports> supports;
detailVariant->GetAsISupports(getter_AddRefs(supports));
nsCOMPtr<nsIPropertyBag2> propBag(do_QueryInterface(supports));
if (!propBag)
return;
int32_t startRow = 0, endRow = -1, startCol = 0, endCol = -1;
propBag->GetPropertyAsInt32(NS_LITERAL_STRING("startrow"),
&startRow);
propBag->GetPropertyAsInt32(NS_LITERAL_STRING("endrow"),
&endRow);
propBag->GetPropertyAsInt32(NS_LITERAL_STRING("startcolumn"),
&startCol);
propBag->GetPropertyAsInt32(NS_LITERAL_STRING("endcolumn"),
&endCol);
aAccessible->TreeViewInvalidated(startRow, endRow, startCol, endCol);
}
#endif