Bug 491645 - use getTreeBody instead explicit searching of treechildren element, r=marcoz
authorAlexander Surkov <surkov.alexander@gmail.com>
Wed, 06 May 2009 17:54:26 +0800
changeset 28029 7518078cb842d44e7019b0481fedb2566f176cc0
parent 28028 2f8e64eb3691d8ff8f0c21444e6a2168e7cc6c43
child 28030 5b6ce32aeab3e5546ee54833fdfb7cc8489c2929
push id6848
push usersurkov.alexander@gmail.com
push dateWed, 06 May 2009 08:54:54 +0000
treeherdermozilla-central@7518078cb842 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarcoz
bugs491645
milestone1.9.2a1pre
Bug 491645 - use getTreeBody instead explicit searching of treechildren element, r=marcoz
accessible/src/base/nsCoreUtils.cpp
accessible/src/base/nsCoreUtils.h
accessible/src/msaa/nsXULTreeAccessibleWrap.cpp
accessible/src/xul/nsXULTreeAccessible.cpp
--- a/accessible/src/base/nsCoreUtils.cpp
+++ b/accessible/src/base/nsCoreUtils.cpp
@@ -49,16 +49,17 @@
 #include "nsIDOMDocumentView.h"
 #include "nsIDOMDocumentXBL.h"
 #include "nsIDOMHTMLDocument.h"
 #include "nsIDOMHTMLElement.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMRange.h"
 #include "nsIDOMViewCSS.h"
 #include "nsIDOMWindowInternal.h"
+#include "nsIDOMXULElement.h"
 #include "nsIDocShell.h"
 #include "nsIDocumentViewer.h"
 #include "nsIContentViewer.h"
 #include "nsIEventListenerManager.h"
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "nsIScrollableFrame.h"
 #include "nsIEventStateManager.h"
@@ -806,8 +807,22 @@ nsCoreUtils::GetComputedStyleDeclaration
     return;
 
   nsCOMPtr<nsIDOMViewCSS> viewCSS(do_QueryInterface(doc->GetWindow()));
   if (!viewCSS)
     return;
 
   viewCSS->GetComputedStyle(domElement, aPseudoElt, aCssDecl);
 }
+
+already_AddRefed<nsIBoxObject>
+nsCoreUtils::GetTreeBodyBoxObject(nsITreeBoxObject *aTreeBoxObj)
+{
+  nsCOMPtr<nsIDOMElement> tcElm;
+  aTreeBoxObj->GetTreeBody(getter_AddRefs(tcElm));
+  nsCOMPtr<nsIDOMXULElement> tcXULElm(do_QueryInterface(tcElm));
+  if (!tcXULElm)
+    return nsnull;
+
+  nsIBoxObject *boxObj = nsnull;
+  tcXULElm->GetBoxObject(&boxObj);
+  return boxObj;
+}
--- a/accessible/src/base/nsCoreUtils.h
+++ b/accessible/src/base/nsCoreUtils.h
@@ -38,16 +38,19 @@
 
 #ifndef nsCoreUtils_h_
 #define nsCoreUtils_h_
 
 #include "nsAccessibilityAtoms.h"
 
 #include "nsIDOMNode.h"
 #include "nsIContent.h"
+#include "nsIBoxObject.h"
+#include "nsITreeBoxObject.h"
+
 #include "nsIFrame.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIArray.h"
 #include "nsPoint.h"
 
 class nsCoreUtils
 {
 public:
@@ -326,13 +329,17 @@ public:
    */
   static nsIContent *GetLabelContent(nsIContent *aForNode);
 
   /**
    * Return the HTML label element for the given HTML element.
    */
   static nsIContent *GetHTMLLabelContent(nsIContent *aForNode);
 
-  
+  /**
+   * Return box object for XUL treechildren element by tree box object.
+   */
+  static already_AddRefed<nsIBoxObject>
+    GetTreeBodyBoxObject(nsITreeBoxObject *aTreeBoxObj);
 };
 
 #endif
 
--- a/accessible/src/msaa/nsXULTreeAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsXULTreeAccessibleWrap.cpp
@@ -33,17 +33,16 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsXULTreeAccessibleWrap.h"
 
-#include "nsIBoxObject.h"
 #include "nsTextFormatter.h"
 #include "nsIFrame.h"
 
 // --------------------------------------------------------
 // nsXULTreeAccessibleWrap
 // --------------------------------------------------------
 
 nsXULTreeAccessibleWrap::nsXULTreeAccessibleWrap(nsIDOMNode *aDOMNode, nsIWeakReference *aShell):
