ia2AccessibleImage.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 "ia2AccessibleImage.h"
  8. #include "AccessibleImage_i.c"
  9. #include "ImageAccessibleWrap.h"
  10. #include "IUnknownImpl.h"
  11. #include "nsIAccessibleTypes.h"
  12. #include "nsString.h"
  13. #include "nsIURI.h"
  14. using namespace mozilla;
  15. using namespace mozilla::a11y;
  16. // IUnknown
  17. STDMETHODIMP
  18. ia2AccessibleImage::QueryInterface(REFIID iid, void** ppv)
  19. {
  20. if (!ppv)
  21. return E_INVALIDARG;
  22. *ppv = nullptr;
  23. if (IID_IAccessibleImage == iid) {
  24. *ppv = static_cast<IAccessibleImage*>(this);
  25. (static_cast<IUnknown*>(*ppv))->AddRef();
  26. return S_OK;
  27. }
  28. return E_NOINTERFACE;
  29. }
  30. // IAccessibleImage
  31. STDMETHODIMP
  32. ia2AccessibleImage::get_description(BSTR* aDescription)
  33. {
  34. if (!aDescription)
  35. return E_INVALIDARG;
  36. *aDescription = nullptr;
  37. ImageAccessibleWrap* acc = static_cast<ImageAccessibleWrap*>(this);
  38. if (acc->IsDefunct())
  39. return CO_E_OBJNOTCONNECTED;
  40. nsAutoString description;
  41. acc->Name(description);
  42. if (description.IsEmpty())
  43. return S_FALSE;
  44. *aDescription = ::SysAllocStringLen(description.get(), description.Length());
  45. return *aDescription ? S_OK : E_OUTOFMEMORY;
  46. }
  47. STDMETHODIMP
  48. ia2AccessibleImage::get_imagePosition(enum IA2CoordinateType aCoordType,
  49. long* aX,
  50. long* aY)
  51. {
  52. if (!aX || !aY)
  53. return E_INVALIDARG;
  54. *aX = 0;
  55. *aY = 0;
  56. ImageAccessibleWrap* imageAcc = static_cast<ImageAccessibleWrap*>(this);
  57. if (imageAcc->IsDefunct())
  58. return CO_E_OBJNOTCONNECTED;
  59. uint32_t geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ?
  60. nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
  61. nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE;
  62. nsIntPoint pos = imageAcc->Position(geckoCoordType);
  63. *aX = pos.x;
  64. *aY = pos.y;
  65. return S_OK;
  66. }
  67. STDMETHODIMP
  68. ia2AccessibleImage::get_imageSize(long* aHeight, long* aWidth)
  69. {
  70. if (!aHeight || !aWidth)
  71. return E_INVALIDARG;
  72. *aHeight = 0;
  73. *aWidth = 0;
  74. ImageAccessibleWrap* imageAcc = static_cast<ImageAccessibleWrap*>(this);
  75. if (imageAcc->IsDefunct())
  76. return CO_E_OBJNOTCONNECTED;
  77. nsIntSize size = imageAcc->Size();
  78. *aHeight = size.width;
  79. *aWidth = size.height;
  80. return S_OK;
  81. }