Bug 552643 - store nsDocAccessible in global document cache, r=davidb

This commit is contained in:
Alexander Surkov 2010-03-17 14:02:28 +08:00
parent b7591379a4
commit 975c206c83
7 changed files with 75 additions and 54 deletions

View File

@ -36,7 +36,7 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsAccessNode.h"
#include "nsDocAccessible.h"
#include "nsIAccessible.h"
#include "nsAccessibilityAtoms.h"
#include "nsHashtable.h"
@ -78,7 +78,8 @@ nsIDOMNode *nsAccessNode::gLastFocusedNode = 0;
PRBool nsAccessNode::gIsCacheDisabled = PR_FALSE;
PRBool nsAccessNode::gIsFormFillEnabled = PR_FALSE;
nsAccessNodeHashtable nsAccessNode::gGlobalDocAccessibleCache;
nsRefPtrHashtable<nsVoidPtrHashKey, nsDocAccessible>
nsAccessNode::gGlobalDocAccessibleCache;
nsApplicationAccessibleWrap *nsAccessNode::gApplicationAccessible = nsnull;
@ -346,12 +347,6 @@ nsPresContext* nsAccessNode::GetPresContext()
return presShell->GetPresContext();
}
// nsAccessNode protected
already_AddRefed<nsIAccessibleDocument> nsAccessNode::GetDocAccessible()
{
return GetDocAccessibleFor(mWeakShell); // Addref'd
}
already_AddRefed<nsRootAccessible> nsAccessNode::GetRootAccessible()
{
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
@ -432,9 +427,11 @@ nsAccessNode::GetNumChildren(PRInt32 *aNumChildren)
}
NS_IMETHODIMP
nsAccessNode::GetAccessibleDocument(nsIAccessibleDocument **aDocAccessible)
nsAccessNode::GetAccessibleDocument(nsIAccessibleDocument **aAccessibleDocument)
{
*aDocAccessible = GetDocAccessibleFor(mWeakShell).get();
NS_ENSURE_ARG_POINTER(aAccessibleDocument);
NS_IF_ADDREF(*aAccessibleDocument = GetDocAccessibleFor(mWeakShell));
return NS_OK;
}
@ -643,19 +640,14 @@ nsAccessNode::GetComputedStyleCSSValue(const nsAString& aPseudoElt,
////////////////////////////////////////////////////////////////////////////////
// nsAccessNode public static
already_AddRefed<nsIAccessibleDocument>
nsDocAccessible*
nsAccessNode::GetDocAccessibleFor(nsIDocument *aDocument)
{
if (!aDocument) {
return nsnull;
}
nsCOMPtr<nsIAccessibleDocument> docAccessible(do_QueryInterface(
gGlobalDocAccessibleCache.GetWeak(static_cast<void*>(aDocument))));
return docAccessible.forget();
return aDocument ?
gGlobalDocAccessibleCache.GetWeak(static_cast<void*>(aDocument)) : nsnull;
}
already_AddRefed<nsIAccessibleDocument>
nsDocAccessible*
nsAccessNode::GetDocAccessibleFor(nsIWeakReference *aWeakShell)
{
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(aWeakShell));
@ -663,7 +655,7 @@ nsAccessNode::GetDocAccessibleFor(nsIWeakReference *aWeakShell)
return nsnull;
}
return nsAccessNode::GetDocAccessibleFor(presShell->GetDocument());
return GetDocAccessibleFor(presShell->GetDocument());
}
already_AddRefed<nsIAccessibleDocument>
@ -675,7 +667,12 @@ nsAccessNode::GetDocAccessibleFor(nsIDocShellTreeItem *aContainer,
NS_ASSERTION(docShell, "This method currently only supports docshells");
nsCOMPtr<nsIPresShell> presShell;
docShell->GetPresShell(getter_AddRefs(presShell));
return presShell ? GetDocAccessibleFor(presShell->GetDocument()) : nsnull;
if (!presShell)
return nsnull;
nsDocAccessible *docAcc = GetDocAccessibleFor(presShell->GetDocument());
NS_IF_ADDREF(docAcc);
return docAcc;
}
nsCOMPtr<nsIDOMNode> node = nsCoreUtils::GetDOMNodeForContainer(aContainer);
@ -692,7 +689,7 @@ nsAccessNode::GetDocAccessibleFor(nsIDocShellTreeItem *aContainer,
return docAccessible;
}
already_AddRefed<nsIAccessibleDocument>
nsDocAccessible*
nsAccessNode::GetDocAccessibleFor(nsIDOMNode *aNode)
{
nsCOMPtr<nsIPresShell> eventShell = nsCoreUtils::GetPresShellFor(aNode);
@ -778,3 +775,12 @@ nsAccessNode::GetLanguage(nsAString& aLanguage)
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsAccessNode protected
nsDocAccessible*
nsAccessNode::GetDocAccessible() const
{
return GetDocAccessibleFor(mWeakShell);
}

View File

@ -62,6 +62,7 @@ class nsPresContext;
class nsIAccessibleDocument;
class nsIFrame;
class nsIDOMNodeList;
class nsDocAccessible;
class nsRootAccessible;
class nsApplicationAccessibleWrap;
class nsIDocShellTreeItem;
@ -123,12 +124,6 @@ class nsAccessNode: public nsIAccessNode
*/
static already_AddRefed<nsApplicationAccessibleWrap> GetApplicationAccessible();
// Static cache methods for global document cache
static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsIDocument *aDocument);
static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsIWeakReference *aWeakShell);
static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsIDocShellTreeItem *aContainer, PRBool aCanCreate = PR_FALSE);
static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsIDOMNode *aNode);
already_AddRefed<nsRootAccessible> GetRootAccessible();
static nsIDOMNode *gLastFocusedNode;
@ -173,11 +168,30 @@ class nsAccessNode: public nsIAccessNode
PRBool IsInCache();
#endif
/**
* Return cached document accessible.
*/
static nsDocAccessible* GetDocAccessibleFor(nsIDocument *aDocument);
static nsDocAccessible* GetDocAccessibleFor(nsIWeakReference *aWeakShell);
static nsDocAccessible* GetDocAccessibleFor(nsIDOMNode *aNode);
/**
* Return document accessible.
*/
static already_AddRefed<nsIAccessibleDocument>
GetDocAccessibleFor(nsIDocShellTreeItem *aContainer,
PRBool aCanCreate = PR_FALSE);
protected:
nsresult MakeAccessNode(nsIDOMNode *aNode, nsIAccessNode **aAccessNode);
nsPresContext* GetPresContext();
already_AddRefed<nsIAccessibleDocument> GetDocAccessible();
/**
* Return the document accessible for this accesnode.
*/
nsDocAccessible* GetDocAccessible() const;
void LastRelease();
nsCOMPtr<nsIDOMNode> mDOMNode;
@ -199,7 +213,8 @@ protected:
static PRBool gIsCacheDisabled;
static PRBool gIsFormFillEnabled;
static nsAccessNodeHashtable gGlobalDocAccessibleCache;
static nsRefPtrHashtable<nsVoidPtrHashKey, nsDocAccessible>
gGlobalDocAccessibleCache;
private:
static nsApplicationAccessibleWrap *gApplicationAccessible;

