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
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
#include "LocalAccessible-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"
|
2021-02-20 02:14:33 +03:00
|
|
|
#include "RemoteAccessible.h"
|
2022-06-01 03:34:17 +03:00
|
|
|
#include "mozilla/a11y/DocAccessibleParent.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)) return;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2006-08-16 07:06:42 +04:00
|
|
|
/*
|
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) {
|
2015-03-27 18:41:04 +03:00
|
|
|
nsAutoString locale;
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
|
2015-03-27 18:41:04 +03:00
|
|
|
if (accWrap) {
|
|
|
|
accWrap->Language(locale);
|
2021-02-20 02:14:33 +03:00
|
|
|
} else if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aDocument))) {
|
2015-03-27 18:41:04 +03:00
|
|
|
proxy->Language(locale);
|
|
|
|
}
|
2011-12-28 00:25:03 +04:00
|
|
|
|
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) {
|
2016-08-31 14:51:18 +03:00
|
|
|
if (aValue.IsEmpty()) {
|
2011-12-28 00:25:03 +04:00
|
|
|
return aList;
|
2016-08-31 14:51:18 +03:00
|
|
|
}
|
2011-12-28 00:25:03 +04:00
|
|
|
|
2016-08-31 14:51:18 +03: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-23 12:20:26 +04:00
|
|
|
}
|
|
|
|
|
2006-08-16 07:06:42 +04:00
|
|
|
AtkAttributeSet* getDocumentAttributesCB(AtkDocument* aDocument) {
|
2015-03-27 18:41:04 +03:00
|
|
|
nsAutoString url;
|
|
|
|
nsAutoString w3cDocType;
|
|
|
|
nsAutoString mimeType;
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
|
2015-03-27 18:41:04 +03:00
|
|
|
if (accWrap) {
|
|
|
|
if (!accWrap->IsDoc()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
DocAccessible* document = accWrap->AsDoc();
|
|
|
|
document->URL(url);
|
|
|
|
document->DocType(w3cDocType);
|
|
|
|
document->MimeType(mimeType);
|
2021-02-20 02:14:33 +03:00
|
|
|
} else if (RemoteAccessible* proxy = GetProxy(ATK_OBJECT(aDocument))) {
|
2015-03-27 18:41:04 +03:00
|
|
|
proxy->URLDocTypeMimeType(url, w3cDocType, mimeType);
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2015-03-27 18:41:04 +03:00
|
|
|
}
|
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;
|
2015-03-27 18:41:04 +03:00
|
|
|
attributes = prependToList(attributes, kDocUrlName, url);
|
|
|
|
attributes = prependToList(attributes, kDocTypeName, w3cDocType);
|
|
|
|
attributes = prependToList(attributes, kMimeTypeName, mimeType);
|
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) {
|
2021-02-20 02:14:33 +03:00
|
|
|
RemoteAccessible* proxy = nullptr;
|
2015-03-27 18:41:04 +03:00
|
|
|
DocAccessible* document = nullptr;
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aDocument));
|
2015-03-27 18:41:04 +03:00
|
|
|
if (accWrap) {
|
|
|
|
if (!accWrap->IsDoc()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
document = accWrap->AsDoc();
|
|
|
|
} else {
|
|
|
|
proxy = GetProxy(ATK_OBJECT(aDocument));
|
|
|
|
if (!proxy) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-06-01 03:34:17 +03:00
|
|
|
MOZ_ASSERT(proxy->IsDoc());
|
2015-03-27 18:41:04 +03:00
|
|
|
}
|
2011-12-28 00:25:03 +04:00
|
|
|
|
|
|
|
nsAutoString attrValue;
|
2015-03-27 18:41:04 +03:00
|
|
|
if (!strcasecmp(aAttrName, kDocTypeName)) {
|
|
|
|
if (document) {
|
|
|
|
document->DocType(attrValue);
|
|
|
|
} else {
|
|
|
|
proxy->DocType(attrValue);
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(aAttrName, kDocUrlName)) {
|
|
|
|
if (document) {
|
|
|
|
document->URL(attrValue);
|
|
|
|
} else {
|
2022-06-01 03:34:17 +03:00
|
|
|
proxy->AsDoc()->URL(attrValue);
|
2015-03-27 18:41:04 +03:00
|
|
|
}
|
|
|
|
} else if (!strcasecmp(aAttrName, kMimeTypeName)) {
|
|
|
|
if (document) {
|
|
|
|
document->MimeType(attrValue);
|
|
|
|
} else {
|
|
|
|
proxy->MimeType(attrValue);
|
|
|
|
}
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2015-03-27 18:41:04 +03:00
|
|
|
}
|
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
|
|
|
}
|