Bug 1135913, part 1 - Simplify nsCSSRendering::DecorationLineToPath to not require a context. r=heycam

This commit is contained in:
Jonathan Watt
2015-02-03 14:34:14 +00:00
parent dc805bc148
commit 88f6fa366d
3 changed files with 37 additions and 41 deletions

View File

@@ -4348,59 +4348,56 @@ nsCSSRendering::PaintDecorationLine(nsIFrame* aFrame,
} }
} }
void Rect
nsCSSRendering::DecorationLineToPath(nsIFrame* aFrame, nsCSSRendering::DecorationLineToPath(const Rect& aDirtyRect,
gfxContext* aGfxContext, const Point& aPt,
const gfxRect& aDirtyRect, const Size& aLineSize,
const nscolor aColor, const Float aAscent,
const gfxPoint& aPt, const Float aOffset,
const gfxFloat aICoordInFrame,
const gfxSize& aLineSize,
const gfxFloat aAscent,
const gfxFloat aOffset,
const uint8_t aDecoration, const uint8_t aDecoration,
const uint8_t aStyle, const uint8_t aStyle,
bool aVertical, bool aVertical,
const gfxFloat aDescentLimit) const Float aDescentLimit)
{ {
NS_ASSERTION(aStyle != NS_STYLE_TEXT_DECORATION_STYLE_NONE, "aStyle is none"); NS_ASSERTION(aStyle != NS_STYLE_TEXT_DECORATION_STYLE_NONE, "aStyle is none");
aGfxContext->NewPath(); Rect path; // To benefit from RVO, we return this from all return points
gfxRect rect = Rect rect = ToRect(
GetTextDecorationRectInternal(aPt, aLineSize, aAscent, aOffset, GetTextDecorationRectInternal(ThebesPoint(aPt), ThebesSize(aLineSize),
aAscent, aOffset,
aDecoration, aStyle, aVertical, aDecoration, aStyle, aVertical,
aDescentLimit); aDescentLimit));
if (rect.IsEmpty() || !rect.Intersects(aDirtyRect)) { if (rect.IsEmpty() || !rect.Intersects(aDirtyRect)) {
return; return path;
} }
if (aDecoration != NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE && if (aDecoration != NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE &&
aDecoration != NS_STYLE_TEXT_DECORATION_LINE_OVERLINE && aDecoration != NS_STYLE_TEXT_DECORATION_LINE_OVERLINE &&
aDecoration != NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH) { aDecoration != NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH) {
NS_ERROR("Invalid decoration value!"); NS_ERROR("Invalid decoration value!");
return; return path;
} }
if (aStyle != NS_STYLE_TEXT_DECORATION_STYLE_SOLID) { if (aStyle != NS_STYLE_TEXT_DECORATION_STYLE_SOLID) {
// For the moment, we support only solid text decorations. // For the moment, we support only solid text decorations.
return; return path;
} }
gfxFloat lineThickness = std::max(NS_round(aLineSize.height), 1.0); Float lineThickness = std::max(NS_round(aLineSize.height), 1.0);
// The block-direction position should be set to the middle of the line. // The block-direction position should be set to the middle of the line.
if (aVertical) { if (aVertical) {
rect.x += lineThickness / 2; rect.x += lineThickness / 2;
aGfxContext->Rectangle path = Rect(rect.TopLeft() - Point(lineThickness / 2, 0.0),
(gfxRect(gfxPoint(rect.TopLeft() - gfxPoint(lineThickness / 2, 0.0)), Size(lineThickness, rect.Height()));
gfxSize(lineThickness, rect.Height())));
} else { } else {
rect.y += lineThickness / 2; rect.y += lineThickness / 2;
aGfxContext->Rectangle path = Rect(rect.TopLeft() - Point(0.0, lineThickness / 2),
(gfxRect(gfxPoint(rect.TopLeft() - gfxPoint(0.0, lineThickness / 2)), Size(rect.Width(), lineThickness));
gfxSize(rect.Width(), lineThickness)));
} }
return path;
} }
nsRect nsRect

View File

@@ -321,7 +321,9 @@ struct nsBackgroundLayerState {
struct nsCSSRendering { struct nsCSSRendering {
typedef mozilla::gfx::DrawTarget DrawTarget; typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::gfx::Float Float; typedef mozilla::gfx::Float Float;
typedef mozilla::gfx::Point Point;
typedef mozilla::gfx::Rect Rect; typedef mozilla::gfx::Rect Rect;
typedef mozilla::gfx::Size Size;
typedef mozilla::gfx::RectCornerRadii RectCornerRadii; typedef mozilla::gfx::RectCornerRadii RectCornerRadii;
typedef mozilla::image::DrawResult DrawResult; typedef mozilla::image::DrawResult DrawResult;
typedef nsIFrame::Sides Sides; typedef nsIFrame::Sides Sides;
@@ -684,25 +686,20 @@ struct nsCSSRendering {
const gfxFloat aDescentLimit = -1.0); const gfxFloat aDescentLimit = -1.0);
/** /**
* Adds a path corresponding to the outline of the decoration line to * Returns a Rect corresponding to the outline of the decoration line for the
* the specified context. Arguments have the same meaning as for * given text metrics. Arguments have the same meaning as for
* PaintDecorationLine. Currently this only works for solid * PaintDecorationLine. Currently this only works for solid
* decorations; for other decoration styles, an empty path is added * decorations; for other decoration styles the returned Rect will be empty.
* to the context.
*/ */
static void DecorationLineToPath(nsIFrame* aFrame, static Rect DecorationLineToPath(const Rect& aDirtyRect,
gfxContext* aGfxContext, const Point& aPt,
const gfxRect& aDirtyRect, const Size& aLineSize,
const nscolor aColor, const Float aAscent,
const gfxPoint& aPt, const Float aOffset,
const gfxFloat aICoordInFrame,
const gfxSize& aLineSize,
const gfxFloat aAscent,
const gfxFloat aOffset,
const uint8_t aDecoration, const uint8_t aDecoration,
const uint8_t aStyle, const uint8_t aStyle,
bool aVertical, bool aVertical,
const gfxFloat aDescentLimit = -1.0); const Float aDescentLimit = -1.0);
/** /**
* Function for getting the decoration line rect for the text. * Function for getting the decoration line rect for the text.

View File

@@ -5234,9 +5234,11 @@ PaintDecorationLine(nsIFrame* aFrame,
} else { } else {
aCallbacks->NotifyBeforeSelectionDecorationLine(lineColor); aCallbacks->NotifyBeforeSelectionDecorationLine(lineColor);
} }
nsCSSRendering::DecorationLineToPath(aFrame, aCtx, aDirtyRect, lineColor, Rect path = nsCSSRendering::DecorationLineToPath(ToRect(aDirtyRect),
aPt, aICoordInFrame, aLineSize, aAscent, aOffset, aDecoration, aStyle, ToPoint(aPt), ToSize(aLineSize), aAscent, aOffset, aDecoration, aStyle,
aVertical, aDescentLimit); aVertical, aDescentLimit);
aCtx->NewPath();
aCtx->Rectangle(ThebesRect(path));
if (aDecorationType == eNormalDecoration) { if (aDecorationType == eNormalDecoration) {
aCallbacks->NotifyDecorationLinePathEmitted(); aCallbacks->NotifyDecorationLinePathEmitted();
} else { } else {