bug 713792 - stop QueryInterface()ing to nsIAccessible image internally r=tbsaunde
authorSantiago Gimeno <santiago.gimeno@gmail.com>
Thu, 05 Jan 2012 23:05:03 -0500
changeset 85339 91c2ca8c60295a27b8caf5de5a86874720f80aa1
parent 85338 648239b7558d601f3d5824a8791308ede33051ee
child 85340 e2342ae9b94d8f8428f793f3205ee85d7c9977e8
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs713792
milestone12.0a1
bug 713792 - stop QueryInterface()ing to nsIAccessible image internally r=tbsaunde
accessible/src/atk/nsAccessibleWrap.cpp
accessible/src/atk/nsMaiInterfaceImage.cpp
accessible/src/base/nsAccessible.h
accessible/src/html/nsHTMLImageAccessible.h
--- a/accessible/src/atk/nsAccessibleWrap.cpp
+++ b/accessible/src/atk/nsAccessibleWrap.cpp
@@ -444,23 +444,18 @@ nsAccessibleWrap::CreateMaiInterfaces(vo
     //nsIAccessibleDocument
     nsCOMPtr<nsIAccessibleDocument> accessInterfaceDocument;
     QueryInterface(NS_GET_IID(nsIAccessibleDocument),
                               getter_AddRefs(accessInterfaceDocument));
     if (accessInterfaceDocument) {
         interfacesBits |= 1 << MAI_INTERFACE_DOCUMENT;
     }
 
-    //nsIAccessibleImage
-    nsCOMPtr<nsIAccessibleImage> accessInterfaceImage;
-    QueryInterface(NS_GET_IID(nsIAccessibleImage),
-                              getter_AddRefs(accessInterfaceImage));
-    if (accessInterfaceImage) {
+    if (IsImageAccessible())
         interfacesBits |= 1 << MAI_INTERFACE_IMAGE;
-    }
 
   // HyperLinkAccessible
   if (IsLink())
     interfacesBits |= 1 << MAI_INTERFACE_HYPERLINK_IMPL;
 
     if (!nsAccUtils::MustPrune(this)) {  // These interfaces require children
       //nsIAccessibleHypertext
       if (IsHyperText()) {
--- a/accessible/src/atk/nsMaiInterfaceImage.cpp
+++ b/accessible/src/atk/nsMaiInterfaceImage.cpp
@@ -32,18 +32,20 @@
  * 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 "nsMaiInterfaceImage.h"
+
 #include "nsAccessibleWrap.h"
-#include "nsMaiInterfaceImage.h"
+#include "nsHTMLImageAccessible.h"
 
 extern "C" const gchar* getDescriptionCB(AtkObject* aAtkObj);
 
 void
 imageInterfaceInitCB(AtkImageIface *aIface)
 {
     g_return_if_fail(aIface != NULL);
 
@@ -53,46 +55,34 @@ imageInterfaceInitCB(AtkImageIface *aIfa
 
 }
 
 void
 getImagePositionCB(AtkImage *aImage, gint *aAccX, gint *aAccY,
                    AtkCoordType aCoordType)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aImage));
-    if (!accWrap) 
+    if (!accWrap || !accWrap->IsImageAccessible())
       return;
 
-    nsCOMPtr<nsIAccessibleImage> image;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleImage),
-                            getter_AddRefs(image));
-    if (!image)
-      return;
-
+    nsHTMLImageAccessible* image = accWrap->AsImage();
     PRUint32 geckoCoordType = (aCoordType == ATK_XY_WINDOW) ?
       nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE :
       nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
-
     // Returned in screen coordinates
     image->GetImagePosition(geckoCoordType, aAccX, aAccY);
 }
 
 const gchar *
 getImageDescriptionCB(AtkImage *aImage)
 {
    return getDescriptionCB(ATK_OBJECT(aImage));
 }
 
 void
 getImageSizeCB(AtkImage *aImage, gint *aAccWidth, gint *aAccHeight)
 {
     nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aImage));
-    if (!accWrap) 
+    if (!accWrap || !accWrap->IsImageAccessible())
       return;
 
-    nsCOMPtr<nsIAccessibleImage> image;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleImage),
-                            getter_AddRefs(image));
-    if (!image)
-      return;
-
-    image->GetImageSize(aAccWidth, aAccHeight);
+    accWrap->AsImage()->GetImageSize(aAccWidth, aAccHeight);
 }
--- a/accessible/src/base/nsAccessible.h
+++ b/accessible/src/base/nsAccessible.h
@@ -55,16 +55,17 @@
 #include "nsRefPtrHashtable.h"
 
 class AccEvent;
 class AccGroupInfo;
 class EmbeddedObjCollector;
 class KeyBinding;
 class nsAccessible;
 class nsHyperTextAccessible;
+class nsHTMLImageAccessible;
 class nsHTMLLIAccessible;
 struct nsRoleMapEntry;
 class Relation;
 class nsTextAccessible;
 
 struct nsRect;
 class nsIContent;
 class nsIFrame;
@@ -423,16 +424,19 @@ public:
 
   inline bool IsHyperText() const { return mFlags & eHyperTextAccessible; }
   nsHyperTextAccessible* AsHyperText();
 
   inline bool IsHTMLFileInput() const { return mFlags & eHTMLFileInputAccessible; }
 
   inline bool IsHTMLListItem() const { return mFlags & eHTMLListItemAccessible; }
   nsHTMLLIAccessible* AsHTMLListItem();
+  
+  inline bool IsImageAccessible() const { return mFlags & eImageAccessible; }
+  nsHTMLImageAccessible* AsImage();
 
   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; }
@@ -649,21 +653,22 @@ protected:
     eApplicationAccessible = 1 << 2,
     eAutoCompleteAccessible = 1 << 3,
     eAutoCompletePopupAccessible = 1 << 4,
     eComboboxAccessible = 1 << 5,
     eDocAccessible = 1 << 6,
     eHyperTextAccessible = 1 << 7,
     eHTMLFileInputAccessible = 1 << 8,
     eHTMLListItemAccessible = 1 << 9,
-    eListControlAccessible = 1 << 10,
-    eMenuButtonAccessible = 1 << 11,
-    eMenuPopupAccessible = 1 << 12,
-    eRootAccessible = 1 << 13,
-    eTextLeafAccessible = 1 << 14
+    eImageAccessible = 1 << 10,
+    eListControlAccessible = 1 << 11,
+    eMenuButtonAccessible = 1 << 12,
+    eMenuPopupAccessible = 1 << 13,
+    eRootAccessible = 1 << 14,
+    eTextLeafAccessible = 1 << 15
   };
 
   //////////////////////////////////////////////////////////////////////////////
   // Miscellaneous helpers
 
   /**
    * Return ARIA role (helper method).
    */
--- a/accessible/src/html/nsHTMLImageAccessible.h
+++ b/accessible/src/html/nsHTMLImageAccessible.h
@@ -87,10 +87,19 @@ private:
    *
    * @param aIndex  The 0-based index to be tested.
    *
    * @returns  true if index is valid for longdesc action.
    */
   bool IsValidLongDescIndex(PRUint8 aIndex);
 };
 
+////////////////////////////////////////////////////////////////////////////////
+// nsAccessible downcasting method
+inline nsHTMLImageAccessible*
+nsAccessible::AsImage()
+{
+  return IsImageAccessible() ?
+    static_cast<nsHTMLImageAccessible*>(this) : nsnull;
+}
+
 #endif