no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / accessible / base / FocusManager.h
blob7460a21f9ad813524bceef825514625329e66fdd
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"
10 class nsINode;
11 class nsISupports;
13 namespace mozilla {
14 namespace dom {
15 class Document;
18 namespace a11y {
20 class Accessible;
21 class AccEvent;
22 class LocalAccessible;
23 class DocAccessible;
24 class DocAccessibleParent;
26 /**
27 * Manage the accessible focus. Used to fire and process accessible events.
29 class FocusManager {
30 public:
31 virtual ~FocusManager();
33 /**
34 * Return the currently focused LocalAccessible. If a remote document has
35 * focus, this will return null.
37 LocalAccessible* FocusedLocalAccessible() const;
39 /**
40 * Return the currently focused Accessible, local or remote.
42 Accessible* FocusedAccessible() const;
44 /**
45 * Return true if given accessible is focused.
47 bool IsFocused(const Accessible* aAccessible) const {
48 return FocusedAccessible() == aAccessible;
51 /**
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;
59 /**
60 * Return DOM node having DOM focus.
62 nsINode* FocusedDOMNode() const;
64 /**
65 * Return true if given DOM node has DOM focus.
67 inline bool HasDOMFocus(const nsINode* aNode) const {
68 return aNode == FocusedDOMNode();
71 /**
72 * Return true if focused accessible is within the given container.
74 bool IsFocusWithin(const Accessible* aContainer) const;
76 /**
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;
84 /**
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
88 * ways:
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).
99 /**
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.
132 * do.
134 void ProcessFocusEvent(AccEvent* aEvent);
136 #ifdef ANDROID
137 void SetFocusedRemoteDoc(DocAccessibleParent* aDoc) {
138 mFocusedRemoteDoc = aDoc;
140 bool IsFocusedRemoteDoc(DocAccessibleParent* aDoc) {
141 return mFocusedRemoteDoc == aDoc;
143 #endif
145 protected:
146 FocusManager();
148 private:
149 FocusManager(const FocusManager&);
150 FocusManager& operator=(const FocusManager&);
153 * Return DOM document having DOM focus.
155 dom::Document* FocusedDOMDocument() const;
157 private:
158 RefPtr<LocalAccessible> mActiveItem;
159 RefPtr<LocalAccessible> mLastFocus;
160 RefPtr<LocalAccessible> mActiveARIAMenubar;
161 #ifdef ANDROID
162 DocAccessibleParent* mFocusedRemoteDoc = nullptr;
163 #endif
166 } // namespace a11y
167 } // namespace mozilla
169 #endif