Bug 1890277: part 2) Add `require-trusted-types-for` directive to CSP parser, guarded...
[gecko.git] / accessible / generic / LocalAccessible-inl.h
blob24a6169b76f889138c10b146170dc6a035aa8527
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/. */
7 #ifndef mozilla_a11y_Accessible_inl_h_
8 #define mozilla_a11y_Accessible_inl_h_
10 #include "DocAccessible.h"
11 #include "ARIAMap.h"
12 #include "nsCoreUtils.h"
13 #include "mozilla/dom/Element.h"
14 #include "mozilla/PresShell.h"
16 #ifdef A11Y_LOG
17 # include "Logging.h"
18 #endif
20 namespace mozilla {
21 namespace a11y {
23 inline mozilla::a11y::role LocalAccessible::Role() const {
24 const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
25 mozilla::a11y::role r =
26 (!roleMapEntry || roleMapEntry->roleRule != kUseMapRole)
27 ? NativeRole()
28 : roleMapEntry->role;
29 r = ARIATransformRole(r);
30 return GetMinimumRole(r);
33 inline mozilla::a11y::role LocalAccessible::ARIARole() {
34 const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
35 if (!roleMapEntry || roleMapEntry->roleRule != kUseMapRole) {
36 return mozilla::a11y::roles::NOTHING;
39 return ARIATransformRole(roleMapEntry->role);
42 inline void LocalAccessible::SetRoleMapEntry(
43 const nsRoleMapEntry* aRoleMapEntry) {
44 mRoleMapEntryIndex = aria::GetIndexFromRoleMap(aRoleMapEntry);
47 inline bool LocalAccessible::NativeHasNumericValue() const {
48 return mGenericTypes & eNumericValue;
51 inline bool LocalAccessible::ARIAHasNumericValue() const {
52 const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
53 if (!roleMapEntry || roleMapEntry->valueRule == eNoValue) return false;
55 if (roleMapEntry->valueRule == eHasValueMinMaxIfFocusable) {
56 return InteractiveState() & states::FOCUSABLE;
59 return true;
62 inline bool LocalAccessible::HasNumericValue() const {
63 return NativeHasNumericValue() || ARIAHasNumericValue();
66 inline bool LocalAccessible::IsDefunct() const {
67 MOZ_ASSERT(mStateFlags & eIsDefunct || IsApplication() || IsDoc() ||
68 mStateFlags & eSharedNode || mContent,
69 "No content");
70 return mStateFlags & eIsDefunct;
73 inline void LocalAccessible::ScrollTo(uint32_t aHow) const {
74 if (mContent) {
75 RefPtr<PresShell> presShell = mDoc->PresShellPtr();
76 nsCOMPtr<nsIContent> content = mContent;
77 nsCoreUtils::ScrollTo(presShell, content, aHow);
81 inline bool LocalAccessible::InsertAfter(LocalAccessible* aNewChild,
82 LocalAccessible* aRefChild) {
83 MOZ_ASSERT(aNewChild, "No new child to insert");
85 if (aRefChild && aRefChild->LocalParent() != this) {
86 #ifdef A11Y_LOG
87 logging::TreeInfo("broken accessible tree", 0, "parent", this,
88 "prev sibling parent", aRefChild->LocalParent(), "child",
89 aNewChild, nullptr);
90 if (logging::IsEnabled(logging::eVerbose)) {
91 logging::Tree("TREE", "Document tree", mDoc);
92 logging::DOMTree("TREE", "DOM document tree", mDoc);
94 #endif
95 MOZ_ASSERT_UNREACHABLE("Broken accessible tree");
96 mDoc->UnbindFromDocument(aNewChild);
97 return false;
100 return InsertChildAt(aRefChild ? aRefChild->IndexInParent() + 1 : 0,
101 aNewChild);
104 } // namespace a11y
105 } // namespace mozilla
107 #endif