Bug 535794 - Shorter printPageDelay, r=roc
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Sat, 19 Dec 2009 12:32:53 +0200
changeset 36472 8356470db21c74969916511ed6663ea7a9f75df5
parent 36471 f6f1982d758db5660309a266c4c2a7db56bf43f9
child 36473 4d0b8367d9406c55f9b86650af90b73748524e2e
push id10823
push useropettay@mozilla.com
push dateSat, 19 Dec 2009 11:53:25 +0000
treeherdermozilla-central@4d0b8367d940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs535794
milestone1.9.3a1pre
Bug 535794 - Shorter printPageDelay, r=roc
layout/printing/nsPagePrintTimer.cpp
layout/printing/nsPagePrintTimer.h
layout/printing/nsPrintEngine.cpp
widget/src/xpwidgets/nsPrintOptionsImpl.cpp
widget/src/xpwidgets/nsPrintSettingsImpl.cpp
--- a/layout/printing/nsPagePrintTimer.cpp
+++ b/layout/printing/nsPagePrintTimer.cpp
@@ -40,16 +40,17 @@
 #include "nsIServiceManager.h"
 #include "nsPrintEngine.h"
 
 NS_IMPL_ISUPPORTS1(nsPagePrintTimer, nsITimerCallback)
 
 nsPagePrintTimer::nsPagePrintTimer() :
   mPrintEngine(nsnull),
   mDelay(0),
+  mFiringCount(0),
   mPrintObj(nsnull)
 {
 }
 
 nsPagePrintTimer::~nsPagePrintTimer()
 {
   // "Destroy" the document viewer; this normally doesn't actually
   // destroy it because of the IncrementDestroyRefCount call below
@@ -64,17 +65,26 @@ nsPagePrintTimer::~nsPagePrintTimer()
 nsresult 
 nsPagePrintTimer::StartTimer(PRBool aUseDelay)
 {
   nsresult result;
   mTimer = do_CreateInstance("@mozilla.org/timer;1", &result);
   if (NS_FAILED(result)) {
     NS_WARNING("unable to start the timer");
   } else {
-    mTimer->InitWithCallback(this, aUseDelay?mDelay:0, nsITimer::TYPE_ONE_SHOT);
+    PRUint32 delay = 0;
+    if (aUseDelay) {
+      if (mFiringCount < 10) {
+        // Longer delay for the few first pages.
+        delay = mDelay + ((10 - mFiringCount) * 100);
+      } else {
+        delay = mDelay;
+      }
+    }
+    mTimer->InitWithCallback(this, delay, nsITimer::TYPE_ONE_SHOT);
   }
   return result;
 }
 
 
 
 // nsITimerCallback
 NS_IMETHODIMP
@@ -95,16 +105,17 @@ nsPagePrintTimer::Notify(nsITimer *timer
       }
     }
 
     // Note that the Stop() destroys this after the print job finishes
     // (The PrintEngine stops holding a reference when DonePrintingPages
     // returns true.)
     Stop(); 
     if (initNewTimer) {
+      ++mFiringCount;
       nsresult result = StartTimer(inRange);
       if (NS_FAILED(result)) {
         donePrinting = PR_TRUE;     // had a failure.. we are finished..
         mPrintEngine->SetIsPrinting(PR_FALSE);
       }
     }
   }
   return NS_OK;
--- a/layout/printing/nsPagePrintTimer.h
+++ b/layout/printing/nsPagePrintTimer.h
@@ -70,16 +70,17 @@ public:
 
 private:
   nsresult StartTimer(PRBool aUseDelay);
 
   nsPrintEngine*             mPrintEngine;
   nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
   nsCOMPtr<nsITimer>         mTimer;
   PRUint32                   mDelay;
+  PRUint32                   mFiringCount;
   nsPrintObject *            mPrintObj;
 };
 
 
 nsresult
 NS_NewPagePrintTimer(nsPagePrintTimer **aResult);
 
 #endif /* nsPagePrintTimer_h___ */
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -3308,17 +3308,17 @@ nsresult
 nsPrintEngine::StartPagePrintTimer(nsPrintObject* aPO)
 {
   if (!mPagePrintTimer) {
     nsresult rv = NS_NewPagePrintTimer(&mPagePrintTimer);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Get the delay time in between the printing of each page
     // this gives the user more time to press cancel
-    PRInt32 printPageDelay = 500;
+    PRInt32 printPageDelay = 50;
     mPrt->mPrintSettings->GetPrintPageDelay(&printPageDelay);
 
     mPagePrintTimer->Init(this, mDocViewerPrint, printPageDelay);
   }
 
   return mPagePrintTimer->Start(aPO);
 }
 
--- a/widget/src/xpwidgets/nsPrintOptionsImpl.cpp
+++ b/widget/src/xpwidgets/nsPrintOptionsImpl.cpp
@@ -100,17 +100,17 @@ static const char kPrintPaperHeight[]   
 static const char kPrintColorspace[]    = "print_colorspace";
 static const char kPrintResolutionName[]= "print_resolution_name";
 static const char kPrintDownloadFonts[] = "print_downloadfonts";
 static const char kPrintOrientation[]   = "print_orientation";
 static const char kPrintCommand[]       = "print_command";
 static const char kPrinterName[]        = "print_printer";
 static const char kPrintToFile[]        = "print_to_file";
 static const char kPrintToFileName[]    = "print_to_filename";
-static const char kPrintPageDelay[]     = "print_pagedelay";
+static const char kPrintPageDelay[]     = "print_page_delay";
 static const char kPrintBGColors[]      = "print_bgcolor";
 static const char kPrintBGImages[]      = "print_bgimages";
 static const char kPrintShrinkToFit[]   = "print_shrink_to_fit";
 static const char kPrintScaling[]       = "print_scaling";
 
 static const char kJustLeft[]   = "left";
 static const char kJustCenter[] = "center";
 static const char kJustRight[]  = "right";
--- a/widget/src/xpwidgets/nsPrintSettingsImpl.cpp
+++ b/widget/src/xpwidgets/nsPrintSettingsImpl.cpp
@@ -58,17 +58,17 @@ nsPrintSettings::nsPrintSettings() :
   mPrintFrameTypeUsage(kUseInternalDefault),
   mPrintFrameType(kFramesAsIs),
   mHowToEnableFrameUI(kFrameEnableNone),
   mIsCancelled(PR_FALSE),
   mPrintSilent(PR_FALSE),
   mPrintPreview(PR_FALSE),
   mShrinkToFit(PR_TRUE),
   mShowPrintProgress(PR_TRUE),
-  mPrintPageDelay(500),
+  mPrintPageDelay(50),
   mPaperData(0),
   mPaperSizeType(kPaperSizeDefined),
   mPaperWidth(8.5),
   mPaperHeight(11.0),
   mPaperSizeUnit(kPaperSizeInches),
   mPrintReversed(PR_FALSE),
   mPrintInColor(PR_TRUE),
   mOrientation(kPortraitOrientation),