tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

xpcAccessibleHyperLink.cpp (2170B)


      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "xpcAccessibleHyperLink.h"
      8 
      9 #include "xpcAccessibleDocument.h"
     10 
     11 using namespace mozilla::a11y;
     12 
     13 NS_IMETHODIMP
     14 xpcAccessibleHyperLink::GetStartIndex(int32_t* aStartIndex) {
     15  NS_ENSURE_ARG_POINTER(aStartIndex);
     16  *aStartIndex = 0;
     17 
     18  if (!Intl()) return NS_ERROR_FAILURE;
     19 
     20  *aStartIndex = static_cast<int32_t>(Intl()->StartOffset());
     21  return NS_OK;
     22 }
     23 
     24 NS_IMETHODIMP
     25 xpcAccessibleHyperLink::GetEndIndex(int32_t* aEndIndex) {
     26  NS_ENSURE_ARG_POINTER(aEndIndex);
     27  *aEndIndex = 0;
     28 
     29  if (!Intl()) return NS_ERROR_FAILURE;
     30 
     31  *aEndIndex = static_cast<int32_t>(Intl()->EndOffset());
     32  return NS_OK;
     33 }
     34 
     35 NS_IMETHODIMP
     36 xpcAccessibleHyperLink::GetAnchorCount(int32_t* aAnchorCount) {
     37  NS_ENSURE_ARG_POINTER(aAnchorCount);
     38  *aAnchorCount = 0;
     39 
     40  if (!Intl()) return NS_ERROR_FAILURE;
     41 
     42  *aAnchorCount = Intl()->AnchorCount();
     43 
     44  return NS_OK;
     45 }
     46 
     47 NS_IMETHODIMP
     48 xpcAccessibleHyperLink::GetURI(int32_t aIndex, nsIURI** aURI) {
     49  NS_ENSURE_ARG_POINTER(aURI);
     50 
     51  if (!Intl()) {
     52    return NS_ERROR_FAILURE;
     53  }
     54 
     55  if (aIndex < 0 || aIndex >= static_cast<int32_t>(Intl()->AnchorCount())) {
     56    return NS_ERROR_INVALID_ARG;
     57  }
     58 
     59  RefPtr<nsIURI>(Intl()->AnchorURIAt(aIndex)).forget(aURI);
     60 
     61  return NS_OK;
     62 }
     63 
     64 NS_IMETHODIMP
     65 xpcAccessibleHyperLink::GetAnchor(int32_t aIndex, nsIAccessible** aAccessible) {
     66  NS_ENSURE_ARG_POINTER(aAccessible);
     67  *aAccessible = nullptr;
     68 
     69  if (!Intl()) return NS_ERROR_FAILURE;
     70 
     71  if (aIndex < 0) return NS_ERROR_INVALID_ARG;
     72 
     73  if (aIndex >= static_cast<int32_t>(Intl()->AnchorCount())) {
     74    return NS_ERROR_INVALID_ARG;
     75  }
     76 
     77  NS_IF_ADDREF(*aAccessible = ToXPC(Intl()->AnchorAt(aIndex)));
     78 
     79  return NS_OK;
     80 }
     81 
     82 NS_IMETHODIMP
     83 xpcAccessibleHyperLink::GetValid(bool* aValid) {
     84  NS_ENSURE_ARG_POINTER(aValid);
     85  *aValid = false;
     86 
     87  if (!Intl()) return NS_ERROR_FAILURE;
     88 
     89  *aValid = Intl()->IsLinkValid();
     90 
     91  return NS_OK;
     92 }