float p2t; mPresContext->GetPixelsToTwips(&p2t); tbounds *= p2t;   mViewManager = do_CreateInstance(kViewManagerCID); NS_ENSURE_TRUE(mViewManager, NS_ERROR_NOT_AVAILABLE);    rv = mViewManager->Init(mDeviceContext);
rv = MakeWindow(mParentWidget, tbounds);
DocumentViewerImpl::Show(void){  NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);  // We don't need the previous viewer anymore since we're not  // displaying it.  if (mPreviousViewer) {    // This little dance *may* only be to keep    // PresShell::EndObservingDocument happy, but I'm not sure.    nsCOMPtr<nsIContentViewer> prevViewer(mPreviousViewer);    mPreviousViewer = nsnull;    prevViewer->Destroy();  }  if (mWindow) {    mWindow->Show(PR_TRUE);  }  if (mDocument && !mPresShell && !mWindow) {    nsresult rv;    nsCOMPtr<nsIBaseWindow> base_win(do_QueryInterface(mContainer));    NS_ENSURE_TRUE(base_win, NS_ERROR_UNEXPECTED);    base_win->GetParentWidget(&mParentWidget);    NS_ENSURE_TRUE(mParentWidget, NS_ERROR_UNEXPECTED);    mDeviceContext = dont_AddRef(mParentWidget->GetDeviceContext());#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)    // Clear PrintPreview Alternate Device    if (mDeviceContext) {      mDeviceContext->SetAltDevice(nsnull);    }#endif    // Create presentation context    if (GetIsCreatingPrintPreview()) {      NS_ERROR("Whoa, we should not get here!");      return NS_ERROR_UNEXPECTED;    }    mPresContext = do_CreateInstance(kGalleyContextCID, &rv);    NS_ENSURE_SUCCESS(rv, rv);    mPresContext->Init(mDeviceContext);    nsRect tbounds;    mParentWidget->GetBounds(tbounds);    float p2t;    mPresContext->GetPixelsToTwips(&p2t);    tbounds *= p2t;    // Create the view manager    mViewManager = do_CreateInstance(kViewManagerCID);    NS_ENSURE_TRUE(mViewManager, NS_ERROR_NOT_AVAILABLE);    // Initialize the view manager with an offset. This allows the    // viewmanager to manage a coordinate space offset from (0,0)    rv = mViewManager->Init(mDeviceContext);    if (NS_FAILED(rv))      return rv;    rv = mViewManager->SetWindowOffset(tbounds.x, tbounds.y);    if (NS_FAILED(rv))      return rv;    // Reset the bounds offset so the root view is set to 0,0. The    // offset is specified in nsIViewManager::Init above.    // Besides, layout will reset the root view to (0,0) during reflow,    // so changing it to 0,0 eliminates placing the root view in the    // wrong place initially.    tbounds.x = 0;    tbounds.y = 0;    // Create a child window of the parent that is our "root    // view/window" Create a view    nsIView *view = nsnull;    rv = CallCreateInstance(kViewCID, &view);    if (NS_FAILED(rv))      return rv;    rv = view->Init(mViewManager, tbounds, nsnull);    if (NS_FAILED(rv))      return rv;    rv = view->CreateWidget(kWidgetCID, nsnull,                            mParentWidget->GetNativeData(NS_NATIVE_WIDGET),                            PR_TRUE, PR_FALSE);    if (NS_FAILED(rv))      return rv;    // Setup hierarchical relationship in view manager    mViewManager->SetRootView(view);    view->GetWidget(*getter_AddRefs(mWindow));    if (mPresContext && mContainer) {      nsCOMPtr<nsILinkHandler> linkHandler(do_GetInterface(mContainer));      if (linkHandler) {        mPresContext->SetLinkHandler(linkHandler);      }      mPresContext->SetContainer(mContainer);    }    if (mPresContext) {      Hide();      rv = InitPresentationStuff(PR_TRUE);    }    // If we get here the document load has already started and the    // window is shown because some JS on the page caused it to be    // shown...    mPresShell->UnsuppressPainting();  }  return NS_OK;}