2017-10-27 17:33:53 +00: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 11:12:37 +00: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/. */
|
2004-10-14 23:02:53 +00:00
|
|
|
|
|
|
|
#ifndef __NS_SVGGRADIENTFRAME_H__
|
|
|
|
#define __NS_SVGGRADIENTFRAME_H__
|
|
|
|
|
2013-05-29 19:37:49 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-03-20 12:15:55 +00:00
|
|
|
#include "gfxMatrix.h"
|
2017-07-05 15:22:00 +00:00
|
|
|
#include "gfxRect.h"
|
2012-03-20 12:15:55 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsLiteralString.h"
|
2006-05-16 15:55:01 +00:00
|
|
|
#include "nsSVGPaintServerFrame.h"
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2012-03-20 12:15:55 +00:00
|
|
|
class gfxPattern;
|
2017-10-02 22:05:19 +00:00
|
|
|
class nsAtom;
|
2012-03-20 12:15:55 +00:00
|
|
|
class nsIContent;
|
|
|
|
class nsIPresShell;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2013-04-14 22:56:34 +00:00
|
|
|
class nsSVGAnimatedTransformList;
|
2013-01-11 08:43:01 +00:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class SVGLinearGradientElement;
|
|
|
|
class SVGRadialGradientElement;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2016-04-18 07:15:23 +00:00
|
|
|
class nsSVGGradientFrame : public nsSVGPaintServerFrame
|
2006-05-11 20:01:12 +00:00
|
|
|
{
|
2015-09-25 07:58:23 +00:00
|
|
|
typedef mozilla::gfx::ExtendMode ExtendMode;
|
|
|
|
|
2007-07-25 09:16:02 +00:00
|
|
|
protected:
|
2018-03-22 18:20:41 +00:00
|
|
|
nsSVGGradientFrame(ComputedStyle* aStyle, ClassID aID);
|
2007-07-25 09:16:02 +00:00
|
|
|
|
2006-05-11 20:01:12 +00:00
|
|
|
public:
|
2015-11-04 09:57:35 +00:00
|
|
|
NS_DECL_ABSTRACT_FRAME(nsSVGGradientFrame)
|
2009-09-12 16:49:24 +00:00
|
|
|
|
2006-05-16 15:55:01 +00:00
|
|
|
// nsSVGPaintServerFrame methods:
|
2017-05-18 20:03:50 +00:00
|
|
|
virtual already_AddRefed<gfxPattern>
|
|
|
|
GetPaintServerPattern(nsIFrame *aSource,
|
2014-09-29 13:15:19 +00:00
|
|
|
const DrawTarget* aDrawTarget,
|
2012-07-13 23:18:38 +00:00
|
|
|
const gfxMatrix& aContextMatrix,
|
2012-05-18 08:34:25 +00:00
|
|
|
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
|
2017-05-18 20:03:50 +00:00
|
|
|
float aOpacity,
|
|
|
|
imgDrawingParams& aImgParams,
|
|
|
|
const gfxRect* aOverrideBounds) override;
|
2006-05-11 20:01:12 +00:00
|
|
|
|
|
|
|
// nsIFrame interface:
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2017-10-02 22:05:19 +00:00
|
|
|
nsAtom* aAttribute,
|
2015-03-21 16:28:04 +00:00
|
|
|
int32_t aModType) override;
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override
|
2006-05-11 20:01:12 +00:00
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGGradient"), aResult);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2008-10-01 00:51:05 +00:00
|
|
|
private:
|
2018-08-21 13:54:26 +00:00
|
|
|
/**
|
|
|
|
* Parses this frame's href and - if it references another gradient - returns
|
|
|
|
* it. It also makes this frame a rendering observer of the specified ID.
|
|
|
|
*/
|
2008-10-01 00:51:05 +00:00
|
|
|
nsSVGGradientFrame* GetReferencedGradient();
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2006-05-17 01:43:44 +00:00
|
|
|
// Optionally get a stop frame (returns stop index/count)
|
2013-05-27 07:34:01 +00:00
|
|
|
void GetStopFrames(nsTArray<nsIFrame*>* aStopFrames);
|
2009-06-11 15:21:03 +00:00
|
|
|
|
2013-04-14 22:56:34 +00:00
|
|
|
const mozilla::nsSVGAnimatedTransformList* GetGradientTransformList(
|
2012-03-06 06:58:40 +00:00
|
|
|
nsIContent* aDefault);
|
2009-06-11 15:21:03 +00:00
|
|
|
// Will be singular for gradientUnits="objectBoundingBox" with an empty bbox.
|
2012-03-06 06:58:40 +00:00
|
|
|
gfxMatrix GetGradientTransform(nsIFrame *aSource,
|
|
|
|
const gfxRect *aOverrideBounds);
|
2006-05-16 15:55:01 +00:00
|
|
|
|
2006-05-11 20:01:12 +00:00
|
|
|
protected:
|
2013-05-27 07:34:01 +00:00
|
|
|
virtual bool GradientVectorLengthIsZero() = 0;
|
2007-04-27 14:28:39 +00:00
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient() = 0;
|
2006-05-16 15:55:01 +00:00
|
|
|
|
2012-03-06 06:58:40 +00:00
|
|
|
// Accessors to lookup gradient attributes
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t GetEnumValue(uint32_t aIndex, nsIContent *aDefault);
|
|
|
|
uint16_t GetEnumValue(uint32_t aIndex)
|
2012-03-06 06:58:40 +00:00
|
|
|
{
|
|
|
|
return GetEnumValue(aIndex, mContent);
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t GetGradientUnits();
|
|
|
|
uint16_t GetSpreadMethod();
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2012-03-06 06:58:40 +00:00
|
|
|
// Gradient-type-specific lookups since the length values differ between
|
|
|
|
// linear and radial gradients
|
2013-01-11 08:43:01 +00:00
|
|
|
virtual mozilla::dom::SVGLinearGradientElement * GetLinearGradientWithLength(
|
|
|
|
uint32_t aIndex, mozilla::dom::SVGLinearGradientElement* aDefault);
|
|
|
|
virtual mozilla::dom::SVGRadialGradientElement * GetRadialGradientWithLength(
|
|
|
|
uint32_t aIndex, mozilla::dom::SVGRadialGradientElement* aDefault);
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2010-07-01 16:40:30 +00:00
|
|
|
// The frame our gradient is (currently) being applied to
|
|
|
|
nsIFrame* mSource;
|
2006-05-11 20:01:12 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Flag to mark this frame as "in use" during recursive calls along our
|
|
|
|
// gradient's reference chain so we can detect reference loops. See:
|
|
|
|
// http://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementHrefAttribute
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mLoopFlag;
|
2008-10-01 00:51:05 +00:00
|
|
|
// Gradients often don't reference other gradients, so here we cache
|
|
|
|
// the fact that that isn't happening.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mNoHRefURI;
|
2006-05-11 20:01:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Linear Gradients
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
2018-09-06 01:23:14 +00:00
|
|
|
class nsSVGLinearGradientFrame final : public nsSVGGradientFrame
|
2006-05-11 20:01:12 +00:00
|
|
|
{
|
2008-10-01 00:51:05 +00:00
|
|
|
friend nsIFrame* NS_NewSVGLinearGradientFrame(nsIPresShell* aPresShell,
|
2018-03-22 18:20:41 +00:00
|
|
|
ComputedStyle* aStyle);
|
2007-07-25 09:16:02 +00:00
|
|
|
protected:
|
2018-03-22 18:20:41 +00:00
|
|
|
explicit nsSVGLinearGradientFrame(ComputedStyle* aStyle)
|
|
|
|
: nsSVGGradientFrame(aStyle, kClassID)
|
2017-04-30 15:30:08 +00:00
|
|
|
{}
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2007-07-25 09:16:02 +00:00
|
|
|
public:
|
2017-05-26 10:11:11 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsSVGLinearGradientFrame)
|
2009-09-12 16:49:24 +00:00
|
|
|
|
2006-05-11 20:01:12 +00:00
|
|
|
// nsIFrame interface:
|
2009-01-19 18:31:34 +00:00
|
|
|
#ifdef DEBUG
|
2014-05-24 22:20:40 +00:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsIFrame* aPrevInFlow) override;
|
2009-01-19 18:31:34 +00:00
|
|
|
#endif
|
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2017-10-02 22:05:19 +00:00
|
|
|
nsAtom* aAttribute,
|
2015-03-21 16:28:04 +00:00
|
|
|
int32_t aModType) override;
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override
|
2006-05-11 20:01:12 +00:00
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGLinearGradient"), aResult);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
protected:
|
2012-08-22 15:56:38 +00:00
|
|
|
float GetLengthValue(uint32_t aIndex);
|
2013-01-11 08:43:01 +00:00
|
|
|
virtual mozilla::dom::SVGLinearGradientElement* GetLinearGradientWithLength(
|
2015-03-21 16:28:04 +00:00
|
|
|
uint32_t aIndex, mozilla::dom::SVGLinearGradientElement* aDefault) override;
|
|
|
|
virtual bool GradientVectorLengthIsZero() override;
|
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient() override;
|
2006-05-11 20:01:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Radial Gradients
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
2018-09-06 01:23:14 +00:00
|
|
|
class nsSVGRadialGradientFrame final : public nsSVGGradientFrame
|
2006-05-11 20:01:12 +00:00
|
|
|
{
|
2008-10-01 00:51:05 +00:00
|
|
|
friend nsIFrame* NS_NewSVGRadialGradientFrame(nsIPresShell* aPresShell,
|
2018-03-22 18:20:41 +00:00
|
|
|
ComputedStyle* aStyle);
|
2007-07-25 09:16:02 +00:00
|
|
|
protected:
|
2018-03-22 18:20:41 +00:00
|
|
|
explicit nsSVGRadialGradientFrame(ComputedStyle* aStyle)
|
|
|
|
: nsSVGGradientFrame(aStyle, kClassID)
|
2017-04-30 15:30:08 +00:00
|
|
|
{}
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2007-07-25 09:16:02 +00:00
|
|
|
public:
|
2017-05-26 10:11:11 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsSVGRadialGradientFrame)
|
2009-09-12 16:49:24 +00:00
|
|
|
|
2006-05-11 20:01:12 +00:00
|
|
|
// nsIFrame interface:
|
2009-01-19 18:31:34 +00:00
|
|
|
#ifdef DEBUG
|
2014-05-24 22:20:40 +00:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsIFrame* aPrevInFlow) override;
|
2009-01-19 18:31:34 +00:00
|
|
|
#endif
|
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2017-10-02 22:05:19 +00:00
|
|
|
nsAtom* aAttribute,
|
2015-03-21 16:28:04 +00:00
|
|
|
int32_t aModType) override;
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override
|
2006-05-11 20:01:12 +00:00
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGRadialGradient"), aResult);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
protected:
|
2012-08-22 15:56:38 +00:00
|
|
|
float GetLengthValue(uint32_t aIndex);
|
|
|
|
float GetLengthValue(uint32_t aIndex, float aDefaultValue);
|
|
|
|
float GetLengthValueFromElement(uint32_t aIndex,
|
2013-01-11 08:43:01 +00:00
|
|
|
mozilla::dom::SVGRadialGradientElement& aElement);
|
|
|
|
virtual mozilla::dom::SVGRadialGradientElement* GetRadialGradientWithLength(
|
2015-03-21 16:28:04 +00:00
|
|
|
uint32_t aIndex, mozilla::dom::SVGRadialGradientElement* aDefault) override;
|
|
|
|
virtual bool GradientVectorLengthIsZero() override;
|
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient() override;
|
2006-05-11 20:01:12 +00:00
|
|
|
};
|
|
|
|
|
2004-10-14 23:02:53 +00:00
|
|
|
#endif // __NS_SVGGRADIENTFRAME_H__
|
|
|
|
|