Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef _nsAccessiblePivot_H_
8 : #define _nsAccessiblePivot_H_
9 :
10 : #include "nsIAccessiblePivot.h"
11 :
12 : #include "Accessible-inl.h"
13 : #include "nsTObserverArray.h"
14 : #include "nsCycleCollectionParticipant.h"
15 : #include "mozilla/Attributes.h"
16 :
17 : class RuleCache;
18 :
19 : /**
20 : * Class represents an accessible pivot.
21 : */
22 : class nsAccessiblePivot final : public nsIAccessiblePivot
23 : {
24 : public:
25 : typedef mozilla::a11y::Accessible Accessible;
26 :
27 : explicit nsAccessiblePivot(Accessible* aRoot);
28 :
29 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
30 0 : NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsAccessiblePivot, nsIAccessiblePivot)
31 :
32 : NS_DECL_NSIACCESSIBLEPIVOT
33 :
34 : /*
35 : * A simple getter for the pivot's position.
36 : */
37 : Accessible* Position() { return mPosition; }
38 :
39 : private:
40 : ~nsAccessiblePivot();
41 : nsAccessiblePivot() = delete;
42 : nsAccessiblePivot(const nsAccessiblePivot&) = delete;
43 : void operator = (const nsAccessiblePivot&) = delete;
44 :
45 : /*
46 : * Notify all observers on a pivot change. Return true if it has changed and
47 : * observers have been notified.
48 : */
49 : bool NotifyOfPivotChange(Accessible* aOldAccessible,
50 : int32_t aOldStart, int32_t aOldEnd,
51 : PivotMoveReason aReason,
52 : bool aIsFromUserInput);
53 :
54 : /*
55 : * Check to see that the given accessible is a descendant of given ancestor
56 : */
57 : bool IsDescendantOf(Accessible* aAccessible, Accessible* aAncestor);
58 :
59 :
60 : /*
61 : * Search in preorder for the first accessible to match the rule.
62 : */
63 : Accessible* SearchForward(Accessible* aAccessible,
64 : nsIAccessibleTraversalRule* aRule,
65 : bool aSearchCurrent,
66 : nsresult* aResult);
67 :
68 : /*
69 : * Reverse search in preorder for the first accessible to match the rule.
70 : */
71 : Accessible* SearchBackward(Accessible* aAccessible,
72 : nsIAccessibleTraversalRule* aRule,
73 : bool aSearchCurrent,
74 : nsresult* aResult);
75 :
76 : /*
77 : * Search in preorder for the first text accessible.
78 : */
79 : mozilla::a11y::HyperTextAccessible* SearchForText(Accessible* aAccessible,
80 : bool aBackward);
81 :
82 : /*
83 : * Get the effective root for this pivot, either the true root or modal root.
84 : */
85 0 : Accessible* GetActiveRoot() const
86 : {
87 0 : if (mModalRoot) {
88 0 : NS_ENSURE_FALSE(mModalRoot->IsDefunct(), mRoot);
89 0 : return mModalRoot;
90 : }
91 :
92 0 : return mRoot;
93 : }
94 :
95 : /*
96 : * Update the pivot, and notify observers. Return true if it moved.
97 : */
98 : bool MovePivotInternal(Accessible* aPosition, PivotMoveReason aReason,
99 : bool aIsFromUserInput);
100 :
101 : /*
102 : * Get initial node we should start a search from with a given rule.
103 : *
104 : * When we do a move operation from one position to another,
105 : * the initial position can be inside of a subtree that is ignored by
106 : * the given rule. We need to step out of the ignored subtree and start
107 : * the search from there.
108 : *
109 : */
110 : Accessible* AdjustStartPosition(Accessible* aAccessible, RuleCache& aCache,
111 : uint16_t* aFilterResult, nsresult* aResult);
112 :
113 : /*
114 : * The root accessible.
115 : */
116 : RefPtr<Accessible> mRoot;
117 :
118 : /*
119 : * The temporary modal root accessible.
120 : */
121 : RefPtr<Accessible> mModalRoot;
122 :
123 : /*
124 : * The current pivot position.
125 : */
126 : RefPtr<Accessible> mPosition;
127 :
128 : /*
129 : * The text start offset ofthe pivot.
130 : */
131 : int32_t mStartOffset;
132 :
133 : /*
134 : * The text end offset ofthe pivot.
135 : */
136 : int32_t mEndOffset;
137 :
138 : /*
139 : * The list of pivot-changed observers.
140 : */
141 : nsTObserverArray<nsCOMPtr<nsIAccessiblePivotObserver> > mObservers;
142 : };
143 :
144 : #endif
|