tor-browser

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

xpcAccessibleTextLeafRange.cpp (2625B)


      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 "xpcAccessibleTextLeafRange.h"
      8 
      9 #include "nsIAccessible.h"
     10 #include "TextLeafRange.h"
     11 #include "xpcAccessibleDocument.h"
     12 
     13 using namespace mozilla;
     14 using namespace mozilla::a11y;
     15 
     16 // xpcAccessibleTextLeafPoint
     17 
     18 NS_IMPL_ADDREF(xpcAccessibleTextLeafPoint)
     19 NS_IMPL_RELEASE(xpcAccessibleTextLeafPoint)
     20 
     21 NS_IMPL_QUERY_INTERFACE(xpcAccessibleTextLeafPoint, nsIAccessibleTextLeafPoint)
     22 
     23 xpcAccessibleTextLeafPoint::xpcAccessibleTextLeafPoint(
     24    nsIAccessible* aAccessible, int32_t aOffset)
     25    : mAccessible(nullptr), mOffset(0) {
     26  // When constructing a text point it will actualize the offset
     27  // and adjust the accessible to the appropriate leaf. These
     28  // might differ from the given constructor arguments.
     29  if (aAccessible) {
     30    TextLeafPoint point(aAccessible->ToInternalGeneric(), aOffset);
     31    mAccessible = ToXPC(point.mAcc);
     32    mOffset = point.mOffset;
     33  }
     34 }
     35 
     36 NS_IMETHODIMP xpcAccessibleTextLeafPoint::GetAccessible(
     37    nsIAccessible** aAccessible) {
     38  NS_ENSURE_ARG_POINTER(aAccessible);
     39  RefPtr<nsIAccessible> acc = mAccessible;
     40  acc.forget(aAccessible);
     41  return NS_OK;
     42 }
     43 
     44 NS_IMETHODIMP xpcAccessibleTextLeafPoint::SetAccessible(
     45    nsIAccessible* aAccessible) {
     46  mAccessible = aAccessible;
     47  return NS_OK;
     48 }
     49 
     50 NS_IMETHODIMP xpcAccessibleTextLeafPoint::GetOffset(int32_t* aOffset) {
     51  NS_ENSURE_ARG_POINTER(aOffset);
     52  *aOffset = mOffset;
     53  return NS_OK;
     54 }
     55 NS_IMETHODIMP xpcAccessibleTextLeafPoint::SetOffset(int32_t aOffset) {
     56  mOffset = aOffset;
     57  return NS_OK;
     58 }
     59 
     60 NS_IMETHODIMP xpcAccessibleTextLeafPoint::FindBoundary(
     61    AccessibleTextBoundary aBoundaryType, uint32_t aDirection, uint32_t aFlags,
     62    nsIAccessibleTextLeafPoint** aPoint) {
     63  TextLeafPoint thisPoint = ToPoint();
     64  if (!thisPoint) {
     65    return NS_ERROR_FAILURE;
     66  }
     67 
     68  TextLeafPoint result = thisPoint.FindBoundary(
     69      aBoundaryType, static_cast<nsDirection>(aDirection),
     70      static_cast<TextLeafPoint::BoundaryFlags>(aFlags));
     71  RefPtr<xpcAccessibleTextLeafPoint> point = new xpcAccessibleTextLeafPoint(
     72      result ? ToXPC(result.mAcc) : nullptr, result ? result.mOffset : 0);
     73  point.forget(aPoint);
     74  return NS_OK;
     75 }
     76 
     77 TextLeafPoint xpcAccessibleTextLeafPoint::ToPoint() {
     78  if (mAccessible) {
     79    return TextLeafPoint(mAccessible->ToInternalGeneric(), mOffset);
     80  }
     81 
     82  return TextLeafPoint();
     83 }