PRINT_DEBUG_MSG2("IsFrameSelected:     %s \n", PRT_YESNO(mPrt->mIsIFrameSelected));
PRINT_DEBUG_MSG2("IsIFrameSelected:    %s \n", PRT_YESNO(mPrt->mIsIFrameSelected));
DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener){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(gCurrentlyPrinting) {    // Beep at the user, let them know we are not ready to print.    nsCOMPtr<nsISound> soundInterface( do_CreateInstance(kSoundCID, &rv) );    if (NS_SUCCEEDED(rv) && (soundInterface != nsnull)){      soundInterface->Beep();    }    return NS_ERROR_FAILURE;  } else {    gCurrentlyPrinting = PR_TRUE;  }  mPrt = new PrintData();  if (mPrt == nsnull) {    gCurrentlyPrinting = 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) {      gCurrentlyPrinting = 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("IsFrameSelected:     %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  nsCOMPtr<nsIDeviceContextSpecFactory> factory =          do_CreateInstance(kDeviceContextSpecFactoryCID);  if (factory) {#ifdef DEBUG_dcone    printf("PRINT JOB STARTING\n");#endif    nsIDeviceContextSpec *devspec = nsnull;    nsCOMPtr<nsIDeviceContext> dx;    mPrt->mPrintDC = nsnull; // XXX why?    mPrt->mFilePointer = aFile;    factory->CreateDeviceContextSpec(mWindow, devspec, aSilent);    if (nsnull != devspec) {      mPresContext->GetDeviceContext(getter_AddRefs(dx));      rv = dx->GetDeviceContextFor(devspec, *getter_AddRefs(mPrt->mPrintDC));       if (NS_SUCCEEDED(rv)) {        NS_RELEASE(devspec);        if(webContainer) {          // load the document and do the initial reflow on the entire document          nsCOMPtr<nsIPrintContext> printcon(do_CreateInstance(kPrintContextCID,&rv));          if (NS_FAILED(rv)) {            gCurrentlyPrinting = PR_FALSE;            return rv;          } else {            mPrt->mPrintPC = do_QueryInterface(printcon, &rv);            if (NS_FAILED(rv)) {              gCurrentlyPrinting = PR_FALSE;              return rv;            }          }                    PRInt32 width, height;          mPrt->mPrintDC->GetDeviceSurfaceDimensions(width,height);          // XXX - Hack Alert          // OK,  so ther eis a selection, we will print the entire selection           // on one page and then crop the 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 selection          if (isSelection) {            //height = 0x0FFFFFFF;          }          mPrt->mPrintPC->Init(mPrt->mPrintDC);          mPrt->mPrintPC->SetContainer(webContainer);          CreateStyleSet(mDocument, getter_AddRefs(mPrt->mPrintSS));          mPrt->mPrintPS = do_CreateInstance(kPresShellCID, &rv);          if(NS_FAILED(rv)){            gCurrentlyPrinting = PR_FALSE;            return rv;          }          mPrt->mPrintVM = do_CreateInstance(kViewManagerCID, &rv);          if(NS_FAILED(rv)) {            gCurrentlyPrinting = PR_FALSE;            return rv;          }          rv = mPrt->mPrintVM->Init(mPrt->mPrintDC);          if(NS_FAILED(rv)) {            gCurrentlyPrinting = PR_FALSE;            return rv;          }          rv = CallCreateInstance(kViewCID, &mPrt->mPrintView);          if(NS_FAILED(rv)) {            gCurrentlyPrinting = PR_FALSE;            return rv;          }          nsRect  tbounds = nsRect(0,0,width,height);          rv = mPrt->mPrintView->Init(mPrt->mPrintVM,tbounds,nsnull);          if(NS_FAILED(rv)) {            gCurrentlyPrinting = PR_FALSE;            return rv;          }          // setup hierarchical relationship in view manager          mPrt->mPrintVM->SetRootView(mPrt->mPrintView);          mPrt->mPrintPS->Init(mDocument,mPrt->mPrintPC,mPrt->mPrintVM,mPrt->mPrintSS);          // Compatability mode must be set in the mPrintPC or the document          // will be printed in "Standard" mode even if it was a "Quirks" doc          nsCompatibility mode;          mPresContext->GetCompatibilityMode(&mode);          mPrt->mPrintPC->SetCompatibilityMode(mode);          mPrt->mPrintPS->InitialReflow(width,height);#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          // 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          }        }      }          } else {      if (mPagePrintTimer) {        mPagePrintTimer->Stop();        NS_RELEASE(mPagePrintTimer);      }      mPrt->OnEndPrinting(NS_ERROR_FAILURE);      delete mPrt;      mPrt = nsnull;      gCurrentlyPrinting = PR_FALSE;      rv = NS_ERROR_FAILURE;    }  }  return rv;}