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_EventQueue_h_
7 #define mozilla_a11y_EventQueue_h_
8 
9 #include "AccEvent.h"
10 
11 namespace mozilla {
12 namespace a11y {
13 
14 class DocAccessible;
15 
16 /**
17  * Used to organize and coalesce pending events.
18  */
19 class EventQueue {
20  protected:
EventQueue(DocAccessible * aDocument)21   explicit EventQueue(DocAccessible* aDocument) : mDocument(aDocument) {}
22 
23   /**
24    * Put an accessible event into the queue to process it later.
25    */
26   bool PushEvent(AccEvent* aEvent);
27 
28   /**
29    * Puts name and/or description change events into the queue, if needed.
30    */
31   bool PushNameOrDescriptionChange(LocalAccessible* aTarget);
32 
33   /**
34    * Process events from the queue and fires events.
35    */
36   void ProcessEventQueue();
37 
38  private:
39   EventQueue(const EventQueue&) = delete;
40   EventQueue& operator=(const EventQueue&) = delete;
41 
42   // Event queue processing
43   /**
44    * Coalesce redundant events from the queue.
45    */
46   void CoalesceEvents();
47 
48   /**
49    * Coalesce events from the same subtree.
50    */
51   void CoalesceReorderEvents(AccEvent* aTailEvent);
52 
53   /**
54    * Coalesce two selection change events within the same select control.
55    */
56   void CoalesceSelChangeEvents(AccSelChangeEvent* aTailEvent,
57                                AccSelChangeEvent* aThisEvent,
58                                uint32_t aThisIndex);
59 
60  protected:
61   /**
62    * The document accessible reference owning this queue.
63    */
64   DocAccessible* mDocument;
65 
66   /**
67    * Pending events array. Don't make this an AutoTArray; we use
68    * SwapElements() on it.
69    */
70   nsTArray<RefPtr<AccEvent>> mEvents;
71 };
72 
73 }  // namespace a11y
74 }  // namespace mozilla
75 
76 #endif  // mozilla_a11y_EventQueue_h_
77