/src/mozilla-central/accessible/atk/nsMaiInterfaceEditableText.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | setTextContentsCB(AtkEditableText *aText, const gchar *aString) |
21 | 0 | { |
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 | 0 | } |
28 | 0 | |
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 | 0 | } |
35 | 0 | } |
36 | | |
37 | | static void |
38 | | insertTextCB(AtkEditableText *aText, |
39 | | const gchar *aString, gint aLength, gint *aPosition) |
40 | 0 | { |
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 | 0 | } |
47 | 0 | |
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 | 0 | } |
54 | 0 | } |
55 | | |
56 | | static void |
57 | | copyTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos) |
58 | 0 | { |
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 | 0 | } |
65 | 0 | |
66 | 0 | text->CopyText(aStartPos, aEndPos); |
67 | 0 | } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) { |
68 | 0 | proxy->CopyText(aStartPos, aEndPos); |
69 | 0 | } |
70 | 0 | } |
71 | | |
72 | | static void |
73 | | cutTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos) |
74 | 0 | { |
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 | 0 | } |
81 | 0 | |
82 | 0 | text->CutText(aStartPos, aEndPos); |
83 | 0 | } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) { |
84 | 0 | proxy->CutText(aStartPos, aEndPos); |
85 | 0 | } |
86 | 0 | } |
87 | | |
88 | | static void |
89 | | deleteTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos) |
90 | 0 | { |
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 | 0 | } |
97 | 0 | |
98 | 0 | text->DeleteText(aStartPos, aEndPos); |
99 | 0 | } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) { |
100 | 0 | proxy->DeleteText(aStartPos, aEndPos); |
101 | 0 | } |
102 | 0 | } |
103 | | |
104 | | static void |
105 | | pasteTextCB(AtkEditableText *aText, gint aPosition) |
106 | 0 | { |
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 | 0 | } |
113 | 0 | |
114 | 0 | text->PasteText(aPosition); |
115 | 0 | } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) { |
116 | 0 | proxy->PasteText(aPosition); |
117 | 0 | } |
118 | 0 | } |
119 | | } |
120 | | |
121 | | void |
122 | | editableTextInterfaceInitCB(AtkEditableTextIface* aIface) |
123 | 0 | { |
124 | 0 | NS_ASSERTION(aIface, "Invalid aIface"); |
125 | 0 | if (MOZ_UNLIKELY(!aIface)) |
126 | 0 | return; |
127 | 0 | |
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 | 0 | } |