2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* David W. Hyatt (hyatt@netscape.com) (Original Author)
|
|
|
|
* Joe Hewitt (hewitt@netscape.com)
|
|
|
|
* Mike Pinkerton (pinkerton@netscape.com)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef nsListBoxBodyFrame_h
|
|
|
|
#define nsListBoxBodyFrame_h
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
#include "nsIListBoxObject.h"
|
|
|
|
#include "nsIScrollbarMediator.h"
|
|
|
|
#include "nsIReflowCallback.h"
|
|
|
|
#include "nsBoxLayoutState.h"
|
2007-08-21 19:57:06 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2008-08-24 08:14:09 -07:00
|
|
|
#include "nsPIBoxObject.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-10 13:10:12 -07:00
|
|
|
class nsPresContext;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsListScrollSmoother;
|
|
|
|
nsIFrame* NS_NewListBoxBodyFrame(nsIPresShell* aPresShell,
|
2009-01-19 10:31:33 -08:00
|
|
|
nsStyleContext* aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsListBoxBodyFrame : public nsBoxFrame,
|
|
|
|
public nsIScrollbarMediator,
|
|
|
|
public nsIReflowCallback
|
|
|
|
{
|
2009-01-19 10:31:33 -08:00
|
|
|
nsListBoxBodyFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
|
2011-07-11 07:05:10 -07:00
|
|
|
nsBoxLayout* aLayoutManager);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual ~nsListBoxBodyFrame();
|
|
|
|
|
|
|
|
public:
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsListBoxBodyFrame)
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_DECL_QUERYFRAME
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
2008-10-27 21:47:19 -07:00
|
|
|
|
|
|
|
// non-virtual nsIListBoxObject
|
|
|
|
nsresult GetRowCount(PRInt32 *aResult);
|
|
|
|
nsresult GetNumberOfVisibleRows(PRInt32 *aResult);
|
|
|
|
nsresult GetIndexOfFirstVisibleRow(PRInt32 *aResult);
|
|
|
|
nsresult EnsureIndexIsVisible(PRInt32 aRowIndex);
|
|
|
|
nsresult ScrollToIndex(PRInt32 aRowIndex);
|
|
|
|
nsresult ScrollByLines(PRInt32 aNumLines);
|
|
|
|
nsresult GetItemAtIndex(PRInt32 aIndex, nsIDOMElement **aResult);
|
|
|
|
nsresult GetIndexOfItem(nsIDOMElement *aItem, PRInt32 *aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
friend nsIFrame* NS_NewListBoxBodyFrame(nsIPresShell* aPresShell,
|
2009-01-19 10:31:33 -08:00
|
|
|
nsStyleContext* aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIFrame
|
|
|
|
NS_IMETHOD Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow);
|
2009-12-23 21:21:15 -08:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRInt32 aModType);
|
|
|
|
|
|
|
|
// nsIScrollbarMediator
|
2011-07-11 07:05:09 -07:00
|
|
|
NS_IMETHOD PositionChanged(nsScrollbarFrame* aScrollbar, PRInt32 aOldIndex, PRInt32& aNewIndex);
|
|
|
|
NS_IMETHOD ScrollbarButtonPressed(nsScrollbarFrame* aScrollbar, PRInt32 aOldIndex, PRInt32 aNewIndex);
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_IMETHOD VisibilityChanged(PRBool aVisible);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIReflowCallback
|
|
|
|
virtual PRBool ReflowFinished();
|
2007-11-30 23:22:44 -08:00
|
|
|
virtual void ReflowCallbackCanceled();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIBox
|
|
|
|
NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState);
|
|
|
|
virtual void MarkIntrinsicWidthsDirty();
|
|
|
|
|
|
|
|
virtual nsSize GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState);
|
|
|
|
virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState);
|
|
|
|
|
|
|
|
// size calculation
|
|
|
|
PRInt32 GetRowCount();
|
|
|
|
PRInt32 GetRowHeightAppUnits() { return mRowHeight; }
|
|
|
|
PRInt32 GetFixedRowSize();
|
2010-04-03 04:36:19 -07:00
|
|
|
void SetRowHeight(nscoord aRowHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord GetYPosition();
|
|
|
|
nscoord GetAvailableHeight();
|
|
|
|
nscoord ComputeIntrinsicWidth(nsBoxLayoutState& aBoxLayoutState);
|
|
|
|
|
|
|
|
// scrolling
|
2007-08-21 19:57:06 -07:00
|
|
|
nsresult InternalPositionChangedCallback();
|
|
|
|
nsresult InternalPositionChanged(PRBool aUp, PRInt32 aDelta);
|
|
|
|
// Process pending position changed events, then do the position change.
|
|
|
|
// This can wipe out the frametree.
|
|
|
|
nsresult DoInternalPositionChangedSync(PRBool aUp, PRInt32 aDelta);
|
|
|
|
// Actually do the internal position change. This can wipe out the frametree
|
|
|
|
nsresult DoInternalPositionChanged(PRBool aUp, PRInt32 aDelta);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListScrollSmoother* GetSmoother();
|
|
|
|
void VerticalScroll(PRInt32 aDelta);
|
|
|
|
|
|
|
|
// frames
|
|
|
|
nsIFrame* GetFirstFrame();
|
|
|
|
nsIFrame* GetLastFrame();
|
|
|
|
|
|
|
|
// lazy row creation and destruction
|
|
|
|
void CreateRows();
|
|
|
|
void DestroyRows(PRInt32& aRowsToLose);
|
|
|
|
void ReverseDestroyRows(PRInt32& aRowsToLose);
|
|
|
|
nsIBox* GetFirstItemBox(PRInt32 aOffset, PRBool* aCreated);
|
|
|
|
nsIBox* GetNextItemBox(nsIBox* aBox, PRInt32 aOffset, PRBool* aCreated);
|
|
|
|
PRBool ContinueReflow(nscoord height);
|
2009-07-30 10:23:32 -07:00
|
|
|
NS_IMETHOD ListBoxAppendFrames(nsFrameList& aFrameList);
|
|
|
|
NS_IMETHOD ListBoxInsertFrames(nsIFrame* aPrevFrame, nsFrameList& aFrameList);
|
2007-03-22 10:30:00 -07:00
|
|
|
void OnContentInserted(nsPresContext* aPresContext, nsIContent* aContent);
|
2009-08-13 08:38:22 -07:00
|
|
|
void OnContentRemoved(nsPresContext* aPresContext, nsIContent* aContainer,
|
2010-07-14 21:38:24 -07:00
|
|
|
nsIFrame* aChildFrame, nsIContent* aOldNextSibling);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void GetListItemContentAt(PRInt32 aIndex, nsIContent** aContent);
|
|
|
|
void GetListItemNextSibling(nsIContent* aListItem, nsIContent** aContent, PRInt32& aSiblingIndex);
|
|
|
|
|
|
|
|
void PostReflowCallback();
|
|
|
|
|
2008-08-24 08:14:09 -07:00
|
|
|
PRBool SetBoxObject(nsPIBoxObject* aBoxObject)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(!mBoxObject, PR_FALSE);
|
|
|
|
mBoxObject = aBoxObject;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2009-01-08 16:11:30 -08:00
|
|
|
|
|
|
|
virtual PRBool SupportsOrdinalsInChildren();
|
|
|
|
|
2010-09-05 20:23:44 -07:00
|
|
|
virtual PRBool ComputesOwnOverflowArea() { return PR_TRUE; }
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2007-08-21 19:57:06 -07:00
|
|
|
class nsPositionChangedEvent;
|
|
|
|
friend class nsPositionChangedEvent;
|
|
|
|
|
|
|
|
class nsPositionChangedEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsPositionChangedEvent(nsListBoxBodyFrame* aFrame,
|
|
|
|
PRBool aUp, PRInt32 aDelta) :
|
|
|
|
mFrame(aFrame), mUp(aUp), mDelta(aDelta)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
if (!mFrame) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrame->mPendingPositionChangeEvents.RemoveElement(this);
|
|
|
|
|
|
|
|
return mFrame->DoInternalPositionChanged(mUp, mDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Revoke() {
|
|
|
|
mFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsListBoxBodyFrame* mFrame;
|
|
|
|
PRBool mUp;
|
|
|
|
PRInt32 mDelta;
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void ComputeTotalRowCount();
|
|
|
|
void RemoveChildFrame(nsBoxLayoutState &aState, nsIFrame *aChild);
|
|
|
|
|
2009-05-12 03:13:09 -07:00
|
|
|
nsTArray< nsRefPtr<nsPositionChangedEvent> > mPendingPositionChangeEvents;
|
|
|
|
nsCOMPtr<nsPIBoxObject> mBoxObject;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// frame markers
|
|
|
|
nsWeakFrame mTopFrame;
|
|
|
|
nsIFrame* mBottomFrame;
|
|
|
|
nsIFrame* mLinkupFrame;
|
2009-05-12 03:13:09 -07:00
|
|
|
|
|
|
|
nsListScrollSmoother* mScrollSmoother;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 mRowsToPrepend;
|
|
|
|
|
2009-05-12 03:13:09 -07:00
|
|
|
// row height
|
|
|
|
PRInt32 mRowCount;
|
|
|
|
nscoord mRowHeight;
|
|
|
|
nscoord mAvailableHeight;
|
|
|
|
nscoord mStringWidth;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// scrolling
|
|
|
|
PRInt32 mCurrentIndex; // Row-based
|
|
|
|
PRInt32 mOldIndex;
|
|
|
|
PRInt32 mYPosition;
|
|
|
|
PRInt32 mTimePerRow;
|
|
|
|
|
2009-05-12 03:13:09 -07:00
|
|
|
// row height
|
|
|
|
PRPackedBool mRowHeightWasSet;
|
|
|
|
// scrolling
|
|
|
|
PRPackedBool mScrolling;
|
|
|
|
PRPackedBool mAdjustScroll;
|
2007-08-21 19:57:06 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRPackedBool mReflowCallbackPosted;
|
2009-05-12 03:13:09 -07:00
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#endif // nsListBoxBodyFrame_h
|