michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsTreeBodyFrame_h michael@0: #define nsTreeBodyFrame_h michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: #include "nsLeafBoxFrame.h" michael@0: #include "nsITreeView.h" michael@0: #include "nsICSSPseudoComparator.h" michael@0: #include "nsIScrollbarMediator.h" michael@0: #include "nsITimer.h" michael@0: #include "nsIReflowCallback.h" michael@0: #include "nsTArray.h" michael@0: #include "nsTreeStyleCache.h" michael@0: #include "nsTreeColumns.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsDataHashtable.h" michael@0: #include "imgIRequest.h" michael@0: #include "imgINotificationObserver.h" michael@0: #include "nsScrollbarFrame.h" michael@0: #include "nsThreadUtils.h" michael@0: #include "mozilla/LookAndFeel.h" michael@0: #include "nsIScrollbarOwner.h" michael@0: michael@0: class nsOverflowChecker; michael@0: class nsTreeImageListener; michael@0: michael@0: namespace mozilla { michael@0: namespace layout { michael@0: class ScrollbarActivity; michael@0: } michael@0: } michael@0: michael@0: // An entry in the tree's image cache michael@0: struct nsTreeImageCacheEntry michael@0: { michael@0: nsTreeImageCacheEntry() {} michael@0: nsTreeImageCacheEntry(imgIRequest *aRequest, imgINotificationObserver *aListener) michael@0: : request(aRequest), listener(aListener) {} michael@0: michael@0: nsCOMPtr request; michael@0: nsCOMPtr listener; michael@0: }; michael@0: michael@0: // The actual frame that paints the cells and rows. michael@0: class nsTreeBodyFrame MOZ_FINAL michael@0: : public nsLeafBoxFrame michael@0: , public nsICSSPseudoComparator michael@0: , public nsIScrollbarMediator michael@0: , public nsIReflowCallback michael@0: , public nsIScrollbarOwner michael@0: { michael@0: public: michael@0: typedef mozilla::layout::ScrollbarActivity ScrollbarActivity; michael@0: michael@0: nsTreeBodyFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: ~nsTreeBodyFrame(); michael@0: michael@0: NS_DECL_QUERYFRAME_TARGET(nsTreeBodyFrame) michael@0: NS_DECL_QUERYFRAME michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: // Callback handler methods for refresh driver based animations. michael@0: // Calls to these functions are forwarded from nsTreeImageListener. These michael@0: // mirror how nsImageFrame works. michael@0: nsresult OnImageIsAnimated(imgIRequest* aRequest); michael@0: michael@0: // non-virtual signatures like nsITreeBodyFrame michael@0: already_AddRefed Columns() const michael@0: { michael@0: nsRefPtr cols = mColumns; michael@0: return cols.forget(); michael@0: } michael@0: already_AddRefed GetExistingView() const michael@0: { michael@0: nsCOMPtr view = mView; michael@0: return view.forget(); michael@0: } michael@0: nsresult GetView(nsITreeView **aView); michael@0: nsresult SetView(nsITreeView *aView); michael@0: nsresult GetFocused(bool *aFocused); michael@0: nsresult SetFocused(bool aFocused); michael@0: nsresult GetTreeBody(nsIDOMElement **aElement); michael@0: nsresult GetRowHeight(int32_t *aValue); michael@0: nsresult GetRowWidth(int32_t *aValue); michael@0: nsresult GetHorizontalPosition(int32_t *aValue); michael@0: nsresult GetSelectionRegion(nsIScriptableRegion **aRegion); michael@0: int32_t FirstVisibleRow() const { return mTopRowIndex; } michael@0: int32_t LastVisibleRow() const { return mTopRowIndex + mPageLength; } michael@0: int32_t PageLength() const { return mPageLength; } michael@0: nsresult EnsureRowIsVisible(int32_t aRow); michael@0: nsresult EnsureCellIsVisible(int32_t aRow, nsITreeColumn *aCol); michael@0: nsresult ScrollToRow(int32_t aRow); michael@0: nsresult ScrollByLines(int32_t aNumLines); michael@0: nsresult ScrollByPages(int32_t aNumPages); michael@0: nsresult ScrollToCell(int32_t aRow, nsITreeColumn *aCol); michael@0: nsresult ScrollToColumn(nsITreeColumn *aCol); michael@0: nsresult ScrollToHorizontalPosition(int32_t aValue); michael@0: nsresult Invalidate(); michael@0: nsresult InvalidateColumn(nsITreeColumn *aCol); michael@0: nsresult InvalidateRow(int32_t aRow); michael@0: nsresult InvalidateCell(int32_t aRow, nsITreeColumn *aCol); michael@0: nsresult InvalidateRange(int32_t aStart, int32_t aEnd); michael@0: nsresult InvalidateColumnRange(int32_t aStart, int32_t aEnd, michael@0: nsITreeColumn *aCol); michael@0: nsresult GetRowAt(int32_t aX, int32_t aY, int32_t *aValue); michael@0: nsresult GetCellAt(int32_t aX, int32_t aY, int32_t *aRow, michael@0: nsITreeColumn **aCol, nsACString &aChildElt); michael@0: nsresult GetCoordsForCellItem(int32_t aRow, nsITreeColumn *aCol, michael@0: const nsACString &aElt, michael@0: int32_t *aX, int32_t *aY, michael@0: int32_t *aWidth, int32_t *aHeight); michael@0: nsresult IsCellCropped(int32_t aRow, nsITreeColumn *aCol, bool *aResult); michael@0: nsresult RowCountChanged(int32_t aIndex, int32_t aCount); michael@0: nsresult BeginUpdateBatch(); michael@0: nsresult EndUpdateBatch(); michael@0: nsresult ClearStyleAndImageCaches(); michael@0: michael@0: void ManageReflowCallback(const nsRect& aRect, nscoord aHorzWidth); michael@0: michael@0: virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: virtual void SetBounds(nsBoxLayoutState& aBoxLayoutState, const nsRect& aRect, michael@0: bool aRemoveOverflowArea = false) MOZ_OVERRIDE; michael@0: michael@0: // nsIReflowCallback michael@0: virtual bool ReflowFinished() MOZ_OVERRIDE; michael@0: virtual void ReflowCallbackCanceled() MOZ_OVERRIDE; michael@0: michael@0: // nsICSSPseudoComparator michael@0: virtual bool PseudoMatches(nsCSSSelector* aSelector) MOZ_OVERRIDE; michael@0: michael@0: // nsIScrollbarMediator michael@0: NS_IMETHOD PositionChanged(nsScrollbarFrame* aScrollbar, int32_t aOldIndex, int32_t& aNewIndex) MOZ_OVERRIDE; michael@0: NS_IMETHOD ScrollbarButtonPressed(nsScrollbarFrame* aScrollbar, int32_t aOldIndex, int32_t aNewIndex) MOZ_OVERRIDE; michael@0: NS_IMETHOD VisibilityChanged(bool aVisible) MOZ_OVERRIDE { Invalidate(); return NS_OK; } michael@0: michael@0: // nsIScrollbarOwner michael@0: virtual nsIFrame* GetScrollbarBox(bool aVertical) MOZ_OVERRIDE { michael@0: ScrollParts parts = GetScrollParts(); michael@0: return aVertical ? parts.mVScrollbar : parts.mHScrollbar; michael@0: } michael@0: michael@0: // Overridden from nsIFrame to cache our pres context. michael@0: virtual void Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* aPrevInFlow) MOZ_OVERRIDE; michael@0: virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult GetCursor(const nsPoint& aPoint, michael@0: nsIFrame::Cursor& aCursor) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult HandleEvent(nsPresContext* aPresContext, michael@0: mozilla::WidgetGUIEvent* aEvent, michael@0: nsEventStatus* aEventStatus) MOZ_OVERRIDE; michael@0: michael@0: virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists) MOZ_OVERRIDE; michael@0: michael@0: virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE; michael@0: michael@0: friend nsIFrame* NS_NewTreeBodyFrame(nsIPresShell* aPresShell); michael@0: friend class nsTreeColumn; michael@0: michael@0: struct ScrollParts { michael@0: nsScrollbarFrame* mVScrollbar; michael@0: nsCOMPtr mVScrollbarContent; michael@0: nsScrollbarFrame* mHScrollbar; michael@0: nsCOMPtr mHScrollbarContent; michael@0: nsIFrame* mColumnsFrame; michael@0: nsIScrollableFrame* mColumnsScrollFrame; michael@0: }; michael@0: michael@0: void PaintTreeBody(nsRenderingContext& aRenderingContext, michael@0: const nsRect& aDirtyRect, nsPoint aPt); michael@0: michael@0: nsITreeBoxObject* GetTreeBoxObject() const { return mTreeBoxObject; } michael@0: michael@0: // Get the base element, or