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
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Main header first:
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGFilterFrame.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2011-10-09 10:17:29 -07:00
|
|
|
#include "nsSVGEffects.h"
|
2012-06-26 03:49:23 -07:00
|
|
|
#include "nsSVGElement.h"
|
2013-02-17 15:28:47 -08:00
|
|
|
#include "mozilla/dom/SVGFilterElement.h"
|
2008-09-10 17:24:16 -07:00
|
|
|
#include "nsSVGFilterInstance.h"
|
2012-06-24 05:59:26 -07:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGUtils.h"
|
2013-01-31 15:11:49 -08:00
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-17 15:28:47 -08:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGFilterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGFilterFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGFilterFrame)
|
|
|
|
|
2013-12-26 10:49:49 -08:00
|
|
|
class MOZ_STACK_CLASS nsSVGFilterFrame::AutoFilterReferencer
|
2012-03-28 04:31:47 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-08-31 20:36:37 -07:00
|
|
|
explicit AutoFilterReferencer(nsSVGFilterFrame *aFrame MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-03-28 04:31:47 -07:00
|
|
|
: mFrame(aFrame)
|
|
|
|
{
|
2013-12-26 10:49:49 -08:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2012-03-28 04:31:47 -07:00
|
|
|
// Reference loops should normally be detected in advance and handled, so
|
|
|
|
// we're not expecting to encounter them here
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(!mFrame->mLoopFlag, "Undetected reference loop!");
|
2012-03-28 04:31:47 -07:00
|
|
|
mFrame->mLoopFlag = true;
|
|
|
|
}
|
|
|
|
~AutoFilterReferencer() {
|
|
|
|
mFrame->mLoopFlag = false;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsSVGFilterFrame *mFrame;
|
2013-12-26 10:49:49 -08:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2012-03-28 04:31:47 -07:00
|
|
|
};
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t
|
|
|
|
nsSVGFilterFrame::GetEnumValue(uint32_t aIndex, nsIContent *aDefault)
|
2012-03-28 04:31:47 -07:00
|
|
|
{
|
|
|
|
nsSVGEnum& thisEnum =
|
2013-02-17 15:28:47 -08:00
|
|
|
static_cast<SVGFilterElement *>(mContent)->mEnumAttributes[aIndex];
|
2012-03-28 04:31:47 -07:00
|
|
|
|
|
|
|
if (thisEnum.IsExplicitlySet())
|
|
|
|
return thisEnum.GetAnimValue();
|
|
|
|
|
|
|
|
AutoFilterReferencer filterRef(this);
|
|
|
|
|
|
|
|
nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse();
|
|
|
|
return next ? next->GetEnumValue(aIndex, aDefault) :
|
2013-02-17 15:28:47 -08:00
|
|
|
static_cast<SVGFilterElement *>(aDefault)->
|
2012-03-28 04:31:47 -07:00
|
|
|
mEnumAttributes[aIndex].GetAnimValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsSVGLength2 *
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGFilterFrame::GetLengthValue(uint32_t aIndex, nsIContent *aDefault)
|
2012-03-28 04:31:47 -07:00
|
|
|
{
|
|
|
|
const nsSVGLength2 *thisLength =
|
2013-02-17 15:28:47 -08:00
|
|
|
&static_cast<SVGFilterElement *>(mContent)->mLengthAttributes[aIndex];
|
2012-03-28 04:31:47 -07:00
|
|
|
|
|
|
|
if (thisLength->IsExplicitlySet())
|
|
|
|
return thisLength;
|
|
|
|
|
|
|
|
AutoFilterReferencer filterRef(this);
|
|
|
|
|
|
|
|
nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse();
|
|
|
|
return next ? next->GetLengthValue(aIndex, aDefault) :
|
2013-02-17 15:28:47 -08:00
|
|
|
&static_cast<SVGFilterElement *>(aDefault)->mLengthAttributes[aIndex];
|
2012-03-28 04:31:47 -07:00
|
|
|
}
|
|
|
|
|
2013-02-17 15:28:47 -08:00
|
|
|
const SVGFilterElement *
|
2012-03-28 04:31:47 -07:00
|
|
|
nsSVGFilterFrame::GetFilterContent(nsIContent *aDefault)
|
|
|
|
{
|
2012-03-29 01:41:37 -07:00
|
|
|
for (nsIContent* child = mContent->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2012-03-28 04:31:47 -07:00
|
|
|
nsRefPtr<nsSVGFE> primitive;
|
|
|
|
CallQueryInterface(child, (nsSVGFE**)getter_AddRefs(primitive));
|
|
|
|
if (primitive) {
|
2013-02-17 15:28:47 -08:00
|
|
|
return static_cast<SVGFilterElement *>(mContent);
|
2012-03-28 04:31:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoFilterReferencer filterRef(this);
|
|
|
|
|
|
|
|
nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse();
|
|
|
|
return next ? next->GetFilterContent(aDefault) :
|
2013-02-17 15:28:47 -08:00
|
|
|
static_cast<SVGFilterElement *>(aDefault);
|
2012-03-28 04:31:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGFilterFrame *
|
|
|
|
nsSVGFilterFrame::GetReferencedFilter()
|
|
|
|
{
|
|
|
|
if (mNoHRefURI)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-28 04:31:47 -07:00
|
|
|
|
|
|
|
nsSVGPaintingProperty *property = static_cast<nsSVGPaintingProperty*>
|
|
|
|
(Properties().Get(nsSVGEffects::HrefProperty()));
|
|
|
|
|
|
|
|
if (!property) {
|
|
|
|
// Fetch our Filter element's xlink:href attribute
|
2013-02-17 15:28:47 -08:00
|
|
|
SVGFilterElement *filter = static_cast<SVGFilterElement *>(mContent);
|
2012-03-28 04:31:47 -07:00
|
|
|
nsAutoString href;
|
2013-02-17 15:28:47 -08:00
|
|
|
filter->mStringAttributes[SVGFilterElement::HREF].GetAnimValue(href, filter);
|
2012-03-28 04:31:47 -07:00
|
|
|
if (href.IsEmpty()) {
|
|
|
|
mNoHRefURI = true;
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr; // no URL
|
2012-03-28 04:31:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert href to an nsIURI
|
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
nsCOMPtr<nsIURI> base = mContent->GetBaseURI();
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), href,
|
|
|
|
mContent->GetCurrentDoc(), base);
|
|
|
|
|
|
|
|
property =
|
|
|
|
nsSVGEffects::GetPaintingProperty(targetURI, this, nsSVGEffects::HrefProperty());
|
|
|
|
if (!property)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-28 04:31:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame *result = property->GetReferencedFrame();
|
|
|
|
if (!result)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-28 04:31:47 -07:00
|
|
|
|
|
|
|
nsIAtom* frameType = result->GetType();
|
|
|
|
if (frameType != nsGkAtoms::svgFilterFrame)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-28 04:31:47 -07:00
|
|
|
|
|
|
|
return static_cast<nsSVGFilterFrame*>(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGFilterFrame *
|
|
|
|
nsSVGFilterFrame::GetReferencedFilterIfNotInUse()
|
|
|
|
{
|
|
|
|
nsSVGFilterFrame *referenced = GetReferencedFilter();
|
|
|
|
if (!referenced)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-28 04:31:47 -07:00
|
|
|
|
|
|
|
if (referenced->mLoopFlag) {
|
|
|
|
// XXXjwatt: we should really send an error to the JavaScript Console here:
|
|
|
|
NS_WARNING("Filter reference loop detected while inheriting attribute!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-28 04:31:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return referenced;
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGFilterFrame::AttributeChanged(int32_t aNameSpaceID,
|
2011-10-09 10:17:29 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2011-10-09 10:17:29 -07:00
|
|
|
{
|
2012-03-28 04:31:47 -07:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::x ||
|
|
|
|
aAttribute == nsGkAtoms::y ||
|
|
|
|
aAttribute == nsGkAtoms::width ||
|
|
|
|
aAttribute == nsGkAtoms::height ||
|
|
|
|
aAttribute == nsGkAtoms::filterUnits ||
|
|
|
|
aAttribute == nsGkAtoms::primitiveUnits)) {
|
2012-06-23 07:19:00 -07:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2012-03-28 04:31:47 -07:00
|
|
|
} else if (aNameSpaceID == kNameSpaceID_XLink &&
|
|
|
|
aAttribute == nsGkAtoms::href) {
|
|
|
|
// Blow away our reference, if any
|
|
|
|
Properties().Delete(nsSVGEffects::HrefProperty());
|
|
|
|
mNoHRefURI = false;
|
|
|
|
// And update whoever references us
|
2012-06-23 07:19:00 -07:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2011-10-09 10:17:29 -07:00
|
|
|
}
|
|
|
|
return nsSVGFilterFrameBase::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
#ifdef DEBUG
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2014-05-24 15:20:40 -07:00
|
|
|
nsSVGFilterFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2009-01-19 10:31:34 -08:00
|
|
|
{
|
2015-03-03 03:08:59 -08:00
|
|
|
NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::filter),
|
2013-01-07 19:22:41 -08:00
|
|
|
"Content is not an SVG filter");
|
2009-01-19 10:31:34 -08:00
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
nsSVGFilterFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2009-01-19 10:31:34 -08:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGFilterFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgFilterFrame;
|
|
|
|
}
|