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/. */
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
#include "InterfaceInitFuncs.h"
|
2015-03-06 23:44:02 +03:00
|
|
|
#include "mozilla/a11y/PDocAccessible.h"
|
2012-12-21 07:16:44 +04:00
|
|
|
#include "Accessible-inl.h"
|
2013-11-18 17:19:33 +04:00
|
|
|
#include "HyperTextAccessible-inl.h"
|
2012-03-20 08:02:50 +04:00
|
|
|
#include "nsMai.h"
|
2015-01-09 23:01:39 +03:00
|
|
|
#include "ProxyAccessible.h"
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2013-09-11 02:18:59 +04:00
|
|
|
#include "nsIAccessibleTypes.h"
|
2012-02-29 14:59:38 +04:00
|
|
|
#include "nsIPersistentProperties2.h"
|
2013-11-18 22:52:21 +04:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2012-02-29 14:59:38 +04:00
|
|
|
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
|
|
|
|
2013-11-18 22:52:21 +04:00
|
|
|
using namespace mozilla;
|
2012-05-02 15:13:34 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2013-11-18 22:52:21 +04:00
|
|
|
static const char* sAtkTextAttrNames[ATK_TEXT_ATTR_LAST_DEFINED];
|
|
|
|
|
2015-03-06 23:44:02 +03:00
|
|
|
void
|
|
|
|
ConvertTextAttributeToAtkAttribute(const nsACString& aName,
|
|
|
|
const nsAString& aValue,
|
|
|
|
AtkAttributeSet** aAttributeSet)
|
|
|
|
{
|
|
|
|
// Handle attributes where atk has its own name.
|
|
|
|
const char* atkName = nullptr;
|
|
|
|
nsAutoString atkValue;
|
|
|
|
if (aName.EqualsLiteral("color")) {
|
|
|
|
// The format of the atk attribute is r,g,b and the gecko one is
|
2015-06-12 23:39:16 +03:00
|
|
|
// rgb(r, g, b).
|
|
|
|
atkValue = Substring(aValue, 4, aValue.Length() - 5);
|
|
|
|
atkValue.StripWhitespace();
|
2015-03-06 23:44:02 +03:00
|
|
|
atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_FG_COLOR];
|
|
|
|
} else if (aName.EqualsLiteral("background-color")) {
|
|
|
|
// The format of the atk attribute is r,g,b and the gecko one is
|
2015-06-12 23:39:16 +03:00
|
|
|
// rgb(r, g, b).
|
|
|
|
atkValue = Substring(aValue, 4, aValue.Length() - 5);
|
|
|
|
atkValue.StripWhitespace();
|
2015-03-06 23:44:02 +03:00
|
|
|
atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_BG_COLOR];
|
|
|
|
} else if (aName.EqualsLiteral("font-family")) {
|
|
|
|
atkValue = aValue;
|
|
|
|
atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_FAMILY_NAME];
|
|
|
|
} else if (aName.EqualsLiteral("font-size")) {
|
|
|
|
// ATK wants the number of pixels without px at the end.
|
|
|
|
atkValue = StringHead(aValue, aValue.Length() - 2);
|
|
|
|
atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_SIZE];
|
|
|
|
} else if (aName.EqualsLiteral("font-weight")) {
|
|
|
|
atkValue = aValue;
|
|
|
|
atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_WEIGHT];
|
|
|
|
} else if (aName.EqualsLiteral("invalid")) {
|
|
|
|
atkValue = aValue;
|
|
|
|
atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_INVALID];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atkName) {
|
|
|
|
AtkAttribute* objAttr =
|
|
|
|
static_cast<AtkAttribute*>(g_malloc(sizeof(AtkAttribute)));
|
|
|
|
objAttr->name = g_strdup(atkName);
|
|
|
|
objAttr->value = g_strdup(NS_ConvertUTF16toUTF8(atkValue).get());
|
|
|
|
*aAttributeSet = g_slist_prepend(*aAttributeSet, objAttr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static AtkAttributeSet*
|
|
|
|
ConvertToAtkTextAttributeSet(nsTArray<Attribute>& aAttributes)
|
|
|
|
{
|
|
|
|
AtkAttributeSet* objAttributeSet = nullptr;
|
|
|
|
for (size_t i = 0; i < aAttributes.Length(); ++i) {
|
|
|
|
AtkAttribute* objAttr = (AtkAttribute *)g_malloc(sizeof(AtkAttribute));
|
|
|
|
objAttr->name = g_strdup(aAttributes[i].Name().get());
|
|
|
|
objAttr->value =
|
|
|
|
g_strdup(NS_ConvertUTF16toUTF8(aAttributes[i].Value()).get());
|
|
|
|
objAttributeSet = g_slist_prepend(objAttributeSet, objAttr);
|
|
|
|
ConvertTextAttributeToAtkAttribute(aAttributes[i].Name(),
|
|
|
|
aAttributes[i].Value(),
|
|
|
|
&objAttributeSet);
|
|
|
|
}
|
|
|
|
return objAttributeSet;
|
|
|
|
}
|
|
|
|
|
2013-11-18 22:52:21 +04:00
|
|
|
static AtkAttributeSet*
|
|
|
|
ConvertToAtkTextAttributeSet(nsIPersistentProperties* aAttributes)
|
|
|
|
{
|
|
|
|
if (!aAttributes)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
AtkAttributeSet* objAttributeSet = nullptr;
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> propEnum;
|
|
|
|
nsresult rv = aAttributes->Enumerate(getter_AddRefs(propEnum));
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
|
|
|
|
bool hasMore = false;
|
|
|
|
while (NS_SUCCEEDED(propEnum->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> sup;
|
|
|
|
rv = propEnum->GetNext(getter_AddRefs(sup));
|
|
|
|
NS_ENSURE_SUCCESS(rv, objAttributeSet);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPropertyElement> propElem(do_QueryInterface(sup));
|
|
|
|
NS_ENSURE_TRUE(propElem, objAttributeSet);
|
|
|
|
|
|
|
|
nsAutoCString name;
|
|
|
|
rv = propElem->GetKey(name);
|
|
|
|
NS_ENSURE_SUCCESS(rv, objAttributeSet);
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
rv = propElem->GetValue(value);
|
|
|
|
NS_ENSURE_SUCCESS(rv, objAttributeSet);
|
|
|
|
|
|
|
|
AtkAttribute* objAttr = (AtkAttribute*)g_malloc(sizeof(AtkAttribute));
|
|
|
|
objAttr->name = g_strdup(name.get());
|
|
|
|
objAttr->value = g_strdup(NS_ConvertUTF16toUTF8(value).get());
|
|
|
|
objAttributeSet = g_slist_prepend(objAttributeSet, objAttr);
|
|
|
|
|
2015-03-06 23:44:02 +03:00
|
|
|
ConvertTextAttributeToAtkAttribute(name, value, &objAttributeSet);
|
2013-11-18 22:52:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// libatk-adaptor will free it
|
|
|
|
return objAttributeSet;
|
|
|
|
}
|
2006-09-12 21:06:12 +04:00
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static void
|
2012-05-29 05:18:45 +04:00
|
|
|
ConvertTexttoAsterisks(AccessibleWrap* accWrap, nsAString& aString)
|
2005-01-19 10:10:38 +03:00
|
|
|
{
|
2012-05-02 15:13:34 +04:00
|
|
|
// convert each char to "*" when it's "password text"
|
|
|
|
if (accWrap->NativeRole() == roles::PASSWORD_TEXT) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < aString.Length(); i++)
|
2012-05-02 15:13:34 +04:00
|
|
|
aString.Replace(i, 1, NS_LITERAL_STRING("*"));
|
|
|
|
}
|
2005-01-19 10:10:38 +03:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
static gchar*
|
2003-05-06 06:23:50 +04:00
|
|
|
getTextCB(AtkText *aText, gint aStartOffset, gint aEndOffset)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-01-09 23:01:39 +03:00
|
|
|
nsAutoString autoStr;
|
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return nullptr;
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
text->TextSubstring(aStartOffset, aEndOffset, autoStr);
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2005-01-19 10:10:38 +03:00
|
|
|
ConvertTexttoAsterisks(accWrap, autoStr);
|
2015-01-09 23:01:39 +03:00
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
proxy->TextSubstring(aStartOffset, aEndOffset, autoStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-01-09 23:01:39 +03:00
|
|
|
//copy and return, libspi will free it.
|
|
|
|
return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gchar*
|
2003-05-06 06:23:50 +04:00
|
|
|
getTextAfterOffsetCB(AtkText *aText, gint aOffset,
|
|
|
|
AtkTextBoundary aBoundaryType,
|
|
|
|
gint *aStartOffset, gint *aEndOffset)
|
|
|
|
{
|
2015-06-08 23:28:06 +03:00
|
|
|
nsAutoString autoStr;
|
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-06-08 23:28:06 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return nullptr;
|
2015-07-15 00:35:53 +03:00
|
|
|
|
2015-06-08 23:28:06 +03:00
|
|
|
text->TextAfterOffset(aOffset, aBoundaryType, &startOffset, &endOffset, autoStr);
|
|
|
|
ConvertTexttoAsterisks(accWrap, autoStr);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
proxy->GetTextAfterOffset(aOffset, aBoundaryType, autoStr, &startOffset,
|
|
|
|
&endOffset);
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2012-08-17 00:57:31 +04:00
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
|
|
|
|
return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gchar*
|
2003-05-06 06:23:50 +04:00
|
|
|
getTextAtOffsetCB(AtkText *aText, gint aOffset,
|
|
|
|
AtkTextBoundary aBoundaryType,
|
|
|
|
gint *aStartOffset, gint *aEndOffset)
|
|
|
|
{
|
2015-06-08 23:28:06 +03:00
|
|
|
nsAutoString autoStr;
|
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-06-08 23:28:06 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return nullptr;
|
2015-06-08 23:28:06 +03:00
|
|
|
|
2015-07-15 00:35:53 +03:00
|
|
|
text->TextAtOffset(aOffset, aBoundaryType, &startOffset, &endOffset, autoStr);
|
|
|
|
ConvertTexttoAsterisks(accWrap, autoStr);
|
2015-06-08 23:28:06 +03:00
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
proxy->GetTextAtOffset(aOffset, aBoundaryType, autoStr, &startOffset,
|
|
|
|
&endOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
|
|
|
|
return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gunichar
|
2012-05-02 15:13:34 +04:00
|
|
|
getCharacterAtOffsetCB(AtkText* aText, gint aOffset)
|
2003-05-06 06:23:50 +04:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-06 20:37:37 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-05-02 15:13:34 +04:00
|
|
|
|
2015-03-06 20:37:37 +03:00
|
|
|
// char16_t is unsigned short in Mozilla, gnuichar is guint32 in glib.
|
|
|
|
return static_cast<gunichar>(text->CharAt(aOffset));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
return static_cast<gunichar>(proxy->CharAt(aOffset));
|
|
|
|
}
|
2012-05-02 15:13:34 +04:00
|
|
|
|
2015-03-06 20:37:37 +03:00
|
|
|
return 0;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gchar*
|
2003-05-06 06:23:50 +04:00
|
|
|
getTextBeforeOffsetCB(AtkText *aText, gint aOffset,
|
|
|
|
AtkTextBoundary aBoundaryType,
|
|
|
|
gint *aStartOffset, gint *aEndOffset)
|
|
|
|
{
|
2015-06-08 23:28:06 +03:00
|
|
|
nsAutoString autoStr;
|
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-06-08 23:28:06 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return nullptr;
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-06-08 23:28:06 +03:00
|
|
|
text->TextBeforeOffset(aOffset, aBoundaryType,
|
|
|
|
&startOffset, &endOffset, autoStr);
|
|
|
|
ConvertTexttoAsterisks(accWrap, autoStr);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
proxy->GetTextBeforeOffset(aOffset, aBoundaryType, autoStr, &startOffset,
|
|
|
|
&endOffset);
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
|
|
|
|
return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gint
|
2003-05-06 06:23:50 +04:00
|
|
|
getCaretOffsetCB(AtkText *aText)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-06 23:43:25 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-06 23:43:25 +03:00
|
|
|
return static_cast<gint>(text->CaretOffset());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
return static_cast<gint>(proxy->CaretOffset());
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-06 23:43:25 +03:00
|
|
|
return 0;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static AtkAttributeSet*
|
2003-05-06 06:23:50 +04:00
|
|
|
getRunAttributesCB(AtkText *aText, gint aOffset,
|
|
|
|
gint *aStartOffset,
|
|
|
|
gint *aEndOffset)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
*aStartOffset = -1;
|
|
|
|
*aEndOffset = -1;
|
2015-03-06 23:44:02 +03:00
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-06 23:44:02 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-06 23:44:02 +03:00
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
text->TextAttributes(false, aOffset, &startOffset, &endOffset);
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-06 23:44:02 +03:00
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2015-03-06 23:44:02 +03:00
|
|
|
return ConvertToAtkTextAttributeSet(attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText));
|
|
|
|
if (!proxy) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-01-31 21:10:57 +03:00
|
|
|
nsAutoTArray<Attribute, 10> attrs;
|
2015-03-06 23:44:02 +03:00
|
|
|
proxy->TextAttributes(false, aOffset, &attrs, &startOffset, &endOffset);
|
2013-11-18 17:19:33 +04:00
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
2015-03-06 23:44:02 +03:00
|
|
|
return ConvertToAtkTextAttributeSet(attrs);
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static AtkAttributeSet*
|
2003-05-06 06:23:50 +04:00
|
|
|
getDefaultAttributesCB(AtkText *aText)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-06 23:44:02 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2015-03-06 23:44:02 +03:00
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes = text->DefaultTextAttributes();
|
|
|
|
return ConvertToAtkTextAttributeSet(attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText));
|
|
|
|
if (!proxy) {
|
2012-08-17 00:57:31 +04:00
|
|
|
return nullptr;
|
2015-03-06 23:44:02 +03:00
|
|
|
}
|
2008-07-17 16:06:24 +04:00
|
|
|
|
2016-01-31 21:10:57 +03:00
|
|
|
nsAutoTArray<Attribute, 10> attrs;
|
2015-03-06 23:44:02 +03:00
|
|
|
proxy->DefaultTextAttributes(&attrs);
|
|
|
|
return ConvertToAtkTextAttributeSet(attrs);
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static void
|
2003-05-06 06:23:50 +04:00
|
|
|
getCharacterExtentsCB(AtkText *aText, gint aOffset,
|
|
|
|
gint *aX, gint *aY,
|
|
|
|
gint *aWidth, gint *aHeight,
|
|
|
|
AtkCoordType aCoords)
|
|
|
|
{
|
2015-03-08 05:33:57 +03:00
|
|
|
if(!aX || !aY || !aWidth || !aHeight) {
|
2012-05-29 05:18:45 +04:00
|
|
|
return;
|
2015-03-08 05:33:57 +03:00
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-08 05:33:57 +03:00
|
|
|
nsIntRect rect;
|
|
|
|
uint32_t geckoCoordType;
|
|
|
|
if (aCoords == ATK_XY_SCREEN) {
|
|
|
|
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
|
|
|
|
} else {
|
|
|
|
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-08 05:33:57 +03:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rect = text->CharBounds(aOffset, geckoCoordType);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
rect = proxy->CharBounds(aOffset, geckoCoordType);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2007-04-23 16:00:45 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
*aX = rect.x;
|
|
|
|
*aY = rect.y;
|
|
|
|
*aWidth = rect.width;
|
|
|
|
*aHeight = rect.height;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static void
|
2006-08-16 17:36:19 +04:00
|
|
|
getRangeExtentsCB(AtkText *aText, gint aStartOffset, gint aEndOffset,
|
|
|
|
AtkCoordType aCoords, AtkTextRectangle *aRect)
|
|
|
|
{
|
2015-03-08 05:33:57 +03:00
|
|
|
if (!aRect) {
|
2012-05-29 05:18:45 +04:00
|
|
|
return;
|
2015-03-08 05:33:57 +03:00
|
|
|
}
|
2006-08-16 17:36:19 +04:00
|
|
|
|
2015-03-08 05:33:57 +03:00
|
|
|
nsIntRect rect;
|
|
|
|
uint32_t geckoCoordType;
|
|
|
|
if (aCoords == ATK_XY_SCREEN) {
|
|
|
|
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
|
|
|
|
} else {
|
|
|
|
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if(accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return;
|
|
|
|
}
|
2006-08-16 17:36:19 +04:00
|
|
|
|
2015-03-08 05:33:57 +03:00
|
|
|
rect = text->TextBounds(aStartOffset, aEndOffset, geckoCoordType);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
rect = proxy->TextBounds(aStartOffset, aEndOffset, geckoCoordType);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2007-04-23 16:00:45 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
aRect->x = rect.x;
|
|
|
|
aRect->y = rect.y;
|
|
|
|
aRect->width = rect.width;
|
|
|
|
aRect->height = rect.height;
|
2006-08-16 17:36:19 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gint
|
2003-05-06 06:23:50 +04:00
|
|
|
getCharacterCountCB(AtkText *aText)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-02-25 15:18:17 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* textAcc = accWrap->AsHyperText();
|
|
|
|
return
|
|
|
|
textAcc->IsDefunct() ? 0 : static_cast<gint>(textAcc->CharacterCount());
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-02-25 15:18:17 +03:00
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
return proxy->CharacterCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gint
|
2003-05-06 06:23:50 +04:00
|
|
|
getOffsetAtPointCB(AtkText *aText,
|
|
|
|
gint aX, gint aY,
|
|
|
|
AtkCoordType aCoords)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-08 15:05:55 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return -1;
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-08 15:05:55 +03:00
|
|
|
return static_cast<gint>(
|
|
|
|
text->OffsetAtPoint(aX, aY,
|
|
|
|
(aCoords == ATK_XY_SCREEN ?
|
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
|
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
return static_cast<gint>(
|
|
|
|
proxy->OffsetAtPoint(aX, aY,
|
|
|
|
(aCoords == ATK_XY_SCREEN ?
|
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
|
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE)));
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-08 15:05:55 +03:00
|
|
|
return -1;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gint
|
2006-05-29 09:46:38 +04:00
|
|
|
getTextSelectionCountCB(AtkText *aText)
|
2003-05-06 06:23:50 +04:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-02-25 15:18:17 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-02-25 15:18:17 +03:00
|
|
|
return text->SelectionCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
return proxy->SelectionCount();
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-02-25 15:18:17 +03:00
|
|
|
return 0;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gchar*
|
2006-05-29 09:46:38 +04:00
|
|
|
getTextSelectionCB(AtkText *aText, gint aSelectionNum,
|
|
|
|
gint *aStartOffset, gint *aEndOffset)
|
2003-05-06 06:23:50 +04:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2013-11-18 17:19:33 +04:00
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
2015-03-09 23:50:16 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-09 23:50:16 +03:00
|
|
|
text->SelectionBoundsAt(aSelectionNum, &startOffset, &endOffset);
|
2003-05-06 06:23:50 +04:00
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
|
|
|
|
|
|
|
return getTextCB(aText, *aStartOffset, *aEndOffset);
|
2015-03-09 23:50:16 +03:00
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
nsString data;
|
|
|
|
proxy->SelectionBoundsAt(aSelectionNum, data, &startOffset, &endOffset);
|
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 dataAsUTF8(data);
|
|
|
|
return (dataAsUTF8.get()) ? g_strdup(dataAsUTF8.get()) : nullptr;
|
|
|
|
}
|
|
|
|
return nullptr;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// set methods
|
2012-03-20 08:02:50 +04:00
|
|
|
static gboolean
|
2006-05-29 09:46:38 +04:00
|
|
|
addTextSelectionCB(AtkText *aText,
|
|
|
|
gint aStartOffset,
|
|
|
|
gint aEndOffset)
|
2003-05-06 06:23:50 +04:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-09 23:50:16 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-09 23:50:16 +03:00
|
|
|
return text->AddToSelection(aStartOffset, aEndOffset);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
return proxy->AddToSelection(aStartOffset, aEndOffset);
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-09 23:50:16 +03:00
|
|
|
return FALSE;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gboolean
|
2006-05-29 09:46:38 +04:00
|
|
|
removeTextSelectionCB(AtkText *aText,
|
|
|
|
gint aSelectionNum)
|
2003-05-06 06:23:50 +04:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-09 23:50:16 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-09 23:50:16 +03:00
|
|
|
return text->RemoveFromSelection(aSelectionNum);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
return proxy->RemoveFromSelection(aSelectionNum);
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-09 23:50:16 +03:00
|
|
|
return FALSE;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gboolean
|
2006-05-29 09:46:38 +04:00
|
|
|
setTextSelectionCB(AtkText *aText, gint aSelectionNum,
|
|
|
|
gint aStartOffset, gint aEndOffset)
|
2003-05-06 06:23:50 +04:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-09 23:50:16 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-09 23:50:16 +03:00
|
|
|
return text->SetSelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
return proxy->SetSelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset);
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-09 23:50:16 +03:00
|
|
|
return FALSE;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gboolean
|
2003-05-06 06:23:50 +04:00
|
|
|
setCaretOffsetCB(AtkText *aText, gint aOffset)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-06 23:43:25 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole() || !text->IsValidOffset(aOffset)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-06 23:43:25 +03:00
|
|
|
text->SetCaretOffset(aOffset);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
2015-10-14 23:36:52 +03:00
|
|
|
proxy->SetCaretOffset(aOffset);
|
|
|
|
return TRUE;
|
2015-03-06 23:43:25 +03:00
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-06 23:43:25 +03:00
|
|
|
return FALSE;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
2012-03-20 08:02:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
textInterfaceInitCB(AtkTextIface* aIface)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aIface, "Invalid aIface");
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(!aIface))
|
2012-03-20 08:02:50 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
aIface->get_text = getTextCB;
|
|
|
|
aIface->get_text_after_offset = getTextAfterOffsetCB;
|
|
|
|
aIface->get_text_at_offset = getTextAtOffsetCB;
|
|
|
|
aIface->get_character_at_offset = getCharacterAtOffsetCB;
|
|
|
|
aIface->get_text_before_offset = getTextBeforeOffsetCB;
|
|
|
|
aIface->get_caret_offset = getCaretOffsetCB;
|
|
|
|
aIface->get_run_attributes = getRunAttributesCB;
|
|
|
|
aIface->get_default_attributes = getDefaultAttributesCB;
|
|
|
|
aIface->get_character_extents = getCharacterExtentsCB;
|
|
|
|
aIface->get_range_extents = getRangeExtentsCB;
|
|
|
|
aIface->get_character_count = getCharacterCountCB;
|
|
|
|
aIface->get_offset_at_point = getOffsetAtPointCB;
|
|
|
|
aIface->get_n_selections = getTextSelectionCountCB;
|
|
|
|
aIface->get_selection = getTextSelectionCB;
|
|
|
|
|
|
|
|
// set methods
|
|
|
|
aIface->add_selection = addTextSelectionCB;
|
|
|
|
aIface->remove_selection = removeTextSelectionCB;
|
|
|
|
aIface->set_selection = setTextSelectionCB;
|
|
|
|
aIface->set_caret_offset = setCaretOffsetCB;
|
2013-11-18 22:52:21 +04:00
|
|
|
|
|
|
|
// Cache the string values of the atk text attribute names.
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(sAtkTextAttrNames); i++)
|
|
|
|
sAtkTextAttrNames[i] =
|
|
|
|
atk_text_attribute_get_name(static_cast<AtkTextAttribute>(i));
|
2012-03-20 08:02:50 +04:00
|
|
|
}
|