EnumVariant.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "EnumVariant.h"
  6. using namespace mozilla;
  7. using namespace mozilla::a11y;
  8. ////////////////////////////////////////////////////////////////////////////////
  9. // ChildrenEnumVariant
  10. ////////////////////////////////////////////////////////////////////////////////
  11. IMPL_IUNKNOWN_QUERY_HEAD(ChildrenEnumVariant)
  12. IMPL_IUNKNOWN_QUERY_IFACE(IEnumVARIANT)
  13. IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(mAnchorAcc)
  14. STDMETHODIMP
  15. ChildrenEnumVariant::Next(ULONG aCount, VARIANT FAR* aItems,
  16. ULONG FAR* aCountFetched)
  17. {
  18. if (!aItems || !aCountFetched)
  19. return E_INVALIDARG;
  20. *aCountFetched = 0;
  21. if (mAnchorAcc->IsDefunct() || mAnchorAcc->GetChildAt(mCurIndex) != mCurAcc)
  22. return CO_E_OBJNOTCONNECTED;
  23. ULONG countFetched = 0;
  24. while (mCurAcc && countFetched < aCount) {
  25. VariantInit(aItems + countFetched);
  26. IDispatch* accNative = AccessibleWrap::NativeAccessible(mCurAcc);
  27. ++mCurIndex;
  28. mCurAcc = mAnchorAcc->GetChildAt(mCurIndex);
  29. // Don't output the accessible and count it as having been fetched unless
  30. // it is non-null
  31. MOZ_ASSERT(accNative);
  32. if (!accNative) {
  33. continue;
  34. }
  35. aItems[countFetched].pdispVal = accNative;
  36. aItems[countFetched].vt = VT_DISPATCH;
  37. ++countFetched;
  38. }
  39. (*aCountFetched) = countFetched;
  40. return countFetched < aCount ? S_FALSE : S_OK;
  41. }
  42. STDMETHODIMP
  43. ChildrenEnumVariant::Skip(ULONG aCount)
  44. {
  45. if (mAnchorAcc->IsDefunct() || mAnchorAcc->GetChildAt(mCurIndex) != mCurAcc)
  46. return CO_E_OBJNOTCONNECTED;
  47. mCurIndex += aCount;
  48. mCurAcc = mAnchorAcc->GetChildAt(mCurIndex);
  49. return mCurAcc ? S_OK : S_FALSE;
  50. }
  51. STDMETHODIMP
  52. ChildrenEnumVariant::Reset()
  53. {
  54. if (mAnchorAcc->IsDefunct())
  55. return CO_E_OBJNOTCONNECTED;
  56. mCurIndex = 0;
  57. mCurAcc = mAnchorAcc->GetChildAt(0);
  58. return S_OK;
  59. }
  60. STDMETHODIMP
  61. ChildrenEnumVariant::Clone(IEnumVARIANT** aEnumVariant)
  62. {
  63. if (!aEnumVariant)
  64. return E_INVALIDARG;
  65. *aEnumVariant = new ChildrenEnumVariant(*this);
  66. (*aEnumVariant)->AddRef();
  67. return S_OK;
  68. }