Bug 636945 - add downcasting for nsRootAccessible, r=davidb, a=davidb
authorAlexander Surkov <surkov.alexander@gmail.com>
Wed, 02 Mar 2011 13:16:28 +0800
changeset 63248 82aabe4f0c3b869feca2f6b303a49cb48ced75ec
parent 63247 f8f86e837e25b57b489c4a5a97ff88e2a7856dbf
child 63249 af9c212658df7e670cdab922cd8246a151709f63
push id19100
push usersurkov.alexander@gmail.com
push dateWed, 02 Mar 2011 05:17:03 +0000
treeherdermozilla-central@82aabe4f0c3b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdavidb, davidb
bugs636945
milestone2.0b13pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 636945 - add downcasting for nsRootAccessible, r=davidb, a=davidb
accessible/src/atk/nsAccessibleWrap.cpp
accessible/src/base/nsAccessNode.cpp
accessible/src/base/nsAccessNode.h
accessible/src/base/nsAccessible.h
accessible/src/base/nsDocAccessible.cpp
accessible/src/base/nsRootAccessible.cpp
accessible/src/base/nsRootAccessible.h
accessible/src/mac/mozAccessible.mm
accessible/src/msaa/nsAccessibleWrap.cpp
accessible/src/msaa/nsDocAccessibleWrap.cpp
--- a/accessible/src/atk/nsAccessibleWrap.cpp
+++ b/accessible/src/atk/nsAccessibleWrap.cpp
@@ -1076,17 +1076,17 @@ nsAccessibleWrap::FirePlatformEvent(AccE
 
     case nsIAccessibleEvent::EVENT_TEXT_REMOVED:
     case nsIAccessibleEvent::EVENT_TEXT_INSERTED:
         return FireAtkTextChangedEvent(aEvent, atkObj);
 
     case nsIAccessibleEvent::EVENT_FOCUS:
       {
         MAI_LOG_DEBUG(("\n\nReceived: EVENT_FOCUS\n"));
-        nsRefPtr<nsRootAccessible> rootAccWrap = accWrap->GetRootAccessible();
+        nsRootAccessible* rootAccWrap = accWrap->RootAccessible();
         if (rootAccWrap && rootAccWrap->mActivated) {
             atk_focus_tracker_notify(atkObj);
             // Fire state change event for focus
             nsRefPtr<AccEvent> stateChangeEvent =
               new AccStateChangeEvent(accessible,
                                       nsIAccessibleStates::STATE_FOCUSED,
                                       PR_FALSE, PR_TRUE);
             return FireAtkStateChangeEvent(stateChangeEvent, atkObj);
--- a/accessible/src/base/nsAccessNode.cpp
+++ b/accessible/src/base/nsAccessNode.cpp
@@ -280,34 +280,34 @@ nsPresContext* nsAccessNode::GetPresCont
 
 nsDocAccessible *
 nsAccessNode::GetDocAccessible() const
 {
   return mContent ?
     GetAccService()->GetDocAccessible(mContent->GetOwnerDoc()) : nsnull;
 }
 
-already_AddRefed<nsRootAccessible> nsAccessNode::GetRootAccessible()
+nsRootAccessible*
+nsAccessNode::RootAccessible() const
 {
   nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
     nsCoreUtils::GetDocShellTreeItemFor(mContent);
   NS_ASSERTION(docShellTreeItem, "No docshell tree item for mContent");
   if (!docShellTreeItem) {
     return nsnull;
   }
   nsCOMPtr<nsIDocShellTreeItem> root;
   docShellTreeItem->GetRootTreeItem(getter_AddRefs(root));
   NS_ASSERTION(root, "No root content tree item");
   if (!root) {
     return nsnull;
   }
 
-  nsDocAccessible *docAcc = nsAccUtils::GetDocAccessibleFor(root);
-  nsRefPtr<nsRootAccessible> rootAcc = do_QueryObject(docAcc);
-  return rootAcc.forget();
+  nsDocAccessible* docAcc = nsAccUtils::GetDocAccessibleFor(root);
+  return docAcc ? docAcc->AsRoot() : nsnull;
 }
 
 nsIFrame*
 nsAccessNode::GetFrame() const
 {
   return mContent ? mContent->GetPrimaryFrame() : nsnull;
 }
 
@@ -342,18 +342,18 @@ nsAccessNode::GetDocument(nsIAccessibleD
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetRootDocument(nsIAccessibleDocument **aRootDocument)
 {
   NS_ENSURE_ARG_POINTER(aRootDocument);
 
-  nsRefPtr<nsRootAccessible> rootDocument = GetRootAccessible();
-  NS_IF_ADDREF(*aRootDocument = rootDocument.get());
+  nsRootAccessible* rootDocument = RootAccessible();
+  NS_IF_ADDREF(*aRootDocument = rootDocument);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsAccessNode::GetInnerHTML(nsAString& aInnerHTML)
 {
   aInnerHTML.Truncate();
 
--- a/accessible/src/base/nsAccessNode.h
+++ b/accessible/src/base/nsAccessNode.h
@@ -100,17 +100,17 @@ public:
   /**
    * Return the document accessible for this access node.
    */
   nsDocAccessible *GetDocAccessible() const;
 
   /**
    * Return the root document accessible for this accessnode.
    */
-  already_AddRefed<nsRootAccessible> GetRootAccessible();
+  nsRootAccessible* RootAccessible() const;
 
   /**
    * Reference to a node of focused accessible.
    */
   static nsINode *gLastFocusedNode;
 
   /**
    * Return focused node within accessible window.
--- a/accessible/src/base/nsAccessible.h
+++ b/accessible/src/base/nsAccessible.h
@@ -359,16 +359,19 @@ public:
   //////////////////////////////////////////////////////////////////////////////
   // Downcasting
 
   inline bool IsApplication() const { return mFlags & eApplicationAccessible; }
 
   inline bool IsHyperText() const { return mFlags & eHyperTextAccessible; }
   nsHyperTextAccessible* AsHyperText();
 
+  inline bool IsRoot() const { return mFlags & eRootAccessible; }
+  nsRootAccessible* AsRoot();
+
   inline bool IsTextLeaf() const { return mFlags & eTextLeafAccessible; }
   nsTextAccessible* AsTextLeaf();
 
   //////////////////////////////////////////////////////////////////////////////
   // HyperLinkAccessible
 
   /**
    * Return true if the accessible is hyper link accessible.
@@ -504,17 +507,18 @@ protected:
 
   /**
    * Flags describing the accessible itself.
    * @note keep these flags in sync with ChildrenFlags
    */
   enum AccessibleTypes {
     eApplicationAccessible = 1 << 2,
     eHyperTextAccessible = 1 << 3,
-    eTextLeafAccessible = 1 << 4
+    eRootAccessible = 1 << 4,
+    eTextLeafAccessible = 1 << 5
   };
 
   //////////////////////////////////////////////////////////////////////////////
   // Miscellaneous helpers
 
   /**
    * Return ARIA role (helper method).
    */
--- a/accessible/src/base/nsDocAccessible.cpp
+++ b/accessible/src/base/nsDocAccessible.cpp
@@ -765,17 +765,17 @@ nsresult nsDocAccessible::AddEventListen
     if (commandManager) {
       commandManager->AddCommandObserver(this, "obs_documentCreated");
     }
   }
 
   nsCOMPtr<nsIDocShellTreeItem> rootTreeItem;
   docShellTreeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem));
   if (rootTreeItem) {
-    nsRefPtr<nsRootAccessible> rootAccessible = GetRootAccessible();
+    nsRootAccessible* rootAccessible = RootAccessible();
     NS_ENSURE_TRUE(rootAccessible, NS_ERROR_FAILURE);
     nsRefPtr<nsCaretAccessible> caretAccessible = rootAccessible->GetCaretAccessible();
     if (caretAccessible) {
       caretAccessible->AddDocSelectionListener(presShell);
     }
   }
 
   // add document observer
@@ -812,17 +812,17 @@ nsresult nsDocAccessible::RemoveEventLis
   }
 
   if (mScrollWatchTimer) {
     mScrollWatchTimer->Cancel();
     mScrollWatchTimer = nsnull;
     NS_RELEASE_THIS(); // Kung fu death grip
   }
 
-  nsRefPtr<nsRootAccessible> rootAccessible(GetRootAccessible());
+  nsRootAccessible* rootAccessible = RootAccessible();
   if (rootAccessible) {
     nsRefPtr<nsCaretAccessible> caretAccessible = rootAccessible->GetCaretAccessible();
     if (caretAccessible) {
       // Don't use GetPresShell() which can call Shutdown() if it sees dead pres shell
       nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
       caretAccessible->RemoveDocSelectionListener(presShell);
     }
   }
@@ -1130,17 +1130,17 @@ nsDocAccessible::ARIAAttributeChanged(ns
   }
 
   if (aAttribute == nsAccessibilityAtoms::aria_activedescendant) {
     // The activedescendant universal property redirects accessible focus events
     // to the element with the id that activedescendant points to
     nsCOMPtr<nsINode> focusedNode = GetCurrentFocus();
     if (nsCoreUtils::GetRoleContent(focusedNode) == aContent) {
       nsAccessible* focusedAcc = GetAccService()->GetAccessible(focusedNode);
-      nsRefPtr<nsRootAccessible> rootAcc = GetRootAccessible();
+      nsRootAccessible* rootAcc = RootAccessible();
       if (rootAcc && focusedAcc) {
         rootAcc->FireAccessibleFocusEvent(focusedAcc, nsnull, PR_TRUE);
       }
     }
     return;
   }
 
   // For aria drag and drop changes we fire a generic attribute change event;
--- a/accessible/src/base/nsRootAccessible.cpp
+++ b/accessible/src/base/nsRootAccessible.cpp
@@ -107,16 +107,17 @@ NS_IMPL_RELEASE_INHERITED(nsRootAccessib
 ////////////////////////////////////////////////////////////////////////////////
 // Constructor/desctructor
 
 nsRootAccessible::
   nsRootAccessible(nsIDocument *aDocument, nsIContent *aRootContent,
                    nsIWeakReference *aShell) :
   nsDocAccessibleWrap(aDocument, aRootContent, aShell)
 {
+  mFlags |= eRootAccessible;
 }
 
 nsRootAccessible::~nsRootAccessible()
 {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIAccessible
--- a/accessible/src/base/nsRootAccessible.h
+++ b/accessible/src/base/nsRootAccessible.h
@@ -159,9 +159,16 @@ protected:
     already_AddRefed<nsIDocShellTreeItem>
            GetContentDocShell(nsIDocShellTreeItem *aStart);
     nsRefPtr<nsCaretAccessible> mCaretAccessible;
   nsCOMPtr<nsINode> mCurrentARIAMenubar;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsRootAccessible, NS_ROOTACCESSIBLE_IMPL_CID)
 
+inline nsRootAccessible*
+nsAccessible::AsRoot()
+{
+  return mFlags & eRootAccessible ?
+    static_cast<nsRootAccessible*>(this) : nsnull;
+}
+
 #endif
--- a/accessible/src/mac/mozAccessible.mm
+++ b/accessible/src/mac/mozAccessible.mm
@@ -360,17 +360,17 @@ GetNativeFromGeckoAccessible(nsIAccessib
       return GetClosestInterestingAccessible(nativeParent);
   }
   
   // GetUnignoredParent() returns null when there is no unignored accessible all the way up to
   // the root accessible. so we'll have to return whatever native accessible is above our root accessible 
   // (which might be the owning NSWindow in the application, for example).
   //
   // get the native root accessible, and tell it to return its first parent unignored accessible.
-  nsRefPtr<nsRootAccessible> root(mGeckoAccessible->GetRootAccessible());
+  nsRootAccessible* root = mGeckoAccessible->RootAccessible();
   id nativeParent = GetNativeFromGeckoAccessible(static_cast<nsIAccessible*>(root));
   NSAssert1 (nativeParent, @"!!! we can't find a parent for %@", self);
   
   return GetClosestInterestingAccessible(nativeParent);
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
 }
 
--- a/accessible/src/msaa/nsAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsAccessibleWrap.cpp
@@ -1767,17 +1767,17 @@ nsAccessibleWrap::GetXPAccessibleFor(con
 }
 
 void nsAccessibleWrap::UpdateSystemCaret()
 {
   // Move the system caret so that Windows Tablet Edition and tradional ATs with 
   // off-screen model can follow the caret
   ::DestroyCaret();
 
-  nsRefPtr<nsRootAccessible> rootAccessible = GetRootAccessible();
+  nsRootAccessible* rootAccessible = RootAccessible();
   if (!rootAccessible) {
     return;
   }
 
   nsRefPtr<nsCaretAccessible> caretAccessible = rootAccessible->GetCaretAccessible();
   if (!caretAccessible) {
     return;
   }
--- a/accessible/src/msaa/nsDocAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsDocAccessibleWrap.cpp
@@ -253,17 +253,17 @@ STDMETHODIMP nsDocAccessibleWrap::get_ac
 // nsAccessNode
 
 PRBool
 nsDocAccessibleWrap::Init()
 {
   if (nsWinUtils::IsWindowEmulationEnabled()) {
     // Create window for tab document.
     if (nsWinUtils::IsTabDocument(mDocument)) {
-      nsRefPtr<nsRootAccessible> root = GetRootAccessible();
+      nsRootAccessible* root = RootAccessible();
       mHWND = nsWinUtils::CreateNativeWindow(kClassNameTabContent,
                                              static_cast<HWND>(root->GetNativeWindow()));
 
       nsAccessibleWrap::sHWNDCache.Put(mHWND, this);
 
     } else {
       nsDocAccessible* parentDocument = ParentDocument();
       if (parentDocument)