ia2AccessibleValue.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim:expandtab:shiftwidth=2:tabstop=2:
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  7. #include "ia2AccessibleValue.h"
  8. #include "AccessibleValue_i.c"
  9. #include "AccessibleWrap.h"
  10. #include "Accessible-inl.h"
  11. #include "IUnknownImpl.h"
  12. #include "mozilla/FloatingPoint.h"
  13. using namespace mozilla::a11y;
  14. // IUnknown
  15. STDMETHODIMP
  16. ia2AccessibleValue::QueryInterface(REFIID iid, void** ppv)
  17. {
  18. if (!ppv)
  19. return E_INVALIDARG;
  20. *ppv = nullptr;
  21. if (IID_IAccessibleValue == iid) {
  22. AccessibleWrap* valueAcc = static_cast<AccessibleWrap*>(this);
  23. if (valueAcc->HasNumericValue()) {
  24. *ppv = static_cast<IAccessibleValue*>(this);
  25. valueAcc->AddRef();
  26. return S_OK;
  27. }
  28. return E_NOINTERFACE;
  29. }
  30. return E_NOINTERFACE;
  31. }
  32. // IAccessibleValue
  33. STDMETHODIMP
  34. ia2AccessibleValue::get_currentValue(VARIANT* aCurrentValue)
  35. {
  36. if (!aCurrentValue)
  37. return E_INVALIDARG;
  38. VariantInit(aCurrentValue);
  39. AccessibleWrap* valueAcc = static_cast<AccessibleWrap*>(this);
  40. double currentValue;
  41. MOZ_ASSERT(!valueAcc->IsProxy());
  42. if (valueAcc->IsDefunct()) {
  43. return CO_E_OBJNOTCONNECTED;
  44. }
  45. currentValue = valueAcc->CurValue();
  46. if (IsNaN(currentValue))
  47. return S_FALSE;
  48. aCurrentValue->vt = VT_R8;
  49. aCurrentValue->dblVal = currentValue;
  50. return S_OK;
  51. }
  52. STDMETHODIMP
  53. ia2AccessibleValue::setCurrentValue(VARIANT aValue)
  54. {
  55. if (aValue.vt != VT_R8)
  56. return E_INVALIDARG;
  57. AccessibleWrap* valueAcc = static_cast<AccessibleWrap*>(this);
  58. MOZ_ASSERT(!valueAcc->IsProxy());
  59. if (valueAcc->IsDefunct())
  60. return CO_E_OBJNOTCONNECTED;
  61. return valueAcc->SetCurValue(aValue.dblVal) ? S_OK : E_FAIL;
  62. }
  63. STDMETHODIMP
  64. ia2AccessibleValue::get_maximumValue(VARIANT* aMaximumValue)
  65. {
  66. if (!aMaximumValue)
  67. return E_INVALIDARG;
  68. VariantInit(aMaximumValue);
  69. AccessibleWrap* valueAcc = static_cast<AccessibleWrap*>(this);
  70. double maximumValue;
  71. MOZ_ASSERT(!valueAcc->IsProxy());
  72. if (valueAcc->IsDefunct()) {
  73. return CO_E_OBJNOTCONNECTED;
  74. }
  75. maximumValue = valueAcc->MaxValue();
  76. if (IsNaN(maximumValue))
  77. return S_FALSE;
  78. aMaximumValue->vt = VT_R8;
  79. aMaximumValue->dblVal = maximumValue;
  80. return S_OK;
  81. }
  82. STDMETHODIMP
  83. ia2AccessibleValue::get_minimumValue(VARIANT* aMinimumValue)
  84. {
  85. if (!aMinimumValue)
  86. return E_INVALIDARG;
  87. VariantInit(aMinimumValue);
  88. AccessibleWrap* valueAcc = static_cast<AccessibleWrap*>(this);
  89. double minimumValue;
  90. MOZ_ASSERT(!valueAcc->IsProxy());
  91. if (valueAcc->IsDefunct()) {
  92. return CO_E_OBJNOTCONNECTED;
  93. }
  94. minimumValue = valueAcc->MinValue();
  95. if (IsNaN(minimumValue))
  96. return S_FALSE;
  97. aMinimumValue->vt = VT_R8;
  98. aMinimumValue->dblVal = minimumValue;
  99. return S_OK;
  100. }