Bug 558742 - Comma doesn't work in print range, r=roc
authorMartin Stransky <stransky@redhat.com>
Tue, 06 Dec 2011 23:45:06 -0500
changeset 83790 845129faeacefca5a1454562eac2cdf428ba6a64
parent 83789 7341f4e8b3f3644b3025fcc23a77b6db8828d9c5
child 83791 c93612dc5922228e9cd10751733c1f025185d24b
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs558742
milestone11.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 558742 - Comma doesn't work in print range, r=roc
layout/generic/nsSimplePageSequence.cpp
layout/generic/nsSimplePageSequence.h
widget/public/nsIPrintSettings.idl
widget/src/gtk2/nsPrintSettingsGTK.cpp
widget/src/gtk2/nsPrintSettingsGTK.h
widget/src/xpwidgets/nsPrintSettingsImpl.cpp
--- a/layout/generic/nsSimplePageSequence.cpp
+++ b/layout/generic/nsSimplePageSequence.cpp
@@ -455,16 +455,17 @@ nsSimplePageSequenceFrame::StartPrint(ns
   }
 
   // Only set them if they are not null
   if (aDocTitle) mPageData->mDocTitle = aDocTitle;
   if (aDocURL) mPageData->mDocURL   = aDocURL;
 
   aPrintSettings->GetStartPageRange(&mFromPageNum);
   aPrintSettings->GetEndPageRange(&mToPageNum);
+  aPrintSettings->GetPageRanges(mPageRanges);
 
   mDoingPageRange = nsIPrintSettings::kRangeSpecifiedPageRange == mPrintRangeType ||
                     nsIPrintSettings::kRangeSelection == mPrintRangeType;
 
   // If printing a range of pages make sure at least the starting page
   // number is valid
   PRInt32 totalPages = mFrames.GetLength();
 
