scrollableView->GetScrolledView(scrolledView);
nsDOMSelection::DoAutoScroll(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint){  nsresult result;  if (!aPresContext || !aFrame)    return NS_ERROR_NULL_POINTER;  if (mAutoScrollTimer)    result = mAutoScrollTimer->Stop();  //  // Get a hold of the root scrollable view for presShell.  //  nsIScrollableView *scrollableView = 0;  result = GetRootScrollableView(&scrollableView);  if (NS_SUCCEEDED(result) && scrollableView)  {    //    // Get a hold of the scrollable view's clip view.    //    const nsIView *cView = 0;    result = scrollableView->GetClipView(&cView);    if (NS_SUCCEEDED(result) && cView)    {      //      // Find out if this frame's view is in the parent hierarchy of the clip view.      // If it is, then we know the drag is happening outside of the clip view,      // so we may need to auto scroll.      //      // Get the frame's parent view.      nsPoint viewOffset(0,0);      nsIView *frameView = 0;      nsIFrame *parentFrame = aFrame;      while (NS_SUCCEEDED(result) && parentFrame && !frameView)      {        result = parentFrame->GetView(aPresContext, &frameView);        if (NS_SUCCEEDED(result) && !frameView)          result = parentFrame->GetParent(&parentFrame);      }      if (NS_SUCCEEDED(result) && frameView)      {        //        // Now make sure that the frame's view is in the        // scrollable view's parent hierarchy.        //        nsIView *view = (nsIView*)frameView;                nscoord x, y;        while (view && view != cView)        {          result = view->GetParent(view);          if (NS_FAILED(result))            view = 0;          else if (view && view != cView)          {            result = view->GetPosition(&x, &y);            if (NS_FAILED(result))              view = 0;            else            {              //              // Keep track of the view offsets so we can              // translate aPoint into the scrollable view's              // coordinate system.              //              viewOffset.x += x;              viewOffset.y += y;            }          }        }        if (view)        {          //          // See if aPoint is outside the clip view's boundaries.          // If it is, scroll the view till it is inside the visible area!          //          nsRect bounds;          result = view->GetBounds(bounds);          scrollableView->GetScrollPosition(bounds.x,bounds.y);          if (NS_SUCCEEDED(result))          {            //            // Calculate the amount we would have to scroll in            // the vertical and horizontal directions to get the point            // within the clip area.            //            nscoord dx = 0, dy = 0;            nsPoint ePoint = aPoint;            ePoint.x -= viewOffset.x;            ePoint.y -= viewOffset.y;                        nscoord x1 = bounds.x;            nscoord x2 = bounds.x + bounds.width;            nscoord y1 = bounds.y;            nscoord y2 = bounds.y + bounds.height;            if (ePoint.x < x1)              dx = ePoint.x - x1;            else if (ePoint.x > x2)              dx = ePoint.x - x2;                            if (ePoint.y < y1)              dy = ePoint.y - y1;            else if (ePoint.y > y2)              dy = ePoint.y - y2;            //            // Now clip the scroll amounts so that we don't scroll            // beyond the ends of the document.            //            nscoord scrollX = 0, scrollY = 0;            nscoord docWidth = 0, docHeight = 0;            result = scrollableView->GetScrollPosition(scrollX, scrollY);            if (NS_SUCCEEDED(result))              result = scrollableView->GetContainerSize(&docWidth, &docHeight);            if (NS_SUCCEEDED(result))            {              if (dx < 0 && scrollX == 0)                dx = 0;              else if (dx > 0)              {                x1 = scrollX + dx + bounds.width;                if (x1 > docWidth)                  dx -= x1 - docWidth;              }              if (dy < 0 && scrollY == 0)                dy = 0;              else if (dy > 0)              {                y1 = scrollY + dy + bounds.height;                if (y1 > docHeight)                  dy -= y1 - docHeight;              }              //              // Now scroll the view if neccessary.              //              if (dx != 0 || dy != 0)              {// make sure latest bits are available before we scroll them.//get the presshell                nsCOMPtr<nsIPresShell> presShell;                result = aPresContext->GetShell(getter_AddRefs(presShell));                NS_ENSURE_TRUE(presShell,result);//get viewmanager                nsCOMPtr<nsIViewManager> viewManager;                result = presShell->GetViewManager(getter_AddRefs(viewManager));                NS_ENSURE_TRUE(viewManager,result);                viewManager->Composite();                result = scrollableView->ScrollTo(scrollX + dx, scrollY + dy, NS_VMREFRESH_NO_SYNC);                if (mAutoScrollTimer)                {                  nsPoint point(aPoint.x + dx,aPoint.y + dy);                  result = mAutoScrollTimer->Start(aPresContext, parentFrame, point);#ifdef DEBUG_SELECTIONprintf("point out of view: x=%u, y=%u\n", (point.x), (point.y));#endif                }              }            }          }        }      }    }  }  return result;}