if (IsScrollingEnabled()) return ScrollFrameIntoView(aFrame, NS_PRESSHELL_SCROLL_ANYWHERE, NS_PRESSHELL_SCROLL_ANYWHERE); return NS_OK;
if (mViewManager) {  nsIScrollableView* scrollingView; mViewManager->GetRootScrollableView(&scrollingView);  if (scrollingView) { nsIView*  scrolledView; nsPoint   offset; nsIView*  closestView;    scrollingView->GetScrolledView(scrolledView); aFrame->GetOffsetFromView(mPresContext, offset, &closestView);    while ((closestView != nsnull) && (closestView != scrolledView)) { nscoord x, y;   closestView->GetPosition(&x, &y); offset.MoveBy(x, y);   closestView->GetParent(closestView); }    const nsIView*  clipView; nsRect          visibleRect;  scrollingView->GetScrollPosition(visibleRect.x, visibleRect.y); scrollingView->GetClipView(&clipView); clipView->GetDimensions(&visibleRect.width, &visibleRect.height);   nscoord scrollOffsetX = visibleRect.x; nscoord scrollOffsetY = visibleRect.y;   nsRect  frameBounds; aFrame->GetRect(frameBounds); frameBounds.x = offset.x; frameBounds.y = offset.y;   if (NS_PRESSHELL_SCROLL_ANYWHERE == aVPercent) {   if (frameBounds.y < visibleRect.y) {  scrollOffsetY = frameBounds.y; } else if (frameBounds.YMost() > visibleRect.YMost()) {   scrollOffsetY += frameBounds.YMost() - visibleRect.YMost(); if (scrollOffsetY > frameBounds.y) { scrollOffsetY = frameBounds.y; } } } else if (NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE == aVPercent) {  if (frameBounds.YMost() < visibleRect.y) {  scrollOffsetY = frameBounds.y; }  else if (frameBounds.y > visibleRect.YMost()) {   scrollOffsetY += frameBounds.YMost() - visibleRect.YMost(); if (scrollOffsetY > frameBounds.y) { scrollOffsetY = frameBounds.y; } } } else {  nscoord frameAlignY = frameBounds.y + (frameBounds.height * aVPercent) / 100; scrollOffsetY = frameAlignY - (visibleRect.height * aVPercent) / 100; }   if (NS_PRESSHELL_SCROLL_ANYWHERE == aHPercent) {   if (frameBounds.x < visibleRect.x) {  scrollOffsetX = frameBounds.x; } else if (frameBounds.XMost() > visibleRect.XMost()) {   scrollOffsetX += frameBounds.XMost() - visibleRect.XMost(); if (scrollOffsetX > frameBounds.x) { scrollOffsetX = frameBounds.x; } } } else if (NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE == aHPercent) {  if (frameBounds.XMost() < visibleRect.x) {  scrollOffsetX = frameBounds.x; }  else if (frameBounds.x > visibleRect.XMost()) {   scrollOffsetX += frameBounds.XMost() - visibleRect.XMost(); if (scrollOffsetX > frameBounds.x) { scrollOffsetX = frameBounds.x; } } } else {  nscoord frameAlignX = frameBounds.x + (frameBounds.width * aHPercent) / 100; scrollOffsetX = frameAlignX - (visibleRect.width * aHPercent) / 100; } if (scrollOffsetX != 0 || scrollOffsetY != 0) { scrollingView->ScrollTo(scrollOffsetX, scrollOffsetY, NS_VMREFRESH_IMMEDIATE); } } } return rv;
PresShell::ScrollFrameIntoView(nsIFrame *aFrame){  if (!aFrame)    return NS_ERROR_NULL_POINTER;      // Before we scroll the frame into view, ask the command dispatcher  // if we're resetting focus because a window just got an activate  // event. If we are, we do not want to scroll the frame into view.  // Example: The user clicks on an anchor, and then deactivates the   // window. When they reactivate the window, the expected behavior  // is not for the anchor link to scroll back into view. That is what  // this check is preventing.  // XXX: The dependency on the command dispatcher needs to be fixed.  nsCOMPtr<nsIContent> content;  aFrame->GetContent(getter_AddRefs(content));  if(content) {    nsCOMPtr<nsIDocument> document;    content->GetDocument(*getter_AddRefs(document));    if(document){      nsCOMPtr<nsIDOMXULCommandDispatcher> commandDispatcher;	  nsCOMPtr<nsIScriptGlobalObject> ourGlobal;	  document->GetScriptGlobalObject(getter_AddRefs(ourGlobal));      nsCOMPtr<nsIDOMWindow> rootWindow;      nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(ourGlobal);      if(ourWindow) {        ourWindow->GetPrivateRoot(getter_AddRefs(rootWindow));        if(rootWindow) {          nsCOMPtr<nsIDOMDocument> rootDocument;          rootWindow->GetDocument(getter_AddRefs(rootDocument));          nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(rootDocument);          if (xulDoc) {            // See if we have a command dispatcher attached.            xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher));            if (commandDispatcher) {              PRBool dontScroll;              commandDispatcher->GetSuppressFocusScroll(&dontScroll);              if(dontScroll)                return NS_OK;			}		  }		}	  }    }  }      if (IsScrollingEnabled())    return ScrollFrameIntoView(aFrame, NS_PRESSHELL_SCROLL_ANYWHERE,                               NS_PRESSHELL_SCROLL_ANYWHERE);  return NS_OK;}