Bug 1251995 part 5 - Unify units of dirty rect used for painting text frame. r=jfkthame

MozReview-Commit-ID: BK7j6y7lBV3

--HG--
extra : source : 4403438493793ddfa7356cab2438d050f8a66da1
This commit is contained in:
Xidorn Quan 2016-03-08 15:56:18 +08:00
Родитель 8ade98d572
Коммит e1002ffcb3
3 изменённых файлов: 55 добавлений и 78 удалений

Просмотреть файл

@ -143,21 +143,6 @@ struct TabwidthAdaptor
}
};
/**
* Helper that is useful to help port the code is this file to typed rects.
* The code here is particularly horrible because it uses gfxRect to
* store app unit values (because we want fractional app unit values), but
* virtually everywhere else gfxRect is in device pixels. :-/
*/
LayoutDeviceRect AppUnitGfxRectToDevRect(gfxRect aRect,
int32_t aAppUnitsPerDevPixel)
{
return LayoutDeviceRect(aRect.x / aAppUnitsPerDevPixel,
aRect.y / aAppUnitsPerDevPixel,
aRect.width / aAppUnitsPerDevPixel,
aRect.height / aAppUnitsPerDevPixel);
}
} // namespace
void
@ -4799,9 +4784,9 @@ nsDisplayText::Paint(nsDisplayListBuilder* aBuilder,
// Add 1 pixel of dirty area around mVisibleRect to allow us to paint
// antialiased pixels beyond the measured text extents.
// This is temporary until we do this in the actual calculation of text extents.
nsRect extraVisible = mVisibleRect;
nscoord appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
extraVisible.Inflate(appUnitsPerDevPixel, appUnitsPerDevPixel);
LayoutDeviceRect extraVisible = LayoutDeviceRect::FromAppUnits(
mVisibleRect, mFrame->PresContext()->AppUnitsPerDevPixel());
extraVisible.Inflate(1);
nsTextFrame* f = static_cast<nsTextFrame*>(mFrame);
DrawTargetAutoDisableSubpixelAntialiasing disable(aCtx->GetDrawTarget(),
@ -4809,8 +4794,8 @@ nsDisplayText::Paint(nsDisplayListBuilder* aBuilder,
gfxContext* ctx = aCtx->ThebesContext();
gfxContextAutoSaveRestore save(ctx);
gfxRect pixelVisible =
nsLayoutUtils::RectToGfxRect(extraVisible, appUnitsPerDevPixel);
gfxRect pixelVisible(extraVisible.x, extraVisible.y,
extraVisible.width, extraVisible.height);
pixelVisible.Inflate(2);
pixelVisible.RoundOut();
@ -5480,7 +5465,7 @@ nsTextFrame::ComputeSelectionUnderlineHeight(
void
nsTextFrame::PaintDecorationLine(gfxContext* const aCtx,
const gfxRect& aDirtyRect,
const LayoutDeviceRect& aDirtyRect,
nscolor aColor,
const nscolor* aOverrideColor,
const Point& aPt,
@ -5497,17 +5482,17 @@ nsTextFrame::PaintDecorationLine(gfxContext* const aCtx,
{
nscolor lineColor = aOverrideColor ? *aOverrideColor : aColor;
if (aCallbacks) {
Rect path = nsCSSRendering::DecorationLineToPath(ToRect(aDirtyRect),
aPt, aLineSize, aAscent, aOffset, aDecoration, aStyle,
aVertical, aDescentLimit);
Rect path = nsCSSRendering::DecorationLineToPath(
aDirtyRect.ToUnknownRect(), aPt, aLineSize, aAscent,
aOffset, aDecoration, aStyle, aVertical, aDescentLimit);
if (aDecorationType == eNormalDecoration) {
aCallbacks->PaintDecorationLine(path, lineColor);
} else {
aCallbacks->PaintSelectionDecorationLine(path, lineColor);
}
} else {
nsCSSRendering::PaintDecorationLine(this, *aCtx->GetDrawTarget(),
ToRect(aDirtyRect), lineColor,
nsCSSRendering::PaintDecorationLine(
this, *aCtx->GetDrawTarget(), aDirtyRect.ToUnknownRect(), lineColor,
aPt, Float(aICoordInFrame), aLineSize, aAscent, aOffset, aDecoration, aStyle,
aVertical, aDescentLimit);
}
@ -5519,7 +5504,7 @@ nsTextFrame::PaintDecorationLine(gfxContext* const aCtx,
*/
void
nsTextFrame::DrawSelectionDecorations(gfxContext* aContext,
const gfxRect& aDirtyRect,
const LayoutDeviceRect& aDirtyRect,
SelectionType aType,
nsTextPaintStyle& aTextPaintStyle,
const TextRangeStyle &aRangeStyle,
@ -5849,7 +5834,8 @@ AddHyphenToMetrics(nsTextFrame* aTextFrame, gfxTextRun* aBaseTextRun,
void
nsTextFrame::PaintOneShadow(Range aRange,
nsCSSShadowItem* aShadowDetails,
PropertyProvider* aProvider, const nsRect& aDirtyRect,
PropertyProvider* aProvider,
const LayoutDeviceRect& aDirtyRect,
const gfxPoint& aFramePt, const gfxPoint& aTextBaselinePt,
gfxContext* aCtx, const nscolor& aForegroundColor,
const nsCharClipDisplayItem::ClipEdges& aClipEdges,
@ -5890,10 +5876,10 @@ nsTextFrame::PaintOneShadow(Range aRange,
NSToCoordRound(shadowGfxRect.Height()));
nsContextBoxBlur contextBoxBlur;
gfxContext* shadowContext = contextBoxBlur.Init(shadowRect, 0, blurRadius,
PresContext()->AppUnitsPerDevPixel(),
aCtx, aDirtyRect, nullptr,
aBlurFlags);
const auto A2D = PresContext()->AppUnitsPerDevPixel();
gfxContext* shadowContext = contextBoxBlur.Init(
shadowRect, 0, blurRadius, A2D, aCtx,
LayoutDevicePixel::ToAppUnits(aDirtyRect, A2D), nullptr, aBlurFlags);
if (!shadowContext)
return;
@ -5918,8 +5904,7 @@ nsTextFrame::PaintOneShadow(Range aRange,
nsTextPaintStyle textPaintStyle(this);
DrawTextParams params(shadowContext);
params.advanceWidth = &advanceWidth;
params.dirtyRect = gfxRect(aDirtyRect.x, aDirtyRect.y,
aDirtyRect.width, aDirtyRect.height);
params.dirtyRect = aDirtyRect;
params.framePt = aFramePt + shadowOffset;
params.provider = aProvider;
params.textStyle = &textPaintStyle;
@ -5938,7 +5923,7 @@ nsTextFrame::PaintOneShadow(Range aRange,
bool
nsTextFrame::PaintTextWithSelectionColors(gfxContext* aCtx,
const gfxPoint& aFramePt, const gfxPoint& aTextBaselinePt,
const gfxRect& aDirtyRect,
const LayoutDeviceRect& aDirtyRect,
PropertyProvider& aProvider,
Range aContentRange,
nsTextPaintStyle& aTextPaintStyle, SelectionDetails* aDetails,
@ -6003,7 +5988,6 @@ nsTextFrame::PaintTextWithSelectionColors(gfxContext* aCtx,
// Draw background colors
if (anyBackgrounds) {
int32_t appUnitsPerDevPixel = aTextPaintStyle.PresContext()->AppUnitsPerDevPixel();
LayoutDeviceRect dirtyRect = AppUnitGfxRectToDevRect(aDirtyRect, appUnitsPerDevPixel);
SelectionIterator iterator(prevailingSelections, aContentRange,
aProvider, mTextRun, startIOffset);
while (iterator.GetNextSegment(&iOffset, &range, &hyphenWidth,
@ -6015,18 +5999,19 @@ nsTextFrame::PaintTextWithSelectionColors(gfxContext* aCtx,
gfxFloat advance = hyphenWidth +
mTextRun->GetAdvanceWidth(range, &aProvider);
if (NS_GET_A(background) > 0) {
gfxRect bgRect;
nsRect bgRect;
gfxFloat offs = iOffset - (mTextRun->IsInlineReversed() ? advance : 0);
if (vertical) {
bgRect = gfxRect(aFramePt.x, aFramePt.y + offs,
GetSize().width, advance);
bgRect = nsRect(aFramePt.x, aFramePt.y + offs,
GetSize().width, advance);
} else {
bgRect = gfxRect(aFramePt.x + offs, aFramePt.y,
advance, GetSize().height);
bgRect = nsRect(aFramePt.x + offs, aFramePt.y,
advance, GetSize().height);
}
PaintSelectionBackground(*aCtx->GetDrawTarget(), background, dirtyRect,
AppUnitGfxRectToDevRect(bgRect, appUnitsPerDevPixel),
aCallbacks);
PaintSelectionBackground(
*aCtx->GetDrawTarget(), background, aDirtyRect,
LayoutDeviceRect::FromAppUnits(bgRect, appUnitsPerDevPixel),
aCallbacks);
}
iterator.UpdateWithAdvance(advance);
}
@ -6044,8 +6029,6 @@ nsTextFrame::PaintTextWithSelectionColors(gfxContext* aCtx,
// Draw text
const nsStyleText* textStyle = StyleText();
nsRect dirtyRect(aDirtyRect.x, aDirtyRect.y,
aDirtyRect.width, aDirtyRect.height);
SelectionIterator iterator(prevailingSelections, aContentRange,
aProvider, mTextRun, startIOffset);
while (iterator.GetNextSegment(&iOffset, &range, &hyphenWidth,
@ -6067,7 +6050,7 @@ nsTextFrame::PaintTextWithSelectionColors(gfxContext* aCtx,
startEdge -= hyphenWidth +
mTextRun->GetAdvanceWidth(range, &aProvider);
}
PaintShadows(shadow, range, dirtyRect, aFramePt, textBaselinePt,
PaintShadows(shadow, range, aDirtyRect, aFramePt, textBaselinePt,
startEdge, aProvider, foreground, aClipEdges, aCtx);
}
@ -6084,7 +6067,7 @@ nsTextFrame::PaintTextWithSelectionColors(gfxContext* aCtx,
void
nsTextFrame::PaintTextSelectionDecorations(gfxContext* aCtx,
const gfxPoint& aFramePt,
const gfxPoint& aTextBaselinePt, const gfxRect& aDirtyRect,
const gfxPoint& aTextBaselinePt, const LayoutDeviceRect& aDirtyRect,
PropertyProvider& aProvider, Range aContentRange,
nsTextPaintStyle& aTextPaintStyle, SelectionDetails* aDetails,
SelectionType aSelectionType,
@ -6149,8 +6132,6 @@ nsTextFrame::PaintTextSelectionDecorations(gfxContext* aCtx,
} else {
pt.y = (aTextBaselinePt.y - mAscent) / app;
}
gfxRect dirtyRect(aDirtyRect.x / app, aDirtyRect.y / app,
aDirtyRect.width / app, aDirtyRect.height / app);
gfxFloat decorationOffsetDir = mTextRun->IsSidewaysLeft() ? -1.0 : 1.0;
SelectionType type;
TextRangeStyle selectedStyle;
@ -6168,7 +6149,7 @@ nsTextFrame::PaintTextSelectionDecorations(gfxContext* aCtx,
}
gfxFloat width = Abs(advance) / app;
gfxFloat xInFrame = pt.x - (aFramePt.x / app);
DrawSelectionDecorations(aCtx, dirtyRect, aSelectionType,
DrawSelectionDecorations(aCtx, aDirtyRect, aSelectionType,
aTextPaintStyle, selectedStyle, pt, xInFrame,
width, mAscent / app, decorationMetrics,
aCallbacks, verticalRun, decorationOffsetDir,
@ -6181,7 +6162,7 @@ nsTextFrame::PaintTextSelectionDecorations(gfxContext* aCtx,
bool
nsTextFrame::PaintTextWithSelection(gfxContext* aCtx,
const gfxPoint& aFramePt,
const gfxPoint& aTextBaselinePt, const gfxRect& aDirtyRect,
const gfxPoint& aTextBaselinePt, const LayoutDeviceRect& aDirtyRect,
PropertyProvider& aProvider,
Range aContentRange,
nsTextPaintStyle& aTextPaintStyle,
@ -6430,7 +6411,7 @@ nsTextFrame::MeasureCharClippedText(PropertyProvider& aProvider,
void
nsTextFrame::PaintShadows(nsCSSShadowArray* aShadow,
Range aRange,
const nsRect& aDirtyRect,
const LayoutDeviceRect& aDirtyRect,
const gfxPoint& aFramePt,
const gfxPoint& aTextBaselinePt,
nscoord aLeftEdgeOffset,
@ -6490,7 +6471,7 @@ nsTextFrame::PaintShadows(nsCSSShadowArray* aShadow,
void
nsTextFrame::PaintText(nsRenderingContext* aRenderingContext, nsPoint aPt,
const nsRect& aDirtyRect,
const LayoutDeviceRect& aDirtyRect,
const nsCharClipDisplayItem& aItem,
gfxTextContextPaint* aContextPaint,
nsTextFrame::DrawPathCallbacks* aCallbacks,
@ -6551,8 +6532,6 @@ nsTextFrame::PaintText(nsRenderingContext* aRenderingContext, nsPoint aPt,
nsTextPaintStyle textPaintStyle(this);
textPaintStyle.SetResolveColors(!aCallbacks);
gfxRect dirtyRect(aDirtyRect.x, aDirtyRect.y,
aDirtyRect.width, aDirtyRect.height);
// Fork off to the (slower) paint-with-selection path if necessary.
if (aItem.mIsFrameSelected.value()) {
MOZ_ASSERT(aOpacity == 1.0f, "We don't support opacity with selections!");
@ -6560,7 +6539,7 @@ nsTextFrame::PaintText(nsRenderingContext* aRenderingContext, nsPoint aPt,
Range contentRange(
uint32_t(tmp.ConvertSkippedToOriginal(startOffset)),
uint32_t(tmp.ConvertSkippedToOriginal(startOffset + maxLength)));
if (PaintTextWithSelection(ctx, framePt, textBaselinePt, dirtyRect,
if (PaintTextWithSelection(ctx, framePt, textBaselinePt, aDirtyRect,
provider, contentRange, textPaintStyle,
clipEdges, aContextPaint, aCallbacks)) {
return;
@ -6584,7 +6563,7 @@ nsTextFrame::PaintText(nsRenderingContext* aRenderingContext, nsPoint aPt,
gfxFloat advanceWidth;
DrawTextParams params(ctx);
params.dirtyRect = dirtyRect;
params.dirtyRect = aDirtyRect;
params.framePt = framePt;
params.provider = &provider;
params.advanceWidth = &advanceWidth;
@ -6694,11 +6673,6 @@ nsTextFrame::DrawTextRunAndDecorations(Range aRange,
ascent = -ascent;
}
gfxRect dirtyRect(aParams.dirtyRect.x / app,
aParams.dirtyRect.y / app,
aParams.dirtyRect.Width() / app,
aParams.dirtyRect.Height() / app);
nscoord inflationMinFontSize =
nsLayoutUtils::InflationMinFontSizeFor(this);
@ -6722,7 +6696,7 @@ nsTextFrame::DrawTextRunAndDecorations(Range aRange,
decSize.height = metrics.underlineSize;
bCoord = (frameBStart - dec.mBaselineOffset) / app;
PaintDecorationLine(aParams.context, dirtyRect, dec.mColor,
PaintDecorationLine(aParams.context, aParams.dirtyRect, dec.mColor,
aParams.decorationOverrideColor, decPt, 0.0, decSize, ascent,
decorationOffsetDir * metrics.underlineOffset,
NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE,
@ -6744,7 +6718,7 @@ nsTextFrame::DrawTextRunAndDecorations(Range aRange,
decSize.height = metrics.underlineSize;
bCoord = (frameBStart - dec.mBaselineOffset) / app;
PaintDecorationLine(aParams.context, dirtyRect, dec.mColor,
PaintDecorationLine(aParams.context, aParams.dirtyRect, dec.mColor,
aParams.decorationOverrideColor, decPt, 0.0, decSize, ascent,
decorationOffsetDir * metrics.maxAscent,
NS_STYLE_TEXT_DECORATION_LINE_OVERLINE, dec.mStyle,
@ -6775,7 +6749,7 @@ nsTextFrame::DrawTextRunAndDecorations(Range aRange,
decSize.height = metrics.strikeoutSize;
bCoord = (frameBStart - dec.mBaselineOffset) / app;
PaintDecorationLine(aParams.context, dirtyRect, dec.mColor,
PaintDecorationLine(aParams.context, aParams.dirtyRect, dec.mColor,
aParams.decorationOverrideColor, decPt, 0.0, decSize, ascent,
decorationOffsetDir * metrics.strikeoutOffset,
NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH,

Просмотреть файл

@ -40,6 +40,7 @@ public:
};
class nsTextFrame : public nsTextFrameBase {
typedef mozilla::LayoutDeviceRect LayoutDeviceRect;
typedef mozilla::TextRangeStyle TextRangeStyle;
typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::gfx::Point Point;
@ -406,7 +407,7 @@ public:
struct DrawTextParams : DrawTextRunParams
{
gfxPoint framePt;
gfxRect dirtyRect;
LayoutDeviceRect dirtyRect;
const nsTextPaintStyle* textStyle = nullptr;
const nsCharClipDisplayItem::ClipEdges* clipEdges = nullptr;
const nscolor* decorationOverrideColor = nullptr;
@ -419,7 +420,8 @@ public:
// object. The private DrawText() is what applies the text to a graphics
// context.
void PaintText(nsRenderingContext* aRenderingContext, nsPoint aPt,
const nsRect& aDirtyRect, const nsCharClipDisplayItem& aItem,
const LayoutDeviceRect& aDirtyRect,
const nsCharClipDisplayItem& aItem,
gfxTextContextPaint* aContextPaint = nullptr,
DrawPathCallbacks* aCallbacks = nullptr,
float aOpacity = 1.0f);
@ -429,7 +431,7 @@ public:
bool PaintTextWithSelection(gfxContext* aCtx,
const gfxPoint& aFramePt,
const gfxPoint& aTextBaselinePt,
const gfxRect& aDirtyRect,
const LayoutDeviceRect& aDirtyRect,
PropertyProvider& aProvider,
Range aRange,
nsTextPaintStyle& aTextPaintStyle,
@ -444,7 +446,7 @@ public:
bool PaintTextWithSelectionColors(gfxContext* aCtx,
const gfxPoint& aFramePt,
const gfxPoint& aTextBaselinePt,
const gfxRect& aDirtyRect,
const LayoutDeviceRect& aDirtyRect,
PropertyProvider& aProvider,
Range aContentRange,
nsTextPaintStyle& aTextPaintStyle,
@ -456,7 +458,7 @@ public:
void PaintTextSelectionDecorations(gfxContext* aCtx,
const gfxPoint& aFramePt,
const gfxPoint& aTextBaselinePt,
const gfxRect& aDirtyRect,
const LayoutDeviceRect& aDirtyRect,
PropertyProvider& aProvider,
Range aContentRange,
nsTextPaintStyle& aTextPaintStyle,
@ -623,7 +625,7 @@ protected:
void PaintOneShadow(Range aRange,
nsCSSShadowItem* aShadowDetails,
PropertyProvider* aProvider,
const nsRect& aDirtyRect,
const LayoutDeviceRect& aDirtyRect,
const gfxPoint& aFramePt,
const gfxPoint& aTextBaselinePt,
gfxContext* aCtx,
@ -635,7 +637,7 @@ protected:
void PaintShadows(nsCSSShadowArray* aShadow,
Range aRange,
const nsRect& aDirtyRect,
const LayoutDeviceRect& aDirtyRect,
const gfxPoint& aFramePt,
const gfxPoint& aTextBaselinePt,
nscoord aLeftEdgeOffset,
@ -737,7 +739,7 @@ protected:
* Utility methods to paint selection.
*/
void DrawSelectionDecorations(gfxContext* aContext,
const gfxRect& aDirtyRect,
const LayoutDeviceRect& aDirtyRect,
SelectionType aType,
nsTextPaintStyle& aTextPaintStyle,
const TextRangeStyle &aRangeStyle,
@ -756,7 +758,7 @@ protected:
eSelectionDecoration
};
void PaintDecorationLine(gfxContext* const aCtx,
const gfxRect& aDirtyRect,
const LayoutDeviceRect& aDirtyRect,
nscolor aColor,
const nscolor* aOverrideColor,
const Point& aPt,

Просмотреть файл

@ -3696,8 +3696,8 @@ SVGTextFrame::PaintSVG(gfxContext& aContext,
// SVG frames' PaintSVG methods paint in CSS px, but normally frames paint in
// dev pixels. Here we multiply a CSS-px-to-dev-pixel factor onto aTransform
// so our non-SVG nsTextFrame children paint correctly.
float cssPxPerDevPx = presContext->
AppUnitsToFloatCSSPixels(presContext->AppUnitsPerDevPixel());
auto auPerDevPx = presContext->AppUnitsPerDevPixel();
float cssPxPerDevPx = presContext->AppUnitsToFloatCSSPixels(auPerDevPx);
gfxMatrix canvasTMForChildren = aTransform;
canvasTMForChildren.Scale(cssPxPerDevPx, cssPxPerDevPx);
initialMatrix.Scale(1 / cssPxPerDevPx, 1 / cssPxPerDevPx);
@ -3749,7 +3749,8 @@ SVGTextFrame::PaintSVG(gfxContext& aContext,
aContext.SetMatrix(runTransform);
if (drawMode != DrawMode(0)) {
nsRect frameRect = frame->GetVisualOverflowRect();
LayoutDeviceRect frameRect = LayoutDevicePixel::
FromAppUnits(frame->GetVisualOverflowRect(), auPerDevPx);
bool paintSVGGlyphs;
if (ShouldRenderAsPath(frame, paintSVGGlyphs)) {
SVGTextDrawPathCallbacks callbacks(&rendCtx, frame,