content/base/src/nsDocumentViewer.cpp - Revision 1.177

There were 117 changes made.
Legend
   Added lines
   Changed lines
   Removed lines

content/base/src/nsDocumentViewer.cpp,1.177
.
Disk File
Skipping to line 117. 
 
.
 
#include "nsPIDOMWindow.h"
.
#include "nsPIDOMWindow.h"
#include "nsIFocusController.h"
.
#include "nsIFocusController.h"
 
.
 
// Print Options
.
// Print Options
 
.
#include "nsIPrintSettings.h"
#include "nsIPrintOptions.h"
.
#include "nsIPrintOptions.h"
#include "nsGfxCIID.h"
.
#include "nsGfxCIID.h"
#include "nsIServiceManager.h"
.
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
.
 
#include "nsHTMLAtoms.h" // XXX until atoms get factored into nsLayoutAtoms
.
#include "nsHTMLAtoms.h" // XXX until atoms get factored into nsLayoutAtoms
 
.
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
 
.
 
// Printing Events
.
// Printing Events
#include "nsIEventQueue.h"
.
#include "nsIEventQueue.h"
#include "nsIEventQueueService.h"
.
#include "nsIEventQueueService.h"
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
.
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
Skipping to line 356. 
  void OnEndPrinting(nsresult aResult);
.
  void OnEndPrinting(nsresult aResult);
  void OnStartPrinting();
.
  void OnStartPrinting();
 
.
 
  nsCOMPtr<nsIDeviceContext>   mPrintDC;
.
  nsCOMPtr<nsIDeviceContext>   mPrintDC;
  nsIView                     *mPrintView;
.
  nsIView                     *mPrintView;
  FILE                        *mFilePointer;    // a file where information ca
n go to when printing
.
  FILE                        *mDebugFilePtr;    // a file where information c
an go to when printing
 
.
 
  PrintObject *                mPrintObject;
.
  PrintObject *                mPrintObject;
  PrintObject *                mSelectedPO;
.
  PrintObject *                mSelectedPO;
 
.
 
  nsCOMPtr<nsIPrintListener>  mPrintListener; // An observer for printing...
.
  nsCOMPtr<nsIPrintListener>  mPrintListener; // An observer for printing...
Skipping to line 377. 
  PRInt32                     mNumPrintableDocs;
.
  PRInt32                     mNumPrintableDocs;
  PRInt32                     mNumDocsPrinted;
.
  PRInt32                     mNumDocsPrinted;
  PRInt32                     mNumPrintablePages;
.
  PRInt32                     mNumPrintablePages;
  PRInt32                     mNumPagesPrinted;
.
  PRInt32                     mNumPagesPrinted;
 
.
 
 
.
  nsCOMPtr<nsIPrintSettings>  mPrintSettings;
 
.
 
#ifdef DEBUG_PRINTING
.
#ifdef DEBUG_PRINTING
  FILE *           mDebugFD;
.
  FILE *           mDebugFD;
#endif
.
#endif
 
.
 
private:
.
private:
Skipping to line 437. 
  typedef void (*CallChildFunc)(nsIMarkupDocumentViewer* aViewer,
.
  typedef void (*CallChildFunc)(nsIMarkupDocumentViewer* aViewer,
                                void* aClosure);
.
                                void* aClosure);
  nsresult CallChildren(CallChildFunc aFunc, void* aClosure);
.
  nsresult CallChildren(CallChildFunc aFunc, void* aClosure);
 
.
 
  // Printing Methods
.
  // Printing Methods
  PRBool   PrintPage(nsIPresContext* aPresContext,nsIPrintOptions* aPrintOptio
ns,PrintObject* aPOect);
.
  PRBool   PrintPage(nsIPresContext* aPresContext,nsIPrintSettings* aPrintSett
ings,PrintObject* aPOect);
  PRBool   DonePrintingPages(PrintObject* aPO);
.
  PRBool   DonePrintingPages(PrintObject* aPO);
  
.
  
  // helper method
.
  // helper method
  static void GetWebShellTitleAndURL(nsIWebShell * aWebShell, PRUnichar** aTit
le, PRUnichar** aURLStr);
.
  static void GetWebShellTitleAndURL(nsIWebShell * aWebShell, PRUnichar** aTit
le, PRUnichar** aURLStr);
 
.
 
Skipping to line 532. 
#endif
.
#endif
 
.
 
 
.
 
  // Timer Methods
.
  // Timer Methods
  nsresult StartPagePrintTimer(nsIPresContext * aPresContext, 
.
  nsresult StartPagePrintTimer(nsIPresContext * aPresContext, 
                               nsIPrintOptions* aPrintOptions,
.
                               nsIPrintSettings* aPrintSettings,
                               PrintObject*     aPOect,
.
                               PrintObject*     aPO,
                               PRUint32         aDelay);
.
                               PRUint32         aDelay);
 
.
 
  void PrepareToStartLoad(void);
.
  void PrepareToStartLoad(void);
  
.
  
  // Misc
.
  // Misc
Skipping to line 586. 
  PRBool            mIsDoingPrintPreview; // per DocumentViewer
.
  PRBool            mIsDoingPrintPreview; // per DocumentViewer
  nsIWidget*        mParentWidget; // purposely won't be ref counted
.
  nsIWidget*        mParentWidget; // purposely won't be ref counted
  PrintData*        mPrtPreview;
.
  PrintData*        mPrtPreview;
#endif
.
#endif
 
.
 
 
.
#ifdef NS_DEBUG
 
.
  FILE* mDebugFile;
 
.
#endif
 
.
 
  // static memeber variables
.
  // static memeber variables
  static PRBool mIsCreatingPrintPreview;
.
  static PRBool mIsCreatingPrintPreview;
  static PRBool mIsDoingPrinting;
.
  static PRBool mIsDoingPrinting;
 
.
 
  // document management data
.
  // document management data
Skipping to line 615. 
public:
.
public:
 
.
 
  NS_DECL_ISUPPORTS
.
  NS_DECL_ISUPPORTS
 
.
 
  nsPagePrintTimer()
.
  nsPagePrintTimer()
      : mDocViewer(nsnull), mPresContext(nsnull), mPrintOptions(nsnull), mDela
y(0)
.
      : mDocViewer(nsnull), mPresContext(nsnull), mPrintSettings(nsnull), mDel
ay(0)
  {
.
  {
    NS_INIT_ISUPPORTS();
.
    NS_INIT_ISUPPORTS();
  }
.
  }
 
.
 
  virtual ~nsPagePrintTimer()
.
  virtual ~nsPagePrintTimer()
Skipping to line 653. 
    if (mPresContext && mDocViewer) {
.
    if (mPresContext && mDocViewer) {
      PRPackedBool initNewTimer = PR_TRUE;
.
      PRPackedBool initNewTimer = PR_TRUE;
      // Check to see if we are done
.
      // Check to see if we are done
      // donePrinting will be true if it completed successfully or
.
      // donePrinting will be true if it completed successfully or
      // if the printing was cancelled
.
      // if the printing was cancelled
      PRBool donePrinting = mDocViewer->PrintPage(mPresContext, mPrintOptions,
 mPrintObj);
.
      PRBool donePrinting = mDocViewer->PrintPage(mPresContext, mPrintSettings
, mPrintObj);
      if (donePrinting) {
.
      if (donePrinting) {
        // now clean up print or print the next webshell
.
        // now clean up print or print the next webshell
        if (mDocViewer->DonePrintingPages(mPrintObj)) {
.
        if (mDocViewer->DonePrintingPages(mPrintObj)) {
          initNewTimer = PR_FALSE;
.
          initNewTimer = PR_FALSE;
        }
.
        }
Skipping to line 674. 
    }
.
    }
  }
.
  }
 
.
 
  void Init(DocumentViewerImpl* aDocViewerImpl, 
.
  void Init(DocumentViewerImpl* aDocViewerImpl, 
            nsIPresContext*     aPresContext,
.
            nsIPresContext*     aPresContext,
            nsIPrintOptions*    aPrintOptions,
.
            nsIPrintSettings*   aPrintSettings,
            PrintObject*        aPO,
.
            PrintObject*        aPO,
            PRUint32            aDelay) 
.
            PRUint32            aDelay) 
  {
.
  {
    NS_IF_RELEASE(mDocViewer);
.
    NS_IF_RELEASE(mDocViewer);
    mDocViewer       = aDocViewerImpl;
.
    mDocViewer       = aDocViewerImpl;
Skipping to line 686. 
 
.
 
    mPresContext     = aPresContext;
.
    mPresContext     = aPresContext;
    mPrintOptions    = aPrintOptions;
.
    mPrintSettings   = aPrintSettings;
    mPrintObj        = aPO;
.
    mPrintObj        = aPO;
    mDelay           = aDelay;
.
    mDelay           = aDelay;
  }
.
  }
 
.
 
  nsresult Start(DocumentViewerImpl* aDocViewerImpl, 
.
  nsresult Start(DocumentViewerImpl* aDocViewerImpl, 
Skipping to line 695. 
                 nsIPrintOptions*    aPrintOptions,
.
                 nsIPrintSettings*   aPrintSettings,
                 PrintObject*        aPO,
.
                 PrintObject*        aPO,
                 PRUint32            aDelay) 
.
                 PRUint32            aDelay) 
  {
.
  {
    Init(aDocViewerImpl, aPresContext, aPrintOptions, aPO, aDelay);
.
    Init(aDocViewerImpl, aPresContext, aPrintSettings, aPO, aDelay);
    return StartTimer();
.
    return StartTimer();
  }
.
  }
 
.
 
 
.
 
  void Stop()
.
  void Stop()
Skipping to line 708. 
      mTimer = nsnull;
.
      mTimer = nsnull;
    }
.
    }
  }
.
  }
 
.
 
private:
.
private:
  DocumentViewerImpl*  mDocViewer;
.
  DocumentViewerImpl*        mDocViewer;
  nsIPresContext*      mPresContext;
.
  nsIPresContext*            mPresContext;
  nsIPrintOptions*     mPrintOptions;
.
  nsCOMPtr<nsIPrintSettings> mPrintSettings;
  nsCOMPtr<nsITimer>   mTimer;
.
  nsCOMPtr<nsITimer>         mTimer;
  PRUint32             mDelay;
.
  PRUint32                   mDelay;
  PrintObject *        mPrintObj;
.
  PrintObject *              mPrintObj;
};
.
};
 
.
 
NS_IMPL_ISUPPORTS1(nsPagePrintTimer, nsITimerCallback)
.
NS_IMPL_ISUPPORTS1(nsPagePrintTimer, nsITimerCallback)
 
.
 
static nsresult NS_NewUpdateTimer(nsPagePrintTimer **aResult)
.
static nsresult NS_NewUpdateTimer(nsPagePrintTimer **aResult)
Skipping to line 740. 
 
.
 
