Bug 743252 - Implement moznomarginboxes attribute. r=roc, a=bajaj, ba=jorgev
authorJulian Viereck <julian.viereck@gmail.com>
Wed, 20 Feb 2013 10:50:21 -0500
changeset 127672 221b9038b2a750a347a9225ea1f90f01856cc3e4
parent 127671 7675ab257ed482bea23b857231439a245bb30c58
child 127673 a5bef71d4e1d913dea9e0a9b106f1ebd4ffaee9a
push id2231
push userryanvm@gmail.com
push dateWed, 06 Mar 2013 16:31:07 +0000
treeherdermozilla-beta@221b9038b2a7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, bajaj
bugs743252
milestone20.0
Bug 743252 - Implement moznomarginboxes attribute. r=roc, a=bajaj, ba=jorgev
content/base/src/nsGkAtomList.h
layout/base/nsDocumentViewer.cpp
layout/printing/nsPrintEngine.cpp
layout/printing/nsPrintEngine.h
widget/nsIPrintSettings.idl
widget/xpwidgets/nsPrintOptionsImpl.cpp
widget/xpwidgets/nsPrintSettingsImpl.cpp
widget/xpwidgets/nsPrintSettingsImpl.h
--- a/content/base/src/nsGkAtomList.h
+++ b/content/base/src/nsGkAtomList.h
@@ -33,16 +33,17 @@
 
 GK_ATOM(_empty, "")
 GK_ATOM(moz, "_moz")
 GK_ATOM(mozframetype, "mozframetype")
 GK_ATOM(mozallowfullscreen, "mozallowfullscreen")
 GK_ATOM(moztype, "_moz-type")
 GK_ATOM(mozdirty, "_moz_dirty")
 GK_ATOM(mozdisallowselectionprint, "mozdisallowselectionprint")
+GK_ATOM(moznomarginboxes, "moznomarginboxes")
 GK_ATOM(mozdonotsend, "moz-do-not-send")
 GK_ATOM(mozeditorbogusnode, "_moz_editor_bogus_node")
 GK_ATOM(mozgeneratedcontentbefore, "_moz_generated_content_before")
 GK_ATOM(mozgeneratedcontentafter, "_moz_generated_content_after")
 GK_ATOM(mozgeneratedcontentimage, "_moz_generated_content_image")
 GK_ATOM(mozquote, "_moz_quote")
 GK_ATOM(_moz_is_glyph, "-moz-is-glyph")
 GK_ATOM(_moz_original_size, "_moz_original_size")
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -3663,16 +3663,19 @@ nsDocumentViewer::Print(nsIPrintSettings
   }
   if (mPrintEngine->HasPrintCallbackCanvas()) {
     mBeforeAndAfterPrint = beforeAndAfterPrint;
   }
   dom::Element* root = mDocument->GetRootElement();
   if (root && root->HasAttr(kNameSpaceID_None, nsGkAtoms::mozdisallowselectionprint)) {
     mPrintEngine->SetDisallowSelectionPrint(true);
   }
+  if (root && root->HasAttr(kNameSpaceID_None, nsGkAtoms::moznomarginboxes)) {
+    mPrintEngine->SetNoMarginBoxes(true);
+  }
   rv = mPrintEngine->Print(aPrintSettings, aWebProgressListener);
   if (NS_FAILED(rv)) {
     OnDonePrinting();
   }
   return rv;
 }
 
 NS_IMETHODIMP
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -231,17 +231,18 @@ nsPrintEngine::nsPrintEngine() :
   mPagePrintTimer(nullptr),
   mPageSeqFrame(nullptr),
   mPrtPreview(nullptr),
   mOldPrtPreview(nullptr),
   mDebugFile(nullptr),
   mLoadCounter(0),
   mDidLoadDataForPrinting(false),
   mIsDestroying(false),
-  mDisallowSelectionPrint(false)
+  mDisallowSelectionPrint(false),
+  mNoMarginBoxes(false)
 {
 }
 
 //-------------------------------------------------------
 nsPrintEngine::~nsPrintEngine()
 {
   Destroy(); // for insurance
 }
@@ -470,16 +471,31 @@ nsPrintEngine::DoCommonPrint(bool       
   }
 
   rv = CheckForPrinters(mPrt->mPrintSettings);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mPrt->mPrintSettings->SetIsCancelled(false);
   mPrt->mPrintSettings->GetShrinkToFit(&mPrt->mShrinkToFit);
 
