1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/base/nsAccessibilityService.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,335 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef __nsAccessibilityService_h__ 1.10 +#define __nsAccessibilityService_h__ 1.11 + 1.12 +#include "nsIAccessibilityService.h" 1.13 + 1.14 +#include "mozilla/a11y/DocManager.h" 1.15 +#include "mozilla/a11y/FocusManager.h" 1.16 +#include "mozilla/a11y/SelectionManager.h" 1.17 + 1.18 +#include "nsIObserver.h" 1.19 + 1.20 +class nsImageFrame; 1.21 +class nsObjectFrame; 1.22 +class nsITreeView; 1.23 + 1.24 +namespace mozilla { 1.25 +namespace a11y { 1.26 + 1.27 +class ApplicationAccessible; 1.28 + 1.29 +/** 1.30 + * Return focus manager. 1.31 + */ 1.32 +FocusManager* FocusMgr(); 1.33 + 1.34 +/** 1.35 + * Return selection manager. 1.36 + */ 1.37 +SelectionManager* SelectionMgr(); 1.38 + 1.39 +/** 1.40 + * Returns the application accessible. 1.41 + */ 1.42 +ApplicationAccessible* ApplicationAcc(); 1.43 + 1.44 +} // namespace a11y 1.45 +} // namespace mozilla 1.46 + 1.47 +class nsAccessibilityService : public mozilla::a11y::DocManager, 1.48 + public mozilla::a11y::FocusManager, 1.49 + public mozilla::a11y::SelectionManager, 1.50 + public nsIAccessibilityService, 1.51 + public nsIObserver 1.52 +{ 1.53 +public: 1.54 + typedef mozilla::a11y::Accessible Accessible; 1.55 + typedef mozilla::a11y::DocAccessible DocAccessible; 1.56 + 1.57 + virtual ~nsAccessibilityService(); 1.58 + 1.59 + NS_DECL_ISUPPORTS_INHERITED 1.60 + NS_DECL_NSIACCESSIBLERETRIEVAL 1.61 + NS_DECL_NSIOBSERVER 1.62 + 1.63 + // nsIAccessibilityService 1.64 + virtual Accessible* GetRootDocumentAccessible(nsIPresShell* aPresShell, 1.65 + bool aCanCreate); 1.66 + already_AddRefed<Accessible> 1.67 + CreatePluginAccessible(nsObjectFrame* aFrame, nsIContent* aContent, 1.68 + Accessible* aContext); 1.69 + 1.70 + /** 1.71 + * Adds/remove ATK root accessible for gtk+ native window to/from children 1.72 + * of the application accessible. 1.73 + */ 1.74 + virtual Accessible* AddNativeRootAccessible(void* aAtkAccessible); 1.75 + virtual void RemoveNativeRootAccessible(Accessible* aRootAccessible); 1.76 + 1.77 + /** 1.78 + * Notification used to update the accessible tree when deck panel is 1.79 + * switched. 1.80 + */ 1.81 + void DeckPanelSwitched(nsIPresShell* aPresShell, nsIContent* aDeckNode, 1.82 + nsIFrame* aPrevBoxFrame, nsIFrame* aCurrentBoxFrame); 1.83 + 1.84 + /** 1.85 + * Notification used to update the accessible tree when new content is 1.86 + * inserted. 1.87 + */ 1.88 + void ContentRangeInserted(nsIPresShell* aPresShell, nsIContent* aContainer, 1.89 + nsIContent* aStartChild, nsIContent* aEndChild); 1.90 + 1.91 + /** 1.92 + * Notification used to update the accessible tree when content is removed. 1.93 + */ 1.94 + void ContentRemoved(nsIPresShell* aPresShell, nsIContent* aContainer, 1.95 + nsIContent* aChild); 1.96 + 1.97 + virtual void UpdateText(nsIPresShell* aPresShell, nsIContent* aContent); 1.98 + 1.99 + /** 1.100 + * Update XUL:tree accessible tree when treeview is changed. 1.101 + */ 1.102 + void TreeViewChanged(nsIPresShell* aPresShell, nsIContent* aContent, 1.103 + nsITreeView* aView); 1.104 + 1.105 + /** 1.106 + * Notify of input@type="element" value change. 1.107 + */ 1.108 + void RangeValueChanged(nsIPresShell* aPresShell, nsIContent* aContent); 1.109 + 1.110 + /** 1.111 + * Update list bullet accessible. 1.112 + */ 1.113 + virtual void UpdateListBullet(nsIPresShell* aPresShell, 1.114 + nsIContent* aHTMLListItemContent, 1.115 + bool aHasBullet); 1.116 + 1.117 + /** 1.118 + * Update the image map. 1.119 + */ 1.120 + void UpdateImageMap(nsImageFrame* aImageFrame); 1.121 + 1.122 + /** 1.123 + * Update the label accessible tree when rendered @value is changed. 1.124 + */ 1.125 + void UpdateLabelValue(nsIPresShell* aPresShell, nsIContent* aLabelElm, 1.126 + const nsString& aNewValue); 1.127 + 1.128 + /** 1.129 + * Notify accessibility that anchor jump has been accomplished to the given 1.130 + * target. Used by layout. 1.131 + */ 1.132 + void NotifyOfAnchorJumpTo(nsIContent *aTarget); 1.133 + 1.134 + /** 1.135 + * Notify that presshell is activated. 1.136 + */ 1.137 + virtual void PresShellActivated(nsIPresShell* aPresShell); 1.138 + 1.139 + /** 1.140 + * Recreate an accessible for the given content node in the presshell. 1.141 + */ 1.142 + void RecreateAccessible(nsIPresShell* aPresShell, nsIContent* aContent); 1.143 + 1.144 + virtual void FireAccessibleEvent(uint32_t aEvent, Accessible* aTarget); 1.145 + 1.146 + // nsAccessibiltiyService 1.147 + 1.148 + /** 1.149 + * Return true if accessibility service has been shutdown. 1.150 + */ 1.151 + static bool IsShutdown() { return gIsShutdown; } 1.152 + 1.153 + /** 1.154 + * Return an accessible for the given DOM node from the cache or create new 1.155 + * one. 1.156 + * 1.157 + * @param aNode [in] the given node 1.158 + * @param aContext [in] context the accessible is created in 1.159 + * @param aIsSubtreeHidden [out, optional] indicates whether the node's 1.160 + * frame and its subtree is hidden 1.161 + */ 1.162 + Accessible* GetOrCreateAccessible(nsINode* aNode, Accessible* aContext, 1.163 + bool* aIsSubtreeHidden = nullptr); 1.164 + 1.165 +private: 1.166 + // nsAccessibilityService creation is controlled by friend 1.167 + // NS_GetAccessibilityService, keep constructors private. 1.168 + nsAccessibilityService(); 1.169 + nsAccessibilityService(const nsAccessibilityService&); 1.170 + nsAccessibilityService& operator =(const nsAccessibilityService&); 1.171 + 1.172 +private: 1.173 + /** 1.174 + * Initialize accessibility service. 1.175 + */ 1.176 + bool Init(); 1.177 + 1.178 + /** 1.179 + * Shutdowns accessibility service. 1.180 + */ 1.181 + void Shutdown(); 1.182 + 1.183 + /** 1.184 + * Create accessible for the element having XBL bindings. 1.185 + */ 1.186 + already_AddRefed<Accessible> 1.187 + CreateAccessibleByType(nsIContent* aContent, DocAccessible* aDoc); 1.188 + 1.189 + /** 1.190 + * Create accessible for HTML node by tag name. 1.191 + */ 1.192 + already_AddRefed<Accessible> 1.193 + CreateHTMLAccessibleByMarkup(nsIFrame* aFrame, nsIContent* aContent, 1.194 + Accessible* aContext); 1.195 + 1.196 + /** 1.197 + * Create an accessible whose type depends on the given frame. 1.198 + */ 1.199 + already_AddRefed<Accessible> 1.200 + CreateAccessibleByFrameType(nsIFrame* aFrame, nsIContent* aContent, 1.201 + Accessible* aContext); 1.202 + 1.203 +#ifdef MOZ_XUL 1.204 + /** 1.205 + * Create accessible for XUL tree element. 1.206 + */ 1.207 + already_AddRefed<Accessible> 1.208 + CreateAccessibleForXULTree(nsIContent* aContent, DocAccessible* aDoc); 1.209 +#endif 1.210 + 1.211 + /** 1.212 + * Reference for accessibility service instance. 1.213 + */ 1.214 + static nsAccessibilityService* gAccessibilityService; 1.215 + 1.216 + /** 1.217 + * Reference for application accessible instance. 1.218 + */ 1.219 + static mozilla::a11y::ApplicationAccessible* gApplicationAccessible; 1.220 + 1.221 + /** 1.222 + * Indicates whether accessibility service was shutdown. 1.223 + */ 1.224 + static bool gIsShutdown; 1.225 + 1.226 + friend nsAccessibilityService* GetAccService(); 1.227 + friend mozilla::a11y::FocusManager* mozilla::a11y::FocusMgr(); 1.228 + friend mozilla::a11y::SelectionManager* mozilla::a11y::SelectionMgr(); 1.229 + friend mozilla::a11y::ApplicationAccessible* mozilla::a11y::ApplicationAcc(); 1.230 + 1.231 + friend nsresult NS_GetAccessibilityService(nsIAccessibilityService** aResult); 1.232 +}; 1.233 + 1.234 +/** 1.235 + * Return the accessibility service instance. (Handy global function) 1.236 + */ 1.237 +inline nsAccessibilityService* 1.238 +GetAccService() 1.239 +{ 1.240 + return nsAccessibilityService::gAccessibilityService; 1.241 +} 1.242 + 1.243 +/** 1.244 + * Map nsIAccessibleEvents constants to strings. Used by 1.245 + * nsIAccessibleRetrieval::getStringEventType() method. 1.246 + */ 1.247 +static const char kEventTypeNames[][40] = { 1.248 + "unknown", // 1.249 + "show", // EVENT_SHOW 1.250 + "hide", // EVENT_HIDE 1.251 + "reorder", // EVENT_REORDER 1.252 + "active decendent change", // EVENT_ACTIVE_DECENDENT_CHANGED 1.253 + "focus", // EVENT_FOCUS 1.254 + "state change", // EVENT_STATE_CHANGE 1.255 + "location change", // EVENT_LOCATION_CHANGE 1.256 + "name changed", // EVENT_NAME_CHANGE 1.257 + "description change", // EVENT_DESCRIPTION_CHANGE 1.258 + "value change", // EVENT_VALUE_CHANGE 1.259 + "help change", // EVENT_HELP_CHANGE 1.260 + "default action change", // EVENT_DEFACTION_CHANGE 1.261 + "action change", // EVENT_ACTION_CHANGE 1.262 + "accelerator change", // EVENT_ACCELERATOR_CHANGE 1.263 + "selection", // EVENT_SELECTION 1.264 + "selection add", // EVENT_SELECTION_ADD 1.265 + "selection remove", // EVENT_SELECTION_REMOVE 1.266 + "selection within", // EVENT_SELECTION_WITHIN 1.267 + "alert", // EVENT_ALERT 1.268 + "foreground", // EVENT_FOREGROUND 1.269 + "menu start", // EVENT_MENU_START 1.270 + "menu end", // EVENT_MENU_END 1.271 + "menupopup start", // EVENT_MENUPOPUP_START 1.272 + "menupopup end", // EVENT_MENUPOPUP_END 1.273 + "capture start", // EVENT_CAPTURE_START 1.274 + "capture end", // EVENT_CAPTURE_END 1.275 + "movesize start", // EVENT_MOVESIZE_START 1.276 + "movesize end", // EVENT_MOVESIZE_END 1.277 + "contexthelp start", // EVENT_CONTEXTHELP_START 1.278 + "contexthelp end", // EVENT_CONTEXTHELP_END 1.279 + "dragdrop start", // EVENT_DRAGDROP_START 1.280 + "dragdrop end", // EVENT_DRAGDROP_END 1.281 + "dialog start", // EVENT_DIALOG_START 1.282 + "dialog end", // EVENT_DIALOG_END 1.283 + "scrolling start", // EVENT_SCROLLING_START 1.284 + "scrolling end", // EVENT_SCROLLING_END 1.285 + "minimize start", // EVENT_MINIMIZE_START 1.286 + "minimize end", // EVENT_MINIMIZE_END 1.287 + "document load complete", // EVENT_DOCUMENT_LOAD_COMPLETE 1.288 + "document reload", // EVENT_DOCUMENT_RELOAD 1.289 + "document load stopped", // EVENT_DOCUMENT_LOAD_STOPPED 1.290 + "document attributes changed", // EVENT_DOCUMENT_ATTRIBUTES_CHANGED 1.291 + "document content changed", // EVENT_DOCUMENT_CONTENT_CHANGED 1.292 + "property changed", // EVENT_PROPERTY_CHANGED 1.293 + "page changed", // EVENT_PAGE_CHANGED 1.294 + "text attribute changed", // EVENT_TEXT_ATTRIBUTE_CHANGED 1.295 + "text caret moved", // EVENT_TEXT_CARET_MOVED 1.296 + "text changed", // EVENT_TEXT_CHANGED 1.297 + "text inserted", // EVENT_TEXT_INSERTED 1.298 + "text removed", // EVENT_TEXT_REMOVED 1.299 + "text updated", // EVENT_TEXT_UPDATED 1.300 + "text selection changed", // EVENT_TEXT_SELECTION_CHANGED 1.301 + "visible data changed", // EVENT_VISIBLE_DATA_CHANGED 1.302 + "text column changed", // EVENT_TEXT_COLUMN_CHANGED 1.303 + "section changed", // EVENT_SECTION_CHANGED 1.304 + "table caption changed", // EVENT_TABLE_CAPTION_CHANGED 1.305 + "table model changed", // EVENT_TABLE_MODEL_CHANGED 1.306 + "table summary changed", // EVENT_TABLE_SUMMARY_CHANGED 1.307 + "table row description changed", // EVENT_TABLE_ROW_DESCRIPTION_CHANGED 1.308 + "table row header changed", // EVENT_TABLE_ROW_HEADER_CHANGED 1.309 + "table row insert", // EVENT_TABLE_ROW_INSERT 1.310 + "table row delete", // EVENT_TABLE_ROW_DELETE 1.311 + "table row reorder", // EVENT_TABLE_ROW_REORDER 1.312 + "table column description changed", // EVENT_TABLE_COLUMN_DESCRIPTION_CHANGED 1.313 + "table column header changed", // EVENT_TABLE_COLUMN_HEADER_CHANGED 1.314 + "table column insert", // EVENT_TABLE_COLUMN_INSERT 1.315 + "table column delete", // EVENT_TABLE_COLUMN_DELETE 1.316 + "table column reorder", // EVENT_TABLE_COLUMN_REORDER 1.317 + "window activate", // EVENT_WINDOW_ACTIVATE 1.318 + "window create", // EVENT_WINDOW_CREATE 1.319 + "window deactivate", // EVENT_WINDOW_DEACTIVATE 1.320 + "window destroy", // EVENT_WINDOW_DESTROY 1.321 + "window maximize", // EVENT_WINDOW_MAXIMIZE 1.322 + "window minimize", // EVENT_WINDOW_MINIMIZE 1.323 + "window resize", // EVENT_WINDOW_RESIZE 1.324 + "window restore", // EVENT_WINDOW_RESTORE 1.325 + "hyperlink end index changed", // EVENT_HYPERLINK_END_INDEX_CHANGED 1.326 + "hyperlink number of anchors changed", // EVENT_HYPERLINK_NUMBER_OF_ANCHORS_CHANGED 1.327 + "hyperlink selected link changed", // EVENT_HYPERLINK_SELECTED_LINK_CHANGED 1.328 + "hypertext link activated", // EVENT_HYPERTEXT_LINK_ACTIVATED 1.329 + "hypertext link selected", // EVENT_HYPERTEXT_LINK_SELECTED 1.330 + "hyperlink start index changed", // EVENT_HYPERLINK_START_INDEX_CHANGED 1.331 + "hypertext changed", // EVENT_HYPERTEXT_CHANGED 1.332 + "hypertext links count changed", // EVENT_HYPERTEXT_NLINKS_CHANGED 1.333 + "object attribute changed", // EVENT_OBJECT_ATTRIBUTE_CHANGED 1.334 + "virtual cursor changed" // EVENT_VIRTUALCURSOR_CHANGED 1.335 +}; 1.336 + 1.337 +#endif /* __nsIAccessibilityService_h__ */ 1.338 +