Bug 1159263 - Add support to nsCaret to stop blinking after a set of cycles r=roc r=snorp
authorMark Finkle <mfinkle@mozilla.com>
Wed, 29 Apr 2015 10:23:19 -0400
changeset 273196 bd3b4ef4eedd20595773a6d9f3de14e39a664f06
parent 273195 ef6fd70cccf50aee7cc20c74b2c22b9f225101e7
child 273197 b30b620283bd852a543a0bd08928745a0c6f9f68
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, snorp
bugs1159263
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1159263 - Add support to nsCaret to stop blinking after a set of cycles r=roc r=snorp
layout/base/nsCaret.cpp
layout/base/nsCaret.h
mobile/android/app/mobile.js
--- a/layout/base/nsCaret.cpp
+++ b/layout/base/nsCaret.cpp
@@ -115,16 +115,17 @@ static bool
 IsBidiUI()
 {
   return Preferences::GetBool("bidi.browser.ui");
 }
 
 nsCaret::nsCaret()
 : mOverrideOffset(0)
 , mIsBlinkOn(false)
+, mBlinkCount(-1)
 , mVisible(false)
 , mReadOnly(false)
 , mShowDuringSelection(false)
 , mIgnoreUserModify(true)
 {
 }
 
 nsCaret::~nsCaret()
@@ -589,16 +590,17 @@ void nsCaret::ResetBlinking()
     mBlinkTimer = do_CreateInstance("@mozilla.org/timer;1", &err);
     if (NS_FAILED(err))
       return;
   }
 
   uint32_t blinkRate = static_cast<uint32_t>(
     LookAndFeel::GetInt(LookAndFeel::eIntID_CaretBlinkTime, 500));
   if (blinkRate > 0) {
+    mBlinkCount = Preferences::GetInt("ui.caretBlinkCount", -1);
     mBlinkTimer->InitWithFuncCallback(CaretBlinkCallback, this, blinkRate,
                                       nsITimer::TYPE_REPEATING_SLACK);
   }
 }
 
 void nsCaret::StopBlinking()
 {
   if (mBlinkTimer)
@@ -908,16 +910,29 @@ nsCaret::ComputeCaretRects(nsIFrame* aFr
 void nsCaret::CaretBlinkCallback(nsITimer* aTimer, void* aClosure)
 {
   nsCaret* theCaret = reinterpret_cast<nsCaret*>(aClosure);
   if (!theCaret) {
     return;
   }
   theCaret->mIsBlinkOn = !theCaret->mIsBlinkOn;
   theCaret->SchedulePaint();
+
+  // mBlinkCount of -1 means blink count is not enabled.
+  if (theCaret->mBlinkCount == -1) {
+    return;
+  }
+
+  // Track the blink count, but only at end of a blink cycle.
+  if (!theCaret->mIsBlinkOn) {
+    // If we exceeded the blink count, stop the timer.
+    if (--theCaret->mBlinkCount <= 0) {
+      theCaret->StopBlinking();
+    }
+  }
 }
 
 void
 nsCaret::SetIgnoreUserModify(bool aIgnoreUserModify)
 {
   mIgnoreUserModify = aIgnoreUserModify;
   SchedulePaint();
 }
--- a/layout/base/nsCaret.h
+++ b/layout/base/nsCaret.h
@@ -201,16 +201,22 @@ protected:
      */
     int32_t               mOverrideOffset;
 
     /**
      * mIsBlinkOn is true when we're in a blink cycle where the caret is on.
      */
     bool                  mIsBlinkOn;
     /**
+     * mBlinkCount is used to control the number of times to blink the caret
+     * before stopping the blink. This is reset each time we reset the
+     * blinking.
+     */
+    int32_t               mBlinkCount;
+    /**
      * mIsVisible is true when SetVisible was last called with 'true'.
      */
     bool                  mVisible;
     /**
      * mReadOnly is true when the caret is set to "read only" mode (i.e.,
      * it doesn't blink).
      */
     bool                  mReadOnly;
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -42,16 +42,19 @@ pref("toolkit.storage.synchronous", 0);
 pref("browser.viewport.desktopWidth", 980);
 // The default fallback zoom level to render pages at. Set to -1 to fit page; otherwise
 // the value is divided by 1000 and clamped to hard-coded min/max scale values.
 pref("browser.viewport.defaultZoom", -1);
 
 /* allow scrollbars to float above chrome ui */
 pref("ui.scrollbarsCanOverlapContent", 1);
 
+/* turn off the caret blink after 10 cycles */
+pref("ui.caretBlinkCount", 10);
+
 /* cache prefs */
 pref("browser.cache.disk.enable", true);
 pref("browser.cache.disk.capacity", 20480); // kilobytes
 pref("browser.cache.disk.max_entry_size", 4096); // kilobytes
 pref("browser.cache.disk.smart_size.enabled", true);
 pref("browser.cache.disk.smart_size.first_run", true);
 
 #ifdef MOZ_PKG_SPECIAL