2004-10-15 03:02:53 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Main header first:
|
2006-05-12 00:01:12 +04:00
|
|
|
#include "nsSVGGradientFrame.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2012-03-26 15:58:59 +04:00
|
|
|
|
|
|
|
// Keep others in (case-insensitive) order:
|
2007-04-27 18:28:39 +04:00
|
|
|
#include "gfxPattern.h"
|
2013-01-11 12:43:01 +04:00
|
|
|
#include "mozilla/dom/SVGGradientElement.h"
|
|
|
|
#include "mozilla/dom/SVGStopElement.h"
|
2011-08-11 17:29:50 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGEffects.h"
|
2013-04-15 02:56:34 +04:00
|
|
|
#include "nsSVGAnimatedTransformList.h"
|
2013-01-11 12:43:01 +04:00
|
|
|
|
|
|
|
// XXX Tight coupling with content classes ahead!
|
2005-03-09 22:24:18 +03:00
|
|
|
|
2013-01-08 07:22:41 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
2015-09-25 03:50:46 +03:00
|
|
|
using namespace mozilla::gfx;
|
2011-09-26 01:04:32 +04:00
|
|
|
|
2012-03-06 10:58:40 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper classes
|
|
|
|
|
2015-09-03 19:15:23 +03:00
|
|
|
class MOZ_RAII nsSVGGradientFrame::AutoGradientReferencer
|
2012-03-06 10:58:40 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit AutoGradientReferencer(nsSVGGradientFrame *aFrame
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-03-06 10:58:40 +04:00
|
|
|
: mFrame(aFrame)
|
|
|
|
{
|
2013-12-26 22:49:49 +04:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2012-03-06 10:58:40 +04:00
|
|
|
// Reference loops should normally be detected in advance and handled, so
|
|
|
|
// we're not expecting to encounter them here
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mFrame->mLoopFlag, "Undetected reference loop!");
|
2012-03-06 10:58:40 +04:00
|
|
|
mFrame->mLoopFlag = true;
|
|
|
|
}
|
|
|
|
~AutoGradientReferencer() {
|
|
|
|
mFrame->mLoopFlag = false;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsSVGGradientFrame *mFrame;
|
2013-12-26 22:49:49 +04:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2012-03-06 10:58:40 +04:00
|
|
|
};
|
|
|
|
|
2004-10-15 03:02:53 +04:00
|
|
|
//----------------------------------------------------------------------
|
2005-03-09 22:24:18 +03:00
|
|
|
// Implementation
|
|
|
|
|
2016-04-18 10:15:23 +03:00
|
|
|
nsSVGGradientFrame::nsSVGGradientFrame(nsStyleContext* aContext)
|
|
|
|
: nsSVGPaintServerFrame(aContext)
|
|
|
|
, mLoopFlag(false)
|
|
|
|
, mNoHRefURI(false)
|
2006-09-08 17:19:47 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-03-09 22:24:18 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods:
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGGradientFrame::AttributeChanged(int32_t aNameSpaceID,
|
2006-03-07 03:04:59 +03:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType)
|
2006-03-07 03:04:59 +03:00
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::gradientUnits ||
|
|
|
|
aAttribute == nsGkAtoms::gradientTransform ||
|
|
|
|
aAttribute == nsGkAtoms::spreadMethod)) {
|
2012-06-23 18:19:00 +04:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2008-10-01 04:51:05 +04:00
|
|
|
} else if (aNameSpaceID == kNameSpaceID_XLink &&
|
|
|
|
aAttribute == nsGkAtoms::href) {
|
|
|
|
// Blow away our reference, if any
|
2010-03-29 05:46:55 +04:00
|
|
|
Properties().Delete(nsSVGEffects::HrefProperty());
|
2011-10-17 18:59:28 +04:00
|
|
|
mNoHRefURI = false;
|
2008-10-01 04:51:05 +04:00
|
|
|
// And update whoever references us
|
2012-06-23 18:19:00 +04:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2006-03-07 03:04:59 +03:00
|
|
|
}
|
|
|
|
|
2016-04-18 10:15:23 +03:00
|
|
|
return nsSVGPaintServerFrame::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
2006-03-07 03:04:59 +03:00
|
|
|
}
|
|
|
|
|
2005-03-09 22:24:18 +03:00
|
|
|
//----------------------------------------------------------------------
|
2004-10-15 03:02:53 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t
|
|
|
|
nsSVGGradientFrame::GetEnumValue(uint32_t aIndex, nsIContent *aDefault)
|
2012-03-06 10:58:40 +04:00
|
|
|
{
|
|
|
|
const nsSVGEnum& thisEnum =
|
2013-01-11 12:43:01 +04:00
|
|
|
static_cast<dom::SVGGradientElement*>(mContent)->mEnumAttributes[aIndex];
|
2012-03-06 10:58:40 +04:00
|
|
|
|
|
|
|
if (thisEnum.IsExplicitlySet())
|
|
|
|
return thisEnum.GetAnimValue();
|
|
|
|
|
|
|
|
AutoGradientReferencer gradientRef(this);
|
|
|
|
|
|
|
|
nsSVGGradientFrame *next = GetReferencedGradientIfNotInUse();
|
|
|
|
return next ? next->GetEnumValue(aIndex, aDefault) :
|
2013-01-11 12:43:01 +04:00
|
|
|
static_cast<dom::SVGGradientElement*>(aDefault)->
|
2012-03-06 10:58:40 +04:00
|
|
|
mEnumAttributes[aIndex].GetAnimValue();
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t
|
2012-03-20 16:15:55 +04:00
|
|
|
nsSVGGradientFrame::GetGradientUnits()
|
|
|
|
{
|
|
|
|
// This getter is called every time the others are called - maybe cache it?
|
2013-01-11 12:43:01 +04:00
|
|
|
return GetEnumValue(dom::SVGGradientElement::GRADIENTUNITS);
|
2012-03-20 16:15:55 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t
|
2012-03-20 16:15:55 +04:00
|
|
|
nsSVGGradientFrame::GetSpreadMethod()
|
|
|
|
{
|
2013-01-11 12:43:01 +04:00
|
|
|
return GetEnumValue(dom::SVGGradientElement::SPREADMETHOD);
|
2012-03-20 16:15:55 +04:00
|
|
|
}
|
|
|
|
|
2013-04-15 02:56:34 +04:00
|
|
|
const nsSVGAnimatedTransformList*
|
2012-03-06 10:58:40 +04:00
|
|
|
nsSVGGradientFrame::GetGradientTransformList(nsIContent* aDefault)
|
|
|
|
{
|
2013-04-15 02:56:34 +04:00
|
|
|
nsSVGAnimatedTransformList *thisTransformList =
|
2013-01-11 12:43:01 +04:00
|
|
|
static_cast<dom::SVGGradientElement*>(mContent)->GetAnimatedTransformList();
|
2012-03-06 10:58:40 +04:00
|
|
|
|
2012-07-30 04:35:26 +04:00
|
|
|
if (thisTransformList && thisTransformList->IsExplicitlySet())
|
2012-03-06 10:58:40 +04:00
|
|
|
return thisTransformList;
|
|
|
|
|
|
|
|
AutoGradientReferencer gradientRef(this);
|
|
|
|
|
|
|
|
nsSVGGradientFrame *next = GetReferencedGradientIfNotInUse();
|
|
|
|
return next ? next->GetGradientTransformList(aDefault) :
|
2013-01-11 12:43:01 +04:00
|
|
|
static_cast<const dom::SVGGradientElement*>(aDefault)
|
2012-03-06 10:58:40 +04:00
|
|
|
->mGradientTransform.get();
|
|
|
|
}
|
|
|
|
|
2007-04-27 18:28:39 +04:00
|
|
|
gfxMatrix
|
2010-07-01 20:40:30 +04:00
|
|
|
nsSVGGradientFrame::GetGradientTransform(nsIFrame *aSource,
|
|
|
|
const gfxRect *aOverrideBounds)
|
2004-10-15 03:02:53 +04:00
|
|
|
{
|
2007-04-27 18:28:39 +04:00
|
|
|
gfxMatrix bboxMatrix;
|
2006-04-20 19:24:51 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t gradientUnits = GetGradientUnits();
|
2013-05-27 11:31:39 +04:00
|
|
|
if (gradientUnits != SVG_UNIT_TYPE_USERSPACEONUSE) {
|
|
|
|
NS_ASSERTION(gradientUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX,
|
|
|
|
"Unknown gradientUnits type");
|
2006-03-28 04:33:22 +04:00
|
|
|
// objectBoundingBox is the default anyway
|
2005-02-19 02:17:48 +03:00
|
|
|
|
2012-03-06 10:58:40 +04:00
|
|
|
gfxRect bbox =
|
|
|
|
aOverrideBounds ? *aOverrideBounds : nsSVGUtils::GetBBox(aSource);
|
|
|
|
bboxMatrix =
|
|
|
|
gfxMatrix(bbox.Width(), 0, 0, bbox.Height(), bbox.X(), bbox.Y());
|
2005-02-19 02:17:48 +03:00
|
|
|
}
|
|
|
|
|
2013-04-15 02:56:34 +04:00
|
|
|
const nsSVGAnimatedTransformList* animTransformList =
|
2012-03-06 10:58:40 +04:00
|
|
|
GetGradientTransformList(mContent);
|
2011-09-26 01:04:32 +04:00
|
|
|
if (!animTransformList)
|
2007-04-27 18:28:39 +04:00
|
|
|
return bboxMatrix;
|
2006-04-20 19:24:51 +04:00
|
|
|
|
2011-09-26 01:04:32 +04:00
|
|
|
gfxMatrix gradientTransform =
|
|
|
|
animTransformList->GetAnimValue().GetConsolidationMatrix();
|
|
|
|
return bboxMatrix.PreMultiply(gradientTransform);
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGLinearGradientElement*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGGradientFrame::GetLinearGradientWithLength(uint32_t aIndex,
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGLinearGradientElement* aDefault)
|
2005-04-11 20:35:02 +04:00
|
|
|
{
|
2012-03-06 10:58:40 +04:00
|
|
|
// If this was a linear gradient with the required length, we would have
|
|
|
|
// already found it in nsSVGLinearGradientFrame::GetLinearGradientWithLength.
|
|
|
|
// Since we didn't find the length, continue looking down the chain.
|
|
|
|
|
|
|
|
AutoGradientReferencer gradientRef(this);
|
2006-05-12 00:01:12 +04:00
|
|
|
|
2012-03-06 10:58:40 +04:00
|
|
|
nsSVGGradientFrame *next = GetReferencedGradientIfNotInUse();
|
|
|
|
return next ? next->GetLinearGradientWithLength(aIndex, aDefault) : aDefault;
|
|
|
|
}
|
|
|
|
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGRadialGradientElement*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGGradientFrame::GetRadialGradientWithLength(uint32_t aIndex,
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGRadialGradientElement* aDefault)
|
2012-03-06 10:58:40 +04:00
|
|
|
{
|
|
|
|
// If this was a radial gradient with the required length, we would have
|
|
|
|
// already found it in nsSVGRadialGradientFrame::GetRadialGradientWithLength.
|
|
|
|
// Since we didn't find the length, continue looking down the chain.
|
|
|
|
|
|
|
|
AutoGradientReferencer gradientRef(this);
|
|
|
|
|
|
|
|
nsSVGGradientFrame *next = GetReferencedGradientIfNotInUse();
|
|
|
|
return next ? next->GetRadialGradientWithLength(aIndex, aDefault) : aDefault;
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2006-05-16 19:55:01 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGPaintServerFrame methods:
|
|
|
|
|
2013-05-27 11:34:01 +04:00
|
|
|
//helper
|
|
|
|
static void GetStopInformation(nsIFrame* aStopFrame,
|
|
|
|
float *aOffset,
|
|
|
|
nscolor *aStopColor,
|
|
|
|
float *aStopOpacity)
|
|
|
|
{
|
|
|
|
nsIContent* stopContent = aStopFrame->GetContent();
|
2015-03-03 14:08:59 +03:00
|
|
|
MOZ_ASSERT(stopContent && stopContent->IsSVGElement(nsGkAtoms::stop));
|
2013-05-27 11:34:01 +04:00
|
|
|
|
|
|
|
static_cast<SVGStopElement*>(stopContent)->
|
|
|
|
GetAnimatedNumberValues(aOffset, nullptr);
|
|
|
|
|
|
|
|
*aOffset = mozilla::clamped(*aOffset, 0.0f, 1.0f);
|
|
|
|
*aStopColor = aStopFrame->StyleSVGReset()->mStopColor;
|
|
|
|
*aStopOpacity = aStopFrame->StyleSVGReset()->mStopOpacity;
|
|
|
|
}
|
|
|
|
|
2010-07-01 20:40:30 +04:00
|
|
|
already_AddRefed<gfxPattern>
|
2014-09-29 17:15:19 +04:00
|
|
|
nsSVGGradientFrame::GetPaintServerPattern(nsIFrame* aSource,
|
|
|
|
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,
|
|
|
|
float aGraphicOpacity,
|
2014-09-29 17:15:19 +04:00
|
|
|
const gfxRect* aOverrideBounds)
|
2006-05-16 19:55:01 +04:00
|
|
|
{
|
2013-05-27 11:31:39 +04:00
|
|
|
uint16_t gradientUnits = GetGradientUnits();
|
|
|
|
MOZ_ASSERT(gradientUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX ||
|
|
|
|
gradientUnits == SVG_UNIT_TYPE_USERSPACEONUSE);
|
|
|
|
if (gradientUnits == SVG_UNIT_TYPE_USERSPACEONUSE) {
|
|
|
|
// Set mSource for this consumer.
|
|
|
|
// If this gradient is applied to text, our caller will be the glyph, which
|
|
|
|
// is not an element, so we need to get the parent
|
|
|
|
mSource = aSource->GetContent()->IsNodeOfType(nsINode::eTEXT) ?
|
|
|
|
aSource->GetParent() : aSource;
|
|
|
|
}
|
2006-05-16 19:55:01 +04:00
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<nsIFrame*,8> stopFrames;
|
2013-05-27 11:34:01 +04:00
|
|
|
GetStopFrames(&stopFrames);
|
|
|
|
|
|
|
|
uint32_t nStops = stopFrames.Length();
|
2008-02-09 00:52:04 +03:00
|
|
|
|
|
|
|
// SVG specification says that no stops should be treated like
|
|
|
|
// the corresponding fill or stroke had "none" specified.
|
|
|
|
if (nStops == 0) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxPattern> pattern = new gfxPattern(Color());
|
2010-07-01 20:40:30 +04:00
|
|
|
return pattern.forget();
|
2008-02-09 00:52:04 +03:00
|
|
|
}
|
2012-10-06 16:52:32 +04:00
|
|
|
|
2013-05-27 11:34:01 +04:00
|
|
|
if (nStops == 1 || GradientVectorLengthIsZero()) {
|
|
|
|
// The gradient paints a single colour, using the stop-color of the last
|
|
|
|
// gradient step if there are more than one.
|
|
|
|
float stopOpacity = stopFrames[nStops-1]->StyleSVGReset()->mStopOpacity;
|
|
|
|
nscolor stopColor = stopFrames[nStops-1]->StyleSVGReset()->mStopColor;
|
|
|
|
|
2015-09-25 03:50:46 +03:00
|
|
|
Color stopColor2 = Color::FromABGR(stopColor);
|
|
|
|
stopColor2.a *= stopOpacity * aGraphicOpacity;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxPattern> pattern = new gfxPattern(stopColor2);
|
2012-10-06 16:52:32 +04:00
|
|
|
return pattern.forget();
|
|
|
|
}
|
2008-02-09 00:52:04 +03:00
|
|
|
|
2013-05-27 11:31:39 +04:00
|
|
|
// Get the transform list (if there is one). We do this after the returns
|
|
|
|
// above since this call can be expensive when "gradientUnits" is set to
|
|
|
|
// "objectBoundingBox" (since that requiring a GetBBox() call).
|
|
|
|
gfxMatrix patternMatrix = GetGradientTransform(aSource, aOverrideBounds);
|
|
|
|
|
|
|
|
if (patternMatrix.IsSingular()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-09-30 21:08:14 +04:00
|
|
|
// revert any vector effect transform so that the gradient appears unchanged
|
2012-05-18 12:34:25 +04:00
|
|
|
if (aFillOrStroke == &nsStyleSVG::mStroke) {
|
2014-09-30 21:08:14 +04:00
|
|
|
gfxMatrix userToOuterSVG;
|
|
|
|
if (nsSVGUtils::GetNonScalingStrokeTransform(aSource, &userToOuterSVG)) {
|
|
|
|
patternMatrix *= userToOuterSVG;
|
2014-07-11 11:06:39 +04:00
|
|
|
}
|
2012-05-18 12:34:25 +04:00
|
|
|
}
|
|
|
|
|
2014-07-11 11:06:39 +04:00
|
|
|
if (!patternMatrix.Invert()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2007-04-27 18:28:39 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxPattern> gradient = CreateGradient();
|
2008-03-17 20:15:43 +03:00
|
|
|
if (!gradient || gradient->CairoStatus())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-05-16 19:55:01 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t aSpread = GetSpreadMethod();
|
2013-02-03 00:23:16 +04:00
|
|
|
if (aSpread == SVG_SPREADMETHOD_PAD)
|
2015-09-25 10:58:23 +03:00
|
|
|
gradient->SetExtend(ExtendMode::CLAMP);
|
2013-02-03 00:23:16 +04:00
|
|
|
else if (aSpread == SVG_SPREADMETHOD_REFLECT)
|
2015-09-25 10:58:23 +03:00
|
|
|
gradient->SetExtend(ExtendMode::REFLECT);
|
2013-02-03 00:23:16 +04:00
|
|
|
else if (aSpread == SVG_SPREADMETHOD_REPEAT)
|
2015-09-25 10:58:23 +03:00
|
|
|
gradient->SetExtend(ExtendMode::REPEAT);
|
2007-04-27 18:28:39 +04:00
|
|
|
|
|
|
|
gradient->SetMatrix(patternMatrix);
|
2006-05-16 19:55:01 +04:00
|
|
|
|
|
|
|
// setup stops
|
|
|
|
float lastOffset = 0.0f;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < nStops; i++) {
|
2007-04-24 12:11:22 +04:00
|
|
|
float offset, stopOpacity;
|
|
|
|
nscolor stopColor;
|
2006-05-16 19:55:01 +04:00
|
|
|
|
2013-05-27 11:34:01 +04:00
|
|
|
GetStopInformation(stopFrames[i], &offset, &stopColor, &stopOpacity);
|
2006-05-16 19:55:01 +04:00
|
|
|
|
|
|
|
if (offset < lastOffset)
|
|
|
|
offset = lastOffset;
|
|
|
|
else
|
|
|
|
lastOffset = offset;
|
|
|
|
|
2015-09-25 03:50:46 +03:00
|
|
|
Color stopColor2 = Color::FromABGR(stopColor);
|
|
|
|
stopColor2.a *= stopOpacity * aGraphicOpacity;
|
|
|
|
gradient->AddColorStop(offset, stopColor2);
|
2006-05-16 19:55:01 +04:00
|
|
|
}
|
|
|
|
|
2010-07-01 20:40:30 +04:00
|
|
|
return gradient.forget();
|
2006-05-16 19:55:01 +04:00
|
|
|
}
|
|
|
|
|
2004-10-15 03:02:53 +04:00
|
|
|
// Private (helper) methods
|
|
|
|
|
2008-10-01 04:51:05 +04:00
|
|
|
nsSVGGradientFrame *
|
|
|
|
nsSVGGradientFrame::GetReferencedGradient()
|
2006-03-28 04:33:22 +04:00
|
|
|
{
|
2008-10-01 04:51:05 +04:00
|
|
|
if (mNoHRefURI)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-09-30 12:47:20 +04:00
|
|
|
|
2010-03-29 05:46:55 +04:00
|
|
|
nsSVGPaintingProperty *property = static_cast<nsSVGPaintingProperty*>
|
|
|
|
(Properties().Get(nsSVGEffects::HrefProperty()));
|
2008-10-01 04:51:05 +04:00
|
|
|
|
|
|
|
if (!property) {
|
|
|
|
// Fetch our gradient element's xlink:href attribute
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGGradientElement*grad = static_cast<dom::SVGGradientElement*>(mContent);
|
2009-01-22 03:56:51 +03:00
|
|
|
nsAutoString href;
|
2013-01-11 12:43:01 +04:00
|
|
|
grad->mStringAttributes[dom::SVGGradientElement::HREF].GetAnimValue(href, grad);
|
2008-10-01 04:51:05 +04:00
|
|
|
if (href.IsEmpty()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mNoHRefURI = true;
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr; // no URL
|
2005-03-09 22:24:18 +03:00
|
|
|
}
|
2008-10-01 04:51:05 +04:00
|
|
|
|
|
|
|
// Convert href to an nsIURI
|
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
nsCOMPtr<nsIURI> base = mContent->GetBaseURI();
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), href,
|
2016-03-31 14:46:32 +03:00
|
|
|
mContent->GetUncomposedDoc(), base);
|
2008-10-01 04:51:05 +04:00
|
|
|
|
2010-03-29 05:46:55 +04:00
|
|
|
property =
|
|
|
|
nsSVGEffects::GetPaintingProperty(targetURI, this, nsSVGEffects::HrefProperty());
|
2008-10-01 04:51:05 +04:00
|
|
|
if (!property)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
2008-10-01 04:51:05 +04:00
|
|
|
|
|
|
|
nsIFrame *result = property->GetReferencedFrame();
|
|
|
|
if (!result)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-10-01 04:51:05 +04:00
|
|
|
|
|
|
|
nsIAtom* frameType = result->GetType();
|
|
|
|
if (frameType != nsGkAtoms::svgLinearGradientFrame &&
|
|
|
|
frameType != nsGkAtoms::svgRadialGradientFrame)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-10-01 04:51:05 +04:00
|
|
|
|
|
|
|
return static_cast<nsSVGGradientFrame*>(result);
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2012-03-06 10:58:40 +04:00
|
|
|
nsSVGGradientFrame *
|
|
|
|
nsSVGGradientFrame::GetReferencedGradientIfNotInUse()
|
2006-03-28 04:33:22 +04:00
|
|
|
{
|
2012-03-06 10:58:40 +04:00
|
|
|
nsSVGGradientFrame *referenced = GetReferencedGradient();
|
|
|
|
if (!referenced)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-03-28 04:33:22 +04:00
|
|
|
|
2012-03-06 10:58:40 +04:00
|
|
|
if (referenced->mLoopFlag) {
|
|
|
|
// XXXjwatt: we should really send an error to the JavaScript Console here:
|
|
|
|
NS_WARNING("gradient reference loop detected while inheriting attribute!");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-03-06 10:58:40 +04:00
|
|
|
}
|
2006-03-28 04:33:22 +04:00
|
|
|
|
2012-03-06 10:58:40 +04:00
|
|
|
return referenced;
|
2006-03-28 04:33:22 +04:00
|
|
|
}
|
|
|
|
|
2013-05-27 11:34:01 +04:00
|
|
|
void
|
|
|
|
nsSVGGradientFrame::GetStopFrames(nsTArray<nsIFrame*>* aStopFrames)
|
2004-10-15 03:02:53 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIFrame *stopFrame = nullptr;
|
2005-03-09 22:24:18 +03:00
|
|
|
for (stopFrame = mFrames.FirstChild(); stopFrame;
|
|
|
|
stopFrame = stopFrame->GetNextSibling()) {
|
2006-05-17 05:43:44 +04:00
|
|
|
if (stopFrame->GetType() == nsGkAtoms::svgStopFrame) {
|
2013-05-27 11:34:01 +04:00
|
|
|
aStopFrames->AppendElement(stopFrame);
|
2005-03-09 22:24:18 +03:00
|
|
|
}
|
|
|
|
}
|
2013-05-27 11:34:01 +04:00
|
|
|
if (aStopFrames->Length() > 0) {
|
|
|
|
return;
|
2006-03-28 04:33:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Our gradient element doesn't have stops - try to "inherit" them
|
|
|
|
|
2012-03-06 10:58:40 +04:00
|
|
|
AutoGradientReferencer gradientRef(this);
|
|
|
|
nsSVGGradientFrame* next = GetReferencedGradientIfNotInUse();
|
2013-05-27 11:34:01 +04:00
|
|
|
if (!next) {
|
|
|
|
return;
|
|
|
|
}
|
2006-03-28 04:33:22 +04:00
|
|
|
|
2013-05-27 11:34:01 +04:00
|
|
|
return next->GetStopFrames(aStopFrames);
|
2006-03-28 04:33:22 +04:00
|
|
|
}
|
|
|
|
|
2005-03-09 22:24:18 +03:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Linear Gradients
|
|
|
|
// -------------------------------------------------------------------------
|
2004-10-15 03:02:53 +04:00
|
|
|
|
2009-01-19 21:31:34 +03:00
|
|
|
#ifdef DEBUG
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsSVGLinearGradientFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2009-01-19 21:31:34 +03:00
|
|
|
{
|
2015-03-03 14:08:59 +03:00
|
|
|
NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::linearGradient),
|
2013-01-08 07:22:41 +04:00
|
|
|
"Content is not an SVG linearGradient");
|
2009-01-19 21:31:34 +03:00
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
nsSVGLinearGradientFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2009-01-19 21:31:34 +03:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2005-04-01 23:56:08 +04:00
|
|
|
nsIAtom*
|
|
|
|
nsSVGLinearGradientFrame::GetType() const
|
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::svgLinearGradientFrame;
|
2005-04-01 23:56:08 +04:00
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGLinearGradientFrame::AttributeChanged(int32_t aNameSpaceID,
|
2006-03-07 03:04:59 +03:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType)
|
2006-03-07 03:04:59 +03:00
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::x1 ||
|
|
|
|
aAttribute == nsGkAtoms::y1 ||
|
|
|
|
aAttribute == nsGkAtoms::x2 ||
|
|
|
|
aAttribute == nsGkAtoms::y2)) {
|
2012-06-23 18:19:00 +04:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2006-03-07 03:04:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsSVGGradientFrame::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
2004-10-15 03:02:53 +04:00
|
|
|
//----------------------------------------------------------------------
|
2006-03-28 04:33:22 +04:00
|
|
|
|
2006-05-12 00:01:12 +04:00
|
|
|
float
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGLinearGradientFrame::GetLengthValue(uint32_t aIndex)
|
2004-10-15 03:02:53 +04:00
|
|
|
{
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGLinearGradientElement* lengthElement =
|
2012-03-06 10:58:40 +04:00
|
|
|
GetLinearGradientWithLength(aIndex,
|
2013-01-11 12:43:01 +04:00
|
|
|
static_cast<dom::SVGLinearGradientElement*>(mContent));
|
2012-03-06 10:58:40 +04:00
|
|
|
// We passed in mContent as a fallback, so, assuming mContent is non-null, the
|
|
|
|
// return value should also be non-null.
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(lengthElement,
|
2012-03-06 10:58:40 +04:00
|
|
|
"Got unexpected null element from GetLinearGradientWithLength");
|
|
|
|
const nsSVGLength2 &length = lengthElement->mLengthAttributes[aIndex];
|
2006-03-07 03:04:59 +03:00
|
|
|
|
|
|
|
// Object bounding box units are handled by setting the appropriate
|
2007-08-28 03:11:14 +04:00
|
|
|
// transform in GetGradientTransform, but we need to handle user
|
2006-03-07 03:04:59 +03:00
|
|
|
// space units as part of the individual Get* routines. Fixes 323669.
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t gradientUnits = GetGradientUnits();
|
2013-02-18 06:14:02 +04:00
|
|
|
if (gradientUnits == SVG_UNIT_TYPE_USERSPACEONUSE) {
|
2012-03-06 10:58:40 +04:00
|
|
|
return nsSVGUtils::UserSpace(mSource, &length);
|
2006-03-07 03:04:59 +03:00
|
|
|
}
|
2006-03-28 04:33:22 +04:00
|
|
|
|
2012-03-06 10:58:40 +04:00
|
|
|
NS_ASSERTION(
|
2013-02-18 06:14:02 +04:00
|
|
|
gradientUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX,
|
2012-03-06 10:58:40 +04:00
|
|
|
"Unknown gradientUnits type");
|
2006-03-28 04:33:22 +04:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
return length.GetAnimValue(static_cast<SVGSVGElement*>(nullptr));
|
2012-03-06 10:58:40 +04:00
|
|
|
}
|
|
|
|
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGLinearGradientElement*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGLinearGradientFrame::GetLinearGradientWithLength(uint32_t aIndex,
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGLinearGradientElement* aDefault)
|
2012-03-06 10:58:40 +04:00
|
|
|
{
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGLinearGradientElement* thisElement =
|
|
|
|
static_cast<dom::SVGLinearGradientElement*>(mContent);
|
2012-03-06 10:58:40 +04:00
|
|
|
const nsSVGLength2 &length = thisElement->mLengthAttributes[aIndex];
|
|
|
|
|
|
|
|
if (length.IsExplicitlySet()) {
|
|
|
|
return thisElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsSVGLinearGradientFrameBase::GetLinearGradientWithLength(aIndex,
|
|
|
|
aDefault);
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2012-10-06 16:52:32 +04:00
|
|
|
bool
|
2013-05-27 11:34:01 +04:00
|
|
|
nsSVGLinearGradientFrame::GradientVectorLengthIsZero()
|
2012-10-06 16:52:32 +04:00
|
|
|
{
|
2013-05-27 11:34:01 +04:00
|
|
|
return GetLengthValue(dom::SVGLinearGradientElement::ATTR_X1) ==
|
|
|
|
GetLengthValue(dom::SVGLinearGradientElement::ATTR_X2) &&
|
|
|
|
GetLengthValue(dom::SVGLinearGradientElement::ATTR_Y1) ==
|
|
|
|
GetLengthValue(dom::SVGLinearGradientElement::ATTR_Y2);
|
2012-10-06 16:52:32 +04:00
|
|
|
}
|
|
|
|
|
2007-04-27 18:28:39 +04:00
|
|
|
already_AddRefed<gfxPattern>
|
2006-05-16 19:55:01 +04:00
|
|
|
nsSVGLinearGradientFrame::CreateGradient()
|
2004-10-15 03:02:53 +04:00
|
|
|
{
|
2006-05-16 19:55:01 +04:00
|
|
|
float x1, y1, x2, y2;
|
|
|
|
|
2013-01-11 12:43:01 +04:00
|
|
|
x1 = GetLengthValue(dom::SVGLinearGradientElement::ATTR_X1);
|
|
|
|
y1 = GetLengthValue(dom::SVGLinearGradientElement::ATTR_Y1);
|
|
|
|
x2 = GetLengthValue(dom::SVGLinearGradientElement::ATTR_X2);
|
|
|
|
y2 = GetLengthValue(dom::SVGLinearGradientElement::ATTR_Y2);
|
2006-05-16 19:55:01 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxPattern> pattern = new gfxPattern(x1, y1, x2, y2);
|
2013-04-22 15:15:59 +04:00
|
|
|
return pattern.forget();
|
2005-03-09 22:24:18 +03:00
|
|
|
}
|
2004-10-15 03:02:53 +04:00
|
|
|
|
2006-03-07 03:04:59 +03:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Radial Gradients
|
|
|
|
// -------------------------------------------------------------------------
|
2004-10-15 03:02:53 +04:00
|
|
|
|
2009-01-19 21:31:34 +03:00
|
|
|
#ifdef DEBUG
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsSVGRadialGradientFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2009-01-19 21:31:34 +03:00
|
|
|
{
|
2015-03-03 14:08:59 +03:00
|
|
|
NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::radialGradient),
|
2013-01-08 07:22:41 +04:00
|
|
|
"Content is not an SVG radialGradient");
|
2009-01-19 21:31:34 +03:00
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
nsSVGRadialGradientFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2009-01-19 21:31:34 +03:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2006-03-07 03:04:59 +03:00
|
|
|
nsIAtom*
|
|
|
|
nsSVGRadialGradientFrame::GetType() const
|
2004-10-15 03:02:53 +04:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::svgRadialGradientFrame;
|
2005-03-09 22:24:18 +03:00
|
|
|
}
|
2004-10-15 03:02:53 +04:00
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGRadialGradientFrame::AttributeChanged(int32_t aNameSpaceID,
|
2006-03-07 03:04:59 +03:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType)
|
2005-03-09 22:24:18 +03:00
|
|
|
{
|
2006-03-07 03:04:59 +03:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::r ||
|
|
|
|
aAttribute == nsGkAtoms::cx ||
|
|
|
|
aAttribute == nsGkAtoms::cy ||
|
|
|
|
aAttribute == nsGkAtoms::fx ||
|
|
|
|
aAttribute == nsGkAtoms::fy)) {
|
2012-06-23 18:19:00 +04:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2006-01-19 02:50:40 +03:00
|
|
|
}
|
2004-10-15 03:02:53 +04:00
|
|
|
|
2006-03-07 03:04:59 +03:00
|
|
|
return nsSVGGradientFrame::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
|
|
|
}
|
2004-10-15 03:02:53 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2006-05-12 00:01:12 +04:00
|
|
|
float
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGRadialGradientFrame::GetLengthValue(uint32_t aIndex)
|
2012-03-06 10:58:40 +04:00
|
|
|
{
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGRadialGradientElement* lengthElement =
|
2012-03-06 10:58:40 +04:00
|
|
|
GetRadialGradientWithLength(aIndex,
|
2013-01-11 12:43:01 +04:00
|
|
|
static_cast<dom::SVGRadialGradientElement*>(mContent));
|
2012-03-06 10:58:40 +04:00
|
|
|
// We passed in mContent as a fallback, so, assuming mContent is non-null,
|
|
|
|
// the return value should also be non-null.
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(lengthElement,
|
2012-03-06 10:58:40 +04:00
|
|
|
"Got unexpected null element from GetRadialGradientWithLength");
|
|
|
|
return GetLengthValueFromElement(aIndex, *lengthElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGRadialGradientFrame::GetLengthValue(uint32_t aIndex, float aDefaultValue)
|
2004-10-15 03:02:53 +04:00
|
|
|
{
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGRadialGradientElement* lengthElement =
|
2012-07-30 18:20:58 +04:00
|
|
|
GetRadialGradientWithLength(aIndex, nullptr);
|
2006-03-28 04:33:22 +04:00
|
|
|
|
2012-03-06 10:58:40 +04:00
|
|
|
return lengthElement ? GetLengthValueFromElement(aIndex, *lengthElement)
|
|
|
|
: aDefaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGRadialGradientFrame::GetLengthValueFromElement(uint32_t aIndex,
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGRadialGradientElement& aElement)
|
2012-03-06 10:58:40 +04:00
|
|
|
{
|
|
|
|
const nsSVGLength2 &length = aElement.mLengthAttributes[aIndex];
|
2006-03-28 04:33:22 +04:00
|
|
|
|
|
|
|
// Object bounding box units are handled by setting the appropriate
|
2007-08-28 03:11:14 +04:00
|
|
|
// transform in GetGradientTransform, but we need to handle user
|
2006-03-28 04:33:22 +04:00
|
|
|
// space units as part of the individual Get* routines. Fixes 323669.
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t gradientUnits = GetGradientUnits();
|
2013-02-18 06:14:02 +04:00
|
|
|
if (gradientUnits == SVG_UNIT_TYPE_USERSPACEONUSE) {
|
2012-03-06 10:58:40 +04:00
|
|
|
return nsSVGUtils::UserSpace(mSource, &length);
|
2006-01-19 02:50:40 +03:00
|
|
|
}
|
2006-03-28 04:33:22 +04:00
|
|
|
|
2012-03-06 10:58:40 +04:00
|
|
|
NS_ASSERTION(
|
2013-02-18 06:14:02 +04:00
|
|
|
gradientUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX,
|
2012-03-06 10:58:40 +04:00
|
|
|
"Unknown gradientUnits type");
|
2006-03-28 04:33:22 +04:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
return length.GetAnimValue(static_cast<SVGSVGElement*>(nullptr));
|
2005-03-09 22:24:18 +03:00
|
|
|
}
|
|
|
|
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGRadialGradientElement*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGRadialGradientFrame::GetRadialGradientWithLength(uint32_t aIndex,
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGRadialGradientElement* aDefault)
|
2005-03-09 22:24:18 +03:00
|
|
|
{
|
2013-01-11 12:43:01 +04:00
|
|
|
dom::SVGRadialGradientElement* thisElement =
|
|
|
|
static_cast<dom::SVGRadialGradientElement*>(mContent);
|
2012-03-06 10:58:40 +04:00
|
|
|
const nsSVGLength2 &length = thisElement->mLengthAttributes[aIndex];
|
2006-05-16 19:55:01 +04:00
|
|
|
|
2012-03-06 10:58:40 +04:00
|
|
|
if (length.IsExplicitlySet()) {
|
|
|
|
return thisElement;
|
|
|
|
}
|
2006-03-28 04:33:22 +04:00
|
|
|
|
2012-03-06 10:58:40 +04:00
|
|
|
return nsSVGRadialGradientFrameBase::GetRadialGradientWithLength(aIndex,
|
|
|
|
aDefault);
|
|
|
|
}
|
2006-03-28 04:33:22 +04:00
|
|
|
|
2012-10-06 16:52:32 +04:00
|
|
|
bool
|
2013-05-27 11:34:01 +04:00
|
|
|
nsSVGRadialGradientFrame::GradientVectorLengthIsZero()
|
2012-10-06 16:52:32 +04:00
|
|
|
{
|
2013-05-27 11:34:01 +04:00
|
|
|
return GetLengthValue(dom::SVGRadialGradientElement::ATTR_R) == 0;
|
2012-10-06 16:52:32 +04:00
|
|
|
}
|
|
|
|
|
2012-03-06 10:58:40 +04:00
|
|
|
already_AddRefed<gfxPattern>
|
|
|
|
nsSVGRadialGradientFrame::CreateGradient()
|
|
|
|
{
|
|
|
|
float cx, cy, r, fx, fy;
|
2006-03-28 04:33:22 +04:00
|
|
|
|
2013-01-11 12:43:01 +04:00
|
|
|
cx = GetLengthValue(dom::SVGRadialGradientElement::ATTR_CX);
|
|
|
|
cy = GetLengthValue(dom::SVGRadialGradientElement::ATTR_CY);
|
|
|
|
r = GetLengthValue(dom::SVGRadialGradientElement::ATTR_R);
|
2012-03-06 10:58:40 +04:00
|
|
|
// If fx or fy are not set, use cx/cy instead
|
2013-01-11 12:43:01 +04:00
|
|
|
fx = GetLengthValue(dom::SVGRadialGradientElement::ATTR_FX, cx);
|
|
|
|
fy = GetLengthValue(dom::SVGRadialGradientElement::ATTR_FY, cy);
|
2006-05-16 19:55:01 +04:00
|
|
|
|
|
|
|
if (fx != cx || fy != cy) {
|
|
|
|
// The focal point (fFx and fFy) must be clamped to be *inside* - not on -
|
|
|
|
// the circumference of the gradient or we'll get rendering anomalies. We
|
|
|
|
// calculate the distance from the focal point to the gradient center and
|
2010-07-01 00:24:53 +04:00
|
|
|
// make sure it is *less* than the gradient radius.
|
|
|
|
// 1/128 is the limit of the fractional part of cairo's 24.8 fixed point
|
|
|
|
// representation divided by 2 to ensure that we get different cairo
|
|
|
|
// fractions
|
2013-01-15 16:22:03 +04:00
|
|
|
double dMax = std::max(0.0, r - 1.0/128);
|
2006-05-16 19:55:01 +04:00
|
|
|
float dx = fx - cx;
|
|
|
|
float dy = fy - cy;
|
|
|
|
double d = sqrt((dx * dx) + (dy * dy));
|
|
|
|
if (d > dMax) {
|
|
|
|
double angle = atan2(dy, dx);
|
|
|
|
fx = (float)(dMax * cos(angle)) + cx;
|
|
|
|
fy = (float)(dMax * sin(angle)) + cy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxPattern> pattern = new gfxPattern(fx, fy, 0, cx, cy, r);
|
2013-04-22 15:15:59 +04:00
|
|
|
return pattern.forget();
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Public functions
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
2008-10-01 04:51:05 +04:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewSVGLinearGradientFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext)
|
2004-10-15 03:02:53 +04:00
|
|
|
{
|
2008-10-11 15:29:35 +04:00
|
|
|
return new (aPresShell) nsSVGLinearGradientFrame(aContext);
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGLinearGradientFrame)
|
|
|
|
|
2005-11-11 05:36:29 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewSVGRadialGradientFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext)
|
2004-10-15 03:02:53 +04:00
|
|
|
{
|
2008-10-11 15:29:35 +04:00
|
|
|
return new (aPresShell) nsSVGRadialGradientFrame(aContext);
|
2004-10-15 03:02:53 +04:00
|
|
|
}
|
2009-09-12 20:49:24 +04:00
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGRadialGradientFrame)
|