diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 634e01f56f2a..f0b1d6e81dc6 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -34,6 +34,8 @@ #include "nsThreadUtils.h" #include "nsIContent.h" #include "nsCharSeparatedTokenizer.h" +#include "gfxContext.h" +#include "gfxFont.h" #include "nsContentList.h" #include "mozilla/AutoRestore.h" @@ -100,6 +102,7 @@ struct nsIntMargin; class nsPIDOMWindow; class nsIDocumentLoaderFactory; class nsIDOMHTMLInputElement; +class gfxTextObjectPaint; namespace mozilla { @@ -2119,6 +2122,13 @@ 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, diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index e8071e14fd02..137d3945a991 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -122,6 +122,10 @@ #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" @@ -6900,6 +6904,60 @@ 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, diff --git a/gfx/thebes/gfxSVGGlyphs.cpp b/gfx/thebes/gfxSVGGlyphs.cpp index 62e4e122ea66..0bbf54bf9e37 100644 --- a/gfx/thebes/gfxSVGGlyphs.cpp +++ b/gfx/thebes/gfxSVGGlyphs.cpp @@ -43,6 +43,7 @@ #include "nsIDOMNodeList.h" #include "nsString.h" #include "nsIDocument.h" +#include "nsPrintfCString.h" #include "nsICategoryManager.h" #include "nsIDocumentLoaderFactory.h" #include "nsIContentViewer.h" @@ -55,11 +56,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") @@ -229,7 +230,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 nsSVGUtils::PaintSVGGlyph(glyph, aContext, aDrawMode, aObjectPaint); + return nsContentUtils::PaintSVGGlyph(glyph, aContext, aDrawMode, aObjectPaint); } bool @@ -239,7 +240,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 nsSVGUtils::GetSVGGlyphExtents(glyph, aSVGToAppSpace, aResult); + return nsContentUtils::GetSVGGlyphExtents(glyph, aSVGToAppSpace, aResult); } Element * diff --git a/layout/svg/nsSVGUtils.cpp b/layout/svg/nsSVGUtils.cpp index 15bbbc0f569c..6af829de6b27 100644 --- a/layout/svg/nsSVGUtils.cpp +++ b/layout/svg/nsSVGUtils.cpp @@ -1864,41 +1864,3 @@ 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; -} diff --git a/layout/svg/nsSVGUtils.h b/layout/svg/nsSVGUtils.h index 374e398b5826..cbdc25e6f629 100644 --- a/layout/svg/nsSVGUtils.h +++ b/layout/svg/nsSVGUtils.h @@ -10,7 +10,6 @@ #define _USE_MATH_DEFINES #include -#include "gfxFont.h" #include "gfxMatrix.h" #include "gfxPoint.h" #include "gfxRect.h" @@ -204,7 +203,6 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGFilterProperty, NS_ISVGFILTERPROPERTY_IID) class nsSVGUtils { public: - typedef mozilla::dom::Element Element; static void Init(); @@ -633,28 +631,6 @@ 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