layout/xul/tree/nsTreeBodyFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/xul/tree/nsTreeBodyFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,634 @@
     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 nsTreeBodyFrame_h
    1.10 +#define nsTreeBodyFrame_h
    1.11 +
    1.12 +#include "mozilla/Attributes.h"
    1.13 +
    1.14 +#include "nsLeafBoxFrame.h"
    1.15 +#include "nsITreeView.h"
    1.16 +#include "nsICSSPseudoComparator.h"
    1.17 +#include "nsIScrollbarMediator.h"
    1.18 +#include "nsITimer.h"
    1.19 +#include "nsIReflowCallback.h"
    1.20 +#include "nsTArray.h"
    1.21 +#include "nsTreeStyleCache.h"
    1.22 +#include "nsTreeColumns.h"
    1.23 +#include "nsAutoPtr.h"
    1.24 +#include "nsDataHashtable.h"
    1.25 +#include "imgIRequest.h"
    1.26 +#include "imgINotificationObserver.h"
    1.27 +#include "nsScrollbarFrame.h"
    1.28 +#include "nsThreadUtils.h"
    1.29 +#include "mozilla/LookAndFeel.h"
    1.30 +#include "nsIScrollbarOwner.h"
    1.31 +
    1.32 +class nsOverflowChecker;
    1.33 +class nsTreeImageListener;
    1.34 +
    1.35 +namespace mozilla {
    1.36 +namespace layout {
    1.37 +class ScrollbarActivity;
    1.38 +}
    1.39 +}
    1.40 +
    1.41 +// An entry in the tree's image cache
    1.42 +struct nsTreeImageCacheEntry
    1.43 +{
    1.44 +  nsTreeImageCacheEntry() {}
    1.45 +  nsTreeImageCacheEntry(imgIRequest *aRequest, imgINotificationObserver *aListener)
    1.46 +    : request(aRequest), listener(aListener) {}
    1.47 +
    1.48 +  nsCOMPtr<imgIRequest> request;
    1.49 +  nsCOMPtr<imgINotificationObserver> listener;
    1.50 +};
    1.51 +
    1.52 +// The actual frame that paints the cells and rows.
    1.53 +class nsTreeBodyFrame MOZ_FINAL
    1.54 +  : public nsLeafBoxFrame
    1.55 +  , public nsICSSPseudoComparator
    1.56 +  , public nsIScrollbarMediator
    1.57 +  , public nsIReflowCallback
    1.58 +  , public nsIScrollbarOwner
    1.59 +{
    1.60 +public:
    1.61 +  typedef mozilla::layout::ScrollbarActivity ScrollbarActivity;
    1.62 +
    1.63 +  nsTreeBodyFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
    1.64 +  ~nsTreeBodyFrame();
    1.65 +
    1.66 +  NS_DECL_QUERYFRAME_TARGET(nsTreeBodyFrame)
    1.67 +  NS_DECL_QUERYFRAME
    1.68 +  NS_DECL_FRAMEARENA_HELPERS
    1.69 +
    1.70 +  // Callback handler methods for refresh driver based animations.
    1.71 +  // Calls to these functions are forwarded from nsTreeImageListener. These
    1.72 +  // mirror how nsImageFrame works.
    1.73 +  nsresult OnImageIsAnimated(imgIRequest* aRequest);
    1.74 +
    1.75 +  // non-virtual signatures like nsITreeBodyFrame
    1.76 +  already_AddRefed<nsTreeColumns> Columns() const
    1.77 +  {
    1.78 +    nsRefPtr<nsTreeColumns> cols = mColumns;
    1.79 +    return cols.forget();
    1.80 +  }
    1.81 +  already_AddRefed<nsITreeView> GetExistingView() const
    1.82 +  {
    1.83 +    nsCOMPtr<nsITreeView> view = mView;
    1.84 +    return view.forget();
    1.85 +  }
    1.86 +  nsresult GetView(nsITreeView **aView);
    1.87 +  nsresult SetView(nsITreeView *aView);
    1.88 +  nsresult GetFocused(bool *aFocused);
    1.89 +  nsresult SetFocused(bool aFocused);
    1.90 +  nsresult GetTreeBody(nsIDOMElement **aElement);
    1.91 +  nsresult GetRowHeight(int32_t *aValue);
    1.92 +  nsresult GetRowWidth(int32_t *aValue);
    1.93 +  nsresult GetHorizontalPosition(int32_t *aValue);
    1.94 +  nsresult GetSelectionRegion(nsIScriptableRegion **aRegion);
    1.95 +  int32_t FirstVisibleRow() const { return mTopRowIndex; }
    1.96 +  int32_t LastVisibleRow() const { return mTopRowIndex + mPageLength; }
    1.97 +  int32_t PageLength() const { return mPageLength; }
    1.98 +  nsresult EnsureRowIsVisible(int32_t aRow);
    1.99 +  nsresult EnsureCellIsVisible(int32_t aRow, nsITreeColumn *aCol);
   1.100 +  nsresult ScrollToRow(int32_t aRow);
   1.101 +  nsresult ScrollByLines(int32_t aNumLines);
   1.102 +  nsresult ScrollByPages(int32_t aNumPages);
   1.103 +  nsresult ScrollToCell(int32_t aRow, nsITreeColumn *aCol);
   1.104 +  nsresult ScrollToColumn(nsITreeColumn *aCol);
   1.105 +  nsresult ScrollToHorizontalPosition(int32_t aValue);
   1.106 +  nsresult Invalidate();
   1.107 +  nsresult InvalidateColumn(nsITreeColumn *aCol);
   1.108 +  nsresult InvalidateRow(int32_t aRow);
   1.109 +  nsresult InvalidateCell(int32_t aRow, nsITreeColumn *aCol);
   1.110 +  nsresult InvalidateRange(int32_t aStart, int32_t aEnd);
   1.111 +  nsresult InvalidateColumnRange(int32_t aStart, int32_t aEnd,
   1.112 +                                 nsITreeColumn *aCol);
   1.113 +  nsresult GetRowAt(int32_t aX, int32_t aY, int32_t *aValue);
   1.114 +  nsresult GetCellAt(int32_t aX, int32_t aY, int32_t *aRow,
   1.115 +                     nsITreeColumn **aCol, nsACString &aChildElt);
   1.116 +  nsresult GetCoordsForCellItem(int32_t aRow, nsITreeColumn *aCol,
   1.117 +                                const nsACString &aElt,
   1.118 +                                int32_t *aX, int32_t *aY,
   1.119 +                                int32_t *aWidth, int32_t *aHeight);
   1.120 +  nsresult IsCellCropped(int32_t aRow, nsITreeColumn *aCol, bool *aResult);
   1.121 +  nsresult RowCountChanged(int32_t aIndex, int32_t aCount);
   1.122 +  nsresult BeginUpdateBatch();
   1.123 +  nsresult EndUpdateBatch();
   1.124 +  nsresult ClearStyleAndImageCaches();
   1.125 +
   1.126 +  void ManageReflowCallback(const nsRect& aRect, nscoord aHorzWidth);
   1.127 +
   1.128 +  virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
   1.129 +  virtual void SetBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect,
   1.130 +                         bool aRemoveOverflowArea = false) MOZ_OVERRIDE;
   1.131 +
   1.132 +  // nsIReflowCallback
   1.133 +  virtual bool ReflowFinished() MOZ_OVERRIDE;
   1.134 +  virtual void ReflowCallbackCanceled() MOZ_OVERRIDE;
   1.135 +
   1.136 +  // nsICSSPseudoComparator
   1.137 +  virtual bool PseudoMatches(nsCSSSelector* aSelector) MOZ_OVERRIDE;
   1.138 +
   1.139 +  // nsIScrollbarMediator
   1.140 +  NS_IMETHOD PositionChanged(nsScrollbarFrame* aScrollbar, int32_t aOldIndex, int32_t& aNewIndex) MOZ_OVERRIDE;
   1.141 +  NS_IMETHOD ScrollbarButtonPressed(nsScrollbarFrame* aScrollbar, int32_t aOldIndex, int32_t aNewIndex) MOZ_OVERRIDE;
   1.142 +  NS_IMETHOD VisibilityChanged(bool aVisible) MOZ_OVERRIDE { Invalidate(); return NS_OK; }
   1.143 +
   1.144 +  // nsIScrollbarOwner
   1.145 +  virtual nsIFrame* GetScrollbarBox(bool aVertical) MOZ_OVERRIDE {
   1.146 +    ScrollParts parts = GetScrollParts();
   1.147 +    return aVertical ? parts.mVScrollbar : parts.mHScrollbar;
   1.148 +  }
   1.149 +
   1.150 +  // Overridden from nsIFrame to cache our pres context.
   1.151 +  virtual void Init(nsIContent*     aContent,
   1.152 +                    nsIFrame*       aParent,
   1.153 +                    nsIFrame*       aPrevInFlow) MOZ_OVERRIDE;
   1.154 +  virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
   1.155 +
   1.156 +  virtual nsresult GetCursor(const nsPoint& aPoint,
   1.157 +                             nsIFrame::Cursor& aCursor) MOZ_OVERRIDE;
   1.158 +
   1.159 +  virtual nsresult HandleEvent(nsPresContext* aPresContext,
   1.160 +                               mozilla::WidgetGUIEvent* aEvent,
   1.161 +                               nsEventStatus* aEventStatus) MOZ_OVERRIDE;
   1.162 +
   1.163 +  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
   1.164 +                                const nsRect&           aDirtyRect,
   1.165 +                                const nsDisplayListSet& aLists) MOZ_OVERRIDE;
   1.166 +
   1.167 +  virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE;
   1.168 +
   1.169 +  friend nsIFrame* NS_NewTreeBodyFrame(nsIPresShell* aPresShell);
   1.170 +  friend class nsTreeColumn;
   1.171 +
   1.172 +  struct ScrollParts {
   1.173 +    nsScrollbarFrame*    mVScrollbar;
   1.174 +    nsCOMPtr<nsIContent> mVScrollbarContent;
   1.175 +    nsScrollbarFrame*    mHScrollbar;
   1.176 +    nsCOMPtr<nsIContent> mHScrollbarContent;
   1.177 +    nsIFrame*            mColumnsFrame;
   1.178 +    nsIScrollableFrame*  mColumnsScrollFrame;
   1.179 +  };
   1.180 +
   1.181 +  void PaintTreeBody(nsRenderingContext& aRenderingContext,
   1.182 +                     const nsRect& aDirtyRect, nsPoint aPt);
   1.183 +
   1.184 +  nsITreeBoxObject* GetTreeBoxObject() const { return mTreeBoxObject; }
   1.185 +
   1.186 +  // Get the base element, <tree> or <select>
   1.187 +  nsIContent* GetBaseElement();
   1.188 +
   1.189 +  bool GetVerticalOverflow() const { return mVerticalOverflow; }
   1.190 +  bool GetHorizontalOverflow() const {return mHorizontalOverflow; }
   1.191 +
   1.192 +protected:
   1.193 +  friend class nsOverflowChecker;
   1.194 +
   1.195 +  // This method paints a specific column background of the tree.
   1.196 +  void PaintColumn(nsTreeColumn*        aColumn,
   1.197 +                   const nsRect&        aColumnRect,
   1.198 +                   nsPresContext*      aPresContext,
   1.199 +                   nsRenderingContext& aRenderingContext,
   1.200 +                   const nsRect&        aDirtyRect);
   1.201 +
   1.202 +  // This method paints a single row in the tree.
   1.203 +  void PaintRow(int32_t              aRowIndex,
   1.204 +                const nsRect&        aRowRect,
   1.205 +                nsPresContext*       aPresContext,
   1.206 +                nsRenderingContext& aRenderingContext,
   1.207 +                const nsRect&        aDirtyRect,
   1.208 +                nsPoint              aPt);
   1.209 +
   1.210 +  // This method paints a single separator in the tree.
   1.211 +  void PaintSeparator(int32_t              aRowIndex,
   1.212 +                      const nsRect&        aSeparatorRect,
   1.213 +                      nsPresContext*      aPresContext,
   1.214 +                      nsRenderingContext& aRenderingContext,
   1.215 +                      const nsRect&        aDirtyRect);
   1.216 +
   1.217 +  // This method paints a specific cell in a given row of the tree.
   1.218 +  void PaintCell(int32_t              aRowIndex, 
   1.219 +                 nsTreeColumn*        aColumn,
   1.220 +                 const nsRect&        aCellRect,
   1.221 +                 nsPresContext*       aPresContext,
   1.222 +                 nsRenderingContext& aRenderingContext,
   1.223 +                 const nsRect&        aDirtyRect,
   1.224 +                 nscoord&             aCurrX,
   1.225 +                 nsPoint              aPt);
   1.226 +
   1.227 +  // This method paints the twisty inside a cell in the primary column of an tree.
   1.228 +  void PaintTwisty(int32_t              aRowIndex,
   1.229 +                   nsTreeColumn*        aColumn,
   1.230 +                   const nsRect&        aTwistyRect,
   1.231 +                   nsPresContext*      aPresContext,
   1.232 +                   nsRenderingContext& aRenderingContext,
   1.233 +                   const nsRect&        aDirtyRect,
   1.234 +                   nscoord&             aRemainingWidth,
   1.235 +                   nscoord&             aCurrX);
   1.236 +
   1.237 +  // This method paints the image inside the cell of an tree.
   1.238 +  void PaintImage(int32_t              aRowIndex,
   1.239 +                  nsTreeColumn*        aColumn,
   1.240 +                  const nsRect&        aImageRect,
   1.241 +                  nsPresContext*      aPresContext,
   1.242 +                  nsRenderingContext& aRenderingContext,
   1.243 +                  const nsRect&        aDirtyRect,
   1.244 +                  nscoord&             aRemainingWidth,
   1.245 +                  nscoord&             aCurrX);
   1.246 +
   1.247 +  // This method paints the text string inside a particular cell of the tree.
   1.248 +  void PaintText(int32_t              aRowIndex, 
   1.249 +                 nsTreeColumn*        aColumn,
   1.250 +                 const nsRect&        aTextRect,
   1.251 +                 nsPresContext*      aPresContext,
   1.252 +                 nsRenderingContext& aRenderingContext,
   1.253 +                 const nsRect&        aDirtyRect,
   1.254 +                 nscoord&             aCurrX);
   1.255 +
   1.256 +  // This method paints the checkbox inside a particular cell of the tree.
   1.257 +  void PaintCheckbox(int32_t              aRowIndex, 
   1.258 +                     nsTreeColumn*        aColumn,
   1.259 +                     const nsRect&        aCheckboxRect,
   1.260 +                     nsPresContext*      aPresContext,
   1.261 +                     nsRenderingContext& aRenderingContext,
   1.262 +                     const nsRect&        aDirtyRect);
   1.263 +
   1.264 +  // This method paints the progress meter inside a particular cell of the tree.
   1.265 +  void PaintProgressMeter(int32_t              aRowIndex, 
   1.266 +                          nsTreeColumn*        aColumn,
   1.267 +                          const nsRect&        aProgressMeterRect,
   1.268 +                          nsPresContext*      aPresContext,
   1.269 +                          nsRenderingContext& aRenderingContext,
   1.270 +                          const nsRect&        aDirtyRect);
   1.271 +
   1.272 +  // This method paints a drop feedback of the tree.
   1.273 +  void PaintDropFeedback(const nsRect&        aDropFeedbackRect, 
   1.274 +                         nsPresContext*      aPresContext,
   1.275 +                         nsRenderingContext& aRenderingContext,
   1.276 +                         const nsRect&        aDirtyRect,
   1.277 +                         nsPoint              aPt);
   1.278 +
   1.279 +  // This method is called with a specific style context and rect to
   1.280 +  // paint the background rect as if it were a full-blown frame.
   1.281 +  void PaintBackgroundLayer(nsStyleContext*      aStyleContext,
   1.282 +                            nsPresContext*      aPresContext, 
   1.283 +                            nsRenderingContext& aRenderingContext, 
   1.284 +                            const nsRect&        aRect,
   1.285 +                            const nsRect&        aDirtyRect);
   1.286 +
   1.287 +
   1.288 +  // An internal hit test.  aX and aY are expected to be in twips in the
   1.289 +  // coordinate system of this frame.
   1.290 +  int32_t GetRowAt(nscoord aX, nscoord aY);
   1.291 +
   1.292 +  // Check for bidi characters in the text, and if there are any, ensure
   1.293 +  // that the prescontext is in bidi mode.
   1.294 +  void CheckTextForBidi(nsAutoString& aText);
   1.295 +
   1.296 +  void AdjustForCellText(nsAutoString& aText,
   1.297 +                         int32_t aRowIndex,  nsTreeColumn* aColumn,
   1.298 +                         nsRenderingContext& aRenderingContext,
   1.299 +                         nsRect& aTextRect);
   1.300 +
   1.301 +  // A helper used when hit testing.
   1.302 +  nsIAtom* GetItemWithinCellAt(nscoord aX, const nsRect& aCellRect,
   1.303 +                               int32_t aRowIndex, nsTreeColumn* aColumn);
   1.304 +
   1.305 +  // An internal hit test.  aX and aY are expected to be in twips in the
   1.306 +  // coordinate system of this frame.
   1.307 +  void GetCellAt(nscoord aX, nscoord aY, int32_t* aRow, nsTreeColumn** aCol,
   1.308 +                 nsIAtom** aChildElt);
   1.309 +
   1.310 +  // Retrieve the area for the twisty for a cell.
   1.311 +  nsITheme* GetTwistyRect(int32_t aRowIndex,
   1.312 +                          nsTreeColumn* aColumn,
   1.313 +                          nsRect& aImageRect,
   1.314 +                          nsRect& aTwistyRect,
   1.315 +                          nsPresContext* aPresContext,
   1.316 +                          nsRenderingContext& aRenderingContext,
   1.317 +                          nsStyleContext* aTwistyContext);
   1.318 +
   1.319 +  // Fetch an image from the image cache.
   1.320 +  nsresult GetImage(int32_t aRowIndex, nsTreeColumn* aCol, bool aUseContext,
   1.321 +                    nsStyleContext* aStyleContext, bool& aAllowImageRegions, imgIContainer** aResult);
   1.322 +
   1.323 +  // Returns the size of a given image.   This size *includes* border and
   1.324 +  // padding.  It does not include margins.
   1.325 +  nsRect GetImageSize(int32_t aRowIndex, nsTreeColumn* aCol, bool aUseContext, nsStyleContext* aStyleContext);
   1.326 +
   1.327 +  // Returns the destination size of the image, not including borders and padding.
   1.328 +  nsSize GetImageDestSize(nsStyleContext* aStyleContext, bool useImageRegion, imgIContainer* image);
   1.329 +
   1.330 +  // Returns the source rectangle of the image to be displayed.
   1.331 +  nsRect GetImageSourceRect(nsStyleContext* aStyleContext, bool useImageRegion, imgIContainer* image);
   1.332 +
   1.333 +  // Returns the height of rows in the tree.
   1.334 +  int32_t GetRowHeight();
   1.335 +
   1.336 +  // Returns our indentation width.
   1.337 +  int32_t GetIndentation();
   1.338 +
   1.339 +  // Calculates our width/height once border and padding have been removed.
   1.340 +  void CalcInnerBox();
   1.341 +
   1.342 +  // Calculate the total width of our scrollable portion
   1.343 +  nscoord CalcHorzWidth(const ScrollParts& aParts);
   1.344 +
   1.345 +  // Looks up a style context in the style cache.  On a cache miss we resolve
   1.346 +  // the pseudo-styles passed in and place them into the cache.
   1.347 +  nsStyleContext* GetPseudoStyleContext(nsIAtom* aPseudoElement);
   1.348 +
   1.349 +  // Retrieves the scrollbars and scrollview relevant to this treebody. We
   1.350 +  // traverse the frame tree under our base element, in frame order, looking
   1.351 +  // for the first relevant vertical scrollbar, horizontal scrollbar, and
   1.352 +  // scrollable frame (with associated content and scrollable view). These
   1.353 +  // are all volatile and should not be retained.
   1.354 +  ScrollParts GetScrollParts();
   1.355 +
   1.356 +  // Update the curpos of the scrollbar.
   1.357 +  void UpdateScrollbars(const ScrollParts& aParts);
   1.358 +
   1.359 +  // Update the maxpos of the scrollbar.
   1.360 +  void InvalidateScrollbars(const ScrollParts& aParts, nsWeakFrame& aWeakColumnsFrame);
   1.361 +
   1.362 +  // Check overflow and generate events.
   1.363 +  void CheckOverflow(const ScrollParts& aParts);
   1.364 +
   1.365 +  // Calls UpdateScrollbars, Invalidate aNeedsFullInvalidation if true,
   1.366 +  // InvalidateScrollbars and finally CheckOverflow.
   1.367 +  // returns true if the frame is still alive after the method call.
   1.368 +  bool FullScrollbarsUpdate(bool aNeedsFullInvalidation);
   1.369 +
   1.370 +  // Use to auto-fill some of the common properties without the view having to do it.
   1.371 +  // Examples include container, open, selected, and focus.
   1.372 +  void PrefillPropertyArray(int32_t aRowIndex, nsTreeColumn* aCol);
   1.373 +
   1.374 +  // Our internal scroll method, used by all the public scroll methods.
   1.375 +  nsresult ScrollInternal(const ScrollParts& aParts, int32_t aRow);
   1.376 +  nsresult ScrollToRowInternal(const ScrollParts& aParts, int32_t aRow);
   1.377 +  nsresult ScrollToColumnInternal(const ScrollParts& aParts, nsITreeColumn* aCol);
   1.378 +  nsresult ScrollHorzInternal(const ScrollParts& aParts, int32_t aPosition);
   1.379 +  nsresult EnsureRowIsVisibleInternal(const ScrollParts& aParts, int32_t aRow);
   1.380 +
   1.381 +  // Convert client pixels into appunits in our coordinate space.
   1.382 +  nsPoint AdjustClientCoordsToBoxCoordSpace(int32_t aX, int32_t aY);
   1.383 +
   1.384 +  // Cache the box object
   1.385 +  void EnsureBoxObject();
   1.386 +
   1.387 +  void EnsureView();
   1.388 +
   1.389 +  nsresult GetCellWidth(int32_t aRow, nsTreeColumn* aCol,
   1.390 +                        nsRenderingContext* aRenderingContext,
   1.391 +                        nscoord& aDesiredSize, nscoord& aCurrentSize);
   1.392 +  nscoord CalcMaxRowWidth();
   1.393 +
   1.394 +  // Translate the given rect horizontally from tree coordinates into the
   1.395 +  // coordinate system of our nsTreeBodyFrame.  If clip is true, then clip the
   1.396 +  // rect to its intersection with mInnerBox in the horizontal direction.
   1.397 +  // Return whether the result has a nonempty intersection with mInnerBox
   1.398 +  // after projecting both onto the horizontal coordinate axis.
   1.399 +  bool OffsetForHorzScroll(nsRect& rect, bool clip);
   1.400 +
   1.401 +  bool CanAutoScroll(int32_t aRowIndex);
   1.402 +
   1.403 +  // Calc the row and above/below/on status given where the mouse currently is hovering.
   1.404 +  // Also calc if we're in the region in which we want to auto-scroll the tree.
   1.405 +  // A positive value of |aScrollLines| means scroll down, a negative value
   1.406 +  // means scroll up, a zero value means that we aren't in drag scroll region.
   1.407 +  void ComputeDropPosition(mozilla::WidgetGUIEvent* aEvent,
   1.408 +                           int32_t* aRow,
   1.409 +                           int16_t* aOrient,
   1.410 +                           int16_t* aScrollLines);
   1.411 +
   1.412 +  // Mark ourselves dirty if we're a select widget
   1.413 +  void MarkDirtyIfSelect();
   1.414 +
   1.415 +  void InvalidateDropFeedback(int32_t aRow, int16_t aOrientation) {
   1.416 +    InvalidateRow(aRow);
   1.417 +    if (aOrientation != nsITreeView::DROP_ON)
   1.418 +      InvalidateRow(aRow + aOrientation);
   1.419 +  }
   1.420 +
   1.421 +public:
   1.422 +  static
   1.423 +  already_AddRefed<nsTreeColumn> GetColumnImpl(nsITreeColumn* aUnknownCol) {
   1.424 +    if (!aUnknownCol)
   1.425 +      return nullptr;
   1.426 +
   1.427 +    nsCOMPtr<nsTreeColumn> col = do_QueryInterface(aUnknownCol);
   1.428 +    return col.forget();
   1.429 +  }
   1.430 +
   1.431 +  /**
   1.432 +   * Remove an nsITreeImageListener from being tracked by this frame. Only tree
   1.433 +   * image listeners that are created by this frame are tracked.
   1.434 +   *
   1.435 +   * @param aListener A pointer to an nsTreeImageListener to no longer
   1.436 +   *        track.
   1.437 +   */
   1.438 +  void RemoveTreeImageListener(nsTreeImageListener* aListener);
   1.439 +
   1.440 +protected:
   1.441 +
   1.442 +  // Create a new timer. This method is used to delay various actions like
   1.443 +  // opening/closing folders or tree scrolling.
   1.444 +  // aID is type of the action, aFunc is the function to be called when
   1.445 +  // the timer fires and aType is type of timer - one shot or repeating.
   1.446 +  nsresult CreateTimer(const mozilla::LookAndFeel::IntID aID,
   1.447 +                       nsTimerCallbackFunc aFunc, int32_t aType,
   1.448 +                       nsITimer** aTimer);
   1.449 +
   1.450 +  static void OpenCallback(nsITimer *aTimer, void *aClosure);
   1.451 +
   1.452 +  static void CloseCallback(nsITimer *aTimer, void *aClosure);
   1.453 +
   1.454 +  static void LazyScrollCallback(nsITimer *aTimer, void *aClosure);
   1.455 +
   1.456 +  static void ScrollCallback(nsITimer *aTimer, void *aClosure);
   1.457 +
   1.458 +  class ScrollEvent : public nsRunnable {
   1.459 +  public:
   1.460 +    NS_DECL_NSIRUNNABLE
   1.461 +    ScrollEvent(nsTreeBodyFrame *aInner) : mInner(aInner) {}
   1.462 +    void Revoke() { mInner = nullptr; }
   1.463 +  private:
   1.464 +    nsTreeBodyFrame* mInner;
   1.465 +  };
   1.466 +
   1.467 +  void PostScrollEvent();
   1.468 +  void FireScrollEvent();
   1.469 +
   1.470 +  virtual void ScrollbarActivityStarted() const MOZ_OVERRIDE;
   1.471 +  virtual void ScrollbarActivityStopped() const MOZ_OVERRIDE;
   1.472 +
   1.473 +  /**
   1.474 +   * Clear the pointer to this frame for all nsTreeImageListeners that were
   1.475 +   * created by this frame.
   1.476 +   */
   1.477 +  void DetachImageListeners();
   1.478 +
   1.479 +#ifdef ACCESSIBILITY
   1.480 +  /**
   1.481 +   * Fires 'treeRowCountChanged' event asynchronously. The event supports
   1.482 +   * nsIDOMCustomEvent interface that is used to expose the following
   1.483 +   * information structures.
   1.484 +   *
   1.485 +   * @param aIndex  the row index rows are added/removed from
   1.486 +   * @param aCount  the number of added/removed rows (the sign points to
   1.487 +   *                an operation, plus - addition, minus - removing)
   1.488 +   */
   1.489 +  void FireRowCountChangedEvent(int32_t aIndex, int32_t aCount);
   1.490 +
   1.491 +  /**
   1.492 +   * Fires 'treeInvalidated' event asynchronously. The event supports
   1.493 +   * nsIDOMCustomEvent interface that is used to expose the information
   1.494 +   * structures described by method arguments.
   1.495 +   *
   1.496 +   * @param aStartRow  the start index of invalidated rows, -1 means that
   1.497 +   *                   columns have been invalidated only
   1.498 +   * @param aEndRow    the end index of invalidated rows, -1 means that columns
   1.499 +   *                   have been invalidated only
   1.500 +   * @param aStartCol  the start invalidated column, nullptr means that only rows
   1.501 +   *                   have been invalidated
   1.502 +   * @param aEndCol    the end invalidated column, nullptr means that rows have
   1.503 +   *                   been invalidated only
   1.504 +   */
   1.505 +  void FireInvalidateEvent(int32_t aStartRow, int32_t aEndRow,
   1.506 +                           nsITreeColumn *aStartCol, nsITreeColumn *aEndCol);
   1.507 +#endif
   1.508 +
   1.509 +protected: // Data Members
   1.510 +
   1.511 +  class Slots {
   1.512 +    public:
   1.513 +      Slots() {
   1.514 +      }
   1.515 +
   1.516 +      ~Slots() {
   1.517 +        if (mTimer)
   1.518 +          mTimer->Cancel();
   1.519 +      }
   1.520 +
   1.521 +      friend class nsTreeBodyFrame;
   1.522 +
   1.523 +    protected:
   1.524 +      // If the drop is actually allowed here or not.
   1.525 +      bool                     mDropAllowed;
   1.526 +
   1.527 +      // True while dragging over the tree.
   1.528 +      bool mIsDragging;
   1.529 +
   1.530 +      // The row the mouse is hovering over during a drop.
   1.531 +      int32_t                  mDropRow;
   1.532 +
   1.533 +      // Where we want to draw feedback (above/on this row/below) if allowed.
   1.534 +      int16_t                  mDropOrient;
   1.535 +
   1.536 +      // Number of lines to be scrolled.
   1.537 +      int16_t                  mScrollLines;
   1.538 +
   1.539 +      // The drag action that was received for this slot
   1.540 +      uint32_t                 mDragAction;
   1.541 +
   1.542 +      // Timer for opening/closing spring loaded folders or scrolling the tree.
   1.543 +      nsCOMPtr<nsITimer>       mTimer;
   1.544 +
   1.545 +      // An array used to keep track of all spring loaded folders.
   1.546 +      nsTArray<int32_t>        mArray;
   1.547 +  };
   1.548 +
   1.549 +  Slots* mSlots;
   1.550 +
   1.551 +  nsRevocableEventPtr<ScrollEvent> mScrollEvent;
   1.552 +
   1.553 +  nsRefPtr<ScrollbarActivity> mScrollbarActivity;
   1.554 +
   1.555 +  // The cached box object parent.
   1.556 +  nsCOMPtr<nsITreeBoxObject> mTreeBoxObject;
   1.557 +
   1.558 +  // Cached column information.
   1.559 +  nsRefPtr<nsTreeColumns> mColumns;
   1.560 +
   1.561 +  // The current view for this tree widget.  We get all of our row and cell data
   1.562 +  // from the view.
   1.563 +  nsCOMPtr<nsITreeView> mView;
   1.564 +
   1.565 +  // A cache of all the style contexts we have seen for rows and cells of the tree.  This is a mapping from
   1.566 +  // a list of atoms to a corresponding style context.  This cache stores every combination that
   1.567 +  // occurs in the tree, so for n distinct properties, this cache could have 2 to the n entries
   1.568 +  // (the power set of all row properties).
   1.569 +  nsTreeStyleCache mStyleCache;
   1.570 +
   1.571 +  // A hashtable that maps from URLs to image request/listener pairs.  The URL
   1.572 +  // is provided by the view or by the style context. The style context
   1.573 +  // represents a resolved :-moz-tree-cell-image (or twisty) pseudo-element.
   1.574 +  // It maps directly to an imgIRequest.
   1.575 +  nsDataHashtable<nsStringHashKey, nsTreeImageCacheEntry> mImageCache;
   1.576 +
   1.577 +  // A scratch array used when looking up cached style contexts.
   1.578 +  AtomArray mScratchArray;
   1.579 +
   1.580 +  // The index of the first visible row and the # of rows visible onscreen.  
   1.581 +  // The tree only examines onscreen rows, starting from
   1.582 +  // this index and going up to index+pageLength.
   1.583 +  int32_t mTopRowIndex;
   1.584 +  int32_t mPageLength;
   1.585 +
   1.586 +  // The horizontal scroll position
   1.587 +  nscoord mHorzPosition;
   1.588 +
   1.589 +  // The original desired horizontal width before changing it and posting a
   1.590 +  // reflow callback. In some cases, the desired horizontal width can first be
   1.591 +  // different from the current desired horizontal width, only to return to
   1.592 +  // the same value later during the same reflow. In this case, we can cancel
   1.593 +  // the posted reflow callback and prevent an unnecessary reflow.
   1.594 +  nscoord mOriginalHorzWidth;
   1.595 +  // Our desired horizontal width (the width for which we actually have tree
   1.596 +  // columns).
   1.597 +  nscoord mHorzWidth;
   1.598 +  // The amount by which to adjust the width of the last cell.
   1.599 +  // This depends on whether or not the columnpicker and scrollbars are present.
   1.600 +  nscoord mAdjustWidth;
   1.601 +
   1.602 +  // Cached heights and indent info.
   1.603 +  nsRect mInnerBox; // 4-byte aligned
   1.604 +  int32_t mRowHeight;
   1.605 +  int32_t mIndentation;
   1.606 +  nscoord mStringWidth;
   1.607 +
   1.608 +  int32_t mUpdateBatchNest;
   1.609 +
   1.610 +  // Cached row count.
   1.611 +  int32_t mRowCount;
   1.612 +
   1.613 +  // The row the mouse is hovering over.
   1.614 +  int32_t mMouseOverRow;
   1.615 +
   1.616 +  // Whether or not we're currently focused.
   1.617 +  bool mFocused;
   1.618 +
   1.619 +  // Do we have a fixed number of onscreen rows?
   1.620 +  bool mHasFixedRowCount;
   1.621 +
   1.622 +  bool mVerticalOverflow;
   1.623 +  bool mHorizontalOverflow;
   1.624 +
   1.625 +  bool mReflowCallbackPosted;
   1.626 +
   1.627 +  // Set while we flush layout to take account of effects of
   1.628 +  // overflow/underflow event handlers
   1.629 +  bool mCheckingOverflow;
   1.630 +
   1.631 +  // Hash table to keep track of which listeners we created and thus
   1.632 +  // have pointers to us.
   1.633 +  nsTHashtable<nsPtrHashKey<nsTreeImageListener> > mCreatedListeners;
   1.634 +
   1.635 +}; // class nsTreeBodyFrame
   1.636 +
   1.637 +#endif

mercurial