2011-04-27 17:42:27 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-05-28 02:37:24 +04:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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/. */
|
2006-08-16 07:06:42 +04:00
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
#include "InterfaceInitFuncs.h"
|
2006-08-16 07:06:42 +04:00
|
|
|
|
2012-12-21 07:16:44 +04:00
|
|
|
#include "Accessible-inl.h"
|
2012-05-29 05:18:45 +04:00
|
|
|
#include "AccessibleWrap.h"
|
2012-05-27 13:01:40 +04:00
|
|
|
#include "DocAccessible.h"
|
2012-03-20 08:02:50 +04:00
|
|
|
#include "nsMai.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2011-12-28 00:25:03 +04:00
|
|
|
|
2012-11-18 06:01:44 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2011-12-28 00:25:03 +04: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);
|
2006-08-16 07:06:42 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
documentInterfaceInitCB(AtkDocumentIface *aIface)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aIface, "Invalid Interface");
|
2012-10-26 17:32:10 +04:00
|
|
|
if(MOZ_UNLIKELY(!aIface))
|
2006-08-16 07:06:42 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
2007-05-23 07:54:19 +04:00
|
|
|
* We don't support get_document or set_attribute right now.
|
2006-08-23 12:20:26 +04:00
|
|
|
* get_document_type is deprecated, we return DocType in
|
|
|
|
* get_document_attribute_value and get_document_attributes instead.
|
2006-08-16 07:06:42 +04:00
|
|
|
*/
|
|
|
|
aIface->get_document_attributes = getDocumentAttributesCB;
|
|
|
|
aIface->get_document_attribute_value = getDocumentAttributeValueCB;
|
2007-05-23 07:54:19 +04:00
|
|
|
aIface->get_document_locale = getDocumentLocaleCB;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
getDocumentLocaleCB(AtkDocument *aDocument)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
|
2011-12-28 00:25:03 +04:00
|
|
|
if (!accWrap)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-12-28 00:25:03 +04:00
|
|
|
|
|
|
|
nsAutoString locale;
|
2012-02-07 17:18:33 +04:00
|
|
|
accWrap->Language(locale);
|
2012-07-30 18:20:58 +04:00
|
|
|
return locale.IsEmpty() ? nullptr : AccessibleWrap::ReturnString(locale);
|
2006-08-16 07:06:42 +04:00
|
|
|
}
|
|
|
|
|
2006-08-23 12:20:26 +04:00
|
|
|
static inline GSList *
|
|
|
|
prependToList(GSList *aList, const char *const aName, const nsAutoString &aValue)
|
|
|
|
{
|
2011-12-28 00:25:03 +04:00
|
|
|
if (aValue.IsEmpty())
|
|
|
|
return aList;
|
|
|
|
|
2006-08-23 12:20:26 +04: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);
|
|
|
|
}
|
|
|
|
|
2006-08-16 07:06:42 +04:00
|
|
|
AtkAttributeSet *
|
|
|
|
getDocumentAttributesCB(AtkDocument *aDocument)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
|
2011-12-28 00:25:03 +04:00
|
|
|
if (!accWrap || !accWrap->IsDoc())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-12-28 00:25:03 +04:00
|
|
|
|
|
|
|
// according to atkobject.h, AtkAttributeSet is a GSList
|
2012-07-30 18:20:58 +04:00
|
|
|
GSList* attributes = nullptr;
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* document = accWrap->AsDoc();
|
2011-12-28 00:25:03 +04:00
|
|
|
nsAutoString aURL;
|
2014-09-23 16:23:02 +04:00
|
|
|
document->URL(aURL);
|
|
|
|
attributes = prependToList(attributes, kDocUrlName, aURL);
|
2011-12-28 00:25:03 +04:00
|
|
|
|
|
|
|
nsAutoString aW3CDocType;
|
2014-10-22 04:49:28 +04:00
|
|
|
document->DocType(aW3CDocType);
|
2014-09-23 16:23:02 +04:00
|
|
|
attributes = prependToList(attributes, kDocTypeName, aW3CDocType);
|
2011-12-28 00:25:03 +04:00
|
|
|
|
|
|
|
nsAutoString aMimeType;
|
2014-09-23 16:23:02 +04:00
|
|
|
document->MimeType(aMimeType);
|
|
|
|
attributes = prependToList(attributes, kMimeTypeName, aMimeType);
|
2011-12-28 00:25:03 +04:00
|
|
|
|
|
|
|
return attributes;
|
2006-08-16 07:06:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
getDocumentAttributeValueCB(AtkDocument *aDocument,
|
|
|
|
const gchar *aAttrName)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
|
2011-12-28 00:25:03 +04:00
|
|
|
if (!accWrap || !accWrap->IsDoc())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-12-28 00:25:03 +04:00
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* document = accWrap->AsDoc();
|
2011-12-28 00:25:03 +04:00
|
|
|
nsAutoString attrValue;
|
|
|
|
if (!strcasecmp(aAttrName, kDocTypeName))
|
2014-10-22 04:49:28 +04:00
|
|
|
document->DocType(attrValue);
|
2011-12-28 00:25:03 +04:00
|
|
|
else if (!strcasecmp(aAttrName, kDocUrlName))
|
2014-09-23 16:23:02 +04:00
|
|
|
document->URL(attrValue);
|
2011-12-28 00:25:03 +04:00
|
|
|
else if (!strcasecmp(aAttrName, kMimeTypeName))
|
2014-09-23 16:23:02 +04:00
|
|
|
document->MimeType(attrValue);
|
2011-12-28 00:25:03 +04:00
|
|
|
else
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-12-28 00:25:03 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return attrValue.IsEmpty() ? nullptr : AccessibleWrap::ReturnString(attrValue);
|
2011-12-28 00:25:03 +04:00
|
|
|
}
|
2006-08-16 07:06:42 +04:00
|
|
|
}
|