nsCOMPtr<nsIWidget> widget; nsIView *closestView = 0;
nsIWidget* widget = nsnull; nsIView *closestView = nsnull;
nsTypedSelection::GetPointFromOffset(nsIFrame *aFrame, PRInt32 aContentOffset, nsPoint *aPoint){  nsresult rv = NS_OK;  if (!mFrameSelection)    return NS_ERROR_FAILURE;//nothing to do  if (!aFrame || !aPoint)    return NS_ERROR_NULL_POINTER;  aPoint->x = 0;  aPoint->y = 0;  //  // Retrieve the device context. We need one to create  // a rendering context.  //  nsIFocusTracker *tracker = mFrameSelection->GetTracker();  if (!tracker)    return NS_ERROR_NULL_POINTER;  nsCOMPtr<nsIPresContext> presContext;  rv = tracker->GetPresContext(getter_AddRefs(presContext));  if (NS_FAILED(rv))    return rv;  if (!presContext)    return NS_ERROR_NULL_POINTER;    nsCOMPtr<nsIDeviceContext> deviceContext;  rv = presContext->GetDeviceContext(getter_AddRefs(deviceContext));  if (NS_FAILED(rv))    return rv;  if (!deviceContext)    return NS_ERROR_NULL_POINTER;  //  // Now get the closest view with a widget so we can create  // a rendering context.  //  nsCOMPtr<nsIWidget> widget;  nsIView *closestView = 0;  nsPoint offset(0, 0);  rv = aFrame->GetOffsetFromView(presContext, offset, &closestView);  while (!widget && closestView)  {    rv = closestView->GetWidget(*getter_AddRefs(widget));    if (NS_FAILED(rv))      return rv;    if (!widget)    {      rv = closestView->GetParent(closestView);      if (NS_FAILED(rv))        return rv;    }  }  if (!closestView)    return NS_ERROR_FAILURE;  //  // Create a rendering context. This context is used by text frames  // to calculate text widths so it can figure out where the point is  // in the frame.  //  nsCOMPtr<nsIRenderingContext> rendContext;  rv = deviceContext->CreateRenderingContext(closestView, *getter_AddRefs(rendContext));    if (NS_FAILED(rv))    return rv;  if (!rendContext)    return NS_ERROR_NULL_POINTER;  //  // Now get the point and return!  //  rv = aFrame->GetPointFromOffset(presContext, rendContext, aContentOffset, aPoint);  return rv;}