DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_a11y_DocAccessible_h__
#define mozilla_a11y_DocAccessible_h__

#include "nsIAccessiblePivot.h"
#include "nsIAccessiblePivot.h"

#include "HyperTextAccessibleWrap.h"
#include "AccEvent.h"

#include "nsClassHashtable.h"
#include "nsClassHashtable.h"
#include "nsDataHashtable.h"
#include "mozilla/dom/Document.h"
#include "mozilla/UniquePtr.h"
#include "nsIDocumentObserver.h"
#include "nsIDocumentObserver.h"
#include "nsIObserver.h"
#include "nsITimer.h"

class nsAccessiblePivot;


const uint32_t kDefaultCacheLength = 128;

namespace mozilla {
namespace mozilla {

class PresShell;
class TextEditor;

namespace dom {
namespace dom {
class Document;
}

namespace a11y {


class DocManager;
class NotificationController;
class DocAccessibleChild;
class RelatedAccIterator;
class RelatedAccIterator;
template <class Class, class... Args>
class TNotification;

class DocAccessible : public HyperTextAccessibleWrap,
                      public nsIDocumentObserver,
                      public nsIDocumentObserver,
                      public nsIObserver,
                      public nsSupportsWeakReference,
                      public nsIAccessiblePivotObserver {
  NS_DECL_ISUPPORTS_INHERITED
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DocAccessible, Accessible)
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DocAccessible, Accessible)

  NS_DECL_NSIOBSERVER
  NS_DECL_NSIACCESSIBLEPIVOTOBSERVER

 protected:
 protected:
  typedef mozilla::dom::Document Document;

 public:
  DocAccessible(Document* aDocument, PresShell* aPresShell);

  // nsIDocumentObserver
  // nsIDocumentObserver
  NS_DECL_NSIDOCUMENTOBSERVER

  // Accessible
  virtual void Init();
  virtual void Shutdown() override;
  virtual void Shutdown() override;
  virtual nsIFrame* GetFrame() const override;
  virtual nsINode* GetNode() const override { return mDocumentNode; }
  Document* DocumentNode() const { return mDocumentNode; }

  virtual mozilla::a11y::ENameValueFlag Name(nsString& aName) const override;
  virtual mozilla::a11y::ENameValueFlag Name(nsString& aName) const override;
  virtual void Description(nsString& aDescription) override;
  virtual Accessible* FocusedChild() override;
  virtual mozilla::a11y::role NativeRole() const override;
  virtual uint64_t NativeState() const override;
  virtual uint64_t NativeInteractiveState() const override;
  virtual uint64_t NativeInteractiveState() const override;
  virtual bool NativelyUnavailable() const override;
  virtual void ApplyARIAState(uint64_t* aState) const override;
  virtual already_AddRefed<nsIPersistentProperties> Attributes() override;


  virtual void TakeFocus() const override;

#ifdef A11Y_LOG
  virtual nsresult HandleAccEvent(AccEvent* aEvent) override;
#endif
#endif

  virtual nsRect RelativeBounds(nsIFrame** aRelativeFrame) const override;
  virtual nsRect RelativeBounds(nsIFrame** aRelativeFrame) const override;

  // HyperTextAccessible
  virtual already_AddRefed<TextEditor> GetEditor() const override;

  // DocAccessible
  // DocAccessible

  /**
   * Return document URL.
   */
   */
  void URL(nsAString& aURL) const;

  /**
   * Return DOM document title.
   */
   */
  void Title(nsString& aTitle) const { mDocumentNode->GetTitle(aTitle); }

  /**
   * Return DOM document mime type.
   */
   */
  void MimeType(nsAString& aType) const {
    mDocumentNode->GetContentType(aType);
  }

  /**
  /**
   * Return DOM document type.
   */
  void DocType(nsAString& aType) const;

  /**
  /**
   * Return virtual cursor associated with the document.
   */
  nsIAccessiblePivot* VirtualCursor();

  /**
   * Returns true if the instance has shutdown.
   * Returns true if the instance has shutdown.
   */
  bool HasShutdown() const { return !mPresShell; }

  /**
   * Return presentation shell for this document accessible.
   * Return presentation shell for this document accessible.
   */
  PresShell* PresShellPtr() const {
    MOZ_DIAGNOSTIC_ASSERT(!HasShutdown());
    return mPresShell;
    return mPresShell;
  }

  /**
   * Return the presentation shell's context.
   */
   */
  nsPresContext* PresContext() const { return mPresShell->GetPresContext(); }

