|
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 |
|
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 { |
|
22 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
|
23 if (!accWrap) |
|
24 return; |
|
25 |
|
26 HyperTextAccessible* text = accWrap->AsHyperText(); |
|
27 if (!text || !text->IsTextRole()) |
|
28 return; |
|
29 |
|
30 NS_ConvertUTF8toUTF16 strContent(aString); |
|
31 text->ReplaceText(strContent); |
|
32 } |
|
33 |
|
34 static void |
|
35 insertTextCB(AtkEditableText *aText, |
|
36 const gchar *aString, gint aLength, gint *aPosition) |
|
37 { |
|
38 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
|
39 if (!accWrap) |
|
40 return; |
|
41 |
|
42 HyperTextAccessible* text = accWrap->AsHyperText(); |
|
43 if (!text || !text->IsTextRole()) |
|
44 return; |
|
45 |
|
46 NS_ConvertUTF8toUTF16 strContent(aString, aLength); |
|
47 text->InsertText(strContent, *aPosition); |
|
48 } |
|
49 |
|
50 static void |
|
51 copyTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos) |
|
52 { |
|
53 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
|
54 if (!accWrap) |
|
55 return; |
|
56 |
|
57 HyperTextAccessible* text = accWrap->AsHyperText(); |
|
58 if (!text || !text->IsTextRole()) |
|
59 return; |
|
60 |
|
61 text->CopyText(aStartPos, aEndPos); |
|
62 } |
|
63 |
|
64 static void |
|
65 cutTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos) |
|
66 { |
|
67 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
|
68 if (!accWrap) |
|
69 return; |
|
70 |
|
71 HyperTextAccessible* text = accWrap->AsHyperText(); |
|
72 if (!text || !text->IsTextRole()) |
|
73 return; |
|
74 |
|
75 text->CutText(aStartPos, aEndPos); |
|
76 } |
|
77 |
|
78 static void |
|
79 deleteTextCB(AtkEditableText *aText, gint aStartPos, gint aEndPos) |
|
80 { |
|
81 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
|
82 if (!accWrap) |
|
83 return; |
|
84 |
|
85 HyperTextAccessible* text = accWrap->AsHyperText(); |
|
86 if (!text || !text->IsTextRole()) |
|
87 return; |
|
88 |
|
89 text->DeleteText(aStartPos, aEndPos); |
|
90 } |
|
91 |
|
92 static void |
|
93 pasteTextCB(AtkEditableText *aText, gint aPosition) |
|
94 { |
|
95 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
|
96 if (!accWrap) |
|
97 return; |
|
98 |
|
99 HyperTextAccessible* text = accWrap->AsHyperText(); |
|
100 if (!text || !text->IsTextRole()) |
|
101 return; |
|
102 |
|
103 text->PasteText(aPosition); |
|
104 } |
|
105 } |
|
106 |
|
107 void |
|
108 editableTextInterfaceInitCB(AtkEditableTextIface* aIface) |
|
109 { |
|
110 NS_ASSERTION(aIface, "Invalid aIface"); |
|
111 if (MOZ_UNLIKELY(!aIface)) |
|
112 return; |
|
113 |
|
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; |
|
120 } |