Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsTreeColumns.h
Line
Count
Source (jump to first uncovered line)
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 "nsITreeBoxObject.h"
11
#include "mozilla/Attributes.h"
12
#include "mozilla/RefPtr.h"
13
#include "nsCoord.h"
14
#include "nsCycleCollectionParticipant.h"
15
#include "nsQueryObject.h"
16
#include "nsWrapperCache.h"
17
#include "nsString.h"
18
19
class nsAtom;
20
class nsTreeBodyFrame;
21
class nsTreeColumns;
22
class nsIFrame;
23
class nsIContent;
24
struct nsRect;
25
26
namespace mozilla {
27
class ErrorResult;
28
namespace dom {
29
class Element;
30
class TreeBoxObject;
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
42
// This class is our column info.  We use it to iterate our columns and to obtain
43
// information about each column.
44
class nsTreeColumn final : public nsISupports
45
                         , public nsWrapperCache
46
{
47
public:
48
  nsTreeColumn(nsTreeColumns* aColumns, mozilla::dom::Element* aElement);
49
50
  NS_DECLARE_STATIC_IID_ACCESSOR(NS_TREECOLUMN_IMPL_CID)
51
52
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
53
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsTreeColumn)
54
55
  // WebIDL
56
  nsIContent* GetParentObject() const;
57
  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
58
59
  mozilla::dom::Element* Element();
60
61
  nsTreeColumns* GetColumns() const { return mColumns; }
62
63
  int32_t GetX(mozilla::ErrorResult& aRv);
64
  int32_t GetWidth(mozilla::ErrorResult& aRv);
65
66
  void GetId(nsAString& aId) const;
67
  int32_t Index() const { return mIndex; }
68
69
  bool Primary() const { return mIsPrimary; }
70
  bool Cycler() const { return mIsCycler; }
71
  bool Editable() const { return mIsEditable; }
72
  bool Selectable() const { return mIsSelectable; }
73
  int16_t Type() const { return mType; }
74
75
  nsTreeColumn* GetNext() const { return mNext; }
76
  nsTreeColumn* GetPrevious() const { return mPrevious; }
77
78
  void Invalidate(mozilla::ErrorResult& aRv);
79
80
  friend class nsTreeBodyFrame;
81
  friend class nsTreeColumns;
82
83
protected:
84
  ~nsTreeColumn();
85
  nsIFrame* GetFrame();
86
  nsIFrame* GetFrame(nsTreeBodyFrame* aBodyFrame);
87
  // Don't call this if GetWidthInTwips or GetRect fails
88
  bool IsLastVisible(nsTreeBodyFrame* aBodyFrame);
89
90
  /**
91
   * Returns a rect with x and width taken from the frame's rect and specified
92
   * y and height. May fail in case there's no frame for the column.
93
   */
94
  nsresult GetRect(nsTreeBodyFrame* aBodyFrame, nscoord aY, nscoord aHeight,
95
                   nsRect* aResult);
96
97
  nsresult GetXInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult);
98
  nsresult GetWidthInTwips(nsTreeBodyFrame* aBodyFrame, nscoord* aResult);
99
100
  void SetColumns(nsTreeColumns* aColumns) { mColumns = aColumns; }
101
102
public:
103
  const nsAString& GetId() const { return mId; }
104
  nsAtom* GetAtom() { return mAtom; }
105
  int32_t GetIndex() { return mIndex; }
106
107
protected:
108
  bool IsPrimary() { return mIsPrimary; }
109
  bool IsCycler() { return mIsCycler; }
110
0
  bool IsEditable() { return mIsEditable; }
111
0
  bool IsSelectable() { return mIsSelectable; }
112
  bool Overflow() { return mOverflow; }
113
114
  int16_t GetType() { return mType; }
115
116
  int8_t GetCropStyle() { return mCropStyle; }
117
  int32_t GetTextAlignment() { return mTextAlignment; }
118
119
  void SetNext(nsTreeColumn* aNext) {
120
    NS_ASSERTION(!mNext, "already have a next sibling");
121
    mNext = aNext;
122
  }
123
  void SetPrevious(nsTreeColumn* aPrevious) { mPrevious = aPrevious; }
124
125
private:
126
  /**
127
   * Non-null nsIContent for the associated <treecol> element.
128
   */
129
  RefPtr<mozilla::dom::Element> mContent;
130
131
  nsTreeColumns* mColumns;
132
133
  nsString mId;
134
  RefPtr<nsAtom> mAtom;
135
136
  int32_t mIndex;
137
138
  bool mIsPrimary;
139
  bool mIsCycler;
140
  bool mIsEditable;
141
  bool mIsSelectable;
142
  bool mOverflow;
143
144
  int16_t mType;
145
146
  int8_t mCropStyle;
147
  int8_t mTextAlignment;
148
149
  RefPtr<nsTreeColumn> mNext;
150
  nsTreeColumn* mPrevious;
151
};
152
153
NS_DEFINE_STATIC_IID_ACCESSOR(nsTreeColumn, NS_TREECOLUMN_IMPL_CID)
154
155
class nsTreeColumns final : public nsISupports
156
                          , public nsWrapperCache
157
{
158
private:
159
  ~nsTreeColumns();
160
161
public:
162
  explicit nsTreeColumns(nsTreeBodyFrame* aTree);
163
164
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
165
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsTreeColumns)
166
167
  nsIContent* GetParentObject() const;
168
  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
169
170
  // WebIDL
171
  mozilla::dom::TreeBoxObject* GetTree() const;
172
  uint32_t Count();
173
  uint32_t Length()
174
  {
175
    return Count();
176
  }
177
178
  nsTreeColumn* GetFirstColumn() { EnsureColumns(); return mFirstColumn; }
179
  nsTreeColumn* GetLastColumn();
180
181
  nsTreeColumn* GetPrimaryColumn();
182
  nsTreeColumn* GetSortedColumn();
183
  nsTreeColumn* GetKeyColumn();
184
185
  nsTreeColumn* GetColumnFor(mozilla::dom::Element* aElement);
186
187
  nsTreeColumn* IndexedGetter(uint32_t aIndex, bool& aFound);
188
  nsTreeColumn* GetColumnAt(uint32_t aIndex);
189
  nsTreeColumn* NamedGetter(const nsAString& aId, bool& aFound);
190
  nsTreeColumn* GetNamedColumn(const nsAString& aId);
191
  void GetSupportedNames(nsTArray<nsString>& aNames);
192
193
  void InvalidateColumns();
194
  void RestoreNaturalOrder();
195
196
  friend class nsTreeBodyFrame;
197
protected:
198
  void SetTree(nsTreeBodyFrame* aTree) { mTree = aTree; }
199
200
  // Builds our cache of column info.
201
  void EnsureColumns();
202
203
private:
204
  nsTreeBodyFrame* mTree;
205
206
  /**
207
   * The first column in the list of columns. All of the columns are supposed
208
   * to be "alive", i.e. have a frame. This is achieved by clearing the columns
209
   * list each time an nsTreeColFrame is destroyed.
210
   *
211
   * XXX this means that new nsTreeColumn objects are unnecessarily created
212
   *     for untouched columns.
213
   */
214
  RefPtr<nsTreeColumn> mFirstColumn;
215
};
216
217
#endif // nsTreeColumns_h__