Bug 526394. Part 12: Convert XUL layout code: scrollboxes and trees. r=mats
authorRobert O'Callahan <robert@ocallahan.org>
Thu, 03 Sep 2009 15:57:46 +1200
changeset 37064 c367c90a3853641d06acaae94b3dcbec8d97a158
parent 37063 bbb0cb6172e3fa423ea5f6e77e51da2ac7d81107
child 37065 bb8115d4556fa6b336e061d12c14d3db6acc672f
push idunknown
push userunknown
push dateunknown
reviewersmats
bugs526394
milestone1.9.3a1pre
Bug 526394. Part 12: Convert XUL layout code: scrollboxes and trees. r=mats
layout/xul/base/src/nsScrollBoxObject.cpp
layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
layout/xul/base/src/tree/src/nsTreeBodyFrame.h
--- a/layout/xul/base/src/nsScrollBoxObject.cpp
+++ b/layout/xul/base/src/nsScrollBoxObject.cpp
@@ -41,30 +41,30 @@
 #include "nsIPresShell.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMNSDocument.h"
 #include "nsIDOMElement.h"
 #include "nsPresContext.h"
 #include "nsIFrame.h"
-#include "nsIScrollableView.h"
 #include "nsIScrollableFrame.h"
 
-
 class nsScrollBoxObject : public nsIScrollBoxObject, public nsBoxObject
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSISCROLLBOXOBJECT
 
   nsScrollBoxObject();
   virtual ~nsScrollBoxObject();
 
-  virtual nsIScrollableView* GetScrollableView();
+  virtual nsIScrollableFrame* GetScrollFrame() {
+    return do_QueryFrame(GetFrame(PR_FALSE));
+  }
 
   /* additional members */
 };
 
 /* Implementation file */
 
 NS_INTERFACE_MAP_BEGIN(nsScrollBoxObject)
   NS_INTERFACE_MAP_ENTRY(nsIScrollBoxObject)
@@ -81,43 +81,47 @@ nsScrollBoxObject::nsScrollBoxObject()
 nsScrollBoxObject::~nsScrollBoxObject()
 {
   /* destructor code */
 }
 
 /* void scrollTo (in long x, in long y); */
 NS_IMETHODIMP nsScrollBoxObject::ScrollTo(PRInt32 x, PRInt32 y)
 {
-  nsIScrollableView* scrollableView = GetScrollableView();
-  if (!scrollableView)
+  nsIScrollableFrame* sf = GetScrollFrame();
+  if (!sf)
     return NS_ERROR_FAILURE;
 
-  return scrollableView->ScrollTo(nsPresContext::CSSPixelsToAppUnits(x),
-                                  nsPresContext::CSSPixelsToAppUnits(y), 0);
+  sf->ScrollTo(nsPoint(nsPresContext::CSSPixelsToAppUnits(x),
+                       nsPresContext::CSSPixelsToAppUnits(y)),
+               nsIScrollableFrame::INSTANT);
+  return NS_OK;
 }
 
 /* void scrollBy (in long dx, in long dy); */
 NS_IMETHODIMP nsScrollBoxObject::ScrollBy(PRInt32 dx, PRInt32 dy)
 {
   PRInt32 x, y;
   nsresult rv = GetPosition(&x, &y);
   if (NS_FAILED(rv))
     return rv;
 
   return ScrollTo(x + dx, y + dy);
 }
 
 /* void scrollByLine (in long dlines); */
 NS_IMETHODIMP nsScrollBoxObject::ScrollByLine(PRInt32 dlines)
 {
-  nsIScrollableView* scrollableView = GetScrollableView();
-  if (!scrollableView)
+  nsIScrollableFrame* sf = GetScrollFrame();
+  if (!sf)
     return NS_ERROR_FAILURE;
 
-  return scrollableView->ScrollByLines(0, dlines);
+  sf->ScrollBy(nsIntPoint(0, dlines), nsIScrollableFrame::LINES,
+               nsIScrollableFrame::SMOOTH);
+  return NS_OK;
 }
 
 // XUL <scrollbox> elements have a single box child element.
 // Get a pointer to that box.
 // Note that now that the <scrollbox> is just a regular box
 // with 'overflow:hidden', the boxobject's frame is an nsXULScrollFrame,
 // the <scrollbox>'s box frame is the scrollframe's "scrolled frame", and
 // the <scrollbox>'s child box is a child of that.
