2008-07-23 10:25:23 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:cindent:ts=2:et:sw=2:
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsPoint.h"
|
|
|
|
#include "nsRect.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsCSSAnonBoxes.h"
|
|
|
|
#include "nsTransform2D.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
|
|
|
#include "imgIRequest.h"
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsCSSColorUtils.h"
|
|
|
|
#include "nsITheme.h"
|
|
|
|
#include "nsThemeConstants.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsBlockFrame.h"
|
2012-04-16 11:37:59 -07:00
|
|
|
#include "sampler.h"
|
2012-10-26 21:32:52 -07:00
|
|
|
#include "nsExpirationTracker.h"
|
2012-11-12 17:55:26 -08:00
|
|
|
#include "RoundedRect.h"
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
#include "gfxContext.h"
|
|
|
|
|
|
|
|
#include "nsCSSRenderingBorders.h"
|
|
|
|
|
2012-10-26 21:32:52 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "gfx2DGlue.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
|
|
|
struct BorderGradientCacheKey : public PLDHashEntryHdr {
|
|
|
|
typedef const BorderGradientCacheKey& KeyType;
|
|
|
|
typedef const BorderGradientCacheKey* KeyTypePointer;
|
|
|
|
|
|
|
|
enum { ALLOW_MEMMOVE = true };
|
|
|
|
|
|
|
|
const uint32_t mColor1;
|
|
|
|
const uint32_t mColor2;
|
|
|
|
const BackendType mBackendType;
|
|
|
|
|
|
|
|
BorderGradientCacheKey(const Color& aColor1, const Color& aColor2,
|
|
|
|
BackendType aBackendType)
|
|
|
|
: mColor1(aColor1.ToABGR()), mColor2(aColor2.ToABGR())
|
|
|
|
, mBackendType(aBackendType)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
BorderGradientCacheKey(const BorderGradientCacheKey* aOther)
|
|
|
|
: mColor1(aOther->mColor1), mColor2(aOther->mColor2)
|
|
|
|
, mBackendType(aOther->mBackendType)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
static PLDHashNumber
|
|
|
|
HashKey(const KeyTypePointer aKey)
|
|
|
|
{
|
|
|
|
PLDHashNumber hash = 0;
|
|
|
|
hash = AddToHash(hash, aKey->mColor1);
|
|
|
|
hash = AddToHash(hash, aKey->mColor2);
|
|
|
|
hash = AddToHash(hash, aKey->mBackendType);
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KeyEquals(KeyTypePointer aKey) const
|
|
|
|
{
|
|
|
|
return (aKey->mColor1 == mColor1) &&
|
|
|
|
(aKey->mColor2 == mColor2) &&
|
|
|
|
(aKey->mBackendType == mBackendType);
|
|
|
|
}
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey)
|
|
|
|
{
|
|
|
|
return &aKey;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is what is cached. It need to be allocated in an object separated
|
|
|
|
* to the cache entry to be able to be tracked by the nsExpirationTracker.
|
|
|
|
* */
|
|
|
|
struct BorderGradientCacheData {
|
|
|
|
BorderGradientCacheData(GradientStops* aStops, const BorderGradientCacheKey& aKey)
|
|
|
|
: mStops(aStops), mKey(aKey)
|
|
|
|
{}
|
|
|
|
|
|
|
|
BorderGradientCacheData(const BorderGradientCacheData& aOther)
|
|
|
|
: mStops(aOther.mStops),
|
|
|
|
mKey(aOther.mKey)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
nsExpirationState *GetExpirationState() {
|
|
|
|
return &mExpirationState;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsExpirationState mExpirationState;
|
|
|
|
RefPtr<GradientStops> mStops;
|
|
|
|
BorderGradientCacheKey mKey;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class implements a cache with no maximum size, that retains the
|
|
|
|
* gradient stops used to draw border corners.
|
|
|
|
*
|
|
|
|
* The key is formed by the two gradient stops, they're always both located
|
|
|
|
* at an offset of 0.5. So they can generously be reused. The key also includes
|
|
|
|
* the backend type a certain gradient was created for.
|
|
|
|
*
|
|
|
|
* An entry stays in the cache as long as it is used often.
|
|
|
|
*
|
|
|
|
* This code was pretty bluntly stolen and modified from nsCSSRendering.
|
|
|
|
*/
|
|
|
|
class BorderGradientCache MOZ_FINAL : public nsExpirationTracker<BorderGradientCacheData,4>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BorderGradientCache()
|
|
|
|
: nsExpirationTracker<BorderGradientCacheData, 4>(GENERATION_MS)
|
|
|
|
{
|
|
|
|
mHashEntries.Init();
|
|
|
|
mTimerPeriod = GENERATION_MS;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void NotifyExpired(BorderGradientCacheData* aObject)
|
|
|
|
{
|
|
|
|
// This will free the gfxPattern.
|
|
|
|
RemoveObject(aObject);
|
|
|
|
mHashEntries.Remove(aObject->mKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
BorderGradientCacheData* Lookup(const Color& aColor1, const Color& aColor2,
|
|
|
|
BackendType aBackendType)
|
|
|
|
{
|
|
|
|
BorderGradientCacheData* gradient =
|
|
|
|
mHashEntries.Get(BorderGradientCacheKey(aColor1, aColor2, aBackendType));
|
|
|
|
|
|
|
|
if (gradient) {
|
|
|
|
MarkUsed(gradient);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gradient;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if we successfully register the gradient in the cache, false
|
|
|
|
// otherwise.
|
|
|
|
bool RegisterEntry(BorderGradientCacheData* aValue)
|
|
|
|
{
|
|
|
|
nsresult rv = AddObject(aValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// We are OOM, and we cannot track this object. We don't want stall
|
|
|
|
// entries in the hash table (since the expiration tracker is responsible
|
|
|
|
// for removing the cache entries), so we avoid putting that entry in the
|
|
|
|
// table, which is a good things considering we are short on memory
|
|
|
|
// anyway, we probably don't want to retain things.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mHashEntries.Put(aValue->mKey, aValue);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint32_t mTimerPeriod;
|
|
|
|
static const uint32_t GENERATION_MS = 4000;
|
|
|
|
/**
|
|
|
|
* FIXME use nsTHashtable to avoid duplicating the BorderGradientCacheKey.
|
|
|
|
* This is analogous to the issue for the generic gradient cache:
|
|
|
|
* https://bugzilla.mozilla.org/show_bug.cgi?id=785794
|
|
|
|
*/
|
|
|
|
nsClassHashtable<BorderGradientCacheKey, BorderGradientCacheData> mHashEntries;
|
|
|
|
};
|
|
|
|
|
2008-07-23 10:25:23 -07:00
|
|
|
/**
|
|
|
|
* nsCSSRendering::PaintBorder
|
|
|
|
* nsCSSRendering::PaintOutline
|
|
|
|
* -> DrawBorders
|
|
|
|
*
|
|
|
|
* DrawBorders
|
2010-12-02 05:17:58 -08:00
|
|
|
* -> Ability to use specialized approach?
|
|
|
|
* |- Draw using specialized function
|
2008-07-23 10:25:23 -07:00
|
|
|
* |- separate corners?
|
|
|
|
* |- dashed side mask
|
|
|
|
* |
|
|
|
|
* -> can border be drawn in 1 pass? (e.g., solid border same color all around)
|
|
|
|
* |- DrawBorderSides with all 4 sides
|
|
|
|
* -> more than 1 pass?
|
|
|
|
* |- for each corner
|
|
|
|
* |- clip to DoCornerClipSubPath
|
|
|
|
* |- for each side adjacent to corner
|
|
|
|
* |- clip to DoSideClipSubPath
|
|
|
|
* |- DrawBorderSides with one side
|
|
|
|
* |- for each side
|
|
|
|
* |- DoSideClipWithoutCornersSubPath
|
|
|
|
* |- DrawDashedSide || DrawBorderSides with one side
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void ComputeBorderCornerDimensions(const gfxRect& aOuterRect,
|
|
|
|
const gfxRect& aInnerRect,
|
|
|
|
const gfxCornerSizes& aRadii,
|
|
|
|
gfxCornerSizes *aDimsResult);
|
|
|
|
|
|
|
|
// given a side index, get the previous and next side index
|
2010-04-27 09:15:02 -07:00
|
|
|
#define NEXT_SIDE(_s) mozilla::css::Side(((_s) + 1) & 3)
|
|
|
|
#define PREV_SIDE(_s) mozilla::css::Side(((_s) + 3) & 3)
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
// from the given base color and the background color, turn
|
|
|
|
// color into a color for the given border pattern style
|
|
|
|
static gfxRGBA MakeBorderColor(const gfxRGBA& aColor,
|
|
|
|
const gfxRGBA& aBackgroundColor,
|
|
|
|
BorderColorStyle aBorderColorStyle);
|
|
|
|
|
|
|
|
|
|
|
|
// Given a line index (an index starting from the outside of the
|
|
|
|
// border going inwards) and an array of line styles, calculate the
|
|
|
|
// color that that stripe of the border should be rendered in.
|
2012-08-22 08:56:38 -07:00
|
|
|
static gfxRGBA ComputeColorForLine(uint32_t aLineIndex,
|
2008-07-23 10:25:23 -07:00
|
|
|
const BorderColorStyle* aBorderColorStyle,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aBorderColorStyleCount,
|
2008-07-23 10:25:23 -07:00
|
|
|
nscolor aBorderColor,
|
|
|
|
nscolor aBackgroundColor);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static gfxRGBA ComputeCompositeColorForLine(uint32_t aLineIndex,
|
2008-07-23 10:25:23 -07:00
|
|
|
const nsBorderColors* aBorderColors);
|
|
|
|
|
|
|
|
// little helper function to check if the array of 4 floats given are
|
|
|
|
// equal to the given value
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2008-07-23 10:25:23 -07:00
|
|
|
CheckFourFloatsEqual(const gfxFloat *vals, gfxFloat k)
|
|
|
|
{
|
|
|
|
return (vals[0] == k &&
|
|
|
|
vals[1] == k &&
|
|
|
|
vals[2] == k &&
|
|
|
|
vals[3] == k);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsZeroSize(const gfxSize& sz) {
|
|
|
|
return sz.width == 0.0 || sz.height == 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
AllCornersZeroSize(const gfxCornerSizes& corners) {
|
2010-04-27 09:15:02 -07:00
|
|
|
return IsZeroSize(corners[NS_CORNER_TOP_LEFT]) &&
|
|
|
|
IsZeroSize(corners[NS_CORNER_TOP_RIGHT]) &&
|
|
|
|
IsZeroSize(corners[NS_CORNER_BOTTOM_RIGHT]) &&
|
|
|
|
IsZeroSize(corners[NS_CORNER_BOTTOM_LEFT]);
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
// Normal solid square corner. Will be rectangular, the size of the
|
|
|
|
// adjacent sides. If the corner has a border radius, the corner
|
|
|
|
// will always be solid, since we don't do dotted/dashed etc.
|
|
|
|
CORNER_NORMAL,
|
|
|
|
|
|
|
|
// Paint the corner in whatever style is not dotted/dashed of the
|
|
|
|
// adjacent corners.
|
|
|
|
CORNER_SOLID,
|
|
|
|
|
|
|
|
// Paint the corner as a dot, the size of the bigger of the adjacent
|
|
|
|
// sides.
|
|
|
|
CORNER_DOT
|
|
|
|
} CornerStyle;
|
|
|
|
|
2012-10-26 21:32:52 -07:00
|
|
|
static BorderGradientCache* gBorderGradientCache = nullptr;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsCSSBorderRenderer::nsCSSBorderRenderer(int32_t aAppUnitsPerPixel,
|
2008-07-23 10:25:23 -07:00
|
|
|
gfxContext* aDestContext,
|
|
|
|
gfxRect& aOuterRect,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint8_t* aBorderStyles,
|
2008-07-23 10:25:23 -07:00
|
|
|
const gfxFloat* aBorderWidths,
|
|
|
|
gfxCornerSizes& aBorderRadii,
|
|
|
|
const nscolor* aBorderColors,
|
|
|
|
nsBorderColors* const* aCompositeColors,
|
2012-08-09 00:09:40 -07:00
|
|
|
int aSkipSides,
|
2008-08-06 03:33:18 -07:00
|
|
|
nscolor aBackgroundColor)
|
2009-05-13 01:26:48 -07:00
|
|
|
: mContext(aDestContext),
|
2008-07-23 10:25:23 -07:00
|
|
|
mOuterRect(aOuterRect),
|
|
|
|
mBorderStyles(aBorderStyles),
|
|
|
|
mBorderWidths(aBorderWidths),
|
|
|
|
mBorderRadii(aBorderRadii),
|
|
|
|
mBorderColors(aBorderColors),
|
|
|
|
mCompositeColors(aCompositeColors),
|
2009-05-13 01:26:48 -07:00
|
|
|
mAUPP(aAppUnitsPerPixel),
|
2008-07-23 10:25:23 -07:00
|
|
|
mSkipSides(aSkipSides),
|
2008-08-06 03:33:18 -07:00
|
|
|
mBackgroundColor(aBackgroundColor)
|
2008-07-23 10:25:23 -07:00
|
|
|
{
|
|
|
|
if (!mCompositeColors) {
|
|
|
|
static nsBorderColors * const noColors[4] = { NULL };
|
|
|
|
mCompositeColors = &noColors[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
mInnerRect = mOuterRect;
|
2011-04-18 20:07:51 -07:00
|
|
|
mInnerRect.Deflate(
|
|
|
|
gfxMargin(mBorderStyles[3] != NS_STYLE_BORDER_STYLE_NONE ? mBorderWidths[3] : 0,
|
|
|
|
mBorderStyles[0] != NS_STYLE_BORDER_STYLE_NONE ? mBorderWidths[0] : 0,
|
|
|
|
mBorderStyles[1] != NS_STYLE_BORDER_STYLE_NONE ? mBorderWidths[1] : 0,
|
|
|
|
mBorderStyles[2] != NS_STYLE_BORDER_STYLE_NONE ? mBorderWidths[2] : 0));
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
ComputeBorderCornerDimensions(mOuterRect, mInnerRect, mBorderRadii, &mBorderCornerDimensions);
|
2008-07-23 10:25:51 -07:00
|
|
|
|
|
|
|
mOneUnitBorder = CheckFourFloatsEqual(mBorderWidths, 1.0);
|
|
|
|
mNoBorderRadius = AllCornersZeroSize(mBorderRadii);
|
2011-10-17 07:59:28 -07:00
|
|
|
mAvoidStroke = false;
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
|
2012-10-26 21:32:52 -07:00
|
|
|
void
|
|
|
|
nsCSSBorderRenderer::Init()
|
|
|
|
{
|
|
|
|
gBorderGradientCache = new BorderGradientCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSBorderRenderer::Shutdown()
|
|
|
|
{
|
|
|
|
delete gBorderGradientCache;
|
|
|
|
}
|
|
|
|
|
2009-01-08 16:28:32 -08:00
|
|
|
/* static */ void
|
|
|
|
nsCSSBorderRenderer::ComputeInnerRadii(const gfxCornerSizes& aRadii,
|
|
|
|
const gfxFloat *aBorderSizes,
|
|
|
|
gfxCornerSizes *aInnerRadiiRet)
|
2008-07-23 10:25:23 -07:00
|
|
|
{
|
|
|
|
gfxCornerSizes& iRadii = *aInnerRadiiRet;
|
|
|
|
|
2009-09-16 08:01:36 -07:00
|
|
|
iRadii[C_TL].width = NS_MAX(0.0, aRadii[C_TL].width - aBorderSizes[NS_SIDE_LEFT]);
|
|
|
|
iRadii[C_TL].height = NS_MAX(0.0, aRadii[C_TL].height - aBorderSizes[NS_SIDE_TOP]);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2009-09-16 08:01:36 -07:00
|
|
|
iRadii[C_TR].width = NS_MAX(0.0, aRadii[C_TR].width - aBorderSizes[NS_SIDE_RIGHT]);
|
|
|
|
iRadii[C_TR].height = NS_MAX(0.0, aRadii[C_TR].height - aBorderSizes[NS_SIDE_TOP]);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2009-09-16 08:01:36 -07:00
|
|
|
iRadii[C_BR].width = NS_MAX(0.0, aRadii[C_BR].width - aBorderSizes[NS_SIDE_RIGHT]);
|
|
|
|
iRadii[C_BR].height = NS_MAX(0.0, aRadii[C_BR].height - aBorderSizes[NS_SIDE_BOTTOM]);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2009-09-16 08:01:36 -07:00
|
|
|
iRadii[C_BL].width = NS_MAX(0.0, aRadii[C_BL].width - aBorderSizes[NS_SIDE_LEFT]);
|
|
|
|
iRadii[C_BL].height = NS_MAX(0.0, aRadii[C_BL].height - aBorderSizes[NS_SIDE_BOTTOM]);
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
|
2012-04-29 19:37:04 -07:00
|
|
|
/* static */ void
|
|
|
|
nsCSSBorderRenderer::ComputeOuterRadii(const gfxCornerSizes& aRadii,
|
|
|
|
const gfxFloat *aBorderSizes,
|
|
|
|
gfxCornerSizes *aOuterRadiiRet)
|
|
|
|
{
|
|
|
|
gfxCornerSizes& oRadii = *aOuterRadiiRet;
|
|
|
|
|
|
|
|
// default all corners to sharp corners
|
|
|
|
oRadii = gfxCornerSizes(0.0);
|
|
|
|
|
|
|
|
// round the edges that have radii > 0.0 to start with
|
|
|
|
if (aRadii[C_TL].width > 0.0 && aRadii[C_TL].height > 0.0) {
|
|
|
|
oRadii[C_TL].width = NS_MAX(0.0, aRadii[C_TL].width + aBorderSizes[NS_SIDE_LEFT]);
|
|
|
|
oRadii[C_TL].height = NS_MAX(0.0, aRadii[C_TL].height + aBorderSizes[NS_SIDE_TOP]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRadii[C_TR].width > 0.0 && aRadii[C_TR].height > 0.0) {
|
|
|
|
oRadii[C_TR].width = NS_MAX(0.0, aRadii[C_TR].width + aBorderSizes[NS_SIDE_RIGHT]);
|
|
|
|
oRadii[C_TR].height = NS_MAX(0.0, aRadii[C_TR].height + aBorderSizes[NS_SIDE_TOP]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRadii[C_BR].width > 0.0 && aRadii[C_BR].height > 0.0) {
|
|
|
|
oRadii[C_BR].width = NS_MAX(0.0, aRadii[C_BR].width + aBorderSizes[NS_SIDE_RIGHT]);
|
|
|
|
oRadii[C_BR].height = NS_MAX(0.0, aRadii[C_BR].height + aBorderSizes[NS_SIDE_BOTTOM]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRadii[C_BL].width > 0.0 && aRadii[C_BL].height > 0.0) {
|
|
|
|
oRadii[C_BL].width = NS_MAX(0.0, aRadii[C_BL].width + aBorderSizes[NS_SIDE_LEFT]);
|
|
|
|
oRadii[C_BL].height = NS_MAX(0.0, aRadii[C_BL].height + aBorderSizes[NS_SIDE_BOTTOM]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-23 10:25:23 -07:00
|
|
|
/*static*/ void
|
|
|
|
ComputeBorderCornerDimensions(const gfxRect& aOuterRect,
|
|
|
|
const gfxRect& aInnerRect,
|
|
|
|
const gfxCornerSizes& aRadii,
|
|
|
|
gfxCornerSizes *aDimsRet)
|
|
|
|
{
|
2011-04-18 20:07:21 -07:00
|
|
|
gfxFloat leftWidth = aInnerRect.X() - aOuterRect.X();
|
|
|
|
gfxFloat topWidth = aInnerRect.Y() - aOuterRect.Y();
|
|
|
|
gfxFloat rightWidth = aOuterRect.Width() - aInnerRect.Width() - leftWidth;
|
|
|
|
gfxFloat bottomWidth = aOuterRect.Height() - aInnerRect.Height() - topWidth;
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
if (AllCornersZeroSize(aRadii)) {
|
|
|
|
// These will always be in pixel units from CSS
|
|
|
|
(*aDimsRet)[C_TL] = gfxSize(leftWidth, topWidth);
|
|
|
|
(*aDimsRet)[C_TR] = gfxSize(rightWidth, topWidth);
|
|
|
|
(*aDimsRet)[C_BR] = gfxSize(rightWidth, bottomWidth);
|
|
|
|
(*aDimsRet)[C_BL] = gfxSize(leftWidth, bottomWidth);
|
|
|
|
} else {
|
|
|
|
// Always round up to whole pixels for the corners; it's safe to
|
|
|
|
// make the corners bigger than necessary, and this way we ensure
|
|
|
|
// that we avoid seams.
|
2009-09-16 08:01:36 -07:00
|
|
|
(*aDimsRet)[C_TL] = gfxSize(ceil(NS_MAX(leftWidth, aRadii[C_TL].width)),
|
|
|
|
ceil(NS_MAX(topWidth, aRadii[C_TL].height)));
|
|
|
|
(*aDimsRet)[C_TR] = gfxSize(ceil(NS_MAX(rightWidth, aRadii[C_TR].width)),
|
|
|
|
ceil(NS_MAX(topWidth, aRadii[C_TR].height)));
|
|
|
|
(*aDimsRet)[C_BR] = gfxSize(ceil(NS_MAX(rightWidth, aRadii[C_BR].width)),
|
|
|
|
ceil(NS_MAX(bottomWidth, aRadii[C_BR].height)));
|
|
|
|
(*aDimsRet)[C_BL] = gfxSize(ceil(NS_MAX(leftWidth, aRadii[C_BL].width)),
|
|
|
|
ceil(NS_MAX(bottomWidth, aRadii[C_BL].height)));
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsCSSBorderRenderer::AreBorderSideFinalStylesSame(uint8_t aSides)
|
2008-07-23 10:25:23 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aSides != 0 && (aSides & ~SIDE_BITS_ALL) == 0,
|
|
|
|
"AreBorderSidesSame: invalid whichSides!");
|
|
|
|
|
|
|
|
/* First check if the specified styles and colors are the same for all sides */
|
|
|
|
int firstStyle = 0;
|
|
|
|
NS_FOR_CSS_SIDES (i) {
|
|
|
|
if (firstStyle == i) {
|
|
|
|
if (((1 << i) & aSides) == 0)
|
|
|
|
firstStyle++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-11-19 08:53:08 -08:00
|
|
|
if (((1 << i) & aSides) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-07-23 10:25:23 -07:00
|
|
|
if (mBorderStyles[firstStyle] != mBorderStyles[i] ||
|
|
|
|
mBorderColors[firstStyle] != mBorderColors[i] ||
|
2008-09-12 08:35:53 -07:00
|
|
|
!nsBorderColors::Equal(mCompositeColors[firstStyle],
|
|
|
|
mCompositeColors[i]))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Then if it's one of the two-tone styles and we're not
|
|
|
|
* just comparing the TL or BR sides */
|
|
|
|
switch (mBorderStyles[firstStyle]) {
|
|
|
|
case NS_STYLE_BORDER_STYLE_GROOVE:
|
|
|
|
case NS_STYLE_BORDER_STYLE_RIDGE:
|
|
|
|
case NS_STYLE_BORDER_STYLE_INSET:
|
|
|
|
case NS_STYLE_BORDER_STYLE_OUTSET:
|
|
|
|
return ((aSides & ~(SIDE_BIT_TOP | SIDE_BIT_LEFT)) == 0 ||
|
|
|
|
(aSides & ~(SIDE_BIT_BOTTOM | SIDE_BIT_RIGHT)) == 0);
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsCSSBorderRenderer::IsSolidCornerStyle(uint8_t aStyle, mozilla::css::Corner aCorner)
|
2008-07-23 10:25:51 -07:00
|
|
|
{
|
|
|
|
switch (aStyle) {
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOTTED:
|
|
|
|
case NS_STYLE_BORDER_STYLE_DASHED:
|
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-07-23 10:25:51 -07:00
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_INSET:
|
|
|
|
case NS_STYLE_BORDER_STYLE_OUTSET:
|
2010-04-27 09:15:02 -07:00
|
|
|
return (aCorner == NS_CORNER_TOP_LEFT || aCorner == NS_CORNER_BOTTOM_RIGHT);
|
2008-07-23 10:25:51 -07:00
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_GROOVE:
|
|
|
|
case NS_STYLE_BORDER_STYLE_RIDGE:
|
2010-04-27 09:15:02 -07:00
|
|
|
return mOneUnitBorder && (aCorner == NS_CORNER_TOP_LEFT || aCorner == NS_CORNER_BOTTOM_RIGHT);
|
2008-07-23 10:25:51 -07:00
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOUBLE:
|
|
|
|
return mOneUnitBorder;
|
|
|
|
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-07-23 10:25:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BorderColorStyle
|
2012-08-22 08:56:38 -07:00
|
|
|
nsCSSBorderRenderer::BorderColorStyleForSolidCorner(uint8_t aStyle, mozilla::css::Corner aCorner)
|
2008-07-23 10:25:51 -07:00
|
|
|
{
|
|
|
|
// note that this function assumes that the corner is already solid,
|
|
|
|
// as per the earlier function
|
|
|
|
switch (aStyle) {
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOTTED:
|
|
|
|
case NS_STYLE_BORDER_STYLE_DASHED:
|
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOUBLE:
|
|
|
|
return BorderColorStyleSolid;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_INSET:
|
|
|
|
case NS_STYLE_BORDER_STYLE_GROOVE:
|
2010-04-27 09:15:02 -07:00
|
|
|
if (aCorner == NS_CORNER_TOP_LEFT)
|
2008-07-23 10:25:51 -07:00
|
|
|
return BorderColorStyleDark;
|
2010-04-27 09:15:02 -07:00
|
|
|
else if (aCorner == NS_CORNER_BOTTOM_RIGHT)
|
2008-07-23 10:25:51 -07:00
|
|
|
return BorderColorStyleLight;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_OUTSET:
|
|
|
|
case NS_STYLE_BORDER_STYLE_RIDGE:
|
2010-04-27 09:15:02 -07:00
|
|
|
if (aCorner == NS_CORNER_TOP_LEFT)
|
2008-07-23 10:25:51 -07:00
|
|
|
return BorderColorStyleLight;
|
2010-04-27 09:15:02 -07:00
|
|
|
else if (aCorner == NS_CORNER_BOTTOM_RIGHT)
|
2008-07-23 10:25:51 -07:00
|
|
|
return BorderColorStyleDark;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return BorderColorStyleNone;
|
|
|
|
}
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
void
|
2010-04-27 09:15:02 -07:00
|
|
|
nsCSSBorderRenderer::DoCornerSubPath(mozilla::css::Corner aCorner)
|
2008-07-23 10:25:23 -07:00
|
|
|
{
|
|
|
|
gfxPoint offset(0.0, 0.0);
|
|
|
|
|
|
|
|
if (aCorner == C_TR || aCorner == C_BR)
|
2011-04-18 20:07:21 -07:00
|
|
|
offset.x = mOuterRect.Width() - mBorderCornerDimensions[aCorner].width;
|
2008-07-23 10:25:23 -07:00
|
|
|
if (aCorner == C_BR || aCorner == C_BL)
|
2011-04-18 20:07:21 -07:00
|
|
|
offset.y = mOuterRect.Height() - mBorderCornerDimensions[aCorner].height;
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2011-04-18 20:07:21 -07:00
|
|
|
mContext->Rectangle(gfxRect(mOuterRect.TopLeft() + offset,
|
2008-07-23 10:25:23 -07:00
|
|
|
mBorderCornerDimensions[aCorner]));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-04-27 09:15:02 -07:00
|
|
|
nsCSSBorderRenderer::DoSideClipWithoutCornersSubPath(mozilla::css::Side aSide)
|
2008-07-23 10:25:23 -07:00
|
|
|
{
|
|
|
|
gfxPoint offset(0.0, 0.0);
|
|
|
|
|
|
|
|
// The offset from the outside rect to the start of this side's
|
|
|
|
// box. For the top and bottom sides, the height of the box
|
|
|
|
// must be the border height; the x start must take into account
|
|
|
|
// the corner size (which may be bigger than the right or left
|
|
|
|
// side's width). The same applies to the right and left sides.
|
|
|
|
if (aSide == NS_SIDE_TOP) {
|
|
|
|
offset.x = mBorderCornerDimensions[C_TL].width;
|
|
|
|
} else if (aSide == NS_SIDE_RIGHT) {
|
2011-04-18 20:07:21 -07:00
|
|
|
offset.x = mOuterRect.Width() - mBorderWidths[NS_SIDE_RIGHT];
|
2008-07-23 10:25:23 -07:00
|
|
|
offset.y = mBorderCornerDimensions[C_TR].height;
|
|
|
|
} else if (aSide == NS_SIDE_BOTTOM) {
|
|
|
|
offset.x = mBorderCornerDimensions[C_BL].width;
|
2011-04-18 20:07:21 -07:00
|
|
|
offset.y = mOuterRect.Height() - mBorderWidths[NS_SIDE_BOTTOM];
|
2008-07-23 10:25:23 -07:00
|
|
|
} else if (aSide == NS_SIDE_LEFT) {
|
|
|
|
offset.y = mBorderCornerDimensions[C_TL].height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The sum of the width & height of the corners adjacent to the
|
|
|
|
// side. This relies on the relationship between side indexing and
|
|
|
|
// corner indexing; that is, 0 == SIDE_TOP and 0 == CORNER_TOP_LEFT,
|
|
|
|
// with both proceeding clockwise.
|
2010-04-27 09:15:02 -07:00
|
|
|
gfxSize sideCornerSum = mBorderCornerDimensions[mozilla::css::Corner(aSide)]
|
|
|
|
+ mBorderCornerDimensions[mozilla::css::Corner(NEXT_SIDE(aSide))];
|
2011-04-18 20:07:21 -07:00
|
|
|
gfxRect rect(mOuterRect.TopLeft() + offset,
|
|
|
|
mOuterRect.Size() - sideCornerSum);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
if (aSide == NS_SIDE_TOP || aSide == NS_SIDE_BOTTOM)
|
2011-04-18 20:07:21 -07:00
|
|
|
rect.height = mBorderWidths[aSide];
|
2008-07-23 10:25:23 -07:00
|
|
|
else
|
2011-04-18 20:07:21 -07:00
|
|
|
rect.width = mBorderWidths[aSide];
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
mContext->Rectangle(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The side border type and the adjacent border types are
|
|
|
|
// examined and one of the different types of clipping (listed
|
|
|
|
// below) is selected.
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
// clip to the trapezoid formed by the corners of the
|
|
|
|
// inner and outer rectangles for the given side
|
|
|
|
SIDE_CLIP_TRAPEZOID,
|
|
|
|
|
|
|
|
// clip to the trapezoid formed by the outer rectangle
|
|
|
|
// corners and the center of the region, making sure
|
|
|
|
// that diagonal lines all go directly from the outside
|
|
|
|
// corner to the inside corner, but that they then continue on
|
|
|
|
// to the middle.
|
|
|
|
//
|
|
|
|
// This is needed for correctly clipping rounded borders,
|
|
|
|
// which might extend past the SIDE_CLIP_TRAPEZOID trap.
|
|
|
|
SIDE_CLIP_TRAPEZOID_FULL,
|
|
|
|
|
|
|
|
// clip to the rectangle formed by the given side; a specific
|
|
|
|
// overlap algorithm is used; see the function for details.
|
|
|
|
// this is currently used for dashing.
|
|
|
|
SIDE_CLIP_RECTANGLE
|
|
|
|
} SideClipType;
|
|
|
|
|
2010-11-10 07:49:53 -08:00
|
|
|
// Given three points, p0, p1, and midPoint, move p1 further in to the
|
|
|
|
// rectangle (of which aMidPoint is the center) so that it reaches the
|
|
|
|
// closer of the horizontal or vertical lines intersecting the midpoint,
|
2010-11-16 09:56:03 -08:00
|
|
|
// while maintaing the slope of the line. If p0 and p1 are the same,
|
|
|
|
// just move p1 to midPoint (since there's no slope to maintain).
|
2010-11-10 07:49:53 -08:00
|
|
|
// FIXME: Extending only to the midpoint isn't actually sufficient for
|
|
|
|
// boxes with asymmetric radii.
|
2008-07-23 10:25:23 -07:00
|
|
|
static void
|
|
|
|
MaybeMoveToMidPoint(gfxPoint& aP0, gfxPoint& aP1, const gfxPoint& aMidPoint)
|
|
|
|
{
|
|
|
|
gfxPoint ps = aP1 - aP0;
|
|
|
|
|
2010-10-26 11:30:42 -07:00
|
|
|
if (ps.x == 0.0) {
|
|
|
|
if (ps.y == 0.0) {
|
2010-11-16 09:56:03 -08:00
|
|
|
aP1 = aMidPoint;
|
2010-10-26 11:30:42 -07:00
|
|
|
} else {
|
|
|
|
aP1.y = aMidPoint.y;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ps.y == 0.0) {
|
|
|
|
aP1.x = aMidPoint.x;
|
|
|
|
} else {
|
|
|
|
gfxFloat k = NS_MIN((aMidPoint.x - aP0.x) / ps.x,
|
2010-11-10 07:49:53 -08:00
|
|
|
(aMidPoint.y - aP0.y) / ps.y);
|
2010-10-26 11:30:42 -07:00
|
|
|
aP1 = aP0 + ps * k;
|
|
|
|
}
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-04-27 09:15:02 -07:00
|
|
|
nsCSSBorderRenderer::DoSideClipSubPath(mozilla::css::Side aSide)
|
2008-07-23 10:25:23 -07:00
|
|
|
{
|
|
|
|
// the clip proceeds clockwise from the top left corner;
|
|
|
|
// so "start" in each case is the start of the region from that side.
|
|
|
|
//
|
|
|
|
// the final path will be formed like:
|
|
|
|
// s0 ------- e0
|
|
|
|
// | /
|
|
|
|
// s1 ----- e1
|
|
|
|
//
|
|
|
|
// that is, the second point will always be on the inside
|
|
|
|
|
|
|
|
gfxPoint start[2];
|
|
|
|
gfxPoint end[2];
|
|
|
|
|
|
|
|
#define IS_DASHED_OR_DOTTED(_s) ((_s) == NS_STYLE_BORDER_STYLE_DASHED || (_s) == NS_STYLE_BORDER_STYLE_DOTTED)
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isDashed = IS_DASHED_OR_DOTTED(mBorderStyles[aSide]);
|
|
|
|
bool startIsDashed = IS_DASHED_OR_DOTTED(mBorderStyles[PREV_SIDE(aSide)]);
|
|
|
|
bool endIsDashed = IS_DASHED_OR_DOTTED(mBorderStyles[NEXT_SIDE(aSide)]);
|
2008-07-23 10:25:23 -07:00
|
|
|
#undef IS_DASHED_OR_DOTTED
|
|
|
|
|
|
|
|
SideClipType startType = SIDE_CLIP_TRAPEZOID;
|
|
|
|
SideClipType endType = SIDE_CLIP_TRAPEZOID;
|
|
|
|
|
2010-04-27 09:15:02 -07:00
|
|
|
if (!IsZeroSize(mBorderRadii[mozilla::css::Corner(aSide)]))
|
2008-07-23 10:25:23 -07:00
|
|
|
startType = SIDE_CLIP_TRAPEZOID_FULL;
|
|
|
|
else if (startIsDashed && isDashed)
|
|
|
|
startType = SIDE_CLIP_RECTANGLE;
|
|
|
|
|
2010-04-27 09:15:02 -07:00
|
|
|
if (!IsZeroSize(mBorderRadii[mozilla::css::Corner(NEXT_SIDE(aSide))]))
|
2008-07-23 10:25:23 -07:00
|
|
|
endType = SIDE_CLIP_TRAPEZOID_FULL;
|
|
|
|
else if (endIsDashed && isDashed)
|
|
|
|
endType = SIDE_CLIP_RECTANGLE;
|
|
|
|
|
2011-04-18 20:07:21 -07:00
|
|
|
gfxPoint midPoint = mInnerRect.Center();
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2010-04-27 09:15:02 -07:00
|
|
|
start[0] = mOuterRect.CCWCorner(aSide);
|
|
|
|
start[1] = mInnerRect.CCWCorner(aSide);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2010-04-27 09:15:02 -07:00
|
|
|
end[0] = mOuterRect.CWCorner(aSide);
|
|
|
|
end[1] = mInnerRect.CWCorner(aSide);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
if (startType == SIDE_CLIP_TRAPEZOID_FULL) {
|
|
|
|
MaybeMoveToMidPoint(start[0], start[1], midPoint);
|
|
|
|
} else if (startType == SIDE_CLIP_RECTANGLE) {
|
|
|
|
if (aSide == NS_SIDE_TOP || aSide == NS_SIDE_BOTTOM)
|
2010-04-27 09:15:02 -07:00
|
|
|
start[1] = gfxPoint(mOuterRect.CCWCorner(aSide).x, mInnerRect.CCWCorner(aSide).y);
|
2008-07-23 10:25:23 -07:00
|
|
|
else
|
2010-04-27 09:15:02 -07:00
|
|
|
start[1] = gfxPoint(mInnerRect.CCWCorner(aSide).x, mOuterRect.CCWCorner(aSide).y);
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (endType == SIDE_CLIP_TRAPEZOID_FULL) {
|
|
|
|
MaybeMoveToMidPoint(end[0], end[1], midPoint);
|
|
|
|
} else if (endType == SIDE_CLIP_RECTANGLE) {
|
|
|
|
if (aSide == NS_SIDE_TOP || aSide == NS_SIDE_BOTTOM)
|
2010-04-27 09:15:02 -07:00
|
|
|
end[0] = gfxPoint(mInnerRect.CWCorner(aSide).x, mOuterRect.CWCorner(aSide).y);
|
2008-07-23 10:25:23 -07:00
|
|
|
else
|
2010-04-27 09:15:02 -07:00
|
|
|
end[0] = gfxPoint(mOuterRect.CWCorner(aSide).x, mInnerRect.CWCorner(aSide).y);
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mContext->MoveTo(start[0]);
|
|
|
|
mContext->LineTo(end[0]);
|
|
|
|
mContext->LineTo(end[1]);
|
|
|
|
mContext->LineTo(start[1]);
|
|
|
|
mContext->ClosePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSBorderRenderer::FillSolidBorder(const gfxRect& aOuterRect,
|
|
|
|
const gfxRect& aInnerRect,
|
|
|
|
const gfxCornerSizes& aBorderRadii,
|
|
|
|
const gfxFloat *aBorderSizes,
|
2012-08-09 00:09:40 -07:00
|
|
|
int aSides,
|
2008-07-23 10:25:23 -07:00
|
|
|
const gfxRGBA& aColor)
|
|
|
|
{
|
|
|
|
mContext->SetColor(aColor);
|
2008-07-23 10:25:51 -07:00
|
|
|
// Note that this function is allowed to draw more than just the
|
|
|
|
// requested sides.
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
// If we have a border radius, do full rounded rectangles
|
|
|
|
// and fill, regardless of what sides we're asked to draw.
|
|
|
|
if (!AllCornersZeroSize(aBorderRadii)) {
|
|
|
|
gfxCornerSizes innerRadii;
|
|
|
|
ComputeInnerRadii(aBorderRadii, aBorderSizes, &innerRadii);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
mContext->NewPath();
|
|
|
|
|
|
|
|
// do the outer border
|
2011-10-17 07:59:28 -07:00
|
|
|
mContext->RoundedRectangle(aOuterRect, aBorderRadii, true);
|
2008-07-23 10:25:51 -07:00
|
|
|
|
|
|
|
// then do the inner border CCW
|
2011-10-17 07:59:28 -07:00
|
|
|
mContext->RoundedRectangle(aInnerRect, innerRadii, false);
|
2008-07-23 10:25:51 -07:00
|
|
|
|
|
|
|
mContext->Fill();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're asked to draw all sides of an equal-sized border,
|
|
|
|
// stroking is fastest. This is a fairly common path, but partial
|
|
|
|
// sides is probably second in the list -- there are a bunch of
|
|
|
|
// common border styles, such as inset and outset, that are
|
|
|
|
// top-left/bottom-right split.
|
|
|
|
if (aSides == SIDE_BITS_ALL &&
|
2011-06-22 05:11:28 -07:00
|
|
|
CheckFourFloatsEqual(aBorderSizes, aBorderSizes[0]) &&
|
|
|
|
!mAvoidStroke)
|
2008-07-23 10:25:23 -07:00
|
|
|
{
|
2008-07-23 10:25:51 -07:00
|
|
|
gfxRect r(aOuterRect);
|
2011-04-18 20:07:51 -07:00
|
|
|
r.Deflate(aBorderSizes[0] / 2.0);
|
2008-07-23 10:25:51 -07:00
|
|
|
mContext->SetLineWidth(aBorderSizes[0]);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
mContext->NewPath();
|
|
|
|
mContext->Rectangle(r);
|
|
|
|
mContext->Stroke();
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
return;
|
|
|
|
}
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
// Otherwise, we have unequal sized borders or we're only
|
|
|
|
// drawing some sides; create rectangles for each side
|
|
|
|
// and fill them.
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
gfxRect r[4];
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
// compute base rects for each side
|
|
|
|
if (aSides & SIDE_BIT_TOP) {
|
2011-04-18 20:07:21 -07:00
|
|
|
r[NS_SIDE_TOP] =
|
|
|
|
gfxRect(aOuterRect.X(), aOuterRect.Y(),
|
|
|
|
aOuterRect.Width(), aBorderSizes[NS_SIDE_TOP]);
|
2008-07-23 10:25:51 -07:00
|
|
|
}
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
if (aSides & SIDE_BIT_BOTTOM) {
|
2011-04-18 20:07:21 -07:00
|
|
|
r[NS_SIDE_BOTTOM] =
|
|
|
|
gfxRect(aOuterRect.X(), aOuterRect.YMost() - aBorderSizes[NS_SIDE_BOTTOM],
|
|
|
|
aOuterRect.Width(), aBorderSizes[NS_SIDE_BOTTOM]);
|
2008-07-23 10:25:51 -07:00
|
|
|
}
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
if (aSides & SIDE_BIT_LEFT) {
|
2011-04-18 20:07:21 -07:00
|
|
|
r[NS_SIDE_LEFT] =
|
|
|
|
gfxRect(aOuterRect.X(), aOuterRect.Y(),
|
|
|
|
aBorderSizes[NS_SIDE_LEFT], aOuterRect.Height());
|
2008-07-23 10:25:51 -07:00
|
|
|
}
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
if (aSides & SIDE_BIT_RIGHT) {
|
2011-04-18 20:07:21 -07:00
|
|
|
r[NS_SIDE_RIGHT] =
|
|
|
|
gfxRect(aOuterRect.XMost() - aBorderSizes[NS_SIDE_RIGHT], aOuterRect.Y(),
|
|
|
|
aBorderSizes[NS_SIDE_RIGHT], aOuterRect.Height());
|
2008-07-23 10:25:51 -07:00
|
|
|
}
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
// If two sides meet at a corner that we're rendering, then
|
|
|
|
// make sure that we adjust one of the sides to avoid overlap.
|
|
|
|
// This is especially important in the case of colors with
|
|
|
|
// an alpha channel.
|
|
|
|
|
|
|
|
if ((aSides & (SIDE_BIT_TOP | SIDE_BIT_LEFT)) == (SIDE_BIT_TOP | SIDE_BIT_LEFT)) {
|
|
|
|
// adjust the left's top down a bit
|
2011-04-18 20:07:21 -07:00
|
|
|
r[NS_SIDE_LEFT].y += aBorderSizes[NS_SIDE_TOP];
|
|
|
|
r[NS_SIDE_LEFT].height -= aBorderSizes[NS_SIDE_TOP];
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
if ((aSides & (SIDE_BIT_TOP | SIDE_BIT_RIGHT)) == (SIDE_BIT_TOP | SIDE_BIT_RIGHT)) {
|
|
|
|
// adjust the top's left a bit
|
2011-04-18 20:07:21 -07:00
|
|
|
r[NS_SIDE_TOP].width -= aBorderSizes[NS_SIDE_RIGHT];
|
2008-07-23 10:25:51 -07:00
|
|
|
}
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
if ((aSides & (SIDE_BIT_BOTTOM | SIDE_BIT_RIGHT)) == (SIDE_BIT_BOTTOM | SIDE_BIT_RIGHT)) {
|
|
|
|
// adjust the right's bottom a bit
|
2011-04-18 20:07:21 -07:00
|
|
|
r[NS_SIDE_RIGHT].height -= aBorderSizes[NS_SIDE_BOTTOM];
|
2008-07-23 10:25:51 -07:00
|
|
|
}
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
if ((aSides & (SIDE_BIT_BOTTOM | SIDE_BIT_LEFT)) == (SIDE_BIT_BOTTOM | SIDE_BIT_LEFT)) {
|
|
|
|
// adjust the bottom's left a bit
|
2011-04-18 20:07:21 -07:00
|
|
|
r[NS_SIDE_BOTTOM].x += aBorderSizes[NS_SIDE_LEFT];
|
|
|
|
r[NS_SIDE_BOTTOM].width -= aBorderSizes[NS_SIDE_LEFT];
|
2008-07-23 10:25:51 -07:00
|
|
|
}
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
// Filling these one by one is faster than filling them all at once.
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < 4; i++) {
|
2008-07-23 10:25:51 -07:00
|
|
|
if (aSides & (1 << i)) {
|
|
|
|
mContext->NewPath();
|
2011-10-17 07:59:28 -07:00
|
|
|
mContext->Rectangle(r[i], true);
|
2008-07-23 10:25:51 -07:00
|
|
|
mContext->Fill();
|
|
|
|
}
|
|
|
|
}
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxRGBA
|
|
|
|
MakeBorderColor(const gfxRGBA& aColor, const gfxRGBA& aBackgroundColor, BorderColorStyle aBorderColorStyle)
|
|
|
|
{
|
|
|
|
nscolor colors[2];
|
|
|
|
int k = 0;
|
|
|
|
|
|
|
|
switch (aBorderColorStyle) {
|
|
|
|
case BorderColorStyleNone:
|
|
|
|
return gfxRGBA(0.0, 0.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
case BorderColorStyleLight:
|
|
|
|
k = 1;
|
|
|
|
/* fall through */
|
|
|
|
case BorderColorStyleDark:
|
|
|
|
NS_GetSpecial3DColors(colors, aBackgroundColor.Packed(), aColor.Packed());
|
|
|
|
return gfxRGBA(colors[k]);
|
|
|
|
|
|
|
|
case BorderColorStyleSolid:
|
|
|
|
default:
|
|
|
|
return aColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxRGBA
|
2012-08-22 08:56:38 -07:00
|
|
|
ComputeColorForLine(uint32_t aLineIndex,
|
2008-07-23 10:25:23 -07:00
|
|
|
const BorderColorStyle* aBorderColorStyle,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aBorderColorStyleCount,
|
2008-07-23 10:25:23 -07:00
|
|
|
nscolor aBorderColor,
|
|
|
|
nscolor aBackgroundColor)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aLineIndex < aBorderColorStyleCount, "Invalid lineIndex given");
|
|
|
|
|
|
|
|
return MakeBorderColor(gfxRGBA(aBorderColor), gfxRGBA(aBackgroundColor), aBorderColorStyle[aLineIndex]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxRGBA
|
2012-08-22 08:56:38 -07:00
|
|
|
ComputeCompositeColorForLine(uint32_t aLineIndex,
|
2008-07-23 10:25:23 -07:00
|
|
|
const nsBorderColors* aBorderColors)
|
|
|
|
{
|
|
|
|
while (aLineIndex-- && aBorderColors->mNext)
|
|
|
|
aBorderColors = aBorderColors->mNext;
|
|
|
|
|
|
|
|
return gfxRGBA(aBorderColors->mColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-09 00:09:40 -07:00
|
|
|
nsCSSBorderRenderer::DrawBorderSidesCompositeColors(int aSides, const nsBorderColors *aCompositeColors)
|
2008-07-23 10:25:23 -07:00
|
|
|
{
|
|
|
|
gfxCornerSizes radii = mBorderRadii;
|
|
|
|
|
|
|
|
// the generic composite colors path; each border is 1px in size
|
|
|
|
gfxRect soRect = mOuterRect;
|
|
|
|
gfxFloat maxBorderWidth = 0;
|
|
|
|
NS_FOR_CSS_SIDES (i) {
|
2009-09-16 08:01:36 -07:00
|
|
|
maxBorderWidth = NS_MAX(maxBorderWidth, mBorderWidths[i]);
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat fakeBorderSizes[4];
|
|
|
|
|
|
|
|
gfxPoint itl = mInnerRect.TopLeft();
|
|
|
|
gfxPoint ibr = mInnerRect.BottomRight();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < uint32_t(maxBorderWidth); i++) {
|
2011-04-18 20:07:21 -07:00
|
|
|
gfxRGBA lineColor = ComputeCompositeColorForLine(i, aCompositeColors);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2011-04-18 20:07:21 -07:00
|
|
|
gfxRect siRect = soRect;
|
2011-04-18 20:07:51 -07:00
|
|
|
siRect.Deflate(1.0);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
// now cap the rects to the real mInnerRect
|
2011-04-18 20:07:21 -07:00
|
|
|
gfxPoint tl = siRect.TopLeft();
|
|
|
|
gfxPoint br = siRect.BottomRight();
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2009-09-16 08:01:36 -07:00
|
|
|
tl.x = NS_MIN(tl.x, itl.x);
|
|
|
|
tl.y = NS_MIN(tl.y, itl.y);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2009-09-16 08:01:36 -07:00
|
|
|
br.x = NS_MAX(br.x, ibr.x);
|
|
|
|
br.y = NS_MAX(br.y, ibr.y);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2011-04-18 20:07:21 -07:00
|
|
|
siRect = gfxRect(tl.x, tl.y, br.x - tl.x , br.y - tl.y);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
fakeBorderSizes[NS_SIDE_TOP] = siRect.TopLeft().y - soRect.TopLeft().y;
|
|
|
|
fakeBorderSizes[NS_SIDE_RIGHT] = soRect.TopRight().x - siRect.TopRight().x;
|
|
|
|
fakeBorderSizes[NS_SIDE_BOTTOM] = soRect.BottomRight().y - siRect.BottomRight().y;
|
|
|
|
fakeBorderSizes[NS_SIDE_LEFT] = siRect.BottomLeft().x - soRect.BottomLeft().x;
|
|
|
|
|
|
|
|
FillSolidBorder(soRect, siRect, radii, fakeBorderSizes, aSides, lineColor);
|
|
|
|
|
|
|
|
soRect = siRect;
|
|
|
|
|
|
|
|
ComputeInnerRadii(radii, fakeBorderSizes, &radii);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-09 00:09:40 -07:00
|
|
|
nsCSSBorderRenderer::DrawBorderSides(int aSides)
|
2008-07-23 10:25:23 -07:00
|
|
|
{
|
|
|
|
if (aSides == 0 || (aSides & ~SIDE_BITS_ALL) != 0) {
|
|
|
|
NS_WARNING("DrawBorderSides: invalid sides!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t borderRenderStyle;
|
2008-07-23 10:25:23 -07:00
|
|
|
nscolor borderRenderColor;
|
2012-07-30 07:20:58 -07:00
|
|
|
const nsBorderColors *compositeColors = nullptr;
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t borderColorStyleCount = 0;
|
2008-07-23 10:25:23 -07:00
|
|
|
BorderColorStyle borderColorStyleTopLeft[3], borderColorStyleBottomRight[3];
|
2012-07-30 07:20:58 -07:00
|
|
|
BorderColorStyle *borderColorStyle = nullptr;
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
NS_FOR_CSS_SIDES (i) {
|
|
|
|
if ((aSides & (1 << i)) == 0)
|
|
|
|
continue;
|
|
|
|
borderRenderStyle = mBorderStyles[i];
|
|
|
|
borderRenderColor = mBorderColors[i];
|
|
|
|
compositeColors = mCompositeColors[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (borderRenderStyle == NS_STYLE_BORDER_STYLE_NONE ||
|
|
|
|
borderRenderStyle == NS_STYLE_BORDER_STYLE_HIDDEN)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// -moz-border-colors is a hack; if we have it for a border, then
|
|
|
|
// it's always drawn solid, and each color is given 1px. The last
|
|
|
|
// color is used for the remainder of the border's size. Just
|
|
|
|
// hand off to another function to do all that.
|
|
|
|
if (compositeColors) {
|
|
|
|
DrawBorderSidesCompositeColors(aSides, compositeColors);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're not doing compositeColors, so we can calculate the
|
|
|
|
// borderColorStyle based on the specified style. The
|
|
|
|
// borderColorStyle array goes from the outer to the inner style.
|
|
|
|
//
|
|
|
|
// If the border width is 1, we need to change the borderRenderStyle
|
|
|
|
// a bit to make sure that we get the right colors -- e.g. 'ridge'
|
|
|
|
// with a 1px border needs to look like solid, not like 'outset'.
|
2008-07-23 10:25:51 -07:00
|
|
|
if (mOneUnitBorder &&
|
|
|
|
(borderRenderStyle == NS_STYLE_BORDER_STYLE_RIDGE ||
|
|
|
|
borderRenderStyle == NS_STYLE_BORDER_STYLE_GROOVE ||
|
|
|
|
borderRenderStyle == NS_STYLE_BORDER_STYLE_DOUBLE))
|
|
|
|
borderRenderStyle = NS_STYLE_BORDER_STYLE_SOLID;
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
switch (borderRenderStyle) {
|
|
|
|
case NS_STYLE_BORDER_STYLE_SOLID:
|
|
|
|
case NS_STYLE_BORDER_STYLE_DASHED:
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOTTED:
|
|
|
|
borderColorStyleTopLeft[0] = BorderColorStyleSolid;
|
|
|
|
|
|
|
|
borderColorStyleBottomRight[0] = BorderColorStyleSolid;
|
|
|
|
|
|
|
|
borderColorStyleCount = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_GROOVE:
|
|
|
|
borderColorStyleTopLeft[0] = BorderColorStyleDark;
|
|
|
|
borderColorStyleTopLeft[1] = BorderColorStyleLight;
|
|
|
|
|
|
|
|
borderColorStyleBottomRight[0] = BorderColorStyleLight;
|
|
|
|
borderColorStyleBottomRight[1] = BorderColorStyleDark;
|
|
|
|
|
|
|
|
borderColorStyleCount = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_RIDGE:
|
|
|
|
borderColorStyleTopLeft[0] = BorderColorStyleLight;
|
|
|
|
borderColorStyleTopLeft[1] = BorderColorStyleDark;
|
|
|
|
|
|
|
|
borderColorStyleBottomRight[0] = BorderColorStyleDark;
|
|
|
|
borderColorStyleBottomRight[1] = BorderColorStyleLight;
|
|
|
|
|
|
|
|
borderColorStyleCount = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_DOUBLE:
|
|
|
|
borderColorStyleTopLeft[0] = BorderColorStyleSolid;
|
|
|
|
borderColorStyleTopLeft[1] = BorderColorStyleNone;
|
|
|
|
borderColorStyleTopLeft[2] = BorderColorStyleSolid;
|
|
|
|
|
|
|
|
borderColorStyleBottomRight[0] = BorderColorStyleSolid;
|
|
|
|
borderColorStyleBottomRight[1] = BorderColorStyleNone;
|
|
|
|
borderColorStyleBottomRight[2] = BorderColorStyleSolid;
|
|
|
|
|
|
|
|
borderColorStyleCount = 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_INSET:
|
|
|
|
borderColorStyleTopLeft[0] = BorderColorStyleDark;
|
|
|
|
borderColorStyleBottomRight[0] = BorderColorStyleLight;
|
|
|
|
|
|
|
|
borderColorStyleCount = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_BORDER_STYLE_OUTSET:
|
|
|
|
borderColorStyleTopLeft[0] = BorderColorStyleLight;
|
|
|
|
borderColorStyleBottomRight[0] = BorderColorStyleDark;
|
|
|
|
|
|
|
|
borderColorStyleCount = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unhandled border style!!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The only way to get to here is by having a
|
|
|
|
// borderColorStyleCount < 1 or > 3; this should never happen,
|
|
|
|
// since -moz-border-colors doesn't get handled here.
|
|
|
|
NS_ASSERTION(borderColorStyleCount > 0 && borderColorStyleCount < 4,
|
|
|
|
"Non-border-colors case with borderColorStyleCount < 1 or > 3; what happened?");
|
|
|
|
|
|
|
|
// The caller should never give us anything with a mix
|
|
|
|
// of TL/BR if the border style would require a
|
|
|
|
// TL/BR split.
|
|
|
|
if (aSides & (SIDE_BIT_BOTTOM | SIDE_BIT_RIGHT))
|
|
|
|
borderColorStyle = borderColorStyleBottomRight;
|
|
|
|
else
|
|
|
|
borderColorStyle = borderColorStyleTopLeft;
|
|
|
|
|
|
|
|
// Distribute the border across the available space.
|
|
|
|
gfxFloat borderWidths[3][4];
|
|
|
|
|
|
|
|
if (borderColorStyleCount == 1) {
|
|
|
|
NS_FOR_CSS_SIDES (i) {
|
|
|
|
borderWidths[0][i] = mBorderWidths[i];
|
|
|
|
}
|
|
|
|
} else if (borderColorStyleCount == 2) {
|
|
|
|
// with 2 color styles, any extra pixel goes to the outside
|
|
|
|
NS_FOR_CSS_SIDES (i) {
|
2012-08-22 08:56:38 -07:00
|
|
|
borderWidths[0][i] = int32_t(mBorderWidths[i]) / 2 + int32_t(mBorderWidths[i]) % 2;
|
|
|
|
borderWidths[1][i] = int32_t(mBorderWidths[i]) / 2;
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
} else if (borderColorStyleCount == 3) {
|
|
|
|
// with 3 color styles, any extra pixel (or lack of extra pixel)
|
|
|
|
// goes to the middle
|
|
|
|
NS_FOR_CSS_SIDES (i) {
|
|
|
|
if (mBorderWidths[i] == 1.0) {
|
|
|
|
borderWidths[0][i] = 1.0;
|
|
|
|
borderWidths[1][i] = borderWidths[2][i] = 0.0;
|
|
|
|
} else {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t rest = int32_t(mBorderWidths[i]) % 3;
|
|
|
|
borderWidths[0][i] = borderWidths[2][i] = borderWidths[1][i] = (int32_t(mBorderWidths[i]) - rest) / 3;
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
if (rest == 1) {
|
|
|
|
borderWidths[1][i] += 1.0;
|
|
|
|
} else if (rest == 2) {
|
|
|
|
borderWidths[0][i] += 1.0;
|
|
|
|
borderWidths[2][i] += 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// make a copy that we can modify
|
|
|
|
gfxCornerSizes radii = mBorderRadii;
|
|
|
|
|
|
|
|
gfxRect soRect(mOuterRect);
|
|
|
|
gfxRect siRect(mOuterRect);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < borderColorStyleCount; i++) {
|
|
|
|
// walk siRect inwards at the start of the loop to get the
|
|
|
|
// correct inner rect.
|
2011-04-18 20:07:51 -07:00
|
|
|
siRect.Deflate(gfxMargin(borderWidths[i][3], borderWidths[i][0],
|
|
|
|
borderWidths[i][1], borderWidths[i][2]));
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
if (borderColorStyle[i] != BorderColorStyleNone) {
|
|
|
|
gfxRGBA color = ComputeColorForLine(i,
|
|
|
|
borderColorStyle, borderColorStyleCount,
|
|
|
|
borderRenderColor, mBackgroundColor);
|
|
|
|
|
|
|
|
FillSolidBorder(soRect, siRect, radii, borderWidths[i], aSides, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
ComputeInnerRadii(radii, borderWidths[i], &radii);
|
|
|
|
|
|
|
|
// And now soRect is the same as siRect, for the next line in.
|
|
|
|
soRect = siRect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-04-27 09:15:02 -07:00
|
|
|
nsCSSBorderRenderer::DrawDashedSide(mozilla::css::Side aSide)
|
2008-07-23 10:25:23 -07:00
|
|
|
{
|
|
|
|
gfxFloat dashWidth;
|
|
|
|
gfxFloat dash[2];
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t style = mBorderStyles[aSide];
|
2008-07-23 10:25:23 -07:00
|
|
|
gfxFloat borderWidth = mBorderWidths[aSide];
|
|
|
|
nscolor borderColor = mBorderColors[aSide];
|
|
|
|
|
|
|
|
if (borderWidth == 0.0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (style == NS_STYLE_BORDER_STYLE_NONE ||
|
|
|
|
style == NS_STYLE_BORDER_STYLE_HIDDEN)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (style == NS_STYLE_BORDER_STYLE_DASHED) {
|
|
|
|
dashWidth = gfxFloat(borderWidth * DOT_LENGTH * DASH_LENGTH);
|
|
|
|
|
|
|
|
dash[0] = dashWidth;
|
|
|
|
dash[1] = dashWidth;
|
|
|
|
|
|
|
|
mContext->SetLineCap(gfxContext::LINE_CAP_BUTT);
|
|
|
|
} else if (style == NS_STYLE_BORDER_STYLE_DOTTED) {
|
|
|
|
dashWidth = gfxFloat(borderWidth * DOT_LENGTH);
|
|
|
|
|
|
|
|
if (borderWidth > 2.0) {
|
|
|
|
dash[0] = 0.0;
|
|
|
|
dash[1] = dashWidth * 2.0;
|
|
|
|
|
|
|
|
mContext->SetLineCap(gfxContext::LINE_CAP_ROUND);
|
|
|
|
} else {
|
|
|
|
dash[0] = dashWidth;
|
|
|
|
dash[1] = dashWidth;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SF("DrawDashedSide: style: %d!!\n", style);
|
|
|
|
NS_ERROR("DrawDashedSide called with style other than DASHED or DOTTED; someone's not playing nice");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SF("dash: %f %f\n", dash[0], dash[1]);
|
|
|
|
|
|
|
|
mContext->SetDash(dash, 2, 0.0);
|
|
|
|
|
2010-04-27 09:15:02 -07:00
|
|
|
gfxPoint start = mOuterRect.CCWCorner(aSide);
|
|
|
|
gfxPoint end = mOuterRect.CWCorner(aSide);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
if (aSide == NS_SIDE_TOP) {
|
|
|
|
start.x += mBorderCornerDimensions[C_TL].width;
|
|
|
|
end.x -= mBorderCornerDimensions[C_TR].width;
|
|
|
|
|
|
|
|
start.y += borderWidth / 2.0;
|
|
|
|
end.y += borderWidth / 2.0;
|
|
|
|
} else if (aSide == NS_SIDE_RIGHT) {
|
|
|
|
start.x -= borderWidth / 2.0;
|
|
|
|
end.x -= borderWidth / 2.0;
|
|
|
|
|
|
|
|
start.y += mBorderCornerDimensions[C_TR].height;
|
|
|
|
end.y -= mBorderCornerDimensions[C_BR].height;
|
|
|
|
} else if (aSide == NS_SIDE_BOTTOM) {
|
|
|
|
start.x -= mBorderCornerDimensions[C_BR].width;
|
|
|
|
end.x += mBorderCornerDimensions[C_BL].width;
|
|
|
|
|
|
|
|
start.y -= borderWidth / 2.0;
|
|
|
|
end.y -= borderWidth / 2.0;
|
|
|
|
} else if (aSide == NS_SIDE_LEFT) {
|
|
|
|
start.x += borderWidth / 2.0;
|
|
|
|
end.x += borderWidth / 2.0;
|
|
|
|
|
|
|
|
start.y -= mBorderCornerDimensions[C_BL].height;
|
|
|
|
end.y += mBorderCornerDimensions[C_TL].height;
|
|
|
|
}
|
|
|
|
|
|
|
|
mContext->NewPath();
|
|
|
|
mContext->MoveTo(start);
|
|
|
|
mContext->LineTo(end);
|
|
|
|
mContext->SetLineWidth(borderWidth);
|
|
|
|
mContext->SetColor(gfxRGBA(borderColor));
|
|
|
|
//mContext->SetColor(gfxRGBA(1.0, 0.0, 0.0, 1.0));
|
|
|
|
mContext->Stroke();
|
|
|
|
}
|
|
|
|
|
2010-12-02 05:17:58 -08:00
|
|
|
void
|
|
|
|
nsCSSBorderRenderer::SetupStrokeStyle(mozilla::css::Side aSide)
|
|
|
|
{
|
|
|
|
mContext->SetColor(gfxRGBA(mBorderColors[aSide]));
|
|
|
|
mContext->SetLineWidth(mBorderWidths[aSide]);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsCSSBorderRenderer::AllBordersSameWidth()
|
|
|
|
{
|
|
|
|
if (mBorderWidths[0] == mBorderWidths[1] &&
|
|
|
|
mBorderWidths[0] == mBorderWidths[2] &&
|
|
|
|
mBorderWidths[0] == mBorderWidths[3])
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsCSSBorderRenderer::AllBordersSolid(bool *aHasCompositeColors)
|
|
|
|
{
|
|
|
|
*aHasCompositeColors = false;
|
|
|
|
NS_FOR_CSS_SIDES(i) {
|
2012-07-30 07:20:58 -07:00
|
|
|
if (mCompositeColors[i] != nullptr) {
|
2010-12-02 05:17:58 -08:00
|
|
|
*aHasCompositeColors = true;
|
|
|
|
}
|
|
|
|
if (mBorderStyles[i] == NS_STYLE_BORDER_STYLE_SOLID ||
|
|
|
|
mBorderStyles[i] == NS_STYLE_BORDER_STYLE_NONE ||
|
|
|
|
mBorderStyles[i] == NS_STYLE_BORDER_STYLE_HIDDEN)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsVisible(int aStyle)
|
|
|
|
{
|
|
|
|
if (aStyle != NS_STYLE_BORDER_STYLE_NONE &&
|
|
|
|
aStyle != NS_STYLE_BORDER_STYLE_HIDDEN) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxPattern>
|
|
|
|
nsCSSBorderRenderer::CreateCornerGradient(mozilla::css::Corner aCorner,
|
|
|
|
const gfxRGBA &aFirstColor,
|
|
|
|
const gfxRGBA &aSecondColor)
|
|
|
|
{
|
|
|
|
typedef struct { gfxFloat a, b; } twoFloats;
|
|
|
|
|
|
|
|
const twoFloats gradientCoeff[4] = { { -1, +1 },
|
|
|
|
{ -1, -1 },
|
|
|
|
{ +1, -1 },
|
|
|
|
{ +1, +1 } };
|
2012-10-26 21:32:52 -07:00
|
|
|
|
2010-12-02 05:17:58 -08:00
|
|
|
// Sides which form the 'width' and 'height' for the calculation of the angle
|
|
|
|
// for our gradient.
|
|
|
|
const int cornerWidth[4] = { 3, 1, 1, 3 };
|
|
|
|
const int cornerHeight[4] = { 0, 0, 2, 2 };
|
|
|
|
|
|
|
|
gfxPoint cornerOrigin = mOuterRect.AtCorner(aCorner);
|
|
|
|
|
|
|
|
gfxPoint pat1, pat2;
|
|
|
|
pat1.x = cornerOrigin.x +
|
|
|
|
mBorderWidths[cornerHeight[aCorner]] * gradientCoeff[aCorner].a;
|
|
|
|
pat1.y = cornerOrigin.y +
|
|
|
|
mBorderWidths[cornerWidth[aCorner]] * gradientCoeff[aCorner].b;
|
|
|
|
pat2.x = cornerOrigin.x -
|
|
|
|
mBorderWidths[cornerHeight[aCorner]] * gradientCoeff[aCorner].a;
|
|
|
|
pat2.y = cornerOrigin.y -
|
|
|
|
mBorderWidths[cornerWidth[aCorner]] * gradientCoeff[aCorner].b;
|
|
|
|
|
|
|
|
float gradientOffset;
|
|
|
|
|
2012-01-04 23:17:52 -08:00
|
|
|
if (mContext->IsCairo() &&
|
|
|
|
(mContext->OriginalSurface()->GetType() == gfxASurface::SurfaceTypeD2D ||
|
|
|
|
mContext->OriginalSurface()->GetType() == gfxASurface::SurfaceTypeQuartz))
|
2010-12-02 05:17:58 -08:00
|
|
|
{
|
|
|
|
// On quarz this doesn't do exactly the right thing, but it does do what
|
|
|
|
// most other browsers do and doing the 'right' thing seems to be
|
|
|
|
// hard with the quartz cairo backend.
|
|
|
|
gradientOffset = 0;
|
|
|
|
} else {
|
2012-01-04 23:17:52 -08:00
|
|
|
// When cairo/Azure does the gradient drawing this gives us pretty nice behavior!
|
2010-12-02 05:17:58 -08:00
|
|
|
gradientOffset = 0.25 / sqrt(pow(mBorderWidths[cornerHeight[aCorner]], 2) +
|
|
|
|
pow(mBorderWidths[cornerHeight[aCorner]], 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxPattern> pattern = new gfxPattern(pat1.x, pat1.y, pat2.x, pat2.y);
|
|
|
|
pattern->AddColorStop(0.5 - gradientOffset, gfxRGBA(aFirstColor));
|
|
|
|
pattern->AddColorStop(0.5 + gradientOffset, gfxRGBA(aSecondColor));
|
|
|
|
|
|
|
|
return pattern.forget();
|
|
|
|
}
|
|
|
|
|
2012-10-26 21:32:52 -07:00
|
|
|
TemporaryRef<GradientStops>
|
|
|
|
nsCSSBorderRenderer::CreateCornerGradient(mozilla::css::Corner aCorner,
|
|
|
|
const gfxRGBA &aFirstColor,
|
|
|
|
const gfxRGBA &aSecondColor,
|
|
|
|
DrawTarget *aDT,
|
|
|
|
Point &aPoint1,
|
|
|
|
Point &aPoint2)
|
|
|
|
{
|
|
|
|
typedef struct { gfxFloat a, b; } twoFloats;
|
|
|
|
|
|
|
|
const twoFloats gradientCoeff[4] = { { -1, +1 },
|
|
|
|
{ -1, -1 },
|
|
|
|
{ +1, -1 },
|
|
|
|
{ +1, +1 } };
|
|
|
|
|
|
|
|
// Sides which form the 'width' and 'height' for the calculation of the angle
|
|
|
|
// for our gradient.
|
|
|
|
const int cornerWidth[4] = { 3, 1, 1, 3 };
|
|
|
|
const int cornerHeight[4] = { 0, 0, 2, 2 };
|
|
|
|
|
|
|
|
gfxPoint cornerOrigin = mOuterRect.AtCorner(aCorner);
|
|
|
|
|
|
|
|
gfxPoint pat1, pat2;
|
|
|
|
pat1.x = cornerOrigin.x +
|
|
|
|
mBorderWidths[cornerHeight[aCorner]] * gradientCoeff[aCorner].a;
|
|
|
|
pat1.y = cornerOrigin.y +
|
|
|
|
mBorderWidths[cornerWidth[aCorner]] * gradientCoeff[aCorner].b;
|
|
|
|
pat2.x = cornerOrigin.x -
|
|
|
|
mBorderWidths[cornerHeight[aCorner]] * gradientCoeff[aCorner].a;
|
|
|
|
pat2.y = cornerOrigin.y -
|
|
|
|
mBorderWidths[cornerWidth[aCorner]] * gradientCoeff[aCorner].b;
|
|
|
|
|
|
|
|
aPoint1 = Point(pat1.x, pat1.y);
|
|
|
|
aPoint2 = Point(pat2.x, pat2.y);
|
|
|
|
|
|
|
|
Color firstColor = ToColor(aFirstColor);
|
|
|
|
Color secondColor = ToColor(aSecondColor);
|
|
|
|
|
|
|
|
BorderGradientCacheData *data =
|
|
|
|
gBorderGradientCache->Lookup(firstColor, secondColor, aDT->GetType());
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
// Having two corners, both with reversed color stops is pretty common
|
|
|
|
// for certain border types. Let's optimize it!
|
|
|
|
data = gBorderGradientCache->Lookup(secondColor, firstColor, aDT->GetType());
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
Point tmp = aPoint1;
|
|
|
|
aPoint1 = aPoint2;
|
|
|
|
aPoint2 = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<GradientStops> stops;
|
|
|
|
if (data) {
|
|
|
|
stops = data->mStops;
|
|
|
|
} else {
|
|
|
|
GradientStop rawStops[2];
|
|
|
|
// This is only guaranteed to give correct (and in some cases more correct)
|
|
|
|
// rendering with the Direct2D Azure and Quartz Cairo backends. For other
|
|
|
|
// cairo backends it could create un-antialiased border corner transitions
|
|
|
|
// since that at least used to be pixman's behaviour for hard stops.
|
|
|
|
rawStops[0].color = firstColor;
|
|
|
|
rawStops[0].offset = 0.5;
|
|
|
|
rawStops[1].color = secondColor;
|
|
|
|
rawStops[1].offset = 0.5;
|
|
|
|
stops = aDT->CreateGradientStops(rawStops, 2);
|
|
|
|
|
|
|
|
data = new BorderGradientCacheData(stops, BorderGradientCacheKey(firstColor, secondColor, aDT->GetType()));
|
|
|
|
|
|
|
|
if (!gBorderGradientCache->RegisterEntry(data)) {
|
|
|
|
delete data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stops;
|
|
|
|
}
|
|
|
|
|
2010-12-02 05:17:58 -08:00
|
|
|
typedef struct { gfxFloat a, b; } twoFloats;
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSBorderRenderer::DrawSingleWidthSolidBorder()
|
|
|
|
{
|
|
|
|
// Easy enough to deal with.
|
|
|
|
mContext->SetLineWidth(1);
|
|
|
|
gfxRect rect = mOuterRect;
|
2011-04-18 20:07:51 -07:00
|
|
|
rect.Deflate(0.5);
|
2010-12-02 05:17:58 -08:00
|
|
|
|
|
|
|
const twoFloats cornerAdjusts[4] = { { +0.5, 0 },
|
|
|
|
{ 0, +0.5 },
|
|
|
|
{ -0.5, 0 },
|
|
|
|
{ 0, -0.5 } };
|
|
|
|
|
|
|
|
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
|
|
|
gfxPoint firstCorner = rect.CCWCorner(side);
|
|
|
|
firstCorner.x += cornerAdjusts[side].a;
|
|
|
|
firstCorner.y += cornerAdjusts[side].b;
|
|
|
|
gfxPoint secondCorner = rect.CWCorner(side);
|
|
|
|
secondCorner.x += cornerAdjusts[side].a;
|
|
|
|
secondCorner.y += cornerAdjusts[side].b;
|
|
|
|
|
|
|
|
mContext->SetColor(gfxRGBA(mBorderColors[side]));
|
|
|
|
mContext->NewPath();
|
|
|
|
mContext->MoveTo(firstCorner);
|
|
|
|
mContext->LineTo(secondCorner);
|
|
|
|
mContext->Stroke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSBorderRenderer::DrawNoCompositeColorSolidBorder()
|
|
|
|
{
|
|
|
|
const gfxFloat alpha = 0.55191497064665766025;
|
|
|
|
|
|
|
|
const twoFloats cornerMults[4] = { { -1, 0 },
|
|
|
|
{ 0, -1 },
|
|
|
|
{ +1, 0 },
|
|
|
|
{ 0, +1 } };
|
|
|
|
|
|
|
|
const twoFloats centerAdjusts[4] = { { 0, +0.5 },
|
|
|
|
{ -0.5, 0 },
|
|
|
|
{ 0, -0.5 },
|
|
|
|
{ +0.5, 0 } };
|
|
|
|
|
|
|
|
gfxPoint pc, pci, p0, p1, p2, p3, pd, p3i;
|
|
|
|
|
|
|
|
gfxCornerSizes innerRadii;
|
|
|
|
ComputeInnerRadii(mBorderRadii, mBorderWidths, &innerRadii);
|
|
|
|
|
|
|
|
gfxRect strokeRect = mOuterRect;
|
2011-04-18 20:07:51 -07:00
|
|
|
strokeRect.Deflate(gfxMargin(mBorderWidths[3] / 2.0, mBorderWidths[0] / 2.0,
|
|
|
|
mBorderWidths[1] / 2.0, mBorderWidths[2] / 2.0));
|
2010-12-02 05:17:58 -08:00
|
|
|
|
|
|
|
NS_FOR_CSS_CORNERS(i) {
|
|
|
|
// the corner index -- either 1 2 3 0 (cw) or 0 3 2 1 (ccw)
|
|
|
|
mozilla::css::Corner c = mozilla::css::Corner((i+1) % 4);
|
|
|
|
mozilla::css::Corner prevCorner = mozilla::css::Corner(i);
|
|
|
|
|
|
|
|
// i+2 and i+3 respectively. These are used to index into the corner
|
|
|
|
// multiplier table, and were deduced by calculating out the long form
|
|
|
|
// of each corner and finding a pattern in the signs and values.
|
|
|
|
int i1 = (i+1) % 4;
|
|
|
|
int i2 = (i+2) % 4;
|
|
|
|
int i3 = (i+3) % 4;
|
|
|
|
|
|
|
|
pc = mOuterRect.AtCorner(c);
|
|
|
|
pci = mInnerRect.AtCorner(c);
|
|
|
|
mContext->SetLineWidth(mBorderWidths[i]);
|
|
|
|
|
|
|
|
nscolor firstColor, secondColor;
|
|
|
|
if (IsVisible(mBorderStyles[i]) && IsVisible(mBorderStyles[i1])) {
|
|
|
|
firstColor = mBorderColors[i];
|
|
|
|
secondColor = mBorderColors[i1];
|
|
|
|
} else if (IsVisible(mBorderStyles[i])) {
|
|
|
|
firstColor = mBorderColors[i];
|
|
|
|
secondColor = mBorderColors[i];
|
|
|
|
} else {
|
|
|
|
firstColor = mBorderColors[i1];
|
|
|
|
secondColor = mBorderColors[i1];
|
|
|
|
}
|
|
|
|
|
|
|
|
mContext->NewPath();
|
|
|
|
|
|
|
|
gfxPoint strokeStart, strokeEnd;
|
|
|
|
|
|
|
|
strokeStart.x = mOuterRect.AtCorner(prevCorner).x +
|
|
|
|
mBorderCornerDimensions[prevCorner].width * cornerMults[i2].a;
|
|
|
|
strokeStart.y = mOuterRect.AtCorner(prevCorner).y +
|
|
|
|
mBorderCornerDimensions[prevCorner].height * cornerMults[i2].b;
|
|
|
|
|
|
|
|
strokeEnd.x = pc.x + mBorderCornerDimensions[c].width * cornerMults[i].a;
|
|
|
|
strokeEnd.y = pc.y + mBorderCornerDimensions[c].height * cornerMults[i].b;
|
|
|
|
|
|
|
|
strokeStart.x += centerAdjusts[i].a * mBorderWidths[i];
|
|
|
|
strokeStart.y += centerAdjusts[i].b * mBorderWidths[i];
|
|
|
|
strokeEnd.x += centerAdjusts[i].a * mBorderWidths[i];
|
|
|
|
strokeEnd.y += centerAdjusts[i].b * mBorderWidths[i];
|
|
|
|
|
|
|
|
mContext->MoveTo(strokeStart);
|
|
|
|
mContext->LineTo(strokeEnd);
|
|
|
|
mContext->SetColor(gfxRGBA(mBorderColors[i]));
|
|
|
|
mContext->Stroke();
|
|
|
|
|
|
|
|
if (firstColor != secondColor) {
|
|
|
|
nsRefPtr<gfxPattern> pattern =
|
|
|
|
CreateCornerGradient(c, firstColor, secondColor);
|
|
|
|
mContext->SetPattern(pattern);
|
|
|
|
} else {
|
|
|
|
mContext->SetColor(firstColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mBorderRadii[c].width > 0 && mBorderRadii[c].height > 0) {
|
|
|
|
p0.x = pc.x + cornerMults[i].a * mBorderRadii[c].width;
|
|
|
|
p0.y = pc.y + cornerMults[i].b * mBorderRadii[c].height;
|
|
|
|
|
|
|
|
p3.x = pc.x + cornerMults[i3].a * mBorderRadii[c].width;
|
|
|
|
p3.y = pc.y + cornerMults[i3].b * mBorderRadii[c].height;
|
|
|
|
|
|
|
|
p1.x = p0.x + alpha * cornerMults[i2].a * mBorderRadii[c].width;
|
|
|
|
p1.y = p0.y + alpha * cornerMults[i2].b * mBorderRadii[c].height;
|
|
|
|
|
|
|
|
p2.x = p3.x - alpha * cornerMults[i3].a * mBorderRadii[c].width;
|
|
|
|
p2.y = p3.y - alpha * cornerMults[i3].b * mBorderRadii[c].height;
|
|
|
|
|
|
|
|
mContext->NewPath();
|
|
|
|
|
|
|
|
gfxPoint cornerStart;
|
|
|
|
cornerStart.x = pc.x + cornerMults[i].a * mBorderCornerDimensions[c].width;
|
|
|
|
cornerStart.y = pc.y + cornerMults[i].b * mBorderCornerDimensions[c].height;
|
|
|
|
|
|
|
|
mContext->MoveTo(cornerStart);
|
|
|
|
mContext->LineTo(p0);
|
|
|
|
|
|
|
|
mContext->CurveTo(p1, p2, p3);
|
|
|
|
|
|
|
|
gfxPoint outerCornerEnd;
|
|
|
|
outerCornerEnd.x = pc.x + cornerMults[i3].a * mBorderCornerDimensions[c].width;
|
|
|
|
outerCornerEnd.y = pc.y + cornerMults[i3].b * mBorderCornerDimensions[c].height;
|
|
|
|
|
|
|
|
mContext->LineTo(outerCornerEnd);
|
|
|
|
|
|
|
|
p0.x = pci.x + cornerMults[i].a * innerRadii[c].width;
|
|
|
|
p0.y = pci.y + cornerMults[i].b * innerRadii[c].height;
|
|
|
|
|
|
|
|
p3i.x = pci.x + cornerMults[i3].a * innerRadii[c].width;
|
|
|
|
p3i.y = pci.y + cornerMults[i3].b * innerRadii[c].height;
|
|
|
|
|
|
|
|
p1.x = p0.x + alpha * cornerMults[i2].a * innerRadii[c].width;
|
|
|
|
p1.y = p0.y + alpha * cornerMults[i2].b * innerRadii[c].height;
|
|
|
|
|
|
|
|
p2.x = p3i.x - alpha * cornerMults[i3].a * innerRadii[c].width;
|
|
|
|
p2.y = p3i.y - alpha * cornerMults[i3].b * innerRadii[c].height;
|
|
|
|
mContext->LineTo(p3i);
|
|
|
|
mContext->CurveTo(p2, p1, p0);
|
|
|
|
mContext->ClosePath();
|
|
|
|
mContext->Fill();
|
|
|
|
} else {
|
|
|
|
gfxPoint c1, c2, c3, c4;
|
|
|
|
|
|
|
|
c1.x = pc.x + cornerMults[i].a * mBorderCornerDimensions[c].width;
|
|
|
|
c1.y = pc.y + cornerMults[i].b * mBorderCornerDimensions[c].height;
|
|
|
|
c2 = pc;
|
|
|
|
c3.x = pc.x + cornerMults[i3].a * mBorderCornerDimensions[c].width;
|
|
|
|
c3.y = pc.y + cornerMults[i3].b * mBorderCornerDimensions[c].height;
|
|
|
|
|
|
|
|
mContext->NewPath();
|
|
|
|
mContext->MoveTo(c1);
|
|
|
|
mContext->LineTo(c2);
|
|
|
|
mContext->LineTo(c3);
|
|
|
|
mContext->LineTo(pci);
|
|
|
|
mContext->ClosePath();
|
|
|
|
|
|
|
|
mContext->Fill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-26 21:32:52 -07:00
|
|
|
void
|
|
|
|
nsCSSBorderRenderer::DrawNoCompositeColorSolidBorderAzure()
|
|
|
|
{
|
|
|
|
DrawTarget *dt = mContext->GetDrawTarget();
|
|
|
|
|
|
|
|
const gfxFloat alpha = 0.55191497064665766025;
|
|
|
|
|
|
|
|
const twoFloats cornerMults[4] = { { -1, 0 },
|
|
|
|
{ 0, -1 },
|
|
|
|
{ +1, 0 },
|
|
|
|
{ 0, +1 } };
|
|
|
|
|
|
|
|
const twoFloats centerAdjusts[4] = { { 0, +0.5 },
|
|
|
|
{ -0.5, 0 },
|
|
|
|
{ 0, -0.5 },
|
|
|
|
{ +0.5, 0 } };
|
|
|
|
|
|
|
|
Point pc, pci, p0, p1, p2, p3, pd, p3i;
|
|
|
|
|
|
|
|
gfxCornerSizes innerRadii;
|
|
|
|
ComputeInnerRadii(mBorderRadii, mBorderWidths, &innerRadii);
|
|
|
|
|
|
|
|
gfxRect strokeRect = mOuterRect;
|
|
|
|
strokeRect.Deflate(gfxMargin(mBorderWidths[3] / 2.0, mBorderWidths[0] / 2.0,
|
|
|
|
mBorderWidths[1] / 2.0, mBorderWidths[2] / 2.0));
|
|
|
|
|
|
|
|
ColorPattern colorPat(Color(0, 0, 0, 0));
|
|
|
|
LinearGradientPattern gradPat(Point(), Point(), NULL);
|
|
|
|
|
|
|
|
NS_FOR_CSS_CORNERS(i) {
|
|
|
|
// the corner index -- either 1 2 3 0 (cw) or 0 3 2 1 (ccw)
|
|
|
|
mozilla::css::Corner c = mozilla::css::Corner((i+1) % 4);
|
|
|
|
mozilla::css::Corner prevCorner = mozilla::css::Corner(i);
|
|
|
|
|
|
|
|
// i+2 and i+3 respectively. These are used to index into the corner
|
|
|
|
// multiplier table, and were deduced by calculating out the long form
|
|
|
|
// of each corner and finding a pattern in the signs and values.
|
|
|
|
int i1 = (i+1) % 4;
|
|
|
|
int i2 = (i+2) % 4;
|
|
|
|
int i3 = (i+3) % 4;
|
|
|
|
|
|
|
|
pc = ToPoint(mOuterRect.AtCorner(c));
|
|
|
|
pci = ToPoint(mInnerRect.AtCorner(c));
|
|
|
|
|
|
|
|
nscolor firstColor, secondColor;
|
|
|
|
if (IsVisible(mBorderStyles[i]) && IsVisible(mBorderStyles[i1])) {
|
|
|
|
firstColor = mBorderColors[i];
|
|
|
|
secondColor = mBorderColors[i1];
|
|
|
|
} else if (IsVisible(mBorderStyles[i])) {
|
|
|
|
firstColor = mBorderColors[i];
|
|
|
|
secondColor = mBorderColors[i];
|
|
|
|
} else {
|
|
|
|
firstColor = mBorderColors[i1];
|
|
|
|
secondColor = mBorderColors[i1];
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<PathBuilder> builder = dt->CreatePathBuilder();
|
|
|
|
|
|
|
|
Point strokeStart, strokeEnd;
|
|
|
|
|
|
|
|
strokeStart.x = mOuterRect.AtCorner(prevCorner).x +
|
|
|
|
mBorderCornerDimensions[prevCorner].width * cornerMults[i2].a;
|
|
|
|
strokeStart.y = mOuterRect.AtCorner(prevCorner).y +
|
|
|
|
mBorderCornerDimensions[prevCorner].height * cornerMults[i2].b;
|
|
|
|
|
|
|
|
strokeEnd.x = pc.x + mBorderCornerDimensions[c].width * cornerMults[i].a;
|
|
|
|
strokeEnd.y = pc.y + mBorderCornerDimensions[c].height * cornerMults[i].b;
|
|
|
|
|
|
|
|
strokeStart.x += centerAdjusts[i].a * mBorderWidths[i];
|
|
|
|
strokeStart.y += centerAdjusts[i].b * mBorderWidths[i];
|
|
|
|
strokeEnd.x += centerAdjusts[i].a * mBorderWidths[i];
|
|
|
|
strokeEnd.y += centerAdjusts[i].b * mBorderWidths[i];
|
|
|
|
|
|
|
|
builder->MoveTo(strokeStart);
|
|
|
|
builder->LineTo(strokeEnd);
|
|
|
|
RefPtr<Path> path = builder->Finish();
|
|
|
|
dt->Stroke(path, ColorPattern(Color::FromABGR(mBorderColors[i])), StrokeOptions(mBorderWidths[i]));
|
|
|
|
|
|
|
|
Pattern *pattern;
|
|
|
|
|
|
|
|
if (firstColor != secondColor) {
|
|
|
|
gradPat.mStops = CreateCornerGradient(c, firstColor, secondColor, dt, gradPat.mBegin, gradPat.mEnd);
|
|
|
|
pattern = &gradPat;
|
|
|
|
} else {
|
|
|
|
colorPat.mColor = Color::FromABGR(firstColor);
|
|
|
|
pattern = &colorPat;
|
|
|
|
}
|
|
|
|
|
|
|
|
builder = dt->CreatePathBuilder();
|
|
|
|
|
|
|
|
if (mBorderRadii[c].width > 0 && mBorderRadii[c].height > 0) {
|
|
|
|
p0.x = pc.x + cornerMults[i].a * mBorderRadii[c].width;
|
|
|
|
p0.y = pc.y + cornerMults[i].b * mBorderRadii[c].height;
|
|
|
|
|
|
|
|
p3.x = pc.x + cornerMults[i3].a * mBorderRadii[c].width;
|
|
|
|
p3.y = pc.y + cornerMults[i3].b * mBorderRadii[c].height;
|
|
|
|
|
|
|
|
p1.x = p0.x + alpha * cornerMults[i2].a * mBorderRadii[c].width;
|
|
|
|
p1.y = p0.y + alpha * cornerMults[i2].b * mBorderRadii[c].height;
|
|
|
|
|
|
|
|
p2.x = p3.x - alpha * cornerMults[i3].a * mBorderRadii[c].width;
|
|
|
|
p2.y = p3.y - alpha * cornerMults[i3].b * mBorderRadii[c].height;
|
|
|
|
|
|
|
|
Point cornerStart;
|
|
|
|
cornerStart.x = pc.x + cornerMults[i].a * mBorderCornerDimensions[c].width;
|
|
|
|
cornerStart.y = pc.y + cornerMults[i].b * mBorderCornerDimensions[c].height;
|
|
|
|
|
|
|
|
builder->MoveTo(cornerStart);
|
|
|
|
builder->LineTo(p0);
|
|
|
|
|
|
|
|
builder->BezierTo(p1, p2, p3);
|
|
|
|
|
|
|
|
Point outerCornerEnd;
|
|
|
|
outerCornerEnd.x = pc.x + cornerMults[i3].a * mBorderCornerDimensions[c].width;
|
|
|
|
outerCornerEnd.y = pc.y + cornerMults[i3].b * mBorderCornerDimensions[c].height;
|
|
|
|
|
|
|
|
builder->LineTo(outerCornerEnd);
|
|
|
|
|
|
|
|
p0.x = pci.x + cornerMults[i].a * innerRadii[c].width;
|
|
|
|
p0.y = pci.y + cornerMults[i].b * innerRadii[c].height;
|
|
|
|
|
|
|
|
p3i.x = pci.x + cornerMults[i3].a * innerRadii[c].width;
|
|
|
|
p3i.y = pci.y + cornerMults[i3].b * innerRadii[c].height;
|
|
|
|
|
|
|
|
p1.x = p0.x + alpha * cornerMults[i2].a * innerRadii[c].width;
|
|
|
|
p1.y = p0.y + alpha * cornerMults[i2].b * innerRadii[c].height;
|
|
|
|
|
|
|
|
p2.x = p3i.x - alpha * cornerMults[i3].a * innerRadii[c].width;
|
|
|
|
p2.y = p3i.y - alpha * cornerMults[i3].b * innerRadii[c].height;
|
|
|
|
builder->LineTo(p3i);
|
|
|
|
builder->BezierTo(p2, p1, p0);
|
|
|
|
builder->Close();
|
|
|
|
path = builder->Finish();
|
|
|
|
dt->Fill(path, *pattern);
|
|
|
|
} else {
|
|
|
|
Point c1, c2, c3, c4;
|
|
|
|
|
|
|
|
c1.x = pc.x + cornerMults[i].a * mBorderCornerDimensions[c].width;
|
|
|
|
c1.y = pc.y + cornerMults[i].b * mBorderCornerDimensions[c].height;
|
|
|
|
c2 = pc;
|
|
|
|
c3.x = pc.x + cornerMults[i3].a * mBorderCornerDimensions[c].width;
|
|
|
|
c3.y = pc.y + cornerMults[i3].b * mBorderCornerDimensions[c].height;
|
|
|
|
|
|
|
|
builder->MoveTo(c1);
|
|
|
|
builder->LineTo(c2);
|
|
|
|
builder->LineTo(c3);
|
|
|
|
builder->LineTo(pci);
|
|
|
|
builder->Close();
|
|
|
|
|
|
|
|
path = builder->Finish();
|
|
|
|
|
|
|
|
dt->Fill(path, *pattern);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-02 05:17:58 -08:00
|
|
|
void
|
|
|
|
nsCSSBorderRenderer::DrawRectangularCompositeColors()
|
|
|
|
{
|
|
|
|
nsBorderColors *currentColors[4];
|
|
|
|
mContext->SetLineWidth(1);
|
|
|
|
memcpy(currentColors, mCompositeColors, sizeof(nsBorderColors*) * 4);
|
|
|
|
gfxRect rect = mOuterRect;
|
2011-04-18 20:07:51 -07:00
|
|
|
rect.Deflate(0.5);
|
2010-12-02 05:17:58 -08:00
|
|
|
|
|
|
|
const twoFloats cornerAdjusts[4] = { { +0.5, 0 },
|
|
|
|
{ 0, +0.5 },
|
|
|
|
{ -0.5, 0 },
|
|
|
|
{ 0, -0.5 } };
|
|
|
|
|
|
|
|
for (int i = 0; i < mBorderWidths[0]; i++) {
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
|
|
|
int sideNext = (side + 1) % 4;
|
|
|
|
|
|
|
|
gfxPoint firstCorner = rect.CCWCorner(side);
|
|
|
|
firstCorner.x += cornerAdjusts[side].a;
|
|
|
|
firstCorner.y += cornerAdjusts[side].b;
|
|
|
|
gfxPoint secondCorner = rect.CWCorner(side);
|
|
|
|
secondCorner.x -= cornerAdjusts[side].a;
|
|
|
|
secondCorner.y -= cornerAdjusts[side].b;
|
|
|
|
|
2010-12-03 20:21:20 -08:00
|
|
|
gfxRGBA currentColor =
|
|
|
|
currentColors[side] ? gfxRGBA(currentColors[side]->mColor)
|
|
|
|
: gfxRGBA(mBorderColors[side]);
|
2010-12-02 05:17:58 -08:00
|
|
|
|
|
|
|
mContext->SetColor(currentColor);
|
|
|
|
mContext->NewPath();
|
|
|
|
mContext->MoveTo(firstCorner);
|
|
|
|
mContext->LineTo(secondCorner);
|
|
|
|
mContext->Stroke();
|
|
|
|
|
|
|
|
mContext->NewPath();
|
|
|
|
gfxPoint cornerTopLeft = rect.CWCorner(side);
|
|
|
|
cornerTopLeft.x -= 0.5;
|
|
|
|
cornerTopLeft.y -= 0.5;
|
|
|
|
mContext->Rectangle(gfxRect(cornerTopLeft, gfxSize(1, 1)));
|
2010-12-03 20:21:20 -08:00
|
|
|
gfxRGBA nextColor =
|
|
|
|
currentColors[sideNext] ? gfxRGBA(currentColors[sideNext]->mColor)
|
|
|
|
: gfxRGBA(mBorderColors[sideNext]);
|
|
|
|
|
2010-12-02 05:17:58 -08:00
|
|
|
gfxRGBA cornerColor((currentColor.r + nextColor.r) / 2.0,
|
|
|
|
(currentColor.g + nextColor.g) / 2.0,
|
|
|
|
(currentColor.b + nextColor.b) / 2.0,
|
|
|
|
(currentColor.a + nextColor.a) / 2.0);
|
|
|
|
mContext->SetColor(cornerColor);
|
|
|
|
mContext->Fill();
|
|
|
|
|
|
|
|
if (side != 0) {
|
|
|
|
// We'll have to keep side 0 for the color averaging on side 3.
|
2010-12-03 20:21:20 -08:00
|
|
|
if (currentColors[side] && currentColors[side]->mNext) {
|
2010-12-02 05:17:58 -08:00
|
|
|
currentColors[side] = currentColors[side]->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Now advance the color for side 0.
|
2010-12-03 20:21:20 -08:00
|
|
|
if (currentColors[0] && currentColors[0]->mNext) {
|
2010-12-02 05:17:58 -08:00
|
|
|
currentColors[0] = currentColors[0]->mNext;
|
|
|
|
}
|
2011-04-18 20:07:51 -07:00
|
|
|
rect.Deflate(1);
|
2010-12-02 05:17:58 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-23 10:25:23 -07:00
|
|
|
void
|
|
|
|
nsCSSBorderRenderer::DrawBorders()
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool forceSeparateCorners = false;
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
// Examine the border style to figure out if we can draw it in one
|
|
|
|
// go or not.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool tlBordersSame = AreBorderSideFinalStylesSame(SIDE_BIT_TOP | SIDE_BIT_LEFT);
|
|
|
|
bool brBordersSame = AreBorderSideFinalStylesSame(SIDE_BIT_BOTTOM | SIDE_BIT_RIGHT);
|
|
|
|
bool allBordersSame = AreBorderSideFinalStylesSame(SIDE_BITS_ALL);
|
2008-07-23 10:25:23 -07:00
|
|
|
if (allBordersSame &&
|
2010-11-08 13:52:02 -08:00
|
|
|
((mCompositeColors[0] == NULL &&
|
|
|
|
(mBorderStyles[0] == NS_STYLE_BORDER_STYLE_NONE ||
|
|
|
|
mBorderStyles[0] == NS_STYLE_BORDER_STYLE_HIDDEN ||
|
|
|
|
mBorderColors[0] == NS_RGBA(0,0,0,0))) ||
|
|
|
|
(mCompositeColors[0] &&
|
|
|
|
(mCompositeColors[0]->mColor == NS_RGBA(0,0,0,0) &&
|
|
|
|
!mCompositeColors[0]->mNext))))
|
2008-07-23 10:25:23 -07:00
|
|
|
{
|
|
|
|
// All borders are the same style, and the style is either none or hidden, or the color
|
|
|
|
// is transparent.
|
2010-11-08 13:52:02 -08:00
|
|
|
// This also checks if the first composite color is transparent, and there are
|
|
|
|
// no others. It doesn't check if there are subsequent transparent ones, because
|
|
|
|
// that would be very silly.
|
2008-07-23 10:25:23 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-02 05:17:58 -08:00
|
|
|
gfxMatrix mat = mContext->CurrentMatrix();
|
|
|
|
|
|
|
|
// Clamp the CTM to be pixel-aligned; we do this only
|
|
|
|
// for translation-only matrices now, but we could do it
|
|
|
|
// if the matrix has just a scale as well. We should not
|
|
|
|
// do it if there's a rotation.
|
2011-06-22 05:11:28 -07:00
|
|
|
if (mat.HasNonTranslation()) {
|
|
|
|
if (!mat.HasNonAxisAlignedTransform()) {
|
|
|
|
// Scale + transform. Avoid stroke fast-paths so that we have a chance
|
|
|
|
// of snapping to pixel boundaries.
|
2011-10-17 07:59:28 -07:00
|
|
|
mAvoidStroke = true;
|
2011-06-22 05:11:28 -07:00
|
|
|
}
|
|
|
|
} else {
|
2010-12-02 05:17:58 -08:00
|
|
|
mat.x0 = floor(mat.x0 + 0.5);
|
|
|
|
mat.y0 = floor(mat.y0 + 0.5);
|
|
|
|
mContext->SetMatrix(mat);
|
2011-06-22 05:11:28 -07:00
|
|
|
|
|
|
|
// round mOuterRect and mInnerRect; they're already an integer
|
|
|
|
// number of pixels apart and should stay that way after
|
|
|
|
// rounding. We don't do this if there's a scale in the current transform
|
|
|
|
// since this loses information that might be relevant when we're scaling.
|
|
|
|
mOuterRect.Round();
|
|
|
|
mInnerRect.Round();
|
2010-12-02 05:17:58 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool allBordersSameWidth = AllBordersSameWidth();
|
2010-12-02 05:17:58 -08:00
|
|
|
|
2010-12-09 20:38:52 -08:00
|
|
|
if (allBordersSameWidth && mBorderWidths[0] == 0.0) {
|
|
|
|
// Some of the allBordersSameWidth codepaths depend on the border
|
|
|
|
// width being greater than zero.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool allBordersSolid;
|
2010-12-02 05:17:58 -08:00
|
|
|
|
|
|
|
// First there's a couple of 'special cases' that have specifically optimized
|
|
|
|
// drawing paths, when none of these can be used we move on to the generalized
|
|
|
|
// border drawing code.
|
|
|
|
if (allBordersSame &&
|
|
|
|
mCompositeColors[0] == NULL &&
|
|
|
|
allBordersSameWidth &&
|
|
|
|
mBorderStyles[0] == NS_STYLE_BORDER_STYLE_SOLID &&
|
2011-06-22 05:11:28 -07:00
|
|
|
mNoBorderRadius &&
|
|
|
|
!mAvoidStroke)
|
2010-12-02 05:17:58 -08:00
|
|
|
{
|
|
|
|
// Very simple case.
|
|
|
|
SetupStrokeStyle(NS_SIDE_TOP);
|
|
|
|
gfxRect rect = mOuterRect;
|
2011-04-18 20:07:51 -07:00
|
|
|
rect.Deflate(mBorderWidths[0] / 2.0);
|
2010-12-02 05:17:58 -08:00
|
|
|
mContext->NewPath();
|
|
|
|
mContext->Rectangle(rect);
|
|
|
|
mContext->Stroke();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allBordersSame &&
|
|
|
|
mCompositeColors[0] == NULL &&
|
|
|
|
allBordersSameWidth &&
|
|
|
|
mBorderStyles[0] == NS_STYLE_BORDER_STYLE_DOTTED &&
|
|
|
|
mBorderWidths[0] < 3 &&
|
2011-06-22 05:11:28 -07:00
|
|
|
mNoBorderRadius &&
|
|
|
|
!mAvoidStroke)
|
2010-12-02 05:17:58 -08:00
|
|
|
{
|
|
|
|
// Very simple case. We draw this rectangular dotted borner without
|
|
|
|
// antialiasing. The dots should be pixel aligned.
|
|
|
|
SetupStrokeStyle(NS_SIDE_TOP);
|
|
|
|
|
|
|
|
gfxFloat dash = mBorderWidths[0];
|
|
|
|
mContext->SetDash(&dash, 1, 0.5);
|
|
|
|
mContext->SetAntialiasMode(gfxContext::MODE_ALIASED);
|
|
|
|
gfxRect rect = mOuterRect;
|
2011-04-18 20:07:51 -07:00
|
|
|
rect.Deflate(mBorderWidths[0] / 2.0);
|
2010-12-02 05:17:58 -08:00
|
|
|
mContext->NewPath();
|
|
|
|
mContext->Rectangle(rect);
|
|
|
|
mContext->Stroke();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (allBordersSame &&
|
|
|
|
mCompositeColors[0] == NULL &&
|
2011-06-22 05:11:28 -07:00
|
|
|
mBorderStyles[0] == NS_STYLE_BORDER_STYLE_SOLID &&
|
2012-11-12 17:55:26 -08:00
|
|
|
!mAvoidStroke &&
|
|
|
|
!mNoBorderRadius)
|
2010-12-02 05:17:58 -08:00
|
|
|
{
|
2012-11-12 17:55:26 -08:00
|
|
|
// Relatively simple case.
|
|
|
|
SetupStrokeStyle(NS_SIDE_TOP);
|
2010-12-02 05:17:58 -08:00
|
|
|
|
2012-11-12 17:55:26 -08:00
|
|
|
RoundedRect borderInnerRect(mOuterRect, mBorderRadii);
|
|
|
|
borderInnerRect.Deflate(mBorderWidths[NS_SIDE_TOP],
|
|
|
|
mBorderWidths[NS_SIDE_BOTTOM],
|
|
|
|
mBorderWidths[NS_SIDE_LEFT],
|
|
|
|
mBorderWidths[NS_SIDE_RIGHT]);
|
|
|
|
|
|
|
|
// Instead of stroking we just use two paths: an inner and an outer.
|
|
|
|
// This allows us to draw borders that we couldn't when stroking. For example,
|
|
|
|
// borders with a border width >= the border radius. (i.e. when there are
|
|
|
|
// square corners on the inside)
|
|
|
|
//
|
|
|
|
// Further, this approach can be more efficient because the backend
|
|
|
|
// doesn't need to compute an offset curve to stroke the path. We know that
|
|
|
|
// the rounded parts are elipses we can offset exactly and can just compute
|
|
|
|
// a new cubic approximation.
|
|
|
|
mContext->NewPath();
|
|
|
|
mContext->RoundedRectangle(mOuterRect, mBorderRadii, true);
|
|
|
|
mContext->RoundedRectangle(borderInnerRect.rect, borderInnerRect.corners, false);
|
|
|
|
mContext->Fill();
|
|
|
|
return;
|
2010-12-02 05:17:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hasCompositeColors;
|
|
|
|
|
|
|
|
allBordersSolid = AllBordersSolid(&hasCompositeColors);
|
|
|
|
// This leaves the border corners non-interpolated for single width borders.
|
|
|
|
// Doing this is slightly faster and shouldn't be a problem visually.
|
|
|
|
if (allBordersSolid &&
|
|
|
|
allBordersSameWidth &&
|
|
|
|
mCompositeColors[0] == NULL &&
|
|
|
|
mBorderWidths[0] == 1 &&
|
2011-06-22 05:11:28 -07:00
|
|
|
mNoBorderRadius &&
|
|
|
|
!mAvoidStroke)
|
2010-12-02 05:17:58 -08:00
|
|
|
{
|
|
|
|
DrawSingleWidthSolidBorder();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-22 05:11:28 -07:00
|
|
|
if (allBordersSolid && !hasCompositeColors &&
|
|
|
|
!mAvoidStroke)
|
2010-12-02 05:17:58 -08:00
|
|
|
{
|
2012-10-26 21:32:52 -07:00
|
|
|
if (mContext->IsCairo()) {
|
|
|
|
DrawNoCompositeColorSolidBorder();
|
|
|
|
} else {
|
|
|
|
DrawNoCompositeColorSolidBorderAzure();
|
|
|
|
}
|
2010-12-02 05:17:58 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allBordersSolid &&
|
|
|
|
allBordersSameWidth &&
|
2011-06-22 05:11:28 -07:00
|
|
|
mNoBorderRadius &&
|
|
|
|
!mAvoidStroke)
|
2010-12-02 05:17:58 -08:00
|
|
|
{
|
|
|
|
// Easy enough to deal with.
|
|
|
|
DrawRectangularCompositeColors();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have composite colors -and- border radius,
|
|
|
|
// then use separate corners so we get OPERATOR_ADD for the corners.
|
|
|
|
// Otherwise, we'll get artifacts as we draw stacked 1px-wide curves.
|
2012-07-30 07:20:58 -07:00
|
|
|
if (allBordersSame && mCompositeColors[0] != nullptr && !mNoBorderRadius)
|
2011-10-17 07:59:28 -07:00
|
|
|
forceSeparateCorners = true;
|
2010-12-02 05:17:58 -08:00
|
|
|
|
2008-07-23 10:25:23 -07:00
|
|
|
S(" mOuterRect: "), S(mOuterRect), SN();
|
|
|
|
S(" mInnerRect: "), S(mInnerRect), SN();
|
|
|
|
SF(" mBorderColors: 0x%08x 0x%08x 0x%08x 0x%08x\n", mBorderColors[0], mBorderColors[1], mBorderColors[2], mBorderColors[3]);
|
|
|
|
|
|
|
|
// if conditioning the outside rect failed, then bail -- the outside
|
|
|
|
// rect is supposed to enclose the entire border
|
|
|
|
mOuterRect.Condition();
|
|
|
|
if (mOuterRect.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
mInnerRect.Condition();
|
2012-08-09 00:09:40 -07:00
|
|
|
int dashedSides = 0;
|
2010-12-02 05:17:58 -08:00
|
|
|
|
2008-07-23 10:25:23 -07:00
|
|
|
NS_FOR_CSS_SIDES(i) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t style = mBorderStyles[i];
|
2008-07-23 10:25:23 -07:00
|
|
|
if (style == NS_STYLE_BORDER_STYLE_DASHED ||
|
|
|
|
style == NS_STYLE_BORDER_STYLE_DOTTED)
|
|
|
|
{
|
|
|
|
// pretend that all borders aren't the same; we need to draw
|
|
|
|
// things separately for dashed/dotting
|
2011-10-17 07:59:28 -07:00
|
|
|
allBordersSame = false;
|
2008-07-23 10:25:23 -07:00
|
|
|
dashedSides |= (1 << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SF(" allBordersSame: %d dashedSides: 0x%02x\n", allBordersSame, dashedSides);
|
|
|
|
|
|
|
|
if (allBordersSame && !forceSeparateCorners) {
|
|
|
|
/* Draw everything in one go */
|
|
|
|
DrawBorderSides(SIDE_BITS_ALL);
|
|
|
|
SN("---------------- (1)");
|
|
|
|
} else {
|
2012-04-16 11:37:59 -07:00
|
|
|
SAMPLE_LABEL("nsCSSBorderRenderer", "DrawBorders::multipass");
|
2008-07-23 10:25:23 -07:00
|
|
|
/* We have more than one pass to go. Draw the corners separately from the sides. */
|
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
/*
|
|
|
|
* If we have a 1px-wide border, the corners are going to be
|
|
|
|
* negligible, so don't bother doing anything fancy. Just extend
|
|
|
|
* the top and bottom borders to the right 1px and the left border
|
|
|
|
* to the bottom 1px. We do this by twiddling the corner dimensions,
|
|
|
|
* which causes the right to happen later on. Only do this if we have
|
|
|
|
* a 1.0 unit border all around and no border radius.
|
|
|
|
*/
|
|
|
|
|
2010-04-27 09:15:02 -07:00
|
|
|
NS_FOR_CSS_CORNERS(corner) {
|
|
|
|
const mozilla::css::Side sides[2] = { mozilla::css::Side(corner), PREV_SIDE(corner) };
|
2008-07-23 10:25:51 -07:00
|
|
|
|
|
|
|
if (!IsZeroSize(mBorderRadii[corner]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mBorderWidths[sides[0]] == 1.0 && mBorderWidths[sides[1]] == 1.0) {
|
2010-04-27 09:15:02 -07:00
|
|
|
if (corner == NS_CORNER_TOP_LEFT || corner == NS_CORNER_TOP_RIGHT)
|
2008-07-23 10:25:51 -07:00
|
|
|
mBorderCornerDimensions[corner].width = 0.0;
|
|
|
|
else
|
|
|
|
mBorderCornerDimensions[corner].height = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-23 10:25:23 -07:00
|
|
|
// First, the corners
|
2010-04-27 09:15:02 -07:00
|
|
|
NS_FOR_CSS_CORNERS(corner) {
|
2008-07-23 10:25:51 -07:00
|
|
|
// if there's no corner, don't do all this work for it
|
|
|
|
if (IsZeroSize(mBorderCornerDimensions[corner]))
|
|
|
|
continue;
|
|
|
|
|
2012-08-09 00:09:40 -07:00
|
|
|
const int sides[2] = { corner, PREV_SIDE(corner) };
|
|
|
|
int sideBits = (1 << sides[0]) | (1 << sides[1]);
|
2008-07-23 10:25:23 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool simpleCornerStyle = mCompositeColors[sides[0]] == NULL &&
|
2008-07-23 10:25:51 -07:00
|
|
|
mCompositeColors[sides[1]] == NULL &&
|
|
|
|
AreBorderSideFinalStylesSame(sideBits);
|
|
|
|
|
|
|
|
// If we don't have anything complex going on in this corner,
|
|
|
|
// then we can just fill the corner with a solid color, and avoid
|
|
|
|
// the potentially expensive clip.
|
|
|
|
if (simpleCornerStyle &&
|
|
|
|
IsZeroSize(mBorderRadii[corner]) &&
|
|
|
|
IsSolidCornerStyle(mBorderStyles[sides[0]], corner))
|
|
|
|
{
|
|
|
|
mContext->NewPath();
|
|
|
|
DoCornerSubPath(corner);
|
|
|
|
mContext->SetColor(MakeBorderColor(mBorderColors[sides[0]],
|
|
|
|
mBackgroundColor,
|
|
|
|
BorderColorStyleForSolidCorner(mBorderStyles[sides[0]], corner)));
|
|
|
|
mContext->Fill();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-07-23 10:25:23 -07:00
|
|
|
mContext->Save();
|
|
|
|
|
|
|
|
// clip to the corner
|
|
|
|
mContext->NewPath();
|
2008-07-23 10:25:51 -07:00
|
|
|
DoCornerSubPath(corner);
|
2008-07-23 10:25:23 -07:00
|
|
|
mContext->Clip();
|
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
if (simpleCornerStyle) {
|
|
|
|
// we don't need a group for this corner, the sides are the same,
|
|
|
|
// but we weren't able to render just a solid block for the corner.
|
2008-07-23 10:25:23 -07:00
|
|
|
DrawBorderSides(sideBits);
|
|
|
|
} else {
|
2012-06-22 07:27:38 -07:00
|
|
|
// Sides are different. We could draw using OPERATOR_ADD to
|
|
|
|
// get correct color blending behaviour at the seam. We'd need
|
2008-07-23 10:25:23 -07:00
|
|
|
// to do it in an offscreen surface to ensure that we're
|
|
|
|
// always compositing on transparent black. If the colors
|
|
|
|
// don't have transparency and the current destination surface
|
|
|
|
// has an alpha channel, we could just clear the region and
|
|
|
|
// avoid the temporary, but that situation doesn't happen all
|
|
|
|
// that often in practice (we double buffer to no-alpha
|
2012-06-22 07:27:38 -07:00
|
|
|
// surfaces). We choose just to seam though, as the performance
|
|
|
|
// advantages outway the modest easthetic improvement.
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
for (int cornerSide = 0; cornerSide < 2; cornerSide++) {
|
2010-04-27 09:15:02 -07:00
|
|
|
mozilla::css::Side side = mozilla::css::Side(sides[cornerSide]);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t style = mBorderStyles[side];
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
SF("corner: %d cornerSide: %d side: %d style: %d\n", corner, cornerSide, side, style);
|
|
|
|
|
|
|
|
mContext->Save();
|
|
|
|
|
|
|
|
mContext->NewPath();
|
|
|
|
DoSideClipSubPath(side);
|
|
|
|
mContext->Clip();
|
|
|
|
|
|
|
|
DrawBorderSides(1 << side);
|
|
|
|
|
|
|
|
mContext->Restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mContext->Restore();
|
|
|
|
|
|
|
|
SN();
|
|
|
|
}
|
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
// in the case of a single-unit border, we already munged the
|
|
|
|
// corners up above; so we can just draw the top left and bottom
|
|
|
|
// right sides separately, if they're the same.
|
2008-10-09 14:49:15 -07:00
|
|
|
//
|
|
|
|
// We need to check for mNoBorderRadius, because when there is
|
|
|
|
// one, FillSolidBorder always draws the full rounded rectangle
|
|
|
|
// and expects there to be a clip in place.
|
2012-08-09 00:09:40 -07:00
|
|
|
int alreadyDrawnSides = 0;
|
2008-10-09 14:49:15 -07:00
|
|
|
if (mOneUnitBorder &&
|
|
|
|
mNoBorderRadius &&
|
|
|
|
(dashedSides & (SIDE_BIT_TOP | SIDE_BIT_LEFT)) == 0)
|
|
|
|
{
|
2008-07-23 10:25:51 -07:00
|
|
|
if (tlBordersSame) {
|
|
|
|
DrawBorderSides(SIDE_BIT_TOP | SIDE_BIT_LEFT);
|
|
|
|
alreadyDrawnSides |= (SIDE_BIT_TOP | SIDE_BIT_LEFT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (brBordersSame && (dashedSides & (SIDE_BIT_BOTTOM | SIDE_BIT_RIGHT)) == 0) {
|
|
|
|
DrawBorderSides(SIDE_BIT_BOTTOM | SIDE_BIT_RIGHT);
|
|
|
|
alreadyDrawnSides |= (SIDE_BIT_BOTTOM | SIDE_BIT_RIGHT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-23 10:25:23 -07:00
|
|
|
// We're done with the corners, now draw the sides.
|
|
|
|
NS_FOR_CSS_SIDES (side) {
|
2008-07-23 10:25:51 -07:00
|
|
|
// if we drew it above, skip it
|
|
|
|
if (alreadyDrawnSides & (1 << side))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If there's no border on this side, skip it
|
|
|
|
if (mBorderWidths[side] == 0.0 ||
|
|
|
|
mBorderStyles[side] == NS_STYLE_BORDER_STYLE_HIDDEN ||
|
|
|
|
mBorderStyles[side] == NS_STYLE_BORDER_STYLE_NONE)
|
|
|
|
continue;
|
|
|
|
|
2008-07-23 10:25:23 -07:00
|
|
|
|
|
|
|
if (dashedSides & (1 << side)) {
|
2008-07-23 10:25:51 -07:00
|
|
|
// Dashed sides will always draw just the part ignoring the
|
|
|
|
// corners for the side, so no need to clip.
|
2008-07-23 10:25:23 -07:00
|
|
|
DrawDashedSide (side);
|
2008-07-23 10:25:51 -07:00
|
|
|
|
2008-07-23 10:25:23 -07:00
|
|
|
SN("---------------- (d)");
|
2008-07-23 10:25:51 -07:00
|
|
|
continue;
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
|
2008-07-23 10:25:51 -07:00
|
|
|
// Undashed sides will currently draw the entire side,
|
|
|
|
// including parts that would normally be covered by a corner,
|
|
|
|
// so we need to clip.
|
|
|
|
//
|
|
|
|
// XXX Optimization -- it would be good to make this work like
|
|
|
|
// DrawDashedSide, and have a DrawOneSide function that just
|
|
|
|
// draws one side and not the corners, because then we can
|
|
|
|
// avoid the potentially expensive clip.
|
|
|
|
mContext->Save();
|
|
|
|
mContext->NewPath();
|
|
|
|
DoSideClipWithoutCornersSubPath(side);
|
|
|
|
mContext->Clip();
|
|
|
|
|
|
|
|
DrawBorderSides(1 << side);
|
|
|
|
|
2008-07-23 10:25:23 -07:00
|
|
|
mContext->Restore();
|
2008-07-23 10:25:51 -07:00
|
|
|
|
|
|
|
SN("---------------- (*)");
|
2008-07-23 10:25:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|