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"
|
2009-03-10 18:59:25 -07:00
|
|
|
|
2012-12-20 19:16:44 -08:00
|
|
|
#include "Accessible-inl.h"
|
2013-11-18 05:19:33 -08:00
|
|
|
#include "HyperTextAccessible-inl.h"
|
2012-03-19 21:02:50 -07:00
|
|
|
#include "nsMai.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-09-10 15:18:59 -07:00
|
|
|
#include "nsIAccessibleTypes.h"
|
2012-02-29 02:59:38 -08:00
|
|
|
#include "nsIPersistentProperties2.h"
|
2013-11-18 10:52:21 -08:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2012-02-29 02:59:38 -08:00
|
|
|
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
|
|
|
|
2013-11-18 10:52:21 -08:00
|
|
|
using namespace mozilla;
|
2012-05-02 04:13:34 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2013-11-18 10:52:21 -08:00
|
|
|
static const char* sAtkTextAttrNames[ATK_TEXT_ATTR_LAST_DEFINED];
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Handle attributes where atk has its own name.
|
|
|
|
const char* atkName = nullptr;
|
|
|
|
nsAutoString atkValue;
|
|
|
|
if (name.EqualsLiteral("color")) {
|
|
|
|
// The format of the atk attribute is r,g,b and the gecko one is
|
|
|
|
// rgb(r,g,b).
|
|
|
|
atkValue = Substring(value, 5, value.Length() - 1);
|
|
|
|
atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_FG_COLOR];
|
|
|
|
} else if (name.EqualsLiteral("background-color")) {
|
|
|
|
// The format of the atk attribute is r,g,b and the gecko one is
|
|
|
|
// rgb(r,g,b).
|
|
|
|
atkValue = Substring(value, 5, value.Length() - 1);
|
|
|
|
atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_BG_COLOR];
|
|
|
|
} else if (name.EqualsLiteral("font-family")) {
|
|
|
|
atkValue = value;
|
|
|
|
atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_FAMILY_NAME];
|
2014-05-21 20:48:51 -07:00
|
|
|
} else if (name.EqualsLiteral("font-size")) {
|
2013-11-18 10:52:21 -08:00
|
|
|
// ATK wants the number of pixels without px at the end.
|
|
|
|
atkValue = StringHead(value, value.Length() - 2);
|
|
|
|
atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_SIZE];
|
|
|
|
} else if (name.EqualsLiteral("font-weight")) {
|
|
|
|
atkValue = value;
|
|
|
|
atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_WEIGHT];
|
|
|
|
} else if (name.EqualsLiteral("invalid")) {
|
|
|
|
atkValue = value;
|
|
|
|
atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_INVALID];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atkName) {
|
|
|
|
objAttr = static_cast<AtkAttribute*>(g_malloc(sizeof(AtkAttribute)));
|
|
|
|
objAttr->name = g_strdup(atkName);
|
|
|
|
objAttr->value = g_strdup(NS_ConvertUTF16toUTF8(atkValue).get());
|
|
|
|
objAttributeSet = g_slist_prepend(objAttributeSet, objAttr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// libatk-adaptor will free it
|
|
|
|
return objAttributeSet;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static void
|
2012-05-28 18:18:45 -07:00
|
|
|
ConvertTexttoAsterisks(AccessibleWrap* accWrap, nsAString& aString)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-02 04:13:34 -07:00
|
|
|
// convert each char to "*" when it's "password text"
|
|
|
|
if (accWrap->NativeRole() == roles::PASSWORD_TEXT) {
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < aString.Length(); i++)
|
2012-05-02 04:13:34 -07:00
|
|
|
aString.Replace(i, 1, NS_LITERAL_STRING("*"));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
static gchar*
|
2007-03-22 10:30:00 -07:00
|
|
|
getTextCB(AtkText *aText, gint aStartOffset, gint aEndOffset)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString autoStr;
|
2013-11-18 05:19:33 -08:00
|
|
|
text->TextSubstring(aStartOffset, aEndOffset, autoStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
ConvertTexttoAsterisks(accWrap, autoStr);
|
|
|
|
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
|
|
|
|
|
|
|
|
//copy and return, libspi will free it.
|
2012-07-30 07:20:58 -07:00
|
|
|
return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gchar*
|
2007-03-22 10:30:00 -07:00
|
|
|
getTextAfterOffsetCB(AtkText *aText, gint aOffset,
|
|
|
|
AtkTextBoundary aBoundaryType,
|
|
|
|
gint *aStartOffset, gint *aEndOffset)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
nsAutoString autoStr;
|
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
2013-11-18 05:19:33 -08:00
|
|
|
text->TextAfterOffset(aOffset, aBoundaryType, &startOffset, &endOffset, autoStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
ConvertTexttoAsterisks(accWrap, autoStr);
|
|
|
|
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
|
|
|
|
return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gchar*
|
2007-03-22 10:30:00 -07:00
|
|
|
getTextAtOffsetCB(AtkText *aText, gint aOffset,
|
|
|
|
AtkTextBoundary aBoundaryType,
|
|
|
|
gint *aStartOffset, gint *aEndOffset)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString autoStr;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
2013-11-18 05:19:33 -08:00
|
|
|
text->TextAtOffset(aOffset, aBoundaryType, &startOffset, &endOffset, autoStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
|
|
|
|
|
|
|
ConvertTexttoAsterisks(accWrap, autoStr);
|
|
|
|
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
|
2012-07-30 07:20:58 -07:00
|
|
|
return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gunichar
|
2012-05-02 04:13:34 -07:00
|
|
|
getCharacterAtOffsetCB(AtkText* aText, gint aOffset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2012-05-02 04:13:34 -07:00
|
|
|
if (!accWrap)
|
|
|
|
return 0;
|
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return 0;
|
2012-05-02 04:13:34 -07:00
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
// char16_t is unsigned short in Mozilla, gnuichar is guint32 in glib.
|
2013-12-19 11:28:51 -08:00
|
|
|
return static_cast<gunichar>(text->CharAt(aOffset));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gchar*
|
2007-03-22 10:30:00 -07:00
|
|
|
getTextBeforeOffsetCB(AtkText *aText, gint aOffset,
|
|
|
|
AtkTextBoundary aBoundaryType,
|
|
|
|
gint *aStartOffset, gint *aEndOffset)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
nsAutoString autoStr;
|
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
|
|
|
text->TextBeforeOffset(aOffset, aBoundaryType,
|
|
|
|
&startOffset, &endOffset, autoStr);
|
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
ConvertTexttoAsterisks(accWrap, autoStr);
|
|
|
|
NS_ConvertUTF16toUTF8 cautoStr(autoStr);
|
|
|
|
return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gint
|
2007-03-22 10:30:00 -07:00
|
|
|
getCaretOffsetCB(AtkText *aText)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
return static_cast<gint>(text->CaretOffset());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static AtkAttributeSet*
|
2007-03-22 10:30:00 -07:00
|
|
|
getRunAttributesCB(AtkText *aText, gint aOffset,
|
|
|
|
gint *aStartOffset,
|
|
|
|
gint *aEndOffset)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
*aStartOffset = -1;
|
|
|
|
*aEndOffset = -1;
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
text->TextAttributes(false, aOffset, &startOffset, &endOffset);
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 10:52:21 -08:00
|
|
|
return ConvertToAtkTextAttributeSet(attributes);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static AtkAttributeSet*
|
2007-03-22 10:30:00 -07:00
|
|
|
getDefaultAttributesCB(AtkText *aText)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return nullptr;
|
2008-07-17 05:06:24 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes = text->DefaultTextAttributes();
|
2013-11-18 10:52:21 -08:00
|
|
|
return ConvertToAtkTextAttributeSet(attributes);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static void
|
2007-03-22 10:30:00 -07:00
|
|
|
getCharacterExtentsCB(AtkText *aText, gint aOffset,
|
|
|
|
gint *aX, gint *aY,
|
|
|
|
gint *aWidth, gint *aHeight,
|
|
|
|
AtkCoordType aCoords)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if(!accWrap || !aX || !aY || !aWidth || !aHeight)
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t geckoCoordType;
|
2007-06-04 01:16:04 -07:00
|
|
|
if (aCoords == ATK_XY_SCREEN)
|
|
|
|
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
|
|
|
|
else
|
|
|
|
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
|
2007-04-23 05:00:45 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
nsIntRect rect = text->CharBounds(aOffset, geckoCoordType);
|
|
|
|
*aX = rect.x;
|
|
|
|
*aY = rect.y;
|
|
|
|
*aWidth = rect.width;
|
|
|
|
*aHeight = rect.height;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static void
|
2007-03-22 10:30:00 -07:00
|
|
|
getRangeExtentsCB(AtkText *aText, gint aStartOffset, gint aEndOffset,
|
|
|
|
AtkCoordType aCoords, AtkTextRectangle *aRect)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if(!accWrap || !aRect)
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t geckoCoordType;
|
2007-06-04 01:16:04 -07:00
|
|
|
if (aCoords == ATK_XY_SCREEN)
|
|
|
|
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE;
|
|
|
|
else
|
|
|
|
geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE;
|
2007-04-23 05:00:45 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
nsIntRect rect = text->TextBounds(aStartOffset, aEndOffset, geckoCoordType);
|
|
|
|
aRect->x = rect.x;
|
|
|
|
aRect->y = rect.y;
|
|
|
|
aRect->width = rect.width;
|
|
|
|
aRect->height = rect.height;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gint
|
2007-03-22 10:30:00 -07:00
|
|
|
getCharacterCountCB(AtkText *aText)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible* textAcc = accWrap->AsHyperText();
|
2012-05-28 18:18:45 -07:00
|
|
|
return textAcc->IsDefunct() ?
|
|
|
|
0 : static_cast<gint>(textAcc->CharacterCount());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gint
|
2007-03-22 10:30:00 -07:00
|
|
|
getOffsetAtPointCB(AtkText *aText,
|
|
|
|
gint aX, gint aY,
|
|
|
|
AtkCoordType aCoords)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
|
|
|
return -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
return static_cast<gint>(
|
|
|
|
text->OffsetAtPoint(aX, aY,
|
|
|
|
(aCoords == ATK_XY_SCREEN ?
|
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
|
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE)));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gint
|
2007-03-22 10:30:00 -07:00
|
|
|
getTextSelectionCountCB(AtkText *aText)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
2012-07-20 04:16:17 -07:00
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
return text->SelectionCount();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gchar*
|
2007-03-22 10:30:00 -07:00
|
|
|
getTextSelectionCB(AtkText *aText, gint aSelectionNum,
|
|
|
|
gint *aStartOffset, gint *aEndOffset)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
|
|
|
text->SelectionBoundsAt(aSelectionNum, &startOffset, &endOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
|
|
|
|
|
|
|
return getTextCB(aText, *aStartOffset, *aEndOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set methods
|
2012-03-19 21:02:50 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
addTextSelectionCB(AtkText *aText,
|
|
|
|
gint aStartOffset,
|
|
|
|
gint aEndOffset)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
2013-11-18 05:19:33 -08:00
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
return text->AddToSelection(aStartOffset, aEndOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
removeTextSelectionCB(AtkText *aText,
|
|
|
|
gint aSelectionNum)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
2013-11-18 05:19:33 -08:00
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
return text->RemoveFromSelection(aSelectionNum);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
setTextSelectionCB(AtkText *aText, gint aSelectionNum,
|
|
|
|
gint aStartOffset, gint aEndOffset)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole())
|
2013-11-18 05:19:33 -08:00
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
return text->SetSelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
setCaretOffsetCB(AtkText *aText, gint aOffset)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
|
|
|
if (!accWrap)
|
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 13:57:31 -07:00
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
2013-11-18 05:19:33 -08:00
|
|
|
if (!text || !text->IsTextRole() || !text->IsValidOffset(aOffset))
|
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-11-18 05:19:33 -08:00
|
|
|
text->SetCaretOffset(aOffset);
|
|
|
|
return TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-03-19 21:02:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
textInterfaceInitCB(AtkTextIface* aIface)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aIface, "Invalid aIface");
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(!aIface))
|
2012-03-19 21:02:50 -07: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 10:52:21 -08: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-19 21:02:50 -07:00
|
|
|
}
|