+  // In the case the margin boxes are not printed store the print settings for
+  // the footer/header to be used as default print setting for follow up prints.
+  mPrt->mPrintSettings->SetPersistMarginBoxSettings(!mNoMarginBoxes);
+
+  if (mNoMarginBoxes) {
+    // Set the footer/header to blank.
+    const PRUnichar* emptyString = EmptyString().get();
+    mPrt->mPrintSettings->SetHeaderStrLeft(emptyString);
+    mPrt->mPrintSettings->SetHeaderStrCenter(emptyString);
+    mPrt->mPrintSettings->SetHeaderStrRight(emptyString);
+    mPrt->mPrintSettings->SetFooterStrLeft(emptyString);
+    mPrt->mPrintSettings->SetFooterStrCenter(emptyString);
+    mPrt->mPrintSettings->SetFooterStrRight(emptyString);
+  }
+
   if (aIsPrintPreview) {
     SetIsCreatingPrintPreview(true);
     SetIsPrintPreview(true);
     nsCOMPtr<nsIMarkupDocumentViewer> viewer =
       do_QueryInterface(mDocViewerPrint);
     if (viewer) {
       viewer->SetTextZoom(1.0f);
       viewer->SetFullZoom(1.0f);
--- a/layout/printing/nsPrintEngine.h
+++ b/layout/printing/nsPrintEngine.h
@@ -204,16 +204,20 @@ public:
     return mIsCreatingPrintPreview;
   }
 
   void SetDisallowSelectionPrint(bool aDisallowSelectionPrint)
   {
     mDisallowSelectionPrint = aDisallowSelectionPrint;
   }
 
+  void SetNoMarginBoxes(bool aNoMarginBoxes) {
+    mNoMarginBoxes = aNoMarginBoxes;
+  }
+
 protected:
 
   nsresult CommonPrint(bool aIsPrintPreview, nsIPrintSettings* aPrintSettings,
                        nsIWebProgressListener* aWebProgressListener,
                        nsIDOMDocument* aDoc);
 
   nsresult DoCommonPrint(bool aIsPrintPreview, nsIPrintSettings* aPrintSettings,
                          nsIWebProgressListener* aWebProgressListener,
@@ -282,16 +286,17 @@ protected:
   nsCOMPtr<nsIDocument>   mDocument;
 
   FILE* mDebugFile;
 
   int32_t mLoadCounter;
   bool mDidLoadDataForPrinting;
   bool mIsDestroying;
   bool mDisallowSelectionPrint;
+  bool mNoMarginBoxes;
 
   nsresult AfterNetworkPrint(bool aHandleError);
 
   nsresult SetRootView(nsPrintObject* aPO,
                        bool& aDoReturn,
                        bool& aDocumentIsTopLevel,
                        nsSize& aAdjSize);
   nsView* GetParentViewForRoot();
--- a/widget/nsIPrintSettings.idl
+++ b/widget/nsIPrintSettings.idl
@@ -262,16 +262,22 @@ interface nsIPrintSettings : nsISupports
   /**
    * This attribute tracks whether the PS has been initialized 
    * from prefs. If a different name is set into the "printerName" 
    * attribute than the one it was initialized with the PS
    * will then get intialized from prefs again.
    */
   attribute boolean isInitializedFromPrefs;
 
+  /**
+   * This attribute tracks if the settings made on the margin box is
+   * stored in the prefs or not.
+   */
+  attribute boolean persistMarginBoxSettings;
+
   /* C++ Helper Functions */
   [noscript] void SetMarginInTwips(in nsNativeIntMarginRef aMargin);
   [noscript] void SetEdgeInTwips(in nsNativeIntMarginRef aEdge);
   /* Purposely made this an "in" arg */
   [noscript] void GetMarginInTwips(in nsNativeIntMarginRef aMargin);
   [noscript] void GetEdgeInTwips(in nsNativeIntMarginRef aEdge);
 
   /**
--- a/widget/xpwidgets/nsPrintOptionsImpl.cpp
+++ b/widget/xpwidgets/nsPrintOptionsImpl.cpp
@@ -504,16 +504,19 @@ nsPrintOptions::ReadPrefs(nsIPrintSettin
  *  @update 1/12/01 rods
  */
 nsresult 
 nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName,
                            uint32_t aFlags)
 {
   NS_ENSURE_ARG_POINTER(aPS);
 
+  bool persistMarginBoxSettings;
+  aPS->GetPersistMarginBoxSettings(&persistMarginBoxSettings);
+
   nsIntMargin margin;
   if (aFlags & nsIPrintSettings::kInitSaveMargins) {
     if (NS_SUCCEEDED(aPS->GetMarginInTwips(margin))) {
       WriteInchesFromTwipsPref(GetPrefName(kMarginTop, aPrinterName),
                                margin.top);
       DUMP_INT(kWriteStr, kMarginTop, margin.top);
       WriteInchesFromTwipsPref(GetPrefName(kMarginLeft, aPrinterName),
                                margin.left);
@@ -608,61 +611,63 @@ nsPrintOptions::WritePrefs(nsIPrintSetti
   if (aFlags & nsIPrintSettings::kInitSaveOddEvenPages) {
     if (NS_SUCCEEDED(aPS->GetPrintOptions(nsIPrintSettings::kPrintOddPages,
                                           &b))) {
           DUMP_BOOL(kWriteStr, kPrintOddPages, b);
           Preferences::SetBool(GetPrefName(kPrintOddPages, aPrinterName), b);
         }
   }
 
-  if (aFlags & nsIPrintSettings::kInitSaveHeaderLeft) {
-    if (NS_SUCCEEDED(aPS->GetHeaderStrLeft(&uStr))) {
-      DUMP_STR(kWriteStr, kPrintHeaderStrLeft, uStr);
-      Preferences::SetString(GetPrefName(kPrintHeaderStrLeft, aPrinterName),
-                             uStr);
+  if (persistMarginBoxSettings) {
+    if (aFlags & nsIPrintSettings::kInitSaveHeaderLeft) {
+      if (NS_SUCCEEDED(aPS->GetHeaderStrLeft(&uStr))) {
+        DUMP_STR(kWriteStr, kPrintHeaderStrLeft, uStr);
+        Preferences::SetString(GetPrefName(kPrintHeaderStrLeft, aPrinterName),
+                               uStr);
+      }
     }
-  }
 
-  if (aFlags & nsIPrintSettings::kInitSaveHeaderCenter) {
-    if (NS_SUCCEEDED(aPS->GetHeaderStrCenter(&uStr))) {
-      DUMP_STR(kWriteStr, kPrintHeaderStrCenter, uStr);
-      Preferences::SetString(GetPrefName(kPrintHeaderStrCenter, aPrinterName),
-                             uStr);
+    if (aFlags & nsIPrintSettings::kInitSaveHeaderCenter) {
+      if (NS_SUCCEEDED(aPS->GetHeaderStrCenter(&uStr))) {
+        DUMP_STR(kWriteStr, kPrintHeaderStrCenter, uStr);
+        Preferences::SetString(GetPrefName(kPrintHeaderStrCenter, aPrinterName),
+                               uStr);
+      }
     }
-  }
 
-  if (aFlags & nsIPrintSettings::kInitSaveHeaderRight) {
-    if (NS_SUCCEEDED(aPS->GetHeaderStrRight(&uStr))) {
-      DUMP_STR(kWriteStr, kPrintHeaderStrRight, uStr);
-      Preferences::SetString(GetPrefName(kPrintHeaderStrRight, aPrinterName),
-                             uStr);
+    if (aFlags & nsIPrintSettings::kInitSaveHeaderRight) {
+      if (NS_SUCCEEDED(aPS->GetHeaderStrRight(&uStr))) {
+        DUMP_STR(kWriteStr, kPrintHeaderStrRight, uStr);
+        Preferences::SetString(GetPrefName(kPrintHeaderStrRight, aPrinterName),
+                               uStr);
+      }
     }
-  }
 
-  if (aFlags & nsIPrintSettings::kInitSaveFooterLeft) {
-    if (NS_SUCCEEDED(aPS->GetFooterStrLeft(&uStr))) {
-      DUMP_STR(kWriteStr, kPrintFooterStrLeft, uStr);
-      Preferences::SetString(GetPrefName(kPrintFooterStrLeft, aPrinterName),
-                             uStr);
+    if (aFlags & nsIPrintSettings::kInitSaveFooterLeft) {
+      if (NS_SUCCEEDED(aPS->GetFooterStrLeft(&uStr))) {
+        DUMP_STR(kWriteStr, kPrintFooterStrLeft, uStr);
+        Preferences::SetString(GetPrefName(kPrintFooterStrLeft, aPrinterName),
+                               uStr);
+      }
     }
-  }
 
-  if (aFlags & nsIPrintSettings::kInitSaveFooterCenter) {
-    if (NS_SUCCEEDED(aPS->GetFooterStrCenter(&uStr))) {
-      DUMP_STR(kWriteStr, kPrintFooterStrCenter, uStr);
-      Preferences::SetString(GetPrefName(kPrintFooterStrCenter, aPrinterName),
-                             uStr);
+    if (aFlags & nsIPrintSettings::kInitSaveFooterCenter) {
+      if (NS_SUCCEEDED(aPS->GetFooterStrCenter(&uStr))) {
+        DUMP_STR(kWriteStr, kPrintFooterStrCenter, uStr);
+        Preferences::SetString(GetPrefName(kPrintFooterStrCenter, aPrinterName),
+                               uStr);
+      }
     }
-  }
 
-  if (aFlags & nsIPrintSettings::kInitSaveFooterRight) {
-    if (NS_SUCCEEDED(aPS->GetFooterStrRight(&uStr))) {
-      DUMP_STR(kWriteStr, kPrintFooterStrRight, uStr);
-      Preferences::SetString(GetPrefName(kPrintFooterStrRight, aPrinterName),
-                             uStr);
+    if (aFlags & nsIPrintSettings::kInitSaveFooterRight) {
+      if (NS_SUCCEEDED(aPS->GetFooterStrRight(&uStr))) {
+        DUMP_STR(kWriteStr, kPrintFooterStrRight, uStr);
+        Preferences::SetString(GetPrefName(kPrintFooterStrRight, aPrinterName),
+                               uStr);
+      }
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveBGColors) {
     if (NS_SUCCEEDED(aPS->GetPrintBGColors(&b))) {
       DUMP_BOOL(kWriteStr, kPrintBGColors, b);
       Preferences::SetBool(GetPrefName(kPrintBGColors, aPrinterName), b);
     }
--- a/widget/xpwidgets/nsPrintSettingsImpl.cpp
+++ b/widget/xpwidgets/nsPrintSettingsImpl.cpp
@@ -40,17 +40,18 @@ nsPrintSettings::nsPrintSettings() :
   mPrintReversed(false),
   mPrintInColor(true),
   mOrientation(kPortraitOrientation),
   mDownloadFonts(false),
   mNumCopies(1),
   mPrintToFile(false),
   mOutputFormat(kOutputFormatNative),
   mIsInitedFromPrinter(false),
-  mIsInitedFromPrefs(false)
+  mIsInitedFromPrefs(false),
+  mPersistMarginBoxSettings(true)
 {
 
   /* member initializers and constructor code */
   int32_t marginWidth = NS_INCHES_TO_INT_TWIPS(DEFAULT_MARGIN_WIDTH);
   mMargin.SizeTo(marginWidth, marginWidth, marginWidth, marginWidth);
   mEdge.SizeTo(0, 0, 0, 0);
   mUnwriteableMargin.SizeTo(0,0,0,0);
 
@@ -358,16 +359,29 @@ NS_IMETHODIMP nsPrintSettings::GetIsInit
   return NS_OK;
 }
 NS_IMETHODIMP nsPrintSettings::SetIsInitializedFromPrefs(bool aInitializedFromPrefs)
 {
   mIsInitedFromPrefs = (bool)aInitializedFromPrefs;
   return NS_OK;
 }
 
+/* attribute boolean persistMarginBoxSettings; */
+NS_IMETHODIMP nsPrintSettings::GetPersistMarginBoxSettings(bool *aPersistMarginBoxSettings)
+{
+  NS_ENSURE_ARG_POINTER(aPersistMarginBoxSettings);
+  *aPersistMarginBoxSettings = mPersistMarginBoxSettings;
+  return NS_OK;
+}
+NS_IMETHODIMP nsPrintSettings::SetPersistMarginBoxSettings(bool aPersistMarginBoxSettings)
+{
+  mPersistMarginBoxSettings = aPersistMarginBoxSettings;
+  return NS_OK;
+}
+
 /* attribute double marginTop; */
 NS_IMETHODIMP nsPrintSettings::GetMarginTop(double *aMarginTop)
 {
   NS_ENSURE_ARG_POINTER(aMarginTop);
   *aMarginTop = NS_TWIPS_TO_INCHES(mMargin.top);
   return NS_OK;
 }
 NS_IMETHODIMP nsPrintSettings::SetMarginTop(double aMarginTop)
--- a/widget/xpwidgets/nsPrintSettingsImpl.h
+++ b/widget/xpwidgets/nsPrintSettingsImpl.h
@@ -96,12 +96,12 @@ protected:
   nsString      mPrintCommand;
   int32_t       mNumCopies;
   nsXPIDLString mPrinter;
   bool          mPrintToFile;
   nsString      mToFileName;
   int16_t       mOutputFormat;
   bool          mIsInitedFromPrinter;
   bool          mIsInitedFromPrefs;
-
+  bool          mPersistMarginBoxSettings;
 };
 
 #endif /* nsPrintSettings_h__ */