Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes
nsGfxScrollFrameInner Class Reference

#include <nsGfxScrollFrame.h>

Inheritance diagram for nsGfxScrollFrameInner:
Inheritance graph
[legend]
Collaboration diagram for nsGfxScrollFrameInner:
Collaboration graph
[legend]

List of all members.

Public Types

typedef
nsIScrollableFrame::ScrollbarStyles 
ScrollbarStyles

Public Member Functions

NS_IMETHOD QueryInterface (REFNSIID aIID, void **aInstancePtr)
 NS_IMETHOD_ (nsrefcnt) AddRef(void)
 NS_IMETHOD_ (nsrefcnt) Release(void)
 nsGfxScrollFrameInner (nsContainerFrame *aOuter, PRBool aIsRoot)
 ~nsGfxScrollFrameInner ()
ScrollbarStyles GetScrollbarStylesFromFrame () const
void ReloadChildFrames ()
PRBool NeedsClipWidget () const
void CreateScrollableView ()
void CreateAnonymousContent (nsISupportsArray &aAnonymousChildren)
void PostScrollPortEvent (PRBool aOverflow, nsScrollPortEvent::orientType aType)
void PostOverflowEvents ()
nsresult GetChildContentAndOffsetsFromPoint (nsPresContext *aCX, const nsPoint &aPoint, nsIContent **aNewContent, PRInt32 &aContentOffset, PRInt32 &aContentOffsetEnd, PRBool &aBeginFrameContent)
NS_IMETHOD ScrollPositionWillChange (nsIScrollableView *aScrollable, nscoord aX, nscoord aY)
NS_IMETHOD ScrollPositionDidChange (nsIScrollableView *aScrollable, nscoord aX, nscoord aY)
 Called whenever actual scrolling happens for any reason.
void CurPosAttributeChanged (nsIContent *aChild, PRInt32 aModType)
void PostScrollEvent ()
void FireScrollEvent ()
void SetScrollbarEnabled (nsIBox *aBox, nscoord aMaxPos, PRBool aReflow=PR_TRUE)
PRBool SetAttribute (nsIBox *aBox, nsIAtom *aAtom, nscoord aSize, PRBool aReflow=PR_TRUE)
 Returns whether it actually needed to change the attribute.
PRInt32 GetIntegerAttribute (nsIBox *aFrame, nsIAtom *atom, PRInt32 defaultValue)
void AdjustHorizontalScrollbar ()
 If RTL, then this will scroll to the right during initial layout.
