DocAccessibleChildBase.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "mozilla/a11y/DocAccessibleChildBase.h"
  6. #include "mozilla/a11y/ProxyAccessible.h"
  7. #include "Accessible-inl.h"
  8. namespace mozilla {
  9. namespace a11y {
  10. /* static */ uint32_t
  11. DocAccessibleChildBase::InterfacesFor(Accessible* aAcc)
  12. {
  13. uint32_t interfaces = 0;
  14. if (aAcc->IsHyperText() && aAcc->AsHyperText()->IsTextRole())
  15. interfaces |= Interfaces::HYPERTEXT;
  16. if (aAcc->IsLink())
  17. interfaces |= Interfaces::HYPERLINK;
  18. if (aAcc->HasNumericValue())
  19. interfaces |= Interfaces::VALUE;
  20. if (aAcc->IsImage())
  21. interfaces |= Interfaces::IMAGE;
  22. if (aAcc->IsTable()) {
  23. interfaces |= Interfaces::TABLE;
  24. }
  25. if (aAcc->IsTableCell())
  26. interfaces |= Interfaces::TABLECELL;
  27. if (aAcc->IsDoc())
  28. interfaces |= Interfaces::DOCUMENT;
  29. if (aAcc->IsSelect()) {
  30. interfaces |= Interfaces::SELECTION;
  31. }
  32. if (aAcc->ActionCount()) {
  33. interfaces |= Interfaces::ACTION;
  34. }
  35. return interfaces;
  36. }
  37. /* static */ void
  38. DocAccessibleChildBase::SerializeTree(Accessible* aRoot,
  39. nsTArray<AccessibleData>& aTree)
  40. {
  41. uint64_t id = reinterpret_cast<uint64_t>(aRoot->UniqueID());
  42. #if defined(XP_WIN)
  43. int32_t msaaId = AccessibleWrap::GetChildIDFor(aRoot);
  44. #endif
  45. uint32_t role = aRoot->Role();
  46. uint32_t childCount = aRoot->ChildCount();
  47. uint32_t interfaces = InterfacesFor(aRoot);
  48. // OuterDocAccessibles are special because we don't want to serialize the
  49. // child doc here, we'll call PDocAccessibleConstructor in
  50. // NotificationController.
  51. MOZ_ASSERT(!aRoot->IsDoc(), "documents shouldn't be serialized");
  52. if (aRoot->IsOuterDoc()) {
  53. childCount = 0;
  54. }
  55. #if defined(XP_WIN)
  56. aTree.AppendElement(AccessibleData(id, msaaId, role, childCount, interfaces));
  57. #else
  58. aTree.AppendElement(AccessibleData(id, role, childCount, interfaces));
  59. #endif
  60. for (uint32_t i = 0; i < childCount; i++) {
  61. SerializeTree(aRoot->GetChildAt(i), aTree);
  62. }
  63. }
  64. void
  65. DocAccessibleChildBase::ShowEvent(AccShowEvent* aShowEvent)
  66. {
  67. Accessible* parent = aShowEvent->Parent();
  68. uint64_t parentID = parent->IsDoc() ? 0 : reinterpret_cast<uint64_t>(parent->UniqueID());
  69. uint32_t idxInParent = aShowEvent->GetAccessible()->IndexInParent();
  70. nsTArray<AccessibleData> shownTree;
  71. ShowEventData data(parentID, idxInParent, shownTree);
  72. SerializeTree(aShowEvent->GetAccessible(), data.NewTree());
  73. MaybeSendShowEvent(data, aShowEvent->IsFromUserInput());
  74. }
  75. } // namespace a11y
  76. } // namespace mozilla