Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef mozilla_a11y_DocAccessible_h__ |
michael@0 | 7 | #define mozilla_a11y_DocAccessible_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsIAccessibleDocument.h" |
michael@0 | 10 | #include "nsIAccessiblePivot.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "AccEvent.h" |
michael@0 | 13 | #include "HyperTextAccessibleWrap.h" |
michael@0 | 14 | |
michael@0 | 15 | #include "nsClassHashtable.h" |
michael@0 | 16 | #include "nsDataHashtable.h" |
michael@0 | 17 | #include "nsIDocument.h" |
michael@0 | 18 | #include "nsIDocumentObserver.h" |
michael@0 | 19 | #include "nsIEditor.h" |
michael@0 | 20 | #include "nsIObserver.h" |
michael@0 | 21 | #include "nsIScrollPositionListener.h" |
michael@0 | 22 | #include "nsITimer.h" |
michael@0 | 23 | #include "nsIWeakReference.h" |
michael@0 | 24 | |
michael@0 | 25 | class nsAccessiblePivot; |
michael@0 | 26 | |
michael@0 | 27 | class nsIScrollableView; |
michael@0 | 28 | |
michael@0 | 29 | const uint32_t kDefaultCacheSize = 256; |
michael@0 | 30 | |
michael@0 | 31 | namespace mozilla { |
michael@0 | 32 | namespace a11y { |
michael@0 | 33 | |
michael@0 | 34 | class DocManager; |
michael@0 | 35 | class NotificationController; |
michael@0 | 36 | class RelatedAccIterator; |
michael@0 | 37 | template<class Class, class Arg> |
michael@0 | 38 | class TNotification; |
michael@0 | 39 | |
michael@0 | 40 | class DocAccessible : public HyperTextAccessibleWrap, |
michael@0 | 41 | public nsIAccessibleDocument, |
michael@0 | 42 | public nsIDocumentObserver, |
michael@0 | 43 | public nsIObserver, |
michael@0 | 44 | public nsIScrollPositionListener, |
michael@0 | 45 | public nsSupportsWeakReference, |
michael@0 | 46 | public nsIAccessiblePivotObserver |
michael@0 | 47 | { |
michael@0 | 48 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 49 | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DocAccessible, Accessible) |
michael@0 | 50 | |
michael@0 | 51 | NS_DECL_NSIACCESSIBLEDOCUMENT |
michael@0 | 52 | |
michael@0 | 53 | NS_DECL_NSIOBSERVER |
michael@0 | 54 | |
michael@0 | 55 | NS_DECL_NSIACCESSIBLEPIVOTOBSERVER |
michael@0 | 56 | |
michael@0 | 57 | public: |
michael@0 | 58 | |
michael@0 | 59 | DocAccessible(nsIDocument* aDocument, nsIContent* aRootContent, |
michael@0 | 60 | nsIPresShell* aPresShell); |
michael@0 | 61 | virtual ~DocAccessible(); |
michael@0 | 62 | |
michael@0 | 63 | // nsIAccessible |
michael@0 | 64 | NS_IMETHOD TakeFocus(void); |
michael@0 | 65 | |
michael@0 | 66 | // nsIScrollPositionListener |
michael@0 | 67 | virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) {} |
michael@0 | 68 | virtual void ScrollPositionDidChange(nscoord aX, nscoord aY); |
michael@0 | 69 | |
michael@0 | 70 | // nsIDocumentObserver |
michael@0 | 71 | NS_DECL_NSIDOCUMENTOBSERVER |
michael@0 | 72 | |
michael@0 | 73 | // Accessible |
michael@0 | 74 | virtual void Init(); |
michael@0 | 75 | virtual void Shutdown(); |
michael@0 | 76 | virtual nsIFrame* GetFrame() const; |
michael@0 | 77 | virtual nsINode* GetNode() const { return mDocumentNode; } |
michael@0 | 78 | nsIDocument* DocumentNode() const { return mDocumentNode; } |
michael@0 | 79 | |
michael@0 | 80 | virtual mozilla::a11y::ENameValueFlag Name(nsString& aName); |
michael@0 | 81 | virtual void Description(nsString& aDescription); |
michael@0 | 82 | virtual Accessible* FocusedChild(); |
michael@0 | 83 | virtual mozilla::a11y::role NativeRole(); |
michael@0 | 84 | virtual uint64_t NativeState(); |
michael@0 | 85 | virtual uint64_t NativeInteractiveState() const; |
michael@0 | 86 | virtual bool NativelyUnavailable() const; |
michael@0 | 87 | virtual void ApplyARIAState(uint64_t* aState) const; |
michael@0 | 88 | virtual already_AddRefed<nsIPersistentProperties> Attributes(); |
michael@0 | 89 | |
michael@0 | 90 | #ifdef A11Y_LOG |
michael@0 | 91 | virtual nsresult HandleAccEvent(AccEvent* aEvent); |
michael@0 | 92 | #endif |
michael@0 | 93 | |
michael@0 | 94 | virtual void GetBoundsRect(nsRect& aRect, nsIFrame** aRelativeFrame); |
michael@0 | 95 | |
michael@0 | 96 | // HyperTextAccessible |
michael@0 | 97 | virtual already_AddRefed<nsIEditor> GetEditor() const; |
michael@0 | 98 | |
michael@0 | 99 | // DocAccessible |
michael@0 | 100 | |
michael@0 | 101 | /** |
michael@0 | 102 | * Return presentation shell for this document accessible. |
michael@0 | 103 | */ |
michael@0 | 104 | nsIPresShell* PresShell() const { return mPresShell; } |
michael@0 | 105 | |
michael@0 | 106 | /** |
michael@0 | 107 | * Return the presentation shell's context. |
michael@0 | 108 | */ |
michael@0 | 109 | nsPresContext* PresContext() const { return mPresShell->GetPresContext(); } |
michael@0 | 110 | |
michael@0 | 111 | /** |
michael@0 | 112 | * Return true if associated DOM document was loaded and isn't unloading. |
michael@0 | 113 | */ |
michael@0 | 114 | bool IsContentLoaded() const |
michael@0 | 115 | { |
michael@0 | 116 | // eDOMLoaded flag check is used for error pages as workaround to make this |
michael@0 | 117 | // method return correct result since error pages do not receive 'pageshow' |
michael@0 | 118 | // event and as consequence nsIDocument::IsShowing() returns false. |
michael@0 | 119 | return mDocumentNode && mDocumentNode->IsVisible() && |
michael@0 | 120 | (mDocumentNode->IsShowing() || HasLoadState(eDOMLoaded)); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | /** |
michael@0 | 124 | * Document load states. |
michael@0 | 125 | */ |
michael@0 | 126 | enum LoadState { |
michael@0 | 127 | // initial tree construction is pending |
michael@0 | 128 | eTreeConstructionPending = 0, |
michael@0 | 129 | // initial tree construction done |
michael@0 | 130 | eTreeConstructed = 1, |
michael@0 | 131 | // DOM document is loaded. |
michael@0 | 132 | eDOMLoaded = 1 << 1, |
michael@0 | 133 | // document is ready |
michael@0 | 134 | eReady = eTreeConstructed | eDOMLoaded, |
michael@0 | 135 | // document and all its subdocuments are ready |
michael@0 | 136 | eCompletelyLoaded = eReady | 1 << 2 |
michael@0 | 137 | }; |
michael@0 | 138 | |
michael@0 | 139 | /** |
michael@0 | 140 | * Return true if the document has given document state. |
michael@0 | 141 | */ |
michael@0 | 142 | bool HasLoadState(LoadState aState) const |
michael@0 | 143 | { return (mLoadState & static_cast<uint32_t>(aState)) == |
michael@0 | 144 | static_cast<uint32_t>(aState); } |
michael@0 | 145 | |
michael@0 | 146 | /** |
michael@0 | 147 | * Return a native window handler or pointer depending on platform. |
michael@0 | 148 | */ |
michael@0 | 149 | virtual void* GetNativeWindow() const; |
michael@0 | 150 | |
michael@0 | 151 | /** |
michael@0 | 152 | * Return the parent document. |
michael@0 | 153 | */ |
michael@0 | 154 | DocAccessible* ParentDocument() const |
michael@0 | 155 | { return mParent ? mParent->Document() : nullptr; } |
michael@0 | 156 | |
michael@0 | 157 | /** |
michael@0 | 158 | * Return the child document count. |
michael@0 | 159 | */ |
michael@0 | 160 | uint32_t ChildDocumentCount() const |
michael@0 | 161 | { return mChildDocuments.Length(); } |
michael@0 | 162 | |
michael@0 | 163 | /** |
michael@0 | 164 | * Return the child document at the given index. |
michael@0 | 165 | */ |
michael@0 | 166 | DocAccessible* GetChildDocumentAt(uint32_t aIndex) const |
michael@0 | 167 | { return mChildDocuments.SafeElementAt(aIndex, nullptr); } |
michael@0 | 168 | |
michael@0 | 169 | /** |
michael@0 | 170 | * Fire accessible event asynchronously. |
michael@0 | 171 | */ |
michael@0 | 172 | void FireDelayedEvent(AccEvent* aEvent); |
michael@0 | 173 | void FireDelayedEvent(uint32_t aEventType, Accessible* aTarget); |
michael@0 | 174 | |
michael@0 | 175 | /** |
michael@0 | 176 | * Fire value change event on the given accessible if applicable. |
michael@0 | 177 | */ |
michael@0 | 178 | void MaybeNotifyOfValueChange(Accessible* aAccessible); |
michael@0 | 179 | |
michael@0 | 180 | /** |
michael@0 | 181 | * Get/set the anchor jump. |
michael@0 | 182 | */ |
michael@0 | 183 | Accessible* AnchorJump() |
michael@0 | 184 | { return GetAccessibleOrContainer(mAnchorJumpElm); } |
michael@0 | 185 | |
michael@0 | 186 | void SetAnchorJump(nsIContent* aTargetNode) |
michael@0 | 187 | { mAnchorJumpElm = aTargetNode; } |
michael@0 | 188 | |
michael@0 | 189 | /** |
michael@0 | 190 | * Bind the child document to the tree. |
michael@0 | 191 | */ |
michael@0 | 192 | void BindChildDocument(DocAccessible* aDocument); |
michael@0 | 193 | |
michael@0 | 194 | /** |
michael@0 | 195 | * Process the generic notification. |
michael@0 | 196 | * |
michael@0 | 197 | * @note The caller must guarantee that the given instance still exists when |
michael@0 | 198 | * notification is processed. |
michael@0 | 199 | * @see NotificationController::HandleNotification |
michael@0 | 200 | */ |
michael@0 | 201 | template<class Class, class Arg> |
michael@0 | 202 | void HandleNotification(Class* aInstance, |
michael@0 | 203 | typename TNotification<Class, Arg>::Callback aMethod, |
michael@0 | 204 | Arg* aArg); |
michael@0 | 205 | |
michael@0 | 206 | /** |
michael@0 | 207 | * Return the cached accessible by the given DOM node if it's in subtree of |
michael@0 | 208 | * this document accessible or the document accessible itself, otherwise null. |
michael@0 | 209 | * |
michael@0 | 210 | * @return the accessible object |
michael@0 | 211 | */ |
michael@0 | 212 | Accessible* GetAccessible(nsINode* aNode) const; |
michael@0 | 213 | |
michael@0 | 214 | /** |
michael@0 | 215 | * Return an accessible for the given node even if the node is not in |
michael@0 | 216 | * document's node map cache (like HTML area element). |
michael@0 | 217 | * |
michael@0 | 218 | * XXX: it should be really merged with GetAccessible(). |
michael@0 | 219 | */ |
michael@0 | 220 | Accessible* GetAccessibleEvenIfNotInMap(nsINode* aNode) const; |
michael@0 | 221 | Accessible* GetAccessibleEvenIfNotInMapOrContainer(nsINode* aNode) const; |
michael@0 | 222 | |
michael@0 | 223 | /** |
michael@0 | 224 | * Return whether the given DOM node has an accessible or not. |
michael@0 | 225 | */ |
michael@0 | 226 | bool HasAccessible(nsINode* aNode) const |
michael@0 | 227 | { return GetAccessible(aNode); } |
michael@0 | 228 | |
michael@0 | 229 | /** |
michael@0 | 230 | * Return the cached accessible by the given unique ID within this document. |
michael@0 | 231 | * |
michael@0 | 232 | * @note the unique ID matches with the uniqueID() of Accessible |
michael@0 | 233 | * |
michael@0 | 234 | * @param aUniqueID [in] the unique ID used to cache the node. |
michael@0 | 235 | */ |
michael@0 | 236 | Accessible* GetAccessibleByUniqueID(void* aUniqueID) |
michael@0 | 237 | { |
michael@0 | 238 | return UniqueID() == aUniqueID ? |
michael@0 | 239 | this : mAccessibleCache.GetWeak(aUniqueID); |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | /** |
michael@0 | 243 | * Return the cached accessible by the given unique ID looking through |
michael@0 | 244 | * this and nested documents. |
michael@0 | 245 | */ |
michael@0 | 246 | Accessible* GetAccessibleByUniqueIDInSubtree(void* aUniqueID); |
michael@0 | 247 | |
michael@0 | 248 | /** |
michael@0 | 249 | * Return an accessible for the given DOM node or container accessible if |
michael@0 | 250 | * the node is not accessible. |
michael@0 | 251 | */ |
michael@0 | 252 | Accessible* GetAccessibleOrContainer(nsINode* aNode) const; |
michael@0 | 253 | |
michael@0 | 254 | /** |
michael@0 | 255 | * Return a container accessible for the given DOM node. |
michael@0 | 256 | */ |
michael@0 | 257 | Accessible* GetContainerAccessible(nsINode* aNode) const |
michael@0 | 258 | { |
michael@0 | 259 | return aNode ? GetAccessibleOrContainer(aNode->GetParentNode()) : nullptr; |
michael@0 | 260 | } |
michael@0 | 261 | |
michael@0 | 262 | /** |
michael@0 | 263 | * Return an accessible for the given node or its first accessible descendant. |
michael@0 | 264 | */ |
michael@0 | 265 | Accessible* GetAccessibleOrDescendant(nsINode* aNode) const; |
michael@0 | 266 | |
michael@0 | 267 | /** |
michael@0 | 268 | * Return true if the given ID is referred by relation attribute. |
michael@0 | 269 | * |
michael@0 | 270 | * @note Different elements may share the same ID if they are hosted inside |
michael@0 | 271 | * XBL bindings. Be careful the result of this method may be senseless |
michael@0 | 272 | * while it's called for XUL elements (where XBL is used widely). |
michael@0 | 273 | */ |
michael@0 | 274 | bool IsDependentID(const nsAString& aID) const |
michael@0 | 275 | { return mDependentIDsHash.Get(aID, nullptr); } |
michael@0 | 276 | |
michael@0 | 277 | /** |
michael@0 | 278 | * Initialize the newly created accessible and put it into document caches. |
michael@0 | 279 | * |
michael@0 | 280 | * @param aAccessible [in] created accessible |
michael@0 | 281 | * @param aRoleMapEntry [in] the role map entry role the ARIA role or nullptr |
michael@0 | 282 | * if none |
michael@0 | 283 | */ |
michael@0 | 284 | void BindToDocument(Accessible* aAccessible, nsRoleMapEntry* aRoleMapEntry); |
michael@0 | 285 | |
michael@0 | 286 | /** |
michael@0 | 287 | * Remove from document and shutdown the given accessible. |
michael@0 | 288 | */ |
michael@0 | 289 | void UnbindFromDocument(Accessible* aAccessible); |
michael@0 | 290 | |
michael@0 | 291 | /** |
michael@0 | 292 | * Notify the document accessible that content was inserted. |
michael@0 | 293 | */ |
michael@0 | 294 | void ContentInserted(nsIContent* aContainerNode, |
michael@0 | 295 | nsIContent* aStartChildNode, |
michael@0 | 296 | nsIContent* aEndChildNode); |
michael@0 | 297 | |
michael@0 | 298 | /** |
michael@0 | 299 | * Notify the document accessible that content was removed. |
michael@0 | 300 | */ |
michael@0 | 301 | void ContentRemoved(nsIContent* aContainerNode, nsIContent* aChildNode); |
michael@0 | 302 | |
michael@0 | 303 | /** |
michael@0 | 304 | * Updates accessible tree when rendered text is changed. |
michael@0 | 305 | */ |
michael@0 | 306 | void UpdateText(nsIContent* aTextNode); |
michael@0 | 307 | |
michael@0 | 308 | /** |
michael@0 | 309 | * Recreate an accessible, results in hide/show events pair. |
michael@0 | 310 | */ |
michael@0 | 311 | void RecreateAccessible(nsIContent* aContent); |
michael@0 | 312 | |
michael@0 | 313 | protected: |
michael@0 | 314 | |
michael@0 | 315 | void LastRelease(); |
michael@0 | 316 | |
michael@0 | 317 | // Accessible |
michael@0 | 318 | virtual void CacheChildren(); |
michael@0 | 319 | |
michael@0 | 320 | // DocAccessible |
michael@0 | 321 | virtual nsresult AddEventListeners(); |
michael@0 | 322 | virtual nsresult RemoveEventListeners(); |
michael@0 | 323 | |
michael@0 | 324 | /** |
michael@0 | 325 | * Marks this document as loaded or loading. |
michael@0 | 326 | */ |
michael@0 | 327 | void NotifyOfLoad(uint32_t aLoadEventType); |
michael@0 | 328 | void NotifyOfLoading(bool aIsReloading); |
michael@0 | 329 | |
michael@0 | 330 | friend class DocManager; |
michael@0 | 331 | |
michael@0 | 332 | /** |
michael@0 | 333 | * Perform initial update (create accessible tree). |
michael@0 | 334 | * Can be overridden by wrappers to prepare initialization work. |
michael@0 | 335 | */ |
michael@0 | 336 | virtual void DoInitialUpdate(); |
michael@0 | 337 | |
michael@0 | 338 | /** |
michael@0 | 339 | * Process document load notification, fire document load and state busy |
michael@0 | 340 | * events if applicable. |
michael@0 | 341 | */ |
michael@0 | 342 | void ProcessLoad(); |
michael@0 | 343 | |
michael@0 | 344 | /** |
michael@0 | 345 | * Add/remove scroll listeners, @see nsIScrollPositionListener interface. |
michael@0 | 346 | */ |
michael@0 | 347 | void AddScrollListener(); |
michael@0 | 348 | void RemoveScrollListener(); |
michael@0 | 349 | |
michael@0 | 350 | /** |
michael@0 | 351 | * Append the given document accessible to this document's child document |
michael@0 | 352 | * accessibles. |
michael@0 | 353 | */ |
michael@0 | 354 | bool AppendChildDocument(DocAccessible* aChildDocument) |
michael@0 | 355 | { |
michael@0 | 356 | return mChildDocuments.AppendElement(aChildDocument); |
michael@0 | 357 | } |
michael@0 | 358 | |
michael@0 | 359 | /** |
michael@0 | 360 | * Remove the given document accessible from this document's child document |
michael@0 | 361 | * accessibles. |
michael@0 | 362 | */ |
michael@0 | 363 | void RemoveChildDocument(DocAccessible* aChildDocument) |
michael@0 | 364 | { |
michael@0 | 365 | mChildDocuments.RemoveElement(aChildDocument); |
michael@0 | 366 | } |
michael@0 | 367 | |
michael@0 | 368 | /** |
michael@0 | 369 | * Add dependent IDs pointed by accessible element by relation attribute to |
michael@0 | 370 | * cache. If the relation attribute is missed then all relation attributes |
michael@0 | 371 | * are checked. |
michael@0 | 372 | * |
michael@0 | 373 | * @param aRelProvider [in] accessible that element has relation attribute |
michael@0 | 374 | * @param aRelAttr [in, optional] relation attribute |
michael@0 | 375 | */ |
michael@0 | 376 | void AddDependentIDsFor(dom::Element* aRelProviderElm, |
michael@0 | 377 | nsIAtom* aRelAttr = nullptr); |
michael@0 | 378 | |
michael@0 | 379 | /** |
michael@0 | 380 | * Remove dependent IDs pointed by accessible element by relation attribute |
michael@0 | 381 | * from cache. If the relation attribute is absent then all relation |
michael@0 | 382 | * attributes are checked. |
michael@0 | 383 | * |
michael@0 | 384 | * @param aRelProvider [in] accessible that element has relation attribute |
michael@0 | 385 | * @param aRelAttr [in, optional] relation attribute |
michael@0 | 386 | */ |
michael@0 | 387 | void RemoveDependentIDsFor(dom::Element* aRelProviderElm, |
michael@0 | 388 | nsIAtom* aRelAttr = nullptr); |
michael@0 | 389 | |
michael@0 | 390 | /** |
michael@0 | 391 | * Update or recreate an accessible depending on a changed attribute. |
michael@0 | 392 | * |
michael@0 | 393 | * @param aElement [in] the element the attribute was changed on |
michael@0 | 394 | * @param aAttribute [in] the changed attribute |
michael@0 | 395 | * @return true if an action was taken on the attribute change |
michael@0 | 396 | */ |
michael@0 | 397 | bool UpdateAccessibleOnAttrChange(mozilla::dom::Element* aElement, |
michael@0 | 398 | nsIAtom* aAttribute); |
michael@0 | 399 | |
michael@0 | 400 | /** |
michael@0 | 401 | * Fire accessible events when attribute is changed. |
michael@0 | 402 | * |
michael@0 | 403 | * @param aAccessible [in] accessible the DOM attribute is changed for |
michael@0 | 404 | * @param aNameSpaceID [in] namespace of changed attribute |
michael@0 | 405 | * @param aAttribute [in] changed attribute |
michael@0 | 406 | */ |
michael@0 | 407 | void AttributeChangedImpl(Accessible* aAccessible, |
michael@0 | 408 | int32_t aNameSpaceID, nsIAtom* aAttribute); |
michael@0 | 409 | |
michael@0 | 410 | /** |
michael@0 | 411 | * Fire accessible events when ARIA attribute is changed. |
michael@0 | 412 | * |
michael@0 | 413 | * @param aAccessible [in] accesislbe the DOM attribute is changed for |
michael@0 | 414 | * @param aAttribute [in] changed attribute |
michael@0 | 415 | */ |
michael@0 | 416 | void ARIAAttributeChanged(Accessible* aAccessible, nsIAtom* aAttribute); |
michael@0 | 417 | |
michael@0 | 418 | /** |
michael@0 | 419 | * Process ARIA active-descendant attribute change. |
michael@0 | 420 | */ |
michael@0 | 421 | void ARIAActiveDescendantChanged(Accessible* aAccessible); |
michael@0 | 422 | |
michael@0 | 423 | /** |
michael@0 | 424 | * Update the accessible tree for inserted content. |
michael@0 | 425 | */ |
michael@0 | 426 | void ProcessContentInserted(Accessible* aContainer, |
michael@0 | 427 | const nsTArray<nsCOMPtr<nsIContent> >* aInsertedContent); |
michael@0 | 428 | |
michael@0 | 429 | /** |
michael@0 | 430 | * Used to notify the document to make it process the invalidation list. |
michael@0 | 431 | * |
michael@0 | 432 | * While children are cached we may encounter the case there's no accessible |
michael@0 | 433 | * for referred content by related accessible. Store these related nodes to |
michael@0 | 434 | * invalidate their containers later. |
michael@0 | 435 | */ |
michael@0 | 436 | void ProcessInvalidationList(); |
michael@0 | 437 | |
michael@0 | 438 | /** |
michael@0 | 439 | * Update the accessible tree for content insertion or removal. |
michael@0 | 440 | */ |
michael@0 | 441 | void UpdateTree(Accessible* aContainer, nsIContent* aChildNode, |
michael@0 | 442 | bool aIsInsert); |
michael@0 | 443 | |
michael@0 | 444 | /** |
michael@0 | 445 | * Helper for UpdateTree() method. Go down to DOM subtree and updates |
michael@0 | 446 | * accessible tree. Return one of these flags. |
michael@0 | 447 | */ |
michael@0 | 448 | enum EUpdateTreeFlags { |
michael@0 | 449 | eNoAccessible = 0, |
michael@0 | 450 | eAccessible = 1, |
michael@0 | 451 | eAlertAccessible = 2 |
michael@0 | 452 | }; |
michael@0 | 453 | |
michael@0 | 454 | uint32_t UpdateTreeInternal(Accessible* aChild, bool aIsInsert, |
michael@0 | 455 | AccReorderEvent* aReorderEvent); |
michael@0 | 456 | |
michael@0 | 457 | /** |
michael@0 | 458 | * Create accessible tree. |
michael@0 | 459 | * |
michael@0 | 460 | * @param aRoot [in] a root of subtree to create |
michael@0 | 461 | * @param aFocusedAcc [in, optional] a focused accessible under created |
michael@0 | 462 | * subtree if any |
michael@0 | 463 | */ |
michael@0 | 464 | void CacheChildrenInSubtree(Accessible* aRoot, |
michael@0 | 465 | Accessible** aFocusedAcc = nullptr); |
michael@0 | 466 | |
michael@0 | 467 | /** |
michael@0 | 468 | * Remove accessibles in subtree from node to accessible map. |
michael@0 | 469 | */ |
michael@0 | 470 | void UncacheChildrenInSubtree(Accessible* aRoot); |
michael@0 | 471 | |
michael@0 | 472 | /** |
michael@0 | 473 | * Shutdown any cached accessible in the subtree. |
michael@0 | 474 | * |
michael@0 | 475 | * @param aAccessible [in] the root of the subrtee to invalidate accessible |
michael@0 | 476 | * child/parent refs in |
michael@0 | 477 | */ |
michael@0 | 478 | void ShutdownChildrenInSubtree(Accessible* aAccessible); |
michael@0 | 479 | |
michael@0 | 480 | /** |
michael@0 | 481 | * Return true if the document is a target of document loading events |
michael@0 | 482 | * (for example, state busy change or document reload events). |
michael@0 | 483 | * |
michael@0 | 484 | * Rules: The root chrome document accessible is never an event target |
michael@0 | 485 | * (for example, Firefox UI window). If the sub document is loaded within its |
michael@0 | 486 | * parent document then the parent document is a target only (aka events |
michael@0 | 487 | * coalescence). |
michael@0 | 488 | */ |
michael@0 | 489 | bool IsLoadEventTarget() const; |
michael@0 | 490 | |
michael@0 | 491 | /** |
michael@0 | 492 | * Used to fire scrolling end event after page scroll. |
michael@0 | 493 | * |
michael@0 | 494 | * @param aTimer [in] the timer object |
michael@0 | 495 | * @param aClosure [in] the document accessible where scrolling happens |
michael@0 | 496 | */ |
michael@0 | 497 | static void ScrollTimerCallback(nsITimer* aTimer, void* aClosure); |
michael@0 | 498 | |
michael@0 | 499 | protected: |
michael@0 | 500 | |
michael@0 | 501 | /** |
michael@0 | 502 | * State and property flags, kept by mDocFlags. |
michael@0 | 503 | */ |
michael@0 | 504 | enum { |
michael@0 | 505 | // Whether scroll listeners were added. |
michael@0 | 506 | eScrollInitialized = 1 << 0, |
michael@0 | 507 | |
michael@0 | 508 | // Whether the document is a tab document. |
michael@0 | 509 | eTabDocument = 1 << 1 |
michael@0 | 510 | }; |
michael@0 | 511 | |
michael@0 | 512 | /** |
michael@0 | 513 | * Cache of accessibles within this document accessible. |
michael@0 | 514 | */ |
michael@0 | 515 | AccessibleHashtable mAccessibleCache; |
michael@0 | 516 | nsDataHashtable<nsPtrHashKey<const nsINode>, Accessible*> |
michael@0 | 517 | mNodeToAccessibleMap; |
michael@0 | 518 | |
michael@0 | 519 | nsIDocument* mDocumentNode; |
michael@0 | 520 | nsCOMPtr<nsITimer> mScrollWatchTimer; |
michael@0 | 521 | uint16_t mScrollPositionChangedTicks; // Used for tracking scroll events |
michael@0 | 522 | |
michael@0 | 523 | /** |
michael@0 | 524 | * Bit mask of document load states (@see LoadState). |
michael@0 | 525 | */ |
michael@0 | 526 | uint32_t mLoadState : 3; |
michael@0 | 527 | |
michael@0 | 528 | /** |
michael@0 | 529 | * Bit mask of other states and props. |
michael@0 | 530 | */ |
michael@0 | 531 | uint32_t mDocFlags : 28; |
michael@0 | 532 | |
michael@0 | 533 | /** |
michael@0 | 534 | * Type of document load event fired after the document is loaded completely. |
michael@0 | 535 | */ |
michael@0 | 536 | uint32_t mLoadEventType; |
michael@0 | 537 | |
michael@0 | 538 | /** |
michael@0 | 539 | * Reference to anchor jump element. |
michael@0 | 540 | */ |
michael@0 | 541 | nsCOMPtr<nsIContent> mAnchorJumpElm; |
michael@0 | 542 | |
michael@0 | 543 | /** |
michael@0 | 544 | * A generic state (see items below) before the attribute value was changed. |
michael@0 | 545 | * @see AttributeWillChange and AttributeChanged notifications. |
michael@0 | 546 | */ |
michael@0 | 547 | union { |
michael@0 | 548 | // ARIA attribute value |
michael@0 | 549 | nsIAtom* mARIAAttrOldValue; |
michael@0 | 550 | |
michael@0 | 551 | // True if the accessible state bit was on |
michael@0 | 552 | bool mStateBitWasOn; |
michael@0 | 553 | }; |
michael@0 | 554 | |
michael@0 | 555 | nsTArray<nsRefPtr<DocAccessible> > mChildDocuments; |
michael@0 | 556 | |
michael@0 | 557 | /** |
michael@0 | 558 | * The virtual cursor of the document. |
michael@0 | 559 | */ |
michael@0 | 560 | nsRefPtr<nsAccessiblePivot> mVirtualCursor; |
michael@0 | 561 | |
michael@0 | 562 | /** |
michael@0 | 563 | * A storage class for pairing content with one of its relation attributes. |
michael@0 | 564 | */ |
michael@0 | 565 | class AttrRelProvider |
michael@0 | 566 | { |
michael@0 | 567 | public: |
michael@0 | 568 | AttrRelProvider(nsIAtom* aRelAttr, nsIContent* aContent) : |
michael@0 | 569 | mRelAttr(aRelAttr), mContent(aContent) { } |
michael@0 | 570 | |
michael@0 | 571 | nsIAtom* mRelAttr; |
michael@0 | 572 | nsCOMPtr<nsIContent> mContent; |
michael@0 | 573 | |
michael@0 | 574 | private: |
michael@0 | 575 | AttrRelProvider(); |
michael@0 | 576 | AttrRelProvider(const AttrRelProvider&); |
michael@0 | 577 | AttrRelProvider& operator =(const AttrRelProvider&); |
michael@0 | 578 | }; |
michael@0 | 579 | |
michael@0 | 580 | typedef nsTArray<nsAutoPtr<AttrRelProvider> > AttrRelProviderArray; |
michael@0 | 581 | typedef nsClassHashtable<nsStringHashKey, AttrRelProviderArray> |
michael@0 | 582 | DependentIDsHashtable; |
michael@0 | 583 | |
michael@0 | 584 | /** |
michael@0 | 585 | * The cache of IDs pointed by relation attributes. |
michael@0 | 586 | */ |
michael@0 | 587 | DependentIDsHashtable mDependentIDsHash; |
michael@0 | 588 | |
michael@0 | 589 | static PLDHashOperator |
michael@0 | 590 | CycleCollectorTraverseDepIDsEntry(const nsAString& aKey, |
michael@0 | 591 | AttrRelProviderArray* aProviders, |
michael@0 | 592 | void* aUserArg); |
michael@0 | 593 | |
michael@0 | 594 | friend class RelatedAccIterator; |
michael@0 | 595 | |
michael@0 | 596 | /** |
michael@0 | 597 | * Used for our caching algorithm. We store the list of nodes that should be |
michael@0 | 598 | * invalidated. |
michael@0 | 599 | * |
michael@0 | 600 | * @see ProcessInvalidationList |
michael@0 | 601 | */ |
michael@0 | 602 | nsTArray<nsIContent*> mInvalidationList; |
michael@0 | 603 | |
michael@0 | 604 | /** |
michael@0 | 605 | * Used to process notification from core and accessible events. |
michael@0 | 606 | */ |
michael@0 | 607 | nsRefPtr<NotificationController> mNotificationController; |
michael@0 | 608 | friend class EventQueue; |
michael@0 | 609 | friend class NotificationController; |
michael@0 | 610 | |
michael@0 | 611 | private: |
michael@0 | 612 | |
michael@0 | 613 | nsIPresShell* mPresShell; |
michael@0 | 614 | }; |
michael@0 | 615 | |
michael@0 | 616 | inline DocAccessible* |
michael@0 | 617 | Accessible::AsDoc() |
michael@0 | 618 | { |
michael@0 | 619 | return IsDoc() ? static_cast<DocAccessible*>(this) : nullptr; |
michael@0 | 620 | } |
michael@0 | 621 | |
michael@0 | 622 | } // namespace a11y |
michael@0 | 623 | } // namespace mozilla |
michael@0 | 624 | |
michael@0 | 625 | #endif |