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