|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:expandtab:shiftwidth=2:tabstop=2: |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #include "ia2AccessibleEditableText.h" |
|
9 |
|
10 #include "AccessibleEditableText_i.c" |
|
11 #include "HyperTextAccessible-inl.h" |
|
12 #include "HyperTextAccessibleWrap.h" |
|
13 |
|
14 #include "nsCOMPtr.h" |
|
15 #include "nsString.h" |
|
16 |
|
17 using namespace mozilla::a11y; |
|
18 |
|
19 // IAccessibleEditableText |
|
20 |
|
21 STDMETHODIMP |
|
22 ia2AccessibleEditableText::copyText(long aStartOffset, long aEndOffset) |
|
23 { |
|
24 A11Y_TRYBLOCK_BEGIN |
|
25 |
|
26 HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this); |
|
27 if (textAcc->IsDefunct()) |
|
28 return CO_E_OBJNOTCONNECTED; |
|
29 |
|
30 if (!textAcc->IsValidRange(aStartOffset, aEndOffset)) |
|
31 return E_INVALIDARG; |
|
32 |
|
33 textAcc->CopyText(aStartOffset, aEndOffset); |
|
34 return S_OK; |
|
35 |
|
36 A11Y_TRYBLOCK_END |
|
37 } |
|
38 |
|
39 STDMETHODIMP |
|
40 ia2AccessibleEditableText::deleteText(long aStartOffset, long aEndOffset) |
|
41 { |
|
42 A11Y_TRYBLOCK_BEGIN |
|
43 |
|
44 HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this); |
|
45 if (textAcc->IsDefunct()) |
|
46 return CO_E_OBJNOTCONNECTED; |
|
47 |
|
48 if (!textAcc->IsValidRange(aStartOffset, aEndOffset)) |
|
49 return E_INVALIDARG; |
|
50 |
|
51 textAcc->DeleteText(aStartOffset, aEndOffset); |
|
52 return S_OK; |
|
53 |
|
54 A11Y_TRYBLOCK_END |
|
55 } |
|
56 |
|
57 STDMETHODIMP |
|
58 ia2AccessibleEditableText::insertText(long aOffset, BSTR *aText) |
|
59 { |
|
60 A11Y_TRYBLOCK_BEGIN |
|
61 |
|
62 HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this); |
|
63 if (textAcc->IsDefunct()) |
|
64 return CO_E_OBJNOTCONNECTED; |
|
65 |
|
66 if (!textAcc->IsValidOffset(aOffset)) |
|
67 return E_INVALIDARG; |
|
68 |
|
69 uint32_t length = ::SysStringLen(*aText); |
|
70 nsAutoString text(*aText, length); |
|
71 |
|
72 textAcc->InsertText(text, aOffset); |
|
73 return S_OK; |
|
74 |
|
75 A11Y_TRYBLOCK_END |
|
76 } |
|
77 |
|
78 STDMETHODIMP |
|
79 ia2AccessibleEditableText::cutText(long aStartOffset, long aEndOffset) |
|
80 { |
|
81 A11Y_TRYBLOCK_BEGIN |
|
82 |
|
83 HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this); |
|
84 if (textAcc->IsDefunct()) |
|
85 return CO_E_OBJNOTCONNECTED; |
|
86 |
|
87 if (!textAcc->IsValidRange(aStartOffset, aEndOffset)) |
|
88 return E_INVALIDARG; |
|
89 |
|
90 textAcc->CutText(aStartOffset, aEndOffset); |
|
91 return S_OK; |
|
92 |
|
93 A11Y_TRYBLOCK_END |
|
94 } |
|
95 |
|
96 STDMETHODIMP |
|
97 ia2AccessibleEditableText::pasteText(long aOffset) |
|
98 { |
|
99 A11Y_TRYBLOCK_BEGIN |
|
100 |
|
101 HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this); |
|
102 if (textAcc->IsDefunct()) |
|
103 return CO_E_OBJNOTCONNECTED; |
|
104 |
|
105 if (!textAcc->IsValidOffset(aOffset)) |
|
106 return E_INVALIDARG; |
|
107 |
|
108 textAcc->PasteText(aOffset); |
|
109 return S_OK; |
|
110 |
|
111 A11Y_TRYBLOCK_END |
|
112 } |
|
113 |
|
114 STDMETHODIMP |
|
115 ia2AccessibleEditableText::replaceText(long aStartOffset, long aEndOffset, |
|
116 BSTR *aText) |
|
117 { |
|
118 A11Y_TRYBLOCK_BEGIN |
|
119 |
|
120 HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this); |
|
121 if (textAcc->IsDefunct()) |
|
122 return CO_E_OBJNOTCONNECTED; |
|
123 |
|
124 if (!textAcc->IsValidRange(aStartOffset, aEndOffset)) |
|
125 return E_INVALIDARG; |
|
126 |
|
127 textAcc->DeleteText(aStartOffset, aEndOffset); |
|
128 |
|
129 uint32_t length = ::SysStringLen(*aText); |
|
130 nsAutoString text(*aText, length); |
|
131 textAcc->InsertText(text, aStartOffset); |
|
132 |
|
133 return S_OK; |
|
134 |
|
135 A11Y_TRYBLOCK_END |
|
136 } |
|
137 |
|
138 STDMETHODIMP |
|
139 ia2AccessibleEditableText::setAttributes(long aStartOffset, long aEndOffset, |
|
140 BSTR *aAttributes) |
|
141 { |
|
142 return E_NOTIMPL; |
|
143 } |