  /**
   * Return true if associated DOM document was loaded and isn't unloading.
   */
   */
  bool IsContentLoaded() const {
    // eDOMLoaded flag check is used for error pages as workaround to make this
    // method return correct result since error pages do not receive 'pageshow'
    // event and as consequence Document::IsShowing() returns false.
    return mDocumentNode && mDocumentNode->IsVisible() &&
    return mDocumentNode && mDocumentNode->IsVisible() &&
           (mDocumentNode->IsShowing() || HasLoadState(eDOMLoaded));
  }

  bool IsHidden() const { return mDocumentNode->Hidden(); }

  /**
   * Document load states.
   */
  enum LoadState {
    // initial tree construction is pending
    // initial tree construction is pending
    eTreeConstructionPending = 0,
    // initial tree construction done
    eTreeConstructed = 1,
    // DOM document is loaded.
    eDOMLoaded = 1 << 1,
    eDOMLoaded = 1 << 1,
    // document is ready
    eReady = eTreeConstructed | eDOMLoaded,
    // document and all its subdocuments are ready
    eCompletelyLoaded = eReady | 1 << 2
  };
  };

  /**
   * Return true if the document has given document state.
   */
  bool HasLoadState(LoadState aState) const {
  bool HasLoadState(LoadState aState) const {
    return (mLoadState & static_cast<uint32_t>(aState)) ==
           static_cast<uint32_t>(aState);
  }

  /**
  /**
   * Return a native window handler or pointer depending on platform.
   */
  virtual void* GetNativeWindow() const;

  /**
   * Return the parent document.
   */
  DocAccessible* ParentDocument() const {
  DocAccessible* ParentDocument() const {
    return mParent ? mParent->Document() : nullptr;
  }

  /**
   * Return the child document count.
   * Return the child document count.
   */
  uint32_t ChildDocumentCount() const { return mChildDocuments.Length(); }

  /**
   * Return the child document at the given index.
   * Return the child document at the given index.
   */
  DocAccessible* GetChildDocumentAt(uint32_t aIndex) const {
    return mChildDocuments.SafeElementAt(aIndex, nullptr);
  }

  /**
   * Fire accessible event asynchronously.
   * Fire accessible event asynchronously.
   */
  void FireDelayedEvent(AccEvent* aEvent);
  void FireDelayedEvent(uint32_t aEventType, Accessible* aTarget);
  void FireEventsOnInsertion(Accessible* aContainer);


  /**
   * Fire value change event on the given accessible if applicable.
   */
  void MaybeNotifyOfValueChange(Accessible* aAccessible);


  /**
   * Get/set the anchor jump.
   */
  Accessible* AnchorJump() { return GetAccessibleOrContainer(mAnchorJumpElm); }

  void SetAnchorJump(nsIContent* aTargetNode) { mAnchorJumpElm = aTargetNode; }


  /**
   * Bind the child document to the tree.
   */
  void BindChildDocument(DocAccessible* aDocument);


  /**
   * Process the generic notification.
   *
   * @note  The caller must guarantee that the given instance still exists when
   *          notification is processed.
   *          notification is processed.
   * @see   NotificationController::HandleNotification
   */
  template <class Class, class... Args>
  void HandleNotification(
      Class* aInstance,
      Class* aInstance,
      typename TNotification<Class, Args...>::Callback aMethod, Args*... aArgs);

  /**
   * Return the cached accessible by the given DOM node if it's in subtree of
   * this document accessible or the document accessible itself, otherwise null.
   * this document accessible or the document accessible itself, otherwise null.
   *
   * @return the accessible object
   */
  Accessible* GetAccessible(nsINode* aNode) const {
    return aNode == mDocumentNode ? const_cast<DocAccessible*>(this)
    return aNode == mDocumentNode ? const_cast<DocAccessible*>(this)
                                  : mNodeToAccessibleMap.Get(aNode);
  }

  /**
  /**
   * Return an accessible for the given node even if the node is not in
   * document's node map cache (like HTML area element).
   *
   * XXX: it should be really merged with GetAccessible().
   */
   */
  Accessible* GetAccessibleEvenIfNotInMap(nsINode* aNode) const;
  Accessible* GetAccessibleEvenIfNotInMapOrContainer(nsINode* aNode) const;

  /**
   * Return whether the given DOM node has an accessible or not.
   * Return whether the given DOM node has an accessible or not.
   */
  bool HasAccessible(nsINode* aNode) const { return GetAccessible(aNode); }

  /**
  /**
   * Return the cached accessible by the given unique ID within this document.
   *
   * @note   the unique ID matches with the uniqueID() of Accessible
   *
   * @param  aUniqueID  [in] the unique ID used to cache the node.
   * @param  aUniqueID  [in] the unique ID used to cache the node.
   */
  Accessible* GetAccessibleByUniqueID(void* aUniqueID) {
    return UniqueID() == aUniqueID ? this : mAccessibleCache.GetWeak(aUniqueID);
  }


  /**
   * Return the cached accessible by the given unique ID looking through
   * this and nested documents.
   */
  Accessible* GetAccessibleByUniqueIDInSubtree(void* aUniqueID);

  /**
  /**
   * Return an accessible for the given DOM node or container accessible if
   * the node is not accessible. If aNoContainerIfPruned is true it will return
   * null if the node is in a pruned subtree (eg. aria-hidden or unselected deck
   * panel)
   */
   */
  Accessible* GetAccessibleOrContainer(nsINode* aNode,
                                       bool aNoContainerIfPruned = false) const;

  /**
   * Return a container accessible for the given DOM node.
   * Return a container accessible for the given DOM node.
   */
  Accessible* GetContainerAccessible(nsINode* aNode) const {
    return aNode ? GetAccessibleOrContainer(aNode->GetParentNode()) : nullptr;
  }


  /**
   * Return an accessible for the given node if any, or an immediate accessible
   * container for it.
   */
  Accessible* AccessibleOrTrueContainer(
  Accessible* AccessibleOrTrueContainer(
      nsINode* aNode, bool aNoContainerIfPruned = false) const;

  /**
   * Return an accessible for the given node or its first accessible descendant.
   */
   */
  Accessible* GetAccessibleOrDescendant(nsINode* aNode) const;

  /**
   * Returns aria-owns seized child at the given index.
   */
  Accessible* ARIAOwnedAt(Accessible* aParent, uint32_t aIndex) const {
  Accessible* ARIAOwnedAt(Accessible* aParent, uint32_t aIndex) const {
    nsTArray<RefPtr<Accessible>>* children = mARIAOwnsHash.Get(aParent);
    if (children) {
      return children->SafeElementAt(aIndex);
    }
    return nullptr;
    return nullptr;
  }
  uint32_t ARIAOwnedCount(Accessible* aParent) const {
    nsTArray<RefPtr<Accessible>>* children = mARIAOwnsHash.Get(aParent);
    return children ? children->Length() : 0;
  }
  }

  /**
   * Return true if the given ID is referred by relation attribute.
   */
   */
  bool IsDependentID(dom::Element* aElement, const nsAString& aID) const {
    return GetRelProviders(aElement, aID);
  }

  /**
  /**
   * Initialize the newly created accessible and put it into document caches.
   *
   * @param  aAccessible    [in] created accessible
   * @param  aRoleMapEntry  [in] the role map entry role the ARIA role or
   * nullptr if none
   * nullptr if none
   */
  void BindToDocument(Accessible* aAccessible,
                      const nsRoleMapEntry* aRoleMapEntry);


  /**
   * Remove from document and shutdown the given accessible.
   */
  void UnbindFromDocument(Accessible* aAccessible);


  /**
   * Notify the document accessible that content was inserted.
   */
  void ContentInserted(nsIContent* aStartChildNode, nsIContent* aEndChildNode);


  /**
   * Update the tree on content removal.
   */
  void ContentRemoved(Accessible* aAccessible);
  void ContentRemoved(nsIContent* aContentNode);
  void ContentRemoved(nsIContent* aContentNode);

  /**
   * Updates accessible tree when rendered text is changed.
   */
  void UpdateText(nsIContent* aTextNode);
  void UpdateText(nsIContent* aTextNode);

  /**
   * Recreate an accessible, results in hide/show events pair.
   */
  void RecreateAccessible(nsIContent* aContent);
  void RecreateAccessible(nsIContent* aContent);

  /**
   * Schedule ARIA owned element relocation if needed. Return true if relocation
   * was scheduled.
   */
  bool RelocateARIAOwnedIfNeeded(nsIContent* aEl);


  /**
   * Return a notification controller associated with the document.
   */
  NotificationController* Controller() const { return mNotificationController; }


  /**
   * If this document is in a content process return the object responsible for
   * communicating with the main process for it.
   */
  DocAccessibleChild* IPCDoc() const { return mIPCDoc; }
  DocAccessibleChild* IPCDoc() const { return mIPCDoc; }

  /**
   * Notify the document that a DOM node has been scrolled. document will
   * dispatch throttled accessibility events for scrolling, and a scroll-end
   * event.
   */
  void HandleScroll(nsINode* aTarget);
  void HandleScroll(nsINode* aTarget);

 protected:
  virtual ~DocAccessible();

  void LastRelease();
  void LastRelease();

  // DocAccessible
  virtual nsresult AddEventListeners();
  virtual nsresult RemoveEventListeners();


  /**
   * Marks this document as loaded or loading.
   */
  void NotifyOfLoad(uint32_t aLoadEventType);
  void NotifyOfLoading(bool aIsReloading);
  void NotifyOfLoading(bool aIsReloading);

  friend class DocManager;

  /**
   * Perform initial update (create accessible tree).
   * Perform initial update (create accessible tree).
   * Can be overridden by wrappers to prepare initialization work.
   */
  virtual void DoInitialUpdate();

  /**
  /**
   * Updates root element and picks up ARIA role on it if any.
   */
  void UpdateRootElIfNeeded();
  void UpdateRootElIfNeeded();


  /**
   * Process document load notification, fire document load and state busy
   * events if applicable.
   * events if applicable.
   */
  void ProcessLoad();

  /**
   * Append the given document accessible to this document's child document
   * Append the given document accessible to this document's child document
   * accessibles.
   */
  bool AppendChildDocument(DocAccessible* aChildDocument) {
    // XXX(Bug 1631371) Check if this should use a fallible operation as it
    // pretended earlier, or change the return type to void.
    // pretended earlier, or change the return type to void.
    mChildDocuments.AppendElement(aChildDocument);
    return true;
  }


  /**
   * Remove the given document accessible from this document's child document
   * accessibles.
   */
  void RemoveChildDocument(DocAccessible* aChildDocument) {
  void RemoveChildDocument(DocAccessible* aChildDocument) {
    mChildDocuments.RemoveElement(aChildDocument);
  }

  /**
   * Add dependent IDs pointed by accessible element by relation attribute to
   * Add dependent IDs pointed by accessible element by relation attribute to
   * cache. If the relation attribute is missed then all relation attributes
   * are checked.
   *
   * @param aRelProvider [in] accessible that element has relation attribute
   * @param aRelAttr     [in, optional] relation attribute
   * @param aRelAttr     [in, optional] relation attribute
   */
  void AddDependentIDsFor(Accessible* aRelProvider, nsAtom* aRelAttr = nullptr);

  /**
   * Remove dependent IDs pointed by accessible element by relation attribute
   * Remove dependent IDs pointed by accessible element by relation attribute
   * from cache. If the relation attribute is absent then all relation
   * attributes are checked.
   *
   * @param aRelProvider [in] accessible that element has relation attribute
   * @param aRelAttr     [in, optional] relation attribute
   */
  void RemoveDependentIDsFor(Accessible* aRelProvider,
                             nsAtom* aRelAttr = nullptr);

  /**
   * Update or recreate an accessible depending on a changed attribute.
   *
   *
   * @param aElement   [in] the element the attribute was changed on
   * @param aAttribute [in] the changed attribute
   * @return            true if an action was taken on the attribute change
   */
  bool UpdateAccessibleOnAttrChange(mozilla::dom::Element* aElement,
  bool UpdateAccessibleOnAttrChange(mozilla::dom::Element* aElement,
                                    nsAtom* aAttribute);

  /**
   * Fire accessible events when attribute is changed.
   *
   *
   * @param aAccessible   [in] accessible the DOM attribute is changed for
   * @param aNameSpaceID  [in] namespace of changed attribute
   * @param aAttribute    [in] changed attribute
   * @param aModType      [in] modification type (changed/added/removed)
   * @param aModType      [in] modification type (changed/added/removed)
   */
  void AttributeChangedImpl(Accessible* aAccessible, int32_t aNameSpaceID,
                            nsAtom* aAttribute, int32_t aModType);

  /**
  /**
   * Fire accessible events when ARIA attribute is changed.
   *
   * @param aAccessible  [in] accesislbe the DOM attribute is changed for
   * @param aAttribute   [in] changed attribute
   */
   */
  void ARIAAttributeChanged(Accessible* aAccessible, nsAtom* aAttribute);

  /**
  /**
   * Process ARIA active-descendant attribute change.
   */
  void ARIAActiveDescendantChanged(Accessible* aAccessible);

  /**
  /**
   * Update the accessible tree for inserted content.
   */
  void ProcessContentInserted(
      Accessible* aContainer,
      const nsTArray<nsCOMPtr<nsIContent>>* aInsertedContent);
      const nsTArray<nsCOMPtr<nsIContent>>* aInsertedContent);
  void ProcessContentInserted(Accessible* aContainer,
                              nsIContent* aInsertedContent);

  /**
   * Used to notify the document to make it process the invalidation list.
   * Used to notify the document to make it process the invalidation list.
   *
   * While children are cached we may encounter the case there's no accessible
   * for referred content by related accessible. Store these related nodes to
   * invalidate their containers later.
   */
  void ProcessInvalidationList();


  /**
   * Steals or puts back accessible subtrees.
   */
  void DoARIAOwnsRelocation(Accessible* aOwner);


  /**
   * Moves children back under their original parents.
   */
  void PutChildrenBack(nsTArray<RefPtr<Accessible>>* aChildren,
                       uint32_t aStartIdx);


  bool MoveChild(Accessible* aChild, Accessible* aNewParent,
                 int32_t aIdxInParent);

  /**
   * Create accessible tree.
   * Create accessible tree.
   *
   * @param aRoot       [in] a root of subtree to create
   * @param aFocusedAcc [in, optional] a focused accessible under created
   *                      subtree if any
   */
  void CacheChildrenInSubtree(Accessible* aRoot,
                              Accessible** aFocusedAcc = nullptr);
                              Accessible** aFocusedAcc = nullptr);
  void CreateSubtree(Accessible* aRoot);

  /**
   * Remove accessibles in subtree from node to accessible map.
   */
   */
  void UncacheChildrenInSubtree(Accessible* aRoot);

  /**
   * Shutdown any cached accessible in the subtree.
   *
   *
   * @param aAccessible  [in] the root of the subrtee to invalidate accessible
   *                      child/parent refs in
   */
  void ShutdownChildrenInSubtree(Accessible* aAccessible);


  /**
   * Return true if the document is a target of document loading events
   * (for example, state busy change or document reload events).
   * (for example, state busy change or document reload events).
   *
   * Rules: The root chrome document accessible is never an event target
   * (for example, Firefox UI window). If the sub document is loaded within its
   * parent document then the parent document is a target only (aka events
   * coalescence).
   */
  bool IsLoadEventTarget() const;
  bool IsLoadEventTarget() const;

  /*
   * Set the object responsible for communicating with the main process on
   * behalf of this document.
   */
   */
  void SetIPCDoc(DocAccessibleChild* aIPCDoc);

  friend class DocAccessibleChildBase;

  /**
  /**
   * Used to fire scrolling end event after page scroll.
   *
   * @param aTimer    [in] the timer object
   * @param aClosure  [in] the document accessible where scrolling happens
   */
   */
  static void ScrollTimerCallback(nsITimer* aTimer, void* aClosure);

  void DispatchScrollingEvent(nsINode* aTarget, uint32_t aEventType);

  /**
  /**
   * Check if an id attribute change affects aria-activedescendant and handle
   * the aria-activedescendant change if appropriate.
   * If the currently focused element has aria-activedescendant and an
   * element's id changes to match this, the id was probably moved from the
   * element's id changes to match this, the id was probably moved from the
   * previous active descendant, thus making this element the new active
   * descendant. In that case, accessible focus must be changed accordingly.
   */
  void ARIAActiveDescendantIDMaybeMoved(dom::Element* aElm);


  /**
   * Traverse content subtree and for each node do one of 3 things:
   * 1. Check if content node has an accessible that should be removed and
   *    remove it.
   * 2. Check if content node has an accessible that needs to be recreated.
   * 2. Check if content node has an accessible that needs to be recreated.
   *    Remove it and schedule it for reinsertion.
   * 3. Check if content node has no accessible but needs one. Schedule one for
   *    insertion.
   *
   * Returns true if the root node should be reinserted.
   * Returns true if the root node should be reinserted.
   */
  bool PruneOrInsertSubtree(nsIContent* aRoot);

 protected:
  /**
  /**
   * State and property flags, kept by mDocFlags.
   */
  enum {
    // Whether the document is a top level content document in this process.
    eTabDocument = 1 << 0
    eTopLevelContentDocInProcess = 1 << 0
  };

  /**
   * Cache of accessibles within this document accessible.
   */
  AccessibleHashtable mAccessibleCache;
  nsDataHashtable<nsPtrHashKey<const nsINode>, Accessible*>
      mNodeToAccessibleMap;
      mNodeToAccessibleMap;

  Document* mDocumentNode;
  nsCOMPtr<nsITimer> mScrollWatchTimer;
  nsDataHashtable<nsPtrHashKey<nsINode>, TimeStamp> mLastScrollingDispatch;


  /**
   * Bit mask of document load states (@see LoadState).
   */
  uint32_t mLoadState : 3;


  /**
   * Bit mask of other states and props.
   */
   */
  uint32_t mDocFlags : 28;
  uint32_t mDocFlags : 28;

  /**
   * Type of document load event fired after the document is loaded completely.
   * Type of document load event fired after the document is loaded completely.
   */
  uint32_t mLoadEventType;

  /**
   * Reference to anchor jump element.
   * Reference to anchor jump element.
   */
  nsCOMPtr<nsIContent> mAnchorJumpElm;

  /**
   * A generic state (see items below) before the attribute value was changed.
   * A generic state (see items below) before the attribute value was changed.
   * @see AttributeWillChange and AttributeChanged notifications.
   */
  union {
    // ARIA attribute value
    const nsAtom* mARIAAttrOldValue;
    const nsAtom* mARIAAttrOldValue;

    // Previous state bits before attribute change
    uint64_t mPrevStateBits;
  };


  nsTArray<RefPtr<DocAccessible>> mChildDocuments;

  /**
   * The virtual cursor of the document.
   */
   */
  RefPtr<nsAccessiblePivot> mVirtualCursor;

  /**
   * A storage class for pairing content with one of its relation attributes.
   */
   */
  class AttrRelProvider {
   public:
    AttrRelProvider(nsAtom* aRelAttr, nsIContent* aContent)
        : mRelAttr(aRelAttr), mContent(aContent) {}


    nsAtom* mRelAttr;
    nsCOMPtr<nsIContent> mContent;

   private:
   private:
    AttrRelProvider();
    AttrRelProvider(const AttrRelProvider&);
    AttrRelProvider& operator=(const AttrRelProvider&);
  };


  typedef nsTArray<mozilla::UniquePtr<AttrRelProvider>> AttrRelProviders;
  typedef nsClassHashtable<nsStringHashKey, AttrRelProviders>
      DependentIDsHashtable;

  /**
   * Returns/creates/removes attribute relation providers associated with
   * Returns/creates/removes attribute relation providers associated with
   * a DOM document if the element is in uncomposed document or associated
   * with shadow DOM the element is in.
   */
  AttrRelProviders* GetRelProviders(dom::Element* aElement,
                                    const nsAString& aID) const;
                                    const nsAString& aID) const;
  AttrRelProviders* GetOrCreateRelProviders(dom::Element* aElement,
                                            const nsAString& aID);
  void RemoveRelProvidersIfEmpty(dom::Element* aElement, const nsAString& aID);

  /**
  /**
   * The cache of IDs pointed by relation attributes.
   */
  nsClassHashtable<nsPtrHashKey<dom::DocumentOrShadowRoot>,
                   DependentIDsHashtable>
                   DependentIDsHashtable>
      mDependentIDsHashes;

  friend class RelatedAccIterator;

  /**
  /**
   * Used for our caching algorithm. We store the list of nodes that should be
   * invalidated.
   *
   * @see ProcessInvalidationList
   */
   */
  nsTArray<RefPtr<nsIContent>> mInvalidationList;

  /**
   * Holds a list of aria-owns relocations.
   */
  nsClassHashtable<nsPtrHashKey<Accessible>, nsTArray<RefPtr<Accessible>>>
      mARIAOwnsHash;


  /**
   * Used to process notification from core and accessible events.
   */
  RefPtr<NotificationController> mNotificationController;
  friend class EventTree;
  friend class EventTree;
  friend class NotificationController;

 private:
  void SetRoleMapEntryForDoc(dom::Element* aElement);


  PresShell* mPresShell;

  // Exclusively owned by IPDL so don't manually delete it!
  DocAccessibleChild* mIPCDoc;
};
};

inline DocAccessible* Accessible::AsDoc() {
  return IsDoc() ? static_cast<DocAccessible*>(this) : nullptr;
}


}  // namespace a11y
}  // namespace mozilla


#endif
#endif