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/. */
|
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:
|
2017-02-21 12:37:09 +03:00
|
|
|
#include "AutoReferenceChainGuard.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "gfxUtils.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2017-08-30 16:14:46 +03:00
|
|
|
#include "SVGObserverUtils.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
|
|
|
|
2017-02-21 12:37:09 +03:00
|
|
|
using namespace mozilla;
|
2013-02-18 03:28:47 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
nsIFrame* NS_NewSVGFilterFrame(nsIPresShell* aPresShell,
|
|
|
|
ComputedStyle* aStyle) {
|
|
|
|
return new (aPresShell) nsSVGFilterFrame(aStyle);
|
2005-09-07 02:30:40 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGFilterFrame)
|
|
|
|
|
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 =
|
2017-08-27 01:58:38 +03:00
|
|
|
static_cast<SVGFilterElement*>(GetContent())->mEnumAttributes[aIndex];
|
2012-03-28 15:31:47 +04:00
|
|
|
|
2018-12-12 09:32:44 +03:00
|
|
|
if (thisEnum.IsExplicitlySet()) {
|
|
|
|
return thisEnum.GetAnimValue();
|
|
|
|
}
|
2012-03-28 15:31:47 +04:00
|
|
|
|
2017-02-21 12:37:09 +03:00
|
|
|
// Before we recurse, make sure we'll break reference loops and over long
|
|
|
|
// reference chains:
|
|
|
|
static int16_t sRefChainLengthCounter = AutoReferenceChainGuard::noChain;
|
|
|
|
AutoReferenceChainGuard refChainGuard(this, &mLoopFlag,
|
|
|
|
&sRefChainLengthCounter);
|
|
|
|
if (MOZ_UNLIKELY(!refChainGuard.Reference())) {
|
|
|
|
// Break reference chain
|
|
|
|
return static_cast<SVGFilterElement*>(aDefault)
|
|
|
|
->mEnumAttributes[aIndex]
|
|
|
|
.GetAnimValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGFilterFrame* next = GetReferencedFilter();
|
2012-03-28 15:31:47 +04:00
|
|
|
|
2017-02-21 12:37:09 +03:00
|
|
|
return next ? next->GetEnumValue(aIndex, aDefault)
|
|
|
|
: static_cast<SVGFilterElement*>(aDefault)
|
|
|
|
->mEnumAttributes[aIndex]
|
|
|
|
.GetAnimValue();
|
2012-03-28 15:31:47 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
const nsSVGLength2* nsSVGFilterFrame::GetLengthValue(uint32_t aIndex,
|
|
|
|
nsIContent* aDefault) {
|
2012-03-28 15:31:47 +04:00
|
|
|
const nsSVGLength2* thisLength =
|
2017-08-27 01:58:38 +03:00
|
|
|
&static_cast<SVGFilterElement*>(GetContent())->mLengthAttributes[aIndex];
|
2012-03-28 15:31:47 +04:00
|
|
|
|
2018-12-12 09:32:44 +03:00
|
|
|
if (thisLength->IsExplicitlySet()) {
|
|
|
|
return thisLength;
|
|
|
|
}
|
2012-03-28 15:31:47 +04:00
|
|
|
|
2017-02-21 12:37:09 +03:00
|
|
|
// Before we recurse, make sure we'll break reference loops and over long
|
|
|
|
// reference chains:
|
|
|
|
static int16_t sRefChainLengthCounter = AutoReferenceChainGuard::noChain;
|
|
|
|
AutoReferenceChainGuard refChainGuard(this, &mLoopFlag,
|
|
|
|
&sRefChainLengthCounter);
|
|
|
|
if (MOZ_UNLIKELY(!refChainGuard.Reference())) {
|
|
|
|
// Break reference chain
|
|
|
|
return &static_cast<SVGFilterElement*>(aDefault)->mLengthAttributes[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGFilterFrame* next = GetReferencedFilter();
|
2012-03-28 15:31:47 +04:00
|
|
|
|
2017-02-21 12:37:09 +03:00
|
|
|
return next ? next->GetLengthValue(aIndex, aDefault)
|
|
|
|
: &static_cast<SVGFilterElement*>(aDefault)
|
|
|
|
->mLengthAttributes[aIndex];
|
2012-03-28 15:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const SVGFilterElement* 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) {
|
2017-08-27 01:58:38 +03:00
|
|
|
return static_cast<SVGFilterElement*>(GetContent());
|
2012-03-28 15:31:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-21 12:37:09 +03:00
|
|
|
// Before we recurse, make sure we'll break reference loops and over long
|
|
|
|
// reference chains:
|
|
|
|
static int16_t sRefChainLengthCounter = AutoReferenceChainGuard::noChain;
|
|
|
|
AutoReferenceChainGuard refChainGuard(this, &mLoopFlag,
|
|
|
|
&sRefChainLengthCounter);
|
|
|
|
if (MOZ_UNLIKELY(!refChainGuard.Reference())) {
|
|
|
|
// Break reference chain
|
|
|
|
return static_cast<SVGFilterElement*>(aDefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGFilterFrame* next = GetReferencedFilter();
|
2012-03-28 15:31:47 +04:00
|
|
|
|
2017-02-21 12:37:09 +03:00
|
|
|
return next ? next->GetFilterContent(aDefault)
|
|
|
|
: static_cast<SVGFilterElement*>(aDefault);
|
2012-03-28 15:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGFilterFrame* nsSVGFilterFrame::GetReferencedFilter() {
|
2018-08-21 16:54:26 +03:00
|
|
|
if (mNoHRefURI) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2018-08-21 16:54:26 +03:00
|
|
|
}
|
2012-03-28 15:31:47 +04:00
|
|
|
|
2018-08-21 16:54:26 +03:00
|
|
|
auto GetHref = [this](nsAString& aHref) {
|
|
|
|
SVGFilterElement* filter = static_cast<SVGFilterElement*>(GetContent());
|
2016-07-05 13:18:51 +03:00
|
|
|
if (filter->mStringAttributes[SVGFilterElement::HREF].IsExplicitlySet()) {
|
|
|
|
filter->mStringAttributes[SVGFilterElement::HREF].GetAnimValue(aHref,
|
2018-08-21 16:54:26 +03:00
|
|
|
filter);
|
2016-07-05 13:18:51 +03:00
|
|
|
} else {
|
|
|
|
filter->mStringAttributes[SVGFilterElement::XLINK_HREF].GetAnimValue(
|
2018-08-21 16:54:26 +03:00
|
|
|
aHref, filter);
|
2016-07-05 13:18:51 +03:00
|
|
|
}
|
2018-08-21 16:54:26 +03:00
|
|
|
this->mNoHRefURI = aHref.IsEmpty();
|
|
|
|
};
|
|
|
|
|
2018-09-25 23:16:49 +03:00
|
|
|
nsIFrame* tframe = SVGObserverUtils::GetAndObserveTemplate(this, GetHref);
|
2018-08-21 16:54:26 +03:00
|
|
|
if (tframe) {
|
|
|
|
LayoutFrameType frameType = tframe->Type();
|
|
|
|
if (frameType == LayoutFrameType::SVGFilter) {
|
|
|
|
return static_cast<nsSVGFilterFrame*>(tframe);
|
2018-08-17 18:57:30 +03:00
|
|
|
}
|
2018-08-21 16:54:26 +03:00
|
|
|
// We don't call SVGObserverUtils::RemoveTemplateObserver and set
|
|
|
|
// `mNoHRefURI = false` here since we want to be invalidated if the ID
|
|
|
|
// specified by our href starts resolving to a different/valid element.
|
2012-03-28 15:31:47 +04:00
|
|
|
}
|
|
|
|
|
2018-08-21 16:54:26 +03:00
|
|
|
return nullptr;
|
2012-03-28 15:31:47 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult nsSVGFilterFrame::AttributeChanged(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType) {
|
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)) {
|
2017-08-30 17:58:31 +03:00
|
|
|
SVGObserverUtils::InvalidateDirectRenderingObservers(this);
|
2016-07-05 13:18:51 +03:00
|
|
|
} else if ((aNameSpaceID == kNameSpaceID_XLink ||
|
|
|
|
aNameSpaceID == kNameSpaceID_None) &&
|
2012-03-28 15:31:47 +04:00
|
|
|
aAttribute == nsGkAtoms::href) {
|
|
|
|
// Blow away our reference, if any
|
2018-08-21 16:54:26 +03:00
|
|
|
SVGObserverUtils::RemoveTemplateObserver(this);
|
2012-03-28 15:31:47 +04:00
|
|
|
mNoHRefURI = false;
|
|
|
|
// And update whoever references us
|
2017-08-30 17:58:31 +03:00
|
|
|
SVGObserverUtils::InvalidateDirectRenderingObservers(this);
|
2011-10-09 21:17:29 +04:00
|
|
|
}
|
2016-04-18 10:02:37 +03:00
|
|
|
return nsSVGContainerFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
2011-10-09 21:17:29 +04:00
|
|
|
}
|
|
|
|
|
2009-01-19 21:31:34 +03:00
|
|
|
#ifdef DEBUG
|
2014-05-25 02:20:40 +04:00
|
|
|
void nsSVGFilterFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
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
|
|
|
|
2016-04-18 10:02:37 +03:00
|
|
|
nsSVGContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2009-01-19 21:31:34 +03:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|