Bug 820230 - Move PaintSVGGlyph and GetSVGGlyphExtents from nsContentUtils to nsSVGUtils. r=roc

This commit is contained in:
Mats Palmgren 2012-12-12 00:15:07 +01:00
parent aad377ff7b
commit fa172a5e94
5 changed files with 65 additions and 72 deletions

View File

@ -34,8 +34,6 @@
#include "nsThreadUtils.h"
#include "nsIContent.h"
#include "nsCharSeparatedTokenizer.h"
#include "gfxContext.h"
#include "gfxFont.h"
#include "nsContentList.h"
#include "mozilla/AutoRestore.h"
@ -102,7 +100,6 @@ struct nsIntMargin;
class nsPIDOMWindow;
class nsIDocumentLoaderFactory;
class nsIDOMHTMLInputElement;
class gfxTextObjectPaint;
namespace mozilla {
@ -2122,13 +2119,6 @@ public:
static nsIEditor* GetHTMLEditor(nsPresContext* aPresContext);
static bool PaintSVGGlyph(Element *aElement, gfxContext *aContext,
gfxFont::DrawMode aDrawMode,
gfxTextObjectPaint *aObjectPaint);
static bool GetSVGGlyphExtents(Element *aElement, const gfxMatrix& aSVGToAppSpace,
gfxRect *aResult);
/**
* Check whether a spec feature/version is supported.
* @param aObject the object, which should support the feature,

View File

@ -122,10 +122,6 @@
#include "nsILoadContext.h"
#include "nsTextFragment.h"
#include "mozilla/Selection.h"
#include "nsSVGUtils.h"
#include "nsISVGChildFrame.h"
#include "nsRenderingContext.h"
#include "gfxSVGGlyphs.h"
#ifdef IBMBIDI
#include "nsIBidiKeyboard.h"
@ -6904,60 +6900,6 @@ nsContentUtils::JSArrayToAtomArray(JSContext* aCx, const JS::Value& aJSArray,
return NS_OK;
}
/* static */
bool
nsContentUtils::PaintSVGGlyph(Element *aElement, gfxContext *aContext,
gfxFont::DrawMode aDrawMode,
gfxTextObjectPaint *aObjectPaint)
{
nsIFrame *frame = aElement->GetPrimaryFrame();
if (!frame) {
NS_WARNING("No frame for SVG glyph");
return false;
}
nsISVGChildFrame *displayFrame = do_QueryFrame(frame);
if (!displayFrame) {
NS_WARNING("Non SVG frame for SVG glyph");
return false;
}
nsRenderingContext context;
context.Init(frame->PresContext()->DeviceContext(), aContext);
context.AddUserData(&gfxTextObjectPaint::sUserDataKey, aObjectPaint, nullptr);
nsresult rv = displayFrame->PaintSVG(&context, nullptr);
NS_ENSURE_SUCCESS(rv, false);
return true;
}
/* static */
bool
nsContentUtils::GetSVGGlyphExtents(Element *aElement, const gfxMatrix& aSVGToAppSpace,
gfxRect *aResult)
{
nsIFrame *frame = aElement->GetPrimaryFrame();
if (!frame) {
NS_WARNING("No frame for SVG glyph");
return false;
}
nsISVGChildFrame *displayFrame = do_QueryFrame(frame);
if (!displayFrame) {
NS_WARNING("Non SVG frame for SVG glyph");
return false;
}
*aResult = displayFrame->GetBBoxContribution(aSVGToAppSpace,
nsSVGUtils::eBBoxIncludeFill | nsSVGUtils::eBBoxIncludeFillGeometry |
nsSVGUtils::eBBoxIncludeStroke | nsSVGUtils::eBBoxIncludeStrokeGeometry |
nsSVGUtils::eBBoxIncludeMarkers);
return true;
}
// static
void
nsContentUtils::GetSelectionInTextControl(Selection* aSelection,

View File

@ -43,7 +43,6 @@
#include "nsIDOMNodeList.h"
#include "nsString.h"
#include "nsIDocument.h"
#include "nsPrintfCString.h"
#include "nsICategoryManager.h"
#include "nsIDocumentLoaderFactory.h"
#include "nsIContentViewer.h"
@ -56,11 +55,11 @@
#include "nsXMLContentSink.h"
#include "nsNetUtil.h"
#include "nsIInputStream.h"
#include "nsContentUtils.h"
#include "nsStringStream.h"
#include "nsStreamUtils.h"
#include "nsIPrincipal.h"
#include "Element.h"
#include "nsSVGUtils.h"
#define SVG_CONTENT_TYPE NS_LITERAL_CSTRING("image/svg+xml")
#define UTF8_CHARSET NS_LITERAL_CSTRING("utf-8")
@ -230,7 +229,7 @@ gfxSVGGlyphs::RenderGlyph(gfxContext *aContext, uint32_t aGlyphId,
Element *glyph = mGlyphIdMap.Get(aGlyphId);
NS_ASSERTION(glyph, "No glyph element. Should check with HasSVGGlyph() first!");
return nsContentUtils::PaintSVGGlyph(glyph, aContext, aDrawMode, aObjectPaint);
return nsSVGUtils::PaintSVGGlyph(glyph, aContext, aDrawMode, aObjectPaint);
}
bool
@ -240,7 +239,7 @@ gfxSVGGlyphs::GetGlyphExtents(uint32_t aGlyphId, const gfxMatrix& aSVGToAppSpace
Element *glyph = mGlyphIdMap.Get(aGlyphId);
NS_ASSERTION(glyph, "No glyph element. Should check with HasSVGGlyph() first!");
return nsContentUtils::GetSVGGlyphExtents(glyph, aSVGToAppSpace, aResult);
return nsSVGUtils::GetSVGGlyphExtents(glyph, aSVGToAppSpace, aResult);
}
Element *

View File

@ -1864,3 +1864,41 @@ nsSVGUtils::SetupCairoStroke(nsIFrame* aFrame, gfxContext* aContext,
return SetupCairoStrokePaint(aFrame, aContext, aObjectPaint);
}
bool
nsSVGUtils::PaintSVGGlyph(Element* aElement, gfxContext* aContext,
gfxFont::DrawMode aDrawMode,
gfxTextObjectPaint* aObjectPaint)
{
nsIFrame* frame = aElement->GetPrimaryFrame();
nsISVGChildFrame* svgFrame = do_QueryFrame(frame);
MOZ_ASSERT(!frame || svgFrame, "Non SVG frame for SVG glyph");
if (svgFrame) {
nsRenderingContext context;
context.Init(frame->PresContext()->DeviceContext(), aContext);
context.AddUserData(&gfxTextObjectPaint::sUserDataKey, aObjectPaint, nullptr);
nsresult rv = svgFrame->PaintSVG(&context, nullptr);
if (NS_SUCCEEDED(rv)) {
return true;
}
}
return false;
}
bool
nsSVGUtils::GetSVGGlyphExtents(Element* aElement,
const gfxMatrix& aSVGToAppSpace,
gfxRect* aResult)
{
nsIFrame* frame = aElement->GetPrimaryFrame();
nsISVGChildFrame* svgFrame = do_QueryFrame(frame);
MOZ_ASSERT(!frame || svgFrame, "Non SVG frame for SVG glyph");
if (svgFrame) {
*aResult = svgFrame->GetBBoxContribution(aSVGToAppSpace,
nsSVGUtils::eBBoxIncludeFill | nsSVGUtils::eBBoxIncludeFillGeometry |
nsSVGUtils::eBBoxIncludeStroke | nsSVGUtils::eBBoxIncludeStrokeGeometry |
nsSVGUtils::eBBoxIncludeMarkers);
return true;
}
return false;
}

View File

@ -10,6 +10,7 @@
#define _USE_MATH_DEFINES
#include <math.h>
#include "gfxFont.h"
#include "gfxMatrix.h"
#include "gfxPoint.h"
#include "gfxRect.h"
@ -203,6 +204,7 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGFilterProperty, NS_ISVGFILTERPROPERTY_IID)
class nsSVGUtils
{
public:
typedef mozilla::dom::Element Element;
static void Init();
@ -631,6 +633,28 @@ public:
* property on the element.
*/
static uint16_t GetGeometryHitTestFlags(nsIFrame* aFrame);
/**
* Render a SVG glyph.
* @param aElement the SVG glyph element to render
* @param aContext the thebes aContext to draw to
* @param aDrawMode fill or stroke or both (see gfxFont::DrawMode)
* @return true if rendering succeeded
*/
static bool PaintSVGGlyph(Element* aElement, gfxContext* aContext,
gfxFont::DrawMode aDrawMode,
gfxTextObjectPaint* aObjectPaint);
/**
* Get the extents of a SVG glyph.
* @param aElement the SVG glyph element
* @param aSVGToAppSpace the matrix mapping the SVG glyph space to the
* target context space
* @param aResult the result (valid when true is returned)
* @return true if calculating the extents succeeded
*/
static bool GetSVGGlyphExtents(Element* aElement,
const gfxMatrix& aSVGToAppSpace,
gfxRect* aResult);
};
#endif