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