Pivot.h (4518B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef mozilla_a11y_Pivot_h_ 7 #define mozilla_a11y_Pivot_h_ 8 9 #include <stdint.h> 10 #include "mozilla/a11y/Role.h" 11 #include "mozilla/dom/ChildIterator.h" 12 13 namespace mozilla { 14 namespace a11y { 15 16 class DocAccessible; 17 class Accessible; 18 19 class PivotRule { 20 public: 21 // A filtering function that returns a bitmask from 22 // nsIAccessibleTraversalRule: FILTER_IGNORE (0x0): Don't match this 23 // accessible. FILTER_MATCH (0x1): Match this accessible FILTER_IGNORE_SUBTREE 24 // (0x2): Ignore accessible's subtree. 25 virtual uint16_t Match(Accessible* aAcc) = 0; 26 }; 27 28 // The Pivot class is used for searching for accessible nodes in a given subtree 29 // with a given criteria. Since it only holds a weak reference to the root, 30 // this class is meant to be used primarily on the stack. 31 class Pivot final { 32 public: 33 explicit Pivot(Accessible* aRoot); 34 Pivot() = delete; 35 Pivot(const Pivot&) = delete; 36 Pivot& operator=(const Pivot&) = delete; 37 38 ~Pivot(); 39 40 // Return the next accessible after aAnchor in pre-order that matches the 41 // given rule. If aIncludeStart, return aAnchor if it matches the rule. 42 Accessible* Next(Accessible* aAnchor, PivotRule& aRule, 43 bool aIncludeStart = false); 44 45 // Return the previous accessible before aAnchor in pre-order that matches the 46 // given rule. If aIncludeStart, return aAnchor if it matches the rule. 47 Accessible* Prev(Accessible* aAnchor, PivotRule& aRule, 48 bool aIncludeStart = false); 49 50 // Return the first accessible within the root that matches the pivot rule. 51 Accessible* First(PivotRule& aRule); 52 53 // Return the last accessible within the root that matches the pivot rule. 54 Accessible* Last(PivotRule& aRule); 55 56 // Return the accessible at the given screen coordinate if it matches the 57 // pivot rule. 58 Accessible* AtPoint(int32_t aX, int32_t aY, PivotRule& aRule); 59 60 private: 61 Accessible* AdjustStartPosition(Accessible* aAnchor, PivotRule& aRule, 62 uint16_t* aFilterResult); 63 64 // Search in preorder for the first accessible to match the rule. 65 Accessible* SearchForward(Accessible* aAnchor, PivotRule& aRule, 66 bool aSearchCurrent); 67 68 // Reverse search in preorder for the first accessible to match the rule. 69 Accessible* SearchBackward(Accessible* aAnchor, PivotRule& aRule, 70 bool aSearchCurrent); 71 72 Accessible* mRoot; 73 }; 74 75 /** 76 * This rule matches accessibles on a given role, filtering out non-direct 77 * descendants if necessary. 78 */ 79 class PivotRoleRule : public PivotRule { 80 public: 81 explicit PivotRoleRule(role aRole); 82 explicit PivotRoleRule(role aRole, Accessible* aDirectDescendantsFrom); 83 84 virtual uint16_t Match(Accessible* aAcc) override; 85 86 protected: 87 role mRole; 88 Accessible* mDirectDescendantsFrom; 89 }; 90 91 /** 92 * This rule matches Accessibles with an explicit value for aria-selected. 93 */ 94 class PivotARIASelectedRule : public PivotRule { 95 public: 96 virtual uint16_t Match(Accessible* aAcc) override; 97 }; 98 99 /** 100 * This rule matches accessibles with a given state. 101 */ 102 class PivotStateRule : public PivotRule { 103 public: 104 explicit PivotStateRule(uint64_t aState); 105 106 virtual uint16_t Match(Accessible* aAcc) override; 107 108 protected: 109 uint64_t mState; 110 }; 111 112 /** 113 * This rule matches any local LocalAccessible (i.e. not RemoteAccessible) in 114 * the same document as the anchor. That is, it includes any descendant 115 * OuterDocAccessible, but not its descendants. 116 */ 117 class LocalAccInSameDocRule : public PivotRule { 118 public: 119 virtual uint16_t Match(Accessible* aAcc) override; 120 }; 121 122 /** 123 * This rule matches remote radio button accessibles with the given name 124 * attribute. It assumes the cache is enabled. 125 */ 126 class PivotRadioNameRule : public PivotRule { 127 public: 128 explicit PivotRadioNameRule(const nsString& aName); 129 130 virtual uint16_t Match(Accessible* aAcc) override; 131 132 protected: 133 const nsString& mName; 134 }; 135 136 /** 137 * This rule doesn't search iframes. Subtrees that should be 138 * pruned by way of nsAccUtils::MustPrune are also not searched. 139 */ 140 141 class MustPruneSameDocRule : public PivotRule { 142 public: 143 virtual uint16_t Match(Accessible* aAcc) override; 144 }; 145 146 } // namespace a11y 147 } // namespace mozilla 148 149 #endif // mozilla_a11y_Pivot_h_