1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIImage.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsPoint.h"
|
|
|
|
#include "nsRect.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIPresShell.h"
|
1998-05-12 02:58:20 +04:00
|
|
|
#include "nsIFrameImageLoader.h"
|
1998-12-18 01:58:51 +03:00
|
|
|
#include "nsIStyleContext.h"
|
1999-01-23 01:24:05 +03:00
|
|
|
#include "nsStyleUtil.h"
|
1999-04-25 06:43:50 +04:00
|
|
|
#include "nsIScrollableView.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kScrollViewIID, NS_ISCROLLABLEVIEW_IID);
|
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
|
|
|
|
};
|
|
|
|
|
1999-04-21 18:23:49 +04:00
|
|
|
static void GetPath(nsPoint aPoints[],nsPoint aPolyPath[],PRInt32 *aCurIndex,ePathTypes aPathType,PRInt32 &aC1Index,float aFrac=0);
|
1999-06-11 18:43:14 +04:00
|
|
|
static void TileImage(nsIRenderingContext& aRC,nsDrawingSurface aDS,nsRect &aSrcRect,PRInt16 aWidth,PRInt16 aHeight,PRInt32 aFlag);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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,
|
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;
|
|
|
|
|
|
|
|
// XXX QQQ We really should decide to do a bevel based on whether there
|
|
|
|
// is a side adjacent or not. This could let you join borders across
|
|
|
|
// block elements (paragraphs).
|
|
|
|
|
|
|
|
PRIntn np = 0;
|
1998-06-18 02:14:20 +04:00
|
|
|
nscoord thickness;
|
|
|
|
|
|
|
|
// Base our thickness check on the segment being less than a pixel and 1/2
|
|
|
|
twipsPerPixel += twipsPerPixel >> 2;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
switch (whichSide) {
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
if (borderPart == BORDER_FULL) {
|
1998-06-18 09:43:32 +04:00
|
|
|
thickness = inside.y - outside.y;
|
1998-06-18 02:14:20 +04:00
|
|
|
|
1998-07-21 13:30:03 +04:00
|
|
|
aPoints[np++].MoveTo(outside.x, outside.y);
|
1998-04-14 00:24:54 +04:00
|
|
|
aPoints[np++].MoveTo(outside.XMost(), outside.y);
|
1998-06-18 02:14:20 +04:00
|
|
|
if (thickness >= twipsPerPixel) {
|
|
|
|
aPoints[np++].MoveTo(inside.XMost(), inside.y);
|
|
|
|
aPoints[np++].MoveTo(inside.x, inside.y);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
} else if (borderPart == BORDER_INSIDE) {
|
|
|
|
aPoints[np++].MoveTo(nscoord(outside.x * borderFrac +
|
|
|
|
inside.x * borderRest),
|
|
|
|
nscoord(outside.y * borderFrac +
|
|
|
|
inside.y * borderRest));
|
|
|
|
aPoints[np++].MoveTo(nscoord(outside.XMost() * borderFrac +
|
|
|
|
inside.XMost() * borderRest),
|
|
|
|
nscoord(outside.y * borderFrac +
|
|
|
|
inside.y * borderRest));
|
|
|
|
aPoints[np++].MoveTo(inside.XMost(), inside.y);
|
|
|
|
aPoints[np++].MoveTo(inside.x, inside.y);
|
|
|
|
} else {
|
|
|
|
aPoints[np++].MoveTo(outside.x, outside.y);
|
|
|
|
aPoints[np++].MoveTo(outside.XMost(), outside.y);
|
|
|
|
aPoints[np++].MoveTo(nscoord(inside.XMost() * borderFrac +
|
|
|
|
outside.XMost() * borderRest),
|
|
|
|
nscoord(inside.y * borderFrac +
|
|
|
|
outside.y * borderRest));
|
|
|
|
aPoints[np++].MoveTo(nscoord(inside.x * borderFrac +
|
|
|
|
outside.x * borderRest),
|
|
|
|
nscoord(inside.y * borderFrac +
|
|
|
|
outside.y * borderRest));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
if (borderPart == BORDER_FULL) {
|
1998-06-18 02:14:20 +04:00
|
|
|
thickness = inside.x - outside.x;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
aPoints[np++].MoveTo(outside.x, outside.y);
|
1998-06-18 02:14:20 +04:00
|
|
|
if (thickness >= twipsPerPixel) {
|
|
|
|
aPoints[np++].MoveTo(inside.x, inside.y);
|
|
|
|
aPoints[np++].MoveTo(inside.x, inside.YMost());
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
aPoints[np++].MoveTo(outside.x, outside.YMost());
|
|
|
|
} else if (borderPart == BORDER_INSIDE) {
|
|
|
|
aPoints[np++].MoveTo(nscoord(outside.x * borderFrac +
|
|
|
|
inside.x * borderRest),
|
|
|
|
nscoord(outside.y * borderFrac +
|
|
|
|
inside.y * borderRest));
|
|
|
|
aPoints[np++].MoveTo(inside.x, inside.y);
|
|
|
|
aPoints[np++].MoveTo(inside.x, inside.YMost());
|
|
|
|
aPoints[np++].MoveTo(nscoord(outside.x * borderFrac +
|
|
|
|
inside.x * borderRest),
|
|
|
|
nscoord(outside.YMost() * borderFrac +
|
|
|
|
inside.YMost() * borderRest));
|
|
|
|
} else {
|
|
|
|
aPoints[np++].MoveTo(outside.x, outside.y);
|
|
|
|
aPoints[np++].MoveTo(nscoord(inside.x * borderFrac +
|
|
|
|
outside.x * borderRest),
|
|
|
|
nscoord(inside.y * borderFrac +
|
|
|
|
outside.y * borderRest));
|
|
|
|
aPoints[np++].MoveTo(nscoord(inside.x * borderFrac +
|
|
|
|
outside.x * borderRest),
|
|
|
|
nscoord(inside.YMost() * borderFrac +
|
|
|
|
outside.YMost() * borderRest));
|
|
|
|
aPoints[np++].MoveTo(outside.x, outside.YMost());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
if (borderPart == BORDER_FULL) {
|
1998-06-18 09:43:32 +04:00
|
|
|
thickness = outside.YMost() - inside.YMost();
|
1998-06-18 02:14:20 +04:00
|
|
|
|
|
|
|
if (thickness >= twipsPerPixel) {
|
1998-07-21 13:30:03 +04:00
|
|
|
aPoints[np++].MoveTo(outside.x, outside.YMost());
|
1998-06-18 02:14:20 +04:00
|
|
|
aPoints[np++].MoveTo(inside.x, inside.YMost());
|
|
|
|
aPoints[np++].MoveTo(inside.XMost(), inside.YMost());
|
1998-07-21 13:30:03 +04:00
|
|
|
aPoints[np++].MoveTo(outside.XMost(), outside.YMost());
|
|
|
|
} else {
|
|
|
|
aPoints[np++].MoveTo(outside.x, inside.YMost());
|
|
|
|
aPoints[np++].MoveTo(outside.XMost(), inside.YMost());
|
1998-06-18 02:14:20 +04:00
|
|
|
}
|
1998-07-21 13:30:03 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
} else if (borderPart == BORDER_INSIDE) {
|
|
|
|
aPoints[np++].MoveTo(nscoord(outside.x * borderFrac +
|
|
|
|
inside.x * borderRest),
|
|
|
|
nscoord(outside.YMost() * borderFrac +
|
|
|
|
inside.YMost() * borderRest));
|
|
|
|
aPoints[np++].MoveTo(inside.x, inside.YMost());
|
|
|
|
aPoints[np++].MoveTo(inside.XMost(), inside.YMost());
|
|
|
|
aPoints[np++].MoveTo(nscoord(outside.XMost() * borderFrac +
|
|
|
|
inside.XMost() * borderRest),
|
|
|
|
nscoord(outside.YMost() * borderFrac +
|
|
|
|
inside.YMost() * borderRest));
|
|
|
|
} else {
|
|
|
|
aPoints[np++].MoveTo(outside.x, outside.YMost());
|
|
|
|
aPoints[np++].MoveTo(nscoord(inside.x * borderFrac +
|
|
|
|
outside.x * borderRest),
|
|
|
|
nscoord(inside.YMost() * borderFrac +
|
|
|
|
outside.YMost() * borderRest));
|
|
|
|
aPoints[np++].MoveTo(nscoord(inside.XMost() * borderFrac +
|
|
|
|
outside.XMost() * borderRest),
|
|
|
|
nscoord(inside.YMost() * borderFrac +
|
|
|
|
outside.YMost() * borderRest));
|
|
|
|
aPoints[np++].MoveTo(outside.XMost(), outside.YMost());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
if (borderPart == BORDER_FULL) {
|
1998-06-18 09:43:32 +04:00
|
|
|
thickness = outside.XMost() - inside.XMost();
|
1998-06-18 02:14:20 +04:00
|
|
|
|
|
|
|
if (thickness >= twipsPerPixel) {
|
1998-07-21 13:30:03 +04:00
|
|
|
aPoints[np++].MoveTo(outside.XMost(), outside.YMost());
|
|
|
|
aPoints[np++].MoveTo(outside.XMost(), outside.y);
|
1998-06-18 02:14:20 +04:00
|
|
|
}
|
1998-07-21 13:30:03 +04:00
|
|
|
aPoints[np++].MoveTo(inside.XMost(), inside.y);
|
|
|
|
aPoints[np++].MoveTo(inside.XMost(), inside.YMost());
|
1998-04-14 00:24:54 +04:00
|
|
|
} else if (borderPart == BORDER_INSIDE) {
|
|
|
|
aPoints[np++].MoveTo(inside.XMost(), inside.y);
|
|
|
|
aPoints[np++].MoveTo(nscoord(outside.XMost() * borderFrac +
|
|
|
|
inside.XMost() * borderRest),
|
|
|
|
nscoord(outside.y * borderFrac +
|
|
|
|
inside.y * borderRest));
|
|
|
|
aPoints[np++].MoveTo(nscoord(outside.XMost() * borderFrac +
|
|
|
|
inside.XMost() * borderRest),
|
|
|
|
nscoord(outside.YMost() * borderFrac +
|
|
|
|
inside.YMost() * borderRest));
|
|
|
|
aPoints[np++].MoveTo(inside.XMost(), inside.YMost());
|
|
|
|
} else {
|
|
|
|
aPoints[np++].MoveTo(nscoord(inside.XMost() * borderFrac +
|
|
|
|
outside.XMost() * borderRest),
|
|
|
|
nscoord(inside.y * borderFrac +
|
|
|
|
outside.y * borderRest));
|
|
|
|
aPoints[np++].MoveTo(outside.XMost(), outside.y);
|
|
|
|
aPoints[np++].MoveTo(outside.XMost(), outside.YMost());
|
|
|
|
aPoints[np++].MoveTo(nscoord(inside.XMost() * borderFrac +
|
|
|
|
outside.XMost() * borderRest),
|
|
|
|
nscoord(inside.YMost() * borderFrac +
|
|
|
|
outside.YMost() * borderRest));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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,
|
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:
|
|
|
|
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:
|
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside,
|
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
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside,
|
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:
|
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside,
|
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:
|
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside,
|
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);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside,
|
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:
|
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside,
|
|
|
|
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-01-23 01:24:05 +03:00
|
|
|
np = MakeSide (theSide, aContext, whichSide, borderOutside, borderInside,
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
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,
|
|
|
|
nsRect* aGap)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRIntn dashLength;
|
|
|
|
nsRect dashRect, firstRect, currRect;
|
|
|
|
|
|
|
|
PRBool bSolid = PR_TRUE;
|
|
|
|
float over = 0.0f;
|
1998-12-07 22:02:13 +03:00
|
|
|
PRUint8 style = borderStyles[startSide];
|
1998-04-14 00:24:54 +04:00
|
|
|
PRBool skippedSide = PR_FALSE;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-07 22:02:13 +03:00
|
|
|
|
|
|
|
void nsCSSRendering::DrawDashedSides(PRIntn startSide,
|
|
|
|
nsIRenderingContext& aContext,
|
|
|
|
const nsStyleSpacing& aSpacing,
|
|
|
|
const nsRect& borderOutside,
|
|
|
|
const nsRect& borderInside,
|
|
|
|
PRIntn aSkipSides,
|
|
|
|
nsRect* aGap)
|
|
|
|
{
|
|
|
|
PRIntn dashLength;
|
|
|
|
nsRect dashRect, firstRect, currRect;
|
|
|
|
|
|
|
|
PRBool bSolid = PR_TRUE;
|
|
|
|
float over = 0.0f;
|
|
|
|
PRUint8 style = aSpacing.GetBorderStyle(startSide);
|
|
|
|
PRBool skippedSide = PR_FALSE;
|
|
|
|
for (PRIntn whichSide = startSide; whichSide < 4; whichSide++) {
|
|
|
|
PRUint8 prevStyle = style;
|
|
|
|
style = aSpacing.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX units for dash & dot?
|
|
|
|
if (style == NS_STYLE_BORDER_STYLE_DASHED) {
|
|
|
|
dashLength = DASH_LENGTH;
|
|
|
|
} else {
|
|
|
|
dashLength = DOT_LENGTH;
|
|
|
|
}
|
|
|
|
|
1999-03-28 08:30:28 +04:00
|
|
|
nscolor sideColor;
|
|
|
|
if (! aSpacing.GetBorderColor(whichSide, sideColor)) {
|
|
|
|
continue; // side is transparent
|
|
|
|
}
|
|
|
|
aContext.SetColor(sideColor);
|
1998-12-07 22:02:13 +03: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;
|
|
|
|
}
|
|
|
|
}
|
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,
|
|
|
|
nsRect* aGap)
|
|
|
|
{
|
|
|
|
PRIntn dashLength;
|
1999-02-12 20:45:58 +03:00
|
|
|
nsRect dashRect, currRect;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
|
|
|
PRBool bSolid = PR_TRUE;
|
|
|
|
float over = 0.0f;
|
|
|
|
PRBool skippedSide = PR_FALSE;
|
|
|
|
PRIntn whichSide=0;
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
printf(" L: totalLength = %d, borderOutside.y = %d, midpoint %d, dashRect.y = %d\n",
|
1998-12-30 09:47:26 +03:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
printf("DASHED LEFT: xywh in loop currRect = %d %d %d %d %s\n",
|
|
|
|
currRect.x, currRect.y, currRect.width, currRect.height, bSolid?"TRUE":"FALSE");
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
printf("DASHED LEFT: xywh in loop currRect = %d %d %d %d %s\n",
|
|
|
|
currRect.x, currRect.y, currRect.width, currRect.height, bSolid?"TRUE":"FALSE");
|
|
|
|
}
|
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;
|
|
|
|
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, 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// XXX improve this to constrain rendering to the damaged area
|
|
|
|
void nsCSSRendering::PaintBorder(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
1999-01-15 21:25:58 +03:00
|
|
|
const nsRect& aBorderArea,
|
1999-01-23 01:24:05 +03:00
|
|
|
const nsStyleSpacing& aBorderStyle,
|
1999-03-05 22:23:52 +03:00
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
PRIntn aSkipSides,
|
1998-10-08 08:38:41 +04:00
|
|
|
nsRect* aGap)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-27 00:52:59 +04:00
|
|
|
PRIntn cnt;
|
|
|
|
nsMargin border;
|
1999-01-23 01:24:05 +03:00
|
|
|
const nsStyleColor* bgColor = nsStyleUtil::FindNonTransparentBackground(aStyleContext);
|
1999-04-19 09:27:55 +04:00
|
|
|
PRInt16 theRadius;
|
|
|
|
nsStyleCoord borderRadius;
|
1999-01-23 01:24:05 +03:00
|
|
|
|
|
|
|
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-04-19 09:27:55 +04:00
|
|
|
// get the radius for our border
|
|
|
|
borderRadius = aBorderStyle.mBorderRadius;
|
|
|
|
theRadius = 0;
|
|
|
|
switch (borderRadius.GetUnit() ) {
|
|
|
|
case eStyleUnit_Inherit:
|
|
|
|
break;
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
break;
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
theRadius = borderRadius.GetCoordValue();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// rounded version of the border
|
|
|
|
if (theRadius > 0){
|
|
|
|
PaintRoundedBorder(aPresContext,aRenderingContext,aForFrame,aDirtyRect,aBorderArea,aBorderStyle,aStyleContext,aSkipSides,theRadius,aGap);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
1999-01-15 21:25:58 +03:00
|
|
|
nsRect inside(aBorderArea);
|
1998-04-14 00:24:54 +04:00
|
|
|
nsRect outside(inside);
|
|
|
|
outside.Deflate(border);
|
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) {
|
1999-01-23 01:24:05 +03:00
|
|
|
DrawDashedSides(cnt, aRenderingContext,aBorderStyle,
|
1998-12-10 20:50:11 +03:00
|
|
|
inside, outside, aSkipSides, aGap);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw all the other sides
|
1999-02-12 20:45:58 +03:00
|
|
|
|
|
|
|
/* XXX something is misnamed here!!!! */
|
|
|
|
nscoord twipsPerPixel;/* XXX */
|
|
|
|
float p2t;/* XXX */
|
|
|
|
aPresContext.GetPixelsToTwips(&p2t);/* XXX */
|
|
|
|
twipsPerPixel = (nscoord) p2t;/* XXX */
|
|
|
|
|
1999-03-28 08:30:28 +04:00
|
|
|
nscolor sideColor;
|
1998-04-14 00:24:54 +04:00
|
|
|
if (0 == (aSkipSides & (1<<NS_SIDE_TOP))) {
|
1999-03-28 08:30:28 +04:00
|
|
|
if (aBorderStyle.GetBorderColor(NS_SIDE_TOP, sideColor)) {
|
|
|
|
DrawSide(aRenderingContext, NS_SIDE_TOP,
|
|
|
|
aBorderStyle.GetBorderStyle(NS_SIDE_TOP),
|
|
|
|
sideColor,
|
|
|
|
bgColor->mBackgroundColor, inside,outside,
|
|
|
|
twipsPerPixel, aGap);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
if (0 == (aSkipSides & (1<<NS_SIDE_LEFT))) {
|
1999-03-28 08:30:28 +04:00
|
|
|
if (aBorderStyle.GetBorderColor(NS_SIDE_LEFT, sideColor)) {
|
|
|
|
DrawSide(aRenderingContext, NS_SIDE_LEFT,
|
|
|
|
aBorderStyle.GetBorderStyle(NS_SIDE_LEFT),
|
|
|
|
sideColor,
|
|
|
|
bgColor->mBackgroundColor,inside, outside,
|
|
|
|
twipsPerPixel, aGap);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
if (0 == (aSkipSides & (1<<NS_SIDE_BOTTOM))) {
|
1999-03-28 08:30:28 +04:00
|
|
|
if (aBorderStyle.GetBorderColor(NS_SIDE_BOTTOM, sideColor)) {
|
|
|
|
DrawSide(aRenderingContext, NS_SIDE_BOTTOM,
|
|
|
|
aBorderStyle.GetBorderStyle(NS_SIDE_BOTTOM),
|
|
|
|
sideColor,
|
|
|
|
bgColor->mBackgroundColor,inside, outside,
|
|
|
|
twipsPerPixel, aGap);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
if (0 == (aSkipSides & (1<<NS_SIDE_RIGHT))) {
|
1999-03-28 08:30:28 +04:00
|
|
|
if (aBorderStyle.GetBorderColor(NS_SIDE_RIGHT, sideColor)) {
|
|
|
|
DrawSide(aRenderingContext, NS_SIDE_RIGHT,
|
|
|
|
aBorderStyle.GetBorderStyle(NS_SIDE_RIGHT),
|
|
|
|
sideColor,
|
|
|
|
bgColor->mBackgroundColor,inside, outside,
|
|
|
|
twipsPerPixel, aGap);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
1998-12-18 01:58:51 +03:00
|
|
|
void nsCSSRendering::PaintBorderEdges(nsIPresContext& aPresContext,
|
|
|
|
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,
|
1999-03-05 22:23:52 +03:00
|
|
|
nsIStyleContext* aStyleContext,
|
1998-12-18 01:58:51 +03:00
|
|
|
PRIntn aSkipSides,
|
|
|
|
nsRect* aGap)
|
|
|
|
{
|
1999-01-23 01:24:05 +03:00
|
|
|
const nsStyleColor* bgColor = nsStyleUtil::FindNonTransparentBackground(aStyleContext);
|
|
|
|
|
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;
|
|
|
|
aPresContext.GetPixelsToTwips(&p2t);
|
|
|
|
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,
|
|
|
|
inside, outside,
|
|
|
|
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,
|
|
|
|
inside, outside,
|
|
|
|
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,
|
|
|
|
inside, outside,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
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,
|
|
|
|
inside, outside,
|
|
|
|
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
|
1998-12-12 06:06:02 +03:00
|
|
|
static void
|
1998-10-27 19:50:19 +03:00
|
|
|
ComputeBackgroundAnchorPoint(const nsStyleColor& aColor,
|
|
|
|
const nsRect& aBounds,
|
|
|
|
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) {
|
|
|
|
x = aColor.mBackgroundXPosition;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nscoord t = aColor.mBackgroundXPosition;
|
|
|
|
float pct = float(t) / 100.0f;
|
|
|
|
nscoord tilePos = nscoord(pct * aTileWidth);
|
|
|
|
nscoord boxPos = nscoord(pct * aBounds.width);
|
|
|
|
x = boxPos - tilePos;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
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) {
|
|
|
|
y = aColor.mBackgroundYPosition;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nscoord t = aColor.mBackgroundYPosition;
|
|
|
|
float pct = float(t) / 100.0f;
|
|
|
|
nscoord tilePos = nscoord(pct * aTileHeight);
|
|
|
|
nscoord boxPos = nscoord(pct * aBounds.height);
|
|
|
|
y = boxPos - tilePos;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
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 clip view associated with the scroll frame's scrolling
|
|
|
|
// view
|
|
|
|
static const nsIView*
|
|
|
|
GetClipView(nsIFrame* aScrollFrame)
|
|
|
|
{
|
|
|
|
nsIView* view;
|
|
|
|
nsIScrollableView* scrollingView;
|
|
|
|
const nsIView* clipView;
|
|
|
|
|
|
|
|
// Get the scrolling view
|
|
|
|
aScrollFrame->GetView(&view);
|
|
|
|
view->QueryInterface(kScrollViewIID, (void**)&scrollingView);
|
|
|
|
|
|
|
|
// Get the clip view
|
|
|
|
scrollingView->GetClipView(&clipView);
|
|
|
|
return clipView;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the nearest scroll frame ancestor
|
|
|
|
static nsIFrame*
|
|
|
|
GetNearestScrollFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
for (nsIFrame* f = aFrame; f; f->GetParent(&f)) {
|
|
|
|
nsIAtom* frameType;
|
|
|
|
|
|
|
|
// Is it a scroll frame?
|
|
|
|
f->GetFrameType(&frameType);
|
|
|
|
if (nsLayoutAtoms::scrollFrame == frameType) {
|
|
|
|
NS_RELEASE(frameType);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(frameType);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSRendering::PaintBackground(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
1999-01-15 21:25:58 +03:00
|
|
|
const nsRect& aBorderArea,
|
1998-09-26 21:16:56 +04:00
|
|
|
const nsStyleColor& aColor,
|
1999-01-15 21:25:58 +03:00
|
|
|
const nsStyleSpacing& aSpacing,
|
1998-09-26 21:16:56 +04:00
|
|
|
nscoord aDX,
|
|
|
|
nscoord aDY)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-07-03 02:39:32 +04:00
|
|
|
PRInt16 theRadius;
|
|
|
|
nsStyleCoord borderRadius;
|
1999-04-21 18:23:49 +04:00
|
|
|
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
if (0 < aColor.mBackgroundImage.Length()) {
|
1998-05-09 07:23:54 +04:00
|
|
|
// Lookup the image
|
|
|
|
nsSize imageSize;
|
1998-05-12 02:58:20 +04:00
|
|
|
nsIImage* image = nsnull;
|
|
|
|
nsIFrameImageLoader* loader = nsnull;
|
1998-07-16 08:34:59 +04:00
|
|
|
PRBool transparentBG = NS_STYLE_BG_COLOR_TRANSPARENT ==
|
1998-09-26 21:16:56 +04:00
|
|
|
(aColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT);
|
|
|
|
nsresult rv = aPresContext.StartLoadImage(aColor.mBackgroundImage,
|
|
|
|
transparentBG
|
|
|
|
? nsnull
|
|
|
|
: &aColor.mBackgroundColor,
|
1999-02-26 20:12:05 +03:00
|
|
|
nsnull,
|
1999-04-14 01:52:19 +04:00
|
|
|
aForFrame, nsnull, nsnull,
|
|
|
|
&loader);
|
1998-05-12 02:58:20 +04:00
|
|
|
if ((NS_OK != rv) || (nsnull == loader) ||
|
1999-04-14 01:52:19 +04:00
|
|
|
(loader->GetImage(&image), (nsnull == image))) {
|
1998-05-12 02:58:20 +04:00
|
|
|
NS_IF_RELEASE(loader);
|
1998-04-14 00:24:54 +04:00
|
|
|
// Redraw will happen later
|
1998-07-16 08:34:59 +04:00
|
|
|
if (!transparentBG) {
|
1998-04-14 00:24:54 +04:00
|
|
|
aRenderingContext.SetColor(aColor.mBackgroundColor);
|
1999-01-15 21:25:58 +03:00
|
|
|
aRenderingContext.FillRect(aBorderArea);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
1998-05-12 02:58:20 +04:00
|
|
|
loader->GetSize(imageSize);
|
|
|
|
NS_RELEASE(loader);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-26 21:29:10 +04:00
|
|
|
PRBool needBackgroundColor = PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
#if XXX
|
|
|
|
// XXX enable this code as soon as nsIImage can support it
|
|
|
|
if (image->NeedsBlend()) {
|
1998-09-26 21:29:10 +04:00
|
|
|
needBackgroundColor = PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-04-14 01:52:19 +04:00
|
|
|
nscoord tileWidth = imageSize.width;
|
|
|
|
nscoord tileHeight = imageSize.height;
|
1998-09-26 21:16:56 +04:00
|
|
|
if ((tileWidth == 0) || (tileHeight == 0)) {
|
|
|
|
return;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-01-15 21:25:58 +03:00
|
|
|
// Background images are tiled over the 'content' and 'padding' areas
|
|
|
|
// only (not the 'border' area)
|
|
|
|
nsRect paddingArea(aBorderArea);
|
|
|
|
nsMargin border;
|
|
|
|
|
|
|
|
aSpacing.GetBorder(border);
|
|
|
|
paddingArea.Deflate(border);
|
|
|
|
|
|
|
|
// The actual dirty rect is the intersection of the padding area and the
|
|
|
|
// dirty rect we were given
|
|
|
|
nsRect dirtyRect;
|
|
|
|
|
|
|
|
if (!dirtyRect.IntersectRect(paddingArea, aDirtyRect)) {
|
|
|
|
// Nothing to paint
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-09-26 21:16:56 +04:00
|
|
|
// Based on the repeat setting, compute how many tiles we should
|
1998-12-12 06:06:02 +03:00
|
|
|
// lay down for each axis. The value computed is the maximum based
|
|
|
|
// on the dirty rect before accounting for the background-position.
|
1998-04-14 00:24:54 +04:00
|
|
|
PRIntn repeat = aColor.mBackgroundRepeat;
|
1998-12-12 06:06:02 +03:00
|
|
|
nscoord xDistance, yDistance;
|
1999-02-26 20:12:05 +03:00
|
|
|
switch (repeat) {
|
1998-04-14 00:24:54 +04:00
|
|
|
case NS_STYLE_BG_REPEAT_OFF:
|
|
|
|
default:
|
1998-12-12 06:06:02 +03:00
|
|
|
xDistance = tileWidth;
|
|
|
|
yDistance = tileHeight;
|
1998-09-26 21:29:10 +04:00
|
|
|
needBackgroundColor = PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
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-09-26 21:29:10 +04:00
|
|
|
needBackgroundColor = PR_TRUE;
|
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-09-26 21:29:10 +04:00
|
|
|
needBackgroundColor = PR_TRUE;
|
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;
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
1999-01-15 21:25:58 +03:00
|
|
|
|
|
|
|
// The background color is rendered over the 'border' 'padding' and
|
|
|
|
// 'content' areas
|
1998-09-26 21:29:10 +04:00
|
|
|
if (needBackgroundColor) {
|
|
|
|
aRenderingContext.SetColor(aColor.mBackgroundColor);
|
1999-01-15 21:25:58 +03:00
|
|
|
aRenderingContext.FillRect(aBorderArea);
|
1998-09-26 21:29:10 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-04-25 06:43:50 +04:00
|
|
|
// If it's a fixed background attachment, then get the nearest scrolling
|
|
|
|
// ancestor
|
|
|
|
nsIFrame* scrollFrame = nsnull;
|
|
|
|
const nsIView* clipView = nsnull;
|
|
|
|
nsRect viewportArea(0, 0, 0, 0);
|
|
|
|
|
|
|
|
if (NS_STYLE_BG_ATTACHMENT_FIXED == aColor.mBackgroundAttachment) {
|
|
|
|
scrollFrame = GetNearestScrollFrame(aForFrame);
|
|
|
|
|
|
|
|
// Get the viewport size
|
|
|
|
clipView = GetClipView(scrollFrame);
|
|
|
|
clipView->GetDimensions(&viewportArea.width, &viewportArea.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the anchor point. If it's a fixed background attachment, then
|
|
|
|
// the image is placed relative to the viewport; otherwise, it's placed
|
|
|
|
// relative to the element's padding area.
|
|
|
|
//
|
|
|
|
// When tiling, the anchor coordinate values will be negative offsets
|
|
|
|
// from the padding area
|
1998-10-27 19:50:19 +03:00
|
|
|
nsPoint anchor;
|
1999-04-25 06:43:50 +04:00
|
|
|
ComputeBackgroundAnchorPoint(aColor, scrollFrame ? viewportArea : paddingArea,
|
1998-12-12 06:06:02 +03:00
|
|
|
tileWidth, tileHeight, anchor);
|
|
|
|
|
1999-04-25 06:43:50 +04:00
|
|
|
// If it's a fixed background attachment, then convert the anchor point
|
|
|
|
// to aForFrame's coordinate space
|
|
|
|
if (NS_STYLE_BG_ATTACHMENT_FIXED == aColor.mBackgroundAttachment) {
|
|
|
|
nsIView* view;
|
|
|
|
|
|
|
|
aForFrame->GetView(&view);
|
|
|
|
if (!view) {
|
|
|
|
nsPoint offset;
|
|
|
|
aForFrame->GetOffsetFromView(offset, &view);
|
|
|
|
anchor -= offset;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(view, "expected a view");
|
|
|
|
while (view && (view != clipView)) {
|
|
|
|
nscoord x, y;
|
|
|
|
|
|
|
|
view->GetPosition(&x, &y);
|
|
|
|
anchor.x -= x;
|
|
|
|
anchor.y -= y;
|
|
|
|
|
|
|
|
// Get the parent view
|
|
|
|
view->GetParent(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-15 21:25:58 +03:00
|
|
|
// Setup clipping so that rendering doesn't leak out of the computed
|
|
|
|
// dirty rect
|
1998-12-12 06:06:02 +03:00
|
|
|
PRBool clipState;
|
|
|
|
aRenderingContext.PushState();
|
1999-01-15 21:25:58 +03:00
|
|
|
aRenderingContext.SetClipRect(dirtyRect, nsClipCombine_kIntersect,
|
1998-12-12 06:06:02 +03:00
|
|
|
clipState);
|
|
|
|
|
|
|
|
// Compute the x and y starting points and limits for tiling
|
|
|
|
nscoord x0, x1;
|
1999-04-25 06:43:50 +04:00
|
|
|
if (NS_STYLE_BG_ATTACHMENT_FIXED == aColor.mBackgroundAttachment) {
|
|
|
|
if (NS_STYLE_BG_REPEAT_X & repeat) {
|
|
|
|
x0 = ((dirtyRect.x - anchor.x) / tileWidth) * tileWidth + anchor.x;
|
|
|
|
x1 = x0 + xDistance + tileWidth;
|
|
|
|
if (0 != anchor.x) {
|
|
|
|
x1 += tileWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// For fixed attachment, the anchor is relative to the nearest scrolling
|
|
|
|
// ancestor (or the viewport)
|
|
|
|
x0 = anchor.x;
|
|
|
|
x1 = x0 + tileWidth;
|
1998-10-27 19:50:19 +03:00
|
|
|
}
|
1998-12-12 06:06:02 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-04-25 06:43:50 +04:00
|
|
|
if (NS_STYLE_BG_REPEAT_X & repeat) {
|
|
|
|
// 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 = (dirtyRect.x / tileWidth) * tileWidth + anchor.x;
|
1999-06-11 18:43:14 +04:00
|
|
|
if(x0+tileWidth<dirtyRect.x)
|
|
|
|
x0+=tileWidth;
|
1999-04-25 06:43:50 +04:00
|
|
|
x1 = x0 + xDistance + tileWidth;
|
|
|
|
if (0 != anchor.x) {
|
|
|
|
x1 += tileWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// For scrolling attachment, the anchor is relative to the padding area
|
|
|
|
x0 = paddingArea.x + anchor.x;
|
|
|
|
x1 = x0 + tileWidth;
|
|
|
|
}
|
1998-12-12 06:06:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord y0, y1;
|
1999-04-25 06:43:50 +04:00
|
|
|
if (NS_STYLE_BG_ATTACHMENT_FIXED == aColor.mBackgroundAttachment) {
|
|
|
|
if (NS_STYLE_BG_REPEAT_Y & repeat) {
|
|
|
|
y0 = ((dirtyRect.y - anchor.y) / tileHeight) * tileHeight + anchor.y;
|
|
|
|
y1 = y0 + yDistance + tileHeight;
|
|
|
|
if (0 != anchor.y) {
|
|
|
|
y1 += tileHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// For fixed attachment, the anchor is relative to the nearest scrolling
|
|
|
|
// ancestor (or the viewport)
|
|
|
|
y0 = anchor.y;
|
|
|
|
y1 = y0 + tileHeight;
|
1998-10-27 19:50:19 +03:00
|
|
|
}
|
1998-08-06 02:24:56 +04:00
|
|
|
}
|
1998-12-12 06:06:02 +03:00
|
|
|
else {
|
1999-04-25 06:43:50 +04:00
|
|
|
if (NS_STYLE_BG_REPEAT_Y & repeat) {
|
|
|
|
// 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 = (dirtyRect.y / tileHeight) * tileHeight + anchor.y;
|
1999-06-11 18:43:14 +04:00
|
|
|
if(y0+tileHeight<dirtyRect.y)
|
|
|
|
y0+=tileHeight;
|
1999-04-25 06:43:50 +04:00
|
|
|
y1 = y0 + yDistance + tileHeight;
|
|
|
|
if (0 != anchor.y) {
|
|
|
|
y1 += tileHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// For scrolling attachment, the anchor is relative to the padding area
|
|
|
|
y0 = paddingArea.y + anchor.y;
|
|
|
|
y1 = y0 + tileHeight;
|
|
|
|
}
|
1998-12-12 06:06:02 +03:00
|
|
|
}
|
1998-07-31 03:31:42 +04:00
|
|
|
|
1999-06-11 18:43:14 +04:00
|
|
|
nsDrawingSurface theSurface;
|
|
|
|
nsRect srcRect,destRect;
|
|
|
|
PRInt32 x,y;
|
|
|
|
PRInt32 flag = NS_COPYBITS_TO_BACK_BUFFER | NS_COPYBITS_XFORM_DEST_VALUES | NS_COPYBITS_XFORM_SOURCE_VALUES;
|
|
|
|
|
|
|
|
srcRect.x = x0;
|
|
|
|
srcRect.y = y0;
|
|
|
|
srcRect.width = tileWidth;
|
|
|
|
srcRect.height = tileHeight;
|
|
|
|
|
|
|
|
// copy the initial image to our buffer
|
|
|
|
aRenderingContext.DrawImage(image,srcRect.x,srcRect.y,tileWidth,tileHeight);
|
|
|
|
//if(anchor.x<0) {
|
|
|
|
if(x0<dirtyRect.x) {
|
|
|
|
aRenderingContext.DrawImage(image,x0+tileWidth,y0,tileWidth,tileHeight);
|
|
|
|
srcRect.x =dirtyRect.x;
|
|
|
|
}
|
|
|
|
//if(anchor.y<0) {
|
|
|
|
if(y0<dirtyRect.y) {
|
|
|
|
aRenderingContext.DrawImage(image,x0,y0+tileHeight,tileWidth,tileHeight);
|
|
|
|
srcRect.y = dirtyRect.y;
|
|
|
|
if(x0<dirtyRect.x) {
|
|
|
|
aRenderingContext.DrawImage(image,x0+tileWidth,y0+tileHeight,tileWidth,tileHeight);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
1999-06-11 18:43:14 +04:00
|
|
|
|
|
|
|
// create a bigger tile
|
|
|
|
aRenderingContext.GetDrawingSurface(&theSurface);
|
|
|
|
TileImage(aRenderingContext,theSurface,srcRect,x1-x0,y1-y0,flag);
|
|
|
|
|
|
|
|
// use the tile to fill in the rest of the image
|
|
|
|
destRect = srcRect;
|
|
|
|
|
|
|
|
for(y=srcRect.y;y<y1;y+=srcRect.height){
|
|
|
|
for(x=srcRect.x;x<x1;x+=srcRect.width){
|
|
|
|
destRect.x = x;
|
|
|
|
destRect.y = y;
|
|
|
|
aRenderingContext.CopyOffScreenBits(theSurface,srcRect.x,srcRect.y,destRect,flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-12 06:06:02 +03:00
|
|
|
// Restore clipping
|
1998-10-30 05:08:25 +03:00
|
|
|
aRenderingContext.PopState(clipState);
|
1999-01-15 21:25:58 +03:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
} else {
|
1999-01-15 21:25:58 +03:00
|
|
|
// See if there's a background color specified. The background color
|
|
|
|
// is rendered over the 'border' 'padding' and 'content' areas
|
1998-04-14 00:24:54 +04:00
|
|
|
if (0 == (aColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT)) {
|
|
|
|
// XXX This step can be avoided if we have an image and it doesn't
|
1998-07-22 09:02:07 +04:00
|
|
|
// have any transparent pixels, and the image is tiled in both
|
1998-04-14 00:24:54 +04:00
|
|
|
// the x and the y
|
1999-04-21 18:23:49 +04:00
|
|
|
|
|
|
|
// check to see if we have a radius
|
|
|
|
borderRadius = aSpacing.mBorderRadius;
|
|
|
|
theRadius = 0;
|
|
|
|
switch (borderRadius.GetUnit() ) {
|
|
|
|
case eStyleUnit_Inherit:
|
|
|
|
break;
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
break;
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
theRadius = borderRadius.GetCoordValue();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// rounded version of the border
|
|
|
|
if (theRadius > 0){
|
|
|
|
PaintRoundedBackground(aPresContext,aRenderingContext,aForFrame,aDirtyRect,aBorderArea,aColor,aSpacing,aDX,aDY,theRadius);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
aRenderingContext.SetColor(aColor.mBackgroundColor);
|
1999-01-15 21:25:58 +03:00
|
|
|
aRenderingContext.FillRect(aBorderArea);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
|
1999-06-11 18:43:14 +04:00
|
|
|
/** ---------------------------------------------------
|
|
|
|
* A bit blitter to tile images to the background recursively
|
|
|
|
* @update 4/13/99 dwc
|
|
|
|
* @param aRC -- Rendering Context to render to
|
|
|
|
* @param aDS -- Target drawing surface for the rendering context
|
|
|
|
* @param aWidth -- width of the tile
|
|
|
|
* @param aHeight -- height of the tile
|
|
|
|
* @param aWidth -- flags for the rendering context to use
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
TileImage(nsIRenderingContext& aRC,nsDrawingSurface aDS,nsRect &aSrcRect,PRInt16 aWidth,PRInt16 aHeight,PRInt32 aFlag)
|
|
|
|
{
|
|
|
|
nsRect destRect;
|
|
|
|
|
|
|
|
if( ((aSrcRect.width)<<1) < (aWidth)) {
|
|
|
|
// width is less than double so double our source bitmap width
|
|
|
|
destRect = aSrcRect;
|
|
|
|
destRect.x += aSrcRect.width;
|
|
|
|
aRC.CopyOffScreenBits(aDS,aSrcRect.x,aSrcRect.y,destRect,aFlag);
|
|
|
|
aSrcRect.width*=2;
|
|
|
|
TileImage(aRC,aDS,aSrcRect,aWidth,aHeight,aFlag);
|
|
|
|
} else if (((aSrcRect.height)<<1) < (aHeight)) {
|
|
|
|
// height is less than double so double our source bitmap height
|
|
|
|
destRect = aSrcRect;
|
|
|
|
destRect.y += aSrcRect.height;
|
|
|
|
aRC.CopyOffScreenBits(aDS,aSrcRect.x,aSrcRect.y,destRect,aFlag);
|
|
|
|
aSrcRect.height*=2;
|
|
|
|
TileImage(aRC,aDS,aSrcRect,aWidth,aHeight,aFlag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-21 18:23:49 +04:00
|
|
|
static void AntiAliasPoly(nsIRenderingContext& aRenderingContext,nsPoint aPoints[],PRInt32 aStartIndex,PRInt32 curIndex,PRInt8 aSide,PRInt8 aCorner);
|
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation in nsCSSRendering.h
|
|
|
|
* @update 3/26/99 dwc
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsCSSRendering::PaintRoundedBackground(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
const nsStyleColor& aColor,
|
|
|
|
const nsStyleSpacing& aSpacing,
|
|
|
|
nscoord aDX,
|
|
|
|
nscoord aDY,
|
|
|
|
PRInt16 aTheRadius)
|
|
|
|
{
|
|
|
|
RoundedRect outerPath;
|
|
|
|
QBCurve cr1,cr2,cr3,cr4;
|
|
|
|
QBCurve UL,UR,LL,LR;
|
1999-04-21 18:23:49 +04:00
|
|
|
PRInt32 curIndex,c1Index;
|
1999-04-19 09:27:55 +04:00
|
|
|
nsPoint anc1,con,anc2;
|
|
|
|
nsPoint thePath[MAXPATHSIZE];
|
|
|
|
nsPoint polyPath[MAXPOLYPATHSIZE];
|
|
|
|
PRInt16 np;
|
|
|
|
nsMargin border;
|
|
|
|
nsStyleCoord borderRadius;
|
|
|
|
|
|
|
|
aRenderingContext.SetColor(aColor.mBackgroundColor);
|
|
|
|
|
|
|
|
// set the rounded rect up, and let'er rip
|
1999-04-21 18:23:49 +04:00
|
|
|
outerPath.Set(aBorderArea.x,aBorderArea.y,aBorderArea.width,aBorderArea.height,aTheRadius);
|
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);
|
|
|
|
|
|
|
|
polyPath[0].x = thePath[0].x;
|
|
|
|
polyPath[0].y = thePath[0].y;
|
|
|
|
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
|
|
|
|
nsCSSRendering::PaintRoundedBorder(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
const nsStyleSpacing& aBorderStyle,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
PRIntn aSkipSides,
|
|
|
|
PRInt16 aBorderRadius,
|
|
|
|
nsRect* aGap)
|
|
|
|
{
|
|
|
|
RoundedRect outerPath;
|
|
|
|
QBCurve UL,LL,UR,LR;
|
|
|
|
QBCurve IUL,ILL,IUR,ILR;
|
|
|
|
QBCurve cr1,cr2,cr3,cr4;
|
|
|
|
QBCurve Icr1,Icr2,Icr3,Icr4;
|
|
|
|
nsPoint anc1,con,anc2;
|
|
|
|
nsPoint thePath[MAXPATHSIZE];
|
|
|
|
PRInt16 np;
|
|
|
|
nsMargin border;
|
|
|
|
nscoord twipsPerPixel;
|
|
|
|
float p2t;
|
|
|
|
|
|
|
|
aBorderStyle.CalcBorderFor(aForFrame, border);
|
|
|
|
if ((0 == border.left) && (0 == border.right) &&
|
|
|
|
(0 == border.top) && (0 == border.bottom)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// needed for our border thickness
|
|
|
|
aPresContext.GetPixelsToTwips(&p2t);
|
|
|
|
twipsPerPixel = (nscoord) p2t;
|
|
|
|
|
|
|
|
// Base our thickness check on the segment being less than a pixel and 1/2
|
|
|
|
twipsPerPixel += twipsPerPixel >> 2;
|
|
|
|
|
|
|
|
// set the rounded rect up, and let'er rip
|
1999-04-21 18:23:49 +04:00
|
|
|
outerPath.Set(aBorderArea.x,aBorderArea.y,aBorderArea.width,aBorderArea.height,aBorderRadius);
|
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
|
|
|
|
if(0==border.top)
|
|
|
|
return;
|
|
|
|
// construct and divide the curves needed
|
|
|
|
UL.MidPointDivide(&cr1,&cr2);
|
|
|
|
UR.MidPointDivide(&cr3,&cr4);
|
|
|
|
IUL.MidPointDivide(&Icr1,&Icr2);
|
|
|
|
IUR.MidPointDivide(&Icr3,&Icr4);
|
|
|
|
|
|
|
|
// the outer part of the path
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
RenderSide(thePath,aRenderingContext,aBorderStyle,aStyleContext,NS_SIDE_TOP,border,twipsPerPixel);
|
|
|
|
|
|
|
|
// RIGHT LINE ----------------------------------------------------------------
|
|
|
|
if(0==border.right)
|
|
|
|
return;
|
|
|
|
LR.MidPointDivide(&cr2,&cr3);
|
|
|
|
ILR.MidPointDivide(&Icr2,&Icr3);
|
|
|
|
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);
|
|
|
|
|
|
|
|
RenderSide(thePath,aRenderingContext,aBorderStyle,aStyleContext,NS_SIDE_RIGHT,border,twipsPerPixel);
|
|
|
|
|
|
|
|
// bottom line ----------------------------------------------------------------
|
|
|
|
if(0==border.bottom)
|
|
|
|
return;
|
|
|
|
LL.MidPointDivide(&cr2,&cr4);
|
|
|
|
ILL.MidPointDivide(&Icr2,&Icr4);
|
|
|
|
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);
|
|
|
|
RenderSide(thePath,aRenderingContext,aBorderStyle,aStyleContext,NS_SIDE_BOTTOM,border,twipsPerPixel);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
RenderSide(thePath,aRenderingContext,aBorderStyle,aStyleContext,NS_SIDE_LEFT,border,twipsPerPixel);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
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
|
|
|
|
nsCSSRendering::RenderSide(nsPoint aPoints[],nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsStyleSpacing& aBorderStyle,nsIStyleContext* aStyleContext,
|
|
|
|
PRUint8 aSide,nsMargin &aBorThick,nscoord aTwipsPerPixel)
|
|
|
|
{
|
|
|
|
QBCurve thecurve,cr1,cr2,cr3,cr4;
|
|
|
|
nscolor sideColor;
|
|
|
|
nsPoint thePath[MAXPATHSIZE];
|
|
|
|
nsPoint polypath[MAXPOLYPATHSIZE];
|
1999-04-21 18:23:49 +04:00
|
|
|
PRInt32 curIndex,c1Index,c2Index,junk;
|
1999-04-19 09:27:55 +04:00
|
|
|
PRInt8 border_Style;
|
1999-04-21 18:23:49 +04:00
|
|
|
PRInt16 r,g,b;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
// set the style information
|
|
|
|
aBorderStyle.GetBorderColor(aSide,sideColor);
|
|
|
|
aRenderingContext.SetColor ( sideColor );
|
|
|
|
|
|
|
|
// if the border is thin, just draw it
|
|
|
|
if (aBorThick.top<aTwipsPerPixel) {
|
|
|
|
// 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);
|
|
|
|
aRenderingContext.DrawLine(aPoints[2].x,aPoints[2].y,aPoints[3].x,aPoints[3].y);
|
|
|
|
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 {
|
|
|
|
|
|
|
|
border_Style = aBorderStyle.GetBorderStyle(aSide);
|
|
|
|
switch (border_Style){
|
|
|
|
case NS_STYLE_BORDER_STYLE_OUTSET:
|
|
|
|
case NS_STYLE_BORDER_STYLE_INSET:
|
|
|
|
{
|
|
|
|
const nsStyleColor* bgColor = nsStyleUtil::FindNonTransparentBackground(aStyleContext);
|
|
|
|
aBorderStyle.GetBorderColor(aSide,sideColor);
|
|
|
|
aRenderingContext.SetColor ( MakeBevelColor (aSide, border_Style, bgColor->mBackgroundColor,sideColor, PR_TRUE));
|
|
|
|
}
|
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
|
|
|
polypath[0].x = aPoints[0].x;
|
|
|
|
polypath[0].y = aPoints[0].y;
|
|
|
|
curIndex = 1;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eOutside,c1Index);
|
|
|
|
c2Index = curIndex;
|
1999-04-19 09:27:55 +04:00
|
|
|
polypath[curIndex].x = aPoints[6].x;
|
|
|
|
polypath[curIndex].y = aPoints[6].y;
|
|
|
|
curIndex++;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eInside,junk);
|
1999-04-19 09:27:55 +04:00
|
|
|
polypath[curIndex].x = aPoints[0].x;
|
|
|
|
polypath[curIndex].y = aPoints[0].y;
|
|
|
|
curIndex++;
|
1999-04-21 18:23:49 +04:00
|
|
|
aRenderingContext.FillPolygon(polypath,curIndex);
|
|
|
|
|
|
|
|
// anti-alias this
|
|
|
|
r = NS_GET_R(sideColor);
|
|
|
|
g = NS_GET_G(sideColor);
|
|
|
|
b = NS_GET_B(sideColor);
|
|
|
|
|
|
|
|
r += (255-r)>>1;
|
|
|
|
g += (255-g)>>1;
|
|
|
|
b += (255-b)>>1;
|
|
|
|
|
|
|
|
sideColor = NS_RGB(r,g,b);
|
|
|
|
|
|
|
|
aRenderingContext.SetColor(sideColor);
|
|
|
|
AntiAliasPoly(aRenderingContext,polypath,0,c1Index,aSide,1);
|
|
|
|
AntiAliasPoly(aRenderingContext,polypath,c1Index+1,c2Index,aSide,2);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOUBLE:
|
|
|
|
polypath[0].x = aPoints[0].x;
|
|
|
|
polypath[0].y = aPoints[0].y;
|
|
|
|
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);
|
|
|
|
polypath[0].x = aPoints[6].x;
|
|
|
|
polypath[0].y = aPoints[6].y;
|
|
|
|
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:
|
|
|
|
case NS_STYLE_BORDER_STYLE_BLANK:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOTTED:
|
|
|
|
case NS_STYLE_BORDER_STYLE_DASHED:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_RIDGE:
|
|
|
|
case NS_STYLE_BORDER_STYLE_GROOVE:
|
|
|
|
{
|
|
|
|
const nsStyleColor* bgColor = nsStyleUtil::FindNonTransparentBackground(aStyleContext);
|
|
|
|
aBorderStyle.GetBorderColor(aSide,sideColor);
|
|
|
|
aRenderingContext.SetColor ( MakeBevelColor (aSide, border_Style, bgColor->mBackgroundColor,sideColor, PR_TRUE));
|
|
|
|
|
|
|
|
polypath[0].x = aPoints[0].x;
|
|
|
|
polypath[0].y = aPoints[0].y;
|
|
|
|
curIndex = 1;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eOutside,c1Index);
|
1999-04-19 09:27:55 +04:00
|
|
|
polypath[curIndex].x = (aPoints[5].x + aPoints[6].x)>>1;
|
|
|
|
polypath[curIndex].y = (aPoints[5].y + aPoints[6].y)>>1;
|
|
|
|
curIndex++;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eCalcRev,c1Index,.5);
|
1999-04-19 09:27:55 +04:00
|
|
|
polypath[curIndex].x = aPoints[0].x;
|
|
|
|
polypath[curIndex].y = aPoints[0].y;
|
|
|
|
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));
|
|
|
|
|
|
|
|
polypath[0].x = (aPoints[0].x + aPoints[11].x)>>1;
|
|
|
|
polypath[0].y = (aPoints[0].y + aPoints[11].y)>>1;
|
|
|
|
curIndex = 1;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eCalc,c1Index,.5);
|
1999-04-19 09:27:55 +04:00
|
|
|
polypath[curIndex].x = aPoints[6].x ;
|
|
|
|
polypath[curIndex].y = aPoints[6].y;
|
|
|
|
curIndex++;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(aPoints,polypath,&curIndex,eInside,c1Index);
|
1999-04-19 09:27:55 +04:00
|
|
|
polypath[curIndex].x = aPoints[0].x;
|
|
|
|
polypath[curIndex].y = aPoints[0].y;
|
|
|
|
curIndex++;
|
|
|
|
aRenderingContext.FillPolygon(polypath,curIndex);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
* AntiAlias the polygon
|
|
|
|
* @update 4/13/99 dwc
|
|
|
|
*/
|
|
|
|
static void
|
1999-04-21 18:23:49 +04:00
|
|
|
AntiAliasPoly(nsIRenderingContext& aRenderingContext,nsPoint aPoints[],PRInt32 aStartIndex,PRInt32 aCurIndex,PRInt8 aSide,PRInt8 aCorner)
|
1999-04-19 09:27:55 +04:00
|
|
|
{
|
|
|
|
PRInt32 i;
|
1999-04-21 18:23:49 +04:00
|
|
|
PRInt32 x0,y0,x1,y1,offsetx,offsety;
|
|
|
|
|
|
|
|
offsetx = offsety = 0;
|
|
|
|
switch (aSide) {
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
if( aCorner == 1) {
|
|
|
|
offsetx = 0;
|
|
|
|
}else{
|
|
|
|
offsetx = -10;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
if( aCorner == 1) {
|
|
|
|
offsetx = 0;
|
|
|
|
}else{
|
|
|
|
offsetx = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
if( aCorner == 1) {
|
|
|
|
offsetx = -10;
|
|
|
|
}else{
|
|
|
|
offsetx = -10;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
if( aCorner == 1) {
|
|
|
|
offsety = -10;
|
|
|
|
}else{
|
|
|
|
offsety = -10;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
|
1999-04-21 18:23:49 +04:00
|
|
|
for(i=aStartIndex+1;i<aCurIndex;i++) {
|
|
|
|
x0 = aPoints[i-1].x+offsetx;
|
|
|
|
y0 = aPoints[i-1].y+offsety;
|
|
|
|
x1 = aPoints[i].x+offsetx;
|
|
|
|
y1 = aPoints[i].y+offsety;
|
|
|
|
aRenderingContext.DrawLine(x0,y0,x1,y1);
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
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
|
|
|
|
* @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)
|
|
|
|
{
|
|
|
|
PRInt32 nLeft,nTop,nRight,nBottom;
|
|
|
|
|
|
|
|
nLeft = mOuterLeft+aBorder.left;
|
|
|
|
nTop = mOuterTop+aBorder.top;
|
|
|
|
nRight = mOuterRight-aBorder.right;
|
|
|
|
nBottom = mOuterBottom-aBorder.bottom;
|
|
|
|
|
1999-04-21 18:23:49 +04:00
|
|
|
if(nLeft > nRight){
|
|
|
|
nLeft = nRight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(nTop > nBottom){
|
|
|
|
nTop = nBottom;
|
|
|
|
}
|
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
// set the passed in curves to the rounded borders of the rectangle
|
|
|
|
aULCurve.SetPoints(nLeft,mInnerTop,nLeft,nTop,mInnerLeft,nTop);
|
|
|
|
aURCurve.SetPoints(mInnerRight,nTop,nRight,nTop,nRight,mInnerTop);
|
|
|
|
aLRCurve.SetPoints(nRight,mInnerBottom,nRight,nBottom,mInnerRight,nBottom);
|
|
|
|
aLLCurve.SetPoints(mInnerLeft,nBottom,nLeft,nBottom,nLeft,mInnerBottom);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
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::Set(nscoord aLeft,nscoord aTop,PRInt32 aWidth,PRInt32 aHeight,PRInt16 aRadius)
|
|
|
|
{
|
1999-04-21 18:23:49 +04:00
|
|
|
PRInt32 width;
|
|
|
|
|
|
|
|
width = aLeft+aWidth;
|
|
|
|
|
|
|
|
if( aRadius > (aWidth>>1) )
|
|
|
|
mRoundness = aWidth>>1;
|
|
|
|
else
|
|
|
|
mRoundness = aRadius;
|
|
|
|
|
|
|
|
if( mRoundness > (aHeight>>1) )
|
|
|
|
mRoundness = aHeight>>1;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
// important coordinates that the path hits
|
|
|
|
mOuterLeft = aLeft;
|
|
|
|
mOuterRight = aLeft + aWidth;
|
|
|
|
mOuterTop = aTop;
|
|
|
|
mOuterBottom = aTop+aHeight;
|
1999-04-21 18:23:49 +04:00
|
|
|
mInnerLeft = mOuterLeft + mRoundness;
|
|
|
|
mInnerRight = mOuterRight - mRoundness;
|
|
|
|
mInnerTop = mOuterTop + mRoundness;
|
|
|
|
mInnerBottom = mOuterBottom - mRoundness;
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
|
|
|
|
// set the passed in curves to the rounded borders of the rectangle
|
|
|
|
aULCurve.SetPoints(mOuterLeft,mInnerTop,mOuterLeft,mOuterTop,mInnerLeft,mOuterTop);
|
|
|
|
aURCurve.SetPoints(mInnerRight,mOuterTop,mOuterRight,mOuterTop,mOuterRight,mInnerTop);
|
|
|
|
aLRCurve.SetPoints(mOuterRight,mInnerBottom,mOuterRight,mOuterBottom,mInnerRight,mOuterBottom);
|
|
|
|
aLLCurve.SetPoints(mInnerLeft,mOuterBottom,mOuterLeft,mOuterBottom,mOuterLeft,mInnerBottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
* 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
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(nsPoint aPoints[],nsPoint aPolyPath[],PRInt32 *aCurIndex,ePathTypes aPathType,PRInt32 &aC1Index,float aFrac)
|
1999-04-19 09:27:55 +04:00
|
|
|
{
|
|
|
|
QBCurve thecurve;
|
|
|
|
|
|
|
|
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;
|
1999-04-19 09:27:55 +04:00
|
|
|
aPolyPath[*aCurIndex].x = aPoints[3].x;
|
|
|
|
aPolyPath[*aCurIndex].y = aPoints[3].y;
|
|
|
|
(*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);
|
|
|
|
aPolyPath[*aCurIndex].x = aPoints[9].x;
|
|
|
|
aPolyPath[*aCurIndex].y = aPoints[9].y;
|
|
|
|
(*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:
|
|
|
|
thecurve.SetPoints( (aPoints[0].x+aPoints[11].x)>>1,(aPoints[0].y+aPoints[11].y)>>1,
|
|
|
|
(aPoints[1].x+aPoints[10].x)>>1,(aPoints[1].y+aPoints[10].y)>>1,
|
|
|
|
(aPoints[2].x+aPoints[9].x)>>1,(aPoints[2].y+aPoints[9].y)>>1);
|
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
|
|
|
aPolyPath[*aCurIndex].x = (aPoints[3].x+aPoints[8].x)>>1;
|
|
|
|
aPolyPath[*aCurIndex].y = (aPoints[3].y+aPoints[8].y)>>1;
|
|
|
|
(*aCurIndex)++;
|
|
|
|
thecurve.SetPoints( (aPoints[3].x+aPoints[8].x)>>1,(aPoints[3].y+aPoints[8].y)>>1,
|
|
|
|
(aPoints[4].x+aPoints[7].x)>>1,(aPoints[4].y+aPoints[7].y)>>1,
|
|
|
|
(aPoints[5].x+aPoints[6].x)>>1,(aPoints[5].y+aPoints[6].y)>>1);
|
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
|
|
|
break;
|
|
|
|
case eCalcRev:
|
|
|
|
thecurve.SetPoints( (aPoints[5].x+aPoints[6].x)>>1,(aPoints[5].y+aPoints[6].y)>>1,
|
|
|
|
(aPoints[4].x+aPoints[7].x)>>1,(aPoints[4].y+aPoints[7].y)>>1,
|
|
|
|
(aPoints[3].x+aPoints[8].x)>>1,(aPoints[3].y+aPoints[8].y)>>1);
|
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
|
|
|
aPolyPath[*aCurIndex].x = (aPoints[2].x+aPoints[9].x)>>1;
|
|
|
|
aPolyPath[*aCurIndex].y = (aPoints[2].y+aPoints[9].y)>>1;
|
|
|
|
(*aCurIndex)++;
|
|
|
|
thecurve.SetPoints( (aPoints[2].x+aPoints[9].x)>>1,(aPoints[2].y+aPoints[9].y)>>1,
|
|
|
|
(aPoints[1].x+aPoints[10].x)>>1,(aPoints[1].y+aPoints[10].y)>>1,
|
|
|
|
(aPoints[0].x+aPoints[11].x)>>1,(aPoints[0].y+aPoints[11].y)>>1);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
QBCurve curve1,curve2;
|
|
|
|
PRInt16 fx,fy,smag;
|
|
|
|
|
|
|
|
// divide the curve into 2 pieces
|
|
|
|
MidPointDivide(&curve1,&curve2);
|
|
|
|
|
|
|
|
fx = (PRInt16)abs(curve1.mAnc2.x - this->mCon.x);
|
|
|
|
fy = (PRInt16)abs(curve1.mAnc2.y - this->mCon.y);
|
|
|
|
|
|
|
|
smag = fx+fy-(PR_MIN(fx,fy)>>1);
|
|
|
|
//smag = fx*fx + fy*fy;
|
|
|
|
|
|
|
|
if (smag>2){
|
|
|
|
// split the curve again
|
|
|
|
curve1.SubDivide(aRenderingContext,aPointArray,aCurIndex);
|
|
|
|
curve2.SubDivide(aRenderingContext,aPointArray,aCurIndex);
|
|
|
|
}else{
|
|
|
|
if(aPointArray ) {
|
|
|
|
// save the points for further processing
|
|
|
|
aPointArray[*aCurIndex].x = curve1.mAnc2.x;
|
|
|
|
aPointArray[*aCurIndex].y = curve1.mAnc2.y;
|
|
|
|
(*aCurIndex)++;
|
|
|
|
aPointArray[*aCurIndex].x = curve2.mAnc2.x;
|
|
|
|
aPointArray[*aCurIndex].y = curve2.mAnc2.y;
|
|
|
|
(*aCurIndex)++;
|
|
|
|
}else{
|
|
|
|
// draw the curve
|
|
|
|
aRenderingContext->DrawLine(curve1.mAnc1.x,curve1.mAnc1.y,curve1.mAnc2.x,curve1.mAnc2.y);
|
|
|
|
aRenderingContext->DrawLine(curve1.mAnc2.x,curve1.mAnc2.y,curve2.mAnc2.x,curve2.mAnc2.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
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)
|
|
|
|
{
|
|
|
|
nsPoint a1,control1,control2;
|
|
|
|
|
|
|
|
// do the math (averages inline)
|
|
|
|
control1.x = (PRInt32)((mAnc1.x + mCon.x)>>1);
|
|
|
|
control1.y = (PRInt32)((mAnc1.y + mCon.y)>>1);
|
|
|
|
|
|
|
|
control2.x = (PRInt32)((mAnc2.x + mCon.x)>>1);
|
|
|
|
control2.y = (PRInt32)((mAnc2.y + mCon.y)>>1);
|
|
|
|
|
|
|
|
a1.x = (PRInt32)((control1.x + control2.x)>>1);
|
|
|
|
a1.y = (PRInt32)((control1.y + control2.y)>>1);
|
|
|
|
|
|
|
|
// put the math into our 2 new curves
|
|
|
|
A->mAnc1 = this->mAnc1;
|
|
|
|
A->mCon = control1;
|
|
|
|
A->mAnc2 = a1;
|
|
|
|
B->mAnc1 = a1;
|
|
|
|
B->mCon = control2;
|
|
|
|
B->mAnc2 = this->mAnc2;
|
|
|
|
}
|