layout/xul/tree/nsTreeColumns.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/xul/tree/nsTreeColumns.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,188 @@
     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 nsTreeColumns_h__
    1.10 +#define nsTreeColumns_h__
    1.11 +
    1.12 +#include "nsITreeColumns.h"
    1.13 +#include "nsITreeBoxObject.h"
    1.14 +#include "mozilla/Attributes.h"
    1.15 +#include "nsCoord.h"
    1.16 +#include "nsCycleCollectionParticipant.h"
    1.17 +#include "nsAutoPtr.h"
    1.18 +#include "nsWrapperCache.h"
    1.19 +#include "nsString.h"
    1.20 +
    1.21 +class nsTreeBodyFrame;
    1.22 +class nsTreeColumns;
    1.23 +class nsIFrame;
    1.24 +class nsIContent;
    1.25 +struct nsRect;
    1.26 +
    1.27 +namespace mozilla {
    1.28 +namespace dom {
    1.29 +class Element;
    1.30 +} // namespace dom
    1.31 +} // namespace mozilla
    1.32 +
    1.33 +#define NS_TREECOLUMN_IMPL_CID                       \
    1.34 +{ /* 02cd1963-4b5d-4a6c-9223-814d3ade93a3 */         \
    1.35 +    0x02cd1963,                                      \
    1.36 +    0x4b5d,                                          \
    1.37 +    0x4a6c,                                          \
    1.38 +    {0x92, 0x23, 0x81, 0x4d, 0x3a, 0xde, 0x93, 0xa3} \
    1.39 +}
    1.40 +
    1.41 +// This class is our column info.  We use it to iterate our columns and to obtain
    1.42 +// information about each column.
    1.43 +class nsTreeColumn MOZ_FINAL : public nsITreeColumn {
    1.44 +public:
    1.45 +  nsTreeColumn(nsTreeColumns* aColumns, nsIContent* aContent);
    1.46 +  ~nsTreeColumn();
    1.47 +
    1.48 +  NS_DECLARE_STATIC_IID_ACCESSOR(NS_TREECOLUMN_IMPL_CID)
    1.49 +
    1.50 +  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.51 +  NS_DECL_CYCLE_COLLECTION_CLASS(nsTreeColumn)
    1.52 +  NS_DECL_NSITREECOLUMN
    1.53 +
    1.54 +  friend class nsTreeBodyFrame;
    1.55 +  friend class nsTreeColumns;
    1.56 +
    1.57 +protected:
    1.58 +  nsIFrame* GetFrame();
    1.59 +  nsIFrame* GetFrame(nsTreeBodyFrame* aBodyFrame);
    1.60 +  // Don't call this if GetWidthInTwips or GetRect fails
    1.61 +  bool IsLastVisible(nsTreeBodyFrame* aBodyFrame);
    1.62 +
    1.63 +  /**
    1.64 +   * Returns a rect with x and width taken from the frame's rect and specified
    1.65 +   * y and height. May fail in case there's no frame for the column.
    1.66 +   */
    1.67 +  nsresult GetRect(nsTreeBodyFrame* aBodyFrame, nscoord aY, nscoord aHeight,
    1.68 +                   nsRect* aResult);
    1.69 +
    1.70 +  nsresult GetXInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult);
    1.71 +  nsresult GetWidthInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult);
    1.72 +
    1.73 +  void SetColumns(nsTreeColumns* aColumns) { mColumns = aColumns; }
    1.74 +
    1.75 +  const nsAString& GetId() { return mId; }
    1.76 +  nsIAtom* GetAtom() { return mAtom; }
    1.77 +
    1.78 +  int32_t GetIndex() { return mIndex; }
    1.79 +
    1.80 +  bool IsPrimary() { return mIsPrimary; }
    1.81 +  bool IsCycler() { return mIsCycler; }
    1.82 +  bool IsEditable() { return mIsEditable; }
    1.83 +  bool IsSelectable() { return mIsSelectable; }
    1.84 +  bool Overflow() { return mOverflow; }
    1.85 +
    1.86 +  int16_t GetType() { return mType; }
    1.87 +
    1.88 +  int8_t GetCropStyle() { return mCropStyle; }
    1.89 +  int32_t GetTextAlignment() { return mTextAlignment; }
    1.90 +
    1.91 +  nsTreeColumn* GetNext() { return mNext; }
    1.92 +  nsTreeColumn* GetPrevious() { return mPrevious; }
    1.93 +  void SetNext(nsTreeColumn* aNext) {
    1.94 +    NS_ASSERTION(!mNext, "already have a next sibling");
    1.95 +    mNext = aNext;
    1.96 +  }
    1.97 +  void SetPrevious(nsTreeColumn* aPrevious) { mPrevious = aPrevious; }
    1.98 +
    1.99 +private:
   1.100 +  /**
   1.101 +   * Non-null nsIContent for the associated <treecol> element.
   1.102 +   */
   1.103 +  nsCOMPtr<nsIContent> mContent;
   1.104 +
   1.105 +  nsTreeColumns* mColumns;
   1.106 +
   1.107 +  nsString mId;
   1.108 +  nsCOMPtr<nsIAtom> mAtom;
   1.109 +
   1.110 +  int32_t mIndex;
   1.111 +
   1.112 +  bool mIsPrimary;
   1.113 +  bool mIsCycler;
   1.114 +  bool mIsEditable;
   1.115 +  bool mIsSelectable;
   1.116 +  bool mOverflow;
   1.117 +
   1.118 +  int16_t mType;
   1.119 +
   1.120 +  int8_t mCropStyle;
   1.121 +  int8_t mTextAlignment;
   1.122 +
   1.123 +  nsRefPtr<nsTreeColumn> mNext;
   1.124 +  nsTreeColumn* mPrevious;
   1.125 +};
   1.126 +
   1.127 +NS_DEFINE_STATIC_IID_ACCESSOR(nsTreeColumn, NS_TREECOLUMN_IMPL_CID)
   1.128 +
   1.129 +class nsTreeColumns MOZ_FINAL : public nsITreeColumns
   1.130 +                              , public nsWrapperCache
   1.131 +{
   1.132 +public:
   1.133 +  nsTreeColumns(nsTreeBodyFrame* aTree);
   1.134 +  ~nsTreeColumns();
   1.135 +
   1.136 +  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   1.137 +  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsTreeColumns)
   1.138 +  NS_DECL_NSITREECOLUMNS
   1.139 +
   1.140 +  nsIContent* GetParentObject() const;
   1.141 +  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
   1.142 +
   1.143 +  // WebIDL
   1.144 +  nsITreeBoxObject* GetTree() const;
   1.145 +  uint32_t Count();
   1.146 +  uint32_t Length()
   1.147 +  {
   1.148 +    return Count();
   1.149 +  }
   1.150 +
   1.151 +  nsTreeColumn* GetFirstColumn() { EnsureColumns(); return mFirstColumn; }
   1.152 +  nsTreeColumn* GetLastColumn();
   1.153 +
   1.154 +  nsTreeColumn* GetPrimaryColumn();
   1.155 +  nsTreeColumn* GetSortedColumn();
   1.156 +  nsTreeColumn* GetKeyColumn();
   1.157 +
   1.158 +  nsTreeColumn* GetColumnFor(mozilla::dom::Element* aElement);
   1.159 +
   1.160 +  nsTreeColumn* IndexedGetter(uint32_t aIndex, bool& aFound);
   1.161 +  nsTreeColumn* GetColumnAt(uint32_t aIndex);
   1.162 +  nsTreeColumn* NamedGetter(const nsAString& aId, bool& aFound);
   1.163 +  bool NameIsEnumerable(const nsAString& aName);
   1.164 +  nsTreeColumn* GetNamedColumn(const nsAString& aId);
   1.165 +  void GetSupportedNames(unsigned, nsTArray<nsString>& aNames);
   1.166 +
   1.167 +  // Uses XPCOM InvalidateColumns().
   1.168 +  // Uses XPCOM RestoreNaturalOrder().
   1.169 +
   1.170 +  friend class nsTreeBodyFrame;
   1.171 +protected:
   1.172 +  void SetTree(nsTreeBodyFrame* aTree) { mTree = aTree; }
   1.173 +
   1.174 +  // Builds our cache of column info.
   1.175 +  void EnsureColumns();
   1.176 +
   1.177 +private:
   1.178 +  nsTreeBodyFrame* mTree;
   1.179 +
   1.180 +  /**
   1.181 +   * The first column in the list of columns. All of the columns are supposed
   1.182 +   * to be "alive", i.e. have a frame. This is achieved by clearing the columns
   1.183 +   * list each time an nsTreeColFrame is destroyed.
   1.184 +   *
   1.185 +   * XXX this means that new nsTreeColumn objects are unnecessarily created
   1.186 +   *     for untouched columns.
   1.187 +   */
   1.188 +  nsTreeColumn* mFirstColumn;
   1.189 +};
   1.190 +
   1.191 +#endif // nsTreeColumns_h__

mercurial