/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/a11y/DocAccessibleChildBase.h" #include "mozilla/a11y/CacheConstants.h" #include "mozilla/a11y/RemoteAccessible.h" #include "mozilla/StaticPrefs_accessibility.h" #include "LocalAccessible-inl.h" namespace mozilla { namespace a11y { /* static */ void DocAccessibleChildBase::FlattenTree(LocalAccessible* aRoot, nsTArray& aTree) { MOZ_ASSERT(!aRoot->IsDoc(), "documents shouldn't be serialized"); aTree.AppendElement(aRoot); // OuterDocAccessibles are special because we don't want to serialize the // child doc here, we'll call PDocAccessibleConstructor in // NotificationController. uint32_t childCount = aRoot->IsOuterDoc() ? 0 : aRoot->ChildCount(); for (uint32_t i = 0; i < childCount; i++) { FlattenTree(aRoot->LocalChildAt(i), aTree); } } /* static */ void DocAccessibleChildBase::SerializeTree(nsTArray& aTree, nsTArray& aData) { for (LocalAccessible* acc : aTree) { uint64_t id = reinterpret_cast(acc->UniqueID()); #if defined(XP_WIN) int32_t msaaId = StaticPrefs::accessibility_cache_enabled_AtStartup() ? 0 : MsaaAccessible::GetChildIDFor(acc); #endif a11y::role role = acc->Role(); uint32_t childCount = acc->IsOuterDoc() ? 0 : acc->ChildCount(); uint32_t genericTypes = acc->mGenericTypes; if (acc->ARIAHasNumericValue()) { // XXX: We need to do this because this requires a state check. genericTypes |= eNumericValue; } if (acc->ActionCount()) { genericTypes |= eActionable; } #if defined(XP_WIN) aData.AppendElement(AccessibleData( id, msaaId, role, childCount, static_cast(acc->mType), static_cast(genericTypes), acc->mRoleMapEntryIndex)); #else aData.AppendElement(AccessibleData( id, role, childCount, static_cast(acc->mType), static_cast(genericTypes), acc->mRoleMapEntryIndex)); #endif } } void DocAccessibleChildBase::InsertIntoIpcTree(LocalAccessible* aParent, LocalAccessible* aChild, uint32_t aIdxInParent, bool aSuppressShowEvent) { uint64_t parentID = aParent->IsDoc() ? 0 : reinterpret_cast(aParent->UniqueID()); nsTArray shownTree; FlattenTree(aChild, shownTree); ShowEventData data(parentID, aIdxInParent, nsTArray(shownTree.Length()), aSuppressShowEvent); SerializeTree(shownTree, data.NewTree()); MaybeSendShowEvent(data, false); if (StaticPrefs::accessibility_cache_enabled_AtStartup()) { nsTArray cache(shownTree.Length()); for (LocalAccessible* acc : shownTree) { RefPtr fields = acc->BundleFieldsForCache(CacheDomain::All, CacheUpdateType::Initial); if (fields->Count()) { uint64_t id = reinterpret_cast(acc->UniqueID()); cache.AppendElement(CacheData(id, fields)); } } Unused << SendCache(CacheUpdateType::Initial, cache, true); } } void DocAccessibleChildBase::ShowEvent(AccShowEvent* aShowEvent) { LocalAccessible* child = aShowEvent->GetAccessible(); InsertIntoIpcTree(aShowEvent->LocalParent(), child, child->IndexInParent(), false); } } // namespace a11y } // namespace mozilla