accessible/xpcom/xpcAccessibleValue.cpp
author Nicholas Nethercote <nnethercote@mozilla.com>
Fri, 19 Aug 2016 09:03:04 +1000
changeset 335989 6a81bba012c8d4283978ae3c6920843916817bfc
parent 335895 8c550a7e9c2adb445010ff404613cc5979bc6fc6
child 336001 d4df5492322828c76d08c3e374b3f45325b9a75e
permissions -rw-r--r--
Bug 1293596 (part 2) - Rework nsIWidget bounds getters. r=mstange. This patch makes GetBounds(), GetScreenBounds() and GetClientBounds() more obviously infallible, like existing functions such as GetNaturalBounds() and GetClientSize(). This results in clearer behaviour in nsCocoaWindow.mm if Objective C exceptions occur. Along the way, the patch removes some useless failure checks for these functions. The patch also removes the NS_IMETHOD from GetRestoredBounds and makes that function MOZ_MUST_USE.

/* -*- 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 "Accessible.h"

using namespace mozilla;
using namespace mozilla::a11y;

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

  if (Intl().IsNull())
    return NS_ERROR_FAILURE;

  if (Intl().IsAccessible() && Intl().AsAccessible()->IsDefunct())
    return NS_ERROR_FAILURE;

  double value;
  if (Intl().IsAccessible()) {
    value = Intl().AsAccessible()->MaxValue();
  } else {
#if defined(XP_WIN)
    return NS_ERROR_NOT_IMPLEMENTED;
#else
    value = Intl().AsProxy()->MaxValue();
#endif
  }

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

  return NS_OK;
}

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

  if (Intl().IsNull())
    return NS_ERROR_FAILURE;

  if (Intl().IsAccessible() && Intl().AsAccessible()->IsDefunct())
    return NS_ERROR_FAILURE;

  double value;
  if (Intl().IsAccessible()) {
    value = Intl().AsAccessible()->MinValue();
  } else {
#if defined(XP_WIN)
    return NS_ERROR_NOT_IMPLEMENTED;
#else
    value = Intl().AsProxy()->MinValue();
#endif
  }

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

  return NS_OK;
}

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

  if (Intl().IsNull())
    return NS_ERROR_FAILURE;

  if (Intl().IsAccessible() && Intl().AsAccessible()->IsDefunct())
    return NS_ERROR_FAILURE;

  double value;
  if (Intl().IsAccessible()) {
    value = Intl().AsAccessible()->CurValue();
  } else {
#if defined(XP_WIN)
    return NS_ERROR_NOT_IMPLEMENTED;
#else
    value = Intl().AsProxy()->CurValue();
#endif
  }

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

  return NS_OK;
}

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

  if (Intl().IsAccessible() && Intl().AsAccessible()->IsDefunct())
    return NS_ERROR_FAILURE;

  if (Intl().IsAccessible()) {
    Intl().AsAccessible()->SetCurValue(aValue);
  } else {
#if defined(XP_WIN)
    return NS_ERROR_NOT_IMPLEMENTED;
#else
    Intl().AsProxy()->SetCurValue(aValue);
#endif
  }

  return NS_OK;
}

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

  if (Intl().IsNull())
    return NS_ERROR_FAILURE;

  if (Intl().IsAccessible() && Intl().AsAccessible()->IsDefunct())
    return NS_ERROR_FAILURE;

  double value;
  if (Intl().IsAccessible()) {
    value = Intl().AsAccessible()->Step();
  } else {
#if defined(XP_WIN)
    return NS_ERROR_NOT_IMPLEMENTED;
#else
    value = Intl().AsProxy()->Step();
#endif
  }

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

  return NS_OK;
}