void InternalScrollPositionDidChange (nscoord aX, nscoord aY)
 Called when we want to update the scrollbar position, either because scrolling happened or the user moved the scrollbar position and we need to undo that (e.g., when the user clicks to scroll and we're using smooth scrolling, so we need to put the thumb back to its initial position for the start of the smooth sequence).
nsIScrollableViewGetScrollableView () const
nsIViewGetParentViewForChildFrame (nsIFrame *aFrame) const
void ScrollToRestoredPosition ()
 this code is resposible for restoring the scroll position back to some saved positon.
nsPresStateSaveState ()
void RestoreState (nsPresState *aState)
nsIFrameGetScrolledFrame () const
void ScrollbarChanged (nsPresContext *aPresContext, nscoord aX, nscoord aY, PRUint32 aFlags)
nsSize GetScrolledSize () const
nsMargin GetActualScrollbarSizes () const
nsMargin GetDesiredScrollbarSizes (nsBoxLayoutState *aState)
PRBool IsScrollbarOnRight ()
void LayoutScrollbars (nsBoxLayoutState &aState, const nsRect &aContentArea, const nsRect &aOldScrollArea, const nsRect &aScrollArea)

Static Public Member Functions

static void SetScrollbarVisibility (nsIBox *aScrollbar, PRBool aVisible)

Public Attributes

nsCOMPtr< nsIEventQueuemScrollEventQueue
nsIScrollableViewmScrollableView
nsIBox * mHScrollbarBox
nsIBox * mVScrollbarBox
nsIFramemScrolledFrame
nsIBox * mScrollCornerBox
nsContainerFramemOuter
nscoord mOnePixel
nsRect mRestoreRect
nsPoint mLastPos
PRInt16 mLastDir
PRPackedBool mNeverHasVerticalScrollbar:1
PRPackedBool mNeverHasHorizontalScrollbar:1
PRPackedBool mHasVerticalScrollbar:1
PRPackedBool mHasHorizontalScrollbar:1
PRPackedBool mViewInitiatedScroll:1
PRPackedBool mFrameInitiatedScroll:1
PRPackedBool mDidHistoryRestore:1
PRPackedBool mIsRoot:1
PRPackedBool mSupppressScrollbarUpdate:1
PRPackedBool mHorizontalOverflow:1
PRPackedBool mVerticalOverflow:1

Detailed Description

Definition at line 60 of file nsGfxScrollFrame.h.


Member Typedef Documentation

Definition at line 69 of file nsGfxScrollFrame.h.


Constructor & Destructor Documentation

Definition at line 1335 of file nsGfxScrollFrame.cpp.

{
  if (mScrollEventQueue) {
    mScrollEventQueue->RevokeEvents(this);
  }
}

Member Function Documentation

If RTL, then this will scroll to the right during initial layout.

Definition at line 1923 of file nsGfxScrollFrame.cpp.

{
#ifdef IBMBIDI
  const nsStyleVisibility* vis = mOuter->GetStyleVisibility();

  // Scroll the view horizontally if:
  // 1)  We are creating the scrollbar for the first time and the
  //     horizontal scroll position of the view is 0 or
  // 2)  The display direction is changed
  PRBool needScroll;
  if (mLastDir == -1) {
    // Creating the scrollbar the first time
    nscoord curPosX = 0, curPosY = 0;
    nsIScrollableView* s = GetScrollableView();
    if (s) {
      s->GetScrollPosition(curPosX, curPosY);
    }
    needScroll = (curPosX == 0);
  } else {
    needScroll = (mLastDir != vis->mDirection);
  }
  if (needScroll) {
    SetAttribute(mHScrollbarBox, nsXULAtoms::curpos,
                 (NS_STYLE_DIRECTION_LTR == vis->mDirection) ? 0 : 0x7FFFFFFF);
  }
  mLastDir = vis->mDirection;
#endif // IBMBIDI
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1648 of file nsGfxScrollFrame.cpp.

{
  nsPresContext* presContext = mOuter->GetPresContext();
  nsIFrame* parent = mOuter->GetParent();

  // Don't create scrollbars if we're printing/print previewing
  // Get rid of this code when printing moves to its own presentation
  if (presContext->IsPaginated()) {
    // allow scrollbars if this is the child of the viewport, because
    // we must be the scrollbars for the print preview window
    if (!mIsRoot) {
      mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = PR_TRUE;
      return;
    }
  }

  nsIScrollableFrame *scrollable;
  CallQueryInterface(mOuter, &scrollable);

  // At this stage in frame construction, the document element and/or
  // BODY overflow styles have not yet been propagated to the
  // viewport. So GetScrollbarStylesFromFrame called here will only
  // take into account the scrollbar preferences set on the docshell.
  // Thus if no scrollbar preferences are set on the docshell, we will
  // always create scrollbars, which means later dynamic changes to
  // propagated overflow styles will show or hide scrollbars on the
  // viewport without requiring frame reconstruction of the viewport
  // (good!).

  // XXX On the other hand, if scrolling="no" is set on the container
  // we won't create scrollbars here so no scrollbars will ever be
  // created even if the container's scrolling attribute is later
  // changed. However, this has never been supported.
  ScrollbarStyles styles = scrollable->GetScrollbarStyles();
  PRBool canHaveHorizontal = styles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN;
  PRBool canHaveVertical = styles.mVertical != NS_STYLE_OVERFLOW_HIDDEN;
  if (!canHaveHorizontal && !canHaveVertical)
    // Nothing to do.
    return;

  // The anonymous <div> used by <inputs> never gets scrollbars.
  nsCOMPtr<nsITextControlFrame> textFrame(do_QueryInterface(parent));
  if (textFrame) {
    // Make sure we are not a text area.
    nsCOMPtr<nsIDOMHTMLTextAreaElement> textAreaElement(do_QueryInterface(parent->GetContent()));
    if (!textAreaElement) {
      mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = PR_TRUE;
      return;
    }
  }

  nsNodeInfoManager *nodeInfoManager =
    presContext->GetDocument()->NodeInfoManager();
  nsCOMPtr<nsINodeInfo> nodeInfo;
  nodeInfoManager->GetNodeInfo(nsXULAtoms::scrollbar, nsnull,
                               kNameSpaceID_XUL, getter_AddRefs(nodeInfo));

  nsCOMPtr<nsIContent> content;

  if (canHaveHorizontal) {
    NS_NewElement(getter_AddRefs(content), kNameSpaceID_XUL, nodeInfo);
    content->SetAttr(kNameSpaceID_None, nsXULAtoms::orient,
                     NS_LITERAL_STRING("horizontal"), PR_FALSE);
    aAnonymousChildren.AppendElement(content);
  }

  if (canHaveVertical) {
    NS_NewElement(getter_AddRefs(content), kNameSpaceID_XUL, nodeInfo);
    content->SetAttr(kNameSpaceID_None, nsXULAtoms::orient,
                     NS_LITERAL_STRING("vertical"), PR_FALSE);
    aAnonymousChildren.AppendElement(content);
  }

  if (canHaveHorizontal && canHaveVertical) {
    nodeInfoManager->GetNodeInfo(nsXULAtoms::scrollcorner, nsnull,
                                 kNameSpaceID_XUL, getter_AddRefs(nodeInfo));
    NS_NewElement(getter_AddRefs(content), kNameSpaceID_XUL, nodeInfo);
    aAnonymousChildren.AppendElement(content);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1402 of file nsGfxScrollFrame.cpp.

{
  nsIView* outerView = mOuter->GetView();
  NS_ASSERTION(outerView, "scrollframes must have views");
  nsIViewManager* viewManager = outerView->GetViewManager();
  mScrollableView = viewManager->CreateScrollableView(mOuter->GetRect(), outerView);
  if (!mScrollableView)
    return;

  nsIView* view = mScrollableView->View();

  // Insert the view into the view hierarchy
  viewManager->InsertChild(outerView, view, nsnull, PR_TRUE);

  // Have the scrolling view create its internal widgets
  if (NeedsClipWidget()) {
    mScrollableView->CreateScrollControls(); 
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1769 of file nsGfxScrollFrame.cpp.

{
  NS_ASSERTION(aContent, "aContent must not be null");

  // Attribute changes on the scrollbars happen in one of three ways:
  // 1) The scrollbar changed the attribute in response to some user event
  // 2) We changed the attribute in response to a ScrollPositionDidChange
  // callback from the scrolling view
  // 3) We changed the attribute to adjust the scrollbars for the start
  // of a smooth scroll operation
  //
  // In case 2), we don't need to scroll the view because the scrolling
  // has already happened. In case 3) we don't need to scroll because
  // we're just adjusting the scrollbars back to the correct setting
  // for the view.
  //
  // Cases 1) and 3) do not indicate that actual scrolling has happened. Only
  // case 2) indicates actual scrolling. Therefore we do not fire onscroll
  // here, but in ScrollPositionDidChange.
  // 
  // We used to detect this case implicitly because we'd compare the
  // scrollbar attributes with the view's current scroll position and
  // bail out if they were equal. But that approach is fragile; it can
  // fail when, for example, the view scrolls horizontally and
  // vertically simultaneously; we'll get here when only the vertical
  // attribute has been set, so the attributes and the view scroll
  // position don't yet agree, and we'd tell the view to scroll to the
  // new vertical position and the old horizontal position! Even worse
  // things could happen when smooth scrolling got involved ... crashes
  // and other terrors.
  if (mViewInitiatedScroll || mFrameInitiatedScroll) return;

  nsIContent* vcontent = mVScrollbarBox ? mVScrollbarBox->GetContent() : nsnull;
  nsIContent* hcontent = mHScrollbarBox ? mHScrollbarBox->GetContent() : nsnull;

  if (hcontent == aContent || vcontent == aContent)
  {
    nscoord x = 0;
    nscoord y = 0;

    nsAutoString value;
    if (hcontent && NS_CONTENT_ATTR_HAS_VALUE == hcontent->GetAttr(kNameSpaceID_None, nsXULAtoms::curpos, value))
    {
      PRInt32 error;

      // convert it to an integer
      x = value.ToInteger(&error);
    }

    if (vcontent && NS_CONTENT_ATTR_HAS_VALUE == vcontent->GetAttr(kNameSpaceID_None, nsXULAtoms::curpos, value))
    {
      PRInt32 error;

      // convert it to an integer
      y = value.ToInteger(&error);
    }

    // Make sure the scrollbars indeed moved before firing the event.
    // I think it is OK to prevent the call to ScrollbarChanged()
    // if we didn't actually move. The following check is the first
    // thing ScrollbarChanged() does anyway, before deciding to move 
    // the scrollbars. 
    nscoord curPosX=0, curPosY=0;
    nsIScrollableView* s = GetScrollableView();
    if (s) {
      s->GetScrollPosition(curPosX, curPosY);
      if ((x*mOnePixel) == curPosX && (y*mOnePixel) == curPosY)
        return;

      PRBool isSmooth = aContent->HasAttr(kNameSpaceID_None, nsXULAtoms::smooth);
        
      if (isSmooth) {
        // Make sure an attribute-setting callback occurs even if the view didn't actually move yet
        // We need to make sure other listeners see that the scroll position is not (yet)
        // what they thought it was.
        s->GetScrollPosition(curPosX, curPosY);

        NS_ASSERTION(!mFrameInitiatedScroll, "Unexpected reentry");
        // Make sure we don't do anything in when the view calls us back for this
        // scroll operation.
        mFrameInitiatedScroll = PR_TRUE;
        InternalScrollPositionDidChange(curPosX, curPosY);
        mFrameInitiatedScroll = PR_FALSE;
      }
      ScrollbarChanged(mOuter->GetPresContext(), x*mOnePixel, y*mOnePixel, isSmooth ? NS_VMREFRESH_SMOOTHSCROLL : 0);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1874 of file nsGfxScrollFrame.cpp.

{
  mScrollEventQueue = nsnull;

  nsScrollbarEvent event(PR_TRUE, NS_SCROLL_EVENT, nsnull);
  nsEventStatus status = nsEventStatus_eIgnore;
  nsIContent* content = mOuter->GetContent();
  nsPresContext* prescontext = mOuter->GetPresContext();
  // Fire viewport scroll events at the document (where they
  // will bubble to the window)
  if (mIsRoot) {
    nsIDocument* doc = content->GetCurrentDoc();
    if (doc) {
      doc->HandleDOMEvent(prescontext, &event, nsnull,
                          NS_EVENT_FLAG_INIT, &status);
    }
  } else {
    nsCOMPtr<nsIPresShell> shell = prescontext->PresShell();
    shell->HandleEventWithTarget(&event, mOuter, content, NS_EVENT_FLAG_INIT,
                                 &status);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2566 of file nsGfxScrollFrame.cpp.

                                                     {
  nsMargin border;
  mOuter->GetBorder(border);
  nsRect r(nsPoint(0,0), mOuter->GetSize());
  r.Deflate(border);
  nsRect scrollArea = mScrollableView->View()->GetBounds();

  return nsMargin(scrollArea.x - r.x, scrollArea.y - r.y,
                  r.XMost() - scrollArea.XMost(),
                  r.YMost() - scrollArea.YMost());
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsGfxScrollFrameInner::GetChildContentAndOffsetsFromPoint ( nsPresContext aCX,
const nsPoint aPoint,
nsIContent **  aNewContent,
PRInt32 aContentOffset,
PRInt32 aContentOffsetEnd,
PRBool aBeginFrameContent 
)

Definition at line 1383 of file nsGfxScrollFrame.cpp.

{
  // We need to overrride this to ensure that scrollbars are ignored

  // Since we definitely have a view, aPoint is relative to this frame's view. We
  // need to make it relative to the scrolled frame.
  nsPoint point = aPoint - mScrollableView->View()->GetOffsetTo(mOuter->GetView());

  return mScrolledFrame->GetContentAndOffsetsFromPoint(aCX, point, aNewContent,
                                                       aContentOffset, aContentOffsetEnd, 
                                                       aBeginFrameContent);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 973 of file nsGfxScrollFrame.cpp.

                                                                                 {
  nsMargin result(0, 0, 0, 0);

  if (mVScrollbarBox) {
    nsSize size;
    mVScrollbarBox->GetPrefSize(*aState, size);
    nsBox::AddMargin(mVScrollbarBox, size);
#ifdef IBMBIDI
    if (IsScrollbarOnRight())
      result.left = size.width;
    else
#endif
      result.right = size.width;
  }

  if (mHScrollbarBox) {
    nsSize size;
    mHScrollbarBox->GetPrefSize(*aState, size);
    nsBox::AddMargin(mHScrollbarBox, size);
    // We don't currently support any scripts that would require a scrollbar
    // at the top. (Are there any?)
    result.bottom = size.height;
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsGfxScrollFrameInner::GetIntegerAttribute ( nsIBox *  aFrame,
nsIAtom atom,
PRInt32  defaultValue 
)

Definition at line 2597 of file nsGfxScrollFrame.cpp.

{
    nsIContent* content = aBox->GetContent();

    nsAutoString value;
    if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, atom, value))
    {
      PRInt32 error;

      // convert it to an integer
      defaultValue = value.ToInteger(&error);
    }

    return defaultValue;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1441 of file nsGfxScrollFrame.cpp.

{
  if (aFrame->GetContent() == mOuter->GetContent()) {
    NS_ASSERTION(mScrollableView, "Scrollable view should have been created by now");
    // scrolled frame, put it under our anonymous view
    return mScrollableView->View();
  }
  // scrollbars and stuff; put them under our regular view
  return mOuter->GetView();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 113 of file nsGfxScrollFrame.h.

{ return mScrollableView; }

Here is the caller graph for this function:

Definition at line 1453 of file nsGfxScrollFrame.cpp.

{
  ScrollbarStyles result;
  if (mIsRoot) {
    nsPresContext *presContext = mOuter->GetPresContext();
    result = presContext->GetViewportOverflowOverride();

    nsCOMPtr<nsISupports> container = presContext->GetContainer();
    if (container) {
      nsCOMPtr<nsIScrollable> scrollable = do_QueryInterface(container);
      HandleScrollPref(scrollable, nsIScrollable::ScrollOrientation_X,
                       result.mHorizontal);
      HandleScrollPref(scrollable, nsIScrollable::ScrollOrientation_Y,
                       result.mVertical);
    }
  } else {
    const nsStyleDisplay *disp = mOuter->GetStyleDisplay();
    result.mHorizontal = disp->mOverflowX;
    result.mVertical = disp->mOverflowY;
  }

  NS_ASSERTION(result.mHorizontal != NS_STYLE_OVERFLOW_VISIBLE &&
               result.mHorizontal != NS_STYLE_OVERFLOW_CLIP &&
               result.mVertical != NS_STYLE_OVERFLOW_VISIBLE &&
               result.mVertical != NS_STYLE_OVERFLOW_CLIP,
               "scrollbars should not have been created");
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 122 of file nsGfxScrollFrame.h.

{ return mScrolledFrame; }

Here is the caller graph for this function:

Definition at line 2559 of file nsGfxScrollFrame.cpp.

{
  nsRect r = mScrolledFrame->GetOverflowRect();
  return nsSize(r.XMost(), r.YMost());
}

Here is the call graph for this function:

Here is the caller graph for this function:

Called when we want to update the scrollbar position, either because scrolling happened or the user moved the scrollbar position and we need to undo that (e.g., when the user clicks to scroll and we're using smooth scrolling, so we need to put the thumb back to its initial position for the start of the smooth sequence).

Definition at line 1743 of file nsGfxScrollFrame.cpp.

{
  if (mVScrollbarBox)
    SetAttribute(mVScrollbarBox, nsXULAtoms::curpos, aY);
  
  if (mHScrollbarBox)
    SetAttribute(mHScrollbarBox, nsXULAtoms::curpos, aX);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2202 of file nsGfxScrollFrame.cpp.

{
#ifdef IBMBIDI
  //TODO make bidi code set these from preferences
  const nsStyleVisibility* vis = mOuter->GetStyleVisibility();
  return vis->mDirection != NS_STYLE_DIRECTION_RTL;
#else
  return PR_TRUE;
#endif // IBMBIDI
}

Here is the caller graph for this function:

void nsGfxScrollFrameInner::LayoutScrollbars ( nsBoxLayoutState aState,
const nsRect aContentArea,
const nsRect aOldScrollArea,
const nsRect aScrollArea 
)

Definition at line 2403 of file nsGfxScrollFrame.cpp.

{
  NS_ASSERTION(!mSupppressScrollbarUpdate,
               "This should have been suppressed");
    
  nsPresContext* presContext = aState.PresContext();
  mOnePixel = presContext->IntScaledPixelsToTwips(1);
  const nsStyleFont* font = mOuter->GetStyleFont();
  const nsFont& f = font->mFont;
  nsCOMPtr<nsIFontMetrics> fm = presContext->GetMetricsFor(f);
  nscoord fontHeight = 1;
  NS_ASSERTION(fm,"FontMetrics is null assuming fontHeight == 1");
  if (fm)
    fm->GetHeight(fontHeight);

  nsSize scrolledContentSize = GetScrolledSize();

  nscoord maxX = scrolledContentSize.width - aScrollArea.width;
  nscoord maxY = scrolledContentSize.height - aScrollArea.height;

  nsIScrollableView* scrollable = GetScrollableView();
  scrollable->SetLineHeight(fontHeight);

  if (mVScrollbarBox) {
    NS_PRECONDITION(mVScrollbarBox->IsBoxFrame(), "Must be a box frame!");
    if (!mHasVerticalScrollbar) {
      SetAttribute(mVScrollbarBox, nsXULAtoms::curpos, 0);
    }
    SetScrollbarEnabled(mVScrollbarBox, maxY);
    SetAttribute(mVScrollbarBox, nsXULAtoms::maxpos, maxY);
    SetAttribute(mVScrollbarBox, nsXULAtoms::pageincrement, nscoord(aScrollArea.height - fontHeight));
    SetAttribute(mVScrollbarBox, nsXULAtoms::increment, fontHeight);

    nsRect vRect(aScrollArea);
    vRect.width = aContentArea.width - aScrollArea.width;
    vRect.x = IsScrollbarOnRight() ? aScrollArea.XMost() : aContentArea.x;
    nsMargin margin;
    mVScrollbarBox->GetMargin(margin);
    vRect.Deflate(margin);
    nsBoxFrame::LayoutChildAt(aState, mVScrollbarBox, vRect);
  }
    
  if (mHScrollbarBox) {
    NS_PRECONDITION(mHScrollbarBox->IsBoxFrame(), "Must be a box frame!");
    if (!mHasHorizontalScrollbar) {
      SetAttribute(mHScrollbarBox, nsXULAtoms::curpos, 0);
    }
    SetScrollbarEnabled(mHScrollbarBox, maxX);
    SetAttribute(mHScrollbarBox, nsXULAtoms::maxpos, maxX);
    SetAttribute(mHScrollbarBox, nsXULAtoms::pageincrement, nscoord(float(aScrollArea.width)*0.8));
    SetAttribute(mHScrollbarBox, nsXULAtoms::increment, 10*mOnePixel);

    nsRect hRect(aScrollArea);
    hRect.height = aContentArea.height - aScrollArea.height;
    hRect.y = PR_TRUE ? aScrollArea.YMost() : aContentArea.y;
    nsMargin margin;
    mHScrollbarBox->GetMargin(margin);
    hRect.Deflate(margin);
    nsBoxFrame::LayoutChildAt(aState, mHScrollbarBox, hRect);
  }

  // place the scrollcorner
  if (mScrollCornerBox) {
    NS_PRECONDITION(mScrollCornerBox->IsBoxFrame(), "Must be a box frame!");
    nsRect r(0, 0, 0, 0);
    if (aContentArea.x != aScrollArea.x) {
      // scrollbar (if any) on left
      r.x = aContentArea.x;
      r.width = aScrollArea.x - aContentArea.x;
      NS_ASSERTION(r.width >= 0, "Scroll area should be inside client rect");
    } else {
      // scrollbar (if any) on right
      r.x = aScrollArea.XMost();
      r.width = aContentArea.XMost() - aScrollArea.XMost();
      NS_ASSERTION(r.width >= 0, "Scroll area should be inside client rect");
    }
    if (aContentArea.y != aScrollArea.y) {
      // scrollbar (if any) on top
      r.y = aContentArea.y;
      r.height = aScrollArea.y - aContentArea.y;
      NS_ASSERTION(r.height >= 0, "Scroll area should be inside client rect");
    } else {
      // scrollbar (if any) on bottom
      r.y = aScrollArea.YMost();
      r.height = aContentArea.YMost() - aScrollArea.YMost();
      NS_ASSERTION(r.height >= 0, "Scroll area should be inside client rect");
    }
    nsBoxFrame::LayoutChildAt(aState, mScrollCornerBox, r); 
  }

  // may need to update fixed position children of the viewport,
  // if the client area changed size because of some dirty reflow
  // (if the reflow is initial or resize, the fixed children will
  // be re-laid out anyway)
  if (aOldScrollArea.Size() != aScrollArea.Size()
      && nsBoxLayoutState::Dirty == aState.LayoutReason() &&
      mIsRoot) {
    // Usually there are no fixed children, so don't do anything unless there's
    // at least one fixed child
    nsIFrame* parentFrame = mOuter->GetParent();
    if (parentFrame->GetFirstChild(nsLayoutAtoms::fixedList)) {
      // force a reflow of the fixed children
      mOuter->GetPresContext()->PresShell()->
        AppendReflowCommand(parentFrame, eReflowType_UserDefined,
                            nsLayoutAtoms::fixedList);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1355 of file nsGfxScrollFrame.cpp.

{
  // Scrollports contained in form controls (e.g., listboxes) don't get
  // widgets.
  for (nsIFrame* parentFrame = mOuter; parentFrame;
       parentFrame = parentFrame->GetParent()) {
    nsIFormControlFrame* fcFrame;
    if ((NS_SUCCEEDED(parentFrame->QueryInterface(NS_GET_IID(nsIFormControlFrame), (void**)&fcFrame)))) {
      return PR_FALSE;
    }
  }

  // Scrollports that don't ever show associated scrollbars don't get
  // widgets, because they will seldom actually be scrolled.
  nsIScrollableFrame *scrollableFrame;
  CallQueryInterface(mOuter, &scrollableFrame);
  ScrollbarStyles scrollbars = scrollableFrame->GetScrollbarStyles();
  if ((scrollbars.mHorizontal == NS_STYLE_OVERFLOW_HIDDEN
       || scrollbars.mHorizontal == NS_STYLE_OVERFLOW_VISIBLE)
      && (scrollbars.mVertical == NS_STYLE_OVERFLOW_HIDDEN
          || scrollbars.mVertical == NS_STYLE_OVERFLOW_VISIBLE)) {
    return PR_FALSE;
  }
 
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2168 of file nsGfxScrollFrame.cpp.

{
  nsSize childSize = mScrolledFrame->GetSize();
  nsSize scrollportSize = mScrollableView->View()->GetBounds().Size();
    
  PRBool newVerticalOverflow = childSize.height > scrollportSize.height;
  PRBool vertChanged = mVerticalOverflow != newVerticalOverflow;
  mVerticalOverflow = newVerticalOverflow;

  PRBool newHorizontalOverflow = childSize.width > scrollportSize.width;
  PRBool horizChanged = mHorizontalOverflow != newHorizontalOverflow;
  mHorizontalOverflow = newHorizontalOverflow;

  if (vertChanged) {
    if (horizChanged) {
      if (mVerticalOverflow == mHorizontalOverflow) {
        // both either overflowed or underflowed. 1 event
        PostScrollPortEvent(mVerticalOverflow, nsScrollPortEvent::both);
      } else {
        // one overflowed and one underflowed
        PostScrollPortEvent(mVerticalOverflow, nsScrollPortEvent::vertical);
        PostScrollPortEvent(mHorizontalOverflow, nsScrollPortEvent::horizontal);
      }
    } else {
      PostScrollPortEvent(mVerticalOverflow, nsScrollPortEvent::vertical);
    }
  } else {
    if (horizChanged) {
      PostScrollPortEvent(mHorizontalOverflow, nsScrollPortEvent::horizontal);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1898 of file nsGfxScrollFrame.cpp.

{
  nsCOMPtr<nsIEventQueueService> service = do_GetService(kEventQueueServiceCID);
  NS_ASSERTION(service, "No event service");
  nsCOMPtr<nsIEventQueue> eventQueue;
  service->GetSpecialEventQueue(
    nsIEventQueueService::UI_THREAD_EVENT_QUEUE, getter_AddRefs(eventQueue));
  NS_ASSERTION(eventQueue, "Event queue is null");

  if (eventQueue == mScrollEventQueue)
    return;
    
  PLEvent* ev = new PLEvent;
  if (!ev)
    return;
  PL_InitEvent(ev, this, ::HandleScrollEvent, ::DestroyScrollEvent);  

  if (mScrollEventQueue) {
    mScrollEventQueue->RevokeEvents(this);
  }
  eventQueue->PostEvent(ev);
  mScrollEventQueue = eventQueue;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1575 of file nsGfxScrollFrame.cpp.

{
  nsScrollPortEvent* event = new nsScrollPortEvent(PR_TRUE, aOverflow ?
                                                   NS_SCROLLPORT_OVERFLOW :
                                                   NS_SCROLLPORT_UNDERFLOW,
                                                   nsnull);
  if (!event) {
    return;
  }
  event->orient = aType;
  nsCOMPtr<nsIEventQueueService> eventService =
    do_GetService(kEventQueueServiceCID);
  if (eventService) {
    nsCOMPtr<nsIEventQueue> eventQueue;
    eventService->GetThreadEventQueue(PR_GetCurrentThread(),
                                      getter_AddRefs(eventQueue));
    if (eventQueue) {
      nsAsyncScrollPortEvent* scrollPortEvent =
        new nsAsyncScrollPortEvent(mOuter->GetContent(), mOuter->GetPresContext(),
                                 event);
      if (scrollPortEvent) {
        PL_InitEvent(scrollPortEvent, nsnull,
                     ::HandleAsyncScrollPortEvent,
                     ::DestroyAsyncScrollPortEvent);
        if (NS_SUCCEEDED(eventQueue->PostEvent(scrollPortEvent))) {
          return;
        }
        PL_DestroyEvent(scrollPortEvent);
        return;
      }
    }
  }
  delete event;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1611 of file nsGfxScrollFrame.cpp.

{
  mScrolledFrame = nsnull;
  mHScrollbarBox = nsnull;
  mVScrollbarBox = nsnull;
  mScrollCornerBox = nsnull;

  nsIFrame* frame = mOuter->GetFirstChild(nsnull);
  while (frame) {
    nsIContent* content = frame->GetContent();
    if (content == mOuter->GetContent()) {
      NS_ASSERTION(!mScrolledFrame, "Already found the scrolled frame");
      mScrolledFrame = frame;
    } else {
      nsAutoString value;
      if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None,
                                                        nsXULAtoms::orient, value)) {
        // probably a scrollbar then
        if (value.LowerCaseEqualsLiteral("horizontal")) {
          NS_ASSERTION(!mHScrollbarBox, "Found multiple horizontal scrollbars?");
          mHScrollbarBox = frame;
        } else {
          NS_ASSERTION(!mVScrollbarBox, "Found multiple vertical scrollbars?");
          mVScrollbarBox = frame;
        }
      } else {
        // probably a scrollcorner
        NS_ASSERTION(!mScrollCornerBox, "Found multiple scrollcorners");
        mScrollCornerBox = frame;
      }
    }

    frame = frame->GetNextSibling();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2674 of file nsGfxScrollFrame.cpp.

{
  nsCOMPtr<nsISupportsPRInt32> xoffset;
  nsCOMPtr<nsISupportsPRInt32> yoffset;
  nsCOMPtr<nsISupportsPRInt32> width;
  nsCOMPtr<nsISupportsPRInt32> height;
  aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("x-offset"), getter_AddRefs(xoffset));
  aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("y-offset"), getter_AddRefs(yoffset));
  aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("width"), getter_AddRefs(width));
  aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("height"), getter_AddRefs(height));

  if (xoffset && yoffset) {
    PRInt32 x,y,w,h;
    nsresult rv = xoffset->GetData(&x);
    if (NS_SUCCEEDED(rv))
      rv = yoffset->GetData(&y);
    if (NS_SUCCEEDED(rv))
      rv = width->GetData(&w);
    if (NS_SUCCEEDED(rv))
      rv = height->GetData(&h);

    mLastPos.x = -1;
    mLastPos.y = -1;
    mRestoreRect.SetRect(-1, -1, -1, -1);

    // don't do it now, store it later and do it in layout.
    if (NS_SUCCEEDED(rv)) {
      mRestoreRect.SetRect(x, y, w, h);
      mDidHistoryRestore = PR_TRUE;
      nsIScrollableView* scrollingView = GetScrollableView();
      if (scrollingView) {
        scrollingView->GetScrollPosition(mLastPos.x, mLastPos.y);
      } else {
        mLastPos = nsPoint(0, 0);
      }
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2614 of file nsGfxScrollFrame.cpp.

{
  nsCOMPtr<nsIScrollbarMediator> mediator;
  nsIFrame* first = GetScrolledFrame();
  mediator = do_QueryInterface(first);
  if (mediator) {
    // Child manages its own scrolling. Bail.
    return nsnull;
  }

  nsIScrollableView* scrollingView = GetScrollableView();
  PRInt32 x,y;
  scrollingView->GetScrollPosition(x,y);
  // Don't save scroll position if we are at (0,0)
  if (!x && !y) {
    return nsnull;
  }

  nsIView* child = nsnull;
  scrollingView->GetScrolledView(child);
  if (!child) {
    return nsnull;
  }

  nsRect childRect = child->GetBounds();
  nsAutoPtr<nsPresState> state;
  nsresult rv = NS_NewPresState(getter_Transfers(state));
  NS_ENSURE_SUCCESS(rv, nsnull);

  nsCOMPtr<nsISupportsPRInt32> xoffset = do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID);
  if (xoffset) {
    rv = xoffset->SetData(x);
    NS_ENSURE_SUCCESS(rv, nsnull);
    state->SetStatePropertyAsSupports(NS_LITERAL_STRING("x-offset"), xoffset);
  }

  nsCOMPtr<nsISupportsPRInt32> yoffset = do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID);
  if (yoffset) {
    rv = yoffset->SetData(y);
    NS_ENSURE_SUCCESS(rv, nsnull);
    state->SetStatePropertyAsSupports(NS_LITERAL_STRING("y-offset"), yoffset);
  }

  nsCOMPtr<nsISupportsPRInt32> width = do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID);
  if (width) {
    rv = width->SetData(childRect.width);
    NS_ENSURE_SUCCESS(rv, nsnull);
    state->SetStatePropertyAsSupports(NS_LITERAL_STRING("width"), width);
  }

  nsCOMPtr<nsISupportsPRInt32> height = do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID);
  if (height) {
    rv = height->SetData(childRect.height);
    NS_ENSURE_SUCCESS(rv, nsnull);
    state->SetStatePropertyAsSupports(NS_LITERAL_STRING("height"), height);
  }
  return state.forget();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsGfxScrollFrameInner::ScrollbarChanged ( nsPresContext aPresContext,
nscoord  aX,
nscoord  aY,
PRUint32  aFlags 
)

Definition at line 2516 of file nsGfxScrollFrame.cpp.

{
  nsIScrollableView* scrollable = GetScrollableView();
  scrollable->ScrollTo(aX, aY, aFlags);
 // printf("scrolling to: %d, %d\n", aX, aY);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Called whenever actual scrolling happens for any reason.

Implements nsIScrollPositionListener.

Definition at line 1756 of file nsGfxScrollFrame.cpp.

Here is the call graph for this function:

Implements nsIScrollPositionListener.

Definition at line 1730 of file nsGfxScrollFrame.cpp.

{
   // Do nothing.
   return NS_OK;
}

this code is resposible for restoring the scroll position back to some saved positon.

if the user has not moved the scroll position manually we keep scrolling down until we get to our orignally position. keep in mind that content could incrementally be coming in. we only want to stop when we reach our new position.

Definition at line 1490 of file nsGfxScrollFrame.cpp.

{
  nsIScrollableView* scrollingView = GetScrollableView();
  if (!scrollingView) {
    return;
  }
  if (mRestoreRect.y == -1 || mLastPos.x == -1 || mLastPos.y == -1) {
    return;
  }
  // make sure our scroll position did not change for where we last put
  // it. if it does then the user must have moved it, and we no longer
  // need to restore.
  nscoord x = 0;
  nscoord y = 0;
  scrollingView->GetScrollPosition(x, y);

  // if we didn't move, we still need to restore
  if (x == mLastPos.x && y == mLastPos.y) {
    nsRect childRect(0, 0, 0, 0);
    nsIView* child = nsnull;
    nsresult rv = scrollingView->GetScrolledView(child);
    if (NS_SUCCEEDED(rv) && child)
      childRect = child->GetBounds();

    PRInt32 cx, cy, x, y;
    scrollingView->GetScrollPosition(cx,cy);

    x = (int)
      (((float)childRect.width / mRestoreRect.width) * mRestoreRect.x);
    y = (int)
      (((float)childRect.height / mRestoreRect.height) * mRestoreRect.y);

    // if our position is greater than the scroll position, scroll.
    // remember that we could be incrementally loading so we may enter
    // and scroll many times.
    if (y > cy || x > cx) {
      scrollingView->ScrollTo(x, y, 0);
      // scrollpostion goes from twips to pixels. this fixes any roundoff
      // problems.
      scrollingView->GetScrollPosition(mLastPos.x, mLastPos.y);
    } else {
      // if we reached the position then stop
      mRestoreRect.y = -1;
      mLastPos.x = -1;
      mLastPos.y = -1;
    }
  } else {
    // user moved the position, so we won't need to restore
    mLastPos.x = -1;
    mLastPos.y = -1;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsGfxScrollFrameInner::SetAttribute ( nsIBox *  aBox,
nsIAtom aAtom,
nscoord  aSize,
PRBool  aReflow = PR_TRUE 
)

Returns whether it actually needed to change the attribute.

Definition at line 2539 of file nsGfxScrollFrame.cpp.

{
  // convert to pixels
  aSize /= mOnePixel;

  // only set the attribute if it changed.

  PRInt32 current = GetIntegerAttribute(aBox, aAtom, -1);
  if (current != aSize)
  {
      nsAutoString newValue;
      newValue.AppendInt(aSize);
      aBox->GetContent()->SetAttr(kNameSpaceID_None, aAtom, newValue, aReflow);
      return PR_TRUE;
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsGfxScrollFrameInner::SetScrollbarEnabled ( nsIBox *  aBox,
nscoord  aMaxPos,
PRBool  aReflow = PR_TRUE 
)

Definition at line 2524 of file nsGfxScrollFrame.cpp.

{
  mOuter->GetPresContext()->PresShell()->PostAttributeChange(
    aBox->GetContent(),
    kNameSpaceID_None,
    nsHTMLAtoms::disabled,
    NS_LITERAL_STRING("true"),
    aReflow,
    aMaxPos ? eChangeType_Remove : eChangeType_Set);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsGfxScrollFrameInner::SetScrollbarVisibility ( nsIBox *  aScrollbar,
PRBool  aVisible 
) [static]

Definition at line 2579 of file nsGfxScrollFrame.cpp.

{
  if (!aScrollbar)
    return;

  nsCOMPtr<nsIScrollbarFrame> scrollbar(do_QueryInterface(aScrollbar));
  if (scrollbar) {
    // See if we have a mediator.
    nsCOMPtr<nsIScrollbarMediator> mediator;
    scrollbar->GetScrollbarMediator(getter_AddRefs(mediator));
    if (mediator) {
      // Inform the mediator of the visibility change.
      mediator->VisibilityChanged(scrollbar, aVisible);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 160 of file nsGfxScrollFrame.h.

Definition at line 159 of file nsGfxScrollFrame.h.

Definition at line 157 of file nsGfxScrollFrame.h.

Definition at line 156 of file nsGfxScrollFrame.h.

Definition at line 166 of file nsGfxScrollFrame.h.

Definition at line 139 of file nsGfxScrollFrame.h.

Definition at line 162 of file nsGfxScrollFrame.h.

Definition at line 152 of file nsGfxScrollFrame.h.

Definition at line 147 of file nsGfxScrollFrame.h.

Definition at line 155 of file nsGfxScrollFrame.h.

Definition at line 154 of file nsGfxScrollFrame.h.

Definition at line 144 of file nsGfxScrollFrame.h.

Definition at line 143 of file nsGfxScrollFrame.h.

Definition at line 146 of file nsGfxScrollFrame.h.

Definition at line 138 of file nsGfxScrollFrame.h.

Definition at line 142 of file nsGfxScrollFrame.h.

Definition at line 141 of file nsGfxScrollFrame.h.

Definition at line 137 of file nsGfxScrollFrame.h.

Definition at line 163 of file nsGfxScrollFrame.h.

Definition at line 167 of file nsGfxScrollFrame.h.

Definition at line 158 of file nsGfxScrollFrame.h.

Definition at line 140 of file nsGfxScrollFrame.h.


The documentation for this class was generated from the following files: