1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/xpcom/xpcAccessibleHyperText.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,618 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "xpcAccessibleHyperText.h" 1.11 + 1.12 +#include "HyperTextAccessible-inl.h" 1.13 +#include "TextRange.h" 1.14 +#include "xpcAccessibleTextRange.h" 1.15 + 1.16 +#include "nsIPersistentProperties2.h" 1.17 +#include "nsIMutableArray.h" 1.18 + 1.19 +using namespace mozilla::a11y; 1.20 + 1.21 +//////////////////////////////////////////////////////////////////////////////// 1.22 +// nsISupports 1.23 + 1.24 +nsresult 1.25 +xpcAccessibleHyperText::QueryInterface(REFNSIID aIID, void** aInstancePtr) 1.26 +{ 1.27 + *aInstancePtr = nullptr; 1.28 + 1.29 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.30 + if (!text->IsTextRole()) 1.31 + return NS_ERROR_NO_INTERFACE; 1.32 + 1.33 + if (aIID.Equals(NS_GET_IID(nsIAccessibleText))) 1.34 + *aInstancePtr = static_cast<nsIAccessibleText*>(text); 1.35 + else if (aIID.Equals(NS_GET_IID(nsIAccessibleEditableText))) 1.36 + *aInstancePtr = static_cast<nsIAccessibleEditableText*>(text); 1.37 + else if (aIID.Equals(NS_GET_IID(nsIAccessibleHyperText))) 1.38 + *aInstancePtr = static_cast<nsIAccessibleHyperText*>(text); 1.39 + else 1.40 + return NS_ERROR_NO_INTERFACE; 1.41 + 1.42 + NS_ADDREF(text); 1.43 + return NS_OK; 1.44 +} 1.45 + 1.46 +//////////////////////////////////////////////////////////////////////////////// 1.47 +// nsIAccessibleText 1.48 + 1.49 +NS_IMETHODIMP 1.50 +xpcAccessibleHyperText::GetCharacterCount(int32_t* aCharacterCount) 1.51 +{ 1.52 + NS_ENSURE_ARG_POINTER(aCharacterCount); 1.53 + *aCharacterCount = 0; 1.54 + 1.55 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.56 + if (text->IsDefunct()) 1.57 + return NS_ERROR_FAILURE; 1.58 + 1.59 + *aCharacterCount = text->CharacterCount(); 1.60 + return NS_OK; 1.61 +} 1.62 + 1.63 +NS_IMETHODIMP 1.64 +xpcAccessibleHyperText::GetText(int32_t aStartOffset, int32_t aEndOffset, 1.65 + nsAString& aText) 1.66 +{ 1.67 + aText.Truncate(); 1.68 + 1.69 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.70 + if (text->IsDefunct()) 1.71 + return NS_ERROR_FAILURE; 1.72 + 1.73 + text->TextSubstring(aStartOffset, aEndOffset, aText); 1.74 + return NS_OK; 1.75 +} 1.76 + 1.77 +NS_IMETHODIMP 1.78 +xpcAccessibleHyperText::GetTextBeforeOffset(int32_t aOffset, 1.79 + AccessibleTextBoundary aBoundaryType, 1.80 + int32_t* aStartOffset, 1.81 + int32_t* aEndOffset, 1.82 + nsAString& aText) 1.83 +{ 1.84 + NS_ENSURE_ARG_POINTER(aStartOffset); 1.85 + NS_ENSURE_ARG_POINTER(aEndOffset); 1.86 + *aStartOffset = *aEndOffset = 0; 1.87 + aText.Truncate(); 1.88 + 1.89 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.90 + if (text->IsDefunct()) 1.91 + return NS_ERROR_FAILURE; 1.92 + 1.93 + text->TextBeforeOffset(aOffset, aBoundaryType, aStartOffset, aEndOffset, aText); 1.94 + return NS_OK; 1.95 +} 1.96 + 1.97 +NS_IMETHODIMP 1.98 +xpcAccessibleHyperText::GetTextAtOffset(int32_t aOffset, 1.99 + AccessibleTextBoundary aBoundaryType, 1.100 + int32_t* aStartOffset, 1.101 + int32_t* aEndOffset, nsAString& aText) 1.102 +{ 1.103 + NS_ENSURE_ARG_POINTER(aStartOffset); 1.104 + NS_ENSURE_ARG_POINTER(aEndOffset); 1.105 + *aStartOffset = *aEndOffset = 0; 1.106 + aText.Truncate(); 1.107 + 1.108 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.109 + if (text->IsDefunct()) 1.110 + return NS_ERROR_FAILURE; 1.111 + 1.112 + text->TextAtOffset(aOffset, aBoundaryType, aStartOffset, aEndOffset, aText); 1.113 + return NS_OK; 1.114 +} 1.115 + 1.116 +NS_IMETHODIMP 1.117 +xpcAccessibleHyperText::GetTextAfterOffset(int32_t aOffset, 1.118 + AccessibleTextBoundary aBoundaryType, 1.119 + int32_t* aStartOffset, 1.120 + int32_t* aEndOffset, nsAString& aText) 1.121 +{ 1.122 + NS_ENSURE_ARG_POINTER(aStartOffset); 1.123 + NS_ENSURE_ARG_POINTER(aEndOffset); 1.124 + *aStartOffset = *aEndOffset = 0; 1.125 + aText.Truncate(); 1.126 + 1.127 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.128 + if (text->IsDefunct()) 1.129 + return NS_ERROR_FAILURE; 1.130 + 1.131 + text->TextAfterOffset(aOffset, aBoundaryType, aStartOffset, aEndOffset, aText); 1.132 + return NS_OK; 1.133 +} 1.134 + 1.135 +NS_IMETHODIMP 1.136 +xpcAccessibleHyperText::GetCharacterAtOffset(int32_t aOffset, 1.137 + char16_t* aCharacter) 1.138 +{ 1.139 + NS_ENSURE_ARG_POINTER(aCharacter); 1.140 + *aCharacter = L'\0'; 1.141 + 1.142 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.143 + if (text->IsDefunct()) 1.144 + return NS_ERROR_FAILURE; 1.145 + 1.146 + *aCharacter = text->CharAt(aOffset); 1.147 + return NS_OK; 1.148 +} 1.149 + 1.150 +NS_IMETHODIMP 1.151 +xpcAccessibleHyperText::GetTextAttributes(bool aIncludeDefAttrs, 1.152 + int32_t aOffset, 1.153 + int32_t* aStartOffset, 1.154 + int32_t* aEndOffset, 1.155 + nsIPersistentProperties** aAttributes) 1.156 +{ 1.157 + NS_ENSURE_ARG_POINTER(aStartOffset); 1.158 + NS_ENSURE_ARG_POINTER(aEndOffset); 1.159 + NS_ENSURE_ARG_POINTER(aAttributes); 1.160 + *aStartOffset = *aEndOffset = 0; 1.161 + *aAttributes = nullptr; 1.162 + 1.163 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.164 + if (text->IsDefunct()) 1.165 + return NS_ERROR_FAILURE; 1.166 + 1.167 + nsCOMPtr<nsIPersistentProperties> attrs = 1.168 + text->TextAttributes(aIncludeDefAttrs, aOffset, aStartOffset, aEndOffset); 1.169 + attrs.swap(*aAttributes); 1.170 + 1.171 + return NS_OK; 1.172 +} 1.173 + 1.174 +NS_IMETHODIMP 1.175 +xpcAccessibleHyperText::GetDefaultTextAttributes(nsIPersistentProperties** aAttributes) 1.176 +{ 1.177 + NS_ENSURE_ARG_POINTER(aAttributes); 1.178 + *aAttributes = nullptr; 1.179 + 1.180 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.181 + if (text->IsDefunct()) 1.182 + return NS_ERROR_FAILURE; 1.183 + 1.184 + nsCOMPtr<nsIPersistentProperties> attrs = text->DefaultTextAttributes(); 1.185 + attrs.swap(*aAttributes); 1.186 + return NS_OK; 1.187 +} 1.188 + 1.189 +NS_IMETHODIMP 1.190 +xpcAccessibleHyperText::GetCharacterExtents(int32_t aOffset, 1.191 + int32_t* aX, int32_t* aY, 1.192 + int32_t* aWidth, int32_t* aHeight, 1.193 + uint32_t aCoordType) 1.194 +{ 1.195 + NS_ENSURE_ARG_POINTER(aX); 1.196 + NS_ENSURE_ARG_POINTER(aY); 1.197 + NS_ENSURE_ARG_POINTER(aWidth); 1.198 + NS_ENSURE_ARG_POINTER(aHeight); 1.199 + *aX = *aY = *aWidth = *aHeight; 1.200 + 1.201 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.202 + if (text->IsDefunct()) 1.203 + return NS_ERROR_FAILURE; 1.204 + 1.205 + nsIntRect rect = text->CharBounds(aOffset, aCoordType); 1.206 + *aX = rect.x; *aY = rect.y; 1.207 + *aWidth = rect.width; *aHeight = rect.height; 1.208 + return NS_OK; 1.209 +} 1.210 + 1.211 +NS_IMETHODIMP 1.212 +xpcAccessibleHyperText::GetRangeExtents(int32_t aStartOffset, int32_t aEndOffset, 1.213 + int32_t* aX, int32_t* aY, 1.214 + int32_t* aWidth, int32_t* aHeight, 1.215 + uint32_t aCoordType) 1.216 +{ 1.217 + NS_ENSURE_ARG_POINTER(aX); 1.218 + NS_ENSURE_ARG_POINTER(aY); 1.219 + NS_ENSURE_ARG_POINTER(aWidth); 1.220 + NS_ENSURE_ARG_POINTER(aHeight); 1.221 + *aX = *aY = *aWidth = *aHeight = 0; 1.222 + 1.223 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.224 + if (text->IsDefunct()) 1.225 + return NS_ERROR_FAILURE; 1.226 + 1.227 + nsIntRect rect = text->TextBounds(aStartOffset, aEndOffset, aCoordType); 1.228 + *aX = rect.x; *aY = rect.y; 1.229 + *aWidth = rect.width; *aHeight = rect.height; 1.230 + return NS_OK; 1.231 +} 1.232 + 1.233 +NS_IMETHODIMP 1.234 +xpcAccessibleHyperText::GetOffsetAtPoint(int32_t aX, int32_t aY, 1.235 + uint32_t aCoordType, int32_t* aOffset) 1.236 +{ 1.237 + NS_ENSURE_ARG_POINTER(aOffset); 1.238 + *aOffset = -1; 1.239 + 1.240 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.241 + if (text->IsDefunct()) 1.242 + return NS_ERROR_FAILURE; 1.243 + 1.244 + *aOffset = text->OffsetAtPoint(aX, aY, aCoordType); 1.245 + return NS_OK; 1.246 +} 1.247 + 1.248 +NS_IMETHODIMP 1.249 +xpcAccessibleHyperText::GetScriptableCaretOffset(int32_t* aCaretOffset) 1.250 +{ 1.251 + NS_ENSURE_ARG_POINTER(aCaretOffset); 1.252 + *aCaretOffset = -1; 1.253 + 1.254 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.255 + if (text->IsDefunct()) 1.256 + return NS_ERROR_FAILURE; 1.257 + 1.258 + *aCaretOffset = text->CaretOffset(); 1.259 + return NS_OK; 1.260 +} 1.261 + 1.262 +NS_IMETHODIMP 1.263 +xpcAccessibleHyperText::SetScriptableCaretOffset(int32_t aCaretOffset) 1.264 +{ 1.265 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.266 + if (text->IsDefunct()) 1.267 + return NS_ERROR_FAILURE; 1.268 + 1.269 + text->SetCaretOffset(aCaretOffset); 1.270 + return NS_OK; 1.271 +} 1.272 + 1.273 +NS_IMETHODIMP 1.274 +xpcAccessibleHyperText::GetSelectionCount(int32_t* aSelectionCount) 1.275 +{ 1.276 + NS_ENSURE_ARG_POINTER(aSelectionCount); 1.277 + *aSelectionCount = 0; 1.278 + 1.279 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.280 + if (text->IsDefunct()) 1.281 + return NS_ERROR_FAILURE; 1.282 + 1.283 + *aSelectionCount = text->SelectionCount(); 1.284 + return NS_OK; 1.285 +} 1.286 + 1.287 +NS_IMETHODIMP 1.288 +xpcAccessibleHyperText::GetSelectionBounds(int32_t aSelectionNum, 1.289 + int32_t* aStartOffset, 1.290 + int32_t* aEndOffset) 1.291 +{ 1.292 + NS_ENSURE_ARG_POINTER(aStartOffset); 1.293 + NS_ENSURE_ARG_POINTER(aEndOffset); 1.294 + *aStartOffset = *aEndOffset = 0; 1.295 + 1.296 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.297 + if (text->IsDefunct()) 1.298 + return NS_ERROR_FAILURE; 1.299 + 1.300 + if (aSelectionNum < 0 || aSelectionNum >= text->SelectionCount()) 1.301 + return NS_ERROR_INVALID_ARG; 1.302 + 1.303 + text->SelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset); 1.304 + return NS_OK; 1.305 +} 1.306 + 1.307 +NS_IMETHODIMP 1.308 +xpcAccessibleHyperText::SetSelectionBounds(int32_t aSelectionNum, 1.309 + int32_t aStartOffset, 1.310 + int32_t aEndOffset) 1.311 +{ 1.312 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.313 + if (text->IsDefunct()) 1.314 + return NS_ERROR_FAILURE; 1.315 + 1.316 + if (aSelectionNum < 0 || 1.317 + !text->SetSelectionBoundsAt(aSelectionNum, aStartOffset, aEndOffset)) 1.318 + return NS_ERROR_INVALID_ARG; 1.319 + 1.320 + return NS_OK; 1.321 +} 1.322 + 1.323 +NS_IMETHODIMP 1.324 +xpcAccessibleHyperText::AddSelection(int32_t aStartOffset, int32_t aEndOffset) 1.325 +{ 1.326 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.327 + if (text->IsDefunct()) 1.328 + return NS_ERROR_FAILURE; 1.329 + 1.330 + text->AddToSelection(aStartOffset, aEndOffset); 1.331 + return NS_OK; 1.332 +} 1.333 + 1.334 +NS_IMETHODIMP 1.335 +xpcAccessibleHyperText::RemoveSelection(int32_t aSelectionNum) 1.336 +{ 1.337 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.338 + if (text->IsDefunct()) 1.339 + return NS_ERROR_FAILURE; 1.340 + 1.341 + text->RemoveFromSelection(aSelectionNum); 1.342 + return NS_OK; 1.343 +} 1.344 + 1.345 +NS_IMETHODIMP 1.346 +xpcAccessibleHyperText::ScriptableScrollSubstringTo(int32_t aStartOffset, 1.347 + int32_t aEndOffset, 1.348 + uint32_t aScrollType) 1.349 +{ 1.350 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.351 + if (text->IsDefunct()) 1.352 + return NS_ERROR_FAILURE; 1.353 + 1.354 + text->ScrollSubstringTo(aStartOffset, aEndOffset, aScrollType); 1.355 + return NS_OK; 1.356 +} 1.357 + 1.358 +NS_IMETHODIMP 1.359 +xpcAccessibleHyperText::ScriptableScrollSubstringToPoint(int32_t aStartOffset, 1.360 + int32_t aEndOffset, 1.361 + uint32_t aCoordinateType, 1.362 + int32_t aX, int32_t aY) 1.363 +{ 1.364 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.365 + if (text->IsDefunct()) 1.366 + return NS_ERROR_FAILURE; 1.367 + 1.368 + text->ScrollSubstringToPoint(aStartOffset, aEndOffset, aCoordinateType, aX, aY); 1.369 + return NS_OK; 1.370 +} 1.371 + 1.372 +NS_IMETHODIMP 1.373 +xpcAccessibleHyperText::GetEnclosingRange(nsIAccessibleTextRange** aRange) 1.374 +{ 1.375 + NS_ENSURE_ARG_POINTER(aRange); 1.376 + *aRange = nullptr; 1.377 + 1.378 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.379 + if (text->IsDefunct()) 1.380 + return NS_ERROR_FAILURE; 1.381 + 1.382 + nsRefPtr<xpcAccessibleTextRange> range = new xpcAccessibleTextRange; 1.383 + text->EnclosingRange(range->mRange); 1.384 + NS_ASSERTION(range->mRange.IsValid(), 1.385 + "Should always have an enclosing range!"); 1.386 + 1.387 + range.forget(aRange); 1.388 + 1.389 + return NS_OK; 1.390 +} 1.391 + 1.392 +NS_IMETHODIMP 1.393 +xpcAccessibleHyperText::GetSelectionRanges(nsIArray** aRanges) 1.394 +{ 1.395 + NS_ENSURE_ARG_POINTER(aRanges); 1.396 + *aRanges = nullptr; 1.397 + 1.398 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.399 + if (text->IsDefunct()) 1.400 + return NS_ERROR_FAILURE; 1.401 + 1.402 + nsresult rv = NS_OK; 1.403 + nsCOMPtr<nsIMutableArray> xpcRanges = 1.404 + do_CreateInstance(NS_ARRAY_CONTRACTID, &rv); 1.405 + NS_ENSURE_SUCCESS(rv, rv); 1.406 + 1.407 + nsAutoTArray<TextRange, 1> ranges; 1.408 + text->SelectionRanges(&ranges); 1.409 + uint32_t len = ranges.Length(); 1.410 + for (uint32_t idx = 0; idx < len; idx++) 1.411 + xpcRanges->AppendElement(new xpcAccessibleTextRange(Move(ranges[idx])), 1.412 + false); 1.413 + 1.414 + xpcRanges.forget(aRanges); 1.415 + return NS_OK; 1.416 +} 1.417 + 1.418 +NS_IMETHODIMP 1.419 +xpcAccessibleHyperText::GetVisibleRanges(nsIArray** aRanges) 1.420 +{ 1.421 + NS_ENSURE_ARG_POINTER(aRanges); 1.422 + *aRanges = nullptr; 1.423 + 1.424 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.425 + if (text->IsDefunct()) 1.426 + return NS_ERROR_FAILURE; 1.427 + 1.428 + nsresult rv = NS_OK; 1.429 + nsCOMPtr<nsIMutableArray> xpcRanges = 1.430 + do_CreateInstance(NS_ARRAY_CONTRACTID, &rv); 1.431 + NS_ENSURE_SUCCESS(rv, rv); 1.432 + 1.433 + nsTArray<TextRange> ranges; 1.434 + text->VisibleRanges(&ranges); 1.435 + uint32_t len = ranges.Length(); 1.436 + for (uint32_t idx = 0; idx < len; idx++) 1.437 + xpcRanges->AppendElement(new xpcAccessibleTextRange(Move(ranges[idx])), 1.438 + false); 1.439 + 1.440 + xpcRanges.forget(aRanges); 1.441 + return NS_OK; 1.442 +} 1.443 + 1.444 +NS_IMETHODIMP 1.445 +xpcAccessibleHyperText::GetRangeByChild(nsIAccessible* aChild, 1.446 + nsIAccessibleTextRange** aRange) 1.447 +{ 1.448 + NS_ENSURE_ARG_POINTER(aRange); 1.449 + *aRange = nullptr; 1.450 + 1.451 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.452 + if (text->IsDefunct()) 1.453 + return NS_ERROR_FAILURE; 1.454 + 1.455 + nsRefPtr<Accessible> child = do_QueryObject(aChild); 1.456 + if (child) { 1.457 + nsRefPtr<xpcAccessibleTextRange> range = new xpcAccessibleTextRange; 1.458 + text->RangeByChild(child, range->mRange); 1.459 + if (range->mRange.IsValid()) 1.460 + range.forget(aRange); 1.461 + } 1.462 + 1.463 + return NS_OK; 1.464 +} 1.465 + 1.466 +NS_IMETHODIMP 1.467 +xpcAccessibleHyperText::GetRangeAtPoint(int32_t aX, int32_t aY, 1.468 + nsIAccessibleTextRange** aRange) 1.469 +{ 1.470 + NS_ENSURE_ARG_POINTER(aRange); 1.471 + *aRange = nullptr; 1.472 + 1.473 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.474 + if (text->IsDefunct()) 1.475 + return NS_ERROR_FAILURE; 1.476 + 1.477 + nsRefPtr<xpcAccessibleTextRange> range = new xpcAccessibleTextRange; 1.478 + text->RangeAtPoint(aX, aY, range->mRange); 1.479 + if (range->mRange.IsValid()) 1.480 + range.forget(aRange); 1.481 + 1.482 + return NS_OK; 1.483 +} 1.484 + 1.485 +//////////////////////////////////////////////////////////////////////////////// 1.486 +// nsIAccessibleEditableText 1.487 + 1.488 +NS_IMETHODIMP 1.489 +xpcAccessibleHyperText::SetTextContents(const nsAString& aText) 1.490 +{ 1.491 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.492 + if (text->IsDefunct()) 1.493 + return NS_ERROR_FAILURE; 1.494 + 1.495 + text->ReplaceText(aText); 1.496 + return NS_OK; 1.497 +} 1.498 + 1.499 +NS_IMETHODIMP 1.500 +xpcAccessibleHyperText::ScriptableInsertText(const nsAString& aText, 1.501 + int32_t aOffset) 1.502 +{ 1.503 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.504 + if (text->IsDefunct()) 1.505 + return NS_ERROR_FAILURE; 1.506 + 1.507 + text->InsertText(aText, aOffset); 1.508 + return NS_OK; 1.509 +} 1.510 + 1.511 +NS_IMETHODIMP 1.512 +xpcAccessibleHyperText::ScriptableCopyText(int32_t aStartOffset, 1.513 + int32_t aEndOffset) 1.514 +{ 1.515 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.516 + if (text->IsDefunct()) 1.517 + return NS_ERROR_FAILURE; 1.518 + 1.519 + text->CopyText(aStartOffset, aEndOffset); 1.520 + return NS_OK; 1.521 +} 1.522 + 1.523 +NS_IMETHODIMP 1.524 +xpcAccessibleHyperText::ScriptableCutText(int32_t aStartOffset, 1.525 + int32_t aEndOffset) 1.526 +{ 1.527 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.528 + if (text->IsDefunct()) 1.529 + return NS_ERROR_FAILURE; 1.530 + 1.531 + text->CutText(aStartOffset, aEndOffset); 1.532 + return NS_OK; 1.533 +} 1.534 + 1.535 +NS_IMETHODIMP 1.536 +xpcAccessibleHyperText::ScriptableDeleteText(int32_t aStartOffset, 1.537 + int32_t aEndOffset) 1.538 +{ 1.539 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.540 + if (text->IsDefunct()) 1.541 + return NS_ERROR_FAILURE; 1.542 + 1.543 + text->DeleteText(aStartOffset, aEndOffset); 1.544 + return NS_OK; 1.545 +} 1.546 + 1.547 +NS_IMETHODIMP 1.548 +xpcAccessibleHyperText::ScriptablePasteText(int32_t aOffset) 1.549 +{ 1.550 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.551 + if (text->IsDefunct()) 1.552 + return NS_ERROR_FAILURE; 1.553 + 1.554 + text->PasteText(aOffset); 1.555 + return NS_OK; 1.556 +} 1.557 + 1.558 +//////////////////////////////////////////////////////////////////////////////// 1.559 +// nsIAccessibleHyperText 1.560 + 1.561 +NS_IMETHODIMP 1.562 +xpcAccessibleHyperText::GetLinkCount(int32_t* aLinkCount) 1.563 +{ 1.564 + NS_ENSURE_ARG_POINTER(aLinkCount); 1.565 + *aLinkCount = 0; 1.566 + 1.567 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.568 + if (text->IsDefunct()) 1.569 + return NS_ERROR_FAILURE; 1.570 + 1.571 + *aLinkCount = text->LinkCount(); 1.572 + return NS_OK; 1.573 +} 1.574 + 1.575 +NS_IMETHODIMP 1.576 +xpcAccessibleHyperText::GetLinkAt(int32_t aIndex, nsIAccessibleHyperLink** aLink) 1.577 +{ 1.578 + NS_ENSURE_ARG_POINTER(aLink); 1.579 + *aLink = nullptr; 1.580 + 1.581 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.582 + if (text->IsDefunct()) 1.583 + return NS_ERROR_FAILURE; 1.584 + 1.585 + nsCOMPtr<nsIAccessibleHyperLink> link = text->LinkAt(aIndex); 1.586 + link.forget(aLink); 1.587 + 1.588 + return NS_OK; 1.589 +} 1.590 + 1.591 +NS_IMETHODIMP 1.592 +xpcAccessibleHyperText::GetLinkIndex(nsIAccessibleHyperLink* aLink, 1.593 + int32_t* aIndex) 1.594 +{ 1.595 + NS_ENSURE_ARG_POINTER(aLink); 1.596 + NS_ENSURE_ARG_POINTER(aIndex); 1.597 + *aIndex = -1; 1.598 + 1.599 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.600 + if (text->IsDefunct()) 1.601 + return NS_ERROR_FAILURE; 1.602 + 1.603 + nsRefPtr<Accessible> link(do_QueryObject(aLink)); 1.604 + *aIndex = text->LinkIndexOf(link); 1.605 + return NS_OK; 1.606 +} 1.607 + 1.608 +NS_IMETHODIMP 1.609 +xpcAccessibleHyperText::GetLinkIndexAtOffset(int32_t aOffset, 1.610 + int32_t* aLinkIndex) 1.611 +{ 1.612 + NS_ENSURE_ARG_POINTER(aLinkIndex); 1.613 + *aLinkIndex = -1; // API says this magic value means 'not found' 1.614 + 1.615 + HyperTextAccessible* text = static_cast<HyperTextAccessible*>(this); 1.616 + if (text->IsDefunct()) 1.617 + return NS_ERROR_FAILURE; 1.618 + 1.619 + *aLinkIndex = text->LinkIndexAtOffset(aOffset); 1.620 + return NS_OK; 1.621 +}