Bug 606924, part6 - move GetAccessibleOrContainer to nsDocAccessible, r=fer, a=final+
authorAlexander Surkov <surkov.alexander@gmail.com>
Fri, 28 Jan 2011 12:37:38 +0800
changeset 61462 0b39828124f935852a17dc07d9d8179d6a3e826f
parent 61461 63586498435058ef012421c3057b09b6f0965f13
child 61463 a2d89cf5cd1820b09fdd1a6af41f8a6849f3ec7b
push idunknown
push userunknown
push dateunknown
reviewersfer, final
bugs606924
milestone2.0b11pre
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 606924, part6 - move GetAccessibleOrContainer to nsDocAccessible, r=fer, a=final+
accessible/src/base/nsAccessibilityService.cpp
accessible/src/base/nsDocAccessible.cpp
accessible/src/base/nsDocAccessible.h
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -786,25 +786,22 @@ nsAccessibilityService::GetAccessible(ns
   nsDocAccessible* document = GetDocAccessible(aNode->GetOwnerDoc());
   return document ? document->GetAccessible(aNode) : nsnull;
 }
 
 nsAccessible*
 nsAccessibilityService::GetAccessibleOrContainer(nsINode* aNode,
                                                  nsIWeakReference* aWeakShell)
 {
-  if (!aNode || !aNode->IsInDoc())
+  if (!aNode)
     return nsnull;
 
-  nsINode* currNode = aNode;
-  nsAccessible* accessible = nsnull;
-  while (!(accessible = GetAccessibleInWeakShell(currNode, aWeakShell)) &&
-         (currNode = currNode->GetNodeParent()));
-
-  return accessible;
+  // XXX: weak shell is ignored until multiple shell documents are supported.
+  nsDocAccessible* document = GetDocAccessible(aNode->GetOwnerDoc());
+  return document ? document->GetAccessibleOrContainer(aNode) : nsnull;
 }
 
 static PRBool HasRelatedContent(nsIContent *aContent)
 {
   nsAutoString id;
   if (!aContent || !nsCoreUtils::GetID(aContent, id) || id.IsEmpty()) {
     return PR_FALSE;
   }
--- a/accessible/src/base/nsDocAccessible.cpp
+++ b/accessible/src/base/nsDocAccessible.cpp
@@ -1320,16 +1320,30 @@ nsDocAccessible::GetAccessibleByUniqueID
     child = childDocument->GetAccessibleByUniqueIDInSubtree(aUniqueID);
     if (child)
       return child;
   }
 
   return nsnull;
 }
 
