height = pageHeight*10;
height = pageHeight*kHundredPagesHigh;
DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO){  NS_ASSERTION(aPO, "Pointer is null!");  // Now locate the nsIDocument for the WebShell  nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aPO->mWebShell));  NS_ASSERTION(docShell, "The DocShell can't be NULL!");  nsCOMPtr<nsIPresShell>  wsPresShell;  docShell->GetPresShell(getter_AddRefs(wsPresShell));  NS_ASSERTION(wsPresShell, "The PresShell can't be NULL!");  nsCOMPtr<nsIDocument> document;  wsPresShell->GetDocument(getter_AddRefs(document));  // create the PresContext  nsresult rv;  nsCOMPtr<nsIPrintContext> printcon(do_CreateInstance(kPrintContextCID, &rv));  if (NS_FAILED(rv)) {    return rv;  } else {    rv = printcon->QueryInterface(NS_GET_IID(nsIPresContext), (void**)&aPO->mPresContext);    if (NS_FAILED(rv)) {      return rv;    }  }  // init it with the DC  (aPO->mPresContext)->Init(mPrt->mPrintDocDC);  CreateStyleSet(document, &aPO->mStyleSet);  rv = nsComponentManager::CreateInstance(kPresShellCID,nsnull,                                    NS_GET_IID(nsIPresShell),(void **)&aPO->mPresShell);  if (NS_FAILED(rv)) {    return rv;  }  rv = nsComponentManager::CreateInstance(kViewManagerCID,nsnull,                                    NS_GET_IID(nsIViewManager),(void **)&aPO->mViewManager);  if (NS_FAILED(rv)) {    return rv;  }  rv = aPO->mViewManager->Init(mPrt->mPrintDocDC);  if (NS_FAILED(rv)) {    return rv;  }  PRInt32 pageWidth, pageHeight;  mPrt->mPrintDocDC->GetDeviceSurfaceDimensions(pageWidth, pageHeight);  PRInt32 width, height;  if (aPO->mContent == nsnull || !aPO->mPrintAsIs ||      (aPO->mPrintAsIs && aPO->mParent != nsnull && !aPO->mParent->mPrintAsIs) ||      (aPO->mFrameType == eIFrame && aPO == mPrt->mSelectedPO)) {    width  = pageWidth;    height = pageHeight;  } else {    width  = aPO->mRect.width;    height = aPO->mRect.height;  }  PRINT_DEBUG_MSG5("In DV::ReflowPrintObject PO: %p (%9s) Setting w,h to %d,%d\n", aPO, gFrameTypesStr[aPO->mFrameType], width, height);  nsCOMPtr<nsIDOMWindowInternal> domWinIntl(do_QueryInterface(mPrt->mPrintDocDW));  // 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  // (see also nsSimplePageSequence.cpp)  PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages;  NS_WITH_SERVICE(nsIPrintOptions, printService, kPrintOptionsCID, &rv);  if (NS_SUCCEEDED(rv)) {    printService->GetPrintRange(&printRangeType);  }  if (printRangeType == nsIPrintOptions::kRangeSelection && IsThereARangeSelection(domWinIntl)) {    height = 0x0FFFFFFF;  }  nsRect tbounds = nsRect(0, 0, width, height);  // Create a child window of the parent that is our "root view/window"  rv = nsComponentManager::CreateInstance(kViewCID, nsnull, NS_GET_IID(nsIView), (void **)&(aPO->mRootView));  if (NS_FAILED(rv)) {    return rv;  }  rv = (aPO->mRootView)->Init(aPO->mViewManager, tbounds, nsnull);  if (NS_FAILED(rv)) {    return rv;  }  // Setup hierarchical relationship in view manager  aPO->mViewManager->SetRootView(aPO->mRootView);  aPO->mPresShell->Init(document, aPO->mPresContext, aPO->mViewManager,aPO->mStyleSet);  nsCompatibility mode;  mPresContext->GetCompatibilityMode(&mode);  aPO->mPresContext->SetCompatibilityMode(mode);  aPO->mPresContext->SetContainer(aPO->mWebShell);  // get the old history  nsCOMPtr<nsIPresShell> presShell;  nsCOMPtr<nsILayoutHistoryState>  layoutState;  NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE);  presShell->CaptureHistoryState(getter_AddRefs(layoutState),PR_TRUE);  aPO->mPresShell->BeginObservingDocument();  nsMargin margin(0,0,0,0);  if (printService) {    printService->GetMarginInTwips(margin);  }  // 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);  // now, change the value for special cases  if (mPrt->mPrintFrameType == nsIPrintOptions::kEachFrameSep) {    if (aPO->mFrameType == eFrame) {      adjRect.SetRect(0, 0, width, height);    } else if (aPO->mFrameType == eIFrame) {      height = pageHeight*10;      adjRect.SetRect(aPO->mRect.x != 0?margin.left:0, aPO->mRect.y != 0?margin.top:0, width, height);    }  } else if (mPrt->mPrintFrameType == nsIPrintOptions::kFramesAsIs) {    if (aPO->mFrameType == eFrame || aPO->mFrameType == eIFrame) {      height = pageHeight*10;      adjRect.SetRect(aPO->mRect.x != 0?margin.left:0, aPO->mRect.y != 0?margin.top:0, width, height);    }  } else if (mPrt->mPrintFrameType == nsIPrintOptions::kSelectedFrame) {    if (aPO->mFrameType == eIFrame) {      height = pageHeight*10;      adjRect.SetRect(aPO->mRect.x != 0?margin.left:0, aPO->mRect.y != 0?margin.top:0, width, height);    }  }  aPO->mPresContext->SetPageDim(&adjRect);  rv = aPO->mPresShell->InitialReflow(width, height);  if (NS_SUCCEEDED(rv)) {    // Transfer Selection Ranges to the new Print PresShell    nsCOMPtr<nsISelection> selection;    nsCOMPtr<nsISelection> selectionPS;    nsresult rvv = GetDocumentSelection(getter_AddRefs(selection), wsPresShell);    if (NS_SUCCEEDED(rvv) && selection) {      rvv = GetDocumentSelection(getter_AddRefs(selectionPS), aPO->mPresShell);      if (NS_SUCCEEDED(rvv) && selectionPS) {        PRInt32 cnt;        selection->GetRangeCount(&cnt);        PRInt32 inx;        for (inx=0;inx<cnt;inx++) {          nsCOMPtr<nsIDOMRange> range;          if (NS_SUCCEEDED(selection->GetRangeAt(inx, getter_AddRefs(range)))) {            selectionPS->AddRange(range);          }        }      }    }            // update the history from the old presentation shell    nsCOMPtr<nsIFrameManager> fm;    rv = aPO->mPresShell->GetFrameManager(getter_AddRefs(fm));    if(NS_SUCCEEDED(rv) && fm) {      nsIFrame* root;      aPO->mPresShell->GetRootFrame(&root);      fm->RestoreFrameState(aPO->mPresContext, root, layoutState);    }  }  aPO->mPresShell->EndObservingDocument();  return rv;}