1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_a11y_FocusManager_h_
6 #define mozilla_a11y_FocusManager_h_
8 #include "mozilla/RefPtr.h"
22 class LocalAccessible
;
24 class DocAccessibleParent
;
27 * Manage the accessible focus. Used to fire and process accessible events.
31 virtual ~FocusManager();
34 * Return the currently focused LocalAccessible. If a remote document has
35 * focus, this will return null.
37 LocalAccessible
* FocusedLocalAccessible() const;
40 * Return the currently focused Accessible, local or remote.
42 Accessible
* FocusedAccessible() const;
45 * Return true if given accessible is focused.
47 bool IsFocused(const Accessible
* aAccessible
) const {
48 return FocusedAccessible() == aAccessible
;
52 * Return true if the given accessible is an active item, i.e. an item that
53 * is current within the active widget.
55 inline bool IsActiveItem(const LocalAccessible
* aAccessible
) {
56 return aAccessible
== mActiveItem
;
60 * Return DOM node having DOM focus.
62 nsINode
* FocusedDOMNode() const;
65 * Return true if given DOM node has DOM focus.
67 inline bool HasDOMFocus(const nsINode
* aNode
) const {
68 return aNode
== FocusedDOMNode();
72 * Return true if focused accessible is within the given container.
74 bool IsFocusWithin(const Accessible
* aContainer
) const;
77 * Return whether the given accessible is focused or contains the focus or
78 * contained by focused accessible.
80 enum FocusDisposition
{ eNone
, eFocused
, eContainsFocus
, eContainedByFocus
};
81 FocusDisposition
IsInOrContainsFocus(
82 const LocalAccessible
* aAccessible
) const;
85 * Return true if the given accessible was the last accessible focused.
86 * This is useful to detect the case where the last focused accessible was
87 * removed before something else was focused. This can happen in one of two
89 * 1. The DOM focus was removed. DOM doesn't fire a blur event when this
90 * happens; see bug 559561.
91 * 2. The accessibility focus was an active item (e.g. aria-activedescendant)
92 * and that item was removed.
94 bool WasLastFocused(const LocalAccessible
* aAccessible
) const;
96 //////////////////////////////////////////////////////////////////////////////
97 // Focus notifications and processing (don't use until you know what you do).
100 * Called when DOM focus event is fired.
102 void NotifyOfDOMFocus(nsISupports
* aTarget
);
105 * Called when DOM blur event is fired.
107 void NotifyOfDOMBlur(nsISupports
* aTarget
);
110 * Called when active item is changed. Note: must be called when accessible
111 * tree is up to date.
113 void ActiveItemChanged(LocalAccessible
* aItem
, bool aCheckIfActive
= true);
116 * Dispatch delayed focus event for the current focus accessible.
118 void ForceFocusEvent();
121 * Dispatch delayed focus event for the given target.
123 void DispatchFocusEvent(DocAccessible
* aDocument
, LocalAccessible
* aTarget
);
126 * Process DOM focus notification.
128 void ProcessDOMFocus(nsINode
* aTarget
);
131 * Process the delayed accessible event.
134 void ProcessFocusEvent(AccEvent
* aEvent
);
137 void SetFocusedRemoteDoc(DocAccessibleParent
* aDoc
) {
138 mFocusedRemoteDoc
= aDoc
;
140 bool IsFocusedRemoteDoc(DocAccessibleParent
* aDoc
) {
141 return mFocusedRemoteDoc
== aDoc
;
149 FocusManager(const FocusManager
&);
150 FocusManager
& operator=(const FocusManager
&);
153 * Return DOM document having DOM focus.
155 dom::Document
* FocusedDOMDocument() const;
158 RefPtr
<LocalAccessible
> mActiveItem
;
159 RefPtr
<LocalAccessible
> mLastFocus
;
160 RefPtr
<LocalAccessible
> mActiveARIAMenubar
;
162 DocAccessibleParent
* mFocusedRemoteDoc
= nullptr;
167 } // namespace mozilla