2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla SVG project.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is IBM Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef NS_SVGUTILS_H
|
|
|
|
#define NS_SVGUTILS_H
|
|
|
|
|
2009-04-02 13:29:31 -07:00
|
|
|
// include math.h to pick up definition of M_SQRT1_2 if the platform defines it
|
2007-03-22 10:30:00 -07:00
|
|
|
#define _USE_MATH_DEFINES
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsRect.h"
|
2008-08-12 01:36:51 -07:00
|
|
|
#include "gfxContext.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2009-04-28 21:31:34 -07:00
|
|
|
#include "gfxRect.h"
|
|
|
|
#include "gfxMatrix.h"
|
2012-02-04 05:11:09 -08:00
|
|
|
#include "nsStyleStruct.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIDocument;
|
|
|
|
class nsPresContext;
|
|
|
|
class nsIContent;
|
2009-08-20 14:52:47 -07:00
|
|
|
class nsStyleContext;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsStyleCoord;
|
|
|
|
class nsFrameList;
|
|
|
|
class nsIFrame;
|
|
|
|
struct nsStyleSVGPaint;
|
2008-01-10 03:26:25 -08:00
|
|
|
class nsIDOMSVGElement;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIDOMSVGLength;
|
|
|
|
class nsIURI;
|
|
|
|
class nsSVGOuterSVGFrame;
|
|
|
|
class nsIAtom;
|
|
|
|
class nsSVGLength2;
|
|
|
|
class nsSVGElement;
|
|
|
|
class nsSVGSVGElement;
|
|
|
|
class nsAttrValue;
|
2008-07-14 21:35:37 -07:00
|
|
|
class gfxContext;
|
2007-03-22 10:30:00 -07:00
|
|
|
class gfxASurface;
|
2008-03-05 22:51:13 -08:00
|
|
|
class gfxPattern;
|
2007-09-17 08:20:35 -07:00
|
|
|
class gfxImageSurface;
|
2007-06-13 02:02:48 -07:00
|
|
|
struct gfxSize;
|
2007-06-25 09:12:35 -07:00
|
|
|
struct nsStyleFont;
|
2007-12-03 20:40:52 -08:00
|
|
|
class nsSVGEnum;
|
|
|
|
class nsISVGChildFrame;
|
2009-03-31 05:19:39 -07:00
|
|
|
class nsSVGGeometryFrame;
|
2011-09-05 10:53:34 -07:00
|
|
|
class nsSVGPathGeometryFrame;
|
2009-04-24 16:17:43 -07:00
|
|
|
class nsSVGDisplayContainerFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-30 06:12:06 -07:00
|
|
|
namespace mozilla {
|
2010-12-19 16:45:29 -08:00
|
|
|
class SVGAnimatedPreserveAspectRatio;
|
2010-12-19 16:45:29 -08:00
|
|
|
class SVGPreserveAspectRatio;
|
2010-04-30 06:12:06 -07:00
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifndef M_PI
|
|
|
|
#define M_PI 3.14159265358979323846
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// SVG Frame state bits
|
2010-12-06 12:57:18 -08:00
|
|
|
#define NS_STATE_IS_OUTER_SVG NS_FRAME_STATE_BIT(20)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* are we the child of a non-display container? */
|
2010-12-06 12:57:18 -08:00
|
|
|
#define NS_STATE_SVG_NONDISPLAY_CHILD NS_FRAME_STATE_BIT(22)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-12-06 12:57:18 -08:00
|
|
|
// If this bit is set, we are a <clipPath> element or descendant.
|
2011-04-20 02:16:01 -07:00
|
|
|
#define NS_STATE_SVG_CLIPPATH_CHILD NS_FRAME_STATE_BIT(23)
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Byte offsets of channels in a native packed gfxColor or cairo image surface.
|
|
|
|
*/
|
|
|
|
#ifdef IS_BIG_ENDIAN
|
|
|
|
#define GFX_ARGB32_OFFSET_A 0
|
|
|
|
#define GFX_ARGB32_OFFSET_R 1
|
|
|
|
#define GFX_ARGB32_OFFSET_G 2
|
|
|
|
#define GFX_ARGB32_OFFSET_B 3
|
|
|
|
#else
|
|
|
|
#define GFX_ARGB32_OFFSET_A 3
|
|
|
|
#define GFX_ARGB32_OFFSET_R 2
|
|
|
|
#define GFX_ARGB32_OFFSET_G 1
|
|
|
|
#define GFX_ARGB32_OFFSET_B 0
|
|
|
|
#endif
|
|
|
|
|
2007-06-13 02:02:48 -07:00
|
|
|
// maximum dimension of an offscreen surface - choose so that
|
|
|
|
// the surface size doesn't overflow a 32-bit signed int using
|
|
|
|
// 4 bytes per pixel; in line with gfxASurface::CheckSurfaceSize
|
2009-12-28 01:49:08 -08:00
|
|
|
// In fact Macs can't even manage that
|
|
|
|
#define NS_SVG_OFFSCREEN_MAX_DIMENSION 4096
|
2007-06-13 02:02:48 -07:00
|
|
|
|
2010-03-26 20:55:28 -07:00
|
|
|
#define SVG_WSP_DELIM "\x20\x9\xD\xA"
|
|
|
|
#define SVG_COMMA_WSP_DELIM "," SVG_WSP_DELIM
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool
|
2010-04-28 16:00:54 -07:00
|
|
|
IsSVGWhitespace(char aChar)
|
|
|
|
{
|
|
|
|
return aChar == '\x20' || aChar == '\x9' ||
|
|
|
|
aChar == '\xD' || aChar == '\xA';
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool
|
2010-12-03 08:40:23 -08:00
|
|
|
IsSVGWhitespace(PRUnichar aChar)
|
|
|
|
{
|
|
|
|
return aChar == PRUnichar('\x20') || aChar == PRUnichar('\x9') ||
|
|
|
|
aChar == PRUnichar('\xD') || aChar == PRUnichar('\xA');
|
|
|
|
}
|
|
|
|
|
2009-03-09 18:20:17 -07:00
|
|
|
/*
|
|
|
|
* Checks the smil enabled preference. Declared as a function to match
|
|
|
|
* NS_SVGEnabled().
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool NS_SMILEnabled();
|
2009-03-09 18:20:17 -07:00
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
|
2008-08-05 18:58:29 -07:00
|
|
|
// GRRR WINDOWS HATE HATE HATE
|
|
|
|
#undef CLIP_MASK
|
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
class NS_STACK_CLASS SVGAutoRenderState
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum RenderMode { NORMAL, CLIP, CLIP_MASK };
|
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
SVGAutoRenderState(nsRenderingContext *aContext, RenderMode aMode);
|
|
|
|
~SVGAutoRenderState();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
void SetPaintingToWindow(bool aPaintingToWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
static RenderMode GetRenderMode(nsRenderingContext *aContext);
|
|
|
|
static bool IsPaintingToWindow(nsRenderingContext *aContext);
|
2010-10-14 18:03:45 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2012-03-02 00:28:59 -08:00
|
|
|
nsRenderingContext *mContext;
|
|
|
|
void *mOriginalRenderState;
|
|
|
|
RenderMode mMode;
|
|
|
|
bool mPaintingToWindow;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-01-02 12:49:13 -08:00
|
|
|
#define NS_ISVGFILTERPROPERTY_IID \
|
|
|
|
{ 0x9744ee20, 0x1bcf, 0x4c62, \
|
|
|
|
{ 0x86, 0x7d, 0xd3, 0x7a, 0x91, 0x60, 0x3e, 0xef } }
|
|
|
|
|
|
|
|
class nsISVGFilterProperty : public nsISupports
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISVGFILTERPROPERTY_IID)
|
|
|
|
virtual void Invalidate() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsISVGFilterProperty, NS_ISVGFILTERPROPERTY_IID)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsSVGUtils
|
|
|
|
{
|
|
|
|
public:
|
2010-12-19 16:45:29 -08:00
|
|
|
typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio;
|
2010-12-19 16:45:29 -08:00
|
|
|
typedef mozilla::SVGPreserveAspectRatio SVGPreserveAspectRatio;
|
2010-12-19 16:45:29 -08:00
|
|
|
|
2009-03-09 06:14:35 -07:00
|
|
|
/*
|
|
|
|
* Get the parent element of an nsIContent
|
|
|
|
*/
|
2010-05-14 10:04:51 -07:00
|
|
|
static mozilla::dom::Element *GetParentElement(nsIContent *aContent);
|
2009-03-09 06:14:35 -07:00
|
|
|
|
2011-02-26 02:21:11 -08:00
|
|
|
/*
|
|
|
|
* Get the outer SVG element of an nsIContent
|
|
|
|
*/
|
|
|
|
static nsSVGSVGElement *GetOuterSVGElement(nsSVGElement *aSVGElement);
|
|
|
|
|
2007-06-25 09:12:35 -07:00
|
|
|
/*
|
2010-07-16 14:42:12 -07:00
|
|
|
* Get the number of CSS px (user units) per em (i.e. the em-height in user
|
|
|
|
* units) for an nsIContent
|
|
|
|
*
|
|
|
|
* XXX document the conditions under which these may fail, and what they
|
|
|
|
* return in those cases.
|
2007-06-25 09:12:35 -07:00
|
|
|
*/
|
2010-04-30 06:12:06 -07:00
|
|
|
static float GetFontSize(mozilla::dom::Element *aElement);
|
2008-09-10 17:24:16 -07:00
|
|
|
static float GetFontSize(nsIFrame *aFrame);
|
2009-08-20 14:52:47 -07:00
|
|
|
static float GetFontSize(nsStyleContext *aStyleContext);
|
2007-06-25 09:12:35 -07:00
|
|
|
/*
|
2010-07-16 14:42:12 -07:00
|
|
|
* Get the number of CSS px (user units) per ex (i.e. the x-height in user
|
|
|
|
* units) for an nsIContent
|
|
|
|
*
|
|
|
|
* XXX document the conditions under which these may fail, and what they
|
|
|
|
* return in those cases.
|
2007-06-25 09:12:35 -07:00
|
|
|
*/
|
2010-04-30 06:12:06 -07:00
|
|
|
static float GetFontXHeight(mozilla::dom::Element *aElement);
|
2008-09-10 17:24:16 -07:00
|
|
|
static float GetFontXHeight(nsIFrame *aFrame);
|
2009-08-20 14:52:47 -07:00
|
|
|
static float GetFontXHeight(nsStyleContext *aStyleContext);
|
2007-06-25 09:12:35 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Converts image data from premultipled to unpremultiplied alpha
|
|
|
|
*/
|
|
|
|
static void UnPremultiplyImageDataAlpha(PRUint8 *data,
|
|
|
|
PRInt32 stride,
|
2008-08-25 02:23:54 -07:00
|
|
|
const nsIntRect &rect);
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Converts image data from unpremultipled to premultiplied alpha
|
|
|
|
*/
|
|
|
|
static void PremultiplyImageDataAlpha(PRUint8 *data,
|
|
|
|
PRInt32 stride,
|
2008-08-25 02:23:54 -07:00
|
|
|
const nsIntRect &rect);
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Converts image data from premultiplied sRGB to Linear RGB
|
|
|
|
*/
|
|
|
|
static void ConvertImageDataToLinearRGB(PRUint8 *data,
|
|
|
|
PRInt32 stride,
|
2008-08-25 02:23:54 -07:00
|
|
|
const nsIntRect &rect);
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Converts image data from LinearRGB to premultiplied sRGB
|
|
|
|
*/
|
|
|
|
static void ConvertImageDataFromLinearRGB(PRUint8 *data,
|
|
|
|
PRInt32 stride,
|
2008-08-25 02:23:54 -07:00
|
|
|
const nsIntRect &rect);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Report a localized error message to the error console.
|
|
|
|
*/
|
|
|
|
static nsresult ReportToConsole(nsIDocument* doc,
|
|
|
|
const char* aWarning,
|
|
|
|
const PRUnichar **aParams,
|
|
|
|
PRUint32 aParamsLength);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Converts a nsStyleCoord into a userspace value. Handles units
|
|
|
|
* Factor (straight userspace), Coord (dimensioned), and Percent (of
|
|
|
|
* the current SVG viewport)
|
|
|
|
*/
|
|
|
|
static float CoordToFloat(nsPresContext *aPresContext,
|
|
|
|
nsSVGElement *aContent,
|
|
|
|
const nsStyleCoord &aCoord);
|
2009-06-26 13:13:07 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static gfxMatrix GetCTM(nsSVGElement *aElement, bool aScreenCTM);
|
2009-07-21 13:34:37 -07:00
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
/**
|
|
|
|
* Check if this is one of the SVG elements that SVG 1.1 Full says
|
|
|
|
* establishes a viewport: svg, symbol, image or foreignObject.
|
2009-07-21 15:55:48 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool EstablishesViewport(nsIContent *aContent);
|
2009-07-23 01:35:59 -07:00
|
|
|
|
|
|
|
static already_AddRefed<nsIDOMSVGElement>
|
|
|
|
GetNearestViewportElement(nsIContent *aContent);
|
|
|
|
|
2009-04-24 16:17:43 -07:00
|
|
|
/**
|
|
|
|
* Gets the nearest nsSVGInnerSVGFrame or nsSVGOuterSVGFrame frame. aFrame
|
|
|
|
* must be an SVG frame. If aFrame is of type nsGkAtoms::svgOuterSVGFrame,
|
|
|
|
* returns nsnull.
|
|
|
|
*/
|
|
|
|
static nsSVGDisplayContainerFrame* GetNearestSVGViewport(nsIFrame *aFrame);
|
2009-07-23 01:35:59 -07:00
|
|
|
|
2008-07-22 19:15:27 -07:00
|
|
|
/**
|
2007-03-22 10:30:00 -07:00
|
|
|
* Figures out the worst case invalidation area for a frame, taking
|
2007-12-03 08:57:34 -08:00
|
|
|
* filters into account.
|
2009-06-11 08:23:43 -07:00
|
|
|
* Note that the caller is responsible for making sure that any cached
|
|
|
|
* covered regions in the frame tree rooted at aFrame are up to date.
|
2008-09-16 04:54:30 -07:00
|
|
|
* @param aRect the area in app units that needs to be invalidated in aFrame
|
|
|
|
* @return the rect in app units that should be invalidated, taking
|
2008-07-22 19:15:27 -07:00
|
|
|
* filters into account. Will return aRect when no filters are present.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-07-22 19:15:27 -07:00
|
|
|
static nsRect FindFilterInvalidation(nsIFrame *aFrame, const nsRect& aRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-12-04 10:17:45 -08:00
|
|
|
/**
|
2012-03-20 05:15:53 -07:00
|
|
|
* Invalidates the area that is painted by the frame without updating its
|
|
|
|
* bounds.
|
|
|
|
*
|
|
|
|
* This is similar to InvalidateOverflowRect(). It will go away when we
|
|
|
|
* support display list based invalidation of SVG.
|
2008-12-04 10:17:45 -08:00
|
|
|
*/
|
2012-03-20 05:15:53 -07:00
|
|
|
static void InvalidateBounds(nsIFrame *aFrame, bool aDuringUpdate = false);
|
2008-12-04 10:17:45 -08:00
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
/**
|
|
|
|
* Schedules an update of the frame's bounds (which will in turn invalidate
|
|
|
|
* the new area that the frame should paint to).
|
|
|
|
*
|
|
|
|
* This does nothing when passed an NS_STATE_SVG_NONDISPLAY_CHILD frame.
|
|
|
|
* In future we may want to allow UpdateBounds to be called on such frames,
|
|
|
|
* but that would be better implemented as a ForceUpdateBounds function to
|
|
|
|
* be called synchronously while painting them without marking or paying
|
|
|
|
* attention to dirty bits like this function.
|
|
|
|
*
|
|
|
|
* This is very similar to PresShell::FrameNeedsReflow. The main reason that
|
|
|
|
* we have this function instead of using FrameNeedsReflow is because we need
|
|
|
|
* to be able to call it under nsSVGOuterSVGFrame::NotifyViewportChange when
|
|
|
|
* that function is called by nsSVGOuterSVGFrame::Reflow. FrameNeedsReflow
|
|
|
|
* is not suitable for calling during reflow though, and it asserts as much.
|
|
|
|
* The reason that we want to be callable under NotifyViewportChange is
|
|
|
|
* because we want to synchronously notify and dirty the nsSVGOuterSVGFrame's
|
|
|
|
* children so that when nsSVGOuterSVGFrame::DidReflow is called its children
|
|
|
|
* will be updated for the new size as appropriate. Otherwise we'd have to
|
|
|
|
* post an event to the event loop to mark dirty flags and request an update.
|
|
|
|
*
|
|
|
|
* Another reason that we don't currently want to call
|
|
|
|
* PresShell::FrameNeedsReflow is because passing eRestyle to it to get it to
|
|
|
|
* mark descendants dirty would cause it to descend through
|
|
|
|
* nsSVGForeignObjectFrame frames to mark their children dirty, but we want to
|
|
|
|
* handle nsSVGForeignObjectFrame specially. It would also do unnecessary work
|
|
|
|
* descending into NS_STATE_SVG_NONDISPLAY_CHILD frames.
|
2008-04-08 05:51:19 -07:00
|
|
|
*/
|
2012-03-20 05:15:53 -07:00
|
|
|
static void ScheduleBoundsUpdate(nsIFrame *aFrame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invalidates the area that the frame last painted to, then schedules an
|
|
|
|
* update of the frame's bounds (which will in turn invalidate the new area
|
|
|
|
* that the frame should paint to).
|
|
|
|
*/
|
|
|
|
static void InvalidateAndScheduleBoundsUpdate(nsIFrame *aFrame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the frame or any of its children need UpdateBounds
|
|
|
|
* to be called on them.
|
|
|
|
*/
|
|
|
|
static bool NeedsUpdatedBounds(nsIFrame *aFrame);
|
2008-04-08 05:51:19 -07:00
|
|
|
|
2008-03-19 14:27:33 -07:00
|
|
|
/*
|
|
|
|
* Update the filter invalidation region for ancestor frames, if relevant.
|
|
|
|
*/
|
|
|
|
static void NotifyAncestorsOfFilterRegionChange(nsIFrame *aFrame);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* enum for specifying coordinate direction for ObjectSpace/UserSpace */
|
|
|
|
enum ctxDirection { X, Y, XY };
|
|
|
|
|
2008-07-15 01:46:54 -07:00
|
|
|
/**
|
|
|
|
* Computes sqrt((aWidth^2 + aHeight^2)/2);
|
|
|
|
*/
|
|
|
|
static double ComputeNormalizedHypotenuse(double aWidth, double aHeight);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Computes the input length in terms of object space coordinates.
|
|
|
|
Input: rect - bounding box
|
|
|
|
length - length to be converted
|
|
|
|
*/
|
2009-06-11 08:21:03 -07:00
|
|
|
static float ObjectSpace(const gfxRect &aRect, const nsSVGLength2 *aLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* Computes the input length in terms of user space coordinates.
|
|
|
|
Input: content - object to be used for determining user space
|
2008-09-10 17:24:16 -07:00
|
|
|
Input: length - length to be converted
|
|
|
|
*/
|
|
|
|
static float UserSpace(nsSVGElement *aSVGElement, const nsSVGLength2 *aLength);
|
|
|
|
|
|
|
|
/* Computes the input length in terms of user space coordinates.
|
|
|
|
Input: aFrame - object to be used for determining user space
|
2007-03-22 10:30:00 -07:00
|
|
|
length - length to be converted
|
|
|
|
*/
|
2008-09-10 17:24:16 -07:00
|
|
|
static float UserSpace(nsIFrame *aFrame, const nsSVGLength2 *aLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* Returns the angle halfway between the two specified angles */
|
|
|
|
static float
|
|
|
|
AngleBisect(float a1, float a2);
|
|
|
|
|
|
|
|
/* Find the outermost SVG frame of the passed frame */
|
|
|
|
static nsSVGOuterSVGFrame *
|
|
|
|
GetOuterSVGFrame(nsIFrame *aFrame);
|
|
|
|
|
2007-05-30 15:32:54 -07:00
|
|
|
/**
|
|
|
|
* Get the covered region for a frame. Return null if it's not an SVG frame.
|
2008-08-25 02:23:54 -07:00
|
|
|
* @param aRect gets a rectangle in app units
|
2007-05-30 15:32:54 -07:00
|
|
|
* @return the outer SVG frame which aRect is relative to
|
|
|
|
*/
|
|
|
|
static nsIFrame*
|
|
|
|
GetOuterSVGFrameAndCoveredRegion(nsIFrame* aFrame, nsRect* aRect);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Generate a viewbox to viewport tranformation matrix */
|
2010-12-19 16:45:29 -08:00
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
static gfxMatrix
|
2011-06-16 03:53:13 -07:00
|
|
|
GetViewBoxTransform(const nsSVGElement* aElement,
|
2010-02-07 18:28:01 -08:00
|
|
|
float aViewportWidth, float aViewportHeight,
|
2007-03-22 10:30:00 -07:00
|
|
|
float aViewboxX, float aViewboxY,
|
|
|
|
float aViewboxWidth, float aViewboxHeight,
|
2010-12-19 16:45:29 -08:00
|
|
|
const SVGAnimatedPreserveAspectRatio &aPreserveAspectRatio);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-12-19 16:45:29 -08:00
|
|
|
static gfxMatrix
|
2011-06-16 03:53:13 -07:00
|
|
|
GetViewBoxTransform(const nsSVGElement* aElement,
|
2010-12-19 16:45:29 -08:00
|
|
|
float aViewportWidth, float aViewportHeight,
|
|
|
|
float aViewboxX, float aViewboxY,
|
|
|
|
float aViewboxWidth, float aViewboxHeight,
|
|
|
|
const SVGPreserveAspectRatio &aPreserveAspectRatio);
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
/* Paint SVG frame with SVG effects - aDirtyRect is the area being
|
|
|
|
* redrawn, in device pixel coordinates relative to the outer svg */
|
2007-03-22 10:30:00 -07:00
|
|
|
static void
|
2012-03-02 00:28:59 -08:00
|
|
|
PaintFrameWithEffects(nsRenderingContext *aContext,
|
2008-10-20 01:42:03 -07:00
|
|
|
const nsIntRect *aDirtyRect,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame *aFrame);
|
|
|
|
|
|
|
|
/* Hit testing - check if point hits the clipPath of indicated
|
2008-08-25 02:23:54 -07:00
|
|
|
* frame. Returns true if no clipPath set. */
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2008-08-25 02:23:54 -07:00
|
|
|
HitTestClip(nsIFrame *aFrame, const nsPoint &aPoint);
|
2008-08-19 09:20:16 -07:00
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
/* Hit testing - check if point hits any children of frame. */
|
|
|
|
|
|
|
|
static nsIFrame *
|
|
|
|
HitTestChildren(nsIFrame *aFrame, const nsPoint &aPoint);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the CanvasTM of the indicated frame, whether it's a
|
2008-09-10 17:24:16 -07:00
|
|
|
* child SVG frame, container SVG frame, or a regular frame.
|
|
|
|
* For regular frames, we just return an identity matrix.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2009-04-28 21:31:34 -07:00
|
|
|
static gfxMatrix GetCanvasTM(nsIFrame* aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-20 06:26:34 -08:00
|
|
|
/*
|
2008-01-25 01:27:03 -08:00
|
|
|
* Tells child frames that something that might affect them has changed
|
2007-12-20 06:26:34 -08:00
|
|
|
*/
|
|
|
|
static void
|
2008-01-25 01:27:03 -08:00
|
|
|
NotifyChildrenOfSVGChange(nsIFrame *aFrame, PRUint32 aFlags);
|
2007-12-20 06:26:34 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Get frame's covered region by walking the children and doing union.
|
|
|
|
*/
|
|
|
|
static nsRect
|
|
|
|
GetCoveredRegion(const nsFrameList &aFrames);
|
|
|
|
|
2012-02-10 04:33:46 -08:00
|
|
|
// Converts aPoint from an app unit point in outer-<svg> content rect space
|
|
|
|
// to an app unit point in a frame's SVG userspace.
|
|
|
|
// This is a temporary helper we should no longer need after bug 614732 is
|
|
|
|
// fixed.
|
|
|
|
static nsPoint
|
|
|
|
TransformOuterSVGPointToChildFrame(nsPoint aPoint,
|
|
|
|
const gfxMatrix& aFrameToCanvasTM,
|
|
|
|
nsPresContext* aPresContext);
|
|
|
|
|
|
|
|
static nsRect
|
|
|
|
TransformFrameRectToOuterSVG(const nsRect& aRect,
|
|
|
|
const gfxMatrix& aMatrix,
|
|
|
|
nsPresContext* aPresContext);
|
|
|
|
|
2007-06-13 02:02:48 -07:00
|
|
|
/*
|
|
|
|
* Convert a surface size to an integer for use by thebes
|
|
|
|
* possibly making it smaller in the process so the surface does not
|
|
|
|
* use excessive memory.
|
2010-09-08 13:40:39 -07:00
|
|
|
*
|
2007-06-13 02:02:48 -07:00
|
|
|
* @param aSize the desired surface size
|
|
|
|
* @param aResultOverflows true if the desired surface size is too big
|
|
|
|
* @return the surface size to use
|
|
|
|
*/
|
2010-09-08 13:40:39 -07:00
|
|
|
static gfxIntSize ConvertToSurfaceSize(const gfxSize& aSize,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *aResultOverflows);
|
2007-06-13 02:02:48 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Hit test a given rectangle/matrix.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2009-07-23 01:35:59 -07:00
|
|
|
HitTestRect(const gfxMatrix &aMatrix,
|
2007-03-22 10:30:00 -07:00
|
|
|
float aRX, float aRY, float aRWidth, float aRHeight,
|
|
|
|
float aX, float aY);
|
|
|
|
|
|
|
|
|
2009-06-17 13:51:40 -07:00
|
|
|
/**
|
|
|
|
* Get the clip rect for the given frame, taking into account the CSS 'clip'
|
|
|
|
* property. See:
|
|
|
|
* http://www.w3.org/TR/SVG11/masking.html#OverflowAndClipProperties
|
|
|
|
* The arguments for aX, aY, aWidth and aHeight should be the dimensions of
|
|
|
|
* the viewport established by aFrame.
|
|
|
|
*/
|
|
|
|
static gfxRect
|
|
|
|
GetClipRectForFrame(nsIFrame *aFrame,
|
|
|
|
float aX, float aY, float aWidth, float aHeight);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static void CompositeSurfaceMatrix(gfxContext *aContext,
|
|
|
|
gfxASurface *aSurface,
|
2009-07-23 01:35:59 -07:00
|
|
|
const gfxMatrix &aCTM, float aOpacity);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-05 22:51:13 -08:00
|
|
|
static void CompositePatternMatrix(gfxContext *aContext,
|
|
|
|
gfxPattern *aPattern,
|
2009-07-23 01:35:59 -07:00
|
|
|
const gfxMatrix &aCTM, float aWidth, float aHeight, float aOpacity);
|
2008-03-05 22:51:13 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static void SetClipRect(gfxContext *aContext,
|
2009-06-18 04:31:25 -07:00
|
|
|
const gfxMatrix &aCTM,
|
2009-06-17 13:51:40 -07:00
|
|
|
const gfxRect &aRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-13 18:21:25 -07:00
|
|
|
/**
|
|
|
|
* Restricts aRect to pixels that intersect aGfxRect.
|
|
|
|
*/
|
|
|
|
static void ClipToGfxRect(nsIntRect* aRect, const gfxRect& aGfxRect);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Using group opacity instead of fill or stroke opacity on a
|
|
|
|
* geometry object seems to be a common authoring mistake. If we're
|
|
|
|
* not applying filters and not both stroking and filling, we can
|
|
|
|
* generate the same result without going through the overhead of a
|
|
|
|
* push/pop group. */
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
CanOptimizeOpacity(nsIFrame *aFrame);
|
|
|
|
|
2007-10-02 07:57:47 -07:00
|
|
|
/* Calculate the maximum expansion of a matrix */
|
|
|
|
static float
|
2009-07-23 01:35:59 -07:00
|
|
|
MaxExpansion(const gfxMatrix &aMatrix);
|
2007-10-02 07:57:47 -07:00
|
|
|
|
2009-06-11 08:21:03 -07:00
|
|
|
/**
|
|
|
|
* Take the CTM to userspace for an element, and adjust it to a CTM to its
|
|
|
|
* object bounding box space if aUnits is SVG_UNIT_TYPE_OBJECTBOUNDINGBOX.
|
|
|
|
* (I.e. so that [0,0] is at the top left of its bbox, and [1,1] is at the
|
|
|
|
* bottom right of its bbox).
|
|
|
|
*
|
|
|
|
* If the bbox is empty, this will return a singular matrix.
|
|
|
|
*/
|
2009-07-23 01:35:59 -07:00
|
|
|
static gfxMatrix
|
|
|
|
AdjustMatrixForUnits(const gfxMatrix &aMatrix,
|
2007-12-03 20:40:52 -08:00
|
|
|
nsSVGEnum *aUnits,
|
2008-09-10 17:24:16 -07:00
|
|
|
nsIFrame *aFrame);
|
|
|
|
|
2011-09-30 02:25:37 -07:00
|
|
|
enum BBoxFlags {
|
|
|
|
eBBoxIncludeFill = 1 << 0,
|
|
|
|
eBBoxIgnoreFillIfNone = 1 << 1,
|
|
|
|
eBBoxIncludeStroke = 1 << 2,
|
|
|
|
eBBoxIgnoreStrokeIfNone = 1 << 3,
|
|
|
|
eBBoxIncludeMarkers = 1 << 4
|
|
|
|
};
|
2008-09-10 17:24:16 -07:00
|
|
|
/**
|
2011-09-30 02:25:37 -07:00
|
|
|
* Get the SVG bbox (the SVG spec's simplified idea of bounds) of aFrame in
|
|
|
|
* aFrame's userspace.
|
2008-09-10 17:24:16 -07:00
|
|
|
*/
|
2011-09-30 02:25:37 -07:00
|
|
|
static gfxRect GetBBox(nsIFrame *aFrame, PRUint32 aFlags = eBBoxIncludeFill);
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
/**
|
|
|
|
* Compute a rectangle in userSpaceOnUse or objectBoundingBoxUnits.
|
|
|
|
* @param aXYWH pointer to 4 consecutive nsSVGLength2 objects containing
|
|
|
|
* the x, y, width and height values in that order
|
|
|
|
* @param aBBox the bounding box of the object the rect is relative to;
|
|
|
|
* may be null if aUnits is not SVG_UNIT_TYPE_OBJECTBOUNDINGBOX
|
|
|
|
* @param aFrame the object in which to interpret user-space units;
|
|
|
|
* may be null if aUnits is SVG_UNIT_TYPE_OBJECTBOUNDINGBOX
|
|
|
|
*/
|
|
|
|
static gfxRect
|
2009-06-11 08:21:03 -07:00
|
|
|
GetRelativeRect(PRUint16 aUnits, const nsSVGLength2 *aXYWH,
|
|
|
|
const gfxRect &aBBox, nsIFrame *aFrame);
|
2007-12-03 20:40:52 -08:00
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
/**
|
|
|
|
* Find the first frame, starting with aStartFrame and going up its
|
|
|
|
* parent chain, that is not an svgAFrame.
|
|
|
|
*/
|
|
|
|
static nsIFrame* GetFirstNonAAncestorFrame(nsIFrame* aStartFrame);
|
|
|
|
|
2007-09-17 08:20:35 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
static void
|
|
|
|
WritePPM(const char *fname, gfxImageSurface *aSurface);
|
2012-03-20 05:15:53 -07:00
|
|
|
|
|
|
|
static bool OuterSVGIsCallingUpdateBounds(nsIFrame *aFrame);
|
2007-09-17 08:20:35 -07:00
|
|
|
#endif
|
|
|
|
|
2009-03-31 05:19:39 -07:00
|
|
|
/**
|
|
|
|
* Compute the maximum possible device space stroke extents of a path given
|
|
|
|
* the path's device space path extents, its stroke style and its ctm.
|
|
|
|
*
|
|
|
|
* This is a workaround for the lack of suitable cairo API for getting the
|
|
|
|
* tight device space stroke extents of a path. This basically gives us the
|
|
|
|
* tightest extents that we can guarantee fully enclose the inked stroke
|
|
|
|
* without doing the calculations for the actual tight extents. We exploit
|
|
|
|
* the fact that cairo does have an API for getting the tight device space
|
|
|
|
* fill/path extents.
|
|
|
|
*
|
|
|
|
* This should die once bug 478152 is fixed.
|
|
|
|
*/
|
|
|
|
static gfxRect PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
|
2012-02-10 04:33:39 -08:00
|
|
|
nsSVGGeometryFrame* aFrame,
|
|
|
|
const gfxMatrix& aMatrix);
|
2011-09-05 10:53:34 -07:00
|
|
|
static gfxRect PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
|
2012-02-10 04:33:39 -08:00
|
|
|
nsSVGPathGeometryFrame* aFrame,
|
|
|
|
const gfxMatrix& aMatrix);
|
2009-03-31 05:19:39 -07:00
|
|
|
|
2010-09-08 13:40:39 -07:00
|
|
|
/**
|
|
|
|
* Convert a floating-point value to a 32-bit integer value, clamping to
|
|
|
|
* the range of valid integers.
|
|
|
|
*/
|
|
|
|
static PRInt32 ClampToInt(double aVal)
|
|
|
|
{
|
|
|
|
return NS_lround(NS_MAX(double(PR_INT32_MIN),
|
|
|
|
NS_MIN(double(PR_INT32_MAX), aVal)));
|
|
|
|
}
|
|
|
|
|
2010-10-06 15:18:52 -07:00
|
|
|
/**
|
|
|
|
* Given a nsIContent* that is actually an nsSVGSVGElement*, this method
|
|
|
|
* checks whether it currently has a valid viewBox, and returns true if so.
|
|
|
|
*
|
|
|
|
* No other type of element should be passed to this method.
|
|
|
|
* (In debug builds, anything non-<svg> will trigger an abort; in non-debug
|
2011-10-17 07:59:28 -07:00
|
|
|
* builds, it will trigger a false return-value as a safe fallback.)
|
2010-10-06 15:18:52 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool RootSVGElementHasViewbox(const nsIContent *aRootSVGElem);
|
2012-02-04 05:11:09 -08:00
|
|
|
|
|
|
|
static void GetFallbackOrPaintColor(gfxContext *aContext,
|
|
|
|
nsStyleContext *aStyleContext,
|
|
|
|
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
|
|
|
|
float *aOpacity, nscolor *color);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|