Bug 1127114, part 2 - Unify SVGTextFrame's NotifyBeforeSelectionBackground and NotifySelectionBackgroundPathEmitted callbacks. r=heycam

This commit is contained in:
Jonathan Watt 2015-01-27 16:32:24 +00:00
parent 08d1936472
commit 348a0c4713
3 changed files with 45 additions and 65 deletions

View File

@ -8,8 +8,10 @@
#include "nsTextFrame.h"
#include "gfx2DGlue.h"
#include "gfxUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/Likely.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/TextEvents.h"
@ -4742,29 +4744,20 @@ nsTextFrame::GetSelectionDetails()
}
static void
PaintSelectionBackground(gfxContext* aCtx,
PaintSelectionBackground(DrawTarget& aDrawTarget,
nscolor aColor,
const LayoutDeviceRect& aDirtyRect,
const LayoutDeviceRect& aRect,
nsTextFrame::DrawPathCallbacks* aCallbacks)
{
DrawTarget& aDrawTarget = *aCtx->GetDrawTarget();
if (aCallbacks) {
aCallbacks->NotifyBeforeSelectionBackground(aColor);
}
Rect rect = aRect.Intersect(aDirtyRect).ToUnknownRect();
// For now, we need to put this in pixel coordinates
aCtx->NewPath();
// pixel-snap
aCtx->Rectangle(ThebesRect(rect), true);
MaybeSnapToDevicePixels(rect, aDrawTarget);
if (aCallbacks) {
aCallbacks->NotifySelectionBackgroundPathEmitted();
aCallbacks->NotifySelectionBackgroundNeedsFill(rect, aColor, aDrawTarget);
} else {
aCtx->SetColor(gfxRGBA(aColor));
aCtx->Fill();
ColorPattern color(ToDeviceColor(aColor));
aDrawTarget.FillRect(rect, color);
}
}
@ -5697,7 +5690,7 @@ nsTextFrame::PaintTextWithSelectionColors(gfxContext* aCtx,
bgRect = gfxRect(aFramePt.x + offs, aFramePt.y,
advance, GetSize().height);
}
PaintSelectionBackground(aCtx, background, dirtyRect,
PaintSelectionBackground(*aCtx->GetDrawTarget(), background, dirtyRect,
AppUnitGfxRectToDevRect(bgRect, appUnitsPerDevPixel),
aCallbacks);
}

View File

@ -7,6 +7,7 @@
#define nsTextFrame_h__
#include "mozilla/Attributes.h"
#include "mozilla/gfx/2D.h"
#include "nsFrame.h"
#include "nsSplittableFrame.h"
#include "nsLineBox.h"
@ -37,6 +38,9 @@ public:
};
class nsTextFrame : public nsTextFrameBase {
typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::gfx::Rect Rect;
public:
NS_DECL_QUERYFRAME_TARGET(nsTextFrame)
NS_DECL_FRAMEARENA_HELPERS
@ -300,7 +304,7 @@ public:
*
* Callbacks are invoked in the following order:
*
* (NotifyBeforeSelectionBackground NotifySelectionBackgroundPathEmitted)?
* (NotifySelectionBackgroundNeedsFill)?
* (NotifyBeforeDecorationLine NotifyDecorationLinePathEmitted)*
* NotifyBeforeText
* (NotifyGlyphPathEmitted |
@ -325,6 +329,14 @@ public:
{
}
/**
* Called to have the selection highlight drawn before the text is drawn
* over the top.
*/
virtual void NotifySelectionBackgroundNeedsFill(const Rect& aBackgroundRect,
nscolor aColor,
DrawTarget& aDrawTarget) { }
/**
* Called just before any paths have been emitted to the gfxContext
* for the glyphs of the frame's text.
@ -337,18 +349,6 @@ public:
*/
virtual void NotifyAfterText() { }
/**
* Called just before a path corresponding to the selection background
* has been emitted to the gfxContext.
*/
virtual void NotifyBeforeSelectionBackground(nscolor aColor) { }
/**
* Called just after a path corresponding to the selection background
* has been emitted to the gfxContext.
*/
virtual void NotifySelectionBackgroundPathEmitted() { }
/**
* Called just before a path corresponding to a text decoration line
* has been emitted to the gfxContext.

View File

@ -2723,13 +2723,14 @@ public:
{
}
void NotifySelectionBackgroundNeedsFill(const Rect& aBackgroundRect,
nscolor aColor,
DrawTarget& aDrawTarget) MOZ_OVERRIDE;
void NotifyBeforeText(nscolor aColor) MOZ_OVERRIDE;
void NotifyGlyphPathEmitted() MOZ_OVERRIDE;
void NotifyBeforeSVGGlyphPainted() MOZ_OVERRIDE;
void NotifyAfterSVGGlyphPainted() MOZ_OVERRIDE;
void NotifyAfterText() MOZ_OVERRIDE;
void NotifyBeforeSelectionBackground(nscolor aColor) MOZ_OVERRIDE;
void NotifySelectionBackgroundPathEmitted() MOZ_OVERRIDE;
void NotifyBeforeDecorationLine(nscolor aColor) MOZ_OVERRIDE;
void NotifyDecorationLinePathEmitted() MOZ_OVERRIDE;
void NotifyBeforeSelectionDecorationLine(nscolor aColor) MOZ_OVERRIDE;
@ -2786,6 +2787,27 @@ private:
nscolor mColor;
};
void
SVGTextDrawPathCallbacks::NotifySelectionBackgroundNeedsFill(
const Rect& aBackgroundRect,
nscolor aColor,
DrawTarget& aDrawTarget)
{
if (IsClipPathChild()) {
// Don't paint selection backgrounds when in a clip path.
return;
}
mColor = aColor; // currently needed by MakeFillPattern
GeneralPattern fillPattern;
MakeFillPattern(&fillPattern);
if (fillPattern.GetPattern()) {
DrawOptions drawOptions(aColor == NS_40PERCENT_FOREGROUND_COLOR ? 0.4 : 1.0);
aDrawTarget.FillRect(aBackgroundRect, fillPattern, drawOptions);
}
}
void
SVGTextDrawPathCallbacks::NotifyBeforeText(nscolor aColor)
{
@ -2820,41 +2842,6 @@ SVGTextDrawPathCallbacks::NotifyAfterText()
gfx->Restore();
}
void
SVGTextDrawPathCallbacks::NotifyBeforeSelectionBackground(nscolor aColor)
{
if (IsClipPathChild()) {
// Don't paint selection backgrounds when in a clip path.
return;
}
mColor = aColor;
gfx->Save();
}
void
SVGTextDrawPathCallbacks::NotifySelectionBackgroundPathEmitted()
{
if (IsClipPathChild()) {
// Don't paint selection backgrounds when in a clip path.
return;
}
GeneralPattern fillPattern;
MakeFillPattern(&fillPattern);
if (fillPattern.GetPattern()) {
RefPtr<Path> path = gfx->GetPath();
FillRule fillRule = nsSVGUtils::ToFillRule(mFrame->StyleSVG()->mFillRule);
if (fillRule != path->GetFillRule()) {
RefPtr<PathBuilder> builder = path->CopyToBuilder(fillRule);
path = builder->Finish();
}
DrawOptions drawOptions(mColor == NS_40PERCENT_FOREGROUND_COLOR ? 0.4 : 1.0);
gfx->GetDrawTarget()->Fill(path, fillPattern, drawOptions);
}
gfx->Restore();
}
void
SVGTextDrawPathCallbacks::NotifyBeforeDecorationLine(nscolor aColor)
{