@@ -134,31 +138,30 @@ static nsIFrame* GetScrolledBox(nsBoxObj
   if (!scrolledFrame)
     return nsnull;
   return scrolledFrame->GetChildBox();
 }
 
 /* void scrollByIndex (in long dindexes); */
 NS_IMETHODIMP nsScrollBoxObject::ScrollByIndex(PRInt32 dindexes)
 {
-    nsIScrollableView* scrollableView = GetScrollableView();
-    if (!scrollableView)
+    nsIScrollableFrame* sf = GetScrollFrame();
+    if (!sf)
        return NS_ERROR_FAILURE;
     nsIFrame* scrolledBox = GetScrolledBox(this);
     if (!scrolledBox)
        return NS_ERROR_FAILURE;
 
     nsRect rect;
 
     // now get the scrolled boxes first child.
     nsIFrame* child = scrolledBox->GetChildBox();
 
     PRBool horiz = scrolledBox->IsHorizontal();
-    nsPoint cp;
-    scrollableView->GetScrollPosition(cp.x,cp.y);
+    nsPoint cp = sf->GetScrollPosition();
     nscoord diff = 0;
     PRInt32 curIndex = 0;
     PRBool isLTR = scrolledBox->IsNormalDirection();
 
     PRInt32 frameWidth = 0;
     if (!isLTR && horiz) {
       GetWidth(&frameWidth);
       nsCOMPtr<nsIPresShell> shell = GetPresShell(PR_FALSE);
@@ -221,42 +224,43 @@ NS_IMETHODIMP nsScrollBoxObject::ScrollB
       }
    }
 
    if (horiz)
        // In the left-to-right case we scroll so that the left edge of the
        // selected child is scrolled to the left edge of the scrollbox.
        // In the right-to-left case we scroll so that the right edge of the
        // selected child is scrolled to the right edge of the scrollbox.
-       return scrollableView->ScrollTo((isLTR) ? rect.x :
-                                       rect.x + rect.width - frameWidth, cp.y, 0);
+       sf->ScrollTo(nsPoint(isLTR ? rect.x : rect.x + rect.width - frameWidth,
+                            cp.y),
+                    nsIScrollableFrame::INSTANT);
    else
