Ejemplo n.º 1
0
void
nsCoreUtils::DispatchClickEvent(nsITreeBoxObject *aTreeBoxObj,
                                int32_t aRowIndex, nsITreeColumn *aColumn,
                                const nsAString& aPseudoElt)
{
  nsCOMPtr<nsIDOMElement> tcElm;
  aTreeBoxObj->GetTreeBody(getter_AddRefs(tcElm));
  if (!tcElm)
    return;

  nsCOMPtr<nsIContent> tcContent(do_QueryInterface(tcElm));
  nsIDocument *document = tcContent->GetCurrentDoc();
  if (!document)
    return;

  nsCOMPtr<nsIPresShell> presShell = document->GetShell();
  if (!presShell)
    return;

  // Ensure row is visible.
  aTreeBoxObj->EnsureRowIsVisible(aRowIndex);

  // Calculate x and y coordinates.
  int32_t x = 0, y = 0, width = 0, height = 0;
  nsresult rv = aTreeBoxObj->GetCoordsForCellItem(aRowIndex, aColumn,
                                                  aPseudoElt,
                                                  &x, &y, &width, &height);
  if (NS_FAILED(rv))
    return;

  nsCOMPtr<nsIDOMXULElement> tcXULElm(do_QueryInterface(tcElm));
  nsCOMPtr<nsIBoxObject> tcBoxObj;
  tcXULElm->GetBoxObject(getter_AddRefs(tcBoxObj));

  int32_t tcX = 0;
  tcBoxObj->GetX(&tcX);

  int32_t tcY = 0;
  tcBoxObj->GetY(&tcY);

  // Dispatch mouse events.
  nsWeakFrame tcFrame = tcContent->GetPrimaryFrame();
  nsIFrame* rootFrame = presShell->GetRootFrame();

  nsPoint offset;
  nsIWidget *rootWidget =
    rootFrame->GetViewExternal()->GetNearestWidget(&offset);

  RefPtr<nsPresContext> presContext = presShell->GetPresContext();

  int32_t cnvdX = presContext->CSSPixelsToDevPixels(tcX + x + 1) +
    presContext->AppUnitsToDevPixels(offset.x);
  int32_t cnvdY = presContext->CSSPixelsToDevPixels(tcY + y + 1) +
    presContext->AppUnitsToDevPixels(offset.y);

  // XUL is just desktop, so there is no real reason for senfing touch events.
  DispatchMouseEvent(eMouseDown, cnvdX, cnvdY,
                     tcContent, tcFrame, presShell, rootWidget);

  DispatchMouseEvent(eMouseUp, cnvdX, cnvdY,
                     tcContent, tcFrame, presShell, rootWidget);
}
NS_IMETHODIMP
nsDocShellTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem,
                                 int32_t aCX, int32_t aCY)
{
  nsCOMPtr<nsIWebBrowserChrome> webBrowserChrome = GetWebBrowserChrome();

  NS_ENSURE_STATE(mTreeOwner || webBrowserChrome);

  if (mTreeOwner) {
    return mTreeOwner->SizeShellTo(aShellItem, aCX, aCY);
  }

  if (aShellItem == mWebBrowser->mDocShell) {
    nsCOMPtr<nsITabChild> tabChild = do_QueryInterface(webBrowserChrome);
    if (tabChild) {
      // The XUL window to resize is in the parent process, but there we
      // won't be able to get aShellItem to do the hack in nsXULWindow::SizeShellTo,
      // so let's send the width and height of aShellItem too.
      nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(aShellItem));
      NS_ENSURE_TRUE(shellAsWin, NS_ERROR_FAILURE);

      int32_t width = 0;
      int32_t height = 0;
      shellAsWin->GetSize(&width, &height);
      return tabChild->RemoteSizeShellTo(aCX, aCY, width, height);
    }
    return webBrowserChrome->SizeBrowserTo(aCX, aCY);
  }

  nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(aShellItem));
  NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);

  nsCOMPtr<nsIDOMDocument> domDocument;
  webNav->GetDocument(getter_AddRefs(domDocument));
  NS_ENSURE_TRUE(domDocument, NS_ERROR_FAILURE);

  nsCOMPtr<nsIDOMElement> domElement;
  domDocument->GetDocumentElement(getter_AddRefs(domElement));
  NS_ENSURE_TRUE(domElement, NS_ERROR_FAILURE);

  // Set the preferred Size
  //XXX
  NS_ERROR("Implement this");
  /*
  Set the preferred size on the aShellItem.
  */

  RefPtr<nsPresContext> presContext;
  mWebBrowser->mDocShell->GetPresContext(getter_AddRefs(presContext));
  NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);

  nsIPresShell* presShell = presContext->GetPresShell();
  NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);

  NS_ENSURE_SUCCESS(
    presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE),
    NS_ERROR_FAILURE);

  nsRect shellArea = presContext->GetVisibleArea();

  int32_t browserCX = presContext->AppUnitsToDevPixels(shellArea.width);
  int32_t browserCY = presContext->AppUnitsToDevPixels(shellArea.height);

  return webBrowserChrome->SizeBrowserTo(browserCX, browserCY);
}