tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsTreeColumns.h (6059B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef nsTreeColumns_h__
      8 #define nsTreeColumns_h__
      9 
     10 #include "mozilla/RefPtr.h"
     11 #include "nsCoord.h"
     12 #include "nsCycleCollectionParticipant.h"
     13 #include "nsQueryObject.h"
     14 #include "nsString.h"
     15 #include "nsWrapperCache.h"
     16 
     17 class nsAtom;
     18 class nsTreeBodyFrame;
     19 class nsTreeColumns;
     20 class nsIFrame;
     21 class nsIContent;
     22 struct nsRect;
     23 
     24 namespace mozilla {
     25 enum class StyleTextAlignKeyword : uint8_t;
     26 using StyleTextAlign = StyleTextAlignKeyword;
     27 class ErrorResult;
     28 namespace dom {
     29 class Element;
     30 class XULTreeElement;
     31 }  // namespace dom
     32 }  // namespace mozilla
     33 
     34 #define NS_TREECOLUMN_IMPL_CID                \
     35  {/* 02cd1963-4b5d-4a6c-9223-814d3ade93a3 */ \
     36   0x02cd1963,                                \
     37   0x4b5d,                                    \
     38   0x4a6c,                                    \
     39   {0x92, 0x23, 0x81, 0x4d, 0x3a, 0xde, 0x93, 0xa3}}
     40 
     41 // This class is our column info.  We use it to iterate our columns and to
     42 // obtain information about each column.
     43 class nsTreeColumn final : public nsISupports, public nsWrapperCache {
     44 public:
     45  nsTreeColumn(nsTreeColumns* aColumns, mozilla::dom::Element* aElement);
     46 
     47  NS_INLINE_DECL_STATIC_IID(NS_TREECOLUMN_IMPL_CID)
     48 
     49  NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL
     50  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(nsTreeColumn)
     51 
     52  // WebIDL
     53  nsIContent* GetParentObject() const;
     54  virtual JSObject* WrapObject(JSContext* aCx,
     55                               JS::Handle<JSObject*> aGivenProto) override;
     56 
     57  mozilla::dom::Element* Element();
     58 
     59  nsTreeColumns* GetColumns() const { return mColumns; }
     60 
     61  int32_t GetX(mozilla::ErrorResult& aRv);
     62  int32_t GetWidth(mozilla::ErrorResult& aRv);
     63 
     64  void GetId(nsAString& aId) const;
     65  int32_t Index() const { return mIndex; }
     66 
     67  bool Primary() const { return mIsPrimary; }
     68  bool Cycler() const { return mIsCycler; }
     69  bool Editable() const { return mIsEditable; }
     70  int16_t Type() const { return mType; }
     71 
     72  nsTreeColumn* GetNext() const { return mNext; }
     73  nsTreeColumn* GetPrevious() const { return mPrevious; }
     74 
     75  already_AddRefed<nsTreeColumn> GetPreviousColumn();
     76 
     77  void Invalidate(mozilla::ErrorResult& aRv);
     78 
     79  friend class nsTreeBodyFrame;
     80  friend class nsTreeColumns;
     81 
     82 protected:
     83  ~nsTreeColumn();
     84  nsIFrame* GetFrame();
     85  nsIFrame* GetFrame(nsTreeBodyFrame* aBodyFrame);
     86  // Don't call this if GetWidthInTwips or GetRect fails
     87  bool IsLastVisible(nsTreeBodyFrame* aBodyFrame);
     88 
     89  /**
     90   * Returns a rect with x and width taken from the frame's rect and specified
     91   * y and height. May fail in case there's no frame for the column.
     92   */
     93  nsresult GetRect(nsTreeBodyFrame* aBodyFrame, nscoord aY, nscoord aHeight,
     94                   nsRect* aResult);
     95 
     96  nsresult GetXInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult);
     97  nsresult GetWidthInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult);
     98 
     99  void SetColumns(nsTreeColumns* aColumns) { mColumns = aColumns; }
    100 
    101 public:
    102  const nsAString& GetId() const { return mId; }
    103  nsAtom* GetAtom() { return mAtom; }
    104  int32_t GetIndex() { return mIndex; }
    105 
    106 protected:
    107  bool IsPrimary() { return mIsPrimary; }
    108  bool IsCycler() { return mIsCycler; }
    109  bool IsEditable() { return mIsEditable; }
    110  bool Overflow() { return mOverflow; }
    111 
    112  int16_t GetType() { return mType; }
    113 
    114  int8_t GetCropStyle() { return mCropStyle; }
    115  mozilla::StyleTextAlign GetTextAlignment() { return mTextAlignment; }
    116 
    117  void SetNext(nsTreeColumn* aNext) {
    118    NS_ASSERTION(!mNext, "already have a next sibling");
    119    mNext = aNext;
    120  }
    121  void SetPrevious(nsTreeColumn* aPrevious) { mPrevious = aPrevious; }
    122 
    123 private:
    124  /**
    125   * Non-null nsIContent for the associated <treecol> element.
    126   */
    127  RefPtr<mozilla::dom::Element> mContent;
    128 
    129  nsTreeColumns* mColumns;
    130 
    131  nsString mId;
    132  RefPtr<nsAtom> mAtom;
    133 
    134  int32_t mIndex;
    135 
    136  bool mIsPrimary;
    137  bool mIsCycler;
    138  bool mIsEditable;
    139  bool mOverflow;
    140 
    141  int16_t mType;
    142 
    143  int8_t mCropStyle;
    144  mozilla::StyleTextAlign mTextAlignment;
    145 
    146  RefPtr<nsTreeColumn> mNext;
    147  nsTreeColumn* mPrevious;
    148 };
    149 
    150 class nsTreeColumns final : public nsISupports, public nsWrapperCache {
    151 private:
    152  ~nsTreeColumns();
    153 
    154 public:
    155  explicit nsTreeColumns(nsTreeBodyFrame* aTree);
    156 
    157  NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL
    158  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(nsTreeColumns)
    159 
    160  nsIContent* GetParentObject() const;
    161  virtual JSObject* WrapObject(JSContext* aCx,
    162                               JS::Handle<JSObject*> aGivenProto) override;
    163 
    164  // WebIDL
    165  mozilla::dom::XULTreeElement* GetTree() const;
    166  uint32_t Count();
    167  uint32_t Length() { return Count(); }
    168 
    169  nsTreeColumn* GetFirstColumn() {
    170    EnsureColumns();
    171    return mFirstColumn;
    172  }
    173  nsTreeColumn* GetLastColumn();
    174 
    175  nsTreeColumn* GetPrimaryColumn();
    176  nsTreeColumn* GetSortedColumn();
    177  nsTreeColumn* GetKeyColumn();
    178 
    179  nsTreeColumn* GetColumnFor(mozilla::dom::Element* aElement);
    180 
    181  nsTreeColumn* IndexedGetter(uint32_t aIndex, bool& aFound);
    182  nsTreeColumn* GetColumnAt(uint32_t aIndex);
    183  nsTreeColumn* NamedGetter(const nsAString& aId, bool& aFound);
    184  nsTreeColumn* GetNamedColumn(const nsAString& aId);
    185  void GetSupportedNames(nsTArray<nsString>& aNames);
    186 
    187  void InvalidateColumns();
    188 
    189  friend class nsTreeBodyFrame;
    190 
    191 protected:
    192  void SetTree(nsTreeBodyFrame* aTree) { mTree = aTree; }
    193 
    194  // Builds our cache of column info.
    195  void EnsureColumns();
    196 
    197 private:
    198  nsTreeBodyFrame* mTree;
    199 
    200  /**
    201   * The first column in the list of columns. All of the columns are supposed
    202   * to be "alive", i.e. have a frame. This is achieved by clearing the columns
    203   * list each time a treecol changes size.
    204   *
    205   * XXX this means that new nsTreeColumn objects are unnecessarily created
    206   *     for untouched columns.
    207   */
    208  RefPtr<nsTreeColumn> mFirstColumn;
    209 };
    210 
    211 #endif  // nsTreeColumns_h__