Bug 1048752. Part 30: Simplify caret blinking logic. r=tn

A few things got mashed together here:
-- Inline KillTimer/PrimeTimer into their callers.
-- Instead of having to call StopBlinking and StartBlinking together,
change StartBlinking to ResetBlinking and have it set up
the correct blink state and reset the blink cycle.
-- nsCaret::NotifySelectionChange needs a SchedulePaint
-- nsCaret::DrawAtPosition needs a ResetBlinking

--HG--
extra : rebase_source : abc7fd78c4f20b787b212e1e3f13226a1ccff16b
This commit is contained in:
Robert O'Callahan 2014-08-06 17:19:30 +12:00
Родитель e2388b41b8
Коммит 22cca61b31
2 изменённых файлов: 42 добавлений и 74 удалений

Просмотреть файл

@ -130,7 +130,7 @@ nsCaret::nsCaret()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
nsCaret::~nsCaret() nsCaret::~nsCaret()
{ {
KillTimer(); StopBlinking();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -211,7 +211,7 @@ void nsCaret::Terminate()
// this doesn't erase the caret if it's drawn. Should it? We might not have // this doesn't erase the caret if it's drawn. Should it? We might not have
// a good drawing environment during teardown. // a good drawing environment during teardown.
KillTimer(); StopBlinking();
mBlinkTimer = nullptr; mBlinkTimer = nullptr;
// unregiser ourselves as a selection listener // unregiser ourselves as a selection listener
@ -240,13 +240,7 @@ void nsCaret::SetSelection(nsISelection *aDOMSel)
{ {
MOZ_ASSERT(aDOMSel); MOZ_ASSERT(aDOMSel);
mDomSelectionWeak = do_GetWeakReference(aDOMSel); // weak reference to pres shell mDomSelectionWeak = do_GetWeakReference(aDOMSel); // weak reference to pres shell
if (mVisible) ResetBlinking();
{
// Stop the caret from blinking in its previous location.
StopBlinking();
// Start the caret blinking in the new location.
StartBlinking();
}
SchedulePaint(); SchedulePaint();
} }
@ -255,13 +249,8 @@ void nsCaret::SetSelection(nsISelection *aDOMSel)
void nsCaret::SetVisible(bool inMakeVisible) void nsCaret::SetVisible(bool inMakeVisible)
{ {
mVisible = inMakeVisible; mVisible = inMakeVisible;
if (mVisible) { mIgnoreUserModify = mVisible;
SetIgnoreUserModify(true); ResetBlinking();
StartBlinking();
} else {
StopBlinking();
SetIgnoreUserModify(false);
}
SchedulePaint(); SchedulePaint();
} }
@ -296,6 +285,7 @@ bool nsCaret::IsVisible()
void nsCaret::SetCaretReadOnly(bool inMakeReadonly) void nsCaret::SetCaretReadOnly(bool inMakeReadonly)
{ {
mReadOnly = inMakeReadonly; mReadOnly = inMakeReadonly;
ResetBlinking();
SchedulePaint(); SchedulePaint();
} }
@ -437,6 +427,7 @@ nsresult nsCaret::DrawAtPosition(nsIDOMNode* aNode, int32_t aOffset)
// tell us. Setting mIsBlinking to false tells us to not set a timer to erase // tell us. Setting mIsBlinking to false tells us to not set a timer to erase
// ourselves, our consumer will take care of that. // ourselves, our consumer will take care of that.
mIsBlinking = false; mIsBlinking = false;
ResetBlinking();
mOverrideContent = do_QueryInterface(aNode); mOverrideContent = do_QueryInterface(aNode);
mOverrideOffset = aOffset; mOverrideOffset = aOffset;
@ -539,7 +530,9 @@ void nsCaret::PaintCaret(nsDisplayListBuilder *aBuilder,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
NS_IMETHODIMP nsCaret::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aDomSel, int16_t aReason) NS_IMETHODIMP
nsCaret::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aDomSel,
int16_t aReason)
{ {
if (aReason & nsISelectionListener::MOUSEUP_REASON)//this wont do if (aReason & nsISelectionListener::MOUSEUP_REASON)//this wont do
return NS_OK; return NS_OK;
@ -557,68 +550,46 @@ NS_IMETHODIMP nsCaret::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aD
if (domSel != aDomSel) if (domSel != aDomSel)
return NS_OK; return NS_OK;
if (mVisible) ResetBlinking();
{ SchedulePaint();
// Stop the caret from blinking in its previous location.
return NS_OK;
}
//-----------------------------------------------------------------------------
void nsCaret::ResetBlinking()
{
if (mReadOnly || !mIsBlinking) {
StopBlinking(); StopBlinking();
// Start the caret blinking in the new location.
StartBlinking();
}
return NS_OK;
}
//-----------------------------------------------------------------------------
void nsCaret::KillTimer()
{
if (mBlinkTimer)
{
mBlinkTimer->Cancel();
}
}
//-----------------------------------------------------------------------------
nsresult nsCaret::PrimeTimer()
{
// set up the blink timer
if (!mReadOnly && mIsBlinking)
{
if (!mBlinkTimer) {
nsresult err;
mBlinkTimer = do_CreateInstance("@mozilla.org/timer;1", &err);
if (NS_FAILED(err))
return err;
}
uint32_t blinkRate = static_cast<uint32_t>(
LookAndFeel::GetInt(LookAndFeel::eIntID_CaretBlinkTime, 500));
mBlinkTimer->InitWithFuncCallback(CaretBlinkCallback, this, blinkRate,
nsITimer::TYPE_REPEATING_SLACK);
}
return NS_OK;
}
//-----------------------------------------------------------------------------
void nsCaret::StartBlinking()
{
mIsBlinkOn = true;
if (mReadOnly) {
return; return;
} }
PrimeTimer(); mIsBlinkOn = true;
if (!mBlinkTimer) {
nsresult err;
mBlinkTimer = do_CreateInstance("@mozilla.org/timer;1", &err);
if (NS_FAILED(err))
return;
} else {
mBlinkTimer->Cancel();
}
uint32_t blinkRate = static_cast<uint32_t>(
LookAndFeel::GetInt(LookAndFeel::eIntID_CaretBlinkTime, 500));
mBlinkTimer->InitWithFuncCallback(CaretBlinkCallback, this, blinkRate,
nsITimer::TYPE_REPEATING_SLACK);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void nsCaret::StopBlinking() void nsCaret::StopBlinking()
{ {
KillTimer(); if (mBlinkTimer)
{
mBlinkTimer->Cancel();
}
} }
nsresult nsresult

Просмотреть файл

@ -156,10 +156,7 @@ protected:
void CheckSelectionLanguageChange(); void CheckSelectionLanguageChange();
void KillTimer(); void ResetBlinking();
nsresult PrimeTimer();
void StartBlinking();
void StopBlinking(); void StopBlinking();
mozilla::dom::Selection* GetSelectionInternal(); mozilla::dom::Selection* GetSelectionInternal();