//---------------------------------------------------
.
//---------------------------------------------------
//-- PrintData Class Impl
.
//-- PrintData Class Impl
//---------------------------------------------------
.
//---------------------------------------------------
PrintData::PrintData() :
.
PrintData::PrintData() :
  mPrintView(nsnull), mFilePointer(nsnull), mPrintObject(nsnull), mSelectedPO(
nsnull),
.
  mPrintView(nsnull), mDebugFilePtr(nsnull), mPrintObject(nsnull), mSelectedPO
(nsnull),
  mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE),
.
  mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE),
  mIsParentAFrameSet(PR_FALSE), mPrintingAsIsSubDoc(PR_FALSE),
.
  mIsParentAFrameSet(PR_FALSE), mPrintingAsIsSubDoc(PR_FALSE),
  mPrintFrameType(nsIPrintOptions::kFramesAsIs), mOnStartSent(PR_FALSE), 
.
  mPrintFrameType(nsIPrintSettings::kFramesAsIs), mOnStartSent(PR_FALSE), 
  mNumPrintableDocs(0), mNumDocsPrinted(0), mNumPrintablePages(0), mNumPagesPr
inted(0)
.
  mNumPrintableDocs(0), mNumDocsPrinted(0), mNumPrintablePages(0), mNumPagesPr
inted(0)
{
.
{
#ifdef DEBUG_PRINTING
.
#ifdef DEBUG_PRINTING
  mDebugFD = fopen("printing.log", "w");
.
  mDebugFD = fopen("printing.log", "w");
#endif
.
#endif
Skipping to line 880. 
 
.
 
#ifdef NS_PRINT_PREVIEW
.
#ifdef NS_PRINT_PREVIEW
  mIsDoingPrintPreview = PR_FALSE;
.
  mIsDoingPrintPreview = PR_FALSE;
  mPrtPreview          = nsnull;
.
  mPrtPreview          = nsnull;
#endif
.
#endif
 
.
 
 
.
#ifdef NS_DEBUG
 
.
  mDebugFile = nsnull;
 
.
#endif
}
.
}
 
.
 
DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext)
.
DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext)
  : mPresContext(aPresContext)
.
  : mPresContext(aPresContext)
{
.
{
Skipping to line 2315. 
  return PR_TRUE;
.
  return PR_TRUE;
}
.
}
 
.
 
//-------------------------------------------------------
.
//-------------------------------------------------------
PRBool
.
PRBool
DocumentViewerImpl::PrintPage(nsIPresContext*  aPresContext,
.
DocumentViewerImpl::PrintPage(nsIPresContext*   aPresContext,
                              nsIPrintOptions* aPrintOptions,
.
                              nsIPrintSettings* aPrintSettings,
                              PrintObject*     aPO)
.
                              PrintObject*      aPO)
{
.
{
  NS_ASSERTION(aPresContext, "Pointer is null!");
.
  NS_ASSERTION(aPresContext, "Pointer is null!");
  NS_ASSERTION(aPrintOptions, "Pointer is null!");
.
  NS_ASSERTION(aPrintSettings, "Pointer is null!");
  NS_ASSERTION(aPO, "Pointer is null!");
.
  NS_ASSERTION(aPO, "Pointer is null!");
 
.
 
  PRINT_DEBUG_MSG1("-----------------------------------\n");
.
  PRINT_DEBUG_MSG1("-----------------------------------\n");
  PRINT_DEBUG_MSG3("------ In DV::PrintPage PO: %p (%s)\n", aPO, gFrameTypesSt
r[aPO->mFrameType]);
.
  PRINT_DEBUG_MSG3("------ In DV::PrintPage PO: %p (%s)\n", aPO, gFrameTypesSt
r[aPO->mFrameType]);
 
.
 
  nsresult rv;
.
  if (aPrintSettings != nsnull) {
  nsCOMPtr<nsIPrintOptions> printService = 
.
 
           do_GetService(kPrintOptionsCID, &rv);
.
 
  if (NS_SUCCEEDED(rv) && printService) {
.
 
Skipping to line 2332. 
    PRBool isCancelled;
.
    PRBool isCancelled;
    printService->GetIsCancelled(&isCancelled);
.
    aPrintSettings->GetIsCancelled(&isCancelled);
    // DO NOT allow the print job to be cancelled if it is Print FrameAsIs
.
    // DO NOT allow the print job to be cancelled if it is Print FrameAsIs
    // because it is only printing one page.
.
    // because it is only printing one page.
    if (isCancelled && mPrt->mPrintFrameType != nsIPrintOptions::kFramesAsIs) 
{
.
    if (isCancelled && mPrt->mPrintFrameType != nsIPrintSettings::kFramesAsIs)
 {
      printService->SetIsCancelled(PR_FALSE);
.
      aPrintSettings->SetIsCancelled(PR_FALSE);
      return PR_TRUE;
.
      return PR_TRUE;
    }
.
    }
  }
.
  }
 
.
 
  PRInt32 pageNum;
.
  PRInt32 pageNum;
Skipping to line 2377. 
  }
.
  }
 
.
 
  // NOTE: mPrt->mPrintFrameType gets set to  "kFramesAsIs" when a
.
  // NOTE: mPrt->mPrintFrameType gets set to  "kFramesAsIs" when a
  // plain document contains IFrames, so we need to override that case here
