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"
|
2003-05-06 06:23:50 +04:00
|
|
|
|
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-03-10 00:04:02 +03:00
|
|
|
#include "ProxyAccessible.h"
|
2012-03-20 08:02:50 +04:00
|
|
|
#include "nsString.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2012-11-18 06:01:44 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
extern "C" {
|
|
|
|
static void
|
2003-05-06 06:23:50 +04:00
|
|
|
setTextContentsCB(AtkEditableText *aText, const gchar *aString)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-10 00:04:02 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF8toUTF16 strContent(aString);
|
|
|
|
text->ReplaceText(strContent);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
NS_ConvertUTF8toUTF16 strContent(aString);
|
|
|
|
proxy->ReplaceText(strContent);
|
|
|
|
}
|
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
|
|
|
insertTextCB(AtkEditableText *aText,
|
|
|
|
const gchar *aString, gint aLength, gint *aPosition)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-10 00:04:02 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF8toUTF16 strContent(aString);
|
|
|
|
text->InsertText(strContent, *aPosition);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
NS_ConvertUTF8toUTF16 strContent(aString);
|
|
|
|
proxy->InsertText(strContent, *aPosition);
|
|
|
|
}
|
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
|
|
|
copyTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-10 00:04:02 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
text->CopyText(aStartPos, aEndPos);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
proxy->CopyText(aStartPos, aEndPos);
|
|
|
|
}
|
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
|
|
|
cutTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-10 00:04:02 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
text->CutText(aStartPos, aEndPos);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
proxy->CutText(aStartPos, aEndPos);
|
|
|
|
}
|
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
|
|
|
deleteTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-10 00:04:02 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
text->DeleteText(aStartPos, aEndPos);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
proxy->DeleteText(aStartPos, aEndPos);
|
|
|
|
}
|
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
|
|
|
pasteTextCB(AtkEditableText *aText, gint aPosition)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-10 00:04:02 +03:00
|
|
|
if (accWrap) {
|
|
|
|
HyperTextAccessible* text = accWrap->AsHyperText();
|
|
|
|
if (!text || !text->IsTextRole()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
text->PasteText(aPosition);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
|
|
|
|
proxy->PasteText(aPosition);
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
2012-03-20 08:02:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
editableTextInterfaceInitCB(AtkEditableTextIface* 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->set_text_contents = setTextContentsCB;
|
|
|
|
aIface->insert_text = insertTextCB;
|
|
|
|
aIface->copy_text = copyTextCB;
|
|
|
|
aIface->cut_text = cutTextCB;
|
|
|
|
aIface->delete_text = deleteTextCB;
|
|
|
|
aIface->paste_text = pasteTextCB;
|
|
|
|
}
|