EventTree.cpp (2700B)
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 #include "EventTree.h" 7 8 #include "EmbeddedObjCollector.h" 9 #include "NotificationController.h" 10 #ifdef A11Y_LOG 11 # include "Logging.h" 12 #endif 13 14 using namespace mozilla; 15 using namespace mozilla::a11y; 16 17 //////////////////////////////////////////////////////////////////////////////// 18 // TreeMutation class 19 20 TreeMutation::TreeMutation(LocalAccessible* aParent, bool aNoEvents) 21 : mParent(aParent), 22 mStartIdx(UINT32_MAX), 23 mStateFlagsCopy(mParent->mStateFlags), 24 mQueueEvents(!aNoEvents) { 25 #ifdef DEBUG 26 mIsDone = false; 27 #endif 28 29 mParent->mStateFlags |= LocalAccessible::eKidsMutating; 30 } 31 32 TreeMutation::~TreeMutation() { 33 MOZ_ASSERT(mIsDone, "Done() must be called explicitly"); 34 } 35 36 void TreeMutation::AfterInsertion(LocalAccessible* aChild) { 37 MOZ_ASSERT(aChild->LocalParent() == mParent); 38 39 if (static_cast<uint32_t>(aChild->mIndexInParent) < mStartIdx) { 40 mStartIdx = aChild->mIndexInParent + 1; 41 } 42 43 if (!mQueueEvents) { 44 return; 45 } 46 47 RefPtr<AccShowEvent> ev = new AccShowEvent(aChild); 48 DebugOnly<bool> added = Controller()->QueueMutationEvent(ev); 49 MOZ_ASSERT(added); 50 aChild->SetShowEventTarget(true); 51 } 52 53 void TreeMutation::BeforeRemoval(LocalAccessible* aChild, bool aNoShutdown) { 54 MOZ_ASSERT(aChild->LocalParent() == mParent); 55 56 if (static_cast<uint32_t>(aChild->mIndexInParent) < mStartIdx) { 57 mStartIdx = aChild->mIndexInParent; 58 } 59 60 if (!mQueueEvents) { 61 return; 62 } 63 64 RefPtr<AccHideEvent> ev = new AccHideEvent(aChild, !aNoShutdown); 65 if (Controller()->QueueMutationEvent(ev)) { 66 aChild->SetHideEventTarget(true); 67 } 68 } 69 70 void TreeMutation::Done() { 71 MOZ_ASSERT(mParent->mStateFlags & LocalAccessible::eKidsMutating); 72 mParent->mStateFlags &= ~LocalAccessible::eKidsMutating; 73 74 uint32_t length = mParent->mChildren.Length(); 75 #ifdef DEBUG 76 for (uint32_t idx = 0; idx < mStartIdx && idx < length; idx++) { 77 MOZ_ASSERT( 78 mParent->mChildren[idx]->mIndexInParent == static_cast<int32_t>(idx), 79 "Wrong index detected"); 80 } 81 #endif 82 83 for (uint32_t idx = mStartIdx; idx < length; idx++) { 84 mParent->mChildren[idx]->mIndexOfEmbeddedChild = -1; 85 } 86 87 for (uint32_t idx = 0; idx < length; idx++) { 88 mParent->mChildren[idx]->mStateFlags |= LocalAccessible::eGroupInfoDirty; 89 } 90 91 mParent->mEmbeddedObjCollector = nullptr; 92 mParent->mStateFlags |= mStateFlagsCopy & LocalAccessible::eKidsMutating; 93 94 #ifdef DEBUG 95 mIsDone = true; 96 #endif 97 }