Bug 1519955, Don't use boxobject properties in accessibility, r=jteh
authorNeil Deakin <neil@mozilla.com>
Fri, 01 Mar 2019 12:26:37 -0500
changeset 461930 1178c5fddda7dee4cb1b0aeee6fd9afb1c6d30d0
parent 461929 fad9ff877c1cbd2b06c03263ba9fc91d2f1fc405
child 461931 aa8dea3c0f43cf09a7edb3b1573d0657df3a1c3a
push id112243
push userneil@mozilla.com
push dateFri, 01 Mar 2019 17:35:50 +0000
treeherdermozilla-inbound@57624be2e55c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjteh
bugs1519955
milestone67.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 1519955, Don't use boxobject properties in accessibility, r=jteh
accessible/base/nsCoreUtils.cpp
accessible/base/nsCoreUtils.h
accessible/xul/XULTreeAccessible.cpp
accessible/xul/XULTreeAccessible.h
accessible/xul/XULTreeGridAccessible.cpp
--- a/accessible/base/nsCoreUtils.cpp
+++ b/accessible/base/nsCoreUtils.cpp
@@ -6,19 +6,17 @@
 #include "nsCoreUtils.h"
 
 #include "nsIAccessibleTypes.h"
 
 #include "nsIBaseWindow.h"
 #include "nsIDocShellTreeOwner.h"
 #include "mozilla/dom/Document.h"
 #include "nsRange.h"
-#include "nsIBoxObject.h"
 #include "nsXULElement.h"
-#include "mozilla/dom/BoxObject.h"
 #include "nsIDocShell.h"
 #include "nsIObserverService.h"
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "nsIScrollableFrame.h"
 #include "nsISelectionController.h"
 #include "nsISimpleEnumerator.h"
 #include "mozilla/dom/TouchEvent.h"
@@ -81,24 +79,19 @@ void nsCoreUtils::DispatchClickEvent(XUL
   // Calculate x and y coordinates.
   nsresult rv;
   nsIntRect rect =
       aTree->GetCoordsForCellItem(aRowIndex, aColumn, aPseudoElt, rv);
   if (NS_FAILED(rv)) {
     return;
   }
 
-  nsCOMPtr<nsIBoxObject> tcBoxObj =
-      nsXULElement::FromNode(tcElm)->GetBoxObject(IgnoreErrors());
-
-  int32_t tcX = 0;
-  tcBoxObj->GetX(&tcX);
-
-  int32_t tcY = 0;
-  tcBoxObj->GetY(&tcY);
+  RefPtr<DOMRect> treeBodyRect = tcElm->GetBoundingClientRect();
+  int32_t tcX = (int32_t)treeBodyRect->X();
+  int32_t tcY = (int32_t)treeBodyRect->Y();
 
   // Dispatch mouse events.
   AutoWeakFrame tcFrame = tcElm->GetPrimaryFrame();
   nsIFrame *rootFrame = presShell->GetRootFrame();
 
   nsPoint offset;
   nsIWidget *rootWidget = rootFrame->GetView()->GetNearestWidget(&offset);
 
@@ -420,25 +413,16 @@ void nsCoreUtils::GetLanguageFor(nsICont
   nsIContent *walkUp = aContent;
   while (walkUp && walkUp != aRootContent &&
          (!walkUp->IsElement() ||
           !walkUp->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::lang,
                                         aLanguage)))
     walkUp = walkUp->GetParent();
 }
 
