зеркало из https://github.com/mozilla/gecko-dev.git
bug288848 Various memory leaks in nsAccessibleHyperText
r = aaronleventhal sr = bzbarsky
This commit is contained in:
Родитель
118f1222ed
Коммит
3a7a80d055
|
@ -67,7 +67,7 @@ nsAccessibleHyperText::nsAccessibleHyperText(nsIDOMNode* aDomNode, nsIWeakRefere
|
|||
|
||||
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(aShell));
|
||||
if (shell) {
|
||||
NS_NewISupportsArray(getter_AddRefs(mTextChildren));
|
||||
NS_NewArray(getter_AddRefs(mTextChildren));
|
||||
if (mTextChildren) {
|
||||
nsIFrame *frame = nsnull;
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(aDomNode));
|
||||
|
@ -113,10 +113,10 @@ PRBool nsAccessibleHyperText::GetAllTextChildren(nsPresContext *aPresContext, ns
|
|||
#endif
|
||||
// some long text node may be divided into several frames,
|
||||
// so we must check whether this node is already in the array
|
||||
PRInt32 index = -1;
|
||||
mTextChildren->GetIndexOf(node, &index);
|
||||
if (index < 0) {
|
||||
mTextChildren->AppendElement(node);
|
||||
PRUint32 index;
|
||||
nsresult rv = mTextChildren->IndexOf(0, node, &index);
|
||||
if (NS_FAILED(rv)) {
|
||||
mTextChildren->AppendElement(node, PR_FALSE);
|
||||
}
|
||||
bSave = PR_TRUE;
|
||||
}
|
||||
|
@ -145,9 +145,9 @@ nsIDOMNode* nsAccessibleHyperText::FindTextNodeByOffset(PRInt32 aOffset, PRInt32
|
|||
aBeforeLength = 0;
|
||||
|
||||
PRUint32 index, count;
|
||||
mTextChildren->Count(&count);
|
||||
mTextChildren->GetLength(&count);
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIDOMNode* domNode = (nsIDOMNode *)mTextChildren->ElementAt(index);
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(mTextChildren, index));
|
||||
nsAccessibleText accText(domNode);
|
||||
PRInt32 charCount;
|
||||
if (NS_SUCCEEDED(accText.GetCharacterCount(&charCount))) {
|
||||
|
@ -186,9 +186,10 @@ NS_IMETHODIMP nsAccessibleHyperText::GetCaretOffset(PRInt32 *aCaretOffset)
|
|||
|
||||
PRInt32 charCount, caretOffset;
|
||||
PRUint32 index, count;
|
||||
mTextChildren->Count(&count);
|
||||
mTextChildren->GetLength(&count);
|
||||
for (index = 0; index < count; index++) {
|
||||
nsAccessibleText accText((nsIDOMNode *)mTextChildren->ElementAt(index));
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(mTextChildren, index));
|
||||
nsAccessibleText accText(domNode);
|
||||
if (NS_SUCCEEDED(accText.GetCaretOffset(&caretOffset))) {
|
||||
*aCaretOffset += caretOffset;
|
||||
return NS_OK;
|
||||
|
@ -221,9 +222,10 @@ NS_IMETHODIMP nsAccessibleHyperText::GetCharacterCount(PRInt32 *aCharacterCount)
|
|||
|
||||
PRInt32 charCount;
|
||||
PRUint32 index, count;
|
||||
mTextChildren->Count(&count);
|
||||
mTextChildren->GetLength(&count);
|
||||
for (index = 0; index < count; index++) {
|
||||
nsAccessibleText accText((nsIDOMNode *)mTextChildren->ElementAt(index));
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(mTextChildren, index));
|
||||
nsAccessibleText accText(domNode);
|
||||
if (NS_SUCCEEDED(accText.GetCharacterCount(&charCount)))
|
||||
*aCharacterCount += charCount;
|
||||
}
|
||||
|
@ -238,9 +240,10 @@ NS_IMETHODIMP nsAccessibleHyperText::GetSelectionCount(PRInt32 *aSelectionCount)
|
|||
|
||||
PRInt32 selCount;
|
||||
PRUint32 index, count;
|
||||
mTextChildren->Count(&count);
|
||||
mTextChildren->GetLength(&count);
|
||||
for (index = 0; index < count; index++) {
|
||||
nsAccessibleText accText((nsIDOMNode *)mTextChildren->ElementAt(index));
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(mTextChildren, index));
|
||||
nsAccessibleText accText(domNode);
|
||||
if (NS_SUCCEEDED(accText.GetSelectionCount(&selCount)))
|
||||
*aSelectionCount += selCount;
|
||||
}
|
||||
|
@ -257,9 +260,10 @@ NS_IMETHODIMP nsAccessibleHyperText::GetText(PRInt32 aStartOffset, PRInt32 aEndO
|
|||
PRInt32 charCount, totalCount = 0, currentStart, currentEnd;
|
||||
PRUint32 index, count;
|
||||
nsAutoString text, nodeText;
|
||||
mTextChildren->Count(&count);
|
||||
mTextChildren->GetLength(&count);
|
||||
for (index = 0; index < count; index++) {
|
||||
nsAccessibleText accText((nsIDOMNode *)mTextChildren->ElementAt(index));
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(mTextChildren, index));
|
||||
nsAccessibleText accText(domNode);
|
||||
if (NS_SUCCEEDED(accText.GetCharacterCount(&charCount))) {
|
||||
currentStart = aStartOffset - totalCount;
|
||||
currentEnd = aEndOffset - totalCount;
|
||||
|
@ -388,7 +392,7 @@ NS_IMETHODIMP nsAccessibleHyperText::RemoveSelection(PRInt32 aSelectionNum)
|
|||
|
||||
PRUint32 index, count;
|
||||
PRInt32 caretOffset;
|
||||
mTextChildren->Count(&count);
|
||||
mTextChildren->GetLength(&count);
|
||||
for (index = 0; index < count; index++) {
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(mTextChildren, index));
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
|
@ -419,7 +423,7 @@ NS_IMETHODIMP nsAccessibleHyperText::RemoveSelection(PRInt32 aSelectionNum)
|
|||
NS_IMETHODIMP nsAccessibleHyperText::GetLink(PRInt32 aIndex, nsIAccessibleHyperLink **aLink)
|
||||
{
|
||||
PRUint32 index, count, linkCount = 0;
|
||||
mTextChildren->Count(&count);
|
||||
mTextChildren->GetLength(&count);
|
||||
for (index = 0; index < count; index++) {
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(mTextChildren, index));
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
|
@ -486,7 +490,7 @@ NS_IMETHODIMP nsAccessibleHyperText::GetSelectedLinkIndex(PRInt32 *aSelectedLink
|
|||
*aSelectedLinkIndex = -1;
|
||||
|
||||
PRUint32 count;
|
||||
mTextChildren->Count(&count);
|
||||
mTextChildren->GetLength(&count);
|
||||
if (count <= 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
@ -522,10 +526,10 @@ nsresult nsAccessibleHyperText::GetBounds(nsIWeakReference *aWeakShell, PRInt32
|
|||
|
||||
nsRect unionRectTwips;
|
||||
PRUint32 index, count;
|
||||
mTextChildren->Count(&count);
|
||||
mTextChildren->GetLength(&count);
|
||||
for (index = 0; index < count; index++) {
|
||||
nsHTMLTextAccessible *accText = new nsHTMLTextAccessible(
|
||||
(nsIDOMNode *)mTextChildren->ElementAt(index), aWeakShell, nsnull);
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(mTextChildren, index));
|
||||
nsHTMLTextAccessible *accText = new nsHTMLTextAccessible(domNode, aWeakShell, nsnull);
|
||||
if (!accText)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#include "nsAccessibleText.h"
|
||||
#include "nsIAccessibleHyperText.h"
|
||||
#include "nsIAccessibleText.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsArray.h"
|
||||
#include "nsTextAccessible.h"
|
||||
|
||||
class nsAccessibleHyperText : public nsIAccessibleHyperText,
|
||||
|
@ -62,7 +62,7 @@ public:
|
|||
PRInt32 GetIndex();
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsISupportsArray> mTextChildren;
|
||||
nsCOMPtr<nsIMutableArray> mTextChildren;
|
||||
PRInt32 mIndex;
|
||||
|
||||
PRBool GetAllTextChildren(nsPresContext *aPresContext, nsIFrame *aCurFrame, nsIDOMNode* aNode, PRBool &bSave);
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
#include "nsIWidget.h"
|
||||
#include "nsStyleStruct.h"
|
||||
#include "nsTextFragment.h"
|
||||
#include "nsArray.h"
|
||||
|
||||
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
||||
|
||||
|
@ -135,14 +136,14 @@ nsresult nsAccessibleText::DOMPointToOffset(nsISupports *aClosure, nsIDOMNode* a
|
|||
|
||||
*aResult = aNodeOffset;
|
||||
|
||||
nsCOMPtr<nsISupportsArray> domNodeArray(do_QueryInterface(aClosure));
|
||||
nsCOMPtr<nsIArray> domNodeArray(do_QueryInterface(aClosure));
|
||||
if (domNodeArray) {
|
||||
// Static text, calculate the offset from a given set of (text) node
|
||||
PRUint32 textLength, totalLength = 0;
|
||||
PRUint32 index, count;
|
||||
domNodeArray->Count(&count);
|
||||
domNodeArray->GetLength(&count);
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIDOMNode* domNode = (nsIDOMNode *)domNodeArray->ElementAt(index);
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(domNodeArray, index));
|
||||
if (aNode == domNode) {
|
||||
*aResult = aNodeOffset + totalLength;
|
||||
break;
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
// --------------------------------------------------------
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLLinkAccessibleWrap, nsHTMLLinkAccessible, nsIAccessibleHyperLink)
|
||||
|
||||
nsHTMLLinkAccessibleWrap::nsHTMLLinkAccessibleWrap(nsIDOMNode* aDomNode, nsISupportsArray* aTextNodes, nsIWeakReference* aShell, nsIFrame *aFrame):
|
||||
nsHTMLLinkAccessibleWrap::nsHTMLLinkAccessibleWrap(nsIDOMNode* aDomNode, nsIArray* aTextNodes, nsIWeakReference* aShell, nsIFrame *aFrame):
|
||||
nsHTMLLinkAccessible(aDomNode, aShell, aFrame)
|
||||
{
|
||||
mTextNodes = aTextNodes;
|
||||
|
@ -138,9 +138,9 @@ nsresult nsHTMLLinkAccessibleWrap::GetLinkOffset(PRInt32* aStartOffset, PRInt32*
|
|||
PRUint32 index, count = 0;
|
||||
PRUint32 totalLength = 0, textLength = 0;
|
||||
|
||||
mTextNodes->Count(&count);
|
||||
mTextNodes->GetLength(&count);
|
||||
for (index = 0; index < count; index++) {
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mTextNodes->ElementAt(index)));
|
||||
nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(mTextNodes, index));
|
||||
nsCOMPtr<nsIDOMText> domText(do_QueryInterface(domNode));
|
||||
if (domText) {
|
||||
domText->GetLength(&textLength);
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#include "nsHTMLImageAccessible.h"
|
||||
#include "nsHTMLLinkAccessible.h"
|
||||
#include "nsIAccessibleHyperLink.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsArray.h"
|
||||
|
||||
class nsHTMLLinkAccessibleWrap : public nsHTMLLinkAccessible,
|
||||
public nsIAccessibleHyperLink
|
||||
|
@ -52,10 +52,10 @@ public:
|
|||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIACCESSIBLEHYPERLINK
|
||||
|
||||
nsHTMLLinkAccessibleWrap(nsIDOMNode* aDomNode, nsISupportsArray* aTextNodes, nsIWeakReference* aShell, nsIFrame *aFrame);
|
||||
nsHTMLLinkAccessibleWrap(nsIDOMNode* aDomNode, nsIArray* aTextNodes, nsIWeakReference* aShell, nsIFrame *aFrame);
|
||||
private:
|
||||
nsresult GetLinkOffset(PRInt32* aStartOffset, PRInt32* aEndOffset);
|
||||
nsISupportsArray* mTextNodes;
|
||||
nsCOMPtr<nsIArray> mTextNodes;
|
||||
};
|
||||
|
||||
class nsHTMLImageMapAccessible : public nsHTMLImageAccessible,
|
||||
|
|
Загрузка…
Ссылка в новой задаче