Bug 1687263: part 4) Defer and in some cases avoid removing spellchecking-ranges...
[gecko.git] / accessible / base / Pivot.h
blob147ed160b82ade08a29c688f77173bd559723717
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"
12 #include "AccessibleOrProxy.h"
14 namespace mozilla {
15 namespace a11y {
17 class LocalAccessible;
18 class HyperTextAccessible;
19 class DocAccessible;
21 class PivotRule {
22 public:
23 // A filtering function that returns a bitmask from
24 // nsIAccessibleTraversalRule: FILTER_IGNORE (0x0): Don't match this
25 // accessible. FILTER_MATCH (0x1): Match this accessible FILTER_IGNORE_SUBTREE
26 // (0x2): Ignore accessible's subtree.
27 virtual uint16_t Match(const AccessibleOrProxy& aAccOrProxy) = 0;
30 // The Pivot class is used for searching for accessible nodes in a given subtree
31 // with a given criteria. Since it only holds a weak reference to the root,
32 // this class is meant to be used primarily on the stack.
33 class Pivot final {
34 public:
35 explicit Pivot(const AccessibleOrProxy& aRoot);
36 Pivot() = delete;
37 Pivot(const Pivot&) = delete;
38 Pivot& operator=(const Pivot&) = delete;
40 ~Pivot();
42 // Return the next accessible after aAnchor in pre-order that matches the
43 // given rule. If aIncludeStart, return aAnchor if it matches the rule.
44 AccessibleOrProxy Next(AccessibleOrProxy& aAnchor, PivotRule& aRule,
45 bool aIncludeStart = false);
47 // Return the previous accessible before aAnchor in pre-order that matches the
48 // given rule. If aIncludeStart, return aAnchor if it matches the rule.
49 AccessibleOrProxy Prev(AccessibleOrProxy& aAnchor, PivotRule& aRule,
50 bool aIncludeStart = false);
52 // Return the first accessible within the root that matches the pivot rule.
53 AccessibleOrProxy First(PivotRule& aRule);
55 // Return the last accessible within the root that matches the pivot rule.
56 AccessibleOrProxy Last(PivotRule& aRule);
58 // Return the next range of text according to the boundary type.
59 LocalAccessible* NextText(LocalAccessible* aAnchor, int32_t* aStartOffset,
60 int32_t* aEndOffset, int32_t aBoundaryType);
62 // Return the previous range of text according to the boundary type.
63 LocalAccessible* PrevText(LocalAccessible* aAnchor, int32_t* aStartOffset,
64 int32_t* aEndOffset, int32_t aBoundaryType);
66 // Return the accessible at the given screen coordinate if it matches the
67 // pivot rule.
68 AccessibleOrProxy AtPoint(int32_t aX, int32_t aY, PivotRule& aRule);
70 private:
71 AccessibleOrProxy AdjustStartPosition(AccessibleOrProxy& aAnchor,
72 PivotRule& aRule,
73 uint16_t* aFilterResult);
75 // Search in preorder for the first accessible to match the rule.
76 AccessibleOrProxy SearchForward(AccessibleOrProxy& aAnchor, PivotRule& aRule,
77 bool aSearchCurrent);
79 // Reverse search in preorder for the first accessible to match the rule.
80 AccessibleOrProxy SearchBackward(AccessibleOrProxy& aAnchor, PivotRule& aRule,
81 bool aSearchCurrent);
83 // Search in preorder for the first text accessible.
84 HyperTextAccessible* SearchForText(LocalAccessible* aAnchor, bool aBackward);
86 AccessibleOrProxy mRoot;
89 /**
90 * This rule matches accessibles on a given role, filtering out non-direct
91 * descendants if necessary.
93 class PivotRoleRule : public PivotRule {
94 public:
95 explicit PivotRoleRule(role aRole);
96 explicit PivotRoleRule(role aRole, AccessibleOrProxy& aDirectDescendantsFrom);
98 virtual uint16_t Match(const AccessibleOrProxy& aAccOrProxy) override;
100 protected:
101 role mRole;
102 AccessibleOrProxy mDirectDescendantsFrom;
106 * This rule matches any local LocalAccessible (i.e. not RemoteAccessible) in
107 * the same document as the anchor. That is, it includes any descendant
108 * OuterDocAccessible, but not its descendants.
110 class LocalAccInSameDocRule : public PivotRule {
111 public:
112 virtual uint16_t Match(const AccessibleOrProxy& aAccOrProxy) override;
115 } // namespace a11y
116 } // namespace mozilla
118 #endif // mozilla_a11y_Pivot_h_