--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -4797,18 +4797,26 @@ nsDisplayText::Paint(nsDisplayListBuilde
gfxMatrix mat = ctx->CurrentMatrix()
.Translate(pt).Scale(scaleFactor, 1.0).Translate(-pt);
ctx->SetMatrix(mat);
}
}
nsTextFrame::PaintTextParams params(aCtx->ThebesContext());
params.framePt = gfxPoint(framePt.x, framePt.y);
params.dirtyRect = extraVisible;
- params.generateTextMask = aBuilder->IsForGenerateGlyphMask();
- params.paintSelectionBackground = aBuilder->IsForPaintingSelectionBG();
+
+ if (aBuilder->IsForGenerateGlyphMask()) {
+ MOZ_ASSERT(!aBuilder->IsForPaintingSelectionBG());
+ params.state = nsTextFrame::PaintTextParams::GenerateTextMask;
+ } else if (aBuilder->IsForPaintingSelectionBG()) {
+ params.state = nsTextFrame::PaintTextParams::PaintTextBGColor;
+ } else {
+ params.state = nsTextFrame::PaintTextParams::PaintText;
+ }
+
f->PaintText(params, *this, mOpacity);
}
void
nsTextFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists)
{
@@ -5998,18 +6006,17 @@ nsTextFrame::PaintTextWithSelectionColor
bool vertical = mTextRun->IsVertical();
const gfxFloat startIOffset = vertical ?
aParams.textBaselinePt.y - aParams.framePt.y :
aParams.textBaselinePt.x - aParams.framePt.x;
gfxFloat iOffset, hyphenWidth;
Range range; // in transformed string
TextRangeStyle rangeStyle;
// Draw background colors
- if (anyBackgrounds && (!aParams.generateTextMask ||
- aParams.paintSelectionBackground)) {
+ if (anyBackgrounds && !aParams.IsGenerateTextMask()) {
int32_t appUnitsPerDevPixel =
aParams.textPaintStyle->PresContext()->AppUnitsPerDevPixel();
SelectionIterator iterator(prevailingSelections, contentRange,
*aParams.provider, mTextRun, startIOffset);
SelectionType selectionType;
while (iterator.GetNextSegment(&iOffset, &range, &hyphenWidth,
&selectionType, &rangeStyle)) {
nscolor foreground, background;
@@ -6032,17 +6039,17 @@ nsTextFrame::PaintTextWithSelectionColor
*aParams.context->GetDrawTarget(), background, aParams.dirtyRect,
LayoutDeviceRect::FromAppUnits(bgRect, appUnitsPerDevPixel),
aParams.callbacks);
}
iterator.UpdateWithAdvance(advance);
}
}
- if (aParams.paintSelectionBackground) {
+ if (aParams.IsPaintBGColor()) {
return true;
}
gfxFloat advance;
DrawTextParams params(aParams.context);
params.dirtyRect = aParams.dirtyRect;
params.framePt = aParams.framePt;
params.provider = aParams.provider;
@@ -6058,17 +6065,17 @@ nsTextFrame::PaintTextWithSelectionColor
// Draw text
const nsStyleText* textStyle = StyleText();
SelectionIterator iterator(prevailingSelections, contentRange,
*aParams.provider, mTextRun, startIOffset);
SelectionType selectionType;
while (iterator.GetNextSegment(&iOffset, &range, &hyphenWidth,
&selectionType, &rangeStyle)) {
nscolor foreground, background;
- if (aParams.generateTextMask) {
+ if (aParams.IsGenerateTextMask()) {
foreground = NS_RGBA(0, 0, 0, 255);
} else {
GetSelectionTextColors(selectionType, *aParams.textPaintStyle,
rangeStyle, &foreground, &background);
}
gfxPoint textBaselinePt = vertical ?
gfxPoint(aParams.textBaselinePt.x, aParams.framePt.y + iOffset) :
@@ -6591,57 +6598,56 @@ nsTextFrame::PaintText(const PaintTextPa
}
nsCharClipDisplayItem::ClipEdges clipEdges(aItem, snappedStartEdge,
snappedEndEdge);
nsTextPaintStyle textPaintStyle(this);
textPaintStyle.SetResolveColors(!aParams.callbacks);
// Fork off to the (slower) paint-with-selection path if necessary.
if (aItem.mIsFrameSelected.value() &&
- (aParams.paintSelectionBackground ||
- ShouldDrawSelection(this->GetParent()))) {
+ (aParams.IsPaintBGColor() || ShouldDrawSelection(this->GetParent()))) {
MOZ_ASSERT(aOpacity == 1.0f, "We don't support opacity with selections!");
gfxSkipCharsIterator tmp(provider.GetStart());
Range contentRange(
uint32_t(tmp.ConvertSkippedToOriginal(startOffset)),
uint32_t(tmp.ConvertSkippedToOriginal(startOffset + maxLength)));
PaintTextSelectionParams params(aParams);
params.textBaselinePt = textBaselinePt;
params.provider = &provider;
params.contentRange = contentRange;
params.textPaintStyle = &textPaintStyle;
if (PaintTextWithSelection(params, clipEdges)) {
return;
}
}
- if (aParams.paintSelectionBackground) {
+ if (aParams.IsPaintBGColor()) {
return;
}
- nscolor foregroundColor = aParams.generateTextMask
+ nscolor foregroundColor = aParams.IsGenerateTextMask()
? NS_RGBA(0, 0, 0, 255)
: textPaintStyle.GetTextColor();
if (aOpacity != 1.0f) {
gfx::Color gfxColor = gfx::Color::FromABGR(foregroundColor);
gfxColor.a *= aOpacity;
foregroundColor = gfxColor.ToABGR();
}
- nscolor textStrokeColor = aParams.generateTextMask
+ nscolor textStrokeColor = aParams.IsGenerateTextMask()
? NS_RGBA(0, 0, 0, 255)
: textPaintStyle.GetWebkitTextStrokeColor();
if (aOpacity != 1.0f) {
gfx::Color gfxColor = gfx::Color::FromABGR(textStrokeColor);
gfxColor.a *= aOpacity;
textStrokeColor = gfxColor.ToABGR();
}
range = Range(startOffset, startOffset + maxLength);
- if (!aParams.callbacks && !aParams.generateTextMask) {
+ if (!aParams.callbacks && aParams.IsPaintText()) {
const nsStyleText* textStyle = StyleText();
PaintShadowParams shadowParams(aParams);
shadowParams.range = range;
shadowParams.textBaselinePt = textBaselinePt;
shadowParams.leftSideOffset = snappedStartEdge;
shadowParams.provider = &provider;
shadowParams.foregroundColor = foregroundColor;
shadowParams.clipEdges = &clipEdges;
--- a/layout/generic/nsTextFrame.h
+++ b/layout/generic/nsTextFrame.h
@@ -390,19 +390,31 @@ public:
struct PaintTextParams
{
gfxContext* context;
gfxPoint framePt;
LayoutDeviceRect dirtyRect;
gfxTextContextPaint* contextPaint = nullptr;
DrawPathCallbacks* callbacks = nullptr;
- bool generateTextMask = false;
- bool paintSelectionBackground = false;
+ enum {
+ PaintText, // Normal text painting.
+ PaintTextBGColor, // Only paint background color of the selected text
+ // range in this state.
+ GenerateTextMask // To generate a mask from a text frame. Should
+ // only paint text itself with opaque color.
+ // Text shadow, text selection color and text
+ // decoration are all discarded in this state.
+ };
+ uint8_t state = PaintText;
explicit PaintTextParams(gfxContext* aContext) : context(aContext) {}
+
+ bool IsPaintText() const { return state == PaintText; }
+ bool IsGenerateTextMask() const { return state == GenerateTextMask; }
+ bool IsPaintBGColor() const { return state == PaintTextBGColor; }
};
struct PaintTextSelectionParams : PaintTextParams
{
gfxPoint textBaselinePt;
PropertyProvider* provider = nullptr;
Range contentRange;
nsTextPaintStyle* textPaintStyle = nullptr;