Bug 571219 - remove unnecessary do_QueryObject, r=davidb

This commit is contained in:
Alexander Surkov 2010-06-12 13:04:50 +09:00
parent 5432bc50e6
commit d0a6b6bff5
15 changed files with 70 additions and 120 deletions

View File

@ -458,18 +458,18 @@ nsARIAGridAccessible::GetSelectedCells(nsIArray **aCells)
nsAccessible *row = nsnull;
while (row = rowIter.GetNext()) {
nsAccIterator cellIter(row, nsAccIterator::GetCell);
nsIAccessible *cell = nsnull;
nsAccessible *cell = nsnull;
if (nsAccUtils::IsARIASelected(row)) {
while (cell = cellIter.GetNext())
selCells->AppendElement(cell, PR_FALSE);
selCells->AppendElement(static_cast<nsIAccessible *>(cell), PR_FALSE);
continue;
}
while (cell = cellIter.GetNext()) {
if (nsAccUtils::IsARIASelected(cell))
selCells->AppendElement(cell, PR_FALSE);
selCells->AppendElement(static_cast<nsIAccessible *>(cell), PR_FALSE);
}
}
@ -1058,8 +1058,7 @@ nsARIAGridCellAccessible::IsSelected(PRBool *aIsSelected)
if (IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIAccessible> row;
GetParent(getter_AddRefs(row));
nsAccessible *row = GetParent();
if (nsAccUtils::Role(row) != nsIAccessibleRole::ROLE_ROW)
return NS_OK;
@ -1084,17 +1083,11 @@ nsARIAGridCellAccessible::GetARIAState(PRUint32 *aState, PRUint32 *aExtraState)
return NS_OK;
// Check aria-selected="true" on the row.
nsCOMPtr<nsIAccessible> row;
GetParent(getter_AddRefs(row));
nsAccessible *row = GetParent();
if (nsAccUtils::Role(row) != nsIAccessibleRole::ROLE_ROW)
return NS_OK;
nsRefPtr<nsAccessible> acc = do_QueryObject(row);
nsCOMPtr<nsIDOMNode> rowNode;
acc->GetDOMNode(getter_AddRefs(rowNode));
NS_ENSURE_STATE(rowNode);
nsCOMPtr<nsIContent> rowContent(do_QueryInterface(rowNode));
nsIContent *rowContent = row->GetContent();
if (nsAccUtils::HasDefinedARIAToken(rowContent,
nsAccessibilityAtoms::aria_selected) &&
!rowContent->AttrValueIs(kNameSpaceID_None,

View File

@ -101,15 +101,15 @@ nsAccUtils::SetAccGroupAttrs(nsIPersistentProperties *aAttributes,
}
PRInt32
nsAccUtils::GetDefaultLevel(nsAccessible *aAcc)
nsAccUtils::GetDefaultLevel(nsAccessible *aAccessible)
{
PRUint32 role = nsAccUtils::Role(aAcc);
PRUint32 role = nsAccUtils::Role(aAccessible);
if (role == nsIAccessibleRole::ROLE_OUTLINEITEM)
return 1;
if (role == nsIAccessibleRole::ROLE_ROW) {
nsCOMPtr<nsIAccessible> parent = aAcc->GetParent();
nsAccessible *parent = aAccessible->GetParent();
if (Role(parent) == nsIAccessibleRole::ROLE_TREE_TABLE) {
// It is a row inside flatten treegrid. Group level is always 1 until it
// is overriden by aria-level attribute.
@ -121,23 +121,16 @@ nsAccUtils::GetDefaultLevel(nsAccessible *aAcc)
}
PRInt32
nsAccUtils::GetARIAOrDefaultLevel(nsIAccessible *aAcc)
nsAccUtils::GetARIAOrDefaultLevel(nsAccessible *aAccessible)
{
nsRefPtr<nsAccessible> acc = do_QueryObject(aAcc);
NS_ENSURE_TRUE(acc, 0);
nsCOMPtr<nsIDOMNode> node;
acc->GetDOMNode(getter_AddRefs(node));
nsCOMPtr<nsIContent> content(do_QueryInterface(node));
NS_ENSURE_TRUE(content, 0);
PRInt32 level = 0;
nsCoreUtils::GetUIntAttr(content, nsAccessibilityAtoms::aria_level, &level);
nsCoreUtils::GetUIntAttr(aAccessible->GetContent(),
nsAccessibilityAtoms::aria_level, &level);
if (level != 0)
return level;
return GetDefaultLevel(acc);
return GetDefaultLevel(aAccessible);
}
void
@ -509,22 +502,11 @@ nsAccUtils::GetMultiSelectableContainer(nsINode *aNode)
}
PRBool
nsAccUtils::IsARIASelected(nsIAccessible *aAccessible)
nsAccUtils::IsARIASelected(nsAccessible *aAccessible)
{
nsRefPtr<nsAccessible> acc = do_QueryObject(aAccessible);
nsCOMPtr<nsIDOMNode> node;
acc->GetDOMNode(getter_AddRefs(node));
NS_ASSERTION(node, "No DOM node!");
if (node) {
nsCOMPtr<nsIContent> content(do_QueryInterface(node));
if (content->AttrValueIs(kNameSpaceID_None,
nsAccessibilityAtoms::aria_selected,
nsAccessibilityAtoms::_true, eCaseMatters))
return PR_TRUE;
}
return PR_FALSE;
return aAccessible->GetContent()->
AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::aria_selected,
nsAccessibilityAtoms::_true, eCaseMatters);
}
already_AddRefed<nsHyperTextAccessible>

View File

@ -107,7 +107,7 @@ public:
* Return ARIA level value or the default one if ARIA is missed for the
* given accessible.
*/
static PRInt32 GetARIAOrDefaultLevel(nsIAccessible *aAcc);
static PRInt32 GetARIAOrDefaultLevel(nsAccessible *aAccessible);
/**
* Compute position in group (posinset) and group size (setsize) for
@ -229,7 +229,7 @@ public:
* Return true if the DOM node of given accessible has aria-selected="true"
* attribute.
*/
static PRBool IsARIASelected(nsIAccessible *aAccessible);
static PRBool IsARIASelected(nsAccessible *aAccessible);
/**
* Return text accessible containing focus point of the given selection.

View File

@ -159,13 +159,16 @@ NS_IMETHODIMP nsAccessNode::GetUniqueID(void **aUniqueID)
}
// nsIAccessNode
NS_IMETHODIMP nsAccessNode::GetOwnerWindow(void **aWindow)
NS_IMETHODIMP
nsAccessNode::GetOwnerWindow(void **aWindow)
{
NS_ENSURE_ARG_POINTER(aWindow);
*aWindow = nsnull;
nsCOMPtr<nsIAccessibleDocument> docAccessible(GetDocAccessible());
if (!docAccessible)
return NS_ERROR_FAILURE; // This node or doc accessible is shut down
return docAccessible->GetWindowHandle(aWindow);
if (IsDefunct())
return NS_ERROR_FAILURE;
return GetDocAccessible()->GetWindowHandle(aWindow);
}
nsApplicationAccessible*
@ -292,6 +295,13 @@ nsPresContext* nsAccessNode::GetPresContext()
return presShell->GetPresContext();
}
nsDocAccessible *
nsAccessNode::GetDocAccessible() const
{
return mContent ?
GetAccService()->GetDocAccessible(mContent->GetOwnerDoc()) : nsnull;
}
already_AddRefed<nsRootAccessible> nsAccessNode::GetRootAccessible()
{
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
@ -318,7 +328,6 @@ nsAccessNode::GetFrame()
return mContent ? mContent->GetPrimaryFrame() : nsnull;
}
////////////////////////////////////////////////////////////////////////////////
// nsIAccessNode
@ -340,7 +349,7 @@ nsAccessNode::GetDocument(nsIAccessibleDocument **aDocument)
{
NS_ENSURE_ARG_POINTER(aDocument);
NS_IF_ADDREF(*aDocument = nsAccUtils::GetDocAccessibleFor(mWeakShell));
NS_IF_ADDREF(*aDocument = GetDocAccessible());
return NS_OK;
}
@ -494,12 +503,3 @@ nsAccessNode::GetLanguage(nsAString& aLanguage)
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsAccessNode protected
nsDocAccessible*
nsAccessNode::GetDocAccessible() const
{
return nsAccUtils::GetDocAccessibleFor(mWeakShell);
}

View File

@ -99,9 +99,9 @@ public:
static nsApplicationAccessible* GetApplicationAccessible();
/**
* Return the document accessible for this accesnode.
* Return the document accessible for this access node.
*/
nsDocAccessible* GetDocAccessible() const;
inline nsDocAccessible *GetDocAccessible() const;
/**
* Return the root document accessible for this accessnode.

View File

@ -262,7 +262,7 @@ nsCaretAccessible::NormalSelectionChanged(nsIDOMDocument *aDoc,
}
}
mLastCaretOffset = caretOffset;
mLastTextAccessible = textAcc;
mLastTextAccessible.swap(textAcc);
nsRefPtr<nsAccEvent> event =
new nsAccCaretMoveEvent(textNode);
@ -305,10 +305,7 @@ nsCaretAccessible::GetCaretRect(nsIWidget **aOutWidget)
return caretRect; // Return empty rect
}
nsRefPtr<nsAccessible> lastTextAccessible =
do_QueryObject(mLastTextAccessible);
nsINode *lastNodeWithCaret = lastTextAccessible->GetNode();
nsINode *lastNodeWithCaret = mLastTextAccessible->GetNode();
NS_ENSURE_TRUE(lastNodeWithCaret, caretRect);
nsIPresShell *presShell = nsCoreUtils::GetPresShellFor(lastNodeWithCaret);

View File

@ -38,17 +38,11 @@
#ifndef __nsCaretAccessible_h__
#define __nsCaretAccessible_h__
#include "nsIWeakReference.h"
#include "nsIAccessibleText.h"
#include "nsIContent.h"
#include "nsHyperTextAccessible.h"
#include "nsISelectionListener.h"
#include "nsISelectionController.h"
#include "nsRect.h"
class nsRootAccessible;
class nsIView;
class nsIPresShell;
class nsIWidget;
/*
* This special accessibility class is for the caret, which is really the currently focused selection.
@ -144,7 +138,7 @@ private:
// If it was on a control, then its control's selection. Otherwise, it's for
// a document where the selection changed.
nsCOMPtr<nsIWeakReference> mLastUsedSelection; // Weak ref to nsISelection
nsCOMPtr<nsIAccessibleText> mLastTextAccessible;
nsRefPtr<nsHyperTextAccessible> mLastTextAccessible;
PRInt32 mLastCaretOffset;
nsRootAccessible *mRootAccessible;

View File

@ -1483,12 +1483,9 @@ nsHTMLTableAccessible::IsProbablyForLayout(PRBool *aIsProbablyForLayout)
NS_ENSURE_TRUE(tableFrame , NS_ERROR_FAILURE);
nsSize tableSize = tableFrame->GetSize();
nsCOMPtr<nsIAccessibleDocument> docAccessible = GetDocAccessible();
nsDocAccessible *docAccessible = GetDocAccessible();
NS_ENSURE_TRUE(docAccessible, NS_ERROR_FAILURE);
nsRefPtr<nsAccessNode> docAccessNode = do_QueryObject(docAccessible);
nsIFrame *docFrame = docAccessNode->GetFrame();
nsIFrame *docFrame = docAccessible->GetFrame();
NS_ENSURE_TRUE(docFrame , NS_ERROR_FAILURE);
nsSize docSize = docFrame->GetSize();

View File

@ -742,7 +742,7 @@ PRInt32
nsHyperTextAccessible::GetRelativeOffset(nsIPresShell *aPresShell,
nsIFrame *aFromFrame,
PRInt32 aFromOffset,
nsIAccessible *aFromAccessible,
nsAccessible *aFromAccessible,
nsSelectionAmount aAmount,
nsDirection aDirection,
PRBool aNeedsStart)
@ -763,9 +763,7 @@ nsHyperTextAccessible::GetRelativeOffset(nsIPresShell *aPresShell,
nsresult rv;
PRInt32 contentOffset = aFromOffset;
if (nsAccUtils::IsText(aFromAccessible)) {
nsRefPtr<nsAccessNode> accessNode = do_QueryObject(aFromAccessible);
nsIFrame *frame = accessNode->GetFrame();
nsIFrame *frame = aFromAccessible->GetFrame();
NS_ENSURE_TRUE(frame, -1);
if (frame->GetType() == nsAccessibilityAtoms::textFrame) {
@ -954,10 +952,8 @@ nsresult nsHyperTextAccessible::GetTextHelper(EGetTextType aType, nsAccessibleTe
GetCharacterCount(&textLength);
if (aBoundaryType == BOUNDARY_LINE_START && aOffset > 0 && aOffset == textLength) {
// Asking for start of line, while on last character
if (startAcc) {
nsRefPtr<nsAccessNode> startAccessNode = do_QueryObject(startAcc);
startFrame = startAccessNode->GetFrame();
}
if (startAcc)
startFrame = startAcc->GetFrame();
}
if (!startFrame) {
return aOffset > textLength ? NS_ERROR_FAILURE : NS_OK;

View File

@ -186,7 +186,7 @@ protected:
* @return the resulting offset into this hypertext
*/
PRInt32 GetRelativeOffset(nsIPresShell *aPresShell, nsIFrame *aFromFrame,
PRInt32 aFromOffset, nsIAccessible *aFromAccessible,
PRInt32 aFromOffset, nsAccessible *aFromAccessible,
nsSelectionAmount aAmount, nsDirection aDirection,
PRBool aNeedsStart);

View File

@ -1727,14 +1727,13 @@ PRInt32 nsAccessibleWrap::GetChildIDFor(nsIAccessible* aAccessible)
}
HWND
nsAccessibleWrap::GetHWNDFor(nsIAccessible *aAccessible)
nsAccessibleWrap::GetHWNDFor(nsAccessible *aAccessible)
{
nsRefPtr<nsAccessNode> accessNode = do_QueryObject(aAccessible);
if (!accessNode)
return 0;
HWND hWnd = 0;
nsIFrame *frame = accessNode->GetFrame();
if (!aAccessible)
return hWnd;
nsIFrame *frame = aAccessible->GetFrame();
if (frame) {
nsIWidget *window = frame->GetWindow();
PRBool isVisible;
@ -1760,7 +1759,7 @@ nsAccessibleWrap::GetHWNDFor(nsIAccessible *aAccessible)
if (!hWnd) {
void* handle = nsnull;
nsDocAccessible *accessibleDoc = accessNode->GetDocAccessible();
nsDocAccessible *accessibleDoc = aAccessible->GetDocAccessible();
if (!accessibleDoc)
return 0;

View File

@ -311,7 +311,7 @@ public: // construction, destruction
// Helper methods
static PRInt32 GetChildIDFor(nsIAccessible* aAccessible);
static HWND GetHWNDFor(nsIAccessible *aAccessible);
static HWND GetHWNDFor(nsAccessible *aAccessible);
static HRESULT ConvertToIA2Attributes(nsIPersistentProperties *aAttributes,
BSTR *aIA2Attributes);

View File

@ -121,23 +121,19 @@ nsXFormsAccessible::CacheSelectChildren(nsIDOMNode *aContainerNode)
PRUint32 length = 0;
children->GetLength(&length);
nsCOMPtr<nsIAccessible> accessible;
nsRefPtr<nsAccessible> acc;
for (PRUint32 index = 0; index < length; index++) {
nsCOMPtr<nsIDOMNode> child;
children->Item(index, getter_AddRefs(child));
if (!child)
nsCOMPtr<nsIDOMNode> DOMChild;
children->Item(index, getter_AddRefs(DOMChild));
if (!DOMChild)
continue;
GetAccService()->GetAttachedAccessibleFor(child,
getter_AddRefs(accessible));
nsCOMPtr<nsIContent> child(do_QueryInterface(DOMChild));
nsAccessible *accessible = GetAccService()->GetAttachedAccessibleFor(child);
if (!accessible)
continue;
acc = do_QueryObject(accessible);
mChildren.AppendElement(acc);
acc->SetParent(this);
mChildren.AppendElement(accessible);
accessible->SetParent(this);
}
}

View File

@ -544,11 +544,9 @@ nsXULTreeAccessible::InvalidateCache(PRInt32 aRow, PRInt32 aCount)
accessible->Shutdown();
// Remove accessible from document cache and tree cache.
nsCOMPtr<nsIAccessibleDocument> docAccessible = GetDocAccessible();
if (docAccessible) {
nsRefPtr<nsDocAccessible> docAcc = do_QueryObject(docAccessible);
docAcc->RemoveAccessNodeFromCache(accessible);
}
nsDocAccessible *docAccessible = GetDocAccessible();
if (docAccessible)
docAccessible->RemoveAccessNodeFromCache(accessible);
mAccessibleCache.Remove(key);
}
@ -573,11 +571,9 @@ nsXULTreeAccessible::InvalidateCache(PRInt32 aRow, PRInt32 aCount)
accessible->Shutdown();
// Remove accessible from document cache and tree cache.
nsCOMPtr<nsIAccessibleDocument> docAccessible = GetDocAccessible();
if (docAccessible) {
nsRefPtr<nsDocAccessible> docAcc = do_QueryObject(docAccessible);
docAcc->RemoveAccessNodeFromCache(accessible);
}
nsDocAccessible *docAccessible = GetDocAccessible();
if (docAccessible)
docAccessible->RemoveAccessNodeFromCache(accessible);
mAccessibleCache.Remove(key);
}