1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
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/. */
8 #ifndef _nsTextEquivUtils_H_
9 #define _nsTextEquivUtils_H_
11 #include "Accessible.h"
17 * Text equivalent computation rules (see nsTextEquivUtils::gRoleToNameRulesMap)
24 // Walk into subtree only if the currently navigated accessible is not root
25 // accessible (i.e. if the accessible is part of text equivalent computation).
26 eNameFromSubtreeIfReqRule
= 0x01,
28 // Text equivalent computation from subtree is allowed.
29 eNameFromSubtreeRule
= 0x03,
31 // The accessible allows to append its value to text equivalent.
32 // XXX: This is temporary solution. Once we move accessible value of links
33 // and linkable accessibles to MSAA part we can remove this.
34 eNameFromValueRule
= 0x04
38 * The class provides utils methods to compute the accessible name and
41 class nsTextEquivUtils
44 typedef mozilla::a11y::Accessible Accessible
;
47 * Determines if the accessible has a given name rule.
49 * @param aAccessible [in] the given accessible
50 * @param aRule [in] a given name rule
51 * @return true if the accessible has the rule
53 static inline bool HasNameRule(Accessible
* aAccessible
, ETextEquivRule aRule
)
55 return (GetRoleRule(aAccessible
->Role()) & aRule
) == aRule
;
59 * Calculates the name from accessible subtree if allowed.
61 * @param aAccessible [in] the given accessible
62 * @param aName [out] accessible name
64 static nsresult
GetNameFromSubtree(Accessible
* aAccessible
,
68 * Calculates text equivalent from the subtree. Similar to GetNameFromSubtree.
69 * However it returns not empty result for things like HTML p.
71 static void GetTextEquivFromSubtree(Accessible
* aAccessible
,
74 aTextEquiv
.Truncate();
76 AppendFromAccessibleChildren(aAccessible
, &aTextEquiv
);
77 aTextEquiv
.CompressWhitespace();
81 * Calculates text equivalent for the given accessible from its IDRefs
82 * attribute (like aria-labelledby or aria-describedby).
84 * @param aAccessible [in] the accessible text equivalent is computed for
85 * @param aIDRefsAttr [in] IDRefs attribute on DOM node of the accessible
86 * @param aTextEquiv [out] result text equivalent
88 static nsresult
GetTextEquivFromIDRefs(Accessible
* aAccessible
,
90 nsAString
& aTextEquiv
);
93 * Calculates the text equivalent from the given content and its subtree if
94 * allowed and appends it to the given string.
96 * @param aInitiatorAcc [in] the accessible text equivalent is computed for
97 * in the end (root accessible of text equivalent
98 * calculation recursion)
99 * @param aContent [in] the given content the text equivalent is
101 * @param aString [in, out] the string
103 static nsresult
AppendTextEquivFromContent(Accessible
* aInitiatorAcc
,
104 nsIContent
*aContent
,
108 * Calculates the text equivalent from the given text content (may be text
109 * node or html:br) and appends it to the given string.
111 * @param aContent [in] the text content
112 * @param aString [in, out] the string
114 static nsresult
AppendTextEquivFromTextContent(nsIContent
*aContent
,
119 * Iterates accessible children and calculates text equivalent from each
122 static nsresult
AppendFromAccessibleChildren(Accessible
* aAccessible
,
126 * Calculates text equivalent from the given accessible and its subtree if
129 static nsresult
AppendFromAccessible(Accessible
* aAccessible
,
133 * Calculates text equivalent from the value of given accessible.
135 static nsresult
AppendFromValue(Accessible
* aAccessible
,
138 * Iterates DOM children and calculates text equivalent from each child node.
140 static nsresult
AppendFromDOMChildren(nsIContent
*aContent
,
144 * Calculates text equivalent from the given DOM node and its subtree if
147 static nsresult
AppendFromDOMNode(nsIContent
*aContent
, nsAString
*aString
);
150 * Concatenates strings and appends space between them. Returns true if
151 * text equivalent string was appended.
153 static bool AppendString(nsAString
*aString
,
154 const nsAString
& aTextEquivalent
);
157 * Returns the rule (constant of ETextEquivRule) for a given role.
159 static uint32_t GetRoleRule(mozilla::a11y::roles::Role aRole
);