.
  // plain document contains IFrames, so we need to override that case here
  if (mPrt->mPrintListener) {
.
  if (mPrt->mPrintListener) {
    if (mPrt->mPrintFrameType == nsIPrintOptions::kEachFrameSep) {
.
    if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) {
      DoProgressForSeparateFrames();
.
      DoProgressForSeparateFrames();
 
.
 
    } else if (mPrt->mPrintFrameType != nsIPrintOptions::kFramesAsIs || 
.
    } else if (mPrt->mPrintFrameType != nsIPrintSettings::kFramesAsIs || 
               mPrt->mPrintObject->mFrameType == eDoc && aPO == mPrt->mPrintOb
ject) {
.
               mPrt->mPrintObject->mFrameType == eDoc && aPO == mPrt->mPrintOb
ject) {
      // Make sure the Listener gets a "zero" progress at the beginning
.
      // Make sure the Listener gets a "zero" progress at the beginning
      // so it can initialize it's state
.
      // so it can initialize it's state
      if (curPage == 1) {
.
      if (curPage == 1) {
        mPrt->mPrintListener->OnProgressPrinting(0, endPage); 
.
        mPrt->mPrintListener->OnProgressPrinting(0, endPage); 
Skipping to line 2396. 
  // Set Clip when Printing "AsIs" or 
.
  // Set Clip when Printing "AsIs" or 
  // when printing an IFrame for SelectedFrame or EachFrame
.
  // when printing an IFrame for SelectedFrame or EachFrame
  PRBool setClip = PR_FALSE;
.
  PRBool setClip = PR_FALSE;
  switch (mPrt->mPrintFrameType) {
.
  switch (mPrt->mPrintFrameType) {
 
.
 
    case nsIPrintOptions::kFramesAsIs:
.
    case nsIPrintSettings::kFramesAsIs:
      setClip = PR_TRUE;
.
      setClip = PR_TRUE;
      break;
.
      break;
 
.
 
    case nsIPrintOptions::kSelectedFrame:
.
    case nsIPrintSettings::kSelectedFrame:
      if (aPO->mPrintAsIs) {
.
      if (aPO->mPrintAsIs) {
        if (aPO->mFrameType == eIFrame) {
.
        if (aPO->mFrameType == eIFrame) {
          setClip = aPO != mPrt->mSelectedPO;
.
          setClip = aPO != mPrt->mSelectedPO;
        }
.
        }
      }
.
      }
Skipping to line 2412. 
 
.
 
    case nsIPrintOptions::kEachFrameSep:
.
    case nsIPrintSettings::kEachFrameSep:
      if (aPO->mPrintAsIs) {
.
      if (aPO->mPrintAsIs) {
        if (aPO->mFrameType == eIFrame) {
.
        if (aPO->mFrameType == eIFrame) {
          setClip = PR_TRUE;
.
          setClip = PR_TRUE;
        }
.
        }
      }
.
      }
Skipping to line 2426. 
 
.
 
  // Print the Page
.
  // Print the Page
  // if a print job was cancelled externally, an EndPage or BeginPage may
.
  // if a print job was cancelled externally, an EndPage or BeginPage may
  // fail and the failure is passed back here.
.
  // fail and the failure is passed back here.
  // Returning PR_TRUE means we are done printing.
.
  // Returning PR_TRUE means we are done printing.
  if (NS_FAILED(mPageSeqFrame->PrintNextPage(aPresContext, aPrintOptions))) {
.
  if (NS_FAILED(mPageSeqFrame->PrintNextPage(aPresContext))) {
    return PR_TRUE;
.
    return PR_TRUE;
  }                
.
  }                
 
.
 
  // Now see if any of the SubDocs are on this page
.
  // Now see if any of the SubDocs are on this page
  if (aPO->mPrintAsIs) {
.
  if (aPO->mPrintAsIs) {
Skipping to line 2460. 
      mPageSeqFrame->DoPageEnd(aPresContext);
.
      mPageSeqFrame->DoPageEnd(aPresContext);
    }
.
    }
 
.
 
    // XXX this is because PrintAsIs for FrameSets reflows to two pages
.
    // XXX this is because PrintAsIs for FrameSets reflows to two pages
    // not sure why, but this needs to be fixed.
.
    // not sure why, but this needs to be fixed.
    if (aPO->mFrameType == eFrameSet && mPrt->mPrintFrameType == nsIPrintOptio
ns::kFramesAsIs) {
.
    if (aPO->mFrameType == eFrameSet && mPrt->mPrintFrameType == nsIPrintSetti
ngs::kFramesAsIs) {
      return PR_TRUE;
.
      return PR_TRUE;
    }
.
    }
  }
.
  }
 
.
 
  return donePrinting;
.
  return donePrinting;
Skipping to line 2807. 
 
.
 
  if (aPO->mFrameType == eFrame) {
.
  if (aPO->mFrameType == eFrame) {
    if (aDoingSetClip) {
.
    if (aDoingSetClip) {
      aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mClipRect.width, aPO->mC
lipRect.height);
.
      aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mClipRect.width, aPO->mC
lipRect.height);
      clipRect = aPO->mClipRect;
.
      clipRect = aPO->mClipRect;
    } else if (mPrt->mPrintFrameType == nsIPrintOptions::kFramesAsIs) {
.
    } else if (mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs) {
      aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mRect.width, aPO->mRect.
height);
.
      aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mRect.width, aPO->mRect.
height);
      clipRect = aPO->mClipRect;
.
      clipRect = aPO->mClipRect;
      doClip = PR_TRUE;
.
      doClip = PR_TRUE;
    }
.
    }
 
.
 
Skipping to line 2820. 
    if (aDoingSetClip) {
.
    if (aDoingSetClip) {
      aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mClipRect.width, aPO->mC
lipRect.height);
.
      aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mClipRect.width, aPO->mC
lipRect.height);
      clipRect = aPO->mClipRect;
.
      clipRect = aPO->mClipRect;
    } else {
.
    } else {
 
.
 
      if (mPrt->mPrintFrameType == nsIPrintOptions::kSelectedFrame) {
.
      if (mPrt->mPrintFrameType == nsIPrintSettings::kSelectedFrame) {
        if (aPO->mParent && aPO->mParent == mPrt->mSelectedPO) {
.
        if (aPO->mParent && aPO->mParent == mPrt->mSelectedPO) {
          aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mRect.width, aPO->mR
ect.height);
.
          aPO->mClipRect.SetRect(aOffsetX, aOffsetY, aPO->mRect.width, aPO->mR
ect.height);
          clipRect = aPO->mClipRect;
.
          clipRect = aPO->mClipRect;
          doClip = PR_TRUE;
.
          doClip = PR_TRUE;
        }
.
        }
Skipping to line 2893. 
 
.
 
  // create the PresContext
.
  // create the PresContext
  PRBool containerIsSet = PR_FALSE;
.
  PRBool containerIsSet = PR_FALSE;
  nsresult rv;
.
  nsresult rv;
  if (mIsCreatingPrintPreview) {
.
  if (mIsCreatingPrintPreview) {
    aPO->mPresContext = do_CreateInstance(kPrintPreviewContextCID,&rv);
 
.
    nsCOMPtr<nsIPrintContext> printPreviewCon = do_CreateInstance(kPrintPrevie
wContextCID,&rv);
    if (NS_FAILED(rv)) {
.
    if (NS_FAILED(rv)) {
      return rv;
.
      return rv;
    }
.
    }
 
.
    printPreviewCon->SetPrintSettings(mPrt->mPrintSettings);
 
.
    aPO->mPresContext = do_QueryInterface(printPreviewCon);
  } else {
.
  } else {
    nsCOMPtr<nsIPrintContext> printcon(do_CreateInstance(kPrintContextCID, &rv
));
.
    nsCOMPtr<nsIPrintContext> printcon(do_CreateInstance(kPrintContextCID, &rv
));
    if (NS_FAILED(rv)) {
.
    if (NS_FAILED(rv)) {
      return rv;
.
      return rv;
    } else {
.
    } else {
 
.
      printcon->SetPrintSettings(mPrt->mPrintSettings);
Skipping to line 2910. 
      aPO->mPresContext = do_QueryInterface(printcon);
.
      aPO->mPresContext = do_QueryInterface(printcon);
      if (NS_FAILED(rv)) {
.
 
        return rv;
.
 
      }
.
 
    }
.
    }
  }
.
  }
 
.
 
  // init it with the DC
.
  // init it with the DC
  (aPO->mPresContext)->Init(mPrt->mPrintDocDC);
.
  (aPO->mPresContext)->Init(mPrt->mPrintDocDC);
Skipping to line 2952. 
  // OK,  so ther eis a selection, we will print the entire selection 
.
  // OK,  so ther eis a selection, we will print the entire selection 
  // on one page and then crop the page.
.
  // on one page and then crop the page.
  // This means you can never print any selection that is longer than one page
.
  // This means you can never print any selection that is longer than one page
  // put it keeps it from page breaking in the middle of your print of the sel
ection
.
  // put it keeps it from page breaking in the middle of your print of the sel
ection
  // (see also nsSimplePageSequence.cpp)
.
  // (see also nsSimplePageSequence.cpp)
  PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages;
.
  PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages;
  nsCOMPtr<nsIPrintOptions> printService = 
.
  if (mPrt->mPrintSettings != nsnull) {
           do_GetService(kPrintOptionsCID, &rv);
.
    mPrt->mPrintSettings->GetPrintRange(&printRangeType);
  if (NS_SUCCEEDED(rv)) {
.
 
    printService->GetPrintRange(&printRangeType);
.
 
  }
.
  }
 
.
 
 
.
 
  if (printRangeType == nsIPrintOptions::kRangeSelection && IsThereARangeSelec
tion(domWinIntl)) {
.
  if (printRangeType == nsIPrintSettings::kRangeSelection && IsThereARangeSele
ction(domWinIntl)) {
    height = 0x0FFFFFFF;
.
    height = 0x0FFFFFFF;
  }
.
  }
  nsRect tbounds = nsRect(0, 0, width, height);
.
  nsRect tbounds = nsRect(0, 0, width, height);
 
.
 
  // Create a child window of the parent that is our "root view/window"
.
  // Create a child window of the parent that is our "root view/window"
Skipping to line 3037. 
  }
.
  }
 
.
 
  aPO->mPresShell->BeginObservingDocument();
.
  aPO->mPresShell->BeginObservingDocument();
 
.
 
  nsMargin margin(0,0,0,0);
.
  nsMargin margin(0,0,0,0);
  if (printService) {
.
  mPrt->mPrintSettings->GetMarginInTwips(margin);
    printService->GetMarginInTwips(margin);
.
 
  }
.
 
 
.
 
  // initialize it with the default/generic case
.
  // initialize it with the default/generic case
  nsRect adjRect(aPO->mRect.x != 0?margin.left:0, aPO->mRect.y != 0?margin.top
:0, width, height);
.
  nsRect adjRect(aPO->mRect.x != 0?margin.left:0, aPO->mRect.y != 0?margin.top
:0, width, height);
 
.
 
  // XXX This is an arbitray height, 
.
  // XXX This is an arbitray height, 
Skipping to line 3049. 
  // basically, we want to reflow a single page that is large 
.
  // basically, we want to reflow a single page that is large 
  // enough to fit any atomic object like an IFrame
.
  // enough to fit any atomic object like an IFrame
  const PRInt32 kFivePagesHigh = 5;
.
  const PRInt32 kFivePagesHigh = 5;
 
.
 
  // now, change the value for special cases
.
  // now, change the value for special cases
  if (mPrt->mPrintFrameType == nsIPrintOptions::kEachFrameSep) {
.
  if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) {
    if (aPO->mFrameType == eFrame) {
.
    if (aPO->mFrameType == eFrame) {
      adjRect.SetRect(0, 0, width, height);
.
      adjRect.SetRect(0, 0, width, height);
    } else if (aPO->mFrameType == eIFrame) {
.
    } else if (aPO->mFrameType == eIFrame) {
      height = pageHeight*kFivePagesHigh;
.
      height = pageHeight*kFivePagesHigh;
      adjRect.SetRect(aPO->mRect.x != 0?margin.left:0, aPO->mRect.y != 0?margi
n.top:0, width, height);
.
      adjRect.SetRect(aPO->mRect.x != 0?margin.left:0, aPO->mRect.y != 0?margi
n.top:0, width, height);
Skipping to line 3061. 
 
.
 
  } else if (mPrt->mPrintFrameType == nsIPrintOptions::kSelectedFrame) {
.
  } else if (mPrt->mPrintFrameType == nsIPrintSettings::kSelectedFrame) {
    if (aPO->mFrameType == eFrame) {
.
    if (aPO->mFrameType == eFrame) {
      adjRect.SetRect(0, 0, width, height);
.
      adjRect.SetRect(0, 0, width, height);
    } else if (aPO->mFrameType == eIFrame) {
.
    } else if (aPO->mFrameType == eIFrame) {
      if (aPO == mPrt->mSelectedPO) {
.
      if (aPO == mPrt->mSelectedPO) {
        adjRect.x = 0;
.
        adjRect.x = 0;
Skipping to line 3224. 
{
.
{
  // NOTE: All POs have been "turned off" for printing
.
  // NOTE: All POs have been "turned off" for printing
  // this is where we decided which POs get printed.
.
  // this is where we decided which POs get printed.
  mPrt->mSelectedPO = nsnull;
.
  mPrt->mSelectedPO = nsnull;
 
.
 
  nsresult rv;
.
  if (mPrt->mPrintSettings == nsnull) {
  nsCOMPtr<nsIPrintOptions> printService = 
.
    return NS_ERROR_FAILURE;
           do_GetService(kPrintOptionsCID, &rv);
.
 
  if (NS_FAILED(rv)) {
.
 
    return rv;
.
 
  }
.
  }
 
.
 
  mPrt->mPrintFrameType = nsIPrintOptions::kNoFrames; 
.
  mPrt->mPrintFrameType = nsIPrintSettings::kNoFrames; 
  printService->GetPrintFrameType(&mPrt->mPrintFrameType);
.
  mPrt->mPrintSettings->GetPrintFrameType(&mPrt->mPrintFrameType);
 
.
 
  PRInt16 printHowEnable = nsIPrintOptions::kFrameEnableNone; 
.
  PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; 
  printService->GetHowToEnableFrameUI(&printHowEnable);
.
  mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable);
 
.
 
  PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages;
.
  PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages;
  printService->GetPrintRange(&printRangeType);
.
  mPrt->mPrintSettings->GetPrintRange(&printRangeType);
 
.
 
  PRINT_DEBUG_MSG1("\n********* DocumentViewerImpl::EnablePOsForPrinting *****
****\n");
.
  PRINT_DEBUG_MSG1("\n********* DocumentViewerImpl::EnablePOsForPrinting *****
****\n");
  PRINT_DEBUG_MSG2("PrintFrameType:     %s \n", gPrintFrameTypeStr[mPrt->mPrin
tFrameType]);
.
  PRINT_DEBUG_MSG2("PrintFrameType:     %s \n", gPrintFrameTypeStr[mPrt->mPrin
tFrameType]);
  PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowE
nable]);
.
  PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[printHowE
nable]);
  PRINT_DEBUG_MSG2("PrintRange:         %s \n", gPrintRangeStr[printRangeType]
);
.
  PRINT_DEBUG_MSG2("PrintRange:         %s \n", gPrintRangeStr[printRangeType]
);
Skipping to line 3247. 
  PRINT_DEBUG_FLUSH
.
  PRINT_DEBUG_FLUSH
 
.
 
  // ***** This is the ultimate override *****
.
  // ***** This is the ultimate override *****
  // if we are printing the selection (either an IFrame or selection range)
.
  // if we are printing the selection (either an IFrame or selection range)
  // then set the mPrintFrameType as if it were the selected frame
.
  // then set the mPrintFrameType as if it were the selected frame
  if (printRangeType == nsIPrintOptions::kRangeSelection) {
.
  if (printRangeType == nsIPrintSettings::kRangeSelection) {
    mPrt->mPrintFrameType = nsIPrintOptions::kSelectedFrame;
.
    mPrt->mPrintFrameType = nsIPrintSettings::kSelectedFrame;
    printHowEnable        = nsIPrintOptions::kFrameEnableNone; 
.
    printHowEnable        = nsIPrintSettings::kFrameEnableNone; 
  }
.
  }
 
.
 
  // This tells us that the "Frame" UI has turned off,
.
  // This tells us that the "Frame" UI has turned off,
  // so therefore there are no FrameSets/Frames/IFrames to be printed
.
  // so therefore there are no FrameSets/Frames/IFrames to be printed
  //
.
  //
Skipping to line 3261. 
  // but the document could contain an IFrame
.
  // but the document could contain an IFrame
  if (printHowEnable == nsIPrintOptions::kFrameEnableNone) {
.
  if (printHowEnable == nsIPrintSettings::kFrameEnableNone) {
 
.
 
    // Print all the pages or a sub range of pages
.
    // Print all the pages or a sub range of pages
    if (printRangeType == nsIPrintOptions::kRangeAllPages ||
.
    if (printRangeType == nsIPrintSettings::kRangeAllPages ||
        printRangeType == nsIPrintOptions::kRangeSpecifiedPageRange) {
.
        printRangeType == nsIPrintSettings::kRangeSpecifiedPageRange) {
      SetPrintPO(mPrt->mPrintObject, PR_TRUE);
.
      SetPrintPO(mPrt->mPrintObject, PR_TRUE);
 
.
 
      // Set the children so they are PrinAsIs
.
      // Set the children so they are PrinAsIs
      // In this case, the children are probably IFrames
.
      // In this case, the children are probably IFrames
      if (mPrt->mPrintObject->mKids.Count() > 0) {
.
      if (mPrt->mPrintObject->mKids.Count() > 0) {
Skipping to line 3274. 
          NS_ASSERTION(po, "PrintObject can't be null!");
.
          NS_ASSERTION(po, "PrintObject can't be null!");
          SetPrintAsIs(po);
.
          SetPrintAsIs(po);
        }
.
        }
 
.
 
        // ***** Another override *****
.
        // ***** Another override *****
        mPrt->mPrintFrameType = nsIPrintOptions::kFramesAsIs;
.
        mPrt->mPrintFrameType = nsIPrintSettings::kFramesAsIs;
      }
.
      }
      PRINT_DEBUG_MSG2("PrintFrameType:     %s \n", gPrintFrameTypeStr[mPrt->m
PrintFrameType]);
.
      PRINT_DEBUG_MSG2("PrintFrameType:     %s \n", gPrintFrameTypeStr[mPrt->m
PrintFrameType]);
      PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[print
HowEnable]);
.
      PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[print
HowEnable]);
      PRINT_DEBUG_MSG2("PrintRange:         %s \n", gPrintRangeStr[printRangeT
ype]);
.
      PRINT_DEBUG_MSG2("PrintRange:         %s \n", gPrintRangeStr[printRangeT
ype]);
      return NS_OK;
.
      return NS_OK;
Skipping to line 3286. 
    
.
    
    // This means we are either printed a selected IFrame or
.
    // This means we are either printed a selected IFrame or
    // we are printing the current selection
.
    // we are printing the current selection
    if (printRangeType == nsIPrintOptions::kRangeSelection) {
.
    if (printRangeType == nsIPrintSettings::kRangeSelection) {
 
.
 
      // If the currentFocusDOMWin can'r be null if something is selected
.
      // If the currentFocusDOMWin can'r be null if something is selected
      if (mPrt->mCurrentFocusWin) {
.
      if (mPrt->mCurrentFocusWin) {
        // Find the selected IFrame
.
        // Find the selected IFrame
        PrintObject * po = FindPrintObjectByDOMWin(mPrt->mPrintObject, mPrt->m
CurrentFocusWin);
.
        PrintObject * po = FindPrintObjectByDOMWin(mPrt->mPrintObject, mPrt->m
CurrentFocusWin);
Skipping to line 3307. 
          //
.
          //
          // XXX this is sort of a hack right here to make the page 
.
          // XXX this is sort of a hack right here to make the page 
          // not try to reposition itself when printing selection
.
          // not try to reposition itself when printing selection
          nsCOMPtr<nsIDOMWindowInternal> domWin = getter_AddRefs(GetDOMWinForW
ebShell(po->mWebShell));
.
          nsCOMPtr<nsIDOMWindowInternal> domWin = getter_AddRefs(GetDOMWinForW
ebShell(po->mWebShell));
          if (!IsThereARangeSelection(domWin)) {
.
          if (!IsThereARangeSelection(domWin)) {
            printRangeType = nsIPrintOptions::kRangeAllPages;
.
            printRangeType = nsIPrintSettings::kRangeAllPages;
            printService->SetPrintRange(printRangeType);
.
            mPrt->mPrintSettings->SetPrintRange(printRangeType);
          }
.
          }
          PRINT_DEBUG_MSG2("PrintFrameType:     %s \n", gPrintFrameTypeStr[mPr
t->mPrintFrameType]);
.
          PRINT_DEBUG_MSG2("PrintFrameType:     %s \n", gPrintFrameTypeStr[mPr
t->mPrintFrameType]);
          PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[p
rintHowEnable]);
.
          PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[p
rintHowEnable]);
          PRINT_DEBUG_MSG2("PrintRange:         %s \n", gPrintRangeStr[printRa
ngeType]);
.
          PRINT_DEBUG_MSG2("PrintRange:         %s \n", gPrintRangeStr[printRa
ngeType]);
          return NS_OK;
.
          return NS_OK;
Skipping to line 3321. 
        for (PRInt32 i=0;i<mPrt->mPrintDocList->Count();i++) {
.
        for (PRInt32 i=0;i<mPrt->mPrintDocList->Count();i++) {
          PrintObject* po = (PrintObject*)mPrt->mPrintDocList->ElementAt(i);
.
          PrintObject* po = (PrintObject*)mPrt->mPrintDocList->ElementAt(i);
          NS_ASSERTION(po, "PrintObject can't be null!");
.
          NS_ASSERTION(po, "PrintObject can't be null!");
          nsCOMPtr<nsIDOMWindowInternal> domWin = getter_AddRefs(GetDOMWinForW
ebShell(po->mWebShell));
.
          nsCOMPtr<nsIDOMWindowInternal> domWin = getter_AddRefs(GetDOMWinForW
ebShell(po->mWebShell));
          if (IsThereARangeSelection(domWin)) {
.
          if (IsThereARangeSelection(domWin)) {
 
.
            mPrt->mCurrentFocusWin = domWin;
            SetPrintPO(po, PR_TRUE);
.
            SetPrintPO(po, PR_TRUE);
            break;
.
            break;
          }
.
          }
        }
.
        }
        return NS_OK;
.
        return NS_OK;
Skipping to line 3333. 
    }
.
    }
  }
.
  }
 
.
 
  // check to see if there is a selection when a FrameSet is present
.
  // check to see if there is a selection when a FrameSet is present
  if (printRangeType == nsIPrintOptions::kRangeSelection) {
.
  if (printRangeType == nsIPrintSettings::kRangeSelection) {
    // If the currentFocusDOMWin can'r be null if something is selected
.
    // If the currentFocusDOMWin can'r be null if something is selected
    if (mPrt->mCurrentFocusWin) {
.
    if (mPrt->mCurrentFocusWin) {
      // Find the selected IFrame
.
      // Find the selected IFrame
      PrintObject * po = FindPrintObjectByDOMWin(mPrt->mPrintObject, mPrt->mCu
rrentFocusWin);
.
      PrintObject * po = FindPrintObjectByDOMWin(mPrt->mPrintObject, mPrt->mCu
rrentFocusWin);
      if (po != nsnull) {
.
      if (po != nsnull) {
Skipping to line 3354. 
        //
.
        //
        // XXX this is sort of a hack right here to make the page 
.
        // XXX this is sort of a hack right here to make the page 
        // not try to reposition itself when printing selection
.
        // not try to reposition itself when printing selection
        nsCOMPtr<nsIDOMWindowInternal> domWin = getter_AddRefs(GetDOMWinForWeb
Shell(po->mWebShell));
.
        nsCOMPtr<nsIDOMWindowInternal> domWin = getter_AddRefs(GetDOMWinForWeb
Shell(po->mWebShell));
        if (!IsThereARangeSelection(domWin)) {
.
        if (!IsThereARangeSelection(domWin)) {
          printRangeType = nsIPrintOptions::kRangeAllPages;
.
          printRangeType = nsIPrintSettings::kRangeAllPages;
          printService->SetPrintRange(printRangeType);
.
          mPrt->mPrintSettings->SetPrintRange(printRangeType);
        }
.
        }
        PRINT_DEBUG_MSG2("PrintFrameType:     %s \n", gPrintFrameTypeStr[mPrt-
>mPrintFrameType]);
.
        PRINT_DEBUG_MSG2("PrintFrameType:     %s \n", gPrintFrameTypeStr[mPrt-
>mPrintFrameType]);
        PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[pri
ntHowEnable]);
.
        PRINT_DEBUG_MSG2("HowToEnableFrameUI: %s \n", gFrameHowToEnableStr[pri
ntHowEnable]);
        PRINT_DEBUG_MSG2("PrintRange:         %s \n", gPrintRangeStr[printRang
eType]);
.
        PRINT_DEBUG_MSG2("PrintRange:         %s \n", gPrintRangeStr[printRang
eType]);
        return NS_OK;
.
        return NS_OK;
Skipping to line 3367. 
    }
.
    }
  }
.
  }
 
.
 
  // If we are printing "AsIs" then sets all the POs to be printed as is
.
  // If we are printing "AsIs" then sets all the POs to be printed as is
  if (mPrt->mPrintFrameType == nsIPrintOptions::kFramesAsIs) {
.
  if (mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs) {
    SetPrintAsIs(mPrt->mPrintObject);
.
    SetPrintAsIs(mPrt->mPrintObject);
    SetPrintPO(mPrt->mPrintObject, PR_TRUE);
.
    SetPrintPO(mPrt->mPrintObject, PR_TRUE);
    return NS_OK;
.
    return NS_OK;
  }
.
  }
 
.
 
Skipping to line 3378. 
  // find that PO for that selected DOMWin and set it all of its
.
  // find that PO for that selected DOMWin and set it all of its
  // children to be printed
.
  // children to be printed
  if (mPrt->mPrintFrameType == nsIPrintOptions::kSelectedFrame) {
.
  if (mPrt->mPrintFrameType == nsIPrintSettings::kSelectedFrame) {
 
.
 
    if ((mPrt->mIsParentAFrameSet && mPrt->mCurrentFocusWin) || mPrt->mIsIFram
eSelected) {
.
    if ((mPrt->mIsParentAFrameSet && mPrt->mCurrentFocusWin) || mPrt->mIsIFram
eSelected) {
      PrintObject * po = FindPrintObjectByDOMWin(mPrt->mPrintObject, mPrt->mCu
rrentFocusWin);
.
      PrintObject * po = FindPrintObjectByDOMWin(mPrt->mPrintObject, mPrt->mCu
rrentFocusWin);
      if (po != nsnull) {
.
      if (po != nsnull) {
        mPrt->mSelectedPO = po;
.
        mPrt->mSelectedPO = po;
Skipping to line 3398. 
    return NS_OK;
.
    return NS_OK;
  } 
.
  } 
  
.
  
  // If we are print each subdoc separately, 
.
  // If we are print each subdoc separately, 
  // then don't print any of the FraneSet Docs 
.
  // then don't print any of the FraneSet Docs 
  if (mPrt->mPrintFrameType == nsIPrintOptions::kEachFrameSep) {
.
  if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) {
    SetPrintPO(mPrt->mPrintObject, PR_TRUE);
.
    SetPrintPO(mPrt->mPrintObject, PR_TRUE);
    PRInt32 cnt = mPrt->mPrintDocList->Count();
.
    PRInt32 cnt = mPrt->mPrintDocList->Count();
    for (PRInt32 i=0;i<cnt;i++) {
.
    for (PRInt32 i=0;i<cnt;i++) {
      PrintObject* po = (PrintObject*)mPrt->mPrintDocList->ElementAt(i);
.
      PrintObject* po = (PrintObject*)mPrt->mPrintDocList->ElementAt(i);
      NS_ASSERTION(po, "PrintObject can't be null!");
.
      NS_ASSERTION(po, "PrintObject can't be null!");
Skipping to line 3502. 
  if (mIsDoingPrinting) {
.
  if (mIsDoingPrinting) {
    // BeginDocument may pass back a FAILURE code
.
    // BeginDocument may pass back a FAILURE code
    // i.e. On Windows, if you are printing to a file and hit "Cancel" 
.
    // i.e. On Windows, if you are printing to a file and hit "Cancel" 
    //      to the "File Name" dialog, this comes back as an error
.
    //      to the "File Name" dialog, this comes back as an error
    // Don't start printing when regression test are executed  
.
    // Don't start printing when regression test are executed  
    rv = mPrt->mFilePointer ? NS_OK: mPrt->mPrintDC->BeginDocument(docTitleStr
);
.
    rv = mPrt->mDebugFilePtr ? NS_OK: mPrt->mPrintDC->BeginDocument(docTitleSt
r);
    PRINT_DEBUG_MSG1("****************** Begin Document **********************
**\n");
.
    PRINT_DEBUG_MSG1("****************** Begin Document **********************
**\n");
 
.
 
    if (docTitleStr != nsnull) {
.
    if (docTitleStr != nsnull) {
      nsMemory::Free(docTitleStr);
.
      nsMemory::Free(docTitleStr);
    }
.
    }
Skipping to line 3541. 
  nsCOMPtr<nsIWebShell> webContainer(do_QueryInterface(mContainer));
.
  nsCOMPtr<nsIWebShell> webContainer(do_QueryInterface(mContainer));
  NS_ASSERTION(webShell, "The WebShell can't be NULL!");
.
  NS_ASSERTION(webShell, "The WebShell can't be NULL!");
 
.
 
  if (webShell != nsnull) {
.
  if (webShell != nsnull) {
 
.
 
    PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages;
.
    PRInt16 printRangeType = nsIPrintSettings::kRangeAllPages;
    nsresult rv;
.
    nsresult rv;
    nsCOMPtr<nsIPrintOptions> printService = 
.
    if (mPrt->mPrintSettings != nsnull) {
             do_GetService(kPrintOptionsCID, &rv);
.
      mPrt->mPrintSettings->GetPrintRange(&printRangeType);
    if (NS_SUCCEEDED(rv) && printService) {
.
 
      printService->GetPrintRange(&printRangeType);
.
 
    }
.
    }
 
.
 
    // Ask the page sequence frame to print all the pages
.
    // Ask the page sequence frame to print all the pages
    nsIPageSequenceFrame* pageSequence;
.
    nsIPageSequenceFrame* pageSequence;
    poPresShell->GetPageSequenceFrame(&pageSequence);
.
    poPresShell->GetPageSequenceFrame(&pageSequence);
Skipping to line 3564. 
    PRBool doAddInParentsOffset   = PR_TRUE;
.
    PRBool doAddInParentsOffset   = PR_TRUE;
    PRBool skipSetTitle           = PR_FALSE;
.
    PRBool skipSetTitle           = PR_FALSE;
 
.
 
    if (aPO->mFrameType == eFrame) {
.
    if (aPO->mFrameType == eFrame) {
      switch (mPrt->mPrintFrameType) {
.
      switch (mPrt->mPrintFrameType) {
      case nsIPrintOptions::kFramesAsIs: 
.
      case nsIPrintSettings::kFramesAsIs: 
          skipAllPageAdjustments = PR_TRUE;
.
          skipAllPageAdjustments = PR_TRUE;
          doOffsetting           = PR_TRUE;
.
          doOffsetting           = PR_TRUE;
          break;
.
          break;
 
.
 
        case nsIPrintOptions::kSelectedFrame:
.
        case nsIPrintSettings::kSelectedFrame:
          if (aPO->mKids.Count() > 0) {
.
          if (aPO->mKids.Count() > 0) {
            skipPageEjectOnly = PR_TRUE;
.
            skipPageEjectOnly = PR_TRUE;
          }
.
          }
          break;
.
          break;
 
.
 
        case nsIPrintOptions::kEachFrameSep:
.
        case nsIPrintSettings::kEachFrameSep:
Skipping to line 3584. 
          break;
.
          break;
      } // switch
.
      } // switch
 
.
 
    } else if (aPO->mFrameType == eIFrame) {
.
    } else if (aPO->mFrameType == eIFrame) {
      switch (mPrt->mPrintFrameType) {
.
      switch (mPrt->mPrintFrameType) {
        case nsIPrintOptions::kFramesAsIs:
.
        case nsIPrintSettings::kFramesAsIs:
          skipAllPageAdjustments = PR_TRUE;
.
          skipAllPageAdjustments = PR_TRUE;
          doOffsetting           = PR_TRUE;
.
          doOffsetting           = PR_TRUE;
          skipSetTitle           = PR_TRUE;
.
          skipSetTitle           = PR_TRUE;
          break;
.
          break;
 
.
 
        case nsIPrintOptions::kSelectedFrame:
.
        case nsIPrintSettings::kSelectedFrame:
Skipping to line 3601. 
          } else {
.
          } else {
            skipPageEjectOnly = aPO->mKids.Count() > 0;
.
            skipPageEjectOnly = aPO->mKids.Count() > 0;
          }
.
          }
          break;
.
          break;
 
.
 
        case nsIPrintOptions::kEachFrameSep:
.
        case nsIPrintSettings::kEachFrameSep:
          skipAllPageAdjustments = PR_TRUE;
.
          skipAllPageAdjustments = PR_TRUE;
          doOffsetting           = PR_TRUE;
.
          doOffsetting           = PR_TRUE;
          doAddInParentsOffset   = aPO->mParent != nsnull && aPO->mParent->mFr
ameType == eIFrame;
.
          doAddInParentsOffset   = aPO->mParent != nsnull && aPO->mParent->mFr
ameType == eIFrame;
          skipSetTitle           = PR_TRUE;
.
          skipSetTitle           = PR_TRUE;
          break;
.
          break;
Skipping to line 3635. 
      if (doOffsetting) {
.
      if (doOffsetting) {
        nscoord x = 0;
.
        nscoord x = 0;
        nscoord y = 0;
.
        nscoord y = 0;
        PrintObject * po = aPO;
.
        PrintObject * po = aPO;
        while (po != nsnull) {
.
        while (po != nsnull) {
          //if (mPrt->mPrintFrameType != nsIPrintOptions::kSelectedFrame || po
 != aPO->mParent) {
.
          //if (mPrt->mPrintFrameType != nsIPrintSettings::kSelectedFrame || p
o != aPO->mParent) {
          PRBool isParent = po == aPO->mParent;
.
          PRBool isParent = po == aPO->mParent;
          if (!isParent || (isParent && doAddInParentsOffset)) {
.
          if (!isParent || (isParent && doAddInParentsOffset)) {
            x += po->mRect.x;
.
            x += po->mRect.x;
            y += po->mRect.y;
.
            y += po->mRect.y;
          }
.
          }
Skipping to line 3651. 
 
.
 
    PRINT_DEBUG_MSG5("*** skipPageEjectOnly: %s  skipAllPageAdjustments: %s  d
oOffsetting: %s  doAddInParentsOffset: %s\n", 
.
    PRINT_DEBUG_MSG5("*** skipPageEjectOnly: %s  skipAllPageAdjustments: %s  d
oOffsetting: %s  doAddInParentsOffset: %s\n", 
                      PRT_YESNO(skipPageEjectOnly), PRT_YESNO(skipAllPageAdjus
tments), 
.
                      PRT_YESNO(skipPageEjectOnly), PRT_YESNO(skipAllPageAdjus
tments), 
                      PRT_YESNO(doOffsetting), PRT_YESNO(doAddInParentsOffset)
);
.
                      PRT_YESNO(doOffsetting), PRT_YESNO(doAddInParentsOffset)
);
 
.
 
    if (nsnull != mPrt->mFilePointer) {
.
    // mPrt->mDebugFilePtr this is onlu non-null when compiled for debugging
 
.
    if (nsnull != mPrt->mDebugFilePtr) {
 
.
#ifdef NS_DEBUG
      // output the regression test
.
      // output the regression test
      nsIFrameDebug* fdbg;
.
      nsIFrameDebug* fdbg;
      nsIFrame* root;
.
      nsIFrame* root;
      poPresShell->GetRootFrame(&root);
.
      poPresShell->GetRootFrame(&root);
 
.
 
Skipping to line 3665. 
        fdbg->DumpRegressionData(poPresContext, mPrt->mFilePointer, 0, PR_TRUE
);
.
        fdbg->DumpRegressionData(poPresContext, mPrt->mDebugFilePtr, 0, PR_TRU
E);
      }
.
      }
      fclose(mPrt->mFilePointer);      
.
      fclose(mPrt->mDebugFilePtr);      
 
.
#endif
    } else {
.
    } else {
      nsIFrame* rootFrame;
.
      nsIFrame* rootFrame;
      poPresShell->GetRootFrame(&rootFrame);
.
      poPresShell->GetRootFrame(&rootFrame);
 
.
 
#if defined(DEBUG_rods) || defined(DEBUG_dconeX)
.
#if defined(DEBUG_rods) || defined(DEBUG_dconeX)
Skipping to line 3679. 
        if (docStr) nsMemory::Free(docStr);
.
        if (docStr) nsMemory::Free(docStr);
        if (urlStr) nsMemory::Free(urlStr);
.
        if (urlStr) nsMemory::Free(urlStr);
      }
.
      }
#endif
.
#endif
 
.
 
      if (printService) {
.
      if (mPrt->mPrintSettings) {
        if (!skipSetTitle) {
.
        if (!skipSetTitle) {
          PRUnichar * docTitleStr;
.
          PRUnichar * docTitleStr;
          PRUnichar * docURLStr;
.
          PRUnichar * docURLStr;
          GetWebShellTitleAndURL(webShell, &docTitleStr, &docURLStr); 
.
          GetWebShellTitleAndURL(webShell, &docTitleStr, &docURLStr); 
 
.
 
Skipping to line 3691. 
            docTitleStr = ToNewUnicode(NS_LITERAL_STRING(""));
.
            docTitleStr = ToNewUnicode(NS_LITERAL_STRING(""));
          }
.
          }
 
.
 
          if (docTitleStr) {
.
          if (docTitleStr) {
            printService->SetTitle(docTitleStr);
.
            mPrt->mPrintSettings->SetTitle(docTitleStr);
            nsMemory::Free(docTitleStr);
.
            nsMemory::Free(docTitleStr);
          }
.
          }
 
.
 
          if (docURLStr) {
.
          if (docURLStr) {
            printService->SetDocURL(docURLStr);
.
            mPrt->mPrintSettings->SetDocURL(docURLStr);
            nsMemory::Free(docURLStr);
.
            nsMemory::Free(docURLStr);
          }
.
          }
        }
.
        }
 
.
 
        if (nsIPrintOptions::kRangeSelection == printRangeType) {
.
        if (nsIPrintSettings::kRangeSelection == printRangeType) {
          poPresContext->SetIsRenderingOnlySelection(PR_TRUE);
.
          poPresContext->SetIsRenderingOnlySelection(PR_TRUE);
          // temporarily creating rendering context
.
          // temporarily creating rendering context
          // which is needed to dinf the selection frames
.
          // which is needed to dinf the selection frames
          nsCOMPtr<nsIRenderingContext> rc;
.
          nsCOMPtr<nsIRenderingContext> rc;
          mPrt->mPrintDocDC->CreateRenderingContext(*getter_AddRefs(rc));
.
          mPrt->mPrintDocDC->CreateRenderingContext(*getter_AddRefs(rc));
Skipping to line 3725. 
 
.
 
          rv = GetPageRangeForSelection(poPresShell, poPresContext, *rc, selec
tionPS, pageSequence, 
.
          rv = GetPageRangeForSelection(poPresShell, poPresContext, *rc, selec
tionPS, pageSequence, 
                                        &startFrame, startPageNum, startRect, 
.
                                        &startFrame, startPageNum, startRect, 
                                        &endFrame, endPageNum, endRect);
.
                                        &endFrame, endPageNum, endRect);
          if (NS_SUCCEEDED(rv)) {
.
          if (NS_SUCCEEDED(rv)) {
            printService->SetStartPageRange(startPageNum);
.
            mPrt->mPrintSettings->SetStartPageRange(startPageNum);
            printService->SetEndPageRange(endPageNum);
.
            mPrt->mPrintSettings->SetEndPageRange(endPageNum);
            nsMargin margin(0,0,0,0);
.
            nsMargin margin(0,0,0,0);
            printService->GetMarginInTwips(margin);
.
            mPrt->mPrintSettings->GetMarginInTwips(margin);
 
.
 
            if (startPageNum == endPageNum) {
.
            if (startPageNum == endPageNum) {
              nsIFrame * seqFrame;
.
              nsIFrame * seqFrame;
              if (NS_FAILED(CallQueryInterface(pageSequence, &seqFrame))) {
.
              if (NS_FAILED(CallQueryInterface(pageSequence, &seqFrame))) {
                mIsDoingPrinting = PR_FALSE;
.
                mIsDoingPrinting = PR_FALSE;
Skipping to line 3774. 
 
.
 
          r.height = srect.height;
.
          r.height = srect.height;
          rootFrame->SetRect(poPresContext, r);
.
          rootFrame->SetRect(poPresContext, r);
 
.
 
          mPageSeqFrame = pageSequence;
.
          mPageSeqFrame = pageSequence;
          mPageSeqFrame->StartPrint(poPresContext, printService);
.
          mPageSeqFrame->StartPrint(poPresContext, mPrt->mPrintSettings);
 
.
 
          if (!aDoSyncPrinting) {
.
          if (!aDoSyncPrinting) {
            // Get the delay time in between the printing of each page
.
            // Get the delay time in between the printing of each page
            // this gives the user more time to press cancel
.
            // this gives the user more time to press cancel
            PRInt32 printPageDelay = 500;
.
            PRInt32 printPageDelay = 500;
            printService->GetPrintPageDelay(&printPageDelay);
.
            mPrt->mPrintSettings->GetPrintPageDelay(&printPageDelay);
Skipping to line 3786. 
 
.
 
            // Schedule Page to Print
.
            // Schedule Page to Print
            PRINT_DEBUG_MSG3("Scheduling Print of PO: %p (%s) \n", aPO, gFrame
TypesStr[aPO->mFrameType]);
.
            PRINT_DEBUG_MSG3("Scheduling Print of PO: %p (%s) \n", aPO, gFrame
TypesStr[aPO->mFrameType]);
            StartPagePrintTimer(poPresContext, printService, aPO, printPageDel
ay);
.
            StartPagePrintTimer(poPresContext, mPrt->mPrintSettings, aPO, prin
tPageDelay);
          } else {
.
          } else {
            DoProgressForAsIsFrames();
.
            DoProgressForAsIsFrames();
            // Print the page synchronously
.
            // Print the page synchronously
            PRINT_DEBUG_MSG3("Async Print of PO: %p (%s) \n", aPO, gFrameTypes
Str[aPO->mFrameType]);
.
            PRINT_DEBUG_MSG3("Async Print of PO: %p (%s) \n", aPO, gFrameTypes
Str[aPO->mFrameType]);
            aDonePrinting = PrintPage(poPresContext, printService, aPO);
 
.
            aDonePrinting = PrintPage(poPresContext, mPrt->mPrintSettings, aPO
);
          }
.
          }
        }
.
        }
      } else {
.
      } else {
        // not sure what to do here!
.
        // not sure what to do here!
        mIsDoingPrinting = PR_FALSE;
.
        mIsDoingPrinting = PR_FALSE;
Skipping to line 3849. 
{
.
{
  if (mPrt->mPrintListener) {
.
  if (mPrt->mPrintListener) {
    // mPrintFrameType is set to kFramesAsIs event though the Doc Type maybe e
Doc
.
    // mPrintFrameType is set to kFramesAsIs event though the Doc Type maybe e
Doc
    // this is done to make the printing of embedded IFrames easier
.
    // this is done to make the printing of embedded IFrames easier
    // NOTE: we don't want to advance the progress in that case, it is down el
sewhere
.
    // NOTE: we don't want to advance the progress in that case, it is down el
sewhere
    if (mPrt->mPrintFrameType == nsIPrintOptions::kFramesAsIs && mPrt->mPrintO
bject->mFrameType != eDoc) {
.
    if (mPrt->mPrintFrameType == nsIPrintSettings::kFramesAsIs && mPrt->mPrint
Object->mFrameType != eDoc) {
      mPrt->mNumDocsPrinted++;
.
      mPrt->mNumDocsPrinted++;
      // notify the listener of printed docs
.
      // notify the listener of printed docs
      if (mPrt->mNumDocsPrinted == 1) {
.
      if (mPrt->mNumDocsPrinted == 1) {
        mPrt->mPrintListener->OnProgressPrinting(0, mPrt->mNumPrintableDocs); 
.
        mPrt->mPrintListener->OnProgressPrinting(0, mPrt->mNumPrintableDocs); 
      }
.
      }
Skipping to line 3865. 
//-------------------------------------------------------
.
//-------------------------------------------------------
void
.
void
DocumentViewerImpl::DoProgressForSeparateFrames()
.
DocumentViewerImpl::DoProgressForSeparateFrames()
{
.
{
  if (mPrt->mPrintListener) {
.
  if (mPrt->mPrintListener) {
    if (mPrt->mPrintFrameType == nsIPrintOptions::kEachFrameSep) {
.
    if (mPrt->mPrintFrameType == nsIPrintSettings::kEachFrameSep) {
      mPrt->mNumPagesPrinted++;
.
      mPrt->mNumPagesPrinted++;
      // notify the listener of printed docs
.
      // notify the listener of printed docs
      if (mPrt->mNumPagesPrinted == 1) {
.
      if (mPrt->mNumPagesPrinted == 1) {
        mPrt->mPrintListener->OnProgressPrinting(0, mPrt->mNumPrintablePages);
 
.
        mPrt->mPrintListener->OnProgressPrinting(0, mPrt->mNumPrintablePages);
 
      }
.
      }
Skipping to line 4706. 
 *
.
 *
 *  For a full and detailed understanding of the issues with 
.
 *  For a full and detailed understanding of the issues with 
 *  PrintPreview: See the design spec that is attached to Bug 107562 
.
 *  PrintPreview: See the design spec that is attached to Bug 107562 
 */
.
 */
NS_IMETHODIMP
.
NS_IMETHODIMP
DocumentViewerImpl::PrintPreview()
.
DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings, 
 
.
                                 nsIPrintListener* aPrintListener, 
 
.
                                 PRBool            aCreateListener)
{
.
{
  nsresult rv = NS_OK;
.
  nsresult rv = NS_OK;
 
.
 
#ifdef NS_PRINT_PREVIEW
.
#ifdef NS_PRINT_PREVIEW
 
.
 
Skipping to line 4741. 
    mIsCreatingPrintPreview = PR_FALSE;
.
    mIsCreatingPrintPreview = PR_FALSE;
    return NS_ERROR_OUT_OF_MEMORY;
.
    return NS_ERROR_OUT_OF_MEMORY;
  }
.
  }
  mIsDoingPrintPreview = PR_TRUE;
.
  mIsDoingPrintPreview = PR_TRUE;
 
.
 
 
.
  // if they don't pass in a PrintSettings, then make one
 
.
  if (aPrintSettings == nsnull) {
 
 
.
    nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &
rv);
 
.
    if (NS_SUCCEEDED(rv) && printService) {
 
 
.
      printService->CreatePrintSettings(getter_AddRefs(mPrt->mPrintSettings));
 
.
    }
 
.
  } else {
 
.
    mPrt->mPrintSettings = aPrintSettings;
 
.
  }
 
 
.
  NS_ASSERTION(mPrt->mPrintSettings, "You can't PrintPreview without a PrintSe
ttings!");
 
.
 
  // Very important! Turn Off scripting
.
  // Very important! Turn Off scripting
  TurnScriptingOn(PR_FALSE);
.
  TurnScriptingOn(PR_FALSE);
 
.
 
  // Get the currently focused window and cache it
.
  // Get the currently focused window and cache it
  // because the Print Dialog will "steal" focus and later when you try
.
  // because the Print Dialog will "steal" focus and later when you try
Skipping to line 4805. 
 
.
 
  DUMP_DOC_LIST("\nAfter Mapping------------------------------------------");
.
  DUMP_DOC_LIST("\nAfter Mapping------------------------------------------");
 
.
 
  // Setup print options for UI
.
  // Setup print options for UI
  rv = NS_ERROR_FAILURE;
.
  rv = NS_ERROR_FAILURE;
  nsCOMPtr<nsIPrintOptions> printService = 
.
  if (mPrt->mPrintSettings != nsnull) {
           do_GetService(kPrintOptionsCID, &rv);
.
 
  if (NS_SUCCEEDED(rv) && printService) {
.
 
    if (mPrt->mIsParentAFrameSet) {
.
    if (mPrt->mIsParentAFrameSet) {
      if (mPrt->mCurrentFocusWin) {
.
      if (mPrt->mCurrentFocusWin) {
        printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAll);
.
        mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEn
ableAll);
      } else {
.
      } else {
        printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAsIsA
ndEach);
.
        mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEn
ableAsIsAndEach);
      }
.
      }
    } else {
.
    } else {
      printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableNone);
 
.
      mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnab
leNone);
    }
.
    }
    // Now determine how to set up the Frame print UI
.
    // Now determine how to set up the Frame print UI
    printService->SetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectio
nRB, isSelection || mPrt->mIsIFrameSelected);
.
    mPrt->mPrintSettings->SetPrintOptions(nsIPrintSettings::kEnableSelectionRB
, isSelection || mPrt->mIsIFrameSelected);
  }
.
  }
 
.
 
#ifdef DEBUG_PRINTING
.
#ifdef DEBUG_PRINTING
  if (printService) {
.
  if (mPrt->mPrintSettings) {
    PRInt16 printHowEnable = nsIPrintOptions::kFrameEnableNone; 
.
    PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; 
    printService->GetHowToEnableFrameUI(&printHowEnable);
.
    mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable);
    PRBool val;
.
    PRBool val;
    printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectio
nRB, &val);
.
    mPrt->mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB
, &val);
 
.
 
    PRINT_DEBUG_MSG1("********* DocumentViewerImpl::Print *********\n");
.
    PRINT_DEBUG_MSG1("********* DocumentViewerImpl::Print *********\n");
    PRINT_DEBUG_MSG2("IsParentAFrameSet:   %s \n", PRT_YESNO(mPrt->mIsParentAF
rameSet));
.
    PRINT_DEBUG_MSG2("IsParentAFrameSet:   %s \n", PRT_YESNO(mPrt->mIsParentAF
rameSet));
    PRINT_DEBUG_MSG2("IsIFrameSelected:    %s \n", PRT_YESNO(mPrt->mIsIFrameSe
lected));
.
    PRINT_DEBUG_MSG2("IsIFrameSelected:    %s \n", PRT_YESNO(mPrt->mIsIFrameSe
lected));
    PRINT_DEBUG_MSG2("Main Doc Frame Type: %s \n", gFrameTypesStr[mPrt->mPrint
Object->mFrameType]);
.
    PRINT_DEBUG_MSG2("Main Doc Frame Type: %s \n", gFrameTypesStr[mPrt->mPrint
Object->mFrameType]);
Skipping to line 4845. 
  nscoord height = NS_INCHES_TO_TWIPS(11.0);
.
  nscoord height = NS_INCHES_TO_TWIPS(11.0);
 
.
 
  nsCOMPtr<nsIDeviceContext> ppDC;
.
  nsCOMPtr<nsIDeviceContext> ppDC;
  nsCOMPtr<nsIDeviceContextSpecFactory> factory = do_CreateInstance(kDeviceCon
textSpecFactoryCID);
.
  nsCOMPtr<nsIDeviceContextSpecFactory> factory = do_CreateInstance(kDeviceCon
textSpecFactoryCID);
  if (factory) {
.
  if (factory) {
 
.
    aPrintSettings->GetPrintSilent(&doSilent);
    nsIDeviceContextSpec *devspec = nsnull;
.
    nsIDeviceContextSpec *devspec = nsnull;
    nsCOMPtr<nsIDeviceContext> dx;
.
    nsCOMPtr<nsIDeviceContext> dx;
    factory->CreateDeviceContextSpec(mWindow, devspec, doSilent);
 
.
    factory->CreateDeviceContextSpec(mWindow, aPrintSettings, devspec, doSilen
t);
    if (nsnull != devspec) {
.
    if (nsnull != devspec) {
      nsresult rv = mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRe
fs(ppDC)); 
.
      nsresult rv = mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRe
fs(ppDC)); 
      if (NS_SUCCEEDED(rv)) {
.
      if (NS_SUCCEEDED(rv)) {
        mDeviceContext->SetAltDevice(ppDC);
.
        mDeviceContext->SetAltDevice(ppDC);
        if (printService) {
.
        if (mPrt->mPrintSettings != nsnull) {
          double scaling;
.
          double scaling;
          printService->GetScaling(&scaling);
.
          mPrt->mPrintSettings->GetScaling(&scaling);
          if (scaling < 1.0) {
.
          if (scaling < 1.0) {
            mDeviceContext->SetCanonicalPixelScale(float(scaling));
.
            mDeviceContext->SetCanonicalPixelScale(float(scaling));
          }
.
          }
        }
.
        }
        ppDC->GetDeviceSurfaceDimensions(width, height);
.
        ppDC->GetDeviceSurfaceDimensions(width, height);
Skipping to line 4867. 
      }
.
      }
    }
.
    }
  }
.
  }
 
.
 
  if (printService && doSilent) {
.
  if (doSilent) {
    //printService->SetPrintRange(nsIPrintOptions::kFramesAsIs);
.
    mPrt->mPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs);
    printService->SetPrintFrameType(nsIPrintOptions::kFramesAsIs);
.
 
  }
.
  }
 
.
 
  mPrt->mPrintDC     = mDeviceContext; // XXX why?
.
  mPrt->mPrintDC = mDeviceContext; // XXX why?
  mPrt->mFilePointer = nsnull;
.
 
 
.
 
  if (mDeviceContext) {
.
  if (mDeviceContext) {
    mDeviceContext->SetUseAltDC(kUseAltDCFor_FONTMETRICS, PR_TRUE);
.
    mDeviceContext->SetUseAltDC(kUseAltDCFor_FONTMETRICS, PR_TRUE);
    mDeviceContext->SetUseAltDC(kUseAltDCFor_CREATE_RC, PR_TRUE);
.
    mDeviceContext->SetUseAltDC(kUseAltDCFor_CREATE_RC, PR_TRUE);
    mDeviceContext->SetUseAltDC(kUseAltDCFor_SURFACE_DIM, PR_TRUE);
.
    mDeviceContext->SetUseAltDC(kUseAltDCFor_SURFACE_DIM, PR_TRUE);
Skipping to line 4916. 
#endif // NS_PRINT_PREVIEW
.
#endif // NS_PRINT_PREVIEW
 
.
 
  return NS_OK;
.
  return NS_OK;
}
.
}
 
.
 
 
.
 
 
.
#ifdef NS_DEBUG
 
.
/** ---------------------------------------------------
 
.
 *  See documentation above in the nsIContentViewerfile class definition
 
.
 *	@update 01/24/00 dwc
 
.
 */
 
.
NS_IMETHODIMP
 
.
DocumentViewerImpl::Print(PRBool            aSilent,
 
.
                          FILE *            aDebugFile, 
 
.
                          nsIPrintSettings* aPrintSettings)
 
.
{
 
.
  mDebugFile = aDebugFile;
 
.
  return Print(aSilent, aPrintSettings, nsnull, PR_FALSE);
 
.
}
 
.
#endif
 
.
 
/** ---------------------------------------------------
.
/** ---------------------------------------------------
 *  See documentation above in the nsIContentViewerfile class definition
.
 *  See documentation above in the nsIContentViewerfile class definition
 *	@update 01/24/00 dwc
.
 *	@update 01/24/00 dwc
 */
.
 */
NS_IMETHODIMP
.
NS_IMETHODIMP
DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrint
Listener)
.
DocumentViewerImpl::Print(PRBool            aSilent,
 
 
.
                          nsIPrintSettings* aPrintSettings,
 
.
                          nsIPrintListener* aPrintListener,
 
.
                          PRBool            aCreateListener)
Skipping to line 4970. 
  if (mPrt == nsnull) {
.
  if (mPrt == nsnull) {
    mIsDoingPrinting = PR_FALSE;
.
    mIsDoingPrinting = PR_FALSE;
    return NS_ERROR_OUT_OF_MEMORY;
.
    return NS_ERROR_OUT_OF_MEMORY;
  }
.
  }
 
.
 
  if (aPrintListener) {
.
 
 
.
  if (aPrintListener != nsnull) {
 
 
.
    NS_ASSERTION(!aCreateListener, "You can't tell it to create a listener and
 provide one at the same time.");
    mPrt->mPrintListener = aPrintListener;
.
    mPrt->mPrintListener = aPrintListener;
 
.
 
 
.
  } else if (aCreateListener) {
 
.
    //CreatePrintListener();
  }
.
  }
 
.
 
 
.
  // if they don't pass in a PrintSettings, then make one
 
.
  // it will have all the default values
 
.
  if (aPrintSettings == nsnull) {
 
 
.
    nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &
rv);
 
.
    if (NS_SUCCEEDED(rv) && printService) {
 
 
.
      printService->CreatePrintSettings(getter_AddRefs(mPrt->mPrintSettings));
 
.
    }
 
.
  } else {
 
.
    mPrt->mPrintSettings = aPrintSettings;
 
.
  }
 
 
.
  NS_ASSERTION(mPrt->mPrintSettings, "You can't Print without a PrintSettings!
");
 
.
  mPrt->mPrintSettings->SetPrintSilent(aSilent);
 
.
  
  // Get the currently focused window and cache it
.
  // Get the currently focused window and cache it
  // because the Print Dialog will "steal" focus and later when you try
.
  // because the Print Dialog will "steal" focus and later when you try
  // to get the currently focused windows it will be NULL
.
  // to get the currently focused windows it will be NULL
  mPrt->mCurrentFocusWin = getter_AddRefs(FindFocusedDOMWindowInternal());
.
  mPrt->mCurrentFocusWin = getter_AddRefs(FindFocusedDOMWindowInternal());
 
.
 
Skipping to line 5037. 
  // Also, check to see if the currently focus webshell 
.
  // Also, check to see if the currently focus webshell 
  // is a child of this webshell
.
  // is a child of this webshell
  mPrt->mIsIFrameSelected = IsThereAnIFrameSelected(webContainer, mPrt->mCurre
ntFocusWin, mPrt->mIsParentAFrameSet);
.
  mPrt->mIsIFrameSelected = IsThereAnIFrameSelected(webContainer, mPrt->mCurre
ntFocusWin, mPrt->mIsParentAFrameSet);
 
.
 
  DUMP_DOC_LIST("\nAfter Mapping------------------------------------------");
.
  DUMP_DOC_LIST("\nAfter Mapping------------------------------------------");
 
.
 
  // Setup print options for UI
.
 
  rv = NS_ERROR_FAILURE;
.
  rv = NS_ERROR_FAILURE;
  nsCOMPtr<nsIPrintOptions> printService = 
.
  // Setup print options for UI
           do_GetService(kPrintOptionsCID, &rv);
.
  if (mPrt->mIsParentAFrameSet) {
  if (NS_SUCCEEDED(rv) && printService) {
.
    if (mPrt->mCurrentFocusWin) {
    if (mPrt->mIsParentAFrameSet) {
 
.
      mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnab
leAll);
      if (mPrt->mCurrentFocusWin) {
.
 
        printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAll);
.
 
 
      } else {
.
 
        printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAsIsA
ndEach);
.
 
 
      }
.
 
    } else {
.
    } else {
      printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableNone);
 
.
      mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnab
leAsIsAndEach);
    }
.
    }
    // Now determine how to set up the Frame print UI
.
  } else {
    printService->SetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectio
nRB, isSelection || mPrt->mIsIFrameSelected);
.
    mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnable
None);
  }
.
  }
 
.
  // Now determine how to set up the Frame print UI
 
 
.
  mPrt->mPrintSettings->SetPrintOptions(nsIPrintSettings::kEnableSelectionRB, 
isSelection || mPrt->mIsIFrameSelected);
 
.
 
#ifdef DEBUG_PRINTING
.
#ifdef DEBUG_PRINTING
  if (printService) {
.
  if (mPrt->mPrintSettings) {
    PRInt16 printHowEnable = nsIPrintOptions::kFrameEnableNone; 
.
    PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; 
    printService->GetHowToEnableFrameUI(&printHowEnable);
.
    mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable);
    PRBool val;
.
    PRBool val;
    printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectio
nRB, &val);
.
    mPrt->mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB
, &val);
 
.
 
    PRINT_DEBUG_MSG1("********* DocumentViewerImpl::Print *********\n");
.
    PRINT_DEBUG_MSG1("********* DocumentViewerImpl::Print *********\n");
    PRINT_DEBUG_MSG2("IsParentAFrameSet:   %s \n", PRT_YESNO(mPrt->mIsParentAF
rameSet));
.
    PRINT_DEBUG_MSG2("IsParentAFrameSet:   %s \n", PRT_YESNO(mPrt->mIsParentAF
rameSet));
    PRINT_DEBUG_MSG2("IsIFrameSelected:    %s \n", PRT_YESNO(mPrt->mIsIFrameSe
lected));
.
    PRINT_DEBUG_MSG2("IsIFrameSelected:    %s \n", PRT_YESNO(mPrt->mIsIFrameSe
lected));
    PRINT_DEBUG_MSG2("Main Doc Frame Type: %s \n", gFrameTypesStr[mPrt->mPrint
Object->mFrameType]);
.
    PRINT_DEBUG_MSG2("Main Doc Frame Type: %s \n", gFrameTypesStr[mPrt->mPrint
Object->mFrameType]);
Skipping to line 5081. 
    printf("PRINT JOB STARTING\n");
.
    printf("PRINT JOB STARTING\n");
#endif
.
#endif
 
.
 
    nsIDeviceContextSpec *devspec = nsnull;
.
    nsIDeviceContextSpec *devspec = nsnull;
    nsCOMPtr<nsIDeviceContext> dx;
.
    nsCOMPtr<nsIDeviceContext> dx;
    mPrt->mPrintDC = nsnull; // XXX why?
.
    mPrt->mPrintDC = nsnull; // XXX why?
    mPrt->mFilePointer = aFile;
.
 
 
.
 
    rv = factory->CreateDeviceContextSpec(mWindow, devspec, aSilent);
.
#ifdef NS_DEBUG
 
.
    mPrt->mDebugFilePtr = mDebugFile;
 
.
#endif
 
.
 
 
.
    PRBool printSilently;
 
.
    mPrt->mPrintSettings->GetPrintSilent(&printSilently);
 
 
.
    rv = factory->CreateDeviceContextSpec(mWindow, mPrt->mPrintSettings, devsp
ec, printSilently);
    if (NS_SUCCEEDED(rv)) {
.
    if (NS_SUCCEEDED(rv)) {
      rv = mPresContext->GetDeviceContext(getter_AddRefs(dx));
.
      rv = mPresContext->GetDeviceContext(getter_AddRefs(dx));
      if (NS_SUCCEEDED(rv))
.
      if (NS_SUCCEEDED(rv))
        rv = dx->GetDeviceContextFor(devspec, *getter_AddRefs(mPrt->mPrintDC))
;
.
        rv = dx->GetDeviceContextFor(devspec, *getter_AddRefs(mPrt->mPrintDC))
;
        if (printService) {
.
        double scaling;
          double scaling;
.
        mPrt->mPrintSettings->GetScaling(&scaling);
          printService->GetScaling(&scaling);
.
        if (scaling < 1.0) {
          if (scaling < 1.0) {
.
          dx->SetCanonicalPixelScale(float(scaling));
            dx->SetCanonicalPixelScale(float(scaling));
.
 
          }
.
 
        }
.
        }
        
.
        
      if (NS_SUCCEEDED(rv)) {
.
      if (NS_SUCCEEDED(rv)) {
        NS_RELEASE(devspec);
.
        NS_RELEASE(devspec);
 
.
 
Skipping to line 5109. 
#ifdef DEBUG_dcone
.
#ifdef DEBUG_dcone
          float   a1,a2;
.
          float   a1,a2;
          PRInt32 i1,i2;
.
          PRInt32 i1,i2;
 
.
 
          printf("CRITICAL PRINTING INFORMATION\n");
.
          printf("CRITICAL PRINTING INFORMATION\n");
          printf("PRESSHELL(%x)  PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n",
.
 
 
              mPrt->mPrintPS, mPrt->mPrintPC,mPrt->mPrintDC,mPrt->mPrintVM,mPr
t->mPrintView);
.
 
 
          
.
 
          // DEVICE CONTEXT INFORMATION from PresContext
.
          // DEVICE CONTEXT INFORMATION from PresContext
          printf("DeviceContext of Presentation Context(%x)\n",dx);
.
          printf("DeviceContext of Presentation Context(%x)\n",dx);
          dx->GetDevUnitsToTwips(a1);
.
          dx->GetDevUnitsToTwips(a1);
          dx->GetTwipsToDevUnits(a2);
.
          dx->GetTwipsToDevUnits(a2);
          printf("    DevToTwips = %f TwipToDev = %f\n",a1,a2);
.
          printf("    DevToTwips = %f TwipToDev = %f\n",a1,a2);
Skipping to line 5151. 
          mPrt->mPrintDC->GetDeviceSurfaceDimensions(i1,i2);
.
          mPrt->mPrintDC->GetDeviceSurfaceDimensions(i1,i2);
          printf("    DeviceDimension w = %d h = %d\n",i1,i2);
.
          printf("    DeviceDimension w = %d h = %d\n",i1,i2);
 
.
 
#endif /* DEBUG_dcone */
.
#endif /* DEBUG_dcone */
 
.
 
          // if there is a frameset and we are printing silently then
.
          // Always check and set the print settings first and then fall back
          // the default must be reset kFramesAsIs
.
          // onto the PrintService if there isn't a PrintSettings
          if (printService && mPrt->mIsParentAFrameSet && aSilent) {
.
          //
            mPrt->mPrintFrameType = nsIPrintOptions::kFramesAsIs; 
.
          // Posiible Usage values:
            printService->SetPrintFrameType(mPrt->mPrintFrameType);
.
          //   nsIPrintSettings::kUseInternalDefault
 
.
          //   nsIPrintSettings::kUseSettingWhenPossible
 
.
          //
 
 
.
          // NOTE: The consts are the same for PrintSettings and PrintSettings
 
 
.
          PRInt16 printFrameTypeUsage = nsIPrintSettings::kUseSettingWhenPossi
ble;
 
.
          mPrt->mPrintSettings->GetPrintFrameTypeUsage(&printFrameTypeUsage);
 
.
 
 
 
.
          // Ok, see if we are going to use our value and override the default
 
 
.
          if (printFrameTypeUsage == nsIPrintSettings::kUseSettingWhenPossible
) {
 
 
.
            // Get the Print Options/Settings PrintFrameType to see what is pr
eferred
 
.
            PRInt16 printFrameType = nsIPrintSettings::kEachFrameSep;
 
.
            mPrt->mPrintSettings->GetPrintFrameType(&printFrameType);
 
.
 
 
.
            // Don't let anybody do something stupid like try to set it to
 
.
            // kNoFrames when we are printing a FrameSet
 
.
            if (printFrameType == nsIPrintSettings::kNoFrames) {
 
.
              mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep;
 
.
              mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType);
 
.
            } else {
 
 
.
              // First find out from the PrinService what options are availabl
e 
 
.
              // to us for Printing FrameSets
 
.
              PRInt16 howToEnableFrameUI;
 
 
.
              mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI)
;
 
.
              if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) {
 
.
                switch (howToEnableFrameUI) {
 
.
                  case nsIPrintSettings::kFrameEnableAll:
 
.
                    mPrt->mPrintFrameType = printFrameType;
 
.
                    break;
 
.
 
 
.
                  case nsIPrintSettings::kFrameEnableAsIsAndEach:
 
.
                    if (printFrameType != nsIPrintSettings::kSelectedFrame) {
 
.
                      mPrt->mPrintFrameType = printFrameType;
 
.
                    } else { // revert back to a good value
 
 
.
                      mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep;
 
.
                    }
 
.
                    break;
 
.
                } // switch
 
 
.
                mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType)
;
 
.
              }
 
.
            }
          }
.
          }
 
.
 
          // Print listener setup...
.
          // Print listener setup...
          if (mPrt != nsnull) {
.
          if (mPrt != nsnull) {
            mPrt->OnStartPrinting();    
.
            mPrt->OnStartPrinting();    
Skipping to line 5207. 
          //
.
          //
          // The mIsPrinting flag is set when the ImageGroup observer is
.
          // The mIsPrinting flag is set when the ImageGroup observer is
          // notified that images must be loaded as a result of the 
.
          // notified that images must be loaded as a result of the 
          // InitialReflow...
.
          // InitialReflow...
          //
.
          //
          if(!mIsPrinting  || (aFile != 0)){
.
          if(!mIsPrinting  || (mPrt->mDebugFilePtr != nsnull)) {
            rv = DocumentReadyForPrinting();
.
            rv = DocumentReadyForPrinting();
#ifdef DEBUG_dcone
.
#ifdef DEBUG_dcone
            printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n");
.
            printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n");
#endif
.
#endif
          } else {
.
          } else {
Skipping to line 6283. 
}
.
}
 
.
 
/*=============== Timer Related Code ======================*/
.
/*=============== Timer Related Code ======================*/
nsresult
.
nsresult
DocumentViewerImpl::StartPagePrintTimer(nsIPresContext * aPresContext, 
.
DocumentViewerImpl::StartPagePrintTimer(nsIPresContext * aPresContext, 
                                        nsIPrintOptions* aPrintOptions,
.
                                        nsIPrintSettings* aPrintSettings,
                                        PrintObject*     aPOect,
.
                                        PrintObject*     aPOect,
                                        PRUint32         aDelay)
.
                                        PRUint32         aDelay)
{
.
{
  nsresult result;
.
  nsresult result;
 
.
 
Skipping to line 6298. 
      return result;
.
      return result;
 
.
 
    ++mDestroyRefCount;
.
    ++mDestroyRefCount;
  }
.
  }
 
.
 
  return mPagePrintTimer->Start(this, aPresContext, aPrintOptions, aPOect, aDe
lay);
.
  return mPagePrintTimer->Start(this, aPresContext, aPrintSettings, aPOect, aD
elay);
}
.
}
 
.