Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/tables/nsTableColFrame.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
#ifndef nsTableColFrame_h__
6
#define nsTableColFrame_h__
7
8
#include "mozilla/Attributes.h"
9
#include "celldata.h"
10
#include "nscore.h"
11
#include "nsContainerFrame.h"
12
#include "nsTArray.h"
13
#include "nsTableColGroupFrame.h"
14
#include "mozilla/WritingModes.h"
15
16
class nsTableColFrame final : public nsSplittableFrame
17
{
18
public:
19
  NS_DECL_FRAMEARENA_HELPERS(nsTableColFrame)
20
21
  enum {eWIDTH_SOURCE_NONE          =0,   // no cell has contributed to the width style
22
        eWIDTH_SOURCE_CELL          =1,   // a cell specified a width
23
        eWIDTH_SOURCE_CELL_WITH_SPAN=2    // a cell implicitly specified a width via colspan
24
  };
25
26
  nsTableColType GetColType() const;
27
  void SetColType(nsTableColType aType);
28
29
  /** instantiate a new instance of nsTableRowFrame.
30
    * @param aPresShell the pres shell for this frame
31
    *
32
    * @return           the frame that was created
33
    */
34
  friend nsTableColFrame* NS_NewTableColFrame(nsIPresShell* aPresShell,
35
                                              ComputedStyle*  aContext);
36
37
  // nsIFrame overrides
38
  virtual void Init(nsIContent*       aContent,
39
                    nsContainerFrame* aParent,
40
                    nsIFrame*         aPrevInFlow) override
41
0
  {
42
0
    nsSplittableFrame::Init(aContent, aParent, aPrevInFlow);
43
0
    if (!aPrevInFlow) {
44
0
      mWritingMode = GetTableFrame()->GetWritingMode();
45
0
    }
46
0
  }
47
48
  /** @see nsIFrame::DidSetComputedStyle */
49
  virtual void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
50
51
  virtual void Reflow(nsPresContext*           aPresContext,
52
                      ReflowOutput&     aDesiredSize,
53
                      const ReflowInput& aReflowInput,
54
                      nsReflowStatus&          aStatus) override;
55
56
  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
57
                                const nsDisplayListSet& aLists) override;
58
59
#ifdef DEBUG_FRAME_DUMP
60
  virtual nsresult GetFrameName(nsAString& aResult) const override;
61
#endif
62
63
  virtual nsSplittableType GetSplittableType() const override;
64
65
  nsTableColGroupFrame* GetTableColGroupFrame() const
66
0
  {
67
0
    nsIFrame* parent = GetParent();
68
0
    MOZ_ASSERT(parent && parent->IsTableColGroupFrame());
69
0
    return static_cast<nsTableColGroupFrame*>(parent);
70
0
  }
71
72
  nsTableFrame* GetTableFrame() const
73
0
  {
74
0
    return GetTableColGroupFrame()->GetTableFrame();
75
0
  }
76
77
  int32_t GetColIndex() const;
78
79
  void SetColIndex (int32_t aColIndex);
80
81
  nsTableColFrame* GetNextCol() const;
82
83
  /** return the number of the columns the col represents.  always >= 1 */
84
  int32_t GetSpan();
85
86
  /** convenience method, calls into cellmap */
87
  int32_t Count() const;
88
89
0
  BCPixelSize GetIStartBorderWidth() const { return mIStartBorderWidth; }
90
0
  BCPixelSize GetIEndBorderWidth() const { return mIEndBorderWidth; }
91
0
  void SetIStartBorderWidth(BCPixelSize aWidth) { mIStartBorderWidth = aWidth; }
92
0
  void SetIEndBorderWidth(BCPixelSize aWidth) { mIEndBorderWidth = aWidth; }
93
94
  /**
95
   * Gets inner border widths before collapsing with cell borders
96
   * Caller must get istart border from previous column or from table
97
   * GetContinuousBCBorderWidth will not overwrite aBorder.IStart
98
   * see nsTablePainter about continuous borders
99
   *
100
   * @return outer iend border width (istart inner for next column)
101
   */
102
  nscoord GetContinuousBCBorderWidth(mozilla::WritingMode aWM,
103
                                     mozilla::LogicalMargin& aBorder);
104
  /**
105
   * Set full border widths before collapsing with cell borders
106
   * @param aForSide - side to set; only valid for bstart, iend, and bend
107
   */
108
  void SetContinuousBCBorderWidth(mozilla::LogicalSide aForSide,
109
                                  BCPixelSize aPixelValue);
110
#ifdef DEBUG
111
  void Dump(int32_t aIndent);
112
#endif
113
114
  /**
115
   * Restore the default values of the intrinsic widths, so that we can
116
   * re-accumulate intrinsic widths from the cells in the column.
117
   */
118
0
  void ResetIntrinsics() {
119
0
    mMinCoord = 0;
120
0
    mPrefCoord = 0;
121
0
    mPrefPercent = 0.0f;
122
0
    mHasSpecifiedCoord = false;
123
0
  }
124
125
  /**
126
   * Restore the default value of the preferred percentage width (the
127
   * only intrinsic width used by FixedTableLayoutStrategy.
128
   */
129
0
  void ResetPrefPercent() {
130
0
    mPrefPercent = 0.0f;
131
0
  }
132
133
  /**
134
   * Restore the default values of the temporary buffer for
135
   * spanning-cell intrinsic widths (as we process spanning cells).
136
   */
137
0
  void ResetSpanIntrinsics() {
138
0
    mSpanMinCoord = 0;
139
0
    mSpanPrefCoord = 0;
140
0
    mSpanPrefPercent = 0.0f;
141
0
  }
142
143
  /**
144
   * Add the widths for a cell or column element, or the contribution of
145
   * the widths from a column-spanning cell:
146
   * @param aMinCoord The minimum intrinsic width
147
   * @param aPrefCoord The preferred intrinsic width or, if there is a
148
   *   specified non-percentage width, max(specified width, minimum intrinsic
149
   *   width).
150
   * @param aHasSpecifiedCoord Whether there is a specified
151
   *   non-percentage width.
152
   *
153
   * Note that the implementation of this functions is a bit tricky
154
   * since mPrefCoord means different things depending on
155
   * whether mHasSpecifiedCoord is true (and likewise for aPrefCoord and
156
   * aHasSpecifiedCoord).  If mHasSpecifiedCoord is false, then
157
   * all widths added had aHasSpecifiedCoord false and mPrefCoord is the
158
   * largest of the pref widths.  But if mHasSpecifiedCoord is true,
159
   * then mPrefCoord is the largest of (1) the pref widths for cells
160
   * with aHasSpecifiedCoord true and (2) the min widths for cells with
161
   * aHasSpecifiedCoord false.
162
   */
163
  void AddCoords(nscoord aMinCoord, nscoord aPrefCoord,
164
0
                 bool aHasSpecifiedCoord) {
165
0
    NS_ASSERTION(aMinCoord <= aPrefCoord, "intrinsic widths out of order");
166
0
167
0
    if (aHasSpecifiedCoord && !mHasSpecifiedCoord) {
168
0
      mPrefCoord = mMinCoord;
169
0
      mHasSpecifiedCoord = true;
170
0
    }
171
0
    if (!aHasSpecifiedCoord && mHasSpecifiedCoord) {
172
0
      aPrefCoord = aMinCoord; // NOTE: modifying argument
173
0
    }
174
0
175
0
    if (aMinCoord > mMinCoord)
176
0
      mMinCoord = aMinCoord;
177
0
    if (aPrefCoord > mPrefCoord)
178
0
      mPrefCoord = aPrefCoord;
179
0
180
0
    NS_ASSERTION(mMinCoord <= mPrefCoord, "min larger than pref");
181
0
  }
182
183
  /**
184
   * Add a percentage width specified on a cell or column element or the
185
   * contribution to this column of a percentage width specified on a
186
   * column-spanning cell.
187
   */
188
0
  void AddPrefPercent(float aPrefPercent) {
189
0
    if (aPrefPercent > mPrefPercent)
190
0
      mPrefPercent = aPrefPercent;
191
0
  }
192
193
  /**
194
   * Get the largest minimum intrinsic width for this column.
195
   */
196
0
  nscoord GetMinCoord() const { return mMinCoord; }
197
  /**
198
   * Get the largest preferred width for this column, or, if there were
199
   * any specified non-percentage widths (see GetHasSpecifiedCoord), the
200
   * largest minimum intrinsic width or specified width.
201
   */
202
0
  nscoord GetPrefCoord() const { return mPrefCoord; }
203
  /**
204
   * Get whether there were any specified widths contributing to this
205
   * column.
206
   */
207
0
  bool GetHasSpecifiedCoord() const { return mHasSpecifiedCoord; }
208
209
  /**
210
   * Get the largest specified percentage width contributing to this
211
   * column (returns 0 if there were none).
212
   */
213
0
  float GetPrefPercent() const { return mPrefPercent; }
214
215
  /**
216
   * Like AddCoords, but into a temporary buffer used for groups of
217
   * column-spanning cells.
218
   */
219
  void AddSpanCoords(nscoord aSpanMinCoord, nscoord aSpanPrefCoord,
220
0
                     bool aSpanHasSpecifiedCoord) {
221
0
    NS_ASSERTION(aSpanMinCoord <= aSpanPrefCoord,
222
0
                 "intrinsic widths out of order");
223
0
224
0
    if (!aSpanHasSpecifiedCoord && mHasSpecifiedCoord) {
225
0
      aSpanPrefCoord = aSpanMinCoord; // NOTE: modifying argument
226
0
    }
227
0
228
0
    if (aSpanMinCoord > mSpanMinCoord)
229
0
      mSpanMinCoord = aSpanMinCoord;
230
0
    if (aSpanPrefCoord > mSpanPrefCoord)
231
0
      mSpanPrefCoord = aSpanPrefCoord;
232
0
233
0
    NS_ASSERTION(mSpanMinCoord <= mSpanPrefCoord, "min larger than pref");
234
0
  }
