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 nsTreeColumns_h__ michael@0: #define nsTreeColumns_h__ michael@0: michael@0: #include "nsITreeColumns.h" michael@0: #include "nsITreeBoxObject.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsCoord.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "nsString.h" michael@0: michael@0: class nsTreeBodyFrame; michael@0: class nsTreeColumns; michael@0: class nsIFrame; michael@0: class nsIContent; michael@0: struct nsRect; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class Element; michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #define NS_TREECOLUMN_IMPL_CID \ michael@0: { /* 02cd1963-4b5d-4a6c-9223-814d3ade93a3 */ \ michael@0: 0x02cd1963, \ michael@0: 0x4b5d, \ michael@0: 0x4a6c, \ michael@0: {0x92, 0x23, 0x81, 0x4d, 0x3a, 0xde, 0x93, 0xa3} \ michael@0: } michael@0: michael@0: // This class is our column info. We use it to iterate our columns and to obtain michael@0: // information about each column. michael@0: class nsTreeColumn MOZ_FINAL : public nsITreeColumn { michael@0: public: michael@0: nsTreeColumn(nsTreeColumns* aColumns, nsIContent* aContent); michael@0: ~nsTreeColumn(); michael@0: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_TREECOLUMN_IMPL_CID) michael@0: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_CLASS(nsTreeColumn) michael@0: NS_DECL_NSITREECOLUMN michael@0: michael@0: friend class nsTreeBodyFrame; michael@0: friend class nsTreeColumns; michael@0: michael@0: protected: michael@0: nsIFrame* GetFrame(); michael@0: nsIFrame* GetFrame(nsTreeBodyFrame* aBodyFrame); michael@0: // Don't call this if GetWidthInTwips or GetRect fails michael@0: bool IsLastVisible(nsTreeBodyFrame* aBodyFrame); michael@0: michael@0: /** michael@0: * Returns a rect with x and width taken from the frame's rect and specified michael@0: * y and height. May fail in case there's no frame for the column. michael@0: */ michael@0: nsresult GetRect(nsTreeBodyFrame* aBodyFrame, nscoord aY, nscoord aHeight, michael@0: nsRect* aResult); michael@0: michael@0: nsresult GetXInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult); michael@0: nsresult GetWidthInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult); michael@0: michael@0: void SetColumns(nsTreeColumns* aColumns) { mColumns = aColumns; } michael@0: michael@0: const nsAString& GetId() { return mId; } michael@0: nsIAtom* GetAtom() { return mAtom; } michael@0: michael@0: int32_t GetIndex() { return mIndex; } michael@0: michael@0: bool IsPrimary() { return mIsPrimary; } michael@0: bool IsCycler() { return mIsCycler; } michael@0: bool IsEditable() { return mIsEditable; } michael@0: bool IsSelectable() { return mIsSelectable; } michael@0: bool Overflow() { return mOverflow; } michael@0: michael@0: int16_t GetType() { return mType; } michael@0: michael@0: int8_t GetCropStyle() { return mCropStyle; } michael@0: int32_t GetTextAlignment() { return mTextAlignment; } michael@0: michael@0: nsTreeColumn* GetNext() { return mNext; } michael@0: nsTreeColumn* GetPrevious() { return mPrevious; } michael@0: void SetNext(nsTreeColumn* aNext) { michael@0: NS_ASSERTION(!mNext, "already have a next sibling"); michael@0: mNext = aNext; michael@0: } michael@0: void SetPrevious(nsTreeColumn* aPrevious) { mPrevious = aPrevious; } michael@0: michael@0: private: michael@0: /** michael@0: * Non-null nsIContent for the associated element. michael@0: */ michael@0: nsCOMPtr mContent; michael@0: michael@0: nsTreeColumns* mColumns; michael@0: michael@0: nsString mId; michael@0: nsCOMPtr mAtom; michael@0: michael@0: int32_t mIndex; michael@0: michael@0: bool mIsPrimary; michael@0: bool mIsCycler; michael@0: bool mIsEditable; michael@0: bool mIsSelectable; michael@0: bool mOverflow; michael@0: michael@0: int16_t mType; michael@0: michael@0: int8_t mCropStyle; michael@0: int8_t mTextAlignment; michael@0: michael@0: nsRefPtr mNext; michael@0: nsTreeColumn* mPrevious; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsTreeColumn, NS_TREECOLUMN_IMPL_CID) michael@0: michael@0: class nsTreeColumns MOZ_FINAL : public nsITreeColumns michael@0: , public nsWrapperCache michael@0: { michael@0: public: michael@0: nsTreeColumns(nsTreeBodyFrame* aTree); michael@0: ~nsTreeColumns(); michael@0: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsTreeColumns) michael@0: NS_DECL_NSITREECOLUMNS michael@0: michael@0: nsIContent* GetParentObject() const; michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: // WebIDL michael@0: nsITreeBoxObject* GetTree() const; michael@0: uint32_t Count(); michael@0: uint32_t Length() michael@0: { michael@0: return Count(); michael@0: } michael@0: michael@0: nsTreeColumn* GetFirstColumn() { EnsureColumns(); return mFirstColumn; } michael@0: nsTreeColumn* GetLastColumn(); michael@0: michael@0: nsTreeColumn* GetPrimaryColumn(); michael@0: nsTreeColumn* GetSortedColumn(); michael@0: nsTreeColumn* GetKeyColumn(); michael@0: michael@0: nsTreeColumn* GetColumnFor(mozilla::dom::Element* aElement); michael@0: michael@0: nsTreeColumn* IndexedGetter(uint32_t aIndex, bool& aFound); michael@0: nsTreeColumn* GetColumnAt(uint32_t aIndex); michael@0: nsTreeColumn* NamedGetter(const nsAString& aId, bool& aFound); michael@0: bool NameIsEnumerable(const nsAString& aName); michael@0: nsTreeColumn* GetNamedColumn(const nsAString& aId); michael@0: void GetSupportedNames(unsigned, nsTArray& aNames); michael@0: michael@0: // Uses XPCOM InvalidateColumns(). michael@0: // Uses XPCOM RestoreNaturalOrder(). michael@0: michael@0: friend class nsTreeBodyFrame; michael@0: protected: michael@0: void SetTree(nsTreeBodyFrame* aTree) { mTree = aTree; } michael@0: michael@0: // Builds our cache of column info. michael@0: void EnsureColumns(); michael@0: michael@0: private: michael@0: nsTreeBodyFrame* mTree; michael@0: michael@0: /** michael@0: * The first column in the list of columns. All of the columns are supposed michael@0: * to be "alive", i.e. have a frame. This is achieved by clearing the columns michael@0: * list each time an nsTreeColFrame is destroyed. michael@0: * michael@0: * XXX this means that new nsTreeColumn objects are unnecessarily created michael@0: * for untouched columns. michael@0: */ michael@0: nsTreeColumn* mFirstColumn; michael@0: }; michael@0: michael@0: #endif // nsTreeColumns_h__