if (NS_FAILED(rv)) return rv; rv = mViewManager->SetWindowOffset(tbounds.x, tbounds.y);
DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget,                               const nsRect& aBounds){  nsresult rv;  mViewManager = do_CreateInstance(kViewManagerCID, &rv);  if (NS_FAILED(rv))    return rv;  nsIDeviceContext *dx = mPresContext->DeviceContext();  nsRect tbounds = aBounds;  float p2t;  p2t = mPresContext->PixelsToTwips();  tbounds *= p2t;   // Initialize the view manager with an offset. This allows the viewmanager   // to manage a coordinate space offset from (0,0)  rv = mViewManager->Init(dx);  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;  // if aParentWidget has a view, we'll hook our view manager up to its view tree  void* clientData;  nsIView* containerView = nsnull;  if (NS_SUCCEEDED(aParentWidget->GetClientData(clientData))) {    nsISupports* data = (nsISupports*)clientData;    if (data) {      CallQueryInterface(data, &containerView);    }  }  if (containerView) {    // see if the containerView has already been hooked into a foreign view manager hierarchy    // if it has, then we have to hook into the hierarchy too otherwise bad things will happen.    nsIViewManager* containerVM = containerView->GetViewManager();    nsIView* pView = containerView;    do {      pView = pView->GetParent();    } while (pView && pView->GetViewManager() == containerVM);    if (!pView) {      // OK, so the container is not already hooked up into a foreign view manager hierarchy.      // That means we can choose not to hook ourselves up.      //      // If the parent container is a chrome shell then we won't hook into its view      // tree. This will improve performance a little bit (especially given scrolling/painting perf bugs)      // but is really just for peace of mind. This check can be removed if we want to support fancy      // chrome effects like transparent controls floating over content, transparent Web browsers, and      // things like that, and the perf bugs are fixed.      nsCOMPtr<nsIDocShellTreeItem> container(do_QueryInterface(mContainer));      nsCOMPtr<nsIDocShellTreeItem> parentContainer;      PRInt32 itemType;      if (nsnull == container          || NS_FAILED(container->GetParent(getter_AddRefs(parentContainer)))          || nsnull == parentContainer          || NS_FAILED(parentContainer->GetItemType(&itemType))          || itemType != nsIDocShellTreeItem::typeContent) {        containerView = nsnull;      }    }  }  rv = view->Init(mViewManager, tbounds, containerView);  if (NS_FAILED(rv))    return rv;  nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(mContainer));  NS_ENSURE_TRUE(treeItem, NS_ERROR_FAILURE);  PRInt32 itemType;  nsContentType contentType = eContentTypeUI;  treeItem->GetItemType(&itemType);  if (itemType == nsIDocShellTreeItem::typeContent ||      itemType == nsIDocShellTreeItem::typeContentWrapper) {#ifdef MOZ_XUL    nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));    if (!xulDoc)#endif      contentType = eContentTypeContent;  }  // pass in a native widget to be the parent widget ONLY if the view hierarchy will stand alone.  // otherwise the view will find its own parent widget and "do the right thing" to  // establish a parent/child widget relationship  rv = view->CreateWidget(kWidgetCID, nsnull,                          containerView != nsnull ? nsnull : aParentWidget->GetNativeData(NS_NATIVE_WIDGET),                          PR_TRUE, PR_FALSE, contentType);  if (NS_FAILED(rv))    return rv;  // Setup hierarchical relationship in view manager  mViewManager->SetRootView(view);  mWindow = view->GetWidget();  // This SetFocus is necessary so the Arrow Key and Page Key events  // go to the scrolled view as soon as the Window is created instead of going to  // the browser window (this enables keyboard scrolling of the document)  // mWindow->SetFocus();  return rv;}