accessible/xpcom/xpcAccessibleValue.cpp
author James Teh <jteh@mozilla.com>
Wed, 01 Feb 2023 05:02:01 +0000
changeset 651150 dd0fdd1daa69783be36acd5c50544f3694eaa8f9
parent 590080 dcc478201cb75d078d3a5fd33f306c7b9cfcd527
permissions -rw-r--r--
Bug 1813980: Check IsDoc before Parent in RemoteAccessibleBase::ApplyCrossDocOffset. r=morgan We call this function on every ancestor when calculating bounds. RemoteParent() currently requires a hash lookup, so it's more efficient to early return for !IsDoc() first. This is a micro-optimisation, but it might have some impact given that we call this on every ancestor, especially when hit testing, where we call Bounds() a lot. As a bit of drive-by cleanup, use RemoteParent() rather than calling Parent() and IsRemote/AsRemote(). Differential Revision: https://phabricator.services.mozilla.com/D168346

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "xpcAccessibleGeneric.h"
#include "LocalAccessible.h"
#include "LocalAccessible-inl.h"

using namespace mozilla;
using namespace mozilla::a11y;

NS_IMETHODIMP
xpcAccessibleValue::GetMaximumValue(double* aValue) {
  NS_ENSURE_ARG_POINTER(aValue);
  *aValue = 0;

  if (!Intl()) return NS_ERROR_FAILURE;

  if (Intl()->IsLocal() && Intl()->AsLocal()->IsDefunct()) {
    return NS_ERROR_FAILURE;
  }

  double value = Intl()->MaxValue();

  if (!IsNaN(value)) *aValue = value;

  return NS_OK;
}

NS_IMETHODIMP
xpcAccessibleValue::GetMinimumValue(double* aValue) {
  NS_ENSURE_ARG_POINTER(aValue);
  *aValue = 0;

  if (!Intl()) return NS_ERROR_FAILURE;

  if (Intl()->IsLocal() && Intl()->AsLocal()->IsDefunct()) {
    return NS_ERROR_FAILURE;
  }

  double value = Intl()->MinValue();

  if (!IsNaN(value)) *aValue = value;

  return NS_OK;
}

NS_IMETHODIMP
xpcAccessibleValue::GetCurrentValue(double* aValue) {
  NS_ENSURE_ARG_POINTER(aValue);
  *aValue = 0;

  if (!Intl()) return NS_ERROR_FAILURE;

  if (Intl()->IsLocal() && Intl()->AsLocal()->IsDefunct()) {
    return NS_ERROR_FAILURE;
  }

  double value = Intl()->CurValue();

  if (!IsNaN(value)) *aValue = value;

  return NS_OK;
}

NS_IMETHODIMP
xpcAccessibleValue::SetCurrentValue(double aValue) {
  if (!Intl()) return NS_ERROR_FAILURE;

  if (Intl()->IsLocal() && Intl()->AsLocal()->IsDefunct()) {
    return NS_ERROR_FAILURE;
  }

  if (Intl()->IsLocal()) {
    Intl()->AsLocal()->SetCurValue(aValue);
  } else {
    Intl()->AsRemote()->SetCurValue(aValue);
  }

  return NS_OK;
}

NS_IMETHODIMP
xpcAccessibleValue::GetMinimumIncrement(double* aValue) {
  NS_ENSURE_ARG_POINTER(aValue);
  *aValue = 0;

  if (!Intl()) return NS_ERROR_FAILURE;

  if (Intl()->IsLocal() && Intl()->AsLocal()->IsDefunct()) {
    return NS_ERROR_FAILURE;
  }

  double value = Intl()->Step();

  if (!IsNaN(value)) *aValue = value;

  return NS_OK;
}