2011-01-18 11:03:38 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-01-18 11:03:38 +03:00
|
|
|
|
2011-01-31 18:53:09 +03:00
|
|
|
#include "NotificationController.h"
|
2011-01-18 11:03:38 +03:00
|
|
|
|
2012-12-27 08:25:27 +04:00
|
|
|
#include "DocAccessible-inl.h"
|
2014-03-08 01:35:19 +04:00
|
|
|
#include "DocAccessibleChild.h"
|
2012-05-23 22:05:57 +04:00
|
|
|
#include "TextLeafAccessible.h"
|
2011-02-08 07:48:41 +03:00
|
|
|
#include "TextUpdater.h"
|
2011-09-28 05:46:11 +04:00
|
|
|
|
2015-05-21 20:04:58 +03:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-07-21 00:23:38 +04:00
|
|
|
#include "mozilla/Telemetry.h"
|
2011-01-18 11:03:38 +03:00
|
|
|
|
2012-07-21 00:23:38 +04:00
|
|
|
using namespace mozilla;
|
2011-09-28 05:46:11 +04:00
|
|
|
using namespace mozilla::a11y;
|
2011-01-18 11:03:38 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// NotificationCollector
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
NotificationController::NotificationController(DocAccessible* aDocument,
|
2011-01-18 11:03:38 +03:00
|
|
|
nsIPresShell* aPresShell) :
|
2013-01-29 14:00:58 +04:00
|
|
|
EventQueue(aDocument), mObservingState(eNotObservingRefresh),
|
2016-11-11 06:12:32 +03:00
|
|
|
mPresShell(aPresShell), mEventGeneration(0)
|
2011-01-18 11:03:38 +03:00
|
|
|
{
|
2016-09-29 22:44:18 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
mMoveGuardOnStack = false;
|
|
|
|
#endif
|
|
|
|
|
2011-01-24 05:58:00 +03:00
|
|
|
// Schedule initial accessible tree construction.
|
|
|
|
ScheduleProcessing();
|
2011-01-18 11:03:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NotificationController::~NotificationController()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mDocument, "Controller wasn't shutdown properly!");
|
|
|
|
if (mDocument)
|
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// NotificationCollector: AddRef/Release and cycle collection
|
|
|
|
|
2012-08-24 20:50:06 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_NATIVE_ADDREF(NotificationController)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_NATIVE_RELEASE(NotificationController)
|
2011-01-18 11:03:38 +03:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(NotificationController)
|
|
|
|
|
2012-11-22 21:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(NotificationController)
|
2011-02-01 19:08:28 +03:00
|
|
|
if (tmp->mDocument)
|
|
|
|
tmp->Shutdown();
|
2011-01-18 11:03:38 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2012-11-22 21:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(NotificationController)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mHangingChildDocuments)
|
2016-02-18 17:31:42 +03:00
|
|
|
for (auto it = tmp->mContentInsertions.ConstIter(); !it.Done(); it.Next()) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mContentInsertions key");
|
|
|
|
cb.NoteXPCOMChild(it.Key());
|
|
|
|
nsTArray<nsCOMPtr<nsIContent>>* list = it.UserData();
|
|
|
|
for (uint32_t i = 0; i < list->Length(); i++) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,
|
|
|
|
"mContentInsertions value item");
|
|
|
|
cb.NoteXPCOMChild(list->ElementAt(i));
|
|
|
|
}
|
|
|
|
}
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEvents)
|
2015-10-30 01:08:48 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRelocations)
|
2011-01-18 11:03:38 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(NotificationController, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(NotificationController, Release)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// NotificationCollector: public
|
|
|
|
|
|
|
|
void
|
|
|
|
NotificationController::Shutdown()
|
|
|
|
{
|
|
|
|
if (mObservingState != eNotObservingRefresh &&
|
2017-01-05 10:31:56 +03:00
|
|
|
mPresShell->RemoveRefreshObserver(this, FlushType::Display)) {
|
2011-01-18 11:03:38 +03:00
|
|
|
mObservingState = eNotObservingRefresh;
|
|
|
|
}
|
|
|
|
|
2011-01-26 09:35:51 +03:00
|
|
|
// Shutdown handling child documents.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t childDocCount = mHangingChildDocuments.Length();
|
|
|
|
for (int32_t idx = childDocCount - 1; idx >= 0; idx--) {
|
2012-03-15 00:37:50 +04:00
|
|
|
if (!mHangingChildDocuments[idx]->IsDefunct())
|
|
|
|
mHangingChildDocuments[idx]->Shutdown();
|
|
|
|
}
|
2011-01-26 09:35:51 +03:00
|
|
|
|
|
|
|
mHangingChildDocuments.Clear();
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocument = nullptr;
|
|
|
|
mPresShell = nullptr;
|
2011-01-26 09:35:51 +03:00
|
|
|
|
2011-01-28 11:42:22 +03:00
|
|
|
mTextHash.Clear();
|
2011-01-18 11:03:38 +03:00
|
|
|
mContentInsertions.Clear();
|
|
|
|
mNotifications.Clear();
|
|
|
|
mEvents.Clear();
|
2015-10-30 01:08:48 +03:00
|
|
|
mRelocations.Clear();
|
2016-04-07 16:30:22 +03:00
|
|
|
mEventTree.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
EventTree*
|
|
|
|
NotificationController::QueueMutation(Accessible* aContainer)
|
|
|
|
{
|
|
|
|
EventTree* tree = mEventTree.FindOrInsert(aContainer);
|
|
|
|
if (tree) {
|
|
|
|
ScheduleProcessing();
|
|
|
|
}
|
|
|
|
return tree;
|
2011-01-18 11:03:38 +03:00
|
|
|
}
|
|
|
|
|
2016-11-11 06:12:32 +03:00
|
|
|
bool
|
|
|
|
NotificationController::QueueMutationEvent(AccTreeMutationEvent* aEvent)
|
|
|
|
{
|
|
|
|
// We have to allow there to be a hide and then a show event for a target
|
|
|
|
// because of targets getting moved. However we need to coalesce a show and
|
|
|
|
// then a hide for a target which means we need to check for that here.
|
|
|
|
if (aEvent->GetEventType() == nsIAccessibleEvent::EVENT_HIDE &&
|
|
|
|
aEvent->GetAccessible()->ShowEventTarget()) {
|
|
|
|
AccTreeMutationEvent* showEvent = mMutationMap.GetEvent(aEvent->GetAccessible(), EventMap::ShowEvent);
|
|
|
|
DropMutationEvent(showEvent);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AccMutationEvent* mutEvent = downcast_accEvent(aEvent);
|
|
|
|
mEventGeneration++;
|
|
|
|
mutEvent->SetEventGeneration(mEventGeneration);
|
|
|
|
|
|
|
|
if (!mFirstMutationEvent) {
|
|
|
|
mFirstMutationEvent = aEvent;
|
|
|
|
ScheduleProcessing();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mLastMutationEvent) {
|
|
|
|
NS_ASSERTION(!mLastMutationEvent->NextEvent(), "why isn't the last event the end?");
|
|
|
|
mLastMutationEvent->SetNextEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
aEvent->SetPrevEvent(mLastMutationEvent);
|
|
|
|
mLastMutationEvent = aEvent;
|
|
|
|
mMutationMap.PutEvent(aEvent);
|
|
|
|
|
|
|
|
// Because we could be hiding the target of a show event we need to get rid
|
|
|
|
// of any such events. It may be possible to do less than coallesce all
|
|
|
|
// events, however that is easiest.
|
|
|
|
if (aEvent->GetEventType() == nsIAccessibleEvent::EVENT_HIDE) {
|
|
|
|
CoalesceMutationEvents();
|
|
|
|
|
|
|
|
// mLastMutationEvent will point to something other than aEvent if and only
|
|
|
|
// if aEvent was just coalesced away. In that case a parent accessible
|
|
|
|
// must already have the required reorder and text change events so we are
|
|
|
|
// done here.
|
|
|
|
if (mLastMutationEvent != aEvent) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to fire a reorder event after all of the events targeted at shown or
|
|
|
|
// hidden children of a container. So either queue a new one, or move an
|
|
|
|
// existing one to the end of the queue if the container already has a
|
|
|
|
// reorder event.
|
|
|
|
Accessible* target = aEvent->GetAccessible();
|
|
|
|
Accessible* container = aEvent->GetAccessible()->Parent();
|
|
|
|
RefPtr<AccReorderEvent> reorder;
|
|
|
|
if (!container->ReorderEventTarget()) {
|
|
|
|
reorder = new AccReorderEvent(container);
|
|
|
|
container->SetReorderEventTarget(true);
|
|
|
|
mMutationMap.PutEvent(reorder);
|
|
|
|
|
|
|
|
// Since this is the first child of container that is changing, the name of
|
|
|
|
// container may be changing.
|
|
|
|
QueueNameChange(target);
|
|
|
|
} else {
|
|
|
|
AccReorderEvent* event = downcast_accEvent(mMutationMap.GetEvent(container, EventMap::ReorderEvent));
|
|
|
|
reorder = event;
|
|
|
|
if (mFirstMutationEvent == event) {
|
|
|
|
mFirstMutationEvent = event->NextEvent();
|
|
|
|
} else {
|
|
|
|
event->PrevEvent()->SetNextEvent(event->NextEvent());
|
|
|
|
}
|
|
|
|
|
|
|
|
event->NextEvent()->SetPrevEvent(event->PrevEvent());
|
|
|
|
event->SetNextEvent(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
reorder->SetEventGeneration(mEventGeneration);
|
|
|
|
reorder->SetPrevEvent(mLastMutationEvent);
|
|
|
|
mLastMutationEvent->SetNextEvent(reorder);
|
|
|
|
mLastMutationEvent = reorder;
|
|
|
|
|
|
|
|
// It is not possible to have a text change event for something other than a
|
|
|
|
// hyper text accessible.
|
|
|
|
if (!container->IsHyperText()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mutEvent);
|
|
|
|
|
|
|
|
nsString text;
|
|
|
|
aEvent->GetAccessible()->AppendTextTo(text);
|
|
|
|
if (text.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t offset = container->AsHyperText()->GetChildOffset(target);
|
|
|
|
AccTreeMutationEvent* prevEvent = aEvent->PrevEvent();
|
|
|
|
while (prevEvent && prevEvent->GetEventType() == nsIAccessibleEvent::EVENT_REORDER) {
|
|
|
|
prevEvent = prevEvent->PrevEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prevEvent && prevEvent->GetEventType() == nsIAccessibleEvent::EVENT_HIDE &&
|
|
|
|
mutEvent->IsHide()) {
|
|
|
|
AccHideEvent* prevHide = downcast_accEvent(prevEvent);
|
|
|
|
AccTextChangeEvent* prevTextChange = prevHide->mTextChangeEvent;
|
2017-01-19 23:13:54 +03:00
|
|
|
if (prevTextChange && prevHide->Parent() == mutEvent->Parent()) {
|
2016-11-11 06:12:32 +03:00
|
|
|
if (prevHide->mNextSibling == target) {
|
|
|
|
target->AppendTextTo(prevTextChange->mModifiedText);
|
2017-01-20 00:35:17 +03:00
|
|
|
prevHide->mTextChangeEvent.swap(mutEvent->mTextChangeEvent);
|
2016-11-11 06:12:32 +03:00
|
|
|
} else if (prevHide->mPrevSibling == target) {
|
|
|
|
nsString temp;
|
|
|
|
target->AppendTextTo(temp);
|
|
|
|
|
|
|
|
uint32_t extraLen = temp.Length();
|
|
|
|
temp += prevTextChange->mModifiedText;;
|
|
|
|
prevTextChange->mModifiedText = temp;
|
|
|
|
prevTextChange->mStart -= extraLen;
|
2017-01-20 00:35:17 +03:00
|
|
|
prevHide->mTextChangeEvent.swap(mutEvent->mTextChangeEvent);
|
2016-11-11 06:12:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (prevEvent && mutEvent->IsShow() &&
|
|
|
|
prevEvent->GetEventType() == nsIAccessibleEvent::EVENT_SHOW) {
|
|
|
|
AccShowEvent* prevShow = downcast_accEvent(prevEvent);
|
|
|
|
AccTextChangeEvent* prevTextChange = prevShow->mTextChangeEvent;
|
2017-01-19 23:13:54 +03:00
|
|
|
if (prevTextChange && prevShow->Parent() == target->Parent()) {
|
2016-11-11 06:12:32 +03:00
|
|
|
int32_t index = target->IndexInParent();
|
|
|
|
int32_t prevIndex = prevShow->GetAccessible()->IndexInParent();
|
|
|
|
if (prevIndex + 1 == index) {
|
|
|
|
target->AppendTextTo(prevTextChange->mModifiedText);
|
2017-01-20 00:35:17 +03:00
|
|
|
prevShow->mTextChangeEvent.swap(mutEvent->mTextChangeEvent);
|
2016-11-11 06:12:32 +03:00
|
|
|
} else if (index + 1 == prevIndex) {
|
|
|
|
nsString temp;
|
|
|
|
target->AppendTextTo(temp);
|
|
|
|
prevTextChange->mStart -= temp.Length();
|
|
|
|
temp += prevTextChange->mModifiedText;
|
|
|
|
prevTextChange->mModifiedText = temp;
|
2017-01-20 00:35:17 +03:00
|
|
|
prevShow->mTextChangeEvent.swap(mutEvent->mTextChangeEvent);
|
2016-11-11 06:12:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mutEvent->mTextChangeEvent) {
|
|
|
|
mutEvent->mTextChangeEvent =
|
|
|
|
new AccTextChangeEvent(container, offset, text, mutEvent->IsShow(),
|
|
|
|
aEvent->mIsFromUserInput ? eFromUserInput : eNoUserInput);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotificationController::DropMutationEvent(AccTreeMutationEvent* aEvent)
|
|
|
|
{
|
|
|
|
// unset the event bits since the event isn't being fired any more.
|
|
|
|
if (aEvent->GetEventType() == nsIAccessibleEvent::EVENT_REORDER) {
|
|
|
|
aEvent->GetAccessible()->SetReorderEventTarget(false);
|
|
|
|
} else if (aEvent->GetEventType() == nsIAccessibleEvent::EVENT_SHOW) {
|
|
|
|
aEvent->GetAccessible()->SetShowEventTarget(false);
|
|
|
|
} else {
|
2017-08-14 18:02:02 +03:00
|
|
|
aEvent->GetAccessible()->SetHideEventTarget(false);
|
|
|
|
|
2016-11-11 06:12:32 +03:00
|
|
|
AccHideEvent* hideEvent = downcast_accEvent(aEvent);
|
|
|
|
MOZ_ASSERT(hideEvent);
|
|
|
|
|
|
|
|
if (hideEvent->NeedsShutdown()) {
|
|
|
|
mDocument->ShutdownChildrenInSubtree(aEvent->GetAccessible());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do the work to splice the event out of the list.
|
|
|
|
if (mFirstMutationEvent == aEvent) {
|
|
|
|
mFirstMutationEvent = aEvent->NextEvent();
|
|
|
|
} else {
|
|
|
|
aEvent->PrevEvent()->SetNextEvent(aEvent->NextEvent());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mLastMutationEvent == aEvent) {
|
|
|
|
mLastMutationEvent = aEvent->PrevEvent();
|
|
|
|
} else {
|
|
|
|
aEvent->NextEvent()->SetPrevEvent(aEvent->PrevEvent());
|
|
|
|
}
|
|
|
|
|
|
|
|
aEvent->SetPrevEvent(nullptr);
|
|
|
|
aEvent->SetNextEvent(nullptr);
|
|
|
|
mMutationMap.RemoveEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotificationController::CoalesceMutationEvents()
|
|
|
|
{
|
|
|
|
AccTreeMutationEvent* event = mFirstMutationEvent;
|
|
|
|
while (event) {
|
|
|
|
AccTreeMutationEvent* nextEvent = event->NextEvent();
|
|
|
|
uint32_t eventType = event->GetEventType();
|
|
|
|
if (event->GetEventType() == nsIAccessibleEvent::EVENT_REORDER) {
|
|
|
|
Accessible* acc = event->GetAccessible();
|
|
|
|
while (acc) {
|
|
|
|
if (acc->IsDoc()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if a parent of the reorder event's target is being hidden that
|
|
|
|
// hide event's target must have a parent that is also a reorder event
|
|
|
|
// target. That means we don't need this reorder event.
|
|
|
|
if (acc->HideEventTarget()) {
|
|
|
|
DropMutationEvent(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Accessible* parent = acc->Parent();
|
|
|
|
if (parent->ReorderEventTarget()) {
|
|
|
|
AccReorderEvent* reorder = downcast_accEvent(mMutationMap.GetEvent(parent, EventMap::ReorderEvent));
|
|
|
|
|
|
|
|
// We want to make sure that a reorder event comes after any show or
|
|
|
|
// hide events targeted at the children of its target. We keep the
|
|
|
|
// invariant that event generation goes up as you are farther in the
|
|
|
|
// queue, so we want to use the spot of the event with the higher
|
|
|
|
// generation number, and keep that generation number.
|
|
|
|
if (reorder && reorder->EventGeneration() < event->EventGeneration()) {
|
|
|
|
reorder->SetEventGeneration(event->EventGeneration());
|
2017-03-16 20:59:59 +03:00
|
|
|
|
|
|
|
// It may be true that reorder was before event, and we coalesced
|
|
|
|
// away all the show / hide events between them. In that case
|
|
|
|
// event is already immediately after reorder in the queue and we
|
|
|
|
// do not need to rearrange the list of events.
|
|
|
|
if (event != reorder->NextEvent()) {
|
|
|
|
// There really should be a show or hide event before the first
|
|
|
|
// reorder event.
|
|
|
|
if (reorder->PrevEvent()) {
|
|
|
|
reorder->PrevEvent()->SetNextEvent(reorder->NextEvent());
|
|
|
|
} else {
|
|
|
|
mFirstMutationEvent = reorder->NextEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
reorder->NextEvent()->SetPrevEvent(reorder->PrevEvent());
|
|
|
|
event->PrevEvent()->SetNextEvent(reorder);
|
|
|
|
reorder->SetPrevEvent(event->PrevEvent());
|
|
|
|
event->SetPrevEvent(reorder);
|
|
|
|
reorder->SetNextEvent(event);
|
|
|
|
}
|
2016-11-11 06:12:32 +03:00
|
|
|
}
|
|
|
|
DropMutationEvent(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
acc = parent;
|
|
|
|
}
|
|
|
|
} else if (eventType == nsIAccessibleEvent::EVENT_SHOW) {
|
|
|
|
Accessible* parent = event->GetAccessible()->Parent();
|
|
|
|
while (parent) {
|
|
|
|
if (parent->IsDoc()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the parent of a show event is being either shown or hidden then
|
|
|
|
// we don't need to fire a show event for a subtree of that change.
|
|
|
|
if (parent->ShowEventTarget() || parent->HideEventTarget()) {
|
|
|
|
DropMutationEvent(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = parent->Parent();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(eventType == nsIAccessibleEvent::EVENT_HIDE, "mutation event list has an invalid event");
|
|
|
|
|
|
|
|
AccHideEvent* hideEvent = downcast_accEvent(event);
|
|
|
|
Accessible* parent = hideEvent->Parent();
|
|
|
|
while (parent) {
|
|
|
|
if (parent->IsDoc()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent->HideEventTarget()) {
|
|
|
|
DropMutationEvent(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent->ShowEventTarget()) {
|
|
|
|
AccShowEvent* showEvent = downcast_accEvent(mMutationMap.GetEvent(parent, EventMap::ShowEvent));
|
|
|
|
if (showEvent->EventGeneration() < hideEvent->EventGeneration()) {
|
|
|
|
DropMutationEvent(hideEvent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = parent->Parent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event = nextEvent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-26 09:35:51 +03:00
|
|
|
void
|
2012-05-27 13:01:40 +04:00
|
|
|
NotificationController::ScheduleChildDocBinding(DocAccessible* aDocument)
|
2011-01-26 09:35:51 +03:00
|
|
|
{
|
|
|
|
// Schedule child document binding to the tree.
|
|
|
|
mHangingChildDocuments.AppendElement(aDocument);
|
|
|
|
ScheduleProcessing();
|
|
|
|
}
|
|
|
|
|
2011-01-18 11:03:38 +03:00
|
|
|
void
|
2012-05-29 05:18:45 +04:00
|
|
|
NotificationController::ScheduleContentInsertion(Accessible* aContainer,
|
2011-01-18 11:03:38 +03:00
|
|
|
nsIContent* aStartChildNode,
|
|
|
|
nsIContent* aEndChildNode)
|
|
|
|
{
|
2016-02-18 17:31:42 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIContent>>* list =
|
|
|
|
mContentInsertions.LookupOrAdd(aContainer);
|
|
|
|
|
|
|
|
bool needsProcessing = false;
|
|
|
|
nsIContent* node = aStartChildNode;
|
|
|
|
while (node != aEndChildNode) {
|
|
|
|
// Notification triggers for content insertion even if no content was
|
|
|
|
// actually inserted, check if the given content has a frame to discard
|
|
|
|
// this case early.
|
|
|
|
if (node->GetPrimaryFrame()) {
|
|
|
|
if (list->AppendElement(node))
|
|
|
|
needsProcessing = true;
|
|
|
|
}
|
|
|
|
node = node->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needsProcessing) {
|
2011-01-18 11:03:38 +03:00
|
|
|
ScheduleProcessing();
|
2011-04-07 09:17:29 +04:00
|
|
|
}
|
2011-01-18 11:03:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotificationController::ScheduleProcessing()
|
|
|
|
{
|
|
|
|
// If notification flush isn't planed yet start notification flush
|
|
|
|
// asynchronously (after style and layout).
|
|
|
|
if (mObservingState == eNotObservingRefresh) {
|
2017-01-05 10:31:56 +03:00
|
|
|
if (mPresShell->AddRefreshObserver(this, FlushType::Display))
|
2011-01-18 11:03:38 +03:00
|
|
|
mObservingState = eRefreshObserving;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-15 19:01:51 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// NotificationCollector: protected
|
|
|
|
|
2011-01-18 11:03:38 +03:00
|
|
|
bool
|
|
|
|
NotificationController::IsUpdatePending()
|
|
|
|
{
|
2011-04-01 01:33:46 +04:00
|
|
|
return mPresShell->IsLayoutFlushObserver() ||
|
2011-01-18 11:03:38 +03:00
|
|
|
mObservingState == eRefreshProcessingForUpdate ||
|
2016-02-18 17:31:42 +03:00
|
|
|
mContentInsertions.Count() != 0 || mNotifications.Length() != 0 ||
|
2011-09-28 05:46:11 +04:00
|
|
|
mTextHash.Count() != 0 ||
|
2012-05-27 13:01:40 +04:00
|
|
|
!mDocument->HasLoadState(DocAccessible::eTreeConstructed);
|
2011-01-18 11:03:38 +03:00
|
|
|
}
|
|
|
|
|
2016-11-11 06:12:32 +03:00
|
|
|
void
|
|
|
|
NotificationController::ProcessMutationEvents()
|
|
|
|
{
|
|
|
|
// there is no reason to fire a hide event for a child of a show event
|
|
|
|
// target. That can happen if something is inserted into the tree and
|
|
|
|
// removed before the next refresh driver tick, but it should not be
|
|
|
|
// observable outside gecko so it should be safe to coalesce away any such
|
|
|
|
// events. This means that it should be fine to fire all of the hide events
|
|
|
|
// first, and then deal with any shown subtrees.
|
|
|
|
for (AccTreeMutationEvent* event = mFirstMutationEvent;
|
|
|
|
event; event = event->NextEvent()) {
|
|
|
|
if (event->GetEventType() != nsIAccessibleEvent::EVENT_HIDE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventShell::FireEvent(event);
|
|
|
|
if (!mDocument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AccMutationEvent* mutEvent = downcast_accEvent(event);
|
|
|
|
if (mutEvent->mTextChangeEvent) {
|
|
|
|
nsEventShell::FireEvent(mutEvent->mTextChangeEvent);
|
|
|
|
if (!mDocument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fire menupopup end event before a hide event if a menu goes away.
|
|
|
|
|
|
|
|
// XXX: We don't look into children of hidden subtree to find hiding
|
|
|
|
// menupopup (as we did prior bug 570275) because we don't do that when
|
|
|
|
// menu is showing (and that's impossible until bug 606924 is fixed).
|
|
|
|
// Nevertheless we should do this at least because layout coalesces
|
|
|
|
// the changes before our processing and we may miss some menupopup
|
|
|
|
// events. Now we just want to be consistent in content insertion/removal
|
|
|
|
// handling.
|
|
|
|
if (event->mAccessible->ARIARole() == roles::MENUPOPUP) {
|
|
|
|
nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_END,
|
|
|
|
event->mAccessible);
|
|
|
|
if (!mDocument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AccHideEvent* hideEvent = downcast_accEvent(event);
|
|
|
|
if (hideEvent->NeedsShutdown()) {
|
|
|
|
mDocument->ShutdownChildrenInSubtree(event->mAccessible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Group the show events by the parent of their target.
|
|
|
|
nsDataHashtable<nsPtrHashKey<Accessible>, nsTArray<AccTreeMutationEvent*>> showEvents;
|
|
|
|
for (AccTreeMutationEvent* event = mFirstMutationEvent;
|
|
|
|
event; event = event->NextEvent()) {
|
|
|
|
if (event->GetEventType() != nsIAccessibleEvent::EVENT_SHOW) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Accessible* parent = event->GetAccessible()->Parent();
|
|
|
|
showEvents.GetOrInsert(parent).AppendElement(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to fire show events for the children of an accessible in the order
|
|
|
|
// of their indices at this point. So sort each set of events for the same
|
|
|
|
// container by the index of their target.
|
|
|
|
for (auto iter = showEvents.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
struct AccIdxComparator {
|
|
|
|
bool LessThan(const AccTreeMutationEvent* a, const AccTreeMutationEvent* b) const
|
|
|
|
{
|
|
|
|
int32_t aIdx = a->GetAccessible()->IndexInParent();
|
|
|
|
int32_t bIdx = b->GetAccessible()->IndexInParent();
|
|
|
|
MOZ_ASSERT(aIdx >= 0 && bIdx >= 0 && aIdx != bIdx);
|
|
|
|
return aIdx < bIdx;
|
|
|
|
}
|
|
|
|
bool Equals(const AccTreeMutationEvent* a, const AccTreeMutationEvent* b) const
|
|
|
|
{
|
|
|
|
DebugOnly<int32_t> aIdx = a->GetAccessible()->IndexInParent();
|
|
|
|
DebugOnly<int32_t> bIdx = b->GetAccessible()->IndexInParent();
|
|
|
|
MOZ_ASSERT(aIdx >= 0 && bIdx >= 0 && aIdx != bIdx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
nsTArray<AccTreeMutationEvent*>& events = iter.Data();
|
|
|
|
events.Sort(AccIdxComparator());
|
|
|
|
for (AccTreeMutationEvent* event: events) {
|
|
|
|
nsEventShell::FireEvent(event);
|
|
|
|
if (!mDocument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AccMutationEvent* mutEvent = downcast_accEvent(event);
|
|
|
|
if (mutEvent->mTextChangeEvent) {
|
|
|
|
nsEventShell::FireEvent(mutEvent->mTextChangeEvent);
|
|
|
|
if (!mDocument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we can fire the reorder events after all the show and hide events.
|
|
|
|
for (AccTreeMutationEvent* event = mFirstMutationEvent;
|
|
|
|
event; event = event->NextEvent()) {
|
|
|
|
if (event->GetEventType() != nsIAccessibleEvent::EVENT_REORDER) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventShell::FireEvent(event);
|
|
|
|
if (!mDocument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Accessible* target = event->GetAccessible();
|
|
|
|
target->Document()->MaybeNotifyOfValueChange(target);
|
|
|
|
if (!mDocument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-18 11:03:38 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// NotificationCollector: private
|
|
|
|
|
|
|
|
void
|
|
|
|
NotificationController::WillRefresh(mozilla::TimeStamp aTime)
|
|
|
|
{
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 10:08:53 +03:00
|
|
|
AUTO_PROFILER_LABEL("NotificationController::WillRefresh", OTHER);
|
2012-07-21 00:23:38 +04:00
|
|
|
|
2011-01-18 11:03:38 +03:00
|
|
|
// If the document accessible that notification collector was created for is
|
|
|
|
// now shut down, don't process notifications anymore.
|
|
|
|
NS_ASSERTION(mDocument,
|
|
|
|
"The document was shut down while refresh observer is attached!");
|
|
|
|
if (!mDocument)
|
|
|
|
return;
|
|
|
|
|
2013-05-24 22:24:19 +04:00
|
|
|
if (mObservingState == eRefreshProcessing ||
|
|
|
|
mObservingState == eRefreshProcessingForUpdate)
|
|
|
|
return;
|
|
|
|
|
2011-01-18 11:03:38 +03:00
|
|
|
// Any generic notifications should be queued if we're processing content
|
|
|
|
// insertions or generic notifications.
|
|
|
|
mObservingState = eRefreshProcessingForUpdate;
|
|
|
|
|
2011-01-24 05:58:00 +03:00
|
|
|
// Initial accessible tree construction.
|
2012-05-27 13:01:40 +04:00
|
|
|
if (!mDocument->HasLoadState(DocAccessible::eTreeConstructed)) {
|
2011-01-26 09:35:51 +03:00
|
|
|
// If document is not bound to parent at this point then the document is not
|
|
|
|
// ready yet (process notifications later).
|
2011-10-14 06:33:41 +04:00
|
|
|
if (!mDocument->IsBoundToParent()) {
|
|
|
|
mObservingState = eRefreshObserving;
|
2011-01-26 09:35:51 +03:00
|
|
|
return;
|
2011-10-14 06:33:41 +04:00
|
|
|
}
|
2011-01-26 09:35:51 +03:00
|
|
|
|
2012-10-04 13:57:09 +04:00
|
|
|
#ifdef A11Y_LOG
|
2012-06-01 08:27:25 +04:00
|
|
|
if (logging::IsEnabled(logging::eTree)) {
|
|
|
|
logging::MsgBegin("TREE", "initial tree created");
|
|
|
|
logging::Address("document", mDocument);
|
|
|
|
logging::MsgEnd();
|
|
|
|
}
|
2011-01-28 11:42:22 +03:00
|
|
|
#endif
|
|
|
|
|
2011-08-08 11:55:36 +04:00
|
|
|
mDocument->DoInitialUpdate();
|
2011-03-03 09:41:46 +03:00
|
|
|
|
2016-02-18 17:31:42 +03:00
|
|
|
NS_ASSERTION(mContentInsertions.Count() == 0,
|
2011-01-24 05:58:00 +03:00
|
|
|
"Pending content insertions while initial accessible tree isn't created!");
|
|
|
|
}
|
|
|
|
|
2012-12-27 08:25:27 +04:00
|
|
|
// Initialize scroll support if needed.
|
|
|
|
if (!(mDocument->mDocFlags & DocAccessible::eScrollInitialized))
|
|
|
|
mDocument->AddScrollListener();
|
|
|
|
|
2011-01-28 11:42:22 +03:00
|
|
|
// Process rendered text change notifications.
|
2015-07-23 06:49:25 +03:00
|
|
|
for (auto iter = mTextHash.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsCOMPtrHashKey<nsIContent>* entry = iter.Get();
|
|
|
|
nsIContent* textNode = entry->GetKey();
|
|
|
|
Accessible* textAcc = mDocument->GetAccessible(textNode);
|
|
|
|
|
|
|
|
// If the text node is not in tree or doesn't have frame then this case should
|
|
|
|
// have been handled already by content removal notifications.
|
|
|
|
nsINode* containerNode = textNode->GetParentNode();
|
|
|
|
if (!containerNode) {
|
|
|
|
NS_ASSERTION(!textAcc,
|
|
|
|
"Text node was removed but accessible is kept alive!");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* textFrame = textNode->GetPrimaryFrame();
|
|
|
|
if (!textFrame) {
|
|
|
|
NS_ASSERTION(!textAcc,
|
|
|
|
"Text node isn't rendered but accessible is kept alive!");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-06-12 17:13:05 +03:00
|
|
|
#ifdef A11Y_LOG
|
2015-07-23 06:49:25 +03:00
|
|
|
nsIContent* containerElm = containerNode->IsElement() ?
|
|
|
|
containerNode->AsElement() : nullptr;
|
2017-06-12 17:13:05 +03:00
|
|
|
#endif
|
2015-07-23 06:49:25 +03:00
|
|
|
|
2015-11-30 16:21:25 +03:00
|
|
|
nsIFrame::RenderedText text = textFrame->GetRenderedText(0,
|
|
|
|
UINT32_MAX, nsIFrame::TextOffsetType::OFFSETS_IN_CONTENT_TEXT,
|
|
|
|
nsIFrame::TrailingWhitespace::DONT_TRIM_TRAILING_WHITESPACE);
|
2015-07-23 06:49:25 +03:00
|
|
|
|
|
|
|
// Remove text accessible if rendered text is empty.
|
|
|
|
if (textAcc) {
|
2015-10-30 09:23:10 +03:00
|
|
|
if (text.mString.IsEmpty()) {
|
2015-07-23 06:49:25 +03:00
|
|
|
#ifdef A11Y_LOG
|
|
|
|
if (logging::IsEnabled(logging::eTree | logging::eText)) {
|
2016-06-08 18:39:28 +03:00
|
|
|
logging::MsgBegin("TREE", "text node lost its content; doc: %p", mDocument);
|
2015-07-23 06:49:25 +03:00
|
|
|
logging::Node("container", containerElm);
|
|
|
|
logging::Node("content", textNode);
|
|
|
|
logging::MsgEnd();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-04-25 21:02:41 +03:00
|
|
|
mDocument->ContentRemoved(textAcc);
|
2015-07-23 06:49:25 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update text of the accessible and fire text change events.
|
|
|
|
#ifdef A11Y_LOG
|
|
|
|
if (logging::IsEnabled(logging::eText)) {
|
2016-06-08 18:39:28 +03:00
|
|
|
logging::MsgBegin("TEXT", "text may be changed; doc: %p", mDocument);
|
2015-07-23 06:49:25 +03:00
|
|
|
logging::Node("container", containerElm);
|
|
|
|
logging::Node("content", textNode);
|
|
|
|
logging::MsgEntry("old text '%s'",
|
|
|
|
NS_ConvertUTF16toUTF8(textAcc->AsTextLeaf()->Text()).get());
|
|
|
|
logging::MsgEntry("new text: '%s'",
|
2015-10-30 09:23:10 +03:00
|
|
|
NS_ConvertUTF16toUTF8(text.mString).get());
|
2015-07-23 06:49:25 +03:00
|
|
|
logging::MsgEnd();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-30 09:23:10 +03:00
|
|
|
TextUpdater::Run(mDocument, textAcc->AsTextLeaf(), text.mString);
|
2015-07-23 06:49:25 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append an accessible if rendered text is not empty.
|
2015-10-30 09:23:10 +03:00
|
|
|
if (!text.mString.IsEmpty()) {
|
2015-07-23 06:49:25 +03:00
|
|
|
#ifdef A11Y_LOG
|
|
|
|
if (logging::IsEnabled(logging::eTree | logging::eText)) {
|
2016-06-08 18:39:28 +03:00
|
|
|
logging::MsgBegin("TREE", "text node gains new content; doc: %p", mDocument);
|
2015-07-23 06:49:25 +03:00
|
|
|
logging::Node("container", containerElm);
|
|
|
|
logging::Node("content", textNode);
|
|
|
|
logging::MsgEnd();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-04-06 03:48:30 +03:00
|
|
|
Accessible* container = mDocument->AccessibleOrTrueContainer(containerNode);
|
|
|
|
MOZ_ASSERT(container,
|
|
|
|
"Text node having rendered text hasn't accessible document!");
|
2015-07-23 06:49:25 +03:00
|
|
|
if (container) {
|
2016-08-08 20:02:26 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIContent>>* list =
|
|
|
|
mContentInsertions.LookupOrAdd(container);
|
|
|
|
list->AppendElement(textNode);
|
2015-07-23 06:49:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-28 11:42:22 +03:00
|
|
|
mTextHash.Clear();
|
|
|
|
|
2016-08-08 20:02:26 +03:00
|
|
|
// Process content inserted notifications to update the tree.
|
|
|
|
for (auto iter = mContentInsertions.ConstIter(); !iter.Done(); iter.Next()) {
|
|
|
|
mDocument->ProcessContentInserted(iter.Key(), iter.UserData());
|
|
|
|
if (!mDocument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mContentInsertions.Clear();
|
|
|
|
|
2017-05-22 12:09:02 +03:00
|
|
|
// Bind hanging child documents unless we are using IPC and the
|
|
|
|
// document has no IPC actor. If we fail to bind the child doc then
|
|
|
|
// shut it down.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t hangingDocCnt = mHangingChildDocuments.Length();
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<DocAccessible>> newChildDocs;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t idx = 0; idx < hangingDocCnt; idx++) {
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* childDoc = mHangingChildDocuments[idx];
|
2012-03-15 00:37:50 +04:00
|
|
|
if (childDoc->IsDefunct())
|
|
|
|
continue;
|
2011-01-26 09:35:51 +03:00
|
|
|
|
2017-05-22 12:09:02 +03:00
|
|
|
if (IPCAccessibilityActive() && !mDocument->IPCDoc()) {
|
|
|
|
childDoc->Shutdown();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-10-12 06:25:34 +04:00
|
|
|
nsIContent* ownerContent = mDocument->DocumentNode()->
|
|
|
|
FindContentForSubDocument(childDoc->DocumentNode());
|
2011-01-26 09:35:51 +03:00
|
|
|
if (ownerContent) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* outerDocAcc = mDocument->GetAccessible(ownerContent);
|
2011-01-26 09:35:51 +03:00
|
|
|
if (outerDocAcc && outerDocAcc->AppendChild(childDoc)) {
|
2014-03-08 01:35:19 +04:00
|
|
|
if (mDocument->AppendChildDocument(childDoc)) {
|
2015-01-07 23:16:37 +03:00
|
|
|
newChildDocs.AppendElement(Move(mHangingChildDocuments[idx]));
|
2011-01-26 09:35:51 +03:00
|
|
|
continue;
|
2014-03-08 01:35:19 +04:00
|
|
|
}
|
2011-07-19 12:30:32 +04:00
|
|
|
|
2011-01-26 09:35:51 +03:00
|
|
|
outerDocAcc->RemoveChild(childDoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Failed to bind the child document, destroy it.
|
|
|
|
childDoc->Shutdown();
|
|
|
|
}
|
|
|
|
}
|
2017-05-22 12:09:02 +03:00
|
|
|
|
|
|
|
// Clear the hanging documents list, even if we didn't bind them.
|
2015-01-07 23:16:37 +03:00
|
|
|
mHangingChildDocuments.Clear();
|
2017-03-23 20:59:16 +03:00
|
|
|
MOZ_ASSERT(mDocument, "Illicit document shutdown");
|
|
|
|
if (!mDocument) {
|
|
|
|
return;
|
|
|
|
}
|
2011-01-26 09:35:51 +03:00
|
|
|
|
2011-08-08 11:55:36 +04:00
|
|
|
// If the document is ready and all its subdocuments are completely loaded
|
|
|
|
// then process the document load.
|
2012-05-27 13:01:40 +04:00
|
|
|
if (mDocument->HasLoadState(DocAccessible::eReady) &&
|
|
|
|
!mDocument->HasLoadState(DocAccessible::eCompletelyLoaded) &&
|
2011-08-08 11:55:36 +04:00
|
|
|
hangingDocCnt == 0) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childDocCnt = mDocument->ChildDocumentCount(), childDocIdx = 0;
|
2011-08-08 11:55:36 +04:00
|
|
|
for (; childDocIdx < childDocCnt; childDocIdx++) {
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* childDoc = mDocument->GetChildDocumentAt(childDocIdx);
|
|
|
|
if (!childDoc->HasLoadState(DocAccessible::eCompletelyLoaded))
|
2011-08-08 11:55:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (childDocIdx == childDocCnt) {
|
|
|
|
mDocument->ProcessLoad();
|
|
|
|
if (!mDocument)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-18 11:03:38 +03:00
|
|
|
// Process only currently queued generic notifications.
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray < RefPtr<Notification> > notifications;
|
2011-01-18 11:03:38 +03:00
|
|
|
notifications.SwapElements(mNotifications);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t notificationCount = notifications.Length();
|
|
|
|
for (uint32_t idx = 0; idx < notificationCount; idx++) {
|
2011-01-18 11:03:38 +03:00
|
|
|
notifications[idx]->Process();
|
|
|
|
if (!mDocument)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-25 07:15:37 +04:00
|
|
|
// Process invalidation list of the document after all accessible tree
|
|
|
|
// modification are done.
|
|
|
|
mDocument->ProcessInvalidationList();
|
|
|
|
|
2015-10-30 01:08:48 +03:00
|
|
|
// Process relocation list.
|
|
|
|
for (uint32_t idx = 0; idx < mRelocations.Length(); idx++) {
|
2016-04-14 20:45:16 +03:00
|
|
|
if (mRelocations[idx]->IsInDocument()) {
|
|
|
|
mDocument->DoARIAOwnsRelocation(mRelocations[idx]);
|
|
|
|
}
|
2015-10-30 01:08:48 +03:00
|
|
|
}
|
|
|
|
mRelocations.Clear();
|
|
|
|
|
2011-01-18 11:03:38 +03:00
|
|
|
// If a generic notification occurs after this point then we may be allowed to
|
2013-05-24 22:24:19 +04:00
|
|
|
// process it synchronously. However we do not want to reenter if fireing
|
|
|
|
// events causes script to run.
|
|
|
|
mObservingState = eRefreshProcessing;
|
2011-01-18 11:03:38 +03:00
|
|
|
|
2016-11-11 08:23:27 +03:00
|
|
|
CoalesceMutationEvents();
|
|
|
|
ProcessMutationEvents();
|
|
|
|
mEventGeneration = 0;
|
2016-11-11 06:12:32 +03:00
|
|
|
|
2016-11-11 06:12:32 +03:00
|
|
|
// Now that we are done with them get rid of the events we fired.
|
|
|
|
RefPtr<AccTreeMutationEvent> mutEvent = Move(mFirstMutationEvent);
|
|
|
|
mLastMutationEvent = nullptr;
|
|
|
|
mFirstMutationEvent = nullptr;
|
|
|
|
while (mutEvent) {
|
|
|
|
RefPtr<AccTreeMutationEvent> nextEvent = mutEvent->NextEvent();
|
|
|
|
Accessible* target = mutEvent->GetAccessible();
|
|
|
|
|
|
|
|
// We need to be careful here, while it may seem that we can simply 0 all
|
|
|
|
// the pending event bits that is not true. Because accessibles may be
|
|
|
|
// reparented they may be the target of both a hide event and a show event
|
|
|
|
// at the same time.
|
|
|
|
if (mutEvent->GetEventType() == nsIAccessibleEvent::EVENT_SHOW) {
|
|
|
|
target->SetShowEventTarget(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mutEvent->GetEventType() == nsIAccessibleEvent::EVENT_HIDE) {
|
|
|
|
target->SetHideEventTarget(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// However it is not possible for a reorder event target to also be the
|
|
|
|
// target of a show or hide, so we can just zero that.
|
|
|
|
target->SetReorderEventTarget(false);
|
|
|
|
|
|
|
|
mutEvent->SetPrevEvent(nullptr);
|
|
|
|
mutEvent->SetNextEvent(nullptr);
|
|
|
|
mMutationMap.RemoveEvent(mutEvent);
|
|
|
|
mutEvent = nextEvent;
|
|
|
|
}
|
|
|
|
|
2012-11-13 10:29:22 +04:00
|
|
|
ProcessEventQueue();
|
2014-10-28 21:18:03 +03:00
|
|
|
|
|
|
|
if (IPCAccessibilityActive()) {
|
|
|
|
size_t newDocCount = newChildDocs.Length();
|
|
|
|
for (size_t i = 0; i < newDocCount; i++) {
|
|
|
|
DocAccessible* childDoc = newChildDocs[i];
|
2016-12-02 22:33:01 +03:00
|
|
|
if (childDoc->IsDefunct()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-03-24 20:52:59 +03:00
|
|
|
Accessible* parent = childDoc->Parent();
|
2014-10-28 21:18:03 +03:00
|
|
|
DocAccessibleChild* parentIPCDoc = mDocument->IPCDoc();
|
2017-01-06 23:27:51 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(parentIPCDoc);
|
2015-03-24 20:52:59 +03:00
|
|
|
uint64_t id = reinterpret_cast<uintptr_t>(parent->UniqueID());
|
2017-01-06 23:27:51 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(id);
|
2015-03-24 20:52:59 +03:00
|
|
|
DocAccessibleChild* ipcDoc = childDoc->IPCDoc();
|
|
|
|
if (ipcDoc) {
|
|
|
|
parentIPCDoc->SendBindChildDoc(ipcDoc, id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-27 20:03:43 +03:00
|
|
|
ipcDoc = new DocAccessibleChild(childDoc, parentIPCDoc->Manager());
|
2015-03-24 20:52:59 +03:00
|
|
|
childDoc->SetIPCDoc(ipcDoc);
|
2016-12-02 02:28:54 +03:00
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
parentIPCDoc->ConstructChildDocInParentProcess(ipcDoc, id,
|
|
|
|
AccessibleWrap::GetChildIDFor(childDoc));
|
|
|
|
#else
|
2015-05-21 20:04:58 +03:00
|
|
|
nsCOMPtr<nsITabChild> tabChild =
|
|
|
|
do_GetInterface(mDocument->DocumentNode()->GetDocShell());
|
2015-12-14 19:00:48 +03:00
|
|
|
if (tabChild) {
|
|
|
|
static_cast<TabChild*>(tabChild.get())->
|
2016-12-02 02:28:54 +03:00
|
|
|
SendPDocAccessibleConstructor(ipcDoc, parentIPCDoc, id, 0, 0);
|
2015-12-14 19:00:48 +03:00
|
|
|
}
|
2016-12-02 02:28:54 +03:00
|
|
|
#endif
|
2014-10-28 21:18:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-24 22:24:19 +04:00
|
|
|
mObservingState = eRefreshObserving;
|
2012-11-13 10:29:22 +04:00
|
|
|
if (!mDocument)
|
|
|
|
return;
|
2011-01-18 11:03:38 +03:00
|
|
|
|
2011-08-08 11:55:36 +04:00
|
|
|
// Stop further processing if there are no new notifications of any kind or
|
|
|
|
// events and document load is processed.
|
2016-02-18 17:31:42 +03:00
|
|
|
if (mContentInsertions.Count() == 0 && mNotifications.IsEmpty() &&
|
2013-05-24 22:24:19 +04:00
|
|
|
mEvents.IsEmpty() && mTextHash.Count() == 0 &&
|
|
|
|
mHangingChildDocuments.IsEmpty() &&
|
2012-05-27 13:01:40 +04:00
|
|
|
mDocument->HasLoadState(DocAccessible::eCompletelyLoaded) &&
|
2017-01-05 10:31:56 +03:00
|
|
|
mPresShell->RemoveRefreshObserver(this, FlushType::Display)) {
|
2011-01-18 11:03:38 +03:00
|
|
|
mObservingState = eNotObservingRefresh;
|
|
|
|
}
|
|
|
|
}
|
2016-11-11 01:05:02 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
NotificationController::EventMap::PutEvent(AccTreeMutationEvent* aEvent)
|
|
|
|
{
|
|
|
|
EventType type = GetEventType(aEvent);
|
|
|
|
uint64_t addr = reinterpret_cast<uintptr_t>(aEvent->GetAccessible());
|
|
|
|
MOZ_ASSERT((addr & 0x3) == 0, "accessible is not 4 byte aligned");
|
|
|
|
addr |= type;
|
|
|
|
mTable.Put(addr, aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
AccTreeMutationEvent*
|
|
|
|
NotificationController::EventMap::GetEvent(Accessible* aTarget, EventType aType)
|
|
|
|
{
|
|
|
|
uint64_t addr = reinterpret_cast<uintptr_t>(aTarget);
|
|
|
|
MOZ_ASSERT((addr & 0x3) == 0, "target is not 4 byte aligned");
|
|
|
|
|
|
|
|
addr |= aType;
|
|
|
|
return mTable.GetWeak(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NotificationController::EventMap::RemoveEvent(AccTreeMutationEvent* aEvent)
|
|
|
|
{
|
|
|
|
EventType type = GetEventType(aEvent);
|
|
|
|
uint64_t addr = reinterpret_cast<uintptr_t>(aEvent->GetAccessible());
|
|
|
|
MOZ_ASSERT((addr & 0x3) == 0, "accessible is not 4 byte aligned");
|
|
|
|
addr |= type;
|
|
|
|
|
|
|
|
MOZ_ASSERT(mTable.GetWeak(addr) == aEvent, "mTable has the wrong event");
|
|
|
|
mTable.Remove(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
NotificationController::EventMap::EventType
|
|
|
|
NotificationController::EventMap::GetEventType(AccTreeMutationEvent* aEvent)
|
|
|
|
{
|
|
|
|
switch(aEvent->GetEventType())
|
|
|
|
{
|
|
|
|
case nsIAccessibleEvent::EVENT_SHOW:
|
|
|
|
return ShowEvent;
|
|
|
|
case nsIAccessibleEvent::EVENT_HIDE:
|
|
|
|
return HideEvent;
|
|
|
|
case nsIAccessibleEvent::EVENT_REORDER:
|
|
|
|
return ReorderEvent;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("event has invalid type");
|
|
|
|
return ShowEvent;
|
|
|
|
}
|
|
|
|
}
|