|
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/. */ |
|
4 |
|
5 #ifndef mozilla_a11y_FocusManager_h_ |
|
6 #define mozilla_a11y_FocusManager_h_ |
|
7 |
|
8 #include "nsAutoPtr.h" |
|
9 |
|
10 class nsINode; |
|
11 class nsIDocument; |
|
12 class nsISupports; |
|
13 |
|
14 namespace mozilla { |
|
15 namespace a11y { |
|
16 |
|
17 class AccEvent; |
|
18 class Accessible; |
|
19 class DocAccessible; |
|
20 |
|
21 /** |
|
22 * Manage the accessible focus. Used to fire and process accessible events. |
|
23 */ |
|
24 class FocusManager |
|
25 { |
|
26 public: |
|
27 virtual ~FocusManager(); |
|
28 |
|
29 /** |
|
30 * Return a focused accessible. |
|
31 */ |
|
32 Accessible* FocusedAccessible() const; |
|
33 |
|
34 /** |
|
35 * Return true if given accessible is focused. |
|
36 */ |
|
37 bool IsFocused(const Accessible* aAccessible) const; |
|
38 |
|
39 /** |
|
40 * Return true if the given accessible is an active item, i.e. an item that |
|
41 * is current within the active widget. |
|
42 */ |
|
43 inline bool IsActiveItem(const Accessible* aAccessible) |
|
44 { return aAccessible == mActiveItem; } |
|
45 |
|
46 /** |
|
47 * Return true if given DOM node has DOM focus. |
|
48 */ |
|
49 inline bool HasDOMFocus(const nsINode* aNode) const |
|
50 { return aNode == FocusedDOMNode(); } |
|
51 |
|
52 /** |
|
53 * Return true if focused accessible is within the given container. |
|
54 */ |
|
55 bool IsFocusWithin(const Accessible* aContainer) const; |
|
56 |
|
57 /** |
|
58 * Return whether the given accessible is focused or contains the focus or |
|
59 * contained by focused accessible. |
|
60 */ |
|
61 enum FocusDisposition { |
|
62 eNone, |
|
63 eFocused, |
|
64 eContainsFocus, |
|
65 eContainedByFocus |
|
66 }; |
|
67 FocusDisposition IsInOrContainsFocus(const Accessible* aAccessible) const; |
|
68 |
|
69 ////////////////////////////////////////////////////////////////////////////// |
|
70 // Focus notifications and processing (don't use until you know what you do). |
|
71 |
|
72 /** |
|
73 * Called when DOM focus event is fired. |
|
74 */ |
|
75 void NotifyOfDOMFocus(nsISupports* aTarget); |
|
76 |
|
77 /** |
|
78 * Called when DOM blur event is fired. |
|
79 */ |
|
80 void NotifyOfDOMBlur(nsISupports* aTarget); |
|
81 |
|
82 /** |
|
83 * Called when active item is changed. Note: must be called when accessible |
|
84 * tree is up to date. |
|
85 */ |
|
86 void ActiveItemChanged(Accessible* aItem, bool aCheckIfActive = true); |
|
87 |
|
88 /** |
|
89 * Dispatch delayed focus event for the current focus accessible. |
|
90 */ |
|
91 void ForceFocusEvent(); |
|
92 |
|
93 /** |
|
94 * Dispatch delayed focus event for the given target. |
|
95 */ |
|
96 void DispatchFocusEvent(DocAccessible* aDocument, Accessible* aTarget); |
|
97 |
|
98 /** |
|
99 * Process DOM focus notification. |
|
100 */ |
|
101 void ProcessDOMFocus(nsINode* aTarget); |
|
102 |
|
103 /** |
|
104 * Process the delayed accessible event. |
|
105 * do. |
|
106 */ |
|
107 void ProcessFocusEvent(AccEvent* aEvent); |
|
108 |
|
109 protected: |
|
110 FocusManager(); |
|
111 |
|
112 private: |
|
113 FocusManager(const FocusManager&); |
|
114 FocusManager& operator =(const FocusManager&); |
|
115 |
|
116 /** |
|
117 * Return DOM node having DOM focus. |
|
118 */ |
|
119 nsINode* FocusedDOMNode() const; |
|
120 |
|
121 /** |
|
122 * Return DOM document having DOM focus. |
|
123 */ |
|
124 nsIDocument* FocusedDOMDocument() const; |
|
125 |
|
126 private: |
|
127 nsRefPtr<Accessible> mActiveItem; |
|
128 nsRefPtr<Accessible> mActiveARIAMenubar; |
|
129 }; |
|
130 |
|
131 } // namespace a11y |
|
132 } // namespace mozilla |
|
133 |
|
134 #endif |