-already_AddRefed<nsIBoxObject> nsCoreUtils::GetTreeBodyBoxObject(
-    XULTreeElement *aTree) {
-  RefPtr<dom::Element> tcElm = aTree->GetTreeBody();
-  RefPtr<nsXULElement> tcXULElm = nsXULElement::FromNodeOrNull(tcElm);
-  if (!tcXULElm) return nullptr;
-
-  return tcXULElm->GetBoxObject(IgnoreErrors());
-}
-
 XULTreeElement *nsCoreUtils::GetTree(nsIContent *aContent) {
   // Find DOMNode's parents recursively until reach the <tree> tag
   nsIContent *currentContent = aContent;
   while (currentContent) {
     if (currentContent->NodeInfo()->Equals(nsGkAtoms::tree, kNameSpaceID_XUL)) {
       return XULTreeElement::FromNode(currentContent);
     }
     currentContent = currentContent->GetFlattenedTreeParent();
--- a/accessible/base/nsCoreUtils.h
+++ b/accessible/base/nsCoreUtils.h
@@ -13,17 +13,16 @@
 #include "mozilla/dom/Document.h"  // for GetShell()
 #include "nsIPresShell.h"
 
 #include "nsPoint.h"
 #include "nsTArray.h"
 
 class nsRange;
 class nsTreeColumn;
-class nsIBoxObject;
 class nsIFrame;
 class nsIDocShell;
 class nsIWidget;
 
 namespace mozilla {
 namespace dom {
 class XULTreeElement;
 }
@@ -49,18 +48,19 @@ class nsCoreUtils {
 
   /**
    * Dispatch click event to XUL tree cell.
    *
    * @param  aTree        [in] tree
    * @param  aRowIndex    [in] row index
    * @param  aColumn      [in] column object
    * @param  aPseudoElm   [in] pseudo element inside the cell, see
-   *                       nsITreeBoxObject for available values
+   *                       XULTreeElement for available values
    */
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY
   static void DispatchClickEvent(mozilla::dom::XULTreeElement *aTree,
                                  int32_t aRowIndex, nsTreeColumn *aColumn,
                                  const nsAString &aPseudoElt = EmptyString());
 
   /**
    * Send mouse event to the given element.
    *
    * @param aMessage     [in] an event message (see EventForwards.h)
@@ -237,22 +237,16 @@ class nsCoreUtils {
    * @param aContent     [in] the given node
    * @param aRootContent [in] container of the given node
    * @param aLanguage    [out] language
    */
   static void GetLanguageFor(nsIContent *aContent, nsIContent *aRootContent,
                              nsAString &aLanguage);
 
   /**
-   * Return box object for XUL treechildren element of the given tree.
-   */
-  static already_AddRefed<nsIBoxObject> GetTreeBodyBoxObject(
-      mozilla::dom::XULTreeElement *aTree);
-
-  /**
    * Return tree from any levels DOMNode under the XUL tree.
    */
   static mozilla::dom::XULTreeElement *GetTree(nsIContent *aContent);
 
   /**
    * Return first sensible column for the given tree box object.
    */
   static already_AddRefed<nsTreeColumn> GetFirstSensibleColumn(
--- a/accessible/xul/XULTreeAccessible.cpp
+++ b/accessible/xul/XULTreeAccessible.cpp
@@ -18,17 +18,16 @@
 #include "States.h"
 #include "XULTreeGridAccessible.h"
 #include "nsQueryObject.h"
 
 #include "nsComponentManagerUtils.h"
 #include "nsIAccessibleRelation.h"
 #include "nsIAutoCompleteInput.h"
 #include "nsIAutoCompletePopup.h"
-#include "nsIBoxObject.h"
 #include "nsIDOMXULMenuListElement.h"
 #include "nsIDOMXULMultSelectCntrlEl.h"
 #include "nsITreeSelection.h"
 #include "nsIMutableArray.h"
 #include "nsTreeBodyFrame.h"
 #include "nsTreeColumns.h"
 #include "nsTreeUtils.h"
 #include "mozilla/dom/XULTreeElementBinding.h"
@@ -610,36 +609,41 @@ NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHER
 Accessible* XULTreeItemAccessibleBase::FocusedChild() {
   return FocusMgr()->FocusedAccessible() == this ? this : nullptr;
 }
 
 nsIntRect XULTreeItemAccessibleBase::BoundsInCSSPixels() const {
   // Get x coordinate and width from treechildren element, get y coordinate and
   // height from tree cell.
 
-  nsCOMPtr<nsIBoxObject> boxObj = nsCoreUtils::GetTreeBodyBoxObject(mTree);
-  if (!boxObj) {
-    return nsIntRect();
-  }
-
   RefPtr<nsTreeColumn> column = nsCoreUtils::GetFirstSensibleColumn(mTree);
 
   nsresult rv;
   nsIntRect rect =
       mTree->GetCoordsForCellItem(mRow, column, NS_LITERAL_STRING("cell"), rv);
   if (NS_FAILED(rv)) {
     return nsIntRect();
   }
 
-  boxObj->GetWidth(&rect.width);
+  RefPtr<dom::Element> bodyElement = mTree->GetTreeBody();
+  if (!bodyElement || !bodyElement->IsXULElement()) {
+    return nsIntRect();
+  }
+
+  rect.width = bodyElement->ClientWidth();
 
-  int32_t tcX = 0, tcY = 0;
-  boxObj->GetScreenX(&tcX);
-  boxObj->GetScreenY(&tcY);
-  return nsIntRect(tcX, rect.y + tcY, rect.width, rect.height);
+  nsIFrame* bodyFrame = bodyElement->GetPrimaryFrame();
+  if (!bodyFrame) {
+    return nsIntRect();
+  }
+
+  CSSIntRect screenRect = bodyFrame->GetScreenRect();
+  rect.x = screenRect.x;
+  rect.y += screenRect.y;
+  return rect;
 }
 
 nsRect XULTreeItemAccessibleBase::BoundsInAppUnits() const {
   nsIntRect bounds = BoundsInCSSPixels();
   nsPresContext* presContext = mDoc->PresContext();
   return nsRect(presContext->CSSPixelsToAppUnits(bounds.X()),
                 presContext->CSSPixelsToAppUnits(bounds.Y()),
                 presContext->CSSPixelsToAppUnits(bounds.Width()),
--- a/accessible/xul/XULTreeAccessible.h
+++ b/accessible/xul/XULTreeAccessible.h
@@ -139,16 +139,17 @@ class XULTreeItemAccessibleBase : public
   // nsISupports and cycle collection
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeItemAccessibleBase,
                                            AccessibleWrap)
 
   // Accessible
   virtual void Shutdown() override;
   virtual nsRect BoundsInAppUnits() const override;
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY
   virtual nsIntRect BoundsInCSSPixels() const override;
   virtual GroupPos GroupPosition() override;
   virtual uint64_t NativeState() const override;
   virtual uint64_t NativeInteractiveState() const override;
   virtual int32_t IndexInParent() const override;
   virtual Relation RelationByType(RelationType aType) const override;
   virtual Accessible* FocusedChild() override;
   virtual void SetSelected(bool aSelect) override;
--- a/accessible/xul/XULTreeGridAccessible.cpp
+++ b/accessible/xul/XULTreeGridAccessible.cpp
@@ -11,17 +11,16 @@
 #include "DocAccessible.h"
 #include "nsEventShell.h"
 #include "Relation.h"
 #include "Role.h"
 #include "States.h"
 #include "nsQueryObject.h"
 #include "nsTreeColumns.h"
 
-#include "nsIBoxObject.h"
 #include "nsIMutableArray.h"
 #include "nsPersistentProperties.h"
 #include "nsITreeSelection.h"
 #include "nsComponentManagerUtils.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/TreeColumnBinding.h"
 #include "mozilla/dom/XULTreeElementBinding.h"
 
@@ -397,32 +396,37 @@ ENameValueFlag XULTreeGridCellAccessible
   if (aName.IsEmpty()) mTreeView->GetCellValue(mRow, mColumn, aName);
 
   return eNameOK;
 }
 
 nsIntRect XULTreeGridCellAccessible::BoundsInCSSPixels() const {
   // Get bounds for tree cell and add x and y of treechildren element to
   // x and y of the cell.
-  nsCOMPtr<nsIBoxObject> boxObj = nsCoreUtils::GetTreeBodyBoxObject(mTree);
-  if (!boxObj) {
-    return nsIntRect();
-  }
-
   nsresult rv;
   nsIntRect rect =
       mTree->GetCoordsForCellItem(mRow, mColumn, NS_LITERAL_STRING("cell"), rv);
   if (NS_FAILED(rv)) {
     return nsIntRect();
   }
 
-  int32_t tcX = 0, tcY = 0;
-  boxObj->GetScreenX(&tcX);
-  boxObj->GetScreenY(&tcY);
-  return nsIntRect(rect.x + tcX, rect.y + tcY, rect.width, rect.height);
+  RefPtr<dom::Element> bodyElement = mTree->GetTreeBody();
+  if (!bodyElement || !bodyElement->IsXULElement()) {
+    return nsIntRect();
+  }
+
+  nsIFrame* bodyFrame = bodyElement->GetPrimaryFrame();
+  if (!bodyFrame) {
+    return nsIntRect();
+  }
+
+  CSSIntRect screenRect = bodyFrame->GetScreenRect();
+  rect.x += screenRect.x;
+  rect.y += screenRect.y;
+  return rect;
 }
 
 nsRect XULTreeGridCellAccessible::BoundsInAppUnits() const {
   nsIntRect bounds = BoundsInCSSPixels();
   nsPresContext* presContext = mDoc->PresContext();
   return nsRect(presContext->CSSPixelsToAppUnits(bounds.X()),
                 presContext->CSSPixelsToAppUnits(bounds.Y()),
                 presContext->CSSPixelsToAppUnits(bounds.Width()),