1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 // vim:cindent:ts=2:et:sw=2:
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsStyleConsts.h"
8 #include "nsCSSColorUtils.h"
9 #include "GeckoProfiler.h"
10 #include "nsExpirationTracker.h"
11 #include "RoundedRect.h"
12 #include "nsClassHashtable.h"
13 #include "nsStyleStruct.h"
14 #include "gfxContext.h"
15 #include "nsCSSRenderingBorders.h"
16 #include "mozilla/gfx/2D.h"
17 #include "gfx2DGlue.h"
18 #include "gfxGradientCache.h"
21 using namespace mozilla
;
22 using namespace mozilla::gfx
;
25 * nsCSSRendering::PaintBorder
26 * nsCSSRendering::PaintOutline
30 * -> Ability to use specialized approach?
31 * |- Draw using specialized function
32 * |- separate corners?
35 * -> can border be drawn in 1 pass? (e.g., solid border same color all around)
36 * |- DrawBorderSides with all 4 sides
37 * -> more than 1 pass?
39 * |- clip to DoCornerClipSubPath
40 * |- for each side adjacent to corner
41 * |- clip to DoSideClipSubPath
42 * |- DrawBorderSides with one side
44 * |- DoSideClipWithoutCornersSubPath
45 * |- DrawDashedSide || DrawBorderSides with one side
48 static void ComputeBorderCornerDimensions(const gfxRect
& aOuterRect
,
49 const gfxRect
& aInnerRect
,
50 const gfxCornerSizes
& aRadii
,
51 gfxCornerSizes
*aDimsResult
);
53 // given a side index, get the previous and next side index
54 #define NEXT_SIDE(_s) mozilla::css::Side(((_s) + 1) & 3)
55 #define PREV_SIDE(_s) mozilla::css::Side(((_s) + 3) & 3)
57 // from the given base color and the background color, turn
58 // color into a color for the given border pattern style
59 static gfxRGBA
MakeBorderColor(const gfxRGBA
& aColor
,
60 const gfxRGBA
& aBackgroundColor
,
61 BorderColorStyle aBorderColorStyle
);
64 // Given a line index (an index starting from the outside of the
65 // border going inwards) and an array of line styles, calculate the
66 // color that that stripe of the border should be rendered in.
67 static gfxRGBA
ComputeColorForLine(uint32_t aLineIndex
,
68 const BorderColorStyle
* aBorderColorStyle
,
69 uint32_t aBorderColorStyleCount
,
71 nscolor aBackgroundColor
);
73 static gfxRGBA
ComputeCompositeColorForLine(uint32_t aLineIndex
,
74 const nsBorderColors
* aBorderColors
);
76 // little helper function to check if the array of 4 floats given are
77 // equal to the given value
79 CheckFourFloatsEqual(const gfxFloat
*vals
, gfxFloat k
)
81 return (vals
[0] == k
&&
88 IsZeroSize(const gfxSize
& sz
) {
89 return sz
.width
== 0.0 || sz
.height
== 0.0;
93 AllCornersZeroSize(const gfxCornerSizes
& corners
) {
94 return IsZeroSize(corners
[NS_CORNER_TOP_LEFT
]) &&
95 IsZeroSize(corners
[NS_CORNER_TOP_RIGHT
]) &&
96 IsZeroSize(corners
[NS_CORNER_BOTTOM_RIGHT
]) &&
97 IsZeroSize(corners
[NS_CORNER_BOTTOM_LEFT
]);
101 // Normal solid square corner. Will be rectangular, the size of the
102 // adjacent sides. If the corner has a border radius, the corner
103 // will always be solid, since we don't do dotted/dashed etc.
106 // Paint the corner in whatever style is not dotted/dashed of the
110 // Paint the corner as a dot, the size of the bigger of the adjacent
115 nsCSSBorderRenderer::nsCSSBorderRenderer(int32_t aAppUnitsPerPixel
,
116 gfxContext
* aDestContext
,
118 const uint8_t* aBorderStyles
,
119 const gfxFloat
* aBorderWidths
,
120 gfxCornerSizes
& aBorderRadii
,
121 const nscolor
* aBorderColors
,
122 nsBorderColors
* const* aCompositeColors
,
123 nscolor aBackgroundColor
)
124 : mContext(aDestContext
),
125 mOuterRect(aOuterRect
),
126 mBorderStyles(aBorderStyles
),
127 mBorderWidths(aBorderWidths
),
128 mBorderRadii(aBorderRadii
),
129 mBorderColors(aBorderColors
),
130 mCompositeColors(aCompositeColors
),
131 mAUPP(aAppUnitsPerPixel
),
132 mBackgroundColor(aBackgroundColor
)
134 if (!mCompositeColors
) {
135 static nsBorderColors
* const noColors
[4] = { nullptr };
136 mCompositeColors
= &noColors
[0];
139 mInnerRect
= mOuterRect
;
141 gfxMargin(mBorderStyles
[0] != NS_STYLE_BORDER_STYLE_NONE
? mBorderWidths
[0] : 0,
142 mBorderStyles
[1] != NS_STYLE_BORDER_STYLE_NONE
? mBorderWidths
[1] : 0,
143 mBorderStyles
[2] != NS_STYLE_BORDER_STYLE_NONE
? mBorderWidths
[2] : 0,
144 mBorderStyles
[3] != NS_STYLE_BORDER_STYLE_NONE
? mBorderWidths
[3] : 0));
146 ComputeBorderCornerDimensions(mOuterRect
, mInnerRect
, mBorderRadii
, &mBorderCornerDimensions
);
148 mOneUnitBorder
= CheckFourFloatsEqual(mBorderWidths
, 1.0);
149 mNoBorderRadius
= AllCornersZeroSize(mBorderRadii
);
150 mAvoidStroke
= false;
154 nsCSSBorderRenderer::ComputeInnerRadii(const gfxCornerSizes
& aRadii
,
155 const gfxFloat
*aBorderSizes
,
156 gfxCornerSizes
*aInnerRadiiRet
)
158 gfxCornerSizes
& iRadii
= *aInnerRadiiRet
;
160 iRadii
[C_TL
].width
= std::max(0.0, aRadii
[C_TL
].width
- aBorderSizes
[NS_SIDE_LEFT
]);
161 iRadii
[C_TL
].height
= std::max(0.0, aRadii
[C_TL
].height
- aBorderSizes
[NS_SIDE_TOP
]);
163 iRadii
[C_TR
].width
= std::max(0.0, aRadii
[C_TR
].width
- aBorderSizes
[NS_SIDE_RIGHT
]);
164 iRadii
[C_TR
].height
= std::max(0.0, aRadii
[C_TR
].height
- aBorderSizes
[NS_SIDE_TOP
]);
166 iRadii
[C_BR
].width
= std::max(0.0, aRadii
[C_BR
].width
- aBorderSizes
[NS_SIDE_RIGHT
]);
167 iRadii
[C_BR
].height
= std::max(0.0, aRadii
[C_BR
].height
- aBorderSizes
[NS_SIDE_BOTTOM
]);
169 iRadii
[C_BL
].width
= std::max(0.0, aRadii
[C_BL
].width
- aBorderSizes
[NS_SIDE_LEFT
]);
170 iRadii
[C_BL
].height
= std::max(0.0, aRadii
[C_BL
].height
- aBorderSizes
[NS_SIDE_BOTTOM
]);
174 nsCSSBorderRenderer::ComputeOuterRadii(const gfxCornerSizes
& aRadii
,
175 const gfxFloat
*aBorderSizes
,
176 gfxCornerSizes
*aOuterRadiiRet
)
178 gfxCornerSizes
& oRadii
= *aOuterRadiiRet
;
180 // default all corners to sharp corners
181 oRadii
= gfxCornerSizes(0.0);
183 // round the edges that have radii > 0.0 to start with
184 if (aRadii
[C_TL
].width
> 0.0 && aRadii
[C_TL
].height
> 0.0) {
185 oRadii
[C_TL
].width
= std::max(0.0, aRadii
[C_TL
].width
+ aBorderSizes
[NS_SIDE_LEFT
]);
186 oRadii
[C_TL
].height
= std::max(0.0, aRadii
[C_TL
].height
+ aBorderSizes
[NS_SIDE_TOP
]);
189 if (aRadii
[C_TR
].width
> 0.0 && aRadii
[C_TR
].height
> 0.0) {
190 oRadii
[C_TR
].width
= std::max(0.0, aRadii
[C_TR
].width
+ aBorderSizes
[NS_SIDE_RIGHT
]);
191 oRadii
[C_TR
].height
= std::max(0.0, aRadii
[C_TR
].height
+ aBorderSizes
[NS_SIDE_TOP
]);
194 if (aRadii
[C_BR
].width
> 0.0 && aRadii
[C_BR
].height
> 0.0) {
195 oRadii
[C_BR
].width
= std::max(0.0, aRadii
[C_BR
].width
+ aBorderSizes
[NS_SIDE_RIGHT
]);
196 oRadii
[C_BR
].height
= std::max(0.0, aRadii
[C_BR
].height
+ aBorderSizes
[NS_SIDE_BOTTOM
]);
199 if (aRadii
[C_BL
].width
> 0.0 && aRadii
[C_BL
].height
> 0.0) {
200 oRadii
[C_BL
].width
= std::max(0.0, aRadii
[C_BL
].width
+ aBorderSizes
[NS_SIDE_LEFT
]);
201 oRadii
[C_BL
].height
= std::max(0.0, aRadii
[C_BL
].height
+ aBorderSizes
[NS_SIDE_BOTTOM
]);
206 ComputeBorderCornerDimensions(const gfxRect
& aOuterRect
,
207 const gfxRect
& aInnerRect
,
208 const gfxCornerSizes
& aRadii
,
209 gfxCornerSizes
*aDimsRet
)
211 gfxFloat leftWidth
= aInnerRect
.X() - aOuterRect
.X();
212 gfxFloat topWidth
= aInnerRect
.Y() - aOuterRect
.Y();
213 gfxFloat rightWidth
= aOuterRect
.Width() - aInnerRect
.Width() - leftWidth
;
214 gfxFloat bottomWidth
= aOuterRect
.Height() - aInnerRect
.Height() - topWidth
;
216 if (AllCornersZeroSize(aRadii
)) {
217 // These will always be in pixel units from CSS
218 (*aDimsRet
)[C_TL
] = gfxSize(leftWidth
, topWidth
);
219 (*aDimsRet
)[C_TR
] = gfxSize(rightWidth
, topWidth
);
220 (*aDimsRet
)[C_BR
] = gfxSize(rightWidth
, bottomWidth
);
221 (*aDimsRet
)[C_BL
] = gfxSize(leftWidth
, bottomWidth
);
223 // Always round up to whole pixels for the corners; it's safe to
224 // make the corners bigger than necessary, and this way we ensure
225 // that we avoid seams.
226 (*aDimsRet
)[C_TL
] = gfxSize(ceil(std::max(leftWidth
, aRadii
[C_TL
].width
)),
227 ceil(std::max(topWidth
, aRadii
[C_TL
].height
)));
228 (*aDimsRet
)[C_TR
] = gfxSize(ceil(std::max(rightWidth
, aRadii
[C_TR
].width
)),
229 ceil(std::max(topWidth
, aRadii
[C_TR
].height
)));
230 (*aDimsRet
)[C_BR
] = gfxSize(ceil(std::max(rightWidth
, aRadii
[C_BR
].width
)),
231 ceil(std::max(bottomWidth
, aRadii
[C_BR
].height
)));
232 (*aDimsRet
)[C_BL
] = gfxSize(ceil(std::max(leftWidth
, aRadii
[C_BL
].width
)),
233 ceil(std::max(bottomWidth
, aRadii
[C_BL
].height
)));
238 nsCSSBorderRenderer::AreBorderSideFinalStylesSame(uint8_t aSides
)
240 NS_ASSERTION(aSides
!= 0 && (aSides
& ~SIDE_BITS_ALL
) == 0,
241 "AreBorderSidesSame: invalid whichSides!");
243 /* First check if the specified styles and colors are the same for all sides */
245 NS_FOR_CSS_SIDES (i
) {
246 if (firstStyle
== i
) {
247 if (((1 << i
) & aSides
) == 0)
252 if (((1 << i
) & aSides
) == 0) {
256 if (mBorderStyles
[firstStyle
] != mBorderStyles
[i
] ||
257 mBorderColors
[firstStyle
] != mBorderColors
[i
] ||
258 !nsBorderColors::Equal(mCompositeColors
[firstStyle
],
259 mCompositeColors
[i
]))
263 /* Then if it's one of the two-tone styles and we're not
264 * just comparing the TL or BR sides */
265 switch (mBorderStyles
[firstStyle
]) {
266 case NS_STYLE_BORDER_STYLE_GROOVE
:
267 case NS_STYLE_BORDER_STYLE_RIDGE
:
268 case NS_STYLE_BORDER_STYLE_INSET
:
269 case NS_STYLE_BORDER_STYLE_OUTSET
:
270 return ((aSides
& ~(SIDE_BIT_TOP
| SIDE_BIT_LEFT
)) == 0 ||
271 (aSides
& ~(SIDE_BIT_BOTTOM
| SIDE_BIT_RIGHT
)) == 0);
278 nsCSSBorderRenderer::IsSolidCornerStyle(uint8_t aStyle
, mozilla::css::Corner aCorner
)
281 case NS_STYLE_BORDER_STYLE_DOTTED
:
282 case NS_STYLE_BORDER_STYLE_DASHED
:
283 case NS_STYLE_BORDER_STYLE_SOLID
:
286 case NS_STYLE_BORDER_STYLE_INSET
:
287 case NS_STYLE_BORDER_STYLE_OUTSET
:
288 return (aCorner
== NS_CORNER_TOP_LEFT
|| aCorner
== NS_CORNER_BOTTOM_RIGHT
);
290 case NS_STYLE_BORDER_STYLE_GROOVE
:
291 case NS_STYLE_BORDER_STYLE_RIDGE
:
292 return mOneUnitBorder
&& (aCorner
== NS_CORNER_TOP_LEFT
|| aCorner
== NS_CORNER_BOTTOM_RIGHT
);
294 case NS_STYLE_BORDER_STYLE_DOUBLE
:
295 return mOneUnitBorder
;
303 nsCSSBorderRenderer::BorderColorStyleForSolidCorner(uint8_t aStyle
, mozilla::css::Corner aCorner
)
305 // note that this function assumes that the corner is already solid,
306 // as per the earlier function
308 case NS_STYLE_BORDER_STYLE_DOTTED
:
309 case NS_STYLE_BORDER_STYLE_DASHED
:
310 case NS_STYLE_BORDER_STYLE_SOLID
:
311 case NS_STYLE_BORDER_STYLE_DOUBLE
:
312 return BorderColorStyleSolid
;
314 case NS_STYLE_BORDER_STYLE_INSET
:
315 case NS_STYLE_BORDER_STYLE_GROOVE
:
316 if (aCorner
== NS_CORNER_TOP_LEFT
)
317 return BorderColorStyleDark
;
318 else if (aCorner
== NS_CORNER_BOTTOM_RIGHT
)
319 return BorderColorStyleLight
;
322 case NS_STYLE_BORDER_STYLE_OUTSET
:
323 case NS_STYLE_BORDER_STYLE_RIDGE
:
324 if (aCorner
== NS_CORNER_TOP_LEFT
)
325 return BorderColorStyleLight
;
326 else if (aCorner
== NS_CORNER_BOTTOM_RIGHT
)
327 return BorderColorStyleDark
;
331 return BorderColorStyleNone
;
335 nsCSSBorderRenderer::DoCornerSubPath(mozilla::css::Corner aCorner
)
337 gfxPoint
offset(0.0, 0.0);
339 if (aCorner
== C_TR
|| aCorner
== C_BR
)
340 offset
.x
= mOuterRect
.Width() - mBorderCornerDimensions
[aCorner
].width
;
341 if (aCorner
== C_BR
|| aCorner
== C_BL
)
342 offset
.y
= mOuterRect
.Height() - mBorderCornerDimensions
[aCorner
].height
;
344 mContext
->Rectangle(gfxRect(mOuterRect
.TopLeft() + offset
,
345 mBorderCornerDimensions
[aCorner
]));
349 nsCSSBorderRenderer::DoSideClipWithoutCornersSubPath(mozilla::css::Side aSide
)
351 gfxPoint
offset(0.0, 0.0);
353 // The offset from the outside rect to the start of this side's
354 // box. For the top and bottom sides, the height of the box
355 // must be the border height; the x start must take into account
356 // the corner size (which may be bigger than the right or left
357 // side's width). The same applies to the right and left sides.
358 if (aSide
== NS_SIDE_TOP
) {
359 offset
.x
= mBorderCornerDimensions
[C_TL
].width
;
360 } else if (aSide
== NS_SIDE_RIGHT
) {
361 offset
.x
= mOuterRect
.Width() - mBorderWidths
[NS_SIDE_RIGHT
];
362 offset
.y
= mBorderCornerDimensions
[C_TR
].height
;
363 } else if (aSide
== NS_SIDE_BOTTOM
) {
364 offset
.x
= mBorderCornerDimensions
[C_BL
].width
;
365 offset
.y
= mOuterRect
.Height() - mBorderWidths
[NS_SIDE_BOTTOM
];
366 } else if (aSide
== NS_SIDE_LEFT
) {
367 offset
.y
= mBorderCornerDimensions
[C_TL
].height
;
370 // The sum of the width & height of the corners adjacent to the
371 // side. This relies on the relationship between side indexing and
372 // corner indexing; that is, 0 == SIDE_TOP and 0 == CORNER_TOP_LEFT,
373 // with both proceeding clockwise.
374 gfxSize sideCornerSum
= mBorderCornerDimensions
[mozilla::css::Corner(aSide
)]
375 + mBorderCornerDimensions
[mozilla::css::Corner(NEXT_SIDE(aSide
))];
376 gfxRect
rect(mOuterRect
.TopLeft() + offset
,
377 mOuterRect
.Size() - sideCornerSum
);
379 if (aSide
== NS_SIDE_TOP
|| aSide
== NS_SIDE_BOTTOM
)
380 rect
.height
= mBorderWidths
[aSide
];
382 rect
.width
= mBorderWidths
[aSide
];
384 mContext
->Rectangle(rect
);
387 // The side border type and the adjacent border types are
388 // examined and one of the different types of clipping (listed
389 // below) is selected.
392 // clip to the trapezoid formed by the corners of the
393 // inner and outer rectangles for the given side
396 // clip to the trapezoid formed by the outer rectangle
397 // corners and the center of the region, making sure
398 // that diagonal lines all go directly from the outside
399 // corner to the inside corner, but that they then continue on
402 // This is needed for correctly clipping rounded borders,
403 // which might extend past the SIDE_CLIP_TRAPEZOID trap.
404 SIDE_CLIP_TRAPEZOID_FULL
,
406 // clip to the rectangle formed by the given side; a specific
407 // overlap algorithm is used; see the function for details.
408 // this is currently used for dashing.
412 // Given three points, p0, p1, and midPoint, move p1 further in to the
413 // rectangle (of which aMidPoint is the center) so that it reaches the
414 // closer of the horizontal or vertical lines intersecting the midpoint,
415 // while maintaing the slope of the line. If p0 and p1 are the same,
416 // just move p1 to midPoint (since there's no slope to maintain).
417 // FIXME: Extending only to the midpoint isn't actually sufficient for
418 // boxes with asymmetric radii.
420 MaybeMoveToMidPoint(gfxPoint
& aP0
, gfxPoint
& aP1
, const gfxPoint
& aMidPoint
)
422 gfxPoint ps
= aP1
- aP0
;
434 gfxFloat k
= std::min((aMidPoint
.x
- aP0
.x
) / ps
.x
,
435 (aMidPoint
.y
- aP0
.y
) / ps
.y
);
442 nsCSSBorderRenderer::DoSideClipSubPath(mozilla::css::Side aSide
)
444 // the clip proceeds clockwise from the top left corner;
445 // so "start" in each case is the start of the region from that side.
447 // the final path will be formed like:
452 // that is, the second point will always be on the inside
457 #define IS_DASHED_OR_DOTTED(_s) ((_s) == NS_STYLE_BORDER_STYLE_DASHED || (_s) == NS_STYLE_BORDER_STYLE_DOTTED)
458 bool isDashed
= IS_DASHED_OR_DOTTED(mBorderStyles
[aSide
]);
459 bool startIsDashed
= IS_DASHED_OR_DOTTED(mBorderStyles
[PREV_SIDE(aSide
)]);
460 bool endIsDashed
= IS_DASHED_OR_DOTTED(mBorderStyles
[NEXT_SIDE(aSide
)]);
461 #undef IS_DASHED_OR_DOTTED
463 SideClipType startType
= SIDE_CLIP_TRAPEZOID
;
464 SideClipType endType
= SIDE_CLIP_TRAPEZOID
;
466 if (!IsZeroSize(mBorderRadii
[mozilla::css::Corner(aSide
)]))
467 startType
= SIDE_CLIP_TRAPEZOID_FULL
;
468 else if (startIsDashed
&& isDashed
)
469 startType
= SIDE_CLIP_RECTANGLE
;
471 if (!IsZeroSize(mBorderRadii
[mozilla::css::Corner(NEXT_SIDE(aSide
))]))
472 endType
= SIDE_CLIP_TRAPEZOID_FULL
;
473 else if (endIsDashed
&& isDashed
)
474 endType
= SIDE_CLIP_RECTANGLE
;
476 gfxPoint midPoint
= mInnerRect
.Center();
478 start
[0] = mOuterRect
.CCWCorner(aSide
);
479 start
[1] = mInnerRect
.CCWCorner(aSide
);
481 end
[0] = mOuterRect
.CWCorner(aSide
);
482 end
[1] = mInnerRect
.CWCorner(aSide
);
484 if (startType
== SIDE_CLIP_TRAPEZOID_FULL
) {
485 MaybeMoveToMidPoint(start
[0], start
[1], midPoint
);
486 } else if (startType
== SIDE_CLIP_RECTANGLE
) {
487 if (aSide
== NS_SIDE_TOP
|| aSide
== NS_SIDE_BOTTOM
)
488 start
[1] = gfxPoint(mOuterRect
.CCWCorner(aSide
).x
, mInnerRect
.CCWCorner(aSide
).y
);
490 start
[1] = gfxPoint(mInnerRect
.CCWCorner(aSide
).x
, mOuterRect
.CCWCorner(aSide
).y
);
493 if (endType
== SIDE_CLIP_TRAPEZOID_FULL
) {
494 MaybeMoveToMidPoint(end
[0], end
[1], midPoint
);
495 } else if (endType
== SIDE_CLIP_RECTANGLE
) {
496 if (aSide
== NS_SIDE_TOP
|| aSide
== NS_SIDE_BOTTOM
)
497 end
[0] = gfxPoint(mInnerRect
.CWCorner(aSide
).x
, mOuterRect
.CWCorner(aSide
).y
);
499 end
[0] = gfxPoint(mOuterRect
.CWCorner(aSide
).x
, mInnerRect
.CWCorner(aSide
).y
);
502 mContext
->MoveTo(start
[0]);
503 mContext
->LineTo(end
[0]);
504 mContext
->LineTo(end
[1]);
505 mContext
->LineTo(start
[1]);
506 mContext
->ClosePath();
510 nsCSSBorderRenderer::FillSolidBorder(const gfxRect
& aOuterRect
,
511 const gfxRect
& aInnerRect
,
512 const gfxCornerSizes
& aBorderRadii
,
513 const gfxFloat
*aBorderSizes
,
515 const gfxRGBA
& aColor
)
517 mContext
->SetColor(aColor
);
518 // Note that this function is allowed to draw more than just the
521 // If we have a border radius, do full rounded rectangles
522 // and fill, regardless of what sides we're asked to draw.
523 if (!AllCornersZeroSize(aBorderRadii
)) {
524 gfxCornerSizes innerRadii
;
525 ComputeInnerRadii(aBorderRadii
, aBorderSizes
, &innerRadii
);
529 // do the outer border
530 mContext
->RoundedRectangle(aOuterRect
, aBorderRadii
, true);
532 // then do the inner border CCW
533 mContext
->RoundedRectangle(aInnerRect
, innerRadii
, false);
540 // If we're asked to draw all sides of an equal-sized border,
541 // stroking is fastest. This is a fairly common path, but partial
542 // sides is probably second in the list -- there are a bunch of
543 // common border styles, such as inset and outset, that are
544 // top-left/bottom-right split.
545 if (aSides
== SIDE_BITS_ALL
&&
546 CheckFourFloatsEqual(aBorderSizes
, aBorderSizes
[0]) &&
549 gfxRect
r(aOuterRect
);
550 r
.Deflate(aBorderSizes
[0] / 2.0);
551 mContext
->SetLineWidth(aBorderSizes
[0]);
554 mContext
->Rectangle(r
);
560 // Otherwise, we have unequal sized borders or we're only
561 // drawing some sides; create rectangles for each side
566 // compute base rects for each side
567 if (aSides
& SIDE_BIT_TOP
) {
569 gfxRect(aOuterRect
.X(), aOuterRect
.Y(),
570 aOuterRect
.Width(), aBorderSizes
[NS_SIDE_TOP
]);
573 if (aSides
& SIDE_BIT_BOTTOM
) {
575 gfxRect(aOuterRect
.X(), aOuterRect
.YMost() - aBorderSizes
[NS_SIDE_BOTTOM
],
576 aOuterRect
.Width(), aBorderSizes
[NS_SIDE_BOTTOM
]);
579 if (aSides
& SIDE_BIT_LEFT
) {
581 gfxRect(aOuterRect
.X(), aOuterRect
.Y(),
582 aBorderSizes
[NS_SIDE_LEFT
], aOuterRect
.Height());
585 if (aSides
& SIDE_BIT_RIGHT
) {
587 gfxRect(aOuterRect
.XMost() - aBorderSizes
[NS_SIDE_RIGHT
], aOuterRect
.Y(),
588 aBorderSizes
[NS_SIDE_RIGHT
], aOuterRect
.Height());
591 // If two sides meet at a corner that we're rendering, then
592 // make sure that we adjust one of the sides to avoid overlap.
593 // This is especially important in the case of colors with
596 if ((aSides
& (SIDE_BIT_TOP
| SIDE_BIT_LEFT
)) == (SIDE_BIT_TOP
| SIDE_BIT_LEFT
)) {
597 // adjust the left's top down a bit
598 r
[NS_SIDE_LEFT
].y
+= aBorderSizes
[NS_SIDE_TOP
];
599 r
[NS_SIDE_LEFT
].height
-= aBorderSizes
[NS_SIDE_TOP
];
602 if ((aSides
& (SIDE_BIT_TOP
| SIDE_BIT_RIGHT
)) == (SIDE_BIT_TOP
| SIDE_BIT_RIGHT
)) {
603 // adjust the top's left a bit
604 r
[NS_SIDE_TOP
].width
-= aBorderSizes
[NS_SIDE_RIGHT
];
607 if ((aSides
& (SIDE_BIT_BOTTOM
| SIDE_BIT_RIGHT
)) == (SIDE_BIT_BOTTOM
| SIDE_BIT_RIGHT
)) {
608 // adjust the right's bottom a bit
609 r
[NS_SIDE_RIGHT
].height
-= aBorderSizes
[NS_SIDE_BOTTOM
];
612 if ((aSides
& (SIDE_BIT_BOTTOM
| SIDE_BIT_LEFT
)) == (SIDE_BIT_BOTTOM
| SIDE_BIT_LEFT
)) {
613 // adjust the bottom's left a bit
614 r
[NS_SIDE_BOTTOM
].x
+= aBorderSizes
[NS_SIDE_LEFT
];
615 r
[NS_SIDE_BOTTOM
].width
-= aBorderSizes
[NS_SIDE_LEFT
];
618 // Filling these one by one is faster than filling them all at once.
619 for (uint32_t i
= 0; i
< 4; i
++) {
620 if (aSides
& (1 << i
)) {
622 mContext
->Rectangle(r
[i
], true);
629 MakeBorderColor(const gfxRGBA
& aColor
, const gfxRGBA
& aBackgroundColor
, BorderColorStyle aBorderColorStyle
)
634 switch (aBorderColorStyle
) {
635 case BorderColorStyleNone
:
636 return gfxRGBA(0.0, 0.0, 0.0, 0.0);
638 case BorderColorStyleLight
:
641 case BorderColorStyleDark
:
642 NS_GetSpecial3DColors(colors
, aBackgroundColor
.Packed(), aColor
.Packed());
643 return gfxRGBA(colors
[k
]);
645 case BorderColorStyleSolid
:
652 ComputeColorForLine(uint32_t aLineIndex
,
653 const BorderColorStyle
* aBorderColorStyle
,
654 uint32_t aBorderColorStyleCount
,
655 nscolor aBorderColor
,
656 nscolor aBackgroundColor
)
658 NS_ASSERTION(aLineIndex
< aBorderColorStyleCount
, "Invalid lineIndex given");
660 return MakeBorderColor(gfxRGBA(aBorderColor
), gfxRGBA(aBackgroundColor
), aBorderColorStyle
[aLineIndex
]);
664 ComputeCompositeColorForLine(uint32_t aLineIndex
,
665 const nsBorderColors
* aBorderColors
)
667 while (aLineIndex
-- && aBorderColors
->mNext
)
668 aBorderColors
= aBorderColors
->mNext
;
670 return gfxRGBA(aBorderColors
->mColor
);
674 nsCSSBorderRenderer::DrawBorderSidesCompositeColors(int aSides
, const nsBorderColors
*aCompositeColors
)
676 gfxCornerSizes radii
= mBorderRadii
;
678 // the generic composite colors path; each border is 1px in size
679 gfxRect soRect
= mOuterRect
;
680 gfxFloat maxBorderWidth
= 0;
681 NS_FOR_CSS_SIDES (i
) {
682 maxBorderWidth
= std::max(maxBorderWidth
, mBorderWidths
[i
]);
685 gfxFloat fakeBorderSizes
[4];
687 gfxPoint itl
= mInnerRect
.TopLeft();
688 gfxPoint ibr
= mInnerRect
.BottomRight();
690 for (uint32_t i
= 0; i
< uint32_t(maxBorderWidth
); i
++) {
691 gfxRGBA lineColor
= ComputeCompositeColorForLine(i
, aCompositeColors
);
693 gfxRect siRect
= soRect
;
696 // now cap the rects to the real mInnerRect
697 gfxPoint tl
= siRect
.TopLeft();
698 gfxPoint br
= siRect
.BottomRight();
700 tl
.x
= std::min(tl
.x
, itl
.x
);
701 tl
.y
= std::min(tl
.y
, itl
.y
);
703 br
.x
= std::max(br
.x
, ibr
.x
);
704 br
.y
= std::max(br
.y
, ibr
.y
);
706 siRect
= gfxRect(tl
.x
, tl
.y
, br
.x
- tl
.x
, br
.y
- tl
.y
);
708 fakeBorderSizes
[NS_SIDE_TOP
] = siRect
.TopLeft().y
- soRect
.TopLeft().y
;
709 fakeBorderSizes
[NS_SIDE_RIGHT
] = soRect
.TopRight().x
- siRect
.TopRight().x
;
710 fakeBorderSizes
[NS_SIDE_BOTTOM
] = soRect
.BottomRight().y
- siRect
.BottomRight().y
;
711 fakeBorderSizes
[NS_SIDE_LEFT
] = siRect
.BottomLeft().x
- soRect
.BottomLeft().x
;
713 FillSolidBorder(soRect
, siRect
, radii
, fakeBorderSizes
, aSides
, lineColor
);
717 ComputeInnerRadii(radii
, fakeBorderSizes
, &radii
);
722 nsCSSBorderRenderer::DrawBorderSides(int aSides
)
724 if (aSides
== 0 || (aSides
& ~SIDE_BITS_ALL
) != 0) {
725 NS_WARNING("DrawBorderSides: invalid sides!");
729 uint8_t borderRenderStyle
= NS_STYLE_BORDER_STYLE_NONE
;
730 nscolor borderRenderColor
;
731 const nsBorderColors
*compositeColors
= nullptr;
733 uint32_t borderColorStyleCount
= 0;
734 BorderColorStyle borderColorStyleTopLeft
[3], borderColorStyleBottomRight
[3];
735 BorderColorStyle
*borderColorStyle
= nullptr;
737 NS_FOR_CSS_SIDES (i
) {
738 if ((aSides
& (1 << i
)) == 0)
740 borderRenderStyle
= mBorderStyles
[i
];
741 borderRenderColor
= mBorderColors
[i
];
742 compositeColors
= mCompositeColors
[i
];
746 if (borderRenderStyle
== NS_STYLE_BORDER_STYLE_NONE
||
747 borderRenderStyle
== NS_STYLE_BORDER_STYLE_HIDDEN
)
750 // -moz-border-colors is a hack; if we have it for a border, then
751 // it's always drawn solid, and each color is given 1px. The last
752 // color is used for the remainder of the border's size. Just
753 // hand off to another function to do all that.
754 if (compositeColors
) {
755 DrawBorderSidesCompositeColors(aSides
, compositeColors
);
759 // We're not doing compositeColors, so we can calculate the
760 // borderColorStyle based on the specified style. The
761 // borderColorStyle array goes from the outer to the inner style.
763 // If the border width is 1, we need to change the borderRenderStyle
764 // a bit to make sure that we get the right colors -- e.g. 'ridge'
765 // with a 1px border needs to look like solid, not like 'outset'.
766 if (mOneUnitBorder
&&
767 (borderRenderStyle
== NS_STYLE_BORDER_STYLE_RIDGE
||
768 borderRenderStyle
== NS_STYLE_BORDER_STYLE_GROOVE
||
769 borderRenderStyle
== NS_STYLE_BORDER_STYLE_DOUBLE
))
770 borderRenderStyle
= NS_STYLE_BORDER_STYLE_SOLID
;
772 switch (borderRenderStyle
) {
773 case NS_STYLE_BORDER_STYLE_SOLID
:
774 case NS_STYLE_BORDER_STYLE_DASHED
:
775 case NS_STYLE_BORDER_STYLE_DOTTED
:
776 borderColorStyleTopLeft
[0] = BorderColorStyleSolid
;
778 borderColorStyleBottomRight
[0] = BorderColorStyleSolid
;
780 borderColorStyleCount
= 1;
783 case NS_STYLE_BORDER_STYLE_GROOVE
:
784 borderColorStyleTopLeft
[0] = BorderColorStyleDark
;
785 borderColorStyleTopLeft
[1] = BorderColorStyleLight
;
787 borderColorStyleBottomRight
[0] = BorderColorStyleLight
;
788 borderColorStyleBottomRight
[1] = BorderColorStyleDark
;
790 borderColorStyleCount
= 2;
793 case NS_STYLE_BORDER_STYLE_RIDGE
:
794 borderColorStyleTopLeft
[0] = BorderColorStyleLight
;
795 borderColorStyleTopLeft
[1] = BorderColorStyleDark
;
797 borderColorStyleBottomRight
[0] = BorderColorStyleDark
;
798 borderColorStyleBottomRight
[1] = BorderColorStyleLight
;
800 borderColorStyleCount
= 2;
803 case NS_STYLE_BORDER_STYLE_DOUBLE
:
804 borderColorStyleTopLeft
[0] = BorderColorStyleSolid
;
805 borderColorStyleTopLeft
[1] = BorderColorStyleNone
;
806 borderColorStyleTopLeft
[2] = BorderColorStyleSolid
;
808 borderColorStyleBottomRight
[0] = BorderColorStyleSolid
;
809 borderColorStyleBottomRight
[1] = BorderColorStyleNone
;
810 borderColorStyleBottomRight
[2] = BorderColorStyleSolid
;
812 borderColorStyleCount
= 3;
815 case NS_STYLE_BORDER_STYLE_INSET
:
816 borderColorStyleTopLeft
[0] = BorderColorStyleDark
;
817 borderColorStyleBottomRight
[0] = BorderColorStyleLight
;
819 borderColorStyleCount
= 1;
822 case NS_STYLE_BORDER_STYLE_OUTSET
:
823 borderColorStyleTopLeft
[0] = BorderColorStyleLight
;
824 borderColorStyleBottomRight
[0] = BorderColorStyleDark
;
826 borderColorStyleCount
= 1;
830 NS_NOTREACHED("Unhandled border style!!");
834 // The only way to get to here is by having a
835 // borderColorStyleCount < 1 or > 3; this should never happen,
836 // since -moz-border-colors doesn't get handled here.
837 NS_ASSERTION(borderColorStyleCount
> 0 && borderColorStyleCount
< 4,
838 "Non-border-colors case with borderColorStyleCount < 1 or > 3; what happened?");
840 // The caller should never give us anything with a mix
841 // of TL/BR if the border style would require a
843 if (aSides
& (SIDE_BIT_BOTTOM
| SIDE_BIT_RIGHT
))
844 borderColorStyle
= borderColorStyleBottomRight
;
846 borderColorStyle
= borderColorStyleTopLeft
;
848 // Distribute the border across the available space.
849 gfxFloat borderWidths
[3][4];
851 if (borderColorStyleCount
== 1) {
852 NS_FOR_CSS_SIDES (i
) {
853 borderWidths
[0][i
] = mBorderWidths
[i
];
855 } else if (borderColorStyleCount
== 2) {
856 // with 2 color styles, any extra pixel goes to the outside
857 NS_FOR_CSS_SIDES (i
) {
858 borderWidths
[0][i
] = int32_t(mBorderWidths
[i
]) / 2 + int32_t(mBorderWidths
[i
]) % 2;
859 borderWidths
[1][i
] = int32_t(mBorderWidths
[i
]) / 2;
861 } else if (borderColorStyleCount
== 3) {
862 // with 3 color styles, any extra pixel (or lack of extra pixel)
863 // goes to the middle
864 NS_FOR_CSS_SIDES (i
) {
865 if (mBorderWidths
[i
] == 1.0) {
866 borderWidths
[0][i
] = 1.0;
867 borderWidths
[1][i
] = borderWidths
[2][i
] = 0.0;
869 int32_t rest
= int32_t(mBorderWidths
[i
]) % 3;
870 borderWidths
[0][i
] = borderWidths
[2][i
] = borderWidths
[1][i
] = (int32_t(mBorderWidths
[i
]) - rest
) / 3;
873 borderWidths
[1][i
] += 1.0;
874 } else if (rest
== 2) {
875 borderWidths
[0][i
] += 1.0;
876 borderWidths
[2][i
] += 1.0;
882 // make a copy that we can modify
883 gfxCornerSizes radii
= mBorderRadii
;
885 gfxRect
soRect(mOuterRect
);
886 gfxRect
siRect(mOuterRect
);
888 for (unsigned int i
= 0; i
< borderColorStyleCount
; i
++) {
889 // walk siRect inwards at the start of the loop to get the
890 // correct inner rect.
891 siRect
.Deflate(gfxMargin(borderWidths
[i
][0], borderWidths
[i
][1],
892 borderWidths
[i
][2], borderWidths
[i
][3]));
894 if (borderColorStyle
[i
] != BorderColorStyleNone
) {
895 gfxRGBA color
= ComputeColorForLine(i
,
896 borderColorStyle
, borderColorStyleCount
,
897 borderRenderColor
, mBackgroundColor
);
899 FillSolidBorder(soRect
, siRect
, radii
, borderWidths
[i
], aSides
, color
);
902 ComputeInnerRadii(radii
, borderWidths
[i
], &radii
);
904 // And now soRect is the same as siRect, for the next line in.
910 nsCSSBorderRenderer::DrawDashedSide(mozilla::css::Side aSide
)
915 uint8_t style
= mBorderStyles
[aSide
];
916 gfxFloat borderWidth
= mBorderWidths
[aSide
];
917 nscolor borderColor
= mBorderColors
[aSide
];
919 if (borderWidth
== 0.0)
922 if (style
== NS_STYLE_BORDER_STYLE_NONE
||
923 style
== NS_STYLE_BORDER_STYLE_HIDDEN
)
926 if (style
== NS_STYLE_BORDER_STYLE_DASHED
) {
927 dashWidth
= gfxFloat(borderWidth
* DOT_LENGTH
* DASH_LENGTH
);
932 mContext
->SetLineCap(gfxContext::LINE_CAP_BUTT
);
933 } else if (style
== NS_STYLE_BORDER_STYLE_DOTTED
) {
934 dashWidth
= gfxFloat(borderWidth
* DOT_LENGTH
);
936 if (borderWidth
> 2.0) {
938 dash
[1] = dashWidth
* 2.0;
940 mContext
->SetLineCap(gfxContext::LINE_CAP_ROUND
);
946 SF("DrawDashedSide: style: %d!!\n", style
);
947 NS_ERROR("DrawDashedSide called with style other than DASHED or DOTTED; someone's not playing nice");
951 SF("dash: %f %f\n", dash
[0], dash
[1]);
953 mContext
->SetDash(dash
, 2, 0.0);
955 gfxPoint start
= mOuterRect
.CCWCorner(aSide
);
956 gfxPoint end
= mOuterRect
.CWCorner(aSide
);
958 if (aSide
== NS_SIDE_TOP
) {
959 start
.x
+= mBorderCornerDimensions
[C_TL
].width
;
960 end
.x
-= mBorderCornerDimensions
[C_TR
].width
;
962 start
.y
+= borderWidth
/ 2.0;
963 end
.y
+= borderWidth
/ 2.0;
964 } else if (aSide
== NS_SIDE_RIGHT
) {
965 start
.x
-= borderWidth
/ 2.0;
966 end
.x
-= borderWidth
/ 2.0;
968 start
.y
+= mBorderCornerDimensions
[C_TR
].height
;
969 end
.y
-= mBorderCornerDimensions
[C_BR
].height
;
970 } else if (aSide
== NS_SIDE_BOTTOM
) {
971 start
.x
-= mBorderCornerDimensions
[C_BR
].width
;
972 end
.x
+= mBorderCornerDimensions
[C_BL
].width
;
974 start
.y
-= borderWidth
/ 2.0;
975 end
.y
-= borderWidth
/ 2.0;
976 } else if (aSide
== NS_SIDE_LEFT
) {
977 start
.x
+= borderWidth
/ 2.0;
978 end
.x
+= borderWidth
/ 2.0;
980 start
.y
-= mBorderCornerDimensions
[C_BL
].height
;
981 end
.y
+= mBorderCornerDimensions
[C_TL
].height
;
985 mContext
->MoveTo(start
);
986 mContext
->LineTo(end
);
987 mContext
->SetLineWidth(borderWidth
);
988 mContext
->SetColor(gfxRGBA(borderColor
));
989 //mContext->SetColor(gfxRGBA(1.0, 0.0, 0.0, 1.0));
994 nsCSSBorderRenderer::SetupStrokeStyle(mozilla::css::Side aSide
)
996 mContext
->SetColor(gfxRGBA(mBorderColors
[aSide
]));
997 mContext
->SetLineWidth(mBorderWidths
[aSide
]);
1001 nsCSSBorderRenderer::AllBordersSameWidth()
1003 if (mBorderWidths
[0] == mBorderWidths
[1] &&
1004 mBorderWidths
[0] == mBorderWidths
[2] &&
1005 mBorderWidths
[0] == mBorderWidths
[3])
1014 nsCSSBorderRenderer::AllBordersSolid(bool *aHasCompositeColors
)
1016 *aHasCompositeColors
= false;
1017 NS_FOR_CSS_SIDES(i
) {
1018 if (mCompositeColors
[i
] != nullptr) {
1019 *aHasCompositeColors
= true;
1021 if (mBorderStyles
[i
] == NS_STYLE_BORDER_STYLE_SOLID
||
1022 mBorderStyles
[i
] == NS_STYLE_BORDER_STYLE_NONE
||
1023 mBorderStyles
[i
] == NS_STYLE_BORDER_STYLE_HIDDEN
)
1033 bool IsVisible(int aStyle
)
1035 if (aStyle
!= NS_STYLE_BORDER_STYLE_NONE
&&
1036 aStyle
!= NS_STYLE_BORDER_STYLE_HIDDEN
) {
1042 already_AddRefed
<gfxPattern
>
1043 nsCSSBorderRenderer::CreateCornerGradient(mozilla::css::Corner aCorner
,
1044 const gfxRGBA
&aFirstColor
,
1045 const gfxRGBA
&aSecondColor
)
1047 typedef struct { gfxFloat a
, b
; } twoFloats
;
1049 const twoFloats gradientCoeff
[4] = { { -1, +1 },
1054 // Sides which form the 'width' and 'height' for the calculation of the angle
1055 // for our gradient.
1056 const int cornerWidth
[4] = { 3, 1, 1, 3 };
1057 const int cornerHeight
[4] = { 0, 0, 2, 2 };
1059 gfxPoint cornerOrigin
= mOuterRect
.AtCorner(aCorner
);
1061 gfxPoint pat1
, pat2
;
1062 pat1
.x
= cornerOrigin
.x
+
1063 mBorderWidths
[cornerHeight
[aCorner
]] * gradientCoeff
[aCorner
].a
;
1064 pat1
.y
= cornerOrigin
.y
+
1065 mBorderWidths
[cornerWidth
[aCorner
]] * gradientCoeff
[aCorner
].b
;
1066 pat2
.x
= cornerOrigin
.x
-
1067 mBorderWidths
[cornerHeight
[aCorner
]] * gradientCoeff
[aCorner
].a
;
1068 pat2
.y
= cornerOrigin
.y
-
1069 mBorderWidths
[cornerWidth
[aCorner
]] * gradientCoeff
[aCorner
].b
;
1071 float gradientOffset
=
1072 0.25 / sqrt(pow(mBorderWidths
[cornerHeight
[aCorner
]], 2) +
1073 pow(mBorderWidths
[cornerHeight
[aCorner
]], 2));
1075 nsRefPtr
<gfxPattern
> pattern
= new gfxPattern(pat1
.x
, pat1
.y
, pat2
.x
, pat2
.y
);
1076 pattern
->AddColorStop(0.5 - gradientOffset
, gfxRGBA(aFirstColor
));
1077 pattern
->AddColorStop(0.5 + gradientOffset
, gfxRGBA(aSecondColor
));
1079 return pattern
.forget();
1082 TemporaryRef
<GradientStops
>
1083 nsCSSBorderRenderer::CreateCornerGradient(mozilla::css::Corner aCorner
,
1084 const gfxRGBA
&aFirstColor
,
1085 const gfxRGBA
&aSecondColor
,
1090 typedef struct { gfxFloat a
, b
; } twoFloats
;
1092 const twoFloats gradientCoeff
[4] = { { -1, +1 },
1097 // Sides which form the 'width' and 'height' for the calculation of the angle
1098 // for our gradient.
1099 const int cornerWidth
[4] = { 3, 1, 1, 3 };
1100 const int cornerHeight
[4] = { 0, 0, 2, 2 };
1102 gfxPoint cornerOrigin
= mOuterRect
.AtCorner(aCorner
);
1104 gfxPoint pat1
, pat2
;
1105 pat1
.x
= cornerOrigin
.x
+
1106 mBorderWidths
[cornerHeight
[aCorner
]] * gradientCoeff
[aCorner
].a
;
1107 pat1
.y
= cornerOrigin
.y
+
1108 mBorderWidths
[cornerWidth
[aCorner
]] * gradientCoeff
[aCorner
].b
;
1109 pat2
.x
= cornerOrigin
.x
-
1110 mBorderWidths
[cornerHeight
[aCorner
]] * gradientCoeff
[aCorner
].a
;
1111 pat2
.y
= cornerOrigin
.y
-
1112 mBorderWidths
[cornerWidth
[aCorner
]] * gradientCoeff
[aCorner
].b
;
1114 aPoint1
= Point(pat1
.x
, pat1
.y
);
1115 aPoint2
= Point(pat2
.x
, pat2
.y
);
1117 Color firstColor
= ToColor(aFirstColor
);
1118 Color secondColor
= ToColor(aSecondColor
);
1120 nsTArray
<gfx::GradientStop
> rawStops(2);
1121 rawStops
.SetLength(2);
1122 // This is only guaranteed to give correct (and in some cases more correct)
1123 // rendering with the Direct2D Azure and Quartz Cairo backends. For other
1124 // cairo backends it could create un-antialiased border corner transitions
1125 // since that at least used to be pixman's behaviour for hard stops.
1126 rawStops
[0].color
= firstColor
;
1127 rawStops
[0].offset
= 0.5;
1128 rawStops
[1].color
= secondColor
;
1129 rawStops
[1].offset
= 0.5;
1130 RefPtr
<GradientStops
> gs
=
1131 gfxGradientCache::GetGradientStops(aDT
, rawStops
, ExtendMode::CLAMP
);
1133 // Having two corners, both with reversed color stops is pretty common
1134 // for certain border types. Let's optimize it!
1135 rawStops
[0].color
= secondColor
;
1136 rawStops
[1].color
= firstColor
;
1137 Point tmp
= aPoint1
;
1140 gs
= gfxGradientCache::GetOrCreateGradientStops(aDT
, rawStops
, ExtendMode::CLAMP
);
1145 typedef struct { gfxFloat a
, b
; } twoFloats
;
1148 nsCSSBorderRenderer::DrawSingleWidthSolidBorder()
1150 // Easy enough to deal with.
1151 mContext
->SetLineWidth(1);
1152 gfxRect rect
= mOuterRect
;
1155 const twoFloats cornerAdjusts
[4] = { { +0.5, 0 },
1161 NS_FOR_CSS_SIDES(side
) {
1162 gfxPoint firstCorner
= rect
.CCWCorner(side
);
1163 firstCorner
.x
+= cornerAdjusts
[side
].a
;
1164 firstCorner
.y
+= cornerAdjusts
[side
].b
;
1165 gfxPoint secondCorner
= rect
.CWCorner(side
);
1166 secondCorner
.x
+= cornerAdjusts
[side
].a
;
1167 secondCorner
.y
+= cornerAdjusts
[side
].b
;
1169 mContext
->SetColor(gfxRGBA(mBorderColors
[side
]));
1170 mContext
->NewPath();
1171 mContext
->MoveTo(firstCorner
);
1172 mContext
->LineTo(secondCorner
);
1178 nsCSSBorderRenderer::DrawNoCompositeColorSolidBorder()
1180 DrawTarget
*dt
= mContext
->GetDrawTarget();
1182 const gfxFloat alpha
= 0.55191497064665766025;
1184 const twoFloats cornerMults
[4] = { { -1, 0 },
1189 const twoFloats centerAdjusts
[4] = { { 0, +0.5 },
1194 Point pc
, pci
, p0
, p1
, p2
, p3
, pd
, p3i
;
1196 gfxCornerSizes innerRadii
;
1197 ComputeInnerRadii(mBorderRadii
, mBorderWidths
, &innerRadii
);
1199 gfxRect strokeRect
= mOuterRect
;
1200 strokeRect
.Deflate(gfxMargin(mBorderWidths
[0] / 2.0, mBorderWidths
[1] / 2.0,
1201 mBorderWidths
[2] / 2.0, mBorderWidths
[3] / 2.0));
1203 ColorPattern
colorPat(Color(0, 0, 0, 0));
1204 LinearGradientPattern
gradPat(Point(), Point(), nullptr);
1206 NS_FOR_CSS_CORNERS(i
) {
1207 // the corner index -- either 1 2 3 0 (cw) or 0 3 2 1 (ccw)
1208 mozilla::css::Corner c
= mozilla::css::Corner((i
+1) % 4);
1209 mozilla::css::Corner prevCorner
= mozilla::css::Corner(i
);
1211 // i+2 and i+3 respectively. These are used to index into the corner
1212 // multiplier table, and were deduced by calculating out the long form
1213 // of each corner and finding a pattern in the signs and values.
1218 pc
= ToPoint(mOuterRect
.AtCorner(c
));
1219 pci
= ToPoint(mInnerRect
.AtCorner(c
));
1221 nscolor firstColor
, secondColor
;
1222 if (IsVisible(mBorderStyles
[i
]) && IsVisible(mBorderStyles
[i1
])) {
1223 firstColor
= mBorderColors
[i
];
1224 secondColor
= mBorderColors
[i1
];
1225 } else if (IsVisible(mBorderStyles
[i
])) {
1226 firstColor
= mBorderColors
[i
];
1227 secondColor
= mBorderColors
[i
];
1229 firstColor
= mBorderColors
[i1
];
1230 secondColor
= mBorderColors
[i1
];
1233 RefPtr
<PathBuilder
> builder
= dt
->CreatePathBuilder();
1235 Point strokeStart
, strokeEnd
;
1237 strokeStart
.x
= mOuterRect
.AtCorner(prevCorner
).x
+
1238 mBorderCornerDimensions
[prevCorner
].width
* cornerMults
[i2
].a
;
1239 strokeStart
.y
= mOuterRect
.AtCorner(prevCorner
).y
+
1240 mBorderCornerDimensions
[prevCorner
].height
* cornerMults
[i2
].b
;
1242 strokeEnd
.x
= pc
.x
+ mBorderCornerDimensions
[c
].width
* cornerMults
[i
].a
;
1243 strokeEnd
.y
= pc
.y
+ mBorderCornerDimensions
[c
].height
* cornerMults
[i
].b
;
1245 strokeStart
.x
+= centerAdjusts
[i
].a
* mBorderWidths
[i
];
1246 strokeStart
.y
+= centerAdjusts
[i
].b
* mBorderWidths
[i
];
1247 strokeEnd
.x
+= centerAdjusts
[i
].a
* mBorderWidths
[i
];
1248 strokeEnd
.y
+= centerAdjusts
[i
].b
* mBorderWidths
[i
];
1250 builder
->MoveTo(strokeStart
);
1251 builder
->LineTo(strokeEnd
);
1252 RefPtr
<Path
> path
= builder
->Finish();
1253 dt
->Stroke(path
, ColorPattern(Color::FromABGR(mBorderColors
[i
])), StrokeOptions(mBorderWidths
[i
]));
1259 if (firstColor
!= secondColor
) {
1260 gradPat
.mStops
= CreateCornerGradient(c
, firstColor
, secondColor
, dt
, gradPat
.mBegin
, gradPat
.mEnd
);
1263 colorPat
.mColor
= Color::FromABGR(firstColor
);
1264 pattern
= &colorPat
;
1267 builder
= dt
->CreatePathBuilder();
1269 if (mBorderRadii
[c
].width
> 0 && mBorderRadii
[c
].height
> 0) {
1270 p0
.x
= pc
.x
+ cornerMults
[i
].a
* mBorderRadii
[c
].width
;
1271 p0
.y
= pc
.y
+ cornerMults
[i
].b
* mBorderRadii
[c
].height
;
1273 p3
.x
= pc
.x
+ cornerMults
[i3
].a
* mBorderRadii
[c
].width
;
1274 p3
.y
= pc
.y
+ cornerMults
[i3
].b
* mBorderRadii
[c
].height
;
1276 p1
.x
= p0
.x
+ alpha
* cornerMults
[i2
].a
* mBorderRadii
[c
].width
;
1277 p1
.y
= p0
.y
+ alpha
* cornerMults
[i2
].b
* mBorderRadii
[c
].height
;
1279 p2
.x
= p3
.x
- alpha
* cornerMults
[i3
].a
* mBorderRadii
[c
].width
;
1280 p2
.y
= p3
.y
- alpha
* cornerMults
[i3
].b
* mBorderRadii
[c
].height
;
1283 cornerStart
.x
= pc
.x
+ cornerMults
[i
].a
* mBorderCornerDimensions
[c
].width
;
1284 cornerStart
.y
= pc
.y
+ cornerMults
[i
].b
* mBorderCornerDimensions
[c
].height
;
1286 builder
->MoveTo(cornerStart
);
1287 builder
->LineTo(p0
);
1289 builder
->BezierTo(p1
, p2
, p3
);
1291 Point outerCornerEnd
;
1292 outerCornerEnd
.x
= pc
.x
+ cornerMults
[i3
].a
* mBorderCornerDimensions
[c
].width
;
1293 outerCornerEnd
.y
= pc
.y
+ cornerMults
[i3
].b
* mBorderCornerDimensions
[c
].height
;
1295 builder
->LineTo(outerCornerEnd
);
1297 p0
.x
= pci
.x
+ cornerMults
[i
].a
* innerRadii
[c
].width
;
1298 p0
.y
= pci
.y
+ cornerMults
[i
].b
* innerRadii
[c
].height
;
1300 p3i
.x
= pci
.x
+ cornerMults
[i3
].a
* innerRadii
[c
].width
;
1301 p3i
.y
= pci
.y
+ cornerMults
[i3
].b
* innerRadii
[c
].height
;
1303 p1
.x
= p0
.x
+ alpha
* cornerMults
[i2
].a
* innerRadii
[c
].width
;
1304 p1
.y
= p0
.y
+ alpha
* cornerMults
[i2
].b
* innerRadii
[c
].height
;
1306 p2
.x
= p3i
.x
- alpha
* cornerMults
[i3
].a
* innerRadii
[c
].width
;
1307 p2
.y
= p3i
.y
- alpha
* cornerMults
[i3
].b
* innerRadii
[c
].height
;
1308 builder
->LineTo(p3i
);
1309 builder
->BezierTo(p2
, p1
, p0
);
1311 path
= builder
->Finish();
1312 dt
->Fill(path
, *pattern
);
1314 Point c1
, c2
, c3
, c4
;
1316 c1
.x
= pc
.x
+ cornerMults
[i
].a
* mBorderCornerDimensions
[c
].width
;
1317 c1
.y
= pc
.y
+ cornerMults
[i
].b
* mBorderCornerDimensions
[c
].height
;
1319 c3
.x
= pc
.x
+ cornerMults
[i3
].a
* mBorderCornerDimensions
[c
].width
;
1320 c3
.y
= pc
.y
+ cornerMults
[i3
].b
* mBorderCornerDimensions
[c
].height
;
1322 builder
->MoveTo(c1
);
1323 builder
->LineTo(c2
);
1324 builder
->LineTo(c3
);
1325 builder
->LineTo(pci
);
1328 path
= builder
->Finish();
1330 dt
->Fill(path
, *pattern
);
1336 nsCSSBorderRenderer::DrawRectangularCompositeColors()
1338 nsBorderColors
*currentColors
[4];
1339 mContext
->SetLineWidth(1);
1340 memcpy(currentColors
, mCompositeColors
, sizeof(nsBorderColors
*) * 4);
1341 gfxRect rect
= mOuterRect
;
1344 const twoFloats cornerAdjusts
[4] = { { +0.5, 0 },
1349 for (int i
= 0; i
< mBorderWidths
[0]; i
++) {
1350 NS_FOR_CSS_SIDES(side
) {
1351 int sideNext
= (side
+ 1) % 4;
1353 gfxPoint firstCorner
= rect
.CCWCorner(side
);
1354 firstCorner
.x
+= cornerAdjusts
[side
].a
;
1355 firstCorner
.y
+= cornerAdjusts
[side
].b
;
1356 gfxPoint secondCorner
= rect
.CWCorner(side
);
1357 secondCorner
.x
-= cornerAdjusts
[side
].a
;
1358 secondCorner
.y
-= cornerAdjusts
[side
].b
;
1360 gfxRGBA currentColor
=
1361 currentColors
[side
] ? gfxRGBA(currentColors
[side
]->mColor
)
1362 : gfxRGBA(mBorderColors
[side
]);
1364 mContext
->SetColor(currentColor
);
1365 mContext
->NewPath();
1366 mContext
->MoveTo(firstCorner
);
1367 mContext
->LineTo(secondCorner
);
1370 mContext
->NewPath();
1371 gfxPoint cornerTopLeft
= rect
.CWCorner(side
);
1372 cornerTopLeft
.x
-= 0.5;
1373 cornerTopLeft
.y
-= 0.5;
1374 mContext
->Rectangle(gfxRect(cornerTopLeft
, gfxSize(1, 1)));
1376 currentColors
[sideNext
] ? gfxRGBA(currentColors
[sideNext
]->mColor
)
1377 : gfxRGBA(mBorderColors
[sideNext
]);
1379 gfxRGBA
cornerColor((currentColor
.r
+ nextColor
.r
) / 2.0,
1380 (currentColor
.g
+ nextColor
.g
) / 2.0,
1381 (currentColor
.b
+ nextColor
.b
) / 2.0,
1382 (currentColor
.a
+ nextColor
.a
) / 2.0);
1383 mContext
->SetColor(cornerColor
);
1387 // We'll have to keep side 0 for the color averaging on side 3.
1388 if (currentColors
[side
] && currentColors
[side
]->mNext
) {
1389 currentColors
[side
] = currentColors
[side
]->mNext
;
1393 // Now advance the color for side 0.
1394 if (currentColors
[0] && currentColors
[0]->mNext
) {
1395 currentColors
[0] = currentColors
[0]->mNext
;
1402 nsCSSBorderRenderer::DrawBorders()
1404 bool forceSeparateCorners
= false;
1406 // Examine the border style to figure out if we can draw it in one
1408 bool tlBordersSame
= AreBorderSideFinalStylesSame(SIDE_BIT_TOP
| SIDE_BIT_LEFT
);
1409 bool brBordersSame
= AreBorderSideFinalStylesSame(SIDE_BIT_BOTTOM
| SIDE_BIT_RIGHT
);
1410 bool allBordersSame
= AreBorderSideFinalStylesSame(SIDE_BITS_ALL
);
1411 if (allBordersSame
&&
1412 ((mCompositeColors
[0] == nullptr &&
1413 (mBorderStyles
[0] == NS_STYLE_BORDER_STYLE_NONE
||
1414 mBorderStyles
[0] == NS_STYLE_BORDER_STYLE_HIDDEN
||
1415 mBorderColors
[0] == NS_RGBA(0,0,0,0))) ||
1416 (mCompositeColors
[0] &&
1417 (mCompositeColors
[0]->mColor
== NS_RGBA(0,0,0,0) &&
1418 !mCompositeColors
[0]->mNext
))))
1420 // All borders are the same style, and the style is either none or hidden, or the color
1422 // This also checks if the first composite color is transparent, and there are
1423 // no others. It doesn't check if there are subsequent transparent ones, because
1424 // that would be very silly.
1428 gfxMatrix mat
= mContext
->CurrentMatrix();
1430 // Clamp the CTM to be pixel-aligned; we do this only
1431 // for translation-only matrices now, but we could do it
1432 // if the matrix has just a scale as well. We should not
1433 // do it if there's a rotation.
1434 if (mat
.HasNonTranslation()) {
1435 if (!mat
.HasNonAxisAlignedTransform()) {
1436 // Scale + transform. Avoid stroke fast-paths so that we have a chance
1437 // of snapping to pixel boundaries.
1438 mAvoidStroke
= true;
1441 mat
._31
= floor(mat
._31
+ 0.5);
1442 mat
._32
= floor(mat
._32
+ 0.5);
1443 mContext
->SetMatrix(mat
);
1445 // round mOuterRect and mInnerRect; they're already an integer
1446 // number of pixels apart and should stay that way after
1447 // rounding. We don't do this if there's a scale in the current transform
1448 // since this loses information that might be relevant when we're scaling.
1453 bool allBordersSameWidth
= AllBordersSameWidth();
1455 if (allBordersSameWidth
&& mBorderWidths
[0] == 0.0) {
1456 // Some of the allBordersSameWidth codepaths depend on the border
1457 // width being greater than zero.
1461 bool allBordersSolid
;
1463 // First there's a couple of 'special cases' that have specifically optimized
1464 // drawing paths, when none of these can be used we move on to the generalized
1465 // border drawing code.
1466 if (allBordersSame
&&
1467 mCompositeColors
[0] == nullptr &&
1468 allBordersSameWidth
&&
1469 mBorderStyles
[0] == NS_STYLE_BORDER_STYLE_SOLID
&&
1473 // Very simple case.
1474 SetupStrokeStyle(NS_SIDE_TOP
);
1475 gfxRect rect
= mOuterRect
;
1476 rect
.Deflate(mBorderWidths
[0] / 2.0);
1477 mContext
->NewPath();
1478 mContext
->Rectangle(rect
);
1483 if (allBordersSame
&&
1484 mCompositeColors
[0] == nullptr &&
1485 allBordersSameWidth
&&
1486 mBorderStyles
[0] == NS_STYLE_BORDER_STYLE_DOTTED
&&
1487 mBorderWidths
[0] < 3 &&
1491 // Very simple case. We draw this rectangular dotted borner without
1492 // antialiasing. The dots should be pixel aligned.
1493 SetupStrokeStyle(NS_SIDE_TOP
);
1495 gfxFloat dash
= mBorderWidths
[0];
1496 mContext
->SetDash(&dash
, 1, 0.5);
1497 mContext
->SetAntialiasMode(gfxContext::MODE_ALIASED
);
1498 gfxRect rect
= mOuterRect
;
1499 rect
.Deflate(mBorderWidths
[0] / 2.0);
1500 mContext
->NewPath();
1501 mContext
->Rectangle(rect
);
1507 if (allBordersSame
&&
1508 mCompositeColors
[0] == nullptr &&
1509 mBorderStyles
[0] == NS_STYLE_BORDER_STYLE_SOLID
&&
1513 // Relatively simple case.
1514 SetupStrokeStyle(NS_SIDE_TOP
);
1516 RoundedRect
borderInnerRect(mOuterRect
, mBorderRadii
);
1517 borderInnerRect
.Deflate(mBorderWidths
[NS_SIDE_TOP
],
1518 mBorderWidths
[NS_SIDE_BOTTOM
],
1519 mBorderWidths
[NS_SIDE_LEFT
],
1520 mBorderWidths
[NS_SIDE_RIGHT
]);
1522 // Instead of stroking we just use two paths: an inner and an outer.
1523 // This allows us to draw borders that we couldn't when stroking. For example,
1524 // borders with a border width >= the border radius. (i.e. when there are
1525 // square corners on the inside)
1527 // Further, this approach can be more efficient because the backend
1528 // doesn't need to compute an offset curve to stroke the path. We know that
1529 // the rounded parts are elipses we can offset exactly and can just compute
1530 // a new cubic approximation.
1531 mContext
->NewPath();
1532 mContext
->RoundedRectangle(mOuterRect
, mBorderRadii
, true);
1533 mContext
->RoundedRectangle(borderInnerRect
.rect
, borderInnerRect
.corners
, false);
1538 bool hasCompositeColors
;
1540 allBordersSolid
= AllBordersSolid(&hasCompositeColors
);
1541 // This leaves the border corners non-interpolated for single width borders.
1542 // Doing this is slightly faster and shouldn't be a problem visually.
1543 if (allBordersSolid
&&
1544 allBordersSameWidth
&&
1545 mCompositeColors
[0] == nullptr &&
1546 mBorderWidths
[0] == 1 &&
1550 DrawSingleWidthSolidBorder();
1554 if (allBordersSolid
&& !hasCompositeColors
&&
1557 DrawNoCompositeColorSolidBorder();
1561 if (allBordersSolid
&&
1562 allBordersSameWidth
&&
1566 // Easy enough to deal with.
1567 DrawRectangularCompositeColors();
1571 // If we have composite colors -and- border radius,
1572 // then use separate corners so we get OPERATOR_ADD for the corners.
1573 // Otherwise, we'll get artifacts as we draw stacked 1px-wide curves.
1574 if (allBordersSame
&& mCompositeColors
[0] != nullptr && !mNoBorderRadius
)
1575 forceSeparateCorners
= true;
1577 S(" mOuterRect: "), S(mOuterRect
), SN();
1578 S(" mInnerRect: "), S(mInnerRect
), SN();
1579 SF(" mBorderColors: 0x%08x 0x%08x 0x%08x 0x%08x\n", mBorderColors
[0], mBorderColors
[1], mBorderColors
[2], mBorderColors
[3]);
1581 // if conditioning the outside rect failed, then bail -- the outside
1582 // rect is supposed to enclose the entire border
1583 mOuterRect
.Condition();
1584 if (mOuterRect
.IsEmpty())
1587 mInnerRect
.Condition();
1588 int dashedSides
= 0;
1590 NS_FOR_CSS_SIDES(i
) {
1591 uint8_t style
= mBorderStyles
[i
];
1592 if (style
== NS_STYLE_BORDER_STYLE_DASHED
||
1593 style
== NS_STYLE_BORDER_STYLE_DOTTED
)
1595 // pretend that all borders aren't the same; we need to draw
1596 // things separately for dashed/dotting
1597 allBordersSame
= false;
1598 dashedSides
|= (1 << i
);
1602 SF(" allBordersSame: %d dashedSides: 0x%02x\n", allBordersSame
, dashedSides
);
1604 if (allBordersSame
&& !forceSeparateCorners
) {
1605 /* Draw everything in one go */
1606 DrawBorderSides(SIDE_BITS_ALL
);
1607 SN("---------------- (1)");
1609 PROFILER_LABEL("nsCSSBorderRenderer", "DrawBorders::multipass",
1610 js::ProfileEntry::Category::GRAPHICS
);
1612 /* We have more than one pass to go. Draw the corners separately from the sides. */
1615 * If we have a 1px-wide border, the corners are going to be
1616 * negligible, so don't bother doing anything fancy. Just extend
1617 * the top and bottom borders to the right 1px and the left border
1618 * to the bottom 1px. We do this by twiddling the corner dimensions,
1619 * which causes the right to happen later on. Only do this if we have
1620 * a 1.0 unit border all around and no border radius.
1623 NS_FOR_CSS_CORNERS(corner
) {
1624 const mozilla::css::Side sides
[2] = { mozilla::css::Side(corner
), PREV_SIDE(corner
) };
1626 if (!IsZeroSize(mBorderRadii
[corner
]))
1629 if (mBorderWidths
[sides
[0]] == 1.0 && mBorderWidths
[sides
[1]] == 1.0) {
1630 if (corner
== NS_CORNER_TOP_LEFT
|| corner
== NS_CORNER_TOP_RIGHT
)
1631 mBorderCornerDimensions
[corner
].width
= 0.0;
1633 mBorderCornerDimensions
[corner
].height
= 0.0;
1637 // First, the corners
1638 NS_FOR_CSS_CORNERS(corner
) {
1639 // if there's no corner, don't do all this work for it
1640 if (IsZeroSize(mBorderCornerDimensions
[corner
]))
1643 const int sides
[2] = { corner
, PREV_SIDE(corner
) };
1644 int sideBits
= (1 << sides
[0]) | (1 << sides
[1]);
1646 bool simpleCornerStyle
= mCompositeColors
[sides
[0]] == nullptr &&
1647 mCompositeColors
[sides
[1]] == nullptr &&
1648 AreBorderSideFinalStylesSame(sideBits
);
1650 // If we don't have anything complex going on in this corner,
1651 // then we can just fill the corner with a solid color, and avoid
1652 // the potentially expensive clip.
1653 if (simpleCornerStyle
&&
1654 IsZeroSize(mBorderRadii
[corner
]) &&
1655 IsSolidCornerStyle(mBorderStyles
[sides
[0]], corner
))
1657 mContext
->NewPath();
1658 DoCornerSubPath(corner
);
1659 mContext
->SetColor(MakeBorderColor(mBorderColors
[sides
[0]],
1661 BorderColorStyleForSolidCorner(mBorderStyles
[sides
[0]], corner
)));
1668 // clip to the corner
1669 mContext
->NewPath();
1670 DoCornerSubPath(corner
);
1673 if (simpleCornerStyle
) {
1674 // we don't need a group for this corner, the sides are the same,
1675 // but we weren't able to render just a solid block for the corner.
1676 DrawBorderSides(sideBits
);
1678 // Sides are different. We could draw using OPERATOR_ADD to
1679 // get correct color blending behaviour at the seam. We'd need
1680 // to do it in an offscreen surface to ensure that we're
1681 // always compositing on transparent black. If the colors
1682 // don't have transparency and the current destination surface
1683 // has an alpha channel, we could just clear the region and
1684 // avoid the temporary, but that situation doesn't happen all
1685 // that often in practice (we double buffer to no-alpha
1686 // surfaces). We choose just to seam though, as the performance
1687 // advantages outway the modest easthetic improvement.
1689 for (int cornerSide
= 0; cornerSide
< 2; cornerSide
++) {
1690 mozilla::css::Side side
= mozilla::css::Side(sides
[cornerSide
]);
1691 uint8_t style
= mBorderStyles
[side
];
1693 SF("corner: %d cornerSide: %d side: %d style: %d\n", corner
, cornerSide
, side
, style
);
1697 mContext
->NewPath();
1698 DoSideClipSubPath(side
);
1701 DrawBorderSides(1 << side
);
1703 mContext
->Restore();
1707 mContext
->Restore();
1712 // in the case of a single-unit border, we already munged the
1713 // corners up above; so we can just draw the top left and bottom
1714 // right sides separately, if they're the same.
1716 // We need to check for mNoBorderRadius, because when there is
1717 // one, FillSolidBorder always draws the full rounded rectangle
1718 // and expects there to be a clip in place.
1719 int alreadyDrawnSides
= 0;
1720 if (mOneUnitBorder
&&
1722 (dashedSides
& (SIDE_BIT_TOP
| SIDE_BIT_LEFT
)) == 0)
1724 if (tlBordersSame
) {
1725 DrawBorderSides(SIDE_BIT_TOP
| SIDE_BIT_LEFT
);
1726 alreadyDrawnSides
|= (SIDE_BIT_TOP
| SIDE_BIT_LEFT
);
1729 if (brBordersSame
&& (dashedSides
& (SIDE_BIT_BOTTOM
| SIDE_BIT_RIGHT
)) == 0) {
1730 DrawBorderSides(SIDE_BIT_BOTTOM
| SIDE_BIT_RIGHT
);
1731 alreadyDrawnSides
|= (SIDE_BIT_BOTTOM
| SIDE_BIT_RIGHT
);
1735 // We're done with the corners, now draw the sides.
1736 NS_FOR_CSS_SIDES (side
) {
1737 // if we drew it above, skip it
1738 if (alreadyDrawnSides
& (1 << side
))
1741 // If there's no border on this side, skip it
1742 if (mBorderWidths
[side
] == 0.0 ||
1743 mBorderStyles
[side
] == NS_STYLE_BORDER_STYLE_HIDDEN
||
1744 mBorderStyles
[side
] == NS_STYLE_BORDER_STYLE_NONE
)
1748 if (dashedSides
& (1 << side
)) {
1749 // Dashed sides will always draw just the part ignoring the
1750 // corners for the side, so no need to clip.
1751 DrawDashedSide (side
);
1753 SN("---------------- (d)");
1757 // Undashed sides will currently draw the entire side,
1758 // including parts that would normally be covered by a corner,
1759 // so we need to clip.
1761 // XXX Optimization -- it would be good to make this work like
1762 // DrawDashedSide, and have a DrawOneSide function that just
1763 // draws one side and not the corners, because then we can
1764 // avoid the potentially expensive clip.
1766 mContext
->NewPath();
1767 DoSideClipWithoutCornersSubPath(side
);
1770 DrawBorderSides(1 << side
);
1772 mContext
->Restore();
1774 SN("---------------- (*)");