if (printService && mPrt->mIsParentAFrameSet && aSilent) { mPrt->mPrintFrameType = nsIPrintOptions::kFramesAsIs; printService->SetPrintFrameType(mPrt->mPrintFrameType);
PRInt16 printFrameTypeUsage = nsIPrintSettings::kUseSettingWhenPossible; mPrt->mPrintSettings->GetPrintFrameTypeUsage(&printFrameTypeUsage);   if (printFrameTypeUsage == nsIPrintSettings::kUseSettingWhenPossible) {  PRInt16 printFrameType = nsIPrintSettings::kEachFrameSep; mPrt->mPrintSettings->GetPrintFrameType(&printFrameType);    if (printFrameType == nsIPrintSettings::kNoFrames) { mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); } else {   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 { mPrt->mPrintFrameType = nsIPrintSettings::kEachFrameSep; } break; } mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType); } }
DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener){#ifdef DEBUG_PRINTING  // need for capturing result on each doc and sub-doc that is printed  gDumpFileNameCnt   = 0;  gDumpLOFileNameCnt = 0;#endif  nsresult rv;  // if we are printing another URL, then exit  // the reason we check here is because this method can be called while   // another is still in here (the printing dialog is a good example).  // the only time we can print more than one job at a time is the regression tests  if (mIsDoingPrinting) {    // Let the user know we are not ready to print.    rv = NS_ERROR_NOT_AVAILABLE;    ShowPrintErrorDialog(rv);    return rv;  }    // Let's print ...  mIsDoingPrinting = PR_TRUE;  mPrt = new PrintData();  if (mPrt == nsnull) {    mIsDoingPrinting = PR_FALSE;    return NS_ERROR_OUT_OF_MEMORY;  }  if (aPrintListener) {    mPrt->mPrintListener = aPrintListener;  }  // Get the currently focused window and cache it  // because the Print Dialog will "steal" focus and later when you try  // to get the currently focused windows it will be NULL  mPrt->mCurrentFocusWin = getter_AddRefs(FindFocusedDOMWindowInternal());  // Check to see if there is a "regular" selection  PRBool isSelection = IsThereARangeSelection(mPrt->mCurrentFocusWin);  // Create a list for storing the WebShells that need to be printed  if (mPrt->mPrintDocList == nsnull) {    mPrt->mPrintDocList = new nsVoidArray();    if (mPrt->mPrintDocList == nsnull) {      mIsDoingPrinting = PR_FALSE;      return NS_ERROR_FAILURE;    }  } else {    mPrt->mPrintDocList->Clear();  }  // Get the webshell for this documentviewer  nsCOMPtr<nsIWebShell> webContainer(do_QueryInterface(mContainer));  // Add Root Doc to Tree and List  mPrt->mPrintObject             = new PrintObject;  mPrt->mPrintObject->mWebShell  = webContainer;  mPrt->mPrintDocList->AppendElement(mPrt->mPrintObject);  mPrt->mIsParentAFrameSet = IsParentAFrameSet(webContainer);  mPrt->mPrintObject->mFrameType = mPrt->mIsParentAFrameSet?eFrameSet:eDoc;  // Build the "tree" of PrintObjects  nsCOMPtr<nsIDocShellTreeNode>  parentAsNode(do_QueryInterface(webContainer));  BuildDocTree(parentAsNode, mPrt->mPrintDocList, mPrt->mPrintObject);  // Create the linkage from the suv-docs back to the content element  // in the parent document  MapContentToWebShells(mPrt->mPrintObject, mPrt->mPrintObject);  // Get whether the doc contains a frameset   // Also, check to see if the currently focus webshell   // is a child of this webshell  mPrt->mIsIFrameSelected = IsThereAnIFrameSelected(webContainer, mPrt->mCurrentFocusWin, mPrt->mIsParentAFrameSet);  DUMP_DOC_LIST("\nAfter Mapping------------------------------------------");  // Setup print options for UI  rv = NS_ERROR_FAILURE;  nsCOMPtr<nsIPrintOptions> printService =            do_GetService(kPrintOptionsCID, &rv);  if (NS_SUCCEEDED(rv) && printService) {    if (mPrt->mIsParentAFrameSet) {      if (mPrt->mCurrentFocusWin) {        printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAll);      } else {        printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAsIsAndEach);      }    } else {      printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableNone);    }    // Now determine how to set up the Frame print UI    printService->SetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, isSelection || mPrt->mIsIFrameSelected);  }#ifdef DEBUG_PRINTING  if (printService) {    PRInt16 printHowEnable = nsIPrintOptions::kFrameEnableNone;     printService->GetHowToEnableFrameUI(&printHowEnable);    PRBool val;    printService->GetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, &val);    PRINT_DEBUG_MSG1("********* DocumentViewerImpl::Print *********\n");    PRINT_DEBUG_MSG2("IsParentAFrameSet:   %s \n", PRT_YESNO(mPrt->mIsParentAFrameSet));    PRINT_DEBUG_MSG2("IsIFrameSelected:    %s \n", PRT_YESNO(mPrt->mIsIFrameSelected));    PRINT_DEBUG_MSG2("Main Doc Frame Type: %s \n", gFrameTypesStr[mPrt->mPrintObject->mFrameType]);    PRINT_DEBUG_MSG2("HowToEnableFrameUI:  %s \n", gFrameHowToEnableStr[printHowEnable]);    PRINT_DEBUG_MSG2("EnableSelectionRB:   %s \n", PRT_YESNO(val));    PRINT_DEBUG_MSG1("*********************************************\n");    PRINT_DEBUG_FLUSH  }#endif  /* create factory (incl. create print dialog) */  nsCOMPtr<nsIDeviceContextSpecFactory> factory =          do_CreateInstance(kDeviceContextSpecFactoryCID, &rv);            if (NS_SUCCEEDED(rv)) {#ifdef DEBUG_dcone    printf("PRINT JOB STARTING\n");#endif    nsIDeviceContextSpec *devspec = nsnull;    nsCOMPtr<nsIDeviceContext> dx;    mPrt->mPrintDC = nsnull; // XXX why?    mPrt->mFilePointer = aFile;    rv = factory->CreateDeviceContextSpec(mWindow, devspec, aSilent);    if (NS_SUCCEEDED(rv)) {      rv = mPresContext->GetDeviceContext(getter_AddRefs(dx));      if (NS_SUCCEEDED(rv))        rv = dx->GetDeviceContextFor(devspec, *getter_AddRefs(mPrt->mPrintDC));        if (printService) {          double scaling;          printService->GetScaling(&scaling);          if (scaling < 1.0) {            dx->SetCanonicalPixelScale(float(scaling));          }        }              if (NS_SUCCEEDED(rv)) {        NS_RELEASE(devspec);        if(webContainer) {#ifdef DEBUG_dcone          float   a1,a2;          PRInt32 i1,i2;          printf("CRITICAL PRINTING INFORMATION\n");          printf("PRESSHELL(%x)  PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n",              mPrt->mPrintPS, mPrt->mPrintPC,mPrt->mPrintDC,mPrt->mPrintVM,mPrt->mPrintView);                    // DEVICE CONTEXT INFORMATION from PresContext          printf("DeviceContext of Presentation Context(%x)\n",dx);          dx->GetDevUnitsToTwips(a1);          dx->GetTwipsToDevUnits(a2);          printf("    DevToTwips = %f TwipToDev = %f\n",a1,a2);          dx->GetAppUnitsToDevUnits(a1);          dx->GetDevUnitsToAppUnits(a2);          printf("    AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);          dx->GetCanonicalPixelScale(a1);          printf("    GetCanonicalPixelScale = %f\n",a1);          dx->GetScrollBarDimensions(a1, a2);          printf("    ScrollBar x = %f y = %f\n",a1,a2);          dx->GetZoom(a1);          printf("    Zoom = %f\n",a1);          dx->GetDepth((PRUint32&)i1);          printf("    Depth = %d\n",i1);          dx->GetDeviceSurfaceDimensions(i1,i2);          printf("    DeviceDimension w = %d h = %d\n",i1,i2);          // DEVICE CONTEXT INFORMATION          printf("DeviceContext created for print(%x)\n",mPrt->mPrintDC);          mPrt->mPrintDC->GetDevUnitsToTwips(a1);          mPrt->mPrintDC->GetTwipsToDevUnits(a2);          printf("    DevToTwips = %f TwipToDev = %f\n",a1,a2);          mPrt->mPrintDC->GetAppUnitsToDevUnits(a1);          mPrt->mPrintDC->GetDevUnitsToAppUnits(a2);          printf("    AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);          mPrt->mPrintDC->GetCanonicalPixelScale(a1);          printf("    GetCanonicalPixelScale = %f\n",a1);          mPrt->mPrintDC->GetScrollBarDimensions(a1, a2);          printf("    ScrollBar x = %f y = %f\n",a1,a2);          mPrt->mPrintDC->GetZoom(a1);          printf("    Zoom = %f\n",a1);          mPrt->mPrintDC->GetDepth((PRUint32&)i1);          printf("    Depth = %d\n",i1);          mPrt->mPrintDC->GetDeviceSurfaceDimensions(i1,i2);          printf("    DeviceDimension w = %d h = %d\n",i1,i2);#endif /* DEBUG_dcone */          // if there is a frameset and we are printing silently then          // the default must be reset kFramesAsIs          if (printService && mPrt->mIsParentAFrameSet && aSilent) {            mPrt->mPrintFrameType = nsIPrintOptions::kFramesAsIs;             printService->SetPrintFrameType(mPrt->mPrintFrameType);          }          // Print listener setup...          if (mPrt != nsnull) {            mPrt->OnStartPrinting();              }          //          // The mIsPrinting flag is set when the ImageGroup observer is          // notified that images must be loaded as a result of the           // InitialReflow...          //          if(!mIsPrinting  || (aFile != 0)){            rv = DocumentReadyForPrinting();#ifdef DEBUG_dcone            printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n");#endif          } else {            // use the observer mechanism to finish the printing#ifdef DEBUG_dcone            printf("PRINTING OBSERVER STARTED\n");#endif          }        }      }          }   }    /* cleaup on failure + notify user */  if (NS_FAILED(rv)) {    /* cleanup... */    if (mPagePrintTimer) {      mPagePrintTimer->Stop();      NS_RELEASE(mPagePrintTimer);    }        if (mPrt) {      mPrt->OnEndPrinting(rv);      delete mPrt;      mPrt = nsnull;    }    mIsDoingPrinting = PR_FALSE;    /* cleanup done, let's fire-up an error dialog to notify the user     * what went wrong...      */    if (rv != NS_ERROR_ABORT)      ShowPrintErrorDialog(rv);  }        return rv;}