зеркало из https://github.com/mozilla/gecko-dev.git
Added RefreshMethod, and tweaked code for the UNIX no-blinking case.
This commit is contained in:
Родитель
006010c385
Коммит
ac19a57cb6
|
@ -49,7 +49,7 @@ nsCaret::nsCaret()
|
||||||
: mPresShell(nsnull)
|
: mPresShell(nsnull)
|
||||||
, mBlinkTimer(nsnull)
|
, mBlinkTimer(nsnull)
|
||||||
, mBlinkRate(500)
|
, mBlinkRate(500)
|
||||||
, mVisible(PR_TRUE)
|
, mVisible(PR_FALSE)
|
||||||
, mReadOnly(PR_TRUE)
|
, mReadOnly(PR_TRUE)
|
||||||
, mDrawn(PR_FALSE)
|
, mDrawn(PR_FALSE)
|
||||||
{
|
{
|
||||||
|
@ -75,7 +75,7 @@ NS_METHOD nsCaret::Init(nsIPresShell *inPresShell, nsCaretProperties *inCaretPro
|
||||||
mPresShell = inPresShell; // the presshell owns us, so no addref
|
mPresShell = inPresShell; // the presshell owns us, so no addref
|
||||||
|
|
||||||
mBlinkRate = inCaretProperties->GetCaretBlinkRate();
|
mBlinkRate = inCaretProperties->GetCaretBlinkRate();
|
||||||
mCaretWidth = inCaretProperties->GetCaretWidth();
|
mCaretWidth = NSIntPointsToTwips(inCaretProperties->GetCaretWidth());
|
||||||
|
|
||||||
// get the selection from the pres shell, and set ourselves up as a selection
|
// get the selection from the pres shell, and set ourselves up as a selection
|
||||||
// listener
|
// listener
|
||||||
|
@ -150,13 +150,33 @@ NS_METHOD nsCaret::SetCaretReadOnly(PRBool inMakeReadonly)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsCaret::Refresh()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (mVisible)
|
||||||
|
{
|
||||||
|
StopBlinking();
|
||||||
|
StartBlinking();
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
NS_METHOD nsCaret::NotifySelectionChanged()
|
NS_METHOD nsCaret::NotifySelectionChanged()
|
||||||
{
|
{
|
||||||
StopBlinking();
|
|
||||||
StartBlinking();
|
if (mVisible)
|
||||||
|
{
|
||||||
|
StopBlinking();
|
||||||
|
StartBlinking();
|
||||||
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,16 +189,21 @@ nsresult nsCaret::StartBlinking()
|
||||||
mBlinkTimer = nsnull;
|
mBlinkTimer = nsnull;
|
||||||
|
|
||||||
// set up the blink timer
|
// set up the blink timer
|
||||||
nsresult err = NS_NewTimer(&mBlinkTimer);
|
if (mBlinkRate > 0)
|
||||||
|
{
|
||||||
|
nsresult err = NS_NewTimer(&mBlinkTimer);
|
||||||
|
|
||||||
|
if (NS_FAILED(err))
|
||||||
|
return err;
|
||||||
|
|
||||||
|
mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate);
|
||||||
|
}
|
||||||
|
|
||||||
if (NS_FAILED(err))
|
|
||||||
return err;
|
|
||||||
|
|
||||||
NS_ASSERTION(!mDrawn, "Caret should not be drawn here");
|
NS_ASSERTION(!mDrawn, "Caret should not be drawn here");
|
||||||
|
|
||||||
DrawCaret(); // draw it right away
|
DrawCaret(); // draw it right away
|
||||||
|
|
||||||
return mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate);
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -306,7 +331,8 @@ void nsCaret::DrawCaret()
|
||||||
}
|
}
|
||||||
|
|
||||||
// prime the timer again
|
// prime the timer again
|
||||||
mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate);
|
if (mBlinkTimer)
|
||||||
|
mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ class nsCaret : public nsICaret,
|
||||||
|
|
||||||
NS_IMETHOD SetCaretVisible(PRBool inMakeVisible);
|
NS_IMETHOD SetCaretVisible(PRBool inMakeVisible);
|
||||||
NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly);
|
NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly);
|
||||||
|
NS_IMETHOD Refresh();
|
||||||
|
|
||||||
/* nsIDOMSelectionListener interface */
|
/* nsIDOMSelectionListener interface */
|
||||||
NS_IMETHOD NotifySelectionChanged();
|
NS_IMETHOD NotifySelectionChanged();
|
||||||
|
|
|
@ -41,6 +41,11 @@ public:
|
||||||
* PR_FALSE to show the caret in normal, editing state
|
* PR_FALSE to show the caret in normal, editing state
|
||||||
*/
|
*/
|
||||||
NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly) = 0;
|
NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly) = 0;
|
||||||
|
|
||||||
|
/** Refresh
|
||||||
|
* Refresh the caret after the frame it is being drawn in has painted
|
||||||
|
*/
|
||||||
|
NS_IMETHOD Refresh() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern nsresult NS_NewCaret(nsICaret** aInstancePtrResult);
|
extern nsresult NS_NewCaret(nsICaret** aInstancePtrResult);
|
||||||
|
|
|
@ -41,6 +41,11 @@ public:
|
||||||
* PR_FALSE to show the caret in normal, editing state
|
* PR_FALSE to show the caret in normal, editing state
|
||||||
*/
|
*/
|
||||||
NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly) = 0;
|
NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly) = 0;
|
||||||
|
|
||||||
|
/** Refresh
|
||||||
|
* Refresh the caret after the frame it is being drawn in has painted
|
||||||
|
*/
|
||||||
|
NS_IMETHOD Refresh() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern nsresult NS_NewCaret(nsICaret** aInstancePtrResult);
|
extern nsresult NS_NewCaret(nsICaret** aInstancePtrResult);
|
||||||
|
|
|
@ -49,7 +49,7 @@ nsCaret::nsCaret()
|
||||||
: mPresShell(nsnull)
|
: mPresShell(nsnull)
|
||||||
, mBlinkTimer(nsnull)
|
, mBlinkTimer(nsnull)
|
||||||
, mBlinkRate(500)
|
, mBlinkRate(500)
|
||||||
, mVisible(PR_TRUE)
|
, mVisible(PR_FALSE)
|
||||||
, mReadOnly(PR_TRUE)
|
, mReadOnly(PR_TRUE)
|
||||||
, mDrawn(PR_FALSE)
|
, mDrawn(PR_FALSE)
|
||||||
{
|
{
|
||||||
|
@ -75,7 +75,7 @@ NS_METHOD nsCaret::Init(nsIPresShell *inPresShell, nsCaretProperties *inCaretPro
|
||||||
mPresShell = inPresShell; // the presshell owns us, so no addref
|
mPresShell = inPresShell; // the presshell owns us, so no addref
|
||||||
|
|
||||||
mBlinkRate = inCaretProperties->GetCaretBlinkRate();
|
mBlinkRate = inCaretProperties->GetCaretBlinkRate();
|
||||||
mCaretWidth = inCaretProperties->GetCaretWidth();
|
mCaretWidth = NSIntPointsToTwips(inCaretProperties->GetCaretWidth());
|
||||||
|
|
||||||
// get the selection from the pres shell, and set ourselves up as a selection
|
// get the selection from the pres shell, and set ourselves up as a selection
|
||||||
// listener
|
// listener
|
||||||
|
@ -150,13 +150,33 @@ NS_METHOD nsCaret::SetCaretReadOnly(PRBool inMakeReadonly)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsCaret::Refresh()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (mVisible)
|
||||||
|
{
|
||||||
|
StopBlinking();
|
||||||
|
StartBlinking();
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
NS_METHOD nsCaret::NotifySelectionChanged()
|
NS_METHOD nsCaret::NotifySelectionChanged()
|
||||||
{
|
{
|
||||||
StopBlinking();
|
|
||||||
StartBlinking();
|
if (mVisible)
|
||||||
|
{
|
||||||
|
StopBlinking();
|
||||||
|
StartBlinking();
|
||||||
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,16 +189,21 @@ nsresult nsCaret::StartBlinking()
|
||||||
mBlinkTimer = nsnull;
|
mBlinkTimer = nsnull;
|
||||||
|
|
||||||
// set up the blink timer
|
// set up the blink timer
|
||||||
nsresult err = NS_NewTimer(&mBlinkTimer);
|
if (mBlinkRate > 0)
|
||||||
|
{
|
||||||
|
nsresult err = NS_NewTimer(&mBlinkTimer);
|
||||||
|
|
||||||
|
if (NS_FAILED(err))
|
||||||
|
return err;
|
||||||
|
|
||||||
|
mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate);
|
||||||
|
}
|
||||||
|
|
||||||
if (NS_FAILED(err))
|
|
||||||
return err;
|
|
||||||
|
|
||||||
NS_ASSERTION(!mDrawn, "Caret should not be drawn here");
|
NS_ASSERTION(!mDrawn, "Caret should not be drawn here");
|
||||||
|
|
||||||
DrawCaret(); // draw it right away
|
DrawCaret(); // draw it right away
|
||||||
|
|
||||||
return mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate);
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -306,7 +331,8 @@ void nsCaret::DrawCaret()
|
||||||
}
|
}
|
||||||
|
|
||||||
// prime the timer again
|
// prime the timer again
|
||||||
mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate);
|
if (mBlinkTimer)
|
||||||
|
mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ class nsCaret : public nsICaret,
|
||||||
|
|
||||||
NS_IMETHOD SetCaretVisible(PRBool inMakeVisible);
|
NS_IMETHOD SetCaretVisible(PRBool inMakeVisible);
|
||||||
NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly);
|
NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly);
|
||||||
|
NS_IMETHOD Refresh();
|
||||||
|
|
||||||
/* nsIDOMSelectionListener interface */
|
/* nsIDOMSelectionListener interface */
|
||||||
NS_IMETHOD NotifySelectionChanged();
|
NS_IMETHOD NotifySelectionChanged();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче