clipView->GetBounds(visibleRect);
nsRect visibleRect = clipView->GetBounds();
nsTypedSelection::ScrollRectIntoView(nsIScrollableView *aScrollableView,                              nsRect& aRect,                              PRIntn  aVPercent,                               PRIntn  aHPercent,                              PRBool aScrollParentViews){  nsresult rv = NS_OK;  if (!mFrameSelection)    return NS_OK;//nothing to do  if (!aScrollableView)    return NS_ERROR_NULL_POINTER;  // Determine the visible rect in the scrolled view's coordinate space.  // The size of the visible area is the clip view size  const nsIView*  clipView;  nsRect          visibleRect;  aScrollableView->GetClipView(&clipView);  clipView->GetBounds(visibleRect);  aScrollableView->GetScrollPosition(visibleRect.x, visibleRect.y);  // The actual scroll offsets  nscoord scrollOffsetX = visibleRect.x;  nscoord scrollOffsetY = visibleRect.y;  // See how aRect should be positioned vertically  if (NS_PRESSHELL_SCROLL_ANYWHERE == aVPercent) {    // The caller doesn't care where aRect is positioned vertically,    // so long as it's fully visible    if (aRect.y < visibleRect.y) {      // Scroll up so aRect's top edge is visible      scrollOffsetY = aRect.y;    } else if (aRect.YMost() > visibleRect.YMost()) {      // Scroll down so aRect's bottom edge is visible. Make sure      // aRect's top edge is still visible      scrollOffsetY += aRect.YMost() - visibleRect.YMost();      if (scrollOffsetY > aRect.y) {        scrollOffsetY = aRect.y;      }    }  } else {    // Align the aRect edge according to the specified percentage    nscoord frameAlignY = aRect.y + (aRect.height * aVPercent) / 100;    scrollOffsetY = frameAlignY - (visibleRect.height * aVPercent) / 100;  }  // See how the aRect should be positioned horizontally  if (NS_PRESSHELL_SCROLL_ANYWHERE == aHPercent) {    // The caller doesn't care where the aRect is positioned horizontally,    // so long as it's fully visible    if (aRect.x < visibleRect.x) {      // Scroll left so the aRect's left edge is visible      scrollOffsetX = aRect.x;    } else if (aRect.XMost() > visibleRect.XMost()) {      // Scroll right so the aRect's right edge is visible. Make sure the      // aRect's left edge is still visible      scrollOffsetX += aRect.XMost() - visibleRect.XMost();      if (scrollOffsetX > aRect.x) {        scrollOffsetX = aRect.x;      }    }        } else {    // Align the aRect edge according to the specified percentage    nscoord frameAlignX = aRect.x + (aRect.width * aHPercent) / 100;    scrollOffsetX = frameAlignX - (visibleRect.width * aHPercent) / 100;  }  aScrollableView->ScrollTo(scrollOffsetX, scrollOffsetY, NS_VMREFRESH_IMMEDIATE);  if (aScrollParentViews)  {    //    // Get aScrollableView's scrolled view.    //    nsIView *scrolledView = 0;    rv = aScrollableView->GetScrolledView(scrolledView);    if (NS_FAILED(rv))      return rv;    if (!scrolledView)      return NS_ERROR_FAILURE;    //    // Check if aScrollableRect has a parent scrollable view!    //    nsIView *view = 0;    rv = CallQueryInterface(aScrollableView, &view);    if (!view)      return rv;    rv = view->GetParent(view);    if (NS_FAILED(rv))      return rv;    if (view)    {      nsIScrollableView *parentSV = 0;      rv = GetClosestScrollableView(view, &parentSV);      if (NS_FAILED(rv))        return rv;      if (parentSV)      {        //        // We have a parent scrollable view, so now map aRect        // into it's scrolled view's coordinate space.        //                nsRect newRect;        rv = parentSV->GetScrolledView(view);        if (NS_FAILED(rv))          return rv;        if (!view)          return NS_ERROR_FAILURE;        rv = GetViewAncestorOffset(scrolledView, view, &newRect.x, &newRect.y);        if (NS_FAILED(rv))          return rv;        newRect.x     += aRect.x;        newRect.y     += aRect.y;        newRect.width  = aRect.width;        newRect.height = aRect.height;        //        // Now scroll the rect into the parent's view.        //        rv = ScrollRectIntoView(parentSV, newRect, aVPercent, aHPercent, aScrollParentViews);      }    }  }  return rv;}