-       return scrollableView->ScrollTo(cp.x, rect.y, 0);
+       sf->ScrollTo(nsPoint(cp.x, rect.y), nsIScrollableFrame::INSTANT);
+
+   return NS_OK;
 }
 
 /* void scrollToLine (in long line); */
 NS_IMETHODIMP nsScrollBoxObject::ScrollToLine(PRInt32 line)
 {
-  nsIScrollableView* scrollableView = GetScrollableView();
-  if (!scrollableView)
-    return NS_ERROR_FAILURE;
+  nsIScrollableFrame* sf = GetScrollFrame();
+  if (!sf)
+     return NS_ERROR_FAILURE;
   
-  nscoord height = 0;
-  scrollableView->GetLineHeight(&height);
-  scrollableView->ScrollTo(0, height * line, 0);
-
+  nscoord y = sf->GetLineScrollAmount().height * line;
+  sf->ScrollTo(nsPoint(0, y), nsIScrollableFrame::INSTANT);
   return NS_OK;
 }
 
 /* void scrollToElement (in nsIDOMElement child); */
 NS_IMETHODIMP nsScrollBoxObject::ScrollToElement(nsIDOMElement *child)
 {
     NS_ENSURE_ARG_POINTER(child);
-    nsIScrollableView* scrollableView = GetScrollableView();
-    if (!scrollableView)
+    nsIScrollableFrame* sf = GetScrollFrame();
+    if (!sf)
        return NS_ERROR_FAILURE;
 
     nsCOMPtr<nsIPresShell> shell = GetPresShell(PR_FALSE);
     if (!shell) {
       return NS_ERROR_UNEXPECTED;
     }
 
     nsIFrame* scrolledBox = GetScrolledBox(this);
@@ -280,55 +284,50 @@ NS_IMETHODIMP nsScrollBoxObject::ScrollT
     childBoxObject->GetY(&y);
     // get the twips rectangle from the boxobject (which has pixels)    
     rect.x = nsPresContext::CSSPixelsToAppUnits(x);
     rect.y = nsPresContext::CSSPixelsToAppUnits(y);
 
     // TODO: make sure the child is inside the box
 
     // get our current info
-    nsPoint cp;
-    scrollableView->GetScrollPosition(cp.x,cp.y);
-
+    nsPoint cp = sf->GetScrollPosition();
     nsIntRect prect;
     GetOffsetRect(prect);
     crect = prect.ToAppUnits(nsPresContext::AppUnitsPerCSSPixel());
     nscoord newx=cp.x, newy=cp.y;
 
     // we only scroll in the direction of the scrollbox orientation
     // always scroll to left or top edge of child element
     if (scrolledBox->IsHorizontal()) {
         newx = rect.x - crect.x;
     } else {
         newy = rect.y - crect.y;
     }
     // scroll away
-    return scrollableView->ScrollTo(newx, newy, 0);
+    sf->ScrollTo(nsPoint(newx, newy), nsIScrollableFrame::INSTANT);
+    return NS_OK;
 }
 
 /* void scrollToIndex (in long index); */
 NS_IMETHODIMP nsScrollBoxObject::ScrollToIndex(PRInt32 index)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* void getPosition (out long x, out long y); */
 NS_IMETHODIMP nsScrollBoxObject::GetPosition(PRInt32 *x, PRInt32 *y)
 {
-  nsIScrollableView* scrollableView = GetScrollableView();
-  if (!scrollableView)
-    return NS_ERROR_FAILURE;
+  nsIScrollableFrame* sf = GetScrollFrame();
+  if (!sf)
+     return NS_ERROR_FAILURE;
 
-  nscoord xc, yc;
-  nsresult rv = scrollableView->GetScrollPosition(xc, yc);
-  if (NS_FAILED(rv))
-    return rv;
-
-  *x = nsPresContext::AppUnitsToIntCSSPixels(xc);
-  *y = nsPresContext::AppUnitsToIntCSSPixels(yc);
+  nsPoint pt = sf->GetScrollPosition();
+  *x = nsPresContext::AppUnitsToIntCSSPixels(pt.x);
+  *y = nsPresContext::AppUnitsToIntCSSPixels(pt.y);
 
   return NS_OK;  
 }
 
 /* void getScrolledSize (out long width, out long height); */
 NS_IMETHODIMP nsScrollBoxObject::GetScrolledSize(PRInt32 *width, PRInt32 *height)
 {
     nsIFrame* scrolledBox = GetScrolledBox(this);
@@ -363,36 +362,35 @@ NS_IMETHODIMP nsScrollBoxObject::EnsureE
       return NS_ERROR_UNEXPECTED;
 
     PRInt32 x, y, width, height;
     childBoxObject->GetX(&x);
     childBoxObject->GetY(&y);
     childBoxObject->GetWidth(&width);
     childBoxObject->GetHeight(&height);
 
-    nsIScrollableView* scrollableView = GetScrollableView();
-    if (!scrollableView)
+    nsIScrollableFrame* sf = GetScrollFrame();
+    if (!sf)
        return NS_ERROR_FAILURE;
 
     nsIFrame* scrolledBox = GetScrolledBox(this);
     if (!scrolledBox)
        return NS_ERROR_FAILURE;
 
     nsRect rect, crect;
     // get the twips rectangle from the boxobject (which has pixels)    
     rect.x = nsPresContext::CSSPixelsToAppUnits(x);
     rect.y = nsPresContext::CSSPixelsToAppUnits(y);
     rect.width = nsPresContext::CSSPixelsToAppUnits(width);
     rect.height = nsPresContext::CSSPixelsToAppUnits(height);
 
     // TODO: make sure the child is inside the box
 
     // get our current info
-    nsPoint cp;
-    scrollableView->GetScrollPosition(cp.x,cp.y);
+    nsPoint cp = sf->GetScrollPosition();
     nsIntRect prect;
     GetOffsetRect(prect);
     crect = prect.ToAppUnits(nsPresContext::AppUnitsPerCSSPixel());
 
     nscoord newx=cp.x, newy=cp.y;
 
     // we only scroll in the direction of the scrollbox orientation
     if (scrolledBox->IsHorizontal()) {
@@ -405,50 +403,32 @@ NS_IMETHODIMP nsScrollBoxObject::EnsureE
         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, 0);
+    sf->ScrollTo(nsPoint(newx, newy), nsIScrollableFrame::INSTANT);
+    return NS_OK;
 }
 
 /* void ensureIndexIsVisible (in long index); */
 NS_IMETHODIMP nsScrollBoxObject::EnsureIndexIsVisible(PRInt32 index)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* void ensureLineIsVisible (in long line); */
 NS_IMETHODIMP nsScrollBoxObject::EnsureLineIsVisible(PRInt32 line)
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-nsIScrollableView* 
-nsScrollBoxObject::GetScrollableView()
-{
-  // get the frame.
-  nsIFrame* frame = GetFrame(PR_FALSE);
-  if (!frame) 
-    return nsnull;
-  
-  nsIScrollableFrame* scrollFrame = do_QueryFrame(frame);
-  if (!scrollFrame)
-    return nsnull;
-
-  nsIScrollableView* scrollingView = scrollFrame->GetScrollableView();
-  if (!scrollingView)
-    return nsnull;
-
-  return scrollingView;
-}
-
 nsresult
 NS_NewScrollBoxObject(nsIBoxObject** aResult)
 {
   *aResult = new nsScrollBoxObject;
   if (!*aResult)
     return NS_ERROR_OUT_OF_MEMORY;
   NS_ADDREF(*aResult);
   return NS_OK;
--- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
@@ -88,17 +88,16 @@
 #include "nsBoxObject.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 #include "nsBoxLayoutState.h"
 #include "nsIDragService.h"
 #include "nsTreeContentView.h"
 #include "nsTreeUtils.h"
 #include "nsChildIterator.h"
-#include "nsIScrollableView.h"
 #include "nsITheme.h"
 #include "nsITimelineService.h"
 #include "imgIRequest.h"
 #include "imgIContainer.h"
 #include "imgIContainerObserver.h"
 #include "imgILoader.h"
 #include "nsINodeInfo.h"
 #include "nsContentUtils.h"
@@ -843,21 +842,21 @@ nsTreeBodyFrame::InvalidateColumnRange(P
   nsIFrame::Invalidate(rangeRect);
 
   return NS_OK;
 }
 
 static void
 FindScrollParts(nsIFrame* aCurrFrame, nsTreeBodyFrame::ScrollParts* aResult)
 {
-  if (!aResult->mColumnsScrollableView) {
+  if (!aResult->mColumnsScrollFrame) {
     nsIScrollableFrame* f = do_QueryFrame(aCurrFrame);
     if (f) {
       aResult->mColumnsFrame = aCurrFrame;
-      aResult->mColumnsScrollableView = f->GetScrollableView();
+      aResult->mColumnsScrollFrame = f;
     }
   }
   
   nsIScrollbarFrame *sf = do_QueryFrame(aCurrFrame);
   if (sf) {
     if (!aCurrFrame->IsHorizontal()) {
       if (!aResult->mVScrollbar) {
         aResult->mVScrollbar = sf;
@@ -869,17 +868,17 @@ FindScrollParts(nsIFrame* aCurrFrame, ns
     }
     // don't bother searching inside a scrollbar
     return;
   }
   
   nsIFrame* child = aCurrFrame->GetFirstChild(nsnull);
   while (child &&
          (!aResult->mVScrollbar || !aResult->mHScrollbar ||
-          !aResult->mColumnsScrollableView)) {
+          !aResult->mColumnsScrollFrame)) {
     FindScrollParts(child, aResult);
     child = child->GetNextSibling();
   }
 }
 
 nsTreeBodyFrame::ScrollParts nsTreeBodyFrame::GetScrollParts()
 {
   ScrollParts result = { nsnull, nsnull, nsnull, nsnull, nsnull, nsnull };
@@ -2521,25 +2520,24 @@ nsTreeBodyFrame::CalcHorzWidth(const Scr
   // Compute the adjustment to the last column. This varies depending on the
   // visibility of the columnpicker and the scrollbar.
   if (aParts.mColumnsFrame)
     mAdjustWidth = mRect.width - aParts.mColumnsFrame->GetRect().width;
   else
     mAdjustWidth = 0;
 
   nscoord width = 0;
-  nscoord height;
-
-  // We calculate this from the scrollable view, so that it 
+
+  // We calculate this from the scrollable frame, so that it 
   // properly covers all contingencies of what could be 
   // scrollable (columns, body, etc...)
 
-  if (aParts.mColumnsScrollableView) {
-    if (NS_FAILED (aParts.mColumnsScrollableView->GetContainerSize(&width, &height)))
-      width = 0;
+  if (aParts.mColumnsScrollFrame) {
+    width = aParts.mColumnsScrollFrame->GetScrollRange().width +
+      aParts.mColumnsScrollFrame->GetScrollPortRect().width;
   }
 
   // If no horz scrolling periphery is present, then just return our width
   if (width == 0)
     width = mRect.width;
 
   return width;
 }
@@ -4160,17 +4158,17 @@ nsTreeBodyFrame::ScrollInternal(const Sc
 
   PostScrollEvent();
   return NS_OK;
 }
 
 nsresult
 nsTreeBodyFrame::ScrollHorzInternal(const ScrollParts& aParts, PRInt32 aPosition)
 {
-  if (!mView || !aParts.mColumnsScrollableView || !aParts.mHScrollbar)
+  if (!mView || !aParts.mColumnsScrollFrame || !aParts.mHScrollbar)
     return NS_OK;
 
   if (aPosition == mHorzPosition)
     return NS_OK;
 
   if (aPosition < 0 || aPosition > mHorzWidth)
     return NS_OK;
 
@@ -4211,17 +4209,18 @@ nsTreeBodyFrame::ScrollHorzInternal(cons
       } else {
         invalid.width = deltaPt.x;
       }
       widget->Invalidate(invalid, PR_FALSE);
     }
   }
 
   // Update the column scroll view
-  aParts.mColumnsScrollableView->ScrollTo(mHorzPosition, 0, 0);
+  aParts.mColumnsScrollFrame->ScrollTo(nsPoint(mHorzPosition, 0),
+                                       nsIScrollableFrame::INSTANT);
 
   // And fire off an event about it all
   PostScrollEvent();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTreeBodyFrame::ScrollbarButtonPressed(nsIScrollbarFrame* aScrollbar, PRInt32 aOldIndex, PRInt32 aNewIndex)
--- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.h
+++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.h
@@ -173,17 +173,17 @@ public:
   friend class nsTreeColumn;
 
   struct ScrollParts {
     nsIScrollbarFrame*   mVScrollbar;
     nsCOMPtr<nsIContent> mVScrollbarContent;
     nsIScrollbarFrame*   mHScrollbar;
     nsCOMPtr<nsIContent> mHScrollbarContent;
     nsIFrame*            mColumnsFrame;
-    nsIScrollableView*   mColumnsScrollableView;
+    nsIScrollableFrame*  mColumnsScrollFrame;
   };
 
   void PaintTreeBody(nsIRenderingContext& aRenderingContext,
                      const nsRect& aDirtyRect, nsPoint aPt);
 
   nsITreeBoxObject* GetTreeBoxObject() const { return mTreeBoxObject; }
 
   PRBool GetVerticalOverflow() const { return mVerticalOverflow; }