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"
|
2007-03-22 10:30:00 -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"
|
2015-03-09 14:04:02 -07:00
|
|
|
#include "ProxyAccessible.h"
|
2012-03-19 21:02:50 -07:00
|
|
|
#include "nsString.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-17 18:01:44 -08:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
extern "C" {
|
|
|
|
static void
|
2007-03-22 10:30:00 -07:00
|
|
|
setTextContentsCB(AtkEditableText *aText, const gchar *aString)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-09 14:04:02 -07: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);
|
|
|
|
}
|
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
|
|
|
insertTextCB(AtkEditableText *aText,
|
|
|
|
const gchar *aString, gint aLength, gint *aPosition)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-09 14:04:02 -07: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);
|
|
|
|
}
|
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
|
|
|
copyTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-09 14:04:02 -07: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);
|
|
|
|
}
|
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
|
|
|
cutTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-09 14:04:02 -07: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);
|
|
|
|
}
|
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
|
|
|
deleteTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-09 14:04:02 -07: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);
|
|
|
|
}
|
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
|
|
|
pasteTextCB(AtkEditableText *aText, gint aPosition)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
|
2015-03-09 14:04:02 -07: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);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-03-19 21:02:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
editableTextInterfaceInitCB(AtkEditableTextIface* 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->set_text_contents = setTextContentsCB;
|
|
|
|
aIface->insert_text = insertTextCB;
|
|
|
|
aIface->copy_text = copyTextCB;
|
|
|
|
aIface->cut_text = cutTextCB;
|
|
|
|
aIface->delete_text = deleteTextCB;
|
|
|
|
aIface->paste_text = pasteTextCB;
|
|
|
|
}
|