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