2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsListBoxBodyFrame_h
|
|
|
|
#define nsListBoxBodyFrame_h
|
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#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
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult GetRowCount(int32_t *aResult);
|
|
|
|
nsresult GetNumberOfVisibleRows(int32_t *aResult);
|
|
|
|
nsresult GetIndexOfFirstVisibleRow(int32_t *aResult);
|
|
|
|
nsresult EnsureIndexIsVisible(int32_t aRowIndex);
|
|
|
|
nsresult ScrollToIndex(int32_t aRowIndex);
|
|
|
|
nsresult ScrollByLines(int32_t aNumLines);
|
|
|
|
nsresult GetItemAtIndex(int32_t aIndex, nsIDOMElement **aResult);
|
|
|
|
nsresult GetIndexOfItem(nsIDOMElement *aItem, int32_t *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
|
2013-03-19 18:47:48 -07:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
NS_IMETHOD AttributeChanged(int32_t aNameSpaceID, nsIAtom* aAttribute, int32_t aModType) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIScrollbarMediator
|
2013-05-14 09:33:23 -07:00
|
|
|
NS_IMETHOD PositionChanged(nsScrollbarFrame* aScrollbar, int32_t aOldIndex, int32_t& aNewIndex) MOZ_OVERRIDE;
|
2012-09-14 09:10:08 -07:00
|
|
|
NS_IMETHOD ScrollbarButtonPressed(nsScrollbarFrame* aScrollbar, int32_t aOldIndex, int32_t aNewIndex) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD VisibilityChanged(bool aVisible) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIReflowCallback
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual bool ReflowFinished() MOZ_OVERRIDE;
|
|
|
|
virtual void ReflowCallbackCanceled() MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-14 09:33:23 -07:00
|
|
|
NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual void MarkIntrinsicWidthsDirty() MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-14 09:33:23 -07:00
|
|
|
virtual nsSize GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
|
|
|
|
virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// size calculation
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetRowCount();
|
|
|
|
int32_t GetRowHeightAppUnits() { return mRowHeight; }
|
|
|
|
int32_t 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();
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult InternalPositionChanged(bool aUp, int32_t aDelta);
|
2007-08-21 19:57:06 -07:00
|
|
|
// Process pending position changed events, then do the position change.
|
|
|
|
// This can wipe out the frametree.
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult DoInternalPositionChangedSync(bool aUp, int32_t aDelta);
|
2007-08-21 19:57:06 -07:00
|
|
|
// Actually do the internal position change. This can wipe out the frametree
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult DoInternalPositionChanged(bool aUp, int32_t aDelta);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsListScrollSmoother* GetSmoother();
|
2012-08-22 08:56:38 -07:00
|
|
|
void VerticalScroll(int32_t aDelta);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// frames
|
|
|
|
nsIFrame* GetFirstFrame();
|
|
|
|
nsIFrame* GetLastFrame();
|
|
|
|
|
|
|
|
// lazy row creation and destruction
|
|
|
|
void CreateRows();
|
2012-08-22 08:56:38 -07:00
|
|
|
void DestroyRows(int32_t& aRowsToLose);
|
|
|
|
void ReverseDestroyRows(int32_t& aRowsToLose);
|
|
|
|
nsIFrame* GetFirstItemBox(int32_t aOffset, bool* aCreated);
|
|
|
|
nsIFrame* GetNextItemBox(nsIFrame* aBox, int32_t aOffset, bool* aCreated);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool 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
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void GetListItemContentAt(int32_t aIndex, nsIContent** aContent);
|
|
|
|
void GetListItemNextSibling(nsIContent* aListItem, nsIContent** aContent, int32_t& aSiblingIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void PostReflowCallback();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool SetBoxObject(nsPIBoxObject* aBoxObject)
|
2008-08-24 08:14:09 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(!mBoxObject, false);
|
2008-08-24 08:14:09 -07:00
|
|
|
mBoxObject = aBoxObject;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-08-24 08:14:09 -07:00
|
|
|
}
|
2009-01-08 16:11:30 -08:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual bool SupportsOrdinalsInChildren() MOZ_OVERRIDE;
|
2009-01-08 16:11:30 -08:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual bool ComputesOwnOverflowArea() MOZ_OVERRIDE { return true; }
|
2010-09-05 20:23:44 -07:00
|
|
|
|
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,
|
2012-08-22 08:56:38 -07:00
|
|
|
bool aUp, int32_t aDelta) :
|
2007-08-21 19:57:06 -07:00
|
|
|
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() {
|
2012-07-30 07:20:58 -07:00
|
|
|
mFrame = nullptr;
|
2007-08-21 19:57:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsListBoxBodyFrame* mFrame;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mUp;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mDelta;
|
2007-08-21 19:57:06 -07:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mRowsToPrepend;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-05-12 03:13:09 -07:00
|
|
|
// row height
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mRowCount;
|
2009-05-12 03:13:09 -07:00
|
|
|
nscoord mRowHeight;
|
|
|
|
nscoord mAvailableHeight;
|
|
|
|
nscoord mStringWidth;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// scrolling
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mCurrentIndex; // Row-based
|
|
|
|
int32_t mOldIndex;
|
|
|
|
int32_t mYPosition;
|
|
|
|
int32_t mTimePerRow;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-05-12 03:13:09 -07:00
|
|
|
// row height
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mRowHeightWasSet;
|
2009-05-12 03:13:09 -07:00
|
|
|
// scrolling
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mScrolling;
|
|
|
|
bool mAdjustScroll;
|
2007-08-21 19:57:06 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mReflowCallbackPosted;
|
2009-05-12 03:13:09 -07:00
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#endif // nsListBoxBodyFrame_h
|