Bug 636945 - add downcasting for nsRootAccessible, r=davidb, a=davidb

This commit is contained in:
Alexander Surkov 2011-03-02 13:16:28 +08:00
parent 8e6b06a6d3
commit 0f5d250d99
10 changed files with 27 additions and 15 deletions

View File

@ -1081,7 +1081,7 @@ nsAccessibleWrap::FirePlatformEvent(AccEvent* aEvent)
case nsIAccessibleEvent::EVENT_FOCUS:
{
MAI_LOG_DEBUG(("\n\nReceived: EVENT_FOCUS\n"));
nsRefPtr<nsRootAccessible> rootAccWrap = accWrap->GetRootAccessible();
nsRootAccessible* rootAccWrap = accWrap->RootAccessible();
if (rootAccWrap && rootAccWrap->mActivated) {
atk_focus_tracker_notify(atkObj);
// Fire state change event for focus

View File

@ -285,7 +285,8 @@ nsAccessNode::GetDocAccessible() const
GetAccService()->GetDocAccessible(mContent->GetOwnerDoc()) : nsnull;
}
already_AddRefed<nsRootAccessible> nsAccessNode::GetRootAccessible()
nsRootAccessible*
nsAccessNode::RootAccessible() const
{
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
nsCoreUtils::GetDocShellTreeItemFor(mContent);
@ -300,9 +301,8 @@ already_AddRefed<nsRootAccessible> nsAccessNode::GetRootAccessible()
return nsnull;
}
nsDocAccessible *docAcc = nsAccUtils::GetDocAccessibleFor(root);
nsRefPtr<nsRootAccessible> rootAcc = do_QueryObject(docAcc);
return rootAcc.forget();
nsDocAccessible* docAcc = nsAccUtils::GetDocAccessibleFor(root);
return docAcc ? docAcc->AsRoot() : nsnull;
}
nsIFrame*
@ -347,8 +347,8 @@ nsAccessNode::GetRootDocument(nsIAccessibleDocument **aRootDocument)
{
NS_ENSURE_ARG_POINTER(aRootDocument);
nsRefPtr<nsRootAccessible> rootDocument = GetRootAccessible();
NS_IF_ADDREF(*aRootDocument = rootDocument.get());
nsRootAccessible* rootDocument = RootAccessible();
NS_IF_ADDREF(*aRootDocument = rootDocument);
return NS_OK;
}

View File

@ -105,7 +105,7 @@ public:
/**
* Return the root document accessible for this accessnode.
*/
already_AddRefed<nsRootAccessible> GetRootAccessible();
nsRootAccessible* RootAccessible() const;
/**
* Reference to a node of focused accessible.

View File

@ -364,6 +364,9 @@ public:
inline bool IsHyperText() const { return mFlags & eHyperTextAccessible; }
nsHyperTextAccessible* AsHyperText();
inline bool IsRoot() const { return mFlags & eRootAccessible; }
nsRootAccessible* AsRoot();
inline bool IsTextLeaf() const { return mFlags & eTextLeafAccessible; }
nsTextAccessible* AsTextLeaf();
@ -509,7 +512,8 @@ protected:
enum AccessibleTypes {
eApplicationAccessible = 1 << 2,
eHyperTextAccessible = 1 << 3,
eTextLeafAccessible = 1 << 4
eRootAccessible = 1 << 4,
eTextLeafAccessible = 1 << 5
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -770,7 +770,7 @@ nsresult nsDocAccessible::AddEventListeners()
nsCOMPtr<nsIDocShellTreeItem> rootTreeItem;
docShellTreeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem));
if (rootTreeItem) {
nsRefPtr<nsRootAccessible> rootAccessible = GetRootAccessible();
nsRootAccessible* rootAccessible = RootAccessible();
NS_ENSURE_TRUE(rootAccessible, NS_ERROR_FAILURE);
nsRefPtr<nsCaretAccessible> caretAccessible = rootAccessible->GetCaretAccessible();
if (caretAccessible) {
@ -817,7 +817,7 @@ nsresult nsDocAccessible::RemoveEventListeners()
NS_RELEASE_THIS(); // Kung fu death grip
}
nsRefPtr<nsRootAccessible> rootAccessible(GetRootAccessible());
nsRootAccessible* rootAccessible = RootAccessible();
if (rootAccessible) {
nsRefPtr<nsCaretAccessible> caretAccessible = rootAccessible->GetCaretAccessible();
if (caretAccessible) {
@ -1135,7 +1135,7 @@ nsDocAccessible::ARIAAttributeChanged(nsIContent* aContent, nsIAtom* aAttribute)
nsCOMPtr<nsINode> focusedNode = GetCurrentFocus();
if (nsCoreUtils::GetRoleContent(focusedNode) == aContent) {
nsAccessible* focusedAcc = GetAccService()->GetAccessible(focusedNode);
nsRefPtr<nsRootAccessible> rootAcc = GetRootAccessible();
nsRootAccessible* rootAcc = RootAccessible();
if (rootAcc && focusedAcc) {
rootAcc->FireAccessibleFocusEvent(focusedAcc, nsnull, PR_TRUE);
}

View File

@ -112,6 +112,7 @@ nsRootAccessible::
nsIWeakReference *aShell) :
nsDocAccessibleWrap(aDocument, aRootContent, aShell)
{
mFlags |= eRootAccessible;
}
nsRootAccessible::~nsRootAccessible()

View File

@ -164,4 +164,11 @@ protected:
NS_DEFINE_STATIC_IID_ACCESSOR(nsRootAccessible, NS_ROOTACCESSIBLE_IMPL_CID)
inline nsRootAccessible*
nsAccessible::AsRoot()
{
return mFlags & eRootAccessible ?
static_cast<nsRootAccessible*>(this) : nsnull;
}
#endif

View File

@ -365,7 +365,7 @@ GetNativeFromGeckoAccessible(nsIAccessible *anAccessible)
// (which might be the owning NSWindow in the application, for example).
//
// get the native root accessible, and tell it to return its first parent unignored accessible.
nsRefPtr<nsRootAccessible> root(mGeckoAccessible->GetRootAccessible());
nsRootAccessible* root = mGeckoAccessible->RootAccessible();
id nativeParent = GetNativeFromGeckoAccessible(static_cast<nsIAccessible*>(root));
NSAssert1 (nativeParent, @"!!! we can't find a parent for %@", self);

View File

@ -1772,7 +1772,7 @@ void nsAccessibleWrap::UpdateSystemCaret()
// off-screen model can follow the caret
::DestroyCaret();
nsRefPtr<nsRootAccessible> rootAccessible = GetRootAccessible();
nsRootAccessible* rootAccessible = RootAccessible();
if (!rootAccessible) {
return;
}

View File

@ -258,7 +258,7 @@ nsDocAccessibleWrap::Init()
if (nsWinUtils::IsWindowEmulationEnabled()) {
// Create window for tab document.
if (nsWinUtils::IsTabDocument(mDocument)) {
nsRefPtr<nsRootAccessible> root = GetRootAccessible();
nsRootAccessible* root = RootAccessible();
mHWND = nsWinUtils::CreateNativeWindow(kClassNameTabContent,
static_cast<HWND>(root->GetNativeWindow()));