Part of the great nsCOMPtr carpool. Approved by those in power.

This commit is contained in:
sfraser%netscape.com 1999-02-17 02:08:01 +00:00
parent 9a63580434
commit f250d738cb
5 changed files with 44 additions and 22 deletions

View File

@ -182,11 +182,11 @@ NS_METHOD nsCaret::NotifySelectionChanged()
#pragma mark -
//-----------------------------------------------------------------------------
nsresult nsCaret::StartBlinking()
nsresult nsCaret::PrimeTimer()
{
NS_IF_RELEASE(mBlinkTimer);
mBlinkTimer = nsnull;
// set up the blink timer
if (mBlinkRate > 0)
@ -198,7 +198,16 @@ nsresult nsCaret::StartBlinking()
mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate);
}
return NS_OK;
}
//-----------------------------------------------------------------------------
nsresult nsCaret::StartBlinking()
{
PrimeTimer();
NS_ASSERTION(!mDrawn, "Caret should not be drawn here");
DrawCaret(); // draw it right away
@ -214,7 +223,6 @@ nsresult nsCaret::StopBlinking()
DrawCaret();
NS_IF_RELEASE(mBlinkTimer);
mBlinkTimer = nsnull;
return NS_OK;
}
@ -237,11 +245,11 @@ void nsCaret::DrawCaret()
// from the selection, and store the rect. If we are drawn, we _have_ to erase,
// which why the rect is stored, and the stored rect used to erase.
if (PR_TRUE || !mDrawn)
if (!mDrawn)
{
nsCOMPtr<nsIDOMSelection> domSelection;
nsresult err = mPresShell->GetSelection(getter_AddRefs(domSelection));
if (!NS_SUCCEEDED(err) || (nsnull == domSelection))
if (!NS_SUCCEEDED(err) || !domSelection)
return;
PRBool isCollapsed;
@ -252,7 +260,7 @@ void nsCaret::DrawCaret()
nsCOMPtr<nsIDOMNode> focusNode;
PRInt32 focusOffset;
domSelection->GetFocusNodeAndOffset(getter_doesnt_AddRef(focusNode), &focusOffset);
domSelection->GetFocusNodeAndOffset(getter_AddRefs(focusNode), &focusOffset);
// is this a text node?
nsCOMPtr<nsIDOMCharacterData> nodeAsText(do_QueryInterface(focusNode));
@ -330,10 +338,7 @@ void nsCaret::DrawCaret()
mDrawn = !mDrawn;
}
// prime the timer again
if (mBlinkTimer)
mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate);
PrimeTimer();
}

View File

@ -58,6 +58,8 @@ class nsCaret : public nsICaret,
protected:
nsresult PrimeTimer();
nsresult StartBlinking();
nsresult StopBlinking();

View File

@ -182,11 +182,11 @@ NS_METHOD nsCaret::NotifySelectionChanged()
#pragma mark -
//-----------------------------------------------------------------------------
nsresult nsCaret::StartBlinking()
nsresult nsCaret::PrimeTimer()
{
NS_IF_RELEASE(mBlinkTimer);
mBlinkTimer = nsnull;
// set up the blink timer
if (mBlinkRate > 0)
@ -198,7 +198,16 @@ nsresult nsCaret::StartBlinking()
mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate);
}
return NS_OK;
}
//-----------------------------------------------------------------------------
nsresult nsCaret::StartBlinking()
{
PrimeTimer();
NS_ASSERTION(!mDrawn, "Caret should not be drawn here");
DrawCaret(); // draw it right away
@ -214,7 +223,6 @@ nsresult nsCaret::StopBlinking()
DrawCaret();
NS_IF_RELEASE(mBlinkTimer);
mBlinkTimer = nsnull;
return NS_OK;
}
@ -237,11 +245,11 @@ void nsCaret::DrawCaret()
// from the selection, and store the rect. If we are drawn, we _have_ to erase,
// which why the rect is stored, and the stored rect used to erase.
if (PR_TRUE || !mDrawn)
if (!mDrawn)
{
nsCOMPtr<nsIDOMSelection> domSelection;
nsresult err = mPresShell->GetSelection(getter_AddRefs(domSelection));
if (!NS_SUCCEEDED(err) || (nsnull == domSelection))
if (!NS_SUCCEEDED(err) || !domSelection)
return;
PRBool isCollapsed;
@ -252,7 +260,7 @@ void nsCaret::DrawCaret()
nsCOMPtr<nsIDOMNode> focusNode;
PRInt32 focusOffset;
domSelection->GetFocusNodeAndOffset(getter_doesnt_AddRef(focusNode), &focusOffset);
domSelection->GetFocusNodeAndOffset(getter_AddRefs(focusNode), &focusOffset);
// is this a text node?
nsCOMPtr<nsIDOMCharacterData> nodeAsText(do_QueryInterface(focusNode));
@ -330,10 +338,7 @@ void nsCaret::DrawCaret()
mDrawn = !mDrawn;
}
// prime the timer again
if (mBlinkTimer)
mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate);
PrimeTimer();
}

View File

@ -58,6 +58,8 @@ class nsCaret : public nsICaret,
protected:
nsresult PrimeTimer();
nsresult StartBlinking();
nsresult StopBlinking();

View File

@ -1264,6 +1264,10 @@ nsRangeList::DeleteFromDocument()
NS_IMETHODIMP
nsRangeList::GetAnchorNodeAndOffset(nsIDOMNode** outAnchorNode, PRInt32 *outAnchorOffset)
{
if (!outAnchorNode || !outAnchorOffset)
return NS_ERROR_NULL_POINTER;
NS_IF_ADDREF((nsIDOMNode *)mAnchorNode);
*outAnchorNode = mAnchorNode;
*outAnchorOffset = mAnchorOffset;
return NS_OK;
@ -1276,6 +1280,10 @@ nsRangeList::GetAnchorNodeAndOffset(nsIDOMNode** outAnchorNode, PRInt32 *outAnch
NS_IMETHODIMP
nsRangeList::GetFocusNodeAndOffset(nsIDOMNode** outFocusNode, PRInt32 *outFocusOffset)
{
if (!outFocusNode || !outFocusOffset)
return NS_ERROR_NULL_POINTER;
NS_IF_ADDREF((nsIDOMNode *)mFocusNode);
*outFocusNode = mFocusNode;
*outFocusOffset = mFocusOffset;
return NS_OK;