Bug 1372761 - Avoid needlessly grabbing the timer thread lock when selections change in order to reset the caret timer; r=mats

This commit is contained in:
Ehsan Akhgari 2017-06-13 20:09:22 -04:00
Родитель d7df561295
Коммит 02b2136122
2 изменённых файлов: 19 добавлений и 2 удалений

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

@ -46,6 +46,9 @@ using namespace mozilla::gfx;
// an insignificant dot
static const int32_t kMinBidiIndicatorPixels = 2;
// The default caret blinking rate (in ms of blinking interval)
static const uint32_t kDefaultCaretBlinkRate = 500;
/**
* Find the first frame in an in-order traversal of the frame subtree rooted
* at aFrame which is either a text frame logically at the end of a line,
@ -120,6 +123,7 @@ IsBidiUI()
nsCaret::nsCaret()
: mOverrideOffset(0)
, mBlinkCount(-1)
, mBlinkRate(0)
, mHideCount(0)
, mIsBlinkOn(false)
, mVisible(false)
@ -636,6 +640,15 @@ void nsCaret::ResetBlinking()
return;
}
uint32_t blinkRate = static_cast<uint32_t>(
LookAndFeel::GetInt(LookAndFeel::eIntID_CaretBlinkTime,
kDefaultCaretBlinkRate));
if (mBlinkRate == blinkRate) {
// If the rate hasn't changed, then there is nothing to do.
return;
}
mBlinkRate = blinkRate;
if (mBlinkTimer) {
mBlinkTimer->Cancel();
} else {
@ -645,8 +658,6 @@ void nsCaret::ResetBlinking()
return;
}
uint32_t blinkRate = static_cast<uint32_t>(
LookAndFeel::GetInt(LookAndFeel::eIntID_CaretBlinkTime, 500));
if (blinkRate > 0) {
mBlinkCount = Preferences::GetInt("ui.caretBlinkCount", -1);
mBlinkTimer->InitWithNamedFuncCallback(CaretBlinkCallback, this, blinkRate,

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

@ -231,6 +231,12 @@ protected:
* blinking.
*/
int32_t mBlinkCount;
/**
* mBlinkRate is the rate of the caret blinking the last time we read it.
* It is used as a way to optimize whether we need to reset the blinking
* timer.
*/
uint32_t mBlinkRate;
/**
* mHideCount is not 0, it means that somebody doesn't want the caret
* to be visible. See AddForceHide() and RemoveForceHide().