1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/svg/nsSVGUtils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,579 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef NS_SVGUTILS_H 1.10 +#define NS_SVGUTILS_H 1.11 + 1.12 +// include math.h to pick up definition of M_ maths defines e.g. M_PI 1.13 +#define _USE_MATH_DEFINES 1.14 +#include <math.h> 1.15 + 1.16 +#include "DrawMode.h" 1.17 +#include "gfx2DGlue.h" 1.18 +#include "gfxMatrix.h" 1.19 +#include "gfxPoint.h" 1.20 +#include "gfxRect.h" 1.21 +#include "mozilla/gfx/Rect.h" 1.22 +#include "nsAlgorithm.h" 1.23 +#include "nsChangeHint.h" 1.24 +#include "nsColor.h" 1.25 +#include "nsCOMPtr.h" 1.26 +#include "nsID.h" 1.27 +#include "nsISupportsBase.h" 1.28 +#include "nsMathUtils.h" 1.29 +#include "nsStyleStruct.h" 1.30 +#include "mozilla/Constants.h" 1.31 +#include <algorithm> 1.32 + 1.33 +class gfxContext; 1.34 +class gfxPattern; 1.35 +class nsFrameList; 1.36 +class nsIContent; 1.37 +class nsIDocument; 1.38 +class nsIFrame; 1.39 +class nsPresContext; 1.40 +class nsRenderingContext; 1.41 +class nsStyleContext; 1.42 +class nsStyleCoord; 1.43 +class nsSVGDisplayContainerFrame; 1.44 +class nsSVGElement; 1.45 +class nsSVGEnum; 1.46 +class nsSVGLength2; 1.47 +class nsSVGOuterSVGFrame; 1.48 +class nsSVGPathGeometryFrame; 1.49 +class nsTextFrame; 1.50 +class gfxTextContextPaint; 1.51 + 1.52 +struct nsStyleSVG; 1.53 +struct nsStyleSVGPaint; 1.54 +struct nsRect; 1.55 +struct nsIntRect; 1.56 +struct nsPoint; 1.57 + 1.58 +namespace mozilla { 1.59 +class SVGAnimatedPreserveAspectRatio; 1.60 +class SVGPreserveAspectRatio; 1.61 +namespace dom { 1.62 +class Element; 1.63 +} // namespace dom 1.64 +namespace gfx { 1.65 +class SourceSurface; 1.66 +} 1.67 +} // namespace mozilla 1.68 + 1.69 +// maximum dimension of an offscreen surface - choose so that 1.70 +// the surface size doesn't overflow a 32-bit signed int using 1.71 +// 4 bytes per pixel; in line with gfxASurface::CheckSurfaceSize 1.72 +// In fact Macs can't even manage that 1.73 +#define NS_SVG_OFFSCREEN_MAX_DIMENSION 4096 1.74 + 1.75 +#define SVG_HIT_TEST_FILL 0x01 1.76 +#define SVG_HIT_TEST_STROKE 0x02 1.77 +#define SVG_HIT_TEST_CHECK_MRECT 0x04 1.78 + 1.79 + 1.80 +bool NS_SVGDisplayListHitTestingEnabled(); 1.81 +bool NS_SVGDisplayListPaintingEnabled(); 1.82 + 1.83 +/** 1.84 + * Sometimes we need to distinguish between an empty box and a box 1.85 + * that contains an element that has no size e.g. a point at the origin. 1.86 + */ 1.87 +class SVGBBox { 1.88 + typedef mozilla::gfx::Rect Rect; 1.89 + 1.90 +public: 1.91 + SVGBBox() 1.92 + : mIsEmpty(true) {} 1.93 + 1.94 + SVGBBox(const Rect& aRect) 1.95 + : mBBox(aRect), mIsEmpty(false) {} 1.96 + 1.97 + SVGBBox(const gfxRect& aRect) 1.98 + : mBBox(ToRect(aRect)), mIsEmpty(false) {} 1.99 + 1.100 + gfxRect ToThebesRect() const { 1.101 + return ThebesRect(mBBox); 1.102 + } 1.103 + 1.104 + bool IsEmpty() const { 1.105 + return mIsEmpty; 1.106 + } 1.107 + 1.108 + void UnionEdges(const SVGBBox& aSVGBBox) { 1.109 + if (aSVGBBox.mIsEmpty) { 1.110 + return; 1.111 + } 1.112 + mBBox = mIsEmpty ? aSVGBBox.mBBox : mBBox.UnionEdges(aSVGBBox.mBBox); 1.113 + mIsEmpty = false; 1.114 + } 1.115 + 1.116 +private: 1.117 + Rect mBBox; 1.118 + bool mIsEmpty; 1.119 +}; 1.120 + 1.121 +// GRRR WINDOWS HATE HATE HATE 1.122 +#undef CLIP_MASK 1.123 + 1.124 +class MOZ_STACK_CLASS SVGAutoRenderState 1.125 +{ 1.126 +public: 1.127 + enum RenderMode { 1.128 + /** 1.129 + * Used to inform SVG frames that they should paint as normal. 1.130 + */ 1.131 + NORMAL, 1.132 + /** 1.133 + * Used to inform SVG frames when they are painting as the child of a 1.134 + * simple clipPath. In this case they should only draw their basic geometry 1.135 + * as a path. They should not fill, stroke, or paint anything else. 1.136 + */ 1.137 + CLIP, 1.138 + /** 1.139 + * Used to inform SVG frames when they are painting as the child of a 1.140 + * complex clipPath that requires the use of a clip mask. In this case they 1.141 + * should only draw their basic geometry as a path and then fill it using 1.142 + * fully opaque white. They should not stroke, or paint anything else. 1.143 + */ 1.144 + CLIP_MASK 1.145 + }; 1.146 + 1.147 + SVGAutoRenderState(nsRenderingContext *aContext, RenderMode aMode 1.148 + MOZ_GUARD_OBJECT_NOTIFIER_PARAM); 1.149 + ~SVGAutoRenderState(); 1.150 + 1.151 + void SetPaintingToWindow(bool aPaintingToWindow); 1.152 + 1.153 + static RenderMode GetRenderMode(nsRenderingContext *aContext); 1.154 + static bool IsPaintingToWindow(nsRenderingContext *aContext); 1.155 + 1.156 +private: 1.157 + nsRenderingContext *mContext; 1.158 + void *mOriginalRenderState; 1.159 + RenderMode mMode; 1.160 + bool mPaintingToWindow; 1.161 + MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER 1.162 +}; 1.163 + 1.164 + 1.165 +#define NS_ISVGFILTERREFERENCE_IID \ 1.166 +{ 0x9744ee20, 0x1bcf, 0x4c62, \ 1.167 + { 0x86, 0x7d, 0xd3, 0x7a, 0x91, 0x60, 0x3e, 0xef } } 1.168 + 1.169 +class nsISVGFilterReference : public nsISupports 1.170 +{ 1.171 +public: 1.172 + NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGFILTERREFERENCE_IID) 1.173 + virtual void Invalidate() = 0; 1.174 +}; 1.175 + 1.176 +NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGFilterReference, NS_ISVGFILTERREFERENCE_IID) 1.177 + 1.178 +/** 1.179 + * General functions used by all of SVG layout and possibly content code. 1.180 + * If a method is used by content and depends only on other content methods 1.181 + * it should go in SVGContentUtils instead. 1.182 + */ 1.183 +class nsSVGUtils 1.184 +{ 1.185 +public: 1.186 + typedef mozilla::dom::Element Element; 1.187 + 1.188 + static void Init(); 1.189 + 1.190 + /** 1.191 + * Gets the nearest nsSVGInnerSVGFrame or nsSVGOuterSVGFrame frame. aFrame 1.192 + * must be an SVG frame. If aFrame is of type nsGkAtoms::svgOuterSVGFrame, 1.193 + * returns nullptr. 1.194 + */ 1.195 + static nsSVGDisplayContainerFrame* GetNearestSVGViewport(nsIFrame *aFrame); 1.196 + 1.197 + /** 1.198 + * Returns the frame's post-filter visual overflow rect when passed the 1.199 + * frame's pre-filter visual overflow rect. If the frame is not currently 1.200 + * being filtered, this function simply returns aUnfilteredRect. 1.201 + */ 1.202 + static nsRect GetPostFilterVisualOverflowRect(nsIFrame *aFrame, 1.203 + const nsRect &aUnfilteredRect); 1.204 + 1.205 + /** 1.206 + * Schedules an update of the frame's bounds (which will in turn invalidate 1.207 + * the new area that the frame should paint to). 1.208 + * 1.209 + * This does nothing when passed an NS_FRAME_IS_NONDISPLAY frame. 1.210 + * In future we may want to allow ReflowSVG to be called on such frames, 1.211 + * but that would be better implemented as a ForceReflowSVG function to 1.212 + * be called synchronously while painting them without marking or paying 1.213 + * attention to dirty bits like this function. 1.214 + * 1.215 + * This is very similar to PresShell::FrameNeedsReflow. The main reason that 1.216 + * we have this function instead of using FrameNeedsReflow is because we need 1.217 + * to be able to call it under nsSVGOuterSVGFrame::NotifyViewportChange when 1.218 + * that function is called by nsSVGOuterSVGFrame::Reflow. FrameNeedsReflow 1.219 + * is not suitable for calling during reflow though, and it asserts as much. 1.220 + * The reason that we want to be callable under NotifyViewportChange is 1.221 + * because we want to synchronously notify and dirty the nsSVGOuterSVGFrame's 1.222 + * children so that when nsSVGOuterSVGFrame::DidReflow is called its children 1.223 + * will be updated for the new size as appropriate. Otherwise we'd have to 1.224 + * post an event to the event loop to mark dirty flags and request an update. 1.225 + * 1.226 + * Another reason that we don't currently want to call 1.227 + * PresShell::FrameNeedsReflow is because passing eRestyle to it to get it to 1.228 + * mark descendants dirty would cause it to descend through 1.229 + * nsSVGForeignObjectFrame frames to mark their children dirty, but we want to 1.230 + * handle nsSVGForeignObjectFrame specially. It would also do unnecessary work 1.231 + * descending into NS_FRAME_IS_NONDISPLAY frames. 1.232 + */ 1.233 + static void ScheduleReflowSVG(nsIFrame *aFrame); 1.234 + 1.235 + /** 1.236 + * Returns true if the frame or any of its children need ReflowSVG 1.237 + * to be called on them. 1.238 + */ 1.239 + static bool NeedsReflowSVG(nsIFrame *aFrame); 1.240 + 1.241 + /* 1.242 + * Update the filter invalidation region for ancestor frames, if relevant. 1.243 + */ 1.244 + static void NotifyAncestorsOfFilterRegionChange(nsIFrame *aFrame); 1.245 + 1.246 + /* Computes the input length in terms of object space coordinates. 1.247 + Input: rect - bounding box 1.248 + length - length to be converted 1.249 + */ 1.250 + static float ObjectSpace(const gfxRect &aRect, const nsSVGLength2 *aLength); 1.251 + 1.252 + /* Computes the input length in terms of user space coordinates. 1.253 + Input: content - object to be used for determining user space 1.254 + Input: length - length to be converted 1.255 + */ 1.256 + static float UserSpace(nsSVGElement *aSVGElement, const nsSVGLength2 *aLength); 1.257 + 1.258 + /* Computes the input length in terms of user space coordinates. 1.259 + Input: aFrame - object to be used for determining user space 1.260 + length - length to be converted 1.261 + */ 1.262 + static float UserSpace(nsIFrame *aFrame, const nsSVGLength2 *aLength); 1.263 + 1.264 + /* Find the outermost SVG frame of the passed frame */ 1.265 + static nsSVGOuterSVGFrame * 1.266 + GetOuterSVGFrame(nsIFrame *aFrame); 1.267 + 1.268 + /** 1.269 + * Get the covered region for a frame. Return null if it's not an SVG frame. 1.270 + * @param aRect gets a rectangle in app units 1.271 + * @return the outer SVG frame which aRect is relative to 1.272 + */ 1.273 + static nsIFrame* 1.274 + GetOuterSVGFrameAndCoveredRegion(nsIFrame* aFrame, nsRect* aRect); 1.275 + 1.276 + /* Paint SVG frame with SVG effects - aDirtyRect is the area being 1.277 + * redrawn, in device pixel coordinates relative to the outer svg */ 1.278 + static void 1.279 + PaintFrameWithEffects(nsRenderingContext *aContext, 1.280 + const nsIntRect *aDirtyRect, 1.281 + nsIFrame *aFrame, 1.282 + nsIFrame* aTransformRoot = nullptr); 1.283 + 1.284 + /* Hit testing - check if point hits the clipPath of indicated 1.285 + * frame. Returns true if no clipPath set. */ 1.286 + static bool 1.287 + HitTestClip(nsIFrame *aFrame, const nsPoint &aPoint); 1.288 + 1.289 + /* Hit testing - check if point hits any children of frame. */ 1.290 + 1.291 + static nsIFrame * 1.292 + HitTestChildren(nsIFrame *aFrame, const nsPoint &aPoint); 1.293 + 1.294 + /* 1.295 + * Returns the CanvasTM of the indicated frame, whether it's a 1.296 + * child SVG frame, container SVG frame, or a regular frame. 1.297 + * For regular frames, we just return an identity matrix. 1.298 + */ 1.299 + static gfxMatrix GetCanvasTM(nsIFrame* aFrame, uint32_t aFor, 1.300 + nsIFrame* aTransformRoot = nullptr); 1.301 + 1.302 + /** 1.303 + * Returns the transform from aFrame's user space to canvas space. Only call 1.304 + * with SVG frames. This is like GetCanvasTM, except that it only includes 1.305 + * the transforms from aFrame's user space (i.e. the coordinate context 1.306 + * established by its 'transform' attribute, or else the coordinate context 1.307 + * that its _parent_ establishes for its children) to outer-<svg> device 1.308 + * space. Specifically, it does not include any other transforms introduced 1.309 + * by the frame such as x/y offsets and viewBox attributes. 1.310 + */ 1.311 + static gfxMatrix GetUserToCanvasTM(nsIFrame* aFrame, uint32_t aFor); 1.312 + 1.313 + /** 1.314 + * Notify the descendants of aFrame of a change to one of their ancestors 1.315 + * that might affect them. 1.316 + */ 1.317 + static void 1.318 + NotifyChildrenOfSVGChange(nsIFrame *aFrame, uint32_t aFlags); 1.319 + 1.320 + /* 1.321 + * Get frame's covered region by walking the children and doing union. 1.322 + */ 1.323 + static nsRect 1.324 + GetCoveredRegion(const nsFrameList &aFrames); 1.325 + 1.326 + // Converts aPoint from an app unit point in outer-<svg> content rect space 1.327 + // to an app unit point in a frame's SVG userspace. 1.328 + // This is a temporary helper we should no longer need after bug 614732 is 1.329 + // fixed. 1.330 + static nsPoint 1.331 + TransformOuterSVGPointToChildFrame(nsPoint aPoint, 1.332 + const gfxMatrix& aFrameToCanvasTM, 1.333 + nsPresContext* aPresContext); 1.334 + 1.335 + static nsRect 1.336 + TransformFrameRectToOuterSVG(const nsRect& aRect, 1.337 + const gfxMatrix& aMatrix, 1.338 + nsPresContext* aPresContext); 1.339 + 1.340 + /* 1.341 + * Convert a surface size to an integer for use by thebes 1.342 + * possibly making it smaller in the process so the surface does not 1.343 + * use excessive memory. 1.344 + * 1.345 + * @param aSize the desired surface size 1.346 + * @param aResultOverflows true if the desired surface size is too big 1.347 + * @return the surface size to use 1.348 + */ 1.349 + static gfxIntSize ConvertToSurfaceSize(const gfxSize& aSize, 1.350 + bool *aResultOverflows); 1.351 + 1.352 + /* 1.353 + * Hit test a given rectangle/matrix. 1.354 + */ 1.355 + static bool 1.356 + HitTestRect(const mozilla::gfx::Matrix &aMatrix, 1.357 + float aRX, float aRY, float aRWidth, float aRHeight, 1.358 + float aX, float aY); 1.359 + 1.360 + 1.361 + /** 1.362 + * Get the clip rect for the given frame, taking into account the CSS 'clip' 1.363 + * property. See: 1.364 + * http://www.w3.org/TR/SVG11/masking.html#OverflowAndClipProperties 1.365 + * The arguments for aX, aY, aWidth and aHeight should be the dimensions of 1.366 + * the viewport established by aFrame. 1.367 + */ 1.368 + static gfxRect 1.369 + GetClipRectForFrame(nsIFrame *aFrame, 1.370 + float aX, float aY, float aWidth, float aHeight); 1.371 + 1.372 + static void SetClipRect(gfxContext *aContext, 1.373 + const gfxMatrix &aCTM, 1.374 + const gfxRect &aRect); 1.375 + 1.376 + /* Using group opacity instead of fill or stroke opacity on a 1.377 + * geometry object seems to be a common authoring mistake. If we're 1.378 + * not applying filters and not both stroking and filling, we can 1.379 + * generate the same result without going through the overhead of a 1.380 + * push/pop group. */ 1.381 + static bool 1.382 + CanOptimizeOpacity(nsIFrame *aFrame); 1.383 + 1.384 + /** 1.385 + * Take the CTM to userspace for an element, and adjust it to a CTM to its 1.386 + * object bounding box space if aUnits is SVG_UNIT_TYPE_OBJECTBOUNDINGBOX. 1.387 + * (I.e. so that [0,0] is at the top left of its bbox, and [1,1] is at the 1.388 + * bottom right of its bbox). 1.389 + * 1.390 + * If the bbox is empty, this will return a singular matrix. 1.391 + */ 1.392 + static gfxMatrix 1.393 + AdjustMatrixForUnits(const gfxMatrix &aMatrix, 1.394 + nsSVGEnum *aUnits, 1.395 + nsIFrame *aFrame); 1.396 + 1.397 + enum BBoxFlags { 1.398 + eBBoxIncludeFill = 1 << 0, 1.399 + eBBoxIncludeFillGeometry = 1 << 1, 1.400 + eBBoxIncludeStroke = 1 << 2, 1.401 + eBBoxIncludeStrokeGeometry = 1 << 3, 1.402 + eBBoxIncludeMarkers = 1 << 4 1.403 + }; 1.404 + /** 1.405 + * Get the SVG bbox (the SVG spec's simplified idea of bounds) of aFrame in 1.406 + * aFrame's userspace. 1.407 + */ 1.408 + static gfxRect GetBBox(nsIFrame *aFrame, 1.409 + uint32_t aFlags = eBBoxIncludeFillGeometry); 1.410 + 1.411 + /* 1.412 + * "User space" is the space that the frame's BBox (as calculated by 1.413 + * nsSVGUtils::GetBBox) is in. "Frame space" is the space that has its origin 1.414 + * at the top left of the union of the frame's border-box rects over all 1.415 + * continuations. 1.416 + * This function returns the offset one needs to add to something in frame 1.417 + * space in order to get its coordinates in user space. 1.418 + */ 1.419 + static gfxPoint FrameSpaceInCSSPxToUserSpaceOffset(nsIFrame *aFrame); 1.420 + 1.421 + /** 1.422 + * Convert a userSpaceOnUse/objectBoundingBoxUnits rectangle that's specified 1.423 + * using four nsSVGLength2 values into a user unit rectangle in user space. 1.424 + * 1.425 + * @param aXYWH pointer to 4 consecutive nsSVGLength2 objects containing 1.426 + * the x, y, width and height values in that order 1.427 + * @param aBBox the bounding box of the object the rect is relative to; 1.428 + * may be null if aUnits is not SVG_UNIT_TYPE_OBJECTBOUNDINGBOX 1.429 + * @param aFrame the object in which to interpret user-space units; 1.430 + * may be null if aUnits is SVG_UNIT_TYPE_OBJECTBOUNDINGBOX 1.431 + */ 1.432 + static gfxRect 1.433 + GetRelativeRect(uint16_t aUnits, const nsSVGLength2 *aXYWH, 1.434 + const gfxRect &aBBox, nsIFrame *aFrame); 1.435 + 1.436 + /** 1.437 + * Find the first frame, starting with aStartFrame and going up its 1.438 + * parent chain, that is not an svgAFrame. 1.439 + */ 1.440 + static nsIFrame* GetFirstNonAAncestorFrame(nsIFrame* aStartFrame); 1.441 + 1.442 + static bool OuterSVGIsCallingReflowSVG(nsIFrame *aFrame); 1.443 + static bool AnyOuterSVGIsCallingReflowSVG(nsIFrame *aFrame); 1.444 + 1.445 + /* 1.446 + * Get any additional transforms that apply only to stroking 1.447 + * e.g. non-scaling-stroke 1.448 + */ 1.449 + static gfxMatrix GetStrokeTransform(nsIFrame *aFrame); 1.450 + 1.451 + /** 1.452 + * Compute the maximum possible device space stroke extents of a path given 1.453 + * the path's device space path extents, its stroke style and its ctm. 1.454 + * 1.455 + * This is a workaround for the lack of suitable cairo API for getting the 1.456 + * tight device space stroke extents of a path. This basically gives us the 1.457 + * tightest extents that we can guarantee fully enclose the inked stroke 1.458 + * without doing the calculations for the actual tight extents. We exploit 1.459 + * the fact that cairo does have an API for getting the tight device space 1.460 + * fill/path extents. 1.461 + * 1.462 + * This should die once bug 478152 is fixed. 1.463 + */ 1.464 + static gfxRect PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents, 1.465 + nsTextFrame* aFrame, 1.466 + const gfxMatrix& aMatrix); 1.467 + static gfxRect PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents, 1.468 + nsSVGPathGeometryFrame* aFrame, 1.469 + const gfxMatrix& aMatrix); 1.470 + 1.471 + /** 1.472 + * Convert a floating-point value to a 32-bit integer value, clamping to 1.473 + * the range of valid integers. 1.474 + */ 1.475 + static int32_t ClampToInt(double aVal) 1.476 + { 1.477 + return NS_lround(std::max(double(INT32_MIN), 1.478 + std::min(double(INT32_MAX), aVal))); 1.479 + } 1.480 + 1.481 + static nscolor GetFallbackOrPaintColor(gfxContext *aContext, 1.482 + nsStyleContext *aStyleContext, 1.483 + nsStyleSVGPaint nsStyleSVG::*aFillOrStroke); 1.484 + 1.485 + /** 1.486 + * Set up cairo context with an object pattern 1.487 + */ 1.488 + static bool SetupContextPaint(gfxContext *aContext, 1.489 + gfxTextContextPaint *aContextPaint, 1.490 + const nsStyleSVGPaint& aPaint, 1.491 + float aOpacity); 1.492 + 1.493 + /** 1.494 + * Sets the current paint on the specified gfxContent to be the SVG 'fill' 1.495 + * for the given frame. 1.496 + */ 1.497 + static bool SetupCairoFillPaint(nsIFrame* aFrame, gfxContext* aContext, 1.498 + gfxTextContextPaint *aContextPaint = nullptr); 1.499 + 1.500 + /** 1.501 + * Sets the current paint on the specified gfxContent to be the SVG 'stroke' 1.502 + * for the given frame. 1.503 + */ 1.504 + static bool SetupCairoStrokePaint(nsIFrame* aFrame, gfxContext* aContext, 1.505 + gfxTextContextPaint *aContextPaint = nullptr); 1.506 + 1.507 + static float GetOpacity(nsStyleSVGOpacitySource aOpacityType, 1.508 + const float& aOpacity, 1.509 + gfxTextContextPaint *aOuterContextPaint); 1.510 + 1.511 + /* 1.512 + * @return false if there is no stroke 1.513 + */ 1.514 + static bool HasStroke(nsIFrame* aFrame, 1.515 + gfxTextContextPaint *aContextPaint = nullptr); 1.516 + 1.517 + static float GetStrokeWidth(nsIFrame* aFrame, 1.518 + gfxTextContextPaint *aContextPaint = nullptr); 1.519 + 1.520 + /* 1.521 + * Set up a cairo context for measuring the bounding box of a stroked path. 1.522 + */ 1.523 + static void SetupCairoStrokeBBoxGeometry(nsIFrame* aFrame, 1.524 + gfxContext *aContext, 1.525 + gfxTextContextPaint *aContextPaint = nullptr); 1.526 + 1.527 + /* 1.528 + * Set up a cairo context for a stroked path (including any dashing that 1.529 + * applies). 1.530 + */ 1.531 + static void SetupCairoStrokeGeometry(nsIFrame* aFrame, gfxContext *aContext, 1.532 + gfxTextContextPaint *aContextPaint = nullptr); 1.533 + 1.534 + /* 1.535 + * Set up a cairo context for stroking, including setting up any stroke-related 1.536 + * properties such as dashing and setting the current paint on the gfxContext. 1.537 + */ 1.538 + static bool SetupCairoStroke(nsIFrame* aFrame, gfxContext *aContext, 1.539 + gfxTextContextPaint *aContextPaint = nullptr); 1.540 + 1.541 + /** 1.542 + * This function returns a set of bit flags indicating which parts of the 1.543 + * element (fill, stroke, bounds) should intercept pointer events. It takes 1.544 + * into account the type of element and the value of the 'pointer-events' 1.545 + * property on the element. 1.546 + */ 1.547 + static uint16_t GetGeometryHitTestFlags(nsIFrame* aFrame); 1.548 + 1.549 + /** 1.550 + * Render a SVG glyph. 1.551 + * @param aElement the SVG glyph element to render 1.552 + * @param aContext the thebes aContext to draw to 1.553 + * @param aDrawMode fill or stroke or both (see DrawMode) 1.554 + * @return true if rendering succeeded 1.555 + */ 1.556 + static bool PaintSVGGlyph(Element* aElement, gfxContext* aContext, 1.557 + DrawMode aDrawMode, 1.558 + gfxTextContextPaint* aContextPaint); 1.559 + /** 1.560 + * Get the extents of a SVG glyph. 1.561 + * @param aElement the SVG glyph element 1.562 + * @param aSVGToAppSpace the matrix mapping the SVG glyph space to the 1.563 + * target context space 1.564 + * @param aResult the result (valid when true is returned) 1.565 + * @return true if calculating the extents succeeded 1.566 + */ 1.567 + static bool GetSVGGlyphExtents(Element* aElement, 1.568 + const gfxMatrix& aSVGToAppSpace, 1.569 + gfxRect* aResult); 1.570 + 1.571 + /** 1.572 + * Returns the app unit canvas bounds of a userspace rect. 1.573 + * 1.574 + * @param aToCanvas Transform from userspace to canvas device space. 1.575 + */ 1.576 + static nsRect 1.577 + ToCanvasBounds(const gfxRect &aUserspaceRect, 1.578 + const gfxMatrix &aToCanvas, 1.579 + const nsPresContext *presContext); 1.580 +}; 1.581 + 1.582 +#endif