Bug 1758984 - add status to mozlog crash so group summary is not marked as OK. r...
[gecko.git] / accessible / atk / nsMaiInterfaceEditableText.cpp
bloba87ff2e6147f673392f2b2a1b26722bc13ba0f26
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"
11 #include "nsMai.h"
12 #include "RemoteAccessible.h"
13 #include "nsString.h"
14 #include "mozilla/Likely.h"
16 using namespace mozilla::a11y;
18 extern "C" {
19 static void setTextContentsCB(AtkEditableText* aText, const gchar* aString) {
20 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
21 if (accWrap) {
22 HyperTextAccessible* text = accWrap->AsHyperText();
23 if (!text || !text->IsTextRole()) {
24 return;
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));
38 if (accWrap) {
39 HyperTextAccessible* text = accWrap->AsHyperText();
40 if (!text || !text->IsTextRole()) {
41 return;
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));
54 if (accWrap) {
55 HyperTextAccessible* text = accWrap->AsHyperText();
56 if (!text || !text->IsTextRole()) {
57 return;
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));
68 if (accWrap) {
69 HyperTextAccessible* text = accWrap->AsHyperText();
70 if (!text || !text->IsTextRole()) {
71 return;
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));
82 if (accWrap) {
83 HyperTextAccessible* text = accWrap->AsHyperText();
84 if (!text || !text->IsTextRole()) {
85 return;
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));
97 if (accWrap) {
98 RefPtr<HyperTextAccessible> text = accWrap->AsHyperText();
99 if (!text || !text->IsTextRole()) {
100 return;
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;