layout/xul/nsListBoxBodyFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/xul/nsListBoxBodyFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,194 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsListBoxBodyFrame_h
    1.10 +#define nsListBoxBodyFrame_h
    1.11 +
    1.12 +#include "mozilla/Attributes.h"
    1.13 +#include "nsCOMPtr.h"
    1.14 +#include "nsBoxFrame.h"
    1.15 +#include "nsIListBoxObject.h"
    1.16 +#include "nsIScrollbarMediator.h"
    1.17 +#include "nsIReflowCallback.h"
    1.18 +#include "nsBoxLayoutState.h"
    1.19 +#include "nsThreadUtils.h"
    1.20 +#include "nsPIBoxObject.h"
    1.21 +
    1.22 +class nsPresContext;
    1.23 +class nsListScrollSmoother;
    1.24 +nsIFrame* NS_NewListBoxBodyFrame(nsIPresShell* aPresShell,
    1.25 +                                 nsStyleContext* aContext);
    1.26 +
    1.27 +class nsListBoxBodyFrame : public nsBoxFrame,
    1.28 +                           public nsIScrollbarMediator,
    1.29 +                           public nsIReflowCallback
    1.30 +{
    1.31 +  nsListBoxBodyFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
    1.32 +                     nsBoxLayout* aLayoutManager);
    1.33 +  virtual ~nsListBoxBodyFrame();
    1.34 +
    1.35 +public:
    1.36 +  NS_DECL_QUERYFRAME_TARGET(nsListBoxBodyFrame)
    1.37 +  NS_DECL_QUERYFRAME
    1.38 +  NS_DECL_FRAMEARENA_HELPERS
    1.39 +
    1.40 +  // non-virtual nsIListBoxObject
    1.41 +  nsresult GetRowCount(int32_t *aResult);
    1.42 +  nsresult GetNumberOfVisibleRows(int32_t *aResult);
    1.43 +  nsresult GetIndexOfFirstVisibleRow(int32_t *aResult);
    1.44 +  nsresult EnsureIndexIsVisible(int32_t aRowIndex);
    1.45 +  nsresult ScrollToIndex(int32_t aRowIndex);
    1.46 +  nsresult ScrollByLines(int32_t aNumLines);
    1.47 +  nsresult GetItemAtIndex(int32_t aIndex, nsIDOMElement **aResult);
    1.48 +  nsresult GetIndexOfItem(nsIDOMElement *aItem, int32_t *aResult);
    1.49 +
    1.50 +  friend nsIFrame* NS_NewListBoxBodyFrame(nsIPresShell* aPresShell,
    1.51 +                                          nsStyleContext* aContext);
    1.52 +  
    1.53 +  // nsIFrame
    1.54 +  virtual void Init(nsIContent*     aContent,
    1.55 +                    nsIFrame*       aParent, 
    1.56 +                    nsIFrame*       aPrevInFlow) MOZ_OVERRIDE;
    1.57 +  virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
    1.58 +
    1.59 +  virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsIAtom* aAttribute, int32_t aModType) MOZ_OVERRIDE;
    1.60 +
    1.61 +  // nsIScrollbarMediator
    1.62 +  NS_IMETHOD PositionChanged(nsScrollbarFrame* aScrollbar, int32_t aOldIndex, int32_t& aNewIndex) MOZ_OVERRIDE;
    1.63 +  NS_IMETHOD ScrollbarButtonPressed(nsScrollbarFrame* aScrollbar, int32_t aOldIndex, int32_t aNewIndex) MOZ_OVERRIDE;
    1.64 +  NS_IMETHOD VisibilityChanged(bool aVisible) MOZ_OVERRIDE;
    1.65 +
    1.66 +  // nsIReflowCallback
    1.67 +  virtual bool ReflowFinished() MOZ_OVERRIDE;
    1.68 +  virtual void ReflowCallbackCanceled() MOZ_OVERRIDE;
    1.69 +
    1.70 +  NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    1.71 +  virtual void MarkIntrinsicWidthsDirty() MOZ_OVERRIDE;
    1.72 +
    1.73 +  virtual nsSize GetMinSizeForScrollArea(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    1.74 +  virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    1.75 +
    1.76 +  // size calculation 
    1.77 +  int32_t GetRowCount();
    1.78 +  int32_t GetRowHeightAppUnits() { return mRowHeight; }
    1.79 +  int32_t GetFixedRowSize();
    1.80 +  void SetRowHeight(nscoord aRowHeight);
    1.81 +  nscoord GetYPosition();
    1.82 +  nscoord GetAvailableHeight();
    1.83 +  nscoord ComputeIntrinsicWidth(nsBoxLayoutState& aBoxLayoutState);
    1.84 +
    1.85 +  // scrolling
    1.86 +  nsresult InternalPositionChangedCallback();
    1.87 +  nsresult InternalPositionChanged(bool aUp, int32_t aDelta);
    1.88 +  // Process pending position changed events, then do the position change.
    1.89 +  // This can wipe out the frametree.
    1.90 +  nsresult DoInternalPositionChangedSync(bool aUp, int32_t aDelta);
    1.91 +  // Actually do the internal position change.  This can wipe out the frametree
    1.92 +  nsresult DoInternalPositionChanged(bool aUp, int32_t aDelta);
    1.93 +  nsListScrollSmoother* GetSmoother();
    1.94 +  void VerticalScroll(int32_t aDelta);
    1.95 +
    1.96 +  // frames
    1.97 +  nsIFrame* GetFirstFrame();
    1.98 +  nsIFrame* GetLastFrame();
    1.99 +
   1.100 +  // lazy row creation and destruction
   1.101 +  void CreateRows();
   1.102 +  void DestroyRows(int32_t& aRowsToLose);
   1.103 +  void ReverseDestroyRows(int32_t& aRowsToLose);
   1.104 +  nsIFrame* GetFirstItemBox(int32_t aOffset, bool* aCreated);
   1.105 +  nsIFrame* GetNextItemBox(nsIFrame* aBox, int32_t aOffset, bool* aCreated);
   1.106 +  bool ContinueReflow(nscoord height);
   1.107 +  NS_IMETHOD ListBoxAppendFrames(nsFrameList& aFrameList);
   1.108 +  NS_IMETHOD ListBoxInsertFrames(nsIFrame* aPrevFrame, nsFrameList& aFrameList);
   1.109 +  void OnContentInserted(nsPresContext* aPresContext, nsIContent* aContent);
   1.110 +  void OnContentRemoved(nsPresContext* aPresContext,  nsIContent* aContainer,
   1.111 +                        nsIFrame* aChildFrame, nsIContent* aOldNextSibling);
   1.112 +
   1.113 +  void GetListItemContentAt(int32_t aIndex, nsIContent** aContent);
   1.114 +  void GetListItemNextSibling(nsIContent* aListItem, nsIContent** aContent, int32_t& aSiblingIndex);
   1.115 +
   1.116 +  void PostReflowCallback();
   1.117 +
   1.118 +  bool SetBoxObject(nsPIBoxObject* aBoxObject)
   1.119 +  {
   1.120 +    NS_ENSURE_TRUE(!mBoxObject, false);
   1.121 +    mBoxObject = aBoxObject;
   1.122 +    return true;
   1.123 +  }
   1.124 +
   1.125 +  virtual bool SupportsOrdinalsInChildren() MOZ_OVERRIDE;
   1.126 +
   1.127 +  virtual bool ComputesOwnOverflowArea() MOZ_OVERRIDE { return true; }
   1.128 +
   1.129 +protected:
   1.130 +  class nsPositionChangedEvent;
   1.131 +  friend class nsPositionChangedEvent;
   1.132 +
   1.133 +  class nsPositionChangedEvent : public nsRunnable
   1.134 +  {
   1.135 +  public:
   1.136 +    nsPositionChangedEvent(nsListBoxBodyFrame* aFrame,
   1.137 +                           bool aUp, int32_t aDelta) :
   1.138 +      mFrame(aFrame), mUp(aUp), mDelta(aDelta)
   1.139 +    {}
   1.140 +  
   1.141 +    NS_IMETHOD Run() MOZ_OVERRIDE
   1.142 +    {
   1.143 +      if (!mFrame) {
   1.144 +        return NS_OK;
   1.145 +      }
   1.146 +
   1.147 +      mFrame->mPendingPositionChangeEvents.RemoveElement(this);
   1.148 +
   1.149 +      return mFrame->DoInternalPositionChanged(mUp, mDelta);
   1.150 +    }
   1.151 +
   1.152 +    void Revoke() {
   1.153 +      mFrame = nullptr;
   1.154 +    }
   1.155 +
   1.156 +    nsListBoxBodyFrame* mFrame;
   1.157 +    bool mUp;
   1.158 +    int32_t mDelta;
   1.159 +  };
   1.160 +
   1.161 +  void ComputeTotalRowCount();
   1.162 +  void RemoveChildFrame(nsBoxLayoutState &aState, nsIFrame *aChild);
   1.163 +
   1.164 +  nsTArray< nsRefPtr<nsPositionChangedEvent> > mPendingPositionChangeEvents;
   1.165 +  nsCOMPtr<nsPIBoxObject> mBoxObject;
   1.166 +
   1.167 +  // frame markers
   1.168 +  nsWeakFrame mTopFrame;
   1.169 +  nsIFrame* mBottomFrame;
   1.170 +  nsIFrame* mLinkupFrame;
   1.171 +
   1.172 +  nsListScrollSmoother* mScrollSmoother;
   1.173 +
   1.174 +  int32_t mRowsToPrepend;
   1.175 +
   1.176 +  // row height
   1.177 +  int32_t mRowCount;
   1.178 +  nscoord mRowHeight;
   1.179 +  nscoord mAvailableHeight;
   1.180 +  nscoord mStringWidth;
   1.181 +
   1.182 +  // scrolling
   1.183 +  int32_t mCurrentIndex; // Row-based
   1.184 +  int32_t mOldIndex; 
   1.185 +  int32_t mYPosition;
   1.186 +  int32_t mTimePerRow;
   1.187 +
   1.188 +  // row height
   1.189 +  bool mRowHeightWasSet;
   1.190 +  // scrolling
   1.191 +  bool mScrolling;
   1.192 +  bool mAdjustScroll;
   1.193 +
   1.194 +  bool mReflowCallbackPosted;
   1.195 +};
   1.196 +
   1.197 +#endif // nsListBoxBodyFrame_h

mercurial