2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2002-01-08 02:46:07 +03:00
|
|
|
// vim:cindent:ts=2:et:sw=2:
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
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.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* 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
|
|
|
|
* either 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"),
|
|
|
|
* 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
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIImage.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsPoint.h"
|
|
|
|
#include "nsRect.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIPresShell.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1999-04-25 06:43:50 +04:00
|
|
|
#include "nsIScrollableView.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
1999-10-01 18:35:20 +04:00
|
|
|
#include "nsIDrawingSurface.h"
|
1999-08-27 18:37:47 +04:00
|
|
|
#include "nsTransform2D.h"
|
1999-10-07 18:57:32 +04:00
|
|
|
#include "nsIDeviceContext.h"
|
2000-03-30 10:27:32 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIDocument.h"
|
2000-06-08 03:06:41 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
2001-08-10 00:22:39 +04:00
|
|
|
#include "imgIRequest.h"
|
|
|
|
#include "imgIContainer.h"
|
2003-03-06 02:34:48 +03:00
|
|
|
#include "gfxIImageFrame.h"
|
2001-10-24 04:01:09 +04:00
|
|
|
#include "nsCSSRendering.h"
|
2002-09-12 08:43:31 +04:00
|
|
|
#include "nsCSSColorUtils.h"
|
2001-11-27 17:50:35 +03:00
|
|
|
#include "nsIPrintContext.h"
|
2001-12-18 01:51:39 +03:00
|
|
|
#include "nsITheme.h"
|
|
|
|
#include "nsThemeConstants.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2002-01-08 02:46:07 +03:00
|
|
|
#include "nsIDOMHTMLBodyElement.h"
|
|
|
|
#include "nsIDOMHTMLDocument.h"
|
2003-02-23 05:49:22 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
#define BORDER_FULL 0 //entire side
|
|
|
|
#define BORDER_INSIDE 1 //inside half
|
|
|
|
#define BORDER_OUTSIDE 2 //outside half
|
|
|
|
|
|
|
|
//thickness of dashed line relative to dotted line
|
|
|
|
#define DOT_LENGTH 1 //square
|
|
|
|
#define DASH_LENGTH 3 //3 times longer than dot
|
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
/** The following classes are used by CSSRendering for the rounded rect implementation */
|
|
|
|
#define MAXPATHSIZE 12
|
|
|
|
#define MAXPOLYPATHSIZE 1000
|
|
|
|
|
|
|
|
enum ePathTypes{
|
|
|
|
eOutside =0,
|
|
|
|
eInside,
|
|
|
|
eCalc,
|
|
|
|
eCalcRev
|
|
|
|
};
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
// To avoid storing this data on nsInlineFrame (bloat) and to avoid
|
|
|
|
// recalculating this for each frame in a continuation (perf), hold
|
|
|
|
// a cache of various coordinate information that we need in order
|
|
|
|
// to paint inline backgrounds.
|
|
|
|
struct InlineBackgroundData
|
|
|
|
{
|
|
|
|
InlineBackgroundData()
|
|
|
|
: mFrame(nsnull)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~InlineBackgroundData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
mBoundingBox.SetRect(0,0,0,0);
|
|
|
|
mContinuationPoint = mUnbrokenWidth = 0;
|
|
|
|
mFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect GetContinuousRect(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
SetFrame(aFrame);
|
|
|
|
|
|
|
|
// Assume background-origin: border and return a rect with offsets
|
|
|
|
// relative to (0,0). If we have a different background-origin,
|
|
|
|
// then our rect should be deflated appropriately by our caller.
|
2003-07-05 19:04:34 +04:00
|
|
|
return nsRect(-mContinuationPoint, 0, mUnbrokenWidth, mFrame->GetSize().height);
|
2003-01-17 12:33:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect GetBoundingRect(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
SetFrame(aFrame);
|
|
|
|
|
|
|
|
// Move the offsets relative to (0,0) which puts the bounding box into
|
|
|
|
// our coordinate system rather than our parent's. We do this by
|
|
|
|
// moving it the back distance from us to the bounding box.
|
|
|
|
// This also assumes background-origin: border, so our caller will
|
|
|
|
// need to deflate us if needed.
|
|
|
|
nsRect boundingBox(mBoundingBox);
|
2003-07-05 19:04:34 +04:00
|
|
|
nsPoint point = mFrame->GetPosition();
|
2003-01-17 12:33:52 +03:00
|
|
|
boundingBox.MoveBy(-point.x, -point.y);
|
|
|
|
|
|
|
|
return boundingBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsIFrame* mFrame;
|
|
|
|
nscoord mContinuationPoint;
|
|
|
|
nscoord mUnbrokenWidth;
|
|
|
|
nsRect mBoundingBox;
|
|
|
|
|
|
|
|
void SetFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Need a frame");
|
|
|
|
|
|
|
|
nsIFrame *prevInFlow = nsnull;
|
|
|
|
aFrame->GetPrevInFlow(&prevInFlow);
|
|
|
|
|
|
|
|
if (!prevInFlow || mFrame != prevInFlow) {
|
|
|
|
// Ok, we've got the wrong frame. We have to start from scratch.
|
|
|
|
Reset();
|
|
|
|
Init(aFrame);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get our last frame's size and add its width to our continuation
|
|
|
|
// point before we cache the new frame.
|
2003-07-05 19:04:34 +04:00
|
|
|
mContinuationPoint += mFrame->GetSize().width;
|
2003-01-17 12:33:52 +03:00
|
|
|
|
|
|
|
mFrame = aFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* inlineFrame;
|
|
|
|
// Start with the previous flow frame as our continuation point
|
|
|
|
// is the total of the widths of the previous frames.
|
|
|
|
aFrame->GetPrevInFlow(&inlineFrame);
|
|
|
|
|
|
|
|
while (inlineFrame) {
|
2003-07-05 19:04:34 +04:00
|
|
|
nsRect rect = inlineFrame->GetRect();
|
2003-01-17 12:33:52 +03:00
|
|
|
mContinuationPoint += rect.width;
|
|
|
|
mUnbrokenWidth += rect.width;
|
|
|
|
mBoundingBox.UnionRect(mBoundingBox, rect);
|
|
|
|
inlineFrame->GetPrevInFlow(&inlineFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next add this frame and subsequent frames to the bounding box and
|
|
|
|
// unbroken width.
|
|
|
|
inlineFrame = aFrame;
|
|
|
|
while (inlineFrame) {
|
2003-07-05 19:04:34 +04:00
|
|
|
nsRect rect = inlineFrame->GetRect();
|
2003-01-17 12:33:52 +03:00
|
|
|
mUnbrokenWidth += rect.width;
|
|
|
|
mBoundingBox.UnionRect(mBoundingBox, rect);
|
|
|
|
inlineFrame->GetNextInFlow(&inlineFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrame = aFrame;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static InlineBackgroundData gInlineBGData;
|
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
static void GetPath(nsFloatPoint aPoints[],nsPoint aPolyPath[],PRInt32 *aCurIndex,ePathTypes aPathType,PRInt32 &aC1Index,float aFrac=0);
|
2000-05-09 04:53:51 +04:00
|
|
|
static nsresult GetFrameForBackgroundUpdate(nsIPresContext *aPresContext,nsIFrame *aFrame, nsIFrame **aBGFrame);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2001-10-03 04:08:25 +04:00
|
|
|
// FillRect or InvertRect depending on the renderingaInvert parameter
|
|
|
|
static void FillOrInvertRect(nsIRenderingContext& aRC,nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, PRBool aInvert);
|
|
|
|
static void FillOrInvertRect(nsIRenderingContext& aRC,const nsRect& aRect, PRBool aInvert);
|
|
|
|
|
1998-10-08 08:38:41 +04:00
|
|
|
// Draw a line, skipping that portion which crosses aGap. aGap defines a rectangle gap
|
|
|
|
// This services fieldset legends and only works for coords defining horizontal lines.
|
|
|
|
void nsCSSRendering::DrawLine (nsIRenderingContext& aContext,
|
|
|
|
nscoord aX1, nscoord aY1, nscoord aX2, nscoord aY2,
|
|
|
|
nsRect* aGap)
|
|
|
|
{
|
|
|
|
if (nsnull == aGap) {
|
|
|
|
aContext.DrawLine(aX1, aY1, aX2, aY2);
|
|
|
|
} else {
|
|
|
|
nscoord x1 = (aX1 < aX2) ? aX1 : aX2;
|
|
|
|
nscoord x2 = (aX1 < aX2) ? aX2 : aX1;
|
|
|
|
nsPoint gapUpperRight(aGap->x + aGap->width, aGap->y);
|
|
|
|
nsPoint gapLowerRight(aGap->x + aGap->width, aGap->y + aGap->height);
|
|
|
|
if ((aGap->y <= aY1) && (gapLowerRight.y >= aY2)) {
|
|
|
|
if ((aGap->x > x1) && (aGap->x < x2)) {
|
|
|
|
aContext.DrawLine(x1, aY1, aGap->x, aY1);
|
|
|
|
}
|
|
|
|
if ((gapLowerRight.x > x1) && (gapLowerRight.x < x2)) {
|
|
|
|
aContext.DrawLine(gapUpperRight.x, aY2, x2, aY2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aContext.DrawLine(aX1, aY1, aX2, aY2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill a polygon, skipping that portion which crosses aGap. aGap defines a rectangle gap
|
|
|
|
// This services fieldset legends and only works for points defining a horizontal rectangle
|
|
|
|
void nsCSSRendering::FillPolygon (nsIRenderingContext& aContext,
|
|
|
|
const nsPoint aPoints[],
|
|
|
|
PRInt32 aNumPoints,
|
|
|
|
nsRect* aGap)
|
|
|
|
{
|
2001-10-03 04:08:25 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsPenMode penMode;
|
2003-02-23 01:27:45 +03:00
|
|
|
if (NS_SUCCEEDED(aContext.GetPenMode(penMode)) &&
|
|
|
|
penMode == nsPenMode_kInvert) {
|
2001-10-03 04:08:25 +04:00
|
|
|
NS_WARNING( "Invert mode ignored in FillPolygon" );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-10-08 08:38:41 +04:00
|
|
|
if (nsnull == aGap) {
|
|
|
|
aContext.FillPolygon(aPoints, aNumPoints);
|
|
|
|
} else if (4 == aNumPoints) {
|
|
|
|
nsPoint gapUpperRight(aGap->x + aGap->width, aGap->y);
|
|
|
|
nsPoint gapLowerRight(aGap->x + aGap->width, aGap->y + aGap->height);
|
|
|
|
|
|
|
|
// sort the 4 points by x
|
|
|
|
nsPoint points[4];
|
1998-10-08 18:58:32 +04:00
|
|
|
for (PRInt32 pX = 0; pX < 4; pX++) {
|
|
|
|
points[pX] = aPoints[pX];
|
1998-10-08 08:38:41 +04:00
|
|
|
}
|
1998-10-08 18:58:32 +04:00
|
|
|
for (PRInt32 i = 0; i < 3; i++) {
|
|
|
|
for (PRInt32 j = i+1; j < 4; j++) {
|
1998-10-08 08:38:41 +04:00
|
|
|
if (points[j].x < points[i].x) {
|
|
|
|
nsPoint swap = points[i];
|
|
|
|
points[i] = points[j];
|
|
|
|
points[j] = swap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint upperLeft = (points[0].y <= points[1].y) ? points[0] : points[1];
|
|
|
|
nsPoint lowerLeft = (points[0].y <= points[1].y) ? points[1] : points[0];
|
|
|
|
nsPoint upperRight = (points[2].y <= points[3].y) ? points[2] : points[3];
|
|
|
|
nsPoint lowerRight = (points[2].y <= points[3].y) ? points[3] : points[2];
|
|
|
|
|
|
|
|
|
|
|
|
if ((aGap->y <= upperLeft.y) && (gapLowerRight.y >= lowerRight.y)) {
|
|
|
|
if ((aGap->x > upperLeft.x) && (aGap->x < upperRight.x)) {
|
|
|
|
nsPoint leftRect[4];
|
|
|
|
leftRect[0] = upperLeft;
|
|
|
|
leftRect[1] = nsPoint(aGap->x, upperLeft.y);
|
|
|
|
leftRect[2] = nsPoint(aGap->x, lowerLeft.y);
|
|
|
|
leftRect[3] = lowerLeft;
|
|
|
|
aContext.FillPolygon(leftRect, 4);
|
|
|
|
}
|
|
|
|
if ((gapUpperRight.x > upperLeft.x) && (gapUpperRight.x < upperRight.x)) {
|
|
|
|
nsPoint rightRect[4];
|
|
|
|
rightRect[0] = nsPoint(gapUpperRight.x, upperRight.y);
|
|
|
|
rightRect[1] = upperRight;
|
|
|
|
rightRect[2] = lowerRight;
|
|
|
|
rightRect[3] = nsPoint(gapLowerRight.x, lowerRight.y);
|
|
|
|
aContext.FillPolygon(rightRect, 4);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aContext.FillPolygon(aPoints, aNumPoints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-05-27 00:52:59 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/**
|
|
|
|
* Make a bevel color
|
|
|
|
*/
|
|
|
|
nscolor nsCSSRendering::MakeBevelColor(PRIntn whichSide, PRUint8 style,
|
1999-01-23 01:24:05 +03:00
|
|
|
nscolor aBackgroundColor,
|
1999-03-05 22:23:52 +03:00
|
|
|
nscolor aBorderColor,
|
|
|
|
PRBool aSpecialCase)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-27 00:52:59 +04:00
|
|
|
|
|
|
|
nscolor colors[2];
|
|
|
|
nscolor theColor;
|
|
|
|
|
1999-03-05 22:23:52 +03:00
|
|
|
// Given a background color and a border color
|
|
|
|
// calculate the color used for the shading
|
|
|
|
if(aSpecialCase)
|
|
|
|
NS_GetSpecial3DColors(colors, aBackgroundColor, aBorderColor);
|
1998-05-27 00:52:59 +04:00
|
|
|
else
|
1999-03-05 22:23:52 +03:00
|
|
|
NS_Get3DColors(colors, aBackgroundColor);
|
1998-05-27 00:52:59 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-01-23 01:24:05 +03:00
|
|
|
if ((style == NS_STYLE_BORDER_STYLE_BG_OUTSET) ||
|
|
|
|
(style == NS_STYLE_BORDER_STYLE_OUTSET) ||
|
1998-04-14 00:24:54 +04:00
|
|
|
(style == NS_STYLE_BORDER_STYLE_RIDGE)) {
|
|
|
|
// Flip colors for these two border style
|
|
|
|
switch (whichSide) {
|
|
|
|
case NS_SIDE_BOTTOM: whichSide = NS_SIDE_TOP; break;
|
|
|
|
case NS_SIDE_RIGHT: whichSide = NS_SIDE_LEFT; break;
|
|
|
|
case NS_SIDE_TOP: whichSide = NS_SIDE_BOTTOM; break;
|
|
|
|
case NS_SIDE_LEFT: whichSide = NS_SIDE_RIGHT; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (whichSide) {
|
|
|
|
case NS_SIDE_BOTTOM:
|
1998-05-27 00:52:59 +04:00
|
|
|
theColor = colors[1];
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
case NS_SIDE_RIGHT:
|
1998-05-27 00:52:59 +04:00
|
|
|
theColor = colors[1];
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
case NS_SIDE_TOP:
|
1998-05-27 00:52:59 +04:00
|
|
|
theColor = colors[0];
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
case NS_SIDE_LEFT:
|
1999-04-14 01:52:19 +04:00
|
|
|
default:
|
1998-05-27 00:52:59 +04:00
|
|
|
theColor = colors[0];
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return theColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Maximum poly points in any of the polygons we generate below
|
|
|
|
#define MAX_POLY_POINTS 4
|
|
|
|
|
|
|
|
// a nifty helper function to create a polygon representing a
|
|
|
|
// particular side of a border. This helps localize code for figuring
|
|
|
|
// mitered edges. It is mainly used by the solid, inset, and outset
|
1998-06-18 02:14:20 +04:00
|
|
|
// styles.
|
|
|
|
//
|
|
|
|
// If the side can be represented as a line segment (because the thickness
|
|
|
|
// is one pixel), then a line with two endpoints is returned
|
1998-04-14 00:24:54 +04:00
|
|
|
PRIntn nsCSSRendering::MakeSide(nsPoint aPoints[],
|
|
|
|
nsIRenderingContext& aContext,
|
|
|
|
PRIntn whichSide,
|
1998-06-18 09:43:32 +04:00
|
|
|
const nsRect& outside, const nsRect& inside,
|
1999-07-28 03:26:36 +04:00
|
|
|
PRIntn aSkipSides,
|
1998-06-18 02:14:20 +04:00
|
|
|
PRIntn borderPart, float borderFrac,
|
|
|
|
nscoord twipsPerPixel)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
float borderRest = 1.0f - borderFrac;
|
|
|
|
|
|
|
|
PRIntn np = 0;
|
1999-07-28 03:26:36 +04:00
|
|
|
nscoord thickness, outsideEdge, insideEdge, outsideTL, insideTL, outsideBR,
|
|
|
|
insideBR;
|
|
|
|
|
|
|
|
// Initialize the following six nscoord's:
|
|
|
|
// outsideEdge, insideEdge, outsideTL, insideTL, outsideBR, insideBR
|
|
|
|
// so that outsideEdge is the x or y of the outside edge, etc., and
|
|
|
|
// outsideTR is the y or x at the top or right end, etc., e.g.:
|
|
|
|
//
|
|
|
|
// outsideEdge --- ----------------------------------------
|
|
|
|
// \ /
|
|
|
|
// \ /
|
|
|
|
// \ /
|
|
|
|
// insideEdge ------- ----------------------------------
|
|
|
|
// | | | |
|
|
|
|
// outsideTL insideTL insideBR outsideBR
|
|
|
|
//
|
|
|
|
// if we don't want the bevel, we'll get rid of it later by setting
|
|
|
|
// outsideXX to insideXX
|
1998-06-18 02:14:20 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
switch (whichSide) {
|
|
|
|
case NS_SIDE_TOP:
|
1999-07-28 03:26:36 +04:00
|
|
|
// the TL points are the left end; the BR points are the right end
|
|
|
|
outsideEdge = outside.y;
|
|
|
|
insideEdge = inside.y;
|
|
|
|
outsideTL = outside.x;
|
|
|
|
insideTL = inside.x;
|
|
|
|
insideBR = inside.XMost();
|
|
|
|
outsideBR = outside.XMost();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
// the TL points are the left end; the BR points are the right end
|
|
|
|
outsideEdge = outside.YMost();
|
|
|
|
insideEdge = inside.YMost();
|
|
|
|
outsideTL = outside.x;
|
|
|
|
insideTL = inside.x;
|
|
|
|
insideBR = inside.XMost();
|
|
|
|
outsideBR = outside.XMost();
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_LEFT:
|
1999-07-28 03:26:36 +04:00
|
|
|
// the TL points are the top end; the BR points are the bottom end
|
|
|
|
outsideEdge = outside.x;
|
|
|
|
insideEdge = inside.x;
|
|
|
|
outsideTL = outside.y;
|
|
|
|
insideTL = inside.y;
|
|
|
|
insideBR = inside.YMost();
|
|
|
|
outsideBR = outside.YMost();
|
|
|
|
break;
|
1998-06-18 02:14:20 +04:00
|
|
|
|
1999-07-28 03:26:36 +04:00
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
// the TL points are the top end; the BR points are the bottom end
|
|
|
|
outsideEdge = outside.XMost();
|
|
|
|
insideEdge = inside.XMost();
|
|
|
|
outsideTL = outside.y;
|
|
|
|
insideTL = inside.y;
|
|
|
|
insideBR = inside.YMost();
|
|
|
|
outsideBR = outside.YMost();
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
1999-07-28 03:26:36 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-28 03:26:36 +04:00
|
|
|
// Don't draw the bevels if an adjacent side is skipped
|
1998-07-21 13:30:03 +04:00
|
|
|
|
1999-07-28 03:26:36 +04:00
|
|
|
if ( (whichSide == NS_SIDE_TOP) || (whichSide == NS_SIDE_BOTTOM) ) {
|
|
|
|
// a top or bottom side
|
|
|
|
if ((1<<NS_SIDE_LEFT) & aSkipSides) {
|
|
|
|
insideTL = outsideTL;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-07-28 03:26:36 +04:00
|
|
|
if ((1<<NS_SIDE_RIGHT) & aSkipSides) {
|
|
|
|
insideBR = outsideBR;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// a right or left side
|
|
|
|
if ((1<<NS_SIDE_TOP) & aSkipSides) {
|
|
|
|
insideTL = outsideTL;
|
|
|
|
}
|
|
|
|
if ((1<<NS_SIDE_BOTTOM) & aSkipSides) {
|
|
|
|
insideBR = outsideBR;
|
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-28 03:26:36 +04:00
|
|
|
// move things around when only drawing part of the border
|
1998-06-18 02:14:20 +04:00
|
|
|
|
1999-07-28 03:26:36 +04:00
|
|
|
if (borderPart == BORDER_INSIDE) {
|
|
|
|
outsideEdge = nscoord(outsideEdge * borderFrac + insideEdge * borderRest);
|
|
|
|
outsideTL = nscoord(outsideTL * borderFrac + insideTL * borderRest);
|
|
|
|
outsideBR = nscoord(outsideBR * borderFrac + insideBR * borderRest);
|
|
|
|
} else if (borderPart == BORDER_OUTSIDE ) {
|
|
|
|
insideEdge = nscoord(insideEdge * borderFrac + outsideEdge * borderRest);
|
|
|
|
insideTL = nscoord(insideTL * borderFrac + outsideTL * borderRest);
|
|
|
|
insideBR = nscoord(insideBR * borderFrac + outsideBR * borderRest);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Base our thickness check on the segment being less than a pixel and 1/2
|
|
|
|
twipsPerPixel += twipsPerPixel >> 2;
|
|
|
|
|
|
|
|
// find the thickness of the piece being drawn
|
|
|
|
if ((whichSide == NS_SIDE_TOP) || (whichSide == NS_SIDE_LEFT)) {
|
|
|
|
thickness = insideEdge - outsideEdge;
|
|
|
|
} else {
|
|
|
|
thickness = outsideEdge - insideEdge;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if returning a line, do it along inside edge for bottom or right borders
|
|
|
|
// so that it's in the same place as it would be with polygons (why?)
|
|
|
|
// XXX The previous version of the code shortened the right border too.
|
|
|
|
if ( !((thickness >= twipsPerPixel) || (borderPart != BORDER_FULL)) &&
|
|
|
|
((whichSide == NS_SIDE_BOTTOM) || (whichSide == NS_SIDE_RIGHT))) {
|
|
|
|
outsideEdge = insideEdge;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-07-28 03:26:36 +04:00
|
|
|
|
|
|
|
// return the appropriate line or trapezoid
|
|
|
|
if ((whichSide == NS_SIDE_TOP) || (whichSide == NS_SIDE_BOTTOM)) {
|
|
|
|
// top and bottom borders
|
|
|
|
aPoints[np++].MoveTo(outsideTL,outsideEdge);
|
|
|
|
aPoints[np++].MoveTo(outsideBR,outsideEdge);
|
|
|
|
// XXX Making this condition only (thickness >= twipsPerPixel) will
|
|
|
|
// improve double borders and some cases of groove/ridge,
|
|
|
|
// but will cause problems with table borders. See last and third
|
|
|
|
// from last tests in test4.htm
|
|
|
|
// Doing it this way emulates the old behavior. It might be worth
|
|
|
|
// fixing.
|
|
|
|
if ((thickness >= twipsPerPixel) || (borderPart != BORDER_FULL) ) {
|
|
|
|
aPoints[np++].MoveTo(insideBR,insideEdge);
|
|
|
|
aPoints[np++].MoveTo(insideTL,insideEdge);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// right and left borders
|
|
|
|
// XXX Ditto above
|
|
|
|
if ((thickness >= twipsPerPixel) || (borderPart != BORDER_FULL) ) {
|
|
|
|
aPoints[np++].MoveTo(insideEdge,insideBR);
|
|
|
|
aPoints[np++].MoveTo(insideEdge,insideTL);
|
|
|
|
}
|
|
|
|
aPoints[np++].MoveTo(outsideEdge,outsideTL);
|
|
|
|
aPoints[np++].MoveTo(outsideEdge,outsideBR);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return np;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSRendering::DrawSide(nsIRenderingContext& aContext,
|
|
|
|
PRIntn whichSide,
|
1998-12-07 22:02:13 +03:00
|
|
|
const PRUint8 borderStyle,
|
1999-01-23 01:24:05 +03:00
|
|
|
const nscolor borderColor,
|
1999-02-12 20:45:58 +03:00
|
|
|
const nscolor aBackgroundColor,
|
|
|
|
const nsRect& borderOutside,
|
1998-05-27 00:52:59 +04:00
|
|
|
const nsRect& borderInside,
|
1999-07-28 03:26:36 +04:00
|
|
|
PRIntn aSkipSides,
|
1998-10-08 08:38:41 +04:00
|
|
|
nscoord twipsPerPixel,
|
|
|
|
nsRect* aGap)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
nsPoint theSide[MAX_POLY_POINTS];
|
1998-12-07 22:02:13 +03:00
|
|
|
nscolor theColor = borderColor;
|
|
|
|
PRUint8 theStyle = borderStyle;
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 np;
|
|
|
|
switch (theStyle) {
|
|
|
|
case NS_STYLE_BORDER_STYLE_NONE:
|
1999-08-25 01:47:55 +04:00
|
|
|
case NS_STYLE_BORDER_STYLE_HIDDEN:
|
1998-04-14 00:24:54 +04:00
|
|
|
case NS_STYLE_BORDER_STYLE_BLANK:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOTTED: //handled a special case elsewhere
|
|
|
|
case NS_STYLE_BORDER_STYLE_DASHED: //handled a special case elsewhere
|
|
|
|
break; // That was easy...
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_GROOVE:
|
|
|
|
case NS_STYLE_BORDER_STYLE_RIDGE:
|
1999-07-28 03:26:36 +04:00
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside, aSkipSides,
|
1998-06-18 02:14:20 +04:00
|
|
|
BORDER_INSIDE, 0.5f, twipsPerPixel);
|
1998-10-27 02:18:32 +03:00
|
|
|
aContext.SetColor ( MakeBevelColor (whichSide,
|
|
|
|
((theStyle == NS_STYLE_BORDER_STYLE_RIDGE) ?
|
|
|
|
NS_STYLE_BORDER_STYLE_GROOVE :
|
|
|
|
NS_STYLE_BORDER_STYLE_RIDGE),
|
1999-01-28 03:31:47 +03:00
|
|
|
aBackgroundColor, theColor,
|
1999-03-05 22:23:52 +03:00
|
|
|
PR_TRUE));
|
1998-06-18 02:14:20 +04:00
|
|
|
if (2 == np) {
|
1998-10-08 08:38:41 +04:00
|
|
|
//aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y);
|
|
|
|
DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap);
|
1998-06-18 02:14:20 +04:00
|
|
|
} else {
|
1998-10-08 08:38:41 +04:00
|
|
|
//aContext.FillPolygon (theSide, np);
|
|
|
|
FillPolygon (aContext, theSide, np, aGap);
|
1998-06-18 02:14:20 +04:00
|
|
|
}
|
1999-07-28 03:26:36 +04:00
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside,aSkipSides,
|
1998-06-18 02:14:20 +04:00
|
|
|
BORDER_OUTSIDE, 0.5f, twipsPerPixel);
|
1999-01-23 01:24:05 +03:00
|
|
|
aContext.SetColor ( MakeBevelColor (whichSide, theStyle, aBackgroundColor,
|
1999-03-05 22:23:52 +03:00
|
|
|
theColor, PR_TRUE));
|
1998-06-18 02:14:20 +04:00
|
|
|
if (2 == np) {
|
1998-10-08 08:38:41 +04:00
|
|
|
//aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y);
|
|
|
|
DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap);
|
1998-06-18 02:14:20 +04:00
|
|
|
} else {
|
1998-10-08 08:38:41 +04:00
|
|
|
//aContext.FillPolygon (theSide, np);
|
|
|
|
FillPolygon (aContext, theSide, np, aGap);
|
1998-06-18 02:14:20 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
1999-07-28 03:26:36 +04:00
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside,aSkipSides,
|
1998-06-18 02:14:20 +04:00
|
|
|
BORDER_FULL, 1.0f, twipsPerPixel);
|
1998-12-07 22:02:13 +03:00
|
|
|
aContext.SetColor (borderColor);
|
1998-06-18 02:14:20 +04:00
|
|
|
if (2 == np) {
|
1998-10-08 08:38:41 +04:00
|
|
|
//aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y);
|
|
|
|
DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap);
|
1998-06-18 02:14:20 +04:00
|
|
|
} else {
|
1998-10-08 08:38:41 +04:00
|
|
|
//aContext.FillPolygon (theSide, np);
|
|
|
|
FillPolygon (aContext, theSide, np, aGap);
|
1998-06-18 02:14:20 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOUBLE:
|
1999-07-28 03:26:36 +04:00
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside,aSkipSides,
|
1998-06-18 02:14:20 +04:00
|
|
|
BORDER_INSIDE, 0.333333f, twipsPerPixel);
|
1998-12-07 22:02:13 +03:00
|
|
|
aContext.SetColor (borderColor);
|
1998-06-18 02:14:20 +04:00
|
|
|
if (2 == np) {
|
1998-10-08 08:38:41 +04:00
|
|
|
//aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y);
|
|
|
|
DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap);
|
1998-06-18 02:14:20 +04:00
|
|
|
} else {
|
1998-10-08 08:38:41 +04:00
|
|
|
//aContext.FillPolygon (theSide, np);
|
|
|
|
FillPolygon (aContext, theSide, np, aGap);
|
|
|
|
}
|
1999-07-28 03:26:36 +04:00
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside,aSkipSides,
|
1998-06-18 02:14:20 +04:00
|
|
|
BORDER_OUTSIDE, 0.333333f, twipsPerPixel);
|
|
|
|
if (2 == np) {
|
1998-10-08 08:38:41 +04:00
|
|
|
//aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y);
|
|
|
|
DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap);
|
1998-06-18 02:14:20 +04:00
|
|
|
} else {
|
1998-10-08 08:38:41 +04:00
|
|
|
//aContext.FillPolygon (theSide, np);
|
|
|
|
FillPolygon (aContext, theSide, np, aGap);
|
1998-06-18 02:14:20 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
|
1999-01-23 01:24:05 +03:00
|
|
|
case NS_STYLE_BORDER_STYLE_BG_OUTSET:
|
|
|
|
case NS_STYLE_BORDER_STYLE_BG_INSET:
|
1999-07-28 03:26:36 +04:00
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside,aSkipSides,
|
1999-01-23 01:24:05 +03:00
|
|
|
BORDER_FULL, 1.0f, twipsPerPixel);
|
|
|
|
aContext.SetColor ( MakeBevelColor (whichSide, theStyle, aBackgroundColor,
|
1999-03-05 22:23:52 +03:00
|
|
|
theColor, PR_FALSE));
|
1999-01-23 01:24:05 +03:00
|
|
|
if (2 == np) {
|
|
|
|
//aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y);
|
|
|
|
DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap);
|
|
|
|
} else {
|
|
|
|
//aContext.FillPolygon (theSide, np);
|
|
|
|
FillPolygon (aContext, theSide, np, aGap);
|
|
|
|
}
|
|
|
|
break;
|
1998-04-14 00:24:54 +04:00
|
|
|
case NS_STYLE_BORDER_STYLE_OUTSET:
|
|
|
|
case NS_STYLE_BORDER_STYLE_INSET:
|
1999-07-28 03:26:36 +04:00
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside,aSkipSides,
|
1998-06-18 02:14:20 +04:00
|
|
|
BORDER_FULL, 1.0f, twipsPerPixel);
|
1999-01-23 01:24:05 +03:00
|
|
|
aContext.SetColor ( MakeBevelColor (whichSide, theStyle, aBackgroundColor,
|
1999-03-05 22:23:52 +03:00
|
|
|
theColor, PR_TRUE));
|
1998-06-18 02:14:20 +04:00
|
|
|
if (2 == np) {
|
1998-10-08 08:38:41 +04:00
|
|
|
//aContext.DrawLine (theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y);
|
|
|
|
DrawLine (aContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap);
|
1998-06-18 02:14:20 +04:00
|
|
|
} else {
|
1998-10-08 08:38:41 +04:00
|
|
|
//aContext.FillPolygon (theSide, np);
|
|
|
|
FillPolygon (aContext, theSide, np, aGap);
|
1998-06-18 02:14:20 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-19 18:48:28 +03:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/**
|
|
|
|
* Draw a dotted/dashed sides of a box
|
|
|
|
*/
|
|
|
|
//XXX dashes which span more than two edges are not handled properly MMP
|
|
|
|
void nsCSSRendering::DrawDashedSides(PRIntn startSide,
|
|
|
|
nsIRenderingContext& aContext,
|
2002-01-08 18:13:02 +03:00
|
|
|
/* XXX unused */ const nsRect& aDirtyRect,
|
1998-12-07 22:02:13 +03:00
|
|
|
const PRUint8 borderStyles[],
|
|
|
|
const nscolor borderColors[],
|
1998-04-14 00:24:54 +04:00
|
|
|
const nsRect& borderOutside,
|
|
|
|
const nsRect& borderInside,
|
1998-10-08 08:38:41 +04:00
|
|
|
PRIntn aSkipSides,
|
2002-01-08 18:13:02 +03:00
|
|
|
/* XXX unused */ nsRect* aGap)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-10-26 18:34:17 +04:00
|
|
|
PRIntn dashLength;
|
|
|
|
nsRect dashRect, firstRect, currRect;
|
|
|
|
PRBool bSolid = PR_TRUE;
|
|
|
|
float over = 0.0f;
|
|
|
|
PRUint8 style = borderStyles[startSide];
|
|
|
|
PRBool skippedSide = PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
for (PRIntn whichSide = startSide; whichSide < 4; whichSide++) {
|
|
|
|
PRUint8 prevStyle = style;
|
1998-12-07 22:02:13 +03:00
|
|
|
style = borderStyles[whichSide];
|
1998-12-10 20:50:11 +03:00
|
|
|
if ((1<<whichSide) & aSkipSides) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// Skipped side
|
|
|
|
skippedSide = PR_TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((style == NS_STYLE_BORDER_STYLE_DASHED) ||
|
|
|
|
(style == NS_STYLE_BORDER_STYLE_DOTTED))
|
|
|
|
{
|
|
|
|
if ((style != prevStyle) || skippedSide) {
|
|
|
|
//style discontinuity
|
|
|
|
over = 0.0f;
|
|
|
|
bSolid = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX units for dash & dot?
|
|
|
|
if (style == NS_STYLE_BORDER_STYLE_DASHED) {
|
|
|
|
dashLength = DASH_LENGTH;
|
|
|
|
} else {
|
|
|
|
dashLength = DOT_LENGTH;
|
|
|
|
}
|
|
|
|
|
1998-12-07 22:02:13 +03:00
|
|
|
aContext.SetColor(borderColors[whichSide]);
|
1998-04-14 00:24:54 +04:00
|
|
|
switch (whichSide) {
|
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
//XXX need to properly handle wrap around from last edge to first edge
|
|
|
|
//(this is the first edge) MMP
|
|
|
|
dashRect.width = borderInside.x - borderOutside.x;
|
|
|
|
dashRect.height = nscoord(dashRect.width * dashLength);
|
|
|
|
dashRect.x = borderOutside.x;
|
|
|
|
dashRect.y = borderInside.YMost() - dashRect.height;
|
|
|
|
|
|
|
|
if (over > 0.0f) {
|
|
|
|
firstRect.x = dashRect.x;
|
|
|
|
firstRect.width = dashRect.width;
|
|
|
|
firstRect.height = nscoord(dashRect.height * over);
|
|
|
|
firstRect.y = dashRect.y + (dashRect.height - firstRect.height);
|
|
|
|
over = 0.0f;
|
|
|
|
currRect = firstRect;
|
|
|
|
} else {
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (currRect.YMost() > borderInside.y) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.y < borderInside.y) {
|
|
|
|
over = float(borderInside.y - dashRect.y) /
|
|
|
|
float(dashRect.height);
|
|
|
|
currRect.height = currRect.height - (borderInside.y - currRect.y);
|
|
|
|
currRect.y = borderInside.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.y = dashRect.y - currRect.height;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
//if we are continuing a solid rect, fill in the corner first
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(borderOutside.x, borderOutside.y,
|
|
|
|
borderInside.x - borderOutside.x,
|
|
|
|
borderInside.y - borderOutside.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
dashRect.height = borderInside.y - borderOutside.y;
|
|
|
|
dashRect.width = dashRect.height * dashLength;
|
|
|
|
dashRect.x = borderInside.x;
|
|
|
|
dashRect.y = borderOutside.y;
|
|
|
|
|
|
|
|
if (over > 0.0f) {
|
|
|
|
firstRect.x = dashRect.x;
|
|
|
|
firstRect.y = dashRect.y;
|
|
|
|
firstRect.width = nscoord(dashRect.width * over);
|
|
|
|
firstRect.height = dashRect.height;
|
|
|
|
over = 0.0f;
|
|
|
|
currRect = firstRect;
|
|
|
|
} else {
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (currRect.x < borderInside.XMost()) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.XMost() > borderInside.XMost()) {
|
|
|
|
over = float(dashRect.XMost() - borderInside.XMost()) /
|
|
|
|
float(dashRect.width);
|
|
|
|
currRect.width = currRect.width -
|
|
|
|
(currRect.XMost() - borderInside.XMost());
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.x = dashRect.x + currRect.width;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
//if we are continuing a solid rect, fill in the corner first
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(borderInside.XMost(), borderOutside.y,
|
|
|
|
borderOutside.XMost() - borderInside.XMost(),
|
|
|
|
borderInside.y - borderOutside.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
dashRect.width = borderOutside.XMost() - borderInside.XMost();
|
|
|
|
dashRect.height = nscoord(dashRect.width * dashLength);
|
|
|
|
dashRect.x = borderInside.XMost();
|
|
|
|
dashRect.y = borderInside.y;
|
|
|
|
|
|
|
|
if (over > 0.0f) {
|
|
|
|
firstRect.x = dashRect.x;
|
|
|
|
firstRect.y = dashRect.y;
|
|
|
|
firstRect.width = dashRect.width;
|
|
|
|
firstRect.height = nscoord(dashRect.height * over);
|
|
|
|
over = 0.0f;
|
|
|
|
currRect = firstRect;
|
|
|
|
} else {
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (currRect.y < borderInside.YMost()) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.YMost() > borderInside.YMost()) {
|
|
|
|
over = float(dashRect.YMost() - borderInside.YMost()) /
|
|
|
|
float(dashRect.height);
|
|
|
|
currRect.height = currRect.height -
|
|
|
|
(currRect.YMost() - borderInside.YMost());
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.y = dashRect.y + currRect.height;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
//if we are continuing a solid rect, fill in the corner first
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(borderInside.XMost(), borderInside.YMost(),
|
|
|
|
borderOutside.XMost() - borderInside.XMost(),
|
|
|
|
borderOutside.YMost() - borderInside.YMost());
|
|
|
|
}
|
|
|
|
|
|
|
|
dashRect.height = borderOutside.YMost() - borderInside.YMost();
|
|
|
|
dashRect.width = nscoord(dashRect.height * dashLength);
|
|
|
|
dashRect.x = borderInside.XMost() - dashRect.width;
|
|
|
|
dashRect.y = borderInside.YMost();
|
|
|
|
|
|
|
|
if (over > 0.0f) {
|
|
|
|
firstRect.y = dashRect.y;
|
|
|
|
firstRect.width = nscoord(dashRect.width * over);
|
|
|
|
firstRect.height = dashRect.height;
|
|
|
|
firstRect.x = dashRect.x + (dashRect.width - firstRect.width);
|
|
|
|
over = 0.0f;
|
|
|
|
currRect = firstRect;
|
|
|
|
} else {
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (currRect.XMost() > borderInside.x) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.x < borderInside.x) {
|
|
|
|
over = float(borderInside.x - dashRect.x) / float(dashRect.width);
|
|
|
|
currRect.width = currRect.width - (borderInside.x - currRect.x);
|
|
|
|
currRect.x = borderInside.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.x = dashRect.x - currRect.width;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
skippedSide = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-26 18:34:17 +04:00
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation in nsCSSRendering.h
|
|
|
|
* @update 10/22/99 dwc
|
|
|
|
*/
|
1998-12-07 22:02:13 +03:00
|
|
|
void nsCSSRendering::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-12-07 22:02:13 +03:00
|
|
|
const nsRect& borderOutside,
|
|
|
|
const nsRect& borderInside,
|
|
|
|
PRIntn aSkipSides,
|
2002-01-08 18:13:02 +03:00
|
|
|
/* XXX unused */ nsRect* aGap)
|
1998-12-07 22:02:13 +03:00
|
|
|
{
|
2001-02-07 12:57:26 +03:00
|
|
|
|
1999-10-26 18:34:17 +04:00
|
|
|
PRIntn dashLength;
|
1999-11-03 08:46:01 +03:00
|
|
|
nsRect dashRect, currRect;
|
2002-01-08 18:13:02 +03:00
|
|
|
nscoord temp, temp1, adjust;
|
1999-10-26 18:34:17 +04:00
|
|
|
PRBool bSolid = PR_TRUE;
|
|
|
|
float over = 0.0f;
|
|
|
|
PRBool skippedSide = PR_FALSE;
|
2001-10-03 04:08:25 +04:00
|
|
|
const nscolor kBlackColor = NS_RGB(0,0,0);
|
1999-10-26 18:34:17 +04:00
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
NS_ASSERTION((aDoOutline && aOutlineStyle) || (!aDoOutline && aBorderStyle), "null params not allowed");
|
|
|
|
PRUint8 style = aDoOutline
|
|
|
|
? aOutlineStyle->GetOutlineStyle()
|
|
|
|
: aBorderStyle->GetBorderStyle(startSide);
|
1999-10-26 18:34:17 +04:00
|
|
|
|
|
|
|
// find the x and y width
|
2002-01-08 18:13:02 +03:00
|
|
|
nscoord xwidth = aDirtyRect.XMost();
|
|
|
|
nscoord ywidth = aDirtyRect.YMost();
|
1998-12-07 22:02:13 +03:00
|
|
|
|
|
|
|
for (PRIntn whichSide = startSide; whichSide < 4; whichSide++) {
|
|
|
|
PRUint8 prevStyle = style;
|
2001-02-07 12:57:26 +03:00
|
|
|
style = aDoOutline
|
|
|
|
? aOutlineStyle->GetOutlineStyle()
|
|
|
|
: aBorderStyle->GetBorderStyle(whichSide);
|
1998-12-10 20:50:11 +03:00
|
|
|
if ((1<<whichSide) & aSkipSides) {
|
1998-12-07 22:02:13 +03:00
|
|
|
// Skipped side
|
|
|
|
skippedSide = PR_TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((style == NS_STYLE_BORDER_STYLE_DASHED) ||
|
|
|
|
(style == NS_STYLE_BORDER_STYLE_DOTTED))
|
|
|
|
{
|
|
|
|
if ((style != prevStyle) || skippedSide) {
|
|
|
|
//style discontinuity
|
|
|
|
over = 0.0f;
|
|
|
|
bSolid = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (style == NS_STYLE_BORDER_STYLE_DASHED) {
|
|
|
|
dashLength = DASH_LENGTH;
|
|
|
|
} else {
|
|
|
|
dashLength = DOT_LENGTH;
|
|
|
|
}
|
|
|
|
|
2001-10-03 04:08:25 +04:00
|
|
|
nscolor sideColor(kBlackColor); // default to black in case color cannot be resolved
|
|
|
|
// (because invert is not supported on cur platform)
|
|
|
|
PRBool isInvert=PR_FALSE;
|
1999-08-19 18:22:47 +04:00
|
|
|
if (aDoOutline) {
|
2001-10-03 04:08:25 +04:00
|
|
|
// see if the outline color is 'invert'
|
|
|
|
if (aOutlineStyle->GetOutlineInvert()) {
|
|
|
|
isInvert = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
aOutlineStyle->GetOutlineColor(sideColor);
|
|
|
|
}
|
1999-08-19 18:22:47 +04:00
|
|
|
} else {
|
2001-06-01 02:19:43 +04:00
|
|
|
PRBool transparent;
|
|
|
|
PRBool foreground;
|
|
|
|
aBorderStyle->GetBorderColor(whichSide, sideColor, transparent, foreground);
|
|
|
|
if (foreground)
|
|
|
|
sideColor = aColorStyle->mColor;
|
|
|
|
if (transparent)
|
1999-08-19 18:22:47 +04:00
|
|
|
continue; // side is transparent
|
1999-03-28 08:30:28 +04:00
|
|
|
}
|
|
|
|
aContext.SetColor(sideColor);
|
2001-10-03 04:08:25 +04:00
|
|
|
|
1998-12-07 22:02:13 +03:00
|
|
|
switch (whichSide) {
|
1999-10-26 18:34:17 +04:00
|
|
|
case NS_SIDE_RIGHT:
|
1998-12-07 22:02:13 +03:00
|
|
|
case NS_SIDE_LEFT:
|
1999-10-26 18:34:17 +04:00
|
|
|
bSolid = PR_FALSE;
|
|
|
|
|
|
|
|
// This is our dot or dash..
|
1999-11-15 18:33:25 +03:00
|
|
|
if(whichSide==NS_SIDE_LEFT){
|
|
|
|
dashRect.width = borderInside.x - borderOutside.x;
|
|
|
|
} else {
|
|
|
|
dashRect.width = borderOutside.XMost() - borderInside.XMost();
|
|
|
|
}
|
1999-11-03 08:46:01 +03:00
|
|
|
if( dashRect.width >0 ) {
|
|
|
|
dashRect.height = dashRect.width * dashLength;
|
|
|
|
dashRect.y = borderOutside.y;
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
if(whichSide == NS_SIDE_RIGHT){
|
|
|
|
dashRect.x = borderInside.XMost();
|
|
|
|
} else {
|
|
|
|
dashRect.x = borderOutside.x;
|
|
|
|
}
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
temp = borderOutside.YMost();
|
|
|
|
temp1 = temp/dashRect.height;
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
currRect = dashRect;
|
1999-10-26 18:34:17 +04:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
if((temp1%2)==0){
|
|
|
|
adjust = (dashRect.height-(temp%dashRect.height))/2; // adjust back
|
|
|
|
// draw in the left and right
|
2001-10-03 04:08:25 +04:00
|
|
|
FillOrInvertRect(aContext, dashRect.x, borderOutside.y,dashRect.width, dashRect.height-adjust,isInvert);
|
|
|
|
FillOrInvertRect(aContext,dashRect.x,(borderOutside.YMost()-(dashRect.height-adjust)),dashRect.width, dashRect.height-adjust,isInvert);
|
1999-11-03 08:46:01 +03:00
|
|
|
currRect.y += (dashRect.height-adjust);
|
|
|
|
temp = temp-= (dashRect.height-adjust);
|
|
|
|
} else {
|
|
|
|
adjust = (temp%dashRect.width)/2; // adjust a tad longer
|
|
|
|
// draw in the left and right
|
2001-10-03 04:08:25 +04:00
|
|
|
FillOrInvertRect(aContext, dashRect.x, borderOutside.y,dashRect.width, dashRect.height+adjust,isInvert);
|
|
|
|
FillOrInvertRect(aContext, dashRect.x,(borderOutside.YMost()-(dashRect.height+adjust)),dashRect.width, dashRect.height+adjust,isInvert);
|
1999-11-03 08:46:01 +03:00
|
|
|
currRect.y += (dashRect.height+adjust);
|
|
|
|
temp = temp-= (dashRect.height+adjust);
|
|
|
|
}
|
1999-10-26 18:34:17 +04:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
if( temp > ywidth)
|
|
|
|
temp = ywidth;
|
|
|
|
|
|
|
|
// get the currRect's x into the view before we start
|
|
|
|
if( currRect.y < aDirtyRect.y){
|
|
|
|
temp1 = NSToCoordFloor((float)((aDirtyRect.y-currRect.y)/dashRect.height));
|
|
|
|
currRect.y += temp1*dashRect.height;
|
|
|
|
if((temp1%2)==1){
|
|
|
|
bSolid = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while(currRect.y<temp) {
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
2001-10-03 04:08:25 +04:00
|
|
|
FillOrInvertRect(aContext, currRect,isInvert);
|
1999-11-03 08:46:01 +03:00
|
|
|
}
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
currRect.y += dashRect.height;
|
1998-12-07 22:02:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-10-26 18:34:17 +04:00
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
bSolid = PR_FALSE;
|
|
|
|
|
|
|
|
// This is our dot or dash..
|
1999-11-15 18:33:25 +03:00
|
|
|
|
|
|
|
if(whichSide==NS_SIDE_TOP){
|
|
|
|
dashRect.height = borderInside.y - borderOutside.y;
|
|
|
|
} else {
|
|
|
|
dashRect.height = borderOutside.YMost() - borderInside.YMost();
|
|
|
|
}
|
1999-11-03 08:46:01 +03:00
|
|
|
if( dashRect.height >0 ) {
|
|
|
|
dashRect.width = dashRect.height * dashLength;
|
|
|
|
dashRect.x = borderOutside.x;
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
if(whichSide == NS_SIDE_BOTTOM){
|
|
|
|
dashRect.y = borderInside.YMost();
|
|
|
|
} else {
|
|
|
|
dashRect.y = borderOutside.y;
|
|
|
|
}
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
temp = borderOutside.XMost();
|
|
|
|
temp1 = temp/dashRect.width;
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
currRect = dashRect;
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
if((temp1%2)==0){
|
|
|
|
adjust = (dashRect.width-(temp%dashRect.width))/2; // even, adjust back
|
|
|
|
// draw in the left and right
|
2001-10-03 04:08:25 +04:00
|
|
|
FillOrInvertRect(aContext, borderOutside.x,dashRect.y,dashRect.width-adjust,dashRect.height,isInvert);
|
|
|
|
FillOrInvertRect(aContext, (borderOutside.XMost()-(dashRect.width-adjust)),dashRect.y,dashRect.width-adjust,dashRect.height,isInvert);
|
1999-11-03 08:46:01 +03:00
|
|
|
currRect.x += (dashRect.width-adjust);
|
|
|
|
temp = temp-= (dashRect.width-adjust);
|
|
|
|
} else {
|
|
|
|
adjust = (temp%dashRect.width)/2;
|
|
|
|
// draw in the left and right
|
2001-10-03 04:08:25 +04:00
|
|
|
FillOrInvertRect(aContext, borderOutside.x,dashRect.y,dashRect.width+adjust,dashRect.height,isInvert);
|
|
|
|
FillOrInvertRect(aContext, (borderOutside.XMost()-(dashRect.width+adjust)),dashRect.y,dashRect.width+adjust,dashRect.height,isInvert);
|
1999-11-03 08:46:01 +03:00
|
|
|
currRect.x += (dashRect.width+adjust);
|
|
|
|
temp = temp-= (dashRect.width+adjust);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( temp > xwidth)
|
|
|
|
temp = xwidth;
|
|
|
|
|
|
|
|
// get the currRect's x into the view before we start
|
|
|
|
if( currRect.x < aDirtyRect.x){
|
|
|
|
temp1 = NSToCoordFloor((float)((aDirtyRect.x-currRect.x)/dashRect.width));
|
|
|
|
currRect.x += temp1*dashRect.width;
|
|
|
|
if((temp1%2)==1){
|
|
|
|
bSolid = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
while(currRect.x<temp) {
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
2001-10-03 04:08:25 +04:00
|
|
|
FillOrInvertRect(aContext, currRect,isInvert);
|
1999-11-03 08:46:01 +03:00
|
|
|
}
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
currRect.x += dashRect.width;
|
1998-12-07 22:02:13 +03:00
|
|
|
}
|
|
|
|
}
|
1999-11-03 08:46:01 +03:00
|
|
|
break;
|
1998-12-07 22:02:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
skippedSide = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
1998-12-18 01:58:51 +03:00
|
|
|
|
1999-01-03 22:23:21 +03:00
|
|
|
/* draw the portions of the border described in aBorderEdges that are dashed.
|
|
|
|
* a border has 4 edges. Each edge has 1 or more segments.
|
|
|
|
* "inside edges" are drawn differently than "outside edges" so the shared edges will match up.
|
|
|
|
* in the case of table collapsing borders, the table edge is the "outside" edge and
|
|
|
|
* cell edges are always "inside" edges (so adjacent cells have 2 shared "inside" edges.)
|
|
|
|
* There is a case for each of the four sides. Only the left side is well documented. The others
|
|
|
|
* are very similar.
|
|
|
|
*/
|
|
|
|
// XXX: doesn't do corners or junctions well at all. Just uses logic stolen
|
|
|
|
// from DrawDashedSides which is insufficient
|
1998-12-30 09:47:26 +03:00
|
|
|
void nsCSSRendering::DrawDashedSegments(nsIRenderingContext& aContext,
|
|
|
|
const nsRect& aBounds,
|
|
|
|
nsBorderEdges * aBorderEdges,
|
|
|
|
PRIntn aSkipSides,
|
2002-01-08 18:13:02 +03:00
|
|
|
/* XXX unused */ nsRect* aGap)
|
1998-12-30 09:47:26 +03:00
|
|
|
{
|
1999-10-26 18:34:17 +04:00
|
|
|
PRIntn dashLength;
|
|
|
|
nsRect dashRect, currRect;
|
|
|
|
|
|
|
|
PRBool bSolid = PR_TRUE;
|
|
|
|
float over = 0.0f;
|
|
|
|
PRBool skippedSide = PR_FALSE;
|
|
|
|
PRIntn whichSide=0;
|
|
|
|
|
1998-12-30 09:47:26 +03:00
|
|
|
|
|
|
|
// do this just to set up initial condition for loop
|
1999-01-03 22:23:21 +03:00
|
|
|
// "segment" is the current portion of the edge we are computing
|
1998-12-30 09:47:26 +03:00
|
|
|
nsBorderEdge * segment = (nsBorderEdge *)(aBorderEdges->mEdges[whichSide].ElementAt(0));
|
|
|
|
PRUint8 style = segment->mStyle;
|
|
|
|
for ( ; whichSide < 4; whichSide++)
|
|
|
|
{
|
|
|
|
if ((1<<whichSide) & aSkipSides) {
|
|
|
|
// Skipped side
|
|
|
|
skippedSide = PR_TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nscoord x=0; nscoord y=0;
|
|
|
|
PRInt32 i;
|
|
|
|
PRInt32 segmentCount = aBorderEdges->mEdges[whichSide].Count();
|
1998-12-31 01:39:49 +03:00
|
|
|
nsBorderEdges * neighborBorderEdges=nsnull;
|
1999-01-03 22:23:21 +03:00
|
|
|
PRIntn neighborEdgeCount=0; // keeps track of which inside neighbor is shared with an outside segment
|
1998-12-30 09:47:26 +03:00
|
|
|
for (i=0; i<segmentCount; i++)
|
|
|
|
{
|
|
|
|
bSolid=PR_TRUE;
|
|
|
|
over = 0.0f;
|
|
|
|
segment = (nsBorderEdge *)(aBorderEdges->mEdges[whichSide].ElementAt(i));
|
|
|
|
style = segment->mStyle;
|
|
|
|
|
|
|
|
// XXX units for dash & dot?
|
|
|
|
if (style == NS_STYLE_BORDER_STYLE_DASHED) {
|
|
|
|
dashLength = DASH_LENGTH;
|
|
|
|
} else {
|
|
|
|
dashLength = DOT_LENGTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
aContext.SetColor(segment->mColor);
|
|
|
|
switch (whichSide) {
|
|
|
|
case NS_SIDE_LEFT:
|
1999-01-03 22:23:21 +03:00
|
|
|
{ // draw left segment i
|
1998-12-30 09:47:26 +03:00
|
|
|
nsBorderEdge * topEdge = (nsBorderEdge *)(aBorderEdges->mEdges[NS_SIDE_TOP].ElementAt(0));
|
|
|
|
if (0==y)
|
1999-01-03 22:23:21 +03:00
|
|
|
{ // y is the offset to the top of this segment. 0 means its the topmost left segment
|
1998-12-30 09:47:26 +03:00
|
|
|
y = aBorderEdges->mMaxBorderWidth.top - topEdge->mWidth;
|
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge)
|
|
|
|
y += topEdge->mWidth;
|
|
|
|
}
|
1999-01-03 22:23:21 +03:00
|
|
|
// the x offset is the x position offset by the max width of the left edge minus this segment's width
|
1998-12-30 09:47:26 +03:00
|
|
|
x = aBounds.x + (aBorderEdges->mMaxBorderWidth.left - segment->mWidth);
|
|
|
|
nscoord height = segment->mLength;
|
1999-01-03 22:23:21 +03:00
|
|
|
// the space between borderOutside and borderInside inclusive is the segment.
|
1998-12-30 09:47:26 +03:00
|
|
|
nsRect borderOutside(x, y, aBounds.width, height);
|
1999-01-03 22:23:21 +03:00
|
|
|
y += segment->mLength; // keep track of the y offset for the next segment
|
1998-12-30 09:47:26 +03:00
|
|
|
if ((style == NS_STYLE_BORDER_STYLE_DASHED) ||
|
|
|
|
(style == NS_STYLE_BORDER_STYLE_DOTTED))
|
|
|
|
{
|
|
|
|
nsRect borderInside(borderOutside);
|
|
|
|
nsMargin outsideMargin(segment->mWidth, 0, 0, 0);
|
|
|
|
borderInside.Deflate(outsideMargin);
|
1999-01-03 22:23:21 +03:00
|
|
|
nscoord totalLength = segment->mLength; // the computed length of this segment
|
|
|
|
// outside edges need info from their inside neighbor. The following code keeps track
|
|
|
|
// of which segment of the inside neighbor's shared edge we should use for this outside segment
|
1998-12-30 09:47:26 +03:00
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge)
|
|
|
|
{
|
1998-12-31 01:39:49 +03:00
|
|
|
if (segment->mInsideNeighbor == neighborBorderEdges)
|
|
|
|
{
|
|
|
|
neighborEdgeCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
neighborBorderEdges = segment->mInsideNeighbor;
|
|
|
|
neighborEdgeCount=0;
|
|
|
|
}
|
|
|
|
nsBorderEdge * neighborLeft = (nsBorderEdge *)(segment->mInsideNeighbor->mEdges[NS_SIDE_LEFT].ElementAt(neighborEdgeCount));
|
1998-12-30 09:47:26 +03:00
|
|
|
totalLength = neighborLeft->mLength;
|
|
|
|
}
|
|
|
|
dashRect.width = borderInside.x - borderOutside.x;
|
|
|
|
dashRect.height = nscoord(dashRect.width * dashLength);
|
|
|
|
dashRect.x = borderOutside.x;
|
|
|
|
dashRect.y = borderOutside.y + (totalLength/2) - dashRect.height;
|
1998-12-31 01:39:49 +03:00
|
|
|
if ((PR_TRUE==aBorderEdges->mOutsideEdge) && (0!=i))
|
1999-01-03 22:23:21 +03:00
|
|
|
dashRect.y -= topEdge->mWidth; // account for the topmost left edge corner with the leftmost top edge
|
|
|
|
if (0)
|
|
|
|
{
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" L: totalLength = %d, borderOutside.y = %d, midpoint %d, dashRect.y = %d\n",
|
|
|
|
totalLength, borderOutside.y, borderOutside.y +(totalLength/2), dashRect.y);
|
1999-01-03 22:23:21 +03:00
|
|
|
}
|
1998-12-30 09:47:26 +03:00
|
|
|
currRect = dashRect;
|
|
|
|
|
1999-01-03 22:23:21 +03:00
|
|
|
// we draw the segment in 2 halves to get the inside and outside edges to line up on the
|
|
|
|
// centerline of the shared edge.
|
|
|
|
|
1998-12-30 09:47:26 +03:00
|
|
|
// draw the top half
|
|
|
|
while (currRect.YMost() > borderInside.y) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.y < borderInside.y) {
|
|
|
|
over = float(borderInside.y - dashRect.y) /
|
|
|
|
float(dashRect.height);
|
|
|
|
currRect.height = currRect.height - (borderInside.y - currRect.y);
|
|
|
|
currRect.y = borderInside.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
1999-01-03 22:23:21 +03:00
|
|
|
if (0)
|
|
|
|
{
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("DASHED LEFT: xywh in loop currRect = %d %d %d %d %s\n",
|
|
|
|
currRect.x, currRect.y, currRect.width, currRect.height, bSolid?"TRUE":"FALSE");
|
1999-01-03 22:23:21 +03:00
|
|
|
}
|
1998-12-30 09:47:26 +03:00
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.y = dashRect.y - currRect.height;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw the bottom half
|
|
|
|
dashRect.y = borderOutside.y + (totalLength/2) + dashRect.height;
|
1998-12-31 01:39:49 +03:00
|
|
|
if ((PR_TRUE==aBorderEdges->mOutsideEdge) && (0!=i))
|
|
|
|
dashRect.y -= topEdge->mWidth;
|
1998-12-30 09:47:26 +03:00
|
|
|
currRect = dashRect;
|
|
|
|
bSolid=PR_TRUE;
|
|
|
|
over = 0.0f;
|
|
|
|
while (currRect.YMost() < borderInside.YMost()) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.y < borderInside.y) {
|
|
|
|
over = float(borderInside.y - dashRect.y) /
|
|
|
|
float(dashRect.height);
|
|
|
|
currRect.height = currRect.height - (borderInside.y - currRect.y);
|
|
|
|
currRect.y = borderInside.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
1999-01-03 22:23:21 +03:00
|
|
|
if (0)
|
|
|
|
{
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("DASHED LEFT: xywh in loop currRect = %d %d %d %d %s\n",
|
|
|
|
currRect.x, currRect.y, currRect.width, currRect.height, bSolid?"TRUE":"FALSE");
|
1999-01-03 22:23:21 +03:00
|
|
|
}
|
1998-12-30 09:47:26 +03:00
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.y = dashRect.y + currRect.height;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_TOP:
|
1999-01-03 22:23:21 +03:00
|
|
|
{ // draw top segment i
|
1998-12-30 09:47:26 +03:00
|
|
|
if (0==x)
|
|
|
|
{
|
|
|
|
nsBorderEdge * leftEdge = (nsBorderEdge *)(aBorderEdges->mEdges[NS_SIDE_LEFT].ElementAt(0));
|
|
|
|
x = aBorderEdges->mMaxBorderWidth.left - leftEdge->mWidth;
|
|
|
|
}
|
|
|
|
y = aBounds.y;
|
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge) // segments of the outside edge are bottom-aligned
|
|
|
|
y += aBorderEdges->mMaxBorderWidth.top - segment->mWidth;
|
|
|
|
nsRect borderOutside(x, y, segment->mLength, aBounds.height);
|
|
|
|
x += segment->mLength;
|
|
|
|
if ((style == NS_STYLE_BORDER_STYLE_DASHED) ||
|
|
|
|
(style == NS_STYLE_BORDER_STYLE_DOTTED))
|
|
|
|
{
|
|
|
|
nsRect borderInside(borderOutside);
|
|
|
|
nsBorderEdge * neighbor;
|
2000-09-20 18:47:18 +04:00
|
|
|
// XXX Adding check to make sure segment->mInsideNeighbor is not null
|
|
|
|
// so it will do the else part, at this point we are assuming this is an
|
|
|
|
// ok thing to do (Bug 52130)
|
2000-09-20 08:02:20 +04:00
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge && segment->mInsideNeighbor)
|
1998-12-30 09:47:26 +03:00
|
|
|
neighbor = (nsBorderEdge *)(segment->mInsideNeighbor->mEdges[NS_SIDE_LEFT].ElementAt(0));
|
|
|
|
else
|
|
|
|
neighbor = (nsBorderEdge *)(aBorderEdges->mEdges[NS_SIDE_LEFT].ElementAt(0));
|
|
|
|
nsMargin outsideMargin(neighbor->mWidth, segment->mWidth, 0, segment->mWidth);
|
|
|
|
borderInside.Deflate(outsideMargin);
|
|
|
|
nscoord firstRectWidth = 0;
|
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge && 0==i)
|
|
|
|
{
|
|
|
|
firstRectWidth = borderInside.x - borderOutside.x;
|
|
|
|
aContext.FillRect(borderOutside.x, borderOutside.y,
|
|
|
|
firstRectWidth,
|
|
|
|
borderInside.y - borderOutside.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
dashRect.height = borderInside.y - borderOutside.y;
|
|
|
|
dashRect.width = dashRect.height * dashLength;
|
|
|
|
dashRect.x = borderOutside.x + firstRectWidth;
|
|
|
|
dashRect.y = borderOutside.y;
|
|
|
|
currRect = dashRect;
|
|
|
|
|
|
|
|
while (currRect.x < borderInside.XMost()) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.XMost() > borderInside.XMost()) {
|
|
|
|
over = float(dashRect.XMost() - borderInside.XMost()) /
|
|
|
|
float(dashRect.width);
|
|
|
|
currRect.width = currRect.width -
|
|
|
|
(currRect.XMost() - borderInside.XMost());
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.x = dashRect.x + currRect.width;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_RIGHT:
|
1999-01-03 22:23:21 +03:00
|
|
|
{ // draw right segment i
|
1998-12-30 09:47:26 +03:00
|
|
|
nsBorderEdge * topEdge = (nsBorderEdge *)
|
|
|
|
(aBorderEdges->mEdges[NS_SIDE_TOP].ElementAt(aBorderEdges->mEdges[NS_SIDE_TOP].Count()-1));
|
|
|
|
if (0==y)
|
|
|
|
{
|
|
|
|
y = aBorderEdges->mMaxBorderWidth.top - topEdge->mWidth;
|
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge)
|
|
|
|
y += topEdge->mWidth;
|
|
|
|
}
|
|
|
|
nscoord width;
|
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge)
|
|
|
|
{
|
|
|
|
width = aBounds.width - aBorderEdges->mMaxBorderWidth.right;
|
|
|
|
width += segment->mWidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = aBounds.width;
|
|
|
|
}
|
|
|
|
nscoord height = segment->mLength;
|
|
|
|
nsRect borderOutside(aBounds.x, y, width, height);
|
|
|
|
y += segment->mLength;
|
|
|
|
if ((style == NS_STYLE_BORDER_STYLE_DASHED) ||
|
|
|
|
(style == NS_STYLE_BORDER_STYLE_DOTTED))
|
|
|
|
{
|
|
|
|
nsRect borderInside(borderOutside);
|
|
|
|
nsMargin outsideMargin(segment->mWidth, 0, (segment->mWidth), 0);
|
|
|
|
borderInside.Deflate(outsideMargin);
|
|
|
|
nscoord totalLength = segment->mLength;
|
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge)
|
|
|
|
{
|
1998-12-31 01:39:49 +03:00
|
|
|
if (segment->mInsideNeighbor == neighborBorderEdges)
|
1998-12-30 09:47:26 +03:00
|
|
|
{
|
1998-12-31 01:39:49 +03:00
|
|
|
neighborEdgeCount++;
|
1998-12-30 09:47:26 +03:00
|
|
|
}
|
1998-12-31 01:39:49 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
neighborBorderEdges = segment->mInsideNeighbor;
|
|
|
|
neighborEdgeCount=0;
|
1998-12-30 09:47:26 +03:00
|
|
|
}
|
1998-12-31 01:39:49 +03:00
|
|
|
nsBorderEdge * neighborRight = (nsBorderEdge *)(segment->mInsideNeighbor->mEdges[NS_SIDE_RIGHT].ElementAt(neighborEdgeCount));
|
|
|
|
totalLength = neighborRight->mLength;
|
1998-12-30 09:47:26 +03:00
|
|
|
}
|
|
|
|
dashRect.width = borderOutside.XMost() - borderInside.XMost();
|
|
|
|
dashRect.height = nscoord(dashRect.width * dashLength);
|
|
|
|
dashRect.x = borderInside.XMost();
|
1998-12-31 01:39:49 +03:00
|
|
|
dashRect.y = borderOutside.y + (totalLength/2) - dashRect.height;
|
|
|
|
if ((PR_TRUE==aBorderEdges->mOutsideEdge) && (0!=i))
|
|
|
|
dashRect.y -= topEdge->mWidth;
|
1999-01-03 22:23:21 +03:00
|
|
|
currRect = dashRect;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
|
|
|
// draw the top half
|
|
|
|
while (currRect.YMost() > borderInside.y) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.y < borderInside.y) {
|
|
|
|
over = float(borderInside.y - dashRect.y) /
|
|
|
|
float(dashRect.height);
|
|
|
|
currRect.height = currRect.height - (borderInside.y - currRect.y);
|
|
|
|
currRect.y = borderInside.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.y = dashRect.y - currRect.height;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw the bottom half
|
1998-12-31 01:39:49 +03:00
|
|
|
dashRect.y = borderOutside.y + (totalLength/2) + dashRect.height;
|
|
|
|
if ((PR_TRUE==aBorderEdges->mOutsideEdge) && (0!=i))
|
|
|
|
dashRect.y -= topEdge->mWidth;
|
1998-12-30 09:47:26 +03:00
|
|
|
currRect = dashRect;
|
|
|
|
bSolid=PR_TRUE;
|
|
|
|
over = 0.0f;
|
|
|
|
while (currRect.YMost() < borderInside.YMost()) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.y < borderInside.y) {
|
|
|
|
over = float(borderInside.y - dashRect.y) /
|
|
|
|
float(dashRect.height);
|
|
|
|
currRect.height = currRect.height - (borderInside.y - currRect.y);
|
|
|
|
currRect.y = borderInside.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.y = dashRect.y + currRect.height;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_BOTTOM:
|
1999-01-03 22:23:21 +03:00
|
|
|
{ // draw bottom segment i
|
1998-12-30 09:47:26 +03:00
|
|
|
if (0==x)
|
|
|
|
{
|
|
|
|
nsBorderEdge * leftEdge = (nsBorderEdge *)
|
|
|
|
(aBorderEdges->mEdges[NS_SIDE_LEFT].ElementAt(aBorderEdges->mEdges[NS_SIDE_LEFT].Count()-1));
|
|
|
|
x = aBorderEdges->mMaxBorderWidth.left - leftEdge->mWidth;
|
|
|
|
}
|
|
|
|
y = aBounds.y;
|
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge) // segments of the outside edge are top-aligned
|
|
|
|
y -= aBorderEdges->mMaxBorderWidth.bottom - segment->mWidth;
|
|
|
|
nsRect borderOutside(x, y, segment->mLength, aBounds.height);
|
|
|
|
x += segment->mLength;
|
|
|
|
if ((style == NS_STYLE_BORDER_STYLE_DASHED) ||
|
|
|
|
(style == NS_STYLE_BORDER_STYLE_DOTTED))
|
|
|
|
{
|
|
|
|
nsRect borderInside(borderOutside);
|
|
|
|
nsBorderEdge * neighbor;
|
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge)
|
|
|
|
neighbor = (nsBorderEdge *)(segment->mInsideNeighbor->mEdges[NS_SIDE_LEFT].ElementAt(0));
|
|
|
|
else
|
|
|
|
neighbor = (nsBorderEdge *)(aBorderEdges->mEdges[NS_SIDE_LEFT].ElementAt(0));
|
|
|
|
nsMargin outsideMargin(neighbor->mWidth, segment->mWidth, 0, segment->mWidth);
|
|
|
|
borderInside.Deflate(outsideMargin);
|
|
|
|
nscoord firstRectWidth = 0;
|
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge && 0==i)
|
|
|
|
{
|
|
|
|
firstRectWidth = borderInside.x - borderOutside.x;
|
|
|
|
aContext.FillRect(borderOutside.x, borderInside.YMost(),
|
|
|
|
firstRectWidth,
|
|
|
|
borderOutside.YMost() - borderInside.YMost());
|
|
|
|
}
|
|
|
|
|
|
|
|
dashRect.height = borderOutside.YMost() - borderInside.YMost();
|
|
|
|
dashRect.width = nscoord(dashRect.height * dashLength);
|
|
|
|
dashRect.x = borderOutside.x + firstRectWidth;
|
|
|
|
dashRect.y = borderInside.YMost();
|
|
|
|
currRect = dashRect;
|
|
|
|
|
|
|
|
while (currRect.x < borderInside.XMost()) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.XMost() > borderInside.XMost()) {
|
|
|
|
over = float(dashRect.XMost() - borderInside.XMost()) /
|
|
|
|
float(dashRect.width);
|
|
|
|
currRect.width = currRect.width -
|
|
|
|
(currRect.XMost() - borderInside.XMost());
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.x = dashRect.x + currRect.width;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
skippedSide = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-12 18:30:00 +04:00
|
|
|
nscolor
|
2001-05-10 18:19:58 +04:00
|
|
|
nsCSSRendering::TransformColor(nscolor aMapColor,PRBool aNoBackGround)
|
|
|
|
{
|
2002-04-12 18:30:00 +04:00
|
|
|
PRUint16 hue,sat,value;
|
|
|
|
nscolor newcolor;
|
2001-05-10 18:19:58 +04:00
|
|
|
|
|
|
|
newcolor = aMapColor;
|
|
|
|
if (PR_TRUE == aNoBackGround){
|
2002-04-12 18:30:00 +04:00
|
|
|
// convert the RBG to HSV so we can get the lightness (which is the v)
|
2002-04-12 19:26:05 +04:00
|
|
|
NS_RGB2HSV(newcolor,hue,sat,value);
|
2003-01-05 07:52:27 +03:00
|
|
|
// The goal here is to send white to black while letting colored
|
|
|
|
// stuff stay colored... So we adopt the following approach.
|
|
|
|
// Something with sat = 0 should end up with value = 0. Something
|
|
|
|
// with a high sat can end up with a high value and it's ok.... At
|
|
|
|
// the same time, we don't want to make things lighter. Do
|
|
|
|
// something simple, since it seems to work.
|
|
|
|
if (value > sat) {
|
|
|
|
value = sat;
|
2002-04-12 18:30:00 +04:00
|
|
|
// convert this color back into the RGB color space.
|
2002-04-12 19:26:05 +04:00
|
|
|
NS_HSV2RGB(newcolor,hue,sat,value);
|
2001-05-10 18:19:58 +04:00
|
|
|
}
|
|
|
|
}
|
2002-04-12 18:30:00 +04:00
|
|
|
return newcolor;
|
2001-05-10 18:19:58 +04:00
|
|
|
}
|
|
|
|
|
2000-03-30 10:27:32 +04:00
|
|
|
// method GetBGColorForHTMLElement
|
|
|
|
//
|
|
|
|
// Now here's a *fun* hack: Nav4 uses the BODY element's background color for the
|
|
|
|
// background color on tables so we need to find that element's
|
|
|
|
// color and use it... Actually, we can use the HTML element as well.
|
|
|
|
//
|
|
|
|
// Traverse from PresContext to PresShell to Document to RootContent. The RootContent is
|
|
|
|
// then checked to ensure that it is the HTML or BODY element, and if it is, we get
|
|
|
|
// it's primary frame and from that the style context and from that the color to use.
|
|
|
|
//
|
|
|
|
PRBool GetBGColorForHTMLElement( nsIPresContext *aPresContext,
|
2001-06-01 02:19:43 +04:00
|
|
|
const nsStyleBackground *&aBGColor )
|
2000-03-30 10:27:32 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aPresContext, "null params not allowed");
|
|
|
|
PRBool result = PR_FALSE; // assume we did not find the HTML element
|
|
|
|
|
|
|
|
nsIPresShell* shell = nsnull;
|
|
|
|
aPresContext->GetShell(&shell);
|
|
|
|
if (shell) {
|
|
|
|
nsIDocument *doc = nsnull;
|
|
|
|
if (NS_SUCCEEDED(shell->GetDocument(&doc)) && doc) {
|
2001-06-20 07:27:48 +04:00
|
|
|
nsIContent *pContent;
|
|
|
|
if (NS_SUCCEEDED(doc->GetRootContent(&pContent)) && pContent) {
|
2000-03-30 10:27:32 +04:00
|
|
|
// make sure that this is the HTML element
|
2003-06-14 00:10:01 +04:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
pContent->GetTag(getter_AddRefs(tag));
|
2000-03-30 10:27:32 +04:00
|
|
|
NS_ASSERTION(tag, "Tag could not be retrieved from root content element");
|
|
|
|
if (tag) {
|
|
|
|
if (tag == nsHTMLAtoms::html ||
|
|
|
|
tag == nsHTMLAtoms::body) {
|
|
|
|
// use this guy's color
|
|
|
|
nsIFrame *pFrame = nsnull;
|
|
|
|
if (NS_SUCCEEDED(shell->GetPrimaryFrameFor(pContent, &pFrame)) && pFrame) {
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext *pContext = pFrame->GetStyleContext();
|
2000-03-30 10:27:32 +04:00
|
|
|
if (pContext) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleBackground* color = pContext->GetStyleBackground();
|
2000-03-30 10:27:32 +04:00
|
|
|
if (0 == (color->mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT)) {
|
|
|
|
aBGColor = color;
|
|
|
|
// set the reslt to TRUE to indicate we mapped the color
|
|
|
|
result = PR_TRUE;
|
|
|
|
}
|
|
|
|
}// if context
|
|
|
|
}// if frame
|
|
|
|
}// if tag == html or body
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf( "Root Content is not HTML or BODY: cannot get bgColor of HTML or BODY\n");
|
2000-03-30 10:27:32 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}// if tag
|
|
|
|
NS_RELEASE(pContent);
|
|
|
|
}// if content
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}// if doc
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
} // if shell
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-05-09 04:53:51 +04:00
|
|
|
// nethod GetFrameForBackgroundUpdate
|
|
|
|
//
|
|
|
|
// If the frame (aFrame) is the HTML or BODY frame then find the canvas frame and set the
|
|
|
|
// aBGFrame param to that. This is used when we need a frame to invalidate after an asynch
|
|
|
|
// image load for the background.
|
|
|
|
//
|
|
|
|
// The check is a bit expensive, however until the canvas frame is somehow cached on the
|
|
|
|
// body frame, or the root element, we need to walk the frames up until we find the canvas
|
|
|
|
//
|
|
|
|
nsresult GetFrameForBackgroundUpdate(nsIPresContext *aPresContext,nsIFrame *aFrame, nsIFrame **aBGFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame && aBGFrame, "illegal null parameter");
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (aFrame && aBGFrame) {
|
|
|
|
*aBGFrame = aFrame; // default to the frame passed in
|
|
|
|
|
2003-07-05 19:04:34 +04:00
|
|
|
nsIContent* pContent = aFrame->GetContent();
|
2000-05-09 04:53:51 +04:00
|
|
|
if (pContent) {
|
|
|
|
// make sure that this is the HTML or BODY element
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
2003-06-14 00:10:01 +04:00
|
|
|
pContent->GetTag(getter_AddRefs(tag));
|
2000-05-09 04:53:51 +04:00
|
|
|
if (tag) {
|
|
|
|
if (tag.get() == nsHTMLAtoms::html ||
|
|
|
|
tag.get() == nsHTMLAtoms::body) {
|
|
|
|
// the frame is the body frame, so we provide the canvas frame
|
2003-07-05 19:04:34 +04:00
|
|
|
nsIFrame *pCanvasFrame = aFrame->GetParent();
|
2000-05-09 04:53:51 +04:00
|
|
|
while (pCanvasFrame) {
|
|
|
|
nsCOMPtr<nsIAtom> parentType;
|
|
|
|
pCanvasFrame->GetFrameType(getter_AddRefs(parentType));
|
|
|
|
if (parentType.get() == nsLayoutAtoms::canvasFrame) {
|
|
|
|
*aBGFrame = pCanvasFrame;
|
|
|
|
break;
|
|
|
|
}
|
2003-07-05 19:04:34 +04:00
|
|
|
pCanvasFrame = pCanvasFrame->GetParent();
|
2000-05-09 04:53:51 +04:00
|
|
|
}
|
|
|
|
}// if tag == html or body
|
|
|
|
}// if tag
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-03-30 10:27:32 +04:00
|
|
|
// helper macro to determine if the borderstyle 'a' is a MOZ-BG-XXX style
|
|
|
|
#define MOZ_BG_BORDER(a)\
|
|
|
|
((a==NS_STYLE_BORDER_STYLE_BG_INSET) || (a==NS_STYLE_BORDER_STYLE_BG_OUTSET))
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
static
|
2001-12-05 11:35:05 +03:00
|
|
|
PRBool GetBorderColor(const nsStyleColor* aColor, const nsStyleBorder& aBorder, PRUint8 aSide, nscolor& aColorVal,
|
|
|
|
nsBorderColors** aCompositeColors = nsnull)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
|
|
|
PRBool transparent;
|
|
|
|
PRBool foreground;
|
2001-12-05 11:35:05 +03:00
|
|
|
|
|
|
|
if (aCompositeColors) {
|
|
|
|
aBorder.GetCompositeColors(aSide, aCompositeColors);
|
|
|
|
if (*aCompositeColors)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
aBorder.GetBorderColor(aSide, aColorVal, transparent, foreground);
|
|
|
|
if (foreground)
|
|
|
|
aColorVal = aColor->mColor;
|
|
|
|
|
|
|
|
return !transparent;
|
|
|
|
}
|
2000-03-30 10:27:32 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// XXX improve this to constrain rendering to the damaged area
|
1999-11-24 09:03:41 +03:00
|
|
|
void nsCSSRendering::PaintBorder(nsIPresContext* 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,
|
1999-03-05 22:23:52 +03:00
|
|
|
PRIntn aSkipSides,
|
1999-09-03 18:12:09 +04:00
|
|
|
nsRect* aGap,
|
|
|
|
nscoord aHardBorderSize,
|
|
|
|
PRBool aShouldIgnoreRounded)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-03-30 10:27:32 +04:00
|
|
|
PRIntn cnt;
|
|
|
|
nsMargin border;
|
|
|
|
nsStyleCoord bordStyleRadius[4];
|
|
|
|
PRInt16 borderRadii[4],i;
|
|
|
|
float percent;
|
|
|
|
nsCompatibility compatMode;
|
|
|
|
aPresContext->GetCompatibilityMode(&compatMode);
|
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
// Check to see if we have an appearance defined. If so, we let the theme
|
2002-09-21 05:03:38 +04:00
|
|
|
// renderer draw the border. DO not get the data from aForFrame, since the passed in style context
|
|
|
|
// may be different! Always use |aStyleContext|!
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleDisplay* displayData = aStyleContext->GetStyleDisplay();
|
2001-12-18 01:51:39 +03:00
|
|
|
if (displayData->mAppearance) {
|
|
|
|
nsCOMPtr<nsITheme> theme;
|
|
|
|
aPresContext->GetTheme(getter_AddRefs(theme));
|
2002-09-21 05:03:38 +04:00
|
|
|
if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame, displayData->mAppearance))
|
2001-12-18 01:51:39 +03:00
|
|
|
return; // Let the theme handle it.
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
// Get our style context's color struct.
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleColor* ourColor = aStyleContext->GetStyleColor();
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2000-03-30 10:27:32 +04:00
|
|
|
// in NavQuirks mode we want to use the parent's context as a starting point
|
|
|
|
// for determining the background color
|
2001-06-01 02:19:43 +04:00
|
|
|
const nsStyleBackground* bgColor =
|
2002-08-11 21:56:15 +04:00
|
|
|
nsCSSRendering::FindNonTransparentBackground(aStyleContext,
|
2000-02-11 04:23:04 +03:00
|
|
|
compatMode == eCompatibility_NavQuirks ? PR_TRUE : PR_FALSE);
|
2000-03-30 10:27:32 +04:00
|
|
|
// mozBGColor is used instead of bgColor when the display type is BG_INSET or BG_OUTSET
|
|
|
|
// AND, in quirk mode, it is set to the BODY element's background color instead of the nearest
|
|
|
|
// ancestor's background color.
|
2001-06-01 02:19:43 +04:00
|
|
|
const nsStyleBackground* mozBGColor = bgColor;
|
2000-03-30 10:27:32 +04:00
|
|
|
|
|
|
|
// now check if we are in Quirks mode and have a border style of BG_INSET or OUTSET
|
|
|
|
// - if so we use the bgColor from the HTML element instead of the nearest ancestor
|
|
|
|
if (compatMode == eCompatibility_NavQuirks) {
|
|
|
|
PRBool bNeedBodyBGColor = PR_FALSE;
|
|
|
|
if (aStyleContext) {
|
|
|
|
for (cnt=0; cnt<4;cnt++) {
|
|
|
|
bNeedBodyBGColor = MOZ_BG_BORDER(aBorderStyle.GetBorderStyle(cnt));
|
|
|
|
if (bNeedBodyBGColor) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bNeedBodyBGColor) {
|
|
|
|
GetBGColorForHTMLElement(aPresContext, mozBGColor);
|
|
|
|
}
|
|
|
|
}
|
1999-01-23 01:24:05 +03:00
|
|
|
|
1999-09-03 18:12:09 +04:00
|
|
|
if (aHardBorderSize > 0) {
|
|
|
|
border.SizeTo(aHardBorderSize, aHardBorderSize, aHardBorderSize, aHardBorderSize);
|
|
|
|
} else {
|
|
|
|
aBorderStyle.CalcBorderFor(aForFrame, border);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
if ((0 == border.left) && (0 == border.right) &&
|
|
|
|
(0 == border.top) && (0 == border.bottom)) {
|
|
|
|
// Empty border area
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-12-23 23:48:07 +03:00
|
|
|
|
|
|
|
// get the radius for our border
|
|
|
|
aBorderStyle.mBorderRadius.GetTop(bordStyleRadius[0]); //topleft
|
|
|
|
aBorderStyle.mBorderRadius.GetRight(bordStyleRadius[1]); //topright
|
|
|
|
aBorderStyle.mBorderRadius.GetBottom(bordStyleRadius[2]); //bottomright
|
|
|
|
aBorderStyle.mBorderRadius.GetLeft(bordStyleRadius[3]); //bottomleft
|
|
|
|
|
|
|
|
for(i=0;i<4;i++) {
|
|
|
|
borderRadii[i] = 0;
|
|
|
|
switch ( bordStyleRadius[i].GetUnit()) {
|
1999-04-19 09:27:55 +04:00
|
|
|
case eStyleUnit_Inherit:
|
|
|
|
break;
|
|
|
|
case eStyleUnit_Percent:
|
1999-12-23 23:48:07 +03:00
|
|
|
percent = bordStyleRadius[i].GetPercentValue();
|
|
|
|
borderRadii[i] = (nscoord)(percent * aBorderArea.width);
|
1999-04-19 09:27:55 +04:00
|
|
|
break;
|
|
|
|
case eStyleUnit_Coord:
|
1999-12-23 23:48:07 +03:00
|
|
|
borderRadii[i] = bordStyleRadius[i].GetCoordValue();
|
1999-04-19 09:27:55 +04:00
|
|
|
break;
|
1999-08-24 18:51:16 +04:00
|
|
|
default:
|
|
|
|
break;
|
1999-12-23 23:48:07 +03:00
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
|
|
|
|
2000-02-01 19:03:13 +03:00
|
|
|
// rounded version of the outline
|
|
|
|
// check for any corner that is rounded
|
|
|
|
for(i=0;i<4;i++){
|
2001-12-05 11:35:05 +03:00
|
|
|
if(borderRadii[i] > 0 && !aBorderStyle.mBorderColors){
|
2001-02-07 12:57:26 +03:00
|
|
|
PaintRoundedBorder(aPresContext,aRenderingContext,aForFrame,aDirtyRect,aBorderArea,&aBorderStyle,nsnull,aStyleContext,aSkipSides,borderRadii,aGap,PR_FALSE);
|
2000-02-01 19:03:13 +03:00
|
|
|
return;
|
1999-09-03 18:12:09 +04:00
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
|
|
|
|
1998-12-10 20:50:11 +03:00
|
|
|
// Turn off rendering for all of the zero sized sides
|
|
|
|
if (0 == border.top) aSkipSides |= (1 << NS_SIDE_TOP);
|
|
|
|
if (0 == border.right) aSkipSides |= (1 << NS_SIDE_RIGHT);
|
|
|
|
if (0 == border.bottom) aSkipSides |= (1 << NS_SIDE_BOTTOM);
|
|
|
|
if (0 == border.left) aSkipSides |= (1 << NS_SIDE_LEFT);
|
1998-12-07 22:02:13 +03:00
|
|
|
|
2001-04-16 17:14:40 +04:00
|
|
|
// get the inside and outside parts of the border
|
|
|
|
nsRect outerRect(aBorderArea);
|
|
|
|
nsRect innerRect(outerRect);
|
|
|
|
innerRect.Deflate(border);
|
|
|
|
|
|
|
|
if (border.left + border.right > aBorderArea.width) {
|
|
|
|
innerRect.x = outerRect.x;
|
|
|
|
innerRect.width = outerRect.width;
|
|
|
|
}
|
|
|
|
if (border.top + border.bottom > aBorderArea.height) {
|
|
|
|
innerRect.y = outerRect.y;
|
|
|
|
innerRect.height = outerRect.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-29 07:25:56 +04:00
|
|
|
|
|
|
|
// If the dirty rect is completely inside the border area (e.g., only the
|
|
|
|
// content is being painted), then we can skip out now
|
2001-04-16 17:14:40 +04:00
|
|
|
if (innerRect.Contains(aDirtyRect)) {
|
1999-08-29 07:25:56 +04:00
|
|
|
return;
|
|
|
|
}
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//see if any sides are dotted or dashed
|
1998-05-20 03:11:28 +04:00
|
|
|
for (cnt = 0; cnt < 4; cnt++) {
|
1999-01-23 01:24:05 +03:00
|
|
|
if ((aBorderStyle.GetBorderStyle(cnt) == NS_STYLE_BORDER_STYLE_DOTTED) ||
|
|
|
|
(aBorderStyle.GetBorderStyle(cnt) == NS_STYLE_BORDER_STYLE_DASHED)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cnt < 4) {
|
2001-06-01 02:19:43 +04:00
|
|
|
DrawDashedSides(cnt, aRenderingContext,aDirtyRect, ourColor, &aBorderStyle,nsnull, PR_FALSE,
|
2001-04-16 17:14:40 +04:00
|
|
|
outerRect, innerRect, aSkipSides, aGap);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2003-03-24 13:17:25 +03:00
|
|
|
// dont clip the borders for composite borders, they use the inner and
|
|
|
|
// outer rect to compute the diagonale to cross the border radius
|
|
|
|
nsRect compositeInnerRect(innerRect);
|
|
|
|
nsRect compositeOuterRect(outerRect);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Draw all the other sides
|
2003-03-11 18:15:08 +03:00
|
|
|
if (!aDirtyRect.Contains(outerRect)) {
|
|
|
|
// Border leaks out of the dirty rectangle - lets clip it but with care
|
|
|
|
if (innerRect.y < aDirtyRect.y) {
|
|
|
|
aSkipSides |= (1 << NS_SIDE_TOP);
|
2003-05-14 04:44:38 +04:00
|
|
|
PRUint32 shortenBy =
|
|
|
|
PR_MIN(innerRect.height, aDirtyRect.y - innerRect.y);
|
|
|
|
innerRect.y += shortenBy;
|
|
|
|
innerRect.height -= shortenBy;
|
|
|
|
outerRect.y += shortenBy;
|
|
|
|
outerRect.height -= shortenBy;
|
2003-03-11 18:15:08 +03:00
|
|
|
}
|
2003-05-14 04:44:38 +04:00
|
|
|
if (aDirtyRect.YMost() < innerRect.YMost()) {
|
2003-03-11 18:15:08 +03:00
|
|
|
aSkipSides |= (1 << NS_SIDE_BOTTOM);
|
2003-05-14 04:44:38 +04:00
|
|
|
PRUint32 shortenBy =
|
|
|
|
PR_MIN(innerRect.height, innerRect.YMost() - aDirtyRect.YMost());
|
|
|
|
innerRect.height -= shortenBy;
|
|
|
|
outerRect.height -= shortenBy;
|
2003-03-11 18:15:08 +03:00
|
|
|
}
|
|
|
|
if (innerRect.x < aDirtyRect.x) {
|
|
|
|
aSkipSides |= (1 << NS_SIDE_LEFT);
|
2003-05-14 04:44:38 +04:00
|
|
|
PRUint32 shortenBy =
|
|
|
|
PR_MIN(innerRect.width, aDirtyRect.x - innerRect.x);
|
|
|
|
innerRect.x += shortenBy;
|
|
|
|
innerRect.width -= shortenBy;
|
|
|
|
outerRect.x += shortenBy;
|
|
|
|
outerRect.width -= shortenBy;
|
2003-03-11 18:15:08 +03:00
|
|
|
}
|
2003-05-14 04:44:38 +04:00
|
|
|
if (aDirtyRect.XMost() < innerRect.XMost()) {
|
2003-03-11 18:15:08 +03:00
|
|
|
aSkipSides |= (1 << NS_SIDE_RIGHT);
|
2003-05-14 04:44:38 +04:00
|
|
|
PRUint32 shortenBy =
|
|
|
|
PR_MIN(innerRect.width, innerRect.XMost() - aDirtyRect.XMost());
|
|
|
|
innerRect.width -= shortenBy;
|
|
|
|
outerRect.width -= shortenBy;
|
2003-03-11 18:15:08 +03:00
|
|
|
}
|
|
|
|
}
|
1999-08-24 18:51:16 +04:00
|
|
|
/* Get our conversion values */
|
|
|
|
nscoord twipsPerPixel;
|
|
|
|
float p2t;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetScaledPixelsToTwips(&p2t);
|
1999-08-24 18:51:16 +04:00
|
|
|
twipsPerPixel = NSIntPixelsToTwips(1,p2t);
|
|
|
|
|
2001-12-05 11:35:05 +03:00
|
|
|
static PRUint8 sideOrder[] = { NS_SIDE_BOTTOM, NS_SIDE_LEFT, NS_SIDE_TOP, NS_SIDE_RIGHT };
|
1999-03-28 08:30:28 +04:00
|
|
|
nscolor sideColor;
|
2001-12-05 11:35:05 +03:00
|
|
|
nsBorderColors* compositeColors = nsnull;
|
|
|
|
for (cnt = 0; cnt < 4; cnt++) {
|
|
|
|
PRUint8 side = sideOrder[cnt];
|
|
|
|
if (0 == (aSkipSides & (1<<side))) {
|
|
|
|
if (GetBorderColor(ourColor, aBorderStyle, side, sideColor, &compositeColors)) {
|
|
|
|
if (compositeColors)
|
2003-03-24 13:17:25 +03:00
|
|
|
DrawCompositeSide(aRenderingContext, side, compositeColors, compositeOuterRect,
|
|
|
|
compositeInnerRect, borderRadii, twipsPerPixel, aGap);
|
2001-12-05 11:35:05 +03:00
|
|
|
else
|
|
|
|
DrawSide(aRenderingContext, side,
|
|
|
|
aBorderStyle.GetBorderStyle(side),
|
|
|
|
sideColor,
|
|
|
|
MOZ_BG_BORDER(aBorderStyle.GetBorderStyle(side)) ?
|
|
|
|
mozBGColor->mBackgroundColor :
|
|
|
|
bgColor->mBackgroundColor,
|
|
|
|
outerRect,innerRect, aSkipSides,
|
|
|
|
twipsPerPixel, aGap);
|
|
|
|
}
|
1999-03-28 08:30:28 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2001-12-05 11:35:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSRendering::DrawCompositeSide(nsIRenderingContext& aRenderingContext,
|
|
|
|
PRIntn aWhichSide,
|
|
|
|
nsBorderColors* aCompositeColors,
|
|
|
|
const nsRect& aOuterRect,
|
|
|
|
const nsRect& aInnerRect,
|
|
|
|
PRInt16* aBorderRadii,
|
|
|
|
nscoord twipsPerPixel,
|
|
|
|
nsRect* aGap)
|
|
|
|
|
|
|
|
{
|
|
|
|
// Loop over each color and at each iteration shrink the length of the
|
|
|
|
// lines that we draw.
|
|
|
|
nsRect currOuterRect(aOuterRect);
|
|
|
|
|
|
|
|
// XXXdwh This border radius code is rather hacky and will only work for
|
|
|
|
// small radii, but it will be sufficient to get a major performance
|
|
|
|
// improvement in themes with small curvature (like Modern).
|
|
|
|
// Still, this code should be rewritten if/when someone chooses to pick
|
|
|
|
// up the -moz-border-radius gauntlet.
|
|
|
|
// Alternatively we could add support for a -moz-border-diagonal property, which is
|
|
|
|
// what this code actually draws (instead of a curve).
|
2001-12-11 14:13:16 +03:00
|
|
|
|
|
|
|
// determine the the number of pixels we need to draw for this side
|
|
|
|
// and the start and end radii
|
|
|
|
nscoord shrinkage, startRadius, endRadius;
|
|
|
|
if (aWhichSide == NS_SIDE_TOP) {
|
|
|
|
shrinkage = aInnerRect.y - aOuterRect.y;
|
|
|
|
startRadius = aBorderRadii[0];
|
|
|
|
endRadius = aBorderRadii[1];
|
|
|
|
} else if (aWhichSide == NS_SIDE_BOTTOM) {
|
|
|
|
shrinkage = (aOuterRect.height+aOuterRect.y) - (aInnerRect.height+aInnerRect.y);
|
|
|
|
startRadius = aBorderRadii[3];
|
|
|
|
endRadius = aBorderRadii[2];
|
|
|
|
} else if (aWhichSide == NS_SIDE_RIGHT) {
|
|
|
|
shrinkage = (aOuterRect.width+aOuterRect.x) - (aInnerRect.width+aInnerRect.x);
|
|
|
|
startRadius = aBorderRadii[1];
|
|
|
|
endRadius = aBorderRadii[2];
|
|
|
|
} else if (aWhichSide == NS_SIDE_LEFT) {
|
|
|
|
shrinkage = aInnerRect.x - aOuterRect.x;
|
|
|
|
startRadius = aBorderRadii[0];
|
|
|
|
endRadius = aBorderRadii[3];
|
|
|
|
}
|
|
|
|
|
2001-12-20 21:02:43 +03:00
|
|
|
while (shrinkage > 0) {
|
2001-12-05 11:35:05 +03:00
|
|
|
nscoord xshrink = 0;
|
|
|
|
nscoord yshrink = 0;
|
|
|
|
nscoord widthshrink = 0;
|
|
|
|
nscoord heightshrink = 0;
|
|
|
|
|
|
|
|
if (startRadius || endRadius) {
|
|
|
|
if (aWhichSide == NS_SIDE_TOP || aWhichSide == NS_SIDE_BOTTOM) {
|
|
|
|
xshrink = startRadius;
|
|
|
|
widthshrink = startRadius + endRadius;
|
|
|
|
}
|
|
|
|
else if (aWhichSide == NS_SIDE_LEFT || aWhichSide == NS_SIDE_RIGHT) {
|
|
|
|
yshrink = startRadius-1;
|
|
|
|
heightshrink = yshrink + endRadius;
|
|
|
|
}
|
1999-03-28 08:30:28 +04:00
|
|
|
}
|
2001-12-05 11:35:05 +03:00
|
|
|
|
2001-12-11 14:13:16 +03:00
|
|
|
// subtract any rounded pixels from the outer rect
|
2001-12-05 11:35:05 +03:00
|
|
|
nsRect newOuterRect(currOuterRect);
|
|
|
|
newOuterRect.x += xshrink;
|
|
|
|
newOuterRect.y += yshrink;
|
|
|
|
newOuterRect.width -= widthshrink;
|
|
|
|
newOuterRect.height -= heightshrink;
|
|
|
|
|
2001-12-11 14:13:16 +03:00
|
|
|
nsRect borderInside(currOuterRect);
|
|
|
|
|
|
|
|
// try to subtract one pixel from each side of the outer rect, but only if
|
|
|
|
// that side has any extra space left to shrink
|
|
|
|
if (aInnerRect.x > borderInside.x) { // shrink left
|
|
|
|
borderInside.x += twipsPerPixel;
|
|
|
|
borderInside.width -= twipsPerPixel;
|
1999-03-28 08:30:28 +04:00
|
|
|
}
|
2001-12-11 14:13:16 +03:00
|
|
|
if (borderInside.x+borderInside.width > aInnerRect.x+aInnerRect.width) // shrink right
|
|
|
|
borderInside.width -= twipsPerPixel;
|
2001-12-05 11:35:05 +03:00
|
|
|
|
2001-12-11 14:13:16 +03:00
|
|
|
if (aInnerRect.y > borderInside.y) { // shrink top
|
|
|
|
borderInside.y += twipsPerPixel;
|
|
|
|
borderInside.height -= twipsPerPixel;
|
2001-12-05 11:35:05 +03:00
|
|
|
}
|
2001-12-11 14:13:16 +03:00
|
|
|
if (borderInside.y+borderInside.height > aInnerRect.y+aInnerRect.height) // shrink bottom
|
|
|
|
borderInside.height -= twipsPerPixel;
|
|
|
|
|
|
|
|
if (!aCompositeColors->mTransparent) {
|
|
|
|
nsPoint theSide[MAX_POLY_POINTS];
|
|
|
|
PRInt32 np = MakeSide(theSide, aRenderingContext, aWhichSide, newOuterRect, borderInside, 0,
|
|
|
|
BORDER_FULL, 1.0f, twipsPerPixel);
|
|
|
|
NS_ASSERTION(np == 2, "Composite border should always be single pixel!");
|
|
|
|
aRenderingContext.SetColor(aCompositeColors->mColor);
|
|
|
|
DrawLine(aRenderingContext, theSide[0].x, theSide[0].y, theSide[1].x, theSide[1].y, aGap);
|
|
|
|
|
|
|
|
if (aWhichSide == NS_SIDE_TOP) {
|
|
|
|
if (startRadius) {
|
|
|
|
// Connecting line between top/left
|
|
|
|
nscoord distance = (startRadius+twipsPerPixel)/2;
|
|
|
|
nscoord remainder = distance%twipsPerPixel;
|
|
|
|
if (remainder)
|
|
|
|
distance += twipsPerPixel - remainder;
|
|
|
|
DrawLine(aRenderingContext,
|
|
|
|
currOuterRect.x+startRadius,
|
|
|
|
currOuterRect.y,
|
|
|
|
currOuterRect.x+startRadius-distance,
|
|
|
|
currOuterRect.y+distance,
|
|
|
|
aGap);
|
|
|
|
}
|
|
|
|
if (endRadius) {
|
|
|
|
// Connecting line between top/right
|
|
|
|
nscoord distance = (endRadius+twipsPerPixel)/2;
|
|
|
|
nscoord remainder = distance%twipsPerPixel;
|
|
|
|
if (remainder)
|
|
|
|
distance += twipsPerPixel - remainder;
|
|
|
|
DrawLine(aRenderingContext,
|
|
|
|
currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel,
|
|
|
|
currOuterRect.y,
|
|
|
|
currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel+distance,
|
|
|
|
currOuterRect.y+distance,
|
|
|
|
aGap);
|
|
|
|
}
|
2001-12-05 11:35:05 +03:00
|
|
|
}
|
2001-12-11 14:13:16 +03:00
|
|
|
else if (aWhichSide == NS_SIDE_BOTTOM) {
|
|
|
|
if (startRadius) {
|
|
|
|
// Connecting line between bottom/left
|
|
|
|
nscoord distance = (startRadius+twipsPerPixel)/2;
|
|
|
|
nscoord remainder = distance%twipsPerPixel;
|
|
|
|
if (remainder)
|
|
|
|
distance += twipsPerPixel - remainder;
|
|
|
|
DrawLine(aRenderingContext,
|
|
|
|
currOuterRect.x+startRadius,
|
|
|
|
currOuterRect.y+currOuterRect.height-twipsPerPixel,
|
|
|
|
currOuterRect.x+startRadius-distance,
|
|
|
|
currOuterRect.y+currOuterRect.height-twipsPerPixel-distance,
|
|
|
|
aGap);
|
|
|
|
}
|
|
|
|
if (endRadius) {
|
|
|
|
// Connecting line between bottom/right
|
|
|
|
nscoord distance = (endRadius+twipsPerPixel)/2;
|
|
|
|
nscoord remainder = distance%twipsPerPixel;
|
|
|
|
if (remainder)
|
|
|
|
distance += twipsPerPixel - remainder;
|
|
|
|
DrawLine(aRenderingContext,
|
|
|
|
currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel,
|
|
|
|
currOuterRect.y+currOuterRect.height-twipsPerPixel,
|
|
|
|
currOuterRect.x+currOuterRect.width-endRadius-twipsPerPixel+distance,
|
|
|
|
currOuterRect.y+currOuterRect.height-twipsPerPixel-distance,
|
|
|
|
aGap);
|
|
|
|
}
|
2001-12-05 11:35:05 +03:00
|
|
|
}
|
2001-12-11 14:13:16 +03:00
|
|
|
else if (aWhichSide == NS_SIDE_LEFT) {
|
|
|
|
if (startRadius) {
|
|
|
|
// Connecting line between left/top
|
|
|
|
nscoord distance = (startRadius-twipsPerPixel)/2;
|
|
|
|
nscoord remainder = distance%twipsPerPixel;
|
|
|
|
if (remainder)
|
|
|
|
distance -= remainder;
|
|
|
|
DrawLine(aRenderingContext,
|
|
|
|
currOuterRect.x+distance,
|
|
|
|
currOuterRect.y+startRadius-distance,
|
|
|
|
currOuterRect.x,
|
|
|
|
currOuterRect.y+startRadius,
|
|
|
|
aGap);
|
|
|
|
}
|
|
|
|
if (endRadius) {
|
|
|
|
// Connecting line between left/bottom
|
|
|
|
nscoord distance = (endRadius-twipsPerPixel)/2;
|
|
|
|
nscoord remainder = distance%twipsPerPixel;
|
|
|
|
if (remainder)
|
|
|
|
distance -= remainder;
|
|
|
|
DrawLine(aRenderingContext,
|
|
|
|
currOuterRect.x+distance,
|
|
|
|
currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius+distance,
|
|
|
|
currOuterRect.x,
|
|
|
|
currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius,
|
|
|
|
aGap);
|
|
|
|
}
|
2001-12-05 11:35:05 +03:00
|
|
|
}
|
2001-12-11 14:13:16 +03:00
|
|
|
else if (aWhichSide == NS_SIDE_RIGHT) {
|
|
|
|
if (startRadius) {
|
|
|
|
// Connecting line between right/top
|
|
|
|
nscoord distance = (startRadius-twipsPerPixel)/2;
|
|
|
|
nscoord remainder = distance%twipsPerPixel;
|
|
|
|
if (remainder)
|
|
|
|
distance -= remainder;
|
|
|
|
DrawLine(aRenderingContext,
|
|
|
|
currOuterRect.x+currOuterRect.width-twipsPerPixel-distance,
|
|
|
|
currOuterRect.y+startRadius-distance,
|
|
|
|
currOuterRect.x+currOuterRect.width-twipsPerPixel,
|
|
|
|
currOuterRect.y+startRadius,
|
|
|
|
aGap);
|
|
|
|
}
|
|
|
|
if (endRadius) {
|
|
|
|
// Connecting line between right/bottom
|
|
|
|
nscoord distance = (endRadius-twipsPerPixel)/2;
|
|
|
|
nscoord remainder = distance%twipsPerPixel;
|
|
|
|
if (remainder)
|
|
|
|
distance -= remainder;
|
|
|
|
DrawLine(aRenderingContext,
|
|
|
|
currOuterRect.x+currOuterRect.width-twipsPerPixel-distance,
|
|
|
|
currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius+distance,
|
|
|
|
currOuterRect.x+currOuterRect.width-twipsPerPixel,
|
|
|
|
currOuterRect.y+currOuterRect.height-twipsPerPixel-endRadius,
|
|
|
|
aGap);
|
|
|
|
}
|
2001-12-05 11:35:05 +03:00
|
|
|
}
|
1999-03-28 08:30:28 +04:00
|
|
|
}
|
2001-12-11 14:13:16 +03:00
|
|
|
|
2001-12-05 11:35:05 +03:00
|
|
|
if (aCompositeColors->mNext)
|
|
|
|
aCompositeColors = aCompositeColors->mNext;
|
2001-12-11 14:13:16 +03:00
|
|
|
|
|
|
|
currOuterRect = borderInside;
|
|
|
|
shrinkage -= twipsPerPixel;
|
|
|
|
|
|
|
|
startRadius -= twipsPerPixel;
|
|
|
|
if (startRadius < 0) startRadius = 0;
|
|
|
|
endRadius -= twipsPerPixel;
|
|
|
|
if (endRadius < 0) endRadius = 0;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-19 18:22:47 +04:00
|
|
|
// XXX improve this to constrain rendering to the damaged area
|
1999-11-24 09:03:41 +03:00
|
|
|
void nsCSSRendering::PaintOutline(nsIPresContext* 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
|
|
|
PRIntn aSkipSides,
|
|
|
|
nsRect* aGap)
|
|
|
|
{
|
2000-02-01 19:03:13 +03:00
|
|
|
nsStyleCoord bordStyleRadius[4];
|
|
|
|
PRInt16 borderRadii[4],i;
|
|
|
|
float percent;
|
2002-08-11 21:56:15 +04:00
|
|
|
const nsStyleBackground* bgColor = nsCSSRendering::FindNonTransparentBackground(aStyleContext);
|
2000-02-01 19:03:13 +03:00
|
|
|
nscoord width;
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
// Get our style context's color struct.
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleColor* ourColor = aStyleContext->GetStyleColor();
|
1999-08-19 18:22:47 +04:00
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
aOutlineStyle.GetOutlineWidth(width);
|
1999-08-19 18:22:47 +04:00
|
|
|
|
|
|
|
if (0 == width) {
|
|
|
|
// Empty outline
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-02-01 19:03:13 +03:00
|
|
|
// get the radius for our border
|
2001-02-07 12:57:26 +03:00
|
|
|
aOutlineStyle.mOutlineRadius.GetTop(bordStyleRadius[0]); //topleft
|
|
|
|
aOutlineStyle.mOutlineRadius.GetRight(bordStyleRadius[1]); //topright
|
|
|
|
aOutlineStyle.mOutlineRadius.GetBottom(bordStyleRadius[2]); //bottomright
|
|
|
|
aOutlineStyle.mOutlineRadius.GetLeft(bordStyleRadius[3]); //bottomleft
|
2000-02-01 19:03:13 +03:00
|
|
|
|
|
|
|
for(i=0;i<4;i++) {
|
|
|
|
borderRadii[i] = 0;
|
|
|
|
switch ( bordStyleRadius[i].GetUnit()) {
|
|
|
|
case eStyleUnit_Inherit:
|
|
|
|
break;
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
percent = bordStyleRadius[i].GetPercentValue();
|
|
|
|
borderRadii[i] = (nscoord)(percent * aBorderArea.width);
|
|
|
|
break;
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
borderRadii[i] = bordStyleRadius[i].GetCoordValue();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-18 17:41:00 +03:00
|
|
|
// This if control whether the outline paints on the inside
|
|
|
|
// or outside of the frame
|
2000-08-24 17:45:48 +04:00
|
|
|
// XXX This is temporary fix for nsbeta3+ Bug 48973
|
|
|
|
// so we can use "mozoutline
|
|
|
|
#if 0 // outside
|
1999-08-19 18:22:47 +04:00
|
|
|
nsRect inside(aBorderArea);
|
|
|
|
nsRect outside(inside);
|
|
|
|
inside.Inflate(width, width);
|
|
|
|
|
|
|
|
nsRect clipRect(aBorderArea);
|
|
|
|
clipRect.Inflate(width, width); // make clip extra big for now
|
|
|
|
|
2000-03-18 17:41:00 +03:00
|
|
|
#else // inside
|
2000-08-24 17:45:48 +04:00
|
|
|
nsMargin borderWidth;
|
|
|
|
aBorderStyle.GetBorder(borderWidth);
|
2000-03-18 17:41:00 +03:00
|
|
|
|
|
|
|
nsRect outside(aBorderArea);
|
2000-08-24 17:45:48 +04:00
|
|
|
outside.Deflate(borderWidth);
|
2000-03-18 17:41:00 +03:00
|
|
|
nsRect inside(outside);
|
|
|
|
inside.Deflate(width, width);
|
|
|
|
|
|
|
|
nsRect clipRect(outside);
|
|
|
|
#endif
|
|
|
|
|
1999-08-19 18:22:47 +04:00
|
|
|
PRBool clipState = PR_FALSE;
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(clipRect, nsClipCombine_kReplace, clipState);
|
|
|
|
|
2000-02-01 19:03:13 +03:00
|
|
|
// rounded version of the border
|
|
|
|
for(i=0;i<4;i++){
|
|
|
|
if(borderRadii[i] > 0){
|
2001-02-07 12:57:26 +03:00
|
|
|
PaintRoundedBorder(aPresContext,aRenderingContext,aForFrame,aDirtyRect,aBorderArea,nsnull,&aOutlineStyle,aStyleContext,aSkipSides,borderRadii,aGap,PR_TRUE);
|
2000-03-18 17:41:00 +03:00
|
|
|
aRenderingContext.PopState(clipState);
|
2000-02-01 19:03:13 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
PRUint8 outlineStyle = aOutlineStyle.GetOutlineStyle();
|
1999-08-19 18:22:47 +04:00
|
|
|
//see if any sides are dotted or dashed
|
|
|
|
if ((outlineStyle == NS_STYLE_BORDER_STYLE_DOTTED) ||
|
|
|
|
(outlineStyle == NS_STYLE_BORDER_STYLE_DASHED)) {
|
2001-06-01 02:19:43 +04:00
|
|
|
DrawDashedSides(0, aRenderingContext, aDirtyRect, ourColor, nsnull, &aOutlineStyle, PR_TRUE,
|
2000-03-18 17:41:00 +03:00
|
|
|
outside, inside, aSkipSides, aGap);
|
1999-08-19 18:22:47 +04:00
|
|
|
aRenderingContext.PopState(clipState);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw all the other sides
|
|
|
|
|
|
|
|
/* XXX something is misnamed here!!!! */
|
|
|
|
nscoord twipsPerPixel;/* XXX */
|
|
|
|
float p2t;/* XXX */
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetPixelsToTwips(&p2t);/* XXX */
|
1999-08-19 18:22:47 +04:00
|
|
|
twipsPerPixel = (nscoord) p2t;/* XXX */
|
|
|
|
|
2001-10-03 04:08:25 +04:00
|
|
|
nscolor outlineColor(NS_RGB(0,0,0)); // default to black in case it is invert color and the platform does not support that
|
|
|
|
PRBool canDraw = PR_FALSE;
|
|
|
|
PRBool modeChanged=PR_FALSE;
|
2001-08-22 02:37:17 +04:00
|
|
|
|
|
|
|
// see if the outline color is 'invert' or can invert.
|
2001-10-03 04:08:25 +04:00
|
|
|
if (aOutlineStyle.GetOutlineInvert()) {
|
2001-08-22 02:37:17 +04:00
|
|
|
canDraw = PR_TRUE;
|
2001-10-03 04:08:25 +04:00
|
|
|
if( NS_SUCCEEDED(aRenderingContext.SetPenMode(nsPenMode_kInvert)) ) {
|
|
|
|
modeChanged=PR_TRUE;
|
|
|
|
}
|
2001-08-22 02:37:17 +04:00
|
|
|
} else {
|
|
|
|
canDraw = aOutlineStyle.GetOutlineColor(outlineColor);
|
|
|
|
}
|
1999-08-19 18:22:47 +04:00
|
|
|
|
2001-08-22 02:37:17 +04:00
|
|
|
if (PR_TRUE == canDraw) {
|
1999-08-19 18:22:47 +04:00
|
|
|
DrawSide(aRenderingContext, NS_SIDE_BOTTOM,
|
|
|
|
outlineStyle,
|
|
|
|
outlineColor,
|
2000-03-18 17:41:00 +03:00
|
|
|
bgColor->mBackgroundColor, outside, inside, aSkipSides,
|
1999-08-19 18:22:47 +04:00
|
|
|
twipsPerPixel, aGap);
|
|
|
|
|
|
|
|
DrawSide(aRenderingContext, NS_SIDE_LEFT,
|
|
|
|
outlineStyle,
|
|
|
|
outlineColor,
|
2000-03-18 17:41:00 +03:00
|
|
|
bgColor->mBackgroundColor,outside, inside,aSkipSides,
|
1999-08-19 18:22:47 +04:00
|
|
|
twipsPerPixel, aGap);
|
|
|
|
|
|
|
|
DrawSide(aRenderingContext, NS_SIDE_TOP,
|
|
|
|
outlineStyle,
|
|
|
|
outlineColor,
|
2000-03-30 10:27:32 +04:00
|
|
|
bgColor->mBackgroundColor,outside, inside,aSkipSides,
|
|
|
|
twipsPerPixel, aGap);
|
1999-08-19 18:22:47 +04:00
|
|
|
|
|
|
|
DrawSide(aRenderingContext, NS_SIDE_RIGHT,
|
|
|
|
outlineStyle,
|
|
|
|
outlineColor,
|
2000-03-30 10:27:32 +04:00
|
|
|
bgColor->mBackgroundColor,outside, inside,aSkipSides,
|
|
|
|
twipsPerPixel, aGap);
|
2001-10-03 04:08:25 +04:00
|
|
|
|
|
|
|
if(modeChanged ) {
|
2001-08-22 02:37:17 +04:00
|
|
|
aRenderingContext.SetPenMode(nsPenMode_kNone);
|
|
|
|
}
|
1999-08-19 18:22:47 +04:00
|
|
|
}
|
|
|
|
// Restore clipping
|
|
|
|
aRenderingContext.PopState(clipState);
|
|
|
|
}
|
|
|
|
|
1999-01-03 22:23:21 +03:00
|
|
|
/* draw the edges of the border described in aBorderEdges one segment at a time.
|
|
|
|
* a border has 4 edges. Each edge has 1 or more segments.
|
|
|
|
* "inside edges" are drawn differently than "outside edges" so the shared edges will match up.
|
|
|
|
* in the case of table collapsing borders, the table edge is the "outside" edge and
|
|
|
|
* cell edges are always "inside" edges (so adjacent cells have 2 shared "inside" edges.)
|
|
|
|
* dashed segments are drawn by DrawDashedSegments().
|
|
|
|
*/
|
|
|
|
// XXX: doesn't do corners or junctions well at all. Just uses logic stolen
|
|
|
|
// from PaintBorder which is insufficient
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
void nsCSSRendering::PaintBorderEdges(nsIPresContext* aPresContext,
|
1998-12-18 01:58:51 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
1999-01-15 21:25:58 +03:00
|
|
|
const nsRect& aBorderArea,
|
1998-12-18 01:58:51 +03:00
|
|
|
nsBorderEdges * aBorderEdges,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* aStyleContext,
|
1998-12-18 01:58:51 +03:00
|
|
|
PRIntn aSkipSides,
|
|
|
|
nsRect* aGap)
|
|
|
|
{
|
2002-08-11 21:56:15 +04:00
|
|
|
const nsStyleBackground* bgColor = nsCSSRendering::FindNonTransparentBackground(aStyleContext);
|
1999-01-23 01:24:05 +03:00
|
|
|
|
1998-12-18 01:58:51 +03:00
|
|
|
if (nsnull==aBorderEdges) { // Empty border segments
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Turn off rendering for all of the zero sized sides
|
|
|
|
if (0 == aBorderEdges->mMaxBorderWidth.top)
|
|
|
|
aSkipSides |= (1 << NS_SIDE_TOP);
|
|
|
|
if (0 == aBorderEdges->mMaxBorderWidth.right)
|
|
|
|
aSkipSides |= (1 << NS_SIDE_RIGHT);
|
|
|
|
if (0 == aBorderEdges->mMaxBorderWidth.bottom)
|
|
|
|
aSkipSides |= (1 << NS_SIDE_BOTTOM);
|
|
|
|
if (0 == aBorderEdges->mMaxBorderWidth.left)
|
|
|
|
aSkipSides |= (1 << NS_SIDE_LEFT);
|
|
|
|
|
1998-12-30 09:47:26 +03:00
|
|
|
// Draw any dashed or dotted segments separately
|
1999-01-15 21:25:58 +03:00
|
|
|
DrawDashedSegments(aRenderingContext, aBorderArea, aBorderEdges, aSkipSides, aGap);
|
1998-12-18 01:58:51 +03:00
|
|
|
|
|
|
|
// Draw all the other sides
|
1999-02-12 20:45:58 +03:00
|
|
|
nscoord twipsPerPixel;
|
|
|
|
float p2t;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetPixelsToTwips(&p2t);
|
1999-02-12 20:45:58 +03:00
|
|
|
twipsPerPixel = (nscoord) p2t;/* XXX huh!*/
|
|
|
|
|
1998-12-18 01:58:51 +03:00
|
|
|
if (0 == (aSkipSides & (1<<NS_SIDE_TOP))) {
|
|
|
|
PRInt32 segmentCount = aBorderEdges->mEdges[NS_SIDE_TOP].Count();
|
|
|
|
PRInt32 i;
|
1998-12-23 18:48:50 +03:00
|
|
|
nsBorderEdge * leftEdge = (nsBorderEdge *)(aBorderEdges->mEdges[NS_SIDE_LEFT].ElementAt(0));
|
|
|
|
nscoord x = aBorderEdges->mMaxBorderWidth.left - leftEdge->mWidth;
|
1998-12-18 01:58:51 +03:00
|
|
|
for (i=0; i<segmentCount; i++)
|
|
|
|
{
|
|
|
|
nsBorderEdge * borderEdge = (nsBorderEdge *)(aBorderEdges->mEdges[NS_SIDE_TOP].ElementAt(i));
|
1999-01-15 21:25:58 +03:00
|
|
|
nscoord y = aBorderArea.y;
|
1998-12-30 09:47:26 +03:00
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge) // segments of the outside edge are bottom-aligned
|
|
|
|
y += aBorderEdges->mMaxBorderWidth.top - borderEdge->mWidth;
|
1999-01-15 21:25:58 +03:00
|
|
|
nsRect inside(x, y, borderEdge->mLength, aBorderArea.height);
|
1998-12-21 09:37:10 +03:00
|
|
|
x += borderEdge->mLength;
|
|
|
|
nsRect outside(inside);
|
1998-12-23 18:48:50 +03:00
|
|
|
nsMargin outsideMargin(0, borderEdge->mWidth, 0, 0);
|
|
|
|
outside.Deflate(outsideMargin);
|
1998-12-18 01:58:51 +03:00
|
|
|
DrawSide(aRenderingContext, NS_SIDE_TOP,
|
|
|
|
borderEdge->mStyle,
|
|
|
|
borderEdge->mColor,
|
1999-03-05 22:23:52 +03:00
|
|
|
bgColor->mBackgroundColor,
|
1999-07-28 03:26:36 +04:00
|
|
|
inside, outside,aSkipSides,
|
1999-03-05 22:23:52 +03:00
|
|
|
twipsPerPixel, aGap);
|
1998-12-18 01:58:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (0 == (aSkipSides & (1<<NS_SIDE_LEFT))) {
|
|
|
|
PRInt32 segmentCount = aBorderEdges->mEdges[NS_SIDE_LEFT].Count();
|
|
|
|
PRInt32 i;
|
1998-12-23 18:48:50 +03:00
|
|
|
nsBorderEdge * topEdge = (nsBorderEdge *)(aBorderEdges->mEdges[NS_SIDE_TOP].ElementAt(0));
|
|
|
|
nscoord y = aBorderEdges->mMaxBorderWidth.top - topEdge->mWidth;
|
1998-12-18 01:58:51 +03:00
|
|
|
for (i=0; i<segmentCount; i++)
|
|
|
|
{
|
|
|
|
nsBorderEdge * borderEdge = (nsBorderEdge *)(aBorderEdges->mEdges[NS_SIDE_LEFT].ElementAt(i));
|
1999-01-15 21:25:58 +03:00
|
|
|
nscoord x = aBorderArea.x + (aBorderEdges->mMaxBorderWidth.left - borderEdge->mWidth);
|
|
|
|
nsRect inside(x, y, aBorderArea.width, borderEdge->mLength);
|
1998-12-21 09:37:10 +03:00
|
|
|
y += borderEdge->mLength;
|
|
|
|
nsRect outside(inside);
|
1998-12-23 18:48:50 +03:00
|
|
|
nsMargin outsideMargin(borderEdge->mWidth, 0, 0, 0);
|
|
|
|
outside.Deflate(outsideMargin);
|
1998-12-18 01:58:51 +03:00
|
|
|
DrawSide(aRenderingContext, NS_SIDE_LEFT,
|
|
|
|
borderEdge->mStyle,
|
|
|
|
borderEdge->mColor,
|
1999-03-05 22:23:52 +03:00
|
|
|
bgColor->mBackgroundColor,
|
1999-07-28 03:26:36 +04:00
|
|
|
inside, outside, aSkipSides,
|
1999-03-05 22:23:52 +03:00
|
|
|
twipsPerPixel, aGap);
|
1998-12-18 01:58:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (0 == (aSkipSides & (1<<NS_SIDE_BOTTOM))) {
|
|
|
|
PRInt32 segmentCount = aBorderEdges->mEdges[NS_SIDE_BOTTOM].Count();
|
|
|
|
PRInt32 i;
|
1998-12-23 18:48:50 +03:00
|
|
|
nsBorderEdge * leftEdge = (nsBorderEdge *)
|
|
|
|
(aBorderEdges->mEdges[NS_SIDE_LEFT].ElementAt(aBorderEdges->mEdges[NS_SIDE_LEFT].Count()-1));
|
|
|
|
nscoord x = aBorderEdges->mMaxBorderWidth.left - leftEdge->mWidth;
|
1998-12-18 01:58:51 +03:00
|
|
|
for (i=0; i<segmentCount; i++)
|
|
|
|
{
|
|
|
|
nsBorderEdge * borderEdge = (nsBorderEdge *)(aBorderEdges->mEdges[NS_SIDE_BOTTOM].ElementAt(i));
|
1999-01-15 21:25:58 +03:00
|
|
|
nscoord y = aBorderArea.y;
|
1998-12-30 09:47:26 +03:00
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge) // segments of the outside edge are top-aligned
|
|
|
|
y -= (aBorderEdges->mMaxBorderWidth.bottom - borderEdge->mWidth);
|
1999-01-15 21:25:58 +03:00
|
|
|
nsRect inside(x, y, borderEdge->mLength, aBorderArea.height);
|
1998-12-21 09:37:10 +03:00
|
|
|
x += borderEdge->mLength;
|
|
|
|
nsRect outside(inside);
|
1998-12-23 18:48:50 +03:00
|
|
|
nsMargin outsideMargin(0, 0, 0, borderEdge->mWidth);
|
|
|
|
outside.Deflate(outsideMargin);
|
1998-12-21 09:37:10 +03:00
|
|
|
DrawSide(aRenderingContext, NS_SIDE_BOTTOM,
|
1998-12-18 01:58:51 +03:00
|
|
|
borderEdge->mStyle,
|
|
|
|
borderEdge->mColor,
|
1999-03-05 22:23:52 +03:00
|
|
|
bgColor->mBackgroundColor,
|
1999-07-28 03:26:36 +04:00
|
|
|
inside, outside,aSkipSides,
|
1999-03-05 22:23:52 +03:00
|
|
|
twipsPerPixel, aGap);
|
1998-12-18 01:58:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (0 == (aSkipSides & (1<<NS_SIDE_RIGHT))) {
|
|
|
|
PRInt32 segmentCount = aBorderEdges->mEdges[NS_SIDE_RIGHT].Count();
|
|
|
|
PRInt32 i;
|
1998-12-23 18:48:50 +03:00
|
|
|
nsBorderEdge * topEdge = (nsBorderEdge *)
|
|
|
|
(aBorderEdges->mEdges[NS_SIDE_TOP].ElementAt(aBorderEdges->mEdges[NS_SIDE_TOP].Count()-1));
|
|
|
|
nscoord y = aBorderEdges->mMaxBorderWidth.top - topEdge->mWidth;
|
1998-12-18 01:58:51 +03:00
|
|
|
for (i=0; i<segmentCount; i++)
|
|
|
|
{
|
|
|
|
nsBorderEdge * borderEdge = (nsBorderEdge *)(aBorderEdges->mEdges[NS_SIDE_RIGHT].ElementAt(i));
|
1998-12-30 09:47:26 +03:00
|
|
|
nscoord width;
|
1998-12-23 18:48:50 +03:00
|
|
|
if (PR_TRUE==aBorderEdges->mOutsideEdge)
|
1998-12-30 09:47:26 +03:00
|
|
|
{
|
1999-01-15 21:25:58 +03:00
|
|
|
width = aBorderArea.width - aBorderEdges->mMaxBorderWidth.right;
|
1998-12-30 09:47:26 +03:00
|
|
|
width += borderEdge->mWidth;
|
|
|
|
}
|
2000-03-30 10:27:32 +04:00
|
|
|
else
|
1998-12-30 09:47:26 +03:00
|
|
|
{
|
1999-01-15 21:25:58 +03:00
|
|
|
width = aBorderArea.width;
|
1998-12-30 09:47:26 +03:00
|
|
|
}
|
1999-01-15 21:25:58 +03:00
|
|
|
nsRect inside(aBorderArea.x, y, width, borderEdge->mLength);
|
1998-12-21 09:37:10 +03:00
|
|
|
y += borderEdge->mLength;
|
|
|
|
nsRect outside(inside);
|
1998-12-30 09:47:26 +03:00
|
|
|
nsMargin outsideMargin(0, 0, (borderEdge->mWidth), 0);
|
1998-12-23 18:48:50 +03:00
|
|
|
outside.Deflate(outsideMargin);
|
1998-12-21 09:37:10 +03:00
|
|
|
DrawSide(aRenderingContext, NS_SIDE_RIGHT,
|
1998-12-18 01:58:51 +03:00
|
|
|
borderEdge->mStyle,
|
|
|
|
borderEdge->mColor,
|
1999-03-05 22:23:52 +03:00
|
|
|
bgColor->mBackgroundColor,
|
1999-07-28 03:26:36 +04:00
|
|
|
inside, outside,aSkipSides,
|
1999-03-05 22:23:52 +03:00
|
|
|
twipsPerPixel, aGap);
|
1998-12-18 01:58:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-04-25 06:43:50 +04:00
|
|
|
// Returns the anchor point to use for the background image. The
|
|
|
|
// anchor point is the (x, y) location where the first tile should
|
|
|
|
// be placed
|
|
|
|
//
|
1999-04-29 22:29:56 +04:00
|
|
|
// For repeated tiling, the anchor values are normalized wrt to the upper-left
|
|
|
|
// edge of the bounds, and are always in the range:
|
1999-04-25 06:43:50 +04:00
|
|
|
// -(aTileWidth - 1) <= anchor.x <= 0
|
|
|
|
// -(aTileHeight - 1) <= anchor.y <= 0
|
|
|
|
//
|
1999-04-25 08:14:06 +04:00
|
|
|
// i.e., they are either 0 or a negative number whose absolute value is
|
|
|
|
// less than the tile size in that dimension
|
2001-08-18 03:26:29 +04:00
|
|
|
//
|
2002-10-08 14:24:53 +04:00
|
|
|
// aOriginBounds is the box to which the tiling position should be relative
|
|
|
|
// aClipBounds is the box in which the tiling will actually be done
|
|
|
|
// They should correspond to 'background-origin' and 'background-clip',
|
|
|
|
// except when painting on the canvas, in which case the origin bounds
|
|
|
|
// should be the bounds of the root element's frame and the clip bounds
|
|
|
|
// should be the bounds of the canvas frame.
|
1998-12-12 06:06:02 +03:00
|
|
|
static void
|
2001-06-01 02:19:43 +04:00
|
|
|
ComputeBackgroundAnchorPoint(const nsStyleBackground& aColor,
|
2002-10-08 14:24:53 +04:00
|
|
|
const nsRect& aOriginBounds,
|
|
|
|
const nsRect& aClipBounds,
|
1998-10-27 19:50:19 +03:00
|
|
|
nscoord aTileWidth, nscoord aTileHeight,
|
|
|
|
nsPoint& aResult)
|
1998-09-26 21:16:56 +04:00
|
|
|
{
|
1998-10-27 19:50:19 +03:00
|
|
|
nscoord x;
|
|
|
|
if (NS_STYLE_BG_X_POSITION_LENGTH & aColor.mBackgroundFlags) {
|
2003-01-19 05:36:04 +03:00
|
|
|
x = aColor.mBackgroundXPosition.mCoord;
|
1998-10-27 19:50:19 +03:00
|
|
|
}
|
2003-01-19 05:36:04 +03:00
|
|
|
else if (NS_STYLE_BG_X_POSITION_PERCENT & aColor.mBackgroundFlags) {
|
|
|
|
PRFloat64 percent = PRFloat64(aColor.mBackgroundXPosition.mFloat);
|
|
|
|
nscoord tilePos = nscoord(percent * PRFloat64(aTileWidth));
|
|
|
|
nscoord boxPos = nscoord(percent * PRFloat64(aOriginBounds.width));
|
1998-10-27 19:50:19 +03:00
|
|
|
x = boxPos - tilePos;
|
|
|
|
}
|
2003-01-19 05:36:04 +03:00
|
|
|
else {
|
|
|
|
x = 0;
|
|
|
|
}
|
2002-10-08 14:24:53 +04:00
|
|
|
x += aOriginBounds.x - aClipBounds.x;
|
1998-10-27 19:50:19 +03:00
|
|
|
if (NS_STYLE_BG_REPEAT_X & aColor.mBackgroundRepeat) {
|
|
|
|
// When we are tiling in the x direction the loop will run from
|
|
|
|
// the left edge of the box to the right edge of the box. We need
|
|
|
|
// to adjust the starting coordinate to lie within the band being
|
|
|
|
// rendered.
|
|
|
|
if (x < 0) {
|
|
|
|
x = -x;
|
|
|
|
if (x < 0) {
|
1998-09-26 21:16:56 +04:00
|
|
|
// Some joker gave us max-negative-integer.
|
1998-10-27 19:50:19 +03:00
|
|
|
x = 0;
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1998-10-27 19:50:19 +03:00
|
|
|
x %= aTileWidth;
|
|
|
|
x = -x;
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1999-04-25 06:43:50 +04:00
|
|
|
else if (x != 0) {
|
1998-10-27 19:50:19 +03:00
|
|
|
x %= aTileWidth;
|
1999-07-27 18:13:09 +04:00
|
|
|
if (x > 0) {
|
|
|
|
x = x - aTileWidth;
|
|
|
|
}
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1999-04-29 22:29:56 +04:00
|
|
|
|
|
|
|
NS_POSTCONDITION((x >= -(aTileWidth - 1)) && (x <= 0), "bad computed anchor value");
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1998-10-27 19:50:19 +03:00
|
|
|
aResult.x = x;
|
1998-09-26 21:16:56 +04:00
|
|
|
|
1998-10-27 19:50:19 +03:00
|
|
|
nscoord y;
|
|
|
|
if (NS_STYLE_BG_Y_POSITION_LENGTH & aColor.mBackgroundFlags) {
|
2003-01-19 05:36:04 +03:00
|
|
|
y = aColor.mBackgroundYPosition.mCoord;
|
1998-10-27 19:50:19 +03:00
|
|
|
}
|
2003-01-19 05:36:04 +03:00
|
|
|
else if (NS_STYLE_BG_Y_POSITION_PERCENT & aColor.mBackgroundFlags){
|
|
|
|
PRFloat64 percent = PRFloat64(aColor.mBackgroundYPosition.mFloat);
|
|
|
|
nscoord tilePos = nscoord(percent * PRFloat64(aTileHeight));
|
|
|
|
nscoord boxPos = nscoord(percent * PRFloat64(aOriginBounds.height));
|
1998-10-27 19:50:19 +03:00
|
|
|
y = boxPos - tilePos;
|
|
|
|
}
|
2003-01-19 05:36:04 +03:00
|
|
|
else {
|
|
|
|
y = 0;
|
|
|
|
}
|
2002-10-08 14:24:53 +04:00
|
|
|
y += aOriginBounds.y - aClipBounds.y;
|
1998-10-27 19:50:19 +03:00
|
|
|
if (NS_STYLE_BG_REPEAT_Y & aColor.mBackgroundRepeat) {
|
|
|
|
// When we are tiling in the y direction the loop will run from
|
|
|
|
// the top edge of the box to the bottom edge of the box. We need
|
|
|
|
// to adjust the starting coordinate to lie within the band being
|
|
|
|
// rendered.
|
|
|
|
if (y < 0) {
|
|
|
|
y = -y;
|
|
|
|
if (y < 0) {
|
1998-09-26 21:16:56 +04:00
|
|
|
// Some joker gave us max-negative-integer.
|
1998-10-27 19:50:19 +03:00
|
|
|
y = 0;
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1998-10-27 19:50:19 +03:00
|
|
|
y %= aTileHeight;
|
|
|
|
y = -y;
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1999-04-25 06:43:50 +04:00
|
|
|
else if (y != 0) {
|
1998-10-27 19:50:19 +03:00
|
|
|
y %= aTileHeight;
|
1999-07-27 18:13:09 +04:00
|
|
|
if (y > 0) {
|
|
|
|
y = y - aTileHeight;
|
|
|
|
}
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1999-04-29 22:29:56 +04:00
|
|
|
|
|
|
|
NS_POSTCONDITION((y >= -(aTileHeight - 1)) && (y <= 0), "bad computed anchor value");
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1998-10-27 19:50:19 +03:00
|
|
|
aResult.y = y;
|
1999-04-25 06:43:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the nearest scroll frame ancestor
|
|
|
|
static nsIFrame*
|
|
|
|
GetNearestScrollFrame(nsIFrame* aFrame)
|
|
|
|
{
|
2003-07-05 19:04:34 +04:00
|
|
|
for (nsIFrame* f = aFrame; f; f = f->GetParent()) {
|
2002-12-24 01:08:04 +03:00
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
|
1999-04-25 06:43:50 +04:00
|
|
|
// Is it a scroll frame?
|
2002-12-24 01:08:04 +03:00
|
|
|
f->GetFrameType(getter_AddRefs(frameType));
|
1999-04-25 06:43:50 +04:00
|
|
|
if (nsLayoutAtoms::scrollFrame == frameType) {
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
|
|
|
|
2002-12-24 01:08:04 +03:00
|
|
|
// Returns the root scrollable frame, which is the first child of the root
|
|
|
|
// frame.
|
|
|
|
static nsIScrollableFrame*
|
|
|
|
GetRootScrollableFrame(nsIPresContext* aPresContext, nsIFrame* aRootFrame)
|
|
|
|
{
|
|
|
|
nsIScrollableFrame* scrollableFrame = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
aRootFrame->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
|
|
|
|
if (nsLayoutAtoms::viewportFrame == frameType) {
|
|
|
|
nsIFrame* childFrame;
|
|
|
|
aRootFrame->FirstChild(aPresContext, nsnull, &childFrame);
|
|
|
|
|
|
|
|
if (childFrame) {
|
|
|
|
childFrame->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
|
|
|
|
if (nsLayoutAtoms::scrollFrame == frameType) {
|
|
|
|
// Use this frame, even if we are using GFX frames for the
|
|
|
|
// viewport, which contains another scroll frame below this
|
|
|
|
// frame, since the GFX scrollport frame does not implement
|
|
|
|
// nsIScrollableFrame.
|
|
|
|
CallQueryInterface(childFrame, &scrollableFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
NS_WARNING("aRootFrame is not a viewport frame");
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
return scrollableFrame;
|
|
|
|
}
|
|
|
|
|
2002-08-11 21:56:15 +04:00
|
|
|
const nsStyleBackground*
|
2003-02-22 03:32:13 +03:00
|
|
|
nsCSSRendering::FindNonTransparentBackground(nsStyleContext* aContext,
|
2002-08-11 21:56:15 +04:00
|
|
|
PRBool aStartAtParent /*= PR_FALSE*/)
|
|
|
|
{
|
|
|
|
const nsStyleBackground* result = nsnull;
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* context;
|
2002-08-11 21:56:15 +04:00
|
|
|
if (aStartAtParent) {
|
2002-10-09 05:46:15 +04:00
|
|
|
context = aContext->GetParent();
|
2002-08-11 21:56:15 +04:00
|
|
|
} else {
|
|
|
|
context = aContext;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(context, "Cannot find NonTransparentBackground in a null context" );
|
|
|
|
|
|
|
|
while (context) {
|
2002-10-09 08:51:59 +04:00
|
|
|
// Have to .get() because some compilers won't match the template
|
|
|
|
// otherwise (they don't look for implicit type conversions while doing
|
|
|
|
// template matching?).
|
2003-05-15 07:42:21 +04:00
|
|
|
result = context->GetStyleBackground();
|
2002-08-11 21:56:15 +04:00
|
|
|
if (0 == (result->mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT))
|
|
|
|
break;
|
|
|
|
|
|
|
|
context = context->GetParent();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-08 02:46:07 +03:00
|
|
|
/**
|
|
|
|
* |FindBackground| finds the correct style data to use to paint the
|
|
|
|
* background. It is responsible for handling the following two
|
|
|
|
* statements in section 14.2 of CSS2:
|
|
|
|
*
|
|
|
|
* The background of the box generated by the root element covers the
|
|
|
|
* entire canvas.
|
|
|
|
*
|
|
|
|
* For HTML documents, however, we recommend that authors specify the
|
|
|
|
* background for the BODY element rather than the HTML element. User
|
|
|
|
* agents should observe the following precedence rules to fill in the
|
|
|
|
* background: if the value of the 'background' property for the HTML
|
|
|
|
* element is different from 'transparent' then use it, else use the
|
|
|
|
* value of the 'background' property for the BODY element. If the
|
|
|
|
* resulting value is 'transparent', the rendering is undefined.
|
|
|
|
*
|
|
|
|
* Thus, in our implementation, it is responsible for ensuring that:
|
|
|
|
* + we paint the correct background on the |nsCanvasFrame|,
|
|
|
|
* |nsRootBoxFrame|, or |nsPageFrame|,
|
|
|
|
* + we don't paint the background on the root element, and
|
|
|
|
* + we don't paint the background on the BODY element in *some* cases,
|
|
|
|
* and for SGML-based HTML documents only.
|
|
|
|
*
|
|
|
|
* |FindBackground| returns true if a background should be painted, and
|
|
|
|
* the resulting style context to use for the background information
|
|
|
|
* will be filled in to |aBackground|. It fills in a boolean indicating
|
|
|
|
* whether the frame is the canvas frame to allow PaintBackground to
|
|
|
|
* ensure that it always paints something non-transparent for the
|
|
|
|
* canvas.
|
|
|
|
*/
|
|
|
|
|
2003-04-06 06:49:40 +04:00
|
|
|
// Returns nsnull if aFrame is not a canvas frame.
|
|
|
|
// Otherwise, it returns the frame we should look for the background on.
|
|
|
|
// This is normally aFrame but if aFrame is the viewport, we need to
|
|
|
|
// look for the background starting at the scroll root (which shares
|
|
|
|
// style context with the document root) or the document root itself.
|
|
|
|
// We need to treat the viewport as canvas because, even though
|
|
|
|
// it does not actually paint a background, we need to get the right
|
|
|
|
// background style so we correctly detect transparent documents.
|
|
|
|
inline nsIFrame*
|
|
|
|
IsCanvasFrame(nsIPresContext* aPresContext, nsIFrame *aFrame)
|
2002-01-08 02:46:07 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
aFrame->GetFrameType(getter_AddRefs(frameType));
|
2003-04-06 06:49:40 +04:00
|
|
|
if (frameType == nsLayoutAtoms::canvasFrame ||
|
|
|
|
frameType == nsLayoutAtoms::rootFrame ||
|
|
|
|
frameType == nsLayoutAtoms::pageFrame) {
|
|
|
|
return aFrame;
|
|
|
|
} else if (frameType == nsLayoutAtoms::viewportFrame) {
|
|
|
|
nsIFrame* firstChild;
|
|
|
|
aFrame->FirstChild(aPresContext, nsnull, &firstChild);
|
|
|
|
if (firstChild) {
|
|
|
|
return firstChild;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline PRBool
|
|
|
|
FindCanvasBackground(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsStyleBackground** aBackground)
|
|
|
|
{
|
|
|
|
// XXXldb What if the root element is positioned, etc.? (We don't
|
|
|
|
// allow that yet, do we?)
|
|
|
|
nsIFrame *firstChild;
|
|
|
|
aForFrame->FirstChild(aPresContext, nsnull, &firstChild);
|
|
|
|
if (firstChild) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleBackground* result = firstChild->GetStyleBackground();
|
2002-02-15 17:48:12 +03:00
|
|
|
|
|
|
|
// for printing and print preview.. this should be a pageContentFrame
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* parentContext;
|
2002-02-15 17:48:12 +03:00
|
|
|
|
|
|
|
firstChild->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
if ( (frameType == nsLayoutAtoms::pageContentFrame) ){
|
|
|
|
// we have to find the background style ourselves.. since the
|
|
|
|
// pageContentframe does not have content
|
|
|
|
while(firstChild){
|
|
|
|
for (nsIFrame* kidFrame = firstChild; nsnull != kidFrame; ) {
|
2003-02-22 03:32:13 +03:00
|
|
|
parentContext = kidFrame->GetStyleContext();
|
2003-05-15 07:42:21 +04:00
|
|
|
result = parentContext->GetStyleBackground();
|
2003-01-17 12:33:52 +03:00
|
|
|
if (!result->IsTransparent()) {
|
2003-05-15 07:42:21 +04:00
|
|
|
*aBackground = kidFrame->GetStyleBackground();
|
2002-02-15 17:48:12 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
2003-07-05 19:04:34 +04:00
|
|
|
kidFrame = kidFrame->GetNextSibling();
|
2002-02-15 17:48:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
firstChild->FirstChild(aPresContext, nsnull, &firstChild);
|
|
|
|
}
|
|
|
|
return PR_FALSE; // nothing found for this
|
|
|
|
}
|
2002-01-08 02:46:07 +03:00
|
|
|
|
|
|
|
// Check if we need to do propagation from BODY rather than HTML.
|
2003-01-17 12:33:52 +03:00
|
|
|
if (result->IsTransparent()) {
|
2003-07-05 19:04:34 +04:00
|
|
|
nsIContent* content = aForFrame->GetContent();
|
2002-01-08 02:46:07 +03:00
|
|
|
if (content) {
|
2002-01-11 22:38:21 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> node( do_QueryInterface(content) );
|
|
|
|
// Use |GetOwnerDocument| so it works during destruction.
|
|
|
|
nsCOMPtr<nsIDOMDocument> doc;
|
|
|
|
node->GetOwnerDocument(getter_AddRefs(doc));
|
2002-01-08 02:46:07 +03:00
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(doc);
|
|
|
|
if (htmlDoc) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> body;
|
|
|
|
htmlDoc->GetBody(getter_AddRefs(body));
|
|
|
|
nsCOMPtr<nsIContent> bodyContent = do_QueryInterface(body);
|
2002-05-08 23:27:40 +04:00
|
|
|
// We need to null check the body node (bug 118829) since
|
|
|
|
// there are cases, thanks to the fix for bug 5569, where we
|
|
|
|
// will reflow a document with no body. In particular, if a
|
|
|
|
// SCRIPT element in the head blocks the parser and then has a
|
|
|
|
// SCRIPT that does "document.location.href = 'foo'", then
|
|
|
|
// nsParser::Terminate will call |DidBuildModel| methods
|
|
|
|
// through to the content sink, which will call |StartLayout|
|
|
|
|
// and thus |InitialReflow| on the pres shell. See bug 119351
|
|
|
|
// for the ugly details.
|
2002-01-09 05:36:49 +03:00
|
|
|
if (bodyContent) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
nsIFrame *bodyFrame;
|
|
|
|
nsresult rv = shell->GetPrimaryFrameFor(bodyContent, &bodyFrame);
|
|
|
|
if (NS_SUCCEEDED(rv) && bodyFrame)
|
2003-05-15 07:42:21 +04:00
|
|
|
result = bodyFrame->GetStyleBackground();
|
2002-01-09 05:36:49 +03:00
|
|
|
}
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aBackground = result;
|
|
|
|
} else {
|
|
|
|
// This should always give transparent, so we'll fill it in with the
|
2002-01-08 07:11:25 +03:00
|
|
|
// default color if needed. This seems to happen a bit while a page is
|
|
|
|
// being loaded.
|
2003-05-15 07:42:21 +04:00
|
|
|
*aBackground = aForFrame->GetStyleBackground();
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PRBool
|
|
|
|
FindElementBackground(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsStyleBackground** aBackground)
|
|
|
|
{
|
2003-07-05 19:04:34 +04:00
|
|
|
nsIFrame *parentFrame = aForFrame->GetParent();
|
2002-01-14 18:00:30 +03:00
|
|
|
// XXXldb We shouldn't have to null-check |parentFrame| here.
|
2003-04-06 06:49:40 +04:00
|
|
|
if (parentFrame && IsCanvasFrame(aPresContext, parentFrame) == parentFrame) {
|
2002-01-08 02:46:07 +03:00
|
|
|
// Check that we're really the root (rather than in another child list).
|
|
|
|
nsIFrame *childFrame;
|
|
|
|
parentFrame->FirstChild(aPresContext, nsnull, &childFrame);
|
|
|
|
if (childFrame == aForFrame)
|
|
|
|
return PR_FALSE; // Background was already drawn for the canvas.
|
|
|
|
}
|
|
|
|
|
2003-05-15 07:42:21 +04:00
|
|
|
*aBackground = aForFrame->GetStyleBackground();
|
2002-01-08 02:46:07 +03:00
|
|
|
|
2003-07-05 19:04:34 +04:00
|
|
|
nsIContent* content = aForFrame->GetContent();
|
2002-03-06 02:17:32 +03:00
|
|
|
if (!content || !content->IsContentOfType(nsIContent::eHTML))
|
|
|
|
return PR_TRUE; // not frame for an HTML element
|
|
|
|
|
|
|
|
if (!parentFrame)
|
|
|
|
return PR_TRUE; // no parent to look at
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
2003-06-14 00:10:01 +04:00
|
|
|
content->GetTag(getter_AddRefs(tag));
|
2002-03-06 02:17:32 +03:00
|
|
|
if (tag != nsHTMLAtoms::body)
|
|
|
|
return PR_TRUE; // not frame for <BODY> element
|
2002-01-08 02:46:07 +03:00
|
|
|
|
2002-02-26 01:18:26 +03:00
|
|
|
// We should only look at the <html> background if we're in an HTML document
|
|
|
|
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
|
|
|
|
nsCOMPtr<nsIDOMDocument> doc;
|
|
|
|
node->GetOwnerDocument(getter_AddRefs(doc));
|
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(doc));
|
|
|
|
if (!htmlDoc)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleBackground* htmlBG = parentFrame->GetStyleBackground();
|
2003-01-17 12:33:52 +03:00
|
|
|
return !htmlBG->IsTransparent();
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCSSRendering::FindBackground(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsStyleBackground** aBackground,
|
|
|
|
PRBool* aIsCanvas)
|
|
|
|
{
|
2003-04-06 06:49:40 +04:00
|
|
|
nsIFrame* canvasFrame = IsCanvasFrame(aPresContext, aForFrame);
|
|
|
|
*aIsCanvas = canvasFrame != nsnull;
|
|
|
|
return canvasFrame
|
|
|
|
? FindCanvasBackground(aPresContext, canvasFrame, aBackground)
|
2002-01-08 02:46:07 +03:00
|
|
|
: FindElementBackground(aPresContext, aForFrame, aBackground);
|
|
|
|
}
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
void
|
|
|
|
nsCSSRendering::DidPaint()
|
|
|
|
{
|
|
|
|
gInlineBGData.Reset();
|
|
|
|
}
|
|
|
|
|
1998-09-26 21:16:56 +04:00
|
|
|
void
|
1999-11-24 09:03:41 +03:00
|
|
|
nsCSSRendering::PaintBackground(nsIPresContext* aPresContext,
|
1998-09-26 21:16:56 +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,
|
2003-02-23 05:49:22 +03:00
|
|
|
PRBool aUsePrintSettings)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2002-01-08 02:46:07 +03:00
|
|
|
NS_PRECONDITION(aForFrame,
|
|
|
|
"Frame is expected to be provided to PaintBackground");
|
|
|
|
|
|
|
|
PRBool isCanvas;
|
|
|
|
const nsStyleBackground *color;
|
2002-02-15 17:48:12 +03:00
|
|
|
|
2002-02-20 05:14:18 +03:00
|
|
|
if (!FindBackground(aPresContext, aForFrame, &color, &isCanvas)) {
|
|
|
|
// we don't want to bail out of moz-appearance is set on a root
|
|
|
|
// node. If it has a parent content node, bail because it's not
|
|
|
|
// a root, other wise keep going in order to let the theme stuff
|
|
|
|
// draw the background. The canvas really should be drawing the
|
|
|
|
// bg, but there's no way to hook that up via css.
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleDisplay* displayData = aForFrame->GetStyleDisplay();
|
2002-02-20 05:14:18 +03:00
|
|
|
if (displayData->mAppearance) {
|
2003-07-05 19:04:34 +04:00
|
|
|
nsIContent* content = aForFrame->GetContent();
|
2003-05-15 07:42:21 +04:00
|
|
|
if (content) {
|
2002-02-20 05:14:18 +03:00
|
|
|
nsCOMPtr<nsIContent> parent;
|
2003-06-14 00:10:01 +04:00
|
|
|
content->GetParent(getter_AddRefs(parent));
|
2003-05-15 07:42:21 +04:00
|
|
|
if (parent)
|
2002-02-20 05:14:18 +03:00
|
|
|
return;
|
2002-02-21 00:51:25 +03:00
|
|
|
else
|
2003-05-15 07:42:21 +04:00
|
|
|
color = aForFrame->GetStyleBackground();
|
2002-02-20 05:14:18 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
2002-01-08 02:46:07 +03:00
|
|
|
if (!isCanvas) {
|
|
|
|
PaintBackgroundWithSC(aPresContext, aRenderingContext, aForFrame,
|
2002-10-08 14:24:53 +04:00
|
|
|
aDirtyRect, aBorderArea, *color, aBorder,
|
2003-02-23 05:49:22 +03:00
|
|
|
aPadding, aUsePrintSettings);
|
2002-01-08 02:46:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-02-21 00:51:25 +03:00
|
|
|
if (!color)
|
|
|
|
return;
|
2002-01-08 02:46:07 +03:00
|
|
|
nsStyleBackground canvasColor(*color);
|
|
|
|
|
2003-07-05 19:04:34 +04:00
|
|
|
nsIViewManager* vm = aPresContext->GetViewManager();
|
2002-02-20 00:33:26 +03:00
|
|
|
|
|
|
|
if (canvasColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) {
|
|
|
|
nsIView* rootView;
|
|
|
|
vm->GetRootView(rootView);
|
2003-07-05 19:04:34 +04:00
|
|
|
if (!rootView->GetParent()) {
|
2003-04-06 06:49:40 +04:00
|
|
|
PRBool widgetIsTranslucent = PR_FALSE;
|
|
|
|
|
2003-07-05 19:04:34 +04:00
|
|
|
if (rootView->HasWidget()) {
|
|
|
|
rootView->GetWidget()->GetWindowTranslucency(widgetIsTranslucent);
|
2003-04-06 06:49:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!widgetIsTranslucent) {
|
|
|
|
// Ensure that we always paint a color for the root (in case there's
|
|
|
|
// no background at all or a partly transparent image).
|
|
|
|
canvasColor.mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
|
|
|
|
aPresContext->GetDefaultBackgroundColor(&canvasColor.mBackgroundColor);
|
|
|
|
}
|
2002-02-20 00:33:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-08 02:46:07 +03:00
|
|
|
vm->SetDefaultBackgroundColor(canvasColor.mBackgroundColor);
|
|
|
|
|
|
|
|
// Since nsHTMLContainerFrame::CreateViewForFrame might have created
|
|
|
|
// the view before we knew about the child with the fixed background
|
|
|
|
// attachment (root or BODY) or the stylesheet specifying that
|
|
|
|
// attachment, set the BitBlt flag here as well.
|
|
|
|
if (canvasColor.mBackgroundAttachment == NS_STYLE_BG_ATTACHMENT_FIXED) {
|
2003-07-05 19:04:34 +04:00
|
|
|
nsIView *view = aForFrame->GetView();
|
2002-01-08 02:46:07 +03:00
|
|
|
if (view)
|
|
|
|
vm->SetViewBitBltEnabled(view, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
PaintBackgroundWithSC(aPresContext, aRenderingContext, aForFrame,
|
|
|
|
aDirtyRect, aBorderArea, canvasColor,
|
2003-02-23 05:49:22 +03:00
|
|
|
aBorder, aPadding, aUsePrintSettings);
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSRendering::PaintBackgroundWithSC(nsIPresContext* aPresContext,
|
|
|
|
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,
|
2002-02-15 17:48:12 +03:00
|
|
|
PRBool aUsePrintSettings)
|
2002-01-08 02:46:07 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aForFrame,
|
|
|
|
"Frame is expected to be provided to PaintBackground");
|
2000-05-11 03:24:08 +04:00
|
|
|
|
2003-02-23 05:49:22 +03:00
|
|
|
PRBool canDrawBackgroundImage = PR_TRUE;
|
|
|
|
PRBool canDrawBackgroundColor = PR_TRUE;
|
|
|
|
|
|
|
|
if (aUsePrintSettings) {
|
2002-02-15 17:48:12 +03:00
|
|
|
aPresContext->GetBackgroundImageDraw(canDrawBackgroundImage);
|
|
|
|
aPresContext->GetBackgroundColorDraw(canDrawBackgroundColor);
|
2001-11-27 17:50:35 +03:00
|
|
|
}
|
2003-02-23 05:49:22 +03:00
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
// Check to see if we have an appearance defined. If so, we let the theme
|
2002-02-21 00:51:25 +03:00
|
|
|
// renderer draw the background and bail out.
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleDisplay* displayData = aForFrame->GetStyleDisplay();
|
2001-12-18 01:51:39 +03:00
|
|
|
if (displayData->mAppearance) {
|
|
|
|
nsCOMPtr<nsITheme> theme;
|
|
|
|
aPresContext->GetTheme(getter_AddRefs(theme));
|
2002-09-21 05:03:38 +04:00
|
|
|
if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame, displayData->mAppearance)) {
|
2001-12-18 01:51:39 +03:00
|
|
|
theme->DrawWidgetBackground(&aRenderingContext, aForFrame,
|
|
|
|
displayData->mAppearance, aBorderArea, aDirtyRect);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// The background is rendered over the 'background-clip' area.
|
|
|
|
nsRect bgClipArea(aBorderArea);
|
|
|
|
if (aColor.mBackgroundClip != NS_STYLE_BG_CLIP_BORDER) {
|
|
|
|
NS_ASSERTION(aColor.mBackgroundClip == NS_STYLE_BG_CLIP_PADDING,
|
|
|
|
"unknown background-clip value");
|
|
|
|
nsMargin border;
|
|
|
|
aBorder.GetBorder(border);
|
|
|
|
bgClipArea.Deflate(border);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The actual dirty rect is the intersection of the 'background-clip'
|
|
|
|
// area and the dirty rect we were given
|
|
|
|
nsRect dirtyRect;
|
|
|
|
if (!dirtyRect.IntersectRect(bgClipArea, aDirtyRect)) {
|
|
|
|
// Nothing to paint
|
|
|
|
return;
|
|
|
|
}
|
2002-02-21 00:51:25 +03:00
|
|
|
|
2002-02-15 17:48:12 +03:00
|
|
|
// if there is no background image or background images are turned off, try a color.
|
2003-02-23 05:49:22 +03:00
|
|
|
if (aColor.mBackgroundImage.IsEmpty() || !canDrawBackgroundImage) {
|
2002-10-08 14:24:53 +04:00
|
|
|
PaintBackgroundColor(aPresContext, aRenderingContext, aForFrame, bgClipArea,
|
2003-02-23 05:49:22 +03:00
|
|
|
aColor, aBorder, aPadding, canDrawBackgroundColor);
|
2002-10-08 14:24:53 +04:00
|
|
|
return;
|
|
|
|
}
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// We have a background image
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// get the frame for the background image load to complete in
|
|
|
|
// - this may be different than the frame we are rendering
|
|
|
|
// (as in the case of the canvas frame)
|
|
|
|
nsIFrame *pBGFrame = nsnull;
|
|
|
|
GetFrameForBackgroundUpdate(aPresContext, aForFrame, &pBGFrame);
|
|
|
|
NS_ASSERTION(pBGFrame, "Background Frame must be set by GetFrameForBackgroundUpdate");
|
|
|
|
|
|
|
|
// Lookup the image
|
|
|
|
nsCOMPtr<imgIRequest> req;
|
|
|
|
nsresult rv = aPresContext->LoadImage(aColor.mBackgroundImage, pBGFrame, getter_AddRefs(req));
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
PRUint32 status = imgIRequest::STATUS_ERROR;
|
|
|
|
if (req)
|
|
|
|
req->GetImageStatus(&status);
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
if (NS_FAILED(rv) || !req || !(status & imgIRequest::STATUS_FRAME_COMPLETE) || !(status & imgIRequest::STATUS_SIZE_AVAILABLE)) {
|
|
|
|
PaintBackgroundColor(aPresContext, aRenderingContext, aForFrame, bgClipArea,
|
2003-02-23 05:49:22 +03:00
|
|
|
aColor, aBorder, aPadding, canDrawBackgroundColor);
|
2002-10-08 14:24:53 +04:00
|
|
|
return;
|
|
|
|
}
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
req->GetImage(getter_AddRefs(image));
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
nsSize imageSize;
|
|
|
|
image->GetWidth(&imageSize.width);
|
|
|
|
image->GetHeight(&imageSize.height);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
float p2t;
|
|
|
|
aPresContext->GetPixelsToTwips(&p2t);
|
|
|
|
imageSize.width = NSIntPixelsToTwips(imageSize.width, p2t);
|
|
|
|
imageSize.height = NSIntPixelsToTwips(imageSize.height, p2t);
|
1999-01-15 21:25:58 +03:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
req = nsnull;
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
nsRect bgOriginArea;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
aForFrame->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
if (frameType == nsLayoutAtoms::inlineFrame) {
|
|
|
|
switch (aColor.mBackgroundInlinePolicy) {
|
|
|
|
case NS_STYLE_BG_INLINE_POLICY_EACH_BOX:
|
|
|
|
bgOriginArea = aBorderArea;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_INLINE_POLICY_BOUNDING_BOX:
|
|
|
|
bgOriginArea = gInlineBGData.GetBoundingRect(aForFrame);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unknown background-inline-policy value! "
|
|
|
|
"Please, teach me what to do.");
|
|
|
|
case NS_STYLE_BG_INLINE_POLICY_CONTINUOUS:
|
|
|
|
bgOriginArea = gInlineBGData.GetContinuousRect(aForFrame);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bgOriginArea = aBorderArea;
|
|
|
|
}
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Background images are tiled over the 'background-clip' area
|
|
|
|
// but the origin of the tiling is based on the 'background-origin' area
|
|
|
|
if (aColor.mBackgroundOrigin != NS_STYLE_BG_ORIGIN_BORDER) {
|
|
|
|
nsMargin border;
|
2001-02-07 12:57:26 +03:00
|
|
|
if (!aBorder.GetBorder(border)) {
|
1999-07-28 08:48:34 +04:00
|
|
|
NS_NOTYETIMPLEMENTED("percentage border");
|
|
|
|
}
|
1999-08-27 18:37:47 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
bgOriginArea.Deflate(border);
|
|
|
|
if (aColor.mBackgroundOrigin != NS_STYLE_BG_ORIGIN_PADDING) {
|
|
|
|
nsMargin padding;
|
|
|
|
// XXX CalcPaddingFor is deprecated, but we need it for percentage padding
|
|
|
|
aPadding.CalcPaddingFor(aForFrame, padding);
|
|
|
|
bgOriginArea.Deflate(padding);
|
|
|
|
NS_ASSERTION(aColor.mBackgroundOrigin == NS_STYLE_BG_ORIGIN_CONTENT,
|
|
|
|
"unknown background-origin value");
|
1999-08-27 18:37:47 +04:00
|
|
|
}
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
1999-01-15 21:25:58 +03:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Based on the repeat setting, compute how many tiles we should
|
|
|
|
// lay down for each axis. The value computed is the maximum based
|
|
|
|
// on the dirty rect before accounting for the background-position.
|
|
|
|
nscoord tileWidth = imageSize.width;
|
|
|
|
nscoord tileHeight = imageSize.height;
|
2003-03-06 02:34:48 +03:00
|
|
|
PRBool needBackgroundColor = !(aColor.mBackgroundFlags &
|
|
|
|
NS_STYLE_BG_COLOR_TRANSPARENT);
|
2002-10-08 14:24:53 +04:00
|
|
|
PRIntn repeat = aColor.mBackgroundRepeat;
|
|
|
|
nscoord xDistance, yDistance;
|
|
|
|
|
|
|
|
switch (repeat) {
|
1998-04-14 00:24:54 +04:00
|
|
|
case NS_STYLE_BG_REPEAT_X:
|
1999-01-15 21:25:58 +03:00
|
|
|
xDistance = dirtyRect.width;
|
1998-12-12 06:06:02 +03:00
|
|
|
yDistance = tileHeight;
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_REPEAT_Y:
|
1998-12-12 06:06:02 +03:00
|
|
|
xDistance = tileWidth;
|
1999-01-15 21:25:58 +03:00
|
|
|
yDistance = dirtyRect.height;
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_REPEAT_XY:
|
1999-01-15 21:25:58 +03:00
|
|
|
xDistance = dirtyRect.width;
|
|
|
|
yDistance = dirtyRect.height;
|
2003-03-06 02:34:48 +03:00
|
|
|
if (needBackgroundColor) {
|
|
|
|
// If the image is completely opaque, we do not need to paint the
|
|
|
|
// background color
|
|
|
|
nsCOMPtr<gfxIImageFrame> gfxImgFrame;
|
|
|
|
image->GetCurrentFrame(getter_AddRefs(gfxImgFrame));
|
|
|
|
if (gfxImgFrame) {
|
|
|
|
gfx_format frameFormat;
|
|
|
|
gfxImgFrame->GetFormat(&frameFormat);
|
|
|
|
NS_ASSERTION(frameFormat >= 0 && frameFormat <= 7,
|
|
|
|
"Unknown gfxIFormats value");
|
|
|
|
needBackgroundColor = frameFormat != gfxIFormats::RGB &&
|
|
|
|
frameFormat != gfxIFormats::BGR;
|
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
2002-10-08 14:24:53 +04:00
|
|
|
case NS_STYLE_BG_REPEAT_OFF:
|
|
|
|
default:
|
|
|
|
NS_ASSERTION(repeat == NS_STYLE_BG_REPEAT_OFF, "unknown background-repeat value");
|
|
|
|
xDistance = tileWidth;
|
|
|
|
yDistance = tileHeight;
|
|
|
|
break;
|
|
|
|
}
|
1999-01-15 21:25:58 +03:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// The background color is rendered over the 'background-clip' area
|
|
|
|
if (needBackgroundColor) {
|
|
|
|
PaintBackgroundColor(aPresContext, aRenderingContext, aForFrame, bgClipArea,
|
2003-02-23 05:49:22 +03:00
|
|
|
aColor, aBorder, aPadding, canDrawBackgroundColor);
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
if ((tileWidth == 0) || (tileHeight == 0) || dirtyRect.IsEmpty()) {
|
|
|
|
// Nothing left to paint
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the anchor point.
|
|
|
|
//
|
|
|
|
// When tiling, the anchor coordinate values will be negative offsets
|
2003-01-17 12:33:52 +03:00
|
|
|
// from the background-origin area.
|
2002-10-08 14:24:53 +04:00
|
|
|
|
|
|
|
nsPoint anchor;
|
|
|
|
if (NS_STYLE_BG_ATTACHMENT_FIXED == aColor.mBackgroundAttachment) {
|
|
|
|
// If it's a fixed background attachment, then the image is placed
|
|
|
|
// relative to the nearest scrolling ancestor, or the viewport if
|
|
|
|
// the frame doesn't have a scrolling ancestor
|
|
|
|
nsIFrame* scrolledFrame = nsnull;
|
|
|
|
nsIView* viewportView = nsnull;
|
|
|
|
nsRect viewportArea;
|
|
|
|
|
|
|
|
// get the nsIScrollableFrame interface from the scrollFrame
|
2002-12-24 01:08:04 +03:00
|
|
|
nsIScrollableFrame* scrollableFrame;
|
2002-12-28 03:03:33 +03:00
|
|
|
nsIFrame* scrollFrame = GetNearestScrollFrame(aForFrame);
|
|
|
|
if (scrollFrame) {
|
|
|
|
CallQueryInterface(scrollFrame, &scrollableFrame);
|
|
|
|
if (scrollableFrame) {
|
|
|
|
scrollableFrame->GetScrolledFrame(aPresContext, scrolledFrame);
|
|
|
|
}
|
2000-05-11 03:24:08 +04:00
|
|
|
}
|
2002-12-24 01:08:04 +03:00
|
|
|
|
|
|
|
if (scrolledFrame) {
|
2003-07-05 19:04:34 +04:00
|
|
|
viewportArea = scrolledFrame->GetRect();
|
|
|
|
viewportView = scrolledFrame->GetView();
|
2002-12-24 01:08:04 +03:00
|
|
|
}
|
|
|
|
else {
|
2002-10-08 14:24:53 +04:00
|
|
|
// The viewport isn't scrollable, so use the root frame's view
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
NS_ASSERTION(presShell, "no pres shell");
|
2000-05-11 03:24:08 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
nsIFrame* rootFrame;
|
|
|
|
presShell->GetRootFrame(&rootFrame);
|
|
|
|
NS_ASSERTION(rootFrame, "no root frame");
|
1999-04-25 06:43:50 +04:00
|
|
|
|
2003-02-23 05:49:22 +03:00
|
|
|
PRBool isPaginated = PR_FALSE;
|
|
|
|
aPresContext->IsPaginated(&isPaginated);
|
|
|
|
if (isPaginated) {
|
|
|
|
nsIFrame* page = nsLayoutUtils::GetPageFrame(aForFrame);
|
|
|
|
NS_ASSERTION(page, "no page");
|
|
|
|
rootFrame = page;
|
|
|
|
}
|
|
|
|
|
2003-07-05 19:04:34 +04:00
|
|
|
viewportView = rootFrame->GetView();
|
2002-10-08 14:24:53 +04:00
|
|
|
NS_ASSERTION(viewportView, "no viewport view");
|
2003-07-05 19:04:34 +04:00
|
|
|
viewportArea = viewportView->GetBounds();
|
2002-10-08 14:24:53 +04:00
|
|
|
viewportArea.x = 0;
|
|
|
|
viewportArea.y = 0;
|
2002-12-24 01:08:04 +03:00
|
|
|
|
|
|
|
scrollableFrame = GetRootScrollableFrame(aPresContext, rootFrame);
|
|
|
|
}
|
|
|
|
|
2002-12-27 10:32:17 +03:00
|
|
|
if (scrollableFrame) {
|
|
|
|
// Now, account for scrollbars, if we have any.
|
|
|
|
PRBool verticalVisible;
|
|
|
|
PRBool horizontalVisible;
|
|
|
|
scrollableFrame->GetScrollbarVisibility(aPresContext, &verticalVisible,
|
|
|
|
&horizontalVisible);
|
|
|
|
|
|
|
|
if (verticalVisible || horizontalVisible) {
|
|
|
|
nscoord verticalWidth;
|
|
|
|
nscoord horizontalHeight;
|
|
|
|
scrollableFrame->GetScrollbarSizes(aPresContext, &verticalWidth,
|
|
|
|
&horizontalHeight);
|
|
|
|
if (verticalVisible) {
|
|
|
|
// Assumes vertical scrollbars are on the right.
|
|
|
|
viewportArea.width -= verticalWidth;
|
|
|
|
}
|
|
|
|
if (horizontalVisible) {
|
|
|
|
// Assumes horizontal scrollbars are on the bottom.
|
|
|
|
viewportArea.height -= horizontalHeight;
|
|
|
|
}
|
2002-12-24 01:08:04 +03:00
|
|
|
}
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
2001-08-18 03:26:29 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Get the anchor point
|
|
|
|
ComputeBackgroundAnchorPoint(aColor, viewportArea, viewportArea, tileWidth, tileHeight, anchor);
|
1999-04-25 06:43:50 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Convert the anchor point to aForFrame's coordinate space
|
2003-07-05 19:04:34 +04:00
|
|
|
nsIView* view = aForFrame->GetView();
|
2002-10-08 14:24:53 +04:00
|
|
|
if (!view) {
|
|
|
|
nsPoint offset;
|
|
|
|
aForFrame->GetOffsetFromView(aPresContext, offset, &view);
|
|
|
|
anchor -= offset;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(view, "expected a view");
|
|
|
|
while (view && (view != viewportView)) {
|
2003-07-05 19:04:34 +04:00
|
|
|
anchor -= view->GetPosition();
|
2002-10-08 14:24:53 +04:00
|
|
|
// Get the parent view until we reach the viewport view
|
2003-07-05 19:04:34 +04:00
|
|
|
view = view->GetParent();
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
|
|
|
} else {
|
2003-01-17 12:33:52 +03:00
|
|
|
if (frameType == nsLayoutAtoms::canvasFrame) {
|
2002-10-08 14:24:53 +04:00
|
|
|
// If the frame is the canvas, the image is placed relative to
|
|
|
|
// the root element's (first) frame (see bug 46446)
|
|
|
|
nsRect firstRootElementFrameArea;
|
|
|
|
nsIFrame* firstRootElementFrame;
|
|
|
|
aForFrame->FirstChild(aPresContext, nsnull, &firstRootElementFrame);
|
|
|
|
NS_ASSERTION(firstRootElementFrame, "A canvas with a background "
|
|
|
|
"image had no child frame, which is impossible according to CSS. "
|
|
|
|
"Make sure there isn't a background image specified on the "
|
|
|
|
"|:viewport| pseudo-element in |html.css|.");
|
|
|
|
|
|
|
|
// temporary null check -- see bug 97226
|
|
|
|
if (firstRootElementFrame) {
|
2003-07-05 19:04:34 +04:00
|
|
|
firstRootElementFrameArea = firstRootElementFrame->GetRect();
|
2002-10-08 14:24:53 +04:00
|
|
|
|
|
|
|
// Take the border out of the frame's rect
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleBorder* borderStyle = firstRootElementFrame->GetStyleBorder();
|
2002-10-08 14:24:53 +04:00
|
|
|
nsMargin border;
|
|
|
|
borderStyle->GetBorder(border);
|
|
|
|
firstRootElementFrameArea.Deflate(border);
|
|
|
|
|
|
|
|
// Get the anchor point
|
|
|
|
ComputeBackgroundAnchorPoint(aColor, firstRootElementFrameArea, bgClipArea, tileWidth, tileHeight, anchor);
|
2001-08-18 03:26:29 +04:00
|
|
|
} else {
|
2002-10-08 14:24:53 +04:00
|
|
|
ComputeBackgroundAnchorPoint(aColor, bgOriginArea, bgClipArea, tileWidth, tileHeight, anchor);
|
2001-08-18 03:26:29 +04:00
|
|
|
}
|
2002-10-08 14:24:53 +04:00
|
|
|
} else {
|
|
|
|
// Otherwise, it is the normal case, and the background is
|
|
|
|
// simply placed relative to the frame's background-clip area
|
|
|
|
ComputeBackgroundAnchorPoint(aColor, bgOriginArea, bgClipArea, tileWidth, tileHeight, anchor);
|
1999-04-25 06:43:50 +04:00
|
|
|
}
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
1999-04-25 06:43:50 +04:00
|
|
|
|
2001-08-18 03:26:29 +04:00
|
|
|
|
2001-12-06 03:09:21 +03:00
|
|
|
#if (!defined(XP_UNIX) && !defined(XP_BEOS)) || defined(XP_MACOSX)
|
2002-10-08 14:24:53 +04:00
|
|
|
// Setup clipping so that rendering doesn't leak out of the computed
|
|
|
|
// dirty rect
|
|
|
|
PRBool clipState;
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(dirtyRect, nsClipCombine_kIntersect,
|
|
|
|
clipState);
|
2000-05-12 10:29:37 +04:00
|
|
|
#endif
|
1998-12-12 06:06:02 +03:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Compute the x and y starting points and limits for tiling
|
|
|
|
|
|
|
|
/* An Overview Of The Following Logic
|
2001-02-15 06:25:22 +03:00
|
|
|
|
|
|
|
A........ . . . . . . . . . . . . . .
|
|
|
|
: +---:-------.-------.-------.---- /|\
|
|
|
|
: | : . . . | nh
|
|
|
|
:.......: . . . x . . . . . . . . . . \|/
|
|
|
|
. | . . . .
|
|
|
|
. | . . ########### .
|
|
|
|
. . . . . . . . . .#. . . . .#. . . .
|
|
|
|
. | . . ########### . /|\
|
|
|
|
. | . . . . | h
|
|
|
|
. . | . . . . . . . . . . . . . z . . \|/
|
|
|
|
. | . . . .
|
|
|
|
|<-----nw------>| |<--w-->|
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
---- = the background clip area edge. The painting is done within
|
|
|
|
to this area. If the background is positioned relative to the
|
|
|
|
viewport ('fixed') then this is the viewport edge.
|
2001-02-15 06:25:22 +03:00
|
|
|
|
|
|
|
.... = the primary tile.
|
|
|
|
|
|
|
|
. . = the other tiles.
|
|
|
|
|
|
|
|
#### = the dirtyRect. This is the minimum region we want to cover.
|
|
|
|
|
|
|
|
A = The anchor point. This is the point at which the tile should
|
|
|
|
start. Always negative or zero.
|
|
|
|
|
|
|
|
x = x0 and y0 in the code. The point at which tiling must start
|
|
|
|
so that the fewest tiles are laid out while completly
|
|
|
|
covering the dirtyRect area.
|
|
|
|
|
|
|
|
z = x1 and y1 in the code. The point at which tiling must end so
|
|
|
|
that the fewest tiles are laid out while completly covering
|
|
|
|
the dirtyRect area.
|
|
|
|
|
|
|
|
w = the width of the tile (tileWidth).
|
|
|
|
|
|
|
|
h = the height of the tile (tileHeight).
|
|
|
|
|
|
|
|
n = the number of whole tiles that fit between 'A' and 'x'.
|
|
|
|
(the vertical n and the horizontal n are different)
|
|
|
|
|
|
|
|
|
|
|
|
Therefore,
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
x0 = bgClipArea.x + anchor.x + n * tileWidth;
|
2001-02-15 06:25:22 +03:00
|
|
|
|
|
|
|
...where n is an integer greater or equal to 0 fitting:
|
|
|
|
|
|
|
|
n * tileWidth <=
|
2002-10-08 14:24:53 +04:00
|
|
|
dirtyRect.x - (bgClipArea.x + anchor.x) <=
|
2001-02-15 06:25:22 +03:00
|
|
|
(n+1) * tileWidth
|
|
|
|
|
|
|
|
...i.e.,
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
n <= (dirtyRect.x - (bgClipArea.x + anchor.x)) / tileWidth < n + 1
|
2001-02-15 06:25:22 +03:00
|
|
|
|
|
|
|
...which, treating the division as an integer divide rounding down, gives:
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
n = (dirtyRect.x - (bgClipArea.x + anchor.x)) / tileWidth
|
2001-02-15 06:25:22 +03:00
|
|
|
|
|
|
|
Substituting into the original expression for x0:
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
x0 = bgClipArea.x + anchor.x +
|
|
|
|
((dirtyRect.x - (bgClipArea.x + anchor.x)) / tileWidth) *
|
2001-02-15 06:25:22 +03:00
|
|
|
tileWidth;
|
|
|
|
|
|
|
|
From this x1 is determined,
|
|
|
|
|
|
|
|
x1 = x0 + m * tileWidth;
|
|
|
|
|
|
|
|
...where m is an integer greater than 0 fitting:
|
|
|
|
|
|
|
|
(m - 1) * tileWidth <
|
|
|
|
dirtyRect.x + dirtyRect.width - x0 <=
|
|
|
|
m * tileWidth
|
|
|
|
|
|
|
|
...i.e.,
|
|
|
|
|
|
|
|
m - 1 < (dirtyRect.x + dirtyRect.width - x0) / tileWidth <= m
|
|
|
|
|
|
|
|
...which, treating the division as an integer divide, and making it
|
|
|
|
round up, gives:
|
|
|
|
|
|
|
|
m = (dirtyRect.x + dirtyRect.width - x0 + tileWidth - 1) / tileWidth
|
|
|
|
|
|
|
|
Substituting into the original expression for x1:
|
|
|
|
|
|
|
|
x1 = x0 + ((dirtyRect.x + dirtyRect.width - x0 + tileWidth - 1) /
|
|
|
|
tileWidth) * tileWidth
|
|
|
|
|
|
|
|
The vertical case is analogous. If the background is fixed, then
|
2002-10-08 14:24:53 +04:00
|
|
|
bgClipArea.x and bgClipArea.y are set to zero when finding the parent
|
2001-02-15 06:25:22 +03:00
|
|
|
viewport, above.
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
*/
|
2001-02-15 06:25:22 +03:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// first do the horizontal case
|
|
|
|
nscoord x0, x1;
|
|
|
|
if (repeat & NS_STYLE_BG_REPEAT_X) {
|
|
|
|
// When tiling in the x direction, adjust the starting position of the
|
|
|
|
// tile to account for dirtyRect.x. When tiling in x, the anchor.x value
|
|
|
|
// will be a negative value used to adjust the starting coordinate.
|
|
|
|
x0 = bgClipArea.x + anchor.x + ((dirtyRect.x - (bgClipArea.x + anchor.x)) / tileWidth) * tileWidth;
|
|
|
|
x1 = x0 + ((dirtyRect.x + dirtyRect.width - x0 + tileWidth - 1) / tileWidth) * tileWidth;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// For scrolling attachment, the anchor is within the 'background-clip'
|
|
|
|
// For fixed attachment, the anchor is within the bounds of the nearest
|
|
|
|
// scrolling ancestor (or the viewport)
|
|
|
|
x0 = anchor.x;
|
|
|
|
if (NS_STYLE_BG_ATTACHMENT_SCROLL == aColor.mBackgroundAttachment) {
|
|
|
|
x0 += bgClipArea.x;
|
|
|
|
}
|
|
|
|
x1 = x0 + tileWidth;
|
|
|
|
}
|
1998-12-12 06:06:02 +03:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// now do all that again with the vertical case
|
|
|
|
nscoord y0, y1;
|
|
|
|
if (repeat & NS_STYLE_BG_REPEAT_Y) {
|
|
|
|
// When tiling in the y direction, adjust the starting position of the
|
|
|
|
// tile to account for dirtyRect.y. When tiling in y, the anchor.y value
|
|
|
|
// will be a negative value used to adjust the starting coordinate.
|
|
|
|
y0 = bgClipArea.y + anchor.y + ((dirtyRect.y - (bgClipArea.y + anchor.y)) / tileHeight) * tileHeight;
|
|
|
|
y1 = y0 + ((dirtyRect.y + dirtyRect.height - y0 + tileHeight - 1) / tileHeight) * tileHeight;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// For scrolling attachment, the anchor is within the 'background-clip'
|
|
|
|
// For fixed attachment, the anchor is within the bounds of the nearest
|
|
|
|
// scrolling ancestor (or the viewport)
|
|
|
|
y0 = anchor.y;
|
|
|
|
if (NS_STYLE_BG_ATTACHMENT_SCROLL == aColor.mBackgroundAttachment) {
|
|
|
|
y0 += bgClipArea.y;
|
|
|
|
}
|
|
|
|
y1 = y0 + tileHeight;
|
|
|
|
}
|
1998-07-31 03:31:42 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Take the intersection again to paint only the required area
|
|
|
|
nsRect tileRect(x0, y0, (x1 - x0), (y1 - y0));
|
|
|
|
nsRect drawRect;
|
2001-08-15 09:24:29 +04:00
|
|
|
|
2003-05-30 03:29:37 +04:00
|
|
|
if (drawRect.IntersectRect(tileRect, dirtyRect))
|
|
|
|
aRenderingContext.DrawTile(image, x0, y0, &drawRect);
|
1999-10-01 18:35:20 +04:00
|
|
|
|
2001-12-06 03:09:21 +03:00
|
|
|
#if (!defined(XP_UNIX) && !defined(XP_BEOS)) || defined(XP_MACOSX)
|
2002-10-08 14:24:53 +04:00
|
|
|
// Restore clipping
|
|
|
|
aRenderingContext.PopState(clipState);
|
2000-05-12 10:29:37 +04:00
|
|
|
#endif
|
1999-04-21 18:23:49 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSRendering::PaintBackgroundColor(nsIPresContext* aPresContext,
|
|
|
|
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)
|
2002-10-08 14:24:53 +04:00
|
|
|
{
|
|
|
|
if (aColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) {
|
|
|
|
// nothing to paint
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleCoord bordStyleRadius[4];
|
|
|
|
PRInt16 borderRadii[4];
|
|
|
|
nsRect bgClipArea(aBgClipArea);
|
|
|
|
|
|
|
|
// get the radius for our border
|
|
|
|
aBorder.mBorderRadius.GetTop(bordStyleRadius[NS_SIDE_TOP]); // topleft
|
|
|
|
aBorder.mBorderRadius.GetRight(bordStyleRadius[NS_SIDE_RIGHT]); // topright
|
|
|
|
aBorder.mBorderRadius.GetBottom(bordStyleRadius[NS_SIDE_BOTTOM]); // bottomright
|
|
|
|
aBorder.mBorderRadius.GetLeft(bordStyleRadius[NS_SIDE_LEFT]); // bottomleft
|
|
|
|
|
|
|
|
PRUint8 side = 0;
|
|
|
|
for (; side < 4; ++side) {
|
|
|
|
borderRadii[side] = 0;
|
|
|
|
switch (bordStyleRadius[side].GetUnit()) {
|
|
|
|
case eStyleUnit_Inherit:
|
|
|
|
// do nothing
|
|
|
|
break;
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
borderRadii[side] = nscoord(bordStyleRadius[side].GetPercentValue() * aBgClipArea.width);
|
|
|
|
break;
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
borderRadii[side] = bordStyleRadius[side].GetCoordValue();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rounded version of the border
|
|
|
|
// XXXdwh Composite borders (with multiple colors per side) use their own border radius
|
|
|
|
// algorithm now, since the current one doesn't work right for small radii.
|
|
|
|
if (!aBorder.mBorderColors) {
|
|
|
|
for (side = 0; side < 4; ++side) {
|
|
|
|
if (borderRadii[side] > 0) {
|
|
|
|
PaintRoundedBackground(aPresContext, aRenderingContext, aForFrame,
|
2003-02-23 05:49:22 +03:00
|
|
|
bgClipArea, aColor, aBorder, borderRadii,
|
|
|
|
aCanPaintNonWhite);
|
2002-10-08 14:24:53 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aColor.mBackgroundClip == NS_STYLE_BG_CLIP_BORDER) {
|
|
|
|
// XXX users of -moz-border-*-colors expect a transparent border-color
|
|
|
|
// to show the parent's background-color instead of its background-color.
|
|
|
|
// This seems wrong, but we handle that here by explictly clipping the
|
|
|
|
// background to the padding area.
|
|
|
|
nsMargin border;
|
|
|
|
aBorder.GetBorder(border);
|
|
|
|
bgClipArea.Deflate(border);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2003-02-23 05:49:22 +03:00
|
|
|
nscolor color = aColor.mBackgroundColor;
|
|
|
|
if (!aCanPaintNonWhite) {
|
|
|
|
color = NS_RGB(255, 255, 255);
|
|
|
|
}
|
|
|
|
aRenderingContext.SetColor(color);
|
2002-10-08 14:24:53 +04:00
|
|
|
aRenderingContext.FillRect(bgClipArea);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation in nsCSSRendering.h
|
|
|
|
* @update 3/26/99 dwc
|
|
|
|
*/
|
|
|
|
void
|
1999-11-24 09:03:41 +03:00
|
|
|
nsCSSRendering::PaintRoundedBackground(nsIPresContext* aPresContext,
|
2002-10-08 14:24:53 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aBgClipArea,
|
|
|
|
const nsStyleBackground& aColor,
|
|
|
|
const nsStyleBorder& aBorder,
|
2003-02-23 05:49:22 +03:00
|
|
|
PRInt16 aTheRadius[4],
|
|
|
|
PRBool aCanPaintNonWhite)
|
1999-04-19 09:27:55 +04:00
|
|
|
{
|
2002-10-08 14:24:53 +04:00
|
|
|
RoundedRect outerPath;
|
|
|
|
QBCurve cr1,cr2,cr3,cr4;
|
|
|
|
QBCurve UL,UR,LL,LR;
|
|
|
|
PRInt32 curIndex,c1Index;
|
|
|
|
nsFloatPoint thePath[MAXPATHSIZE];
|
|
|
|
static nsPoint polyPath[MAXPOLYPATHSIZE];
|
|
|
|
PRInt16 np;
|
|
|
|
nscoord twipsPerPixel;
|
|
|
|
float p2t;
|
1999-10-20 18:46:27 +04:00
|
|
|
|
|
|
|
// needed for our border thickness
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetPixelsToTwips(&p2t);
|
1999-10-20 18:46:27 +04:00
|
|
|
twipsPerPixel = NSToCoordRound(p2t);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2003-02-23 05:49:22 +03:00
|
|
|
nscolor color = aColor.mBackgroundColor;
|
|
|
|
if (!aCanPaintNonWhite) {
|
|
|
|
color = NS_RGB(255, 255, 255);
|
|
|
|
}
|
|
|
|
aRenderingContext.SetColor(color);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Adjust for background-clip, if necessary
|
|
|
|
if (aColor.mBackgroundClip != NS_STYLE_BG_CLIP_BORDER) {
|
|
|
|
NS_ASSERTION(aColor.mBackgroundClip == NS_STYLE_BG_CLIP_PADDING, "unknown background-clip value");
|
|
|
|
|
|
|
|
// Get the radius to the outer edge of the padding.
|
|
|
|
// -moz-border-radius is the radius to the outer edge of the border.
|
|
|
|
nsMargin border;
|
|
|
|
aBorder.GetBorder(border);
|
|
|
|
aTheRadius[NS_SIDE_TOP] -= border.top;
|
|
|
|
aTheRadius[NS_SIDE_RIGHT] -= border.right;
|
|
|
|
aTheRadius[NS_SIDE_BOTTOM] -= border.bottom;
|
|
|
|
aTheRadius[NS_SIDE_LEFT] -= border.left;
|
|
|
|
for (PRUint8 i = 0; i < 4; ++i) {
|
|
|
|
if (aTheRadius[i] < 0) {
|
|
|
|
aTheRadius[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
// set the rounded rect up, and let'er rip
|
2002-10-08 14:24:53 +04:00
|
|
|
outerPath.Set(aBgClipArea.x,aBgClipArea.y,aBgClipArea.width,aBgClipArea.height,aTheRadius,twipsPerPixel);
|
1999-04-19 09:27:55 +04:00
|
|
|
outerPath.GetRoundedBorders(UL,UR,LL,LR);
|
|
|
|
|
|
|
|
// BUILD THE ENTIRE OUTSIDE PATH
|
|
|
|
// TOP LINE ----------------------------------------------------------------
|
|
|
|
UL.MidPointDivide(&cr1,&cr2);
|
|
|
|
UR.MidPointDivide(&cr3,&cr4);
|
|
|
|
np=0;
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc1.x,cr2.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mCon.x, cr2.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc2.x, cr2.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mAnc1.x, cr3.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mCon.x, cr3.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mAnc2.x, cr3.mAnc2.y);
|
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
polyPath[0].x = NSToCoordRound(thePath[0].x);
|
|
|
|
polyPath[0].y = NSToCoordRound(thePath[0].y);
|
1999-04-19 09:27:55 +04:00
|
|
|
curIndex = 1;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(thePath,polyPath,&curIndex,eOutside,c1Index);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
// RIGHT LINE ----------------------------------------------------------------
|
|
|
|
LR.MidPointDivide(&cr2,&cr3);
|
|
|
|
np=0;
|
|
|
|
thePath[np++].MoveTo(cr4.mAnc1.x,cr4.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr4.mCon.x, cr4.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr4.mAnc2.x, cr4.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc1.x, cr2.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mCon.x, cr2.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc2.x, cr2.mAnc2.y);
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(thePath,polyPath,&curIndex,eOutside,c1Index);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
// BOTTOM LINE ----------------------------------------------------------------
|
|
|
|
LL.MidPointDivide(&cr2,&cr4);
|
|
|
|
np=0;
|
|
|
|
thePath[np++].MoveTo(cr3.mAnc1.x,cr3.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mCon.x, cr3.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mAnc2.x, cr3.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc1.x, cr2.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mCon.x, cr2.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc2.x, cr2.mAnc2.y);
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(thePath,polyPath,&curIndex,eOutside,c1Index);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
// LEFT LINE ----------------------------------------------------------------
|
|
|
|
np=0;
|
|
|
|
thePath[np++].MoveTo(cr4.mAnc1.x,cr4.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr4.mCon.x, cr4.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr4.mAnc2.x, cr4.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(cr1.mAnc1.x, cr1.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr1.mCon.x, cr1.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr1.mAnc2.x, cr1.mAnc2.y);
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(thePath,polyPath,&curIndex,eOutside,c1Index);
|
|
|
|
|
|
|
|
aRenderingContext.FillPolygon(polyPath,curIndex);
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation in nsCSSRendering.h
|
|
|
|
* @update 3/26/99 dwc
|
|
|
|
*/
|
|
|
|
void
|
1999-11-24 09:03:41 +03:00
|
|
|
nsCSSRendering::PaintRoundedBorder(nsIPresContext* aPresContext,
|
1999-04-19 09:27:55 +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-04-19 09:27:55 +04:00
|
|
|
PRIntn aSkipSides,
|
1999-12-23 23:48:07 +03:00
|
|
|
PRInt16 aBorderRadius[4],
|
2000-02-01 19:03:13 +03:00
|
|
|
nsRect* aGap,
|
|
|
|
PRBool aIsOutline)
|
1999-04-19 09:27:55 +04:00
|
|
|
{
|
2000-03-30 10:27:32 +04:00
|
|
|
RoundedRect outerPath;
|
|
|
|
QBCurve UL,LL,UR,LR;
|
|
|
|
QBCurve IUL,ILL,IUR,ILR;
|
|
|
|
QBCurve cr1,cr2,cr3,cr4;
|
|
|
|
QBCurve Icr1,Icr2,Icr3,Icr4;
|
2000-05-11 07:59:43 +04:00
|
|
|
nsFloatPoint thePath[MAXPATHSIZE];
|
2000-03-30 10:27:32 +04:00
|
|
|
PRInt16 np;
|
|
|
|
nsMargin border;
|
|
|
|
nscoord twipsPerPixel,qtwips;
|
|
|
|
float p2t;
|
1999-10-22 17:29:06 +04:00
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
NS_ASSERTION((aIsOutline && aOutlineStyle) || (!aIsOutline && aBorderStyle), "null params not allowed");
|
2000-02-01 19:03:13 +03:00
|
|
|
if (!aIsOutline) {
|
2001-02-07 12:57:26 +03:00
|
|
|
aBorderStyle->CalcBorderFor(aForFrame, border);
|
2000-02-01 19:03:13 +03:00
|
|
|
if ((0 == border.left) && (0 == border.right) &&
|
|
|
|
(0 == border.top) && (0 == border.bottom)) {
|
|
|
|
return;
|
|
|
|
}
|
2000-03-18 17:41:00 +03:00
|
|
|
} else {
|
|
|
|
nscoord width;
|
2001-02-07 12:57:26 +03:00
|
|
|
if (!aOutlineStyle->GetOutlineWidth(width)) {
|
2000-03-18 17:41:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
border.left = width;
|
|
|
|
border.right = width;
|
|
|
|
border.top = width;
|
|
|
|
border.bottom = width;
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// needed for our border thickness
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetPixelsToTwips(&p2t);
|
1999-10-20 18:46:27 +04:00
|
|
|
twipsPerPixel = NSToCoordRound(p2t);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
// Base our thickness check on the segment being less than a pixel and 1/2
|
2000-05-15 08:55:49 +04:00
|
|
|
qtwips = twipsPerPixel >> 2;
|
|
|
|
//qtwips = twipsPerPixel;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
1999-10-20 18:46:27 +04:00
|
|
|
outerPath.Set(aBorderArea.x,aBorderArea.y,aBorderArea.width,aBorderArea.height,aBorderRadius,twipsPerPixel);
|
1999-04-19 09:27:55 +04:00
|
|
|
outerPath.GetRoundedBorders(UL,UR,LL,LR);
|
|
|
|
outerPath.CalcInsetCurves(IUL,IUR,ILL,ILR,border);
|
|
|
|
|
|
|
|
// TOP LINE -- construct and divide the curves first, then put together our top and bottom paths
|
|
|
|
UL.MidPointDivide(&cr1,&cr2);
|
|
|
|
UR.MidPointDivide(&cr3,&cr4);
|
|
|
|
IUL.MidPointDivide(&Icr1,&Icr2);
|
|
|
|
IUR.MidPointDivide(&Icr3,&Icr4);
|
1999-10-20 18:46:27 +04:00
|
|
|
if(0!=border.top){
|
|
|
|
np=0;
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc1.x,cr2.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mCon.x, cr2.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc2.x, cr2.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mAnc1.x, cr3.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mCon.x, cr3.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mAnc2.x, cr3.mAnc2.y);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
1999-10-20 18:46:27 +04:00
|
|
|
thePath[np++].MoveTo(Icr3.mAnc2.x,Icr3.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(Icr3.mCon.x, Icr3.mCon.y);
|
|
|
|
thePath[np++].MoveTo(Icr3.mAnc1.x, Icr3.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(Icr2.mAnc2.x, Icr2.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(Icr2.mCon.x, Icr2.mCon.y);
|
|
|
|
thePath[np++].MoveTo(Icr2.mAnc1.x, Icr2.mAnc1.y);
|
2001-02-07 12:57:26 +03:00
|
|
|
RenderSide(thePath,aRenderingContext,aBorderStyle,aOutlineStyle,aStyleContext,NS_SIDE_TOP,border,qtwips, aIsOutline);
|
1999-10-20 18:46:27 +04:00
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
// RIGHT LINE ----------------------------------------------------------------
|
|
|
|
LR.MidPointDivide(&cr2,&cr3);
|
|
|
|
ILR.MidPointDivide(&Icr2,&Icr3);
|
1999-10-20 18:46:27 +04:00
|
|
|
if(0!=border.right){
|
|
|
|
np=0;
|
|
|
|
thePath[np++].MoveTo(cr4.mAnc1.x,cr4.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr4.mCon.x, cr4.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr4.mAnc2.x,cr4.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc1.x,cr2.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mCon.x, cr2.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc2.x,cr2.mAnc2.y);
|
|
|
|
|
|
|
|
thePath[np++].MoveTo(Icr2.mAnc2.x,Icr2.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(Icr2.mCon.x, Icr2.mCon.y);
|
|
|
|
thePath[np++].MoveTo(Icr2.mAnc1.x,Icr2.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(Icr4.mAnc2.x,Icr4.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(Icr4.mCon.x, Icr4.mCon.y);
|
|
|
|
thePath[np++].MoveTo(Icr4.mAnc1.x,Icr4.mAnc1.y);
|
2001-02-07 12:57:26 +03:00
|
|
|
RenderSide(thePath,aRenderingContext,aBorderStyle,aOutlineStyle,aStyleContext,NS_SIDE_RIGHT,border,qtwips, aIsOutline);
|
1999-10-20 18:46:27 +04:00
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
// bottom line ----------------------------------------------------------------
|
|
|
|
LL.MidPointDivide(&cr2,&cr4);
|
|
|
|
ILL.MidPointDivide(&Icr2,&Icr4);
|
1999-10-20 18:46:27 +04:00
|
|
|
if(0!=border.bottom){
|
|
|
|
np=0;
|
|
|
|
thePath[np++].MoveTo(cr3.mAnc1.x,cr3.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mCon.x, cr3.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mAnc2.x, cr3.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc1.x, cr2.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mCon.x, cr2.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc2.x, cr2.mAnc2.y);
|
|
|
|
|
|
|
|
thePath[np++].MoveTo(Icr2.mAnc2.x,Icr2.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(Icr2.mCon.x, Icr2.mCon.y);
|
|
|
|
thePath[np++].MoveTo(Icr2.mAnc1.x, Icr2.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(Icr3.mAnc2.x, Icr3.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(Icr3.mCon.x, Icr3.mCon.y);
|
|
|
|
thePath[np++].MoveTo(Icr3.mAnc1.x, Icr3.mAnc1.y);
|
2001-02-07 12:57:26 +03:00
|
|
|
RenderSide(thePath,aRenderingContext,aBorderStyle,aOutlineStyle,aStyleContext,NS_SIDE_BOTTOM,border,qtwips, aIsOutline);
|
1999-10-20 18:46:27 +04:00
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
// left line ----------------------------------------------------------------
|
|
|
|
if(0==border.left)
|
|
|
|
return;
|
|
|
|
np=0;
|
|
|
|
thePath[np++].MoveTo(cr4.mAnc1.x,cr4.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr4.mCon.x, cr4.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr4.mAnc2.x, cr4.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(cr1.mAnc1.x, cr1.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr1.mCon.x, cr1.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr1.mAnc2.x, cr1.mAnc2.y);
|
|
|
|
|
|
|
|
|
|
|
|
thePath[np++].MoveTo(Icr1.mAnc2.x,Icr1.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(Icr1.mCon.x, Icr1.mCon.y);
|
|
|
|
thePath[np++].MoveTo(Icr1.mAnc1.x, Icr1.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(Icr4.mAnc2.x, Icr4.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(Icr4.mCon.x, Icr4.mCon.y);
|
|
|
|
thePath[np++].MoveTo(Icr4.mAnc1.x, Icr4.mAnc1.y);
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
RenderSide(thePath,aRenderingContext,aBorderStyle,aOutlineStyle,aStyleContext,NS_SIDE_LEFT,border,qtwips, aIsOutline);
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
1999-04-21 18:23:49 +04:00
|
|
|
* See documentation in nsCSSRendering.h
|
1999-04-19 09:27:55 +04:00
|
|
|
* @update 3/26/99 dwc
|
|
|
|
*/
|
|
|
|
void
|
2000-05-11 07:59:43 +04:00
|
|
|
nsCSSRendering::RenderSide(nsFloatPoint aPoints[],nsIRenderingContext& aRenderingContext,
|
2003-02-22 03:32:13 +03:00
|
|
|
const nsStyleBorder* aBorderStyle,const nsStyleOutline* aOutlineStyle,nsStyleContext* aStyleContext,
|
2000-03-18 17:41:00 +03:00
|
|
|
PRUint8 aSide,nsMargin &aBorThick,nscoord aTwipsPerPixel,
|
|
|
|
PRBool aIsOutline)
|
1999-04-19 09:27:55 +04:00
|
|
|
{
|
2000-03-30 10:27:32 +04:00
|
|
|
QBCurve thecurve;
|
2000-08-23 07:57:13 +04:00
|
|
|
nscolor sideColor = NS_RGB(0,0,0);
|
2001-02-20 04:14:03 +03:00
|
|
|
static nsPoint polypath[MAXPOLYPATHSIZE];
|
2000-03-30 10:27:32 +04:00
|
|
|
PRInt32 curIndex,c1Index,c2Index,junk;
|
|
|
|
PRInt8 border_Style;
|
|
|
|
PRInt16 thickness;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
// Get our style context's color struct.
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleColor* ourColor = aStyleContext->GetStyleColor();
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
NS_ASSERTION((aIsOutline && aOutlineStyle) || (!aIsOutline && aBorderStyle), "null params not allowed");
|
1999-04-19 09:27:55 +04:00
|
|
|
// set the style information
|
2000-03-18 17:41:00 +03:00
|
|
|
if (!aIsOutline) {
|
2002-08-30 10:39:34 +04:00
|
|
|
if (!GetBorderColor(ourColor, *aBorderStyle, aSide, sideColor)) {
|
|
|
|
return;
|
|
|
|
}
|
2000-03-18 17:41:00 +03:00
|
|
|
} else {
|
2001-02-07 12:57:26 +03:00
|
|
|
aOutlineStyle->GetOutlineColor(sideColor);
|
2000-03-18 17:41:00 +03:00
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
aRenderingContext.SetColor ( sideColor );
|
|
|
|
|
1999-11-18 19:03:45 +03:00
|
|
|
thickness = 0;
|
|
|
|
switch(aSide){
|
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
thickness = aBorThick.left;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
thickness = aBorThick.top;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
thickness = aBorThick.right;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
thickness = aBorThick.bottom;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
// if the border is thin, just draw it
|
2000-05-11 07:59:43 +04:00
|
|
|
if (thickness<=aTwipsPerPixel) {
|
1999-04-19 09:27:55 +04:00
|
|
|
// NOTHING FANCY JUST DRAW OUR OUTSIDE BORDER
|
|
|
|
thecurve.SetPoints(aPoints[0].x,aPoints[0].y,aPoints[1].x,aPoints[1].y,aPoints[2].x,aPoints[2].y);
|
|
|
|
thecurve.SubDivide((nsIRenderingContext*)&aRenderingContext,0,0);
|
2000-05-11 07:59:43 +04:00
|
|
|
aRenderingContext.DrawLine((nscoord)aPoints[2].x,(nscoord)aPoints[2].y,(nscoord)aPoints[3].x,(nscoord)aPoints[3].y);
|
1999-04-19 09:27:55 +04:00
|
|
|
thecurve.SetPoints(aPoints[3].x,aPoints[3].y,aPoints[4].x,aPoints[4].y,aPoints[5].x,aPoints[5].y);
|
|
|
|
thecurve.SubDivide((nsIRenderingContext*)&aRenderingContext,0,0);
|
|
|
|
} else {
|
|
|
|
|
2000-03-18 17:41:00 +03:00
|
|
|
if (!aIsOutline) {
|
2001-02-07 12:57:26 +03:00
|
|
|
border_Style = aBorderStyle->GetBorderStyle(aSide);
|
2000-03-18 17:41:00 +03:00
|
|
|
} else {
|
2001-02-07 12:57:26 +03:00
|
|
|
border_Style = aOutlineStyle->GetOutlineStyle();
|
2000-03-18 17:41:00 +03:00
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
switch (border_Style){
|
|
|
|
case NS_STYLE_BORDER_STYLE_OUTSET:
|
|
|
|
case NS_STYLE_BORDER_STYLE_INSET:
|
|
|
|
{
|
2002-08-11 21:56:15 +04:00
|
|
|
const nsStyleBackground* bgColor = nsCSSRendering::FindNonTransparentBackground(aStyleContext);
|
1999-04-19 09:27:55 +04:00
|
|
|
aRenderingContext.SetColor ( MakeBevelColor (aSide, border_Style, bgColor->mBackgroundColor,sideColor, PR_TRUE));
|
|
|
|
}
|
1999-11-18 18:09:02 +03:00
|
|
|
case NS_STYLE_BORDER_STYLE_DOTTED:
|
|
|
|
case NS_STYLE_BORDER_STYLE_DASHED:
|
|
|
|
// break; This is here until dotted and dashed are supported. It is ok to have
|
|
|
|
// dotted and dashed render in solid until this style is supported. This code should
|
|
|
|
// be moved when it is supported so that the above outset and inset will fall into the
|
|
|
|
// solid code below....
|
1999-04-19 09:27:55 +04:00
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
2000-05-11 07:59:43 +04:00
|
|
|
polypath[0].x = NSToCoordRound(aPoints[0].x);
|
|
|
|
polypath[0].y = NSToCoordRound(aPoints[0].y);
|
1999-04-19 09:27:55 +04:00
|
|
|
curIndex = 1;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eOutside,c1Index);
|
|
|
|
c2Index = curIndex;
|
2000-05-11 07:59:43 +04:00
|
|
|
polypath[curIndex].x = NSToCoordRound(aPoints[6].x);
|
|
|
|
polypath[curIndex].y = NSToCoordRound(aPoints[6].y);
|
1999-04-19 09:27:55 +04:00
|
|
|
curIndex++;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eInside,junk);
|
2000-05-11 07:59:43 +04:00
|
|
|
polypath[curIndex].x = NSToCoordRound(aPoints[0].x);
|
|
|
|
polypath[curIndex].y = NSToCoordRound(aPoints[0].y);
|
1999-04-19 09:27:55 +04:00
|
|
|
curIndex++;
|
1999-04-21 18:23:49 +04:00
|
|
|
aRenderingContext.FillPolygon(polypath,curIndex);
|
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOUBLE:
|
2000-05-11 07:59:43 +04:00
|
|
|
polypath[0].x = NSToCoordRound(aPoints[0].x);
|
|
|
|
polypath[0].y = NSToCoordRound(aPoints[0].y);
|
1999-04-19 09:27:55 +04:00
|
|
|
curIndex = 1;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eOutside,c1Index);
|
1999-04-19 09:27:55 +04:00
|
|
|
aRenderingContext.DrawPolyline(polypath,curIndex);
|
2000-05-11 07:59:43 +04:00
|
|
|
polypath[0].x = NSToCoordRound(aPoints[6].x);
|
|
|
|
polypath[0].y = NSToCoordRound(aPoints[6].y);
|
1999-04-19 09:27:55 +04:00
|
|
|
curIndex = 1;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eInside,c1Index);
|
1999-04-19 09:27:55 +04:00
|
|
|
aRenderingContext.DrawPolyline(polypath,curIndex);
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_NONE:
|
1999-08-25 01:47:55 +04:00
|
|
|
case NS_STYLE_BORDER_STYLE_HIDDEN:
|
1999-04-19 09:27:55 +04:00
|
|
|
case NS_STYLE_BORDER_STYLE_BLANK:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_RIDGE:
|
|
|
|
case NS_STYLE_BORDER_STYLE_GROOVE:
|
|
|
|
{
|
2002-08-11 21:56:15 +04:00
|
|
|
const nsStyleBackground* bgColor = nsCSSRendering::FindNonTransparentBackground(aStyleContext);
|
1999-04-19 09:27:55 +04:00
|
|
|
aRenderingContext.SetColor ( MakeBevelColor (aSide, border_Style, bgColor->mBackgroundColor,sideColor, PR_TRUE));
|
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
polypath[0].x = NSToCoordRound(aPoints[0].x);
|
|
|
|
polypath[0].y = NSToCoordRound(aPoints[0].y);
|
1999-04-19 09:27:55 +04:00
|
|
|
curIndex = 1;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eOutside,c1Index);
|
2000-05-11 07:59:43 +04:00
|
|
|
polypath[curIndex].x = NSToCoordRound((aPoints[5].x + aPoints[6].x)/2.0f);
|
|
|
|
polypath[curIndex].y = NSToCoordRound((aPoints[5].y + aPoints[6].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
curIndex++;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eCalcRev,c1Index,.5);
|
2000-05-11 07:59:43 +04:00
|
|
|
polypath[curIndex].x = NSToCoordRound(aPoints[0].x);
|
|
|
|
polypath[curIndex].y = NSToCoordRound(aPoints[0].y);
|
1999-04-19 09:27:55 +04:00
|
|
|
curIndex++;
|
|
|
|
aRenderingContext.FillPolygon(polypath,curIndex);
|
|
|
|
|
|
|
|
aRenderingContext.SetColor ( MakeBevelColor (aSide,
|
|
|
|
((border_Style == NS_STYLE_BORDER_STYLE_RIDGE) ?
|
|
|
|
NS_STYLE_BORDER_STYLE_GROOVE :
|
|
|
|
NS_STYLE_BORDER_STYLE_RIDGE),
|
|
|
|
bgColor->mBackgroundColor,sideColor, PR_TRUE));
|
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
polypath[0].x = NSToCoordRound((aPoints[0].x + aPoints[11].x)/2.0f);
|
|
|
|
polypath[0].y = NSToCoordRound((aPoints[0].y + aPoints[11].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
curIndex = 1;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eCalc,c1Index,.5);
|
2000-05-11 07:59:43 +04:00
|
|
|
polypath[curIndex].x = NSToCoordRound(aPoints[6].x) ;
|
|
|
|
polypath[curIndex].y = NSToCoordRound(aPoints[6].y);
|
1999-04-19 09:27:55 +04:00
|
|
|
curIndex++;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eInside,c1Index);
|
2000-05-11 07:59:43 +04:00
|
|
|
polypath[curIndex].x = NSToCoordRound(aPoints[0].x);
|
|
|
|
polypath[curIndex].y = NSToCoordRound(aPoints[0].y);
|
1999-04-19 09:27:55 +04:00
|
|
|
curIndex++;
|
|
|
|
aRenderingContext.FillPolygon(polypath,curIndex);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
1999-04-21 18:23:49 +04:00
|
|
|
* See documentation in nsCSSRendering.h
|
|
|
|
* @update 3/26/99 dwc
|
1999-04-19 09:27:55 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
RoundedRect::CalcInsetCurves(QBCurve &aULCurve,QBCurve &aURCurve,QBCurve &aLLCurve,QBCurve &aLRCurve,nsMargin &aBorder)
|
|
|
|
{
|
2000-05-11 07:59:43 +04:00
|
|
|
PRInt32 nLeft,nTop,nRight,nBottom;
|
|
|
|
PRInt32 tLeft,bLeft,tRight,bRight,lTop,rTop,lBottom,rBottom;
|
|
|
|
PRInt16 adjust=0;
|
1999-08-27 18:37:47 +04:00
|
|
|
|
|
|
|
if(mDoRound)
|
1999-12-23 23:48:07 +03:00
|
|
|
adjust = mRoundness[0]>>3;
|
|
|
|
|
|
|
|
nLeft = mLeft + aBorder.left;
|
|
|
|
tLeft = mLeft + mRoundness[0];
|
|
|
|
bLeft = mLeft + mRoundness[3];
|
|
|
|
|
|
|
|
if(tLeft < nLeft){
|
|
|
|
tLeft = nLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(bLeft < nLeft){
|
|
|
|
bLeft = nLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
nRight = mRight - aBorder.right;
|
|
|
|
tRight = mRight - mRoundness[1];
|
|
|
|
bRight = mRight - mRoundness[2];
|
|
|
|
|
|
|
|
if(tRight > nRight){
|
|
|
|
tRight = nRight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(bRight > nRight){
|
|
|
|
bRight = nRight;
|
|
|
|
}
|
|
|
|
|
|
|
|
nTop = mTop + aBorder.top;
|
|
|
|
lTop = mTop + mRoundness[0];
|
|
|
|
rTop = mTop + mRoundness[1];
|
|
|
|
|
|
|
|
if(lTop < nTop){
|
|
|
|
lTop = nTop;
|
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
|
1999-12-23 23:48:07 +03:00
|
|
|
if(rTop < nTop){
|
|
|
|
rTop = nTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
nBottom = mBottom - aBorder.bottom;
|
|
|
|
lBottom = mBottom - mRoundness[3];
|
|
|
|
rBottom = mBottom - mRoundness[2];
|
1999-04-19 09:27:55 +04:00
|
|
|
|
1999-12-23 23:48:07 +03:00
|
|
|
if(lBottom > nBottom){
|
|
|
|
lBottom = nBottom;
|
1999-04-21 18:23:49 +04:00
|
|
|
}
|
|
|
|
|
1999-12-23 23:48:07 +03:00
|
|
|
if(rBottom > nBottom){
|
|
|
|
rBottom = nBottom;
|
1999-04-21 18:23:49 +04:00
|
|
|
}
|
|
|
|
|
1999-12-23 23:48:07 +03:00
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
// set the passed in curves to the rounded borders of the rectangle
|
2000-05-11 07:59:43 +04:00
|
|
|
aULCurve.SetPoints( (float)nLeft,(float)lTop,
|
|
|
|
(float)nLeft+adjust,(float)nTop+adjust,
|
|
|
|
(float)tLeft,(float)nTop);
|
|
|
|
aURCurve.SetPoints( (float)tRight,(float)nTop,
|
|
|
|
(float)nRight-adjust,(float)nTop+adjust,
|
|
|
|
(float)nRight,(float)rTop);
|
|
|
|
aLRCurve.SetPoints( (float)nRight,(float)rBottom,
|
|
|
|
(float)nRight-adjust,(float)nBottom-adjust,
|
|
|
|
(float)bRight,(float)nBottom);
|
|
|
|
aLLCurve.SetPoints( (float)bLeft,(float)nBottom,
|
|
|
|
(float)nLeft+adjust,(float)nBottom-adjust,
|
|
|
|
(float)nLeft,(float)lBottom);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
1999-04-21 18:23:49 +04:00
|
|
|
* See documentation in nsCSSRendering.h
|
1999-04-19 09:27:55 +04:00
|
|
|
* @update 4/13/99 dwc
|
|
|
|
*/
|
|
|
|
void
|
1999-12-23 23:48:07 +03:00
|
|
|
RoundedRect::Set(nscoord aLeft,nscoord aTop,PRInt32 aWidth,PRInt32 aHeight,PRInt16 aRadius[4],PRInt16 aNumTwipPerPix)
|
1999-04-19 09:27:55 +04:00
|
|
|
{
|
2000-03-30 10:27:32 +04:00
|
|
|
nscoord x,y,width,height;
|
|
|
|
int i;
|
1999-10-20 18:46:27 +04:00
|
|
|
|
|
|
|
// convert this rect to pixel boundaries
|
|
|
|
x = (aLeft/aNumTwipPerPix)*aNumTwipPerPix;
|
|
|
|
y = (aTop/aNumTwipPerPix)*aNumTwipPerPix;
|
|
|
|
width = (aWidth/aNumTwipPerPix)*aNumTwipPerPix;
|
|
|
|
height = (aHeight/aNumTwipPerPix)*aNumTwipPerPix;
|
1999-04-21 18:23:49 +04:00
|
|
|
|
|
|
|
|
1999-12-23 23:48:07 +03:00
|
|
|
for(i=0;i<4;i++) {
|
|
|
|
if( (aRadius[i]) > (aWidth>>1) ){
|
|
|
|
mRoundness[i] = (aWidth>>1);
|
|
|
|
} else {
|
|
|
|
mRoundness[i] = aRadius[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if( mRoundness[i] > (aHeight>>1) )
|
|
|
|
mRoundness[i] = aHeight>>1;
|
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
|
1999-08-27 18:37:47 +04:00
|
|
|
|
2000-01-14 17:43:05 +03:00
|
|
|
// if we are drawing a circle
|
|
|
|
mDoRound = PR_FALSE;
|
|
|
|
if(aHeight==aWidth){
|
2000-08-17 12:26:53 +04:00
|
|
|
PRBool doRound = PR_TRUE;
|
2000-01-14 17:43:05 +03:00
|
|
|
for(i=0;i<4;i++){
|
|
|
|
if(mRoundness[i]<(aWidth>>1)){
|
|
|
|
doRound = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(doRound){
|
|
|
|
mDoRound = PR_TRUE;
|
|
|
|
for(i=0;i<4;i++){
|
|
|
|
mRoundness[i] = aWidth>>1;
|
|
|
|
}
|
|
|
|
}
|
1999-08-27 18:37:47 +04:00
|
|
|
}
|
|
|
|
|
2000-01-14 17:43:05 +03:00
|
|
|
|
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
// important coordinates that the path hits
|
1999-12-23 23:48:07 +03:00
|
|
|
mLeft = x;
|
|
|
|
mTop = y;
|
|
|
|
mRight = x+width;
|
|
|
|
mBottom = y+height;
|
1999-04-21 18:23:49 +04:00
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
1999-04-21 18:23:49 +04:00
|
|
|
* See documentation in nsCSSRendering.h
|
1999-04-19 09:27:55 +04:00
|
|
|
* @update 4/13/99 dwc
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RoundedRect::GetRoundedBorders(QBCurve &aULCurve,QBCurve &aURCurve,QBCurve &aLLCurve,QBCurve &aLRCurve)
|
|
|
|
{
|
|
|
|
|
2000-03-30 10:27:32 +04:00
|
|
|
PRInt16 adjust=0;
|
1999-08-27 18:37:47 +04:00
|
|
|
|
|
|
|
if(mDoRound)
|
1999-12-23 23:48:07 +03:00
|
|
|
adjust = mRoundness[0]>>3;
|
1999-08-27 18:37:47 +04:00
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
// set the passed in curves to the rounded borders of the rectangle
|
2000-05-11 07:59:43 +04:00
|
|
|
aULCurve.SetPoints( (float)mLeft,(float)mTop + mRoundness[0],
|
|
|
|
(float)mLeft+adjust,(float)mTop+adjust,
|
|
|
|
(float)mLeft+mRoundness[0],(float)mTop);
|
|
|
|
aURCurve.SetPoints( (float)mRight - mRoundness[1],(float)mTop,
|
|
|
|
(float)mRight-adjust,(float)mTop+adjust,
|
|
|
|
(float)mRight,(float)mTop + mRoundness[1]);
|
|
|
|
aLRCurve.SetPoints( (float)mRight,(float)mBottom - mRoundness[2],
|
|
|
|
(float)mRight-adjust,(float)mBottom-adjust,
|
|
|
|
(float)mRight - mRoundness[2],(float)mBottom);
|
|
|
|
aLLCurve.SetPoints( (float)mLeft + mRoundness[3],(float)mBottom,
|
|
|
|
(float)mLeft+adjust,(float)mBottom-adjust,
|
|
|
|
(float)mLeft,(float)mBottom - mRoundness[3]);
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
* Given a qbezier path, convert it into a polygon path
|
|
|
|
* @update 3/26/99 dwc
|
1999-04-21 18:23:49 +04:00
|
|
|
* @param aPoints -- an array of points to use for the path
|
|
|
|
* @param aPolyPath -- an array of points containing the flattened polygon to use
|
|
|
|
* @param aCurIndex -- the index that points to the last element of the array
|
|
|
|
* @param aPathType -- what kind of path that should be returned
|
|
|
|
* @param aFrac -- the inset amount for a eCalc type path
|
1999-04-19 09:27:55 +04:00
|
|
|
*/
|
|
|
|
static void
|
2000-05-11 07:59:43 +04:00
|
|
|
GetPath(nsFloatPoint aPoints[],nsPoint aPolyPath[],PRInt32 *aCurIndex,ePathTypes aPathType,PRInt32 &aC1Index,float aFrac)
|
1999-04-19 09:27:55 +04:00
|
|
|
{
|
2000-03-30 10:27:32 +04:00
|
|
|
QBCurve thecurve;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
switch (aPathType) {
|
|
|
|
case eOutside:
|
|
|
|
thecurve.SetPoints(aPoints[0].x,aPoints[0].y,aPoints[1].x,aPoints[1].y,aPoints[2].x,aPoints[2].y);
|
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
1999-04-21 18:23:49 +04:00
|
|
|
aC1Index = *aCurIndex;
|
2000-05-11 07:59:43 +04:00
|
|
|
aPolyPath[*aCurIndex].x = (nscoord)aPoints[3].x;
|
|
|
|
aPolyPath[*aCurIndex].y = (nscoord)aPoints[3].y;
|
1999-04-19 09:27:55 +04:00
|
|
|
(*aCurIndex)++;
|
|
|
|
thecurve.SetPoints(aPoints[3].x,aPoints[3].y,aPoints[4].x,aPoints[4].y,aPoints[5].x,aPoints[5].y);
|
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
|
|
|
break;
|
|
|
|
case eInside:
|
|
|
|
thecurve.SetPoints(aPoints[6].x,aPoints[6].y,aPoints[7].x,aPoints[7].y,aPoints[8].x,aPoints[8].y);
|
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
2000-05-11 07:59:43 +04:00
|
|
|
aPolyPath[*aCurIndex].x = (nscoord)aPoints[9].x;
|
|
|
|
aPolyPath[*aCurIndex].y = (nscoord)aPoints[9].y;
|
1999-04-19 09:27:55 +04:00
|
|
|
(*aCurIndex)++;
|
|
|
|
thecurve.SetPoints(aPoints[9].x,aPoints[9].y,aPoints[10].x,aPoints[10].y,aPoints[11].x,aPoints[11].y);
|
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
|
|
|
break;
|
|
|
|
case eCalc:
|
2000-05-11 07:59:43 +04:00
|
|
|
thecurve.SetPoints( (aPoints[0].x+aPoints[11].x)/2.0f,(aPoints[0].y+aPoints[11].y)/2.0f,
|
|
|
|
(aPoints[1].x+aPoints[10].x)/2.0f,(aPoints[1].y+aPoints[10].y)/2.0f,
|
|
|
|
(aPoints[2].x+aPoints[9].x)/2.0f,(aPoints[2].y+aPoints[9].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
2000-05-11 07:59:43 +04:00
|
|
|
aPolyPath[*aCurIndex].x = (nscoord)((aPoints[3].x+aPoints[8].x)/2.0f);
|
|
|
|
aPolyPath[*aCurIndex].y = (nscoord)((aPoints[3].y+aPoints[8].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
(*aCurIndex)++;
|
2000-05-11 07:59:43 +04:00
|
|
|
thecurve.SetPoints( (aPoints[3].x+aPoints[8].x)/2.0f,(aPoints[3].y+aPoints[8].y)/2.0f,
|
|
|
|
(aPoints[4].x+aPoints[7].x)/2.0f,(aPoints[4].y+aPoints[7].y)/2.0f,
|
|
|
|
(aPoints[5].x+aPoints[6].x)/2.0f,(aPoints[5].y+aPoints[6].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
|
|
|
break;
|
|
|
|
case eCalcRev:
|
2000-05-11 07:59:43 +04:00
|
|
|
thecurve.SetPoints( (aPoints[5].x+aPoints[6].x)/2.0f,(aPoints[5].y+aPoints[6].y)/2.0f,
|
|
|
|
(aPoints[4].x+aPoints[7].x)/2.0f,(aPoints[4].y+aPoints[7].y)/2.0f,
|
|
|
|
(aPoints[3].x+aPoints[8].x)/2.0f,(aPoints[3].y+aPoints[8].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
2000-05-11 07:59:43 +04:00
|
|
|
aPolyPath[*aCurIndex].x = (nscoord)((aPoints[2].x+aPoints[9].x)/2.0f);
|
|
|
|
aPolyPath[*aCurIndex].y = (nscoord)((aPoints[2].y+aPoints[9].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
(*aCurIndex)++;
|
2000-05-11 07:59:43 +04:00
|
|
|
thecurve.SetPoints( (aPoints[2].x+aPoints[9].x)/2.0f,(aPoints[2].y+aPoints[9].y)/2.0f,
|
|
|
|
(aPoints[1].x+aPoints[10].x)/2.0f,(aPoints[1].y+aPoints[10].y)/2.0f,
|
|
|
|
(aPoints[0].x+aPoints[11].x)/2.0f,(aPoints[0].y+aPoints[11].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
1999-04-21 18:23:49 +04:00
|
|
|
* See documentation in nsCSSRendering.h
|
|
|
|
* @update 4/13/99 dwc
|
1999-04-19 09:27:55 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
QBCurve::SubDivide(nsIRenderingContext *aRenderingContext,nsPoint aPointArray[],PRInt32 *aCurIndex)
|
|
|
|
{
|
2000-03-30 10:27:32 +04:00
|
|
|
QBCurve curve1,curve2;
|
2000-05-11 07:59:43 +04:00
|
|
|
float fx,fy,smag;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
// divide the curve into 2 pieces
|
|
|
|
MidPointDivide(&curve1,&curve2);
|
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
fx = (float)fabs(curve1.mAnc2.x - this->mCon.x);
|
|
|
|
fy = (float)fabs(curve1.mAnc2.y - this->mCon.y);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
//smag = fx+fy-(PR_MIN(fx,fy)>>1);
|
|
|
|
smag = fx*fx + fy*fy;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
1999-08-24 18:51:16 +04:00
|
|
|
if (smag>1){
|
1999-04-19 09:27:55 +04:00
|
|
|
// split the curve again
|
|
|
|
curve1.SubDivide(aRenderingContext,aPointArray,aCurIndex);
|
|
|
|
curve2.SubDivide(aRenderingContext,aPointArray,aCurIndex);
|
|
|
|
}else{
|
|
|
|
if(aPointArray ) {
|
|
|
|
// save the points for further processing
|
2000-05-11 07:59:43 +04:00
|
|
|
aPointArray[*aCurIndex].x = (nscoord)curve1.mAnc2.x;
|
|
|
|
aPointArray[*aCurIndex].y = (nscoord)curve1.mAnc2.y;
|
1999-04-19 09:27:55 +04:00
|
|
|
(*aCurIndex)++;
|
2000-05-11 07:59:43 +04:00
|
|
|
aPointArray[*aCurIndex].x = (nscoord)curve2.mAnc2.x;
|
|
|
|
aPointArray[*aCurIndex].y = (nscoord)curve2.mAnc2.y;
|
1999-04-19 09:27:55 +04:00
|
|
|
(*aCurIndex)++;
|
|
|
|
}else{
|
|
|
|
// draw the curve
|
1999-08-24 18:51:16 +04:00
|
|
|
nsTransform2D *aTransform;
|
|
|
|
aRenderingContext->GetCurrentTransform(aTransform);
|
|
|
|
|
1999-08-27 18:37:47 +04:00
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
aRenderingContext->DrawLine((nscoord)curve1.mAnc1.x,(nscoord)curve1.mAnc1.y,(nscoord)curve1.mAnc2.x,(nscoord)curve1.mAnc2.y);
|
|
|
|
aRenderingContext->DrawLine((nscoord)curve1.mAnc2.x,(nscoord)curve1.mAnc2.y,(nscoord)curve2.mAnc2.x,(nscoord)curve2.mAnc2.y);
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
1999-04-21 18:23:49 +04:00
|
|
|
* See documentation in nsCSSRendering.h
|
|
|
|
* @update 4/13/99 dwc
|
1999-04-19 09:27:55 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
QBCurve::MidPointDivide(QBCurve *A,QBCurve *B)
|
|
|
|
{
|
2000-05-11 07:59:43 +04:00
|
|
|
float c1x,c1y,c2x,c2y;
|
|
|
|
nsFloatPoint a1;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
c1x = (mAnc1.x+mCon.x)/2.0f;
|
|
|
|
c1y = (mAnc1.y+mCon.y)/2.0f;
|
|
|
|
c2x = (mAnc2.x+mCon.x)/2.0f;
|
|
|
|
c2y = (mAnc2.y+mCon.y)/2.0f;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
a1.x = (c1x + c2x)/2.0f;
|
|
|
|
a1.y = (c1y + c2y)/2.0f;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
// put the math into our 2 new curves
|
|
|
|
A->mAnc1 = this->mAnc1;
|
2000-05-11 07:59:43 +04:00
|
|
|
A->mCon.x = c1x;
|
|
|
|
A->mCon.y = c1y;
|
1999-04-19 09:27:55 +04:00
|
|
|
A->mAnc2 = a1;
|
|
|
|
B->mAnc1 = a1;
|
2000-05-11 07:59:43 +04:00
|
|
|
B->mCon.x = c2x;
|
|
|
|
B->mCon.y = c2y;
|
1999-04-19 09:27:55 +04:00
|
|
|
B->mAnc2 = this->mAnc2;
|
|
|
|
}
|
2001-10-03 04:08:25 +04:00
|
|
|
|
|
|
|
void FillOrInvertRect(nsIRenderingContext& aRC, nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, PRBool aInvert)
|
|
|
|
{
|
|
|
|
if (aInvert) {
|
|
|
|
aRC.InvertRect(aX, aY, aWidth, aHeight);
|
|
|
|
} else {
|
|
|
|
aRC.FillRect(aX, aY, aWidth, aHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FillOrInvertRect(nsIRenderingContext& aRC, const nsRect& aRect, PRBool aInvert)
|
|
|
|
{
|
|
|
|
if (aInvert) {
|
|
|
|
aRC.InvertRect(aRect);
|
|
|
|
} else {
|
|
|
|
aRC.FillRect(aRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-19 18:48:28 +03:00
|
|
|
// Begin table border-collapsing section
|
|
|
|
// These functions were written to not disrupt the normal ones and yet satisfy some additional requirements
|
|
|
|
// At some point, all functions should be unified to include the additional functionality that these provide
|
|
|
|
|
|
|
|
static nscoord
|
|
|
|
RoundIntToPixel(nscoord aValue,
|
|
|
|
nscoord aTwipsPerPixel,
|
|
|
|
PRBool aRoundDown = PR_FALSE)
|
|
|
|
{
|
2002-04-07 02:28:39 +04:00
|
|
|
if (aTwipsPerPixel <= 0)
|
|
|
|
// We must be rendering to a device that has a resolution greater than Twips!
|
|
|
|
// In that case, aValue is as accurate as it's going to get.
|
|
|
|
return aValue;
|
|
|
|
|
2002-02-19 18:48:28 +03:00
|
|
|
nscoord halfPixel = NSToCoordRound(aTwipsPerPixel / 2.0f);
|
|
|
|
nscoord extra = aValue % aTwipsPerPixel;
|
|
|
|
nscoord finalValue = (!aRoundDown && (extra >= halfPixel)) ? aValue + (aTwipsPerPixel - extra) : aValue - extra;
|
|
|
|
return finalValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nscoord
|
|
|
|
RoundFloatToPixel(float aValue,
|
|
|
|
nscoord aTwipsPerPixel,
|
|
|
|
PRBool aRoundDown = PR_FALSE)
|
|
|
|
{
|
|
|
|
return RoundIntToPixel(NSToCoordRound(aValue), aTwipsPerPixel, aRoundDown);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetPoly(const nsRect& aRect,
|
|
|
|
nsPoint* poly)
|
|
|
|
{
|
|
|
|
poly[0].x = aRect.x;
|
|
|
|
poly[0].y = aRect.y;
|
|
|
|
poly[1].x = aRect.x + aRect.width;
|
|
|
|
poly[1].y = aRect.y;
|
|
|
|
poly[2].x = aRect.x + aRect.width;
|
|
|
|
poly[2].y = aRect.y + aRect.height;
|
|
|
|
poly[3].x = aRect.x;
|
|
|
|
poly[3].y = aRect.y + aRect.height;
|
|
|
|
poly[4].x = aRect.x;
|
|
|
|
poly[4].y = aRect.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DrawSolidBorderSegment(nsIRenderingContext& aContext,
|
|
|
|
nsRect aRect,
|
|
|
|
nscoord aTwipsPerPixel,
|
|
|
|
PRUint8 aStartBevelSide = 0,
|
|
|
|
nscoord aStartBevelOffset = 0,
|
|
|
|
PRUint8 aEndBevelSide = 0,
|
|
|
|
nscoord aEndBevelOffset = 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((aRect.width == aTwipsPerPixel) || (aRect.height == aTwipsPerPixel) ||
|
|
|
|
((0 == aStartBevelOffset) && (0 == aEndBevelOffset))) {
|
|
|
|
// simple line or rectangle
|
|
|
|
if ((NS_SIDE_TOP == aStartBevelSide) || (NS_SIDE_BOTTOM == aStartBevelSide)) {
|
|
|
|
if (1 == aRect.height)
|
|
|
|
aContext.DrawLine(aRect.x, aRect.y, aRect.x, aRect.y + aRect.height);
|
|
|
|
else
|
|
|
|
aContext.FillRect(aRect);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (1 == aRect.width)
|
|
|
|
aContext.DrawLine(aRect.x, aRect.y, aRect.x + aRect.width, aRect.y);
|
|
|
|
else
|
|
|
|
aContext.FillRect(aRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// polygon with beveling
|
|
|
|
nsPoint poly[5];
|
|
|
|
SetPoly(aRect, poly);
|
|
|
|
switch(aStartBevelSide) {
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
poly[0].x += aStartBevelOffset;
|
|
|
|
poly[4].x = poly[0].x;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
poly[3].x += aStartBevelOffset;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
poly[1].y += aStartBevelOffset;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
poly[0].y += aStartBevelOffset;
|
|
|
|
poly[4].y = poly[0].y;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(aEndBevelSide) {
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
poly[1].x -= aEndBevelOffset;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
poly[2].x -= aEndBevelOffset;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
poly[2].y -= aEndBevelOffset;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
poly[3].y -= aEndBevelOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
aContext.FillPolygon(poly, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetDashInfo(nscoord aBorderLength,
|
|
|
|
nscoord aDashLength,
|
|
|
|
nscoord aTwipsPerPixel,
|
|
|
|
PRInt32& aNumDashSpaces,
|
|
|
|
nscoord& aStartDashLength,
|
|
|
|
nscoord& aEndDashLength)
|
|
|
|
{
|
|
|
|
aNumDashSpaces = 0;
|
|
|
|
if (aStartDashLength + aDashLength + aEndDashLength >= aBorderLength) {
|
|
|
|
aStartDashLength = aBorderLength;
|
|
|
|
aEndDashLength = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aNumDashSpaces = aBorderLength / (2 * aDashLength); // round down
|
|
|
|
nscoord extra = aBorderLength - aStartDashLength - aEndDashLength - (((2 * aNumDashSpaces) - 1) * aDashLength);
|
|
|
|
if (extra > 0) {
|
|
|
|
nscoord half = RoundIntToPixel(extra / 2, aTwipsPerPixel);
|
|
|
|
aStartDashLength += half;
|
|
|
|
aEndDashLength += (extra - half);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSRendering::DrawTableBorderSegment(nsIRenderingContext& aContext,
|
|
|
|
PRUint8 aBorderStyle,
|
|
|
|
nscolor aBorderColor,
|
|
|
|
const nsStyleBackground* aBGColor,
|
|
|
|
const nsRect& aBorder,
|
|
|
|
float aPixelsToTwips,
|
|
|
|
PRUint8 aStartBevelSide,
|
|
|
|
nscoord aStartBevelOffset,
|
|
|
|
PRUint8 aEndBevelSide,
|
|
|
|
nscoord aEndBevelOffset)
|
|
|
|
{
|
|
|
|
aContext.SetColor (aBorderColor);
|
|
|
|
|
|
|
|
PRBool horizontal = ((NS_SIDE_TOP == aStartBevelSide) || (NS_SIDE_BOTTOM == aStartBevelSide));
|
|
|
|
nscoord twipsPerPixel = NSIntPixelsToTwips(1, aPixelsToTwips);
|
|
|
|
PRBool ridgeGroove = NS_STYLE_BORDER_STYLE_RIDGE;
|
|
|
|
|
|
|
|
if ((twipsPerPixel >= aBorder.width) || (twipsPerPixel >= aBorder.height) ||
|
|
|
|
(NS_STYLE_BORDER_STYLE_DASHED == aBorderStyle) || (NS_STYLE_BORDER_STYLE_DOTTED == aBorderStyle)) {
|
|
|
|
// no beveling for 1 pixel border, dash or dot
|
|
|
|
aStartBevelOffset = 0;
|
|
|
|
aEndBevelOffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aBorderStyle) {
|
|
|
|
case NS_STYLE_BORDER_STYLE_NONE:
|
|
|
|
case NS_STYLE_BORDER_STYLE_HIDDEN:
|
|
|
|
case NS_STYLE_BORDER_STYLE_BLANK:
|
|
|
|
//NS_ASSERTION(PR_FALSE, "style of none, hidden, or blank");
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOTTED:
|
|
|
|
case NS_STYLE_BORDER_STYLE_DASHED:
|
|
|
|
{
|
|
|
|
nscoord dashLength = (NS_STYLE_BORDER_STYLE_DASHED == aBorderStyle) ? DASH_LENGTH : DOT_LENGTH;
|
|
|
|
// make the dash length proportional to the border thickness
|
|
|
|
dashLength *= (horizontal) ? aBorder.height : aBorder.width;
|
|
|
|
// make the min dash length for the ends 1/2 the dash length
|
|
|
|
nscoord minDashLength = (NS_STYLE_BORDER_STYLE_DASHED == aBorderStyle)
|
|
|
|
? RoundFloatToPixel(((float)dashLength) / 2.0f, twipsPerPixel) : dashLength;
|
|
|
|
minDashLength = PR_MAX(minDashLength, twipsPerPixel);
|
|
|
|
nscoord numDashSpaces = 0;
|
|
|
|
nscoord startDashLength = minDashLength;
|
|
|
|
nscoord endDashLength = minDashLength;
|
|
|
|
if (horizontal) {
|
|
|
|
GetDashInfo(aBorder.width, dashLength, twipsPerPixel, numDashSpaces, startDashLength, endDashLength);
|
|
|
|
nsRect rect(aBorder.x, aBorder.y, startDashLength, aBorder.height);
|
|
|
|
DrawSolidBorderSegment(aContext, rect, PR_TRUE);
|
|
|
|
for (PRInt32 spaceX = 0; spaceX < numDashSpaces; spaceX++) {
|
|
|
|
rect.x += rect.width + dashLength;
|
|
|
|
rect.width = (spaceX == (numDashSpaces - 1)) ? endDashLength : dashLength;
|
|
|
|
DrawSolidBorderSegment(aContext, rect, PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GetDashInfo(aBorder.height, dashLength, twipsPerPixel, numDashSpaces, startDashLength, endDashLength);
|
|
|
|
nsRect rect(aBorder.x, aBorder.y, aBorder.width, startDashLength);
|
|
|
|
DrawSolidBorderSegment(aContext, rect, PR_FALSE);
|
|
|
|
for (PRInt32 spaceY = 0; spaceY < numDashSpaces; spaceY++) {
|
|
|
|
rect.y += rect.height + dashLength;
|
|
|
|
rect.height = (spaceY == (numDashSpaces - 1)) ? endDashLength : dashLength;
|
|
|
|
DrawSolidBorderSegment(aContext, rect, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_GROOVE:
|
|
|
|
ridgeGroove = NS_STYLE_BORDER_STYLE_GROOVE; // and fall through to ridge
|
|
|
|
case NS_STYLE_BORDER_STYLE_RIDGE:
|
|
|
|
if ((horizontal && (twipsPerPixel >= aBorder.height)) ||
|
|
|
|
(!horizontal && (twipsPerPixel >= aBorder.width))) {
|
|
|
|
// a one pixel border
|
|
|
|
DrawSolidBorderSegment(aContext, aBorder, twipsPerPixel, aStartBevelSide, aStartBevelOffset,
|
|
|
|
aEndBevelSide, aEndBevelOffset);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nscoord startBevel = (aStartBevelOffset > 0)
|
|
|
|
? RoundFloatToPixel(0.5f * (float)aStartBevelOffset, twipsPerPixel, PR_TRUE) : 0;
|
|
|
|
nscoord endBevel = (aEndBevelOffset > 0)
|
|
|
|
? RoundFloatToPixel(0.5f * (float)aEndBevelOffset, twipsPerPixel, PR_TRUE) : 0;
|
|
|
|
PRUint8 ridgeGrooveSide = (horizontal) ? NS_SIDE_TOP : NS_SIDE_LEFT;
|
|
|
|
aContext.SetColor (
|
|
|
|
MakeBevelColor (ridgeGrooveSide, ridgeGroove, aBGColor->mBackgroundColor, aBorderColor, PR_TRUE));
|
|
|
|
nsRect rect(aBorder);
|
|
|
|
nscoord half;
|
|
|
|
if (horizontal) { // top, bottom
|
|
|
|
half = RoundFloatToPixel(0.5f * (float)aBorder.height, twipsPerPixel);
|
|
|
|
rect.height = half;
|
|
|
|
if (NS_SIDE_TOP == aStartBevelSide) {
|
|
|
|
rect.x += startBevel;
|
|
|
|
rect.width -= startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_TOP == aEndBevelSide) {
|
|
|
|
rect.width -= endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
}
|
|
|
|
else { // left, right
|
|
|
|
half = RoundFloatToPixel(0.5f * (float)aBorder.width, twipsPerPixel);
|
|
|
|
rect.width = half;
|
|
|
|
if (NS_SIDE_LEFT == aStartBevelSide) {
|
|
|
|
rect.y += startBevel;
|
|
|
|
rect.height -= startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_LEFT == aEndBevelSide) {
|
|
|
|
rect.height -= endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
rect = aBorder;
|
|
|
|
ridgeGrooveSide = (NS_SIDE_TOP == ridgeGrooveSide) ? NS_SIDE_BOTTOM : NS_SIDE_RIGHT;
|
|
|
|
aContext.SetColor (
|
|
|
|
MakeBevelColor (ridgeGrooveSide, ridgeGroove, aBGColor->mBackgroundColor, aBorderColor, PR_TRUE));
|
|
|
|
if (horizontal) {
|
|
|
|
rect.y = rect.y + half;
|
|
|
|
rect.height = aBorder.height - half;
|
|
|
|
if (NS_SIDE_BOTTOM == aStartBevelSide) {
|
|
|
|
rect.x += startBevel;
|
|
|
|
rect.width -= startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_BOTTOM == aEndBevelSide) {
|
|
|
|
rect.width -= endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rect.x = rect.x + half;
|
|
|
|
rect.width = aBorder.width - half;
|
|
|
|
if (NS_SIDE_RIGHT == aStartBevelSide) {
|
|
|
|
rect.y += aStartBevelOffset - startBevel;
|
|
|
|
rect.height -= startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_RIGHT == aEndBevelSide) {
|
|
|
|
rect.height -= endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOUBLE:
|
|
|
|
if ((aBorder.width > 2) && (aBorder.height > 2)) {
|
|
|
|
nscoord startBevel = (aStartBevelOffset > 0)
|
|
|
|
? RoundFloatToPixel(0.333333f * (float)aStartBevelOffset, twipsPerPixel) : 0;
|
|
|
|
nscoord endBevel = (aEndBevelOffset > 0)
|
|
|
|
? RoundFloatToPixel(0.333333f * (float)aEndBevelOffset, twipsPerPixel) : 0;
|
|
|
|
if (horizontal) { // top, bottom
|
|
|
|
nscoord thirdHeight = RoundFloatToPixel(0.333333f * (float)aBorder.height, twipsPerPixel);
|
|
|
|
|
|
|
|
// draw the top line or rect
|
|
|
|
nsRect topRect(aBorder.x, aBorder.y, aBorder.width, thirdHeight);
|
|
|
|
if (NS_SIDE_TOP == aStartBevelSide) {
|
|
|
|
topRect.x += aStartBevelOffset - startBevel;
|
|
|
|
topRect.width -= aStartBevelOffset - startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_TOP == aEndBevelSide) {
|
|
|
|
topRect.width -= aEndBevelOffset - endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, topRect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
|
|
|
|
// draw the botom line or rect
|
|
|
|
nscoord heightOffset = aBorder.height - thirdHeight;
|
|
|
|
nsRect bottomRect(aBorder.x, aBorder.y + heightOffset, aBorder.width, aBorder.height - heightOffset);
|
|
|
|
if (NS_SIDE_BOTTOM == aStartBevelSide) {
|
|
|
|
bottomRect.x += aStartBevelOffset - startBevel;
|
|
|
|
bottomRect.width -= aStartBevelOffset - startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_BOTTOM == aEndBevelSide) {
|
|
|
|
bottomRect.width -= aEndBevelOffset - endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, bottomRect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
}
|
|
|
|
else { // left, right
|
|
|
|
nscoord thirdWidth = RoundFloatToPixel(0.333333f * (float)aBorder.width, twipsPerPixel);
|
|
|
|
|
|
|
|
nsRect leftRect(aBorder.x, aBorder.y, thirdWidth, aBorder.height);
|
|
|
|
if (NS_SIDE_LEFT == aStartBevelSide) {
|
|
|
|
leftRect.y += aStartBevelOffset - startBevel;
|
|
|
|
leftRect.height -= aStartBevelOffset - startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_LEFT == aEndBevelSide) {
|
|
|
|
leftRect.height -= aEndBevelOffset - endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, leftRect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
|
|
|
|
nscoord widthOffset = aBorder.width - thirdWidth;
|
|
|
|
nsRect rightRect(aBorder.x + widthOffset, aBorder.y, aBorder.width - widthOffset, aBorder.height);
|
|
|
|
if (NS_SIDE_RIGHT == aStartBevelSide) {
|
|
|
|
rightRect.y += aStartBevelOffset - startBevel;
|
|
|
|
rightRect.height -= aStartBevelOffset - startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_RIGHT == aEndBevelSide) {
|
|
|
|
rightRect.height -= aEndBevelOffset - endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, rightRect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// else fall through to solid
|
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
|
|
|
DrawSolidBorderSegment(aContext, aBorder, twipsPerPixel, aStartBevelSide,
|
|
|
|
aStartBevelOffset, aEndBevelSide, aEndBevelOffset);
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_BG_OUTSET:
|
|
|
|
case NS_STYLE_BORDER_STYLE_BG_INSET:
|
|
|
|
case NS_STYLE_BORDER_STYLE_OUTSET:
|
|
|
|
case NS_STYLE_BORDER_STYLE_INSET:
|
|
|
|
NS_ASSERTION(PR_FALSE, "inset, outset should have been converted to groove, ridge");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// End table border-collapsing section
|
|
|
|
|