2011-04-27 06:42:27 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-05-27 15:37:24 -07:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
#include "InterfaceInitFuncs.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
#include "AccessibleWrap.h"
|
2012-05-27 02:01:40 -07:00
|
|
|
#include "DocAccessible.h"
|
2012-03-19 21:02:50 -07:00
|
|
|
#include "nsMai.h"
|
2011-12-27 12:25:03 -08:00
|
|
|
|
|
|
|
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);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
documentInterfaceInitCB(AtkDocumentIface *aIface)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aIface, "Invalid Interface");
|
2012-03-19 21:02:50 -07:00
|
|
|
if(NS_UNLIKELY(!aIface))
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
2007-05-22 20:54:19 -07:00
|
|
|
* We don't support get_document or set_attribute right now.
|
2007-03-22 10:30:00 -07:00
|
|
|
* get_document_type is deprecated, we return DocType in
|
|
|
|
* get_document_attribute_value and get_document_attributes instead.
|
|
|
|
*/
|
|
|
|
aIface->get_document_attributes = getDocumentAttributesCB;
|
|
|
|
aIface->get_document_attribute_value = getDocumentAttributeValueCB;
|
2007-05-22 20:54:19 -07:00
|
|
|
aIface->get_document_locale = getDocumentLocaleCB;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
getDocumentLocaleCB(AtkDocument *aDocument)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
|
2011-12-27 12:25:03 -08:00
|
|
|
if (!accWrap)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsAutoString locale;
|
2012-02-07 05:18:33 -08:00
|
|
|
accWrap->Language(locale);
|
2012-05-28 18:18:45 -07:00
|
|
|
return locale.IsEmpty() ? nsnull : AccessibleWrap::ReturnString(locale);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline GSList *
|
|
|
|
prependToList(GSList *aList, const char *const aName, const nsAutoString &aValue)
|
|
|
|
{
|
2011-12-27 12:25:03 -08:00
|
|
|
if (aValue.IsEmpty())
|
|
|
|
return aList;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
|
2011-12-27 12:25:03 -08:00
|
|
|
if (!accWrap || !accWrap->IsDoc())
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
// according to atkobject.h, AtkAttributeSet is a GSList
|
|
|
|
GSList* attributes = nsnull;
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* document = accWrap->AsDoc();
|
2011-12-27 12:25:03 -08:00
|
|
|
nsAutoString aURL;
|
|
|
|
nsresult rv = document->GetURL(aURL);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
attributes = prependToList(attributes, kDocUrlName, aURL);
|
|
|
|
|
|
|
|
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;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
getDocumentAttributeValueCB(AtkDocument *aDocument,
|
|
|
|
const gchar *aAttrName)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
|
2011-12-27 12:25:03 -08:00
|
|
|
if (!accWrap || !accWrap->IsDoc())
|
|
|
|
return nsnull;
|
|
|
|
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* document = accWrap->AsDoc();
|
2011-12-27 12:25:03 -08:00
|
|
|
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);
|
2012-05-28 18:18:45 -07:00
|
|
|
return attrValue.IsEmpty() ? nsnull : AccessibleWrap::ReturnString(attrValue);
|
2011-12-27 12:25:03 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|