2008-07-23 21:25:23 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:cindent:ts=2:et:sw=2:
|
2012-05-21 15:12:37 +04: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 21:25:23 +04:00
|
|
|
|
|
|
|
#ifndef NS_CSS_RENDERING_BORDERS_H
|
|
|
|
#define NS_CSS_RENDERING_BORDERS_H
|
|
|
|
|
|
|
|
#include "nsColor.h"
|
|
|
|
|
2013-08-20 02:55:18 +04:00
|
|
|
class gfxContext;
|
2013-10-02 01:01:49 +04:00
|
|
|
class gfxPattern;
|
|
|
|
struct gfxRGBA;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
class GradientStops;
|
|
|
|
}
|
|
|
|
}
|
2008-07-23 21:25:23 +04:00
|
|
|
|
|
|
|
// define this to enable a bunch of debug dump info
|
|
|
|
#undef DEBUG_NEW_BORDERS
|
|
|
|
|
|
|
|
//thickness of dashed line relative to dotted line
|
|
|
|
#define DOT_LENGTH 1 //square
|
|
|
|
#define DASH_LENGTH 3 //3 times longer than dot
|
|
|
|
|
|
|
|
//some shorthand for side bits
|
|
|
|
#define SIDE_BIT_TOP (1 << NS_SIDE_TOP)
|
|
|
|
#define SIDE_BIT_RIGHT (1 << NS_SIDE_RIGHT)
|
|
|
|
#define SIDE_BIT_BOTTOM (1 << NS_SIDE_BOTTOM)
|
|
|
|
#define SIDE_BIT_LEFT (1 << NS_SIDE_LEFT)
|
|
|
|
#define SIDE_BITS_ALL (SIDE_BIT_TOP|SIDE_BIT_RIGHT|SIDE_BIT_BOTTOM|SIDE_BIT_LEFT)
|
|
|
|
|
2010-04-27 20:15:02 +04:00
|
|
|
#define C_TL NS_CORNER_TOP_LEFT
|
|
|
|
#define C_TR NS_CORNER_TOP_RIGHT
|
|
|
|
#define C_BR NS_CORNER_BOTTOM_RIGHT
|
|
|
|
#define C_BL NS_CORNER_BOTTOM_LEFT
|
2008-07-23 21:25:23 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper class that handles border rendering.
|
|
|
|
*
|
|
|
|
* appUnitsPerPixel -- current value of AUPP
|
|
|
|
* destContext -- the gfxContext to which the border should be rendered
|
|
|
|
* outsideRect -- the rectangle on the outer edge of the border
|
2010-04-27 20:15:01 +04:00
|
|
|
*
|
2008-07-23 21:25:23 +04:00
|
|
|
* For any parameter where an array of side values is passed in,
|
|
|
|
* they are in top, right, bottom, left order.
|
|
|
|
*
|
|
|
|
* borderStyles -- one border style enum per side
|
|
|
|
* borderWidths -- one border width per side
|
|
|
|
* borderRadii -- a gfxCornerSizes struct describing the w/h for each rounded corner.
|
|
|
|
* If the corner doesn't have a border radius, 0,0 should be given for it.
|
|
|
|
* borderColors -- one nscolor per side
|
2013-10-08 22:47:21 +04:00
|
|
|
* compositeColors -- a pointer to an array of composite color structs, or
|
|
|
|
* nullptr if none.
|
2008-07-23 21:25:23 +04:00
|
|
|
*
|
|
|
|
* skipSides -- a bit mask specifying which sides, if any, to skip
|
|
|
|
* backgroundColor -- the background color of the element.
|
|
|
|
* Used in calculating colors for 2-tone borders, such as inset and outset
|
|
|
|
* gapRect - a rectangle that should be clipped out to leave a gap in a border,
|
2012-07-30 18:20:58 +04:00
|
|
|
* or nullptr if none.
|
2008-07-23 21:25:23 +04:00
|
|
|
*/
|
|
|
|
|
2008-07-23 21:25:51 +04:00
|
|
|
typedef enum {
|
|
|
|
BorderColorStyleNone,
|
|
|
|
BorderColorStyleSolid,
|
|
|
|
BorderColorStyleLight,
|
|
|
|
BorderColorStyleDark
|
|
|
|
} BorderColorStyle;
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
struct nsCSSBorderRenderer {
|
2012-08-22 19:56:38 +04:00
|
|
|
nsCSSBorderRenderer(int32_t aAppUnitsPerPixel,
|
2008-07-23 21:25:23 +04:00
|
|
|
gfxContext* aDestContext,
|
|
|
|
gfxRect& aOuterRect,
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint8_t* aBorderStyles,
|
2008-07-23 21:25:23 +04:00
|
|
|
const gfxFloat* aBorderWidths,
|
|
|
|
gfxCornerSizes& aBorderRadii,
|
|
|
|
const nscolor* aBorderColors,
|
|
|
|
nsBorderColors* const* aCompositeColors,
|
2008-08-06 14:33:18 +04:00
|
|
|
nscolor aBackgroundColor);
|
2008-07-23 21:25:23 +04:00
|
|
|
|
2009-05-13 12:26:48 +04:00
|
|
|
gfxCornerSizes mBorderCornerDimensions;
|
2008-07-23 21:25:23 +04:00
|
|
|
|
|
|
|
// destination context
|
|
|
|
gfxContext* mContext;
|
|
|
|
|
|
|
|
// the rectangle of the outside and the inside of the border
|
|
|
|
gfxRect mOuterRect;
|
|
|
|
gfxRect mInnerRect;
|
|
|
|
|
|
|
|
// the style and size of the border
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint8_t* mBorderStyles;
|
2008-07-23 21:25:23 +04:00
|
|
|
const gfxFloat* mBorderWidths;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t* mSanitizedStyles;
|
2010-12-02 16:17:58 +03:00
|
|
|
gfxFloat* mSanitizedWidths;
|
2008-07-23 21:25:23 +04:00
|
|
|
gfxCornerSizes mBorderRadii;
|
|
|
|
|
|
|
|
// colors
|
|
|
|
const nscolor* mBorderColors;
|
|
|
|
nsBorderColors* const* mCompositeColors;
|
|
|
|
|
2009-05-13 12:26:48 +04:00
|
|
|
// core app units per pixel
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mAUPP;
|
2009-05-13 12:26:48 +04:00
|
|
|
|
2014-05-05 21:55:54 +04:00
|
|
|
// the background color
|
2008-07-23 21:25:23 +04:00
|
|
|
nscolor mBackgroundColor;
|
|
|
|
|
|
|
|
// calculated values
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mOneUnitBorder;
|
|
|
|
bool mNoBorderRadius;
|
|
|
|
bool mAvoidStroke;
|
2008-07-23 21:25:51 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
// For all the sides in the bitmask, would they be rendered
|
|
|
|
// in an identical color and style?
|
2012-08-22 19:56:38 +04:00
|
|
|
bool AreBorderSideFinalStylesSame(uint8_t aSides);
|
2008-07-23 21:25:23 +04:00
|
|
|
|
2008-07-23 21:25:51 +04:00
|
|
|
// For the given style, is the given corner a solid color?
|
2012-08-22 19:56:38 +04:00
|
|
|
bool IsSolidCornerStyle(uint8_t aStyle, mozilla::css::Corner aCorner);
|
2008-07-23 21:25:51 +04:00
|
|
|
|
|
|
|
// For the given solid corner, what color style should be used?
|
2012-08-22 19:56:38 +04:00
|
|
|
BorderColorStyle BorderColorStyleForSolidCorner(uint8_t aStyle, mozilla::css::Corner aCorner);
|
2008-07-23 21:25:51 +04:00
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
//
|
|
|
|
// Path generation functions
|
|
|
|
//
|
|
|
|
|
2008-07-23 21:25:51 +04:00
|
|
|
// add the path for drawing the given corner to the context
|
2010-04-27 20:15:02 +04:00
|
|
|
void DoCornerSubPath(mozilla::css::Corner aCorner);
|
2008-07-23 21:25:23 +04:00
|
|
|
// add the path for drawing the given side without any adjacent corners to the context
|
2010-04-27 20:15:02 +04:00
|
|
|
void DoSideClipWithoutCornersSubPath(mozilla::css::Side aSide);
|
2008-07-23 21:25:23 +04:00
|
|
|
|
|
|
|
// Create a clip path for the wedge that this side of
|
|
|
|
// the border should take up. This is only called
|
|
|
|
// when we're drawing separate border sides, so we know
|
|
|
|
// that ADD compositing is taking place.
|
|
|
|
//
|
|
|
|
// This code needs to make sure that the individual pieces
|
|
|
|
// don't ever (mathematically) overlap; the pixel overlap
|
|
|
|
// is taken care of by the ADD compositing.
|
2010-04-27 20:15:02 +04:00
|
|
|
void DoSideClipSubPath(mozilla::css::Side aSide);
|
2008-07-23 21:25:23 +04:00
|
|
|
|
|
|
|
// Given a set of sides to fill and a color, do so in the fastest way.
|
|
|
|
//
|
|
|
|
// Stroke tends to be faster for smaller borders because it doesn't go
|
|
|
|
// through the tessellator, which has initialization overhead. If
|
|
|
|
// we're rendering all sides, we can use stroke at any thickness; we
|
|
|
|
// also do TL/BR pairs at 1px thickness using stroke.
|
|
|
|
//
|
|
|
|
// If we can't stroke, then if it's a TL/BR pair, we use the specific
|
|
|
|
// TL/BR paths. Otherwise, we do the full path and fill.
|
|
|
|
//
|
|
|
|
// Calling code is expected to only set up a clip as necessary; no
|
|
|
|
// clip is needed if we can render the entire border in 1 or 2 passes.
|
|
|
|
void FillSolidBorder(const gfxRect& aOuterRect,
|
|
|
|
const gfxRect& aInnerRect,
|
|
|
|
const gfxCornerSizes& aBorderRadii,
|
|
|
|
const gfxFloat *aBorderSizes,
|
2012-08-09 11:09:40 +04:00
|
|
|
int aSides,
|
2008-07-23 21:25:23 +04:00
|
|
|
const gfxRGBA& aColor);
|
|
|
|
|
|
|
|
//
|
|
|
|
// core rendering
|
|
|
|
//
|
|
|
|
|
|
|
|
// draw the border for the given sides, using the style of the first side
|
|
|
|
// present in the bitmask
|
2012-08-09 11:09:40 +04:00
|
|
|
void DrawBorderSides (int aSides);
|
2008-07-23 21:25:23 +04:00
|
|
|
|
|
|
|
// function used by the above to handle -moz-border-colors
|
2012-08-09 11:09:40 +04:00
|
|
|
void DrawBorderSidesCompositeColors(int aSides, const nsBorderColors *compositeColors);
|
2008-07-23 21:25:23 +04:00
|
|
|
|
|
|
|
// draw the given dashed side
|
2010-04-27 20:15:02 +04:00
|
|
|
void DrawDashedSide (mozilla::css::Side aSide);
|
2010-12-02 16:17:58 +03:00
|
|
|
|
|
|
|
// Setup the stroke style for a given side
|
|
|
|
void SetupStrokeStyle(mozilla::css::Side aSize);
|
|
|
|
|
|
|
|
// Analyze if all border sides have the same width.
|
|
|
|
bool AllBordersSameWidth();
|
|
|
|
|
|
|
|
// Analyze if all borders are 'solid' this also considers hidden or 'none'
|
|
|
|
// borders because they can be considered 'solid' borders of 0 width and
|
|
|
|
// with no color effect.
|
|
|
|
bool AllBordersSolid(bool *aHasCompositeColors);
|
|
|
|
|
|
|
|
// Create a gradient pattern that will handle the color transition for a
|
|
|
|
// corner.
|
|
|
|
already_AddRefed<gfxPattern> CreateCornerGradient(mozilla::css::Corner aCorner,
|
|
|
|
const gfxRGBA &aFirstColor,
|
|
|
|
const gfxRGBA &aSecondColor);
|
|
|
|
|
2012-10-27 08:32:52 +04:00
|
|
|
// Azure variant of CreateCornerGradient.
|
|
|
|
mozilla::TemporaryRef<mozilla::gfx::GradientStops>
|
|
|
|
CreateCornerGradient(mozilla::css::Corner aCorner, const gfxRGBA &aFirstColor,
|
|
|
|
const gfxRGBA &aSecondColor, mozilla::gfx::DrawTarget *aDT,
|
|
|
|
mozilla::gfx::Point &aPoint1, mozilla::gfx::Point &aPoint2);
|
|
|
|
|
2010-12-02 16:17:58 +03:00
|
|
|
// Draw a solid color border that is uniformly the same width.
|
|
|
|
void DrawSingleWidthSolidBorder();
|
|
|
|
|
|
|
|
// Draw any border which is solid on all sides and does not use
|
|
|
|
// CompositeColors.
|
|
|
|
void DrawNoCompositeColorSolidBorder();
|
|
|
|
|
|
|
|
// Draw a solid border that has no border radius (i.e. is rectangular) and
|
|
|
|
// uses CompositeColors.
|
|
|
|
void DrawRectangularCompositeColors();
|
2008-07-23 21:25:23 +04:00
|
|
|
|
|
|
|
// draw the entire border
|
|
|
|
void DrawBorders ();
|
2009-01-09 03:28:32 +03:00
|
|
|
|
|
|
|
// utility function used for background painting as well as borders
|
|
|
|
static void ComputeInnerRadii(const gfxCornerSizes& aRadii,
|
|
|
|
const gfxFloat *aBorderSizes,
|
|
|
|
gfxCornerSizes *aInnerRadiiRet);
|
2012-04-30 06:37:04 +04:00
|
|
|
|
|
|
|
// Given aRadii as the border radii for a rectangle, compute the
|
|
|
|
// appropriate radii for another rectangle *outside* that rectangle
|
|
|
|
// by increasing the radii, except keeping sharp corners sharp.
|
|
|
|
// Used for spread box-shadows
|
|
|
|
static void ComputeOuterRadii(const gfxCornerSizes& aRadii,
|
|
|
|
const gfxFloat *aBorderSizes,
|
|
|
|
gfxCornerSizes *aOuterRadiiRet);
|
2008-07-23 21:25:23 +04:00
|
|
|
};
|
|
|
|
|
2013-11-15 06:43:56 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
#ifdef DEBUG_NEW_BORDERS
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
static inline void S(const gfxPoint& p) {
|
|
|
|
fprintf (stderr, "[%f,%f]", p.x, p.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void S(const gfxSize& s) {
|
|
|
|
fprintf (stderr, "[%f %f]", s.width, s.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void S(const gfxRect& r) {
|
|
|
|
fprintf (stderr, "[%f %f %f %f]", r.pos.x, r.pos.y, r.size.width, r.size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void S(const gfxFloat f) {
|
|
|
|
fprintf (stderr, "%f", f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void S(const char *s) {
|
|
|
|
fprintf (stderr, "%s", s);
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
static inline void SN(const char *s = nullptr) {
|
2008-07-23 21:25:23 +04:00
|
|
|
if (s)
|
|
|
|
fprintf (stderr, "%s", s);
|
|
|
|
fprintf (stderr, "\n");
|
|
|
|
fflush (stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void SF(const char *fmt, ...) {
|
|
|
|
va_list vl;
|
|
|
|
va_start(vl, fmt);
|
|
|
|
vfprintf (stderr, fmt, vl);
|
|
|
|
va_end(vl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void SX(gfxContext *ctx) {
|
|
|
|
gfxPoint p = ctx->CurrentPoint();
|
|
|
|
fprintf (stderr, "p: %f %f\n", p.x, p.y);
|
|
|
|
return;
|
|
|
|
ctx->MoveTo(p + gfxPoint(-2, -2)); ctx->LineTo(p + gfxPoint(2, 2));
|
|
|
|
ctx->MoveTo(p + gfxPoint(-2, 2)); ctx->LineTo(p + gfxPoint(2, -2));
|
|
|
|
ctx->MoveTo(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
static inline void S(const gfxPoint& p) {}
|
|
|
|
static inline void S(const gfxSize& s) {}
|
|
|
|
static inline void S(const gfxRect& r) {}
|
|
|
|
static inline void S(const gfxFloat f) {}
|
|
|
|
static inline void S(const char *s) {}
|
2012-07-30 18:20:58 +04:00
|
|
|
static inline void SN(const char *s = nullptr) {}
|
2008-07-23 21:25:23 +04:00
|
|
|
static inline void SF(const char *fmt, ...) {}
|
|
|
|
static inline void SX(gfxContext *ctx) {}
|
|
|
|
#endif
|
|
|
|
|
2013-11-15 06:43:56 +04:00
|
|
|
}
|
|
|
|
|
2008-07-23 21:25:23 +04:00
|
|
|
#endif /* NS_CSS_RENDERING_BORDERS_H */
|