2005-09-07 02:30:40 +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/. */
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Main header first:
|
2005-09-07 02:30:40 +04:00
|
|
|
#include "nsSVGFilterFrame.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxUtils.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2011-10-09 21:17:29 +04:00
|
|
|
#include "nsSVGEffects.h"
|
2012-06-26 14:49:23 +04:00
|
|
|
#include "nsSVGElement.h"
|
2013-02-18 03:28:47 +04:00
|
|
|
#include "mozilla/dom/SVGFilterElement.h"
|
2008-09-11 04:24:16 +04:00
|
|
|
#include "nsSVGFilterInstance.h"
|
2012-06-24 16:59:26 +04:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGUtils.h"
|
2013-02-01 03:11:49 +04:00
|
|
|
#include "nsContentUtils.h"
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2013-02-18 03:28:47 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2005-11-11 05:36:29 +03:00
|
|
|
nsIFrame*
|
2009-01-19 21:31:34 +03:00
|
|
|
NS_NewSVGFilterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2005-09-07 02:30:40 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsSVGFilterFrame(aContext);
|
2005-09-07 02:30:40 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGFilterFrame)
|
|
|
|
|
2015-09-03 19:15:23 +03:00
|
|
|
class MOZ_RAII nsSVGFilterFrame::AutoFilterReferencer
|
2012-03-28 15:31:47 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit AutoFilterReferencer(nsSVGFilterFrame *aFrame MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-03-28 15:31:47 +04:00
|
|
|
: mFrame(aFrame)
|
|
|
|
{
|
2013-12-26 22:49:49 +04:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2012-03-28 15:31:47 +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-28 15:31:47 +04:00
|
|
|
mFrame->mLoopFlag = true;
|
|
|
|
}
|
|
|
|
~AutoFilterReferencer() {
|
|
|
|
mFrame->mLoopFlag = false;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsSVGFilterFrame *mFrame;
|
2013-12-26 22:49:49 +04:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2012-03-28 15:31:47 +04:00
|
|
|
};
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t
|
|
|
|
nsSVGFilterFrame::GetEnumValue(uint32_t aIndex, nsIContent *aDefault)
|
2012-03-28 15:31:47 +04:00
|
|
|
{
|
|
|
|
nsSVGEnum& thisEnum =
|
2013-02-18 03:28:47 +04:00
|
|
|
static_cast<SVGFilterElement *>(mContent)->mEnumAttributes[aIndex];
|
2012-03-28 15:31:47 +04:00
|
|
|
|
|
|
|
if (thisEnum.IsExplicitlySet())
|
|
|
|
return thisEnum.GetAnimValue();
|
|
|
|
|
|
|
|
AutoFilterReferencer filterRef(this);
|
|
|
|
|
|
|
|
nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse();
|
|
|
|
return next ? next->GetEnumValue(aIndex, aDefault) :
|
2013-02-18 03:28:47 +04:00
|
|
|
static_cast<SVGFilterElement *>(aDefault)->
|
2012-03-28 15:31:47 +04:00
|
|
|
mEnumAttributes[aIndex].GetAnimValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsSVGLength2 *
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGFilterFrame::GetLengthValue(uint32_t aIndex, nsIContent *aDefault)
|
2012-03-28 15:31:47 +04:00
|
|
|
{
|
|
|
|
const nsSVGLength2 *thisLength =
|
2013-02-18 03:28:47 +04:00
|
|
|
&static_cast<SVGFilterElement *>(mContent)->mLengthAttributes[aIndex];
|
2012-03-28 15:31:47 +04:00
|
|
|
|
|
|
|
if (thisLength->IsExplicitlySet())
|
|
|
|
return thisLength;
|
|
|
|
|
|
|
|
AutoFilterReferencer filterRef(this);
|
|
|
|
|
|
|
|
nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse();
|
|
|
|
return next ? next->GetLengthValue(aIndex, aDefault) :
|
2013-02-18 03:28:47 +04:00
|
|
|
&static_cast<SVGFilterElement *>(aDefault)->mLengthAttributes[aIndex];
|
2012-03-28 15:31:47 +04:00
|
|
|
}
|
|
|
|
|
2013-02-18 03:28:47 +04:00
|
|
|
const SVGFilterElement *
|
2012-03-28 15:31:47 +04:00
|
|
|
nsSVGFilterFrame::GetFilterContent(nsIContent *aDefault)
|
|
|
|
{
|
2012-03-29 12:41:37 +04:00
|
|
|
for (nsIContent* child = mContent->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSVGFE> primitive;
|
2012-03-28 15:31:47 +04:00
|
|
|
CallQueryInterface(child, (nsSVGFE**)getter_AddRefs(primitive));
|
|
|
|
if (primitive) {
|
2013-02-18 03:28:47 +04:00
|
|
|
return static_cast<SVGFilterElement *>(mContent);
|
2012-03-28 15:31:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoFilterReferencer filterRef(this);
|
|
|
|
|
|
|
|
nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse();
|
|
|
|
return next ? next->GetFilterContent(aDefault) :
|
2013-02-18 03:28:47 +04:00
|
|
|
static_cast<SVGFilterElement *>(aDefault);
|
2012-03-28 15:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGFilterFrame *
|
|
|
|
nsSVGFilterFrame::GetReferencedFilter()
|
|
|
|
{
|
|
|
|
if (mNoHRefURI)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-03-28 15:31:47 +04:00
|
|
|
|
|
|
|
nsSVGPaintingProperty *property = static_cast<nsSVGPaintingProperty*>
|
|
|
|
(Properties().Get(nsSVGEffects::HrefProperty()));
|
|
|
|
|
|
|
|
if (!property) {
|
|
|
|
// Fetch our Filter element's xlink:href attribute
|
2013-02-18 03:28:47 +04:00
|
|
|
SVGFilterElement *filter = static_cast<SVGFilterElement *>(mContent);
|
2012-03-28 15:31:47 +04:00
|
|
|
nsAutoString href;
|
2013-02-18 03:28:47 +04:00
|
|
|
filter->mStringAttributes[SVGFilterElement::HREF].GetAnimValue(href, filter);
|
2012-03-28 15:31:47 +04:00
|
|
|
if (href.IsEmpty()) {
|
|
|
|
mNoHRefURI = true;
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr; // no URL
|
2012-03-28 15:31:47 +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);
|
2012-03-28 15:31:47 +04:00
|
|
|
|
|
|
|
property =
|
|
|
|
nsSVGEffects::GetPaintingProperty(targetURI, this, nsSVGEffects::HrefProperty());
|
|
|
|
if (!property)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-03-28 15:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame *result = property->GetReferencedFrame();
|
|
|
|
if (!result)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-03-28 15:31:47 +04:00
|
|
|
|
|
|
|
nsIAtom* frameType = result->GetType();
|
|
|
|
if (frameType != nsGkAtoms::svgFilterFrame)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-03-28 15:31:47 +04:00
|
|
|
|
|
|
|
return static_cast<nsSVGFilterFrame*>(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGFilterFrame *
|
|
|
|
nsSVGFilterFrame::GetReferencedFilterIfNotInUse()
|
|
|
|
{
|
|
|
|
nsSVGFilterFrame *referenced = GetReferencedFilter();
|
|
|
|
if (!referenced)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-03-28 15:31:47 +04: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 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-03-28 15:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return referenced;
|
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGFilterFrame::AttributeChanged(int32_t aNameSpaceID,
|
2011-10-09 21:17:29 +04:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType)
|
2011-10-09 21:17:29 +04:00
|
|
|
{
|
2012-03-28 15:31:47 +04: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 18:19:00 +04:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2012-03-28 15:31:47 +04: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 18:19:00 +04:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2011-10-09 21:17:29 +04:00
|
|
|
}
|
|
|
|
return nsSVGFilterFrameBase::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
nsSVGFilterFrame::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::filter),
|
2013-01-08 07:22:41 +04:00
|
|
|
"Content is not an SVG filter");
|
2009-01-19 21:31:34 +03:00
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
nsSVGFilterFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2009-01-19 21:31:34 +03:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2005-09-07 02:30:40 +04:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGFilterFrame::GetType() const
|
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::svgFilterFrame;
|
2005-09-07 02:30:40 +04:00
|
|
|
}
|