|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef __nsAccessibilityService_h__ |
|
7 #define __nsAccessibilityService_h__ |
|
8 |
|
9 #include "nsIAccessibilityService.h" |
|
10 |
|
11 #include "mozilla/a11y/DocManager.h" |
|
12 #include "mozilla/a11y/FocusManager.h" |
|
13 #include "mozilla/a11y/SelectionManager.h" |
|
14 |
|
15 #include "nsIObserver.h" |
|
16 |
|
17 class nsImageFrame; |
|
18 class nsObjectFrame; |
|
19 class nsITreeView; |
|
20 |
|
21 namespace mozilla { |
|
22 namespace a11y { |
|
23 |
|
24 class ApplicationAccessible; |
|
25 |
|
26 /** |
|
27 * Return focus manager. |
|
28 */ |
|
29 FocusManager* FocusMgr(); |
|
30 |
|
31 /** |
|
32 * Return selection manager. |
|
33 */ |
|
34 SelectionManager* SelectionMgr(); |
|
35 |
|
36 /** |
|
37 * Returns the application accessible. |
|
38 */ |
|
39 ApplicationAccessible* ApplicationAcc(); |
|
40 |
|
41 } // namespace a11y |
|
42 } // namespace mozilla |
|
43 |
|
44 class nsAccessibilityService : public mozilla::a11y::DocManager, |
|
45 public mozilla::a11y::FocusManager, |
|
46 public mozilla::a11y::SelectionManager, |
|
47 public nsIAccessibilityService, |
|
48 public nsIObserver |
|
49 { |
|
50 public: |
|
51 typedef mozilla::a11y::Accessible Accessible; |
|
52 typedef mozilla::a11y::DocAccessible DocAccessible; |
|
53 |
|
54 virtual ~nsAccessibilityService(); |
|
55 |
|
56 NS_DECL_ISUPPORTS_INHERITED |
|
57 NS_DECL_NSIACCESSIBLERETRIEVAL |
|
58 NS_DECL_NSIOBSERVER |
|
59 |
|
60 // nsIAccessibilityService |
|
61 virtual Accessible* GetRootDocumentAccessible(nsIPresShell* aPresShell, |
|
62 bool aCanCreate); |
|
63 already_AddRefed<Accessible> |
|
64 CreatePluginAccessible(nsObjectFrame* aFrame, nsIContent* aContent, |
|
65 Accessible* aContext); |
|
66 |
|
67 /** |
|
68 * Adds/remove ATK root accessible for gtk+ native window to/from children |
|
69 * of the application accessible. |
|
70 */ |
|
71 virtual Accessible* AddNativeRootAccessible(void* aAtkAccessible); |
|
72 virtual void RemoveNativeRootAccessible(Accessible* aRootAccessible); |
|
73 |
|
74 /** |
|
75 * Notification used to update the accessible tree when deck panel is |
|
76 * switched. |
|
77 */ |
|
78 void DeckPanelSwitched(nsIPresShell* aPresShell, nsIContent* aDeckNode, |
|
79 nsIFrame* aPrevBoxFrame, nsIFrame* aCurrentBoxFrame); |
|
80 |
|
81 /** |
|
82 * Notification used to update the accessible tree when new content is |
|
83 * inserted. |
|
84 */ |
|
85 void ContentRangeInserted(nsIPresShell* aPresShell, nsIContent* aContainer, |
|
86 nsIContent* aStartChild, nsIContent* aEndChild); |
|
87 |
|
88 /** |
|
89 * Notification used to update the accessible tree when content is removed. |
|
90 */ |
|
91 void ContentRemoved(nsIPresShell* aPresShell, nsIContent* aContainer, |
|
92 nsIContent* aChild); |
|
93 |
|
94 virtual void UpdateText(nsIPresShell* aPresShell, nsIContent* aContent); |
|
95 |
|
96 /** |
|
97 * Update XUL:tree accessible tree when treeview is changed. |
|
98 */ |
|
99 void TreeViewChanged(nsIPresShell* aPresShell, nsIContent* aContent, |
|
100 nsITreeView* aView); |
|
101 |
|
102 /** |
|
103 * Notify of input@type="element" value change. |
|
104 */ |
|
105 void RangeValueChanged(nsIPresShell* aPresShell, nsIContent* aContent); |
|
106 |
|
107 /** |
|
108 * Update list bullet accessible. |
|
109 */ |
|
110 virtual void UpdateListBullet(nsIPresShell* aPresShell, |
|
111 nsIContent* aHTMLListItemContent, |
|
112 bool aHasBullet); |
|
113 |
|
114 /** |
|
115 * Update the image map. |
|
116 */ |
|
117 void UpdateImageMap(nsImageFrame* aImageFrame); |
|
118 |
|
119 /** |
|
120 * Update the label accessible tree when rendered @value is changed. |
|
121 */ |
|
122 void UpdateLabelValue(nsIPresShell* aPresShell, nsIContent* aLabelElm, |
|
123 const nsString& aNewValue); |
|
124 |
|
125 /** |
|
126 * Notify accessibility that anchor jump has been accomplished to the given |
|
127 * target. Used by layout. |
|
128 */ |
|
129 void NotifyOfAnchorJumpTo(nsIContent *aTarget); |
|
130 |
|
131 /** |
|
132 * Notify that presshell is activated. |
|
133 */ |
|
134 virtual void PresShellActivated(nsIPresShell* aPresShell); |
|
135 |
|
136 /** |
|
137 * Recreate an accessible for the given content node in the presshell. |
|
138 */ |
|
139 void RecreateAccessible(nsIPresShell* aPresShell, nsIContent* aContent); |
|
140 |
|
141 virtual void FireAccessibleEvent(uint32_t aEvent, Accessible* aTarget); |
|
142 |
|
143 // nsAccessibiltiyService |
|
144 |
|
145 /** |
|
146 * Return true if accessibility service has been shutdown. |
|
147 */ |
|
148 static bool IsShutdown() { return gIsShutdown; } |
|
149 |
|
150 /** |
|
151 * Return an accessible for the given DOM node from the cache or create new |
|
152 * one. |
|
153 * |
|
154 * @param aNode [in] the given node |
|
155 * @param aContext [in] context the accessible is created in |
|
156 * @param aIsSubtreeHidden [out, optional] indicates whether the node's |
|
157 * frame and its subtree is hidden |
|
158 */ |
|
159 Accessible* GetOrCreateAccessible(nsINode* aNode, Accessible* aContext, |
|
160 bool* aIsSubtreeHidden = nullptr); |
|
161 |
|
162 private: |
|
163 // nsAccessibilityService creation is controlled by friend |
|
164 // NS_GetAccessibilityService, keep constructors private. |
|
165 nsAccessibilityService(); |
|
166 nsAccessibilityService(const nsAccessibilityService&); |
|
167 nsAccessibilityService& operator =(const nsAccessibilityService&); |
|
168 |
|
169 private: |
|
170 /** |
|
171 * Initialize accessibility service. |
|
172 */ |
|
173 bool Init(); |
|
174 |
|
175 /** |
|
176 * Shutdowns accessibility service. |
|
177 */ |
|
178 void Shutdown(); |
|
179 |
|
180 /** |
|
181 * Create accessible for the element having XBL bindings. |
|
182 */ |
|
183 already_AddRefed<Accessible> |
|
184 CreateAccessibleByType(nsIContent* aContent, DocAccessible* aDoc); |
|
185 |
|
186 /** |
|
187 * Create accessible for HTML node by tag name. |
|
188 */ |
|
189 already_AddRefed<Accessible> |
|
190 CreateHTMLAccessibleByMarkup(nsIFrame* aFrame, nsIContent* aContent, |
|
191 Accessible* aContext); |
|
192 |
|
193 /** |
|
194 * Create an accessible whose type depends on the given frame. |
|
195 */ |
|
196 already_AddRefed<Accessible> |
|
197 CreateAccessibleByFrameType(nsIFrame* aFrame, nsIContent* aContent, |
|
198 Accessible* aContext); |
|
199 |
|
200 #ifdef MOZ_XUL |
|
201 /** |
|
202 * Create accessible for XUL tree element. |
|
203 */ |
|
204 already_AddRefed<Accessible> |
|
205 CreateAccessibleForXULTree(nsIContent* aContent, DocAccessible* aDoc); |
|
206 #endif |
|
207 |
|
208 /** |
|
209 * Reference for accessibility service instance. |
|
210 */ |
|
211 static nsAccessibilityService* gAccessibilityService; |
|
212 |
|
213 /** |
|
214 * Reference for application accessible instance. |
|
215 */ |
|
216 static mozilla::a11y::ApplicationAccessible* gApplicationAccessible; |
|
217 |
|
218 /** |
|
219 * Indicates whether accessibility service was shutdown. |
|
220 */ |
|
221 static bool gIsShutdown; |
|
222 |
|
223 friend nsAccessibilityService* GetAccService(); |
|
224 friend mozilla::a11y::FocusManager* mozilla::a11y::FocusMgr(); |
|
225 friend mozilla::a11y::SelectionManager* mozilla::a11y::SelectionMgr(); |
|
226 friend mozilla::a11y::ApplicationAccessible* mozilla::a11y::ApplicationAcc(); |
|
227 |
|
228 friend nsresult NS_GetAccessibilityService(nsIAccessibilityService** aResult); |
|
229 }; |
|
230 |
|
231 /** |
|
232 * Return the accessibility service instance. (Handy global function) |
|
233 */ |
|
234 inline nsAccessibilityService* |
|
235 GetAccService() |
|
236 { |
|
237 return nsAccessibilityService::gAccessibilityService; |
|
238 } |
|
239 |
|
240 /** |
|
241 * Map nsIAccessibleEvents constants to strings. Used by |
|
242 * nsIAccessibleRetrieval::getStringEventType() method. |
|
243 */ |
|
244 static const char kEventTypeNames[][40] = { |
|
245 "unknown", // |
|
246 "show", // EVENT_SHOW |
|
247 "hide", // EVENT_HIDE |
|
248 "reorder", // EVENT_REORDER |
|
249 "active decendent change", // EVENT_ACTIVE_DECENDENT_CHANGED |
|
250 "focus", // EVENT_FOCUS |
|
251 "state change", // EVENT_STATE_CHANGE |
|
252 "location change", // EVENT_LOCATION_CHANGE |
|
253 "name changed", // EVENT_NAME_CHANGE |
|
254 "description change", // EVENT_DESCRIPTION_CHANGE |
|
255 "value change", // EVENT_VALUE_CHANGE |
|
256 "help change", // EVENT_HELP_CHANGE |
|
257 "default action change", // EVENT_DEFACTION_CHANGE |
|
258 "action change", // EVENT_ACTION_CHANGE |
|
259 "accelerator change", // EVENT_ACCELERATOR_CHANGE |
|
260 "selection", // EVENT_SELECTION |
|
261 "selection add", // EVENT_SELECTION_ADD |
|
262 "selection remove", // EVENT_SELECTION_REMOVE |
|
263 "selection within", // EVENT_SELECTION_WITHIN |
|
264 "alert", // EVENT_ALERT |
|
265 "foreground", // EVENT_FOREGROUND |
|
266 "menu start", // EVENT_MENU_START |
|
267 "menu end", // EVENT_MENU_END |
|
268 "menupopup start", // EVENT_MENUPOPUP_START |
|
269 "menupopup end", // EVENT_MENUPOPUP_END |
|
270 "capture start", // EVENT_CAPTURE_START |
|
271 "capture end", // EVENT_CAPTURE_END |
|
272 "movesize start", // EVENT_MOVESIZE_START |
|
273 "movesize end", // EVENT_MOVESIZE_END |
|
274 "contexthelp start", // EVENT_CONTEXTHELP_START |
|
275 "contexthelp end", // EVENT_CONTEXTHELP_END |
|
276 "dragdrop start", // EVENT_DRAGDROP_START |
|
277 "dragdrop end", // EVENT_DRAGDROP_END |
|
278 "dialog start", // EVENT_DIALOG_START |
|
279 "dialog end", // EVENT_DIALOG_END |
|
280 "scrolling start", // EVENT_SCROLLING_START |
|
281 "scrolling end", // EVENT_SCROLLING_END |
|
282 "minimize start", // EVENT_MINIMIZE_START |
|
283 "minimize end", // EVENT_MINIMIZE_END |
|
284 "document load complete", // EVENT_DOCUMENT_LOAD_COMPLETE |
|
285 "document reload", // EVENT_DOCUMENT_RELOAD |
|
286 "document load stopped", // EVENT_DOCUMENT_LOAD_STOPPED |
|
287 "document attributes changed", // EVENT_DOCUMENT_ATTRIBUTES_CHANGED |
|
288 "document content changed", // EVENT_DOCUMENT_CONTENT_CHANGED |
|
289 "property changed", // EVENT_PROPERTY_CHANGED |
|
290 "page changed", // EVENT_PAGE_CHANGED |
|
291 "text attribute changed", // EVENT_TEXT_ATTRIBUTE_CHANGED |
|
292 "text caret moved", // EVENT_TEXT_CARET_MOVED |
|
293 "text changed", // EVENT_TEXT_CHANGED |
|
294 "text inserted", // EVENT_TEXT_INSERTED |
|
295 "text removed", // EVENT_TEXT_REMOVED |
|
296 "text updated", // EVENT_TEXT_UPDATED |
|
297 "text selection changed", // EVENT_TEXT_SELECTION_CHANGED |
|
298 "visible data changed", // EVENT_VISIBLE_DATA_CHANGED |
|
299 "text column changed", // EVENT_TEXT_COLUMN_CHANGED |
|
300 "section changed", // EVENT_SECTION_CHANGED |
|
301 "table caption changed", // EVENT_TABLE_CAPTION_CHANGED |
|
302 "table model changed", // EVENT_TABLE_MODEL_CHANGED |
|
303 "table summary changed", // EVENT_TABLE_SUMMARY_CHANGED |
|
304 "table row description changed", // EVENT_TABLE_ROW_DESCRIPTION_CHANGED |
|
305 "table row header changed", // EVENT_TABLE_ROW_HEADER_CHANGED |
|
306 "table row insert", // EVENT_TABLE_ROW_INSERT |
|
307 "table row delete", // EVENT_TABLE_ROW_DELETE |
|
308 "table row reorder", // EVENT_TABLE_ROW_REORDER |
|
309 "table column description changed", // EVENT_TABLE_COLUMN_DESCRIPTION_CHANGED |
|
310 "table column header changed", // EVENT_TABLE_COLUMN_HEADER_CHANGED |
|
311 "table column insert", // EVENT_TABLE_COLUMN_INSERT |
|
312 "table column delete", // EVENT_TABLE_COLUMN_DELETE |
|
313 "table column reorder", // EVENT_TABLE_COLUMN_REORDER |
|
314 "window activate", // EVENT_WINDOW_ACTIVATE |
|
315 "window create", // EVENT_WINDOW_CREATE |
|
316 "window deactivate", // EVENT_WINDOW_DEACTIVATE |
|
317 "window destroy", // EVENT_WINDOW_DESTROY |
|
318 "window maximize", // EVENT_WINDOW_MAXIMIZE |
|
319 "window minimize", // EVENT_WINDOW_MINIMIZE |
|
320 "window resize", // EVENT_WINDOW_RESIZE |
|
321 "window restore", // EVENT_WINDOW_RESTORE |
|
322 "hyperlink end index changed", // EVENT_HYPERLINK_END_INDEX_CHANGED |
|
323 "hyperlink number of anchors changed", // EVENT_HYPERLINK_NUMBER_OF_ANCHORS_CHANGED |
|
324 "hyperlink selected link changed", // EVENT_HYPERLINK_SELECTED_LINK_CHANGED |
|
325 "hypertext link activated", // EVENT_HYPERTEXT_LINK_ACTIVATED |
|
326 "hypertext link selected", // EVENT_HYPERTEXT_LINK_SELECTED |
|
327 "hyperlink start index changed", // EVENT_HYPERLINK_START_INDEX_CHANGED |
|
328 "hypertext changed", // EVENT_HYPERTEXT_CHANGED |
|
329 "hypertext links count changed", // EVENT_HYPERTEXT_NLINKS_CHANGED |
|
330 "object attribute changed", // EVENT_OBJECT_ATTRIBUTE_CHANGED |
|
331 "virtual cursor changed" // EVENT_VIRTUALCURSOR_CHANGED |
|
332 }; |
|
333 |
|
334 #endif /* __nsIAccessibilityService_h__ */ |
|
335 |