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 #ifndef _ACCESSIBLE_TEXT_H 9 #define _ACCESSIBLE_TEXT_H 10 11 #include "nsIAccessibleText.h" 12 13 #include "AccessibleText.h" 14 15 namespace mozilla { 16 namespace a11y { 17 class HyperTextAccessibleWrap; 18 19 class ia2AccessibleText : public IAccessibleText { 20 public: 21 // IAccessibleText 22 virtual HRESULT STDMETHODCALLTYPE addSelection( 23 /* [in] */ long startOffset, 24 /* [in] */ long endOffset); 25 26 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_attributes( 27 /* [in] */ long offset, 28 /* [out] */ long *startOffset, 29 /* [out] */ long *endOffset, 30 /* [retval][out] */ BSTR *textAttributes); 31 32 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_caretOffset( 33 /* [retval][out] */ long *offset); 34 35 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_characterExtents( 36 /* [in] */ long offset, 37 /* [in] */ enum IA2CoordinateType coordType, 38 /* [out] */ long *x, 39 /* [out] */ long *y, 40 /* [out] */ long *width, 41 /* [retval][out] */ long *height); 42 43 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_nSelections( 44 /* [retval][out] */ long *nSelections); 45 46 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_offsetAtPoint( 47 /* [in] */ long x, 48 /* [in] */ long y, 49 /* [in] */ enum IA2CoordinateType coordType, 50 /* [retval][out] */ long *offset); 51 52 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_selection( 53 /* [in] */ long selectionIndex, 54 /* [out] */ long *startOffset, 55 /* [retval][out] */ long *endOffset); 56 57 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_text( 58 /* [in] */ long startOffset, 59 /* [in] */ long endOffset, 60 /* [retval][out] */ BSTR *text); 61 62 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_textBeforeOffset( 63 /* [in] */ long offset, 64 /* [in] */ enum IA2TextBoundaryType boundaryType, 65 /* [out] */ long *startOffset, 66 /* [out] */ long *endOffset, 67 /* [retval][out] */ BSTR *text); 68 69 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_textAfterOffset( 70 /* [in] */ long offset, 71 /* [in] */ enum IA2TextBoundaryType boundaryType, 72 /* [out] */ long *startOffset, 73 /* [out] */ long *endOffset, 74 /* [retval][out] */ BSTR *text); 75 76 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_textAtOffset( 77 /* [in] */ long offset, 78 /* [in] */ enum IA2TextBoundaryType boundaryType, 79 /* [out] */ long *startOffset, 80 /* [out] */ long *endOffset, 81 /* [retval][out] */ BSTR *text); 82 83 virtual HRESULT STDMETHODCALLTYPE removeSelection( 84 /* [in] */ long selectionIndex); 85 86 virtual HRESULT STDMETHODCALLTYPE setCaretOffset( 87 /* [in] */ long offset); 88 89 virtual HRESULT STDMETHODCALLTYPE setSelection( 90 /* [in] */ long selectionIndex, 91 /* [in] */ long startOffset, 92 /* [in] */ long endOffset); 93 94 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_nCharacters( 95 /* [retval][out] */ long *nCharacters); 96 97 virtual HRESULT STDMETHODCALLTYPE scrollSubstringTo( 98 /* [in] */ long startIndex, 99 /* [in] */ long endIndex, 100 /* [in] */ enum IA2ScrollType scrollType); 101 102 virtual HRESULT STDMETHODCALLTYPE scrollSubstringToPoint( 103 /* [in] */ long startIndex, 104 /* [in] */ long endIndex, 105 /* [in] */ enum IA2CoordinateType coordinateType, 106 /* [in] */ long x, 107 /* [in] */ long y); 108 109 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_newText( 110 /* [retval][out] */ IA2TextSegment *newText); 111 112 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_oldText( 113 /* [retval][out] */ IA2TextSegment *oldText); 114 115 static void InitTextChangeData(); 116 static void UpdateTextChangeData(HyperTextAccessibleWrap *aAcc, bool aInsert, 117 const nsString &aStr, int32_t aStart, 118 uint32_t aLen); 119 120 protected: 121 static StaticRefPtr<HyperTextAccessibleWrap> sLastTextChangeAcc; 122 static StaticAutoPtr<nsString> sLastTextChangeString; 123 static bool sLastTextChangeWasInsert; 124 static uint32_t sLastTextChangeStart; 125 static uint32_t sLastTextChangeEnd; 126 127 private: 128 HRESULT GetModifiedText(bool aGetInsertedText, IA2TextSegment *aNewText); 129 AccessibleTextBoundary GetGeckoTextBoundary( 130 enum IA2TextBoundaryType coordinateType); 131 }; 132 133 } // namespace a11y 134 } // namespace mozilla 135 136 #define FORWARD_IACCESSIBLETEXT(Class) \ 137 virtual HRESULT STDMETHODCALLTYPE addSelection(long startOffset, \ 138 long endOffset) { \ 139 return Class::addSelection(startOffset, endOffset); \ 140 } \ 141 \ 142 virtual HRESULT STDMETHODCALLTYPE get_attributes( \ 143 long offset, long *startOffset, long *endOffset, BSTR *textAttributes) { \ 144 return Class::get_attributes(offset, startOffset, endOffset, \ 145 textAttributes); \ 146 } \ 147 \ 148 virtual HRESULT STDMETHODCALLTYPE get_caretOffset(long *offset) { \ 149 return Class::get_caretOffset(offset); \ 150 } \ 151 \ 152 virtual HRESULT STDMETHODCALLTYPE get_characterExtents( \ 153 long offset, enum IA2CoordinateType coordType, long *x, long *y, \ 154 long *width, long *height) { \ 155 return Class::get_characterExtents(offset, coordType, x, y, width, \ 156 height); \ 157 } \ 158 \ 159 virtual HRESULT STDMETHODCALLTYPE get_nSelections(long *nSelections) { \ 160 return Class::get_nSelections(nSelections); \ 161 } \ 162 \ 163 virtual HRESULT STDMETHODCALLTYPE get_offsetAtPoint( \ 164 long x, long y, enum IA2CoordinateType coordType, long *offset) { \ 165 return Class::get_offsetAtPoint(x, y, coordType, offset); \ 166 } \ 167 \ 168 virtual HRESULT STDMETHODCALLTYPE get_selection( \ 169 long selectionIndex, long *startOffset, long *endOffset) { \ 170 return Class::get_selection(selectionIndex, startOffset, endOffset); \ 171 } \ 172 \ 173 virtual HRESULT STDMETHODCALLTYPE get_text(long startOffset, long endOffset, \ 174 BSTR *text) { \ 175 return Class::get_text(startOffset, endOffset, text); \ 176 } \ 177 \ 178 virtual HRESULT STDMETHODCALLTYPE get_textBeforeOffset( \ 179 long offset, enum IA2TextBoundaryType boundaryType, long *startOffset, \ 180 long *endOffset, BSTR *text) { \ 181 return Class::get_textBeforeOffset(offset, boundaryType, startOffset, \ 182 endOffset, text); \ 183 } \ 184 \ 185 virtual HRESULT STDMETHODCALLTYPE get_textAfterOffset( \ 186 long offset, enum IA2TextBoundaryType boundaryType, long *startOffset, \ 187 long *endOffset, BSTR *text) { \ 188 return Class::get_textAfterOffset(offset, boundaryType, startOffset, \ 189 endOffset, text); \ 190 } \ 191 \ 192 virtual HRESULT STDMETHODCALLTYPE get_textAtOffset( \ 193 long offset, enum IA2TextBoundaryType boundaryType, long *startOffset, \ 194 long *endOffset, BSTR *text) { \ 195 return Class::get_textAtOffset(offset, boundaryType, startOffset, \ 196 endOffset, text); \ 197 } \ 198 \ 199 virtual HRESULT STDMETHODCALLTYPE removeSelection(long selectionIndex) { \ 200 return Class::removeSelection(selectionIndex); \ 201 } \ 202 \ 203 virtual HRESULT STDMETHODCALLTYPE setCaretOffset(long offset) { \ 204 return Class::setCaretOffset(offset); \ 205 } \ 206 \ 207 virtual HRESULT STDMETHODCALLTYPE setSelection( \ 208 long selectionIndex, long startOffset, long endOffset) { \ 209 return Class::setSelection(selectionIndex, startOffset, endOffset); \ 210 } \ 211 \ 212 virtual HRESULT STDMETHODCALLTYPE get_nCharacters(long *nCharacters) { \ 213 return Class::get_nCharacters(nCharacters); \ 214 } \ 215 \ 216 virtual HRESULT STDMETHODCALLTYPE scrollSubstringTo( \ 217 long startIndex, long endIndex, enum IA2ScrollType scrollType) { \ 218 return Class::scrollSubstringTo(startIndex, endIndex, scrollType); \ 219 } \ 220 \ 221 virtual HRESULT STDMETHODCALLTYPE scrollSubstringToPoint( \ 222 long startIndex, long endIndex, enum IA2CoordinateType coordinateType, \ 223 long x, long y) { \ 224 return Class::scrollSubstringToPoint(startIndex, endIndex, coordinateType, \ 225 x, y); \ 226 } \ 227 \ 228 virtual HRESULT STDMETHODCALLTYPE get_newText(IA2TextSegment *newText) { \ 229 return Class::get_newText(newText); \ 230 } \ 231 \ 232 virtual HRESULT STDMETHODCALLTYPE get_oldText(IA2TextSegment *oldText) { \ 233 return Class::get_oldText(oldText); \ 234 } 235 236 #endif 237