Bug 349635 Return DocType in atk_document_get_attribute*

patch by Evan.Yan at Sun.COM r=ginn.chen, aaronleventhal
This commit is contained in:
ginn.chen%sun.com 2006-08-23 08:20:26 +00:00
Родитель dc3833bf60
Коммит 513ee78182
2 изменённых файлов: 26 добавлений и 14 удалений

Просмотреть файл

@ -44,6 +44,7 @@
const char *const kDocTypeName = "W3C-doctype";
const char *const kDocUrlName = "DocURL";
const char *const kMimeTypeName = "MimeType";
void
documentInterfaceInitCB(AtkDocumentIface *aIface)
@ -54,8 +55,9 @@ documentInterfaceInitCB(AtkDocumentIface *aIface)
/*
* We don't support get_document, get_locale and set_attribute right now.
* get_document_type is deprecated, we return DocType in
* get_document_attribute_value and get_document_attributes instead.
*/
aIface->get_document_type = getDocumentTypeCB;
aIface->get_document_attributes = getDocumentAttributesCB;
aIface->get_document_attribute_value = getDocumentAttributeValueCB;
}
@ -77,6 +79,16 @@ getDocumentTypeCB(AtkDocument *aDocument)
return nsAccessibleWrap::ReturnString(aMimeType);
}
static inline GSList *
prependToList(GSList *aList, const char *const aName, const nsAutoString &aValue)
{
// 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)
{
@ -91,23 +103,20 @@ getDocumentAttributesCB(AtkDocument *aDocument)
// according to atkobject.h, AtkAttributeSet is a GSList
GSList *attributes = nsnull;
nsAutoString aURL, aW3CDocType;
nsAutoString aURL;
nsresult rv = accDocument->GetURL(aURL);
if (NS_SUCCEEDED(rv)) {
// libspi will free these
AtkAttribute *attrURL = (AtkAttribute *)g_malloc(sizeof(AtkAttribute));
attrURL->name = g_strdup(kDocUrlName);
attrURL->value = g_strdup(NS_ConvertUTF16toUTF8(aURL).get());
attributes = g_slist_prepend(attributes, attrURL);
attributes = prependToList(attributes, kDocUrlName, aURL);
}
nsAutoString aW3CDocType;
rv = accDocument->GetDocType(aW3CDocType);
if (NS_SUCCEEDED(rv)) {
// libspi will free these
AtkAttribute *attrDocType = (AtkAttribute *)g_malloc(sizeof(AtkAttribute));
attrDocType->name = g_strdup(kDocTypeName);
attrDocType->value = g_strdup(NS_ConvertUTF16toUTF8(aW3CDocType).get());
attributes = g_slist_prepend(attributes, attrDocType);
attributes = prependToList(attributes, kDocTypeName, aW3CDocType);
}
nsAutoString aMimeType;
rv = accDocument->GetMimeType(aMimeType);
if (NS_SUCCEEDED(rv)) {
attributes = prependToList(attributes, kMimeTypeName, aMimeType);
}
return attributes;
@ -135,6 +144,10 @@ getDocumentAttributeValueCB(AtkDocument *aDocument,
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;
}

Просмотреть файл

@ -48,7 +48,6 @@ G_BEGIN_DECLS
/* document interface callbacks */
void documentInterfaceInitCB(AtkDocumentIface *aIface);
const gchar* getDocumentTypeCB(AtkDocument *aDocument);
AtkAttributeSet* getDocumentAttributesCB(AtkDocument *aDocument);
const gchar* getDocumentAttributeValueCB(AtkDocument *aDocument,
const gchar *aAttrName);