Bug 1048752. Part 12: Replace mBlinkRate with mIsBlinking. r=tn
authorRobert O'Callahan <robert@ocallahan.org>
Wed, 06 Aug 2014 17:19:26 +1200
changeset 199949 5761be456996aaa8708918539e236546ae619520
parent 199948 7b885c741dc9d772c8258172b5499495e0408484
child 199950 744443e8760a693dd58e9b4ba932b16bb8e23d1e
push id9784
push userryanvm@gmail.com
push dateSat, 16 Aug 2014 21:45:40 +0000
treeherderb2g-inbound@94ba78a42305 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn
bugs1048752
milestone34.0a1
Bug 1048752. Part 12: Replace mBlinkRate with mIsBlinking. r=tn We don't need to store the blink rate. Instead we can just fetch it whenever we need it. However we do need a flag to handle the case where nsCaret::DrawAtPosition disables blinking.
layout/base/nsCaret.cpp
layout/base/nsCaret.h
--- a/layout/base/nsCaret.cpp
+++ b/layout/base/nsCaret.cpp
@@ -106,17 +106,17 @@ AdjustCaretFrameForLineEnd(nsIFrame** aF
     }
   }
 }
 
 //-----------------------------------------------------------------------------
 
 nsCaret::nsCaret()
 : mPresShell(nullptr)
-, mBlinkRate(500)
+, mIsBlinking(true)
 , mVisible(false)
 , mDrawn(false)
 , mPendingDraw(false)
 , mReadOnly(false)
 , mShowDuringSelection(false)
 , mIgnoreUserModify(true)
 , mKeyboardRTL(false)
 , mLastBidiLevel(0)
@@ -134,18 +134,16 @@ nsCaret::~nsCaret()
 //-----------------------------------------------------------------------------
 nsresult nsCaret::Init(nsIPresShell *inPresShell)
 {
   NS_ENSURE_ARG(inPresShell);
 
   mPresShell = do_GetWeakReference(inPresShell);    // the presshell owns us, so no addref
   NS_ASSERTION(mPresShell, "Hey, pres shell should support weak refs");
 
-  mBlinkRate = static_cast<uint32_t>(
-    LookAndFeel::GetInt(LookAndFeel::eIntID_CaretBlinkTime, mBlinkRate));
   mShowDuringSelection =
     LookAndFeel::GetInt(LookAndFeel::eIntID_ShowCaretDuringSelection,
                         mShowDuringSelection ? 1 : 0) != 0;
 
   // get the selection from the pres shell, and set ourselves up as a selection
   // listener
 
   nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mPresShell);
@@ -387,17 +385,17 @@ void nsCaret::DrawCaretAfterBriefDelay()
   mBlinkTimer->InitWithFuncCallback(CaretBlinkCallback, this, 0,
                                     nsITimer::TYPE_ONE_SHOT);
 }
 
 void nsCaret::EraseCaret()
 {
   if (mDrawn) {
     DrawCaret(true);
-    if (mReadOnly && mBlinkRate) {
+    if (mReadOnly && mIsBlinking) {
       // If readonly we don't have a blink timer set, so caret won't
       // be redrawn automatically. We need to force the caret to get
       // redrawn right after the paint
       DrawCaretAfterBriefDelay();
     }
   }
 }
 
@@ -412,19 +410,19 @@ nsresult nsCaret::DrawAtPosition(nsIDOMN
 
   uint8_t bidiLevel;
   nsRefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
   if (!frameSelection)
     return NS_ERROR_FAILURE;
   bidiLevel = frameSelection->GetCaretBidiLevel();
 
   // DrawAtPosition is used by consumers who want us to stay drawn where they
-  // tell us. Setting mBlinkRate to 0 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.
-  mBlinkRate = 0;
+  mIsBlinking = false;
 
   nsCOMPtr<nsIContent> node = do_QueryInterface(aNode);
   nsresult rv = DrawAtPositionWithHint(aNode, aOffset,
                                        nsFrameSelection::GetHintForPosition(node, aOffset),
                                        bidiLevel, true)
     ?  NS_OK : NS_ERROR_FAILURE;
   ToggleDrawnStatus();
   return rv;
@@ -542,26 +540,29 @@ void nsCaret::KillTimer()
   }
 }
 
 
 //-----------------------------------------------------------------------------
 nsresult nsCaret::PrimeTimer()
 {
   // set up the blink timer
-  if (!mReadOnly && mBlinkRate > 0)
+  if (!mReadOnly && mIsBlinking)
   {
     if (!mBlinkTimer) {
       nsresult  err;
       mBlinkTimer = do_CreateInstance("@mozilla.org/timer;1", &err);    
       if (NS_FAILED(err))
         return err;
     }    
 
-    mBlinkTimer->InitWithFuncCallback(CaretBlinkCallback, this, mBlinkRate,
+    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()
--- a/layout/base/nsCaret.h
+++ b/layout/base/nsCaret.h
@@ -194,19 +194,17 @@ protected:
 
 protected:
 
     nsWeakPtr             mPresShell;
     nsWeakPtr             mDomSelectionWeak;
 
     nsCOMPtr<nsITimer>    mBlinkTimer;
 
-    // XXX these fields should go away and the values be acquired as needed,
-    // probably by ComputeMetrics.
-    uint32_t              mBlinkRate;         // time for one cyle (on then off), in milliseconds
+    bool                  mIsBlinking;
 
     bool                  mVisible;           // is the caret blinking
 
     bool                  mDrawn;             // Denotes when the caret is physically drawn on the screen.
     bool                  mPendingDraw;       // True when the last on-state draw was suppressed.
 
     bool                  mReadOnly;          // it the caret in readonly state (draws differently)
     bool                  mShowDuringSelection; // show when text is selected