summaryrefslogtreecommitdiff
path: root/accessible/base/EventTree.h
blob: cdb5e8911bba8e26f463801ede56ffbdff0efd51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_a11y_EventTree_h_
#define mozilla_a11y_EventTree_h_

#include "AccEvent.h"
#include "Accessible.h"
#include "DocAccessible.h"

#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h"

namespace mozilla {
namespace a11y {

/**
 * This class makes sure required tasks are done before and after tree
 * mutations. Currently this only includes group info invalidation. You must
 * have an object of this class on the stack when calling methods that mutate
 * the accessible tree.
 */
class TreeMutation final
{
public:
  static const bool kNoEvents = true;
  static const bool kNoShutdown = true;

  explicit TreeMutation(Accessible* aParent, bool aNoEvents = false);
  ~TreeMutation();

  void AfterInsertion(Accessible* aChild);
  void BeforeRemoval(Accessible* aChild, bool aNoShutdown = false);
  void Done();

private:
  NotificationController* Controller() const
    { return mParent->Document()->Controller(); }

  static EventTree* const kNoEventTree;

#ifdef A11Y_LOG
  static const char* PrefixLog(void* aData, Accessible*);
#endif

  Accessible* mParent;
  uint32_t mStartIdx;
  uint32_t mStateFlagsCopy;

  /*
   * True if mutation events should be queued.
   */
  bool mQueueEvents;

#ifdef DEBUG
  bool mIsDone;
#endif
};


/**
 * A mutation events coalescence structure.
 */
class EventTree final {
public:
  EventTree() :
    mFirst(nullptr), mNext(nullptr), mContainer(nullptr), mFireReorder(false) { }
  explicit EventTree(Accessible* aContainer, bool aFireReorder) :
    mFirst(nullptr), mNext(nullptr), mContainer(aContainer),
    mFireReorder(aFireReorder) { }
  ~EventTree() { Clear(); }

  void Shown(Accessible* aTarget);
  void Hidden(Accessible*, bool);

  /**
   * Return an event tree node for the given accessible.
   */
  const EventTree* Find(const Accessible* aContainer) const;

  /**
   * Add a mutation event to this event tree.
   */
  void Mutated(AccMutationEvent* aEv);

#ifdef A11Y_LOG
  void Log(uint32_t aLevel = UINT32_MAX) const;
#endif

private:
  /**
   * Processes the event queue and fires events.
   */
  void Process(const RefPtr<DocAccessible>& aDeathGrip);

  /**
   * Return an event subtree for the given accessible.
   */
  EventTree* FindOrInsert(Accessible* aContainer);

  void Clear();

  UniquePtr<EventTree> mFirst;
  UniquePtr<EventTree> mNext;

  Accessible* mContainer;
  nsTArray<RefPtr<AccMutationEvent>> mDependentEvents;
  bool mFireReorder;

  static NotificationController* Controller(Accessible* aAcc)
    { return aAcc->Document()->Controller(); }

  friend class NotificationController;
};


} // namespace a11y
} // namespace mozilla

#endif // mozilla_a11y_EventQueue_h_