Bumping manifests a=b2g-bump
[gecko.git] / accessible / base / nsTextEquivUtils.h
blob3c35d0c072114d2e43d5089c773ef9161403ecc2
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
3 */
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"
12 #include "Role.h"
14 class nsIContent;
16 /**
17 * Text equivalent computation rules (see nsTextEquivUtils::gRoleToNameRulesMap)
19 enum ETextEquivRule
21 // No rule.
22 eNoNameRule = 0x00,
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
37 /**
38 * The class provides utils methods to compute the accessible name and
39 * description.
41 class nsTextEquivUtils
43 public:
44 typedef mozilla::a11y::Accessible Accessible;
46 /**
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;
58 /**
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,
65 nsAString& aName);
67 /**
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,
72 nsString& aTextEquiv)
74 aTextEquiv.Truncate();
76 AppendFromAccessibleChildren(aAccessible, &aTextEquiv);
77 aTextEquiv.CompressWhitespace();
80 /**
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,
89 nsIAtom *aIDRefsAttr,
90 nsAString& aTextEquiv);
92 /**
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
100 * computed from
101 * @param aString [in, out] the string
103 static nsresult AppendTextEquivFromContent(Accessible* aInitiatorAcc,
104 nsIContent *aContent,
105 nsAString *aString);
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,
115 nsAString *aString);
117 private:
119 * Iterates accessible children and calculates text equivalent from each
120 * child.
122 static nsresult AppendFromAccessibleChildren(Accessible* aAccessible,
123 nsAString *aString);
126 * Calculates text equivalent from the given accessible and its subtree if
127 * allowed.
129 static nsresult AppendFromAccessible(Accessible* aAccessible,
130 nsAString *aString);
133 * Calculates text equivalent from the value of given accessible.
135 static nsresult AppendFromValue(Accessible* aAccessible,
136 nsAString *aString);
138 * Iterates DOM children and calculates text equivalent from each child node.
140 static nsresult AppendFromDOMChildren(nsIContent *aContent,
141 nsAString *aString);
144 * Calculates text equivalent from the given DOM node and its subtree if
145 * allowed.
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);
162 #endif