Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "InterfaceInitFuncs.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "Accessible-inl.h" |
michael@0 | 10 | #include "HyperTextAccessible-inl.h" |
michael@0 | 11 | #include "nsMai.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "nsIAccessibleTypes.h" |
michael@0 | 14 | #include "nsIPersistentProperties2.h" |
michael@0 | 15 | #include "nsISimpleEnumerator.h" |
michael@0 | 16 | |
michael@0 | 17 | #include "mozilla/Likely.h" |
michael@0 | 18 | |
michael@0 | 19 | using namespace mozilla; |
michael@0 | 20 | using namespace mozilla::a11y; |
michael@0 | 21 | |
michael@0 | 22 | static const char* sAtkTextAttrNames[ATK_TEXT_ATTR_LAST_DEFINED]; |
michael@0 | 23 | |
michael@0 | 24 | static AtkAttributeSet* |
michael@0 | 25 | ConvertToAtkTextAttributeSet(nsIPersistentProperties* aAttributes) |
michael@0 | 26 | { |
michael@0 | 27 | if (!aAttributes) |
michael@0 | 28 | return nullptr; |
michael@0 | 29 | |
michael@0 | 30 | AtkAttributeSet* objAttributeSet = nullptr; |
michael@0 | 31 | nsCOMPtr<nsISimpleEnumerator> propEnum; |
michael@0 | 32 | nsresult rv = aAttributes->Enumerate(getter_AddRefs(propEnum)); |
michael@0 | 33 | NS_ENSURE_SUCCESS(rv, nullptr); |
michael@0 | 34 | |
michael@0 | 35 | bool hasMore = false; |
michael@0 | 36 | while (NS_SUCCEEDED(propEnum->HasMoreElements(&hasMore)) && hasMore) { |
michael@0 | 37 | nsCOMPtr<nsISupports> sup; |
michael@0 | 38 | rv = propEnum->GetNext(getter_AddRefs(sup)); |
michael@0 | 39 | NS_ENSURE_SUCCESS(rv, objAttributeSet); |
michael@0 | 40 | |
michael@0 | 41 | nsCOMPtr<nsIPropertyElement> propElem(do_QueryInterface(sup)); |
michael@0 | 42 | NS_ENSURE_TRUE(propElem, objAttributeSet); |
michael@0 | 43 | |
michael@0 | 44 | nsAutoCString name; |
michael@0 | 45 | rv = propElem->GetKey(name); |
michael@0 | 46 | NS_ENSURE_SUCCESS(rv, objAttributeSet); |
michael@0 | 47 | |
michael@0 | 48 | nsAutoString value; |
michael@0 | 49 | rv = propElem->GetValue(value); |
michael@0 | 50 | NS_ENSURE_SUCCESS(rv, objAttributeSet); |
michael@0 | 51 | |
michael@0 | 52 | AtkAttribute* objAttr = (AtkAttribute*)g_malloc(sizeof(AtkAttribute)); |
michael@0 | 53 | objAttr->name = g_strdup(name.get()); |
michael@0 | 54 | objAttr->value = g_strdup(NS_ConvertUTF16toUTF8(value).get()); |
michael@0 | 55 | objAttributeSet = g_slist_prepend(objAttributeSet, objAttr); |
michael@0 | 56 | |
michael@0 | 57 | // Handle attributes where atk has its own name. |
michael@0 | 58 | const char* atkName = nullptr; |
michael@0 | 59 | nsAutoString atkValue; |
michael@0 | 60 | if (name.EqualsLiteral("color")) { |
michael@0 | 61 | // The format of the atk attribute is r,g,b and the gecko one is |
michael@0 | 62 | // rgb(r,g,b). |
michael@0 | 63 | atkValue = Substring(value, 5, value.Length() - 1); |
michael@0 | 64 | atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_FG_COLOR]; |
michael@0 | 65 | } else if (name.EqualsLiteral("background-color")) { |
michael@0 | 66 | // The format of the atk attribute is r,g,b and the gecko one is |
michael@0 | 67 | // rgb(r,g,b). |
michael@0 | 68 | atkValue = Substring(value, 5, value.Length() - 1); |
michael@0 | 69 | atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_BG_COLOR]; |
michael@0 | 70 | } else if (name.EqualsLiteral("font-family")) { |
michael@0 | 71 | atkValue = value; |
michael@0 | 72 | atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_FAMILY_NAME]; |
michael@0 | 73 | } else if (name.Equals("font-size")) { |
michael@0 | 74 | // ATK wants the number of pixels without px at the end. |
michael@0 | 75 | atkValue = StringHead(value, value.Length() - 2); |
michael@0 | 76 | atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_SIZE]; |
michael@0 | 77 | } else if (name.EqualsLiteral("font-weight")) { |
michael@0 | 78 | atkValue = value; |
michael@0 | 79 | atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_WEIGHT]; |
michael@0 | 80 | } else if (name.EqualsLiteral("invalid")) { |
michael@0 | 81 | atkValue = value; |
michael@0 | 82 | atkName = sAtkTextAttrNames[ATK_TEXT_ATTR_INVALID]; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | if (atkName) { |
michael@0 | 86 | objAttr = static_cast<AtkAttribute*>(g_malloc(sizeof(AtkAttribute))); |
michael@0 | 87 | objAttr->name = g_strdup(atkName); |
michael@0 | 88 | objAttr->value = g_strdup(NS_ConvertUTF16toUTF8(atkValue).get()); |
michael@0 | 89 | objAttributeSet = g_slist_prepend(objAttributeSet, objAttr); |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | // libatk-adaptor will free it |
michael@0 | 94 | return objAttributeSet; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | static void |
michael@0 | 98 | ConvertTexttoAsterisks(AccessibleWrap* accWrap, nsAString& aString) |
michael@0 | 99 | { |
michael@0 | 100 | // convert each char to "*" when it's "password text" |
michael@0 | 101 | if (accWrap->NativeRole() == roles::PASSWORD_TEXT) { |
michael@0 | 102 | for (uint32_t i = 0; i < aString.Length(); i++) |
michael@0 | 103 | aString.Replace(i, 1, NS_LITERAL_STRING("*")); |
michael@0 | 104 | } |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | extern "C" { |
michael@0 | 108 | |
michael@0 | 109 | static gchar* |
michael@0 | 110 | getTextCB(AtkText *aText, gint aStartOffset, gint aEndOffset) |
michael@0 | 111 | { |
michael@0 | 112 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 113 | if (!accWrap) |
michael@0 | 114 | return nullptr; |
michael@0 | 115 | |
michael@0 | 116 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 117 | if (!text || !text->IsTextRole()) |
michael@0 | 118 | return nullptr; |
michael@0 | 119 | |
michael@0 | 120 | nsAutoString autoStr; |
michael@0 | 121 | text->TextSubstring(aStartOffset, aEndOffset, autoStr); |
michael@0 | 122 | |
michael@0 | 123 | ConvertTexttoAsterisks(accWrap, autoStr); |
michael@0 | 124 | NS_ConvertUTF16toUTF8 cautoStr(autoStr); |
michael@0 | 125 | |
michael@0 | 126 | //copy and return, libspi will free it. |
michael@0 | 127 | return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | static gchar* |
michael@0 | 131 | getTextAfterOffsetCB(AtkText *aText, gint aOffset, |
michael@0 | 132 | AtkTextBoundary aBoundaryType, |
michael@0 | 133 | gint *aStartOffset, gint *aEndOffset) |
michael@0 | 134 | { |
michael@0 | 135 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 136 | if (!accWrap) |
michael@0 | 137 | return nullptr; |
michael@0 | 138 | |
michael@0 | 139 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 140 | if (!text || !text->IsTextRole()) |
michael@0 | 141 | return nullptr; |
michael@0 | 142 | |
michael@0 | 143 | nsAutoString autoStr; |
michael@0 | 144 | int32_t startOffset = 0, endOffset = 0; |
michael@0 | 145 | text->TextAfterOffset(aOffset, aBoundaryType, &startOffset, &endOffset, autoStr); |
michael@0 | 146 | |
michael@0 | 147 | *aStartOffset = startOffset; |
michael@0 | 148 | *aEndOffset = endOffset; |
michael@0 | 149 | |
michael@0 | 150 | ConvertTexttoAsterisks(accWrap, autoStr); |
michael@0 | 151 | NS_ConvertUTF16toUTF8 cautoStr(autoStr); |
michael@0 | 152 | return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr; |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | static gchar* |
michael@0 | 156 | getTextAtOffsetCB(AtkText *aText, gint aOffset, |
michael@0 | 157 | AtkTextBoundary aBoundaryType, |
michael@0 | 158 | gint *aStartOffset, gint *aEndOffset) |
michael@0 | 159 | { |
michael@0 | 160 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 161 | if (!accWrap) |
michael@0 | 162 | return nullptr; |
michael@0 | 163 | |
michael@0 | 164 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 165 | if (!text || !text->IsTextRole()) |
michael@0 | 166 | return nullptr; |
michael@0 | 167 | |
michael@0 | 168 | nsAutoString autoStr; |
michael@0 | 169 | int32_t startOffset = 0, endOffset = 0; |
michael@0 | 170 | text->TextAtOffset(aOffset, aBoundaryType, &startOffset, &endOffset, autoStr); |
michael@0 | 171 | *aStartOffset = startOffset; |
michael@0 | 172 | *aEndOffset = endOffset; |
michael@0 | 173 | |
michael@0 | 174 | ConvertTexttoAsterisks(accWrap, autoStr); |
michael@0 | 175 | NS_ConvertUTF16toUTF8 cautoStr(autoStr); |
michael@0 | 176 | return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr; |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | static gunichar |
michael@0 | 180 | getCharacterAtOffsetCB(AtkText* aText, gint aOffset) |
michael@0 | 181 | { |
michael@0 | 182 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 183 | if (!accWrap) |
michael@0 | 184 | return 0; |
michael@0 | 185 | |
michael@0 | 186 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 187 | if (!text || !text->IsTextRole()) |
michael@0 | 188 | return 0; |
michael@0 | 189 | |
michael@0 | 190 | // char16_t is unsigned short in Mozilla, gnuichar is guint32 in glib. |
michael@0 | 191 | return static_cast<gunichar>(text->CharAt(aOffset)); |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | static gchar* |
michael@0 | 195 | getTextBeforeOffsetCB(AtkText *aText, gint aOffset, |
michael@0 | 196 | AtkTextBoundary aBoundaryType, |
michael@0 | 197 | gint *aStartOffset, gint *aEndOffset) |
michael@0 | 198 | { |
michael@0 | 199 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 200 | if (!accWrap) |
michael@0 | 201 | return nullptr; |
michael@0 | 202 | |
michael@0 | 203 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 204 | if (!text || !text->IsTextRole()) |
michael@0 | 205 | return nullptr; |
michael@0 | 206 | |
michael@0 | 207 | nsAutoString autoStr; |
michael@0 | 208 | int32_t startOffset = 0, endOffset = 0; |
michael@0 | 209 | text->TextBeforeOffset(aOffset, aBoundaryType, |
michael@0 | 210 | &startOffset, &endOffset, autoStr); |
michael@0 | 211 | *aStartOffset = startOffset; |
michael@0 | 212 | *aEndOffset = endOffset; |
michael@0 | 213 | |
michael@0 | 214 | ConvertTexttoAsterisks(accWrap, autoStr); |
michael@0 | 215 | NS_ConvertUTF16toUTF8 cautoStr(autoStr); |
michael@0 | 216 | return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr; |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | static gint |
michael@0 | 220 | getCaretOffsetCB(AtkText *aText) |
michael@0 | 221 | { |
michael@0 | 222 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 223 | if (!accWrap) |
michael@0 | 224 | return 0; |
michael@0 | 225 | |
michael@0 | 226 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 227 | if (!text || !text->IsTextRole()) |
michael@0 | 228 | return 0; |
michael@0 | 229 | |
michael@0 | 230 | return static_cast<gint>(text->CaretOffset()); |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | static AtkAttributeSet* |
michael@0 | 234 | getRunAttributesCB(AtkText *aText, gint aOffset, |
michael@0 | 235 | gint *aStartOffset, |
michael@0 | 236 | gint *aEndOffset) |
michael@0 | 237 | { |
michael@0 | 238 | *aStartOffset = -1; |
michael@0 | 239 | *aEndOffset = -1; |
michael@0 | 240 | |
michael@0 | 241 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 242 | if (!accWrap) |
michael@0 | 243 | return nullptr; |
michael@0 | 244 | |
michael@0 | 245 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 246 | if (!text || !text->IsTextRole()) |
michael@0 | 247 | return nullptr; |
michael@0 | 248 | |
michael@0 | 249 | int32_t startOffset = 0, endOffset = 0; |
michael@0 | 250 | nsCOMPtr<nsIPersistentProperties> attributes = |
michael@0 | 251 | text->TextAttributes(false, aOffset, &startOffset, &endOffset); |
michael@0 | 252 | |
michael@0 | 253 | *aStartOffset = startOffset; |
michael@0 | 254 | *aEndOffset = endOffset; |
michael@0 | 255 | |
michael@0 | 256 | return ConvertToAtkTextAttributeSet(attributes); |
michael@0 | 257 | } |
michael@0 | 258 | |
michael@0 | 259 | static AtkAttributeSet* |
michael@0 | 260 | getDefaultAttributesCB(AtkText *aText) |
michael@0 | 261 | { |
michael@0 | 262 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 263 | if (!accWrap) |
michael@0 | 264 | return nullptr; |
michael@0 | 265 | |
michael@0 | 266 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 267 | if (!text || !text->IsTextRole()) |
michael@0 | 268 | return nullptr; |
michael@0 | 269 | |
michael@0 | 270 | nsCOMPtr<nsIPersistentProperties> attributes = text->DefaultTextAttributes(); |
michael@0 | 271 | return ConvertToAtkTextAttributeSet(attributes); |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | static void |
michael@0 | 275 | getCharacterExtentsCB(AtkText *aText, gint aOffset, |
michael@0 | 276 | gint *aX, gint *aY, |
michael@0 | 277 | gint *aWidth, gint *aHeight, |
michael@0 | 278 | AtkCoordType aCoords) |
michael@0 | 279 | { |
michael@0 | 280 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 281 | if(!accWrap || !aX || !aY || !aWidth || !aHeight) |
michael@0 | 282 | return; |
michael@0 | 283 | |
michael@0 | 284 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 285 | if (!text || !text->IsTextRole()) |
michael@0 | 286 | return; |
michael@0 | 287 | |
michael@0 | 288 | uint32_t geckoCoordType; |
michael@0 | 289 | if (aCoords == ATK_XY_SCREEN) |
michael@0 | 290 | geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE; |
michael@0 | 291 | else |
michael@0 | 292 | geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE; |
michael@0 | 293 | |
michael@0 | 294 | nsIntRect rect = text->CharBounds(aOffset, geckoCoordType); |
michael@0 | 295 | *aX = rect.x; |
michael@0 | 296 | *aY = rect.y; |
michael@0 | 297 | *aWidth = rect.width; |
michael@0 | 298 | *aHeight = rect.height; |
michael@0 | 299 | } |
michael@0 | 300 | |
michael@0 | 301 | static void |
michael@0 | 302 | getRangeExtentsCB(AtkText *aText, gint aStartOffset, gint aEndOffset, |
michael@0 | 303 | AtkCoordType aCoords, AtkTextRectangle *aRect) |
michael@0 | 304 | { |
michael@0 | 305 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 306 | if(!accWrap || !aRect) |
michael@0 | 307 | return; |
michael@0 | 308 | |
michael@0 | 309 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 310 | if (!text || !text->IsTextRole()) |
michael@0 | 311 | return; |
michael@0 | 312 | |
michael@0 | 313 | uint32_t geckoCoordType; |
michael@0 | 314 | if (aCoords == ATK_XY_SCREEN) |
michael@0 | 315 | geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE; |
michael@0 | 316 | else |
michael@0 | 317 | geckoCoordType = nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE; |
michael@0 | 318 | |
michael@0 | 319 | nsIntRect rect = text->TextBounds(aStartOffset, aEndOffset, geckoCoordType); |
michael@0 | 320 | aRect->x = rect.x; |
michael@0 | 321 | aRect->y = rect.y; |
michael@0 | 322 | aRect->width = rect.width; |
michael@0 | 323 | aRect->height = rect.height; |
michael@0 | 324 | } |
michael@0 | 325 | |
michael@0 | 326 | static gint |
michael@0 | 327 | getCharacterCountCB(AtkText *aText) |
michael@0 | 328 | { |
michael@0 | 329 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 330 | if (!accWrap) |
michael@0 | 331 | return 0; |
michael@0 | 332 | |
michael@0 | 333 | HyperTextAccessible* textAcc = accWrap->AsHyperText(); |
michael@0 | 334 | return textAcc->IsDefunct() ? |
michael@0 | 335 | 0 : static_cast<gint>(textAcc->CharacterCount()); |
michael@0 | 336 | } |
michael@0 | 337 | |
michael@0 | 338 | static gint |
michael@0 | 339 | getOffsetAtPointCB(AtkText *aText, |
michael@0 | 340 | gint aX, gint aY, |
michael@0 | 341 | AtkCoordType aCoords) |
michael@0 | 342 | { |
michael@0 | 343 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 344 | if (!accWrap) |
michael@0 | 345 | return -1; |
michael@0 | 346 | |
michael@0 | 347 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 348 | if (!text || !text->IsTextRole()) |
michael@0 | 349 | return -1; |
michael@0 | 350 | |
michael@0 | 351 | return static_cast<gint>( |
michael@0 | 352 | text->OffsetAtPoint(aX, aY, |
michael@0 | 353 | (aCoords == ATK_XY_SCREEN ? |
michael@0 | 354 | nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE : |
michael@0 | 355 | nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE))); |
michael@0 | 356 | } |
michael@0 | 357 | |
michael@0 | 358 | static gint |
michael@0 | 359 | getTextSelectionCountCB(AtkText *aText) |
michael@0 | 360 | { |
michael@0 | 361 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 362 | if (!accWrap) |
michael@0 | 363 | return 0; |
michael@0 | 364 | |
michael@0 | 365 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 366 | if (!text || !text->IsTextRole()) |
michael@0 | 367 | return 0; |
michael@0 | 368 | |
michael@0 | 369 | return text->SelectionCount(); |
michael@0 | 370 | } |
michael@0 | 371 | |
michael@0 | 372 | static gchar* |
michael@0 | 373 | getTextSelectionCB(AtkText *aText, gint aSelectionNum, |
michael@0 | 374 | gint *aStartOffset, gint *aEndOffset) |
michael@0 | 375 | { |
michael@0 | 376 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 377 | if (!accWrap) |
michael@0 | 378 | return nullptr; |
michael@0 | 379 | |
michael@0 | 380 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 381 | if (!text || !text->IsTextRole()) |
michael@0 | 382 | return nullptr; |
michael@0 | 383 | |
michael@0 | 384 | int32_t startOffset = 0, endOffset = 0; |
michael@0 | 385 | text->SelectionBoundsAt(aSelectionNum, &startOffset, &endOffset); |
michael@0 | 386 | |
michael@0 | 387 | *aStartOffset = startOffset; |
michael@0 | 388 | *aEndOffset = endOffset; |
michael@0 | 389 | |
michael@0 | 390 | return getTextCB(aText, *aStartOffset, *aEndOffset); |
michael@0 | 391 | } |
michael@0 | 392 | |
michael@0 | 393 | // set methods |
michael@0 | 394 | static gboolean |
michael@0 | 395 | addTextSelectionCB(AtkText *aText, |
michael@0 | 396 | gint aStartOffset, |
michael@0 | 397 | gint aEndOffset) |
michael@0 | 398 | { |
michael@0 | 399 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 400 | if (!accWrap) |
michael@0 | 401 | return FALSE; |
michael@0 | 402 | |
michael@0 | 403 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 404 | if (!text || !text->IsTextRole()) |
michael@0 | 405 | return FALSE; |
michael@0 | 406 | |
michael@0 | 407 | return text->AddToSelection(aStartOffset, aEndOffset); |
michael@0 | 408 | } |
michael@0 | 409 | |
michael@0 | 410 | static gboolean |
michael@0 | 411 | removeTextSelectionCB(AtkText *aText, |
michael@0 | 412 | gint aSelectionNum) |
michael@0 | 413 | { |
michael@0 | 414 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 415 | if (!accWrap) |
michael@0 | 416 | return FALSE; |
michael@0 | 417 | |
michael@0 | 418 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 419 | if (!text || !text->IsTextRole()) |
michael@0 | 420 | return FALSE; |
michael@0 | 421 | |
michael@0 | 422 | return text->RemoveFromSelection(aSelectionNum); |
michael@0 | 423 | } |
michael@0 | 424 | |
michael@0 | 425 | static gboolean |
michael@0 | 426 | setTextSelectionCB(AtkText *aText, gint aSelectionNum, |
michael@0 | 427 | gint aStartOffset, gint aEndOffset) |
michael@0 | 428 | { |
michael@0 | 429 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 430 | if (!accWrap) |
michael@0 | 431 | return FALSE; |
michael@0 | 432 | |
michael@0 | 433 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 434 | if (!text || !text->IsTextRole()) |
michael@0 | 435 | return FALSE; |
michael@0 | 436 | |
michael@0 | 437 | return text->SetSelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset); |
michael@0 | 438 | } |
michael@0 | 439 | |
michael@0 | 440 | static gboolean |
michael@0 | 441 | setCaretOffsetCB(AtkText *aText, gint aOffset) |
michael@0 | 442 | { |
michael@0 | 443 | AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText)); |
michael@0 | 444 | if (!accWrap) |
michael@0 | 445 | return FALSE; |
michael@0 | 446 | |
michael@0 | 447 | HyperTextAccessible* text = accWrap->AsHyperText(); |
michael@0 | 448 | if (!text || !text->IsTextRole() || !text->IsValidOffset(aOffset)) |
michael@0 | 449 | return FALSE; |
michael@0 | 450 | |
michael@0 | 451 | text->SetCaretOffset(aOffset); |
michael@0 | 452 | return TRUE; |
michael@0 | 453 | } |
michael@0 | 454 | } |
michael@0 | 455 | |
michael@0 | 456 | void |
michael@0 | 457 | textInterfaceInitCB(AtkTextIface* aIface) |
michael@0 | 458 | { |
michael@0 | 459 | NS_ASSERTION(aIface, "Invalid aIface"); |
michael@0 | 460 | if (MOZ_UNLIKELY(!aIface)) |
michael@0 | 461 | return; |
michael@0 | 462 | |
michael@0 | 463 | aIface->get_text = getTextCB; |
michael@0 | 464 | aIface->get_text_after_offset = getTextAfterOffsetCB; |
michael@0 | 465 | aIface->get_text_at_offset = getTextAtOffsetCB; |
michael@0 | 466 | aIface->get_character_at_offset = getCharacterAtOffsetCB; |
michael@0 | 467 | aIface->get_text_before_offset = getTextBeforeOffsetCB; |
michael@0 | 468 | aIface->get_caret_offset = getCaretOffsetCB; |
michael@0 | 469 | aIface->get_run_attributes = getRunAttributesCB; |
michael@0 | 470 | aIface->get_default_attributes = getDefaultAttributesCB; |
michael@0 | 471 | aIface->get_character_extents = getCharacterExtentsCB; |
michael@0 | 472 | aIface->get_range_extents = getRangeExtentsCB; |
michael@0 | 473 | aIface->get_character_count = getCharacterCountCB; |
michael@0 | 474 | aIface->get_offset_at_point = getOffsetAtPointCB; |
michael@0 | 475 | aIface->get_n_selections = getTextSelectionCountCB; |
michael@0 | 476 | aIface->get_selection = getTextSelectionCB; |
michael@0 | 477 | |
michael@0 | 478 | // set methods |
michael@0 | 479 | aIface->add_selection = addTextSelectionCB; |
michael@0 | 480 | aIface->remove_selection = removeTextSelectionCB; |
michael@0 | 481 | aIface->set_selection = setTextSelectionCB; |
michael@0 | 482 | aIface->set_caret_offset = setCaretOffsetCB; |
michael@0 | 483 | |
michael@0 | 484 | // Cache the string values of the atk text attribute names. |
michael@0 | 485 | for (uint32_t i = 0; i < ArrayLength(sAtkTextAttrNames); i++) |
michael@0 | 486 | sAtkTextAttrNames[i] = |
michael@0 | 487 | atk_text_attribute_get_name(static_cast<AtkTextAttribute>(i)); |
michael@0 | 488 | } |