235
236
  /*
237
   * Accumulate percentage widths on column spanning cells into
238
   * temporary variables.
239
   */
240
0
  void AddSpanPrefPercent(float aSpanPrefPercent) {
241
0
    if (aSpanPrefPercent > mSpanPrefPercent)
242
0
      mSpanPrefPercent = aSpanPrefPercent;
243
0
  }
244
245
  /*
246
   * Accumulate the temporary variables for column spanning cells into
247
   * the primary variables.
248
   */
249
0
  void AccumulateSpanIntrinsics() {
250
0
    AddCoords(mSpanMinCoord, mSpanPrefCoord, mHasSpecifiedCoord);
251
0
    AddPrefPercent(mSpanPrefPercent);
252
0
  }
253
254
  // Used to adjust a column's pref percent so that the table's total
255
  // never exceeeds 100% (by only allowing percentages to be used,
256
  // starting at the first column, until they reach 100%).
257
0
  void AdjustPrefPercent(float *aTableTotalPercent) {
258
0
    float allowed = 1.0f - *aTableTotalPercent;
259
0
    if (mPrefPercent > allowed)
260
0
      mPrefPercent = allowed;
261
0
    *aTableTotalPercent += mPrefPercent;
262
0
  }
263
264
  // The final width of the column.
265
0
  void ResetFinalISize() {
266
0
    mFinalISize = nscoord_MIN; // so we detect that it changed
267
0
  }
268
0
  void SetFinalISize(nscoord aFinalISize) {
269
0
    mFinalISize = aFinalISize;
270
0
  }
271
0
  nscoord GetFinalISize() {
272
0
    return mFinalISize;
273
0
  }
274
275
  virtual bool IsFrameOfType(uint32_t aFlags) const override
276
0
  {
277
0
    if (aFlags & eSupportsContainLayoutAndPaint) {
278
0
      return false;
279
0
    }
280
0
281
0
    return nsSplittableFrame::IsFrameOfType(aFlags & ~(nsIFrame::eTablePart));
282
0
  }
283
284
  virtual void InvalidateFrame(uint32_t aDisplayItemKey = 0, bool aRebuildDisplayItems = true) override;
285
  virtual void InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey = 0, bool aRebuildDisplayItems = true) override;
286
0
  virtual void InvalidateFrameForRemoval() override { InvalidateFrameSubtree(); }
287
288
protected:
289
290
  explicit nsTableColFrame(ComputedStyle* aStyle);
291
  ~nsTableColFrame();
292
293
  nscoord mMinCoord;
294
  nscoord mPrefCoord;
295
  nscoord mSpanMinCoord; // XXX...
296
  nscoord mSpanPrefCoord; // XXX...
297
  float mPrefPercent;
298
  float mSpanPrefPercent; // XXX...
299
  // ...XXX the four members marked above could be allocated as part of
300
  // a separate array allocated only during
301
  // BasicTableLayoutStrategy::ComputeColumnIntrinsicISizes (and only
302
  // when colspans were present).
303
  nscoord mFinalISize;
304
305
  // the index of the column with respect to the whole table (starting at 0)
306
  // it should never be smaller then the start column index of the parent
307
  // colgroup
308
  uint32_t mColIndex;
309
310
  // border width in pixels of the inner half of the border only
311
  BCPixelSize mIStartBorderWidth;
312
  BCPixelSize mIEndBorderWidth;
313
  BCPixelSize mBStartContBorderWidth;
314
  BCPixelSize mIEndContBorderWidth;
315
  BCPixelSize mBEndContBorderWidth;
316
317
  bool mHasSpecifiedCoord;
318
};
319
320
inline int32_t nsTableColFrame::GetColIndex() const
321
0
{
322
0
  return mColIndex;
323
0
}
324
325
inline void nsTableColFrame::SetColIndex (int32_t aColIndex)
326
0
{
327
0
  mColIndex = aColIndex;
328
0
}
329
330
inline nscoord
331
nsTableColFrame::GetContinuousBCBorderWidth(mozilla::WritingMode aWM,
332
                                            mozilla::LogicalMargin& aBorder)
333
0
{
334
0
  int32_t d2a = PresContext()->AppUnitsPerDevPixel();
335
0
  aBorder.BStart(aWM) = BC_BORDER_END_HALF_COORD(d2a,
336
0
                                                 mBStartContBorderWidth);
337
0
  aBorder.IEnd(aWM) = BC_BORDER_START_HALF_COORD(d2a,
338
0
                                                 mIEndContBorderWidth);
339
0
  aBorder.BEnd(aWM) = BC_BORDER_START_HALF_COORD(d2a,
340
0
                                                 mBEndContBorderWidth);
341
0
  return BC_BORDER_END_HALF_COORD(d2a, mIEndContBorderWidth);
342
0
}
343
344
#endif
345