Bug 1769547 - Do not MOZ_CRASH() on missing process r=nika
[gecko.git] / accessible / base / Pivot.h
blobdda7bc32880439e8659fb4a35032a47c82847d8b
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/. */
6 #ifndef mozilla_a11y_Pivot_h_
7 #define mozilla_a11y_Pivot_h_
9 #include <stdint.h>
10 #include "Role.h"
11 #include "mozilla/dom/ChildIterator.h"
13 namespace mozilla {
14 namespace a11y {
16 class DocAccessible;
17 class Accessible;
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;
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;
38 ~Pivot();
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);
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);
50 // Return the first accessible within the root that matches the pivot rule.
51 Accessible* First(PivotRule& aRule);
53 // Return the last accessible within the root that matches the pivot rule.
54 Accessible* Last(PivotRule& aRule);
56 // Return the next range of text according to the boundary type.
57 Accessible* NextText(Accessible* aAnchor, int32_t* aStartOffset,
58 int32_t* aEndOffset, int32_t aBoundaryType);
60 // Return the previous range of text according to the boundary type.
61 Accessible* PrevText(Accessible* aAnchor, int32_t* aStartOffset,
62 int32_t* aEndOffset, int32_t aBoundaryType);
64 // Return the accessible at the given screen coordinate if it matches the
65 // pivot rule.
66 Accessible* AtPoint(int32_t aX, int32_t aY, PivotRule& aRule);
68 private:
69 Accessible* AdjustStartPosition(Accessible* aAnchor, PivotRule& aRule,
70 uint16_t* aFilterResult);
72 // Search in preorder for the first accessible to match the rule.
73 Accessible* SearchForward(Accessible* aAnchor, PivotRule& aRule,
74 bool aSearchCurrent);
76 // Reverse search in preorder for the first accessible to match the rule.
77 Accessible* SearchBackward(Accessible* aAnchor, PivotRule& aRule,
78 bool aSearchCurrent);
80 // Search in preorder for the first text accessible.
81 Accessible* SearchForText(Accessible* aAnchor, bool aBackward);
83 Accessible* mRoot;
86 /**
87 * This rule matches accessibles on a given role, filtering out non-direct
88 * descendants if necessary.
90 class PivotRoleRule : public PivotRule {
91 public:
92 explicit PivotRoleRule(role aRole);
93 explicit PivotRoleRule(role aRole, Accessible* aDirectDescendantsFrom);
95 virtual uint16_t Match(Accessible* aAcc) override;
97 protected:
98 role mRole;
99 Accessible* mDirectDescendantsFrom;
103 * This rule matches accessibles with a given state.
105 class PivotStateRule : public PivotRule {
106 public:
107 explicit PivotStateRule(uint64_t aState);
109 virtual uint16_t Match(Accessible* aAcc) override;
111 protected:
112 uint64_t mState;
116 * This rule matches any local LocalAccessible (i.e. not RemoteAccessible) in
117 * the same document as the anchor. That is, it includes any descendant
118 * OuterDocAccessible, but not its descendants.
120 class LocalAccInSameDocRule : public PivotRule {
121 public:
122 virtual uint16_t Match(Accessible* aAcc) override;
125 } // namespace a11y
126 } // namespace mozilla
128 #endif // mozilla_a11y_Pivot_h_