LocalAccessible-inl.h (2987B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_a11y_Accessible_inl_h_ 8 #define mozilla_a11y_Accessible_inl_h_ 9 10 #include "DocAccessible.h" 11 #include "ARIAMap.h" 12 #include "nsCoreUtils.h" 13 #include "mozilla/dom/Element.h" 14 #include "mozilla/PresShell.h" 15 16 #ifdef A11Y_LOG 17 # include "Logging.h" 18 #endif 19 20 namespace mozilla { 21 namespace a11y { 22 23 inline mozilla::a11y::role LocalAccessible::ARIARole() { 24 const nsRoleMapEntry* roleMapEntry = ARIARoleMap(); 25 if (!roleMapEntry || roleMapEntry->roleRule != kUseMapRole) { 26 return mozilla::a11y::roles::NOTHING; 27 } 28 29 return ARIATransformRole(roleMapEntry->role); 30 } 31 32 inline void LocalAccessible::SetRoleMapEntry( 33 const nsRoleMapEntry* aRoleMapEntry) { 34 mRoleMapEntryIndex = aria::GetIndexFromRoleMap(aRoleMapEntry); 35 } 36 37 inline bool LocalAccessible::NativeHasNumericValue() const { 38 return mGenericTypes & eNumericValue; 39 } 40 41 inline bool LocalAccessible::ARIAHasNumericValue() const { 42 const nsRoleMapEntry* roleMapEntry = ARIARoleMap(); 43 if (!roleMapEntry || roleMapEntry->valueRule == eNoValue) return false; 44 45 if (roleMapEntry->valueRule == eHasValueMinMaxIfFocusable) { 46 return InteractiveState() & states::FOCUSABLE; 47 } 48 49 return true; 50 } 51 52 inline bool LocalAccessible::HasNumericValue() const { 53 return NativeHasNumericValue() || ARIAHasNumericValue(); 54 } 55 56 inline bool LocalAccessible::IsDefunct() const { 57 MOZ_ASSERT(mStateFlags & eIsDefunct || IsApplication() || IsDoc() || 58 mStateFlags & eSharedNode || mContent, 59 "No content"); 60 return mStateFlags & eIsDefunct; 61 } 62 63 inline void LocalAccessible::ScrollTo(uint32_t aHow) const { 64 if (mContent) { 65 RefPtr<PresShell> presShell = mDoc->PresShellPtr(); 66 nsCOMPtr<nsIContent> content = mContent; 67 nsCoreUtils::ScrollTo(presShell, content, aHow); 68 } 69 } 70 71 inline bool LocalAccessible::InsertAfter(LocalAccessible* aNewChild, 72 LocalAccessible* aRefChild) { 73 MOZ_ASSERT(aNewChild, "No new child to insert"); 74 75 if (aRefChild && aRefChild->LocalParent() != this) { 76 #ifdef A11Y_LOG 77 logging::TreeInfo("broken accessible tree", 0, "parent", this, 78 "prev sibling parent", aRefChild->LocalParent(), "child", 79 aNewChild, nullptr); 80 if (logging::IsEnabled(logging::eVerbose)) { 81 logging::Tree("TREE", "Document tree", mDoc); 82 logging::DOMTree("TREE", "DOM document tree", mDoc); 83 } 84 #endif 85 MOZ_ASSERT_UNREACHABLE("Broken accessible tree"); 86 mDoc->UnbindFromDocument(aNewChild); 87 return false; 88 } 89 90 return InsertChildAt(aRefChild ? aRefChild->IndexInParent() + 1 : 0, 91 aNewChild); 92 } 93 94 } // namespace a11y 95 } // namespace mozilla 96 97 #endif