2012-05-21 04:12:37 -07: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/. */
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
#ifndef nsAccDocManager_h_
|
|
|
|
#define nsAccDocManager_h_
|
|
|
|
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMEventListener.h"
|
2011-01-27 20:38:14 -08:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2010-06-08 09:39:58 -07:00
|
|
|
#include "nsIWebProgress.h"
|
|
|
|
#include "nsIWebProgressListener.h"
|
|
|
|
#include "nsWeakReference.h"
|
2012-04-16 22:29:47 -07:00
|
|
|
#include "nsIPresShell.h"
|
2010-06-08 09:39:58 -07:00
|
|
|
|
2011-01-27 20:38:14 -08:00
|
|
|
class nsAccessible;
|
2010-06-08 09:39:58 -07:00
|
|
|
class nsDocAccessible;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manage the document accessible life cycle.
|
|
|
|
*/
|
|
|
|
class nsAccDocManager : public nsIWebProgressListener,
|
|
|
|
public nsIDOMEventListener,
|
|
|
|
public nsSupportsWeakReference
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~nsAccDocManager() { };
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBPROGRESSLISTENER
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return document accessible for the given DOM node.
|
|
|
|
*/
|
|
|
|
nsDocAccessible *GetDocAccessible(nsIDocument *aDocument);
|
|
|
|
|
2012-04-16 22:29:47 -07:00
|
|
|
/**
|
|
|
|
* Return document accessible for the given presshell.
|
|
|
|
*/
|
|
|
|
nsDocAccessible* GetDocAccessible(const nsIPresShell* aPresShell)
|
|
|
|
{
|
|
|
|
return aPresShell ? GetDocAccessible(aPresShell->GetDocument()) : nsnull;
|
|
|
|
}
|
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
/**
|
|
|
|
* Search through all document accessibles for an accessible with the given
|
|
|
|
* unique id.
|
|
|
|
*/
|
2010-10-20 21:16:10 -07:00
|
|
|
nsAccessible* FindAccessibleInCache(nsINode* aNode) const;
|
2010-06-08 09:39:58 -07:00
|
|
|
|
2010-06-17 19:44:09 -07:00
|
|
|
/**
|
|
|
|
* Return document accessible from the cache. Convenient method for testing.
|
|
|
|
*/
|
|
|
|
inline nsDocAccessible* GetDocAccessibleFromCache(nsIDocument* aDocument) const
|
|
|
|
{
|
2010-10-20 21:16:10 -07:00
|
|
|
return mDocAccessibleCache.GetWeak(aDocument);
|
2010-06-17 19:44:09 -07:00
|
|
|
}
|
|
|
|
|
2010-10-28 02:34:26 -07:00
|
|
|
/**
|
|
|
|
* Called by document accessible when it gets shutdown.
|
|
|
|
*/
|
|
|
|
inline void NotifyOfDocumentShutdown(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
mDocAccessibleCache.Remove(aDocument);
|
|
|
|
}
|
|
|
|
|
2011-10-05 19:10:30 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool IsProcessingRefreshDriverNotification() const;
|
|
|
|
#endif
|
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
protected:
|
|
|
|
nsAccDocManager() { };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the manager.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Init();
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shutdown the manager.
|
|
|
|
*/
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsAccDocManager(const nsAccDocManager&);
|
|
|
|
nsAccDocManager& operator =(const nsAccDocManager&);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Create an accessible document if it was't created and fire accessibility
|
|
|
|
* events if needed.
|
|
|
|
*
|
|
|
|
* @param aDocument [in] loaded DOM document
|
|
|
|
* @param aLoadEventType [in] specifies the event type to fire load event,
|
|
|
|
* if 0 then no event is fired
|
|
|
|
*/
|
|
|
|
void HandleDOMDocumentLoad(nsIDocument *aDocument,
|
2010-11-22 00:22:04 -08:00
|
|
|
PRUint32 aLoadEventType);
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
/**
|
2010-06-17 19:44:09 -07:00
|
|
|
* Add 'pagehide' and 'DOMContentLoaded' event listeners.
|
2010-06-08 09:39:58 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
void AddListeners(nsIDocument *aDocument, bool aAddPageShowListener);
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create document or root accessible.
|
|
|
|
*/
|
|
|
|
nsDocAccessible *CreateDocOrRootAccessible(nsIDocument *aDocument);
|
|
|
|
|
2010-10-20 21:16:10 -07:00
|
|
|
typedef nsRefPtrHashtable<nsPtrHashKey<const nsIDocument>, nsDocAccessible>
|
2010-06-08 09:39:58 -07:00
|
|
|
nsDocAccessibleHashtable;
|
|
|
|
|
|
|
|
/**
|
2010-12-02 08:07:14 -08:00
|
|
|
* Get first entry of the document accessible from cache.
|
2010-06-08 09:39:58 -07:00
|
|
|
*/
|
|
|
|
static PLDHashOperator
|
2010-12-02 08:07:14 -08:00
|
|
|
GetFirstEntryInDocCache(const nsIDocument* aKey,
|
|
|
|
nsDocAccessible* aDocAccessible,
|
|
|
|
void* aUserArg);
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the cache and shutdown the document accessibles.
|
|
|
|
*/
|
2010-12-02 08:07:14 -08:00
|
|
|
void ClearDocCache();
|
2010-06-08 09:39:58 -07:00
|
|
|
|
|
|
|
struct nsSearchAccessibleInCacheArg
|
|
|
|
{
|
2010-06-11 21:04:35 -07:00
|
|
|
nsAccessible *mAccessible;
|
2010-10-20 21:16:10 -07:00
|
|
|
nsINode* mNode;
|
2010-06-08 09:39:58 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static PLDHashOperator
|
2010-10-20 21:16:10 -07:00
|
|
|
SearchAccessibleInDocCache(const nsIDocument* aKey,
|
2010-06-08 09:39:58 -07:00
|
|
|
nsDocAccessible* aDocAccessible,
|
|
|
|
void* aUserArg);
|
|
|
|
|
2011-10-05 19:10:30 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
static PLDHashOperator
|
|
|
|
SearchIfDocIsRefreshing(const nsIDocument* aKey,
|
|
|
|
nsDocAccessible* aDocAccessible, void* aUserArg);
|
|
|
|
#endif
|
|
|
|
|
2010-06-08 09:39:58 -07:00
|
|
|
nsDocAccessibleHashtable mDocAccessibleCache;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsAccDocManager_h_
|