2014-03-07 21:35:19 +00: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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_a11y_DocAccessibleParent_h
|
|
|
|
#define mozilla_a11y_DocAccessibleParent_h
|
|
|
|
|
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#include "ProxyAccessible.h"
|
|
|
|
#include "mozilla/a11y/PDocAccessibleParent.h"
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These objects live in the main process and comunicate with and represent
|
|
|
|
* an accessible document in a content process.
|
|
|
|
*/
|
|
|
|
class DocAccessibleParent : public ProxyAccessible,
|
|
|
|
public PDocAccessibleParent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DocAccessibleParent() :
|
2015-01-14 04:42:27 +00:00
|
|
|
ProxyAccessible(this), mParentDoc(nullptr), mShutdown(false)
|
2014-03-07 21:35:19 +00:00
|
|
|
{ MOZ_COUNT_CTOR_INHERITED(DocAccessibleParent, ProxyAccessible); }
|
|
|
|
~DocAccessibleParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR_INHERITED(DocAccessibleParent, ProxyAccessible);
|
|
|
|
MOZ_ASSERT(mChildDocs.Length() == 0);
|
|
|
|
MOZ_ASSERT(!mParentDoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when a message from a document in a child process notifies the main
|
|
|
|
* process it is firing an event.
|
|
|
|
*/
|
2014-09-30 14:00:26 +00:00
|
|
|
virtual bool RecvEvent(const uint64_t& aID, const uint32_t& aType)
|
2015-03-21 16:28:04 +00:00
|
|
|
override;
|
2014-03-07 21:35:19 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool RecvShowEvent(const ShowEventData& aData) override;
|
|
|
|
virtual bool RecvHideEvent(const uint64_t& aRootID) override;
|
2014-03-07 21:35:19 +00:00
|
|
|
|
2015-03-24 17:52:59 +00:00
|
|
|
virtual bool RecvBindChildDoc(PDocAccessibleParent* aChildDoc, const uint64_t& aID) override;
|
|
|
|
void Unbind()
|
|
|
|
{
|
|
|
|
mParent = nullptr;
|
|
|
|
mParentDoc->mChildDocs.RemoveElement(this);
|
|
|
|
mParentDoc = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-14 04:42:27 +00:00
|
|
|
void Destroy();
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void ActorDestroy(ActorDestroyReason aWhy) override
|
2015-01-14 04:42:27 +00:00
|
|
|
{
|
|
|
|
if (!mShutdown)
|
|
|
|
Destroy();
|
|
|
|
}
|
2014-03-07 21:35:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the main processes representation of the parent document (if any)
|
|
|
|
* of the document this object represents.
|
|
|
|
*/
|
|
|
|
DocAccessibleParent* Parent() const { return mParentDoc; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when a document in a content process notifies the main process of a
|
|
|
|
* new child document.
|
|
|
|
*/
|
2015-03-24 17:52:59 +00:00
|
|
|
bool AddChildDoc(DocAccessibleParent* aChildDoc, uint64_t aParentID,
|
|
|
|
bool aCreating = true);
|
2014-03-07 21:35:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when the document in the content process this object represents
|
|
|
|
* notifies the main process a child document has been removed.
|
|
|
|
*/
|
|
|
|
void RemoveChildDoc(DocAccessibleParent* aChildDoc)
|
|
|
|
{
|
|
|
|
aChildDoc->mParent->SetChildDoc(nullptr);
|
|
|
|
mChildDocs.RemoveElement(aChildDoc);
|
|
|
|
aChildDoc->mParentDoc = nullptr;
|
|
|
|
MOZ_ASSERT(aChildDoc->mChildDocs.Length() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveAccessible(ProxyAccessible* aAccessible)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mAccessibles.GetEntry(aAccessible->ID()));
|
|
|
|
mAccessibles.RemoveEntry(aAccessible->ID());
|
|
|
|
}
|
|
|
|
|
2015-01-29 16:58:34 +00:00
|
|
|
/**
|
|
|
|
* Return the accessible for given id.
|
|
|
|
*/
|
|
|
|
ProxyAccessible* GetAccessible(uintptr_t aID) const
|
|
|
|
{
|
|
|
|
ProxyEntry* e = mAccessibles.GetEntry(aID);
|
|
|
|
return e ? e->mProxy : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-03-07 21:35:19 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
class ProxyEntry : public PLDHashEntryHdr
|
|
|
|
{
|
|
|
|
public:
|
2014-10-10 21:28:35 +00:00
|
|
|
explicit ProxyEntry(const void*) : mProxy(nullptr) {}
|
2014-03-07 21:35:19 +00:00
|
|
|
ProxyEntry(ProxyEntry&& aOther) :
|
|
|
|
mProxy(aOther.mProxy) { aOther.mProxy = nullptr; }
|
|
|
|
~ProxyEntry() { delete mProxy; }
|
|
|
|
|
|
|
|
typedef uint64_t KeyType;
|
|
|
|
typedef const void* KeyTypePointer;
|
|
|
|
|
|
|
|
bool KeyEquals(const void* aKey) const
|
|
|
|
{ return mProxy->ID() == (uint64_t)aKey; }
|
|
|
|
|
|
|
|
static const void* KeyToPointer(uint64_t aKey) { return (void*)aKey; }
|
|
|
|
|
|
|
|
static PLDHashNumber HashKey(const void* aKey) { return (uint64_t)aKey; }
|
|
|
|
|
|
|
|
enum { ALLOW_MEMMOVE = true };
|
|
|
|
|
|
|
|
ProxyAccessible* mProxy;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t AddSubtree(ProxyAccessible* aParent,
|
|
|
|
const nsTArray<AccessibleData>& aNewTree, uint32_t aIdx,
|
|
|
|
uint32_t aIdxInParent);
|
2014-12-12 22:33:28 +00:00
|
|
|
static PLDHashOperator ShutdownAccessibles(ProxyEntry* entry, void* unused);
|
2014-03-07 21:35:19 +00:00
|
|
|
|
|
|
|
nsTArray<DocAccessibleParent*> mChildDocs;
|
|
|
|
DocAccessibleParent* mParentDoc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Conceptually this is a map from IDs to proxies, but we store the ID in the
|
|
|
|
* proxy object so we can't use a real map.
|
|
|
|
*/
|
|
|
|
nsTHashtable<ProxyEntry> mAccessibles;
|
2015-01-14 04:42:27 +00:00
|
|
|
bool mShutdown;
|
2014-03-07 21:35:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|