Line data Source code
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_EventTree_h_
7 : #define mozilla_a11y_EventTree_h_
8 :
9 : #include "AccEvent.h"
10 : #include "Accessible.h"
11 :
12 : #include "mozilla/RefPtr.h"
13 : #include "mozilla/UniquePtr.h"
14 :
15 : namespace mozilla {
16 : namespace a11y {
17 :
18 : /**
19 : * This class makes sure required tasks are done before and after tree
20 : * mutations. Currently this only includes group info invalidation. You must
21 : * have an object of this class on the stack when calling methods that mutate
22 : * the accessible tree.
23 : */
24 : class TreeMutation final
25 : {
26 : public:
27 : static const bool kNoEvents = true;
28 : static const bool kNoShutdown = true;
29 :
30 : explicit TreeMutation(Accessible* aParent, bool aNoEvents = false);
31 : ~TreeMutation();
32 :
33 : void AfterInsertion(Accessible* aChild);
34 : void BeforeRemoval(Accessible* aChild, bool aNoShutdown = false);
35 : void Done();
36 :
37 : private:
38 0 : NotificationController* Controller() const
39 0 : { return mParent->Document()->Controller(); }
40 :
41 : static EventTree* const kNoEventTree;
42 :
43 : #ifdef A11Y_LOG
44 : static const char* PrefixLog(void* aData, Accessible*);
45 : #endif
46 :
47 : Accessible* mParent;
48 : uint32_t mStartIdx;
49 : uint32_t mStateFlagsCopy;
50 :
51 : /*
52 : * True if mutation events should be queued.
53 : */
54 : bool mQueueEvents;
55 :
56 : #ifdef DEBUG
57 : bool mIsDone;
58 : #endif
59 : };
60 :
61 :
62 : /**
63 : * A mutation events coalescence structure.
64 : */
65 : class EventTree final {
66 : public:
67 0 : EventTree() :
68 0 : mFirst(nullptr), mNext(nullptr), mContainer(nullptr), mFireReorder(false) { }
69 0 : explicit EventTree(Accessible* aContainer, bool aFireReorder) :
70 : mFirst(nullptr), mNext(nullptr), mContainer(aContainer),
71 0 : mFireReorder(aFireReorder) { }
72 0 : ~EventTree() { Clear(); }
73 :
74 : void Shown(Accessible* aTarget);
75 : void Hidden(Accessible*, bool);
76 :
77 : /**
78 : * Return an event tree node for the given accessible.
79 : */
80 : const EventTree* Find(const Accessible* aContainer) const;
81 :
82 : /**
83 : * Add a mutation event to this event tree.
84 : */
85 : void Mutated(AccMutationEvent* aEv);
86 :
87 : #ifdef A11Y_LOG
88 : void Log(uint32_t aLevel = UINT32_MAX) const;
89 : #endif
90 :
91 : private:
92 : /**
93 : * Processes the event queue and fires events.
94 : */
95 : void Process(const RefPtr<DocAccessible>& aDeathGrip);
96 :
97 : /**
98 : * Return an event subtree for the given accessible.
99 : */
100 : EventTree* FindOrInsert(Accessible* aContainer);
101 :
102 : void Clear();
103 :
104 : UniquePtr<EventTree> mFirst;
105 : UniquePtr<EventTree> mNext;
106 :
107 : Accessible* mContainer;
108 : nsTArray<RefPtr<AccMutationEvent>> mDependentEvents;
109 : bool mFireReorder;
110 :
111 0 : static NotificationController* Controller(Accessible* aAcc)
112 0 : { return aAcc->Document()->Controller(); }
113 :
114 : friend class NotificationController;
115 : };
116 :
117 :
118 : } // namespace a11y
119 : } // namespace mozilla
120 :
121 : #endif // mozilla_a11y_EventQueue_h_
|