Back to index

lightning-sunbird  0.9+nobinonly
nsTableColFrame.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #include "nsCOMPtr.h"
00038 #include "nsTableColFrame.h"
00039 #include "nsTableFrame.h"
00040 #include "nsContainerFrame.h"
00041 #include "nsStyleContext.h"
00042 #include "nsStyleConsts.h"
00043 #include "nsPresContext.h"
00044 #include "nsHTMLAtoms.h"
00045 #include "nsCSSRendering.h"
00046 #include "nsLayoutAtoms.h"
00047 #include "nsIContent.h"
00048 #include "nsIDOMHTMLTableColElement.h"
00049 
00050 #define COL_TYPE_BITS                 0xF0000000 // uses bits 29-32 from mState
00051 #define COL_TYPE_OFFSET               28
00052 
00053 #define COL_CONSTRAINT_BITS           0x07000000 // uses bits 25-27
00054 #define COL_CONSTRAINT_OFFSET         24
00055 
00056 nsTableColFrame::nsTableColFrame()
00057   : nsFrame()
00058 {
00059   SetColType(eColContent);
00060   ResetSizingInfo();
00061 }
00062 
00063 nsTableColFrame::~nsTableColFrame()
00064 {
00065 }
00066 
00067 nsTableColType 
00068 nsTableColFrame::GetColType() const 
00069 {
00070   return (nsTableColType)((mState & COL_TYPE_BITS) >> COL_TYPE_OFFSET);
00071 }
00072 
00073 void 
00074 nsTableColFrame::SetColType(nsTableColType aType) 
00075 {
00076   PRUint32 type = aType - eColContent;
00077   mState |= (type << COL_TYPE_OFFSET);
00078 }
00079 
00080 nsColConstraint 
00081 nsTableColFrame::GetConstraint() const
00082 { 
00083   return (nsColConstraint)((mState & COL_CONSTRAINT_BITS) >> COL_CONSTRAINT_OFFSET);
00084 }
00085 
00086 void 
00087 nsTableColFrame::SetConstraint(nsColConstraint aConstraint)
00088 { 
00089   PRUint32 con = aConstraint - eNoConstraint;
00090   mState |= (con << COL_CONSTRAINT_OFFSET);
00091 }
00092 
00093 // XXX what about other style besides width
00094 nsStyleCoord nsTableColFrame::GetStyleWidth() const
00095 {
00096   nsStyleCoord styleWidth = GetStylePosition()->mWidth;
00097   if (eStyleUnit_Auto == styleWidth.GetUnit()) {
00098     styleWidth = GetParent()->GetStylePosition()->mWidth;
00099   }
00100 
00101   nsStyleCoord returnWidth;
00102   returnWidth.mUnit  = styleWidth.mUnit;
00103   returnWidth.mValue = styleWidth.mValue;
00104   return returnWidth;
00105 }
00106 
00107 void nsTableColFrame::SetContinuousBCBorderWidth(PRUint8     aForSide,
00108                                                  BCPixelSize aPixelValue)
00109 {
00110   switch (aForSide) {
00111     case NS_SIDE_TOP:
00112       mTopContBorderWidth = aPixelValue;
00113       return;
00114     case NS_SIDE_RIGHT:
00115       mRightContBorderWidth = aPixelValue;
00116       return;
00117     case NS_SIDE_BOTTOM:
00118       mBottomContBorderWidth = aPixelValue;
00119       return;
00120     default:
00121       NS_ERROR("invalid side arg");
00122   }
00123 }
00124 
00125 void nsTableColFrame::ResetSizingInfo()
00126 {
00127   memset(mWidths, WIDTH_NOT_SET, NUM_WIDTHS * sizeof(PRInt32));
00128   SetConstraint(eNoConstraint);
00129 }
00130 
00131 NS_METHOD 
00132 nsTableColFrame::Paint(nsPresContext*      aPresContext,
00133                        nsIRenderingContext& aRenderingContext,
00134                        const nsRect&        aDirtyRect,
00135                        nsFramePaintLayer    aWhichLayer,
00136                        PRUint32             aFlags)
00137 {
00138   PRBool isVisible;
00139   if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_FALSE, &isVisible)) && !isVisible) {
00140     return NS_OK;
00141   }
00142 
00143   return NS_OK;
00144 }
00145 
00146 // override, since we want to act like a block
00147 NS_IMETHODIMP
00148 nsTableColFrame::GetFrameForPoint(const nsPoint& aPoint,
00149                           nsFramePaintLayer aWhichLayer,
00150                           nsIFrame** aFrame)
00151 {
00152   return NS_ERROR_FAILURE;
00153 }
00154 
00155 NS_METHOD nsTableColFrame::Reflow(nsPresContext*          aPresContext,
00156                                   nsHTMLReflowMetrics&     aDesiredSize,
00157                                   const nsHTMLReflowState& aReflowState,
00158                                   nsReflowStatus&          aStatus)
00159 {
00160   DO_GLOBAL_REFLOW_COUNT("nsTableColFrame", aReflowState.reason);
00161   DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
00162   aDesiredSize.width=0;
00163   aDesiredSize.height=0;
00164   const nsStyleVisibility* colVis = GetStyleVisibility();
00165   PRBool collapseCol = (NS_STYLE_VISIBILITY_COLLAPSE == colVis->mVisible);
00166   if (collapseCol) {
00167     nsTableFrame* tableFrame = nsnull;
00168     nsTableFrame::GetTableFrame(this, tableFrame);
00169     if (tableFrame)  {
00170       tableFrame->SetNeedToCollapseColumns(PR_TRUE);
00171     }    
00172   }
00173   if (aDesiredSize.mComputeMEW)
00174   {
00175     aDesiredSize.mMaxElementWidth=0;
00176   }
00177   aStatus = NS_FRAME_COMPLETE;
00178   NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
00179   return NS_OK;
00180 }
00181 
00182 PRInt32 nsTableColFrame::GetSpan()
00183 {
00184   return GetStyleTable()->mSpan;
00185 }
00186 
00187 nscoord nsTableColFrame::GetWidth(PRUint32 aWidthType)
00188 {
00189   NS_ASSERTION(aWidthType < NUM_WIDTHS, "GetWidth: bad width type");
00190   return mWidths[aWidthType];
00191 }
00192 
00193 void nsTableColFrame::SetWidth(PRUint32 aWidthType,
00194                                nscoord  aWidth)
00195 {
00196   NS_ASSERTION(aWidthType < NUM_WIDTHS, "SetWidth: bad width type");
00197   mWidths[aWidthType] = aWidth;
00198 #ifdef MY_DEBUG
00199   if (aWidth > 0) {
00200     nscoord minWidth = GetMinWidth();
00201     if ((MIN_CON != aWidthType) && (aWidth < minWidth)) {
00202       printf("non min width set to lower than min \n");
00203     }
00204   }
00205 #endif
00206 }
00207 
00208 nscoord nsTableColFrame::GetMinWidth()
00209 {
00210   return PR_MAX(mWidths[MIN_CON], mWidths[MIN_ADJ]);
00211 }
00212 
00213 nscoord nsTableColFrame::GetDesWidth()
00214 {
00215   return PR_MAX(mWidths[DES_CON], mWidths[DES_ADJ]);
00216 }
00217 
00218 nscoord nsTableColFrame::GetFixWidth()
00219 {
00220   return PR_MAX(mWidths[FIX], mWidths[FIX_ADJ]);
00221 }
00222 
00223 nscoord nsTableColFrame::GetPctWidth()
00224 {
00225   return PR_MAX(mWidths[PCT], mWidths[PCT_ADJ]);
00226 }
00227 
00228 #ifdef DEBUG
00229 void nsTableColFrame::Dump(PRInt32 aIndent)
00230 {
00231   char* indent = new char[aIndent + 1];
00232   if (!indent) return;
00233   for (PRInt32 i = 0; i < aIndent + 1; i++) {
00234     indent[i] = ' ';
00235   }
00236   indent[aIndent] = 0;
00237 
00238   printf("%s**START COL DUMP**\n%s colIndex=%d constraint=%d coltype=",
00239     indent, indent, mColIndex, GetConstraint());
00240   nsTableColType colType = GetColType();
00241   switch (colType) {
00242   case eColContent:
00243     printf(" content ");
00244     break;
00245   case eColAnonymousCol: 
00246     printf(" anonymous-column ");
00247     break;
00248   case eColAnonymousColGroup:
00249     printf(" anonymous-colgroup ");
00250     break;
00251   case eColAnonymousCell: 
00252     printf(" anonymous-cell ");
00253     break;
00254   }
00255   printf("\n%s widths=", indent);
00256   for (PRInt32 widthX = 0; widthX < NUM_WIDTHS; widthX++) {
00257     printf("%d ", mWidths[widthX]);
00258   }
00259   printf("\n%s**END COL DUMP** ", indent);
00260   delete [] indent;
00261 }
00262 #endif
00263 /* ----- global methods ----- */
00264 
00265 nsresult 
00266 NS_NewTableColFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
00267 {
00268   NS_PRECONDITION(aNewFrame, "null OUT ptr");
00269   if (nsnull == aNewFrame) {
00270     return NS_ERROR_NULL_POINTER;
00271   }
00272   nsTableColFrame* it = new (aPresShell) nsTableColFrame;
00273   if (nsnull == it) {
00274     return NS_ERROR_OUT_OF_MEMORY;
00275   }
00276   *aNewFrame = it;
00277   return NS_OK;
00278 }
00279 
00280 NS_IMETHODIMP
00281 nsTableColFrame::Init(nsPresContext*  aPresContext,
00282                       nsIContent*      aContent,
00283                       nsIFrame*        aParent,
00284                       nsStyleContext*  aContext,
00285                       nsIFrame*        aPrevInFlow)
00286 {
00287   nsresult  rv;
00288 
00289   // Let the the base class do its initialization
00290   rv = nsFrame::Init(aPresContext, aContent, aParent, aContext,
00291                      aPrevInFlow);
00292 
00293   // record that children that are ignorable whitespace should be excluded 
00294   mState |= NS_FRAME_EXCLUDE_IGNORABLE_WHITESPACE;
00295 
00296   return rv;
00297 }
00298 
00299 nsTableColFrame*  
00300 nsTableColFrame::GetNextCol() const
00301 {
00302   nsIFrame* childFrame = GetNextSibling();
00303   while (childFrame) {
00304     if (nsLayoutAtoms::tableColFrame == childFrame->GetType()) {
00305       return (nsTableColFrame*)childFrame;
00306     }
00307     childFrame = childFrame->GetNextSibling();
00308   }
00309   return nsnull;
00310 }
00311 
00312 nsIAtom*
00313 nsTableColFrame::GetType() const
00314 {
00315   return nsLayoutAtoms::tableColFrame;
00316 }
00317 
00318 #ifdef DEBUG
00319 NS_IMETHODIMP
00320 nsTableColFrame::GetFrameName(nsAString& aResult) const
00321 {
00322   return MakeFrameName(NS_LITERAL_STRING("TableCol"), aResult);
00323 }
00324 #endif