Bug 740725 - Add down-casting to nsXULTreeAccessible, r=tbsaunde, f=surkov
authorMark Capella <markcapella@twcny.rr.com>
Tue, 03 Apr 2012 18:54:01 +0900
changeset 94215 8f85a5488ffb5801e19b8d03123b9558c8865b37
parent 94214 8d741cb2569a3309dea63e2f2ffc952a7332824a
child 94216 5964d3d4bc66b41b2042767139da40bba4c9c6b7
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs740725
milestone14.0a1
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 740725 - Add down-casting to nsXULTreeAccessible, r=tbsaunde, f=surkov
accessible/src/base/nsAccessibilityService.cpp
accessible/src/base/nsAccessible.h
accessible/src/base/nsRootAccessible.cpp
accessible/src/xul/nsXULTreeAccessible.cpp
accessible/src/xul/nsXULTreeAccessible.h
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -600,17 +600,17 @@ void
 nsAccessibilityService::TreeViewChanged(nsIPresShell* aPresShell,
                                         nsIContent* aContent,
                                         nsITreeView* aView)
 {
   nsDocAccessible* document = GetDocAccessible(aPresShell->GetDocument());
   if (document) {
     nsAccessible* accessible = document->GetAccessible(aContent);
     if (accessible) {
-      nsRefPtr<nsXULTreeAccessible> treeAcc = do_QueryObject(accessible);
+      nsXULTreeAccessible* treeAcc = accessible->AsXULTree();
       if (treeAcc) 
         treeAcc->TreeViewChanged(aView);
     }
   }
 }
 
 void
 nsAccessibilityService::UpdateListBullet(nsIPresShell* aPresShell,
--- a/accessible/src/base/nsAccessible.h
+++ b/accessible/src/base/nsAccessible.h
@@ -67,16 +67,17 @@ class nsHTMLLIAccessible;
 struct nsRoleMapEntry;
 class Relation;
 namespace mozilla {
 namespace a11y {
 class TableAccessible;
 }
 }
 class nsTextAccessible;
+class nsXULTreeAccessible;
 
 struct nsRect;
 class nsIContent;
 class nsIFrame;
 class nsIAtom;
 class nsIView;
 
 typedef nsRefPtrHashtable<nsPtrHashKey<const void>, nsAccessible>
@@ -462,16 +463,19 @@ public:
   nsHTMLLIAccessible* AsHTMLListItem();
 
   inline bool IsImageAccessible() const { return mFlags & eImageAccessible; }
   nsHTMLImageAccessible* AsImage();
 
   bool IsImageMapAccessible() const { return mFlags & eImageMapAccessible; }
   nsHTMLImageMapAccessible* AsImageMap();
 
+  inline bool IsXULTree() const { return mFlags & eXULTreeAccessible; }
+  nsXULTreeAccessible* AsXULTree();
+
   inline bool IsListControl() const { return mFlags & eListControlAccessible; }
 
   inline bool IsMenuButton() const { return mFlags & eMenuButtonAccessible; }
 
   inline bool IsMenuPopup() const { return mFlags & eMenuPopupAccessible; }
 
   inline bool IsRoot() const { return mFlags & eRootAccessible; }
   nsRootAccessible* AsRoot();
@@ -713,17 +717,18 @@ protected:
     eHTMLFileInputAccessible = 1 << 9,
     eHTMLListItemAccessible = 1 << 10,
     eImageAccessible = 1 << 11,
     eImageMapAccessible = 1 << 12,
     eListControlAccessible = 1 << 13,
     eMenuButtonAccessible = 1 << 14,
     eMenuPopupAccessible = 1 << 15,
     eRootAccessible = 1 << 16,
-    eTextLeafAccessible = 1 << 17
+    eTextLeafAccessible = 1 << 17,
+    eXULTreeAccessible = 1 << 18
   };
 
   //////////////////////////////////////////////////////////////////////////////
   // Miscellaneous helpers
 
   /**
    * Return ARIA role (helper method).
    */
