1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/tables/nsTableColFrame.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,352 @@ 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 +#ifndef nsTableColFrame_h__ 1.9 +#define nsTableColFrame_h__ 1.10 + 1.11 +#include "mozilla/Attributes.h" 1.12 +#include "celldata.h" 1.13 +#include "nscore.h" 1.14 +#include "nsContainerFrame.h" 1.15 +#include "nsTArray.h" 1.16 + 1.17 +class nsTableCellFrame; 1.18 + 1.19 +enum nsTableColType { 1.20 + eColContent = 0, // there is real col content associated 1.21 + eColAnonymousCol = 1, // the result of a span on a col 1.22 + eColAnonymousColGroup = 2, // the result of a span on a col group 1.23 + eColAnonymousCell = 3 // the result of a cell alone 1.24 +}; 1.25 + 1.26 +class nsTableColFrame : public nsSplittableFrame { 1.27 +public: 1.28 + NS_DECL_FRAMEARENA_HELPERS 1.29 + 1.30 + enum {eWIDTH_SOURCE_NONE =0, // no cell has contributed to the width style 1.31 + eWIDTH_SOURCE_CELL =1, // a cell specified a width 1.32 + eWIDTH_SOURCE_CELL_WITH_SPAN=2 // a cell implicitly specified a width via colspan 1.33 + }; 1.34 + 1.35 + nsTableColType GetColType() const; 1.36 + void SetColType(nsTableColType aType); 1.37 + 1.38 + /** instantiate a new instance of nsTableRowFrame. 1.39 + * @param aPresShell the pres shell for this frame 1.40 + * 1.41 + * @return the frame that was created 1.42 + */ 1.43 + friend nsTableColFrame* NS_NewTableColFrame(nsIPresShell* aPresShell, 1.44 + nsStyleContext* aContext); 1.45 + /** @see nsIFrame::DidSetStyleContext */ 1.46 + virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE; 1.47 + 1.48 + int32_t GetColIndex() const; 1.49 + 1.50 + void SetColIndex (int32_t aColIndex); 1.51 + 1.52 + nsTableColFrame* GetNextCol() const; 1.53 + 1.54 + virtual nsresult Reflow(nsPresContext* aPresContext, 1.55 + nsHTMLReflowMetrics& aDesiredSize, 1.56 + const nsHTMLReflowState& aReflowState, 1.57 + nsReflowStatus& aStatus) MOZ_OVERRIDE; 1.58 + 1.59 + /** 1.60 + * Table columns never paint anything, nor receive events. 1.61 + */ 1.62 + virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, 1.63 + const nsRect& aDirtyRect, 1.64 + const nsDisplayListSet& aLists) MOZ_OVERRIDE {} 1.65 + 1.66 + /** 1.67 + * Get the "type" of the frame 1.68 + * 1.69 + * @see nsGkAtoms::tableColFrame 1.70 + */ 1.71 + virtual nsIAtom* GetType() const MOZ_OVERRIDE; 1.72 + 1.73 +#ifdef DEBUG_FRAME_DUMP 1.74 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; 1.75 +#endif 1.76 + 1.77 + virtual nsSplittableType GetSplittableType() const MOZ_OVERRIDE; 1.78 + 1.79 + /** return the number of the columns the col represents. always >= 1 */ 1.80 + int32_t GetSpan(); 1.81 + 1.82 + /** convenience method, calls into cellmap */ 1.83 + int32_t Count() const; 1.84 + 1.85 + nscoord GetLeftBorderWidth(); 1.86 + void SetLeftBorderWidth(BCPixelSize aWidth); 1.87 + nscoord GetRightBorderWidth(); 1.88 + void SetRightBorderWidth(BCPixelSize aWidth); 1.89 + 1.90 + /** 1.91 + * Gets inner border widths before collapsing with cell borders 1.92 + * Caller must get left border from previous column or from table 1.93 + * GetContinuousBCBorderWidth will not overwrite aBorder.left 1.94 + * see nsTablePainter about continuous borders 1.95 + * 1.96 + * @return outer right border width (left inner for next column) 1.97 + */ 1.98 + nscoord GetContinuousBCBorderWidth(nsMargin& aBorder); 1.99 + /** 1.100 + * Set full border widths before collapsing with cell borders 1.101 + * @param aForSide - side to set; only valid for top, right, and bottom 1.102 + */ 1.103 + void SetContinuousBCBorderWidth(uint8_t aForSide, 1.104 + BCPixelSize aPixelValue); 1.105 +#ifdef DEBUG 1.106 + void Dump(int32_t aIndent); 1.107 +#endif 1.108 + 1.109 + /** 1.110 + * Restore the default values of the intrinsic widths, so that we can 1.111 + * re-accumulate intrinsic widths from the cells in the column. 1.112 + */ 1.113 + void ResetIntrinsics() { 1.114 + mMinCoord = 0; 1.115 + mPrefCoord = 0; 1.116 + mPrefPercent = 0.0f; 1.117 + mHasSpecifiedCoord = false; 1.118 + } 1.119 + 1.120 + /** 1.121 + * Restore the default value of the preferred percentage width (the 1.122 + * only intrinsic width used by FixedTableLayoutStrategy. 1.123 + */ 1.124 + void ResetPrefPercent() { 1.125 + mPrefPercent = 0.0f; 1.126 + } 1.127 + 1.128 + /** 1.129 + * Restore the default values of the temporary buffer for 1.130 + * spanning-cell intrinsic widths (as we process spanning cells). 1.131 + */ 1.132 + void ResetSpanIntrinsics() { 1.133 + mSpanMinCoord = 0; 1.134 + mSpanPrefCoord = 0; 1.135 + mSpanPrefPercent = 0.0f; 1.136 + } 1.137 + 1.138 + /** 1.139 + * Add the widths for a cell or column element, or the contribution of 1.140 + * the widths from a column-spanning cell: 1.141 + * @param aMinCoord The minimum intrinsic width 1.142 + * @param aPrefCoord The preferred intrinsic width or, if there is a 1.143 + * specified non-percentage width, max(specified width, minimum intrinsic 1.144 + * width). 1.145 + * @param aHasSpecifiedCoord Whether there is a specified 1.146 + * non-percentage width. 1.147 + * 1.148 + * Note that the implementation of this functions is a bit tricky 1.149 + * since mPrefCoord means different things depending on 1.150 + * whether mHasSpecifiedCoord is true (and likewise for aPrefCoord and 1.151 + * aHasSpecifiedCoord). If mHasSpecifiedCoord is false, then 1.152 + * all widths added had aHasSpecifiedCoord false and mPrefCoord is the 1.153 + * largest of the pref widths. But if mHasSpecifiedCoord is true, 1.154 + * then mPrefCoord is the largest of (1) the pref widths for cells 1.155 + * with aHasSpecifiedCoord true and (2) the min widths for cells with 1.156 + * aHasSpecifiedCoord false. 1.157 + */ 1.158 + void AddCoords(nscoord aMinCoord, nscoord aPrefCoord, 1.159 + bool aHasSpecifiedCoord) { 1.160 + NS_ASSERTION(aMinCoord <= aPrefCoord, "intrinsic widths out of order"); 1.161 + 1.162 + if (aHasSpecifiedCoord && !mHasSpecifiedCoord) { 1.163 + mPrefCoord = mMinCoord; 1.164 + mHasSpecifiedCoord = true; 1.165 + } 1.166 + if (!aHasSpecifiedCoord && mHasSpecifiedCoord) { 1.167 + aPrefCoord = aMinCoord; // NOTE: modifying argument 1.168 + } 1.169 + 1.170 + if (aMinCoord > mMinCoord) 1.171 + mMinCoord = aMinCoord; 1.172 + if (aPrefCoord > mPrefCoord) 1.173 + mPrefCoord = aPrefCoord; 1.174 + 1.175 + NS_ASSERTION(mMinCoord <= mPrefCoord, "min larger than pref"); 1.176 + } 1.177 + 1.178 + /** 1.179 + * Add a percentage width specified on a cell or column element or the 1.180 + * contribution to this column of a percentage width specified on a 1.181 + * column-spanning cell. 1.182 + */ 1.183 + void AddPrefPercent(float aPrefPercent) { 1.184 + if (aPrefPercent > mPrefPercent) 1.185 + mPrefPercent = aPrefPercent; 1.186 + } 1.187 + 1.188 + /** 1.189 + * Get the largest minimum intrinsic width for this column. 1.190 + */ 1.191 + nscoord GetMinCoord() const { return mMinCoord; } 1.192 + /** 1.193 + * Get the largest preferred width for this column, or, if there were 1.194 + * any specified non-percentage widths (see GetHasSpecifiedCoord), the 1.195 + * largest minimum intrinsic width or specified width. 1.196 + */ 1.197 + nscoord GetPrefCoord() const { return mPrefCoord; } 1.198 + /** 1.199 + * Get whether there were any specified widths contributing to this 1.200 + * column. 1.201 + */ 1.202 + bool GetHasSpecifiedCoord() const { return mHasSpecifiedCoord; } 1.203 + 1.204 + /** 1.205 + * Get the largest specified percentage width contributing to this 1.206 + * column (returns 0 if there were none). 1.207 + */ 1.208 + float GetPrefPercent() const { return mPrefPercent; } 1.209 + 1.210 + /** 1.211 + * Like AddCoords, but into a temporary buffer used for groups of 1.212 + * column-spanning cells. 1.213 + */ 1.214 + void AddSpanCoords(nscoord aSpanMinCoord, nscoord aSpanPrefCoord, 1.215 + bool aSpanHasSpecifiedCoord) { 1.216 + NS_ASSERTION(aSpanMinCoord <= aSpanPrefCoord, 1.217 + "intrinsic widths out of order"); 1.218 + 1.219 + if (!aSpanHasSpecifiedCoord && mHasSpecifiedCoord) { 1.220 + aSpanPrefCoord = aSpanMinCoord; // NOTE: modifying argument 1.221 + } 1.222 + 1.223 + if (aSpanMinCoord > mSpanMinCoord) 1.224 + mSpanMinCoord = aSpanMinCoord; 1.225 + if (aSpanPrefCoord > mSpanPrefCoord) 1.226 + mSpanPrefCoord = aSpanPrefCoord; 1.227 + 1.228 + NS_ASSERTION(mSpanMinCoord <= mSpanPrefCoord, "min larger than pref"); 1.229 + } 1.230 + 1.231 + /* 1.232 + * Accumulate percentage widths on column spanning cells into 1.233 + * temporary variables. 1.234 + */ 1.235 + void AddSpanPrefPercent(float aSpanPrefPercent) { 1.236 + if (aSpanPrefPercent > mSpanPrefPercent) 1.237 + mSpanPrefPercent = aSpanPrefPercent; 1.238 + } 1.239 + 1.240 + /* 1.241 + * Accumulate the temporary variables for column spanning cells into 1.242 + * the primary variables. 1.243 + */ 1.244 + void AccumulateSpanIntrinsics() { 1.245 + AddCoords(mSpanMinCoord, mSpanPrefCoord, mHasSpecifiedCoord); 1.246 + AddPrefPercent(mSpanPrefPercent); 1.247 + } 1.248 + 1.249 + // Used to adjust a column's pref percent so that the table's total 1.250 + // never exceeeds 100% (by only allowing percentages to be used, 1.251 + // starting at the first column, until they reach 100%). 1.252 + void AdjustPrefPercent(float *aTableTotalPercent) { 1.253 + float allowed = 1.0f - *aTableTotalPercent; 1.254 + if (mPrefPercent > allowed) 1.255 + mPrefPercent = allowed; 1.256 + *aTableTotalPercent += mPrefPercent; 1.257 + } 1.258 + 1.259 + // The final width of the column. 1.260 + void ResetFinalWidth() { 1.261 + mFinalWidth = nscoord_MIN; // so we detect that it changed 1.262 + } 1.263 + void SetFinalWidth(nscoord aFinalWidth) { 1.264 + mFinalWidth = aFinalWidth; 1.265 + } 1.266 + nscoord GetFinalWidth() { 1.267 + return mFinalWidth; 1.268 + } 1.269 + 1.270 + virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE 1.271 + { 1.272 + return nsSplittableFrame::IsFrameOfType(aFlags & ~(nsIFrame::eTablePart)); 1.273 + } 1.274 + 1.275 + virtual void InvalidateFrame(uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE; 1.276 + virtual void InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE; 1.277 + virtual void InvalidateFrameForRemoval() MOZ_OVERRIDE { InvalidateFrameSubtree(); } 1.278 + 1.279 +protected: 1.280 + 1.281 + nsTableColFrame(nsStyleContext* aContext); 1.282 + ~nsTableColFrame(); 1.283 + 1.284 + nscoord mMinCoord; 1.285 + nscoord mPrefCoord; 1.286 + nscoord mSpanMinCoord; // XXX... 1.287 + nscoord mSpanPrefCoord; // XXX... 1.288 + float mPrefPercent; 1.289 + float mSpanPrefPercent; // XXX... 1.290 + // ...XXX the four members marked above could be allocated as part of 1.291 + // a separate array allocated only during 1.292 + // BasicTableLayoutStrategy::ComputeColumnIntrinsicWidths (and only 1.293 + // when colspans were present). 1.294 + nscoord mFinalWidth; 1.295 + 1.296 + // the index of the column with respect to the whole table (starting at 0) 1.297 + // it should never be smaller then the start column index of the parent 1.298 + // colgroup 1.299 + uint32_t mColIndex; 1.300 + 1.301 + // border width in pixels of the inner half of the border only 1.302 + BCPixelSize mLeftBorderWidth; 1.303 + BCPixelSize mRightBorderWidth; 1.304 + BCPixelSize mTopContBorderWidth; 1.305 + BCPixelSize mRightContBorderWidth; 1.306 + BCPixelSize mBottomContBorderWidth; 1.307 + 1.308 + bool mHasSpecifiedCoord; 1.309 +}; 1.310 + 1.311 +inline int32_t nsTableColFrame::GetColIndex() const 1.312 +{ 1.313 + return mColIndex; 1.314 +} 1.315 + 1.316 +inline void nsTableColFrame::SetColIndex (int32_t aColIndex) 1.317 +{ 1.318 + mColIndex = aColIndex; 1.319 +} 1.320 + 1.321 +inline nscoord nsTableColFrame::GetLeftBorderWidth() 1.322 +{ 1.323 + return mLeftBorderWidth; 1.324 +} 1.325 + 1.326 +inline void nsTableColFrame::SetLeftBorderWidth(BCPixelSize aWidth) 1.327 +{ 1.328 + mLeftBorderWidth = aWidth; 1.329 +} 1.330 + 1.331 +inline nscoord nsTableColFrame::GetRightBorderWidth() 1.332 +{ 1.333 + return mRightBorderWidth; 1.334 +} 1.335 + 1.336 +inline void nsTableColFrame::SetRightBorderWidth(BCPixelSize aWidth) 1.337 +{ 1.338 + mRightBorderWidth = aWidth; 1.339 +} 1.340 + 1.341 +inline nscoord 1.342 +nsTableColFrame::GetContinuousBCBorderWidth(nsMargin& aBorder) 1.343 +{ 1.344 + int32_t aPixelsToTwips = nsPresContext::AppUnitsPerCSSPixel(); 1.345 + aBorder.top = BC_BORDER_BOTTOM_HALF_COORD(aPixelsToTwips, 1.346 + mTopContBorderWidth); 1.347 + aBorder.right = BC_BORDER_LEFT_HALF_COORD(aPixelsToTwips, 1.348 + mRightContBorderWidth); 1.349 + aBorder.bottom = BC_BORDER_TOP_HALF_COORD(aPixelsToTwips, 1.350 + mBottomContBorderWidth); 1.351 + return BC_BORDER_RIGHT_HALF_COORD(aPixelsToTwips, mRightContBorderWidth); 1.352 +} 1.353 + 1.354 +#endif 1.355 +