2014-03-07 13:35:19 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "DocAccessibleParent.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "mozilla/a11y/Platform.h"
|
2015-01-09 12:01:39 -08:00
|
|
|
#include "ProxyAccessible.h"
|
2015-06-02 07:30:51 -07:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2014-03-07 13:35:19 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
|
|
|
|
bool
|
|
|
|
DocAccessibleParent::RecvShowEvent(const ShowEventData& aData)
|
|
|
|
{
|
2015-01-26 11:41:41 -08:00
|
|
|
if (mShutdown)
|
|
|
|
return true;
|
|
|
|
|
2014-03-07 13:35:19 -08:00
|
|
|
if (aData.NewTree().IsEmpty()) {
|
|
|
|
NS_ERROR("no children being added");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-13 08:57:14 -07:00
|
|
|
ProxyAccessible* parent = GetAccessible(aData.ID());
|
2014-03-07 13:35:19 -08:00
|
|
|
|
|
|
|
// XXX This should really never happen, but sometimes we fail to fire the
|
|
|
|
// required show events.
|
|
|
|
if (!parent) {
|
|
|
|
NS_ERROR("adding child to unknown accessible");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t newChildIdx = aData.Idx();
|
|
|
|
if (newChildIdx > parent->ChildrenCount()) {
|
|
|
|
NS_ERROR("invalid index to add child at");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t consumed = AddSubtree(parent, aData.NewTree(), 0, newChildIdx);
|
|
|
|
MOZ_ASSERT(consumed == aData.NewTree().Length());
|
2014-10-22 11:30:30 -07:00
|
|
|
#ifdef DEBUG
|
2014-03-07 13:35:19 -08:00
|
|
|
for (uint32_t i = 0; i < consumed; i++) {
|
|
|
|
uint64_t id = aData.NewTree()[i].ID();
|
|
|
|
MOZ_ASSERT(mAccessibles.GetEntry(id));
|
|
|
|
}
|
2014-10-22 11:30:30 -07:00
|
|
|
#endif
|
2014-03-07 13:35:19 -08:00
|
|
|
|
2015-01-28 09:41:56 -08:00
|
|
|
return consumed != 0;
|
2014-03-07 13:35:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
DocAccessibleParent::AddSubtree(ProxyAccessible* aParent,
|
|
|
|
const nsTArray<a11y::AccessibleData>& aNewTree,
|
|
|
|
uint32_t aIdx, uint32_t aIdxInParent)
|
|
|
|
{
|
|
|
|
if (aNewTree.Length() <= aIdx) {
|
|
|
|
NS_ERROR("bad index in serialized tree!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const AccessibleData& newChild = aNewTree[aIdx];
|
|
|
|
if (newChild.Role() > roles::LAST_ROLE) {
|
|
|
|
NS_ERROR("invalid role");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto role = static_cast<a11y::role>(newChild.Role());
|
|
|
|
ProxyAccessible* newProxy =
|
2014-09-23 02:53:03 -07:00
|
|
|
new ProxyAccessible(newChild.ID(), aParent, this, role);
|
2014-03-07 13:35:19 -08:00
|
|
|
aParent->AddChildAt(aIdxInParent, newProxy);
|
|
|
|
mAccessibles.PutEntry(newChild.ID())->mProxy = newProxy;
|
2015-01-09 12:01:39 -08:00
|
|
|
ProxyCreated(newProxy, newChild.Interfaces());
|
2014-03-07 13:35:19 -08:00
|
|
|
|
|
|
|
uint32_t accessibles = 1;
|
|
|
|
uint32_t kids = newChild.ChildrenCount();
|
|
|
|
for (uint32_t i = 0; i < kids; i++) {
|
|
|
|
uint32_t consumed = AddSubtree(newProxy, aNewTree, aIdx + accessibles, i);
|
|
|
|
if (!consumed)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
accessibles += consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(newProxy->ChildrenCount() == kids);
|
|
|
|
|
|
|
|
return accessibles;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DocAccessibleParent::RecvHideEvent(const uint64_t& aRootID)
|
|
|
|
{
|
2015-01-26 11:41:41 -08:00
|
|
|
if (mShutdown)
|
|
|
|
return true;
|
|
|
|
|
2014-03-07 13:35:19 -08:00
|
|
|
ProxyEntry* rootEntry = mAccessibles.GetEntry(aRootID);
|
|
|
|
if (!rootEntry) {
|
|
|
|
NS_ERROR("invalid root being removed!");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProxyAccessible* root = rootEntry->mProxy;
|
|
|
|
if (!root) {
|
|
|
|
NS_ERROR("invalid root being removed!");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProxyAccessible* parent = root->Parent();
|
|
|
|
parent->RemoveChild(root);
|
|
|
|
root->Shutdown();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-30 07:00:26 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
DocAccessibleParent::RecvEvent(const uint64_t& aID, const uint32_t& aEventType)
|
|
|
|
{
|
2015-05-13 08:57:14 -07:00
|
|
|
ProxyAccessible* proxy = GetAccessible(aID);
|
|
|
|
if (!proxy) {
|
2014-09-30 07:00:26 -07:00
|
|
|
NS_ERROR("no proxy for event!");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-13 08:57:14 -07:00
|
|
|
ProxyEvent(proxy, aEventType);
|
2014-09-30 07:00:26 -07:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-24 10:52:59 -07:00
|
|
|
|
2015-05-13 11:21:23 -07:00
|
|
|
bool
|
|
|
|
DocAccessibleParent::RecvStateChangeEvent(const uint64_t& aID,
|
|
|
|
const uint64_t& aState,
|
|
|
|
const bool& aEnabled)
|
|
|
|
{
|
|
|
|
ProxyAccessible* target = GetAccessible(aID);
|
|
|
|
if (!target)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ProxyStateChangeEvent(target, aState, aEnabled);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DocAccessibleParent::RecvCaretMoveEvent(const uint64_t& aID, const int32_t& aOffset)
|
|
|
|
{
|
|
|
|
ProxyAccessible* proxy = GetAccessible(aID);
|
|
|
|
if (!proxy)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ProxyCaretMoveEvent(proxy, aOffset);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-24 10:52:59 -07:00
|
|
|
bool
|
|
|
|
DocAccessibleParent::RecvBindChildDoc(PDocAccessibleParent* aChildDoc, const uint64_t& aID)
|
|
|
|
{
|
|
|
|
auto childDoc = static_cast<DocAccessibleParent*>(aChildDoc);
|
|
|
|
DebugOnly<bool> result = AddChildDoc(childDoc, aID, false);
|
|
|
|
MOZ_ASSERT(result);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-11 14:36:59 -08:00
|
|
|
bool
|
|
|
|
DocAccessibleParent::AddChildDoc(DocAccessibleParent* aChildDoc,
|
2015-03-24 10:52:59 -07:00
|
|
|
uint64_t aParentID, bool aCreating)
|
2014-12-11 14:36:59 -08:00
|
|
|
{
|
|
|
|
ProxyAccessible* outerDoc = mAccessibles.GetEntry(aParentID)->mProxy;
|
|
|
|
if (!outerDoc)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
aChildDoc->mParent = outerDoc;
|
|
|
|
outerDoc->SetChildDoc(aChildDoc);
|
|
|
|
mChildDocs.AppendElement(aChildDoc);
|
|
|
|
aChildDoc->mParentDoc = this;
|
2015-03-24 10:52:59 -07:00
|
|
|
|
|
|
|
if (aCreating) {
|
|
|
|
ProxyCreated(aChildDoc, 0);
|
|
|
|
}
|
|
|
|
|
2014-12-11 14:36:59 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-12 14:33:28 -08:00
|
|
|
PLDHashOperator
|
|
|
|
DocAccessibleParent::ShutdownAccessibles(ProxyEntry* entry, void*)
|
|
|
|
{
|
|
|
|
ProxyDestroyed(entry->mProxy);
|
2015-01-26 11:41:41 -08:00
|
|
|
return PL_DHASH_REMOVE;
|
2014-12-12 14:33:28 -08:00
|
|
|
}
|
|
|
|
|
2015-06-02 07:30:51 -07:00
|
|
|
bool
|
|
|
|
DocAccessibleParent::RecvShutdown()
|
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
|
|
|
|
if (!static_cast<dom::TabParent*>(Manager())->IsDestroyed()) {
|
|
|
|
return PDocAccessibleParent::Send__delete__(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-11 14:36:59 -08:00
|
|
|
void
|
2015-01-13 20:42:27 -08:00
|
|
|
DocAccessibleParent::Destroy()
|
2014-12-11 14:36:59 -08:00
|
|
|
{
|
2015-01-26 11:41:41 -08:00
|
|
|
NS_ASSERTION(mChildDocs.IsEmpty(),
|
|
|
|
"why weren't the child docs destroyed already?");
|
2015-01-13 20:42:27 -08:00
|
|
|
MOZ_ASSERT(!mShutdown);
|
|
|
|
mShutdown = true;
|
2014-12-12 14:33:28 -08:00
|
|
|
|
2015-01-26 11:41:41 -08:00
|
|
|
uint32_t childDocCount = mChildDocs.Length();
|
|
|
|
for (uint32_t i = childDocCount - 1; i < childDocCount; i--)
|
|
|
|
mChildDocs[i]->Destroy();
|
|
|
|
|
2014-12-12 14:33:28 -08:00
|
|
|
mAccessibles.EnumerateEntries(ShutdownAccessibles, nullptr);
|
|
|
|
ProxyDestroyed(this);
|
2015-06-10 11:11:34 -07:00
|
|
|
if (mParentDoc)
|
|
|
|
mParentDoc->RemoveChildDoc(this);
|
|
|
|
else if (IsTopLevel())
|
|
|
|
GetAccService()->RemoteDocShutdown(this);
|
2014-03-07 13:35:19 -08:00
|
|
|
}
|
2015-06-10 11:11:34 -07:00
|
|
|
|
|
|
|
} // a11y
|
|
|
|
} // mozilla
|