--- a/accessible/src/base/nsRootAccessible.cpp
+++ b/accessible/src/base/nsRootAccessible.cpp
@@ -381,31 +381,26 @@ nsRootAccessible::ProcessDOMEvent(nsIDOM
   nsAccessible* accessible = 
     targetDocument->GetAccessibleOrContainer(origTargetNode);
   if (!accessible)
     return;
 
   nsINode* targetNode = accessible->GetNode();
 
 #ifdef MOZ_XUL
-  nsRefPtr<nsXULTreeAccessible> treeAcc;
-  if (targetNode->IsElement() &&
-      targetNode->AsElement()->NodeInfo()->Equals(nsGkAtoms::tree,
-                                                  kNameSpaceID_XUL)) {
-    treeAcc = do_QueryObject(accessible);
-    if (treeAcc) {
-      if (eventType.EqualsLiteral("TreeRowCountChanged")) {
-        HandleTreeRowCountChangedEvent(aDOMEvent, treeAcc);
-        return;
-      }
+  nsXULTreeAccessible* treeAcc = accessible->AsXULTree();
+  if (treeAcc) {
+    if (eventType.EqualsLiteral("TreeRowCountChanged")) {
+      HandleTreeRowCountChangedEvent(aDOMEvent, treeAcc);
+      return;
+    }
 
-      if (eventType.EqualsLiteral("TreeInvalidated")) {
-        HandleTreeInvalidatedEvent(aDOMEvent, treeAcc);
-        return;
-      }
+    if (eventType.EqualsLiteral("TreeInvalidated")) {
+      HandleTreeInvalidatedEvent(aDOMEvent, treeAcc);
+      return;
     }
   }
 #endif
 
   if (eventType.EqualsLiteral("RadioStateChange")) {
     PRUint64 state = accessible->State();
 
     // radiogroup in prefWindow is exposed as a list,
--- a/accessible/src/xul/nsXULTreeAccessible.cpp
+++ b/accessible/src/xul/nsXULTreeAccessible.cpp
@@ -63,16 +63,18 @@ using namespace mozilla::a11y;
 ////////////////////////////////////////////////////////////////////////////////
 // nsXULTreeAccessible
 ////////////////////////////////////////////////////////////////////////////////
 
 nsXULTreeAccessible::
   nsXULTreeAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
   nsAccessibleWrap(aContent, aDoc)
 {
+  mFlags |= eXULTreeAccessible;
+
   mTree = nsCoreUtils::GetTreeBoxObject(aContent);
   if (mTree)
     mTree->GetView(getter_AddRefs(mTreeView));
 
   NS_ASSERTION(mTree && mTreeView, "Can't get mTree or mTreeView!\n");
 
   nsIContent* parentContent = mContent->GetParent();
   if (parentContent) {
@@ -858,17 +860,17 @@ nsXULTreeItemAccessibleBase::RelationByT
 
   PRInt32 parentIndex = -1;
   if (!NS_SUCCEEDED(mTreeView->GetParentIndex(mRow, &parentIndex)))
     return Relation();
 
   if (parentIndex == -1)
     return Relation(mParent);
 
-  nsRefPtr<nsXULTreeAccessible> treeAcc = do_QueryObject(mParent);
+  nsXULTreeAccessible* treeAcc = mParent->AsXULTree();
   return Relation(treeAcc->GetTreeItemAccessible(parentIndex));
 }
 
 PRUint8
 nsXULTreeItemAccessibleBase::ActionCount()
 {
   // "activate" action is available for all treeitems, "expand/collapse" action
   // is avaible for treeitem which is container.
@@ -1278,17 +1280,17 @@ nsXULTreeColumnsAccessible::GetSiblingAt
   nsCOMPtr<nsITreeBoxObject> tree = nsCoreUtils::GetTreeBoxObject(mContent);
   if (tree) {
     nsCOMPtr<nsITreeView> treeView;
     tree->GetView(getter_AddRefs(treeView));
     if (treeView) {
       PRInt32 rowCount = 0;
       treeView->GetRowCount(&rowCount);
       if (rowCount > 0 && aOffset <= rowCount) {
-        nsRefPtr<nsXULTreeAccessible> treeAcc = do_QueryObject(Parent());
+        nsXULTreeAccessible* treeAcc = Parent()->AsXULTree();
 
         if (treeAcc)
           return treeAcc->GetTreeItemAccessible(aOffset - 1);
       }
     }
   }
 
   return nsnull;
--- a/accessible/src/xul/nsXULTreeAccessible.h
+++ b/accessible/src/xul/nsXULTreeAccessible.h
@@ -315,9 +315,19 @@ public:
 
 protected:
 
   // nsAccessible
   virtual nsAccessible* GetSiblingAtOffset(PRInt32 aOffset,
                                            nsresult *aError = nsnull) const;
 };
 
+////////////////////////////////////////////////////////////////////////////////
+// nsAccessible downcasting method
+
+inline nsXULTreeAccessible*
+nsAccessible::AsXULTree()
+{
+  return IsXULTree() ?
+    static_cast<nsXULTreeAccessible*>(this) : nsnull;
+}
+
 #endif