Back to index

lightning-sunbird  0.9+nobinonly
nsListBoxBodyFrame.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   David W. Hyatt (hyatt@netscape.com) (Original Author)
00024  *   Joe Hewitt (hewitt@netscape.com)
00025  *   Mike Pinkerton (pinkerton@netscape.com)
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #ifndef nsListBoxBodyFrame_h
00042 #define nsListBoxBodyFrame_h
00043 
00044 #include "nsCOMPtr.h"
00045 #include "nsBoxFrame.h"
00046 #include "nsIListBoxObject.h"
00047 #include "nsIScrollbarMediator.h"
00048 #include "nsIReflowCallback.h"
00049 #include "nsPresContext.h"
00050 #include "nsBoxLayoutState.h"
00051 
00052 class nsCSSFrameConstructor;
00053 class nsListScrollSmoother;
00054 nsresult NS_NewListBoxBodyFrame(nsIPresShell* aPresShell, 
00055                                 nsIFrame** aNewFrame, 
00056                                 PRBool aIsRoot = PR_FALSE,
00057                                 nsIBoxLayout* aLayoutManager = nsnull);
00058 
00059 class nsListBoxBodyFrame : public nsBoxFrame,
00060                            public nsIListBoxObject,
00061                            public nsIScrollbarMediator,
00062                            public nsIReflowCallback
00063 {
00064   nsListBoxBodyFrame(nsIPresShell* aPresShell, PRBool aIsRoot = nsnull, nsIBoxLayout* aLayoutManager = nsnull);
00065   virtual ~nsListBoxBodyFrame();
00066 
00067 public:
00068   NS_DECL_ISUPPORTS
00069   NS_DECL_NSILISTBOXOBJECT
00070 
00071   friend nsresult NS_NewListBoxBodyFrame(nsIPresShell* aPresShell, 
00072                                          nsIFrame** aNewFrame, 
00073                                          PRBool aIsRoot,
00074                                          nsIBoxLayout* aLayoutManager);
00075   
00076   // nsIFrame
00077   NS_IMETHOD Init(nsPresContext* aPresContext, nsIContent* aContent,
00078                   nsIFrame* aParent, nsStyleContext* aContext, nsIFrame* aPrevInFlow);
00079   NS_IMETHOD Destroy(nsPresContext* aPresContext);
00080   NS_IMETHOD AttributeChanged(nsIContent* aChild, PRInt32 aNameSpaceID,
00081                               nsIAtom* aAttribute, PRInt32 aModType);
00082 
00083   // nsIScrollbarMediator
00084   NS_IMETHOD PositionChanged(nsISupports* aScrollbar, PRInt32 aOldIndex, PRInt32& aNewIndex);
00085   NS_IMETHOD ScrollbarButtonPressed(nsISupports* aScrollbar, PRInt32 aOldIndex, PRInt32 aNewIndex);
00086   NS_IMETHOD VisibilityChanged(nsISupports* aScrollbar, PRBool aVisible);
00087 
00088   // nsIReflowCallback
00089   NS_IMETHOD ReflowFinished(nsIPresShell* aPresShell, PRBool* aFlushFlag);
00090 
00091   // nsIBox
00092   NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState);
00093   NS_IMETHOD NeedsRecalc();
00094 
00095   virtual nsSize GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState);
00096   NS_IMETHOD GetPrefSize(nsBoxLayoutState& aBoxLayoutState, nsSize& aSize);
00097 
00098   // size calculation 
00099   PRInt32 GetRowCount();
00100   PRInt32 GetRowHeightTwips() { return mRowHeight; }
00101   PRInt32 GetFixedRowSize();
00102   void SetRowHeight(PRInt32 aRowHeight);
00103   nscoord GetYPosition();
00104   nscoord GetAvailableHeight();
00105   nscoord ComputeIntrinsicWidth(nsBoxLayoutState& aBoxLayoutState);
00106 
00107   // scrolling
00108   NS_IMETHOD InternalPositionChangedCallback();
00109   NS_IMETHOD InternalPositionChanged(PRBool aUp, PRInt32 aDelta);
00110   nsListScrollSmoother* GetSmoother();
00111   void VerticalScroll(PRInt32 aDelta);
00112 
00113   // frames
00114   nsIFrame* GetFirstFrame();
00115   nsIFrame* GetLastFrame();
00116 
00117   // lazy row creation and destruction
00118   void CreateRows();
00119   void DestroyRows(PRInt32& aRowsToLose);
00120   void ReverseDestroyRows(PRInt32& aRowsToLose);
00121   nsIBox* GetFirstItemBox(PRInt32 aOffset, PRBool* aCreated);
00122   nsIBox* GetNextItemBox(nsIBox* aBox, PRInt32 aOffset, PRBool* aCreated);
00123   PRBool ContinueReflow(nscoord height);
00124   NS_IMETHOD ListBoxAppendFrames(nsIFrame* aFrameList);
00125   NS_IMETHOD ListBoxInsertFrames(nsIFrame* aPrevFrame, nsIFrame* aFrameList);
00126   void OnContentInserted(nsPresContext* aPresContext, nsIContent* aContent);
00127   void OnContentRemoved(nsPresContext* aPresContext,  nsIFrame* aChildFrame, PRInt32 aIndex);
00128 
00129   void GetListItemContentAt(PRInt32 aIndex, nsIContent** aContent);
00130   void GetListItemNextSibling(nsIContent* aListItem, nsIContent** aContent, PRInt32& aSiblingIndex);
00131 
00132   void PostReflowCallback();
00133 
00134   void InitGroup(nsCSSFrameConstructor* aFC, nsPresContext* aContext) 
00135   {
00136     mFrameConstructor = aFC;
00137     mPresContext = aContext;
00138   }
00139 
00140 protected:
00141   void ComputeTotalRowCount();
00142   void RemoveChildFrame(nsBoxLayoutState &aState, nsIFrame *aChild);
00143 
00144   // We don't own this. (No addref/release allowed, punk.)
00145   nsCSSFrameConstructor* mFrameConstructor;
00146   nsPresContext* mPresContext;
00147 
00148   // row height
00149   PRInt32 mRowCount;
00150   PRInt32 mRowHeight;
00151   PRPackedBool mRowHeightWasSet;
00152   nscoord mAvailableHeight;
00153   nscoord mStringWidth;
00154 
00155   // frame markers
00156   nsWeakFrame mTopFrame;
00157   nsIFrame* mBottomFrame;
00158   nsIFrame* mLinkupFrame;
00159   PRInt32 mRowsToPrepend;
00160 
00161   // scrolling
00162   nscoord mOnePixel;
00163   PRInt32 mCurrentIndex; // Row-based
00164   PRInt32 mOldIndex; 
00165   PRPackedBool mScrolling;
00166   PRPackedBool mAdjustScroll;
00167   PRInt32 mYPosition;
00168   nsListScrollSmoother* mScrollSmoother;
00169   PRInt32 mTimePerRow;
00170 
00171   PRPackedBool mReflowCallbackPosted;
00172 }; 
00173 
00174 #endif // nsListBoxBodyFrame_h