nsCOMPtr<nsIDOMXULElement> childDOMXULElement (do_QueryInterface(child)); nsIBoxObject * childBoxObject; childDOMXULElement->GetBoxObject(&childBoxObject);
nsCOMPtr<nsIDOMDocument> doc; child->GetOwnerDocument(getter_AddRefs(doc)); nsCOMPtr<nsIDOMNSDocument> nsDoc(do_QueryInterface(doc)); if(!nsDoc) return NS_ERROR_UNEXPECTED;  nsCOMPtr<nsIBoxObject> childBoxObject; nsDoc->GetBoxObjectFor(child, getter_AddRefs(childBoxObject)); if(!childBoxObject) return NS_ERROR_UNEXPECTED;
NS_IMETHODIMP nsScrollBoxObject::EnsureElementIsVisible(nsIDOMElement *child){    nsIScrollableView* scrollableView = GetScrollableView();    if (!scrollableView)       return NS_ERROR_FAILURE;    // prepare for twips    float pixelsToTwips = 0.0;    pixelsToTwips = mPresShell->GetPresContext()->PixelsToTwips();        nsIBox* scrolledBox = GetScrolledBox(this);    if (!scrolledBox)       return NS_ERROR_FAILURE;    nsRect rect, crect;    nsCOMPtr<nsIDOMXULElement> childDOMXULElement (do_QueryInterface(child));    nsIBoxObject * childBoxObject;    childDOMXULElement->GetBoxObject(&childBoxObject);    PRInt32 x,y,width,height;    childBoxObject->GetX(&x);    childBoxObject->GetY(&y);    childBoxObject->GetWidth(&width);    childBoxObject->GetHeight(&height);    // get the twips rectangle from the boxobject (which has pixels)        rect.x = NSToIntRound(x * pixelsToTwips);    rect.y = NSToIntRound(y * pixelsToTwips);    rect.width = NSToIntRound(width * pixelsToTwips);    rect.height = NSToIntRound(height * pixelsToTwips);    // TODO: make sure the child is inside the box    // get our current info    PRBool horiz = PR_FALSE;    scrolledBox->GetOrientation(horiz);    nsPoint cp;    scrollableView->GetScrollPosition(cp.x,cp.y);    GetOffsetRect(crect);        crect.x = NSToIntRound(crect.x * pixelsToTwips);    crect.y = NSToIntRound(crect.y * pixelsToTwips);    crect.width = NSToIntRound(crect.width * pixelsToTwips);    crect.height = NSToIntRound(crect.height * pixelsToTwips);    nscoord newx=cp.x, newy=cp.y;    // we only scroll in the direction of the scrollbox orientation    if (horiz) {        if ((rect.x - crect.x) + rect.width > cp.x + crect.width) {            newx = cp.x + (((rect.x - crect.x) + rect.width)-(cp.x + crect.width));        } else if (rect.x - crect.x < cp.x) {            newx = rect.x - crect.x;        }    } else {        if ((rect.y - crect.y) + rect.height > cp.y + crect.height) {            newy = cp.y + (((rect.y - crect.y) + rect.height)-(cp.y + crect.height));        } else if (rect.y - crect.y < cp.y) {            newy = rect.y - crect.y;        }    }        // scroll away    return scrollableView->ScrollTo(newx, newy, NS_SCROLL_PROPERTY_ALWAYS_BLIT);}