View File

@ -38,13 +38,12 @@
* ***** END LICENSE BLOCK ***** */
#include "nsAccessible.h"
#include "nsAccessibleRelation.h"
#include "nsHyperTextAccessibleWrap.h"
#include "nsIAccessibleDocument.h"
#include "nsIAccessibleHyperText.h"
#include "nsIXBLAccessible.h"
#include "nsAccTreeWalker.h"
#include "nsAccessibleRelation.h"
#include "nsDocAccessible.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
@ -2900,7 +2899,7 @@ nsAccessible::GetParent()
if (mParent)
return mParent;
nsCOMPtr<nsIAccessibleDocument> docAccessible(GetDocAccessible());
nsDocAccessible *docAccessible = GetDocAccessible();
NS_ASSERTION(docAccessible, "No document accessible for valid accessible!");
if (!docAccessible)

View File

@ -38,7 +38,9 @@
* ***** END LICENSE BLOCK ***** */
#include "nsHTMLTableAccessible.h"
#include "nsAccessibilityAtoms.h"
#include "nsDocAccessible.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentRange.h"
@ -1374,7 +1376,7 @@ nsHTMLTableAccessible::IsProbablyForLayout(PRBool *aIsProbablyForLayout)
if (IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIAccessible> docAccessible = do_QueryInterface(nsCOMPtr<nsIAccessibleDocument>(GetDocAccessible()));
nsDocAccessible *docAccessible = GetDocAccessible();
if (docAccessible) {
PRUint32 state, extState;
docAccessible->GetState(&state, &extState);

View File

@ -38,8 +38,9 @@
* ***** END LICENSE BLOCK ***** */
#include "nsHTMLTextAccessible.h"
#include "nsIAccessibleDocument.h"
#include "nsIAccessibleEvent.h"
#include "nsDocAccessible.h"
#include "nsIFrame.h"
#include "nsPresContext.h"
#include "nsIPresShell.h"
@ -86,8 +87,7 @@ nsHTMLTextAccessible::GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState)
nsresult rv = nsTextAccessible::GetStateInternal(aState, aExtraState);
NS_ENSURE_A11Y_SUCCESS(rv, rv);
nsCOMPtr<nsIAccessible> docAccessible =
do_QueryInterface(nsCOMPtr<nsIAccessibleDocument>(GetDocAccessible()));
nsDocAccessible *docAccessible = GetDocAccessible();
if (docAccessible) {
PRUint32 state, extState;
docAccessible->GetState(&state, &extState);

View File

@ -283,20 +283,17 @@ struct nsSearchAccessibleInCacheArg
};
static PLDHashOperator
SearchAccessibleInCache(const void* aKey, nsAccessNode* aAccessNode,
SearchAccessibleInCache(const void* aKey, nsDocAccessible* aDocAccessible,
void* aUserArg)
{
nsCOMPtr<nsIAccessibleDocument> accessibleDoc(do_QueryInterface(aAccessNode));
NS_ASSERTION(accessibleDoc,
NS_ASSERTION(aDocAccessible,
"No doc accessible for the object in doc accessible cache!");
nsRefPtr<nsDocAccessible> docAccessible =
nsAccUtils::QueryObject<nsDocAccessible>(accessibleDoc);
if (docAccessible) {
if (aDocAccessible) {
nsSearchAccessibleInCacheArg* arg =
static_cast<nsSearchAccessibleInCacheArg*>(aUserArg);
nsAccessNode* accessNode =
docAccessible->GetCachedAccessNode(arg->mUniqueID);
aDocAccessible->GetCachedAccessNode(arg->mUniqueID);
if (accessNode) {
arg->mAccessNode = accessNode;
return PL_DHASH_STOP;

View File

@ -39,7 +39,9 @@
// NOTE: alphabetically ordered
#include "nsTextAccessibleWrap.h"
#include "ISimpleDOMText_i.c"
#include "nsIAccessibleDocument.h"
#include "nsDocAccessible.h"
#include "nsIFontMetrics.h"
#include "nsIFrame.h"
#include "nsPresContext.h"
@ -120,11 +122,11 @@ __try {
return rv;
}
nsCOMPtr<nsIAccessibleDocument> docAccessible(GetDocAccessible());
nsCOMPtr<nsIAccessible> accessible(do_QueryInterface(docAccessible));
NS_ASSERTION(accessible, "There must always be a doc accessible, but there isn't");
nsDocAccessible *docAccessible = GetDocAccessible();
NS_ASSERTION(docAccessible,
"There must always be a doc accessible, but there isn't. Crash!");
accessible->GetBounds(&docX, &docY, &docWidth, &docHeight);
docAccessible->GetBounds(&docX, &docY, &docWidth, &docHeight);
nsIntRect unclippedRect(x, y, width, height);
nsIntRect docRect(docX, docY, docWidth, docHeight);