@@ -551,16 +552,31 @@ nsSimplePageSequenceFrame::PrintNextPage
   // range of pages to print
   if (mDoingPageRange) {
     if (mPageNum < mFromPageNum) {
       mPrintThisPage = false;
     } else if (mPageNum > mToPageNum) {
       mPageNum++;
       mCurrentPageFrame = nsnull;
       return NS_OK;
+    } else {
+      PRInt32 length = mPageRanges.Length();
+    
+      // Page ranges are pairs (start, end)
+      if (length && (length % 2 == 0)) {
+        mPrintThisPage = false;
+      
+        PRInt32 i;
+        for (i = 0; i < length; i += 2) {          
+          if (mPageRanges[i] <= mPageNum && mPageNum <= mPageRanges[i+1]) {
+            mPrintThisPage = true;
+            break;
+          }
+        }
+      }
     }
   }
 
   // Check for printing of odd and even pages
   if (mPageNum & 0x1) {
     if (!printOddPages) {
       mPrintThisPage = false;  // don't print odd numbered page
     }
--- a/layout/generic/nsSimplePageSequence.h
+++ b/layout/generic/nsSimplePageSequence.h
@@ -160,16 +160,17 @@ protected:
 
   // Asynch Printing
   nsIFrame *   mCurrentPageFrame;
   PRInt32      mPageNum;
   PRInt32      mTotalPages;
   PRInt32      mPrintRangeType;
   PRInt32      mFromPageNum;
   PRInt32      mToPageNum;
+  nsTArray<PRInt32> mPageRanges;
 
   // Selection Printing Info
   nscoord      mSelectionHeight;
   nscoord      mYSelOffset;
 
   // Asynch Printing
   bool mPrintThisPage;
   bool mDoingPageRange;
--- a/widget/public/nsIPrintSettings.idl
+++ b/widget/public/nsIPrintSettings.idl
@@ -39,29 +39,31 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
 
 %{ C++
 #include "nsMargin.h"
+#include "nsTArray.h"
 %}
 
 /**
  * Native types
  */
   [ref] native nsNativeIntMarginRef(nsIntMargin);
+  [ref] native IntegerArray(nsTArray<PRInt32>);
   
 interface nsIPrintSession;
 
 /**
  * Simplified graphics interface for JS rendering.
  */
-[scriptable, uuid(343700dd-078b-42b6-a809-b9c1d7e951d0)]
+[scriptable, uuid(4404c94b-0506-4255-9e3c-4582dba6cfbb)]
 
 interface nsIPrintSettings : nsISupports
 {
   /**
    * PrintSettings to be Saved Navigation Constants
    */
   const unsigned long kInitSaveOddEvenPages   = 0x00000001;
   const unsigned long kInitSaveHeaderLeft     = 0x00000002;
@@ -324,9 +326,20 @@ interface nsIPrintSettings : nsISupports
    * attributes, to place the headers and content, respectively.
    *
    * Note: Implementations of SetUnwriteableMarginInTwips should handle
    * negative margin values by falling back on the system default for
    * that margin.
    */
   [noscript] void SetUnwriteableMarginInTwips(in nsNativeIntMarginRef aEdge);
   [noscript] void GetUnwriteableMarginInTwips(in nsNativeIntMarginRef aEdge);
+  
+  /**
+   * Get more accurate print ranges from the superior interval 
+   * (startPageRange, endPageRange). The aPages array is populated with a 
+   * list of pairs (start, end), where the endpoints are included. The print 
+   * ranges (start, end), must not overlap and must be in the 
+   * (startPageRange, endPageRange) scope.
+   *
+   * If there are no print ranges the aPages array is cleared.
+   */
+  [noscript] void GetPageRanges(in IntegerArray aPages);
 };
--- a/widget/src/gtk2/nsPrintSettingsGTK.cpp
+++ b/widget/src/gtk2/nsPrintSettingsGTK.cpp
@@ -744,8 +744,28 @@ nsPrintSettingsGTK::SetupSilentPrinting(
   gtk_enumerate_printers(printer_enumerator, this, NULL, TRUE);
 
   // XXX If no default printer set, get the first one.
   if (!GTK_IS_PRINTER(mGTKPrinter))
     gtk_enumerate_printers(ref_printer, this, NULL, TRUE);
 
   return NS_OK;
 }
+
+NS_IMETHODIMP
+nsPrintSettingsGTK::GetPageRanges(nsTArray<PRInt32> &aPages)
+{
+  gint ctRanges;
+  GtkPageRange* lstRanges = gtk_print_settings_get_page_ranges(mPrintSettings, &ctRanges);
+
+  aPages.Clear();
+
+  if (ctRanges > 1) {
+    for (gint i = 0; i < ctRanges; i++) {
+      aPages.AppendElement(lstRanges[i].start+1);
+      aPages.AppendElement(lstRanges[i].end+1);
+    }
+  }
+
+  g_free(lstRanges);
+  return NS_OK;
+}
+
--- a/widget/src/gtk2/nsPrintSettingsGTK.h
+++ b/widget/src/gtk2/nsPrintSettingsGTK.h
@@ -134,16 +134,18 @@ public:
   NS_IMETHOD SetPaperHeight(double aPaperHeight);
 
   NS_IMETHOD SetPaperSizeUnit(PRInt16 aPaperSizeUnit);
 
   NS_IMETHOD GetEffectivePageSize(double *aWidth, double *aHeight);
 
   NS_IMETHOD SetupSilentPrinting();
 
+  NS_IMETHOD GetPageRanges(nsTArray<PRInt32> &aPages);
+
 protected:
   nsPrintSettingsGTK(const nsPrintSettingsGTK& src);
   nsPrintSettingsGTK& operator=(const nsPrintSettingsGTK& rhs);
 
   virtual nsresult _Clone(nsIPrintSettings **_retval);
   virtual nsresult _Assign(nsIPrintSettings *aPS);
 
   GtkUnit GetGTKUnit(PRInt16 aGeckoUnit);
--- a/widget/src/xpwidgets/nsPrintSettingsImpl.cpp
+++ b/widget/src/xpwidgets/nsPrintSettingsImpl.cpp
@@ -1087,16 +1087,23 @@ nsPrintSettings::GetEffectivePageSize(do
   if (kLandscapeOrientation == mOrientation) {
     double temp = *aWidth;
     *aWidth = *aHeight;
     *aHeight = temp;
   }
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsPrintSettings::GetPageRanges(nsTArray<PRInt32> &aPages)
+{
+  aPages.Clear();
+  return NS_OK;
+}
+
 nsresult 
 nsPrintSettings::_Clone(nsIPrintSettings **_retval)
 {
   nsPrintSettings* printSettings = new nsPrintSettings(*this);
   return printSettings->QueryInterface(NS_GET_IID(nsIPrintSettings), (void**)_retval); // ref counts
 }
 
 /* nsIPrintSettings clone (); */