2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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/. */
|
2005-04-05 01:42:26 +04:00
|
|
|
|
|
|
|
#ifndef NS_SVGUTILS_H
|
|
|
|
#define NS_SVGUTILS_H
|
|
|
|
|
2012-09-22 23:26:05 +04:00
|
|
|
// include math.h to pick up definition of M_ maths defines e.g. M_PI
|
2006-01-26 19:39:39 +03:00
|
|
|
#include <math.h>
|
|
|
|
|
2016-04-22 13:52:19 +03:00
|
|
|
#include "DrawMode.h"
|
2017-12-11 18:37:59 +03:00
|
|
|
#include "ImgDrawResult.h"
|
2013-11-01 15:04:01 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "gfxPoint.h"
|
|
|
|
#include "gfxRect.h"
|
2013-11-01 15:04:01 +04:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
#include "nsAlgorithm.h"
|
2012-05-17 08:05:09 +04:00
|
|
|
#include "nsChangeHint.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
#include "nsColor.h"
|
2006-02-26 20:58:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
#include "nsID.h"
|
2015-04-27 13:15:36 +03:00
|
|
|
#include "nsIFrame.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
#include "nsISupportsBase.h"
|
|
|
|
#include "nsMathUtils.h"
|
2012-09-06 08:58:46 +04:00
|
|
|
#include "nsStyleStruct.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2005-09-15 03:30:37 +04:00
|
|
|
|
2012-03-20 16:15:55 +04:00
|
|
|
class gfxContext;
|
|
|
|
class nsFrameList;
|
|
|
|
class nsIContent;
|
2019-01-02 16:05:23 +03:00
|
|
|
|
2012-03-20 16:15:55 +04:00
|
|
|
class nsIFrame;
|
2005-04-05 01:42:26 +04:00
|
|
|
class nsPresContext;
|
2012-03-20 16:15:55 +04:00
|
|
|
class nsSVGDisplayContainerFrame;
|
|
|
|
class nsSVGOuterSVGFrame;
|
2012-08-10 15:13:44 +04:00
|
|
|
class nsTextFrame;
|
2012-03-20 16:15:55 +04:00
|
|
|
|
|
|
|
struct nsStyleSVG;
|
2013-09-07 06:15:49 +04:00
|
|
|
struct nsRect;
|
2005-04-05 01:42:26 +04:00
|
|
|
|
2010-04-30 17:12:06 +04:00
|
|
|
namespace mozilla {
|
2019-04-04 20:40:56 +03:00
|
|
|
class SVGAnimatedEnumeration;
|
2019-04-09 23:04:33 +03:00
|
|
|
class SVGAnimatedLength;
|
2016-07-22 16:56:09 +03:00
|
|
|
class SVGContextPaint;
|
2016-07-25 18:04:20 +03:00
|
|
|
struct SVGContextPaintImpl;
|
2016-12-18 14:11:47 +03:00
|
|
|
class SVGGeometryFrame;
|
2010-04-30 17:12:06 +04:00
|
|
|
namespace dom {
|
|
|
|
class Element;
|
2018-12-21 11:58:14 +03:00
|
|
|
class SVGElement;
|
2014-09-15 14:12:50 +04:00
|
|
|
class UserSpaceMetrics;
|
2010-04-30 17:12:06 +04:00
|
|
|
} // namespace dom
|
2013-11-27 15:25:29 +04:00
|
|
|
namespace gfx {
|
2014-09-30 21:08:13 +04:00
|
|
|
class DrawTarget;
|
2014-09-29 17:26:15 +04:00
|
|
|
class GeneralPattern;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
2010-04-30 17:12:06 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2007-06-13 13:02:48 +04:00
|
|
|
// maximum dimension of an offscreen surface - choose so that
|
|
|
|
// the surface size doesn't overflow a 32-bit signed int using
|
2016-06-10 15:32:01 +03:00
|
|
|
// 4 bytes per pixel; in line with Factory::CheckSurfaceSize
|
2009-12-28 12:49:08 +03:00
|
|
|
// In fact Macs can't even manage that
|
|
|
|
#define NS_SVG_OFFSCREEN_MAX_DIMENSION 4096
|
2007-06-13 13:02:48 +04:00
|
|
|
|
2012-08-10 15:13:43 +04:00
|
|
|
#define SVG_HIT_TEST_FILL 0x01
|
|
|
|
#define SVG_HIT_TEST_STROKE 0x02
|
|
|
|
#define SVG_HIT_TEST_CHECK_MRECT 0x04
|
|
|
|
|
2012-05-17 08:05:04 +04:00
|
|
|
bool NS_SVGDisplayListHitTestingEnabled();
|
|
|
|
bool NS_SVGDisplayListPaintingEnabled();
|
2014-05-13 05:24:35 +04:00
|
|
|
bool NS_SVGNewGetBBoxEnabled();
|
2012-05-17 08:05:04 +04:00
|
|
|
|
2012-04-16 12:23:48 +04: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 {
|
2013-11-01 15:04:01 +04:00
|
|
|
typedef mozilla::gfx::Rect Rect;
|
|
|
|
|
2012-04-16 12:23:48 +04:00
|
|
|
public:
|
|
|
|
SVGBBox() : mIsEmpty(true) {}
|
|
|
|
|
2014-08-20 08:58:22 +04:00
|
|
|
MOZ_IMPLICIT SVGBBox(const Rect& aRect) : mBBox(aRect), mIsEmpty(false) {}
|
2012-04-16 12:23:48 +04:00
|
|
|
|
2014-08-20 08:58:22 +04:00
|
|
|
MOZ_IMPLICIT SVGBBox(const gfxRect& aRect)
|
2013-11-01 15:04:01 +04:00
|
|
|
: mBBox(ToRect(aRect)), mIsEmpty(false) {}
|
2012-04-16 12:23:48 +04:00
|
|
|
|
2017-02-27 14:43:16 +03:00
|
|
|
operator const Rect&() { return mBBox; }
|
|
|
|
|
2013-11-01 15:04:01 +04:00
|
|
|
gfxRect ToThebesRect() const { return ThebesRect(mBBox); }
|
2012-04-16 12:23:48 +04:00
|
|
|
|
|
|
|
bool IsEmpty() const { return mIsEmpty; }
|
|
|
|
|
2014-07-05 22:19:13 +04:00
|
|
|
bool IsFinite() const { return mBBox.IsFinite(); }
|
|
|
|
|
|
|
|
void Scale(float aScale) { mBBox.Scale(aScale); }
|
|
|
|
|
2012-04-16 12:23:48 +04:00
|
|
|
void UnionEdges(const SVGBBox& aSVGBBox) {
|
|
|
|
if (aSVGBBox.mIsEmpty) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mBBox = mIsEmpty ? aSVGBBox.mBBox : mBBox.UnionEdges(aSVGBBox.mBBox);
|
|
|
|
mIsEmpty = false;
|
|
|
|
}
|
|
|
|
|
2014-05-13 05:24:35 +04:00
|
|
|
void Intersect(const SVGBBox& aSVGBBox) {
|
|
|
|
if (!mIsEmpty && !aSVGBBox.mIsEmpty) {
|
|
|
|
mBBox = mBBox.Intersect(aSVGBBox.mBBox);
|
|
|
|
if (mBBox.IsEmpty()) {
|
|
|
|
mIsEmpty = true;
|
|
|
|
mBBox = Rect(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mIsEmpty = true;
|
|
|
|
mBBox = Rect(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-16 12:23:48 +04:00
|
|
|
private:
|
2013-11-01 15:04:01 +04:00
|
|
|
Rect mBBox;
|
|
|
|
bool mIsEmpty;
|
2012-04-16 12:23:48 +04:00
|
|
|
};
|
2012-03-02 12:28:59 +04:00
|
|
|
|
2008-08-06 05:58:29 +04:00
|
|
|
// GRRR WINDOWS HATE HATE HATE
|
|
|
|
#undef CLIP_MASK
|
|
|
|
|
2015-09-03 19:15:23 +03:00
|
|
|
class MOZ_RAII SVGAutoRenderState {
|
2014-09-30 21:08:13 +04:00
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
|
|
|
|
2006-11-27 20:30:57 +03:00
|
|
|
public:
|
2014-10-11 12:24:44 +04:00
|
|
|
explicit SVGAutoRenderState(
|
|
|
|
DrawTarget* aDrawTarget MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
|
2012-03-02 12:28:59 +04:00
|
|
|
~SVGAutoRenderState();
|
2006-11-27 20:30:57 +03:00
|
|
|
|
2012-03-02 12:28:59 +04:00
|
|
|
void SetPaintingToWindow(bool aPaintingToWindow);
|
2006-11-27 20:30:57 +03:00
|
|
|
|
2014-09-30 21:08:13 +04:00
|
|
|
static bool IsPaintingToWindow(DrawTarget* aDrawTarget);
|
2010-10-15 05:03:45 +04:00
|
|
|
|
2006-11-27 20:30:57 +03:00
|
|
|
private:
|
2014-09-30 21:08:13 +04:00
|
|
|
DrawTarget* mDrawTarget;
|
|
|
|
void* mOriginalRenderState;
|
2012-03-02 12:28:59 +04:00
|
|
|
bool mPaintingToWindow;
|
2013-12-26 22:49:49 +04:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2006-11-27 20:30:57 +03:00
|
|
|
};
|
|
|
|
|
2012-09-22 23:26:05 +04: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.
|
|
|
|
*/
|
2005-04-05 01:42:26 +04:00
|
|
|
class nsSVGUtils {
|
|
|
|
public:
|
2012-12-12 03:15:07 +04:00
|
|
|
typedef mozilla::dom::Element Element;
|
2018-12-21 11:58:14 +03:00
|
|
|
typedef mozilla::dom::SVGElement SVGElement;
|
2014-11-05 12:16:37 +03:00
|
|
|
typedef mozilla::gfx::AntialiasMode AntialiasMode;
|
2016-04-22 13:52:19 +03:00
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
2014-09-29 17:15:19 +04:00
|
|
|
typedef mozilla::gfx::FillRule FillRule;
|
2014-09-29 17:26:15 +04:00
|
|
|
typedef mozilla::gfx::GeneralPattern GeneralPattern;
|
2015-05-25 00:40:37 +03:00
|
|
|
typedef mozilla::gfx::Size Size;
|
2019-04-09 23:04:33 +03:00
|
|
|
typedef mozilla::SVGAnimatedLength SVGAnimatedLength;
|
2016-07-22 16:56:09 +03:00
|
|
|
typedef mozilla::SVGContextPaint SVGContextPaint;
|
2016-07-25 18:04:20 +03:00
|
|
|
typedef mozilla::SVGContextPaintImpl SVGContextPaintImpl;
|
2016-12-18 14:11:47 +03:00
|
|
|
typedef mozilla::SVGGeometryFrame SVGGeometryFrame;
|
2017-05-18 23:03:41 +03:00
|
|
|
typedef mozilla::image::imgDrawingParams imgDrawingParams;
|
2010-12-20 03:45:29 +03:00
|
|
|
|
2016-01-28 06:23:59 +03:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(ObjectBoundingBoxProperty, gfxRect)
|
2015-04-27 13:15:36 +03:00
|
|
|
|
2009-04-25 03:17:43 +04:00
|
|
|
/**
|
2012-05-17 08:05:09 +04: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,
|
2019-04-27 10:57:50 +03:00
|
|
|
const nsRect& aPreFilterRect);
|
2012-05-17 08:05:09 +04:00
|
|
|
|
2012-03-20 16:15:53 +04:00
|
|
|
/**
|
|
|
|
* Schedules an update of the frame's bounds (which will in turn invalidate
|
|
|
|
* the new area that the frame should paint to).
|
|
|
|
*
|
2013-07-12 11:13:07 +04:00
|
|
|
* This does nothing when passed an NS_FRAME_IS_NONDISPLAY frame.
|
2012-07-22 04:01:44 +04: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 16:15:53 +04: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
|
2013-07-12 11:13:07 +04:00
|
|
|
* descending into NS_FRAME_IS_NONDISPLAY frames.
|
2008-04-08 16:51:19 +04:00
|
|
|
*/
|
2012-07-22 04:01:44 +04:00
|
|
|
static void ScheduleReflowSVG(nsIFrame* aFrame);
|
2012-03-20 16:15:53 +04:00
|
|
|
|
|
|
|
/**
|
2012-07-22 04:01:44 +04:00
|
|
|
* Returns true if the frame or any of its children need ReflowSVG
|
2012-03-20 16:15:53 +04:00
|
|
|
* to be called on them.
|
|
|
|
*/
|
2012-07-22 04:01:44 +04:00
|
|
|
static bool NeedsReflowSVG(nsIFrame* aFrame);
|
2008-04-08 16:51:19 +04:00
|
|
|
|
2015-05-25 00:40:37 +03:00
|
|
|
/**
|
|
|
|
* Percentage lengths in SVG are resolved against the width/height of the
|
|
|
|
* nearest viewport (or its viewBox, if set). This helper returns the size
|
|
|
|
* of this "context" for the given frame so that percentage values can be
|
|
|
|
* resolved.
|
|
|
|
*/
|
|
|
|
static Size GetContextSize(const nsIFrame* aFrame);
|
|
|
|
|
2005-09-07 02:30:40 +04:00
|
|
|
/* Computes the input length in terms of object space coordinates.
|
|
|
|
Input: rect - bounding box
|
|
|
|
length - length to be converted
|
|
|
|
*/
|
2019-04-09 23:04:33 +03:00
|
|
|
static float ObjectSpace(const gfxRect& aRect,
|
|
|
|
const SVGAnimatedLength* aLength);
|
2005-09-07 02:30:40 +04:00
|
|
|
|
|
|
|
/* Computes the input length in terms of user space coordinates.
|
|
|
|
Input: content - object to be used for determining user space
|
2008-09-11 04:24:16 +04:00
|
|
|
Input: length - length to be converted
|
|
|
|
*/
|
2019-04-09 23:04:33 +03:00
|
|
|
static float UserSpace(SVGElement* aSVGElement,
|
|
|
|
const SVGAnimatedLength* aLength);
|
2019-04-27 10:57:50 +03:00
|
|
|
static float UserSpace(nsIFrame* aNonSVGContext,
|
|
|
|
const SVGAnimatedLength* aLength);
|
2017-03-23 11:53:47 +03:00
|
|
|
static float UserSpace(const mozilla::dom::UserSpaceMetrics& aMetrics,
|
2019-04-09 23:04:33 +03:00
|
|
|
const SVGAnimatedLength* aLength);
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2006-02-14 00:22:41 +03:00
|
|
|
/* Find the outermost SVG frame of the passed frame */
|
2017-03-23 11:53:47 +03:00
|
|
|
static nsSVGOuterSVGFrame* GetOuterSVGFrame(nsIFrame* aFrame);
|
2006-02-14 00:22:41 +03:00
|
|
|
|
2007-05-31 02:32:54 +04:00
|
|
|
/**
|
|
|
|
* Get the covered region for a frame. Return null if it's not an SVG frame.
|
2008-08-25 13:23:54 +04:00
|
|
|
* @param aRect gets a rectangle in app units
|
2007-05-31 02:32:54 +04:00
|
|
|
* @return the outer SVG frame which aRect is relative to
|
|
|
|
*/
|
2017-03-23 11:53:47 +03:00
|
|
|
static nsIFrame* GetOuterSVGFrameAndCoveredRegion(nsIFrame* aFrame,
|
|
|
|
nsRect* aRect);
|
2007-05-31 02:32:54 +04:00
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
/* Paint SVG frame with SVG effects - aDirtyRect is the area being
|
|
|
|
* redrawn, in device pixel coordinates relative to the outer svg */
|
2017-05-18 23:03:41 +03:00
|
|
|
static void PaintFrameWithEffects(nsIFrame* aFrame, gfxContext& aContext,
|
|
|
|
const gfxMatrix& aTransform,
|
|
|
|
imgDrawingParams& aImgParams,
|
|
|
|
const nsIntRect* aDirtyRect = nullptr);
|
2006-03-21 18:49:20 +03:00
|
|
|
|
|
|
|
/* Hit testing - check if point hits the clipPath of indicated
|
2008-08-25 13:23:54 +04:00
|
|
|
* frame. Returns true if no clipPath set. */
|
2017-03-23 11:53:47 +03:00
|
|
|
static bool HitTestClip(nsIFrame* aFrame, const gfxPoint& aPoint);
|
|
|
|
|
2014-08-07 11:09:31 +04:00
|
|
|
/**
|
|
|
|
* Hit testing - check if point hits any children of aFrame. aPoint is
|
|
|
|
* expected to be in the coordinate space established by aFrame for its
|
|
|
|
* children (e.g. the space established by the 'viewBox' attribute on <svg>).
|
|
|
|
*/
|
2017-03-23 11:53:47 +03:00
|
|
|
static nsIFrame* HitTestChildren(nsSVGDisplayContainerFrame* aFrame,
|
|
|
|
const gfxPoint& aPoint);
|
2006-03-21 18:49:20 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the CanvasTM of the indicated frame, whether it's a
|
2008-09-11 04:24:16 +04:00
|
|
|
* child SVG frame, container SVG frame, or a regular frame.
|
|
|
|
* For regular frames, we just return an identity matrix.
|
2006-03-21 18:49:20 +03:00
|
|
|
*/
|
2014-09-08 15:28:50 +04:00
|
|
|
static gfxMatrix GetCanvasTM(nsIFrame* aFrame);
|
2006-03-21 18:49:20 +03:00
|
|
|
|
2012-06-23 20:36:46 +04:00
|
|
|
/**
|
|
|
|
* Notify the descendants of aFrame of a change to one of their ancestors
|
|
|
|
* that might affect them.
|
2007-12-20 17:26:34 +03:00
|
|
|
*/
|
2017-03-23 11:53:47 +03:00
|
|
|
static void NotifyChildrenOfSVGChange(nsIFrame* aFrame, uint32_t aFlags);
|
2007-12-20 17:26:34 +03:00
|
|
|
|
2017-03-23 11:53:47 +03:00
|
|
|
static nsRect TransformFrameRectToOuterSVG(const nsRect& aRect,
|
|
|
|
const gfxMatrix& aMatrix,
|
|
|
|
nsPresContext* aPresContext);
|
2012-02-10 16:33:46 +04:00
|
|
|
|
2007-06-13 13:02:48 +04: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-09 00:40:39 +04:00
|
|
|
*
|
2007-06-13 13:02:48 +04:00
|
|
|
* @param aSize the desired surface size
|
|
|
|
* @param aResultOverflows true if the desired surface size is too big
|
|
|
|
* @return the surface size to use
|
|
|
|
*/
|
2015-09-23 21:49:05 +03:00
|
|
|
static mozilla::gfx::IntSize ConvertToSurfaceSize(const gfxSize& aSize,
|
|
|
|
bool* aResultOverflows);
|
2007-06-13 13:02:48 +04:00
|
|
|
|
2006-09-19 20:35:29 +04:00
|
|
|
/*
|
|
|
|
* Hit test a given rectangle/matrix.
|
|
|
|
*/
|
2017-03-23 11:53:47 +03:00
|
|
|
static bool HitTestRect(const mozilla::gfx::Matrix& aMatrix, float aRX,
|
|
|
|
float aRY, float aRWidth, float aRHeight, float aX,
|
|
|
|
float aY);
|
2006-09-27 02:27:56 +04:00
|
|
|
|
2009-06-18 00:51:40 +04: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.
|
|
|
|
*/
|
2017-03-23 11:53:47 +03:00
|
|
|
static gfxRect GetClipRectForFrame(nsIFrame* aFrame, float aX, float aY,
|
|
|
|
float aWidth, float aHeight);
|
2009-06-18 00:51:40 +04:00
|
|
|
|
2006-11-27 20:30:57 +03:00
|
|
|
static void SetClipRect(gfxContext* aContext, const gfxMatrix& aCTM,
|
2009-06-18 00:51:40 +04:00
|
|
|
const gfxRect& aRect);
|
2006-11-27 20:30:57 +03:00
|
|
|
|
2007-01-04 18:05:39 +03: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. */
|
2017-03-23 11:53:47 +03:00
|
|
|
static bool CanOptimizeOpacity(nsIFrame* aFrame);
|
2007-01-04 18:05:39 +03:00
|
|
|
|
2009-06-11 19:21:03 +04: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.
|
2017-08-17 04:52:17 +03:00
|
|
|
*
|
|
|
|
* @param aFlags One or more of the BBoxFlags values defined below.
|
2009-06-11 19:21:03 +04:00
|
|
|
*/
|
2017-03-23 11:53:47 +03:00
|
|
|
static gfxMatrix AdjustMatrixForUnits(const gfxMatrix& aMatrix,
|
2019-04-04 20:40:56 +03:00
|
|
|
mozilla::SVGAnimatedEnumeration* aUnits,
|
2019-01-02 21:24:11 +03:00
|
|
|
nsIFrame* aFrame, uint32_t aFlags);
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2011-09-30 13:25:37 +04:00
|
|
|
enum BBoxFlags {
|
2012-07-11 15:25:27 +04:00
|
|
|
eBBoxIncludeFill = 1 << 0,
|
2017-09-01 20:31:57 +03:00
|
|
|
// Include the geometry of the fill even when the fill does not
|
|
|
|
// actually render (e.g. when fill="none" or fill-opacity="0")
|
2012-07-11 15:25:27 +04:00
|
|
|
eBBoxIncludeFillGeometry = 1 << 1,
|
|
|
|
eBBoxIncludeStroke = 1 << 2,
|
2017-09-01 20:31:57 +03:00
|
|
|
// Include the geometry of the stroke even when the stroke does not
|
|
|
|
// actually render (e.g. when stroke="none" or stroke-opacity="0")
|
2012-07-11 15:25:27 +04:00
|
|
|
eBBoxIncludeStrokeGeometry = 1 << 3,
|
2014-05-13 05:24:35 +04:00
|
|
|
eBBoxIncludeMarkers = 1 << 4,
|
2017-03-15 13:36:53 +03:00
|
|
|
eBBoxIncludeClipped = 1 << 5,
|
|
|
|
// Normally a getBBox call on outer-<svg> should only return the
|
2017-08-17 04:52:17 +03:00
|
|
|
// bounds of the elements children. This flag will cause the
|
2017-03-15 13:36:53 +03:00
|
|
|
// element's bounds to be returned instead.
|
2017-02-27 14:43:16 +03:00
|
|
|
eUseFrameBoundsForOuterSVG = 1 << 6,
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
|
|
|
|
eForGetClientRects = 1 << 7,
|
2017-08-17 04:52:17 +03:00
|
|
|
// If the given frame is an HTML element, only include the region of the
|
|
|
|
// given frame, instead of all continuations of it, while computing bbox if
|
|
|
|
// this flag is set.
|
|
|
|
eIncludeOnlyCurrentFrameForNonSVGElement = 1 << 8,
|
2017-08-29 15:41:45 +03:00
|
|
|
// This flag is only has an effect when the target is a <use> element.
|
|
|
|
// getBBox returns the bounds of the elements children in user space if
|
|
|
|
// this flag is set; Otherwise, getBBox returns the union bounds in
|
|
|
|
// the coordinate system formed by the <use> element.
|
|
|
|
eUseUserSpaceOfUseElement = 1 << 9,
|
2018-05-12 01:55:30 +03:00
|
|
|
// For a frame with a clip-path, if this flag is set then the result
|
|
|
|
// will not be clipped to the bbox of the content inside the clip-path.
|
|
|
|
eDoNotClipToBBoxOfContentInsideClipPath = 1 << 10,
|
2011-09-30 13:25:37 +04:00
|
|
|
};
|
2008-09-11 04:24:16 +04:00
|
|
|
/**
|
2017-02-27 14:43:16 +03:00
|
|
|
* This function in primarily for implementing the SVG DOM function getBBox()
|
|
|
|
* and the SVG attribute value 'objectBoundingBox'. However, it has been
|
|
|
|
* extended with various extra parameters in order to become more of a
|
|
|
|
* general purpose getter of all sorts of bounds that we might need to obtain
|
|
|
|
* for SVG elements, or even for other elements that have SVG effects applied
|
|
|
|
* to them.
|
|
|
|
*
|
|
|
|
* @param aFrame The frame of the element for which the bounds are to be
|
|
|
|
* obtained.
|
|
|
|
* @param aFlags One or more of the BBoxFlags values defined above.
|
|
|
|
* @param aToBoundsSpace If not specified the returned rect is in aFrame's
|
2017-08-17 04:52:17 +03:00
|
|
|
* element's "user space". A matrix can optionally be pass to specify a
|
2017-02-27 14:43:16 +03:00
|
|
|
* transform from aFrame's user space to the bounds space of interest
|
|
|
|
* (typically this will be the ancestor nsSVGOuterSVGFrame, but it could be
|
|
|
|
* to any other coordinate space).
|
2008-09-11 04:24:16 +04:00
|
|
|
*/
|
2012-07-11 15:25:27 +04:00
|
|
|
static gfxRect GetBBox(nsIFrame* aFrame,
|
2015-04-27 13:15:36 +03:00
|
|
|
// If the default arg changes, update the handling for
|
|
|
|
// ObjectBoundingBoxProperty() in the implementation.
|
2017-02-27 14:43:16 +03:00
|
|
|
uint32_t aFlags = eBBoxIncludeFillGeometry,
|
|
|
|
const gfxMatrix* aToBoundsSpace = nullptr);
|
2011-09-30 13:25:37 +04:00
|
|
|
|
2014-04-23 13:47:42 +04:00
|
|
|
/*
|
|
|
|
* "User space" is the space that the frame's BBox (as calculated by
|
|
|
|
* nsSVGUtils::GetBBox) is in. "Frame space" is the space that has its origin
|
|
|
|
* at the top left of the union of the frame's border-box rects over all
|
|
|
|
* continuations.
|
|
|
|
* This function returns the offset one needs to add to something in frame
|
|
|
|
* space in order to get its coordinates in user space.
|
|
|
|
*/
|
|
|
|
static gfxPoint FrameSpaceInCSSPxToUserSpaceOffset(nsIFrame* aFrame);
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
/**
|
2012-04-13 17:22:06 +04:00
|
|
|
* Convert a userSpaceOnUse/objectBoundingBoxUnits rectangle that's specified
|
2019-04-09 23:04:33 +03:00
|
|
|
* using four SVGAnimatedLength values into a user unit rectangle in user
|
|
|
|
* space.
|
2012-04-13 17:22:06 +04:00
|
|
|
*
|
2019-04-09 23:04:33 +03:00
|
|
|
* @param aXYWH pointer to 4 consecutive SVGAnimatedLength objects containing
|
2008-09-11 04:24:16 +04:00
|
|
|
* 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
|
|
|
|
*/
|
2019-04-09 23:04:33 +03:00
|
|
|
static gfxRect GetRelativeRect(uint16_t aUnits,
|
|
|
|
const SVGAnimatedLength* aXYWH,
|
2017-03-23 11:53:47 +03:00
|
|
|
const gfxRect& aBBox, nsIFrame* aFrame);
|
2014-09-15 14:12:50 +04:00
|
|
|
|
2017-03-23 11:53:47 +03:00
|
|
|
static gfxRect GetRelativeRect(
|
2019-04-09 23:04:33 +03:00
|
|
|
uint16_t aUnits, const SVGAnimatedLength* aXYWH, const gfxRect& aBBox,
|
2017-03-23 11:53:47 +03:00
|
|
|
const mozilla::dom::UserSpaceMetrics& aMetrics);
|
2007-12-04 07:40:52 +03:00
|
|
|
|
2009-01-19 21:31:34 +03: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-22 04:01:44 +04:00
|
|
|
static bool OuterSVGIsCallingReflowSVG(nsIFrame* aFrame);
|
2013-06-03 18:15:29 +04:00
|
|
|
static bool AnyOuterSVGIsCallingReflowSVG(nsIFrame* aFrame);
|
2007-09-17 19:20:35 +04:00
|
|
|
|
2014-09-30 21:08:14 +04:00
|
|
|
/**
|
|
|
|
* See https://svgwg.org/svg2-draft/painting.html#NonScalingStroke
|
|
|
|
*
|
|
|
|
* If the computed value of the 'vector-effect' property on aFrame is
|
|
|
|
* 'non-scaling-stroke', then this function will set aUserToOuterSVG to the
|
|
|
|
* transform from aFrame's SVG user space to the initial coordinate system
|
|
|
|
* established by the viewport of aFrame's outer-<svg>'s (the coordinate
|
|
|
|
* system in which the stroke is fixed). If aUserToOuterSVG is set to a
|
|
|
|
* non-identity matrix this function returns true, else it returns false.
|
2012-05-18 12:34:25 +04:00
|
|
|
*/
|
2014-09-30 21:08:14 +04:00
|
|
|
static bool GetNonScalingStrokeTransform(nsIFrame* aFrame,
|
|
|
|
gfxMatrix* aUserToOuterSVG);
|
2012-05-18 12:34:25 +04:00
|
|
|
|
2009-03-31 16:19:39 +04: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.
|
|
|
|
*/
|
2012-08-10 15:13:44 +04:00
|
|
|
static gfxRect PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
|
|
|
|
nsTextFrame* aFrame,
|
|
|
|
const gfxMatrix& aMatrix);
|
2011-09-05 21:53:34 +04:00
|
|
|
static gfxRect PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
|
2016-12-18 14:11:47 +03:00
|
|
|
SVGGeometryFrame* aFrame,
|
2012-02-10 16:33:39 +04:00
|
|
|
const gfxMatrix& aMatrix);
|
2009-03-31 16:19:39 +04:00
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
/**
|
|
|
|
* Convert a floating-point value to a 32-bit integer value, clamping to
|
|
|
|
* the range of valid integers.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t ClampToInt(double aVal) {
|
2013-01-15 16:22:03 +04:00
|
|
|
return NS_lround(
|
|
|
|
std::max(double(INT32_MIN), std::min(double(INT32_MAX), aVal)));
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
static nscolor GetFallbackOrPaintColor(
|
2019-07-06 11:31:02 +03:00
|
|
|
const mozilla::ComputedStyle&,
|
|
|
|
mozilla::StyleSVGPaint nsStyleSVG::*aFillOrStroke);
|
2012-08-05 23:10:21 +04:00
|
|
|
|
2017-05-18 23:03:41 +03:00
|
|
|
static void MakeFillPatternFor(nsIFrame* aFrame, gfxContext* aContext,
|
|
|
|
GeneralPattern* aOutPattern,
|
|
|
|
imgDrawingParams& aImgParams,
|
|
|
|
SVGContextPaint* aContextPaint = nullptr);
|
2012-08-10 15:13:43 +04:00
|
|
|
|
2014-09-29 17:12:06 +04:00
|
|
|
static void MakeStrokePatternFor(nsIFrame* aFrame, gfxContext* aContext,
|
2014-09-29 17:26:15 +04:00
|
|
|
GeneralPattern* aOutPattern,
|
2017-05-18 23:03:41 +03:00
|
|
|
imgDrawingParams& aImgParams,
|
|
|
|
SVGContextPaint* aContextPaint = nullptr);
|
2012-08-10 15:13:43 +04:00
|
|
|
|
2012-09-06 08:58:47 +04:00
|
|
|
static float GetOpacity(nsStyleSVGOpacitySource aOpacityType,
|
|
|
|
const float& aOpacity,
|
2016-07-22 16:56:09 +03:00
|
|
|
SVGContextPaint* aContextPaint);
|
2012-09-06 08:58:47 +04:00
|
|
|
|
2012-08-10 15:13:43 +04:00
|
|
|
/*
|
|
|
|
* @return false if there is no stroke
|
|
|
|
*/
|
2012-09-06 08:58:47 +04:00
|
|
|
static bool HasStroke(nsIFrame* aFrame,
|
2016-07-22 16:56:09 +03:00
|
|
|
SVGContextPaint* aContextPaint = nullptr);
|
2012-08-10 15:13:43 +04:00
|
|
|
|
2012-09-06 08:58:47 +04:00
|
|
|
static float GetStrokeWidth(nsIFrame* aFrame,
|
2016-07-22 16:56:09 +03:00
|
|
|
SVGContextPaint* aContextPaint = nullptr);
|
2012-08-10 15:13:43 +04:00
|
|
|
|
|
|
|
/*
|
2017-07-31 15:20:28 +03:00
|
|
|
* Set up a context for a stroked path (including any dashing that applies).
|
2012-08-05 23:10:21 +04:00
|
|
|
*/
|
2017-07-31 15:20:28 +03:00
|
|
|
static void SetupStrokeGeometry(nsIFrame* aFrame, gfxContext* aContext,
|
2016-07-22 16:56:09 +03:00
|
|
|
SVGContextPaint* aContextPaint = nullptr);
|
2012-08-10 15:13:43 +04:00
|
|
|
|
2012-08-05 23:10:21 +04:00
|
|
|
/**
|
2012-08-10 15:13:43 +04: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 23:10:21 +04:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint16_t GetGeometryHitTestFlags(nsIFrame* aFrame);
|
2012-12-12 03:15:07 +04:00
|
|
|
|
2016-08-15 19:17:04 +03:00
|
|
|
static FillRule ToFillRule(mozilla::StyleFillRule aFillRule) {
|
2016-08-17 09:43:26 +03:00
|
|
|
return aFillRule == mozilla::StyleFillRule::Evenodd
|
2014-09-29 17:15:19 +04:00
|
|
|
? FillRule::FILL_EVEN_ODD
|
|
|
|
: FillRule::FILL_WINDING;
|
2014-09-29 17:12:06 +04:00
|
|
|
}
|
|
|
|
|
2018-11-30 08:08:46 +03:00
|
|
|
static AntialiasMode ToAntialiasMode(
|
|
|
|
mozilla::StyleTextRendering aTextRendering) {
|
|
|
|
return aTextRendering == mozilla::StyleTextRendering::Optimizespeed
|
2014-11-05 12:16:37 +03:00
|
|
|
? AntialiasMode::NONE
|
|
|
|
: AntialiasMode::SUBPIXEL;
|
|
|
|
}
|
|
|
|
|
2012-12-12 03:15:07 +04:00
|
|
|
/**
|
|
|
|
* Render a SVG glyph.
|
|
|
|
* @param aElement the SVG glyph element to render
|
|
|
|
* @param aContext the thebes aContext to draw to
|
|
|
|
* @return true if rendering succeeded
|
|
|
|
*/
|
2017-05-18 23:03:41 +03:00
|
|
|
static void PaintSVGGlyph(Element* aElement, gfxContext* aContext);
|
2017-03-23 11:53:47 +03:00
|
|
|
|
2012-12-12 03:15:07 +04:00
|
|
|
/**
|
|
|
|
* 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);
|
2013-02-11 10:22:18 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the app unit canvas bounds of a userspace rect.
|
|
|
|
*
|
|
|
|
* @param aToCanvas Transform from userspace to canvas device space.
|
|
|
|
*/
|
2017-03-23 11:53:47 +03:00
|
|
|
static nsRect ToCanvasBounds(const gfxRect& aUserspaceRect,
|
|
|
|
const gfxMatrix& aToCanvas,
|
|
|
|
const nsPresContext* presContext);
|
2016-11-03 06:08:06 +03:00
|
|
|
|
|
|
|
struct MaskUsage {
|
|
|
|
bool shouldGenerateMaskLayer;
|
|
|
|
bool shouldGenerateClipMaskLayer;
|
|
|
|
bool shouldApplyClipPath;
|
2018-08-18 01:48:02 +03:00
|
|
|
bool shouldApplyBasicShapeOrPath;
|
2016-11-03 06:08:06 +03:00
|
|
|
float opacity;
|
|
|
|
|
|
|
|
MaskUsage()
|
2018-08-18 01:48:02 +03:00
|
|
|
: shouldGenerateMaskLayer(false),
|
|
|
|
shouldGenerateClipMaskLayer(false),
|
|
|
|
shouldApplyClipPath(false),
|
|
|
|
shouldApplyBasicShapeOrPath(false),
|
|
|
|
opacity(0.0) {}
|
2018-07-05 15:05:34 +03:00
|
|
|
|
|
|
|
bool shouldDoSomething() {
|
|
|
|
return shouldGenerateMaskLayer || shouldGenerateClipMaskLayer ||
|
2018-08-18 01:48:02 +03:00
|
|
|
shouldApplyClipPath || shouldApplyBasicShapeOrPath ||
|
2018-07-05 15:05:34 +03:00
|
|
|
opacity != 1.0;
|
|
|
|
}
|
2016-11-03 06:08:06 +03:00
|
|
|
};
|
|
|
|
|
2017-03-23 11:53:47 +03:00
|
|
|
static void DetermineMaskUsage(nsIFrame* aFrame, bool aHandleOpacity,
|
|
|
|
MaskUsage& aUsage);
|
2016-11-03 06:08:06 +03:00
|
|
|
|
2017-03-23 11:53:47 +03:00
|
|
|
static float ComputeOpacity(nsIFrame* aFrame, bool aHandleOpacity);
|
2017-01-24 18:22:43 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SVG frames expect to paint in SVG user units, which are equal to CSS px
|
|
|
|
* units. This method provides a transform matrix to multiply onto a
|
|
|
|
* gfxContext's current transform to convert the context's current units from
|
|
|
|
* its usual dev pixels to SVG user units/CSS px to keep the SVG code happy.
|
|
|
|
*/
|
2017-03-23 11:53:47 +03:00
|
|
|
static gfxMatrix GetCSSPxToDevPxMatrix(nsIFrame* aNonSVGFrame);
|
2017-03-23 10:29:11 +03:00
|
|
|
|
|
|
|
static bool IsInSVGTextSubtree(const nsIFrame* aFrame) {
|
|
|
|
// Returns true if the frame is an SVGTextFrame or one of its descendants.
|
|
|
|
return aFrame->GetStateBits() & NS_FRAME_IS_SVG_TEXT;
|
|
|
|
}
|
2019-04-18 20:19:42 +03:00
|
|
|
|
|
|
|
/**
|
2019-04-27 10:22:53 +03:00
|
|
|
* It is a replacement of
|
|
|
|
* SVGElement::PrependLocalTransformsTo(eUserSpaceToParent).
|
|
|
|
* If no CSS transform is involved, they should behave exactly the same;
|
|
|
|
* if there are CSS transforms, this one will take them into account
|
|
|
|
* while SVGElement::PrependLocalTransformsTo won't.
|
2019-04-18 20:19:42 +03:00
|
|
|
*/
|
2019-04-27 10:22:53 +03:00
|
|
|
static gfxMatrix GetTransformMatrixInUserSpace(const nsIFrame* aFrame);
|
2005-04-05 01:42:26 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|