ia2AccessibleComponent.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 "ia2AccessibleComponent.h"
  8. #include "AccessibleComponent_i.c"
  9. #include "AccessibleWrap.h"
  10. #include "States.h"
  11. #include "IUnknownImpl.h"
  12. #include "nsIFrame.h"
  13. using namespace mozilla::a11y;
  14. // IUnknown
  15. STDMETHODIMP
  16. ia2AccessibleComponent::QueryInterface(REFIID iid, void** ppv)
  17. {
  18. if (!ppv)
  19. return E_INVALIDARG;
  20. *ppv = nullptr;
  21. if (IID_IAccessibleComponent == iid) {
  22. *ppv = static_cast<IAccessibleComponent*>(this);
  23. (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
  24. return S_OK;
  25. }
  26. return E_NOINTERFACE;
  27. }
  28. // IAccessibleComponent
  29. STDMETHODIMP
  30. ia2AccessibleComponent::get_locationInParent(long* aX, long* aY)
  31. {
  32. if (!aX || !aY)
  33. return E_INVALIDARG;
  34. *aX = 0;
  35. *aY = 0;
  36. AccessibleWrap* acc = static_cast<AccessibleWrap*>(this);
  37. if (acc->IsDefunct())
  38. return CO_E_OBJNOTCONNECTED;
  39. // If the object is not on any screen the returned position is (0,0).
  40. uint64_t state = acc->State();
  41. if (state & states::INVISIBLE)
  42. return S_OK;
  43. nsIntRect rect = acc->Bounds();
  44. // The coordinates of the returned position are relative to this object's
  45. // parent or relative to the screen on which this object is rendered if it
  46. // has no parent.
  47. if (!acc->Parent()) {
  48. *aX = rect.x;
  49. *aY = rect.y;
  50. return S_OK;
  51. }
  52. // The coordinates of the bounding box are given relative to the parent's
  53. // coordinate system.
  54. nsIntRect parentRect = acc->Parent()->Bounds();
  55. *aX = rect.x - parentRect.x;
  56. *aY = rect.y - parentRect.y;
  57. return S_OK;
  58. }
  59. STDMETHODIMP
  60. ia2AccessibleComponent::get_foreground(IA2Color* aForeground)
  61. {
  62. if (!aForeground)
  63. return E_INVALIDARG;
  64. *aForeground = 0;
  65. AccessibleWrap* acc = static_cast<AccessibleWrap*>(this);
  66. if (acc->IsDefunct())
  67. return CO_E_OBJNOTCONNECTED;
  68. nsIFrame* frame = acc->GetFrame();
  69. if (frame)
  70. *aForeground = frame->StyleColor()->mColor;
  71. return S_OK;
  72. }
  73. STDMETHODIMP
  74. ia2AccessibleComponent::get_background(IA2Color* aBackground)
  75. {
  76. if (!aBackground)
  77. return E_INVALIDARG;
  78. *aBackground = 0;
  79. AccessibleWrap* acc = static_cast<AccessibleWrap*>(this);
  80. if (acc->IsDefunct())
  81. return CO_E_OBJNOTCONNECTED;
  82. nsIFrame* frame = acc->GetFrame();
  83. if (frame)
  84. *aBackground = frame->StyleBackground()->mBackgroundColor;
  85. return S_OK;
  86. }