2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-30 09:56:38 +04:00
|
|
|
|
|
|
|
/* utility functions for drawing borders and backgrounds */
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#ifndef nsCSSRendering_h___
|
|
|
|
#define nsCSSRendering_h___
|
|
|
|
|
|
|
|
#include "nsIRenderingContext.h"
|
2007-08-06 12:15:00 +04:00
|
|
|
#include "gfxContext.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
struct nsPoint;
|
2003-02-22 03:32:13 +03:00
|
|
|
class nsStyleContext;
|
2004-08-01 03:15:21 +04:00
|
|
|
class nsPresContext;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
class nsCSSRendering {
|
|
|
|
public:
|
2007-03-14 22:48:51 +03:00
|
|
|
/**
|
|
|
|
* Initialize any static variables used by nsCSSRendering.
|
|
|
|
*/
|
|
|
|
static nsresult Init();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up any static variables used by nsCSSRendering.
|
|
|
|
*/
|
|
|
|
static void Shutdown();
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/**
|
|
|
|
* Render the border for an element using css rendering rules
|
|
|
|
* for borders. aSkipSides is a bitmask of the sides to skip
|
|
|
|
* when rendering. If 0 then no sides are skipped.
|
1998-07-22 06:46:00 +04:00
|
|
|
*
|
1999-01-15 21:25:58 +03:00
|
|
|
* Both aDirtyRect and aBorderArea are in the local coordinate space
|
1998-07-22 06:46:00 +04:00
|
|
|
* of aForFrame
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
2004-08-01 03:15:21 +04:00
|
|
|
static void PaintBorder(nsPresContext* aPresContext,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
1999-01-15 21:25:58 +03:00
|
|
|
const nsRect& aBorderArea,
|
2001-02-07 12:57:26 +03:00
|
|
|
const nsStyleBorder& aBorderStyle,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* aStyleContext,
|
1998-10-08 08:38:41 +04:00
|
|
|
PRIntn aSkipSides,
|
1999-09-03 18:12:09 +04:00
|
|
|
nsRect* aGap = 0,
|
|
|
|
nscoord aHardBorderSize = 0,
|
|
|
|
PRBool aShouldIgnoreRounded = PR_FALSE);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-08-19 18:22:47 +04:00
|
|
|
/**
|
|
|
|
* Render the outline for an element using css rendering rules
|
|
|
|
* for borders. aSkipSides is a bitmask of the sides to skip
|
|
|
|
* when rendering. If 0 then no sides are skipped.
|
|
|
|
*
|
|
|
|
* Both aDirtyRect and aBorderArea are in the local coordinate space
|
|
|
|
* of aForFrame
|
|
|
|
*/
|
2004-08-01 03:15:21 +04:00
|
|
|
static void PaintOutline(nsPresContext* aPresContext,
|
1999-08-19 18:22:47 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
2001-02-07 12:57:26 +03:00
|
|
|
const nsStyleBorder& aBorderStyle,
|
|
|
|
const nsStyleOutline& aOutlineStyle,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* aStyleContext,
|
1999-08-19 18:22:47 +04:00
|
|
|
nsRect* aGap = 0);
|
|
|
|
|
2002-01-08 02:46:07 +03:00
|
|
|
/**
|
|
|
|
* Fill in an nsStyleBackground to be used to paint the background for
|
|
|
|
* an element. The nsStyleBackground should first be initialized
|
|
|
|
* using the pres context. This applies the rules for propagating
|
|
|
|
* backgrounds between BODY, the root element, and the canvas.
|
2006-01-26 05:29:17 +03:00
|
|
|
* @return PR_TRUE if there is some meaningful background.
|
2002-01-08 02:46:07 +03:00
|
|
|
*/
|
2004-08-01 03:15:21 +04:00
|
|
|
static PRBool FindBackground(nsPresContext* aPresContext,
|
2002-01-08 02:46:07 +03:00
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsStyleBackground** aBackground,
|
|
|
|
PRBool* aIsCanvas);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2002-08-11 21:56:15 +04:00
|
|
|
/**
|
|
|
|
* Find a non-transparent background, for various table-related and
|
|
|
|
* HR-related backwards-compatibility hacks. Be very hesitant if
|
|
|
|
* you're considering calling this function -- it's usually not what
|
|
|
|
* you want.
|
|
|
|
*/
|
|
|
|
static const nsStyleBackground*
|
2003-02-22 03:32:13 +03:00
|
|
|
FindNonTransparentBackground(nsStyleContext* aContext,
|
2002-08-11 21:56:15 +04:00
|
|
|
PRBool aStartAtParent = PR_FALSE);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/**
|
|
|
|
* Render the background for an element using css rendering rules
|
|
|
|
* for backgrounds.
|
1998-07-22 09:02:07 +04:00
|
|
|
*
|
1999-01-15 21:25:58 +03:00
|
|
|
* Both aDirtyRect and aBorderArea are in the local coordinate space
|
1998-07-22 09:02:07 +04:00
|
|
|
* of aForFrame
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
2004-08-01 03:15:21 +04:00
|
|
|
static void PaintBackground(nsPresContext* aPresContext,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
1999-01-15 21:25:58 +03:00
|
|
|
const nsRect& aBorderArea,
|
2001-02-07 12:57:26 +03:00
|
|
|
const nsStyleBorder& aBorder,
|
2002-10-08 14:24:53 +04:00
|
|
|
const nsStylePadding& aPadding,
|
2004-03-09 09:48:35 +03:00
|
|
|
PRBool aUsePrintSettings,
|
|
|
|
nsRect* aBGClipRect = nsnull);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-01-08 02:46:07 +03:00
|
|
|
/**
|
|
|
|
* Same as |PaintBackground|, except using the provided style context
|
|
|
|
* (which short-circuits the code that ensures that the root element's
|
|
|
|
* background is drawn on the canvas.
|
|
|
|
*/
|
2004-08-01 03:15:21 +04:00
|
|
|
static void PaintBackgroundWithSC(nsPresContext* aPresContext,
|
2002-01-08 02:46:07 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
const nsStyleBackground& aColor,
|
|
|
|
const nsStyleBorder& aBorder,
|
2002-10-08 14:24:53 +04:00
|
|
|
const nsStylePadding& aPadding,
|
2004-03-09 09:48:35 +03:00
|
|
|
PRBool aUsePrintSettings = PR_FALSE,
|
|
|
|
nsRect* aBGClipRect = nsnull);
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
/**
|
|
|
|
* Called by the presShell when painting is finished, so we can clear our
|
|
|
|
* inline background data cache.
|
|
|
|
*/
|
|
|
|
static void DidPaint();
|
|
|
|
|
2002-01-08 02:46:07 +03:00
|
|
|
|
1998-10-17 04:35:32 +04:00
|
|
|
static void DrawDashedSides(PRIntn startSide,
|
|
|
|
nsIRenderingContext& aContext,
|
1999-10-26 18:34:17 +04:00
|
|
|
const nsRect& aDirtyRect,
|
1998-10-17 04:35:32 +04:00
|
|
|
const PRUint8 borderStyles[],
|
1998-12-07 22:04:39 +03:00
|
|
|
const nscolor borderColors[],
|
|
|
|
const nsRect& borderOutside,
|
|
|
|
const nsRect& borderInside,
|
|
|
|
PRIntn aSkipSides,
|
|
|
|
nsRect* aGap);
|
|
|
|
|
|
|
|
static void DrawDashedSides(PRIntn startSide,
|
|
|
|
nsIRenderingContext& aContext,
|
1999-10-26 18:34:17 +04:00
|
|
|
const nsRect& aDirtyRect,
|
2001-06-01 02:19:43 +04:00
|
|
|
const nsStyleColor* aColorStyle,
|
2001-02-07 12:57:26 +03:00
|
|
|
const nsStyleBorder* aBorderStyle,
|
|
|
|
const nsStyleOutline* aOutlineStyle,
|
1999-08-19 18:22:47 +04:00
|
|
|
PRBool aDoOutline,
|
1998-10-17 04:35:32 +04:00
|
|
|
const nsRect& borderOutside,
|
|
|
|
const nsRect& borderInside,
|
|
|
|
PRIntn aSkipSides,
|
|
|
|
nsRect* aGap);
|
|
|
|
|
2002-02-19 18:48:28 +03:00
|
|
|
// Draw a border segment in the table collapsing border model without beveling corners
|
|
|
|
static void DrawTableBorderSegment(nsIRenderingContext& aContext,
|
|
|
|
PRUint8 aBorderStyle,
|
|
|
|
nscolor aBorderColor,
|
|
|
|
const nsStyleBackground* aBGColor,
|
|
|
|
const nsRect& aBorderRect,
|
2007-02-23 20:52:09 +03:00
|
|
|
PRInt32 aAppUnitsPerCSSPixel,
|
2002-02-19 18:48:28 +03:00
|
|
|
PRUint8 aStartBevelSide = 0,
|
|
|
|
nscoord aStartBevelOffset = 0,
|
|
|
|
PRUint8 aEndBevelSide = 0,
|
|
|
|
nscoord aEndBevelOffset = 0);
|
2001-05-10 18:19:58 +04:00
|
|
|
/**
|
|
|
|
* transform a color to a color that will show up on a printer if needed
|
|
|
|
* aMapColor - color to evaluate
|
|
|
|
* aIsPrinter - Is this a printing device
|
|
|
|
* return - the transformed color
|
|
|
|
*/
|
|
|
|
static nscolor TransformColor(nscolor aMapColor,PRBool aNoBackGround);
|
|
|
|
|
2007-08-06 12:15:00 +04:00
|
|
|
/**
|
|
|
|
* Function for painting the decoration lines for the text.
|
2007-08-22 15:13:46 +04:00
|
|
|
* NOTE: aPt, aLineSize, aAscent, aOffset and aPreferredHeight are non-rounded
|
2007-08-06 12:15:00 +04:00
|
|
|
* device pixels, not app units.
|
|
|
|
* input:
|
|
|
|
* @param aGfxContext
|
|
|
|
* @param aColor the color of the decoration line
|
|
|
|
* @param aPt the top/left edge of the text
|
|
|
|
* @param aLineSize the width and the height of the decoration
|
|
|
|
* line
|
|
|
|
* @param aAscent the ascent of the text
|
|
|
|
* @param aOffset the offset of the decoration line from
|
|
|
|
* the baseline of the text (if the value is
|
|
|
|
* positive, the line is lifted up)
|
|
|
|
* @param aPreferredHeight the preferred size of the decoration line by
|
|
|
|
* the font of the text
|
|
|
|
* @param aDecoration which line will be painted. The value can be
|
|
|
|
* NS_STYLE_TEXT_DECORATION_UNDERLINE or
|
|
|
|
* NS_STYLE_TEXT_DECORATION_OVERLINE or
|
|
|
|
* NS_STYLE_TEXT_DECORATION_LINE_THROUGH.
|
|
|
|
* @param aStyle the style of the decoration line. The value
|
|
|
|
* can be NS_STYLE_BORDER_STYLE_SOLID or
|
|
|
|
* NS_STYLE_BORDER_STYLE_DOTTED or
|
|
|
|
* NS_STYLE_BORDER_STYLE_DASHED or
|
|
|
|
* NS_STYLE_BORDER_STYLE_DOUBLE or
|
|
|
|
* NS_STYLE_BORDER_STYLE_NONE.
|
|
|
|
* @param aIsRTL when the text is RTL, it is true.
|
|
|
|
*/
|
|
|
|
static void PaintDecorationLine(gfxContext* aGfxContext,
|
|
|
|
const nscolor aColor,
|
|
|
|
const gfxPoint& aPt,
|
|
|
|
const gfxSize& aLineSize,
|
|
|
|
const gfxFloat aAscent,
|
|
|
|
const gfxFloat aOffset,
|
|
|
|
const gfxFloat aPreferredSize,
|
|
|
|
const PRUint8 aDecoration,
|
|
|
|
const PRUint8 aStyle,
|
|
|
|
const PRBool aIsRTL);
|
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
protected:
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
static void PaintBackgroundColor(nsPresContext* aPresContext,
|
2002-10-08 14:24:53 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aBgClipArea,
|
|
|
|
const nsStyleBackground& aColor,
|
|
|
|
const nsStyleBorder& aBorder,
|
|
|
|
const nsStylePadding& aPadding,
|
2003-02-23 05:49:22 +03:00
|
|
|
PRBool aCanPaintNonWhite);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
static void PaintRoundedBackground(nsPresContext* aPresContext,
|
2002-10-08 14:24:53 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
const nsStyleBackground& aColor,
|
|
|
|
const nsStyleBorder& aBorder,
|
2007-07-18 18:14:53 +04:00
|
|
|
nscoord aTheRadius[4],
|
2003-02-23 05:49:22 +03:00
|
|
|
PRBool aCanPaintNonWhite);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
static nscolor MakeBevelColor(PRIntn whichSide, PRUint8 style,
|
1999-01-23 01:22:26 +03:00
|
|
|
nscolor aBackgroundColor,
|
2007-02-01 05:45:55 +03:00
|
|
|
nscolor aBorderColor);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-10-08 08:38:41 +04:00
|
|
|
static void DrawLine (nsIRenderingContext& aContext,
|
|
|
|
nscoord aX1, nscoord aY1, nscoord aX2, nscoord aY2,
|
|
|
|
nsRect* aGap);
|
|
|
|
|
|
|
|
static void FillPolygon (nsIRenderingContext& aContext,
|
|
|
|
const nsPoint aPoints[],
|
|
|
|
PRInt32 aNumPoints,
|
|
|
|
nsRect* aGap);
|
2001-05-10 18:19:58 +04:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#endif /* nsCSSRendering_h___ */
|