no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / accessible / base / EventTree.cpp
blob29cf66e4932a1b7f851b6944b90c7166e5a8d375
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/. */
6 #include "EventTree.h"
8 #include "EmbeddedObjCollector.h"
9 #include "NotificationController.h"
10 #ifdef A11Y_LOG
11 # include "Logging.h"
12 #endif
14 #include "mozilla/UniquePtr.h"
16 using namespace mozilla;
17 using namespace mozilla::a11y;
19 ////////////////////////////////////////////////////////////////////////////////
20 // TreeMutation class
22 TreeMutation::TreeMutation(LocalAccessible* aParent, bool aNoEvents)
23 : mParent(aParent),
24 mStartIdx(UINT32_MAX),
25 mStateFlagsCopy(mParent->mStateFlags),
26 mQueueEvents(!aNoEvents) {
27 #ifdef DEBUG
28 mIsDone = false;
29 #endif
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;
45 if (!mQueueEvents) {
46 return;
49 RefPtr<AccShowEvent> ev = new AccShowEvent(aChild);
50 DebugOnly<bool> added = Controller()->QueueMutationEvent(ev);
51 MOZ_ASSERT(added);
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;
62 if (!mQueueEvents) {
63 return;
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();
77 #ifdef DEBUG
78 for (uint32_t idx = 0; idx < mStartIdx && idx < length; idx++) {
79 MOZ_ASSERT(
80 mParent->mChildren[idx]->mIndexInParent == static_cast<int32_t>(idx),
81 "Wrong index detected");
83 #endif
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;
96 #ifdef DEBUG
97 mIsDone = true;
98 #endif