1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "InterfaceInitFuncs.h"
9 #include "LocalAccessible-inl.h"
10 #include "HyperTextAccessible-inl.h"
12 #include "RemoteAccessible.h"
14 #include "mozilla/Likely.h"
16 using namespace mozilla::a11y
;
19 static void setTextContentsCB(AtkEditableText
* aText
, const gchar
* aString
) {
20 AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aText
));
22 HyperTextAccessible
* text
= accWrap
->AsHyperText();
23 if (!text
|| !text
->IsTextRole()) {
27 NS_ConvertUTF8toUTF16
strContent(aString
);
28 text
->ReplaceText(strContent
);
29 } else if (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aText
))) {
30 NS_ConvertUTF8toUTF16
strContent(aString
);
31 proxy
->ReplaceText(strContent
);
35 static void insertTextCB(AtkEditableText
* aText
, const gchar
* aString
,
36 gint aLength
, gint
* aPosition
) {
37 AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aText
));
39 HyperTextAccessible
* text
= accWrap
->AsHyperText();
40 if (!text
|| !text
->IsTextRole()) {
44 NS_ConvertUTF8toUTF16
strContent(aString
);
45 text
->InsertText(strContent
, *aPosition
);
46 } else if (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aText
))) {
47 NS_ConvertUTF8toUTF16
strContent(aString
);
48 proxy
->InsertText(strContent
, *aPosition
);
52 static void copyTextCB(AtkEditableText
* aText
, gint aStartPos
, gint aEndPos
) {
53 AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aText
));
55 HyperTextAccessible
* text
= accWrap
->AsHyperText();
56 if (!text
|| !text
->IsTextRole()) {
60 text
->CopyText(aStartPos
, aEndPos
);
61 } else if (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aText
))) {
62 proxy
->CopyText(aStartPos
, aEndPos
);
66 static void cutTextCB(AtkEditableText
* aText
, gint aStartPos
, gint aEndPos
) {
67 AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aText
));
69 HyperTextAccessible
* text
= accWrap
->AsHyperText();
70 if (!text
|| !text
->IsTextRole()) {
74 text
->CutText(aStartPos
, aEndPos
);
75 } else if (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aText
))) {
76 proxy
->CutText(aStartPos
, aEndPos
);
80 static void deleteTextCB(AtkEditableText
* aText
, gint aStartPos
, gint aEndPos
) {
81 AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aText
));
83 HyperTextAccessible
* text
= accWrap
->AsHyperText();
84 if (!text
|| !text
->IsTextRole()) {
88 text
->DeleteText(aStartPos
, aEndPos
);
89 } else if (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aText
))) {
90 proxy
->DeleteText(aStartPos
, aEndPos
);
94 MOZ_CAN_RUN_SCRIPT_BOUNDARY
95 static void pasteTextCB(AtkEditableText
* aText
, gint aPosition
) {
96 AccessibleWrap
* accWrap
= GetAccessibleWrap(ATK_OBJECT(aText
));
98 RefPtr
<HyperTextAccessible
> text
= accWrap
->AsHyperText();
99 if (!text
|| !text
->IsTextRole()) {
103 text
->PasteText(aPosition
);
104 } else if (RemoteAccessible
* proxy
= GetProxy(ATK_OBJECT(aText
))) {
105 proxy
->PasteText(aPosition
);
110 void editableTextInterfaceInitCB(AtkEditableTextIface
* aIface
) {
111 NS_ASSERTION(aIface
, "Invalid aIface");
112 if (MOZ_UNLIKELY(!aIface
)) return;
114 aIface
->set_text_contents
= setTextContentsCB
;
115 aIface
->insert_text
= insertTextCB
;
116 aIface
->copy_text
= copyTextCB
;
117 aIface
->cut_text
= cutTextCB
;
118 aIface
->delete_text
= deleteTextCB
;
119 aIface
->paste_text
= pasteTextCB
;