Bug 573910 - switch nsApplicationAccessible to nsAccessible::Append/RemoveChild, r=davidb, sr=roc
authorAlexander Surkov <surkov.alexander@gmail.com>
Fri, 25 Jun 2010 18:50:23 +0900
changeset 46207 3a9f8129178825c41213f1c9c5cc713c8792bc65
parent 46206 b51803f3fdefce7c505566dee8d6d93ee9673bc3
child 46208 0368fa7482602b714602770eb2fdece6a52b3c1b
push id14069
push usersurkov.alexander@gmail.com
push dateFri, 25 Jun 2010 09:51:32 +0000
treeherdermozilla-central@3a9f81291788 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdavidb, roc
bugs573910
milestone1.9.3a6pre
first release with
nightly linux32
3a9f81291788 / 3.7a6pre / 20100625030252 / files
nightly linux64
3a9f81291788 / 3.7a6pre / 20100625030857 / files
nightly mac
3a9f81291788 / 3.7a6pre / 20100625031140 / files
nightly win32
3a9f81291788 / 3.7a6pre / 20100625040119 / files
nightly win64
3a9f81291788 / 3.7a6pre / 20100625041938 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 573910 - switch nsApplicationAccessible to nsAccessible::Append/RemoveChild, r=davidb, sr=roc
accessible/public/nsIAccessibilityService.h
accessible/src/atk/nsApplicationAccessibleWrap.cpp
accessible/src/atk/nsApplicationAccessibleWrap.h
accessible/src/base/nsAccessibilityService.cpp
accessible/src/base/nsAccessibilityService.h
accessible/src/base/nsApplicationAccessible.cpp
accessible/src/base/nsApplicationAccessible.h
accessible/src/base/nsRootAccessible.cpp
widget/src/gtk2/nsAccessibilityHelper.cpp
--- a/accessible/public/nsIAccessibilityService.h
+++ b/accessible/public/nsIAccessibilityService.h
@@ -127,20 +127,18 @@ public:
                                                  nsIAccessible **aAccessible) = 0;
   virtual nsresult CreateHTMLCaptionAccessible(nsIFrame *aFrame,
                                                nsIAccessible **aAccessible) = 0;
 
   /**
    * Adds/remove ATK root accessible for gtk+ native window to/from children
    * of the application accessible.
    */
-  virtual nsresult AddNativeRootAccessible(void *aAtkAccessible,
-                                           nsIAccessible **aAccessible) = 0;
-  virtual nsresult
-    RemoveNativeRootAccessible(nsIAccessible *aRootAccessible) = 0;
+  virtual nsAccessible* AddNativeRootAccessible(void* aAtkAccessible) = 0;
+  virtual void RemoveNativeRootAccessible(nsAccessible* aRootAccessible) = 0;
 
   /**
    * Used to describe sort of changes leading to accessible tree invalidation.
    */
   enum {
     NODE_APPEND = 0x01,
     NODE_REMOVE = 0x02,
     NODE_SIGNIFICANT_CHANGE = 0x03,
--- a/accessible/src/atk/nsApplicationAccessibleWrap.cpp
+++ b/accessible/src/atk/nsApplicationAccessibleWrap.cpp
@@ -648,26 +648,23 @@ gboolean fireRootAccessibleAddedCB(gpoin
                           eventData->index, eventData->root_accessible, NULL);
     g_object_unref(eventData->app_accessible);
     g_object_unref(eventData->root_accessible);
     free(data);
     
     return FALSE;
 }
 
-nsresult
-nsApplicationAccessibleWrap::AddRootAccessible(nsIAccessible *aRootAccWrap)
+PRBool
+nsApplicationAccessibleWrap::AppendChild(nsAccessible *aChild)
 {
-    NS_ENSURE_ARG_POINTER(aRootAccWrap);
+    if (!nsApplicationAccessible::AppendChild(aChild))
+      return PR_FALSE;
 
-    // add by weak reference
-    nsresult rv = nsApplicationAccessible::AddRootAccessible(aRootAccWrap);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    AtkObject *atkAccessible = nsAccessibleWrap::GetAtkObject(aRootAccWrap);
+    AtkObject *atkAccessible = nsAccessibleWrap::GetAtkObject(aChild);
     atk_object_set_parent(atkAccessible, mAtkObject);
 
     PRUint32 count = mChildren.Length();
 
     // Emit children_changed::add in a timeout
     // to make sure aRootAccWrap is fully initialized.
     AtkRootAccessibleAddedEvent* eventData = (AtkRootAccessibleAddedEvent*)
       malloc(sizeof(AtkRootAccessibleAddedEvent));
@@ -675,32 +672,30 @@ nsApplicationAccessibleWrap::AddRootAcce
       eventData->app_accessible = mAtkObject;
       eventData->root_accessible = atkAccessible;
       eventData->index = count -1;
       g_object_ref(mAtkObject);
       g_object_ref(atkAccessible);
       g_timeout_add(0, fireRootAccessibleAddedCB, eventData);
     }
 
