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/. */
8 #include "EmbeddedObjCollector.h"
9 #include "NotificationController.h"
14 #include "mozilla/UniquePtr.h"
16 using namespace mozilla
;
17 using namespace mozilla::a11y
;
19 ////////////////////////////////////////////////////////////////////////////////
22 TreeMutation::TreeMutation(LocalAccessible
* aParent
, bool aNoEvents
)
24 mStartIdx(UINT32_MAX
),
25 mStateFlagsCopy(mParent
->mStateFlags
),
26 mQueueEvents(!aNoEvents
) {
31 mParent
->mStateFlags
|= LocalAccessible::eKidsMutating
;
34 TreeMutation::~TreeMutation() {
35 MOZ_ASSERT(mIsDone
, "Done() must be called explicitly");
38 void TreeMutation::AfterInsertion(LocalAccessible
* aChild
) {
39 MOZ_ASSERT(aChild
->LocalParent() == mParent
);
41 if (static_cast<uint32_t>(aChild
->mIndexInParent
) < mStartIdx
) {
42 mStartIdx
= aChild
->mIndexInParent
+ 1;
49 RefPtr
<AccShowEvent
> ev
= new AccShowEvent(aChild
);
50 DebugOnly
<bool> added
= Controller()->QueueMutationEvent(ev
);
52 aChild
->SetShowEventTarget(true);
55 void TreeMutation::BeforeRemoval(LocalAccessible
* aChild
, bool aNoShutdown
) {
56 MOZ_ASSERT(aChild
->LocalParent() == mParent
);
58 if (static_cast<uint32_t>(aChild
->mIndexInParent
) < mStartIdx
) {
59 mStartIdx
= aChild
->mIndexInParent
;
66 RefPtr
<AccHideEvent
> ev
= new AccHideEvent(aChild
, !aNoShutdown
);
67 if (Controller()->QueueMutationEvent(ev
)) {
68 aChild
->SetHideEventTarget(true);
72 void TreeMutation::Done() {
73 MOZ_ASSERT(mParent
->mStateFlags
& LocalAccessible::eKidsMutating
);
74 mParent
->mStateFlags
&= ~LocalAccessible::eKidsMutating
;
76 uint32_t length
= mParent
->mChildren
.Length();
78 for (uint32_t idx
= 0; idx
< mStartIdx
&& idx
< length
; idx
++) {
80 mParent
->mChildren
[idx
]->mIndexInParent
== static_cast<int32_t>(idx
),
81 "Wrong index detected");
85 for (uint32_t idx
= mStartIdx
; idx
< length
; idx
++) {
86 mParent
->mChildren
[idx
]->mIndexOfEmbeddedChild
= -1;
89 for (uint32_t idx
= 0; idx
< length
; idx
++) {
90 mParent
->mChildren
[idx
]->mStateFlags
|= LocalAccessible::eGroupInfoDirty
;
93 mParent
->mEmbeddedObjCollector
= nullptr;
94 mParent
->mStateFlags
|= mStateFlagsCopy
& LocalAccessible::eKidsMutating
;