tor-browser

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

nsMaiInterfaceHypertext.cpp (1892B)


      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
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "InterfaceInitFuncs.h"
      8 
      9 #include "LocalAccessible-inl.h"
     10 #include "HyperTextAccessible.h"
     11 #include "nsMai.h"
     12 #include "nsMaiHyperlink.h"
     13 #include "RemoteAccessible.h"
     14 #include "mozilla/Likely.h"
     15 
     16 using namespace mozilla::a11y;
     17 
     18 extern "C" {
     19 
     20 static AtkHyperlink* getLinkCB(AtkHypertext* aText, gint aLinkIndex) {
     21  if (Accessible* acc = GetInternalObj(ATK_OBJECT(aText))) {
     22    if (HyperTextAccessibleBase* hyperText = acc->AsHyperTextBase()) {
     23      Accessible* linkAcc = hyperText->LinkAt(aLinkIndex);
     24      AtkObject* atkHyperLink = GetWrapperFor(linkAcc);
     25      NS_ENSURE_TRUE(IS_MAI_OBJECT(atkHyperLink), nullptr);
     26      return MAI_ATK_OBJECT(atkHyperLink)->GetAtkHyperlink();
     27    }
     28  }
     29 
     30  return nullptr;
     31 }
     32 
     33 static gint getLinkCountCB(AtkHypertext* aText) {
     34  if (Accessible* acc = GetInternalObj(ATK_OBJECT(aText))) {
     35    if (HyperTextAccessibleBase* hyperText = acc->AsHyperTextBase()) {
     36      return static_cast<gint>(hyperText->LinkCount());
     37    }
     38  }
     39  return -1;
     40 }
     41 
     42 static gint getLinkIndexCB(AtkHypertext* aText, gint aCharIndex) {
     43  Accessible* acc = GetInternalObj(ATK_OBJECT(aText));
     44  if (!acc) {
     45    return -1;
     46  }
     47  HyperTextAccessibleBase* hyperText = acc->AsHyperTextBase();
     48  if (!hyperText) {
     49    return -1;
     50  }
     51  return hyperText->LinkIndexAtOffset(aCharIndex);
     52 }
     53 
     54 }  // extern "C"
     55 
     56 void hypertextInterfaceInitCB(AtkHypertextIface* aIface) {
     57  NS_ASSERTION(aIface, "no interface!");
     58  if (MOZ_UNLIKELY(!aIface)) return;
     59 
     60  aIface->get_link = getLinkCB;
     61  aIface->get_n_links = getLinkCountCB;
     62  aIface->get_link_index = getLinkIndexCB;
     63 }