mViewManager->EnableRefresh();
mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE);
DocumentViewerImpl::Init(nsNativeWidget aNativeParent,                         nsIDeviceContext* aDeviceContext,                         nsIPref* aPrefs,                         const nsRect& aBounds,                         nsScrollPreference aScrolling){  nsresult rv;  if (!mDocument) {    return NS_ERROR_NULL_POINTER;  }  mDeviceContext = dont_QueryInterface(aDeviceContext);  PRBool makeCX = PR_FALSE;  if (!mPresContext) {    // Create presentation context    rv = NS_NewGalleyContext(getter_AddRefs(mPresContext));    if (NS_FAILED(rv)) return rv;    mPresContext->Init(aDeviceContext, aPrefs);     makeCX = PR_TRUE;  }  nsCOMPtr<nsIInterfaceRequestor> requestor(do_QueryInterface(mContainer));  if (requestor) {    nsCOMPtr<nsILinkHandler> linkHandler;    requestor->GetInterface(NS_GET_IID(nsILinkHandler),        getter_AddRefs(linkHandler));    mPresContext->SetContainer(mContainer);    mPresContext->SetLinkHandler(linkHandler);    // Set script-context-owner in the document    nsCOMPtr<nsIScriptGlobalObjectOwner> owner;    requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner),       getter_AddRefs(owner));    if (nsnull != owner) {      nsCOMPtr<nsIScriptGlobalObject> global;      rv = owner->GetScriptGlobalObject(getter_AddRefs(global));      if (NS_SUCCEEDED(rv) && (nsnull != global)) {        mDocument->SetScriptGlobalObject(global);        nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(mDocument));        if (nsnull != domdoc) {          global->SetNewDocument(domdoc);        }      }    }  }  // Create the ViewManager and Root View...  rv = MakeWindow(aNativeParent, aBounds, aScrolling);  if (NS_FAILED(rv)) return rv;  // Create the style set...  nsIStyleSet* styleSet;  rv = CreateStyleSet(mDocument, &styleSet);  if (NS_FAILED(rv)) return rv;    // Now make the shell for the document    rv = mDocument->CreateShell(mPresContext, mViewManager, styleSet,                                getter_AddRefs(mPresShell));    NS_RELEASE(styleSet);  if (NS_FAILED(rv)) return rv;        // Initialize our view manager      nsRect bounds;      mWindow->GetBounds(bounds);      nscoord width = bounds.width;      nscoord height = bounds.height;      float p2t;      mPresContext->GetPixelsToTwips(&p2t);      width = NSIntPixelsToTwips(width, p2t);      height = NSIntPixelsToTwips(height, p2t);      mViewManager->DisableRefresh();      mViewManager->SetWindowDimensions(width, height);      if (!makeCX) {        // Make shell an observer for next time        mPresShell->BeginObservingDocument();//XXX I don't think this should be done *here*; and why paint nothing//(which turns out to cause black flashes!)???        // Resize-reflow this time        mPresShell->InitialReflow(width, height);        // Now trigger a refresh        if (mEnableRendering) {          mViewManager->EnableRefresh();        }      }#if 0  // enable this when we resolve the ref cycle issues.  // now register ourselves as a selection listener, so that we get called  // when the selection changes in the window  nsCOMPtr<nsIDOMSelection> selection;  rv = GetDocumentSelection(getter_AddRefs(selection));  if (NS_FAILED(rv)) return rv;    rv = selection->AddSelectionListener(this);		// this creates a circular ref, causing leaks. Fix this.  if (NS_FAILED(rv)) return rv;    // we need to RemoveSelectionListener somewhere too#endif  return rv;}