bug 717683 - clean up atk document impl r=davidb
authorTrevor Saunders <trev.saunders@gmail.com>
Tue, 27 Dec 2011 15:25:03 -0500
changeset 84631 5f6a7d59e259f066719c49cfae9bc016c7f54157
parent 84630 f0cf32f96fa8cf15e0817d3ead738fad803fe4e4
child 84632 a57d0b0d3c2800dfe31caba76b0d3c6c747cf6b3
push id21868
push usermak77@bonardo.net
push dateTue, 17 Jan 2012 15:23:07 +0000
treeherdermozilla-central@ff1bedd7d463 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdavidb
bugs717683
milestone12.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 717683 - clean up atk document impl r=davidb
accessible/src/atk/nsMaiInterfaceDocument.cpp
accessible/src/atk/nsMaiInterfaceDocument.h
--- a/accessible/src/atk/nsMaiInterfaceDocument.cpp
+++ b/accessible/src/atk/nsMaiInterfaceDocument.cpp
@@ -32,22 +32,32 @@
  * 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 "nsAccessibleWrap.h"
 #include "nsMaiInterfaceDocument.h"
 
-const char *const kDocTypeName = "W3C-doctype";
-const char *const kDocUrlName = "DocURL";
-const char *const kMimeTypeName = "MimeType";
+#include "nsAccessibleWrap.h"
+#include "nsDocAccessible.h"
+
+static const char* const kDocTypeName = "W3C-doctype";
+static const char* const kDocUrlName = "DocURL";
+static const char* const kMimeTypeName = "MimeType";
+
+// below functions are vfuncs on an ATK  interface so they need to be C call
+extern "C" {
+
+static const gchar* getDocumentLocaleCB(AtkDocument* aDocument);
+static AtkAttributeSet* getDocumentAttributesCB(AtkDocument* aDocument);
+static const gchar* getDocumentAttributeValueCB(AtkDocument* aDocument,
+                                                const gchar* aAttrName);
 
 void
 documentInterfaceInitCB(AtkDocumentIface *aIface)
 {
     NS_ASSERTION(aIface, "Invalid Interface");
     if(!aIface)
         return;
 
@@ -59,101 +69,82 @@ documentInterfaceInitCB(AtkDocumentIface
     aIface->get_document_attributes = getDocumentAttributesCB;
     aIface->get_document_attribute_value = getDocumentAttributeValueCB;
     aIface->get_document_locale = getDocumentLocaleCB;
 }
 
 const gchar *
 getDocumentLocaleCB(AtkDocument *aDocument)
 {
-    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
-    if (!accWrap)
-        return nsnull;
+  nsAccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
+  if (!accWrap)
+    return nsnull;
 
-    nsCOMPtr<nsIAccessNode> docAccessNode;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessNode),
-                            getter_AddRefs(docAccessNode));
-    NS_ENSURE_TRUE(docAccessNode, nsnull);
-
-    nsAutoString locale;
-    docAccessNode->GetLanguage(locale);
-    if (locale.IsEmpty()) {
-      return nsnull;
-    }
-    return nsAccessibleWrap::ReturnString(locale);
+  nsAutoString locale;
+  accWrap->GetLanguage(locale);
+  return locale.IsEmpty() ? nsnull : nsAccessibleWrap::ReturnString(locale);
 }
 
 static inline GSList *
 prependToList(GSList *aList, const char *const aName, const nsAutoString &aValue)
 {
+  if (aValue.IsEmpty())
+    return aList;
+
     // libspi will free these
     AtkAttribute *atkAttr = (AtkAttribute *)g_malloc(sizeof(AtkAttribute));
     atkAttr->name = g_strdup(aName);
     atkAttr->value = g_strdup(NS_ConvertUTF16toUTF8(aValue).get());
     return g_slist_prepend(aList, atkAttr);
 }
 
 AtkAttributeSet *
 getDocumentAttributesCB(AtkDocument *aDocument)
 {
-    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
-    if (!accWrap)
-        return nsnull;
+  nsAccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
+  if (!accWrap || !accWrap->IsDoc())
+    return nsnull;
 
-    nsCOMPtr<nsIAccessibleDocument> accDocument;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleDocument),
-                            getter_AddRefs(accDocument));
-    NS_ENSURE_TRUE(accDocument, nsnull);
-
-    // according to atkobject.h, AtkAttributeSet is a GSList
-    GSList *attributes = nsnull;
+  // according to atkobject.h, AtkAttributeSet is a GSList
+  GSList* attributes = nsnull;
+  nsDocAccessible* document = accWrap->AsDoc();
+  nsAutoString aURL;
+  nsresult rv = document->GetURL(aURL);
+  if (NS_SUCCEEDED(rv))
+    attributes = prependToList(attributes, kDocUrlName, aURL);
 