@@ -111,23 +110,17 @@ nsXULTreeitemAccessibleWrap::GetBounds(P
   *aHeight = 0;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   // Get x coordinate and width from treechildren element, get y coordinate and
   // height from tree cell.
 
-  nsCOMPtr<nsIDOMElement> tcElm;
-  mTree->GetTreeBody(getter_AddRefs(tcElm));
-  nsCOMPtr<nsIDOMXULElement> tcXULElm(do_QueryInterface(tcElm));
-  NS_ENSURE_STATE(tcXULElm);
-
-  nsCOMPtr<nsIBoxObject> boxObj;
-  tcXULElm->GetBoxObject(getter_AddRefs(boxObj));
+  nsCOMPtr<nsIBoxObject> boxObj = nsCoreUtils::GetTreeBodyBoxObject(mTree);
   NS_ENSURE_STATE(boxObj);
 
   PRInt32 cellStartX, cellWidth;
   nsresult rv = mTree->GetCoordsForCellItem(mRow, mColumn, EmptyCString(),
                                             &cellStartX, aY,
                                             &cellWidth, aHeight);
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/accessible/src/xul/nsXULTreeAccessible.cpp
+++ b/accessible/src/xul/nsXULTreeAccessible.cpp
@@ -31,17 +31,16 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "nsIBoxObject.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDOMXULMultSelectCntrlEl.h"
 #include "nsIDOMXULTreeElement.h"
 #include "nsITreeSelection.h"
 #include "nsXULTreeAccessibleWrap.h"
 #include "nsIMutableArray.h"
 #include "nsComponentManagerUtils.h"
 
@@ -1185,71 +1184,47 @@ NS_IMETHODIMP nsXULTreeitemAccessible::D
   }
   else if (index == eAction_Expand && IsExpandable()) {
     return mTreeView->ToggleOpenState(mRow);
   }
 
   return NS_ERROR_INVALID_ARG;
 }
 
-NS_IMETHODIMP nsXULTreeitemAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
+NS_IMETHODIMP
+nsXULTreeitemAccessible::GetBounds(PRInt32 *aX, PRInt32 *aY,
+                                   PRInt32 *aWidth, PRInt32 *aHeight)
 {
-  NS_ENSURE_ARG_POINTER(x);
-  *x = 0;
-  NS_ENSURE_ARG_POINTER(y);
-  *y = 0;
-  NS_ENSURE_ARG_POINTER(width);
-  *width = 0;
-  NS_ENSURE_ARG_POINTER(height);
-  *height = 0;
+  NS_ENSURE_ARG_POINTER(aX);
+  *aX = 0;
+  NS_ENSURE_ARG_POINTER(aY);
+  *aY = 0;
+  NS_ENSURE_ARG_POINTER(aWidth);
+  *aWidth = 0;
+  NS_ENSURE_ARG_POINTER(aHeight);
+  *aHeight = 0;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  // This Bounds are based on Tree's coord
-  mTree->GetCoordsForCellItem(mRow, mColumn, EmptyCString(), x, y, width, height);
+  // Get bounds for tree cell and add x and y of treechildren element to
+  // x and y of the cell.
 
-  // Get treechildren's BoxObject to adjust the Bounds' upper left corner
-  // XXXvarga consider using mTree->GetTreeBody()
-  nsCOMPtr<nsIBoxObject> boxObject(do_QueryInterface(mTree));
-  if (boxObject) {
-    nsCOMPtr<nsIDOMElement> boxElement;
-    boxObject->GetElement(getter_AddRefs(boxElement));
-    nsCOMPtr<nsIDOMNode> boxNode(do_QueryInterface(boxElement));
-    if (boxNode) {
-      nsCOMPtr<nsIDOMNodeList> childNodes;
-      boxNode->GetChildNodes(getter_AddRefs(childNodes));
-      if (childNodes) {
-        nsAutoString name;
-        nsCOMPtr<nsIDOMNode> childNode;
-        PRUint32 childCount, childIndex;
+  nsCOMPtr<nsIBoxObject> boxObj = nsCoreUtils::GetTreeBodyBoxObject(mTree);
+  NS_ENSURE_STATE(boxObj);
 
-        childNodes->GetLength(&childCount);
-        for (childIndex = 0; childIndex < childCount; childIndex++) {
-          childNodes->Item(childIndex, getter_AddRefs(childNode));
-          childNode->GetLocalName(name);
-          if (name.EqualsLiteral("treechildren")) {
-            nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(childNode));
-            if (xulElement) {
-              nsCOMPtr<nsIBoxObject> box;
-              xulElement->GetBoxObject(getter_AddRefs(box));
-              if (box) {
-                PRInt32 myX, myY;
-                box->GetScreenX(&myX);
-                box->GetScreenY(&myY);
-                *x += myX;
-                *y += myY;
-              }
-            }
-            break;
-          }
-        }
-      }
-    }
-  }
+  nsresult rv = mTree->GetCoordsForCellItem(mRow, mColumn, EmptyCString(),
+                                            aX, aY, aWidth, aHeight);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  PRInt32 tcX = 0, tcY = 0;
+  boxObj->GetScreenX(&tcX);
+  boxObj->GetScreenY(&tcY);
+  *aX += tcX;
+  *aY += tcY;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsXULTreeitemAccessible::SetSelected(PRBool aSelect)
 {
   if (IsDefunct())
     return NS_ERROR_FAILURE;