Line data Source code
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/. */
6 :
7 : #include "InterfaceInitFuncs.h"
8 :
9 : #include "Accessible-inl.h"
10 : #include "HyperTextAccessible-inl.h"
11 : #include "nsMai.h"
12 : #include "ProxyAccessible.h"
13 : #include "nsString.h"
14 : #include "mozilla/Likely.h"
15 :
16 : using namespace mozilla::a11y;
17 :
18 : extern "C" {
19 : static void
20 0 : setTextContentsCB(AtkEditableText *aText, const gchar *aString)
21 : {
22 0 : AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
23 0 : if (accWrap) {
24 0 : HyperTextAccessible* text = accWrap->AsHyperText();
25 0 : if (!text || !text->IsTextRole()) {
26 0 : return;
27 : }
28 :
29 0 : NS_ConvertUTF8toUTF16 strContent(aString);
30 0 : text->ReplaceText(strContent);
31 0 : } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
32 0 : NS_ConvertUTF8toUTF16 strContent(aString);
33 0 : proxy->ReplaceText(strContent);
34 : }
35 : }
36 :
37 : static void
38 0 : insertTextCB(AtkEditableText *aText,
39 : const gchar *aString, gint aLength, gint *aPosition)
40 : {
41 0 : AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
42 0 : if (accWrap) {
43 0 : HyperTextAccessible* text = accWrap->AsHyperText();
44 0 : if (!text || !text->IsTextRole()) {
45 0 : return;
46 : }
47 :
48 0 : NS_ConvertUTF8toUTF16 strContent(aString);
49 0 : text->InsertText(strContent, *aPosition);
50 0 : } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
51 0 : NS_ConvertUTF8toUTF16 strContent(aString);
52 0 : proxy->InsertText(strContent, *aPosition);
53 : }
54 : }
55 :
56 : static void
57 0 : copyTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
58 : {
59 0 : AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
60 0 : if (accWrap) {
61 0 : HyperTextAccessible* text = accWrap->AsHyperText();
62 0 : if (!text || !text->IsTextRole()) {
63 0 : return;
64 : }
65 :
66 0 : text->CopyText(aStartPos, aEndPos);
67 0 : } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
68 0 : proxy->CopyText(aStartPos, aEndPos);
69 : }
70 : }
71 :
72 : static void
73 0 : cutTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
74 : {
75 0 : AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
76 0 : if (accWrap) {
77 0 : HyperTextAccessible* text = accWrap->AsHyperText();
78 0 : if (!text || !text->IsTextRole()) {
79 0 : return;
80 : }
81 :
82 0 : text->CutText(aStartPos, aEndPos);
83 0 : } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
84 0 : proxy->CutText(aStartPos, aEndPos);
85 : }
86 : }
87 :
88 : static void
89 0 : deleteTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos)
90 : {
91 0 : AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
92 0 : if (accWrap) {
93 0 : HyperTextAccessible* text = accWrap->AsHyperText();
94 0 : if (!text || !text->IsTextRole()) {
95 0 : return;
96 : }
97 :
98 0 : text->DeleteText(aStartPos, aEndPos);
99 0 : } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
100 0 : proxy->DeleteText(aStartPos, aEndPos);
101 : }
102 : }
103 :
104 : static void
105 0 : pasteTextCB(AtkEditableText *aText, gint aPosition)
106 : {
107 0 : AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
108 0 : if (accWrap) {
109 0 : HyperTextAccessible* text = accWrap->AsHyperText();
110 0 : if (!text || !text->IsTextRole()) {
111 0 : return;
112 : }
113 :
114 0 : text->PasteText(aPosition);
115 0 : } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
116 0 : proxy->PasteText(aPosition);
117 : }
118 : }
119 : }
120 :
121 : void
122 0 : editableTextInterfaceInitCB(AtkEditableTextIface* aIface)
123 : {
124 0 : NS_ASSERTION(aIface, "Invalid aIface");
125 0 : if (MOZ_UNLIKELY(!aIface))
126 0 : return;
127 :
128 0 : aIface->set_text_contents = setTextContentsCB;
129 0 : aIface->insert_text = insertTextCB;
130 0 : aIface->copy_text = copyTextCB;
131 0 : aIface->cut_text = cutTextCB;
132 0 : aIface->delete_text = deleteTextCB;
133 0 : aIface->paste_text = pasteTextCB;
134 : }
|