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"
|
|
|
|
#include "nsAccessibilityService.h"
|
2014-09-23 12:23:02 +00:00
|
|
|
#include "nsAccessiblePivot.h"
|
2012-06-01 18:39:47 +00:00
|
|
|
#include "NotificationController.h"
|
2012-11-17 03:32:51 +00:00
|
|
|
#include "States.h"
|
2013-09-10 22:18:59 +00:00
|
|
|
#include "nsIScrollableFrame.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 {
|
|
|
|
|
2018-07-04 14:18:43 +00:00
|
|
|
inline Accessible* DocAccessible::AccessibleOrTrueContainer(
|
|
|
|
nsINode* aNode, int aIgnoreARIAHidden) const {
|
2016-03-28 17:40:21 +00:00
|
|
|
// HTML comboboxes have no-content list accessible as an intermediate
|
|
|
|
// containing all options.
|
2018-07-04 14:18:43 +00:00
|
|
|
Accessible* container = GetAccessibleOrContainer(aNode, aIgnoreARIAHidden);
|
2016-03-28 17:40:21 +00:00
|
|
|
if (container && container->IsHTMLCombobox()) {
|
|
|
|
return container->FirstChild();
|
|
|
|
}
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2014-09-23 12:23:02 +00:00
|
|
|
inline nsIAccessiblePivot* DocAccessible::VirtualCursor() {
|
|
|
|
if (!mVirtualCursor) {
|
|
|
|
mVirtualCursor = new nsAccessiblePivot(this);
|
|
|
|
mVirtualCursor->AddObserver(this);
|
|
|
|
}
|
|
|
|
return mVirtualCursor;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
Accessible* 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.
|
|
|
|
if (mNotificationController && HasLoadState(eTreeConstructed))
|
|
|
|
mNotificationController->ScheduleTextUpdate(aTextNode);
|
|
|
|
}
|
|
|
|
|
2012-12-27 04:25:27 +00:00
|
|
|
inline void DocAccessible::AddScrollListener() {
|
|
|
|
// Delay scroll initializing until the document has a root frame.
|
|
|
|
if (!mPresShell->GetRootFrame()) return;
|
|
|
|
|
|
|
|
mDocFlags |= eScrollInitialized;
|
|
|
|
nsIScrollableFrame* sf = mPresShell->GetRootScrollFrameAsScrollable();
|
|
|
|
if (sf) {
|
|
|
|
sf->AddScrollPositionListener(this);
|
|
|
|
|
|
|
|
#ifdef A11Y_LOG
|
|
|
|
if (logging::IsEnabled(logging::eDocCreate))
|
|
|
|
logging::Text("add scroll listener");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void DocAccessible::RemoveScrollListener() {
|
|
|
|
nsIScrollableFrame* sf = mPresShell->GetRootScrollFrameAsScrollable();
|
|
|
|
if (sf) sf->RemoveScrollPositionListener(this);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-28 04:21:40 +00:00
|
|
|
inline void DocAccessible::MaybeNotifyOfValueChange(Accessible* aAccessible) {
|
2017-07-11 09:16:00 +00:00
|
|
|
if (aAccessible->IsCombobox() || aAccessible->Role() == roles::ENTRY)
|
2015-11-02 20:34:51 +00:00
|
|
|
FireDelayedEvent(nsIAccessibleEvent::EVENT_TEXT_VALUE_CHANGE, aAccessible);
|
2012-11-13 06:29:22 +00:00
|
|
|
}
|
2012-07-28 04:21:40 +00:00
|
|
|
|
2014-03-06 00:36:56 +00:00
|
|
|
inline Accessible* DocAccessible::GetAccessibleEvenIfNotInMapOrContainer(
|
|
|
|
nsINode* aNode) const {
|
|
|
|
Accessible* acc = GetAccessibleEvenIfNotInMap(aNode);
|
|
|
|
return acc ? acc : GetContainerAccessible(aNode);
|
|
|
|
}
|
|
|
|
|
2016-04-25 13:10:41 +00:00
|
|
|
inline void DocAccessible::CreateSubtree(Accessible* aChild) {
|
|
|
|
// 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.
|
|
|
|
Accessible* focusedAcc = nullptr;
|
|
|
|
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();
|
|
|
|
DependentIDsHashtable* hash = mDependentIDsHashes.Get(docOrShadowRoot);
|
|
|
|
if (!hash) {
|
|
|
|
hash = new DependentIDsHashtable();
|
|
|
|
mDependentIDsHashes.Put(docOrShadowRoot, hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
AttrRelProviders* providers = hash->Get(aID);
|
|
|
|
if (!providers) {
|
|
|
|
providers = new AttrRelProviders();
|
|
|
|
hash->Put(aID, providers);
|
|
|
|
}
|
|
|
|
return providers;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|