Followup to fix the test for the rightmost column b=306990 r=Enn sr=roc a=dbaron
authorneil@parkwaycc.co.uk
Tue, 04 Sep 2007 02:08:15 -0700
changeset 5625 eabae7d25ace827f5055ec4d26788c6e4c78a412
parent 5624 3e59d2a907436d1eae125fd39cd52238c44b2a6d
child 5626 557f7cc6b6d6e5cf79635ab63966fe8da13ee8b8
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEnn, roc, dbaron
bugs306990
milestone1.9a8pre
Followup to fix the test for the rightmost column b=306990 r=Enn sr=roc a=dbaron
layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
layout/xul/base/src/tree/src/nsTreeColumns.cpp
layout/xul/base/src/tree/src/nsTreeColumns.h
--- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
@@ -3792,17 +3792,17 @@ NS_IMETHODIMP nsTreeBodyFrame::EnsureCel
   nscoord columnPos;
   rv = col->GetXInTwips(this, &columnPos);
   if(NS_FAILED(rv)) return rv;
 
   nscoord columnWidth;
   rv = col->GetWidthInTwips(this, &columnWidth);
   if(NS_FAILED(rv)) return rv;
 
-  if (!col->GetNext())
+  if (col->IsLastVisible(this))
     columnWidth -= mAdjustWidth; // this is one case we don't want to adjust
 
   // If the start of the column is before the
   // start of the horizontal view, then scroll
   if (columnPos < mHorzPosition)
     result = columnPos;
   // If the end of the column is past the end of 
   // the horizontal view, then scroll
--- a/layout/xul/base/src/tree/src/nsTreeColumns.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeColumns.cpp
@@ -107,29 +107,51 @@ nsTreeColumn::GetFrame()
 
   nsIPresShell *shell = document->GetPrimaryShell();
   if (!shell)
     return nsnull;
 
   return shell->GetPrimaryFrameFor(mContent);
 }
 
+PRBool
+nsTreeColumn::IsLastVisible(nsTreeBodyFrame* aBodyFrame)
+{
+  NS_ASSERTION(GetFrame(aBodyFrame), "should have checked for this already");
+
+  // cyclers are fixed width, don't adjust them
+  if (IsCycler())
+    return PR_FALSE;
+
+  // we're certainly not the last visible if we're not visible
+  if (GetFrame(aBodyFrame)->GetRect().width == 0)
+    return PR_FALSE;
+
+  // try to find a visible successor
+  for (nsTreeColumn *next = GetNext(); next; next = next->GetNext()) {
+    nsIFrame* frame = next->GetFrame(aBodyFrame);
+    if (frame && frame->GetRect().width > 0)
+      return PR_FALSE;
+  }
+  return PR_TRUE;
+}
+
 nsresult
 nsTreeColumn::GetRect(nsTreeBodyFrame* aBodyFrame, nscoord aY, nscoord aHeight, nsRect* aResult)
 {
   nsIFrame* frame = GetFrame(aBodyFrame);
   if (!frame) {
     *aResult = nsRect();
     return NS_ERROR_FAILURE;
   }
 
   *aResult = frame->GetRect();
   aResult->y = aY;
   aResult->height = aHeight;
-  if (!GetNext())
+  if (IsLastVisible(aBodyFrame))
     aResult->width += aBodyFrame->mAdjustWidth;
   return NS_OK;
 }
 
 nsresult
 nsTreeColumn::GetXInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult)
 {
   nsIFrame* frame = GetFrame(aBodyFrame);
@@ -145,17 +167,17 @@ nsresult
 nsTreeColumn::GetWidthInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult)
 {
   nsIFrame* frame = GetFrame(aBodyFrame);
   if (!frame) {
     *aResult = 0;
     return NS_ERROR_FAILURE;
   }
   *aResult = frame->GetRect().width;
-  if (!GetNext())
+  if (IsLastVisible(aBodyFrame))
     *aResult += aBodyFrame->mAdjustWidth;
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsTreeColumn::GetElement(nsIDOMElement** aElement)
 {
--- a/layout/xul/base/src/tree/src/nsTreeColumns.h
+++ b/layout/xul/base/src/tree/src/nsTreeColumns.h
@@ -59,16 +59,18 @@ public:
   NS_DECL_NSITREECOLUMN
 
   friend class nsTreeBodyFrame;
   friend class nsTreeColumns;
 
 protected:
   nsIFrame* GetFrame();
   nsIFrame* GetFrame(nsTreeBodyFrame* aBodyFrame);
+  // Don't call this if GetWidthInTwips or GetRect fails
+  PRBool IsLastVisible(nsTreeBodyFrame* aBodyFrame);
 
   /**
    * Returns a rect with x and width taken from the frame's rect and specified
    * y and height. May fail in case there's no frame for the column.
    */
   nsresult GetRect(nsTreeBodyFrame* aBodyFrame, nscoord aY, nscoord aHeight,
                    nsRect* aResult);