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>
|
2008-06-03 02:52:25 +04:00
|
|
|
* L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
|
2008-06-13 02:02:32 +04:00
|
|
|
* Michael Ventnor <m.ventnor@gmail.com>
|
2008-07-17 10:30:25 +04:00
|
|
|
* Rob Arnold <robarnold@mozilla.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"
|
2008-06-03 02:52:25 +04:00
|
|
|
#include "nsCSSAnonBoxes.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"
|
2008-02-19 21:47:34 +03:00
|
|
|
#include "nsIHTMLDocument.h"
|
2003-02-23 05:49:22 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2003-10-15 06:48:25 +04:00
|
|
|
#include "nsINameSpaceManager.h"
|
2008-02-27 13:46:29 +03:00
|
|
|
#include "nsBlockFrame.h"
|
2006-04-21 21:52:05 +04:00
|
|
|
#include "gfxContext.h"
|
2008-07-17 10:30:25 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "nsStyleStructInlines.h"
|
2008-08-08 12:21:13 +04:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2006-04-21 21:52:05 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
#include "nsCSSRenderingBorders.h"
|
1999-04-19 09:27:55 +04:00
|
|
|
|
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()
|
2008-02-27 13:46:29 +03:00
|
|
|
: mFrame(nsnull), mBlockFrame(nsnull)
|
2003-01-17 12:33:52 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~InlineBackgroundData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
mBoundingBox.SetRect(0,0,0,0);
|
2008-02-27 13:46:29 +03:00
|
|
|
mContinuationPoint = mLineContinuationPoint = mUnbrokenWidth = 0;
|
|
|
|
mFrame = mBlockFrame = nsnull;
|
2003-01-17 12:33:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect GetContinuousRect(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
SetFrame(aFrame);
|
|
|
|
|
2008-02-27 13:46:29 +03:00
|
|
|
nscoord x;
|
|
|
|
if (mBidiEnabled) {
|
|
|
|
x = mLineContinuationPoint;
|
|
|
|
|
|
|
|
// Scan continuations on the same line as aFrame and accumulate the widths
|
|
|
|
// of frames that are to the left (if this is an LTR block) or right
|
|
|
|
// (if it's RTL) of the current one.
|
|
|
|
PRBool isRtlBlock = (mBlockFrame->GetStyleVisibility()->mDirection ==
|
|
|
|
NS_STYLE_DIRECTION_RTL);
|
|
|
|
nscoord curOffset = aFrame->GetOffsetTo(mBlockFrame).x;
|
|
|
|
|
|
|
|
nsIFrame* inlineFrame = aFrame->GetPrevContinuation();
|
|
|
|
// If the continuation is fluid we know inlineFrame is not on the same line.
|
|
|
|
// If it's not fluid, we need to test furhter to be sure.
|
|
|
|
while (inlineFrame && !inlineFrame->GetNextInFlow() &&
|
|
|
|
AreOnSameLine(aFrame, inlineFrame)) {
|
|
|
|
nscoord frameXOffset = inlineFrame->GetOffsetTo(mBlockFrame).x;
|
|
|
|
if(isRtlBlock == (frameXOffset >= curOffset)) {
|
|
|
|
x += inlineFrame->GetSize().width;
|
|
|
|
}
|
|
|
|
inlineFrame = inlineFrame->GetPrevContinuation();
|
|
|
|
}
|
|
|
|
|
|
|
|
inlineFrame = aFrame->GetNextContinuation();
|
|
|
|
while (inlineFrame && !inlineFrame->GetPrevInFlow() &&
|
|
|
|
AreOnSameLine(aFrame, inlineFrame)) {
|
|
|
|
nscoord frameXOffset = inlineFrame->GetOffsetTo(mBlockFrame).x;
|
|
|
|
if(isRtlBlock == (frameXOffset >= curOffset)) {
|
|
|
|
x += inlineFrame->GetSize().width;
|
|
|
|
}
|
|
|
|
inlineFrame = inlineFrame->GetNextContinuation();
|
|
|
|
}
|
|
|
|
if (isRtlBlock) {
|
|
|
|
// aFrame itself is also to the right of its left edge, so add its width.
|
|
|
|
x += aFrame->GetSize().width;
|
|
|
|
// x is now the distance from the left edge of aFrame to the right edge
|
|
|
|
// of the unbroken content. Change it to indicate the distance from the
|
|
|
|
// left edge of the unbroken content to the left edge of aFrame.
|
|
|
|
x = mUnbrokenWidth - x;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
x = mContinuationPoint;
|
|
|
|
}
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
// 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.
|
2008-02-27 13:46:29 +03:00
|
|
|
return nsRect(-x, 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;
|
|
|
|
|
2008-02-27 13:46:29 +03:00
|
|
|
PRBool mBidiEnabled;
|
|
|
|
nsBlockFrame* mBlockFrame;
|
|
|
|
nscoord mLineContinuationPoint;
|
|
|
|
|
2003-01-17 12:33:52 +03:00
|
|
|
void SetFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Need a frame");
|
|
|
|
|
2008-01-09 22:19:49 +03:00
|
|
|
nsIFrame *prevContinuation = aFrame->GetPrevContinuation();
|
2003-01-17 12:33:52 +03:00
|
|
|
|
2008-01-09 22:19:49 +03:00
|
|
|
if (!prevContinuation || mFrame != prevContinuation) {
|
2003-01-17 12:33:52 +03:00
|
|
|
// 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
|
|
|
|
2008-02-27 13:46:29 +03:00
|
|
|
// If this a new line, update mLineContinuationPoint.
|
|
|
|
if (mBidiEnabled &&
|
|
|
|
(aFrame->GetPrevInFlow() || !AreOnSameLine(mFrame, aFrame))) {
|
|
|
|
mLineContinuationPoint = mContinuationPoint;
|
|
|
|
}
|
|
|
|
|
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.
|
2008-01-09 22:19:49 +03:00
|
|
|
nsIFrame* inlineFrame = aFrame->GetPrevContinuation();
|
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);
|
2008-01-09 22:19:49 +03:00
|
|
|
inlineFrame = inlineFrame->GetPrevContinuation();
|
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);
|
2008-01-09 22:19:49 +03:00
|
|
|
inlineFrame = inlineFrame->GetNextContinuation();
|
2003-01-17 12:33:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mFrame = aFrame;
|
2008-02-27 13:46:29 +03:00
|
|
|
|
|
|
|
mBidiEnabled = aFrame->PresContext()->BidiEnabled();
|
|
|
|
if (mBidiEnabled) {
|
|
|
|
// Find the containing block frame
|
|
|
|
nsIFrame* frame = aFrame;
|
2009-01-09 19:35:24 +03:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
while (frame &&
|
|
|
|
frame->IsFrameOfType(nsIFrame::eLineParticipant) &&
|
|
|
|
NS_FAILED(rv)) {
|
2008-02-27 13:46:29 +03:00
|
|
|
frame = frame->GetParent();
|
2009-01-09 19:35:24 +03:00
|
|
|
rv = frame->QueryInterface(kBlockFrameCID, (void**)&mBlockFrame);
|
2008-02-27 13:46:29 +03:00
|
|
|
}
|
2009-01-09 19:35:24 +03:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv) && mBlockFrame, "Cannot find containing block.");
|
2008-02-27 13:46:29 +03:00
|
|
|
|
|
|
|
mLineContinuationPoint = mContinuationPoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool AreOnSameLine(nsIFrame* aFrame1, nsIFrame* aFrame2) {
|
|
|
|
// Assumes that aFrame1 and aFrame2 are both decsendants of mBlockFrame.
|
|
|
|
PRBool isValid1, isValid2;
|
|
|
|
nsBlockInFlowLineIterator it1(mBlockFrame, aFrame1, &isValid1);
|
|
|
|
nsBlockInFlowLineIterator it2(mBlockFrame, aFrame2, &isValid2);
|
|
|
|
return isValid1 && isValid2 && it1.GetLine() == it2.GetLine();
|
2003-01-17 12:33:52 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-09-25 20:03:15 +04:00
|
|
|
/* Local functions */
|
|
|
|
static void DrawBorderImage(nsPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
const nsStyleBorder& aBorderStyle);
|
|
|
|
|
|
|
|
static void DrawBorderImageSide(gfxContext *aThebesContext,
|
|
|
|
nsIDeviceContext* aDeviceContext,
|
|
|
|
imgIContainer* aImage,
|
|
|
|
gfxRect& aDestRect,
|
2008-10-08 02:10:19 +04:00
|
|
|
gfxSize aInterSize,
|
2008-09-25 20:03:15 +04:00
|
|
|
gfxRect& aSourceRect,
|
|
|
|
PRUint8 aHFillType,
|
|
|
|
PRUint8 aVFillType);
|
|
|
|
|
|
|
|
static nscolor MakeBevelColor(PRIntn whichSide, PRUint8 style,
|
|
|
|
nscolor aBackgroundColor,
|
|
|
|
nscolor aBorderColor);
|
|
|
|
|
|
|
|
static gfxRect GetTextDecorationRectInternal(const gfxPoint& aPt,
|
|
|
|
const gfxSize& aLineSize,
|
|
|
|
const gfxFloat aAscent,
|
|
|
|
const gfxFloat aOffset,
|
|
|
|
const PRUint8 aDecoration,
|
|
|
|
const PRUint8 aStyle);
|
|
|
|
|
|
|
|
/* Returns FALSE iff all returned aTwipsRadii == 0, TRUE otherwise */
|
2008-10-01 09:50:52 +04:00
|
|
|
static PRBool GetBorderRadiusTwips(const nsStyleCorners& aBorderRadius,
|
2008-09-25 20:03:15 +04:00
|
|
|
const nscoord& aFrameWidth,
|
2008-10-01 09:50:52 +04:00
|
|
|
nscoord aTwipsRadii[8]);
|
2008-09-25 20:03:15 +04:00
|
|
|
|
2007-03-14 22:48:51 +03:00
|
|
|
static InlineBackgroundData* gInlineBGData = nsnull;
|
2003-01-17 12:33:52 +03:00
|
|
|
|
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-04-14 00:24:54 +04:00
|
|
|
/**
|
|
|
|
* Make a bevel color
|
|
|
|
*/
|
2008-09-25 20:03:15 +04:00
|
|
|
static nscolor
|
|
|
|
MakeBevelColor(PRIntn whichSide, PRUint8 style,
|
|
|
|
nscolor aBackgroundColor, 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;
|
|
|
|
}
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Thebes Border Rendering Code Start
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// helper function to convert a nsRect to a gfxRect
|
2007-05-30 06:46:54 +04:00
|
|
|
static gfxRect
|
|
|
|
RectToGfxRect(const nsRect& rect, nscoord twipsPerPixel)
|
|
|
|
{
|
|
|
|
return gfxRect(gfxFloat(rect.x) / twipsPerPixel,
|
|
|
|
gfxFloat(rect.y) / twipsPerPixel,
|
|
|
|
gfxFloat(rect.width) / twipsPerPixel,
|
|
|
|
gfxFloat(rect.height) / twipsPerPixel);
|
|
|
|
}
|
|
|
|
|
2007-05-01 07:31:25 +04:00
|
|
|
/*
|
2008-07-23 21:25:23 +04:00
|
|
|
* Compute the float-pixel radii that should be used for drawing
|
|
|
|
* this border/outline, given the various input bits.
|
2007-05-01 07:31:25 +04:00
|
|
|
*
|
2008-10-01 09:50:52 +04:00
|
|
|
* If a side is skipped via skipSides, its corners are forced to 0.
|
|
|
|
* All corner radii are then adjusted so they do not require more
|
|
|
|
* space than outerRect, according to the algorithm in css3-background.
|
2007-05-30 06:46:54 +04:00
|
|
|
*/
|
2007-05-01 07:31:25 +04:00
|
|
|
static void
|
2008-07-23 21:25:23 +04:00
|
|
|
ComputePixelRadii(const nscoord *aTwipsRadii,
|
|
|
|
const nsRect& outerRect,
|
|
|
|
PRIntn skipSides,
|
|
|
|
nscoord twipsPerPixel,
|
|
|
|
gfxCornerSizes *oBorderRadii)
|
2007-05-01 07:31:25 +04:00
|
|
|
{
|
2008-10-01 09:50:52 +04:00
|
|
|
nscoord twipsRadii[8];
|
|
|
|
memcpy(twipsRadii, aTwipsRadii, sizeof twipsRadii);
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
if (skipSides & SIDE_BIT_TOP) {
|
2008-10-01 09:50:52 +04:00
|
|
|
twipsRadii[NS_CORNER_TOP_LEFT_X] = 0;
|
|
|
|
twipsRadii[NS_CORNER_TOP_LEFT_Y] = 0;
|
|
|
|
twipsRadii[NS_CORNER_TOP_RIGHT_X] = 0;
|
|
|
|
twipsRadii[NS_CORNER_TOP_RIGHT_Y] = 0;
|
2007-05-30 06:46:54 +04:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
if (skipSides & SIDE_BIT_RIGHT) {
|
2008-10-01 09:50:52 +04:00
|
|
|
twipsRadii[NS_CORNER_TOP_RIGHT_X] = 0;
|
|
|
|
twipsRadii[NS_CORNER_TOP_RIGHT_Y] = 0;
|
|
|
|
twipsRadii[NS_CORNER_BOTTOM_RIGHT_X] = 0;
|
|
|
|
twipsRadii[NS_CORNER_BOTTOM_RIGHT_Y] = 0;
|
2007-05-30 06:46:54 +04:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
if (skipSides & SIDE_BIT_BOTTOM) {
|
2008-10-01 09:50:52 +04:00
|
|
|
twipsRadii[NS_CORNER_BOTTOM_RIGHT_X] = 0;
|
|
|
|
twipsRadii[NS_CORNER_BOTTOM_RIGHT_Y] = 0;
|
|
|
|
twipsRadii[NS_CORNER_BOTTOM_LEFT_X] = 0;
|
|
|
|
twipsRadii[NS_CORNER_BOTTOM_LEFT_Y] = 0;
|
2007-05-30 06:46:54 +04:00
|
|
|
}
|
2007-05-08 21:40:08 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
if (skipSides & SIDE_BIT_LEFT) {
|
2008-10-01 09:50:52 +04:00
|
|
|
twipsRadii[NS_CORNER_BOTTOM_LEFT_X] = 0;
|
|
|
|
twipsRadii[NS_CORNER_BOTTOM_LEFT_Y] = 0;
|
|
|
|
twipsRadii[NS_CORNER_TOP_LEFT_X] = 0;
|
|
|
|
twipsRadii[NS_CORNER_TOP_LEFT_Y] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat radii[8];
|
|
|
|
NS_FOR_CSS_HALF_CORNERS(corner)
|
|
|
|
radii[corner] = twipsRadii[corner] / twipsPerPixel;
|
|
|
|
|
|
|
|
// css3-background specifies this algorithm for reducing
|
|
|
|
// corner radii when they are too big.
|
|
|
|
gfxFloat maxWidth = outerRect.width / twipsPerPixel;
|
|
|
|
gfxFloat maxHeight = outerRect.height / twipsPerPixel;
|
|
|
|
gfxFloat f = 1.0f;
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
|
|
|
PRUint32 hc1 = NS_SIDE_TO_HALF_CORNER(side, PR_FALSE, PR_TRUE);
|
|
|
|
PRUint32 hc2 = NS_SIDE_TO_HALF_CORNER(side, PR_TRUE, PR_TRUE);
|
|
|
|
gfxFloat length = NS_SIDE_IS_VERTICAL(side) ? maxHeight : maxWidth;
|
|
|
|
gfxFloat sum = radii[hc1] + radii[hc2];
|
|
|
|
// avoid floating point division in the normal case
|
|
|
|
if (length < sum)
|
|
|
|
f = PR_MIN(f, length/sum);
|
|
|
|
}
|
|
|
|
if (f < 1.0) {
|
|
|
|
NS_FOR_CSS_HALF_CORNERS(corner) {
|
|
|
|
radii[corner] *= f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(*oBorderRadii)[C_TL] = gfxSize(radii[NS_CORNER_TOP_LEFT_X],
|
|
|
|
radii[NS_CORNER_TOP_LEFT_Y]);
|
|
|
|
(*oBorderRadii)[C_TR] = gfxSize(radii[NS_CORNER_TOP_RIGHT_X],
|
|
|
|
radii[NS_CORNER_TOP_RIGHT_Y]);
|
|
|
|
(*oBorderRadii)[C_BR] = gfxSize(radii[NS_CORNER_BOTTOM_RIGHT_X],
|
|
|
|
radii[NS_CORNER_BOTTOM_RIGHT_Y]);
|
|
|
|
(*oBorderRadii)[C_BL] = gfxSize(radii[NS_CORNER_BOTTOM_LEFT_X],
|
|
|
|
radii[NS_CORNER_BOTTOM_LEFT_Y]);
|
2007-05-30 06:46:54 +04:00
|
|
|
}
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
void
|
|
|
|
nsCSSRendering::PaintBorder(nsPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
const nsStyleBorder& aBorderStyle,
|
|
|
|
nsStyleContext* aStyleContext,
|
2008-08-06 14:33:18 +04:00
|
|
|
PRIntn aSkipSides)
|
2007-05-30 06:46:54 +04:00
|
|
|
{
|
2008-07-23 21:25:23 +04:00
|
|
|
nsMargin border;
|
2008-10-01 09:50:52 +04:00
|
|
|
nscoord twipsRadii[8];
|
2008-07-23 21:25:23 +04:00
|
|
|
nsCompatibility compatMode = aPresContext->CompatibilityMode();
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
SN("++ PaintBorder");
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// Check to see if we have an appearance defined. If so, we let the theme
|
|
|
|
// renderer draw the border. DO not get the data from aForFrame, since the passed in style context
|
|
|
|
// may be different! Always use |aStyleContext|!
|
|
|
|
const nsStyleDisplay* displayData = aStyleContext->GetStyleDisplay();
|
|
|
|
if (displayData->mAppearance) {
|
|
|
|
nsITheme *theme = aPresContext->GetTheme();
|
|
|
|
if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame, displayData->mAppearance))
|
|
|
|
return; // Let the theme handle it.
|
2007-05-30 06:46:54 +04:00
|
|
|
}
|
2007-05-08 21:40:08 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
if (aBorderStyle.IsBorderImageLoaded()) {
|
|
|
|
DrawBorderImage(aPresContext, aRenderingContext, aForFrame,
|
2008-08-06 14:33:18 +04:00
|
|
|
aBorderArea, aBorderStyle);
|
2008-07-23 21:25:23 +04:00
|
|
|
return;
|
2007-05-30 06:46:54 +04:00
|
|
|
}
|
2008-07-23 21:25:23 +04:00
|
|
|
|
|
|
|
// Get our style context's color struct.
|
|
|
|
const nsStyleColor* ourColor = aStyleContext->GetStyleColor();
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// in NavQuirks mode we want to use the parent's context as a starting point
|
|
|
|
// for determining the background color
|
2009-01-09 03:29:38 +03:00
|
|
|
nsStyleContext* bgContext = nsCSSRendering::FindNonTransparentBackground
|
2008-07-23 21:25:23 +04:00
|
|
|
(aStyleContext, compatMode == eCompatibility_NavQuirks ? PR_TRUE : PR_FALSE);
|
2009-01-09 03:29:38 +03:00
|
|
|
const nsStyleBackground* bgColor = bgContext->GetStyleBackground();
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2008-08-06 14:33:18 +04:00
|
|
|
border = aBorderStyle.GetComputedBorder();
|
2008-07-23 21:25:23 +04:00
|
|
|
if ((0 == border.left) && (0 == border.right) &&
|
|
|
|
(0 == border.top) && (0 == border.bottom)) {
|
|
|
|
// Empty border area
|
|
|
|
return;
|
2007-05-01 07:31:25 +04:00
|
|
|
}
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-10-01 09:50:52 +04:00
|
|
|
GetBorderRadiusTwips(aBorderStyle.mBorderRadius, aForFrame->GetSize().width,
|
|
|
|
twipsRadii);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// Turn off rendering for all of the zero sized sides
|
|
|
|
if (aSkipSides & SIDE_BIT_TOP) border.top = 0;
|
|
|
|
if (aSkipSides & SIDE_BIT_RIGHT) border.right = 0;
|
|
|
|
if (aSkipSides & SIDE_BIT_BOTTOM) border.bottom = 0;
|
|
|
|
if (aSkipSides & SIDE_BIT_LEFT) border.left = 0;
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// get the inside and outside parts of the border
|
|
|
|
nsRect outerRect(aBorderArea);
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
SF(" outerRect: %d %d %d %d\n", outerRect.x, outerRect.y, outerRect.width, outerRect.height);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// we can assume that we're already clipped to aDirtyRect -- I think? (!?)
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// Get our conversion values
|
|
|
|
nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// convert outer and inner rects
|
|
|
|
gfxRect oRect(RectToGfxRect(outerRect, twipsPerPixel));
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// convert the border widths
|
|
|
|
gfxFloat borderWidths[4] = { border.top / twipsPerPixel,
|
|
|
|
border.right / twipsPerPixel,
|
|
|
|
border.bottom / twipsPerPixel,
|
|
|
|
border.left / twipsPerPixel };
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// convert the radii
|
|
|
|
gfxCornerSizes borderRadii;
|
2008-10-01 09:50:52 +04:00
|
|
|
ComputePixelRadii(twipsRadii, outerRect, aSkipSides, twipsPerPixel,
|
|
|
|
&borderRadii);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
PRUint8 borderStyles[4];
|
|
|
|
nscolor borderColors[4];
|
|
|
|
nsBorderColors *compositeColors[4];
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// pull out styles, colors, composite colors
|
|
|
|
NS_FOR_CSS_SIDES (i) {
|
2008-09-12 19:35:53 +04:00
|
|
|
PRBool foreground;
|
2008-07-23 21:25:23 +04:00
|
|
|
borderStyles[i] = aBorderStyle.GetBorderStyle(i);
|
2008-09-12 19:35:53 +04:00
|
|
|
aBorderStyle.GetBorderColor(i, borderColors[i], foreground);
|
2008-07-23 21:25:23 +04:00
|
|
|
aBorderStyle.GetCompositeColors(i, &compositeColors[i]);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-09-12 19:35:53 +04:00
|
|
|
if (foreground)
|
2008-07-23 21:25:23 +04:00
|
|
|
borderColors[i] = ourColor->mColor;
|
2007-05-30 06:46:54 +04:00
|
|
|
}
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
SF(" borderStyles: %d %d %d %d\n", borderStyles[0], borderStyles[1], borderStyles[2], borderStyles[3]);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// start drawing
|
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
ctx->Save();
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
#if 0
|
|
|
|
// this will draw a transparent red backround underneath the oRect area
|
|
|
|
ctx->Save();
|
|
|
|
ctx->Rectangle(oRect);
|
|
|
|
ctx->SetColor(gfxRGBA(1.0, 0.0, 0.0, 0.5));
|
|
|
|
ctx->Fill();
|
|
|
|
ctx->Restore();
|
|
|
|
#endif
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
//SF ("borderRadii: %f %f %f %f\n", borderRadii[0], borderRadii[1], borderRadii[2], borderRadii[3]);
|
|
|
|
|
|
|
|
nsCSSBorderRenderer br(twipsPerPixel,
|
|
|
|
ctx,
|
|
|
|
oRect,
|
|
|
|
borderStyles,
|
|
|
|
borderWidths,
|
|
|
|
borderRadii,
|
|
|
|
borderColors,
|
|
|
|
compositeColors,
|
|
|
|
aSkipSides,
|
2008-08-06 14:33:18 +04:00
|
|
|
bgColor->mBackgroundColor);
|
2008-07-23 21:25:23 +04:00
|
|
|
br.DrawBorders();
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
ctx->Restore();
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
SN();
|
2007-05-30 06:46:54 +04:00
|
|
|
}
|
2007-05-01 07:31:25 +04:00
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
static nsRect
|
|
|
|
GetOutlineInnerRect(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsRect* savedOutlineInnerRect = static_cast<nsRect*>
|
|
|
|
(aFrame->GetProperty(nsGkAtoms::outlineInnerRectProperty));
|
|
|
|
if (savedOutlineInnerRect)
|
|
|
|
return *savedOutlineInnerRect;
|
|
|
|
return aFrame->GetOverflowRect();
|
|
|
|
}
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
void
|
|
|
|
nsCSSRendering::PaintOutline(nsPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
const nsStyleBorder& aBorderStyle,
|
|
|
|
const nsStyleOutline& aOutlineStyle,
|
2008-08-06 14:33:18 +04:00
|
|
|
nsStyleContext* aStyleContext)
|
2007-05-30 06:46:54 +04:00
|
|
|
{
|
2008-10-01 09:50:52 +04:00
|
|
|
nscoord twipsRadii[8];
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// Get our style context's color struct.
|
|
|
|
const nsStyleColor* ourColor = aStyleContext->GetStyleColor();
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
nscoord width;
|
|
|
|
aOutlineStyle.GetOutlineWidth(width);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
if (width == 0) {
|
|
|
|
// Empty outline
|
|
|
|
return;
|
2007-05-30 06:46:54 +04:00
|
|
|
}
|
|
|
|
|
2009-01-09 03:29:38 +03:00
|
|
|
nsStyleContext* bgContext = nsCSSRendering::FindNonTransparentBackground
|
2008-07-23 21:25:23 +04:00
|
|
|
(aStyleContext, PR_FALSE);
|
2009-01-09 03:29:38 +03:00
|
|
|
const nsStyleBackground* bgColor = bgContext->GetStyleBackground();
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// get the radius for our outline
|
2008-10-01 09:50:52 +04:00
|
|
|
GetBorderRadiusTwips(aOutlineStyle.mOutlineRadius, aBorderArea.width,
|
|
|
|
twipsRadii);
|
2007-05-30 06:46:54 +04:00
|
|
|
|
2008-06-03 02:52:25 +04:00
|
|
|
// When the outline property is set on :-moz-anonymous-block or
|
|
|
|
// :-moz-anonyomus-positioned-block pseudo-elements, it inherited that
|
|
|
|
// outline from the inline that was broken because it contained a
|
|
|
|
// block. In that case, we don't want a really wide outline if the
|
|
|
|
// block inside the inline is narrow, so union the actual contents of
|
|
|
|
// the anonymous blocks.
|
|
|
|
nsIFrame *frameForArea = aForFrame;
|
|
|
|
do {
|
|
|
|
nsIAtom *pseudoType = frameForArea->GetStyleContext()->GetPseudoType();
|
|
|
|
if (pseudoType != nsCSSAnonBoxes::mozAnonymousBlock &&
|
|
|
|
pseudoType != nsCSSAnonBoxes::mozAnonymousPositionedBlock)
|
|
|
|
break;
|
|
|
|
// If we're done, we really want it and all its later siblings.
|
|
|
|
frameForArea = frameForArea->GetFirstChild(nsnull);
|
|
|
|
NS_ASSERTION(frameForArea, "anonymous block with no children?");
|
|
|
|
} while (frameForArea);
|
2008-09-11 04:24:16 +04:00
|
|
|
nsRect innerRect; // relative to aBorderArea.TopLeft()
|
2008-06-03 02:52:25 +04:00
|
|
|
if (frameForArea == aForFrame) {
|
2008-09-11 04:24:16 +04:00
|
|
|
innerRect = GetOutlineInnerRect(aForFrame);
|
2008-06-03 02:52:25 +04:00
|
|
|
} else {
|
|
|
|
for (; frameForArea; frameForArea = frameForArea->GetNextSibling()) {
|
|
|
|
// The outline has already been included in aForFrame's overflow
|
|
|
|
// area, but not in those of its descendants, so we have to
|
|
|
|
// include it. Otherwise we'll end up drawing the outline inside
|
|
|
|
// the border.
|
2008-09-11 04:24:16 +04:00
|
|
|
nsRect r(GetOutlineInnerRect(frameForArea) +
|
2008-06-03 02:52:25 +04:00
|
|
|
frameForArea->GetOffsetTo(aForFrame));
|
2008-09-11 04:24:16 +04:00
|
|
|
innerRect.UnionRect(innerRect, r);
|
2008-06-03 02:52:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
innerRect += aBorderArea.TopLeft();
|
2008-09-13 07:45:37 +04:00
|
|
|
nscoord offset = aOutlineStyle.mOutlineOffset;
|
2008-09-11 04:24:16 +04:00
|
|
|
innerRect.Inflate(offset, offset);
|
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.
|
2008-09-11 04:24:16 +04:00
|
|
|
if (innerRect.Contains(aDirtyRect))
|
2007-05-01 07:31:25 +04:00
|
|
|
return;
|
2008-09-11 04:24:16 +04:00
|
|
|
|
|
|
|
nsRect outerRect = innerRect;
|
|
|
|
outerRect.Inflate(width, width);
|
2000-02-01 19:03:13 +03:00
|
|
|
|
2007-05-30 06:46:54 +04:00
|
|
|
// Get our conversion values
|
2007-05-01 07:31:25 +04:00
|
|
|
nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// get the outer rectangles
|
2007-05-30 06:46:54 +04:00
|
|
|
gfxRect oRect(RectToGfxRect(outerRect, twipsPerPixel));
|
1999-08-19 18:22:47 +04:00
|
|
|
|
2007-05-30 06:46:54 +04:00
|
|
|
// convert the radii
|
2007-07-18 18:14:53 +04:00
|
|
|
nsMargin outlineMargin(width, width, width, width);
|
2008-07-23 21:25:23 +04:00
|
|
|
gfxCornerSizes outlineRadii;
|
2008-10-01 09:50:52 +04:00
|
|
|
ComputePixelRadii(twipsRadii, outerRect, 0, twipsPerPixel,
|
|
|
|
&outlineRadii);
|
1999-08-19 18:22:47 +04:00
|
|
|
|
2007-05-30 06:46:54 +04:00
|
|
|
PRUint8 outlineStyle = aOutlineStyle.GetOutlineStyle();
|
|
|
|
PRUint8 outlineStyles[4] = { outlineStyle,
|
|
|
|
outlineStyle,
|
|
|
|
outlineStyle,
|
|
|
|
outlineStyle };
|
2007-05-21 02:41:21 +04:00
|
|
|
|
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;
|
2007-05-30 06:46:54 +04:00
|
|
|
nscolor outlineColors[4] = { outlineColor,
|
|
|
|
outlineColor,
|
|
|
|
outlineColor,
|
|
|
|
outlineColor };
|
2007-05-01 08:58:44 +04:00
|
|
|
|
2007-05-30 06:46:54 +04:00
|
|
|
// convert the border widths
|
|
|
|
gfxFloat outlineWidths[4] = { width / twipsPerPixel,
|
|
|
|
width / twipsPerPixel,
|
|
|
|
width / twipsPerPixel,
|
|
|
|
width / twipsPerPixel };
|
1999-08-19 18:22:47 +04:00
|
|
|
|
2007-05-30 06:46:54 +04:00
|
|
|
// start drawing
|
2008-06-04 02:25:31 +04:00
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
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
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
nsCSSBorderRenderer br(twipsPerPixel,
|
|
|
|
ctx,
|
|
|
|
oRect,
|
|
|
|
outlineStyles,
|
|
|
|
outlineWidths,
|
|
|
|
outlineRadii,
|
|
|
|
outlineColors,
|
2008-08-06 14:33:18 +04:00
|
|
|
nsnull, 0,
|
|
|
|
bgColor->mBackgroundColor);
|
|
|
|
br.DrawBorders();
|
|
|
|
|
|
|
|
ctx->Restore();
|
|
|
|
|
|
|
|
SN();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSRendering::PaintFocus(nsPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aFocusRect,
|
|
|
|
nscolor aColor)
|
|
|
|
{
|
|
|
|
nscoord oneCSSPixel = nsPresContext::CSSPixelsToAppUnits(1);
|
|
|
|
nscoord oneDevPixel = aPresContext->DevPixelsToAppUnits(1);
|
|
|
|
|
|
|
|
gfxRect focusRect(RectToGfxRect(aFocusRect, oneDevPixel));
|
|
|
|
|
|
|
|
gfxCornerSizes focusRadii;
|
|
|
|
{
|
2008-10-01 09:50:52 +04:00
|
|
|
nscoord twipsRadii[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
|
|
ComputePixelRadii(twipsRadii, aFocusRect, 0, oneDevPixel, &focusRadii);
|
2008-08-06 14:33:18 +04:00
|
|
|
}
|
|
|
|
gfxFloat focusWidths[4] = { oneCSSPixel / oneDevPixel,
|
|
|
|
oneCSSPixel / oneDevPixel,
|
|
|
|
oneCSSPixel / oneDevPixel,
|
|
|
|
oneCSSPixel / oneDevPixel };
|
|
|
|
|
|
|
|
PRUint8 focusStyles[4] = { NS_STYLE_BORDER_STYLE_DOTTED,
|
|
|
|
NS_STYLE_BORDER_STYLE_DOTTED,
|
|
|
|
NS_STYLE_BORDER_STYLE_DOTTED,
|
|
|
|
NS_STYLE_BORDER_STYLE_DOTTED };
|
|
|
|
nscolor focusColors[4] = { aColor, aColor, aColor, aColor };
|
|
|
|
|
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
|
|
|
|
|
|
|
ctx->Save();
|
|
|
|
|
|
|
|
// Because this renders a dotted border, the background color
|
|
|
|
// should not be used. Therefore, we provide a value that will
|
|
|
|
// be blatantly wrong if it ever does get used. (If this becomes
|
|
|
|
// something that CSS can style, this function will then have access
|
|
|
|
// to a style context and can use the same logic that PaintBorder
|
|
|
|
// and PaintOutline do.)
|
|
|
|
nsCSSBorderRenderer br(oneDevPixel,
|
|
|
|
ctx,
|
|
|
|
focusRect,
|
|
|
|
focusStyles,
|
|
|
|
focusWidths,
|
|
|
|
focusRadii,
|
|
|
|
focusColors,
|
|
|
|
nsnull, 0,
|
|
|
|
NS_RGB(255, 0, 0));
|
2008-07-23 21:25:23 +04:00
|
|
|
br.DrawBorders();
|
2007-05-01 07:31:25 +04:00
|
|
|
|
|
|
|
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
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
/**
|
|
|
|
* Computes the placement of a background image.
|
|
|
|
*
|
|
|
|
* @param aOriginBounds is the box to which the tiling position should be
|
|
|
|
* relative
|
|
|
|
* This should correspond to 'background-origin' for the frame,
|
|
|
|
* except when painting on the canvas, in which case the origin bounds
|
|
|
|
* should be the bounds of the root element's frame.
|
|
|
|
* @param aTopLeft the top-left corner where an image tile should be drawn
|
|
|
|
* @param aAnchorPoint a point which should be pixel-aligned by
|
|
|
|
* nsLayoutUtils::DrawImage. This is the same as aTopLeft, unless CSS
|
|
|
|
* specifies a percentage (including 'right' or 'bottom'), in which case
|
|
|
|
* it's that percentage within of aOriginBounds. So 'right' would set
|
|
|
|
* aAnchorPoint.x to aOriginBounds.XMost().
|
|
|
|
*
|
|
|
|
* Points are returned relative to aOriginBounds.
|
|
|
|
*/
|
1998-12-12 06:06:02 +03:00
|
|
|
static void
|
2001-06-01 02:19:43 +04:00
|
|
|
ComputeBackgroundAnchorPoint(const nsStyleBackground& aColor,
|
2008-11-05 01:01:21 +03:00
|
|
|
const nsSize& aOriginBounds,
|
|
|
|
const nsSize& aImageSize,
|
|
|
|
nsPoint* aTopLeft,
|
|
|
|
nsPoint* aAnchorPoint)
|
1998-09-26 21:16:56 +04:00
|
|
|
{
|
1998-10-27 19:50:19 +03:00
|
|
|
if (NS_STYLE_BG_X_POSITION_LENGTH & aColor.mBackgroundFlags) {
|
2008-11-05 01:01:21 +03:00
|
|
|
aTopLeft->x = aAnchorPoint->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) {
|
2008-11-05 01:01:21 +03:00
|
|
|
double percent = aColor.mBackgroundXPosition.mFloat;
|
|
|
|
aAnchorPoint->x = NSToCoordRound(percent*aOriginBounds.width);
|
|
|
|
aTopLeft->x = NSToCoordRound(percent*(aOriginBounds.width - aImageSize.width));
|
1998-10-27 19:50:19 +03:00
|
|
|
}
|
2003-01-19 05:36:04 +03:00
|
|
|
else {
|
2008-11-05 01:01:21 +03:00
|
|
|
aTopLeft->x = aAnchorPoint->x = 0;
|
2003-01-19 05:36:04 +03:00
|
|
|
}
|
1999-04-29 22:29:56 +04:00
|
|
|
|
1998-10-27 19:50:19 +03:00
|
|
|
if (NS_STYLE_BG_Y_POSITION_LENGTH & aColor.mBackgroundFlags) {
|
2008-11-05 01:01:21 +03:00
|
|
|
aTopLeft->y = aAnchorPoint->y = aColor.mBackgroundYPosition.mCoord;
|
1998-10-27 19:50:19 +03:00
|
|
|
}
|
2008-11-05 01:01:21 +03:00
|
|
|
else if (NS_STYLE_BG_Y_POSITION_PERCENT & aColor.mBackgroundFlags) {
|
|
|
|
double percent = aColor.mBackgroundYPosition.mFloat;
|
|
|
|
aAnchorPoint->y = NSToCoordRound(percent*aOriginBounds.height);
|
|
|
|
aTopLeft->y = NSToCoordRound(percent*(aOriginBounds.height - aImageSize.height));
|
1998-10-27 19:50:19 +03:00
|
|
|
}
|
2003-01-19 05:36:04 +03:00
|
|
|
else {
|
2008-11-05 01:01:21 +03:00
|
|
|
aTopLeft->y = aAnchorPoint->y = 0;
|
1998-09-26 21:16:56 +04:00
|
|
|
}
|
1999-04-25 06:43:50 +04:00
|
|
|
}
|
|
|
|
|
2009-01-09 03:29:38 +03:00
|
|
|
nsStyleContext*
|
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" );
|
|
|
|
|
|
|
|
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) {
|
2009-01-09 03:29:38 +03:00
|
|
|
const nsStyleBackground* bg = context->GetStyleBackground();
|
|
|
|
if (NS_GET_A(bg->mBackgroundColor) > 0)
|
2002-08-11 21:56:15 +04:00
|
|
|
break;
|
|
|
|
|
2009-01-09 03:29:38 +03:00
|
|
|
const nsStyleDisplay* display = context->GetStyleDisplay();
|
|
|
|
if (display->mAppearance)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsStyleContext* parent = context->GetParent();
|
|
|
|
if (!parent)
|
|
|
|
break;
|
|
|
|
|
|
|
|
context = parent;
|
2002-08-11 21:56:15 +04:00
|
|
|
}
|
2009-01-09 03:29:38 +03:00
|
|
|
return context;
|
2002-08-11 21:56:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2008-08-08 12:21:13 +04:00
|
|
|
// Returns true if aFrame is a canvas frame.
|
2003-04-06 06:49:40 +04:00
|
|
|
// 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.
|
2008-08-08 12:21:13 +04:00
|
|
|
inline PRBool
|
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();
|
2008-08-08 12:21:13 +04:00
|
|
|
return frameType == nsGkAtoms::canvasFrame ||
|
|
|
|
frameType == nsGkAtoms::rootFrame ||
|
|
|
|
frameType == nsGkAtoms::pageFrame ||
|
|
|
|
frameType == nsGkAtoms::pageContentFrame ||
|
|
|
|
frameType == nsGkAtoms::viewportFrame;
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline PRBool
|
2008-08-08 12:21:13 +04:00
|
|
|
FindCanvasBackground(nsIFrame* aForFrame, nsIFrame* aRootElementFrame,
|
2002-01-08 02:46:07 +03:00
|
|
|
const nsStyleBackground** aBackground)
|
|
|
|
{
|
2008-08-08 12:21:13 +04:00
|
|
|
if (aRootElementFrame) {
|
|
|
|
const nsStyleBackground* result = aRootElementFrame->GetStyleBackground();
|
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()) {
|
2008-08-08 12:21:13 +04:00
|
|
|
nsIContent* content = aRootElementFrame->GetContent();
|
|
|
|
// The root element content can't be null. We wouldn't know what
|
|
|
|
// frame to create for aRootElementFrame.
|
|
|
|
// Use |GetOwnerDoc| so it works during destruction.
|
|
|
|
nsIDocument* document = content->GetOwnerDoc();
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(document);
|
|
|
|
if (htmlDoc) {
|
|
|
|
nsIContent* bodyContent = htmlDoc->GetBodyContentExternal();
|
|
|
|
// 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) {
|
|
|
|
nsIFrame *bodyFrame = aForFrame->PresContext()->GetPresShell()->
|
|
|
|
GetPrimaryFrameFor(bodyContent);
|
|
|
|
if (bodyFrame)
|
|
|
|
result = bodyFrame->GetStyleBackground();
|
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
|
2008-08-08 12:21:13 +04:00
|
|
|
FindElementBackground(nsIFrame* aForFrame, nsIFrame* aRootElementFrame,
|
2002-01-08 02:46:07 +03:00
|
|
|
const nsStyleBackground** aBackground)
|
|
|
|
{
|
2008-08-08 12:21:13 +04:00
|
|
|
if (aForFrame == aRootElementFrame) {
|
|
|
|
// We must have propagated our background to the viewport or canvas. Abort.
|
|
|
|
return PR_FALSE;
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
|
2008-08-08 07:34:43 +04:00
|
|
|
nsIContent* content = aForFrame->GetContent();
|
2008-08-08 12:21:13 +04:00
|
|
|
if (!content || content->Tag() != nsGkAtoms::body)
|
|
|
|
return PR_TRUE; // not frame for a "body" element
|
|
|
|
// It could be a non-HTML "body" element but that's OK, we'd fail the
|
|
|
|
// bodyContent check below
|
2008-08-08 07:34:43 +04:00
|
|
|
|
2008-08-08 12:21:13 +04:00
|
|
|
if (aForFrame->GetStyleContext()->GetPseudoType())
|
|
|
|
return PR_TRUE; // A pseudo-element frame.
|
2008-08-08 07:34:43 +04: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();
|
2008-02-19 21:47:34 +03:00
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(document);
|
2002-02-26 01:18:26 +03:00
|
|
|
if (!htmlDoc)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2008-02-19 21:47:34 +03:00
|
|
|
nsIContent* bodyContent = htmlDoc->GetBodyContentExternal();
|
2005-11-04 02:06:54 +03:00
|
|
|
if (bodyContent != content)
|
|
|
|
return PR_TRUE; // this wasn't the background that was propagated
|
|
|
|
|
2008-08-08 12:21:13 +04:00
|
|
|
// This can be called even when there's no root element yet, during frame
|
|
|
|
// construction, via nsLayoutUtils::FrameHasTransparency and
|
|
|
|
// nsContainerFrame::SyncFrameViewProperties.
|
|
|
|
if (!aRootElementFrame)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
const nsStyleBackground* htmlBG = aRootElementFrame->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)
|
|
|
|
{
|
2008-08-08 12:21:13 +04:00
|
|
|
nsIFrame* rootElementFrame =
|
|
|
|
aPresContext->PresShell()->FrameConstructor()->GetRootElementStyleFrame();
|
|
|
|
PRBool isCanvasFrame = IsCanvasFrame(aForFrame);
|
|
|
|
*aIsCanvas = isCanvasFrame;
|
|
|
|
return isCanvasFrame
|
|
|
|
? FindCanvasBackground(aForFrame, rootElementFrame, aBackground)
|
|
|
|
: FindElementBackground(aForFrame, rootElementFrame, 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
|
|
|
}
|
|
|
|
|
2008-09-25 20:03:15 +04:00
|
|
|
static PRBool
|
2008-10-01 09:50:52 +04:00
|
|
|
GetBorderRadiusTwips(const nsStyleCorners& aBorderRadius,
|
|
|
|
const nscoord& aFrameWidth, nscoord aTwipsRadii[8])
|
2008-07-08 04:57:47 +04:00
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
2008-10-01 09:50:52 +04:00
|
|
|
|
2008-07-08 04:57:47 +04:00
|
|
|
// Convert percentage values
|
2008-10-01 09:50:52 +04:00
|
|
|
NS_FOR_CSS_HALF_CORNERS(i) {
|
|
|
|
const nsStyleCoord c = aBorderRadius.Get(i);
|
2008-07-08 04:57:47 +04:00
|
|
|
|
2008-10-01 09:50:52 +04:00
|
|
|
switch (c.GetUnit()) {
|
2008-07-08 04:57:47 +04:00
|
|
|
case eStyleUnit_Percent:
|
2008-10-01 09:50:52 +04:00
|
|
|
aTwipsRadii[i] = (nscoord)(c.GetPercentValue() * aFrameWidth);
|
2008-07-08 04:57:47 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Coord:
|
2008-10-01 09:50:52 +04:00
|
|
|
aTwipsRadii[i] = c.GetCoordValue();
|
2008-07-08 04:57:47 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-10-01 09:50:52 +04:00
|
|
|
NS_NOTREACHED("GetBorderRadiusTwips: bad unit");
|
|
|
|
aTwipsRadii[i] = 0;
|
2008-07-08 04:57:47 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aTwipsRadii[i])
|
|
|
|
result = PR_TRUE;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSRendering::PaintBoxShadow(nsPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame,
|
2008-12-03 00:16:22 +03:00
|
|
|
const nsPoint& aForFramePt,
|
|
|
|
const nsRect& aDirtyRect)
|
2008-07-08 04:57:47 +04:00
|
|
|
{
|
|
|
|
nsMargin borderValues;
|
|
|
|
PRIntn sidesToSkip;
|
|
|
|
nsRect frameRect;
|
|
|
|
|
|
|
|
const nsStyleBorder* styleBorder = aForFrame->GetStyleBorder();
|
2008-07-17 10:30:25 +04:00
|
|
|
borderValues = styleBorder->GetActualBorder();
|
2008-07-08 04:57:47 +04:00
|
|
|
sidesToSkip = aForFrame->GetSkipSides();
|
|
|
|
frameRect = nsRect(aForFramePt, aForFrame->GetSize());
|
|
|
|
|
|
|
|
// Get any border radius, since box-shadow must also have rounded corners if the frame does
|
2008-10-01 09:50:52 +04:00
|
|
|
nscoord twipsRadii[8];
|
|
|
|
PRBool hasBorderRadius = GetBorderRadiusTwips(styleBorder->mBorderRadius,
|
|
|
|
frameRect.width, twipsRadii);
|
2008-07-08 04:57:47 +04:00
|
|
|
nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
|
2008-07-23 21:25:23 +04:00
|
|
|
|
|
|
|
gfxCornerSizes borderRadii;
|
2008-10-01 09:50:52 +04:00
|
|
|
ComputePixelRadii(twipsRadii, frameRect, sidesToSkip,
|
|
|
|
twipsPerPixel, &borderRadii);
|
2008-07-08 04:57:47 +04:00
|
|
|
|
|
|
|
gfxRect frameGfxRect = RectToGfxRect(frameRect, twipsPerPixel);
|
2009-01-05 03:41:01 +03:00
|
|
|
frameGfxRect.Round();
|
2008-12-03 00:16:22 +03:00
|
|
|
gfxRect dirtyGfxRect = RectToGfxRect(aDirtyRect, twipsPerPixel);
|
|
|
|
|
2008-07-08 04:57:47 +04:00
|
|
|
for (PRUint32 i = styleBorder->mBoxShadow->Length(); i > 0; --i) {
|
|
|
|
nsCSSShadowItem* shadowItem = styleBorder->mBoxShadow->ShadowAt(i - 1);
|
|
|
|
gfxRect shadowRect(frameRect.x, frameRect.y, frameRect.width, frameRect.height);
|
2008-09-13 07:45:37 +04:00
|
|
|
shadowRect.MoveBy(gfxPoint(shadowItem->mXOffset, shadowItem->mYOffset));
|
|
|
|
shadowRect.Outset(shadowItem->mSpread);
|
2008-07-08 04:57:47 +04:00
|
|
|
|
|
|
|
gfxRect shadowRectPlusBlur = shadowRect;
|
|
|
|
shadowRect.ScaleInverse(twipsPerPixel);
|
2009-01-05 03:41:01 +03:00
|
|
|
shadowRect.Round();
|
2008-07-08 04:57:47 +04:00
|
|
|
|
|
|
|
// shadowRect won't include the blur, so make an extra rect here that includes the blur
|
|
|
|
// for use in the even-odd rule below.
|
2008-09-13 07:45:37 +04:00
|
|
|
nscoord blurRadius = shadowItem->mRadius;
|
2008-07-08 04:57:47 +04:00
|
|
|
shadowRectPlusBlur.Outset(blurRadius);
|
|
|
|
shadowRectPlusBlur.ScaleInverse(twipsPerPixel);
|
|
|
|
shadowRectPlusBlur.RoundOut();
|
|
|
|
|
|
|
|
gfxContext* renderContext = aRenderingContext.ThebesContext();
|
|
|
|
nsRefPtr<gfxContext> shadowContext;
|
|
|
|
nsContextBoxBlur blurringArea;
|
|
|
|
|
2008-12-03 00:16:22 +03:00
|
|
|
// shadowRect is already in device pixels, pass 1 as the appunits/pixel value
|
2008-07-08 04:57:47 +04:00
|
|
|
blurRadius /= twipsPerPixel;
|
2008-12-03 00:16:22 +03:00
|
|
|
shadowContext = blurringArea.Init(shadowRect, blurRadius, 1, renderContext, dirtyGfxRect);
|
2008-07-08 04:57:47 +04:00
|
|
|
if (!shadowContext)
|
2008-08-13 10:27:47 +04:00
|
|
|
continue;
|
2008-07-08 04:57:47 +04:00
|
|
|
|
|
|
|
// Set the shadow color; if not specified, use the foreground color
|
|
|
|
nscolor shadowColor;
|
|
|
|
if (shadowItem->mHasColor)
|
|
|
|
shadowColor = shadowItem->mColor;
|
|
|
|
else
|
|
|
|
shadowColor = aForFrame->GetStyleColor()->mColor;
|
|
|
|
|
|
|
|
renderContext->Save();
|
|
|
|
renderContext->SetColor(gfxRGBA(shadowColor));
|
|
|
|
|
|
|
|
// Clip out the area of the actual frame so the shadow is not shown within
|
|
|
|
// the frame
|
|
|
|
renderContext->NewPath();
|
|
|
|
renderContext->Rectangle(shadowRectPlusBlur);
|
|
|
|
if (hasBorderRadius)
|
2008-07-23 21:25:23 +04:00
|
|
|
renderContext->RoundedRectangle(frameGfxRect, borderRadii);
|
2008-07-08 04:57:47 +04:00
|
|
|
else
|
|
|
|
renderContext->Rectangle(frameGfxRect);
|
|
|
|
renderContext->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
|
|
|
|
renderContext->Clip();
|
|
|
|
|
|
|
|
// Draw the shape of the frame so it can be blurred. Recall how nsContextBoxBlur
|
|
|
|
// doesn't make any temporary surfaces if blur is 0 and it just returns the original
|
|
|
|
// surface? If we have no blur, we're painting this fill on the actual content surface
|
|
|
|
// (renderContext == shadowContext) which is why we set up the color and clip
|
|
|
|
// before doing this.
|
|
|
|
shadowContext->NewPath();
|
|
|
|
if (hasBorderRadius)
|
2008-07-23 21:25:23 +04:00
|
|
|
shadowContext->RoundedRectangle(shadowRect, borderRadii);
|
2008-07-08 04:57:47 +04:00
|
|
|
else
|
|
|
|
shadowContext->Rectangle(shadowRect);
|
|
|
|
shadowContext->Fill();
|
|
|
|
|
|
|
|
blurringArea.DoPaint();
|
|
|
|
renderContext->Restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
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;
|
2008-09-24 08:07:22 +04:00
|
|
|
const nsStyleBorder* border = aForFrame->GetStyleBorder();
|
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,
|
2008-09-24 08:07:22 +04:00
|
|
|
aDirtyRect, aBorderArea, *color, *border,
|
2008-09-25 19:53:27 +04:00
|
|
|
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
|
|
|
|
2008-09-12 19:36:53 +04:00
|
|
|
if (NS_GET_A(canvasColor.mBackgroundColor) < 255) {
|
|
|
|
// If the window is intended to be opaque, ensure that we always
|
|
|
|
// paint an opaque color for its root element, in case there's no
|
|
|
|
// background at all or a partly transparent image.
|
|
|
|
nsIView* rView;
|
|
|
|
vm->GetRootView(rView);
|
|
|
|
if (!rView->GetParent() &&
|
|
|
|
(!rView->HasWidget() ||
|
|
|
|
rView->GetWidget()->GetTransparencyMode() == eTransparencyOpaque)) {
|
2008-09-19 21:06:46 +04:00
|
|
|
nscolor backColor = aPresContext->DefaultBackgroundColor();
|
|
|
|
NS_ASSERTION(NS_GET_A(backColor) == 255,
|
|
|
|
"default background color is not opaque");
|
2008-09-12 19:36:53 +04:00
|
|
|
|
|
|
|
canvasColor.mBackgroundColor =
|
|
|
|
NS_ComposeColors(backColor, canvasColor.mBackgroundColor);
|
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,
|
2008-09-25 19:53:27 +04:00
|
|
|
*border, aUsePrintSettings, aBGClipRect);
|
2002-01-08 02:46:07 +03:00
|
|
|
}
|
|
|
|
|
2008-08-13 07:11:35 +04:00
|
|
|
static PRBool
|
|
|
|
IsSolidBorderEdge(const nsStyleBorder& aBorder, PRUint32 aSide)
|
|
|
|
{
|
|
|
|
if (aBorder.GetActualBorder().side(aSide) == 0)
|
|
|
|
return PR_TRUE;
|
|
|
|
if (aBorder.GetBorderStyle(aSide) != NS_STYLE_BORDER_STYLE_SOLID)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-10-30 12:24:58 +03:00
|
|
|
// If we're using a border image, assume it's not fully opaque,
|
|
|
|
// because we may not even have the image loaded at this point, and
|
|
|
|
// even if we did, checking whether the relevant tile is fully
|
|
|
|
// opaque would be too much work.
|
|
|
|
if (aBorder.GetBorderImage())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-08-13 07:11:35 +04:00
|
|
|
nscolor color;
|
|
|
|
PRBool isForeground;
|
2008-09-12 19:35:53 +04:00
|
|
|
aBorder.GetBorderColor(aSide, color, isForeground);
|
2008-10-30 12:24:58 +03:00
|
|
|
|
|
|
|
// We don't know the foreground color here, so if it's being used
|
|
|
|
// we must assume it might be transparent.
|
|
|
|
if (isForeground)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-09-12 19:35:53 +04:00
|
|
|
return NS_GET_A(color) == 255;
|
2008-08-13 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if all border edges are either missing or opaque.
|
|
|
|
*/
|
|
|
|
static PRBool
|
|
|
|
IsSolidBorder(const nsStyleBorder& aBorder)
|
|
|
|
{
|
2009-01-09 03:28:32 +03:00
|
|
|
if (aBorder.mBorderColors)
|
2008-08-13 07:11:35 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
for (PRUint32 i = 0; i < 4; ++i) {
|
|
|
|
if (!IsSolidBorderEdge(aBorder, i))
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
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,
|
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
|
|
|
|
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.
|
2009-01-09 03:28:32 +03:00
|
|
|
// XXXzw this ignores aBGClipRect.
|
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();
|
2009-01-09 03:28:32 +03:00
|
|
|
if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame,
|
|
|
|
displayData->mAppearance)) {
|
2006-01-26 05:29:17 +03:00
|
|
|
nsRect dirty;
|
2008-07-27 20:08:51 +04:00
|
|
|
dirty.IntersectRect(aDirtyRect, aBorderArea);
|
2001-12-18 01:51:39 +03:00
|
|
|
theme->DrawWidgetBackground(&aRenderingContext, aForFrame,
|
2008-07-27 20:08:51 +04:00
|
|
|
displayData->mAppearance, aBorderArea, dirty);
|
2001-12-18 01:51:39 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-09 03:28:32 +03:00
|
|
|
// Determine whether we are drawing background images and/or
|
|
|
|
// background colors.
|
|
|
|
PRBool drawBackgroundImage = PR_TRUE;
|
|
|
|
PRBool drawBackgroundColor = PR_TRUE;
|
|
|
|
|
|
|
|
if (aUsePrintSettings) {
|
|
|
|
drawBackgroundImage = aPresContext->GetBackgroundImageDraw();
|
|
|
|
drawBackgroundColor = aPresContext->GetBackgroundColorDraw();
|
2009-01-08 11:10:21 +03:00
|
|
|
}
|
2009-01-09 03:28:32 +03:00
|
|
|
|
|
|
|
if ((aColor.mBackgroundFlags & NS_STYLE_BG_IMAGE_NONE) ||
|
|
|
|
!aColor.mBackgroundImage) {
|
|
|
|
NS_ASSERTION((aColor.mBackgroundFlags & NS_STYLE_BG_IMAGE_NONE) &&
|
|
|
|
!aColor.mBackgroundImage, "background flags/image mismatch");
|
|
|
|
drawBackgroundImage = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If GetBackgroundColorDraw() is false, we are still expected to
|
|
|
|
// draw color in the background of any frame that's not completely
|
|
|
|
// transparent, but we are expected to use white instead of whatever
|
|
|
|
// color was specified.
|
|
|
|
nscolor bgColor;
|
|
|
|
if (drawBackgroundColor) {
|
|
|
|
bgColor = aColor.mBackgroundColor;
|
|
|
|
if (NS_GET_A(bgColor) == 0)
|
|
|
|
drawBackgroundColor = PR_FALSE;
|
|
|
|
} else {
|
|
|
|
bgColor = NS_RGB(255, 255, 255);
|
2009-01-10 19:37:01 +03:00
|
|
|
if (drawBackgroundImage || !aColor.IsTransparent())
|
2009-01-09 03:28:32 +03:00
|
|
|
drawBackgroundColor = PR_TRUE;
|
2009-01-08 11:10:21 +03:00
|
|
|
}
|
|
|
|
|
2009-01-09 03:28:32 +03:00
|
|
|
// At this point, drawBackgroundImage and drawBackgroundColor are
|
|
|
|
// true if and only if we are actually supposed to paint an image or
|
|
|
|
// color into aDirtyRect, respectively.
|
|
|
|
if (!drawBackgroundImage && !drawBackgroundColor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Compute the outermost boundary of the area that might be painted.
|
2009-01-08 13:19:21 +03:00
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
2009-01-09 03:28:32 +03:00
|
|
|
nscoord appUnitsPerPixel = aPresContext->AppUnitsPerDevPixel();
|
|
|
|
|
|
|
|
// Same coordinate space as aBorderArea & aBGClipRect
|
|
|
|
nsRect bgArea;
|
|
|
|
gfxCornerSizes bgRadii;
|
|
|
|
PRBool haveRoundedCorners;
|
|
|
|
PRBool radiiAreOuter = PR_TRUE;
|
|
|
|
{
|
|
|
|
nscoord radii[8];
|
|
|
|
haveRoundedCorners =
|
|
|
|
GetBorderRadiusTwips(aBorder.mBorderRadius, aForFrame->GetSize().width,
|
|
|
|
radii);
|
|
|
|
if (haveRoundedCorners)
|
|
|
|
ComputePixelRadii(radii, aBorderArea, aForFrame->GetSkipSides(),
|
|
|
|
appUnitsPerPixel, &bgRadii);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The background is rendered over the 'background-clip' area,
|
|
|
|
// which is normally equal to the border area but may be reduced
|
|
|
|
// to the padding area by CSS. Also, if the border is solid, we
|
|
|
|
// don't need to draw outside the padding area. In either case,
|
|
|
|
// if the borders are rounded, make sure we use the same inner
|
|
|
|
// radii as the border code will.
|
|
|
|
bgArea = aBorderArea;
|
|
|
|
if (aColor.mBackgroundClip != NS_STYLE_BG_CLIP_BORDER ||
|
|
|
|
IsSolidBorder(aBorder)) {
|
|
|
|
nsMargin border = aForFrame->GetUsedBorder();
|
|
|
|
aForFrame->ApplySkipSides(border);
|
|
|
|
bgArea.Deflate(border);
|
|
|
|
if (haveRoundedCorners) {
|
|
|
|
gfxCornerSizes outerRadii = bgRadii;
|
|
|
|
gfxFloat borderSizes[4] = {
|
|
|
|
border.top / appUnitsPerPixel, border.right / appUnitsPerPixel,
|
|
|
|
border.bottom / appUnitsPerPixel, border.left / appUnitsPerPixel
|
|
|
|
};
|
|
|
|
nsCSSBorderRenderer::ComputeInnerRadii(outerRadii, borderSizes,
|
|
|
|
&bgRadii);
|
|
|
|
radiiAreOuter = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The 'bgClipArea' (used only by the image tiling logic, far below)
|
|
|
|
// is the caller-provided aBGClipRect if any, or else the bgArea
|
|
|
|
// computed above. (Arguably it should be the intersection, but
|
|
|
|
// that breaks the table painter -- in particular, honoring the
|
|
|
|
// bgArea when we have aBGClipRect breaks reftests/bugs/403429-1[ab].)
|
|
|
|
// The dirtyRect is the intersection of that rectangle with the
|
|
|
|
// caller-provided aDirtyRect. If the dirtyRect is empty there is
|
|
|
|
// nothing to draw.
|
|
|
|
|
|
|
|
nsRect bgClipArea;
|
|
|
|
if (aBGClipRect)
|
|
|
|
bgClipArea = *aBGClipRect;
|
|
|
|
else
|
|
|
|
bgClipArea = bgArea;
|
2008-06-04 02:25:31 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
nsRect dirtyRect;
|
2009-01-09 03:28:32 +03:00
|
|
|
dirtyRect.IntersectRect(bgClipArea, aDirtyRect);
|
|
|
|
|
|
|
|
if (dirtyRect.IsEmpty())
|
2002-10-08 14:24:53 +04:00
|
|
|
return;
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2009-01-09 03:28:32 +03:00
|
|
|
// Compute the Thebes equivalent of the dirtyRect.
|
|
|
|
gfxRect dirtyRectGfx(RectToGfxRect(dirtyRect, appUnitsPerPixel));
|
|
|
|
dirtyRectGfx.Round();
|
|
|
|
dirtyRectGfx.Condition();
|
|
|
|
if (dirtyRectGfx.IsEmpty()) {
|
|
|
|
NS_WARNING("converted dirty rect should not be empty");
|
2009-01-08 11:10:21 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2009-01-09 03:28:32 +03:00
|
|
|
// If we have rounded corners, clip all subsequent drawing to the
|
|
|
|
// rounded rectangle defined by bgArea and bgRadii (we don't know
|
|
|
|
// whether the rounded corners intrude on the dirtyRect or not).
|
|
|
|
// Do not do this if we have a caller-provided clip rect --
|
|
|
|
// as above with bgArea, arguably a bug, but table painting seems
|
|
|
|
// to depend on it.
|
|
|
|
|
|
|
|
gfxContextAutoSaveRestore autoSR;
|
|
|
|
if (haveRoundedCorners && !aBGClipRect) {
|
|
|
|
gfxRect bgAreaGfx(RectToGfxRect(bgArea, appUnitsPerPixel));
|
|
|
|
bgAreaGfx.Round();
|
|
|
|
bgAreaGfx.Condition();
|
|
|
|
if (bgAreaGfx.IsEmpty()) {
|
|
|
|
NS_WARNING("converted background area should not be empty");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
autoSR.SetContext(ctx);
|
|
|
|
ctx->NewPath();
|
|
|
|
ctx->RoundedRectangle(bgAreaGfx, bgRadii, radiiAreOuter);
|
|
|
|
ctx->Clip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we might be using a background color, go ahead and set it now.
|
|
|
|
if (drawBackgroundColor)
|
|
|
|
ctx->SetColor(gfxRGBA(bgColor));
|
|
|
|
|
|
|
|
// If there is no background image, draw a color. (If there is
|
|
|
|
// neither a background image nor a color, we wouldn't have gotten
|
|
|
|
// this far.)
|
|
|
|
if (!drawBackgroundImage) {
|
|
|
|
ctx->NewPath();
|
|
|
|
ctx->Rectangle(dirtyRectGfx);
|
|
|
|
ctx->Fill();
|
|
|
|
return;
|
|
|
|
}
|
2009-01-08 13:19:21 +03:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Lookup the image
|
2008-10-29 00:36:17 +03: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
|
|
|
|
2009-01-09 03:28:32 +03:00
|
|
|
// While waiting for the image, draw a color, if any.
|
|
|
|
if (!req ||
|
|
|
|
!(status & imgIRequest::STATUS_FRAME_COMPLETE) ||
|
|
|
|
!(status & imgIRequest::STATUS_SIZE_AVAILABLE)) {
|
|
|
|
if (drawBackgroundColor) {
|
|
|
|
ctx->NewPath();
|
|
|
|
ctx->Rectangle(dirtyRectGfx);
|
|
|
|
ctx->Fill();
|
|
|
|
}
|
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
|
|
|
|
2008-09-28 11:38:34 +04:00
|
|
|
nsSize imageSize;
|
2008-09-28 14:13:58 +04:00
|
|
|
image->GetWidth(&imageSize.width);
|
|
|
|
image->GetHeight(&imageSize.height);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
// relative to aBorderArea
|
|
|
|
nsRect bgOriginRect;
|
2003-01-17 12:33:52 +03:00
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom* frameType = aForFrame->GetType();
|
2008-11-05 01:01:21 +03:00
|
|
|
nsIFrame* geometryFrame = aForFrame;
|
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:
|
2008-11-05 01:01:21 +03:00
|
|
|
bgOriginRect = nsRect(nsPoint(0,0), aBorderArea.Size());
|
2003-01-17 12:33:52 +03:00
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_INLINE_POLICY_BOUNDING_BOX:
|
2008-11-05 01:01:21 +03:00
|
|
|
bgOriginRect = gInlineBGData->GetBoundingRect(aForFrame);
|
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:
|
2008-11-05 01:01:21 +03:00
|
|
|
bgOriginRect = gInlineBGData->GetContinuousRect(aForFrame);
|
2003-01-17 12:33:52 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-11-05 01:01:21 +03:00
|
|
|
} else if (frameType == nsGkAtoms::canvasFrame) {
|
|
|
|
geometryFrame = aForFrame->GetFirstChild(nsnull);
|
|
|
|
NS_ASSERTION(geometryFrame, "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|.");
|
|
|
|
bgOriginRect = geometryFrame->GetRect();
|
|
|
|
} else {
|
|
|
|
bgOriginRect = nsRect(nsPoint(0,0), aBorderArea.Size());
|
2003-01-17 12:33:52 +03:00
|
|
|
}
|
|
|
|
|
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) {
|
2008-11-05 01:01:21 +03:00
|
|
|
nsMargin border = geometryFrame->GetUsedBorder();
|
|
|
|
geometryFrame->ApplySkipSides(border);
|
|
|
|
bgOriginRect.Deflate(border);
|
2002-10-08 14:24:53 +04:00
|
|
|
if (aColor.mBackgroundOrigin != NS_STYLE_BG_ORIGIN_PADDING) {
|
2008-11-05 01:01:21 +03:00
|
|
|
nsMargin padding = geometryFrame->GetUsedPadding();
|
|
|
|
geometryFrame->ApplySkipSides(padding);
|
|
|
|
bgOriginRect.Deflate(padding);
|
2002-10-08 14:24:53 +04:00
|
|
|
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
|
|
|
PRIntn repeat = aColor.mBackgroundRepeat;
|
|
|
|
switch (repeat) {
|
1998-04-14 00:24:54 +04:00
|
|
|
case NS_STYLE_BG_REPEAT_X:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_REPEAT_Y:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_REPEAT_XY:
|
2009-01-09 03:28:32 +03:00
|
|
|
if (drawBackgroundColor) {
|
|
|
|
// If the image is completely opaque, we may not need to paint
|
|
|
|
// the background color.
|
2003-03-06 02:34:48 +03:00
|
|
|
nsCOMPtr<gfxIImageFrame> gfxImgFrame;
|
|
|
|
image->GetCurrentFrame(getter_AddRefs(gfxImgFrame));
|
|
|
|
if (gfxImgFrame) {
|
2009-01-09 03:28:32 +03:00
|
|
|
gfxImgFrame->GetNeedsBackground(&drawBackgroundColor);
|
|
|
|
if (!drawBackgroundColor) {
|
|
|
|
// If the current frame is smaller than its container, we
|
|
|
|
// need to paint the background color even if the frame
|
|
|
|
// itself is opaque.
|
|
|
|
nsSize iSize;
|
|
|
|
image->GetWidth(&iSize.width);
|
|
|
|
image->GetHeight(&iSize.height);
|
|
|
|
nsRect iframeRect;
|
|
|
|
gfxImgFrame->GetRect(iframeRect);
|
|
|
|
if (iSize.width != iframeRect.width ||
|
|
|
|
iSize.height != iframeRect.height) {
|
|
|
|
drawBackgroundColor = PR_TRUE;
|
|
|
|
}
|
2004-01-17 02:28:51 +03:00
|
|
|
}
|
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:
|
2009-01-09 03:28:32 +03:00
|
|
|
NS_ASSERTION(repeat == NS_STYLE_BG_REPEAT_OFF,
|
|
|
|
"unknown background-repeat value");
|
2002-10-08 14:24:53 +04:00
|
|
|
break;
|
|
|
|
}
|
1999-01-15 21:25:58 +03:00
|
|
|
|
2009-01-09 03:28:32 +03:00
|
|
|
// The background color is rendered over the entire dirty area,
|
|
|
|
// even if the image isn't.
|
|
|
|
if (drawBackgroundColor) {
|
|
|
|
ctx->NewPath();
|
|
|
|
ctx->Rectangle(dirtyRectGfx);
|
|
|
|
ctx->Fill();
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2002-10-08 14:24:53 +04:00
|
|
|
// Compute the anchor point.
|
|
|
|
//
|
2008-11-05 01:01:21 +03:00
|
|
|
// relative to aBorderArea.TopLeft() (which is where the top-left
|
|
|
|
// of aForFrame's border-box will be rendered)
|
|
|
|
nsPoint imageTopLeft, anchor;
|
2002-10-08 14:24:53 +04:00
|
|
|
if (NS_STYLE_BG_ATTACHMENT_FIXED == aColor.mBackgroundAttachment) {
|
2007-07-04 05:13:07 +04:00
|
|
|
// If it's a fixed background attachment, then the image is placed
|
|
|
|
// relative to the viewport, which is the area of the root frame
|
|
|
|
// in a screen context or the page content frame in a print context.
|
2002-10-08 14:24:53 +04:00
|
|
|
|
2006-09-20 02:05:33 +04:00
|
|
|
// Remember that we've drawn position-varying content in this prescontext
|
|
|
|
aPresContext->SetRenderedPositionVaryingContent();
|
|
|
|
|
2007-07-04 05:13:07 +04:00
|
|
|
nsIFrame* topFrame =
|
2004-09-02 07:08:51 +04:00
|
|
|
aPresContext->PresShell()->FrameManager()->GetRootFrame();
|
2007-07-04 05:13:07 +04:00
|
|
|
NS_ASSERTION(topFrame, "no root frame");
|
2008-02-06 21:22:24 +03:00
|
|
|
nsIFrame* pageContentFrame = nsnull;
|
2004-03-03 21:24:20 +03:00
|
|
|
if (aPresContext->IsPaginated()) {
|
2008-02-06 21:22:24 +03:00
|
|
|
pageContentFrame =
|
2007-07-04 05:13:07 +04:00
|
|
|
nsLayoutUtils::GetClosestFrameOfType(aForFrame, nsGkAtoms::pageContentFrame);
|
|
|
|
if (pageContentFrame) {
|
|
|
|
topFrame = pageContentFrame;
|
|
|
|
}
|
|
|
|
// else this is an embedded shell and its root frame is what we want
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
2001-08-18 03:26:29 +04:00
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
nsRect viewportArea(nsPoint(0, 0), topFrame->GetSize());
|
2008-02-06 21:22:24 +03:00
|
|
|
|
|
|
|
if (!pageContentFrame) {
|
|
|
|
// Subtract the size of scrollbars.
|
|
|
|
nsIScrollableFrame* scrollableFrame =
|
|
|
|
aPresContext->PresShell()->GetRootScrollFrameAsScrollable();
|
|
|
|
if (scrollableFrame) {
|
|
|
|
nsMargin scrollbars = scrollableFrame->GetActualScrollbarSizes();
|
|
|
|
viewportArea.Deflate(scrollbars);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the anchor point, relative to the viewport.
|
2008-11-05 01:01:21 +03:00
|
|
|
ComputeBackgroundAnchorPoint(aColor, viewportArea.Size(), imageSize,
|
|
|
|
&imageTopLeft, &anchor);
|
1999-04-25 06:43:50 +04:00
|
|
|
|
2007-07-04 05:13:07 +04:00
|
|
|
// Convert the anchor point from viewport coordinates to aForFrame
|
|
|
|
// coordinates.
|
2008-11-05 01:01:21 +03:00
|
|
|
nsPoint offset = viewportArea.TopLeft() - aForFrame->GetOffsetTo(topFrame);
|
|
|
|
imageTopLeft += offset;
|
|
|
|
anchor += offset;
|
2002-10-08 14:24:53 +04:00
|
|
|
} else {
|
2008-11-05 01:01:21 +03:00
|
|
|
ComputeBackgroundAnchorPoint(aColor, bgOriginRect.Size(), imageSize,
|
|
|
|
&imageTopLeft, &anchor);
|
|
|
|
imageTopLeft += bgOriginRect.TopLeft();
|
|
|
|
anchor += bgOriginRect.TopLeft();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2001-08-18 03:26:29 +04:00
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
nsRect destArea(imageTopLeft + aBorderArea.TopLeft(), imageSize);
|
2008-11-26 01:19:34 +03:00
|
|
|
nsRect fillArea = destArea;
|
2002-10-08 14:24:53 +04:00
|
|
|
if (repeat & NS_STYLE_BG_REPEAT_X) {
|
2008-11-05 01:01:21 +03:00
|
|
|
fillArea.x = bgClipArea.x;
|
|
|
|
fillArea.width = bgClipArea.width;
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
|
|
|
if (repeat & NS_STYLE_BG_REPEAT_Y) {
|
2008-11-05 01:01:21 +03:00
|
|
|
fillArea.y = bgClipArea.y;
|
|
|
|
fillArea.height = bgClipArea.height;
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
2008-11-26 01:19:34 +03:00
|
|
|
fillArea.IntersectRect(fillArea, bgClipArea);
|
1998-07-31 03:31:42 +04:00
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
nsLayoutUtils::DrawImage(&aRenderingContext, image,
|
|
|
|
destArea, fillArea, anchor + aBorderArea.TopLeft(), dirtyRect);
|
2002-10-08 14:24:53 +04:00
|
|
|
}
|
|
|
|
|
2008-09-25 20:03:15 +04:00
|
|
|
static void
|
|
|
|
DrawBorderImage(nsPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFrame* aForFrame, const nsRect& aBorderArea,
|
|
|
|
const nsStyleBorder& aBorderStyle)
|
2008-07-17 10:30:25 +04:00
|
|
|
{
|
|
|
|
float percent;
|
|
|
|
nsStyleCoord borderImageSplit[4];
|
|
|
|
PRInt32 borderImageSplitInt[4];
|
|
|
|
nsMargin border;
|
|
|
|
gfxFloat borderTop, borderRight, borderBottom, borderLeft;
|
|
|
|
gfxFloat borderImageSplitGfx[4];
|
|
|
|
|
2008-08-06 14:33:18 +04:00
|
|
|
border = aBorderStyle.GetActualBorder();
|
2008-07-17 10:30:25 +04:00
|
|
|
if ((0 == border.left) && (0 == border.right) &&
|
|
|
|
(0 == border.top) && (0 == border.bottom)) {
|
|
|
|
// Empty border area
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
borderImageSplit[NS_SIDE_TOP] = aBorderStyle.mBorderImageSplit.GetTop();
|
|
|
|
borderImageSplit[NS_SIDE_RIGHT] = aBorderStyle.mBorderImageSplit.GetRight();
|
|
|
|
borderImageSplit[NS_SIDE_BOTTOM] = aBorderStyle.mBorderImageSplit.GetBottom();
|
|
|
|
borderImageSplit[NS_SIDE_LEFT] = aBorderStyle.mBorderImageSplit.GetLeft();
|
|
|
|
|
2008-10-29 00:36:17 +03:00
|
|
|
imgIRequest *req = aPresContext->LoadBorderImage(aBorderStyle.GetBorderImage(), aForFrame);
|
2008-07-17 10:30:25 +04:00
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
req->GetImage(getter_AddRefs(image));
|
|
|
|
|
|
|
|
nsSize imageSize;
|
|
|
|
image->GetWidth(&imageSize.width);
|
|
|
|
image->GetHeight(&imageSize.height);
|
|
|
|
imageSize.width = nsPresContext::CSSPixelsToAppUnits(imageSize.width);
|
|
|
|
imageSize.height = nsPresContext::CSSPixelsToAppUnits(imageSize.height);
|
|
|
|
|
|
|
|
// convert percentage values
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
|
|
|
borderImageSplitInt[side] = 0;
|
|
|
|
switch (borderImageSplit[side].GetUnit()) {
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
percent = borderImageSplit[side].GetPercentValue();
|
|
|
|
if (side == NS_SIDE_TOP || side == NS_SIDE_BOTTOM)
|
|
|
|
borderImageSplitInt[side] = (nscoord)(percent * imageSize.height);
|
|
|
|
else
|
|
|
|
borderImageSplitInt[side] = (nscoord)(percent * imageSize.width);
|
|
|
|
break;
|
|
|
|
case eStyleUnit_Integer:
|
|
|
|
borderImageSplitInt[side] = nsPresContext::CSSPixelsToAppUnits(borderImageSplit[side].
|
|
|
|
GetIntValue());
|
|
|
|
break;
|
|
|
|
case eStyleUnit_Factor:
|
|
|
|
borderImageSplitInt[side] = nsPresContext::CSSPixelsToAppUnits(borderImageSplit[side].GetFactorValue());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxContext *thebesCtx = aRenderingContext.ThebesContext();
|
|
|
|
nsCOMPtr<nsIDeviceContext> dc;
|
|
|
|
aRenderingContext.GetDeviceContext(*getter_AddRefs(dc));
|
|
|
|
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
|
|
|
borderImageSplitGfx[side] = nsPresContext::AppUnitsToFloatCSSPixels(borderImageSplitInt[side]);
|
|
|
|
}
|
|
|
|
|
|
|
|
borderTop = dc->AppUnitsToGfxUnits(border.top);
|
|
|
|
borderRight = dc->AppUnitsToGfxUnits(border.right);
|
|
|
|
borderBottom = dc->AppUnitsToGfxUnits(border.bottom);
|
|
|
|
borderLeft = dc->AppUnitsToGfxUnits(border.left);
|
|
|
|
|
|
|
|
gfxSize gfxImageSize;
|
|
|
|
gfxImageSize.width = nsPresContext::AppUnitsToFloatCSSPixels(imageSize.width);
|
|
|
|
gfxImageSize.height = nsPresContext::AppUnitsToFloatCSSPixels(imageSize.height);
|
|
|
|
|
|
|
|
nsRect outerRect(aBorderArea);
|
|
|
|
gfxRect rectToDraw,
|
|
|
|
rectToDrawSource;
|
|
|
|
|
|
|
|
gfxRect clipRect;
|
|
|
|
clipRect.pos.x = dc->AppUnitsToGfxUnits(outerRect.x);
|
|
|
|
clipRect.pos.y = dc->AppUnitsToGfxUnits(outerRect.y);
|
|
|
|
clipRect.size.width = dc->AppUnitsToGfxUnits(outerRect.width);
|
|
|
|
clipRect.size.height = dc->AppUnitsToGfxUnits(outerRect.height);
|
2008-10-08 02:10:19 +04:00
|
|
|
if (thebesCtx->UserToDevicePixelSnapped(clipRect))
|
|
|
|
clipRect = thebesCtx->DeviceToUser(clipRect);
|
2008-07-17 10:30:25 +04:00
|
|
|
|
|
|
|
thebesCtx->Save();
|
|
|
|
thebesCtx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
|
|
|
|
|
|
|
|
gfxSize middleSize(clipRect.size.width - (borderLeft + borderRight),
|
|
|
|
clipRect.size.height - (borderTop + borderBottom));
|
|
|
|
|
|
|
|
// middle size in source space
|
|
|
|
gfxIntSize middleSizeSource(gfxImageSize.width - (borderImageSplitGfx[NS_SIDE_RIGHT] + borderImageSplitGfx[NS_SIDE_LEFT]),
|
|
|
|
gfxImageSize.height - (borderImageSplitGfx[NS_SIDE_TOP] + borderImageSplitGfx[NS_SIDE_BOTTOM]));
|
|
|
|
|
|
|
|
gfxSize interSizeTop, interSizeBottom, interSizeLeft, interSizeRight,
|
|
|
|
interSizeMiddle;
|
|
|
|
gfxFloat topScale = borderTop/borderImageSplitGfx[NS_SIDE_TOP];
|
|
|
|
gfxFloat bottomScale = borderBottom/borderImageSplitGfx[NS_SIDE_BOTTOM];
|
|
|
|
gfxFloat leftScale = borderLeft/borderImageSplitGfx[NS_SIDE_LEFT];
|
|
|
|
gfxFloat rightScale = borderRight/borderImageSplitGfx[NS_SIDE_RIGHT];
|
|
|
|
gfxFloat middleScaleH,
|
|
|
|
middleScaleV;
|
|
|
|
// TODO: check for nan and properly check for inf
|
|
|
|
if (topScale != 0.0 && borderImageSplitGfx[NS_SIDE_TOP] != 0.0) {
|
|
|
|
middleScaleH = topScale;
|
|
|
|
} else if (bottomScale != 0.0 && borderImageSplitGfx[NS_SIDE_BOTTOM] != 0.0) {
|
|
|
|
middleScaleH = bottomScale;
|
|
|
|
} else {
|
|
|
|
middleScaleH = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leftScale != 0.0 && borderImageSplitGfx[NS_SIDE_LEFT] != 0.0) {
|
|
|
|
middleScaleV = leftScale;
|
|
|
|
} else if (rightScale != 0.0 && borderImageSplitGfx[NS_SIDE_RIGHT] != 0.0) {
|
|
|
|
middleScaleV = rightScale;
|
|
|
|
} else {
|
|
|
|
middleScaleV = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
interSizeTop.height = borderTop;
|
|
|
|
interSizeTop.width = middleSizeSource.width*topScale;
|
|
|
|
|
|
|
|
interSizeBottom.height = borderBottom;
|
|
|
|
interSizeBottom.width = middleSizeSource.width*bottomScale;
|
|
|
|
|
|
|
|
interSizeLeft.width = borderLeft;
|
|
|
|
interSizeLeft.height = middleSizeSource.height*leftScale;
|
|
|
|
|
|
|
|
interSizeRight.width = borderRight;
|
|
|
|
interSizeRight.height = middleSizeSource.height*rightScale;
|
|
|
|
|
|
|
|
interSizeMiddle.width = middleSizeSource.width*middleScaleH;
|
|
|
|
interSizeMiddle.height = middleSizeSource.height*middleScaleV;
|
|
|
|
|
|
|
|
// draw top left corner
|
|
|
|
rectToDraw = clipRect;
|
|
|
|
rectToDraw.size.width = borderLeft;
|
|
|
|
rectToDraw.size.height = borderTop;
|
|
|
|
rectToDrawSource.pos.x = 0;
|
|
|
|
rectToDrawSource.pos.y = 0;
|
|
|
|
rectToDrawSource.size.width = borderImageSplitGfx[NS_SIDE_LEFT];
|
|
|
|
rectToDrawSource.size.height = borderImageSplitGfx[NS_SIDE_TOP];
|
|
|
|
DrawBorderImageSide(thebesCtx, dc, image,
|
|
|
|
rectToDraw, rectToDraw.size, rectToDrawSource,
|
|
|
|
NS_STYLE_BORDER_IMAGE_STRETCH, NS_STYLE_BORDER_IMAGE_STRETCH);
|
|
|
|
|
|
|
|
// draw top
|
|
|
|
rectToDraw = clipRect;
|
|
|
|
rectToDraw.pos.x += borderLeft;
|
|
|
|
rectToDraw.size.width = middleSize.width;
|
|
|
|
rectToDraw.size.height = borderTop;
|
|
|
|
rectToDrawSource.pos.x = borderImageSplitGfx[NS_SIDE_LEFT];
|
|
|
|
rectToDrawSource.pos.y = 0;
|
|
|
|
rectToDrawSource.size.width = middleSizeSource.width;
|
|
|
|
rectToDrawSource.size.height = borderImageSplitGfx[NS_SIDE_TOP];
|
|
|
|
DrawBorderImageSide(thebesCtx, dc, image,
|
|
|
|
rectToDraw, interSizeTop, rectToDrawSource,
|
|
|
|
aBorderStyle.mBorderImageHFill, NS_STYLE_BORDER_IMAGE_STRETCH);
|
|
|
|
|
|
|
|
// draw top right corner
|
|
|
|
rectToDraw = clipRect;
|
|
|
|
rectToDraw.pos.x += clipRect.size.width - borderRight;
|
|
|
|
rectToDraw.size.width = borderRight;
|
|
|
|
rectToDraw.size.height = borderTop;
|
|
|
|
rectToDrawSource.pos.x = gfxImageSize.width - borderImageSplitGfx[NS_SIDE_RIGHT];
|
|
|
|
rectToDrawSource.pos.y = 0;
|
|
|
|
rectToDrawSource.size.width = borderImageSplitGfx[NS_SIDE_RIGHT];
|
|
|
|
rectToDrawSource.size.height = borderImageSplitGfx[NS_SIDE_TOP];
|
|
|
|
DrawBorderImageSide(thebesCtx, dc, image,
|
|
|
|
rectToDraw, rectToDraw.size, rectToDrawSource,
|
|
|
|
NS_STYLE_BORDER_IMAGE_STRETCH, NS_STYLE_BORDER_IMAGE_STRETCH);
|
|
|
|
|
|
|
|
// draw right
|
|
|
|
rectToDraw = clipRect;
|
|
|
|
rectToDraw.pos.x += clipRect.size.width - borderRight;
|
|
|
|
rectToDraw.pos.y += borderTop;
|
|
|
|
rectToDraw.size.width = borderRight;
|
|
|
|
rectToDraw.size.height = middleSize.height;
|
|
|
|
rectToDrawSource.pos.x = gfxImageSize.width - borderImageSplitGfx[NS_SIDE_RIGHT];
|
|
|
|
rectToDrawSource.pos.y = borderImageSplitGfx[NS_SIDE_TOP];
|
|
|
|
rectToDrawSource.size.width = borderImageSplitGfx[NS_SIDE_RIGHT];
|
|
|
|
rectToDrawSource.size.height = middleSizeSource.height;
|
|
|
|
DrawBorderImageSide(thebesCtx, dc, image,
|
|
|
|
rectToDraw, interSizeRight, rectToDrawSource,
|
|
|
|
NS_STYLE_BORDER_IMAGE_STRETCH, aBorderStyle.mBorderImageVFill);
|
|
|
|
|
|
|
|
// draw bottom right corner
|
|
|
|
rectToDraw = clipRect;
|
|
|
|
rectToDraw.pos.x += clipRect.size.width - borderRight;
|
|
|
|
rectToDraw.pos.y += clipRect.size.height - borderBottom;
|
|
|
|
rectToDraw.size.width = borderRight;
|
|
|
|
rectToDraw.size.height = borderBottom;
|
|
|
|
rectToDrawSource.pos.x = gfxImageSize.width - borderImageSplitGfx[NS_SIDE_RIGHT];
|
|
|
|
rectToDrawSource.pos.y = gfxImageSize.height - borderImageSplitGfx[NS_SIDE_BOTTOM];
|
|
|
|
rectToDrawSource.size.width = borderImageSplitGfx[NS_SIDE_RIGHT];
|
|
|
|
rectToDrawSource.size.height = borderImageSplitGfx[NS_SIDE_BOTTOM];
|
|
|
|
DrawBorderImageSide(thebesCtx, dc, image,
|
|
|
|
rectToDraw, rectToDraw.size, rectToDrawSource,
|
|
|
|
NS_STYLE_BORDER_IMAGE_STRETCH, NS_STYLE_BORDER_IMAGE_STRETCH);
|
|
|
|
|
|
|
|
// draw bottom
|
|
|
|
rectToDraw = clipRect;
|
|
|
|
rectToDraw.pos.x += borderLeft;
|
|
|
|
rectToDraw.pos.y += clipRect.size.height - borderBottom;
|
|
|
|
rectToDraw.size.width = middleSize.width;
|
|
|
|
rectToDraw.size.height = borderBottom;
|
|
|
|
rectToDrawSource.pos.x = borderImageSplitGfx[NS_SIDE_LEFT];
|
|
|
|
rectToDrawSource.pos.y = gfxImageSize.height - borderImageSplitGfx[NS_SIDE_BOTTOM];
|
|
|
|
rectToDrawSource.size.width = middleSizeSource.width;
|
|
|
|
rectToDrawSource.size.height = borderImageSplitGfx[NS_SIDE_BOTTOM];
|
|
|
|
DrawBorderImageSide(thebesCtx, dc, image,
|
|
|
|
rectToDraw, interSizeBottom, rectToDrawSource,
|
|
|
|
aBorderStyle.mBorderImageHFill, NS_STYLE_BORDER_IMAGE_STRETCH);
|
|
|
|
|
|
|
|
// draw bottom left corner
|
|
|
|
rectToDraw = clipRect;
|
|
|
|
rectToDraw.pos.y += clipRect.size.height - borderBottom;
|
|
|
|
rectToDraw.size.width = borderLeft;
|
|
|
|
rectToDraw.size.height = borderBottom;
|
|
|
|
rectToDrawSource.pos.x = 0;
|
|
|
|
rectToDrawSource.pos.y = gfxImageSize.height - borderImageSplitGfx[NS_SIDE_BOTTOM];
|
|
|
|
rectToDrawSource.size.width = borderImageSplitGfx[NS_SIDE_LEFT];
|
|
|
|
rectToDrawSource.size.height = borderImageSplitGfx[NS_SIDE_BOTTOM];
|
|
|
|
DrawBorderImageSide(thebesCtx, dc, image,
|
|
|
|
rectToDraw, rectToDraw.size, rectToDrawSource,
|
|
|
|
NS_STYLE_BORDER_IMAGE_STRETCH, NS_STYLE_BORDER_IMAGE_STRETCH);
|
|
|
|
|
|
|
|
// draw left
|
|
|
|
rectToDraw = clipRect;
|
|
|
|
rectToDraw.pos.y += borderTop;
|
|
|
|
rectToDraw.size.width = borderLeft;
|
|
|
|
rectToDraw.size.height = middleSize.height;
|
|
|
|
rectToDrawSource.pos.x = 0;
|
|
|
|
rectToDrawSource.pos.y = borderImageSplitGfx[NS_SIDE_TOP];
|
|
|
|
rectToDrawSource.size.width = borderImageSplitGfx[NS_SIDE_LEFT];
|
|
|
|
rectToDrawSource.size.height = middleSizeSource.height;
|
|
|
|
DrawBorderImageSide(thebesCtx, dc, image,
|
|
|
|
rectToDraw, interSizeLeft, rectToDrawSource,
|
|
|
|
NS_STYLE_BORDER_IMAGE_STRETCH, aBorderStyle.mBorderImageVFill);
|
|
|
|
|
|
|
|
// Draw middle
|
|
|
|
rectToDraw = clipRect;
|
|
|
|
rectToDraw.pos.x += borderLeft;
|
|
|
|
rectToDraw.pos.y += borderTop;
|
|
|
|
rectToDraw.size.width = middleSize.width;
|
|
|
|
rectToDraw.size.height = middleSize.height;
|
|
|
|
rectToDrawSource.pos.x = borderImageSplitGfx[NS_SIDE_LEFT];
|
|
|
|
rectToDrawSource.pos.y = borderImageSplitGfx[NS_SIDE_TOP];
|
|
|
|
rectToDrawSource.size = middleSizeSource;
|
|
|
|
DrawBorderImageSide(thebesCtx, dc, image,
|
|
|
|
rectToDraw, interSizeMiddle, rectToDrawSource,
|
|
|
|
aBorderStyle.mBorderImageHFill, aBorderStyle.mBorderImageVFill);
|
|
|
|
|
|
|
|
thebesCtx->PopGroupToSource();
|
|
|
|
thebesCtx->SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
thebesCtx->Paint();
|
|
|
|
thebesCtx->Restore();
|
|
|
|
}
|
|
|
|
|
2008-09-25 20:03:15 +04:00
|
|
|
static void
|
|
|
|
DrawBorderImageSide(gfxContext *aThebesContext,
|
|
|
|
nsIDeviceContext* aDeviceContext,
|
|
|
|
imgIContainer* aImage,
|
|
|
|
gfxRect& aDestRect,
|
2008-10-08 02:10:19 +04:00
|
|
|
gfxSize aInterSize, // non-ref to allow aliasing
|
2008-09-25 20:03:15 +04:00
|
|
|
gfxRect& aSourceRect,
|
|
|
|
PRUint8 aHFillType,
|
|
|
|
PRUint8 aVFillType)
|
2008-07-17 10:30:25 +04:00
|
|
|
{
|
|
|
|
if (aDestRect.size.width < 1.0 || aDestRect.size.height < 1.0 ||
|
|
|
|
aSourceRect.size.width < 1.0 || aSourceRect.size.height < 1.0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxIntSize gfxSourceSize((PRInt32)aSourceRect.size.width,
|
|
|
|
(PRInt32)aSourceRect.size.height);
|
|
|
|
|
|
|
|
// where the actual border ends up being rendered
|
2008-10-08 02:10:19 +04:00
|
|
|
if (aThebesContext->UserToDevicePixelSnapped(aDestRect))
|
|
|
|
aDestRect = aThebesContext->DeviceToUser(aDestRect);
|
|
|
|
if (aThebesContext->UserToDevicePixelSnapped(aSourceRect))
|
|
|
|
aSourceRect = aThebesContext->DeviceToUser(aSourceRect);
|
2008-07-17 10:30:25 +04:00
|
|
|
|
|
|
|
if (aDestRect.size.height < 1.0 ||
|
|
|
|
aDestRect.size.width < 1.0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aInterSize.width < 1.0 ||
|
|
|
|
aInterSize.height < 1.0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Surface will hold just the part of the source image specified by the aSourceRect
|
|
|
|
// but at a different size
|
|
|
|
nsRefPtr<gfxASurface> interSurface =
|
|
|
|
gfxPlatform::GetPlatform()->CreateOffscreenSurface(
|
|
|
|
gfxSourceSize, gfxASurface::ImageFormatARGB32);
|
|
|
|
|
|
|
|
gfxMatrix srcMatrix;
|
|
|
|
// Adjust the matrix scale for Step 1 of the spec
|
|
|
|
srcMatrix.Scale(aSourceRect.size.width/aInterSize.width,
|
|
|
|
aSourceRect.size.height/aInterSize.height);
|
|
|
|
{
|
|
|
|
nsCOMPtr<gfxIImageFrame> frame;
|
|
|
|
nsresult rv = aImage->GetCurrentFrame(getter_AddRefs(frame));
|
|
|
|
if(NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
nsCOMPtr<nsIImage> image;
|
|
|
|
image = do_GetInterface(frame);
|
|
|
|
if(!image)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// surface for the whole image
|
|
|
|
nsRefPtr<gfxPattern> imagePattern;
|
|
|
|
rv = image->GetPattern(getter_AddRefs(imagePattern));
|
|
|
|
if(NS_FAILED(rv) || !imagePattern)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gfxMatrix mat;
|
|
|
|
mat.Translate(aSourceRect.pos);
|
|
|
|
imagePattern->SetMatrix(mat);
|
|
|
|
|
|
|
|
// Straightforward blit - no resizing
|
|
|
|
nsRefPtr<gfxContext> srcCtx = new gfxContext(interSurface);
|
|
|
|
srcCtx->SetPattern(imagePattern);
|
|
|
|
srcCtx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
srcCtx->Paint();
|
|
|
|
srcCtx = nsnull;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// offset to make the middle tile centered in the middle of the border
|
|
|
|
gfxPoint renderOffset(0, 0);
|
|
|
|
gfxSize rectSize(aDestRect.size);
|
|
|
|
|
|
|
|
aThebesContext->Save();
|
|
|
|
aThebesContext->Clip(aDestRect);
|
|
|
|
|
|
|
|
gfxFloat hScale(1.0), vScale(1.0);
|
|
|
|
|
|
|
|
nsRefPtr<gfxPattern> pattern = new gfxPattern(interSurface);
|
2008-09-25 23:49:55 +04:00
|
|
|
pattern->SetExtend(gfxPattern::EXTEND_PAD_EDGE);
|
2008-07-17 10:30:25 +04:00
|
|
|
switch (aHFillType) {
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT:
|
|
|
|
renderOffset.x = (rectSize.width - aInterSize.width*NS_ceil(rectSize.width/aInterSize.width))*-0.5;
|
|
|
|
aDestRect.pos.x -= renderOffset.x;
|
|
|
|
pattern->SetExtend(gfxPattern::EXTEND_REPEAT);
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_IMAGE_ROUND:
|
|
|
|
hScale = aInterSize.width*(NS_ceil(aDestRect.size.width/aInterSize.width)/aDestRect.size.width);
|
|
|
|
pattern->SetExtend(gfxPattern::EXTEND_REPEAT);
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_IMAGE_STRETCH:
|
|
|
|
default:
|
|
|
|
hScale = aInterSize.width/aDestRect.size.width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aVFillType) {
|
|
|
|
case NS_STYLE_BORDER_IMAGE_REPEAT:
|
|
|
|
renderOffset.y = (rectSize.height - aInterSize.height*NS_ceil(rectSize.height/aInterSize.height))*-0.5;
|
|
|
|
aDestRect.pos.y -= renderOffset.y;
|
|
|
|
pattern->SetExtend(gfxPattern::EXTEND_REPEAT);
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_IMAGE_ROUND:
|
|
|
|
vScale = aInterSize.height*(NS_ceil(aDestRect.size.height/aInterSize.height)/aDestRect.size.height);
|
|
|
|
pattern->SetExtend(gfxPattern::EXTEND_REPEAT);
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_IMAGE_STRETCH:
|
|
|
|
default:
|
|
|
|
vScale = aInterSize.height/aDestRect.size.height;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust the matrix scale for Step 2 of the spec
|
|
|
|
srcMatrix.Scale(hScale,vScale);
|
|
|
|
pattern->SetMatrix(srcMatrix);
|
|
|
|
|
|
|
|
// render
|
|
|
|
aThebesContext->Translate(aDestRect.pos);
|
|
|
|
aThebesContext->SetPattern(pattern);
|
|
|
|
aThebesContext->NewPath();
|
|
|
|
aThebesContext->Rectangle(gfxRect(renderOffset, rectSize));
|
|
|
|
aThebesContext->SetOperator(gfxContext::OPERATOR_ADD);
|
|
|
|
aThebesContext->Fill();
|
|
|
|
aThebesContext->Restore();
|
|
|
|
}
|
|
|
|
|
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);
|
2007-10-10 04:00:05 +04:00
|
|
|
PRUint8 ridgeGroove = NS_STYLE_BORDER_STYLE_RIDGE;
|
2002-02-19 18:48:28 +03:00
|
|
|
|
|
|
|
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-12-19 02:01:15 +03:00
|
|
|
gfxContext *ctx = aContext.ThebesContext();
|
2007-02-23 20:52:09 +03:00
|
|
|
gfxContext::AntialiasMode oldMode = ctx->CurrentAntialiasMode();
|
|
|
|
ctx->SetAntialiasMode(gfxContext::MODE_ALIASED);
|
|
|
|
|
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
|
|
|
|
|
|
|
ctx->SetAntialiasMode(oldMode);
|
2002-02-19 18:48:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// End table border-collapsing section
|
|
|
|
|
2007-08-06 12:15:00 +04:00
|
|
|
void
|
|
|
|
nsCSSRendering::PaintDecorationLine(gfxContext* aGfxContext,
|
|
|
|
const nscolor aColor,
|
|
|
|
const gfxPoint& aPt,
|
|
|
|
const gfxSize& aLineSize,
|
|
|
|
const gfxFloat aAscent,
|
|
|
|
const gfxFloat aOffset,
|
|
|
|
const PRUint8 aDecoration,
|
2008-04-06 12:12:09 +04:00
|
|
|
const PRUint8 aStyle)
|
2007-08-06 12:15:00 +04:00
|
|
|
{
|
2008-02-16 18:31:27 +03:00
|
|
|
gfxRect rect =
|
|
|
|
GetTextDecorationRectInternal(aPt, aLineSize, aAscent, aOffset,
|
|
|
|
aDecoration, aStyle);
|
|
|
|
if (rect.IsEmpty())
|
2007-08-06 12:15:00 +04:00
|
|
|
return;
|
|
|
|
|
2008-01-11 01:10:38 +03:00
|
|
|
if (aDecoration != NS_STYLE_TEXT_DECORATION_UNDERLINE &&
|
|
|
|
aDecoration != NS_STYLE_TEXT_DECORATION_OVERLINE &&
|
|
|
|
aDecoration != NS_STYLE_TEXT_DECORATION_LINE_THROUGH)
|
|
|
|
{
|
|
|
|
NS_ERROR("Invalid decoration value!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-16 18:31:27 +03:00
|
|
|
gfxFloat lineHeight = PR_MAX(NS_round(aLineSize.height), 1.0);
|
2007-08-06 12:15:00 +04:00
|
|
|
PRBool contextIsSaved = PR_FALSE;
|
2008-01-11 01:10:38 +03:00
|
|
|
|
|
|
|
gfxFloat oldLineWidth;
|
|
|
|
nsRefPtr<gfxPattern> oldPattern;
|
|
|
|
|
2007-08-06 12:15:00 +04:00
|
|
|
switch (aStyle) {
|
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
2008-02-16 18:31:27 +03:00
|
|
|
case NS_STYLE_BORDER_STYLE_DOUBLE:
|
2008-01-11 01:10:38 +03:00
|
|
|
oldLineWidth = aGfxContext->CurrentLineWidth();
|
|
|
|
oldPattern = aGfxContext->GetPattern();
|
2007-08-06 12:15:00 +04:00
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_DASHED: {
|
|
|
|
aGfxContext->Save();
|
|
|
|
contextIsSaved = PR_TRUE;
|
2008-02-16 18:31:27 +03:00
|
|
|
gfxFloat dashWidth = lineHeight * DOT_LENGTH * DASH_LENGTH;
|
2007-08-06 12:15:00 +04:00
|
|
|
gfxFloat dash[2] = { dashWidth, dashWidth };
|
|
|
|
aGfxContext->SetLineCap(gfxContext::LINE_CAP_BUTT);
|
|
|
|
aGfxContext->SetDash(dash, 2, 0.0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOTTED: {
|
|
|
|
aGfxContext->Save();
|
|
|
|
contextIsSaved = PR_TRUE;
|
2008-02-16 18:31:27 +03:00
|
|
|
gfxFloat dashWidth = lineHeight * DOT_LENGTH;
|
2007-08-06 12:15:00 +04:00
|
|
|
gfxFloat dash[2];
|
2008-02-16 18:31:27 +03:00
|
|
|
if (lineHeight > 2.0) {
|
2007-08-06 12:15:00 +04:00
|
|
|
dash[0] = 0.0;
|
|
|
|
dash[1] = dashWidth * 2.0;
|
|
|
|
aGfxContext->SetLineCap(gfxContext::LINE_CAP_ROUND);
|
|
|
|
} else {
|
|
|
|
dash[0] = dashWidth;
|
|
|
|
dash[1] = dashWidth;
|
|
|
|
}
|
|
|
|
aGfxContext->SetDash(dash, 2, 0.0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NS_ERROR("Invalid style value!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The y position should be set to the middle of the line.
|
2008-02-16 18:31:27 +03:00
|
|
|
rect.pos.y += lineHeight / 2;
|
2007-08-06 12:15:00 +04:00
|
|
|
|
|
|
|
aGfxContext->SetColor(gfxRGBA(aColor));
|
2008-02-16 18:31:27 +03:00
|
|
|
aGfxContext->SetLineWidth(lineHeight);
|
2007-08-06 12:15:00 +04:00
|
|
|
switch (aStyle) {
|
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
|
|
|
aGfxContext->NewPath();
|
2008-02-16 18:31:27 +03:00
|
|
|
aGfxContext->MoveTo(rect.TopLeft());
|
|
|
|
aGfxContext->LineTo(rect.TopRight());
|
2007-08-06 12:15:00 +04:00
|
|
|
aGfxContext->Stroke();
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOUBLE:
|
|
|
|
aGfxContext->NewPath();
|
2008-02-16 18:31:27 +03:00
|
|
|
aGfxContext->MoveTo(rect.TopLeft());
|
|
|
|
aGfxContext->LineTo(rect.TopRight());
|
|
|
|
rect.size.height -= lineHeight;
|
|
|
|
aGfxContext->MoveTo(rect.BottomLeft());
|
|
|
|
aGfxContext->LineTo(rect.BottomRight());
|
2007-08-06 12:15:00 +04:00
|
|
|
aGfxContext->Stroke();
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOTTED:
|
|
|
|
case NS_STYLE_BORDER_STYLE_DASHED:
|
|
|
|
aGfxContext->NewPath();
|
2008-04-08 03:57:13 +04:00
|
|
|
aGfxContext->MoveTo(rect.TopLeft());
|
|
|
|
aGfxContext->LineTo(rect.TopRight());
|
2007-08-06 12:15:00 +04:00
|
|
|
aGfxContext->Stroke();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Invalid style value!");
|
|
|
|
break;
|
|
|
|
}
|
2008-01-11 01:10:38 +03:00
|
|
|
|
|
|
|
if (contextIsSaved) {
|
|
|
|
aGfxContext->Restore();
|
|
|
|
} else {
|
|
|
|
aGfxContext->SetPattern(oldPattern);
|
|
|
|
aGfxContext->SetLineWidth(oldLineWidth);
|
|
|
|
}
|
2007-08-06 12:15:00 +04:00
|
|
|
}
|
2008-02-16 18:31:27 +03:00
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsCSSRendering::GetTextDecorationRect(nsPresContext* aPresContext,
|
|
|
|
const gfxSize& aLineSize,
|
|
|
|
const gfxFloat aAscent,
|
|
|
|
const gfxFloat aOffset,
|
|
|
|
const PRUint8 aDecoration,
|
|
|
|
const PRUint8 aStyle)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aPresContext, "aPresContext is null");
|
|
|
|
|
|
|
|
gfxRect rect =
|
|
|
|
GetTextDecorationRectInternal(gfxPoint(0, 0), aLineSize, aAscent, aOffset,
|
|
|
|
aDecoration, aStyle);
|
|
|
|
// The rect values are already rounded to nearest device pixels.
|
|
|
|
nsRect r;
|
|
|
|
r.x = aPresContext->GfxUnitsToAppUnits(rect.X());
|
|
|
|
r.y = aPresContext->GfxUnitsToAppUnits(rect.Y());
|
|
|
|
r.width = aPresContext->GfxUnitsToAppUnits(rect.Width());
|
|
|
|
r.height = aPresContext->GfxUnitsToAppUnits(rect.Height());
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-09-25 20:03:15 +04:00
|
|
|
static gfxRect
|
|
|
|
GetTextDecorationRectInternal(const gfxPoint& aPt,
|
|
|
|
const gfxSize& aLineSize,
|
|
|
|
const gfxFloat aAscent,
|
|
|
|
const gfxFloat aOffset,
|
|
|
|
const PRUint8 aDecoration,
|
|
|
|
const PRUint8 aStyle)
|
2008-02-16 18:31:27 +03:00
|
|
|
{
|
|
|
|
gfxRect r;
|
2008-03-05 22:24:44 +03:00
|
|
|
r.pos.x = NS_floor(aPt.x + 0.5);
|
2008-02-16 18:31:27 +03:00
|
|
|
r.size.width = NS_round(aLineSize.width);
|
|
|
|
|
|
|
|
gfxFloat basesize = NS_round(aLineSize.height);
|
|
|
|
basesize = PR_MAX(basesize, 1.0);
|
|
|
|
r.size.height = basesize;
|
|
|
|
if (aStyle == NS_STYLE_BORDER_STYLE_DOUBLE) {
|
|
|
|
gfxFloat gap = NS_round(basesize / 2.0);
|
|
|
|
gap = PR_MAX(gap, 1.0);
|
|
|
|
r.size.height = basesize * 2.0 + gap;
|
|
|
|
} else {
|
|
|
|
r.size.height = basesize;
|
|
|
|
}
|
|
|
|
|
2008-03-05 22:24:44 +03:00
|
|
|
gfxFloat baseline = NS_floor(aPt.y + aAscent + 0.5);
|
2008-02-16 18:31:27 +03:00
|
|
|
gfxFloat offset = 0;
|
|
|
|
switch (aDecoration) {
|
|
|
|
case NS_STYLE_TEXT_DECORATION_UNDERLINE:
|
2008-03-05 22:24:44 +03:00
|
|
|
offset = aOffset;
|
2008-02-16 18:31:27 +03:00
|
|
|
break;
|
|
|
|
case NS_STYLE_TEXT_DECORATION_OVERLINE:
|
2008-03-05 22:24:44 +03:00
|
|
|
offset = aOffset - basesize + r.Height();
|
2008-02-16 18:31:27 +03:00
|
|
|
break;
|
|
|
|
case NS_STYLE_TEXT_DECORATION_LINE_THROUGH: {
|
2008-03-05 22:24:44 +03:00
|
|
|
gfxFloat extra = NS_floor(r.Height() / 2.0 + 0.5);
|
2008-02-16 18:31:27 +03:00
|
|
|
extra = PR_MAX(extra, basesize);
|
2008-03-05 22:24:44 +03:00
|
|
|
offset = aOffset - basesize + extra;
|
2008-02-16 18:31:27 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NS_ERROR("Invalid decoration value!");
|
|
|
|
}
|
2008-03-05 22:24:44 +03:00
|
|
|
r.pos.y = baseline - NS_floor(offset + 0.5);
|
2008-02-16 18:31:27 +03:00
|
|
|
return r;
|
|
|
|
}
|
2008-06-13 02:02:32 +04:00
|
|
|
|
|
|
|
// -----
|
|
|
|
// nsContextBoxBlur
|
|
|
|
// -----
|
|
|
|
gfxContext*
|
|
|
|
nsContextBoxBlur::Init(const gfxRect& aRect, nscoord aBlurRadius,
|
|
|
|
PRInt32 aAppUnitsPerDevPixel,
|
2008-12-03 00:16:22 +03:00
|
|
|
gfxContext* aDestinationCtx,
|
|
|
|
const gfxRect& aDirtyRect)
|
2008-06-13 02:02:32 +04:00
|
|
|
{
|
2008-09-25 23:53:09 +04:00
|
|
|
mDestinationCtx = aDestinationCtx;
|
2008-06-13 02:02:32 +04:00
|
|
|
|
2008-09-25 23:53:09 +04:00
|
|
|
PRInt32 blurRadius = static_cast<PRInt32>(aBlurRadius / aAppUnitsPerDevPixel);
|
|
|
|
|
|
|
|
// if not blurring, draw directly onto the destination device
|
|
|
|
if (blurRadius <= 0) {
|
2008-06-13 02:02:32 +04:00
|
|
|
mContext = aDestinationCtx;
|
|
|
|
return mContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert from app units to device pixels
|
2008-09-25 23:53:09 +04:00
|
|
|
gfxRect rect = aRect;
|
|
|
|
rect.ScaleInverse(aAppUnitsPerDevPixel);
|
2008-06-13 02:02:32 +04:00
|
|
|
|
2008-09-25 23:53:09 +04:00
|
|
|
if (rect.IsEmpty()) {
|
2008-07-14 14:35:15 +04:00
|
|
|
mContext = aDestinationCtx;
|
|
|
|
return mContext;
|
|
|
|
}
|
|
|
|
|
2008-12-03 00:16:22 +03:00
|
|
|
gfxRect dirtyRect = aDirtyRect;
|
|
|
|
dirtyRect.ScaleInverse(aAppUnitsPerDevPixel);
|
|
|
|
|
2008-07-14 14:35:15 +04:00
|
|
|
mDestinationCtx = aDestinationCtx;
|
|
|
|
|
2008-12-06 21:54:36 +03:00
|
|
|
// Create the temporary surface for blurring
|
|
|
|
mContext = blur.Init(rect, gfxIntSize(blurRadius, blurRadius), &dirtyRect);
|
2008-06-13 02:02:32 +04:00
|
|
|
return mContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsContextBoxBlur::DoPaint()
|
|
|
|
{
|
2008-09-25 23:53:09 +04:00
|
|
|
if (mContext == mDestinationCtx)
|
2008-06-13 02:02:32 +04:00
|
|
|
return;
|
|
|
|
|
2008-09-25 23:53:09 +04:00
|
|
|
blur.Paint(mDestinationCtx);
|
2008-06-13 02:02:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxContext*
|
|
|
|
nsContextBoxBlur::GetContext()
|
|
|
|
{
|
|
|
|
return mContext;
|
|
|
|
}
|
2008-12-03 00:16:22 +03:00
|
|
|
|