+nsAccessible*
+nsDocAccessible::GetAccessibleOrContainer(nsINode* aNode)
+{
+  if (!aNode || !aNode->IsInDoc())
+    return nsnull;
+
+  nsINode* currNode = aNode;
+  nsAccessible* accessible = nsnull;
+  while (!(accessible = GetAccessible(currNode)) &&
+         (currNode = currNode->GetNodeParent()));
+
+  return accessible;
+}
+
 bool
 nsDocAccessible::BindToDocument(nsAccessible* aAccessible,
                                 nsRoleMapEntry* aRoleMapEntry)
 {
   if (!aAccessible)
     return false;
 
   // Put into DOM node cache.
@@ -1385,34 +1399,32 @@ nsDocAccessible::ContentInserted(nsICont
                                  nsIContent* aStartChildNode,
                                  nsIContent* aEndChildNode)
 {
   /// Pend tree update on content insertion until layout.
   if (mNotificationController) {
     // Update the whole tree of this document accessible when the container is
     // null (document element is inserted or removed).
     nsAccessible* container = aContainerNode ?
-      GetAccService()->GetAccessibleOrContainer(aContainerNode, mWeakShell) :
-      this;
+      GetAccessibleOrContainer(aContainerNode) : this;
 
     mNotificationController->ScheduleContentInsertion(container,
                                                       aStartChildNode,
                                                       aEndChildNode);
   }
 }
 
 void
 nsDocAccessible::ContentRemoved(nsIContent* aContainerNode,
                                 nsIContent* aChildNode)
 {
   // Update the whole tree of this document accessible when the container is
   // null (document element is removed).
   nsAccessible* container = aContainerNode ?
-    GetAccService()->GetAccessibleOrContainer(aContainerNode, mWeakShell) :
-    this;
+    GetAccessibleOrContainer(aContainerNode) : this;
 
   UpdateTree(container, aChildNode, PR_FALSE);
 }
 
 void
 nsDocAccessible::RecreateAccessible(nsINode* aNode)
 {
   // XXX: we shouldn't recreate whole accessible subtree that happens when
@@ -1441,17 +1453,17 @@ nsDocAccessible::RecreateAccessible(nsIN
 
   } else {
     // Not accessible node may not have container accessible if we recreate
     // an accessible asynchronously.
     // XXX: asynchronous RecreateAccessible notifications should be coalesced
     // with accessible tree mutation notifications. We could trigger
     // ContentRemoved/ContentInserted pair for that but it moves us away from
     // the idea to not recreate the whole subtree.
-    parent = GetAccService()->GetContainerAccessible(aNode, mWeakShell);
+    parent = GetContainerAccessible(aNode);
     if (!parent)
       return;
   }
 
   // Get new accessible and fire show event.
   parent->UpdateChildren();
 
   nsAccessible* newAccessible =
@@ -1486,18 +1498,17 @@ nsDocAccessible::NotifyOfCachingEnd(nsAc
   if (mCacheRoot == aAccessible && !mIsPostCacheProcessing) {
     // Allow invalidation list insertions while container children are recached.
     mIsPostCacheProcessing = PR_TRUE;
 
     // Invalidate children of container accessible for each element in
     // invalidation list.
     for (PRUint32 idx = 0; idx < mInvalidationList.Length(); idx++) {
       nsIContent* content = mInvalidationList[idx];
-      nsAccessible* container =
-        GetAccService()->GetContainerAccessible(content, mWeakShell);
+      nsAccessible* container = GetContainerAccessible(content);
 
       // Make sure we keep children updated. While we're inside of caching loop
       // then we must exist it with cached children.
       container->UpdateChildren();
     }
     mInvalidationList.Clear();
 
     mCacheRoot = nsnull;
@@ -1818,18 +1829,17 @@ nsDocAccessible::ProcessPendingEvent(Acc
   }
 }
 
 void
 nsDocAccessible::ProcessAnchorJump(nsIContent* aTargetNode)
 {
   // If the jump target is not accessible then fire an event for nearest
   // accessible in parent chain.
-  nsAccessible* target = GetAccService()->GetAccessibleOrContainer(aTargetNode,
-                                                                   mWeakShell);
+  nsAccessible* target = GetAccessibleOrContainer(aTargetNode);
   if (!target)
     return;
 
   // XXX: bug 625699, note in some cases the node could go away before we flush
   // the queue, for example if the node becomes inaccessible, or is removed from
   // the DOM.
   FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_SCROLLING_START,
                              target->GetNode());
@@ -1866,18 +1876,17 @@ nsDocAccessible::ProcessContentInserted(
   // inserted content and its container or the content was reinserted into
   // different container of unrelated part of tree). These cases result in
   // double processing, however generated events are coalesced and we don't
   // harm an AT.
   // Theoretically the element might be not in tree at all at this point what
   // means there's no container.
   for (PRUint32 idx = 0; idx < aInsertedContent->Length(); idx++) {
     nsAccessible* directContainer =
-      GetAccService()->GetContainerAccessible(aInsertedContent->ElementAt(idx),
-                                              mWeakShell);
+      GetContainerAccessible(aInsertedContent->ElementAt(idx));
     if (directContainer)
       UpdateTree(directContainer, aInsertedContent->ElementAt(idx), PR_TRUE);
   }
 }
 
 void
 nsDocAccessible::UpdateTree(nsAccessible* aContainer, nsIContent* aChildNode,
                             PRBool aIsInsert)
--- a/accessible/src/base/nsDocAccessible.h
+++ b/accessible/src/base/nsDocAccessible.h
@@ -255,16 +255,30 @@ public:
 
   /**
    * Return the cached accessible by the given unique ID looking through
    * this and nested documents.
    */
   nsAccessible* GetAccessibleByUniqueIDInSubtree(void* aUniqueID);
 
   /**
+   * Return an accessible for the given DOM node or container accessible if
+   * the node is not accessible.
+   */
+  nsAccessible* GetAccessibleOrContainer(nsINode* aNode);
+
+  /**
+   * Return a container accessible for the given DOM node.
+   */
+  inline nsAccessible* GetContainerAccessible(nsINode* aNode)
+  {
+    return aNode ? GetAccessibleOrContainer(aNode->GetNodeParent()) : nsnull;
+  }
+
+  /**
    * Return true if the given ID is referred by relation attribute.
    *
    * @note Different elements may share the same ID if they are hosted inside
    *       XBL bindings. Be careful the result of this method may be  senseless
    *       while it's called for XUL elements (where XBL is used widely).
    */
   PRBool IsDependentID(const nsAString& aID) const
     { return mDependentIDsHash.Get(aID, nsnull); }