2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef NS_SVGUTILS_H
|
|
|
|
#define NS_SVGUTILS_H
|
|
|
|
|
2012-09-22 12:26:05 -07:00
|
|
|
// include math.h to pick up definition of M_ maths defines e.g. M_PI
|
2007-03-22 10:30:00 -07:00
|
|
|
#define _USE_MATH_DEFINES
|
|
|
|
#include <math.h>
|
|
|
|
|
2012-03-20 05:15:55 -07:00
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "gfxPoint.h"
|
|
|
|
#include "gfxRect.h"
|
|
|
|
#include "nsAlgorithm.h"
|
2012-05-16 21:05:09 -07:00
|
|
|
#include "nsChangeHint.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
#include "nsColor.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsISupportsBase.h"
|
|
|
|
#include "nsMathUtils.h"
|
|
|
|
#include "nsPoint.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsRect.h"
|
2012-09-05 21:58:46 -07:00
|
|
|
#include "nsStyleStruct.h"
|
2012-08-06 13:32:11 -07:00
|
|
|
#include "mozilla/Constants.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-20 05:15:55 -07:00
|
|
|
class gfxASurface;
|
|
|
|
class gfxContext;
|
|
|
|
class gfxImageSurface;
|
|
|
|
class gfxPattern;
|
|
|
|
class nsFrameList;
|
|
|
|
class nsIContent;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIDocument;
|
2012-03-20 05:15:55 -07:00
|
|
|
class nsIFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsPresContext;
|
2012-03-20 05:15:55 -07:00
|
|
|
class nsRenderingContext;
|
2009-08-20 14:52:47 -07:00
|
|
|
class nsStyleContext;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsStyleCoord;
|
2012-03-20 05:15:55 -07:00
|
|
|
class nsSVGDisplayContainerFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsSVGElement;
|
2007-12-03 20:40:52 -08:00
|
|
|
class nsSVGEnum;
|
2009-03-31 05:19:39 -07:00
|
|
|
class nsSVGGeometryFrame;
|
2012-03-20 05:15:55 -07:00
|
|
|
class nsSVGLength2;
|
|
|
|
class nsSVGOuterSVGFrame;
|
2011-09-05 10:53:34 -07:00
|
|
|
class nsSVGPathGeometryFrame;
|
2012-08-10 04:13:44 -07:00
|
|
|
class nsTextFrame;
|
2012-09-05 21:58:46 -07:00
|
|
|
class gfxTextObjectPaint;
|
2012-03-20 05:15:55 -07:00
|
|
|
|
|
|
|
struct nsStyleSVG;
|
|
|
|
struct nsStyleSVGPaint;
|
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
|
|
|
// 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
|
|
|
|
2012-08-10 04:13:43 -07:00
|
|
|
#define SVG_HIT_TEST_FILL 0x01
|
|
|
|
#define SVG_HIT_TEST_STROKE 0x02
|
|
|
|
#define SVG_HIT_TEST_CHECK_MRECT 0x04
|
|
|
|
|
2009-03-09 18:20:17 -07:00
|
|
|
/*
|
2012-09-22 12:26:05 -07:00
|
|
|
* Checks the smil enabled preference.
|
2009-03-09 18:20:17 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool NS_SMILEnabled();
|
2009-03-09 18:20:17 -07:00
|
|
|
|
2012-05-16 21:05:04 -07:00
|
|
|
bool NS_SVGDisplayListHitTestingEnabled();
|
|
|
|
bool NS_SVGDisplayListPaintingEnabled();
|
2012-08-08 04:46:06 -07:00
|
|
|
bool NS_SVGTextCSSFramesEnabled();
|
2012-05-16 21:05:04 -07:00
|
|
|
|
2012-04-16 01:23:48 -07:00
|
|
|
/**
|
|
|
|
* Sometimes we need to distinguish between an empty box and a box
|
|
|
|
* that contains an element that has no size e.g. a point at the origin.
|
|
|
|
*/
|
|
|
|
class SVGBBox {
|
|
|
|
public:
|
|
|
|
SVGBBox()
|
|
|
|
: mIsEmpty(true) {}
|
|
|
|
|
|
|
|
SVGBBox(const gfxRect& aRect)
|
|
|
|
: mBBox(aRect), mIsEmpty(false) {}
|
|
|
|
|
|
|
|
SVGBBox& operator=(const gfxRect& aRect) {
|
|
|
|
mBBox = aRect;
|
|
|
|
mIsEmpty = false;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator const gfxRect& () const {
|
|
|
|
return mBBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEmpty() const {
|
|
|
|
return mIsEmpty;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnionEdges(const SVGBBox& aSVGBBox) {
|
|
|
|
if (aSVGBBox.mIsEmpty) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mBBox = mIsEmpty ? aSVGBBox.mBBox : mBBox.UnionEdges(aSVGBBox.mBBox);
|
|
|
|
mIsEmpty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
gfxRect mBBox;
|
|
|
|
bool mIsEmpty;
|
|
|
|
};
|
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:
|
2012-06-15 02:06:34 -07:00
|
|
|
enum RenderMode {
|
|
|
|
/**
|
|
|
|
* Used to inform SVG frames that they should paint as normal.
|
|
|
|
*/
|
|
|
|
NORMAL,
|
|
|
|
/**
|
|
|
|
* Used to inform SVG frames when they are painting as the child of a
|
|
|
|
* simple clipPath. In this case they should only draw their basic geometry
|
|
|
|
* as a path. They should not fill, stroke, or paint anything else.
|
|
|
|
*/
|
|
|
|
CLIP,
|
|
|
|
/**
|
|
|
|
* Used to inform SVG frames when they are painting as the child of a
|
|
|
|
* complex clipPath that requires the use of a clip mask. In this case they
|
|
|
|
* should only draw their basic geometry as a path and then fill it using
|
|
|
|
* fully opaque white. They should not stroke, or paint anything else.
|
|
|
|
*/
|
|
|
|
CLIP_MASK
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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)
|
|
|
|
|
2012-09-22 12:26:05 -07:00
|
|
|
/**
|
|
|
|
* General functions used by all of SVG layout and possibly content code.
|
|
|
|
* If a method is used by content and depends only on other content methods
|
|
|
|
* it should go in SVGContentUtils instead.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsSVGUtils
|
|
|
|
{
|
|
|
|
public:
|
2010-12-19 16:45:29 -08:00
|
|
|
|
2012-05-16 21:05:04 -07:00
|
|
|
static void Init();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Converts image data from premultipled to unpremultiplied alpha
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static void UnPremultiplyImageDataAlpha(uint8_t *data,
|
|
|
|
int32_t 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
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static void PremultiplyImageDataAlpha(uint8_t *data,
|
|
|
|
int32_t 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
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static void ConvertImageDataToLinearRGB(uint8_t *data,
|
|
|
|
int32_t 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
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static void ConvertImageDataFromLinearRGB(uint8_t *data,
|
|
|
|
int32_t stride,
|
2008-08-25 02:23:54 -07:00
|
|
|
const nsIntRect &rect);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
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,
|
2012-07-30 07:20:58 -07:00
|
|
|
* returns nullptr.
|
2009-04-24 16:17:43 -07:00
|
|
|
*/
|
|
|
|
static nsSVGDisplayContainerFrame* GetNearestSVGViewport(nsIFrame *aFrame);
|
2012-05-16 21:05:09 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the frame's post-filter visual overflow rect when passed the
|
|
|
|
* frame's pre-filter visual overflow rect. If the frame is not currently
|
|
|
|
* being filtered, this function simply returns aUnfilteredRect.
|
|
|
|
*/
|
|
|
|
static nsRect GetPostFilterVisualOverflowRect(nsIFrame *aFrame,
|
|
|
|
const nsRect &aUnfilteredRect);
|
|
|
|
|
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.
|
2012-06-24 05:59:26 -07:00
|
|
|
*
|
|
|
|
* @param aBoundsSubArea If non-null, a sub-area of aFrame's pre-filter
|
|
|
|
* visual overflow rect that should be invalidated instead of aFrame's
|
|
|
|
* entire visual overflow rect.
|
2008-12-04 10:17:45 -08:00
|
|
|
*/
|
2012-06-24 05:59:26 -07:00
|
|
|
static void InvalidateBounds(nsIFrame *aFrame, bool aDuringUpdate = false,
|
2012-07-30 07:20:58 -07:00
|
|
|
const nsRect *aBoundsSubArea = nullptr,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags = 0);
|
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.
|
2012-07-21 17:01:44 -07:00
|
|
|
* In future we may want to allow ReflowSVG to be called on such frames,
|
|
|
|
* but that would be better implemented as a ForceReflowSVG function to
|
2012-03-20 05:15:53 -07:00
|
|
|
* 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-07-21 17:01:44 -07:00
|
|
|
static void ScheduleReflowSVG(nsIFrame *aFrame);
|
2012-03-20 05:15:53 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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).
|
|
|
|
*/
|
2012-07-21 17:01:44 -07:00
|
|
|
static void InvalidateAndScheduleReflowSVG(nsIFrame *aFrame);
|
2012-03-20 05:15:53 -07:00
|
|
|
|
|
|
|
/**
|
2012-07-21 17:01:44 -07:00
|
|
|
* Returns true if the frame or any of its children need ReflowSVG
|
2012-03-20 05:15:53 -07:00
|
|
|
* to be called on them.
|
|
|
|
*/
|
2012-07-21 17:01:44 -07:00
|
|
|
static bool NeedsReflowSVG(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
|
|
|
/* 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
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
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
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static gfxMatrix GetCanvasTM(nsIFrame* aFrame, uint32_t aFor);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-26 03:49:23 -07:00
|
|
|
/**
|
|
|
|
* Returns the transform from aFrame's user space to canvas space. Only call
|
|
|
|
* with SVG frames. This is like GetCanvasTM, except that it only includes
|
|
|
|
* the transforms from aFrame's user space (i.e. the coordinate context
|
|
|
|
* established by its 'transform' attribute, or else the coordinate context
|
|
|
|
* that its _parent_ establishes for its children) to outer-<svg> device
|
|
|
|
* space. Specifically, it does not include any other transforms introduced
|
|
|
|
* by the frame such as x/y offsets and viewBox attributes.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static gfxMatrix GetUserToCanvasTM(nsIFrame* aFrame, uint32_t aFor);
|
2012-06-26 03:49:23 -07:00
|
|
|
|
2012-06-23 09:36:46 -07:00
|
|
|
/**
|
|
|
|
* Notify the descendants of aFrame of a change to one of their ancestors
|
|
|
|
* that might affect them.
|
|
|
|
*
|
|
|
|
* If the changed ancestor renders and needs to be invalidated, it should
|
|
|
|
* call nsSVGUtils::InvalidateAndScheduleBoundsUpdate or
|
|
|
|
* nsSVGUtils::InvalidateBounds _before_ calling this method. That makes it
|
|
|
|
* cheaper when descendants schedule their own bounds update because the code
|
|
|
|
* that walks up the parent chain marking dirty bits can stop earlier.
|
2007-12-20 06:26:34 -08:00
|
|
|
*/
|
|
|
|
static void
|
2012-08-22 08:56:38 -07:00
|
|
|
NotifyChildrenOfSVGChange(nsIFrame *aFrame, uint32_t 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 {
|
2012-07-11 04:25:27 -07:00
|
|
|
eBBoxIncludeFill = 1 << 0,
|
|
|
|
eBBoxIncludeFillGeometry = 1 << 1,
|
|
|
|
eBBoxIncludeStroke = 1 << 2,
|
|
|
|
eBBoxIncludeStrokeGeometry = 1 << 3,
|
|
|
|
eBBoxIncludeMarkers = 1 << 4
|
2011-09-30 02:25:37 -07:00
|
|
|
};
|
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
|
|
|
*/
|
2012-07-11 04:25:27 -07:00
|
|
|
static gfxRect GetBBox(nsIFrame *aFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags = eBBoxIncludeFillGeometry);
|
2011-09-30 02:25:37 -07:00
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
/**
|
2012-04-13 06:22:06 -07:00
|
|
|
* Convert a userSpaceOnUse/objectBoundingBoxUnits rectangle that's specified
|
|
|
|
* using four nsSVGLength2 values into a user unit rectangle in user space.
|
|
|
|
*
|
2008-09-10 17:24:16 -07:00
|
|
|
* @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
|
2012-08-22 08:56:38 -07:00
|
|
|
GetRelativeRect(uint16_t aUnits, const nsSVGLength2 *aXYWH,
|
2009-06-11 08:21:03 -07:00
|
|
|
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);
|
|
|
|
|
2012-07-21 17:01:44 -07:00
|
|
|
static bool OuterSVGIsCallingReflowSVG(nsIFrame *aFrame);
|
2007-09-17 08:20:35 -07:00
|
|
|
|
2012-05-18 01:34:25 -07:00
|
|
|
/*
|
|
|
|
* Get any additional transforms that apply only to stroking
|
|
|
|
* e.g. non-scaling-stroke
|
|
|
|
*/
|
|
|
|
static gfxMatrix GetStrokeTransform(nsIFrame *aFrame);
|
|
|
|
|
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);
|
2012-08-10 04:13:44 -07:00
|
|
|
static gfxRect PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
|
|
|
|
nsTextFrame* 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.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t ClampToInt(double aVal)
|
2010-09-08 13:40:39 -07:00
|
|
|
{
|
2012-09-27 23:57:33 -07:00
|
|
|
return NS_lround(NS_MAX(double(INT32_MIN),
|
|
|
|
NS_MIN(double(INT32_MAX), aVal)));
|
2010-09-08 13:40:39 -07:00
|
|
|
}
|
|
|
|
|
2012-08-05 12:10:21 -07:00
|
|
|
static nscolor GetFallbackOrPaintColor(gfxContext *aContext,
|
|
|
|
nsStyleContext *aStyleContext,
|
|
|
|
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke);
|
|
|
|
|
2012-09-05 21:58:46 -07:00
|
|
|
/**
|
|
|
|
* Set up cairo context with an object pattern
|
|
|
|
*/
|
|
|
|
static bool SetupObjectPaint(gfxContext *aContext,
|
|
|
|
gfxTextObjectPaint *aObjectPaint,
|
|
|
|
const nsStyleSVGPaint& aPaint,
|
|
|
|
float aOpacity);
|
|
|
|
|
2012-08-05 12:10:21 -07:00
|
|
|
/**
|
2012-08-10 04:13:43 -07:00
|
|
|
* Sets the current paint on the specified gfxContent to be the SVG 'fill'
|
|
|
|
* for the given frame.
|
|
|
|
*/
|
2012-09-05 21:58:46 -07:00
|
|
|
static bool SetupCairoFillPaint(nsIFrame* aFrame, gfxContext* aContext,
|
|
|
|
gfxTextObjectPaint *aObjectPaint = nullptr);
|
2012-08-10 04:13:43 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the current paint on the specified gfxContent to be the SVG 'stroke'
|
|
|
|
* for the given frame.
|
|
|
|
*/
|
2012-09-05 21:58:46 -07:00
|
|
|
static bool SetupCairoStrokePaint(nsIFrame* aFrame, gfxContext* aContext,
|
|
|
|
gfxTextObjectPaint *aObjectPaint = nullptr);
|
2012-08-10 04:13:43 -07:00
|
|
|
|
2012-09-05 21:58:47 -07:00
|
|
|
static float GetOpacity(nsStyleSVGOpacitySource aOpacityType,
|
|
|
|
const float& aOpacity,
|
|
|
|
gfxTextObjectPaint *aOuterObjectPaint);
|
|
|
|
|
2012-08-10 04:13:43 -07:00
|
|
|
/*
|
|
|
|
* @return false if there is no stroke
|
|
|
|
*/
|
2012-09-05 21:58:47 -07:00
|
|
|
static bool HasStroke(nsIFrame* aFrame,
|
|
|
|
gfxTextObjectPaint *aObjectPaint = nullptr);
|
2012-08-10 04:13:43 -07:00
|
|
|
|
2012-09-05 21:58:47 -07:00
|
|
|
static float GetStrokeWidth(nsIFrame* aFrame,
|
|
|
|
gfxTextObjectPaint *aObjectPaint = nullptr);
|
2012-08-10 04:13:43 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up a cairo context for measuring a stroked path
|
|
|
|
*/
|
2012-09-05 21:58:47 -07:00
|
|
|
static void SetupCairoStrokeGeometry(nsIFrame* aFrame, gfxContext *aContext,
|
|
|
|
gfxTextObjectPaint *aObjectPaint = nullptr);
|
2012-08-10 04:13:43 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up a cairo context for hit testing a stroked path
|
2012-08-05 12:10:21 -07:00
|
|
|
*/
|
2012-09-05 21:58:47 -07:00
|
|
|
static void SetupCairoStrokeHitGeometry(nsIFrame* aFrame, gfxContext *aContext,
|
|
|
|
gfxTextObjectPaint *aObjectPaint = nullptr);
|
2012-08-10 04:13:43 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up a cairo context for stroking, including setting up any stroke-related
|
|
|
|
* properties such as dashing and setting the current paint on the gfxContext.
|
|
|
|
*/
|
2012-09-05 21:58:46 -07:00
|
|
|
static bool SetupCairoStroke(nsIFrame* aFrame, gfxContext *aContext,
|
|
|
|
gfxTextObjectPaint *aObjectPaint = nullptr);
|
2012-08-10 04:13:43 -07:00
|
|
|
|
2012-08-05 12:10:21 -07:00
|
|
|
/**
|
2012-08-10 04:13:43 -07:00
|
|
|
* This function returns a set of bit flags indicating which parts of the
|
|
|
|
* element (fill, stroke, bounds) should intercept pointer events. It takes
|
|
|
|
* into account the type of element and the value of the 'pointer-events'
|
|
|
|
* property on the element.
|
2012-08-05 12:10:21 -07:00
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint16_t GetGeometryHitTestFlags(nsIFrame* aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|