2002-01-12 04:18:10 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2002-01-12 04:18:10 +03:00
|
|
|
|
|
|
|
#ifndef nsListBoxBodyFrame_h
|
|
|
|
#define nsListBoxBodyFrame_h
|
|
|
|
|
2012-09-14 20:10:08 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2002-01-12 04:18:10 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsBoxFrame.h"
|
|
|
|
#include "nsIScrollbarMediator.h"
|
|
|
|
#include "nsIReflowCallback.h"
|
|
|
|
#include "nsBoxLayoutState.h"
|
2007-08-22 06:57:06 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2008-08-24 19:14:09 +04:00
|
|
|
#include "nsPIBoxObject.h"
|
2002-01-12 04:18:10 +03:00
|
|
|
|
2010-04-11 00:10:12 +04:00
|
|
|
class nsPresContext;
|
2002-01-12 04:18:10 +03:00
|
|
|
class nsListScrollSmoother;
|
2006-03-27 01:30:36 +04:00
|
|
|
nsIFrame* NS_NewListBoxBodyFrame(nsIPresShell* aPresShell,
|
2009-01-19 21:31:33 +03:00
|
|
|
nsStyleContext* aContext);
|
2002-01-12 04:18:10 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsListBoxBodyFrame final : public nsBoxFrame,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIScrollbarMediator,
|
|
|
|
public nsIReflowCallback
|
2002-01-12 04:18:10 +03:00
|
|
|
{
|
2015-01-06 12:27:56 +03:00
|
|
|
nsListBoxBodyFrame(nsStyleContext* aContext,
|
2011-07-11 18:05:10 +04:00
|
|
|
nsBoxLayout* aLayoutManager);
|
2002-01-12 04:18:10 +03:00
|
|
|
virtual ~nsListBoxBodyFrame();
|
|
|
|
|
|
|
|
public:
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsListBoxBodyFrame)
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_DECL_QUERYFRAME
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
2008-10-28 07:47:19 +03:00
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
// non-virtual ListBoxObject
|
|
|
|
int32_t GetNumberOfVisibleRows();
|
|
|
|
int32_t GetIndexOfFirstVisibleRow();
|
2012-08-22 19:56:38 +04:00
|
|
|
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);
|
2002-01-12 04:18:10 +03:00
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
friend nsIFrame* NS_NewListBoxBodyFrame(nsIPresShell* aPresShell,
|
2009-01-19 21:31:33 +03:00
|
|
|
nsStyleContext* aContext);
|
2002-01-12 04:18:10 +03:00
|
|
|
|
|
|
|
// nsIFrame
|
2014-05-25 02:20:40 +04:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIFrame* aPrevInFlow) override;
|
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
|
2006-04-10 04:16:29 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsIAtom* aAttribute, int32_t aModType) override;
|
2002-01-12 04:18:10 +03:00
|
|
|
|
|
|
|
// nsIScrollbarMediator
|
2015-03-25 21:40:31 +03:00
|
|
|
virtual void ScrollByPage(nsScrollbarFrame* aScrollbar, int32_t aDirection,
|
|
|
|
nsIScrollbarMediator::ScrollSnapMode snapMode
|
|
|
|
= nsIScrollbarMediator::DISABLE_SNAP) override;
|
|
|
|
virtual void ScrollByWhole(nsScrollbarFrame* aScrollbar, int32_t aDirection,
|
|
|
|
nsIScrollbarMediator::ScrollSnapMode snapMode
|
|
|
|
= nsIScrollbarMediator::DISABLE_SNAP) override;
|
|
|
|
virtual void ScrollByLine(nsScrollbarFrame* aScrollbar, int32_t aDirection,
|
|
|
|
nsIScrollbarMediator::ScrollSnapMode snapMode
|
|
|
|
= nsIScrollbarMediator::DISABLE_SNAP) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void RepeatButtonScroll(nsScrollbarFrame* aScrollbar) override;
|
2014-02-05 05:30:34 +04:00
|
|
|
virtual void ThumbMoved(nsScrollbarFrame* aScrollbar,
|
|
|
|
int32_t aOldPos,
|
2015-03-21 19:28:04 +03:00
|
|
|
int32_t aNewPos) override;
|
2015-03-25 21:40:31 +03:00
|
|
|
virtual void ScrollbarReleased(nsScrollbarFrame* aScrollbar) override {}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void VisibilityChanged(bool aVisible) override;
|
|
|
|
virtual nsIFrame* GetScrollbarBox(bool aVertical) override;
|
|
|
|
virtual void ScrollbarActivityStarted() const override {}
|
|
|
|
virtual void ScrollbarActivityStopped() const override {}
|
2015-05-12 11:49:25 +03:00
|
|
|
virtual bool IsScrollbarOnRight() const override {
|
|
|
|
return (StyleVisibility()->mDirection == NS_STYLE_DIRECTION_LTR);
|
|
|
|
}
|
2014-02-05 05:30:34 +04:00
|
|
|
|
2002-01-12 04:18:10 +03:00
|
|
|
|
|
|
|
// nsIReflowCallback
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool ReflowFinished() override;
|
|
|
|
virtual void ReflowCallbackCanceled() override;
|
2002-01-12 04:18:10 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) override;
|
|
|
|
virtual void MarkIntrinsicISizesDirty() override;
|
2002-01-12 04:18:10 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsSize GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) override;
|
|
|
|
virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) override;
|
2004-11-03 05:52:16 +03:00
|
|
|
|
2002-01-12 04:18:10 +03:00
|
|
|
// size calculation
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t GetRowCount();
|
|
|
|
int32_t GetRowHeightAppUnits() { return mRowHeight; }
|
|
|
|
int32_t GetFixedRowSize();
|
2010-04-03 15:36:19 +04:00
|
|
|
void SetRowHeight(nscoord aRowHeight);
|
2002-01-12 04:18:10 +03:00
|
|
|
nscoord GetYPosition();
|
|
|
|
nscoord GetAvailableHeight();
|
2014-07-24 21:03:26 +04:00
|
|
|
nscoord ComputeIntrinsicISize(nsBoxLayoutState& aBoxLayoutState);
|
2002-01-12 04:18:10 +03:00
|
|
|
|
|
|
|
// scrolling
|
2007-08-22 06:57:06 +04:00
|
|
|
nsresult InternalPositionChangedCallback();
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult InternalPositionChanged(bool aUp, int32_t aDelta);
|
2007-08-22 06:57:06 +04:00
|
|
|
// Process pending position changed events, then do the position change.
|
|
|
|
// This can wipe out the frametree.
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult DoInternalPositionChangedSync(bool aUp, int32_t aDelta);
|
2007-08-22 06:57:06 +04:00
|
|
|
// Actually do the internal position change. This can wipe out the frametree
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult DoInternalPositionChanged(bool aUp, int32_t aDelta);
|
2002-01-12 04:18:10 +03:00
|
|
|
nsListScrollSmoother* GetSmoother();
|
2012-08-22 19:56:38 +04:00
|
|
|
void VerticalScroll(int32_t aDelta);
|
2014-10-09 16:14:26 +04:00
|
|
|
// Update the scroll index given a position, in CSS pixels
|
|
|
|
void UpdateIndex(int32_t aNewPos);
|
2002-01-12 04:18:10 +03:00
|
|
|
|
|
|
|
// frames
|
|
|
|
nsIFrame* GetFirstFrame();
|
|
|
|
nsIFrame* GetLastFrame();
|
|
|
|
|
|
|
|
// lazy row creation and destruction
|
2005-02-05 06:32:17 +03:00
|
|
|
void CreateRows();
|
2012-08-22 19:56:38 +04: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-29 10:19:26 +04:00
|
|
|
bool ContinueReflow(nscoord height);
|
2009-07-30 21:23:32 +04:00
|
|
|
NS_IMETHOD ListBoxAppendFrames(nsFrameList& aFrameList);
|
|
|
|
NS_IMETHOD ListBoxInsertFrames(nsIFrame* aPrevFrame, nsFrameList& aFrameList);
|
2015-12-07 04:15:53 +03:00
|
|
|
void OnContentInserted(nsIContent* aContent);
|
2009-08-13 19:38:22 +04:00
|
|
|
void OnContentRemoved(nsPresContext* aPresContext, nsIContent* aContainer,
|
2010-07-15 08:38:24 +04:00
|
|
|
nsIFrame* aChildFrame, nsIContent* aOldNextSibling);
|
2002-01-12 04:18:10 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void GetListItemContentAt(int32_t aIndex, nsIContent** aContent);
|
|
|
|
void GetListItemNextSibling(nsIContent* aListItem, nsIContent** aContent, int32_t& aSiblingIndex);
|
2002-01-12 04:18:10 +03:00
|
|
|
|
|
|
|
void PostReflowCallback();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool SetBoxObject(nsPIBoxObject* aBoxObject)
|
2008-08-24 19:14:09 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(!mBoxObject, false);
|
2008-08-24 19:14:09 +04:00
|
|
|
mBoxObject = aBoxObject;
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-08-24 19:14:09 +04:00
|
|
|
}
|
2009-01-09 03:11:30 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool SupportsOrdinalsInChildren() override;
|
2009-01-09 03:11:30 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool ComputesOwnOverflowArea() override { return true; }
|
2010-09-06 07:23:44 +04:00
|
|
|
|
2002-01-12 04:18:10 +03:00
|
|
|
protected:
|
2007-08-22 06:57:06 +04:00
|
|
|
class nsPositionChangedEvent;
|
|
|
|
friend class nsPositionChangedEvent;
|
|
|
|
|
|
|
|
class nsPositionChangedEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsPositionChangedEvent(nsListBoxBodyFrame* aFrame,
|
2012-08-22 19:56:38 +04:00
|
|
|
bool aUp, int32_t aDelta) :
|
2007-08-22 06:57:06 +04:00
|
|
|
mFrame(aFrame), mUp(aUp), mDelta(aDelta)
|
|
|
|
{}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override
|
2007-08-22 06:57:06 +04:00
|
|
|
{
|
|
|
|
if (!mFrame) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrame->mPendingPositionChangeEvents.RemoveElement(this);
|
|
|
|
|
|
|
|
return mFrame->DoInternalPositionChanged(mUp, mDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Revoke() {
|
2012-07-30 18:20:58 +04:00
|
|
|
mFrame = nullptr;
|
2007-08-22 06:57:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsListBoxBodyFrame* mFrame;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mUp;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mDelta;
|
2007-08-22 06:57:06 +04:00
|
|
|
};
|
|
|
|
|
2002-01-12 04:18:10 +03:00
|
|
|
void ComputeTotalRowCount();
|
2014-10-09 16:14:26 +04:00
|
|
|
int32_t ToRowIndex(nscoord aPos) const;
|
2004-09-28 22:37:50 +04:00
|
|
|
void RemoveChildFrame(nsBoxLayoutState &aState, nsIFrame *aChild);
|
2002-01-12 04:18:10 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray< RefPtr<nsPositionChangedEvent> > mPendingPositionChangeEvents;
|
2009-05-12 14:13:09 +04:00
|
|
|
nsCOMPtr<nsPIBoxObject> mBoxObject;
|
2002-01-12 04:18:10 +03:00
|
|
|
|
|
|
|
// frame markers
|
2006-11-16 18:45:55 +03:00
|
|
|
nsWeakFrame mTopFrame;
|
2002-01-12 04:18:10 +03:00
|
|
|
nsIFrame* mBottomFrame;
|
|
|
|
nsIFrame* mLinkupFrame;
|
2009-05-12 14:13:09 +04:00
|
|
|
|
|
|
|
nsListScrollSmoother* mScrollSmoother;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mRowsToPrepend;
|
2002-01-12 04:18:10 +03:00
|
|
|
|
2009-05-12 14:13:09 +04:00
|
|
|
// row height
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mRowCount;
|
2009-05-12 14:13:09 +04:00
|
|
|
nscoord mRowHeight;
|
|
|
|
nscoord mAvailableHeight;
|
|
|
|
nscoord mStringWidth;
|
|
|
|
|
2002-01-12 04:18:10 +03:00
|
|
|
// scrolling
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mCurrentIndex; // Row-based
|
|
|
|
int32_t mOldIndex;
|
|
|
|
int32_t mYPosition;
|
|
|
|
int32_t mTimePerRow;
|
2002-01-12 04:18:10 +03:00
|
|
|
|
2009-05-12 14:13:09 +04:00
|
|
|
// row height
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mRowHeightWasSet;
|
2009-05-12 14:13:09 +04:00
|
|
|
// scrolling
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mScrolling;
|
|
|
|
bool mAdjustScroll;
|
2007-08-22 06:57:06 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mReflowCallbackPosted;
|
2009-05-12 14:13:09 +04:00
|
|
|
};
|
2002-01-12 04:18:10 +03:00
|
|
|
|
|
|
|
#endif // nsListBoxBodyFrame_h
|