HyperTextAccessibleWrap.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "HyperTextAccessibleWrap.h"
  8. #include "Accessible-inl.h"
  9. #include "nsEventShell.h"
  10. #include "mozilla/StaticPtr.h"
  11. using namespace mozilla;
  12. using namespace mozilla::a11y;
  13. NS_IMPL_ISUPPORTS_INHERITED0(HyperTextAccessibleWrap,
  14. HyperTextAccessible)
  15. STDMETHODIMP
  16. HyperTextAccessibleWrap::QueryInterface(REFIID aIID, void** aInstancePtr)
  17. {
  18. if (!aInstancePtr)
  19. return E_FAIL;
  20. *aInstancePtr = nullptr;
  21. if (IsTextRole()) {
  22. if (aIID == IID_IAccessibleText)
  23. *aInstancePtr =
  24. static_cast<IAccessibleText*>(static_cast<ia2AccessibleText*>(this));
  25. else if (aIID == IID_IAccessibleHypertext)
  26. *aInstancePtr = static_cast<IAccessibleHypertext*>(this);
  27. else if (aIID == IID_IAccessibleEditableText)
  28. *aInstancePtr = static_cast<IAccessibleEditableText*>(this);
  29. if (*aInstancePtr) {
  30. AddRef();
  31. return S_OK;
  32. }
  33. }
  34. return AccessibleWrap::QueryInterface(aIID, aInstancePtr);
  35. }
  36. nsresult
  37. HyperTextAccessibleWrap::HandleAccEvent(AccEvent* aEvent)
  38. {
  39. uint32_t eventType = aEvent->GetEventType();
  40. if (eventType == nsIAccessibleEvent::EVENT_TEXT_REMOVED ||
  41. eventType == nsIAccessibleEvent::EVENT_TEXT_INSERTED) {
  42. Accessible* accessible = aEvent->GetAccessible();
  43. if (accessible && accessible->IsHyperText()) {
  44. AccTextChangeEvent* event = downcast_accEvent(aEvent);
  45. HyperTextAccessibleWrap* text =
  46. static_cast<HyperTextAccessibleWrap*>(accessible->AsHyperText());
  47. ia2AccessibleText::UpdateTextChangeData(text, event->IsTextInserted(),
  48. event->ModifiedText(),
  49. event->GetStartOffset(),
  50. event->GetLength());
  51. }
  52. }
  53. return HyperTextAccessible::HandleAccEvent(aEvent);
  54. }