2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2002-01-08 02:46:07 +03:00
|
|
|
// vim:cindent:ts=2:et:sw=2:
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2005-08-29 08:39:31 +04:00
|
|
|
* Mats Palmgren <mats.palmgren@bredband.net>
|
2005-11-30 16:26:34 +03:00
|
|
|
* Takeshi Ichimaru <ayakawa.m@gmail.com>
|
|
|
|
* Masayuki Nakano <masayuki@d-toybox.com>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-30 09:56:38 +04:00
|
|
|
|
|
|
|
/* utility functions for drawing borders and backgrounds */
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsStyleConsts.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIImage.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsPoint.h"
|
|
|
|
#include "nsRect.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIPresShell.h"
|
2004-09-02 07:08:51 +04:00
|
|
|
#include "nsFrameManager.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1999-10-01 18:35:20 +04:00
|
|
|
#include "nsIDrawingSurface.h"
|
1999-08-27 18:37:47 +04:00
|
|
|
#include "nsTransform2D.h"
|
1999-10-07 18:57:32 +04:00
|
|
|
#include "nsIDeviceContext.h"
|
2000-03-30 10:27:32 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
2000-06-08 03:06:41 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
2001-08-10 00:22:39 +04:00
|
|
|
#include "imgIRequest.h"
|
|
|
|
#include "imgIContainer.h"
|
2003-03-06 02:34:48 +03:00
|
|
|
#include "gfxIImageFrame.h"
|
2001-10-24 04:01:09 +04:00
|
|
|
#include "nsCSSRendering.h"
|
2002-09-12 08:43:31 +04:00
|
|
|
#include "nsCSSColorUtils.h"
|
2001-12-18 01:51:39 +03:00
|
|
|
#include "nsITheme.h"
|
|
|
|
#include "nsThemeConstants.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2002-01-08 02:46:07 +03:00
|
|
|
#include "nsIDOMHTMLBodyElement.h"
|
|
|
|
#include "nsIDOMHTMLDocument.h"
|
2003-02-23 05:49:22 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2003-10-15 06:48:25 +04:00
|
|
|
#include "nsINameSpaceManager.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2006-04-21 21:52:05 +04:00
|
|
|
#include "gfxContext.h"
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#define BORDER_FULL 0 //entire side
|
|
|
|
#define BORDER_INSIDE 1 //inside half
|
|
|
|
#define BORDER_OUTSIDE 2 //outside half
|
|
|
|
|
|
|
|
//thickness of dashed line relative to dotted line
|
|
|
|
#define DOT_LENGTH 1 //square
|
|
|
|
#define DASH_LENGTH 3 //3 times longer than dot
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
//some shorthand for side bits
|
|
|
|
#define SIDE_BIT_TOP (1 << NS_SIDE_TOP)
|
|
|
|
#define SIDE_BIT_RIGHT (1 << NS_SIDE_RIGHT)
|
|
|
|
#define SIDE_BIT_BOTTOM (1 << NS_SIDE_BOTTOM)
|
|
|
|
#define SIDE_BIT_LEFT (1 << NS_SIDE_LEFT)
|
|
|
|
#define SIDE_BITS_ALL (SIDE_BIT_TOP|SIDE_BIT_RIGHT|SIDE_BIT_BOTTOM|SIDE_BIT_LEFT)
|
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
/** The following classes are used by CSSRendering for the rounded rect implementation */
|
|
|
|
#define MAXPATHSIZE 12
|
|
|
|
#define MAXPOLYPATHSIZE 1000
|
|
|
|
|
|
|
|
enum ePathTypes{
|
|
|
|
eOutside =0,
|
|
|
|
eInside,
|
|
|
|
eCalc,
|
|
|
|
eCalcRev
|
|
|
|
};
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
// To avoid storing this data on nsInlineFrame (bloat) and to avoid
|
|
|
|
// recalculating this for each frame in a continuation (perf), hold
|
|
|
|
// a cache of various coordinate information that we need in order
|
|
|
|
// to paint inline backgrounds.
|
|
|
|
struct InlineBackgroundData
|
|
|
|
{
|
|
|
|
InlineBackgroundData()
|
|
|
|
: mFrame(nsnull)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~InlineBackgroundData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
mBoundingBox.SetRect(0,0,0,0);
|
|
|
|
mContinuationPoint = mUnbrokenWidth = 0;
|
|
|
|
mFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect GetContinuousRect(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
SetFrame(aFrame);
|
|
|
|
|
|
|
|
// Assume background-origin: border and return a rect with offsets
|
|
|
|
// relative to (0,0). If we have a different background-origin,
|
|
|
|
// then our rect should be deflated appropriately by our caller.
|
2003-07-05 19:04:34 +04:00
|
|
|
return nsRect(-mContinuationPoint, 0, mUnbrokenWidth, mFrame->GetSize().height);
|
2003-01-17 12:33:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect GetBoundingRect(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
SetFrame(aFrame);
|
|
|
|
|
|
|
|
// Move the offsets relative to (0,0) which puts the bounding box into
|
|
|
|
// our coordinate system rather than our parent's. We do this by
|
|
|
|
// moving it the back distance from us to the bounding box.
|
|
|
|
// This also assumes background-origin: border, so our caller will
|
|
|
|
// need to deflate us if needed.
|
|
|
|
nsRect boundingBox(mBoundingBox);
|
2003-07-05 19:04:34 +04:00
|
|
|
nsPoint point = mFrame->GetPosition();
|
2003-01-17 12:33:52 +03:00
|
|
|
boundingBox.MoveBy(-point.x, -point.y);
|
|
|
|
|
|
|
|
return boundingBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsIFrame* mFrame;
|
|
|
|
nscoord mContinuationPoint;
|
|
|
|
nscoord mUnbrokenWidth;
|
|
|
|
nsRect mBoundingBox;
|
|
|
|
|
|
|
|
void SetFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Need a frame");
|
|
|
|
|
2004-09-14 06:28:03 +04:00
|
|
|
nsIFrame *prevInFlow = aFrame->GetPrevInFlow();
|
2003-01-17 12:33:52 +03:00
|
|
|
|
|
|
|
if (!prevInFlow || mFrame != prevInFlow) {
|
|
|
|
// Ok, we've got the wrong frame. We have to start from scratch.
|
|
|
|
Reset();
|
|
|
|
Init(aFrame);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get our last frame's size and add its width to our continuation
|
|
|
|
// point before we cache the new frame.
|
2003-07-05 19:04:34 +04:00
|
|
|
mContinuationPoint += mFrame->GetSize().width;
|
2003-01-17 12:33:52 +03:00
|
|
|
|
|
|
|
mFrame = aFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init(nsIFrame* aFrame)
|
2004-09-14 06:28:03 +04:00
|
|
|
{
|
2003-01-17 12:33:52 +03:00
|
|
|
// Start with the previous flow frame as our continuation point
|
|
|
|
// is the total of the widths of the previous frames.
|
2004-09-14 06:28:03 +04:00
|
|
|
nsIFrame* inlineFrame = aFrame->GetPrevInFlow();
|
2003-01-17 12:33:52 +03:00
|
|
|
|
|
|
|
while (inlineFrame) {
|
2003-07-05 19:04:34 +04:00
|
|
|
nsRect rect = inlineFrame->GetRect();
|
2003-01-17 12:33:52 +03:00
|
|
|
mContinuationPoint += rect.width;
|
|
|
|
mUnbrokenWidth += rect.width;
|
|
|
|
mBoundingBox.UnionRect(mBoundingBox, rect);
|
2004-09-14 06:28:03 +04:00
|
|
|
inlineFrame = inlineFrame->GetPrevInFlow();
|
2003-01-17 12:33:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Next add this frame and subsequent frames to the bounding box and
|
|
|
|
// unbroken width.
|
|
|
|
inlineFrame = aFrame;
|
|
|
|
while (inlineFrame) {
|
2003-07-05 19:04:34 +04:00
|
|
|
nsRect rect = inlineFrame->GetRect();
|
2003-01-17 12:33:52 +03:00
|
|
|
mUnbrokenWidth += rect.width;
|
|
|
|
mBoundingBox.UnionRect(mBoundingBox, rect);
|
2004-09-14 06:28:03 +04:00
|
|
|
inlineFrame = inlineFrame->GetNextInFlow();
|
2003-01-17 12:33:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mFrame = aFrame;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-03-14 22:48:51 +03:00
|
|
|
static InlineBackgroundData* gInlineBGData = nsnull;
|
2003-01-17 12:33:52 +03:00
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
static void GetPath(nsFloatPoint aPoints[],nsPoint aPolyPath[],PRInt32 *aCurIndex,ePathTypes aPathType,PRInt32 &aC1Index,float aFrac=0);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2001-10-03 04:08:25 +04:00
|
|
|
// FillRect or InvertRect depending on the renderingaInvert parameter
|
|
|
|
static void FillOrInvertRect(nsIRenderingContext& aRC,nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, PRBool aInvert);
|
|
|
|
static void FillOrInvertRect(nsIRenderingContext& aRC,const nsRect& aRect, PRBool aInvert);
|
|
|
|
|
2007-03-14 22:48:51 +03:00
|
|
|
// Initialize any static variables used by nsCSSRendering.
|
|
|
|
nsresult nsCSSRendering::Init()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!gInlineBGData, "Init called twice");
|
|
|
|
gInlineBGData = new InlineBackgroundData();
|
|
|
|
if (!gInlineBGData)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up any global variables used by nsCSSRendering.
|
|
|
|
void nsCSSRendering::Shutdown()
|
|
|
|
{
|
|
|
|
delete gInlineBGData;
|
|
|
|
gInlineBGData = nsnull;
|
|
|
|
}
|
|
|
|
|
1998-10-08 08:38:41 +04:00
|
|
|
// Draw a line, skipping that portion which crosses aGap. aGap defines a rectangle gap
|
|
|
|
// This services fieldset legends and only works for coords defining horizontal lines.
|
|
|
|
void nsCSSRendering::DrawLine (nsIRenderingContext& aContext,
|
|
|
|
nscoord aX1, nscoord aY1, nscoord aX2, nscoord aY2,
|
|
|
|
nsRect* aGap)
|
|
|
|
{
|
|
|
|
if (nsnull == aGap) {
|
|
|
|
aContext.DrawLine(aX1, aY1, aX2, aY2);
|
|
|
|
} else {
|
|
|
|
nscoord x1 = (aX1 < aX2) ? aX1 : aX2;
|
|
|
|
nscoord x2 = (aX1 < aX2) ? aX2 : aX1;
|
|
|
|
nsPoint gapUpperRight(aGap->x + aGap->width, aGap->y);
|
|
|
|
nsPoint gapLowerRight(aGap->x + aGap->width, aGap->y + aGap->height);
|
|
|
|
if ((aGap->y <= aY1) && (gapLowerRight.y >= aY2)) {
|
|
|
|
if ((aGap->x > x1) && (aGap->x < x2)) {
|
|
|
|
aContext.DrawLine(x1, aY1, aGap->x, aY1);
|
|
|
|
}
|
|
|
|
if ((gapLowerRight.x > x1) && (gapLowerRight.x < x2)) {
|
|
|
|
aContext.DrawLine(gapUpperRight.x, aY2, x2, aY2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aContext.DrawLine(aX1, aY1, aX2, aY2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill a polygon, skipping that portion which crosses aGap. aGap defines a rectangle gap
|
|
|
|
// This services fieldset legends and only works for points defining a horizontal rectangle
|
|
|
|
void nsCSSRendering::FillPolygon (nsIRenderingContext& aContext,
|
|
|
|
const nsPoint aPoints[],
|
|
|
|
PRInt32 aNumPoints,
|
|
|
|
nsRect* aGap)
|
|
|
|
{
|
2001-10-03 04:08:25 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsPenMode penMode;
|
2003-02-23 01:27:45 +03:00
|
|
|
if (NS_SUCCEEDED(aContext.GetPenMode(penMode)) &&
|
|
|
|
penMode == nsPenMode_kInvert) {
|
2001-10-03 04:08:25 +04:00
|
|
|
NS_WARNING( "Invert mode ignored in FillPolygon" );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-10-08 08:38:41 +04:00
|
|
|
if (nsnull == aGap) {
|
|
|
|
aContext.FillPolygon(aPoints, aNumPoints);
|
|
|
|
} else if (4 == aNumPoints) {
|
|
|
|
nsPoint gapUpperRight(aGap->x + aGap->width, aGap->y);
|
|
|
|
nsPoint gapLowerRight(aGap->x + aGap->width, aGap->y + aGap->height);
|
|
|
|
|
|
|
|
// sort the 4 points by x
|
|
|
|
nsPoint points[4];
|
1998-10-08 18:58:32 +04:00
|
|
|
for (PRInt32 pX = 0; pX < 4; pX++) {
|
|
|
|
points[pX] = aPoints[pX];
|
1998-10-08 08:38:41 +04:00
|
|
|
}
|
1998-10-08 18:58:32 +04:00
|
|
|
for (PRInt32 i = 0; i < 3; i++) {
|
|
|
|
for (PRInt32 j = i+1; j < 4; j++) {
|
1998-10-08 08:38:41 +04:00
|
|
|
if (points[j].x < points[i].x) {
|
|
|
|
nsPoint swap = points[i];
|
|
|
|
points[i] = points[j];
|
|
|
|
points[j] = swap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint upperLeft = (points[0].y <= points[1].y) ? points[0] : points[1];
|
|
|
|
nsPoint lowerLeft = (points[0].y <= points[1].y) ? points[1] : points[0];
|
|
|
|
nsPoint upperRight = (points[2].y <= points[3].y) ? points[2] : points[3];
|
|
|
|
nsPoint lowerRight = (points[2].y <= points[3].y) ? points[3] : points[2];
|
|
|
|
|
|
|
|
|
|
|
|
if ((aGap->y <= upperLeft.y) && (gapLowerRight.y >= lowerRight.y)) {
|
|
|
|
if ((aGap->x > upperLeft.x) && (aGap->x < upperRight.x)) {
|
|
|
|
nsPoint leftRect[4];
|
|
|
|
leftRect[0] = upperLeft;
|
|
|
|
leftRect[1] = nsPoint(aGap->x, upperLeft.y);
|
|
|
|
leftRect[2] = nsPoint(aGap->x, lowerLeft.y);
|
|
|
|
leftRect[3] = lowerLeft;
|
|
|
|
aContext.FillPolygon(leftRect, 4);
|
|
|
|
}
|
|
|
|
if ((gapUpperRight.x > upperLeft.x) && (gapUpperRight.x < upperRight.x)) {
|
|
|
|
nsPoint rightRect[4];
|
|
|
|
rightRect[0] = nsPoint(gapUpperRight.x, upperRight.y);
|
|
|
|
rightRect[1] = upperRight;
|
|
|
|
rightRect[2] = lowerRight;
|
|
|
|
rightRect[3] = nsPoint(gapLowerRight.x, lowerRight.y);
|
|
|
|
aContext.FillPolygon(rightRect, 4);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aContext.FillPolygon(aPoints, aNumPoints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-05-27 00:52:59 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/**
|
|
|
|
* Make a bevel color
|
|
|
|
*/
|
|
|
|
nscolor nsCSSRendering::MakeBevelColor(PRIntn whichSide, PRUint8 style,
|
1999-01-23 01:24:05 +03:00
|
|
|
nscolor aBackgroundColor,
|
2007-02-01 05:45:55 +03:00
|
|
|
nscolor aBorderColor)
|
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
|
2007-02-01 05:45:55 +03:00
|
|
|
NS_GetSpecial3DColors(colors, aBackgroundColor, aBorderColor);
|
1998-05-27 00:52:59 +04:00
|
|
|
|
2007-02-01 05:45:55 +03:00
|
|
|
if ((style == NS_STYLE_BORDER_STYLE_OUTSET) ||
|
1998-04-14 00:24:54 +04:00
|
|
|
(style == NS_STYLE_BORDER_STYLE_RIDGE)) {
|
2007-02-01 05:45:55 +03:00
|
|
|
// Flip colors for these two border styles
|
1998-04-14 00:24:54 +04:00
|
|
|
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
|
|
|
|
|
2005-11-30 16:26:34 +03:00
|
|
|
#define ACTUAL_THICKNESS(outside, inside, frac, tpp) \
|
|
|
|
(NSToCoordRound(((outside) - (inside)) * (frac) / (tpp)) * (tpp))
|
|
|
|
|
2002-02-19 18:48:28 +03:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/**
|
|
|
|
* Draw a dotted/dashed sides of a box
|
|
|
|
*/
|
|
|
|
//XXX dashes which span more than two edges are not handled properly MMP
|
|
|
|
void nsCSSRendering::DrawDashedSides(PRIntn startSide,
|
|
|
|
nsIRenderingContext& aContext,
|
2002-01-08 18:13:02 +03:00
|
|
|
/* XXX unused */ const nsRect& aDirtyRect,
|
1998-12-07 22:02:13 +03:00
|
|
|
const PRUint8 borderStyles[],
|
|
|
|
const nscolor borderColors[],
|
1998-04-14 00:24:54 +04:00
|
|
|
const nsRect& borderOutside,
|
|
|
|
const nsRect& borderInside,
|
1998-10-08 08:38:41 +04:00
|
|
|
PRIntn aSkipSides,
|
2002-01-08 18:13:02 +03:00
|
|
|
/* XXX unused */ nsRect* aGap)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-10-26 18:34:17 +04:00
|
|
|
PRIntn dashLength;
|
|
|
|
nsRect dashRect, firstRect, currRect;
|
|
|
|
PRBool bSolid = PR_TRUE;
|
|
|
|
float over = 0.0f;
|
|
|
|
PRUint8 style = borderStyles[startSide];
|
|
|
|
PRBool skippedSide = PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
for (PRIntn whichSide = startSide; whichSide < 4; whichSide++) {
|
|
|
|
PRUint8 prevStyle = style;
|
1998-12-07 22:02:13 +03:00
|
|
|
style = borderStyles[whichSide];
|
1998-12-10 20:50:11 +03:00
|
|
|
if ((1<<whichSide) & aSkipSides) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// Skipped side
|
|
|
|
skippedSide = PR_TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((style == NS_STYLE_BORDER_STYLE_DASHED) ||
|
|
|
|
(style == NS_STYLE_BORDER_STYLE_DOTTED))
|
|
|
|
{
|
|
|
|
if ((style != prevStyle) || skippedSide) {
|
|
|
|
//style discontinuity
|
|
|
|
over = 0.0f;
|
|
|
|
bSolid = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX units for dash & dot?
|
|
|
|
if (style == NS_STYLE_BORDER_STYLE_DASHED) {
|
|
|
|
dashLength = DASH_LENGTH;
|
|
|
|
} else {
|
|
|
|
dashLength = DOT_LENGTH;
|
|
|
|
}
|
|
|
|
|
1998-12-07 22:02:13 +03:00
|
|
|
aContext.SetColor(borderColors[whichSide]);
|
1998-04-14 00:24:54 +04:00
|
|
|
switch (whichSide) {
|
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
//XXX need to properly handle wrap around from last edge to first edge
|
|
|
|
//(this is the first edge) MMP
|
|
|
|
dashRect.width = borderInside.x - borderOutside.x;
|
|
|
|
dashRect.height = nscoord(dashRect.width * dashLength);
|
|
|
|
dashRect.x = borderOutside.x;
|
|
|
|
dashRect.y = borderInside.YMost() - dashRect.height;
|
|
|
|
|
|
|
|
if (over > 0.0f) {
|
|
|
|
firstRect.x = dashRect.x;
|
|
|
|
firstRect.width = dashRect.width;
|
|
|
|
firstRect.height = nscoord(dashRect.height * over);
|
|
|
|
firstRect.y = dashRect.y + (dashRect.height - firstRect.height);
|
|
|
|
over = 0.0f;
|
|
|
|
currRect = firstRect;
|
|
|
|
} else {
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (currRect.YMost() > borderInside.y) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.y < borderInside.y) {
|
|
|
|
over = float(borderInside.y - dashRect.y) /
|
|
|
|
float(dashRect.height);
|
|
|
|
currRect.height = currRect.height - (borderInside.y - currRect.y);
|
|
|
|
currRect.y = borderInside.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.y = dashRect.y - currRect.height;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
//if we are continuing a solid rect, fill in the corner first
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(borderOutside.x, borderOutside.y,
|
|
|
|
borderInside.x - borderOutside.x,
|
|
|
|
borderInside.y - borderOutside.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
dashRect.height = borderInside.y - borderOutside.y;
|
|
|
|
dashRect.width = dashRect.height * dashLength;
|
|
|
|
dashRect.x = borderInside.x;
|
|
|
|
dashRect.y = borderOutside.y;
|
|
|
|
|
|
|
|
if (over > 0.0f) {
|
|
|
|
firstRect.x = dashRect.x;
|
|
|
|
firstRect.y = dashRect.y;
|
|
|
|
firstRect.width = nscoord(dashRect.width * over);
|
|
|
|
firstRect.height = dashRect.height;
|
|
|
|
over = 0.0f;
|
|
|
|
currRect = firstRect;
|
|
|
|
} else {
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (currRect.x < borderInside.XMost()) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.XMost() > borderInside.XMost()) {
|
|
|
|
over = float(dashRect.XMost() - borderInside.XMost()) /
|
|
|
|
float(dashRect.width);
|
|
|
|
currRect.width = currRect.width -
|
|
|
|
(currRect.XMost() - borderInside.XMost());
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.x = dashRect.x + currRect.width;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
//if we are continuing a solid rect, fill in the corner first
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(borderInside.XMost(), borderOutside.y,
|
|
|
|
borderOutside.XMost() - borderInside.XMost(),
|
|
|
|
borderInside.y - borderOutside.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
dashRect.width = borderOutside.XMost() - borderInside.XMost();
|
|
|
|
dashRect.height = nscoord(dashRect.width * dashLength);
|
|
|
|
dashRect.x = borderInside.XMost();
|
|
|
|
dashRect.y = borderInside.y;
|
|
|
|
|
|
|
|
if (over > 0.0f) {
|
|
|
|
firstRect.x = dashRect.x;
|
|
|
|
firstRect.y = dashRect.y;
|
|
|
|
firstRect.width = dashRect.width;
|
|
|
|
firstRect.height = nscoord(dashRect.height * over);
|
|
|
|
over = 0.0f;
|
|
|
|
currRect = firstRect;
|
|
|
|
} else {
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (currRect.y < borderInside.YMost()) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.YMost() > borderInside.YMost()) {
|
|
|
|
over = float(dashRect.YMost() - borderInside.YMost()) /
|
|
|
|
float(dashRect.height);
|
|
|
|
currRect.height = currRect.height -
|
|
|
|
(currRect.YMost() - borderInside.YMost());
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.y = dashRect.y + currRect.height;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
//if we are continuing a solid rect, fill in the corner first
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(borderInside.XMost(), borderInside.YMost(),
|
|
|
|
borderOutside.XMost() - borderInside.XMost(),
|
|
|
|
borderOutside.YMost() - borderInside.YMost());
|
|
|
|
}
|
|
|
|
|
|
|
|
dashRect.height = borderOutside.YMost() - borderInside.YMost();
|
|
|
|
dashRect.width = nscoord(dashRect.height * dashLength);
|
|
|
|
dashRect.x = borderInside.XMost() - dashRect.width;
|
|
|
|
dashRect.y = borderInside.YMost();
|
|
|
|
|
|
|
|
if (over > 0.0f) {
|
|
|
|
firstRect.y = dashRect.y;
|
|
|
|
firstRect.width = nscoord(dashRect.width * over);
|
|
|
|
firstRect.height = dashRect.height;
|
|
|
|
firstRect.x = dashRect.x + (dashRect.width - firstRect.width);
|
|
|
|
over = 0.0f;
|
|
|
|
currRect = firstRect;
|
|
|
|
} else {
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (currRect.XMost() > borderInside.x) {
|
|
|
|
//clip if necessary
|
|
|
|
if (currRect.x < borderInside.x) {
|
|
|
|
over = float(borderInside.x - dashRect.x) / float(dashRect.width);
|
|
|
|
currRect.width = currRect.width - (borderInside.x - currRect.x);
|
|
|
|
currRect.x = borderInside.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
|
|
|
aContext.FillRect(currRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup for next iteration
|
|
|
|
if (over == 0.0f) {
|
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
}
|
|
|
|
dashRect.x = dashRect.x - currRect.width;
|
|
|
|
currRect = dashRect;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
skippedSide = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-26 18:34:17 +04:00
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation in nsCSSRendering.h
|
2003-07-30 12:13:07 +04:00
|
|
|
* @update 10/22/99 dwc
|
1999-10-26 18:34:17 +04:00
|
|
|
*/
|
1998-12-07 22:02:13 +03:00
|
|
|
void nsCSSRendering::DrawDashedSides(PRIntn startSide,
|
|
|
|
nsIRenderingContext& aContext,
|
1999-10-26 18:34:17 +04:00
|
|
|
const nsRect& aDirtyRect,
|
2001-06-01 02:19:43 +04:00
|
|
|
const nsStyleColor* aColorStyle,
|
2001-02-07 12:57:26 +03:00
|
|
|
const nsStyleBorder* aBorderStyle,
|
|
|
|
const nsStyleOutline* aOutlineStyle,
|
1999-08-19 18:22:47 +04:00
|
|
|
PRBool aDoOutline,
|
1998-12-07 22:02:13 +03:00
|
|
|
const nsRect& borderOutside,
|
|
|
|
const nsRect& borderInside,
|
|
|
|
PRIntn aSkipSides,
|
2002-01-08 18:13:02 +03:00
|
|
|
/* XXX unused */ nsRect* aGap)
|
1998-12-07 22:02:13 +03:00
|
|
|
{
|
2001-02-07 12:57:26 +03:00
|
|
|
|
1999-10-26 18:34:17 +04:00
|
|
|
PRIntn dashLength;
|
1999-11-03 08:46:01 +03:00
|
|
|
nsRect dashRect, currRect;
|
2002-01-08 18:13:02 +03:00
|
|
|
nscoord temp, temp1, adjust;
|
1999-10-26 18:34:17 +04:00
|
|
|
PRBool bSolid = PR_TRUE;
|
|
|
|
float over = 0.0f;
|
|
|
|
PRBool skippedSide = PR_FALSE;
|
|
|
|
|
2006-04-29 03:21:01 +04:00
|
|
|
NS_ASSERTION(aColorStyle &&
|
|
|
|
((aDoOutline && aOutlineStyle) || (!aDoOutline && aBorderStyle)),
|
|
|
|
"null params not allowed");
|
2001-02-07 12:57:26 +03:00
|
|
|
PRUint8 style = aDoOutline
|
|
|
|
? aOutlineStyle->GetOutlineStyle()
|
|
|
|
: aBorderStyle->GetBorderStyle(startSide);
|
1999-10-26 18:34:17 +04:00
|
|
|
|
|
|
|
// find the x and y width
|
2002-01-08 18:13:02 +03:00
|
|
|
nscoord xwidth = aDirtyRect.XMost();
|
|
|
|
nscoord ywidth = aDirtyRect.YMost();
|
1998-12-07 22:02:13 +03:00
|
|
|
|
|
|
|
for (PRIntn whichSide = startSide; whichSide < 4; whichSide++) {
|
|
|
|
PRUint8 prevStyle = style;
|
2001-02-07 12:57:26 +03:00
|
|
|
style = aDoOutline
|
|
|
|
? aOutlineStyle->GetOutlineStyle()
|
|
|
|
: aBorderStyle->GetBorderStyle(whichSide);
|
1998-12-10 20:50:11 +03:00
|
|
|
if ((1<<whichSide) & aSkipSides) {
|
1998-12-07 22:02:13 +03:00
|
|
|
// Skipped side
|
|
|
|
skippedSide = PR_TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((style == NS_STYLE_BORDER_STYLE_DASHED) ||
|
|
|
|
(style == NS_STYLE_BORDER_STYLE_DOTTED))
|
|
|
|
{
|
|
|
|
if ((style != prevStyle) || skippedSide) {
|
|
|
|
//style discontinuity
|
|
|
|
over = 0.0f;
|
|
|
|
bSolid = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (style == NS_STYLE_BORDER_STYLE_DASHED) {
|
|
|
|
dashLength = DASH_LENGTH;
|
|
|
|
} else {
|
|
|
|
dashLength = DOT_LENGTH;
|
|
|
|
}
|
|
|
|
|
2006-04-25 13:19:29 +04:00
|
|
|
// default to current color in case color cannot be resolved
|
|
|
|
// (because invert is not supported on cur platform)
|
|
|
|
nscolor sideColor(aColorStyle->mColor);
|
|
|
|
|
2007-03-15 19:16:20 +03:00
|
|
|
PRBool isInvert = PR_FALSE;
|
1999-08-19 18:22:47 +04:00
|
|
|
if (aDoOutline) {
|
2007-03-15 19:16:20 +03:00
|
|
|
if (!aOutlineStyle->GetOutlineInitialColor()) {
|
2001-10-03 04:08:25 +04:00
|
|
|
aOutlineStyle->GetOutlineColor(sideColor);
|
|
|
|
}
|
2007-03-15 19:16:20 +03:00
|
|
|
#ifdef GFX_HAS_INVERT
|
|
|
|
else {
|
|
|
|
isInvert = PR_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
1999-08-19 18:22:47 +04:00
|
|
|
} else {
|
2001-06-01 02:19:43 +04:00
|
|
|
PRBool transparent;
|
|
|
|
PRBool foreground;
|
|
|
|
aBorderStyle->GetBorderColor(whichSide, sideColor, transparent, foreground);
|
|
|
|
if (foreground)
|
|
|
|
sideColor = aColorStyle->mColor;
|
|
|
|
if (transparent)
|
1999-08-19 18:22:47 +04:00
|
|
|
continue; // side is transparent
|
1999-03-28 08:30:28 +04:00
|
|
|
}
|
|
|
|
aContext.SetColor(sideColor);
|
2001-10-03 04:08:25 +04:00
|
|
|
|
1998-12-07 22:02:13 +03:00
|
|
|
switch (whichSide) {
|
1999-10-26 18:34:17 +04:00
|
|
|
case NS_SIDE_RIGHT:
|
1998-12-07 22:02:13 +03:00
|
|
|
case NS_SIDE_LEFT:
|
1999-10-26 18:34:17 +04:00
|
|
|
bSolid = PR_FALSE;
|
|
|
|
|
|
|
|
// This is our dot or dash..
|
1999-11-15 18:33:25 +03:00
|
|
|
if(whichSide==NS_SIDE_LEFT){
|
|
|
|
dashRect.width = borderInside.x - borderOutside.x;
|
|
|
|
} else {
|
|
|
|
dashRect.width = borderOutside.XMost() - borderInside.XMost();
|
|
|
|
}
|
1999-11-03 08:46:01 +03:00
|
|
|
if( dashRect.width >0 ) {
|
|
|
|
dashRect.height = dashRect.width * dashLength;
|
|
|
|
dashRect.y = borderOutside.y;
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
if(whichSide == NS_SIDE_RIGHT){
|
|
|
|
dashRect.x = borderInside.XMost();
|
|
|
|
} else {
|
|
|
|
dashRect.x = borderOutside.x;
|
|
|
|
}
|
1998-12-07 22:02:13 +03:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
temp = borderOutside.height;
|
1999-11-03 08:46:01 +03:00
|
|
|
temp1 = temp/dashRect.height;
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
currRect = dashRect;
|
1999-10-26 18:34:17 +04:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
if((temp1%2)==0){
|
|
|
|
adjust = (dashRect.height-(temp%dashRect.height))/2; // adjust back
|
|
|
|
// draw in the left and right
|
2001-10-03 04:08:25 +04:00
|
|
|
FillOrInvertRect(aContext, dashRect.x, borderOutside.y,dashRect.width, dashRect.height-adjust,isInvert);
|
|
|
|
FillOrInvertRect(aContext,dashRect.x,(borderOutside.YMost()-(dashRect.height-adjust)),dashRect.width, dashRect.height-adjust,isInvert);
|
1999-11-03 08:46:01 +03:00
|
|
|
currRect.y += (dashRect.height-adjust);
|
2006-01-26 05:29:17 +03:00
|
|
|
temp-= (dashRect.height-adjust);
|
1999-11-03 08:46:01 +03:00
|
|
|
} else {
|
|
|
|
adjust = (temp%dashRect.width)/2; // adjust a tad longer
|
|
|
|
// draw in the left and right
|
2001-10-03 04:08:25 +04:00
|
|
|
FillOrInvertRect(aContext, dashRect.x, borderOutside.y,dashRect.width, dashRect.height+adjust,isInvert);
|
|
|
|
FillOrInvertRect(aContext, dashRect.x,(borderOutside.YMost()-(dashRect.height+adjust)),dashRect.width, dashRect.height+adjust,isInvert);
|
1999-11-03 08:46:01 +03:00
|
|
|
currRect.y += (dashRect.height+adjust);
|
2006-01-26 05:29:17 +03:00
|
|
|
temp-= (dashRect.height+adjust);
|
1999-11-03 08:46:01 +03:00
|
|
|
}
|
1999-10-26 18:34:17 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
temp += borderOutside.y;
|
1999-11-03 08:46:01 +03:00
|
|
|
if( temp > ywidth)
|
|
|
|
temp = ywidth;
|
|
|
|
|
|
|
|
// get the currRect's x into the view before we start
|
|
|
|
if( currRect.y < aDirtyRect.y){
|
|
|
|
temp1 = NSToCoordFloor((float)((aDirtyRect.y-currRect.y)/dashRect.height));
|
|
|
|
currRect.y += temp1*dashRect.height;
|
|
|
|
if((temp1%2)==1){
|
|
|
|
bSolid = PR_TRUE;
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
1999-11-03 08:46:01 +03:00
|
|
|
|
|
|
|
while(currRect.y<temp) {
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
2001-10-03 04:08:25 +04:00
|
|
|
FillOrInvertRect(aContext, currRect,isInvert);
|
1999-11-03 08:46:01 +03:00
|
|
|
}
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
currRect.y += dashRect.height;
|
1998-12-07 22:02:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-10-26 18:34:17 +04:00
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
bSolid = PR_FALSE;
|
|
|
|
|
|
|
|
// This is our dot or dash..
|
1999-11-15 18:33:25 +03:00
|
|
|
|
|
|
|
if(whichSide==NS_SIDE_TOP){
|
|
|
|
dashRect.height = borderInside.y - borderOutside.y;
|
|
|
|
} else {
|
|
|
|
dashRect.height = borderOutside.YMost() - borderInside.YMost();
|
|
|
|
}
|
1999-11-03 08:46:01 +03:00
|
|
|
if( dashRect.height >0 ) {
|
|
|
|
dashRect.width = dashRect.height * dashLength;
|
|
|
|
dashRect.x = borderOutside.x;
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
if(whichSide == NS_SIDE_BOTTOM){
|
|
|
|
dashRect.y = borderInside.YMost();
|
|
|
|
} else {
|
|
|
|
dashRect.y = borderOutside.y;
|
|
|
|
}
|
1998-12-07 22:02:13 +03:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
temp = borderOutside.width;
|
1999-11-03 08:46:01 +03:00
|
|
|
temp1 = temp/dashRect.width;
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
currRect = dashRect;
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
if((temp1%2)==0){
|
|
|
|
adjust = (dashRect.width-(temp%dashRect.width))/2; // even, adjust back
|
|
|
|
// draw in the left and right
|
2001-10-03 04:08:25 +04:00
|
|
|
FillOrInvertRect(aContext, borderOutside.x,dashRect.y,dashRect.width-adjust,dashRect.height,isInvert);
|
|
|
|
FillOrInvertRect(aContext, (borderOutside.XMost()-(dashRect.width-adjust)),dashRect.y,dashRect.width-adjust,dashRect.height,isInvert);
|
1999-11-03 08:46:01 +03:00
|
|
|
currRect.x += (dashRect.width-adjust);
|
2006-01-26 05:29:17 +03:00
|
|
|
temp-= (dashRect.width-adjust);
|
1999-11-03 08:46:01 +03:00
|
|
|
} else {
|
|
|
|
adjust = (temp%dashRect.width)/2;
|
|
|
|
// draw in the left and right
|
2001-10-03 04:08:25 +04:00
|
|
|
FillOrInvertRect(aContext, borderOutside.x,dashRect.y,dashRect.width+adjust,dashRect.height,isInvert);
|
|
|
|
FillOrInvertRect(aContext, (borderOutside.XMost()-(dashRect.width+adjust)),dashRect.y,dashRect.width+adjust,dashRect.height,isInvert);
|
1999-11-03 08:46:01 +03:00
|
|
|
currRect.x += (dashRect.width+adjust);
|
2006-01-26 05:29:17 +03:00
|
|
|
temp-= (dashRect.width+adjust);
|
1999-11-03 08:46:01 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
temp += borderOutside.x;
|
1999-11-03 08:46:01 +03:00
|
|
|
if( temp > xwidth)
|
|
|
|
temp = xwidth;
|
|
|
|
|
|
|
|
// get the currRect's x into the view before we start
|
|
|
|
if( currRect.x < aDirtyRect.x){
|
|
|
|
temp1 = NSToCoordFloor((float)((aDirtyRect.x-currRect.x)/dashRect.width));
|
|
|
|
currRect.x += temp1*dashRect.width;
|
|
|
|
if((temp1%2)==1){
|
|
|
|
bSolid = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
while(currRect.x<temp) {
|
|
|
|
//draw if necessary
|
|
|
|
if (bSolid) {
|
2001-10-03 04:08:25 +04:00
|
|
|
FillOrInvertRect(aContext, currRect,isInvert);
|
1999-11-03 08:46:01 +03:00
|
|
|
}
|
1998-12-07 22:02:13 +03:00
|
|
|
|
1999-11-03 08:46:01 +03:00
|
|
|
bSolid = PRBool(!bSolid);
|
|
|
|
currRect.x += dashRect.width;
|
1998-12-07 22:02:13 +03:00
|
|
|
}
|
|
|
|
}
|
1999-11-03 08:46:01 +03:00
|
|
|
break;
|
1998-12-07 22:02:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
skippedSide = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
1998-12-18 01:58:51 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
nscolor
|
|
|
|
nsCSSRendering::TransformColor(nscolor aMapColor,PRBool aNoBackGround)
|
|
|
|
{
|
|
|
|
PRUint16 hue,sat,value;
|
|
|
|
nscolor newcolor;
|
|
|
|
|
|
|
|
newcolor = aMapColor;
|
|
|
|
if (PR_TRUE == aNoBackGround){
|
|
|
|
// convert the RBG to HSV so we can get the lightness (which is the v)
|
|
|
|
NS_RGB2HSV(newcolor,hue,sat,value);
|
|
|
|
// The goal here is to send white to black while letting colored
|
|
|
|
// stuff stay colored... So we adopt the following approach.
|
|
|
|
// Something with sat = 0 should end up with value = 0. Something
|
|
|
|
// with a high sat can end up with a high value and it's ok.... At
|
|
|
|
// the same time, we don't want to make things lighter. Do
|
|
|
|
// something simple, since it seems to work.
|
|
|
|
if (value > sat) {
|
|
|
|
value = sat;
|
|
|
|
// convert this color back into the RGB color space.
|
|
|
|
NS_HSV2RGB(newcolor,hue,sat,value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newcolor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
PRBool GetBorderColor(const nsStyleColor* aColor, const nsStyleBorder& aBorder, PRUint8 aSide, nscolor& aColorVal,
|
|
|
|
nsBorderColors** aCompositeColors = nsnull)
|
|
|
|
{
|
|
|
|
PRBool transparent;
|
|
|
|
PRBool foreground;
|
|
|
|
|
|
|
|
if (aCompositeColors) {
|
|
|
|
aBorder.GetCompositeColors(aSide, aCompositeColors);
|
|
|
|
if (*aCompositeColors)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aBorder.GetBorderColor(aSide, aColorVal, transparent, foreground);
|
|
|
|
if (foreground)
|
|
|
|
aColorVal = aColor->mColor;
|
|
|
|
|
|
|
|
return !transparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Thebes Border Rendering Code Start
|
|
|
|
|
|
|
|
#undef DEBUG_NEW_BORDERS
|
|
|
|
|
|
|
|
#ifdef DEBUG_NEW_BORDERS
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
static inline void S(const gfxPoint& p) {
|
|
|
|
fprintf (stderr, "[%f,%f]", p.x, p.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void S(const gfxSize& s) {
|
|
|
|
fprintf (stderr, "[%f %f]", s.width, s.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void S(const gfxRect& r) {
|
|
|
|
fprintf (stderr, "[%f %f %f %f]", r.pos.x, r.pos.y, r.size.width, r.size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void S(const gfxFloat f) {
|
|
|
|
fprintf (stderr, "%f", f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void S(const char *s) {
|
|
|
|
fprintf (stderr, "%s", s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void SN(const char *s = nsnull) {
|
|
|
|
if (s)
|
|
|
|
fprintf (stderr, "%s", s);
|
|
|
|
fprintf (stderr, "\n");
|
|
|
|
fflush (stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void SF(const char *fmt, ...) {
|
|
|
|
va_list vl;
|
|
|
|
va_start(vl, fmt);
|
|
|
|
vfprintf (stderr, fmt, vl);
|
|
|
|
va_end(vl);
|
|
|
|
}
|
2007-05-08 21:40:08 +04:00
|
|
|
|
|
|
|
static inline void SX(gfxContext *ctx) {
|
|
|
|
gfxPoint p = ctx->CurrentPoint();
|
|
|
|
fprintf (stderr, "p: %f %f\n", p.x, p.y);
|
|
|
|
return;
|
|
|
|
ctx->MoveTo(p + gfxPoint(-2, -2)); ctx->LineTo(p + gfxPoint(2, 2));
|
|
|
|
ctx->MoveTo(p + gfxPoint(-2, 2)); ctx->LineTo(p + gfxPoint(2, -2));
|
|
|
|
ctx->MoveTo(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
#else
|
|
|
|
static inline void S(const gfxPoint& p) {}
|
|
|
|
static inline void S(const gfxSize& s) {}
|
|
|
|
static inline void S(const gfxRect& r) {}
|
|
|
|
static inline void S(const gfxFloat f) {}
|
|
|
|
static inline void S(const char *s) {}
|
|
|
|
static inline void SN(const char *s = nsnull) {}
|
|
|
|
static inline void SF(const char *fmt, ...) {}
|
2007-05-08 21:40:08 +04:00
|
|
|
static inline void SX(gfxContext *ctx) {}
|
2007-05-01 07:31:25 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out whether we need to draw using separate side rendering or
|
|
|
|
* not.
|
|
|
|
*
|
|
|
|
* The only case where we can draw the border in one shot is:
|
|
|
|
* - the style is SOLID or DOUBLE
|
|
|
|
* - the same color is used on all sides
|
|
|
|
* - composite colors are not involved
|
|
|
|
*
|
|
|
|
*
|
1999-01-03 22:23:21 +03:00
|
|
|
*/
|
2007-05-01 07:31:25 +04:00
|
|
|
static PRBool
|
|
|
|
ShouldDoSeparateSides (const nsStyleBorder& aBorderStyle,
|
|
|
|
const nsStyleColor *aOurColor)
|
1998-12-30 09:47:26 +03:00
|
|
|
{
|
2007-05-01 07:31:25 +04:00
|
|
|
PRUint8 firstSideStyle;
|
|
|
|
nscolor firstSideColor;
|
|
|
|
nscolor sideColor;
|
|
|
|
nsBorderColors* compositeColors = nsnull;
|
1999-10-26 18:34:17 +04:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
static PRUint8 sideOrder[] = { NS_SIDE_BOTTOM, NS_SIDE_LEFT, NS_SIDE_TOP, NS_SIDE_RIGHT };
|
1999-10-26 18:34:17 +04:00
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2007-05-01 07:31:25 +04:00
|
|
|
PRUint8 side = sideOrder[i];
|
|
|
|
PRUint8 borderRenderStyle = aBorderStyle.GetBorderStyle(side);
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// always do separate sides for borders where all 4 sides wouldn't
|
|
|
|
// be rendered in an identical way
|
|
|
|
if (borderRenderStyle != NS_STYLE_BORDER_STYLE_SOLID &&
|
|
|
|
borderRenderStyle != NS_STYLE_BORDER_STYLE_DOUBLE)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
firstSideStyle = borderRenderStyle;
|
|
|
|
else if (borderRenderStyle != firstSideStyle)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
if (GetBorderColor(aOurColor, aBorderStyle, side, sideColor, &compositeColors)) {
|
|
|
|
// always do separate sides with compositeColors
|
|
|
|
if (compositeColors)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
// do separate sides if we have different colors on different sides
|
|
|
|
if (i == 0)
|
|
|
|
firstSideColor = sideColor;
|
|
|
|
else if (sideColor != firstSideColor)
|
|
|
|
return PR_TRUE;
|
1998-12-30 09:47:26 +03:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
}
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
#define C_TL 0
|
|
|
|
#define C_TR 1
|
|
|
|
#define C_BR 2
|
|
|
|
#define C_BL 3
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
#ifndef NS_PI
|
|
|
|
#define NS_PI 3.14159265358979323846
|
|
|
|
#endif
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// return the length of the given side of lRect, taking into
|
|
|
|
// acount corner radii.
|
|
|
|
static gfxFloat
|
|
|
|
SideLength(gfxRect& oRect,
|
|
|
|
gfxRect& lRect,
|
|
|
|
PRUint8 side,
|
|
|
|
gfxFloat *radii)
|
|
|
|
{
|
|
|
|
if (radii == nsnull) {
|
|
|
|
if (side == NS_SIDE_TOP || side == NS_SIDE_BOTTOM)
|
|
|
|
return oRect.size.width;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
return oRect.size.height;
|
|
|
|
} else {
|
|
|
|
// XXX radii, don't fix this until DoSingleSideBorderPath
|
|
|
|
// does per-side borders with radius
|
|
|
|
if (side == NS_SIDE_TOP || side == NS_SIDE_BOTTOM)
|
|
|
|
return oRect.size.width;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
return oRect.size.height;
|
|
|
|
}
|
|
|
|
}
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
//
|
|
|
|
// draw the entire border path, as a single rectangle/etc.
|
|
|
|
//
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
static void
|
|
|
|
DoAllSidesBorderPath(gfxContext *ctx,
|
|
|
|
gfxRect& lRect,
|
2007-05-08 21:40:08 +04:00
|
|
|
gfxFloat *radii,
|
|
|
|
PRIntn skipSides = 0)
|
2007-05-01 07:31:25 +04:00
|
|
|
{
|
|
|
|
ctx->NewPath();
|
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
SF("DoAllSidesBorderPath: [%f %f %f %f] radii: %p skipSides: %d\n", lRect.pos.x, lRect.pos.y, lRect.size.width, lRect.size.height, radii, skipSides);
|
|
|
|
if (radii) {
|
|
|
|
SF(" %f %f %f %f\n", radii[0], radii[1], radii[2], radii[3]);
|
|
|
|
}
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// if we don't have border radius, then this is easy
|
|
|
|
if (radii == nsnull) {
|
|
|
|
ctx->Rectangle(lRect);
|
|
|
|
} else {
|
|
|
|
// ok, we have at least one border radius. The fun starts here!
|
|
|
|
// We have a potential radius at each corner, so draw lines in between
|
|
|
|
// corners, and arcs where there need to be arcs at the corners.
|
|
|
|
// The lines are offset by the radius in both directions.
|
|
|
|
//
|
|
|
|
// When we support CSS3 two-radius specification, this will have
|
|
|
|
// to change, as we'll need to do scaling tricks to get that to work.
|
|
|
|
// specifically, we need to pick one radius, and scale the other axis
|
|
|
|
// so that r1 * scale = r2, because we can't draw ellipses directly
|
|
|
|
// with cairo.
|
|
|
|
//
|
|
|
|
// The path that's created looks like this, with *'s indicating
|
|
|
|
// points along the path, and > the path direction:
|
|
|
|
//
|
|
|
|
// v- start point
|
|
|
|
// *--->----*
|
|
|
|
// / \
|
|
|
|
// * *
|
|
|
|
// | |
|
|
|
|
// * *
|
|
|
|
// \ /
|
|
|
|
// *--------*
|
2007-05-08 21:40:08 +04:00
|
|
|
//
|
|
|
|
// However, if any sides are to be skipped, the start point is
|
|
|
|
// adjusted so that the segment that's rendered has all the joins
|
|
|
|
// correct -- we can't use ClosePath to get a correct join if we
|
|
|
|
// ever do a MoveTo (to skip a segment), because it closes to the
|
|
|
|
// position of the last MoveTo.
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
gfxMatrix mat = ctx->CurrentMatrix();
|
|
|
|
ctx->Translate(lRect.pos);
|
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
// Decide which side to start drawing the path on, taking into
|
|
|
|
// account the skipped sides. We always draw the path
|
|
|
|
// in the usual order: top -> left -> right -> bottom. But if
|
|
|
|
// one or more of these sides is skipped, we start in a different
|
|
|
|
// spot to make sure that we get the joins right.
|
|
|
|
//
|
|
|
|
// For example, if the right and bottom sides are to be skipped,
|
|
|
|
// without this we would draw a line from the TL to the TR corner,
|
|
|
|
// and then the BL to the TL corner. But we can't use ClosePath()
|
|
|
|
// to get a join at the TL corner, because it closes the subpath
|
|
|
|
// started with the last MoveTo(); so, we'll end up not having a
|
|
|
|
// join in the TL corner, which will look bad.
|
|
|
|
//
|
|
|
|
// Instead, this code will decide to start drawing the path from
|
|
|
|
// the BL corner, and will draw a single path from BL -> TL -> TR.
|
|
|
|
PRIntn currentSide = NS_SIDE_TOP;
|
|
|
|
switch (skipSides) {
|
|
|
|
case SIDE_BIT_TOP:
|
|
|
|
case SIDE_BIT_TOP | SIDE_BIT_LEFT:
|
|
|
|
case SIDE_BIT_TOP | SIDE_BIT_LEFT | SIDE_BIT_BOTTOM:
|
|
|
|
currentSide = NS_SIDE_RIGHT;
|
|
|
|
break;
|
|
|
|
case SIDE_BIT_RIGHT:
|
|
|
|
case SIDE_BIT_RIGHT | SIDE_BIT_TOP:
|
|
|
|
case SIDE_BIT_RIGHT | SIDE_BIT_TOP | SIDE_BIT_LEFT:
|
|
|
|
currentSide = NS_SIDE_BOTTOM;
|
|
|
|
break;
|
|
|
|
case SIDE_BIT_BOTTOM:
|
|
|
|
case SIDE_BIT_BOTTOM | SIDE_BIT_RIGHT:
|
|
|
|
case SIDE_BIT_BOTTOM | SIDE_BIT_RIGHT | SIDE_BIT_TOP:
|
|
|
|
currentSide = NS_SIDE_LEFT;
|
|
|
|
break;
|
|
|
|
case SIDE_BIT_LEFT:
|
|
|
|
case SIDE_BIT_LEFT | SIDE_BIT_BOTTOM:
|
|
|
|
case SIDE_BIT_LEFT | SIDE_BIT_BOTTOM | SIDE_BIT_RIGHT:
|
|
|
|
currentSide = NS_SIDE_TOP;
|
|
|
|
break;
|
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
switch (currentSide) {
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
ctx->MoveTo(gfxPoint(radii[C_TL] / 2.0, 0.0));
|
|
|
|
break;
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
ctx->MoveTo(gfxPoint(lRect.size.width, radii[C_TR] / 2.0));
|
|
|
|
break;
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
ctx->MoveTo(gfxPoint(lRect.size.width - radii[C_BR] / 2.0, lRect.size.height));
|
|
|
|
break;
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
ctx->MoveTo(gfxPoint(0.0, lRect.size.height - radii[C_BL] / 2.0));
|
|
|
|
break;
|
2007-05-01 07:31:25 +04:00
|
|
|
}
|
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
SX(ctx);
|
|
|
|
|
|
|
|
int sidesToDraw = 4;
|
|
|
|
while (sidesToDraw-- > 0) {
|
|
|
|
switch (currentSide) {
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
if (skipSides & SIDE_BIT_TOP) {
|
|
|
|
ctx->MoveTo(gfxPoint(lRect.size.width, 0.0));
|
|
|
|
} else if (radii[C_TR]) {
|
|
|
|
ctx->LineTo(gfxPoint(lRect.size.width - radii[C_TR] / 2.0, 0.0));
|
|
|
|
SX(ctx);
|
|
|
|
|
|
|
|
ctx->Arc(gfxPoint(lRect.size.width - radii[C_TR] / 2.0, radii[C_TR] / 2.0),
|
|
|
|
radii[C_TR] / 2.0,
|
|
|
|
3.0 * NS_PI / 2.0, 0.0);
|
|
|
|
SX(ctx);
|
|
|
|
} else {
|
|
|
|
ctx->LineTo(gfxPoint(lRect.size.width, 0.0));
|
|
|
|
SX(ctx);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
if (skipSides & SIDE_BIT_RIGHT) {
|
|
|
|
ctx->MoveTo(gfxPoint(lRect.size.width, lRect.size.height));
|
|
|
|
} else if (radii[C_BR]) {
|
|
|
|
ctx->LineTo(gfxPoint(lRect.size.width, lRect.size.height - radii[C_BR] / 2.0));
|
|
|
|
SX(ctx);
|
|
|
|
|
|
|
|
ctx->Arc(gfxPoint(lRect.size.width - radii[C_BR] / 2.0, lRect.size.height - radii[C_BR] / 2.0),
|
|
|
|
radii[C_BR] / 2.0,
|
|
|
|
0.0, NS_PI / 2.0);
|
|
|
|
SX(ctx);
|
|
|
|
} else {
|
|
|
|
ctx->LineTo(gfxPoint(lRect.size.width, lRect.size.height));
|
|
|
|
SX(ctx);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
if (skipSides & SIDE_BIT_BOTTOM) {
|
|
|
|
ctx->MoveTo(gfxPoint(0.0, lRect.size.height));
|
|
|
|
} else if (radii[C_BL]) {
|
|
|
|
ctx->LineTo(gfxPoint(radii[C_BL] / 2.0, lRect.size.height));
|
|
|
|
SX(ctx);
|
|
|
|
|
|
|
|
ctx->Arc(gfxPoint(radii[C_BL] / 2.0, lRect.size.height - radii[C_BL] / 2.0),
|
|
|
|
radii[C_BL] / 2.0,
|
|
|
|
NS_PI / 2.0,
|
|
|
|
NS_PI);
|
|
|
|
SX(ctx);
|
|
|
|
} else {
|
|
|
|
ctx->LineTo(gfxPoint(0.0, lRect.size.height));
|
|
|
|
SX(ctx);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
if (skipSides & SIDE_BIT_LEFT) {
|
|
|
|
ctx->MoveTo(gfxPoint(0.0, lRect.size.height));
|
|
|
|
} else if (radii[C_TL]) {
|
|
|
|
ctx->LineTo(gfxPoint(0.0, radii[C_TL] / 2.0));
|
|
|
|
SX(ctx);
|
|
|
|
|
|
|
|
ctx->Arc(gfxPoint(radii[C_TL] / 2.0, radii[C_TL] / 2.0),
|
|
|
|
radii[C_TL] / 2.0,
|
|
|
|
NS_PI,
|
|
|
|
3.0 * NS_PI / 2.0);
|
|
|
|
SX(ctx);
|
|
|
|
} else {
|
|
|
|
ctx->LineTo(gfxPoint(0.0, 0.0));
|
|
|
|
SX(ctx);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
currentSide = (currentSide + 1) % 4;
|
2007-05-01 07:31:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx->SetMatrix(mat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
DoSingleSideBorderPath(gfxContext *ctx,
|
|
|
|
gfxRect& oRect,
|
|
|
|
gfxRect& lRect,
|
|
|
|
gfxFloat *radii,
|
|
|
|
PRInt8 whichSide)
|
|
|
|
{
|
|
|
|
// we are drawing one specific side. We need to be very accurate here,
|
|
|
|
// because we can't just draw the rectangle and hope that clipping wins.
|
|
|
|
// If we do that, we'll have problems at the corners, especially if there
|
|
|
|
// are dashes involved.
|
|
|
|
|
|
|
|
// XXX this code doesn't handle radii yet, so when there is a border radius
|
|
|
|
// we just use the code above
|
|
|
|
|
|
|
|
// Make sure to draw these lines in the same order as the rectangle lines
|
|
|
|
// are drawn to avoid confusion.
|
|
|
|
|
|
|
|
ctx->NewPath();
|
|
|
|
|
|
|
|
if (whichSide == NS_SIDE_TOP) {
|
|
|
|
ctx->MoveTo(gfxPoint(oRect.pos.x, lRect.pos.y));
|
|
|
|
ctx->LineTo(gfxPoint(oRect.pos.x + oRect.size.width, lRect.pos.y));
|
|
|
|
} else if (whichSide == NS_SIDE_RIGHT) {
|
|
|
|
ctx->MoveTo(gfxPoint(lRect.pos.x + lRect.size.width, oRect.pos.y));
|
|
|
|
ctx->LineTo(gfxPoint(lRect.pos.x + lRect.size.width, oRect.pos.y + oRect.size.height));
|
|
|
|
} else if (whichSide == NS_SIDE_BOTTOM) {
|
|
|
|
ctx->MoveTo(gfxPoint(oRect.pos.x + oRect.size.width, lRect.pos.y + lRect.size.height));
|
|
|
|
ctx->LineTo(gfxPoint(oRect.pos.x, lRect.pos.y + lRect.size.height));
|
|
|
|
} else if (whichSide == NS_SIDE_LEFT) {
|
|
|
|
ctx->MoveTo(gfxPoint(lRect.pos.x, oRect.pos.y + oRect.size.height));
|
|
|
|
ctx->LineTo(gfxPoint(lRect.pos.x, oRect.pos.y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create a clip path for the wedge that this side of
|
|
|
|
// the border should take up. This is only called
|
|
|
|
// when we're drawing separate border sides, so we know
|
|
|
|
// that ADD compositing is taking place.
|
|
|
|
//
|
|
|
|
// This code needs to make sure that the individual pieces
|
|
|
|
// don't ever (mathematically) overlap; the pixel overlap
|
|
|
|
// is taken care of by the ADD compositing.
|
|
|
|
//
|
|
|
|
// The side border type and the adjacent border types are
|
|
|
|
// examined and one of the different types of clipping (listed
|
|
|
|
// below) is selected.
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
// clip to the trapezoid formed by the corners of the
|
|
|
|
// inner and outer rectangles for the given side
|
|
|
|
SIDE_CLIP_TRAPEZOID,
|
|
|
|
|
|
|
|
// clip to the trapezoid formed by the outer rectangle
|
|
|
|
// corners and the center of the region, making sure
|
|
|
|
// that diagonal lines all go directly from the outside
|
|
|
|
// corner to the inside corner, but that they then continue on
|
|
|
|
// to the middle.
|
|
|
|
//
|
|
|
|
// This is needed for correctly clipping rounded borders,
|
|
|
|
// which might extend past the SIDE_CLIP_TRAPEZOID trap.
|
|
|
|
SIDE_CLIP_TRAPEZOID_FULL,
|
|
|
|
|
|
|
|
// clip to the rectangle formed by the given side; a specific
|
|
|
|
// overlap algorithm is used; see the function for details.
|
|
|
|
// this is currently used for dashing.
|
|
|
|
SIDE_CLIP_RECTANGLE
|
|
|
|
} SideClipType;
|
|
|
|
|
|
|
|
static void
|
|
|
|
DoSideClipPath(gfxContext *ctx,
|
|
|
|
gfxRect& iRect,
|
|
|
|
gfxRect& oRect,
|
|
|
|
gfxRect& lRect,
|
|
|
|
PRUint8 whichSide,
|
|
|
|
const nsStyleBorder& borderStyle,
|
2007-05-08 21:40:08 +04:00
|
|
|
const PRInt32 *borderRadii)
|
2007-05-01 07:31:25 +04:00
|
|
|
{
|
|
|
|
// the clip proceeds clockwise from the top left corner;
|
|
|
|
// so "start" in each case is the start of the region from that side.
|
|
|
|
//
|
|
|
|
// the final path will be formed like:
|
|
|
|
// s0 ------- e0
|
|
|
|
// | /
|
|
|
|
// s1 ----- e1
|
|
|
|
//
|
|
|
|
// that is, the second point will always be on the inside
|
|
|
|
|
|
|
|
gfxPoint start[2];
|
|
|
|
gfxPoint end[2];
|
|
|
|
|
|
|
|
PRUint8 style = borderStyle.GetBorderStyle(whichSide);
|
|
|
|
PRUint8 startAdjacentStyle = borderStyle.GetBorderStyle(((whichSide - 1) + 4) % 4);
|
|
|
|
PRUint8 endAdjacentStyle = borderStyle.GetBorderStyle((whichSide + 1) % 4);
|
|
|
|
|
|
|
|
PRBool isDashed =
|
|
|
|
(style == NS_STYLE_BORDER_STYLE_DASHED || style == NS_STYLE_BORDER_STYLE_DOTTED);
|
|
|
|
PRBool startIsDashed =
|
|
|
|
(startAdjacentStyle == NS_STYLE_BORDER_STYLE_DASHED || startAdjacentStyle == NS_STYLE_BORDER_STYLE_DOTTED);
|
|
|
|
PRBool endIsDashed =
|
|
|
|
(endAdjacentStyle == NS_STYLE_BORDER_STYLE_DASHED || endAdjacentStyle == NS_STYLE_BORDER_STYLE_DOTTED);
|
|
|
|
|
|
|
|
PRBool startHasRadius = PR_FALSE;
|
|
|
|
PRBool endHasRadius = PR_FALSE;
|
|
|
|
|
|
|
|
SideClipType startType = SIDE_CLIP_TRAPEZOID;
|
|
|
|
SideClipType endType = SIDE_CLIP_TRAPEZOID;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
if (borderRadii) {
|
|
|
|
startHasRadius = borderRadii[whichSide] != 0;
|
|
|
|
endHasRadius = borderRadii[(whichSide+1) % 4] != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startHasRadius) {
|
|
|
|
startType = SIDE_CLIP_TRAPEZOID_FULL;
|
|
|
|
} else if (startIsDashed && isDashed) {
|
|
|
|
startType = SIDE_CLIP_RECTANGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endHasRadius) {
|
|
|
|
endType = SIDE_CLIP_TRAPEZOID_FULL;
|
|
|
|
} else if (endIsDashed && isDashed) {
|
|
|
|
endType = SIDE_CLIP_RECTANGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startType == SIDE_CLIP_TRAPEZOID ||
|
|
|
|
startType == SIDE_CLIP_TRAPEZOID_FULL)
|
|
|
|
{
|
|
|
|
switch (whichSide) {
|
1998-12-30 09:47:26 +03:00
|
|
|
case NS_SIDE_TOP:
|
2007-05-01 07:31:25 +04:00
|
|
|
start[0] = oRect.TopLeft();
|
|
|
|
start[1] = iRect.TopLeft();
|
|
|
|
break;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
start[0] = oRect.TopRight();
|
|
|
|
start[1] = iRect.TopRight();
|
|
|
|
break;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
start[0] = oRect.BottomRight();
|
|
|
|
start[1] = iRect.BottomRight();
|
|
|
|
break;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
start[0] = oRect.BottomLeft();
|
|
|
|
start[1] = iRect.BottomLeft();
|
|
|
|
break;
|
|
|
|
}
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
if (startType == SIDE_CLIP_TRAPEZOID_FULL) {
|
|
|
|
gfxFloat mx = iRect.pos.x + iRect.size.width / 2.0;
|
|
|
|
gfxFloat my = iRect.pos.y + iRect.size.height / 2.0;
|
|
|
|
|
|
|
|
gfxPoint ps, pc;
|
|
|
|
|
|
|
|
ps = start[1] - start[0];
|
|
|
|
if (ps.x == 0.0 && ps.y == 0.0) {
|
|
|
|
// do nothing; pc == start[1]
|
|
|
|
} else if (ps.x == 0.0) {
|
|
|
|
start[1] = start[0] + gfxSize(ps.y, ps.y);
|
|
|
|
} else if (ps.y == 0.0) {
|
|
|
|
start[1] = start[0] + gfxSize(ps.x, ps.x);
|
|
|
|
} else {
|
|
|
|
gfxFloat k = PR_MIN((mx - start[0].x) / ps.x,
|
|
|
|
(my - start[0].y) / ps.y);
|
|
|
|
start[1] = start[0] + ps * k;
|
1998-12-30 09:47:26 +03:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
}
|
|
|
|
} else if (startType == SIDE_CLIP_RECTANGLE) {
|
|
|
|
switch (whichSide) {
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
start[0] = oRect.TopLeft();
|
|
|
|
start[1] = gfxPoint(start[0].x, iRect.TopLeft().y);
|
|
|
|
break;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
|
|
|
case NS_SIDE_RIGHT:
|
2007-05-01 07:31:25 +04:00
|
|
|
start[0] = oRect.TopRight();
|
|
|
|
start[1] = gfxPoint(iRect.TopRight().x, start[0].y);
|
|
|
|
break;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
start[0] = oRect.BottomRight();
|
|
|
|
start[1] = gfxPoint(start[0].x, iRect.BottomRight().y);
|
|
|
|
break;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
start[0] = oRect.BottomLeft();
|
|
|
|
start[1] = gfxPoint(iRect.BottomLeft().x, start[0].y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
if (endType == SIDE_CLIP_TRAPEZOID ||
|
|
|
|
endType == SIDE_CLIP_TRAPEZOID_FULL)
|
|
|
|
{
|
|
|
|
switch (whichSide) {
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
end[0] = oRect.TopRight();
|
|
|
|
end[1] = iRect.TopRight();
|
|
|
|
break;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
end[0] = oRect.BottomRight();
|
|
|
|
end[1] = iRect.BottomRight();
|
|
|
|
break;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
end[0] = oRect.BottomLeft();
|
|
|
|
end[1] = iRect.BottomLeft();
|
|
|
|
break;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
end[0] = oRect.TopLeft();
|
|
|
|
end[1] = iRect.TopLeft();
|
|
|
|
break;
|
|
|
|
}
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
if (endType == SIDE_CLIP_TRAPEZOID_FULL) {
|
|
|
|
gfxFloat mx = iRect.pos.x + iRect.size.width / 2.0;
|
|
|
|
gfxFloat my = iRect.pos.y + iRect.size.height / 2.0;
|
|
|
|
|
|
|
|
gfxPoint ps, pc;
|
|
|
|
|
|
|
|
ps = end[1] - end[0];
|
|
|
|
if (ps.x == 0.0 && ps.y == 0.0) {
|
|
|
|
// do nothing; pc == end[1]
|
|
|
|
} else if (ps.x == 0.0) {
|
|
|
|
end[1] = end[0] + gfxSize(ps.y, ps.y);
|
|
|
|
} else if (ps.y == 0.0) {
|
|
|
|
end[1] = end[0] + gfxSize(ps.x, ps.x);
|
|
|
|
} else {
|
|
|
|
gfxFloat k = PR_MIN((mx - end[0].x) / ps.x,
|
|
|
|
(my - end[0].y) / ps.y);
|
|
|
|
end[1] = end[0] + ps * k;
|
1998-12-30 09:47:26 +03:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
}
|
|
|
|
} else if (startType == SIDE_CLIP_RECTANGLE) {
|
|
|
|
switch (whichSide) {
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
end[0] = gfxPoint(iRect.TopRight().x, oRect.TopRight().y);
|
|
|
|
end[1] = iRect.TopRight();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
end[0] = gfxPoint(oRect.BottomRight().x, iRect.BottomRight().y);
|
|
|
|
end[1] = iRect.BottomRight();
|
|
|
|
break;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
|
|
|
case NS_SIDE_BOTTOM:
|
2007-05-01 07:31:25 +04:00
|
|
|
end[0] = gfxPoint(iRect.BottomLeft().x, oRect.BottomLeft().y);
|
|
|
|
end[1] = iRect.BottomLeft();
|
|
|
|
break;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
end[0] = gfxPoint(oRect.TopLeft().x, iRect.TopLeft().y);
|
|
|
|
end[1] = iRect.TopLeft();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
ctx->NewPath();
|
|
|
|
ctx->MoveTo(start[0]);
|
|
|
|
ctx->LineTo(end[0]);
|
|
|
|
ctx->LineTo(end[1]);
|
|
|
|
ctx->LineTo(start[1]);
|
|
|
|
ctx->ClosePath();
|
|
|
|
}
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
typedef enum {
|
|
|
|
BorderColorStyleNone,
|
|
|
|
BorderColorStyleSolid,
|
|
|
|
BorderColorStyleLight,
|
|
|
|
BorderColorStyleDark
|
|
|
|
} BorderColorStyle;
|
1998-12-30 09:47:26 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
static void
|
|
|
|
MakeBorderColor(gfxRGBA& color, const gfxRGBA& backgroundColor, BorderColorStyle bpat)
|
|
|
|
{
|
|
|
|
nscolor colors[2];
|
|
|
|
|
|
|
|
switch (bpat) {
|
|
|
|
case BorderColorStyleNone:
|
|
|
|
color.r = 0.0;
|
|
|
|
color.g = 0.0;
|
|
|
|
color.b = 0.0;
|
|
|
|
color.a = 0.0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BorderColorStyleSolid:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BorderColorStyleLight:
|
|
|
|
NS_GetSpecial3DColors(colors, backgroundColor.Packed(), color.Packed());
|
|
|
|
color.r = NS_GET_R(colors[1]) / 255.0;
|
|
|
|
color.g = NS_GET_G(colors[1]) / 255.0;
|
|
|
|
color.b = NS_GET_B(colors[1]) / 255.0;
|
|
|
|
color.a = 1.0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BorderColorStyleDark:
|
|
|
|
NS_GetSpecial3DColors(colors, backgroundColor.Packed(), color.Packed());
|
|
|
|
color.r = NS_GET_R(colors[0]) / 255.0;
|
|
|
|
color.g = NS_GET_G(colors[0]) / 255.0;
|
|
|
|
color.b = NS_GET_B(colors[0]) / 255.0;
|
|
|
|
color.a = 1.0;
|
1998-12-30 09:47:26 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
static void
|
|
|
|
ComputeColorForLine(PRUint32 lineIndex,
|
|
|
|
PRUint32 borderWidth,
|
|
|
|
BorderColorStyle* borderColorStyle,
|
|
|
|
PRUint32 borderColorStyleCount,
|
|
|
|
nsBorderColors* borderColors,
|
|
|
|
PRUint32 borderColorCount,
|
|
|
|
nscolor borderColor,
|
|
|
|
nscolor backgroundColor,
|
|
|
|
gfxRGBA& outColor)
|
2001-05-10 18:19:58 +04:00
|
|
|
{
|
2007-05-01 07:31:25 +04:00
|
|
|
NS_ASSERTION(lineIndex < borderColorStyleCount, "Invalid lineIndex given");
|
2001-05-10 18:19:58 +04:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
if (borderColors) {
|
|
|
|
if (lineIndex >= borderColorCount) {
|
|
|
|
//outColor = gfxRGBA(borderColor);
|
|
|
|
//return;
|
|
|
|
|
|
|
|
// use the last color
|
|
|
|
lineIndex = borderColorCount - 1;
|
2001-05-10 18:19:58 +04:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
while (lineIndex--)
|
|
|
|
borderColors = borderColors->mNext;
|
|
|
|
|
|
|
|
if (borderColors->mTransparent)
|
|
|
|
outColor.r = outColor.g = outColor.b = outColor.a = 0.0;
|
|
|
|
else
|
|
|
|
outColor = gfxRGBA(borderColors->mColor);
|
|
|
|
|
|
|
|
return;
|
2001-05-10 18:19:58 +04:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
outColor = gfxRGBA(borderColor);
|
|
|
|
|
|
|
|
MakeBorderColor(outColor, gfxRGBA(backgroundColor), borderColorStyle[lineIndex]);
|
2001-05-10 18:19:58 +04:00
|
|
|
}
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
/**
|
|
|
|
** This function ASSUMES that it can twiddle with the gfx state, and
|
|
|
|
** expects to be called between a Save/Restore pair.
|
|
|
|
**/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There are three different drawing styles:
|
|
|
|
*
|
|
|
|
* 1) solid
|
|
|
|
* 2) dotted/dashed
|
|
|
|
* 3) split, where split is a diagonal [/] slice, with left and top being the same,
|
|
|
|
* and bottom and right being the same
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
DrawBorderSides(gfxContext *ctx,
|
|
|
|
PRUint32 borderWidth,
|
|
|
|
PRUint8 borderRenderStyle,
|
|
|
|
nscolor borderRenderColor,
|
|
|
|
nsBorderColors *compositeColors,
|
|
|
|
gfxRect& iRect,
|
|
|
|
gfxRect& oRect,
|
|
|
|
gfxRect& lRect,
|
|
|
|
nscolor fgColor,
|
|
|
|
nscolor bgColor,
|
|
|
|
PRBool doSeparateSides,
|
|
|
|
PRUint8 side,
|
2007-05-08 21:40:08 +04:00
|
|
|
PRIntn skipSides,
|
2007-05-01 07:31:25 +04:00
|
|
|
nscoord twipsPerPixel,
|
2007-05-08 21:40:08 +04:00
|
|
|
PRInt32 *borderRadii)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2007-05-01 07:31:25 +04:00
|
|
|
PRBool dashedRendering = PR_FALSE;
|
|
|
|
gfxFloat dash[2];
|
|
|
|
gfxFloat radii[4];
|
|
|
|
gfxFloat *radiiPtr = nsnull;
|
|
|
|
gfxFloat dashWidth;
|
2001-12-05 11:35:05 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
PRUint32 borderColorStyleCount = 0;
|
|
|
|
BorderColorStyle borderColorStyleTopLeft[3], borderColorStyleBottomRight[3];
|
|
|
|
BorderColorStyle *borderColorStyle = nsnull;
|
|
|
|
PRUint32 compositeColorCount = 0;
|
|
|
|
|
|
|
|
PRBool useSpecialDotDashSeparateSides = doSeparateSides;
|
|
|
|
|
|
|
|
if (borderRadii) {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
radii[i] = gfxFloat(borderRadii[i]) / twipsPerPixel;
|
|
|
|
}
|
|
|
|
|
|
|
|
radiiPtr = &radii[0];
|
|
|
|
}
|
|
|
|
|
2007-05-21 02:44:45 +04:00
|
|
|
// if this got through, and it shouldn't have (see bug 379419),
|
|
|
|
// just ignore this.
|
|
|
|
if (borderRenderStyle & NS_STYLE_BORDER_STYLE_RULES_MARKER)
|
|
|
|
return;
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// disable pretty drawing of dotted/dashed borders if
|
|
|
|
// we have a border radius
|
|
|
|
if (radiiPtr)
|
|
|
|
useSpecialDotDashSeparateSides = PR_FALSE;
|
|
|
|
|
|
|
|
// if we're not doing compositeColors, we can calculate the borderColorStyle based
|
|
|
|
// on the specified style. The borderColorStyle array goes from the outer to the inner
|
|
|
|
// style.
|
|
|
|
|
|
|
|
if (!compositeColors) {
|
|
|
|
// if the border width is 1, we need to change the borderRenderStyle a bit to make sure
|
|
|
|
// that we get the right colors -- e.g. 'ridge' with a 1px border needs to look like
|
|
|
|
// solid, not like 'outset'.
|
|
|
|
if (borderWidth == 1) {
|
|
|
|
if (borderRenderStyle == NS_STYLE_BORDER_STYLE_RIDGE ||
|
|
|
|
borderRenderStyle == NS_STYLE_BORDER_STYLE_GROOVE ||
|
|
|
|
borderRenderStyle == NS_STYLE_BORDER_STYLE_DOUBLE)
|
|
|
|
borderRenderStyle = NS_STYLE_BORDER_STYLE_SOLID;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (borderRenderStyle) {
|
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
|
|
|
case NS_STYLE_BORDER_STYLE_DASHED:
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOTTED:
|
|
|
|
borderColorStyleTopLeft[0] = BorderColorStyleSolid;
|
|
|
|
borderColorStyleBottomRight[0] = BorderColorStyleSolid;
|
|
|
|
borderColorStyleCount = 1;
|
|
|
|
|
|
|
|
// We always want the dash to start on an integer pixel boundary; so if
|
|
|
|
// the path will start on a boundary between pixels, we need to shift the
|
|
|
|
// dash by half a pixel backwards (into the white space) so that the
|
|
|
|
// actual dash starts in the right spot.
|
|
|
|
if (borderRenderStyle == NS_STYLE_BORDER_STYLE_DASHED) {
|
|
|
|
dashWidth = gfxFloat(borderWidth * DOT_LENGTH * DASH_LENGTH);
|
|
|
|
dashedRendering = PR_TRUE;
|
|
|
|
|
|
|
|
dash[0] = dashWidth;
|
|
|
|
dash[1] = dashWidth;
|
|
|
|
} else if (borderRenderStyle == NS_STYLE_BORDER_STYLE_DOTTED) {
|
|
|
|
dashWidth = gfxFloat(borderWidth * DOT_LENGTH);
|
|
|
|
dashedRendering = PR_TRUE;
|
|
|
|
|
|
|
|
// do circles when the border is > 2 in size
|
|
|
|
if (borderWidth > 2) {
|
|
|
|
dash[0] = 0;
|
|
|
|
dash[1] = dashWidth * 2;
|
|
|
|
|
|
|
|
ctx->SetLineCap(gfxContext::LINE_CAP_ROUND);
|
|
|
|
} else {
|
|
|
|
dash[0] = dashWidth;
|
|
|
|
dash[1] = dashWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dashedRendering) {
|
|
|
|
gfxFloat dashOffset = 0.0;
|
|
|
|
gfxFloat sideLen = SideLength(oRect, lRect, side, radiiPtr);
|
|
|
|
gfxFloat sideOffset = 0.0;
|
|
|
|
|
|
|
|
// we want to make sure that the side starts and ends on a dash. If
|
|
|
|
// the side is super short, then we can't do much.
|
|
|
|
//
|
|
|
|
// XXX the dashed/dotted rendering is still voodoo; this needs to be
|
|
|
|
// improved.
|
|
|
|
#if 0
|
|
|
|
if (sideLen > dashWidth) {
|
|
|
|
gfxFloat rep = sideLen / (dashWidth * 2.0);
|
|
|
|
gfxFloat rem = sideLen - dashWidth * 2.0 * floor(rep);
|
|
|
|
gfxFloat offsetrem = sideOffset - floor(sideOffset / (dashWidth * 2.0)) * (dashWidth * 20);
|
|
|
|
|
|
|
|
if (rem < dashWidth) {
|
|
|
|
// it will end with a dash of 'rem' width; distribute space.
|
|
|
|
dashOffset = (dashWidth - (dashWidth + rem)) / 2.0;
|
|
|
|
} else {
|
|
|
|
// it will end with empty space
|
|
|
|
dashOffset = (dashWidth + (dashWidth - rem)) / 2.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// clamp dashOffset to a multiple of the borderWidth
|
|
|
|
dashOffset = floor(dashOffset * borderWidth) / borderWidth;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (sideLen > dashWidth) {
|
|
|
|
gfxFloat rep = sideLen / (dashWidth * 2.0);
|
|
|
|
gfxFloat rem = sideLen - dashWidth * 2.0 * floor(rep);
|
|
|
|
|
|
|
|
if (rem < dashWidth) {
|
|
|
|
// it will end with a dash of 'rem' width; distribute space.
|
|
|
|
dashOffset = dashWidth - (rem / 2.0);
|
|
|
|
} else {
|
|
|
|
// it will end with empty space, push it forward
|
|
|
|
dashOffset = rem / 2.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dashOffset = floor(dashOffset);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SF("sideLen: %f dashWidth: %f dashOffset: %f final: %f\n", sideLen, dashWidth, dashOffset, (borderWidth & 1) ? dashOffset-0.5 : dashOffset);
|
|
|
|
ctx->SetDash(dash, 2, dashOffset /*(borderWidth & 1) ? dashOffset-0.5 : dashOffset*/);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_GROOVE:
|
|
|
|
borderColorStyleTopLeft[0] = BorderColorStyleDark;
|
|
|
|
borderColorStyleTopLeft[1] = BorderColorStyleLight;
|
|
|
|
|
|
|
|
borderColorStyleBottomRight[0] = BorderColorStyleLight;
|
|
|
|
borderColorStyleBottomRight[1] = BorderColorStyleDark;
|
|
|
|
|
|
|
|
borderColorStyleCount = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_RIDGE:
|
|
|
|
borderColorStyleTopLeft[0] = BorderColorStyleLight;
|
|
|
|
borderColorStyleTopLeft[1] = BorderColorStyleDark;
|
|
|
|
|
|
|
|
borderColorStyleBottomRight[0] = BorderColorStyleDark;
|
|
|
|
borderColorStyleBottomRight[1] = BorderColorStyleLight;
|
|
|
|
|
|
|
|
borderColorStyleCount = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOUBLE:
|
|
|
|
borderColorStyleTopLeft[0] = BorderColorStyleSolid;
|
|
|
|
borderColorStyleTopLeft[1] = BorderColorStyleNone;
|
|
|
|
borderColorStyleTopLeft[2] = BorderColorStyleSolid;
|
|
|
|
|
|
|
|
borderColorStyleBottomRight[0] = BorderColorStyleSolid;
|
|
|
|
borderColorStyleBottomRight[1] = BorderColorStyleNone;
|
|
|
|
borderColorStyleBottomRight[2] = BorderColorStyleSolid;
|
|
|
|
|
|
|
|
borderColorStyleCount = 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_INSET:
|
|
|
|
borderColorStyleTopLeft[0] = BorderColorStyleDark;
|
|
|
|
borderColorStyleBottomRight[0] = BorderColorStyleLight;
|
|
|
|
|
|
|
|
borderColorStyleCount = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_OUTSET:
|
|
|
|
borderColorStyleTopLeft[0] = BorderColorStyleLight;
|
|
|
|
borderColorStyleBottomRight[0] = BorderColorStyleDark;
|
|
|
|
|
|
|
|
borderColorStyleCount = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-05-08 21:40:08 +04:00
|
|
|
NS_NOTREACHED("Unhandled border style!!");
|
2007-05-01 07:31:25 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (side == NS_SIDE_BOTTOM || side == NS_SIDE_RIGHT)
|
|
|
|
borderColorStyle = borderColorStyleBottomRight;
|
|
|
|
else
|
|
|
|
borderColorStyle = borderColorStyleTopLeft;
|
|
|
|
} else {
|
|
|
|
// composite colors; we need to calculate borderColorStyle differently --
|
|
|
|
// all borders are rendered as "solid", but we might need an arbitrary number
|
|
|
|
// of them.
|
|
|
|
borderColorStyle = new BorderColorStyle[borderWidth];
|
|
|
|
borderColorStyleCount = borderWidth;
|
|
|
|
|
|
|
|
nsBorderColors *tmp = compositeColors;
|
|
|
|
do {
|
|
|
|
compositeColorCount++;
|
|
|
|
tmp = tmp->mNext;
|
|
|
|
} while (tmp);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < borderColorStyleCount; i++) {
|
|
|
|
borderColorStyle[i] = BorderColorStyleSolid;
|
|
|
|
}
|
2001-12-05 11:35:05 +03:00
|
|
|
}
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
SF("borderWidth: %d lRect: ", borderWidth), S(lRect), SN(), SF(" borderColorStyleCount: %d special: %d\n", borderColorStyleCount, useSpecialDotDashSeparateSides);
|
2007-05-08 21:40:08 +04:00
|
|
|
if (radiiPtr) {
|
|
|
|
SF(" radii: %f %f %f %f\n", radiiPtr[0], radiiPtr[1], radiiPtr[2], radiiPtr[3]);
|
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
// -moz-border-colors is a hack; if we have it for a border, then
|
|
|
|
// it's always drawn solid, and each color is given 1px. The last
|
|
|
|
// color is used for the remainder of the border's size.
|
|
|
|
//
|
|
|
|
// Otherwise, we distribute the border across the available space.
|
|
|
|
|
|
|
|
if (compositeColorCount == 0) {
|
|
|
|
if (borderColorStyleCount == 1) {
|
|
|
|
gfxRGBA color;
|
|
|
|
ComputeColorForLine(0, borderWidth,
|
|
|
|
borderColorStyle, borderColorStyleCount,
|
|
|
|
compositeColors, compositeColorCount,
|
|
|
|
borderRenderColor, bgColor, color);
|
|
|
|
|
|
|
|
ctx->SetLineWidth(borderWidth);
|
|
|
|
ctx->SetColor(color);
|
|
|
|
|
|
|
|
SF("borderColorStyle: %d color: %f %f %f %f\n", borderColorStyle[0], color.r, color.g, color.b, color.a);
|
|
|
|
|
|
|
|
// add the path to the context; if we're drawing dashed,
|
|
|
|
// we need to use the special path that will stroke the
|
|
|
|
// entire side.
|
|
|
|
if (useSpecialDotDashSeparateSides)
|
|
|
|
DoSingleSideBorderPath(ctx, oRect, lRect, radiiPtr, side);
|
|
|
|
else
|
2007-05-08 21:40:08 +04:00
|
|
|
DoAllSidesBorderPath(ctx, lRect, radiiPtr, skipSides);
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
ctx->Stroke();
|
2007-05-08 21:40:08 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
// debug; draw a line down the middle of the border
|
|
|
|
ctx->SetLineWidth(1.0);
|
|
|
|
ctx->SetDash(nsnull, 0, 0.0);
|
|
|
|
ctx->SetColor(gfxRGBA(1.0, 0.0, 0.0, 1.0));
|
|
|
|
ctx->Stroke();
|
|
|
|
#endif
|
2007-05-01 07:31:25 +04:00
|
|
|
} else if (borderColorStyleCount == 2) {
|
|
|
|
// with 2 color styles, any extra pixel goes to the outside
|
|
|
|
|
|
|
|
PRInt32 outerBorderWidth, innerBorderWidth;
|
|
|
|
outerBorderWidth = (borderWidth / 2) + (borderWidth % 2);
|
|
|
|
innerBorderWidth = (borderWidth / 2);
|
|
|
|
|
|
|
|
gfxRGBA color;
|
|
|
|
gfxRect sRect;
|
|
|
|
|
|
|
|
// draw outer rect
|
|
|
|
if (outerBorderWidth != 0 && borderColorStyle[1] != BorderColorStyleNone) {
|
|
|
|
ComputeColorForLine(0, borderWidth,
|
|
|
|
borderColorStyle, borderColorStyleCount,
|
|
|
|
compositeColors, compositeColorCount,
|
|
|
|
borderRenderColor, bgColor, color);
|
|
|
|
|
|
|
|
sRect = lRect;
|
|
|
|
sRect.pos.x -= innerBorderWidth / 2.0;
|
|
|
|
sRect.pos.y -= innerBorderWidth / 2.0;
|
|
|
|
sRect.size.width += innerBorderWidth;
|
|
|
|
sRect.size.height += innerBorderWidth;
|
|
|
|
|
|
|
|
ctx->SetLineWidth(outerBorderWidth);
|
|
|
|
ctx->SetColor(color);
|
2007-05-08 21:40:08 +04:00
|
|
|
DoAllSidesBorderPath(ctx, sRect, radiiPtr, skipSides);
|
2007-05-01 07:31:25 +04:00
|
|
|
ctx->Stroke();
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw inner rect
|
|
|
|
if (innerBorderWidth != 0 && borderColorStyle[0] != BorderColorStyleNone) {
|
|
|
|
ComputeColorForLine(1, borderWidth,
|
|
|
|
borderColorStyle, borderColorStyleCount,
|
|
|
|
compositeColors, compositeColorCount,
|
|
|
|
borderRenderColor, bgColor, color);
|
|
|
|
|
|
|
|
sRect = lRect;
|
|
|
|
sRect.pos.x += outerBorderWidth / 2.0;
|
|
|
|
sRect.pos.y += outerBorderWidth / 2.0;
|
|
|
|
sRect.size.width -= outerBorderWidth;
|
|
|
|
sRect.size.height -= outerBorderWidth;
|
|
|
|
|
|
|
|
ctx->SetLineWidth(innerBorderWidth);
|
|
|
|
ctx->SetColor(color);
|
2007-05-08 21:40:08 +04:00
|
|
|
DoAllSidesBorderPath(ctx, sRect, radiiPtr, skipSides);
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
ctx->Stroke();
|
|
|
|
}
|
|
|
|
} else if (borderColorStyleCount == 3) {
|
|
|
|
// with 3 color styles, any extra pixel (or lack of extra pixel)
|
|
|
|
// goes to the middle
|
|
|
|
|
|
|
|
PRInt32 outerBorderWidth, middleBorderWidth, innerBorderWidth;
|
|
|
|
|
|
|
|
if (borderWidth == 1) {
|
|
|
|
outerBorderWidth = 1;
|
|
|
|
middleBorderWidth = innerBorderWidth = 0;
|
|
|
|
} else {
|
|
|
|
PRInt32 rest = borderWidth % 3;
|
|
|
|
outerBorderWidth = innerBorderWidth = middleBorderWidth = (borderWidth - rest) / 3;
|
|
|
|
if (rest == 1) {
|
|
|
|
middleBorderWidth++;
|
|
|
|
} else if (rest == 2) {
|
|
|
|
outerBorderWidth++;
|
|
|
|
innerBorderWidth++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxRGBA color;
|
|
|
|
gfxRect sRect;
|
|
|
|
|
|
|
|
// draw outer rect
|
|
|
|
if (outerBorderWidth != 0 && borderColorStyle[2] != BorderColorStyleNone) {
|
|
|
|
ComputeColorForLine(0, borderWidth,
|
|
|
|
borderColorStyle, borderColorStyleCount,
|
|
|
|
compositeColors, compositeColorCount,
|
|
|
|
borderRenderColor, bgColor, color);
|
|
|
|
|
|
|
|
sRect = lRect;
|
|
|
|
sRect.pos.x -= (innerBorderWidth + middleBorderWidth) / 2.0;
|
|
|
|
sRect.pos.y -= (innerBorderWidth + middleBorderWidth) / 2.0;
|
|
|
|
sRect.size.width += (innerBorderWidth + middleBorderWidth);
|
|
|
|
sRect.size.height += (innerBorderWidth + middleBorderWidth);
|
|
|
|
|
|
|
|
ctx->SetLineWidth(outerBorderWidth);
|
|
|
|
ctx->SetColor(color);
|
2007-05-08 21:40:08 +04:00
|
|
|
DoAllSidesBorderPath(ctx, sRect, radiiPtr, skipSides);
|
2007-05-01 07:31:25 +04:00
|
|
|
ctx->Stroke();
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw middle rect
|
|
|
|
if (middleBorderWidth != 0 && borderColorStyle[1] != BorderColorStyleNone) {
|
|
|
|
ComputeColorForLine(1, borderWidth,
|
|
|
|
borderColorStyle, borderColorStyleCount,
|
|
|
|
compositeColors, compositeColorCount,
|
|
|
|
borderRenderColor, bgColor, color);
|
|
|
|
|
|
|
|
// the middle rect will always be the odd one out, so
|
|
|
|
// lRect should run straight down the middle of it
|
|
|
|
// to begin with.
|
|
|
|
sRect = lRect;
|
|
|
|
|
|
|
|
ctx->SetLineWidth(middleBorderWidth);
|
|
|
|
ctx->SetColor(color);
|
2007-05-08 21:40:08 +04:00
|
|
|
DoAllSidesBorderPath(ctx, sRect, radiiPtr, skipSides);
|
2007-05-01 07:31:25 +04:00
|
|
|
ctx->Stroke();
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// draw inner rect
|
|
|
|
if (innerBorderWidth != 0 && borderColorStyle[0] != BorderColorStyleNone) {
|
|
|
|
ComputeColorForLine(2, borderWidth,
|
|
|
|
borderColorStyle, borderColorStyleCount,
|
|
|
|
compositeColors, compositeColorCount,
|
|
|
|
borderRenderColor, bgColor, color);
|
|
|
|
|
|
|
|
sRect = lRect;
|
|
|
|
sRect.pos.x += (outerBorderWidth + middleBorderWidth) / 2.0;
|
|
|
|
sRect.pos.y += (outerBorderWidth + middleBorderWidth) / 2.0;
|
|
|
|
sRect.size.width -= (outerBorderWidth + middleBorderWidth);
|
|
|
|
sRect.size.height -= (outerBorderWidth + middleBorderWidth);
|
|
|
|
|
|
|
|
ctx->SetLineWidth(innerBorderWidth);
|
|
|
|
ctx->SetColor(color);
|
2007-05-08 21:40:08 +04:00
|
|
|
DoAllSidesBorderPath(ctx, sRect, radiiPtr, skipSides);
|
2007-05-01 07:31:25 +04:00
|
|
|
ctx->Stroke();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The only way to get to here is by having a
|
|
|
|
// borderColorStyleCount < 1 or > 3; this should never happen,
|
|
|
|
// since -moz-border-colors doesn't get handled here.
|
|
|
|
NS_ERROR("Non-border-colors case with borderColorStyleCount < 1 or > 3; what happened?");
|
|
|
|
}
|
|
|
|
} else {
|
2007-05-08 21:40:08 +04:00
|
|
|
// the generic composite colors path; each border is 1px in size
|
2007-05-01 07:31:25 +04:00
|
|
|
gfxRect sRect = oRect;
|
|
|
|
|
|
|
|
// offset the top-left so that it starts in the right place
|
|
|
|
// in the pixel
|
|
|
|
sRect.pos.x += 0.5;
|
|
|
|
sRect.pos.y += 0.5;
|
|
|
|
sRect.size.width -= 1.0;
|
|
|
|
sRect.size.height -= 1.0;
|
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
// if we have a radius, we're no longer drawing from the middle of the
|
|
|
|
// border -- so we need to tweak the radius such that the correct
|
|
|
|
// radius gets calculated for each additional stroke
|
|
|
|
if (radiiPtr) {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (radiiPtr[i] > 0.0)
|
|
|
|
radiiPtr[i] *= 2.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
for (PRUint32 i = 0; i < borderColorStyleCount; i++) {
|
|
|
|
gfxRGBA lineColor;
|
|
|
|
|
|
|
|
ComputeColorForLine(i, borderWidth,
|
|
|
|
borderColorStyle, borderColorStyleCount,
|
|
|
|
compositeColors, compositeColorCount,
|
|
|
|
borderRenderColor, bgColor, lineColor);
|
|
|
|
|
|
|
|
ctx->SetLineWidth(1.0);
|
|
|
|
ctx->SetColor(lineColor);
|
2007-05-08 21:40:08 +04:00
|
|
|
DoAllSidesBorderPath(ctx, sRect, radiiPtr, skipSides);
|
2007-05-01 07:31:25 +04:00
|
|
|
ctx->Stroke();
|
|
|
|
|
|
|
|
sRect.pos.x += 1.0;
|
|
|
|
sRect.pos.y += 1.0;
|
|
|
|
sRect.size.width -= 2.0;
|
|
|
|
sRect.size.height -= 2.0;
|
2007-05-08 21:40:08 +04:00
|
|
|
|
|
|
|
if (radiiPtr) {
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (radiiPtr[i] > 0.0)
|
|
|
|
radiiPtr[i] -= 2.0;
|
|
|
|
}
|
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (compositeColors) {
|
|
|
|
delete [] borderColorStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
// debug; draw a line on the outside and inside edge
|
|
|
|
// of the border.
|
|
|
|
ctx->SetLineWidth(1.0);
|
|
|
|
ctx->SetDash(nsnull, 0, 0.0);
|
|
|
|
ctx->SetColor(gfxRGBA(1.0, 0.0, 0.0, 1.0));
|
|
|
|
ctx->NewPath();
|
|
|
|
ctx->Rectangle(oRect);
|
|
|
|
ctx->Stroke();
|
|
|
|
ctx->NewPath();
|
|
|
|
ctx->Rectangle(iRect);
|
|
|
|
ctx->Stroke();
|
|
|
|
#endif
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2000-03-30 10:27:32 +04:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
void
|
|
|
|
nsCSSRendering::PaintBorder(nsPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
const nsStyleBorder& aBorderStyle,
|
|
|
|
nsStyleContext* aStyleContext,
|
|
|
|
PRIntn aSkipSides,
|
|
|
|
nsRect* aGap,
|
|
|
|
nscoord aHardBorderSize,
|
|
|
|
PRBool aShouldIgnoreRounded)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-03-30 10:27:32 +04:00
|
|
|
nsMargin border;
|
|
|
|
nsStyleCoord bordStyleRadius[4];
|
2007-05-08 21:40:08 +04:00
|
|
|
PRInt32 borderRadii[4];
|
2000-03-30 10:27:32 +04:00
|
|
|
float percent;
|
2003-12-25 00:51:50 +03:00
|
|
|
nsCompatibility compatMode = aPresContext->CompatibilityMode();
|
2007-05-01 07:31:25 +04:00
|
|
|
PRBool haveBorderRadius = PR_FALSE;
|
|
|
|
|
|
|
|
SN("++ PaintBorder");
|
2000-03-30 10:27:32 +04:00
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
// Check to see if we have an appearance defined. If so, we let the theme
|
2002-09-21 05:03:38 +04:00
|
|
|
// renderer draw the border. DO not get the data from aForFrame, since the passed in style context
|
|
|
|
// may be different! Always use |aStyleContext|!
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleDisplay* displayData = aStyleContext->GetStyleDisplay();
|
2001-12-18 01:51:39 +03:00
|
|
|
if (displayData->mAppearance) {
|
2004-07-29 23:41:39 +04:00
|
|
|
nsITheme *theme = aPresContext->GetTheme();
|
2002-09-21 05:03:38 +04:00
|
|
|
if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame, displayData->mAppearance))
|
2001-12-18 01:51:39 +03:00
|
|
|
return; // Let the theme handle it.
|
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
// Get our style context's color struct.
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleColor* ourColor = aStyleContext->GetStyleColor();
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// in NavQuirks mode we want to use the parent's context as a starting point
|
2000-03-30 10:27:32 +04:00
|
|
|
// for determining the background color
|
2007-05-01 07:31:25 +04:00
|
|
|
const nsStyleBackground* bgColor = nsCSSRendering::FindNonTransparentBackground
|
|
|
|
(aStyleContext, compatMode == eCompatibility_NavQuirks ? PR_TRUE : PR_FALSE);
|
2003-07-30 12:13:07 +04:00
|
|
|
|
1999-09-03 18:12:09 +04:00
|
|
|
if (aHardBorderSize > 0) {
|
|
|
|
border.SizeTo(aHardBorderSize, aHardBorderSize, aHardBorderSize, aHardBorderSize);
|
|
|
|
} else {
|
2006-12-14 02:04:57 +03:00
|
|
|
border = aBorderStyle.GetBorder();
|
1999-09-03 18:12:09 +04:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
if ((0 == border.left) && (0 == border.right) &&
|
|
|
|
(0 == border.top) && (0 == border.bottom)) {
|
|
|
|
// Empty border area
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-12-23 23:48:07 +03:00
|
|
|
// get the radius for our border
|
|
|
|
aBorderStyle.mBorderRadius.GetTop(bordStyleRadius[0]); //topleft
|
|
|
|
aBorderStyle.mBorderRadius.GetRight(bordStyleRadius[1]); //topright
|
|
|
|
aBorderStyle.mBorderRadius.GetBottom(bordStyleRadius[2]); //bottomright
|
|
|
|
aBorderStyle.mBorderRadius.GetLeft(bordStyleRadius[3]); //bottomleft
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// convert percentage values
|
2007-05-08 21:40:08 +04:00
|
|
|
for(int i = 0; i < 4; i++) {
|
1999-12-23 23:48:07 +03:00
|
|
|
borderRadii[i] = 0;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
switch (bordStyleRadius[i].GetUnit()) {
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
percent = bordStyleRadius[i].GetPercentValue();
|
|
|
|
borderRadii[i] = (nscoord)(percent * aForFrame->GetSize().width);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
borderRadii[i] = bordStyleRadius[i].GetCoordValue();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
1999-09-03 18:12:09 +04:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
if (borderRadii[i])
|
|
|
|
haveBorderRadius = PR_TRUE;
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
2007-05-08 21:40:08 +04:00
|
|
|
SF("Border[0]: %d %d %d %d\n", borderRadii[0], borderRadii[1], borderRadii[2], borderRadii[3]);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
1998-12-10 20:50:11 +03:00
|
|
|
// Turn off rendering for all of the zero sized sides
|
2007-05-01 07:31:25 +04:00
|
|
|
if (border.top == 0) aSkipSides |= SIDE_BIT_TOP;
|
|
|
|
if (border.right == 0) aSkipSides |= SIDE_BIT_RIGHT;
|
|
|
|
if (border.bottom == 0) aSkipSides |= SIDE_BIT_BOTTOM;
|
|
|
|
if (border.left == 0) aSkipSides |= SIDE_BIT_LEFT;
|
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
if (aSkipSides & SIDE_BIT_TOP) {
|
|
|
|
border.top = 0;
|
|
|
|
borderRadii[C_TL] = 0;
|
|
|
|
borderRadii[C_TR] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSkipSides & SIDE_BIT_RIGHT) {
|
|
|
|
border.right = 0;
|
|
|
|
borderRadii[C_TR] = 0;
|
|
|
|
borderRadii[C_BR] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSkipSides & SIDE_BIT_BOTTOM) {
|
|
|
|
border.bottom = 0;
|
|
|
|
borderRadii[C_BR] = 0;
|
|
|
|
borderRadii[C_BL] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSkipSides & SIDE_BIT_LEFT) {
|
|
|
|
border.left = 0;
|
|
|
|
borderRadii[C_BL] = 0;
|
|
|
|
borderRadii[C_TL] = 0;
|
|
|
|
}
|
1998-12-07 22:02:13 +03:00
|
|
|
|
2001-04-16 17:14:40 +04:00
|
|
|
// get the inside and outside parts of the border
|
2007-05-01 07:31:25 +04:00
|
|
|
nsRect outerRect(aBorderArea), innerRect(aBorderArea);
|
2001-04-16 17:14:40 +04:00
|
|
|
innerRect.Deflate(border);
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
SF(" innerRect: %d %d %d %d\n", innerRect.x, innerRect.y, innerRect.width, innerRect.height);
|
|
|
|
SF(" outerRect: %d %d %d %d\n", outerRect.x, outerRect.y, outerRect.width, outerRect.height);
|
|
|
|
|
|
|
|
// if the border size is more than the appropriate dimension of the area,
|
|
|
|
// then... do what?
|
|
|
|
// XXX what is this? according to bug 62245, this check might not be
|
|
|
|
// needed any more
|
2001-04-16 17:14:40 +04:00
|
|
|
if (border.left + border.right > aBorderArea.width) {
|
|
|
|
innerRect.x = outerRect.x;
|
|
|
|
innerRect.width = outerRect.width;
|
|
|
|
}
|
|
|
|
if (border.top + border.bottom > aBorderArea.height) {
|
|
|
|
innerRect.y = outerRect.y;
|
|
|
|
innerRect.height = outerRect.height;
|
|
|
|
}
|
|
|
|
|
1999-08-29 07:25:56 +04:00
|
|
|
// If the dirty rect is completely inside the border area (e.g., only the
|
|
|
|
// content is being painted), then we can skip out now
|
2007-05-01 07:31:25 +04:00
|
|
|
// XXX this isn't exactly true for rounded borders, where the inner curves may
|
|
|
|
// encroach into the content area. A safer calculation would be to
|
|
|
|
// shorten innerRect by the radius one each side before performing this test.
|
2001-04-16 17:14:40 +04:00
|
|
|
if (innerRect.Contains(aDirtyRect)) {
|
1999-08-29 07:25:56 +04:00
|
|
|
return;
|
|
|
|
}
|
1999-08-24 18:51:16 +04:00
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
SF("Border[0.5]: %d %d %d %d\n", borderRadii[0], borderRadii[1], borderRadii[2], borderRadii[3]);
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// The border radius has to be equal to or less than half the length
|
|
|
|
// of the two sides that form the corner. I think this is what trunk does;
|
|
|
|
// without this check, the result is still well defined: the center of the
|
|
|
|
// arc created by the corner is always inset by (radius,radius) from the
|
|
|
|
// relevant corner, even if that causes it to go into another quadrant.
|
|
|
|
if (haveBorderRadius) {
|
2007-05-08 21:40:08 +04:00
|
|
|
borderRadii[C_TL] = PR_MIN(borderRadii[C_TL], innerRect.width + border.left);
|
|
|
|
borderRadii[C_TL] = PR_MIN(borderRadii[C_TL], innerRect.height + border.top);
|
|
|
|
borderRadii[C_TL] = PR_MAX(borderRadii[C_TL], 0);
|
2005-06-08 18:34:16 +04:00
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
borderRadii[C_TR] = PR_MIN(borderRadii[C_TR], innerRect.width + border.right);
|
|
|
|
borderRadii[C_TR] = PR_MIN(borderRadii[C_TR], innerRect.height + border.top);
|
|
|
|
borderRadii[C_TR] = PR_MAX(borderRadii[C_TR], 0);
|
2006-04-21 21:52:05 +04:00
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
borderRadii[C_BR] = PR_MIN(borderRadii[C_BR], innerRect.width + border.right);
|
|
|
|
borderRadii[C_BR] = PR_MIN(borderRadii[C_BR], innerRect.height + border.bottom);
|
|
|
|
borderRadii[C_BR] = PR_MAX(borderRadii[C_BR], 0);
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
borderRadii[C_BL] = PR_MIN(borderRadii[C_BL], innerRect.width + border.left);
|
|
|
|
borderRadii[C_BL] = PR_MIN(borderRadii[C_BL], innerRect.height + border.bottom);
|
|
|
|
borderRadii[C_BL] = PR_MAX(borderRadii[C_BL], 0);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2006-04-21 21:52:05 +04:00
|
|
|
|
2007-05-08 21:40:08 +04:00
|
|
|
SF("Border[1]: %d %d %d %d\n", borderRadii[0], borderRadii[1], borderRadii[2], borderRadii[3]);
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// we can assume that we're already clipped to aDirtyRect -- I think? (!?)
|
2001-12-05 11:35:05 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
/* Get our conversion values */
|
|
|
|
nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
|
2001-12-05 11:35:05 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
static PRUint8 sideOrder[] = { NS_SIDE_BOTTOM, NS_SIDE_LEFT, NS_SIDE_TOP, NS_SIDE_RIGHT };
|
2001-12-05 11:35:05 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
nsRefPtr<gfxContext> ctx = (gfxContext*)
|
|
|
|
aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
|
2001-12-05 11:35:05 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
PRBool doSeparateSides = PR_FALSE;
|
2001-12-11 14:13:16 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// If we have to skip some sides, we have to draw separate sides.
|
|
|
|
// Otherwise, examine the border style to figure out if we can
|
|
|
|
// draw it in one go or not.
|
|
|
|
if (aSkipSides ||
|
|
|
|
border.left != border.right ||
|
|
|
|
border.left != border.top ||
|
|
|
|
border.left != border.bottom)
|
|
|
|
{
|
|
|
|
doSeparateSides = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
doSeparateSides = ShouldDoSeparateSides (aBorderStyle, ourColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
SF("doSeparateSides: %d skipsides: t:%d l:%d r:%d b:%d\n", doSeparateSides,
|
|
|
|
(aSkipSides & SIDE_BIT_TOP) ? 1 : 0,
|
|
|
|
(aSkipSides & SIDE_BIT_LEFT) ? 1 : 0,
|
|
|
|
(aSkipSides & SIDE_BIT_RIGHT) ? 1 : 0,
|
|
|
|
(aSkipSides & SIDE_BIT_BOTTOM) ? 1 : 0);
|
|
|
|
|
|
|
|
// the outside border rect
|
|
|
|
gfxRect oRect(gfxFloat(outerRect.x) / twipsPerPixel,
|
|
|
|
gfxFloat(outerRect.y) / twipsPerPixel,
|
|
|
|
gfxFloat(outerRect.width) / twipsPerPixel,
|
|
|
|
gfxFloat(outerRect.height) / twipsPerPixel);
|
|
|
|
|
|
|
|
// the inside border rect
|
|
|
|
gfxRect iRect(gfxFloat(innerRect.x) / twipsPerPixel,
|
|
|
|
gfxFloat(innerRect.y) / twipsPerPixel,
|
|
|
|
gfxFloat(innerRect.width) / twipsPerPixel,
|
|
|
|
gfxFloat(innerRect.height) / twipsPerPixel);
|
|
|
|
|
|
|
|
|
|
|
|
// round oRect and iRect; they're already an integer
|
|
|
|
// number of pixels apart and should stay that way after
|
|
|
|
// rounding.
|
|
|
|
oRect.Round();
|
|
|
|
iRect.Round();
|
|
|
|
|
|
|
|
// the border "line", right down the middle of each border edge
|
|
|
|
// lRect must NOT be rounded
|
|
|
|
gfxRect lRect(oRect.pos.x + border.left / (2.0 * twipsPerPixel),
|
|
|
|
oRect.pos.y + border.top / (2.0 * twipsPerPixel),
|
|
|
|
oRect.size.width - (border.left + border.right) / (2.0 * twipsPerPixel),
|
|
|
|
oRect.size.height - (border.top + border.bottom) / (2.0 * twipsPerPixel));
|
|
|
|
|
|
|
|
S(" oRect: "), S(oRect), SN();
|
|
|
|
S(" iRect: "), S(iRect), SN();
|
|
|
|
S(" lRect: "), S(lRect), SN();
|
|
|
|
|
2007-05-21 02:41:21 +04:00
|
|
|
// if conditioning the outside rect failed, then ail -- the outside
|
|
|
|
// rect is supposed to enclose the entire border
|
|
|
|
oRect.Condition();
|
|
|
|
if (oRect.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
iRect.Condition();
|
|
|
|
lRect.Condition();
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
ctx->Save();
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// this will draw a transparent red backround underneath the area between iRect and oRect
|
|
|
|
ctx->Save();
|
|
|
|
ctx->Rectangle(iRect);
|
|
|
|
ctx->Clip();
|
|
|
|
ctx->NewPath();
|
|
|
|
|
|
|
|
ctx->Rectangle(oRect);
|
|
|
|
ctx->SetColor(gfxRGBA(1.0, 0.0, 0.0, 0.5));
|
|
|
|
ctx->Fill();
|
|
|
|
ctx->Restore();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Clamp the CTM to be pixel-aligned; we do this only
|
|
|
|
// for translation-only matrices now, but we could do it
|
|
|
|
// if the matrix has just a scale as well. We should not
|
|
|
|
// do it if there's a rotation.
|
|
|
|
gfxMatrix mat = ctx->CurrentMatrix();
|
|
|
|
if (!mat.HasNonTranslation()) {
|
|
|
|
mat.x0 = floor(mat.x0 + 0.5);
|
|
|
|
mat.y0 = floor(mat.y0 + 0.5);
|
|
|
|
ctx->SetMatrix(mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we're going to do separate sides, we need to do it as
|
|
|
|
// a temporary surface group
|
|
|
|
if (doSeparateSides) {
|
|
|
|
// clip to oRect to define the size of the temporary surface
|
|
|
|
ctx->NewPath();
|
|
|
|
ctx->Rectangle(oRect);
|
|
|
|
|
|
|
|
if (aGap) {
|
|
|
|
gfxRect gapRect(gfxFloat(aGap->x) / twipsPerPixel,
|
|
|
|
gfxFloat(aGap->y) / twipsPerPixel,
|
|
|
|
gfxFloat(aGap->width) / twipsPerPixel,
|
|
|
|
gfxFloat(aGap->height) / twipsPerPixel);
|
|
|
|
ctx->Rectangle(gapRect);
|
|
|
|
ctx->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
|
|
|
|
ctx->Clip();
|
|
|
|
ctx->SetFillRule(gfxContext::FILL_RULE_WINDING);
|
|
|
|
} else {
|
|
|
|
ctx->Clip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// start a compositing group and render using ADD so that
|
|
|
|
// we get correct behaviour at the joins
|
|
|
|
ctx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_ADD);
|
|
|
|
} else if (aGap) {
|
|
|
|
gfxRect gapRect(gfxFloat(aGap->x) / twipsPerPixel,
|
|
|
|
gfxFloat(aGap->y) / twipsPerPixel,
|
|
|
|
gfxFloat(aGap->width) / twipsPerPixel,
|
|
|
|
gfxFloat(aGap->height) / twipsPerPixel);
|
|
|
|
ctx->Rectangle(gapRect);
|
|
|
|
ctx->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
|
|
|
|
ctx->Clip();
|
|
|
|
ctx->SetFillRule(gfxContext::FILL_RULE_WINDING);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're doing separateSides, then do all 4 sides.
|
|
|
|
// Otherwise, we can just use the style of the first side
|
|
|
|
// (since all 4 are identical) and not set any clip so that
|
|
|
|
// DrawBorderSides draws the entire border in one go.
|
|
|
|
int numSides = doSeparateSides ? 4 : 1;
|
2007-05-08 21:40:08 +04:00
|
|
|
for (int i = 0; i < numSides; i++) {
|
2007-05-01 07:31:25 +04:00
|
|
|
PRUint8 side = sideOrder[i];
|
|
|
|
|
|
|
|
// skip this side if it's, well, skipped
|
|
|
|
if (doSeparateSides) {
|
|
|
|
if (aSkipSides & (1 << side))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ctx->Save();
|
|
|
|
|
|
|
|
PRUint8 style = aBorderStyle.GetBorderStyle(side);
|
|
|
|
|
|
|
|
// Figure out how to clip to this side. We have three options; see
|
|
|
|
// the comments for DoSideClipPath for more details.
|
|
|
|
//
|
|
|
|
// TRAPEZOID_FULL: used when we have a border radius to get the curve
|
|
|
|
// that's inside iRect to appear and not get clipped out. It's technically
|
|
|
|
// a triangle.
|
|
|
|
//
|
|
|
|
// RECTANGLE: used for dotted/dashed borders so that we can draw the right
|
|
|
|
// sides correctly.
|
|
|
|
//
|
|
|
|
// TRAPEZOID: used in all other cases. The trapezoid formed by the relevant
|
|
|
|
// corners of iRect and oRect.
|
|
|
|
DoSideClipPath(ctx, iRect, oRect, lRect, side, aBorderStyle, borderRadii);
|
|
|
|
ctx->Clip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the whole border along lRect. If we're not doing doSeparateSides,
|
|
|
|
// then sides are identical and no clip was set -- this will draw the entire border.
|
|
|
|
// Otherwise, this will still draw the entire border in the style of this side, but it
|
|
|
|
// will be clipped by the above code. We do this to get the joins looking correct.
|
|
|
|
|
|
|
|
nscolor borderRenderColor;
|
|
|
|
PRBool transparent, foreground;
|
|
|
|
nsBorderColors *compositeColors = nsnull;
|
|
|
|
|
|
|
|
aBorderStyle.GetBorderColor(side, borderRenderColor, transparent, foreground);
|
|
|
|
aBorderStyle.GetCompositeColors(side, &compositeColors);
|
|
|
|
|
|
|
|
if (!transparent || compositeColors) {
|
|
|
|
if (foreground)
|
|
|
|
borderRenderColor = ourColor->mColor;
|
|
|
|
|
|
|
|
PRUint32 borderWidth = border.side(side) / twipsPerPixel;
|
|
|
|
NS_ASSERTION(borderWidth * twipsPerPixel == border.side(side), "Border size from style system was not an integer number of pixels!");
|
|
|
|
DrawBorderSides(ctx,
|
|
|
|
borderWidth,
|
|
|
|
aBorderStyle.GetBorderStyle(side),
|
|
|
|
borderRenderColor,
|
|
|
|
compositeColors,
|
|
|
|
iRect, oRect, lRect,
|
|
|
|
ourColor->mColor, bgColor->mBackgroundColor,
|
2007-05-08 21:40:08 +04:00
|
|
|
doSeparateSides, side, aSkipSides,
|
2007-05-01 07:31:25 +04:00
|
|
|
twipsPerPixel,
|
|
|
|
haveBorderRadius ? borderRadii : nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doSeparateSides)
|
|
|
|
ctx->Restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doSeparateSides) {
|
|
|
|
ctx->PopGroupToSource();
|
|
|
|
ctx->Paint();
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->Restore();
|
|
|
|
|
|
|
|
SN();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
void
|
|
|
|
nsCSSRendering::PaintOutline(nsPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
const nsStyleBorder& aBorderStyle,
|
|
|
|
const nsStyleOutline& aOutlineStyle,
|
|
|
|
nsStyleContext* aStyleContext,
|
|
|
|
nsRect* aGap)
|
1999-08-19 18:22:47 +04:00
|
|
|
{
|
2007-05-01 07:31:25 +04:00
|
|
|
nsStyleCoord bordStyleRadius[4];
|
2007-05-08 21:40:08 +04:00
|
|
|
PRInt32 borderRadii[4];
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
PRBool haveBorderRadius = PR_FALSE;
|
2000-02-01 19:03:13 +03:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
// Get our style context's color struct.
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleColor* ourColor = aStyleContext->GetStyleColor();
|
1999-08-19 18:22:47 +04:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
nscoord width, offset;
|
|
|
|
float percent;
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
aOutlineStyle.GetOutlineWidth(width);
|
1999-08-19 18:22:47 +04:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
if (width == 0) {
|
1999-08-19 18:22:47 +04:00
|
|
|
// Empty outline
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
const nsStyleBackground* bgColor = nsCSSRendering::FindNonTransparentBackground
|
|
|
|
(aStyleContext, PR_FALSE);
|
|
|
|
|
2004-10-26 16:57:15 +04:00
|
|
|
// get the radius for our outline
|
2001-02-07 12:57:26 +03:00
|
|
|
aOutlineStyle.mOutlineRadius.GetTop(bordStyleRadius[0]); //topleft
|
|
|
|
aOutlineStyle.mOutlineRadius.GetRight(bordStyleRadius[1]); //topright
|
|
|
|
aOutlineStyle.mOutlineRadius.GetBottom(bordStyleRadius[2]); //bottomright
|
|
|
|
aOutlineStyle.mOutlineRadius.GetLeft(bordStyleRadius[3]); //bottomleft
|
2000-02-01 19:03:13 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// convert percentage values
|
2007-05-08 21:40:08 +04:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2000-02-01 19:03:13 +03:00
|
|
|
borderRadii[i] = 0;
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
switch (bordStyleRadius[i].GetUnit()) {
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
percent = bordStyleRadius[i].GetPercentValue();
|
|
|
|
borderRadii[i] = (nscoord)(percent * aBorderArea.width);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
borderRadii[i] = bordStyleRadius[i].GetCoordValue();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2000-02-01 19:03:13 +03:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
if (borderRadii[i])
|
|
|
|
haveBorderRadius = PR_TRUE;
|
2000-02-01 19:03:13 +03:00
|
|
|
}
|
|
|
|
|
2007-03-28 09:53:29 +04:00
|
|
|
nsRect overflowArea = aForFrame->GetOverflowRect();
|
1999-08-19 18:22:47 +04:00
|
|
|
|
2004-10-26 16:57:15 +04:00
|
|
|
// get the offset for our outline
|
|
|
|
aOutlineStyle.GetOutlineOffset(offset);
|
2007-03-28 09:53:29 +04:00
|
|
|
nsRect outside(overflowArea + aBorderArea.TopLeft());
|
2004-08-26 04:07:56 +04:00
|
|
|
nsRect inside(outside);
|
2004-10-26 16:57:15 +04:00
|
|
|
if (width + offset >= 0) {
|
|
|
|
// the overflow area is exactly the outside edge of the outline
|
|
|
|
inside.Deflate(width, width);
|
|
|
|
} else {
|
|
|
|
// the overflow area is exactly the rectangle containing the frame and its
|
|
|
|
// children; we can compute the outline directly
|
|
|
|
inside.Deflate(-offset, -offset);
|
|
|
|
if (inside.width < 0 || inside.height < 0) {
|
|
|
|
return; // Protect against negative outline sizes
|
|
|
|
}
|
|
|
|
outside = inside;
|
|
|
|
outside.Inflate(width, width);
|
|
|
|
}
|
1999-08-19 18:22:47 +04:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// If the dirty rect is completely inside the border area (e.g., only the
|
|
|
|
// content is being painted), then we can skip out now
|
|
|
|
// XXX this isn't exactly true for rounded borders, where the inside curves may
|
|
|
|
// encroach into the content area. A safer calculation would be to
|
|
|
|
// shorten insideRect by the radius one each side before performing this test.
|
|
|
|
if (inside.Contains(aDirtyRect)) {
|
|
|
|
return;
|
2000-02-01 19:03:13 +03:00
|
|
|
}
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// The border radius has to be equal to or less than half the length
|
|
|
|
// of the two sides that form the corner. I think this is what trunk does;
|
|
|
|
// without this check, the result is still well defined: the center of the
|
|
|
|
// arc created by the corner is always inset by (radius,radius) from the
|
|
|
|
// relevant corner, even if that causes it to go into another quadrant.
|
|
|
|
if (haveBorderRadius) {
|
|
|
|
borderRadii[0] = PR_MIN(borderRadii[0], (inside.width + width) / 2);
|
|
|
|
borderRadii[0] = PR_MIN(borderRadii[0], (inside.height + width) / 2);
|
2007-05-08 21:40:08 +04:00
|
|
|
borderRadii[0] = PR_MAX(borderRadii[0], 0);
|
2000-02-01 19:03:13 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
borderRadii[1] = PR_MIN(borderRadii[1], (inside.width + width) / 2);
|
|
|
|
borderRadii[1] = PR_MIN(borderRadii[1], (inside.height + width) / 2);
|
2007-05-08 21:40:08 +04:00
|
|
|
borderRadii[1] = PR_MAX(borderRadii[1], 0);
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
borderRadii[2] = PR_MIN(borderRadii[2], (inside.width + width) / 2);
|
|
|
|
borderRadii[2] = PR_MIN(borderRadii[2], (inside.height + width) / 2);
|
2007-05-08 21:40:08 +04:00
|
|
|
borderRadii[2] = PR_MAX(borderRadii[2], 0);
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
borderRadii[3] = PR_MIN(borderRadii[3], (inside.width + width) / 2);
|
|
|
|
borderRadii[3] = PR_MIN(borderRadii[3], (inside.height + width) / 2);
|
2007-05-08 21:40:08 +04:00
|
|
|
borderRadii[3] = PR_MAX(borderRadii[3], 0);
|
1999-08-19 18:22:47 +04:00
|
|
|
}
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
/* Get our conversion values */
|
|
|
|
nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
|
|
|
|
|
|
|
|
gfxRect oRect(gfxFloat(outside.x) / twipsPerPixel,
|
|
|
|
gfxFloat(outside.y) / twipsPerPixel,
|
|
|
|
gfxFloat(outside.width) / twipsPerPixel,
|
|
|
|
gfxFloat(outside.height) / twipsPerPixel);
|
|
|
|
|
|
|
|
gfxRect iRect(gfxFloat(inside.x) / twipsPerPixel,
|
|
|
|
gfxFloat(inside.y) / twipsPerPixel,
|
|
|
|
gfxFloat(inside.width) / twipsPerPixel,
|
|
|
|
gfxFloat(inside.height) / twipsPerPixel);
|
|
|
|
|
|
|
|
oRect.Round();
|
|
|
|
iRect.Round();
|
1999-08-19 18:22:47 +04:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// the border "line", right down the middle of each border edge
|
|
|
|
// lRect must NOT be rounded
|
|
|
|
gfxRect lRect(oRect.pos.x + width / (2.0 * twipsPerPixel),
|
|
|
|
oRect.pos.y + width / (2.0 * twipsPerPixel),
|
|
|
|
oRect.size.width - (2*width) / (2.0 * twipsPerPixel),
|
|
|
|
oRect.size.height - (2*width) / (2.0 * twipsPerPixel));
|
1999-08-19 18:22:47 +04:00
|
|
|
|
2007-05-21 02:41:21 +04:00
|
|
|
// if conditioning the outside rect failed, then bail -- the outside
|
|
|
|
// rect is supposed to enclose the entire outline
|
|
|
|
oRect.Condition();
|
|
|
|
if (oRect.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
iRect.Condition();
|
|
|
|
lRect.Condition();
|
|
|
|
|
2007-05-01 08:58:44 +04:00
|
|
|
nscolor outlineColor;
|
|
|
|
|
|
|
|
// PR_FALSE means use the initial color; PR_TRUE means a color was
|
|
|
|
// set.
|
|
|
|
if (!aOutlineStyle.GetOutlineColor(outlineColor))
|
|
|
|
outlineColor = ourColor->mColor;
|
|
|
|
|
|
|
|
PRUint8 outlineStyle = aOutlineStyle.GetOutlineStyle();
|
1999-08-19 18:22:47 +04:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// grab the thebes context
|
|
|
|
nsRefPtr<gfxContext> ctx = (gfxContext*)
|
|
|
|
aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
|
1999-01-03 22:23:21 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
ctx->Save();
|
1999-02-12 20:45:58 +03:00
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// Clamp the CTM to be pixel-aligned; we do this only
|
|
|
|
// for translation-only matrices now, but we could do it
|
|
|
|
// if the matrix has just a scale as well. We should not
|
|
|
|
// do it if there's a rotation.
|
|
|
|
gfxMatrix mat = ctx->CurrentMatrix();
|
|
|
|
if (!mat.HasNonTranslation()) {
|
|
|
|
mat.x0 = floor(mat.x0 + 0.5);
|
|
|
|
mat.y0 = floor(mat.y0 + 0.5);
|
|
|
|
ctx->SetMatrix(mat);
|
1998-12-18 01:58:51 +03:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
PRBool doSeparateSides = PR_FALSE;
|
|
|
|
if (outlineStyle == NS_STYLE_BORDER_STYLE_DASHED ||
|
|
|
|
outlineStyle == NS_STYLE_BORDER_STYLE_DOTTED)
|
|
|
|
{
|
|
|
|
doSeparateSides = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we're going to do separate sides, we need to do it as
|
|
|
|
// a temporary surface group
|
|
|
|
if (doSeparateSides) {
|
|
|
|
// clip to oRect to define the size of the temporary surface
|
|
|
|
ctx->NewPath();
|
|
|
|
ctx->Rectangle(oRect);
|
|
|
|
|
|
|
|
if (aGap) {
|
|
|
|
gfxRect gapRect(gfxFloat(aGap->x) / twipsPerPixel,
|
|
|
|
gfxFloat(aGap->y) / twipsPerPixel,
|
|
|
|
gfxFloat(aGap->width) / twipsPerPixel,
|
|
|
|
gfxFloat(aGap->height) / twipsPerPixel);
|
|
|
|
ctx->Rectangle(gapRect);
|
|
|
|
ctx->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
|
|
|
|
ctx->Clip();
|
|
|
|
ctx->SetFillRule(gfxContext::FILL_RULE_WINDING);
|
|
|
|
} else {
|
|
|
|
ctx->Clip();
|
1998-12-18 01:58:51 +03:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
// start a compositing group and render using ADD so that
|
|
|
|
// we get correct behaviour at the joins
|
|
|
|
ctx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_ADD);
|
|
|
|
} else if (aGap) {
|
|
|
|
gfxRect gapRect(gfxFloat(aGap->x) / twipsPerPixel,
|
|
|
|
gfxFloat(aGap->y) / twipsPerPixel,
|
|
|
|
gfxFloat(aGap->width) / twipsPerPixel,
|
|
|
|
gfxFloat(aGap->height) / twipsPerPixel);
|
|
|
|
ctx->Rectangle(gapRect);
|
|
|
|
ctx->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
|
|
|
|
ctx->Clip();
|
|
|
|
ctx->SetFillRule(gfxContext::FILL_RULE_WINDING);
|
1998-12-18 01:58:51 +03:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
// If we're doing separateSides, then do all 4 sides.
|
|
|
|
// Otherwise, we can just use the style of the first side
|
|
|
|
// (since all 4 are identical) and not set any clip so that
|
|
|
|
// DrawBorderSides draws the entire border in one go.
|
|
|
|
|
|
|
|
static PRUint8 sideOrder[] = { NS_SIDE_BOTTOM, NS_SIDE_LEFT, NS_SIDE_TOP, NS_SIDE_RIGHT };
|
|
|
|
|
|
|
|
int numSides = doSeparateSides ? 4 : 1;
|
2007-05-08 21:40:08 +04:00
|
|
|
for (int i = 0; i < numSides; i++) {
|
2007-05-01 07:31:25 +04:00
|
|
|
PRUint8 side = sideOrder[i];
|
|
|
|
|
|
|
|
// skip this side if it's, well, skipped
|
|
|
|
if (doSeparateSides) {
|
|
|
|
ctx->Save();
|
|
|
|
|
|
|
|
PRUint8 style = outlineStyle;
|
|
|
|
|
|
|
|
// Figure out how to clip to this side. We have three options; see
|
|
|
|
// the comments for DoSideClipPath for more details.
|
|
|
|
//
|
|
|
|
// TRAPEZOID_FULL: used when we have a border radius to get the curve
|
|
|
|
// that's inside iRect to appear and not get clipped out. It's technically
|
|
|
|
// a triangle.
|
|
|
|
//
|
|
|
|
// RECTANGLE: used for dotted/dashed borders so that we can draw the right
|
|
|
|
// sides correctly.
|
|
|
|
//
|
|
|
|
// TRAPEZOID: used in all other cases. The trapezoid formed by the relevant
|
|
|
|
// corners of iRect and oRect.
|
|
|
|
DoSideClipPath(ctx, iRect, oRect, lRect, side, aBorderStyle, borderRadii);
|
|
|
|
ctx->Clip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the whole border along lRect. If we're not doing doSeparateSides,
|
|
|
|
// then sides are identical and no clip was set -- this will draw the entire border.
|
|
|
|
// Otherwise, this will still draw the entire border in the style of this side, but it
|
|
|
|
// will be clipped by the above code. We do this to get the joins looking correct.
|
|
|
|
|
|
|
|
PRUint32 outlineWidth = NSToCoordRound(float(gfxFloat(width) / twipsPerPixel));
|
|
|
|
DrawBorderSides(ctx,
|
|
|
|
outlineWidth,
|
|
|
|
outlineStyle,
|
|
|
|
outlineColor,
|
|
|
|
nsnull,
|
|
|
|
iRect, oRect, lRect,
|
|
|
|
outlineColor, bgColor->mBackgroundColor,
|
2007-05-08 21:40:08 +04:00
|
|
|
doSeparateSides, side, 0,
|
2007-05-01 07:31:25 +04:00
|
|
|
twipsPerPixel,
|
|
|
|
haveBorderRadius ? borderRadii : nsnull);
|
|
|
|
|
|
|
|
if (doSeparateSides)
|
|
|
|
ctx->Restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doSeparateSides) {
|
|
|
|
ctx->PopGroupToSource();
|
|
|
|
ctx->Paint();
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->Restore();
|
|
|
|
|
|
|
|
SN();
|
1998-12-18 01:58:51 +03:00
|
|
|
}
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
// Thebes Border Rendering Code End
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-12-18 01:58:51 +03:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-04-25 06:43:50 +04:00
|
|
|
// Returns the anchor point to use for the background image. The
|
|
|
|
// anchor point is the (x, y) location where the first tile should
|
|
|
|
// be placed
|
|
|
|
//
|
1999-04-29 22:29:56 +04:00
|
|
|
// For repeated tiling, the anchor values are normalized wrt to the upper-left
|
|
|
|
// edge of the bounds, and are always in the range:
|
1999-04-25 06:43:50 +04:00
|
|
|
// -(aTileWidth - 1) <= anchor.x <= 0
|
|
|
|
// -(aTileHeight - 1) <= anchor.y <= 0
|
|
|
|
//
|
1999-04-25 08:14:06 +04:00
|
|
|
// i.e., they are either 0 or a negative number whose absolute value is
|
|
|
|
// less than the tile size in that dimension
|
2001-08-18 03:26:29 +04:00
|
|
|
//
|
2002-10-08 14:24:53 +04:00
|
|
|
// aOriginBounds is the box to which the tiling position should be relative
|
|
|
|
// aClipBounds is the box in which the tiling will actually be done
|
|
|
|
// They should correspond to 'background-origin' and 'background-clip',
|
|
|
|
// except when painting on the canvas, in which case the origin bounds
|
|
|
|
// should be the bounds of the root element's frame and the clip bounds
|
|
|
|
// should be the bounds of the canvas frame.
|
1998-12-12 06:06:02 +03:00
|
|
|
static void
|
2001-06-01 02:19:43 +04:00
|
|
|
ComputeBackgroundAnchorPoint(const nsStyleBackground& aColor,
|
2002-10-08 14:24:53 +04:00
|
|
|
const nsRect& aOriginBounds,
|
|
|
|
const nsRect& aClipBounds,
|
1998-10-27 19:50:19 +03:00
|
|
|
nscoord aTileWidth, nscoord aTileHeight,
|
|
|
|
nsPoint& aResult)
|
1998-09-26 21:16:56 +04:00
|
|
|
{
|
1998-10-27 19:50:19 +03:00
|
|
|
nscoord x;
|
|
|
|
if (NS_STYLE_BG_X_POSITION_LENGTH & aColor.mBackgroundFlags) {
|
2003-01-19 05:36:04 +03:00
|
|
|
x = aColor.mBackgroundXPosition.mCoord;
|
1998-10-27 19:50:19 +03:00
|
|
|
}
|
2003-01-19 05:36:04 +03:00
|
|
|
else if (NS_STYLE_BG_X_POSITION_PERCENT & aColor.mBackgroundFlags) {
|
|
|
|
PRFloat64 percent = PRFloat64(aColor.mBackgroundXPosition.mFloat);
|
|
|
|
nscoord tilePos = nscoord(percent * PRFloat64(aTileWidth));
|
|
|
|
nscoord boxPos = nscoord(percent * PRFloat64(aOriginBounds.width));
|
1998-10-27 19:50:19 +03:00
|
|
|
x = boxPos - tilePos;
|
|
|
|
}
|
2003-01-19 05:36:04 +03:00
|
|
|
else {
|
|
|
|
x = 0;
|
|
|
|
}
|
2002-10-08 14:24:53 +04:00
|
|
|
x += aOriginBounds.x - aClipBounds.x;
|
1998-10-27 19:50:19 +03:00
|
|
|
if (NS_STYLE_BG_REPEAT_X & aColor.mBackgroundRepeat) {
|
|
|
|
// When we are tiling in the x direction the loop will run from
|
|
|
|
// the left edge of the box to the right edge of the box. We need
|
|
|
|
// to adjust the starting coordinate to lie within the band being
|
|
|
|
// rendered.
|
|
|
|
if (x < 0) {
|
|
|
|
x = -x;
|
|
|
|
if (x < 0) {
|
1998-09-26 21:16:56 +04:00
|
|
|
// Some joker gave us max-negative-integer.
|
1998-10-27 19:50:19 +03:00
|
|
|
x = 0;
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1998-10-27 19:50:19 +03:00
|
|
|
x %= aTileWidth;
|
|
|
|
x = -x;
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1999-04-25 06:43:50 +04:00
|
|
|
else if (x != 0) {
|
1998-10-27 19:50:19 +03:00
|
|
|
x %= aTileWidth;
|
1999-07-27 18:13:09 +04:00
|
|
|
if (x > 0) {
|
|
|
|
x = x - aTileWidth;
|
|
|
|
}
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1999-04-29 22:29:56 +04:00
|
|
|
|
|
|
|
NS_POSTCONDITION((x >= -(aTileWidth - 1)) && (x <= 0), "bad computed anchor value");
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1998-10-27 19:50:19 +03:00
|
|
|
aResult.x = x;
|
1998-09-26 21:16:56 +04:00
|
|
|
|
1998-10-27 19:50:19 +03:00
|
|
|
nscoord y;
|
|
|
|
if (NS_STYLE_BG_Y_POSITION_LENGTH & aColor.mBackgroundFlags) {
|
2003-01-19 05:36:04 +03:00
|
|
|
y = aColor.mBackgroundYPosition.mCoord;
|
1998-10-27 19:50:19 +03:00
|
|
|
}
|
2003-01-19 05:36:04 +03:00
|
|
|
else if (NS_STYLE_BG_Y_POSITION_PERCENT & aColor.mBackgroundFlags){
|
|
|
|
PRFloat64 percent = PRFloat64(aColor.mBackgroundYPosition.mFloat);
|
|
|
|
nscoord tilePos = nscoord(percent * PRFloat64(aTileHeight));
|
|
|
|
nscoord boxPos = nscoord(percent * PRFloat64(aOriginBounds.height));
|
1998-10-27 19:50:19 +03:00
|
|
|
y = boxPos - tilePos;
|
|
|
|
}
|
2003-01-19 05:36:04 +03:00
|
|
|
else {
|
|
|
|
y = 0;
|
|
|
|
}
|
2002-10-08 14:24:53 +04:00
|
|
|
y += aOriginBounds.y - aClipBounds.y;
|
1998-10-27 19:50:19 +03:00
|
|
|
if (NS_STYLE_BG_REPEAT_Y & aColor.mBackgroundRepeat) {
|
|
|
|
// When we are tiling in the y direction the loop will run from
|
|
|
|
// the top edge of the box to the bottom edge of the box. We need
|
|
|
|
// to adjust the starting coordinate to lie within the band being
|
|
|
|
// rendered.
|
|
|
|
if (y < 0) {
|
|
|
|
y = -y;
|
|
|
|
if (y < 0) {
|
1998-09-26 21:16:56 +04:00
|
|
|
// Some joker gave us max-negative-integer.
|
1998-10-27 19:50:19 +03:00
|
|
|
y = 0;
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1998-10-27 19:50:19 +03:00
|
|
|
y %= aTileHeight;
|
|
|
|
y = -y;
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1999-04-25 06:43:50 +04:00
|
|
|
else if (y != 0) {
|
1998-10-27 19:50:19 +03:00
|
|
|
y %= aTileHeight;
|
1999-07-27 18:13:09 +04:00
|
|
|
if (y > 0) {
|
|
|
|
y = y - aTileHeight;
|
|
|
|
}
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1999-04-29 22:29:56 +04:00
|
|
|
|
|
|
|
NS_POSTCONDITION((y >= -(aTileHeight - 1)) && (y <= 0), "bad computed anchor value");
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1998-10-27 19:50:19 +03:00
|
|
|
aResult.y = y;
|
1999-04-25 06:43:50 +04:00
|
|
|
}
|
|
|
|
|
2002-12-24 01:08:04 +03:00
|
|
|
// Returns the root scrollable frame, which is the first child of the root
|
|
|
|
// frame.
|
|
|
|
static nsIScrollableFrame*
|
2004-08-01 03:15:21 +04:00
|
|
|
GetRootScrollableFrame(nsPresContext* aPresContext, nsIFrame* aRootFrame)
|
2002-12-24 01:08:04 +03:00
|
|
|
{
|
|
|
|
nsIScrollableFrame* scrollableFrame = nsnull;
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::viewportFrame == aRootFrame->GetType()) {
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame* childFrame = aRootFrame->GetFirstChild(nsnull);
|
2002-12-24 01:08:04 +03:00
|
|
|
|
|
|
|
if (childFrame) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::scrollFrame == childFrame->GetType()) {
|
2002-12-24 01:08:04 +03:00
|
|
|
// Use this frame, even if we are using GFX frames for the
|
|
|
|
// viewport, which contains another scroll frame below this
|
|
|
|
// frame, since the GFX scrollport frame does not implement
|
|
|
|
// nsIScrollableFrame.
|
|
|
|
CallQueryInterface(childFrame, &scrollableFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
NS_WARNING("aRootFrame is not a viewport frame");
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
return scrollableFrame;
|
|
|
|
}
|
|
|
|
|
2002-08-11 21:56:15 +04:00
|
|
|
const nsStyleBackground*
|
2003-02-22 03:32:13 +03:00
|
|
|
nsCSSRendering::FindNonTransparentBackground(nsStyleContext* aContext,
|
2002-08-11 21:56:15 +04:00
|
|
|
PRBool aStartAtParent /*= PR_FALSE*/)
|
|
|
|
{
|
2004-03-31 07:13:54 +04:00
|
|
|
NS_ASSERTION(aContext, "Cannot find NonTransparentBackground in a null context" );
|
|
|
|
|
2002-08-11 21:56:15 +04:00
|
|
|
const nsStyleBackground* result = nsnull;
|
2004-03-31 07:13:54 +04:00
|
|
|
nsStyleContext* context = nsnull;
|
2002-08-11 21:56:15 +04:00
|
|
|
if (aStartAtParent) {
|
2002-10-09 05:46:15 +04:00
|
|
|
context = aContext->GetParent();
|
2004-03-31 07:13:54 +04:00
|
|
|
}
|
|
|
|
if (!context) {
|
2002-08-11 21:56:15 +04:00
|
|
|
context = aContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (context) {
|
2003-05-15 07:42:21 +04:00
|
|
|
result = context->GetStyleBackground();
|
2002-08-11 21:56:15 +04:00
|
|
|
if (0 == (result->mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT))
|
|
|
|
break;
|
|
|
|
|
|
|
|
context = context->GetParent();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-08 02:46:07 +03:00
|
|
|
/**
|
|
|
|
* |FindBackground| finds the correct style data to use to paint the
|
|
|
|
* background. It is responsible for handling the following two
|
|
|
|
* statements in section 14.2 of CSS2:
|
|
|
|
*
|
|
|
|
* The background of the box generated by the root element covers the
|
|
|
|
* entire canvas.
|
|
|
|
*
|
|
|
|
* For HTML documents, however, we recommend that authors specify the
|
|
|
|
* background for the BODY element rather than the HTML element. User
|
|
|
|
* agents should observe the following precedence rules to fill in the
|
|
|
|
* background: if the value of the 'background' property for the HTML
|
|
|
|
* element is different from 'transparent' then use it, else use the
|
|
|
|
* value of the 'background' property for the BODY element. If the
|
|
|
|
* resulting value is 'transparent', the rendering is undefined.
|
|
|
|
*
|
|
|
|
* Thus, in our implementation, it is responsible for ensuring that:
|
|
|
|
* + we paint the correct background on the |nsCanvasFrame|,
|
|
|
|
* |nsRootBoxFrame|, or |nsPageFrame|,
|
|
|
|
* + we don't paint the background on the root element, and
|
|
|
|
* + we don't paint the background on the BODY element in *some* cases,
|
|
|
|
* and for SGML-based HTML documents only.
|
|
|
|
*
|
|
|
|
* |FindBackground| returns true if a background should be painted, and
|
|
|
|
* the resulting style context to use for the background information
|
|
|
|
* will be filled in to |aBackground|. It fills in a boolean indicating
|
|
|
|
* whether the frame is the canvas frame to allow PaintBackground to
|
|
|
|
* ensure that it always paints something non-transparent for the
|
|
|
|
* canvas.
|
|
|
|
*/
|
|
|
|
|
2003-04-06 06:49:40 +04:00
|
|
|
// Returns nsnull if aFrame is not a canvas frame.
|
|
|
|
// Otherwise, it returns the frame we should look for the background on.
|
|
|
|
// This is normally aFrame but if aFrame is the viewport, we need to
|
|
|
|
// look for the background starting at the scroll root (which shares
|
|
|
|
// style context with the document root) or the document root itself.
|
|
|
|
// We need to treat the viewport as canvas because, even though
|
|
|
|
// it does not actually paint a background, we need to get the right
|
|
|
|
// background style so we correctly detect transparent documents.
|
|
|
|
inline nsIFrame*
|
2006-01-21 12:20:04 +03:00
|
|
|
IsCanvasFrame(nsIFrame *aFrame)
|
2002-01-08 02:46:07 +03:00
|
|
|
{
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom* frameType = aFrame->GetType();
|
2006-12-26 20:47:52 +03:00
|
|
|
if (frameType == nsGkAtoms::canvasFrame ||
|
|
|
|
frameType == nsGkAtoms::rootFrame ||
|
|
|
|
frameType == nsGkAtoms::pageFrame ||
|
|
|
|
frameType == nsGkAtoms::pageContentFrame) {
|
2003-04-06 06:49:40 +04:00
|
|
|
return aFrame;
|
2006-12-26 20:47:52 +03:00
|
|
|
} else if (frameType == nsGkAtoms::viewportFrame) {
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame* firstChild = aFrame->GetFirstChild(nsnull);
|
2003-04-06 06:49:40 +04:00
|
|
|
if (firstChild) {
|
|
|
|
return firstChild;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline PRBool
|
2006-01-21 12:20:04 +03:00
|
|
|
FindCanvasBackground(nsIFrame* aForFrame,
|
2002-01-08 02:46:07 +03:00
|
|
|
const nsStyleBackground** aBackground)
|
|
|
|
{
|
|
|
|
// XXXldb What if the root element is positioned, etc.? (We don't
|
|
|
|
// allow that yet, do we?)
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame *firstChild = aForFrame->GetFirstChild(nsnull);
|
2002-01-08 02:46:07 +03:00
|
|
|
if (firstChild) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleBackground* result = firstChild->GetStyleBackground();
|
2005-08-29 08:39:31 +04:00
|
|
|
nsIFrame* topFrame = aForFrame;
|
2002-02-15 17:48:12 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (firstChild->GetType() == nsGkAtoms::pageContentFrame) {
|
2005-08-29 08:39:31 +04:00
|
|
|
topFrame = firstChild->GetFirstChild(nsnull);
|
|
|
|
NS_ASSERTION(topFrame,
|
|
|
|
"nsPageContentFrame is missing a normal flow child");
|
2006-07-20 13:41:01 +04:00
|
|
|
if (!topFrame) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2005-08-29 08:39:31 +04:00
|
|
|
NS_ASSERTION(topFrame->GetContent(),
|
|
|
|
"nsPageContentFrame child without content");
|
|
|
|
result = topFrame->GetStyleBackground();
|
2002-02-15 17:48:12 +03:00
|
|
|
}
|
2002-01-08 02:46:07 +03:00
|
|
|
|
|
|
|
// Check if we need to do propagation from BODY rather than HTML.
|
2003-01-17 12:33:52 +03:00
|
|
|
if (result->IsTransparent()) {
|
2005-08-29 08:39:31 +04:00
|
|
|
nsIContent* content = topFrame->GetContent();
|
2002-01-08 02:46:07 +03:00
|
|
|
if (content) {
|
2004-10-11 20:29:42 +04:00
|
|
|
// Use |GetOwnerDoc| so it works during destruction.
|
|
|
|
nsIDocument* document = content->GetOwnerDoc();
|
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(document);
|
2002-01-08 02:46:07 +03:00
|
|
|
if (htmlDoc) {
|
2003-10-15 09:54:46 +04:00
|
|
|
if (!document->IsCaseSensitive()) { // HTML, not XHTML
|
2003-10-15 06:48:25 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLElement> body;
|
|
|
|
htmlDoc->GetBody(getter_AddRefs(body));
|
|
|
|
nsCOMPtr<nsIContent> bodyContent = do_QueryInterface(body);
|
|
|
|
// We need to null check the body node (bug 118829) since
|
|
|
|
// there are cases, thanks to the fix for bug 5569, where we
|
|
|
|
// will reflow a document with no body. In particular, if a
|
|
|
|
// SCRIPT element in the head blocks the parser and then has a
|
|
|
|
// SCRIPT that does "document.location.href = 'foo'", then
|
|
|
|
// nsParser::Terminate will call |DidBuildModel| methods
|
|
|
|
// through to the content sink, which will call |StartLayout|
|
|
|
|
// and thus |InitialReflow| on the pres shell. See bug 119351
|
|
|
|
// for the ugly details.
|
|
|
|
if (bodyContent) {
|
2007-03-31 01:11:41 +04:00
|
|
|
nsIFrame *bodyFrame = aForFrame->PresContext()->GetPresShell()->
|
2005-08-23 02:24:29 +04:00
|
|
|
GetPrimaryFrameFor(bodyContent);
|
|
|
|
if (bodyFrame)
|
2003-10-15 06:48:25 +04:00
|
|
|
result = bodyFrame->GetStyleBackground();
|
|
|
|
}
|
2002-01-09 05:36:49 +03:00
|
|
|
}
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aBackground = result;
|
|
|
|
} else {
|
|
|
|
// This should always give transparent, so we'll fill it in with the
|
2002-01-08 07:11:25 +03:00
|
|
|
// default color if needed. This seems to happen a bit while a page is
|
|
|
|
// being loaded.
|
2003-05-15 07:42:21 +04:00
|
|
|
*aBackground = aForFrame->GetStyleBackground();
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PRBool
|
2006-01-21 12:20:04 +03:00
|
|
|
FindElementBackground(nsIFrame* aForFrame,
|
2002-01-08 02:46:07 +03:00
|
|
|
const nsStyleBackground** aBackground)
|
|
|
|
{
|
2003-07-05 19:04:34 +04:00
|
|
|
nsIFrame *parentFrame = aForFrame->GetParent();
|
2002-01-14 18:00:30 +03:00
|
|
|
// XXXldb We shouldn't have to null-check |parentFrame| here.
|
2006-01-21 12:20:04 +03:00
|
|
|
if (parentFrame && IsCanvasFrame(parentFrame) == parentFrame) {
|
2002-01-08 02:46:07 +03:00
|
|
|
// Check that we're really the root (rather than in another child list).
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame *childFrame = parentFrame->GetFirstChild(nsnull);
|
2002-01-08 02:46:07 +03:00
|
|
|
if (childFrame == aForFrame)
|
|
|
|
return PR_FALSE; // Background was already drawn for the canvas.
|
|
|
|
}
|
|
|
|
|
2003-05-15 07:42:21 +04:00
|
|
|
*aBackground = aForFrame->GetStyleBackground();
|
2002-01-08 02:46:07 +03:00
|
|
|
|
2005-08-03 00:11:09 +04:00
|
|
|
// Return true unless the frame is for a BODY element whose background
|
|
|
|
// was propagated to the viewport.
|
|
|
|
|
|
|
|
if (aForFrame->GetStyleContext()->GetPseudoType())
|
|
|
|
return PR_TRUE; // A pseudo-element frame.
|
|
|
|
|
2003-07-05 19:04:34 +04:00
|
|
|
nsIContent* content = aForFrame->GetContent();
|
2006-05-05 10:52:21 +04:00
|
|
|
if (!content || !content->IsNodeOfType(nsINode::eHTML))
|
2002-03-06 02:17:32 +03:00
|
|
|
return PR_TRUE; // not frame for an HTML element
|
2003-10-15 06:48:25 +04:00
|
|
|
|
2002-03-06 02:17:32 +03:00
|
|
|
if (!parentFrame)
|
|
|
|
return PR_TRUE; // no parent to look at
|
2003-11-19 04:20:56 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (content->Tag() != nsGkAtoms::body)
|
2002-03-06 02:17:32 +03:00
|
|
|
return PR_TRUE; // not frame for <BODY> element
|
2002-01-08 02:46:07 +03:00
|
|
|
|
2002-02-26 01:18:26 +03:00
|
|
|
// We should only look at the <html> background if we're in an HTML document
|
2004-10-11 20:29:42 +04:00
|
|
|
nsIDocument* document = content->GetOwnerDoc();
|
2004-10-19 04:35:46 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(document);
|
2002-02-26 01:18:26 +03:00
|
|
|
if (!htmlDoc)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2003-10-15 09:54:46 +04:00
|
|
|
if (document->IsCaseSensitive()) // XHTML, not HTML
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2005-11-04 02:06:54 +03:00
|
|
|
nsCOMPtr<nsIDOMHTMLElement> body;
|
|
|
|
htmlDoc->GetBody(getter_AddRefs(body));
|
|
|
|
nsCOMPtr<nsIContent> bodyContent = do_QueryInterface(body);
|
|
|
|
if (bodyContent != content)
|
|
|
|
return PR_TRUE; // this wasn't the background that was propagated
|
|
|
|
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleBackground* htmlBG = parentFrame->GetStyleBackground();
|
2003-01-17 12:33:52 +03:00
|
|
|
return !htmlBG->IsTransparent();
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2004-08-01 03:15:21 +04:00
|
|
|
nsCSSRendering::FindBackground(nsPresContext* aPresContext,
|
2002-01-08 02:46:07 +03:00
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsStyleBackground** aBackground,
|
|
|
|
PRBool* aIsCanvas)
|
|
|
|
{
|
2006-01-21 12:20:04 +03:00
|
|
|
nsIFrame* canvasFrame = IsCanvasFrame(aForFrame);
|
2003-04-06 06:49:40 +04:00
|
|
|
*aIsCanvas = canvasFrame != nsnull;
|
|
|
|
return canvasFrame
|
2006-01-21 12:20:04 +03:00
|
|
|
? FindCanvasBackground(canvasFrame, aBackground)
|
|
|
|
: FindElementBackground(aForFrame, aBackground);
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
void
|
|
|
|
nsCSSRendering::DidPaint()
|
|
|
|
{
|
2007-03-14 22:48:51 +03:00
|
|
|
gInlineBGData->Reset();
|
2003-01-17 12:33:52 +03:00
|
|
|
}
|
|
|
|
|
1998-09-26 21:16:56 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsCSSRendering::PaintBackground(nsPresContext* aPresContext,
|
1998-09-26 21:16:56 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
1999-01-15 21:25:58 +03:00
|
|
|
const nsRect& aBorderArea,
|
2001-02-07 12:57:26 +03:00
|
|
|
const nsStyleBorder& aBorder,
|
2002-10-08 14:24:53 +04:00
|
|
|
const nsStylePadding& aPadding,
|
2004-03-09 09:48:35 +03:00
|
|
|
PRBool aUsePrintSettings,
|
|
|
|
nsRect* aBGClipRect)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2002-01-08 02:46:07 +03:00
|
|
|
NS_PRECONDITION(aForFrame,
|
|
|
|
"Frame is expected to be provided to PaintBackground");
|
|
|
|
|
|
|
|
PRBool isCanvas;
|
|
|
|
const nsStyleBackground *color;
|
2002-02-15 17:48:12 +03:00
|
|
|
|
2002-02-20 05:14:18 +03:00
|
|
|
if (!FindBackground(aPresContext, aForFrame, &color, &isCanvas)) {
|
|
|
|
// we don't want to bail out of moz-appearance is set on a root
|
|
|
|
// node. If it has a parent content node, bail because it's not
|
|
|
|
// a root, other wise keep going in order to let the theme stuff
|
|
|
|
// draw the background. The canvas really should be drawing the
|
|
|
|
// bg, but there's no way to hook that up via css.
|
2003-07-29 01:25:13 +04:00
|
|
|
if (!aForFrame->GetStyleDisplay()->mAppearance) {
|
|
|
|
return;
|
2002-02-20 05:14:18 +03:00
|
|
|
}
|
2003-07-29 01:25:13 +04:00
|
|
|
|
|
|
|
nsIContent* content = aForFrame->GetContent();
|
|
|
|
if (!content || content->GetParent()) {
|
2002-02-20 05:14:18 +03:00
|
|
|
return;
|
2003-07-29 01:25:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
color = aForFrame->GetStyleBackground();
|
2002-02-20 05:14:18 +03:00
|
|
|
}
|
2002-01-08 02:46:07 +03:00
|
|
|
if (!isCanvas) {
|
|
|
|
PaintBackgroundWithSC(aPresContext, aRenderingContext, aForFrame,
|
2002-10-08 14:24:53 +04:00
|
|
|
aDirtyRect, aBorderArea, *color, aBorder,
|
2004-03-09 09:48:35 +03:00
|
|
|
aPadding, aUsePrintSettings, aBGClipRect);
|
2002-01-08 02:46:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleBackground canvasColor(*color);
|
|
|
|
|
2003-07-05 19:04:34 +04:00
|
|
|
nsIViewManager* vm = aPresContext->GetViewManager();
|
2002-02-20 00:33:26 +03:00
|
|
|
|
|
|
|
if (canvasColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) {
|
2004-05-17 20:29:13 +04:00
|
|
|
nsIView* rootView;
|
|
|
|
vm->GetRootView(rootView);
|
2006-11-23 04:12:52 +03:00
|
|
|
if (!rootView->GetParent()) {
|
|
|
|
PRBool widgetIsTranslucent = PR_FALSE;
|
2003-04-06 06:49:40 +04:00
|
|
|
|
2006-11-23 04:12:52 +03:00
|
|
|
if (rootView->HasWidget()) {
|
|
|
|
rootView->GetWidget()->GetWindowTranslucency(widgetIsTranslucent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!widgetIsTranslucent) {
|
|
|
|
// Ensure that we always paint a color for the root (in case there's
|
|
|
|
// no background at all or a partly transparent image).
|
|
|
|
canvasColor.mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
|
|
|
|
canvasColor.mBackgroundColor = aPresContext->DefaultBackgroundColor();
|
|
|
|
}
|
2002-02-20 00:33:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-08 02:46:07 +03:00
|
|
|
vm->SetDefaultBackgroundColor(canvasColor.mBackgroundColor);
|
|
|
|
|
|
|
|
PaintBackgroundWithSC(aPresContext, aRenderingContext, aForFrame,
|
|
|
|
aDirtyRect, aBorderArea, canvasColor,
|
2004-03-09 09:48:35 +03:00
|
|
|
aBorder, aPadding, aUsePrintSettings, aBGClipRect);
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
|
2006-02-07 09:05:00 +03:00
|
|
|
inline nscoord IntDivFloor(nscoord aDividend, nscoord aDivisor)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aDivisor > 0,
|
|
|
|
"this function only works for positive divisors");
|
|
|
|
// ANSI C, ISO 9899:1999 section 6.5.5 defines integer division as
|
|
|
|
// truncation of the result towards zero. Earlier C standards, as
|
|
|
|
// well as the C++ standards (1998 and 2003) do not, but we depend
|
|
|
|
// on it elsewhere.
|
|
|
|
return (aDividend < 0 ? (aDividend - aDivisor + 1) : aDividend) / aDivisor;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nscoord IntDivCeil(nscoord aDividend, nscoord aDivisor)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aDivisor > 0,
|
|
|
|
"this function only works for positive divisors");
|
|
|
|
// ANSI C, ISO 9899:1999 section 6.5.5 defines integer division as
|
|
|
|
// truncation of the result towards zero. Earlier C standards, as
|
|
|
|
// well as the C++ standards (1998 and 2003) do not, but we depend
|
|
|
|
// on it elsewhere.
|
|
|
|
return (aDividend > 0 ? (aDividend + aDivisor - 1) : aDividend) / aDivisor;
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
/**
|
|
|
|
* Return the largest 'v' such that v = aTileOffset + N*aTileSize, for some
|
|
|
|
* integer N, and v <= aDirtyStart.
|
|
|
|
*/
|
|
|
|
static nscoord
|
|
|
|
FindTileStart(nscoord aDirtyStart, nscoord aTileOffset, nscoord aTileSize)
|
|
|
|
{
|
|
|
|
// Find largest integer N such that aTileOffset + N*aTileSize <= aDirtyStart
|
2006-02-07 09:05:00 +03:00
|
|
|
return aTileOffset +
|
|
|
|
IntDivFloor(aDirtyStart - aTileOffset, aTileSize) * aTileSize;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the smallest 'v' such that v = aTileOffset + N*aTileSize, for some
|
|
|
|
* integer N, and v >= aDirtyEnd.
|
|
|
|
*/
|
|
|
|
static nscoord
|
|
|
|
FindTileEnd(nscoord aDirtyEnd, nscoord aTileOffset, nscoord aTileSize)
|
|
|
|
{
|
|
|
|
// Find smallest integer N such that aTileOffset + N*aTileSize >= aDirtyEnd
|
2006-02-07 09:05:00 +03:00
|
|
|
return aTileOffset +
|
|
|
|
IntDivCeil(aDirtyEnd - aTileOffset, aTileSize) * aTileSize;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2002-01-08 02:46:07 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsCSSRendering::PaintBackgroundWithSC(nsPresContext* aPresContext,
|
2002-01-08 02:46:07 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
const nsStyleBackground& aColor,
|
|
|
|
const nsStyleBorder& aBorder,
|
2002-10-08 14:24:53 +04:00
|
|
|
const nsStylePadding& aPadding,
|
2004-03-09 09:48:35 +03:00
|
|
|
PRBool aUsePrintSettings,
|
|
|
|
nsRect* aBGClipRect)
|
2002-01-08 02:46:07 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aForFrame,
|
|
|
|
"Frame is expected to be provided to PaintBackground");
|
2000-05-11 03:24:08 +04:00
|
|
|
|
2003-02-23 05:49:22 +03:00
|
|
|
PRBool canDrawBackgroundImage = PR_TRUE;
|
|
|
|
PRBool canDrawBackgroundColor = PR_TRUE;
|
|
|
|
|
|
|
|
if (aUsePrintSettings) {
|
2004-02-20 20:49:01 +03:00
|
|
|
canDrawBackgroundImage = aPresContext->GetBackgroundImageDraw();
|
|
|
|
canDrawBackgroundColor = aPresContext->GetBackgroundColorDraw();
|
2001-11-27 17:50:35 +03:00
|
|
|
}
|
2003-02-23 05:49:22 +03:00
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
// Check to see if we have an appearance defined. If so, we let the theme
|
2002-02-21 00:51:25 +03:00
|
|
|
// renderer draw the background and bail out.
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleDisplay* displayData = aForFrame->GetStyleDisplay();
|
2001-12-18 01:51:39 +03:00
|
|
|
if (displayData->mAppearance) {
|
2004-07-29 23:41:39 +04:00
|
|
|
nsITheme *theme = aPresContext->GetTheme();
|
2002-09-21 05:03:38 +04:00
|
|
|
if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame, displayData->mAppearance)) {
|
2006-01-26 05:29:17 +03:00
|
|
|
nsPoint offset = aBorderArea.TopLeft();
|
|
|
|
nsIRenderingContext::AutoPushTranslation
|
|
|
|
translate(&aRenderingContext, offset.x, offset.y);
|
|
|
|
nsRect dirty;
|
|
|
|
nsRect border = aBorderArea - offset;
|
|
|
|
dirty.IntersectRect(aDirtyRect - offset, border);
|
2001-12-18 01:51:39 +03:00
|
|
|
theme->DrawWidgetBackground(&aRenderingContext, aForFrame,
|
2006-01-26 05:29:17 +03:00
|
|
|
displayData->mAppearance, border, dirty);
|
2001-12-18 01:51:39 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-09 09:48:35 +03:00
|
|
|
nsRect bgClipArea;
|
|
|
|
if (aBGClipRect) {
|
|
|
|
bgClipArea = *aBGClipRect;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// The background is rendered over the 'background-clip' area.
|
|
|
|
bgClipArea = aBorderArea;
|
|
|
|
if (aColor.mBackgroundClip != NS_STYLE_BG_CLIP_BORDER) {
|
|
|
|
NS_ASSERTION(aColor.mBackgroundClip == NS_STYLE_BG_CLIP_PADDING,
|
|
|
|
"unknown background-clip value");
|
2007-01-31 08:21:05 +03:00
|
|
|
nsMargin border = aForFrame->GetUsedBorder();
|
|
|
|
aForFrame->ApplySkipSides(border);
|
|
|
|
bgClipArea.Deflate(border);
|
2004-03-09 09:48:35 +03:00
|
|
|
}
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The actual dirty rect is the intersection of the 'background-clip'
|
|
|
|
// area and the dirty rect we were given
|
|
|
|
nsRect dirtyRect;
|
|
|
|
if (!dirtyRect.IntersectRect(bgClipArea, aDirtyRect)) {
|
|
|
|
// Nothing to paint
|
|
|
|
return;
|
|
|
|
}
|
2002-02-21 00:51:25 +03:00
|
|
|
|
2002-02-15 17:48:12 +03:00
|
|
|
// if there is no background image or background images are turned off, try a color.
|
2003-10-02 02:53:56 +04:00
|
|
|
if (!aColor.mBackgroundImage || !canDrawBackgroundImage) {
|
2002-10-08 14:24:53 +04:00
|
|
|
PaintBackgroundColor(aPresContext, aRenderingContext, aForFrame, bgClipArea,
|
2003-02-23 05:49:22 +03:00
|
|
|
aColor, aBorder, aPadding, canDrawBackgroundColor);
|
2002-10-08 14:24:53 +04:00
|
|
|
return;
|
|
|
|
}
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// We have a background image
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Lookup the image
|
2004-07-29 23:41:39 +04:00
|
|
|
imgIRequest *req = aPresContext->LoadImage(aColor.mBackgroundImage,
|
|
|
|
aForFrame);
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
PRUint32 status = imgIRequest::STATUS_ERROR;
|
|
|
|
if (req)
|
|
|
|
req->GetImageStatus(&status);
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2004-07-29 23:41:39 +04:00
|
|
|
if (!req || !(status & imgIRequest::STATUS_FRAME_COMPLETE) || !(status & imgIRequest::STATUS_SIZE_AVAILABLE)) {
|
2002-10-08 14:24:53 +04:00
|
|
|
PaintBackgroundColor(aPresContext, aRenderingContext, aForFrame, bgClipArea,
|
2003-02-23 05:49:22 +03:00
|
|
|
aColor, aBorder, aPadding, canDrawBackgroundColor);
|
2002-10-08 14:24:53 +04:00
|
|
|
return;
|
|
|
|
}
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
req->GetImage(getter_AddRefs(image));
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
nsSize imageSize;
|
|
|
|
image->GetWidth(&imageSize.width);
|
|
|
|
image->GetHeight(&imageSize.height);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2007-02-07 10:46:44 +03:00
|
|
|
imageSize.width = nsPresContext::CSSPixelsToAppUnits(imageSize.width);
|
|
|
|
imageSize.height = nsPresContext::CSSPixelsToAppUnits(imageSize.height);
|
1999-01-15 21:25:58 +03:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
req = nsnull;
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
nsRect bgOriginArea;
|
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom* frameType = aForFrame->GetType();
|
2006-12-26 20:47:52 +03:00
|
|
|
if (frameType == nsGkAtoms::inlineFrame ||
|
|
|
|
frameType == nsGkAtoms::positionedInlineFrame) {
|
2003-01-17 12:33:52 +03:00
|
|
|
switch (aColor.mBackgroundInlinePolicy) {
|
|
|
|
case NS_STYLE_BG_INLINE_POLICY_EACH_BOX:
|
|
|
|
bgOriginArea = aBorderArea;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_INLINE_POLICY_BOUNDING_BOX:
|
2007-03-14 22:48:51 +03:00
|
|
|
bgOriginArea = gInlineBGData->GetBoundingRect(aForFrame) +
|
2006-02-06 00:58:46 +03:00
|
|
|
aBorderArea.TopLeft();
|
2003-01-17 12:33:52 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unknown background-inline-policy value! "
|
|
|
|
"Please, teach me what to do.");
|
|
|
|
case NS_STYLE_BG_INLINE_POLICY_CONTINUOUS:
|
2007-03-14 22:48:51 +03:00
|
|
|
bgOriginArea = gInlineBGData->GetContinuousRect(aForFrame) +
|
2006-02-06 00:58:46 +03:00
|
|
|
aBorderArea.TopLeft();
|
2003-01-17 12:33:52 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bgOriginArea = aBorderArea;
|
|
|
|
}
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Background images are tiled over the 'background-clip' area
|
|
|
|
// but the origin of the tiling is based on the 'background-origin' area
|
|
|
|
if (aColor.mBackgroundOrigin != NS_STYLE_BG_ORIGIN_BORDER) {
|
2007-01-31 08:21:05 +03:00
|
|
|
nsMargin border = aForFrame->GetUsedBorder();
|
|
|
|
aForFrame->ApplySkipSides(border);
|
|
|
|
bgOriginArea.Deflate(border);
|
2002-10-08 14:24:53 +04:00
|
|
|
if (aColor.mBackgroundOrigin != NS_STYLE_BG_ORIGIN_PADDING) {
|
2006-12-14 02:04:57 +03:00
|
|
|
nsMargin padding = aForFrame->GetUsedPadding();
|
2007-01-31 08:21:05 +03:00
|
|
|
aForFrame->ApplySkipSides(padding);
|
2002-10-08 14:24:53 +04:00
|
|
|
bgOriginArea.Deflate(padding);
|
|
|
|
NS_ASSERTION(aColor.mBackgroundOrigin == NS_STYLE_BG_ORIGIN_CONTENT,
|
|
|
|
"unknown background-origin value");
|
1999-08-27 18:37:47 +04:00
|
|
|
}
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
1999-01-15 21:25:58 +03:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Based on the repeat setting, compute how many tiles we should
|
|
|
|
// lay down for each axis. The value computed is the maximum based
|
|
|
|
// on the dirty rect before accounting for the background-position.
|
|
|
|
nscoord tileWidth = imageSize.width;
|
|
|
|
nscoord tileHeight = imageSize.height;
|
2003-03-06 02:34:48 +03:00
|
|
|
PRBool needBackgroundColor = !(aColor.mBackgroundFlags &
|
|
|
|
NS_STYLE_BG_COLOR_TRANSPARENT);
|
2002-10-08 14:24:53 +04:00
|
|
|
PRIntn repeat = aColor.mBackgroundRepeat;
|
|
|
|
nscoord xDistance, yDistance;
|
|
|
|
|
|
|
|
switch (repeat) {
|
1998-04-14 00:24:54 +04:00
|
|
|
case NS_STYLE_BG_REPEAT_X:
|
1999-01-15 21:25:58 +03:00
|
|
|
xDistance = dirtyRect.width;
|
1998-12-12 06:06:02 +03:00
|
|
|
yDistance = tileHeight;
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_REPEAT_Y:
|
1998-12-12 06:06:02 +03:00
|
|
|
xDistance = tileWidth;
|
1999-01-15 21:25:58 +03:00
|
|
|
yDistance = dirtyRect.height;
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_REPEAT_XY:
|
1999-01-15 21:25:58 +03:00
|
|
|
xDistance = dirtyRect.width;
|
|
|
|
yDistance = dirtyRect.height;
|
2003-03-06 02:34:48 +03:00
|
|
|
if (needBackgroundColor) {
|
|
|
|
// If the image is completely opaque, we do not need to paint the
|
|
|
|
// background color
|
|
|
|
nsCOMPtr<gfxIImageFrame> gfxImgFrame;
|
|
|
|
image->GetCurrentFrame(getter_AddRefs(gfxImgFrame));
|
|
|
|
if (gfxImgFrame) {
|
2005-03-08 06:44:28 +03:00
|
|
|
gfxImgFrame->GetNeedsBackground(&needBackgroundColor);
|
2004-01-17 02:28:51 +03:00
|
|
|
|
|
|
|
/* check for tiling of a image where frame smaller than container */
|
|
|
|
nsSize iSize;
|
|
|
|
image->GetWidth(&iSize.width);
|
|
|
|
image->GetHeight(&iSize.height);
|
|
|
|
nsRect iframeRect;
|
|
|
|
gfxImgFrame->GetRect(iframeRect);
|
|
|
|
if (iSize.width != iframeRect.width ||
|
|
|
|
iSize.height != iframeRect.height) {
|
|
|
|
needBackgroundColor = PR_TRUE;
|
|
|
|
}
|
2003-03-06 02:34:48 +03:00
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
2002-10-08 14:24:53 +04:00
|
|
|
case NS_STYLE_BG_REPEAT_OFF:
|
|
|
|
default:
|
|
|
|
NS_ASSERTION(repeat == NS_STYLE_BG_REPEAT_OFF, "unknown background-repeat value");
|
|
|
|
xDistance = tileWidth;
|
|
|
|
yDistance = tileHeight;
|
|
|
|
break;
|
|
|
|
}
|
1999-01-15 21:25:58 +03:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// The background color is rendered over the 'background-clip' area
|
|
|
|
if (needBackgroundColor) {
|
|
|
|
PaintBackgroundColor(aPresContext, aRenderingContext, aForFrame, bgClipArea,
|
2003-02-23 05:49:22 +03:00
|
|
|
aColor, aBorder, aPadding, canDrawBackgroundColor);
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
if ((tileWidth == 0) || (tileHeight == 0) || dirtyRect.IsEmpty()) {
|
|
|
|
// Nothing left to paint
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the anchor point.
|
|
|
|
//
|
|
|
|
// When tiling, the anchor coordinate values will be negative offsets
|
2003-01-17 12:33:52 +03:00
|
|
|
// from the background-origin area.
|
2002-10-08 14:24:53 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// relative to the origin of aForFrame
|
2002-10-08 14:24:53 +04:00
|
|
|
nsPoint anchor;
|
|
|
|
if (NS_STYLE_BG_ATTACHMENT_FIXED == aColor.mBackgroundAttachment) {
|
|
|
|
// If it's a fixed background attachment, then the image is placed
|
2004-02-27 08:40:16 +03:00
|
|
|
// relative to the viewport
|
2002-10-08 14:24:53 +04:00
|
|
|
nsIView* viewportView = nsnull;
|
|
|
|
nsRect viewportArea;
|
|
|
|
|
2006-09-20 02:05:33 +04:00
|
|
|
// Remember that we've drawn position-varying content in this prescontext
|
|
|
|
aPresContext->SetRenderedPositionVaryingContent();
|
|
|
|
|
2004-09-02 07:08:51 +04:00
|
|
|
nsIFrame* rootFrame =
|
|
|
|
aPresContext->PresShell()->FrameManager()->GetRootFrame();
|
2004-02-27 08:40:16 +03:00
|
|
|
NS_ASSERTION(rootFrame, "no root frame");
|
2002-12-24 01:08:04 +03:00
|
|
|
|
2004-03-03 21:24:20 +03:00
|
|
|
if (aPresContext->IsPaginated()) {
|
2004-02-27 08:40:16 +03:00
|
|
|
nsIFrame* page = nsLayoutUtils::GetPageFrame(aForFrame);
|
|
|
|
NS_ASSERTION(page, "no page");
|
|
|
|
rootFrame = page;
|
2002-12-24 01:08:04 +03:00
|
|
|
}
|
1999-04-25 06:43:50 +04:00
|
|
|
|
2004-02-27 08:40:16 +03:00
|
|
|
viewportView = rootFrame->GetView();
|
|
|
|
NS_ASSERTION(viewportView, "no viewport view");
|
|
|
|
viewportArea = viewportView->GetBounds();
|
|
|
|
viewportArea.x = 0;
|
|
|
|
viewportArea.y = 0;
|
2002-12-24 01:08:04 +03:00
|
|
|
|
2004-02-27 08:40:16 +03:00
|
|
|
nsIScrollableFrame* scrollableFrame =
|
|
|
|
GetRootScrollableFrame(aPresContext, rootFrame);
|
2002-12-24 01:08:04 +03:00
|
|
|
|
2002-12-27 10:32:17 +03:00
|
|
|
if (scrollableFrame) {
|
2004-01-09 22:21:20 +03:00
|
|
|
nsMargin scrollbars = scrollableFrame->GetActualScrollbarSizes();
|
|
|
|
viewportArea.Deflate(scrollbars);
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
2001-08-18 03:26:29 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// Get the anchor point, relative to rootFrame
|
2002-10-08 14:24:53 +04:00
|
|
|
ComputeBackgroundAnchorPoint(aColor, viewportArea, viewportArea, tileWidth, tileHeight, anchor);
|
1999-04-25 06:43:50 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// Convert the anchor point from viewport coordinates (relative to aRootFrame) to
|
|
|
|
// relative to aForFrame
|
|
|
|
anchor -= aForFrame->GetOffsetTo(rootFrame);
|
2002-10-08 14:24:53 +04:00
|
|
|
} else {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (frameType == nsGkAtoms::canvasFrame) {
|
2002-10-08 14:24:53 +04:00
|
|
|
// If the frame is the canvas, the image is placed relative to
|
|
|
|
// the root element's (first) frame (see bug 46446)
|
|
|
|
nsRect firstRootElementFrameArea;
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame* firstRootElementFrame = aForFrame->GetFirstChild(nsnull);
|
2002-10-08 14:24:53 +04:00
|
|
|
NS_ASSERTION(firstRootElementFrame, "A canvas with a background "
|
|
|
|
"image had no child frame, which is impossible according to CSS. "
|
|
|
|
"Make sure there isn't a background image specified on the "
|
|
|
|
"|:viewport| pseudo-element in |html.css|.");
|
|
|
|
|
|
|
|
// temporary null check -- see bug 97226
|
|
|
|
if (firstRootElementFrame) {
|
2003-07-05 19:04:34 +04:00
|
|
|
firstRootElementFrameArea = firstRootElementFrame->GetRect();
|
2002-10-08 14:24:53 +04:00
|
|
|
|
|
|
|
// Take the border out of the frame's rect
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleBorder* borderStyle = firstRootElementFrame->GetStyleBorder();
|
2005-04-29 19:44:38 +04:00
|
|
|
firstRootElementFrameArea.Deflate(borderStyle->GetBorder());
|
2002-10-08 14:24:53 +04:00
|
|
|
|
|
|
|
// Get the anchor point
|
2006-01-26 05:29:17 +03:00
|
|
|
ComputeBackgroundAnchorPoint(aColor, firstRootElementFrameArea +
|
|
|
|
aBorderArea.TopLeft(), bgClipArea, tileWidth, tileHeight, anchor);
|
2001-08-18 03:26:29 +04:00
|
|
|
} else {
|
2002-10-08 14:24:53 +04:00
|
|
|
ComputeBackgroundAnchorPoint(aColor, bgOriginArea, bgClipArea, tileWidth, tileHeight, anchor);
|
2001-08-18 03:26:29 +04:00
|
|
|
}
|
2002-10-08 14:24:53 +04:00
|
|
|
} else {
|
|
|
|
// Otherwise, it is the normal case, and the background is
|
|
|
|
// simply placed relative to the frame's background-clip area
|
|
|
|
ComputeBackgroundAnchorPoint(aColor, bgOriginArea, bgClipArea, tileWidth, tileHeight, anchor);
|
1999-04-25 06:43:50 +04:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// For scrolling attachment, the anchor is within the 'background-clip'
|
|
|
|
anchor.x += bgClipArea.x - aBorderArea.x;
|
|
|
|
anchor.y += bgClipArea.y - aBorderArea.y;
|
|
|
|
}
|
2001-08-18 03:26:29 +04:00
|
|
|
|
2001-12-06 03:09:21 +03:00
|
|
|
#if (!defined(XP_UNIX) && !defined(XP_BEOS)) || defined(XP_MACOSX)
|
2002-10-08 14:24:53 +04:00
|
|
|
// Setup clipping so that rendering doesn't leak out of the computed
|
|
|
|
// dirty rect
|
|
|
|
aRenderingContext.PushState();
|
2004-04-23 20:13:26 +04:00
|
|
|
aRenderingContext.SetClipRect(dirtyRect, nsClipCombine_kIntersect);
|
2000-05-12 10:29:37 +04:00
|
|
|
#endif
|
1998-12-12 06:06:02 +03:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Compute the x and y starting points and limits for tiling
|
|
|
|
|
|
|
|
/* An Overview Of The Following Logic
|
2001-02-15 06:25:22 +03:00
|
|
|
|
|
|
|
A........ . . . . . . . . . . . . . .
|
|
|
|
: +---:-------.-------.-------.---- /|\
|
|
|
|
: | : . . . | nh
|
|
|
|
:.......: . . . x . . . . . . . . . . \|/
|
|
|
|
. | . . . .
|
|
|
|
. | . . ########### .
|
|
|
|
. . . . . . . . . .#. . . . .#. . . .
|
|
|
|
. | . . ########### . /|\
|
|
|
|
. | . . . . | h
|
|
|
|
. . | . . . . . . . . . . . . . z . . \|/
|
|
|
|
. | . . . .
|
|
|
|
|<-----nw------>| |<--w-->|
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
---- = the background clip area edge. The painting is done within
|
|
|
|
to this area. If the background is positioned relative to the
|
|
|
|
viewport ('fixed') then this is the viewport edge.
|
2001-02-15 06:25:22 +03:00
|
|
|
|
|
|
|
.... = the primary tile.
|
|
|
|
|
|
|
|
. . = the other tiles.
|
|
|
|
|
|
|
|
#### = the dirtyRect. This is the minimum region we want to cover.
|
|
|
|
|
|
|
|
A = The anchor point. This is the point at which the tile should
|
|
|
|
start. Always negative or zero.
|
|
|
|
|
|
|
|
x = x0 and y0 in the code. The point at which tiling must start
|
2005-11-21 01:05:24 +03:00
|
|
|
so that the fewest tiles are laid out while completely
|
2001-02-15 06:25:22 +03:00
|
|
|
covering the dirtyRect area.
|
|
|
|
|
|
|
|
z = x1 and y1 in the code. The point at which tiling must end so
|
2005-11-21 01:05:24 +03:00
|
|
|
that the fewest tiles are laid out while completely covering
|
2001-02-15 06:25:22 +03:00
|
|
|
the dirtyRect area.
|
|
|
|
|
|
|
|
w = the width of the tile (tileWidth).
|
|
|
|
|
|
|
|
h = the height of the tile (tileHeight).
|
|
|
|
|
|
|
|
n = the number of whole tiles that fit between 'A' and 'x'.
|
|
|
|
(the vertical n and the horizontal n are different)
|
|
|
|
|
|
|
|
|
|
|
|
Therefore,
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
x0 = bgClipArea.x + anchor.x + n * tileWidth;
|
2001-02-15 06:25:22 +03:00
|
|
|
|
|
|
|
...where n is an integer greater or equal to 0 fitting:
|
|
|
|
|
|
|
|
n * tileWidth <=
|
2002-10-08 14:24:53 +04:00
|
|
|
dirtyRect.x - (bgClipArea.x + anchor.x) <=
|
2001-02-15 06:25:22 +03:00
|
|
|
(n+1) * tileWidth
|
|
|
|
|
|
|
|
...i.e.,
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
n <= (dirtyRect.x - (bgClipArea.x + anchor.x)) / tileWidth < n + 1
|
2001-02-15 06:25:22 +03:00
|
|
|
|
|
|
|
...which, treating the division as an integer divide rounding down, gives:
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
n = (dirtyRect.x - (bgClipArea.x + anchor.x)) / tileWidth
|
2001-02-15 06:25:22 +03:00
|
|
|
|
|
|
|
Substituting into the original expression for x0:
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
x0 = bgClipArea.x + anchor.x +
|
|
|
|
((dirtyRect.x - (bgClipArea.x + anchor.x)) / tileWidth) *
|
2001-02-15 06:25:22 +03:00
|
|
|
tileWidth;
|
|
|
|
|
|
|
|
From this x1 is determined,
|
|
|
|
|
|
|
|
x1 = x0 + m * tileWidth;
|
|
|
|
|
|
|
|
...where m is an integer greater than 0 fitting:
|
|
|
|
|
|
|
|
(m - 1) * tileWidth <
|
|
|
|
dirtyRect.x + dirtyRect.width - x0 <=
|
|
|
|
m * tileWidth
|
|
|
|
|
|
|
|
...i.e.,
|
|
|
|
|
|
|
|
m - 1 < (dirtyRect.x + dirtyRect.width - x0) / tileWidth <= m
|
|
|
|
|
|
|
|
...which, treating the division as an integer divide, and making it
|
|
|
|
round up, gives:
|
|
|
|
|
|
|
|
m = (dirtyRect.x + dirtyRect.width - x0 + tileWidth - 1) / tileWidth
|
|
|
|
|
|
|
|
Substituting into the original expression for x1:
|
|
|
|
|
|
|
|
x1 = x0 + ((dirtyRect.x + dirtyRect.width - x0 + tileWidth - 1) /
|
|
|
|
tileWidth) * tileWidth
|
|
|
|
|
|
|
|
The vertical case is analogous. If the background is fixed, then
|
2002-10-08 14:24:53 +04:00
|
|
|
bgClipArea.x and bgClipArea.y are set to zero when finding the parent
|
2001-02-15 06:25:22 +03:00
|
|
|
viewport, above.
|
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
*/
|
2001-02-15 06:25:22 +03:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// relative to aBorderArea.TopLeft()
|
|
|
|
nsRect tileRect(anchor, nsSize(tileWidth, tileHeight));
|
2002-10-08 14:24:53 +04:00
|
|
|
if (repeat & NS_STYLE_BG_REPEAT_X) {
|
|
|
|
// When tiling in the x direction, adjust the starting position of the
|
|
|
|
// tile to account for dirtyRect.x. When tiling in x, the anchor.x value
|
|
|
|
// will be a negative value used to adjust the starting coordinate.
|
2006-01-26 05:29:17 +03:00
|
|
|
nscoord x0 = FindTileStart(dirtyRect.x - aBorderArea.x, anchor.x, tileWidth);
|
|
|
|
nscoord x1 = FindTileEnd(dirtyRect.XMost() - aBorderArea.x, anchor.x, tileWidth);
|
|
|
|
tileRect.x = x0;
|
|
|
|
tileRect.width = x1 - x0;
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
|
|
|
if (repeat & NS_STYLE_BG_REPEAT_Y) {
|
|
|
|
// When tiling in the y direction, adjust the starting position of the
|
|
|
|
// tile to account for dirtyRect.y. When tiling in y, the anchor.y value
|
|
|
|
// will be a negative value used to adjust the starting coordinate.
|
2006-01-26 05:29:17 +03:00
|
|
|
nscoord y0 = FindTileStart(dirtyRect.y - aBorderArea.y, anchor.y, tileHeight);
|
|
|
|
nscoord y1 = FindTileEnd(dirtyRect.YMost() - aBorderArea.y, anchor.y, tileHeight);
|
|
|
|
tileRect.y = y0;
|
|
|
|
tileRect.height = y1 - y0;
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
1998-07-31 03:31:42 +04:00
|
|
|
|
2006-11-30 00:58:13 +03:00
|
|
|
// Take the intersection again to paint only the required area.
|
2006-01-26 05:29:17 +03:00
|
|
|
nsRect absTileRect = tileRect + aBorderArea.TopLeft();
|
2007-02-07 10:46:44 +03:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
nsRect drawRect;
|
2006-01-26 05:29:17 +03:00
|
|
|
if (drawRect.IntersectRect(absTileRect, dirtyRect)) {
|
2006-11-30 00:58:13 +03:00
|
|
|
// Note that due to the way FindTileStart works we're guaranteed
|
|
|
|
// that drawRect overlaps the top-left-most tile when repeating.
|
|
|
|
NS_ASSERTION(drawRect.x >= absTileRect.x && drawRect.y >= absTileRect.y,
|
|
|
|
"Bogus intersection");
|
|
|
|
NS_ASSERTION(drawRect.x < absTileRect.x + tileWidth,
|
|
|
|
"Bogus x coord for draw rect");
|
|
|
|
NS_ASSERTION(drawRect.y < absTileRect.y + tileHeight,
|
|
|
|
"Bogus y coord for draw rect");
|
|
|
|
// Figure out whether we can get away with not tiling at all.
|
|
|
|
nsRect sourceRect = drawRect - absTileRect.TopLeft();
|
|
|
|
if (sourceRect.XMost() <= tileWidth && sourceRect.YMost() <= tileHeight) {
|
|
|
|
// The entire drawRect is contained inside a single tile; just
|
|
|
|
// draw the corresponding part of the image once.
|
2007-03-20 03:58:20 +03:00
|
|
|
nsLayoutUtils::DrawImage(&aRenderingContext, image, absTileRect, drawRect);
|
2006-11-30 00:58:13 +03:00
|
|
|
} else {
|
|
|
|
aRenderingContext.DrawTile(image, absTileRect.x, absTileRect.y, &drawRect);
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
1999-10-01 18:35:20 +04:00
|
|
|
|
2001-12-06 03:09:21 +03:00
|
|
|
#if (!defined(XP_UNIX) && !defined(XP_BEOS)) || defined(XP_MACOSX)
|
2002-10-08 14:24:53 +04:00
|
|
|
// Restore clipping
|
2004-04-18 17:55:11 +04:00
|
|
|
aRenderingContext.PopState();
|
2000-05-12 10:29:37 +04:00
|
|
|
#endif
|
1999-04-21 18:23:49 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsCSSRendering::PaintBackgroundColor(nsPresContext* aPresContext,
|
2002-10-08 14:24:53 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aBgClipArea,
|
|
|
|
const nsStyleBackground& aColor,
|
|
|
|
const nsStyleBorder& aBorder,
|
|
|
|
const nsStylePadding& aPadding,
|
2003-02-23 05:49:22 +03:00
|
|
|
PRBool aCanPaintNonWhite)
|
2002-10-08 14:24:53 +04:00
|
|
|
{
|
2006-04-21 05:57:47 +04:00
|
|
|
// If we're only allowed to paint white, then don't bail out on transparent
|
|
|
|
// color if we're not completely transparent. See the corresponding check
|
|
|
|
// for whether we're allowed to paint background images in
|
|
|
|
// PaintBackgroundWithSC before the first call to PaintBackgroundColor.
|
|
|
|
if ((aColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) &&
|
|
|
|
(aCanPaintNonWhite || aColor.IsTransparent())) {
|
2002-10-08 14:24:53 +04:00
|
|
|
// nothing to paint
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleCoord bordStyleRadius[4];
|
|
|
|
PRInt16 borderRadii[4];
|
|
|
|
nsRect bgClipArea(aBgClipArea);
|
|
|
|
|
|
|
|
// get the radius for our border
|
|
|
|
aBorder.mBorderRadius.GetTop(bordStyleRadius[NS_SIDE_TOP]); // topleft
|
|
|
|
aBorder.mBorderRadius.GetRight(bordStyleRadius[NS_SIDE_RIGHT]); // topright
|
|
|
|
aBorder.mBorderRadius.GetBottom(bordStyleRadius[NS_SIDE_BOTTOM]); // bottomright
|
|
|
|
aBorder.mBorderRadius.GetLeft(bordStyleRadius[NS_SIDE_LEFT]); // bottomleft
|
|
|
|
|
|
|
|
PRUint8 side = 0;
|
|
|
|
for (; side < 4; ++side) {
|
|
|
|
borderRadii[side] = 0;
|
|
|
|
switch (bordStyleRadius[side].GetUnit()) {
|
|
|
|
case eStyleUnit_Percent:
|
2006-12-30 08:23:51 +03:00
|
|
|
borderRadii[side] = nscoord(bordStyleRadius[side].GetPercentValue() *
|
|
|
|
aForFrame->GetSize().width);
|
2002-10-08 14:24:53 +04:00
|
|
|
break;
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
borderRadii[side] = bordStyleRadius[side].GetCoordValue();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rounded version of the border
|
|
|
|
// XXXdwh Composite borders (with multiple colors per side) use their own border radius
|
|
|
|
// algorithm now, since the current one doesn't work right for small radii.
|
|
|
|
if (!aBorder.mBorderColors) {
|
|
|
|
for (side = 0; side < 4; ++side) {
|
|
|
|
if (borderRadii[side] > 0) {
|
|
|
|
PaintRoundedBackground(aPresContext, aRenderingContext, aForFrame,
|
2003-02-23 05:49:22 +03:00
|
|
|
bgClipArea, aColor, aBorder, borderRadii,
|
|
|
|
aCanPaintNonWhite);
|
2002-10-08 14:24:53 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aColor.mBackgroundClip == NS_STYLE_BG_CLIP_BORDER) {
|
|
|
|
// XXX users of -moz-border-*-colors expect a transparent border-color
|
|
|
|
// to show the parent's background-color instead of its background-color.
|
|
|
|
// This seems wrong, but we handle that here by explictly clipping the
|
|
|
|
// background to the padding area.
|
2007-01-31 08:21:05 +03:00
|
|
|
nsMargin border = aForFrame->GetUsedBorder();
|
|
|
|
aForFrame->ApplySkipSides(border);
|
|
|
|
bgClipArea.Deflate(border);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2006-04-21 05:57:47 +04:00
|
|
|
nscolor color;
|
2003-02-23 05:49:22 +03:00
|
|
|
if (!aCanPaintNonWhite) {
|
|
|
|
color = NS_RGB(255, 255, 255);
|
2006-04-21 05:57:47 +04:00
|
|
|
} else {
|
|
|
|
color = aColor.mBackgroundColor;
|
2003-02-23 05:49:22 +03:00
|
|
|
}
|
2006-04-21 05:57:47 +04:00
|
|
|
|
2003-02-23 05:49:22 +03:00
|
|
|
aRenderingContext.SetColor(color);
|
2002-10-08 14:24:53 +04:00
|
|
|
aRenderingContext.FillRect(bgClipArea);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
* See documentation in nsCSSRendering.h
|
2003-07-30 12:13:07 +04:00
|
|
|
* @update 3/26/99 dwc
|
1999-04-19 09:27:55 +04:00
|
|
|
*/
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsCSSRendering::PaintRoundedBackground(nsPresContext* aPresContext,
|
2002-10-08 14:24:53 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aBgClipArea,
|
|
|
|
const nsStyleBackground& aColor,
|
|
|
|
const nsStyleBorder& aBorder,
|
2003-02-23 05:49:22 +03:00
|
|
|
PRInt16 aTheRadius[4],
|
|
|
|
PRBool aCanPaintNonWhite)
|
1999-04-19 09:27:55 +04:00
|
|
|
{
|
2002-10-08 14:24:53 +04:00
|
|
|
RoundedRect outerPath;
|
|
|
|
QBCurve cr1,cr2,cr3,cr4;
|
|
|
|
QBCurve UL,UR,LL,LR;
|
|
|
|
PRInt32 curIndex,c1Index;
|
|
|
|
nsFloatPoint thePath[MAXPATHSIZE];
|
|
|
|
static nsPoint polyPath[MAXPOLYPATHSIZE];
|
|
|
|
PRInt16 np;
|
1999-10-20 18:46:27 +04:00
|
|
|
|
|
|
|
// needed for our border thickness
|
2007-02-07 10:46:44 +03:00
|
|
|
nscoord appUnitsPerPixel = nsPresContext::AppUnitsPerCSSPixel();
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2003-02-23 05:49:22 +03:00
|
|
|
nscolor color = aColor.mBackgroundColor;
|
|
|
|
if (!aCanPaintNonWhite) {
|
|
|
|
color = NS_RGB(255, 255, 255);
|
|
|
|
}
|
|
|
|
aRenderingContext.SetColor(color);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Adjust for background-clip, if necessary
|
|
|
|
if (aColor.mBackgroundClip != NS_STYLE_BG_CLIP_BORDER) {
|
|
|
|
NS_ASSERTION(aColor.mBackgroundClip == NS_STYLE_BG_CLIP_PADDING, "unknown background-clip value");
|
|
|
|
|
|
|
|
// Get the radius to the outer edge of the padding.
|
|
|
|
// -moz-border-radius is the radius to the outer edge of the border.
|
2005-04-29 19:44:38 +04:00
|
|
|
NS_FOR_CSS_SIDES(side) {
|
|
|
|
aTheRadius[side] -= aBorder.GetBorderWidth(side);
|
|
|
|
aTheRadius[side] = PR_MAX(aTheRadius[side], 0);
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
// set the rounded rect up, and let'er rip
|
2007-02-07 10:46:44 +03:00
|
|
|
outerPath.Set(aBgClipArea.x, aBgClipArea.y, aBgClipArea.width,
|
|
|
|
aBgClipArea.height, aTheRadius, appUnitsPerPixel);
|
1999-04-19 09:27:55 +04:00
|
|
|
outerPath.GetRoundedBorders(UL,UR,LL,LR);
|
|
|
|
|
|
|
|
// BUILD THE ENTIRE OUTSIDE PATH
|
|
|
|
// TOP LINE ----------------------------------------------------------------
|
|
|
|
UL.MidPointDivide(&cr1,&cr2);
|
|
|
|
UR.MidPointDivide(&cr3,&cr4);
|
|
|
|
np=0;
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc1.x,cr2.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mCon.x, cr2.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc2.x, cr2.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mAnc1.x, cr3.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mCon.x, cr3.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mAnc2.x, cr3.mAnc2.y);
|
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
polyPath[0].x = NSToCoordRound(thePath[0].x);
|
|
|
|
polyPath[0].y = NSToCoordRound(thePath[0].y);
|
1999-04-19 09:27:55 +04:00
|
|
|
curIndex = 1;
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(thePath,polyPath,&curIndex,eOutside,c1Index);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
// RIGHT LINE ----------------------------------------------------------------
|
|
|
|
LR.MidPointDivide(&cr2,&cr3);
|
|
|
|
np=0;
|
|
|
|
thePath[np++].MoveTo(cr4.mAnc1.x,cr4.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr4.mCon.x, cr4.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr4.mAnc2.x, cr4.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc1.x, cr2.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mCon.x, cr2.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc2.x, cr2.mAnc2.y);
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(thePath,polyPath,&curIndex,eOutside,c1Index);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
// BOTTOM LINE ----------------------------------------------------------------
|
|
|
|
LL.MidPointDivide(&cr2,&cr4);
|
|
|
|
np=0;
|
|
|
|
thePath[np++].MoveTo(cr3.mAnc1.x,cr3.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mCon.x, cr3.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr3.mAnc2.x, cr3.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc1.x, cr2.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mCon.x, cr2.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr2.mAnc2.x, cr2.mAnc2.y);
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(thePath,polyPath,&curIndex,eOutside,c1Index);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
// LEFT LINE ----------------------------------------------------------------
|
|
|
|
np=0;
|
|
|
|
thePath[np++].MoveTo(cr4.mAnc1.x,cr4.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr4.mCon.x, cr4.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr4.mAnc2.x, cr4.mAnc2.y);
|
|
|
|
thePath[np++].MoveTo(cr1.mAnc1.x, cr1.mAnc1.y);
|
|
|
|
thePath[np++].MoveTo(cr1.mCon.x, cr1.mCon.y);
|
|
|
|
thePath[np++].MoveTo(cr1.mAnc2.x, cr1.mAnc2.y);
|
1999-04-21 18:23:49 +04:00
|
|
|
GetPath(thePath,polyPath,&curIndex,eOutside,c1Index);
|
|
|
|
|
|
|
|
aRenderingContext.FillPolygon(polyPath,curIndex);
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
1999-04-21 18:23:49 +04:00
|
|
|
* See documentation in nsCSSRendering.h
|
2003-07-30 12:13:07 +04:00
|
|
|
* @update 3/26/99 dwc
|
1999-04-19 09:27:55 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
RoundedRect::CalcInsetCurves(QBCurve &aULCurve,QBCurve &aURCurve,QBCurve &aLLCurve,QBCurve &aLRCurve,nsMargin &aBorder)
|
|
|
|
{
|
2000-05-11 07:59:43 +04:00
|
|
|
PRInt32 nLeft,nTop,nRight,nBottom;
|
|
|
|
PRInt32 tLeft,bLeft,tRight,bRight,lTop,rTop,lBottom,rBottom;
|
|
|
|
PRInt16 adjust=0;
|
1999-08-27 18:37:47 +04:00
|
|
|
|
|
|
|
if(mDoRound)
|
1999-12-23 23:48:07 +03:00
|
|
|
adjust = mRoundness[0]>>3;
|
|
|
|
|
|
|
|
nLeft = mLeft + aBorder.left;
|
|
|
|
tLeft = mLeft + mRoundness[0];
|
|
|
|
bLeft = mLeft + mRoundness[3];
|
|
|
|
|
|
|
|
if(tLeft < nLeft){
|
|
|
|
tLeft = nLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(bLeft < nLeft){
|
|
|
|
bLeft = nLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
nRight = mRight - aBorder.right;
|
|
|
|
tRight = mRight - mRoundness[1];
|
|
|
|
bRight = mRight - mRoundness[2];
|
|
|
|
|
|
|
|
if(tRight > nRight){
|
|
|
|
tRight = nRight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(bRight > nRight){
|
|
|
|
bRight = nRight;
|
|
|
|
}
|
|
|
|
|
|
|
|
nTop = mTop + aBorder.top;
|
|
|
|
lTop = mTop + mRoundness[0];
|
|
|
|
rTop = mTop + mRoundness[1];
|
|
|
|
|
|
|
|
if(lTop < nTop){
|
|
|
|
lTop = nTop;
|
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
|
1999-12-23 23:48:07 +03:00
|
|
|
if(rTop < nTop){
|
|
|
|
rTop = nTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
nBottom = mBottom - aBorder.bottom;
|
|
|
|
lBottom = mBottom - mRoundness[3];
|
|
|
|
rBottom = mBottom - mRoundness[2];
|
1999-04-19 09:27:55 +04:00
|
|
|
|
1999-12-23 23:48:07 +03:00
|
|
|
if(lBottom > nBottom){
|
|
|
|
lBottom = nBottom;
|
1999-04-21 18:23:49 +04:00
|
|
|
}
|
|
|
|
|
1999-12-23 23:48:07 +03:00
|
|
|
if(rBottom > nBottom){
|
|
|
|
rBottom = nBottom;
|
1999-04-21 18:23:49 +04:00
|
|
|
}
|
|
|
|
|
1999-12-23 23:48:07 +03:00
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
// set the passed in curves to the rounded borders of the rectangle
|
2000-05-11 07:59:43 +04:00
|
|
|
aULCurve.SetPoints( (float)nLeft,(float)lTop,
|
|
|
|
(float)nLeft+adjust,(float)nTop+adjust,
|
|
|
|
(float)tLeft,(float)nTop);
|
|
|
|
aURCurve.SetPoints( (float)tRight,(float)nTop,
|
|
|
|
(float)nRight-adjust,(float)nTop+adjust,
|
|
|
|
(float)nRight,(float)rTop);
|
|
|
|
aLRCurve.SetPoints( (float)nRight,(float)rBottom,
|
|
|
|
(float)nRight-adjust,(float)nBottom-adjust,
|
|
|
|
(float)bRight,(float)nBottom);
|
|
|
|
aLLCurve.SetPoints( (float)bLeft,(float)nBottom,
|
|
|
|
(float)nLeft+adjust,(float)nBottom-adjust,
|
|
|
|
(float)nLeft,(float)lBottom);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
1999-04-21 18:23:49 +04:00
|
|
|
* See documentation in nsCSSRendering.h
|
2003-07-30 12:13:07 +04:00
|
|
|
* @update 4/13/99 dwc
|
1999-04-19 09:27:55 +04:00
|
|
|
*/
|
|
|
|
void
|
1999-12-23 23:48:07 +03:00
|
|
|
RoundedRect::Set(nscoord aLeft,nscoord aTop,PRInt32 aWidth,PRInt32 aHeight,PRInt16 aRadius[4],PRInt16 aNumTwipPerPix)
|
1999-04-19 09:27:55 +04:00
|
|
|
{
|
2000-03-30 10:27:32 +04:00
|
|
|
nscoord x,y,width,height;
|
|
|
|
int i;
|
1999-10-20 18:46:27 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// Convert this rect to pixel boundaries. Preserve the same pixel centers.
|
|
|
|
// It's important that this preserve the same drawn-pixels as gfx's
|
|
|
|
// rounding.
|
|
|
|
x = NSToCoordRound((float)aLeft/aNumTwipPerPix)*aNumTwipPerPix;
|
|
|
|
y = NSToCoordRound((float)aTop/aNumTwipPerPix)*aNumTwipPerPix;
|
|
|
|
width = (NSToCoordRound((float)aLeft + aWidth)/aNumTwipPerPix)*aNumTwipPerPix - x;
|
|
|
|
height = (NSToCoordRound((float)aTop + aHeight)/aNumTwipPerPix)*aNumTwipPerPix - y;
|
1999-04-21 18:23:49 +04:00
|
|
|
|
|
|
|
|
1999-12-23 23:48:07 +03:00
|
|
|
for(i=0;i<4;i++) {
|
|
|
|
if( (aRadius[i]) > (aWidth>>1) ){
|
|
|
|
mRoundness[i] = (aWidth>>1);
|
|
|
|
} else {
|
|
|
|
mRoundness[i] = aRadius[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if( mRoundness[i] > (aHeight>>1) )
|
|
|
|
mRoundness[i] = aHeight>>1;
|
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
|
1999-08-27 18:37:47 +04:00
|
|
|
|
2000-01-14 17:43:05 +03:00
|
|
|
// if we are drawing a circle
|
|
|
|
mDoRound = PR_FALSE;
|
|
|
|
if(aHeight==aWidth){
|
2000-08-17 12:26:53 +04:00
|
|
|
PRBool doRound = PR_TRUE;
|
2000-01-14 17:43:05 +03:00
|
|
|
for(i=0;i<4;i++){
|
|
|
|
if(mRoundness[i]<(aWidth>>1)){
|
|
|
|
doRound = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(doRound){
|
|
|
|
mDoRound = PR_TRUE;
|
|
|
|
for(i=0;i<4;i++){
|
|
|
|
mRoundness[i] = aWidth>>1;
|
|
|
|
}
|
|
|
|
}
|
1999-08-27 18:37:47 +04:00
|
|
|
}
|
|
|
|
|
2000-01-14 17:43:05 +03:00
|
|
|
|
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
// important coordinates that the path hits
|
1999-12-23 23:48:07 +03:00
|
|
|
mLeft = x;
|
|
|
|
mTop = y;
|
|
|
|
mRight = x+width;
|
|
|
|
mBottom = y+height;
|
1999-04-21 18:23:49 +04:00
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
1999-04-21 18:23:49 +04:00
|
|
|
* See documentation in nsCSSRendering.h
|
2003-07-30 12:13:07 +04:00
|
|
|
* @update 4/13/99 dwc
|
1999-04-19 09:27:55 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
RoundedRect::GetRoundedBorders(QBCurve &aULCurve,QBCurve &aURCurve,QBCurve &aLLCurve,QBCurve &aLRCurve)
|
|
|
|
{
|
|
|
|
|
2000-03-30 10:27:32 +04:00
|
|
|
PRInt16 adjust=0;
|
1999-08-27 18:37:47 +04:00
|
|
|
|
|
|
|
if(mDoRound)
|
1999-12-23 23:48:07 +03:00
|
|
|
adjust = mRoundness[0]>>3;
|
1999-08-27 18:37:47 +04:00
|
|
|
|
1999-04-19 09:27:55 +04:00
|
|
|
// set the passed in curves to the rounded borders of the rectangle
|
2000-05-11 07:59:43 +04:00
|
|
|
aULCurve.SetPoints( (float)mLeft,(float)mTop + mRoundness[0],
|
|
|
|
(float)mLeft+adjust,(float)mTop+adjust,
|
|
|
|
(float)mLeft+mRoundness[0],(float)mTop);
|
|
|
|
aURCurve.SetPoints( (float)mRight - mRoundness[1],(float)mTop,
|
|
|
|
(float)mRight-adjust,(float)mTop+adjust,
|
|
|
|
(float)mRight,(float)mTop + mRoundness[1]);
|
|
|
|
aLRCurve.SetPoints( (float)mRight,(float)mBottom - mRoundness[2],
|
|
|
|
(float)mRight-adjust,(float)mBottom-adjust,
|
|
|
|
(float)mRight - mRoundness[2],(float)mBottom);
|
|
|
|
aLLCurve.SetPoints( (float)mLeft + mRoundness[3],(float)mBottom,
|
|
|
|
(float)mLeft+adjust,(float)mBottom-adjust,
|
|
|
|
(float)mLeft,(float)mBottom - mRoundness[3]);
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
|
|
|
* Given a qbezier path, convert it into a polygon path
|
2003-07-30 12:13:07 +04:00
|
|
|
* @update 3/26/99 dwc
|
1999-04-21 18:23:49 +04:00
|
|
|
* @param aPoints -- an array of points to use for the path
|
|
|
|
* @param aPolyPath -- an array of points containing the flattened polygon to use
|
|
|
|
* @param aCurIndex -- the index that points to the last element of the array
|
|
|
|
* @param aPathType -- what kind of path that should be returned
|
|
|
|
* @param aFrac -- the inset amount for a eCalc type path
|
1999-04-19 09:27:55 +04:00
|
|
|
*/
|
|
|
|
static void
|
2000-05-11 07:59:43 +04:00
|
|
|
GetPath(nsFloatPoint aPoints[],nsPoint aPolyPath[],PRInt32 *aCurIndex,ePathTypes aPathType,PRInt32 &aC1Index,float aFrac)
|
1999-04-19 09:27:55 +04:00
|
|
|
{
|
2000-03-30 10:27:32 +04:00
|
|
|
QBCurve thecurve;
|
2005-10-29 17:40:38 +04:00
|
|
|
|
|
|
|
if (*aCurIndex >= MAXPOLYPATHSIZE)
|
|
|
|
return;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
switch (aPathType) {
|
|
|
|
case eOutside:
|
|
|
|
thecurve.SetPoints(aPoints[0].x,aPoints[0].y,aPoints[1].x,aPoints[1].y,aPoints[2].x,aPoints[2].y);
|
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
1999-04-21 18:23:49 +04:00
|
|
|
aC1Index = *aCurIndex;
|
2005-11-01 08:15:10 +03:00
|
|
|
if (*aCurIndex >= MAXPOLYPATHSIZE)
|
|
|
|
return;
|
2000-05-11 07:59:43 +04:00
|
|
|
aPolyPath[*aCurIndex].x = (nscoord)aPoints[3].x;
|
|
|
|
aPolyPath[*aCurIndex].y = (nscoord)aPoints[3].y;
|
1999-04-19 09:27:55 +04:00
|
|
|
(*aCurIndex)++;
|
2005-11-01 08:15:10 +03:00
|
|
|
if (*aCurIndex >= MAXPOLYPATHSIZE)
|
|
|
|
return;
|
1999-04-19 09:27:55 +04:00
|
|
|
thecurve.SetPoints(aPoints[3].x,aPoints[3].y,aPoints[4].x,aPoints[4].y,aPoints[5].x,aPoints[5].y);
|
|
|
|
thecurve.SubDivide(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);
|
2005-11-01 08:15:10 +03:00
|
|
|
if (*aCurIndex >= MAXPOLYPATHSIZE)
|
|
|
|
return;
|
2000-05-11 07:59:43 +04:00
|
|
|
aPolyPath[*aCurIndex].x = (nscoord)aPoints[9].x;
|
|
|
|
aPolyPath[*aCurIndex].y = (nscoord)aPoints[9].y;
|
1999-04-19 09:27:55 +04:00
|
|
|
(*aCurIndex)++;
|
2005-11-01 08:15:10 +03:00
|
|
|
if (*aCurIndex >= MAXPOLYPATHSIZE)
|
|
|
|
return;
|
1999-04-19 09:27:55 +04:00
|
|
|
thecurve.SetPoints(aPoints[9].x,aPoints[9].y,aPoints[10].x,aPoints[10].y,aPoints[11].x,aPoints[11].y);
|
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
|
|
|
break;
|
|
|
|
case eCalc:
|
2000-05-11 07:59:43 +04:00
|
|
|
thecurve.SetPoints( (aPoints[0].x+aPoints[11].x)/2.0f,(aPoints[0].y+aPoints[11].y)/2.0f,
|
|
|
|
(aPoints[1].x+aPoints[10].x)/2.0f,(aPoints[1].y+aPoints[10].y)/2.0f,
|
|
|
|
(aPoints[2].x+aPoints[9].x)/2.0f,(aPoints[2].y+aPoints[9].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
2005-11-01 08:15:10 +03:00
|
|
|
if (*aCurIndex >= MAXPOLYPATHSIZE)
|
|
|
|
return;
|
2000-05-11 07:59:43 +04:00
|
|
|
aPolyPath[*aCurIndex].x = (nscoord)((aPoints[3].x+aPoints[8].x)/2.0f);
|
|
|
|
aPolyPath[*aCurIndex].y = (nscoord)((aPoints[3].y+aPoints[8].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
(*aCurIndex)++;
|
2005-11-01 08:15:10 +03:00
|
|
|
if (*aCurIndex >= MAXPOLYPATHSIZE)
|
|
|
|
return;
|
2000-05-11 07:59:43 +04:00
|
|
|
thecurve.SetPoints( (aPoints[3].x+aPoints[8].x)/2.0f,(aPoints[3].y+aPoints[8].y)/2.0f,
|
|
|
|
(aPoints[4].x+aPoints[7].x)/2.0f,(aPoints[4].y+aPoints[7].y)/2.0f,
|
|
|
|
(aPoints[5].x+aPoints[6].x)/2.0f,(aPoints[5].y+aPoints[6].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
|
|
|
break;
|
|
|
|
case eCalcRev:
|
2000-05-11 07:59:43 +04:00
|
|
|
thecurve.SetPoints( (aPoints[5].x+aPoints[6].x)/2.0f,(aPoints[5].y+aPoints[6].y)/2.0f,
|
|
|
|
(aPoints[4].x+aPoints[7].x)/2.0f,(aPoints[4].y+aPoints[7].y)/2.0f,
|
|
|
|
(aPoints[3].x+aPoints[8].x)/2.0f,(aPoints[3].y+aPoints[8].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
2000-05-11 07:59:43 +04:00
|
|
|
aPolyPath[*aCurIndex].x = (nscoord)((aPoints[2].x+aPoints[9].x)/2.0f);
|
|
|
|
aPolyPath[*aCurIndex].y = (nscoord)((aPoints[2].y+aPoints[9].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
(*aCurIndex)++;
|
2005-11-01 08:15:10 +03:00
|
|
|
if (*aCurIndex >= MAXPOLYPATHSIZE)
|
|
|
|
return;
|
2000-05-11 07:59:43 +04:00
|
|
|
thecurve.SetPoints( (aPoints[2].x+aPoints[9].x)/2.0f,(aPoints[2].y+aPoints[9].y)/2.0f,
|
|
|
|
(aPoints[1].x+aPoints[10].x)/2.0f,(aPoints[1].y+aPoints[10].y)/2.0f,
|
|
|
|
(aPoints[0].x+aPoints[11].x)/2.0f,(aPoints[0].y+aPoints[11].y)/2.0f);
|
1999-04-19 09:27:55 +04:00
|
|
|
thecurve.SubDivide(nsnull,aPolyPath,aCurIndex);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
1999-04-21 18:23:49 +04:00
|
|
|
* See documentation in nsCSSRendering.h
|
2003-07-30 12:13:07 +04:00
|
|
|
* @update 4/13/99 dwc
|
1999-04-19 09:27:55 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
QBCurve::SubDivide(nsIRenderingContext *aRenderingContext,nsPoint aPointArray[],PRInt32 *aCurIndex)
|
|
|
|
{
|
2005-10-29 17:40:38 +04:00
|
|
|
QBCurve curve1,curve2;
|
2005-11-01 08:15:10 +03:00
|
|
|
float fx,fy,smag, oldfx, oldfy, oldsmag;
|
2005-10-29 17:40:38 +04:00
|
|
|
|
2005-11-18 00:24:05 +03:00
|
|
|
if (aCurIndex && (*aCurIndex >= MAXPOLYPATHSIZE))
|
2005-10-29 17:40:38 +04:00
|
|
|
return;
|
2005-11-01 08:15:10 +03:00
|
|
|
|
|
|
|
oldfx = (this->mAnc1.x + this->mAnc2.x)/2.0f - this->mCon.x;
|
|
|
|
oldfy = (this->mAnc1.y + this->mAnc2.y)/2.0f - this->mCon.y;
|
|
|
|
oldsmag = oldfx * oldfx + oldfy * oldfy;
|
1999-04-19 09:27:55 +04:00
|
|
|
// divide the curve into 2 pieces
|
2003-07-30 12:13:07 +04:00
|
|
|
MidPointDivide(&curve1,&curve2);
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2003-07-30 12:13:07 +04:00
|
|
|
fx = (float)fabs(curve1.mAnc2.x - this->mCon.x);
|
|
|
|
fy = (float)fabs(curve1.mAnc2.y - this->mCon.y);
|
|
|
|
|
|
|
|
//smag = fx+fy-(PR_MIN(fx,fy)>>1);
|
2000-05-11 07:59:43 +04:00
|
|
|
smag = fx*fx + fy*fy;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2003-07-30 12:13:07 +04:00
|
|
|
if (smag>1){
|
2005-11-01 08:15:10 +03:00
|
|
|
if (smag + 0.2 > oldsmag)
|
|
|
|
return; // we did not get closer
|
2003-07-30 12:13:07 +04:00
|
|
|
// split the curve again
|
1999-04-19 09:27:55 +04:00
|
|
|
curve1.SubDivide(aRenderingContext,aPointArray,aCurIndex);
|
|
|
|
curve2.SubDivide(aRenderingContext,aPointArray,aCurIndex);
|
2003-07-30 12:13:07 +04:00
|
|
|
}else{
|
1999-04-19 09:27:55 +04:00
|
|
|
if(aPointArray ) {
|
|
|
|
// save the points for further processing
|
2000-05-11 07:59:43 +04:00
|
|
|
aPointArray[*aCurIndex].x = (nscoord)curve1.mAnc2.x;
|
|
|
|
aPointArray[*aCurIndex].y = (nscoord)curve1.mAnc2.y;
|
1999-04-19 09:27:55 +04:00
|
|
|
(*aCurIndex)++;
|
2005-10-29 17:40:38 +04:00
|
|
|
if (*aCurIndex >= MAXPOLYPATHSIZE)
|
|
|
|
return;
|
2000-05-11 07:59:43 +04:00
|
|
|
aPointArray[*aCurIndex].x = (nscoord)curve2.mAnc2.x;
|
|
|
|
aPointArray[*aCurIndex].y = (nscoord)curve2.mAnc2.y;
|
1999-04-19 09:27:55 +04:00
|
|
|
(*aCurIndex)++;
|
|
|
|
}else{
|
2003-07-30 12:13:07 +04:00
|
|
|
// draw the curve
|
1999-08-24 18:51:16 +04:00
|
|
|
nsTransform2D *aTransform;
|
|
|
|
aRenderingContext->GetCurrentTransform(aTransform);
|
|
|
|
|
1999-08-27 18:37:47 +04:00
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
aRenderingContext->DrawLine((nscoord)curve1.mAnc1.x,(nscoord)curve1.mAnc1.y,(nscoord)curve1.mAnc2.x,(nscoord)curve1.mAnc2.y);
|
|
|
|
aRenderingContext->DrawLine((nscoord)curve1.mAnc2.x,(nscoord)curve1.mAnc2.y,(nscoord)curve2.mAnc2.x,(nscoord)curve2.mAnc2.y);
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
2003-07-30 12:13:07 +04:00
|
|
|
}
|
1999-04-19 09:27:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** ---------------------------------------------------
|
1999-04-21 18:23:49 +04:00
|
|
|
* See documentation in nsCSSRendering.h
|
2003-07-30 12:13:07 +04:00
|
|
|
* @update 4/13/99 dwc
|
1999-04-19 09:27:55 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
QBCurve::MidPointDivide(QBCurve *A,QBCurve *B)
|
|
|
|
{
|
2003-07-30 12:13:07 +04:00
|
|
|
float c1x,c1y,c2x,c2y;
|
|
|
|
nsFloatPoint a1;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
c1x = (mAnc1.x+mCon.x)/2.0f;
|
|
|
|
c1y = (mAnc1.y+mCon.y)/2.0f;
|
|
|
|
c2x = (mAnc2.x+mCon.x)/2.0f;
|
|
|
|
c2y = (mAnc2.y+mCon.y)/2.0f;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
2000-05-11 07:59:43 +04:00
|
|
|
a1.x = (c1x + c2x)/2.0f;
|
2003-07-30 12:13:07 +04:00
|
|
|
a1.y = (c1y + c2y)/2.0f;
|
1999-04-19 09:27:55 +04:00
|
|
|
|
|
|
|
// put the math into our 2 new curves
|
|
|
|
A->mAnc1 = this->mAnc1;
|
2000-05-11 07:59:43 +04:00
|
|
|
A->mCon.x = c1x;
|
|
|
|
A->mCon.y = c1y;
|
1999-04-19 09:27:55 +04:00
|
|
|
A->mAnc2 = a1;
|
|
|
|
B->mAnc1 = a1;
|
2000-05-11 07:59:43 +04:00
|
|
|
B->mCon.x = c2x;
|
|
|
|
B->mCon.y = c2y;
|
1999-04-19 09:27:55 +04:00
|
|
|
B->mAnc2 = this->mAnc2;
|
|
|
|
}
|
2001-10-03 04:08:25 +04:00
|
|
|
|
|
|
|
void FillOrInvertRect(nsIRenderingContext& aRC, nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, PRBool aInvert)
|
|
|
|
{
|
2007-03-15 19:16:20 +03:00
|
|
|
#ifdef GFX_HAS_INVERT
|
2001-10-03 04:08:25 +04:00
|
|
|
if (aInvert) {
|
|
|
|
aRC.InvertRect(aX, aY, aWidth, aHeight);
|
|
|
|
} else {
|
2006-04-25 13:19:29 +04:00
|
|
|
#endif
|
2001-10-03 04:08:25 +04:00
|
|
|
aRC.FillRect(aX, aY, aWidth, aHeight);
|
2007-03-15 19:16:20 +03:00
|
|
|
#ifdef GFX_HAS_INVERT
|
2001-10-03 04:08:25 +04:00
|
|
|
}
|
2006-04-25 13:19:29 +04:00
|
|
|
#endif
|
2001-10-03 04:08:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void FillOrInvertRect(nsIRenderingContext& aRC, const nsRect& aRect, PRBool aInvert)
|
|
|
|
{
|
2007-03-15 19:16:20 +03:00
|
|
|
#ifdef GFX_HAS_INVERT
|
2001-10-03 04:08:25 +04:00
|
|
|
if (aInvert) {
|
|
|
|
aRC.InvertRect(aRect);
|
|
|
|
} else {
|
2006-04-25 13:19:29 +04:00
|
|
|
#endif
|
2001-10-03 04:08:25 +04:00
|
|
|
aRC.FillRect(aRect);
|
2007-03-15 19:16:20 +03:00
|
|
|
#ifdef GFX_HAS_INVERT
|
2001-10-03 04:08:25 +04:00
|
|
|
}
|
2006-04-25 13:19:29 +04:00
|
|
|
#endif
|
2001-10-03 04:08:25 +04:00
|
|
|
}
|
|
|
|
|
2002-02-19 18:48:28 +03:00
|
|
|
// Begin table border-collapsing section
|
|
|
|
// These functions were written to not disrupt the normal ones and yet satisfy some additional requirements
|
|
|
|
// At some point, all functions should be unified to include the additional functionality that these provide
|
|
|
|
|
|
|
|
static nscoord
|
|
|
|
RoundIntToPixel(nscoord aValue,
|
|
|
|
nscoord aTwipsPerPixel,
|
|
|
|
PRBool aRoundDown = PR_FALSE)
|
|
|
|
{
|
2002-04-07 02:28:39 +04:00
|
|
|
if (aTwipsPerPixel <= 0)
|
|
|
|
// We must be rendering to a device that has a resolution greater than Twips!
|
|
|
|
// In that case, aValue is as accurate as it's going to get.
|
|
|
|
return aValue;
|
|
|
|
|
2002-02-19 18:48:28 +03:00
|
|
|
nscoord halfPixel = NSToCoordRound(aTwipsPerPixel / 2.0f);
|
|
|
|
nscoord extra = aValue % aTwipsPerPixel;
|
|
|
|
nscoord finalValue = (!aRoundDown && (extra >= halfPixel)) ? aValue + (aTwipsPerPixel - extra) : aValue - extra;
|
|
|
|
return finalValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nscoord
|
|
|
|
RoundFloatToPixel(float aValue,
|
|
|
|
nscoord aTwipsPerPixel,
|
|
|
|
PRBool aRoundDown = PR_FALSE)
|
|
|
|
{
|
|
|
|
return RoundIntToPixel(NSToCoordRound(aValue), aTwipsPerPixel, aRoundDown);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetPoly(const nsRect& aRect,
|
|
|
|
nsPoint* poly)
|
|
|
|
{
|
|
|
|
poly[0].x = aRect.x;
|
|
|
|
poly[0].y = aRect.y;
|
|
|
|
poly[1].x = aRect.x + aRect.width;
|
|
|
|
poly[1].y = aRect.y;
|
|
|
|
poly[2].x = aRect.x + aRect.width;
|
|
|
|
poly[2].y = aRect.y + aRect.height;
|
|
|
|
poly[3].x = aRect.x;
|
|
|
|
poly[3].y = aRect.y + aRect.height;
|
|
|
|
poly[4].x = aRect.x;
|
|
|
|
poly[4].y = aRect.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DrawSolidBorderSegment(nsIRenderingContext& aContext,
|
|
|
|
nsRect aRect,
|
|
|
|
nscoord aTwipsPerPixel,
|
|
|
|
PRUint8 aStartBevelSide = 0,
|
|
|
|
nscoord aStartBevelOffset = 0,
|
|
|
|
PRUint8 aEndBevelSide = 0,
|
|
|
|
nscoord aEndBevelOffset = 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((aRect.width == aTwipsPerPixel) || (aRect.height == aTwipsPerPixel) ||
|
|
|
|
((0 == aStartBevelOffset) && (0 == aEndBevelOffset))) {
|
|
|
|
// simple line or rectangle
|
|
|
|
if ((NS_SIDE_TOP == aStartBevelSide) || (NS_SIDE_BOTTOM == aStartBevelSide)) {
|
|
|
|
if (1 == aRect.height)
|
|
|
|
aContext.DrawLine(aRect.x, aRect.y, aRect.x, aRect.y + aRect.height);
|
|
|
|
else
|
|
|
|
aContext.FillRect(aRect);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (1 == aRect.width)
|
|
|
|
aContext.DrawLine(aRect.x, aRect.y, aRect.x + aRect.width, aRect.y);
|
|
|
|
else
|
|
|
|
aContext.FillRect(aRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// polygon with beveling
|
|
|
|
nsPoint poly[5];
|
|
|
|
SetPoly(aRect, poly);
|
|
|
|
switch(aStartBevelSide) {
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
poly[0].x += aStartBevelOffset;
|
|
|
|
poly[4].x = poly[0].x;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
poly[3].x += aStartBevelOffset;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
poly[1].y += aStartBevelOffset;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
poly[0].y += aStartBevelOffset;
|
|
|
|
poly[4].y = poly[0].y;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(aEndBevelSide) {
|
|
|
|
case NS_SIDE_TOP:
|
|
|
|
poly[1].x -= aEndBevelOffset;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_BOTTOM:
|
|
|
|
poly[2].x -= aEndBevelOffset;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_RIGHT:
|
|
|
|
poly[2].y -= aEndBevelOffset;
|
|
|
|
break;
|
|
|
|
case NS_SIDE_LEFT:
|
|
|
|
poly[3].y -= aEndBevelOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
aContext.FillPolygon(poly, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetDashInfo(nscoord aBorderLength,
|
|
|
|
nscoord aDashLength,
|
|
|
|
nscoord aTwipsPerPixel,
|
|
|
|
PRInt32& aNumDashSpaces,
|
|
|
|
nscoord& aStartDashLength,
|
|
|
|
nscoord& aEndDashLength)
|
|
|
|
{
|
|
|
|
aNumDashSpaces = 0;
|
|
|
|
if (aStartDashLength + aDashLength + aEndDashLength >= aBorderLength) {
|
|
|
|
aStartDashLength = aBorderLength;
|
|
|
|
aEndDashLength = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aNumDashSpaces = aBorderLength / (2 * aDashLength); // round down
|
|
|
|
nscoord extra = aBorderLength - aStartDashLength - aEndDashLength - (((2 * aNumDashSpaces) - 1) * aDashLength);
|
|
|
|
if (extra > 0) {
|
|
|
|
nscoord half = RoundIntToPixel(extra / 2, aTwipsPerPixel);
|
|
|
|
aStartDashLength += half;
|
|
|
|
aEndDashLength += (extra - half);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSRendering::DrawTableBorderSegment(nsIRenderingContext& aContext,
|
|
|
|
PRUint8 aBorderStyle,
|
|
|
|
nscolor aBorderColor,
|
|
|
|
const nsStyleBackground* aBGColor,
|
|
|
|
const nsRect& aBorder,
|
2007-02-23 20:52:09 +03:00
|
|
|
PRInt32 aAppUnitsPerCSSPixel,
|
2002-02-19 18:48:28 +03:00
|
|
|
PRUint8 aStartBevelSide,
|
|
|
|
nscoord aStartBevelOffset,
|
|
|
|
PRUint8 aEndBevelSide,
|
|
|
|
nscoord aEndBevelOffset)
|
|
|
|
{
|
|
|
|
aContext.SetColor (aBorderColor);
|
|
|
|
|
|
|
|
PRBool horizontal = ((NS_SIDE_TOP == aStartBevelSide) || (NS_SIDE_BOTTOM == aStartBevelSide));
|
2007-02-23 20:52:09 +03:00
|
|
|
nscoord twipsPerPixel = NSIntPixelsToAppUnits(1, aAppUnitsPerCSSPixel);
|
2002-02-19 18:48:28 +03:00
|
|
|
PRBool ridgeGroove = NS_STYLE_BORDER_STYLE_RIDGE;
|
|
|
|
|
|
|
|
if ((twipsPerPixel >= aBorder.width) || (twipsPerPixel >= aBorder.height) ||
|
|
|
|
(NS_STYLE_BORDER_STYLE_DASHED == aBorderStyle) || (NS_STYLE_BORDER_STYLE_DOTTED == aBorderStyle)) {
|
|
|
|
// no beveling for 1 pixel border, dash or dot
|
|
|
|
aStartBevelOffset = 0;
|
|
|
|
aEndBevelOffset = 0;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:52:09 +03:00
|
|
|
#ifdef MOZ_CAIRO_GFX
|
|
|
|
gfxContext *ctx = (gfxContext*) aContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
|
|
|
|
gfxContext::AntialiasMode oldMode = ctx->CurrentAntialiasMode();
|
|
|
|
ctx->SetAntialiasMode(gfxContext::MODE_ALIASED);
|
|
|
|
#endif
|
|
|
|
|
2002-02-19 18:48:28 +03:00
|
|
|
switch (aBorderStyle) {
|
|
|
|
case NS_STYLE_BORDER_STYLE_NONE:
|
|
|
|
case NS_STYLE_BORDER_STYLE_HIDDEN:
|
2004-02-11 07:34:12 +03:00
|
|
|
//NS_ASSERTION(PR_FALSE, "style of none or hidden");
|
2002-02-19 18:48:28 +03:00
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOTTED:
|
|
|
|
case NS_STYLE_BORDER_STYLE_DASHED:
|
|
|
|
{
|
|
|
|
nscoord dashLength = (NS_STYLE_BORDER_STYLE_DASHED == aBorderStyle) ? DASH_LENGTH : DOT_LENGTH;
|
|
|
|
// make the dash length proportional to the border thickness
|
|
|
|
dashLength *= (horizontal) ? aBorder.height : aBorder.width;
|
|
|
|
// make the min dash length for the ends 1/2 the dash length
|
|
|
|
nscoord minDashLength = (NS_STYLE_BORDER_STYLE_DASHED == aBorderStyle)
|
|
|
|
? RoundFloatToPixel(((float)dashLength) / 2.0f, twipsPerPixel) : dashLength;
|
|
|
|
minDashLength = PR_MAX(minDashLength, twipsPerPixel);
|
|
|
|
nscoord numDashSpaces = 0;
|
|
|
|
nscoord startDashLength = minDashLength;
|
|
|
|
nscoord endDashLength = minDashLength;
|
|
|
|
if (horizontal) {
|
|
|
|
GetDashInfo(aBorder.width, dashLength, twipsPerPixel, numDashSpaces, startDashLength, endDashLength);
|
|
|
|
nsRect rect(aBorder.x, aBorder.y, startDashLength, aBorder.height);
|
2007-03-30 06:53:45 +04:00
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel);
|
2002-02-19 18:48:28 +03:00
|
|
|
for (PRInt32 spaceX = 0; spaceX < numDashSpaces; spaceX++) {
|
|
|
|
rect.x += rect.width + dashLength;
|
|
|
|
rect.width = (spaceX == (numDashSpaces - 1)) ? endDashLength : dashLength;
|
2007-03-30 06:53:45 +04:00
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel);
|
2002-02-19 18:48:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GetDashInfo(aBorder.height, dashLength, twipsPerPixel, numDashSpaces, startDashLength, endDashLength);
|
|
|
|
nsRect rect(aBorder.x, aBorder.y, aBorder.width, startDashLength);
|
2007-03-30 06:53:45 +04:00
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel);
|
2002-02-19 18:48:28 +03:00
|
|
|
for (PRInt32 spaceY = 0; spaceY < numDashSpaces; spaceY++) {
|
|
|
|
rect.y += rect.height + dashLength;
|
|
|
|
rect.height = (spaceY == (numDashSpaces - 1)) ? endDashLength : dashLength;
|
2007-03-30 06:53:45 +04:00
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel);
|
2002-02-19 18:48:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_GROOVE:
|
|
|
|
ridgeGroove = NS_STYLE_BORDER_STYLE_GROOVE; // and fall through to ridge
|
|
|
|
case NS_STYLE_BORDER_STYLE_RIDGE:
|
|
|
|
if ((horizontal && (twipsPerPixel >= aBorder.height)) ||
|
|
|
|
(!horizontal && (twipsPerPixel >= aBorder.width))) {
|
|
|
|
// a one pixel border
|
|
|
|
DrawSolidBorderSegment(aContext, aBorder, twipsPerPixel, aStartBevelSide, aStartBevelOffset,
|
|
|
|
aEndBevelSide, aEndBevelOffset);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nscoord startBevel = (aStartBevelOffset > 0)
|
|
|
|
? RoundFloatToPixel(0.5f * (float)aStartBevelOffset, twipsPerPixel, PR_TRUE) : 0;
|
|
|
|
nscoord endBevel = (aEndBevelOffset > 0)
|
|
|
|
? RoundFloatToPixel(0.5f * (float)aEndBevelOffset, twipsPerPixel, PR_TRUE) : 0;
|
|
|
|
PRUint8 ridgeGrooveSide = (horizontal) ? NS_SIDE_TOP : NS_SIDE_LEFT;
|
|
|
|
aContext.SetColor (
|
2007-02-01 05:45:55 +03:00
|
|
|
MakeBevelColor(ridgeGrooveSide, ridgeGroove, aBGColor->mBackgroundColor, aBorderColor));
|
2002-02-19 18:48:28 +03:00
|
|
|
nsRect rect(aBorder);
|
|
|
|
nscoord half;
|
|
|
|
if (horizontal) { // top, bottom
|
|
|
|
half = RoundFloatToPixel(0.5f * (float)aBorder.height, twipsPerPixel);
|
|
|
|
rect.height = half;
|
|
|
|
if (NS_SIDE_TOP == aStartBevelSide) {
|
|
|
|
rect.x += startBevel;
|
|
|
|
rect.width -= startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_TOP == aEndBevelSide) {
|
|
|
|
rect.width -= endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
}
|
|
|
|
else { // left, right
|
|
|
|
half = RoundFloatToPixel(0.5f * (float)aBorder.width, twipsPerPixel);
|
|
|
|
rect.width = half;
|
|
|
|
if (NS_SIDE_LEFT == aStartBevelSide) {
|
|
|
|
rect.y += startBevel;
|
|
|
|
rect.height -= startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_LEFT == aEndBevelSide) {
|
|
|
|
rect.height -= endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
rect = aBorder;
|
|
|
|
ridgeGrooveSide = (NS_SIDE_TOP == ridgeGrooveSide) ? NS_SIDE_BOTTOM : NS_SIDE_RIGHT;
|
|
|
|
aContext.SetColor (
|
2007-02-01 05:45:55 +03:00
|
|
|
MakeBevelColor(ridgeGrooveSide, ridgeGroove, aBGColor->mBackgroundColor, aBorderColor));
|
2002-02-19 18:48:28 +03:00
|
|
|
if (horizontal) {
|
|
|
|
rect.y = rect.y + half;
|
|
|
|
rect.height = aBorder.height - half;
|
|
|
|
if (NS_SIDE_BOTTOM == aStartBevelSide) {
|
|
|
|
rect.x += startBevel;
|
|
|
|
rect.width -= startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_BOTTOM == aEndBevelSide) {
|
|
|
|
rect.width -= endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rect.x = rect.x + half;
|
|
|
|
rect.width = aBorder.width - half;
|
|
|
|
if (NS_SIDE_RIGHT == aStartBevelSide) {
|
|
|
|
rect.y += aStartBevelOffset - startBevel;
|
|
|
|
rect.height -= startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_RIGHT == aEndBevelSide) {
|
|
|
|
rect.height -= endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, rect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOUBLE:
|
|
|
|
if ((aBorder.width > 2) && (aBorder.height > 2)) {
|
|
|
|
nscoord startBevel = (aStartBevelOffset > 0)
|
|
|
|
? RoundFloatToPixel(0.333333f * (float)aStartBevelOffset, twipsPerPixel) : 0;
|
|
|
|
nscoord endBevel = (aEndBevelOffset > 0)
|
|
|
|
? RoundFloatToPixel(0.333333f * (float)aEndBevelOffset, twipsPerPixel) : 0;
|
|
|
|
if (horizontal) { // top, bottom
|
|
|
|
nscoord thirdHeight = RoundFloatToPixel(0.333333f * (float)aBorder.height, twipsPerPixel);
|
|
|
|
|
|
|
|
// draw the top line or rect
|
|
|
|
nsRect topRect(aBorder.x, aBorder.y, aBorder.width, thirdHeight);
|
|
|
|
if (NS_SIDE_TOP == aStartBevelSide) {
|
|
|
|
topRect.x += aStartBevelOffset - startBevel;
|
|
|
|
topRect.width -= aStartBevelOffset - startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_TOP == aEndBevelSide) {
|
|
|
|
topRect.width -= aEndBevelOffset - endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, topRect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
|
|
|
|
// draw the botom line or rect
|
|
|
|
nscoord heightOffset = aBorder.height - thirdHeight;
|
|
|
|
nsRect bottomRect(aBorder.x, aBorder.y + heightOffset, aBorder.width, aBorder.height - heightOffset);
|
|
|
|
if (NS_SIDE_BOTTOM == aStartBevelSide) {
|
|
|
|
bottomRect.x += aStartBevelOffset - startBevel;
|
|
|
|
bottomRect.width -= aStartBevelOffset - startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_BOTTOM == aEndBevelSide) {
|
|
|
|
bottomRect.width -= aEndBevelOffset - endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, bottomRect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
}
|
|
|
|
else { // left, right
|
|
|
|
nscoord thirdWidth = RoundFloatToPixel(0.333333f * (float)aBorder.width, twipsPerPixel);
|
|
|
|
|
|
|
|
nsRect leftRect(aBorder.x, aBorder.y, thirdWidth, aBorder.height);
|
|
|
|
if (NS_SIDE_LEFT == aStartBevelSide) {
|
|
|
|
leftRect.y += aStartBevelOffset - startBevel;
|
|
|
|
leftRect.height -= aStartBevelOffset - startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_LEFT == aEndBevelSide) {
|
|
|
|
leftRect.height -= aEndBevelOffset - endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, leftRect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
|
|
|
|
nscoord widthOffset = aBorder.width - thirdWidth;
|
|
|
|
nsRect rightRect(aBorder.x + widthOffset, aBorder.y, aBorder.width - widthOffset, aBorder.height);
|
|
|
|
if (NS_SIDE_RIGHT == aStartBevelSide) {
|
|
|
|
rightRect.y += aStartBevelOffset - startBevel;
|
|
|
|
rightRect.height -= aStartBevelOffset - startBevel;
|
|
|
|
}
|
|
|
|
if (NS_SIDE_RIGHT == aEndBevelSide) {
|
|
|
|
rightRect.height -= aEndBevelOffset - endBevel;
|
|
|
|
}
|
|
|
|
DrawSolidBorderSegment(aContext, rightRect, twipsPerPixel, aStartBevelSide,
|
|
|
|
startBevel, aEndBevelSide, endBevel);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// else fall through to solid
|
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
|
|
|
DrawSolidBorderSegment(aContext, aBorder, twipsPerPixel, aStartBevelSide,
|
|
|
|
aStartBevelOffset, aEndBevelSide, aEndBevelOffset);
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_OUTSET:
|
|
|
|
case NS_STYLE_BORDER_STYLE_INSET:
|
|
|
|
NS_ASSERTION(PR_FALSE, "inset, outset should have been converted to groove, ridge");
|
|
|
|
break;
|
2005-03-27 15:36:08 +04:00
|
|
|
case NS_STYLE_BORDER_STYLE_AUTO:
|
|
|
|
NS_ASSERTION(PR_FALSE, "Unexpected 'auto' table border");
|
|
|
|
break;
|
2002-02-19 18:48:28 +03:00
|
|
|
}
|
2007-02-23 20:52:09 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_CAIRO_GFX
|
|
|
|
ctx->SetAntialiasMode(oldMode);
|
|
|
|
#endif
|
2002-02-19 18:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// End table border-collapsing section
|
|
|
|
|