-    nsAutoString aURL;
-    nsresult rv = accDocument->GetURL(aURL);
-    if (NS_SUCCEEDED(rv)) {
-        attributes = prependToList(attributes, kDocUrlName, aURL);
-    }
-    nsAutoString aW3CDocType;
-    rv = accDocument->GetDocType(aW3CDocType);
-    if (NS_SUCCEEDED(rv)) {
-        attributes = prependToList(attributes, kDocTypeName, aW3CDocType);
-    }
-    nsAutoString aMimeType;
-    rv = accDocument->GetMimeType(aMimeType);
-    if (NS_SUCCEEDED(rv)) {
-        attributes = prependToList(attributes, kMimeTypeName, aMimeType);
-    }
-    
-    return attributes;
+  nsAutoString aW3CDocType;
+  rv = document->GetDocType(aW3CDocType);
+  if (NS_SUCCEEDED(rv))
+    attributes = prependToList(attributes, kDocTypeName, aW3CDocType);
+
+  nsAutoString aMimeType;
+  rv = document->GetMimeType(aMimeType);
+  if (NS_SUCCEEDED(rv))
+    attributes = prependToList(attributes, kMimeTypeName, aMimeType);
+
+  return attributes;
 }
 
 const gchar *
 getDocumentAttributeValueCB(AtkDocument *aDocument,
                             const gchar *aAttrName)
 {
-    nsAccessibleWrap *accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
-    if (!accWrap)
-        return nsnull;
-
-    nsCOMPtr<nsIAccessibleDocument> accDocument;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleDocument),
-                            getter_AddRefs(accDocument));
-    NS_ENSURE_TRUE(accDocument, nsnull);
+  nsAccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
+  if (!accWrap || !accWrap->IsDoc())
+    return nsnull;
 
-    nsresult rv;
-    nsAutoString attrValue;
-    if (!g_ascii_strcasecmp(aAttrName, kDocTypeName)) {
-        rv = accDocument->GetDocType(attrValue);
-        NS_ENSURE_SUCCESS(rv, nsnull);
-    }
-    else if (!g_ascii_strcasecmp(aAttrName, kDocUrlName)) {
-        rv = accDocument->GetURL(attrValue);
-        NS_ENSURE_SUCCESS(rv, nsnull);
-    }
-    else if (!g_ascii_strcasecmp(aAttrName, kMimeTypeName)) {
-        rv = accDocument->GetMimeType(attrValue);
-        NS_ENSURE_SUCCESS(rv, nsnull);
-    }
-    else {
-        return nsnull;
-    }
-    return nsAccessibleWrap::ReturnString(attrValue);
+  nsDocAccessible* document = accWrap->AsDoc();
+  nsresult rv;
+  nsAutoString attrValue;
+  if (!strcasecmp(aAttrName, kDocTypeName))
+    rv = document->GetDocType(attrValue);
+  else if (!strcasecmp(aAttrName, kDocUrlName))
+    rv = document->GetURL(attrValue);
+  else if (!strcasecmp(aAttrName, kMimeTypeName))
+    rv = document->GetMimeType(attrValue);
+  else
+    return nsnull;
+
+  NS_ENSURE_SUCCESS(rv, nsnull);
+  return attrValue.IsEmpty() ? nsnull : nsAccessibleWrap::ReturnString(attrValue);
 }
+}
--- a/accessible/src/atk/nsMaiInterfaceDocument.h
+++ b/accessible/src/atk/nsMaiInterfaceDocument.h
@@ -36,22 +36,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef __MAI_INTERFACE_DOCUMENT_H__
 #define __MAI_INTERFACE_DOCUMENT_H__
 
 #include "nsMai.h"
-#include "nsIAccessibleDocument.h"
 
 G_BEGIN_DECLS
 
 /* document interface callbacks */
 void documentInterfaceInitCB(AtkDocumentIface *aIface);
-AtkAttributeSet* getDocumentAttributesCB(AtkDocument *aDocument);
-const gchar* getDocumentLocaleCB(AtkDocument *aDocument);
-const gchar* getDocumentAttributeValueCB(AtkDocument *aDocument,
-                                         const gchar *aAttrName);
 
 G_END_DECLS
 
 #endif /* __MAI_INTERFACE_DOCUMENT_H__ */