accessible/src/base/nsTextEquivUtils.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:expandtab:shiftwidth=2:tabstop=2:
michael@0 3 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #ifndef _nsTextEquivUtils_H_
michael@0 9 #define _nsTextEquivUtils_H_
michael@0 10
michael@0 11 #include "Accessible.h"
michael@0 12 #include "Role.h"
michael@0 13
michael@0 14 class nsIContent;
michael@0 15
michael@0 16 /**
michael@0 17 * Text equivalent computation rules (see nsTextEquivUtils::gRoleToNameRulesMap)
michael@0 18 */
michael@0 19 enum ETextEquivRule
michael@0 20 {
michael@0 21 // No rule.
michael@0 22 eNoNameRule = 0x00,
michael@0 23
michael@0 24 // Walk into subtree only if the currently navigated accessible is not root
michael@0 25 // accessible (i.e. if the accessible is part of text equivalent computation).
michael@0 26 eNameFromSubtreeIfReqRule = 0x01,
michael@0 27
michael@0 28 // Text equivalent computation from subtree is allowed.
michael@0 29 eNameFromSubtreeRule = 0x03,
michael@0 30
michael@0 31 // The accessible allows to append its value to text equivalent.
michael@0 32 // XXX: This is temporary solution. Once we move accessible value of links
michael@0 33 // and linkable accessibles to MSAA part we can remove this.
michael@0 34 eNameFromValueRule = 0x04
michael@0 35 };
michael@0 36
michael@0 37 /**
michael@0 38 * The class provides utils methods to compute the accessible name and
michael@0 39 * description.
michael@0 40 */
michael@0 41 class nsTextEquivUtils
michael@0 42 {
michael@0 43 public:
michael@0 44 typedef mozilla::a11y::Accessible Accessible;
michael@0 45
michael@0 46 /**
michael@0 47 * Determines if the accessible has a given name rule.
michael@0 48 *
michael@0 49 * @param aAccessible [in] the given accessible
michael@0 50 * @param aRule [in] a given name rule
michael@0 51 * @return true if the accessible has the rule
michael@0 52 */
michael@0 53 static inline bool HasNameRule(Accessible* aAccessible, ETextEquivRule aRule)
michael@0 54 {
michael@0 55 return (GetRoleRule(aAccessible->Role()) & aRule) == aRule;
michael@0 56 }
michael@0 57
michael@0 58 /**
michael@0 59 * Calculates the name from accessible subtree if allowed.
michael@0 60 *
michael@0 61 * @param aAccessible [in] the given accessible
michael@0 62 * @param aName [out] accessible name
michael@0 63 */
michael@0 64 static nsresult GetNameFromSubtree(Accessible* aAccessible,
michael@0 65 nsAString& aName);
michael@0 66
michael@0 67 /**
michael@0 68 * Calculates text equivalent from the subtree. Similar to GetNameFromSubtree.
michael@0 69 * However it returns not empty result for things like HTML p.
michael@0 70 */
michael@0 71 static void GetTextEquivFromSubtree(Accessible* aAccessible,
michael@0 72 nsString& aTextEquiv)
michael@0 73 {
michael@0 74 aTextEquiv.Truncate();
michael@0 75
michael@0 76 AppendFromAccessibleChildren(aAccessible, &aTextEquiv);
michael@0 77 aTextEquiv.CompressWhitespace();
michael@0 78 }
michael@0 79
michael@0 80 /**
michael@0 81 * Calculates text equivalent for the given accessible from its IDRefs
michael@0 82 * attribute (like aria-labelledby or aria-describedby).
michael@0 83 *
michael@0 84 * @param aAccessible [in] the accessible text equivalent is computed for
michael@0 85 * @param aIDRefsAttr [in] IDRefs attribute on DOM node of the accessible
michael@0 86 * @param aTextEquiv [out] result text equivalent
michael@0 87 */
michael@0 88 static nsresult GetTextEquivFromIDRefs(Accessible* aAccessible,
michael@0 89 nsIAtom *aIDRefsAttr,
michael@0 90 nsAString& aTextEquiv);
michael@0 91
michael@0 92 /**
michael@0 93 * Calculates the text equivalent from the given content and its subtree if
michael@0 94 * allowed and appends it to the given string.
michael@0 95 *
michael@0 96 * @param aInitiatorAcc [in] the accessible text equivalent is computed for
michael@0 97 * in the end (root accessible of text equivalent
michael@0 98 * calculation recursion)
michael@0 99 * @param aContent [in] the given content the text equivalent is
michael@0 100 * computed from
michael@0 101 * @param aString [in, out] the string
michael@0 102 */
michael@0 103 static nsresult AppendTextEquivFromContent(Accessible* aInitiatorAcc,
michael@0 104 nsIContent *aContent,
michael@0 105 nsAString *aString);
michael@0 106
michael@0 107 /**
michael@0 108 * Calculates the text equivalent from the given text content (may be text
michael@0 109 * node or html:br) and appends it to the given string.
michael@0 110 *
michael@0 111 * @param aContent [in] the text content
michael@0 112 * @param aString [in, out] the string
michael@0 113 */
michael@0 114 static nsresult AppendTextEquivFromTextContent(nsIContent *aContent,
michael@0 115 nsAString *aString);
michael@0 116
michael@0 117 private:
michael@0 118 /**
michael@0 119 * Iterates accessible children and calculates text equivalent from each
michael@0 120 * child.
michael@0 121 */
michael@0 122 static nsresult AppendFromAccessibleChildren(Accessible* aAccessible,
michael@0 123 nsAString *aString);
michael@0 124
michael@0 125 /**
michael@0 126 * Calculates text equivalent from the given accessible and its subtree if
michael@0 127 * allowed.
michael@0 128 */
michael@0 129 static nsresult AppendFromAccessible(Accessible* aAccessible,
michael@0 130 nsAString *aString);
michael@0 131
michael@0 132 /**
michael@0 133 * Calculates text equivalent from the value of given accessible.
michael@0 134 */
michael@0 135 static nsresult AppendFromValue(Accessible* aAccessible,
michael@0 136 nsAString *aString);
michael@0 137 /**
michael@0 138 * Iterates DOM children and calculates text equivalent from each child node.
michael@0 139 */
michael@0 140 static nsresult AppendFromDOMChildren(nsIContent *aContent,
michael@0 141 nsAString *aString);
michael@0 142
michael@0 143 /**
michael@0 144 * Calculates text equivalent from the given DOM node and its subtree if
michael@0 145 * allowed.
michael@0 146 */
michael@0 147 static nsresult AppendFromDOMNode(nsIContent *aContent, nsAString *aString);
michael@0 148
michael@0 149 /**
michael@0 150 * Concatenates strings and appends space between them. Returns true if
michael@0 151 * text equivalent string was appended.
michael@0 152 */
michael@0 153 static bool AppendString(nsAString *aString,
michael@0 154 const nsAString& aTextEquivalent);
michael@0 155
michael@0 156 /**
michael@0 157 * Returns the rule (constant of ETextEquivRule) for a given role.
michael@0 158 */
michael@0 159 static uint32_t GetRoleRule(mozilla::a11y::roles::Role aRole);
michael@0 160 };
michael@0 161
michael@0 162 #endif

mercurial