aVscrollbarNeedsReflow = PR_TRUE;
nsGfxScrollFrameInner::ReflowScrollArea(   nsIPresContext*          aPresContext,                                   nsHTMLReflowMetrics&     aDesiredSize,                                   const nsHTMLReflowState& aReflowState,                                   nsReflowStatus&          aStatus,                                   PRBool&                  aHscrollbarNeedsReflow,                                    PRBool&                  aVscrollbarNeedsReflow,                                    PRBool&                  aScrollAreaNeedsReflow,                                    nsIFrame*&               aIncrementalChild){    aVscrollbarNeedsReflow = PR_FALSE;    aHscrollbarNeedsReflow = PR_FALSE;    nsSize scrollAreaSize;    if (!aScrollAreaNeedsReflow) {       // if we don't need to reflow the content area then just use its old size.       GetFrameSize(mScrollAreaFrame, scrollAreaSize);    } else {      // get the current scrollarea size      nsSize oldScrollAreaSize;      GetFrameSize(mScrollAreaFrame, oldScrollAreaSize);      // get the width of the vertical scrollbar and the height of the horizontal scrollbar      nsSize sbSize;      GetScrollbarDimensions(aPresContext, sbSize);      // Compute the scroll area size (area inside of the border edge and inside      // of any vertical and horizontal scrollbars)      nsHTMLReflowMetrics scrollAreaDesiredSize(aDesiredSize.maxElementSize);      CalculateScrollAreaSize(aPresContext, aReflowState, sbSize,                              scrollAreaSize);      // -------- flow the scroll area -----------      nsSize      scrollAreaReflowSize(scrollAreaSize.width, scrollAreaSize.height);      PRBool resized = PR_FALSE;      ReflowFrame(aPresContext, scrollAreaDesiredSize, aReflowState, aStatus, mScrollAreaFrame,                   scrollAreaReflowSize,                  scrollAreaReflowSize,                  resized,                  aIncrementalChild);      // make sure we take into account any children outside our bounds      CalculateChildTotalSize(mScrollAreaFrame, scrollAreaDesiredSize);      // its possible that we will have to do this twice. Its a special case      // when a the scrollarea is exactly the same height as its content but      // the contents width is greater. We will need a horizontal scrollbar      // but the size of the scrollbar will cause the scrollarea to be shorter      // than the content. So we will need a vertical scrollbar. But that could      // require us to squeeze the content. So we would have to reflow. Basically      // we have to start over. Thats why this loop is here.      for (int i=0; i < 1; i++) {        // if we are shrink wrapping the height.         if (NS_INTRINSICSIZE == scrollAreaSize.height) {              // the view port become the size that child requested.              scrollAreaSize.height = scrollAreaDesiredSize.height;              // if we were auto and have a vertical scrollbar remove it because we              // can have whatever size we wanted.              if (aReflowState.mStyleDisplay->mOverflow != NS_STYLE_OVERFLOW_SCROLL                  && aReflowState.mStyleDisplay->mOverflow != NS_STYLE_OVERFLOW_SCROLLBARS_VERTICAL) {                RemoveVerticalScrollbar(sbSize, scrollAreaSize);              }        } else {          // if we are not shrink wrapping          // if we have 'auto' scrollbars          if (aReflowState.mStyleDisplay->mOverflow != NS_STYLE_OVERFLOW_SCROLL              && aReflowState.mStyleDisplay->mOverflow != NS_STYLE_OVERFLOW_SCROLLBARS_VERTICAL) {            // get the ara frame is the scrollarea            nsSize size;            GetScrolledContentSize(aPresContext, size);            PRBool  mustReflow = PR_FALSE;            // There are two cases to consider              if (size.height <= scrollAreaSize.height                  || aReflowState.mStyleDisplay->mOverflow == NS_STYLE_OVERFLOW_SCROLLBARS_HORIZONTAL                  || aReflowState.mStyleDisplay->mOverflow == NS_STYLE_OVERFLOW_SCROLLBARS_NONE) {                if (mHasVerticalScrollbar) {                  // We left room for the vertical scrollbar, but it's not needed;                  // remove it.                  RemoveVerticalScrollbar(sbSize, scrollAreaSize);                  mustReflow = PR_TRUE;                }              } else {                if (!mHasVerticalScrollbar) {                  // We didn't leave room for the vertical scrollbar, but it turns                  // out we needed it                  AddVerticalScrollbar(sbSize, scrollAreaSize);                  mustReflow = PR_TRUE;                  aVscrollbarNeedsReflow = PR_TRUE;                }            }            // Go ahead and reflow the child a second time if we added or removed the scrollbar            if (mustReflow) {              scrollAreaReflowSize.SizeTo(scrollAreaSize.width, scrollAreaSize.height);              resized = PR_FALSE;              ReflowFrame(aPresContext, scrollAreaDesiredSize, aReflowState, aStatus, mScrollAreaFrame,                               scrollAreaReflowSize,                              scrollAreaReflowSize,                              resized,                              aIncrementalChild);                        CalculateChildTotalSize(mScrollAreaFrame, scrollAreaDesiredSize);              //scrollAreaSize.height = scrollAreaDesiredSize.height;            }          }        }              // if we are shrink wrapping the scroll area height becomes whatever the child wanted          if (NS_INTRINSICSIZE == scrollAreaSize.width) {             scrollAreaSize.width = scrollAreaDesiredSize.width;             // if we have auto scrollbars the remove the horizontal scrollbar             if (aReflowState.mStyleDisplay->mOverflow != NS_STYLE_OVERFLOW_SCROLL                 && aReflowState.mStyleDisplay->mOverflow != NS_STYLE_OVERFLOW_SCROLLBARS_HORIZONTAL) {                 RemoveHorizontalScrollbar(sbSize, scrollAreaSize);             }          } else {            // if scrollbars are auto            if ((NS_STYLE_OVERFLOW_SCROLL != aReflowState.mStyleDisplay->mOverflow)                && (NS_STYLE_OVERFLOW_SCROLLBARS_HORIZONTAL != aReflowState.mStyleDisplay->mOverflow))            {              // get the ara frame is the scrollarea              nsSize size;              GetScrolledContentSize(aPresContext, size);              // if the child is wider that the scroll area              // and we don't have a scrollbar add one.              if (size.width > scrollAreaSize.width                  && aReflowState.mStyleDisplay->mOverflow != NS_STYLE_OVERFLOW_SCROLLBARS_VERTICAL                  && aReflowState.mStyleDisplay->mOverflow != NS_STYLE_OVERFLOW_SCROLLBARS_NONE) {                 if (!mHasHorizontalScrollbar) {                     AddHorizontalScrollbar(sbSize, scrollAreaSize);                     // if we added a horizonal scrollbar and we did not have a vertical                     // there is a chance that by adding the horizonal scrollbar we will                     // suddenly need a vertical scrollbar. Is a special case but its                      // important.                     if (!mHasVerticalScrollbar && size.height > scrollAreaSize.height - sbSize.height)                        continue;                }              } else {                  // if the area is smaller or equal to and we have a scrollbar then                  // remove it.                  RemoveHorizontalScrollbar(sbSize, scrollAreaSize);              }            }        }        // always break out of the loop. Only continue if another scrollbar was added.        break;      }      // if the scroll area changed size      if (oldScrollAreaSize != scrollAreaSize)      {        // if the scroll area changed height then signal for reflow of the vertical scrollbar        if (oldScrollAreaSize.height != scrollAreaSize.height)           aVscrollbarNeedsReflow = PR_TRUE;        // if the scroll area changed width then signal for reflow of the horizontal scrollbar        if (oldScrollAreaSize.width != scrollAreaSize.width)           aHscrollbarNeedsReflow = PR_TRUE;      }      nsSize size;      GetScrolledContentSize(aPresContext, size);      float p2t;      aPresContext->GetScaledPixelsToTwips(&p2t);      mOnePixel = NSIntPixelsToTwips(1, p2t);      const nsStyleFont* font;      mOuter->GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&) font);      const nsFont& f = font->mFont;      nsCOMPtr<nsIFontMetrics> fm;      aPresContext->GetMetricsFor(f, getter_AddRefs(fm));      nscoord fontHeight = 1;      fm->GetHeight(fontHeight);      //nscoord curX = GetIntegerAttribute(mHScrollbarFrame, nsXULAtoms::curpos, 0);      //nscoord curY = GetIntegerAttribute(mVScrollbarFrame, nsXULAtoms::curpos, 0);      nscoord maxX = size.width - scrollAreaSize.width;      nscoord maxY = size.height - scrollAreaSize.height;      //if (curX > maxX)      //    curX = maxX;      //if (curY > maxY)       //   curY = maxY;      //SetAttribute(mVScrollbarFrame, nsXULAtoms::curpos, curY);      //SetAttribute(mHScrollbarFrame, nsXULAtoms::curpos, curX);      SetAttribute(mVScrollbarFrame, nsXULAtoms::maxpos, maxY);      SetAttribute(mHScrollbarFrame, nsXULAtoms::maxpos, maxX);      SetAttribute(mVScrollbarFrame, nsXULAtoms::pageincrement, nscoord(scrollAreaSize.height - fontHeight));      SetAttribute(mHScrollbarFrame, nsXULAtoms::pageincrement, nscoord(scrollAreaSize.width - 10*mOnePixel));      SetAttribute(mVScrollbarFrame, nsXULAtoms::increment, fontHeight);      nsIScrollableView* scrollable = GetScrollableView(aPresContext);      scrollable->SetLineHeight(fontHeight);      SetAttribute(mHScrollbarFrame, nsXULAtoms::increment, 10*mOnePixel);      // size the scroll area      // even if it is different from the old size. This is because ReflowFrame set the child's      // frame so we have to make sure our final size is scrollAreaSize      SetFrameSize(aPresContext, mScrollAreaFrame, scrollAreaSize);    } }  