Back to index

lightning-sunbird  0.9+nobinonly
nsCSSRendering.h
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 #ifndef nsCSSRendering_h___
00038 #define nsCSSRendering_h___
00039 
00040 #include "nsIRenderingContext.h"
00041 struct nsPoint;
00042 class nsStyleContext;
00043 class nsPresContext;
00044 
00045 class nsCSSRendering {
00046 public:
00055   static void PaintBorder(nsPresContext* aPresContext,
00056                           nsIRenderingContext& aRenderingContext,
00057                           nsIFrame* aForFrame,
00058                           const nsRect& aDirtyRect,
00059                           const nsRect& aBorderArea,
00060                           const nsStyleBorder& aBorderStyle,
00061                           nsStyleContext* aStyleContext,
00062                           PRIntn aSkipSides,
00063                           nsRect* aGap = 0,
00064                           nscoord aHardBorderSize = 0,
00065                           PRBool aShouldIgnoreRounded = PR_FALSE);
00066 
00075   static void PaintOutline(nsPresContext* aPresContext,
00076                           nsIRenderingContext& aRenderingContext,
00077                           nsIFrame* aForFrame,
00078                           const nsRect& aDirtyRect,
00079                           const nsRect& aBorderArea,
00080                           const nsStyleBorder& aBorderStyle,
00081                           const nsStyleOutline& aOutlineStyle,
00082                           nsStyleContext* aStyleContext,
00083                           PRIntn aSkipSides,
00084                           nsRect* aGap = 0);
00085 
00097   static void PaintBorderEdges(nsPresContext* aPresContext,
00098                                nsIRenderingContext& aRenderingContext,
00099                                nsIFrame* aForFrame,
00100                                const nsRect& aDirtyRect,
00101                                const nsRect& aBorderArea,
00102                                nsBorderEdges * aBorderEdges,
00103                                nsStyleContext* aStyleContext,
00104                                PRIntn aSkipSides,
00105                                nsRect* aGap = 0);
00106 
00107 
00114   static PRBool FindBackground(nsPresContext* aPresContext,
00115                                nsIFrame* aForFrame,
00116                                const nsStyleBackground** aBackground,
00117                                PRBool* aIsCanvas);
00118 
00125   static const nsStyleBackground*
00126   FindNonTransparentBackground(nsStyleContext* aContext,
00127                                PRBool aStartAtParent = PR_FALSE);
00128 
00136   static void PaintBackground(nsPresContext* aPresContext,
00137                               nsIRenderingContext& aRenderingContext,
00138                               nsIFrame* aForFrame,
00139                               const nsRect& aDirtyRect,
00140                               const nsRect& aBorderArea,
00141                               const nsStyleBorder& aBorder,
00142                               const nsStylePadding& aPadding,
00143                               PRBool aUsePrintSettings,
00144                               nsRect* aBGClipRect = nsnull);
00145 
00151   static void PaintBackgroundWithSC(nsPresContext* aPresContext,
00152                                     nsIRenderingContext& aRenderingContext,
00153                                     nsIFrame* aForFrame,
00154                                     const nsRect& aDirtyRect,
00155                                     const nsRect& aBorderArea,
00156                                     const nsStyleBackground& aColor,
00157                                     const nsStyleBorder& aBorder,
00158                                     const nsStylePadding& aPadding,
00159                                     PRBool aUsePrintSettings = PR_FALSE,
00160                                     nsRect* aBGClipRect = nsnull);
00161 
00166   static void DidPaint();
00167 
00168 
00169   static void DrawDashedSides(PRIntn startSide,
00170                               nsIRenderingContext& aContext,
00171                               const nsRect& aDirtyRect,
00172                               const PRUint8 borderStyles[],
00173                               const nscolor borderColors[],    
00174                               const nsRect& borderOutside,
00175                               const nsRect& borderInside,
00176                               PRIntn aSkipSides,
00177                               nsRect* aGap);
00178 
00179   static void DrawDashedSides(PRIntn startSide,
00180                               nsIRenderingContext& aContext,
00181                               const nsRect& aDirtyRect,
00182                               const nsStyleColor* aColorStyle,
00183                               const nsStyleBorder* aBorderStyle,  
00184                               const nsStyleOutline* aOutlineStyle,  
00185                               PRBool aDoOutline,
00186                               const nsRect& borderOutside,
00187                               const nsRect& borderInside,
00188                               PRIntn aSkipSides,
00189                               nsRect* aGap);
00190 
00192   //XXX: boy is it annoying that we have 3 methods to draw dashed sides!
00193   //     they clearly can be factored.
00194   static void DrawDashedSegments(nsIRenderingContext& aContext,
00195                                  const nsRect& aBounds,
00196                                  nsBorderEdges * aBorderEdges,
00197                                  PRIntn aSkipSides,
00198                                  nsRect* aGap);
00199 
00200   // Draw a border segment in the table collapsing border model without beveling corners
00201   static void DrawTableBorderSegment(nsIRenderingContext&     aContext,
00202                                      PRUint8                  aBorderStyle,  
00203                                      nscolor                  aBorderColor,
00204                                      const nsStyleBackground* aBGColor,
00205                                      const nsRect&            aBorderRect,
00206                                      float                    aPixelsToTwips,
00207                                      PRUint8                  aStartBevelSide = 0,
00208                                      nscoord                  aStartBevelOffset = 0,
00209                                      PRUint8                  aEndBevelSide = 0,
00210                                      nscoord                  aEndBevelOffset = 0);
00217   static nscolor TransformColor(nscolor  aMapColor,PRBool aNoBackGround);
00218 
00219 protected:
00227   static void PaintRoundedBorder(nsPresContext* aPresContext,
00228                           nsIRenderingContext& aRenderingContext,
00229                           nsIFrame* aForFrame,
00230                           const nsRect& aDirtyRect,
00231                           const nsRect& aBorderArea,
00232                           const nsStyleBorder* aBorderStyle,
00233                           const nsStyleOutline* aOutlineStyle,
00234                           nsStyleContext* aStyleContext,
00235                           PRIntn aSkipSides,
00236                           PRInt16 aBorderRadius[4],nsRect* aGap = 0,
00237                           PRBool aIsOutline=PR_FALSE);
00238 
00239   static void RenderSide(nsFloatPoint aPoints[],nsIRenderingContext& aRenderingContext,
00240                         const nsStyleBorder* aBorderStyle,const nsStyleOutline* aOutlineStyle,nsStyleContext* aStyleContext,
00241                         PRUint8 aSide,nsMargin  &aBorThick,nscoord aTwipsPerPixel,
00242                         PRBool aIsOutline=PR_FALSE);
00243 
00244   static void PaintBackgroundColor(nsPresContext* aPresContext,
00245                                    nsIRenderingContext& aRenderingContext,
00246                                    nsIFrame* aForFrame,
00247                                    const nsRect& aBgClipArea,
00248                                    const nsStyleBackground& aColor,
00249                                    const nsStyleBorder& aBorder,
00250                                    const nsStylePadding& aPadding,
00251                                    PRBool aCanPaintNonWhite);
00252 
00253   static void PaintRoundedBackground(nsPresContext* aPresContext,
00254                                      nsIRenderingContext& aRenderingContext,
00255                                      nsIFrame* aForFrame,
00256                                      const nsRect& aBorderArea,
00257                                      const nsStyleBackground& aColor,
00258                                      const nsStyleBorder& aBorder,
00259                                      PRInt16 aTheRadius[4],
00260                                      PRBool aCanPaintNonWhite);
00261 
00262   static nscolor MakeBevelColor(PRIntn whichSide, PRUint8 style,
00263                                 nscolor aBackgroundColor,
00264                                 nscolor aBorderColor,
00265                                 PRBool aSpecialCase);
00266 
00267   static PRIntn MakeSide(nsPoint aPoints[],
00268                          nsIRenderingContext& aContext,
00269                          PRIntn whichSide,
00270                          const nsRect& outside, const nsRect& inside,
00271                          PRIntn aSkipSides,
00272                          PRIntn borderPart, float borderFrac,
00273                          nscoord twipsPerPixel);
00274 
00275   static void DrawSide(nsIRenderingContext& aContext,
00276                        PRIntn whichSide,
00277                        const PRUint8 borderStyle,
00278                        const nscolor borderColor,
00279                        const nscolor aBackgroundColor, 
00280                        const nsRect& borderOutside,
00281                        const nsRect& borderInside,
00282                        PRIntn aSkipSides,
00283                        nscoord twipsPerPixel,
00284                        nsRect* aGap = 0);
00285 
00286 
00287   static void DrawCompositeSide(nsIRenderingContext& aContext,
00288                                 PRIntn aWhichSide,
00289                                 nsBorderColors* aCompositeColors,
00290                                 const nsRect& aOuterRect,
00291                                 const nsRect& aInnerRect,
00292                                 PRInt16* aBorderRadii,
00293                                 nscoord aTwipsPerPixel,
00294                                 nsRect* aGap);
00295 
00296   static void DrawLine (nsIRenderingContext& aContext, 
00297                         nscoord aX1, nscoord aY1, nscoord aX2, nscoord aY2,
00298                         nsRect* aGap);
00299 
00300   static void FillPolygon (nsIRenderingContext& aContext, 
00301                            const nsPoint aPoints[],
00302                            PRInt32 aNumPoints,
00303                            nsRect* aGap);
00304 
00305 };
00306 
00307 
00308 
00313 class QBCurve
00314 {
00315 
00316 public:
00317        nsFloatPoint  mAnc1;
00318        nsFloatPoint  mCon;
00319        nsFloatPoint mAnc2;
00320 
00321   QBCurve() {mAnc1.x=0;mAnc1.y=0;mCon=mAnc2=mAnc1;}
00322   void SetControls(nsFloatPoint &aAnc1,nsFloatPoint &aCon,nsFloatPoint &aAnc2) { mAnc1 = aAnc1; mCon = aCon; mAnc2 = aAnc2;}
00323   void SetPoints(float a1x,float a1y,float acx,float acy,float a2x,float a2y) {mAnc1.MoveTo(a1x,a1y),mCon.MoveTo(acx,acy),mAnc2.MoveTo(a2x,a2y);}
00324 
00333   void SubDivide(nsIRenderingContext *aRenderingContext,nsPoint  aPointArray[],PRInt32 *aCurIndex);
00334 
00341   void MidPointDivide(QBCurve *A,QBCurve *B);
00342 };
00343 
00344 
00350 class RoundedRect
00351 {
00352 
00353 public:
00354   PRInt32 mRoundness[4];
00355 
00356   PRBool  mDoRound;
00357 
00358   PRInt32 mLeft;
00359   PRInt32 mRight;
00360   PRInt32 mTop;
00361   PRInt32 mBottom;
00362 
00367   void  RoundRect() {mRoundness[0]=0;}
00368 
00378   void  Set(nscoord aLeft,nscoord aTop,PRInt32  aWidth,PRInt32 aHeight,PRInt16 aRadius[4],PRInt16 aNumTwipPerPix);
00379 
00380 
00387   void  CalcInsetCurves(QBCurve &aULCurve,QBCurve &aURCurve,QBCurve &aLLCurve,QBCurve &aLRCurve,nsMargin &aBorder);
00388 
00397   void GetRoundedBorders(QBCurve &aULCurve,QBCurve &aURCurve,QBCurve &aLLCurve,QBCurve &aLRCurve);
00398 
00399 };
00400 
00401 
00402 #endif /* nsCSSRendering_h___ */