mPresContext->GetPixelsToTwips(&p2t);
p2t = mPresContext->PixelsToTwips();
DocumentViewerImpl::InitPresentationStuff(PRBool aDoInitialReflow){  // Create the style set...  nsStyleSet *styleSet;  nsresult rv = CreateStyleSet(mDocument, &styleSet);  NS_ENSURE_SUCCESS(rv, rv);  // Now make the shell for the document  rv = mDocument->CreateShell(mPresContext, mViewManager, styleSet,                              getter_AddRefs(mPresShell));  if (NS_FAILED(rv)) {    delete styleSet;    return rv;  }  if (aDoInitialReflow) {    // Since InitialReflow() will create frames for *all* items    // that are currently in the document tree, we need to flush    // any pending notifications to prevent the content sink from    // duplicating layout frames for content it has added to the tree    // but hasn't notified the document about. (Bug 154018)    //    // Note that we are flushing before we add mPresShell as an observer    // to avoid bogus notifications.    mDocument->FlushPendingNotifications(PR_FALSE);  }  mPresShell->BeginObservingDocument();  // Initialize our view manager  nsRect bounds;  mWindow->GetBounds(bounds);  float p2t;  mPresContext->GetPixelsToTwips(&p2t);  nscoord width = NSIntPixelsToTwips(bounds.width, p2t);  nscoord height = NSIntPixelsToTwips(bounds.height, p2t);  mViewManager->DisableRefresh();  mViewManager->SetWindowDimensions(width, height);  // Setup default view manager background color  // This may be overridden by the docshell with the background color  // for the last document loaded into the docshell  mViewManager->SetDefaultBackgroundColor(mPresContext->DefaultBackgroundColor());  if (aDoInitialReflow) {    nsCOMPtr<nsIScrollable> sc = do_QueryInterface(mContainer);    if (sc) {      nsCOMPtr<nsIDOMHTMLFrameSetElement> frameset(do_QueryInterface(mDocument->GetRootContent()));      if (frameset) {        // If this is a frameset (i.e. not a frame) then we never want        // scrollbars on it, the scrollbars go inside the frames        // inside the frameset...        sc->SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_Y,                                           NS_STYLE_OVERFLOW_HIDDEN);        sc->SetCurrentScrollbarPreferences(nsIScrollable::ScrollOrientation_X,                                           NS_STYLE_OVERFLOW_HIDDEN);      } else {        sc->ResetScrollbarPreferences();      }    }    // Initial reflow    mPresShell->InitialReflow(width, height);    // Now trigger a refresh    if (mEnableRendering) {      mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE);    }  }  // now register ourselves as a selection listener, so that we get  // called when the selection changes in the window  nsDocViewerSelectionListener *selectionListener =    new nsDocViewerSelectionListener();  NS_ENSURE_TRUE(selectionListener, NS_ERROR_OUT_OF_MEMORY);  selectionListener->Init(this);  // mSelectionListener is a owning reference  mSelectionListener = selectionListener;  nsCOMPtr<nsISelection> selection;  rv = GetDocumentSelection(getter_AddRefs(selection));  NS_ENSURE_SUCCESS(rv, rv);  nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(selection));  rv = selPrivate->AddSelectionListener(mSelectionListener);  if (NS_FAILED(rv))    return rv;  // Save old listener so we can unregister it  nsCOMPtr<nsIDOMFocusListener> mOldFocusListener = mFocusListener;  // focus listener  //  // now register ourselves as a focus listener, so that we get called  // when the focus changes in the window  nsDocViewerFocusListener *focusListener;  NS_NEWXPCOM(focusListener, nsDocViewerFocusListener);  NS_ENSURE_TRUE(focusListener, NS_ERROR_OUT_OF_MEMORY);  focusListener->Init(this);  // mFocusListener is a strong reference  mFocusListener = focusListener;  // get the DOM event receiver  nsCOMPtr<nsIDOMEventReceiver> erP(do_QueryInterface(mDocument));  NS_WARN_IF_FALSE(erP, "No event receiver in document!");  if (erP) {    rv = erP->AddEventListenerByIID(mFocusListener,                                    NS_GET_IID(nsIDOMFocusListener));    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener");    if (mOldFocusListener) {      rv = erP->RemoveEventListenerByIID(mOldFocusListener,                                      NS_GET_IID(nsIDOMFocusListener));      NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove focus listener");    }  }  return NS_OK;}