-    return NS_OK;
+    return PR_TRUE;
 }
 
-nsresult
-nsApplicationAccessibleWrap::RemoveRootAccessible(nsIAccessible *aRootAccWrap)
+PRBool
+nsApplicationAccessibleWrap::RemoveChild(nsAccessible* aChild)
 {
-    NS_ENSURE_ARG_POINTER(aRootAccWrap);
+    PRInt32 index = aChild->GetIndexInParent();
 
-    PRInt32 index = mChildren.IndexOf(aRootAccWrap);
-
-    AtkObject *atkAccessible = nsAccessibleWrap::GetAtkObject(aRootAccWrap);
+    AtkObject *atkAccessible = nsAccessibleWrap::GetAtkObject(aChild);
     atk_object_set_parent(atkAccessible, NULL);
     g_signal_emit_by_name(mAtkObject, "children_changed::remove", index,
                           atkAccessible, NULL);
 
-    return nsApplicationAccessible::RemoveRootAccessible(aRootAccWrap);
+    return nsApplicationAccessible::RemoveChild(aChild);
 }
 
 void
 nsApplicationAccessibleWrap::PreCreate()
 {
     if (!sATKChecked) {
         sATKLib = PR_LoadLibrary(sATKLibName);
         if (sATKLib) {
--- a/accessible/src/atk/nsApplicationAccessibleWrap.h
+++ b/accessible/src/atk/nsApplicationAccessibleWrap.h
@@ -52,17 +52,17 @@ public:
 
 public:
     nsApplicationAccessibleWrap();
     virtual ~nsApplicationAccessibleWrap();
 
     // nsAccessNode
     virtual PRBool Init();
 
+    // nsAccessible
+    virtual PRBool AppendChild(nsAccessible* aChild);
+    virtual PRBool RemoveChild(nsAccessible* aChild);
+
     // return the atk object for app root accessible
     NS_IMETHOD GetNativeInterface(void **aOutAccessible);
-
-    // nsApplicationAccessible
-    virtual nsresult AddRootAccessible(nsIAccessible *aRootAccWrap);
-    virtual nsresult RemoveRootAccessible(nsIAccessible *aRootAccWrap);
 };
 
 #endif   /* __NS_APP_ROOT_ACCESSIBLE_H__ */
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -1896,55 +1896,46 @@ nsAccessibilityService::CreateAccessible
   }
 
   return accessible.forget();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIAccessibilityService (DON'T put methods here)
 
-nsresult
-nsAccessibilityService::AddNativeRootAccessible(void *aAtkAccessible,
-                                                nsIAccessible **aRootAccessible)
+nsAccessible*
+nsAccessibilityService::AddNativeRootAccessible(void* aAtkAccessible)
+ {
+#ifdef MOZ_ACCESSIBILITY_ATK
+  nsApplicationAccessible* applicationAcc =
+    nsAccessNode::GetApplicationAccessible();
+  if (!applicationAcc)
+    return nsnull;
+
+  nsNativeRootAccessibleWrap* nativeRootAcc =
+     new nsNativeRootAccessibleWrap((AtkObject*)aAtkAccessible);
+  if (!nativeRootAcc)
+    return nsnull;
+
+  if (applicationAcc->AppendChild(nativeRootAcc))
+    return nativeRootAcc;
+#endif
+
+  return nsnull;
+ }
+
+void
+nsAccessibilityService::RemoveNativeRootAccessible(nsAccessible* aAccessible)
 {
 #ifdef MOZ_ACCESSIBILITY_ATK
-  nsNativeRootAccessibleWrap* rootAccWrap =
-    new nsNativeRootAccessibleWrap((AtkObject*)aAtkAccessible);
-
-  *aRootAccessible = static_cast<nsIAccessible*>(rootAccWrap);
-  NS_ADDREF(*aRootAccessible);
-
-  nsApplicationAccessible *applicationAcc =
+  nsApplicationAccessible* applicationAcc =
     nsAccessNode::GetApplicationAccessible();
-  NS_ENSURE_STATE(applicationAcc);
-
-  applicationAcc->AddRootAccessible(*aRootAccessible);
 
-  return NS_OK;
-#else
-  return NS_ERROR_NOT_IMPLEMENTED;
-#endif
-}
-
-nsresult
-nsAccessibilityService::RemoveNativeRootAccessible(nsIAccessible *aRootAccessible)
-{
-#ifdef MOZ_ACCESSIBILITY_ATK
-  void* atkAccessible;
-  aRootAccessible->GetNativeInterface(&atkAccessible);
-
-  nsApplicationAccessible *applicationAcc =
-    nsAccessNode::GetApplicationAccessible();
-  NS_ENSURE_STATE(applicationAcc);
-
-  applicationAcc->RemoveRootAccessible(aRootAccessible);
-
-  return NS_OK;
-#else
-  return NS_ERROR_NOT_IMPLEMENTED;
+  if (applicationAcc)
+    applicationAcc->RemoveChild(aAccessible);
 #endif
 }
 
 // Called from layout when the frame tree owned by a node changes significantly
 nsresult
 nsAccessibilityService::InvalidateSubtreeFor(nsIPresShell *aShell,
                                              nsIContent *aChangeContent,
                                              PRUint32 aChangeType)
--- a/accessible/src/base/nsAccessibilityService.h
+++ b/accessible/src/base/nsAccessibilityService.h
@@ -109,19 +109,18 @@ public:
                                                  nsIAccessible **aAccessible);
   virtual nsresult CreateHTMLTextAccessible(nsIFrame *aFrame,
                                             nsIAccessible **aAccessible);
   virtual nsresult CreateHTMLTextFieldAccessible(nsIFrame *aFrame,
                                                  nsIAccessible **aAccessible);
   virtual nsresult CreateHTMLCaptionAccessible(nsIFrame *aFrame,
                                                nsIAccessible **aAccessible);
 
-  virtual nsresult AddNativeRootAccessible(void *aAtkAccessible,
-                                           nsIAccessible **aAccessible);
-  virtual nsresult RemoveNativeRootAccessible(nsIAccessible *aRootAccessible);
+  virtual nsAccessible* AddNativeRootAccessible(void* aAtkAccessible);
+  virtual void RemoveNativeRootAccessible(nsAccessible* aRootAccessible);
 
   virtual nsresult InvalidateSubtreeFor(nsIPresShell *aPresShell,
                                         nsIContent *aContent,
                                         PRUint32 aChangeType);
 
   virtual void NotifyOfAnchorJumpTo(nsIContent *aTarget);
 
   virtual void PresShellDestroyed(nsIPresShell* aPresShell);
--- a/accessible/src/base/nsApplicationAccessible.cpp
+++ b/accessible/src/base/nsApplicationAccessible.cpp
@@ -409,32 +409,32 @@ nsAccessible*
 nsApplicationAccessible::GetParent()
 {
   return nsnull;
 }
 
 void
 nsApplicationAccessible::InvalidateChildren()
 {
-  // Do nothing because application children are kept updated by
-  // AddRootAccessible() and RemoveRootAccessible() method calls.
+  // Do nothing because application children are kept updated by AppendChild()
+  // and RemoveChild() method calls.
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessible protected methods
 
 void
 nsApplicationAccessible::CacheChildren()
 {
   // CacheChildren is called only once for application accessible when its
   // children are requested because empty InvalidateChldren() prevents its
   // repeated calls.
 
-  // Basically children are kept updated by Add/RemoveRootAccessible method
-  // calls. However if there are open windows before accessibility was started
+  // Basically children are kept updated by Append/RemoveChild method calls.
+  // However if there are open windows before accessibility was started
   // then we need to make sure root accessibles for open windows are created so
   // that all root accessibles are stored in application accessible children
   // array.
 
   nsCOMPtr<nsIWindowMediator> windowMediator =
     do_GetService(NS_WINDOWMEDIATOR_CONTRACTID);
 
   nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
@@ -476,40 +476,32 @@ nsApplicationAccessible::GetSiblingAtOff
     *aError = NS_OK; // fail peacefully
 
   return nsnull;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // Public methods
 
-nsresult
-nsApplicationAccessible::AddRootAccessible(nsIAccessible *aRootAccessible)
+PRBool
+nsApplicationAccessible::AppendChild(nsAccessible* aChild)
 {
-  NS_ENSURE_ARG_POINTER(aRootAccessible);
-
-  nsRefPtr<nsAccessible> rootAcc = do_QueryObject(aRootAccessible);
+  if (!mChildren.AppendElement(aChild))
+    return PR_FALSE;
 
-  if (!mChildren.AppendElement(rootAcc))
-    return NS_ERROR_FAILURE;
-
-  rootAcc->SetParent(this);
-
-  return NS_OK;
+  aChild->SetParent(this);
+  return PR_TRUE;
 }
 
-nsresult
-nsApplicationAccessible::RemoveRootAccessible(nsIAccessible *aRootAccessible)
+PRBool
+nsApplicationAccessible::RemoveChild(nsAccessible* aChild)
 {
-  NS_ENSURE_ARG_POINTER(aRootAccessible);
-
-  // It's not needed to void root accessible parent because this method is
-  // called on root accessible shutdown and its parent will be cleared
-  // properly.
-  return mChildren.RemoveElement(aRootAccessible) ? NS_OK : NS_ERROR_FAILURE;
+  // It's not needed to unbind root accessible from parent because this method
+  // is called when root accessible is shutdown and it'll be unbound properly.
+  return mChildren.RemoveElement(aChild);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIAccessNode
 
 NS_IMETHODIMP
 nsApplicationAccessible::GetDOMNode(nsIDOMNode **aDOMNode)
 {
--- a/accessible/src/base/nsApplicationAccessible.h
+++ b/accessible/src/base/nsApplicationAccessible.h
@@ -111,20 +111,18 @@ public:
 
   // nsAccessible
   virtual nsresult GetARIAState(PRUint32 *aState, PRUint32 *aExtraState);
   virtual nsresult GetRoleInternal(PRUint32 *aRole);
   virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
   virtual nsAccessible* GetParent();
 
   virtual void InvalidateChildren();
-
-  // nsApplicationAccessible
-  virtual nsresult AddRootAccessible(nsIAccessible *aRootAccWrap);
-  virtual nsresult RemoveRootAccessible(nsIAccessible *aRootAccWrap);
+  virtual PRBool AppendChild(nsAccessible* aChild);
+  virtual PRBool RemoveChild(nsAccessible* aChild);
 
 protected:
 
   // nsAccessible
   virtual void CacheChildren();
   virtual nsAccessible* GetSiblingAtOffset(PRInt32 aOffset,
                                            nsresult *aError = nsnull);
 
--- a/accessible/src/base/nsRootAccessible.cpp
+++ b/accessible/src/base/nsRootAccessible.cpp
@@ -826,36 +826,34 @@ void nsRootAccessible::GetTargetNode(nsI
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessNode
 
 PRBool
 nsRootAccessible::Init()
 {
   nsApplicationAccessible *applicationAcc = GetApplicationAccessible();
-  if (!applicationAcc)
+  if (!applicationAcc || !applicationAcc->AppendChild(this))
     return PR_FALSE;
 
-  applicationAcc->AddRootAccessible(this);
-
   return nsDocAccessibleWrap::Init();
 }
 
 void
 nsRootAccessible::Shutdown()
 {
   // Called manually or by nsAccessNode::LastRelease()
   if (!mWeakShell)
     return;  // Already shutdown
 
   nsApplicationAccessible *applicationAcc = GetApplicationAccessible();
   if (!applicationAcc)
     return;
 
-  applicationAcc->RemoveRootAccessible(this);
+  applicationAcc->RemoveChild(this);
 
   mCurrentARIAMenubar = nsnull;
 
   nsDocAccessibleWrap::Shutdown();
 }
 
 // nsRootAccessible protected member
 already_AddRefed<nsIDocShellTreeItem>
@@ -935,18 +933,18 @@ nsRootAccessible::GetRelationByType(PRUi
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessible
 
 nsAccessible*
 nsRootAccessible::GetParent()
 {
-  // Parent has been setted in nsApplicationAccesible::AddRootAccessible()
-  // when root accessible was intialized.
+  // Parent has been set in nsApplicationAccesible::AppendChild() when root
+  // accessible was initialized.
   return mParent;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // Protected members
 
 nsresult
 nsRootAccessible::HandlePopupShownEvent(nsAccessible *aAccessible)
--- a/widget/src/gtk2/nsAccessibilityHelper.cpp
+++ b/widget/src/gtk2/nsAccessibilityHelper.cpp
@@ -49,28 +49,28 @@ gint RunDialog(GtkDialog* aDialog)
 {
 #ifdef ACCESSIBILITY
   if (!nsWindow::sAccessibilityEnabled) {
     return gtk_dialog_run (aDialog);
   }
 
   nsCOMPtr<nsIAccessibilityService> accService =
     do_GetService ("@mozilla.org/accessibilityService;1");
-  nsCOMPtr<nsIAccessible> accessible;
 
   // Attach the dialog accessible to app accessible tree
+  nsAccessible* windowAcc = nsnull;
   if (accService) {
     AtkObject* gailWindow = gtk_widget_get_accessible(GTK_WIDGET(aDialog));
-    accService->AddNativeRootAccessible(gailWindow, getter_AddRefs(accessible));
+    windowAcc = accService->AddNativeRootAccessible(gailWindow);
   }
 
   gint result = gtk_dialog_run (aDialog);
 
   // Deattach the dialog accessible
-  if (accService && accessible) {
-    accService->RemoveNativeRootAccessible(accessible);
+  if (accService && windowAcc) {
+    accService->RemoveNativeRootAccessible(windowAcc);
   }
 
   return result;
 #else
   return gtk_dialog_run (aDialog);
 #endif
 }