2012-05-30 02:21:24 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_a11y_DocAccessible_inl_h_
|
|
|
|
#define mozilla_a11y_DocAccessible_inl_h_
|
|
|
|
|
|
|
|
#include "DocAccessible.h"
|
2023-07-27 15:02:25 +00:00
|
|
|
#include "LocalAccessible-inl.h"
|
2012-05-30 02:21:24 +00:00
|
|
|
#include "nsAccessibilityService.h"
|
2012-06-01 18:39:47 +00:00
|
|
|
#include "NotificationController.h"
|
2012-11-17 03:32:51 +00:00
|
|
|
#include "States.h"
|
2019-01-02 13:05:23 +00:00
|
|
|
#include "mozilla/dom/DocumentInlines.h"
|
2012-05-30 02:21:24 +00:00
|
|
|
|
2012-11-20 04:53:38 +00:00
|
|
|
#ifdef A11Y_LOG
|
|
|
|
# include "Logging.h"
|
|
|
|
#endif
|
|
|
|
|
2012-11-18 02:01:44 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
|
2021-02-19 23:14:32 +00:00
|
|
|
inline LocalAccessible* DocAccessible::AccessibleOrTrueContainer(
|
2019-05-20 15:54:56 +00:00
|
|
|
nsINode* aNode, bool aNoContainerIfPruned) const {
|
2016-03-28 17:40:21 +00:00
|
|
|
// HTML comboboxes have no-content list accessible as an intermediate
|
|
|
|
// containing all options.
|
2021-02-19 23:14:32 +00:00
|
|
|
LocalAccessible* container =
|
|
|
|
GetAccessibleOrContainer(aNode, aNoContainerIfPruned);
|
2016-03-28 17:40:21 +00:00
|
|
|
if (container && container->IsHTMLCombobox()) {
|
2021-02-16 20:05:10 +00:00
|
|
|
return container->LocalFirstChild();
|
2016-03-28 17:40:21 +00:00
|
|
|
}
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2020-11-23 16:07:43 +00:00
|
|
|
inline bool DocAccessible::IsContentLoaded() const {
|
|
|
|
// eDOMLoaded flag check is used for error pages as workaround to make this
|
|
|
|
// method return correct result since error pages do not receive 'pageshow'
|
|
|
|
// event and as consequence Document::IsShowing() returns false.
|
|
|
|
return mDocumentNode && mDocumentNode->IsVisible() &&
|
|
|
|
(mDocumentNode->IsShowing() || HasLoadState(eDOMLoaded));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool DocAccessible::IsHidden() const { return mDocumentNode->Hidden(); }
|
|
|
|
|
2012-11-20 04:53:38 +00:00
|
|
|
inline void DocAccessible::FireDelayedEvent(AccEvent* aEvent) {
|
|
|
|
#ifdef A11Y_LOG
|
|
|
|
if (logging::IsEnabled(logging::eDocLoad)) logging::DocLoadEventFired(aEvent);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mNotificationController->QueueEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void DocAccessible::FireDelayedEvent(uint32_t aEventType,
|
2021-02-19 23:14:32 +00:00
|
|
|
LocalAccessible* aTarget) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<AccEvent> event = new AccEvent(aEventType, aTarget);
|
2012-11-20 04:53:38 +00:00
|
|
|
FireDelayedEvent(event);
|
|
|
|
}
|
|
|
|
|
2012-06-01 18:39:47 +00:00
|
|
|
inline void DocAccessible::BindChildDocument(DocAccessible* aDocument) {
|
|
|
|
mNotificationController->ScheduleChildDocBinding(aDocument);
|
|
|
|
}
|
|
|
|
|
2019-03-25 05:04:36 +00:00
|
|
|
template <class Class, class... Args>
|
2012-06-01 18:39:47 +00:00
|
|
|
inline void DocAccessible::HandleNotification(
|
2019-03-25 05:04:36 +00:00
|
|
|
Class* aInstance, typename TNotification<Class, Args...>::Callback aMethod,
|
|
|
|
Args*... aArgs) {
|
2012-06-01 18:39:47 +00:00
|
|
|
if (mNotificationController) {
|
2019-03-25 05:04:36 +00:00
|
|
|
mNotificationController->HandleNotification<Class, Args...>(
|
|
|
|
aInstance, aMethod, aArgs...);
|
2012-06-01 18:39:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void DocAccessible::UpdateText(nsIContent* aTextNode) {
|
|
|
|
NS_ASSERTION(mNotificationController, "The document was shut down!");
|
|
|
|
|
|
|
|
// Ignore the notification if initial tree construction hasn't been done yet.
|
2021-02-19 23:14:32 +00:00
|
|
|
if (mNotificationController && HasLoadState(eTreeConstructed)) {
|
2012-06-01 18:39:47 +00:00
|
|
|
mNotificationController->ScheduleTextUpdate(aTextNode);
|
2021-02-19 23:14:32 +00:00
|
|
|
}
|
2012-06-01 18:39:47 +00:00
|
|
|
}
|
|
|
|
|
2012-11-17 03:32:51 +00:00
|
|
|
inline void DocAccessible::NotifyOfLoad(uint32_t aLoadEventType) {
|
|
|
|
mLoadState |= eDOMLoaded;
|
|
|
|
mLoadEventType = aLoadEventType;
|
|
|
|
|
|
|
|
// If the document is loaded completely then network activity was presumingly
|
|
|
|
// caused by file loading. Fire busy state change event.
|
|
|
|
if (HasLoadState(eCompletelyLoaded) && IsLoadEventTarget()) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<AccEvent> stateEvent =
|
2012-11-18 02:01:44 +00:00
|
|
|
new AccStateChangeEvent(this, states::BUSY, false);
|
2012-11-20 04:53:38 +00:00
|
|
|
FireDelayedEvent(stateEvent);
|
2012-11-17 03:32:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-19 23:14:32 +00:00
|
|
|
inline void DocAccessible::MaybeNotifyOfValueChange(
|
|
|
|
LocalAccessible* aAccessible) {
|
2020-01-16 04:57:24 +00:00
|
|
|
if (aAccessible->IsCombobox() || aAccessible->Role() == roles::ENTRY ||
|
|
|
|
aAccessible->Role() == roles::SPINBUTTON) {
|
2015-11-02 20:34:51 +00:00
|
|
|
FireDelayedEvent(nsIAccessibleEvent::EVENT_TEXT_VALUE_CHANGE, aAccessible);
|
2020-01-16 04:57:24 +00:00
|
|
|
}
|
2012-11-13 06:29:22 +00:00
|
|
|
}
|
2012-07-28 04:21:40 +00:00
|
|
|
|
2021-02-19 23:14:32 +00:00
|
|
|
inline LocalAccessible* DocAccessible::GetAccessibleEvenIfNotInMapOrContainer(
|
2014-03-06 00:36:56 +00:00
|
|
|
nsINode* aNode) const {
|
2021-02-19 23:14:32 +00:00
|
|
|
LocalAccessible* acc = GetAccessibleEvenIfNotInMap(aNode);
|
2014-03-06 00:36:56 +00:00
|
|
|
return acc ? acc : GetContainerAccessible(aNode);
|
|
|
|
}
|
|
|
|
|
2021-02-19 23:14:32 +00:00
|
|
|
inline void DocAccessible::CreateSubtree(LocalAccessible* aChild) {
|
2016-04-25 13:10:41 +00:00
|
|
|
// If a focused node has been shown then it could mean its frame was recreated
|
|
|
|
// while the node stays focused and we need to fire focus event on
|
|
|
|
// the accessible we just created. If the queue contains a focus event for
|
|
|
|
// this node already then it will be suppressed by this one.
|
2021-02-19 23:14:32 +00:00
|
|
|
LocalAccessible* focusedAcc = nullptr;
|
2016-04-25 13:10:41 +00:00
|
|
|
CacheChildrenInSubtree(aChild, &focusedAcc);
|
|
|
|
|
2016-08-19 16:10:58 +00:00
|
|
|
#ifdef A11Y_LOG
|
|
|
|
if (logging::IsEnabled(logging::eVerbose)) {
|
|
|
|
logging::Tree("TREE", "Created subtree", aChild);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-05-18 12:58:26 +00:00
|
|
|
// Fire events for ARIA elements.
|
|
|
|
if (aChild->HasARIARole()) {
|
|
|
|
roles::Role role = aChild->ARIARole();
|
|
|
|
if (role == roles::MENUPOPUP) {
|
|
|
|
FireDelayedEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_START, aChild);
|
|
|
|
} else if (role == roles::ALERT) {
|
|
|
|
FireDelayedEvent(nsIAccessibleEvent::EVENT_ALERT, aChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-25 13:10:41 +00:00
|
|
|
// XXX: do we really want to send focus to focused DOM node not taking into
|
|
|
|
// account active item?
|
|
|
|
if (focusedAcc) {
|
|
|
|
FocusMgr()->DispatchFocusEvent(this, focusedAcc);
|
|
|
|
SelectionMgr()->SetControlSelectionListener(
|
|
|
|
focusedAcc->GetNode()->AsElement());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-30 00:17:04 +00:00
|
|
|
inline DocAccessible::AttrRelProviders* DocAccessible::GetRelProviders(
|
|
|
|
dom::Element* aElement, const nsAString& aID) const {
|
|
|
|
DependentIDsHashtable* hash = mDependentIDsHashes.Get(
|
|
|
|
aElement->GetUncomposedDocOrConnectedShadowRoot());
|
|
|
|
if (hash) {
|
|
|
|
return hash->Get(aID);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline DocAccessible::AttrRelProviders* DocAccessible::GetOrCreateRelProviders(
|
|
|
|
dom::Element* aElement, const nsAString& aID) {
|
|
|
|
dom::DocumentOrShadowRoot* docOrShadowRoot =
|
|
|
|
aElement->GetUncomposedDocOrConnectedShadowRoot();
|
2021-02-15 15:12:17 +00:00
|
|
|
DependentIDsHashtable* hash =
|
2021-02-26 09:22:54 +00:00
|
|
|
mDependentIDsHashes.GetOrInsertNew(docOrShadowRoot);
|
|
|
|
|
|
|
|
return hash->GetOrInsertNew(aID);
|
2018-10-30 00:17:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void DocAccessible::RemoveRelProvidersIfEmpty(dom::Element* aElement,
|
|
|
|
const nsAString& aID) {
|
|
|
|
dom::DocumentOrShadowRoot* docOrShadowRoot =
|
|
|
|
aElement->GetUncomposedDocOrConnectedShadowRoot();
|
|
|
|
DependentIDsHashtable* hash = mDependentIDsHashes.Get(docOrShadowRoot);
|
|
|
|
if (hash) {
|
|
|
|
AttrRelProviders* providers = hash->Get(aID);
|
|
|
|
if (providers && providers->Length() == 0) {
|
|
|
|
hash->Remove(aID);
|
|
|
|
if (mDependentIDsHashes.IsEmpty()) {
|
|
|
|
mDependentIDsHashes.Remove(docOrShadowRoot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-18 02:01:44 +00:00
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-05-30 02:21:24 +00:00
|
|
|
#endif
|