2015-05-03 22:32:37 +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
|
|
|
|
2018-12-28 05:47:10 +03:00
|
|
|
#include "SVGFilters.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2019-01-02 21:24:11 +03:00
|
|
|
#include <algorithm>
|
|
|
|
#include "DOMSVGAnimatedNumberList.h"
|
2019-03-19 03:01:03 +03:00
|
|
|
#include "DOMSVGAnimatedLength.h"
|
2006-07-28 22:10:48 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2019-01-02 21:44:12 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2019-01-02 21:24:11 +03:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2019-04-04 20:40:56 +03:00
|
|
|
#include "SVGAnimatedEnumeration.h"
|
|
|
|
#include "SVGAnimatedNumberPair.h"
|
|
|
|
#include "SVGAnimatedString.h"
|
2010-12-03 19:40:23 +03:00
|
|
|
#include "SVGNumberList.h"
|
2018-12-28 05:47:10 +03:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2019-01-02 21:24:11 +03:00
|
|
|
#include "mozilla/ComputedStyle.h"
|
|
|
|
#include "mozilla/SVGContentUtils.h"
|
2020-06-30 21:11:50 +03:00
|
|
|
#include "mozilla/SVGFilterInstance.h"
|
2013-02-12 14:01:17 +04:00
|
|
|
#include "mozilla/dom/SVGComponentTransferFunctionElement.h"
|
2019-01-02 21:24:11 +03:00
|
|
|
#include "mozilla/dom/SVGElement.h"
|
2013-03-15 12:20:30 +04:00
|
|
|
#include "mozilla/dom/SVGFEDistantLightElement.h"
|
2013-02-12 14:10:24 +04:00
|
|
|
#include "mozilla/dom/SVGFEFuncAElementBinding.h"
|
|
|
|
#include "mozilla/dom/SVGFEFuncBElementBinding.h"
|
|
|
|
#include "mozilla/dom/SVGFEFuncGElementBinding.h"
|
|
|
|
#include "mozilla/dom/SVGFEFuncRElementBinding.h"
|
2013-03-14 01:41:20 +04:00
|
|
|
#include "mozilla/dom/SVGFEPointLightElement.h"
|
2013-03-25 10:26:04 +04:00
|
|
|
#include "mozilla/dom/SVGFESpotLightElement.h"
|
2019-01-02 21:24:11 +03:00
|
|
|
#include "mozilla/dom/SVGFilterElement.h"
|
2018-02-02 16:21:33 +03:00
|
|
|
#include "mozilla/dom/SVGLengthBinding.h"
|
2008-07-14 05:21:25 +04:00
|
|
|
|
2013-03-25 10:26:04 +04:00
|
|
|
#if defined(XP_WIN)
|
2008-01-08 01:23:01 +03:00
|
|
|
// Prevent Windows redefining LoadImage
|
|
|
|
# undef LoadImage
|
|
|
|
#endif
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2013-11-27 15:25:29 +04:00
|
|
|
using namespace mozilla::gfx;
|
2012-04-13 11:01:55 +04:00
|
|
|
|
2018-12-21 15:32:35 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2007-07-26 10:57:42 +04:00
|
|
|
//--------------------Filter Element Base Class-----------------------
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2018-12-21 15:32:35 +03:00
|
|
|
SVGElement::LengthInfo SVGFE::sLengthInfo[4] = {
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::x, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE,
|
|
|
|
SVGContentUtils::X},
|
|
|
|
{nsGkAtoms::y, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE,
|
|
|
|
SVGContentUtils::Y},
|
|
|
|
{nsGkAtoms::width, 100, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE,
|
|
|
|
SVGContentUtils::X},
|
|
|
|
{nsGkAtoms::height, 100, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE,
|
|
|
|
SVGContentUtils::Y}};
|
2006-07-28 22:10:48 +04:00
|
|
|
|
2005-09-07 02:30:40 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
2018-12-21 15:32:35 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(SVGFE, SVGFEBase)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(SVGFE, SVGFEBase)
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2018-12-21 15:32:35 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN(SVGFE)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONCRETE(SVGFE)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(SVGFEBase)
|
2005-09-07 02:30:40 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2018-12-21 19:24:17 +03:00
|
|
|
void SVGFE::GetSourceImageNames(nsTArray<SVGStringInfo>& aSources) {}
|
2008-02-18 10:29:00 +03:00
|
|
|
|
2018-12-21 15:32:35 +03:00
|
|
|
bool SVGFE::OutputIsTainted(const nsTArray<bool>& aInputsAreTainted,
|
|
|
|
nsIPrincipal* aReferencePrincipal) {
|
2014-01-08 13:30:03 +04:00
|
|
|
// This is the default implementation for OutputIsTainted.
|
|
|
|
// Our output is tainted if we have at least one tainted input.
|
|
|
|
for (uint32_t i = 0; i < aInputsAreTainted.Length(); i++) {
|
|
|
|
if (aInputsAreTainted[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-21 15:32:35 +03:00
|
|
|
bool SVGFE::AttributeAffectsRendering(int32_t aNameSpaceID,
|
|
|
|
nsAtom* aAttribute) const {
|
2011-11-19 21:53:52 +04:00
|
|
|
return aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::x || aAttribute == nsGkAtoms::y ||
|
|
|
|
aAttribute == nsGkAtoms::width || aAttribute == nsGkAtoms::height ||
|
|
|
|
aAttribute == nsGkAtoms::result);
|
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedLength> SVGFE::X() {
|
2013-03-07 11:17:00 +04:00
|
|
|
return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this);
|
2007-07-26 10:57:42 +04:00
|
|
|
}
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedLength> SVGFE::Y() {
|
2013-03-07 11:17:00 +04:00
|
|
|
return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this);
|
2005-09-07 02:30:40 +04:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedLength> SVGFE::Width() {
|
2013-03-07 11:17:00 +04:00
|
|
|
return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this);
|
2007-07-26 10:57:42 +04:00
|
|
|
}
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedLength> SVGFE::Height() {
|
2013-03-07 11:17:00 +04:00
|
|
|
return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this);
|
2005-09-07 02:30:40 +04:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedString> SVGFE::Result() {
|
2013-03-07 11:17:00 +04:00
|
|
|
return GetResultImageName().ToDOMAnimatedString(this);
|
2005-09-07 02:30:40 +04:00
|
|
|
}
|
|
|
|
|
2011-08-20 17:02:41 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2018-12-21 15:32:35 +03:00
|
|
|
SVGFE::IsAttributeMapped(const nsAtom* name) const {
|
2011-08-20 17:02:41 +04:00
|
|
|
static const MappedAttributeEntry* const map[] = {sFiltersMap};
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2011-12-18 14:09:27 +04:00
|
|
|
return FindAttributeDependence(name, map) ||
|
2018-12-21 15:32:35 +03:00
|
|
|
SVGFEBase::IsAttributeMapped(name);
|
2011-08-20 17:02:41 +04:00
|
|
|
}
|
|
|
|
|
2006-07-28 22:10:48 +04:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-21 11:58:14 +03:00
|
|
|
// SVGElement methods
|
2006-07-28 22:10:48 +04:00
|
|
|
|
2018-12-21 15:32:35 +03:00
|
|
|
bool SVGFE::StyleIsSetToSRGB() {
|
2013-11-27 15:25:29 +04:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
|
|
|
if (!frame) return false;
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* style = frame->Style();
|
2013-11-27 15:25:29 +04:00
|
|
|
return style->StyleSVG()->mColorInterpolationFilters ==
|
2020-02-29 18:41:13 +03:00
|
|
|
StyleColorInterpolation::Srgb;
|
2013-11-27 15:25:29 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* virtual */
|
|
|
|
bool SVGFE::HasValidDimensions() const {
|
2013-03-07 11:17:00 +04:00
|
|
|
return (!mLengthAttributes[ATTR_WIDTH].IsExplicitlySet() ||
|
|
|
|
mLengthAttributes[ATTR_WIDTH].GetAnimValInSpecifiedUnits() > 0) &&
|
|
|
|
(!mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet() ||
|
|
|
|
mLengthAttributes[ATTR_HEIGHT].GetAnimValInSpecifiedUnits() > 0);
|
2012-03-03 13:21:09 +04:00
|
|
|
}
|
|
|
|
|
2020-06-30 21:11:50 +03:00
|
|
|
Size SVGFE::GetKernelUnitLength(SVGFilterInstance* aInstance,
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedNumberPair* aKernelUnitLength) {
|
2013-11-27 15:25:29 +04:00
|
|
|
if (!aKernelUnitLength->IsExplicitlySet()) {
|
|
|
|
return Size(1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
float kernelX = aInstance->GetPrimitiveNumber(
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGContentUtils::X, aKernelUnitLength, SVGAnimatedNumberPair::eFirst);
|
2013-11-27 15:25:29 +04:00
|
|
|
float kernelY = aInstance->GetPrimitiveNumber(
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGContentUtils::Y, aKernelUnitLength, SVGAnimatedNumberPair::eSecond);
|
2013-11-27 15:25:29 +04:00
|
|
|
return Size(kernelX, kernelY);
|
|
|
|
}
|
|
|
|
|
2018-12-21 15:32:35 +03:00
|
|
|
SVGElement::LengthAttributesInfo SVGFE::GetLengthInfo() {
|
2007-07-26 10:57:42 +04:00
|
|
|
return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
|
2011-10-11 09:50:08 +04:00
|
|
|
ArrayLength(sLengthInfo));
|
2006-07-28 22:10:48 +04:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::NumberListInfo
|
2013-02-12 13:56:55 +04:00
|
|
|
SVGComponentTransferFunctionElement::sNumberListInfo[1] = {
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::tableValues}};
|
2010-12-03 19:40:23 +03:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::NumberInfo SVGComponentTransferFunctionElement::sNumberInfo[5] = {
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::slope, 1, false},
|
|
|
|
{nsGkAtoms::intercept, 0, false},
|
|
|
|
{nsGkAtoms::amplitude, 1, false},
|
|
|
|
{nsGkAtoms::exponent, 1, false},
|
|
|
|
{nsGkAtoms::offset, 0, false}};
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2019-01-02 21:24:11 +03:00
|
|
|
SVGEnumMapping SVGComponentTransferFunctionElement::sTypeMap[] = {
|
2013-03-18 21:54:04 +04:00
|
|
|
{nsGkAtoms::identity, SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY},
|
|
|
|
{nsGkAtoms::table, SVG_FECOMPONENTTRANSFER_TYPE_TABLE},
|
|
|
|
{nsGkAtoms::discrete, SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE},
|
|
|
|
{nsGkAtoms::linear, SVG_FECOMPONENTTRANSFER_TYPE_LINEAR},
|
|
|
|
{nsGkAtoms::gamma, SVG_FECOMPONENTTRANSFER_TYPE_GAMMA},
|
2012-07-30 18:20:58 +04:00
|
|
|
{nullptr, 0}};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::EnumInfo SVGComponentTransferFunctionElement::sEnumInfo[1] = {
|
2013-03-18 21:54:04 +04:00
|
|
|
{nsGkAtoms::type, sTypeMap, SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY}};
|
2007-08-28 03:11:14 +04:00
|
|
|
|
2005-09-07 02:30:40 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
2013-02-12 13:56:55 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(SVGComponentTransferFunctionElement,
|
|
|
|
SVGComponentTransferFunctionElementBase)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(SVGComponentTransferFunctionElement,
|
|
|
|
SVGComponentTransferFunctionElementBase)
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2013-02-12 13:56:55 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(SVGComponentTransferFunctionElement)
|
2018-05-22 02:33:18 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONCRETE(SVGComponentTransferFunctionElement)
|
2013-02-12 13:56:55 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(SVGComponentTransferFunctionElementBase)
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2011-11-19 21:53:52 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsFEUnstyledElement methods
|
|
|
|
|
2013-02-12 13:56:55 +04:00
|
|
|
bool SVGComponentTransferFunctionElement::AttributeAffectsRendering(
|
2017-10-03 01:05:19 +03:00
|
|
|
int32_t aNameSpaceID, nsAtom* aAttribute) const {
|
2011-11-19 21:53:52 +04:00
|
|
|
return aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::tableValues ||
|
|
|
|
aAttribute == nsGkAtoms::slope ||
|
|
|
|
aAttribute == nsGkAtoms::intercept ||
|
|
|
|
aAttribute == nsGkAtoms::amplitude ||
|
|
|
|
aAttribute == nsGkAtoms::exponent ||
|
|
|
|
aAttribute == nsGkAtoms::offset || aAttribute == nsGkAtoms::type);
|
|
|
|
}
|
|
|
|
|
2005-09-07 02:30:40 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedEnumeration>
|
2013-02-12 14:10:24 +04:00
|
|
|
SVGComponentTransferFunctionElement::Type() {
|
|
|
|
return mEnumAttributes[TYPE].ToDOMAnimatedEnum(this);
|
|
|
|
}
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2013-02-12 14:10:24 +04:00
|
|
|
already_AddRefed<DOMSVGAnimatedNumberList>
|
|
|
|
SVGComponentTransferFunctionElement::TableValues() {
|
|
|
|
return DOMSVGAnimatedNumberList::GetDOMWrapper(
|
|
|
|
&mNumberListAttributes[TABLEVALUES], this, TABLEVALUES);
|
|
|
|
}
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedNumber>
|
2013-02-12 14:10:24 +04:00
|
|
|
SVGComponentTransferFunctionElement::Slope() {
|
|
|
|
return mNumberAttributes[SLOPE].ToDOMAnimatedNumber(this);
|
|
|
|
}
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedNumber>
|
2013-02-12 14:10:24 +04:00
|
|
|
SVGComponentTransferFunctionElement::Intercept() {
|
|
|
|
return mNumberAttributes[INTERCEPT].ToDOMAnimatedNumber(this);
|
|
|
|
}
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedNumber>
|
2013-02-12 14:10:24 +04:00
|
|
|
SVGComponentTransferFunctionElement::Amplitude() {
|
|
|
|
return mNumberAttributes[AMPLITUDE].ToDOMAnimatedNumber(this);
|
|
|
|
}
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedNumber>
|
2013-02-12 14:10:24 +04:00
|
|
|
SVGComponentTransferFunctionElement::Exponent() {
|
|
|
|
return mNumberAttributes[EXPONENT].ToDOMAnimatedNumber(this);
|
|
|
|
}
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedNumber>
|
2013-02-12 14:10:24 +04:00
|
|
|
SVGComponentTransferFunctionElement::Offset() {
|
|
|
|
return mNumberAttributes[OFFSET].ToDOMAnimatedNumber(this);
|
|
|
|
}
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
void SVGComponentTransferFunctionElement::ComputeAttributes(
|
|
|
|
int32_t aChannel, ComponentTransferAttributes& aAttributes) {
|
2013-11-27 15:25:29 +04:00
|
|
|
uint32_t type = mEnumAttributes[TYPE].GetAnimValue();
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2006-07-28 22:10:48 +04:00
|
|
|
float slope, intercept, amplitude, exponent, offset;
|
|
|
|
GetAnimatedNumberValues(&slope, &intercept, &litude, &exponent, &offset,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr);
|
2006-07-28 22:10:48 +04:00
|
|
|
|
2010-12-03 19:40:23 +03:00
|
|
|
const SVGNumberList& tableValues =
|
2011-07-01 11:19:52 +04:00
|
|
|
mNumberListAttributes[TABLEVALUES].GetAnimValue();
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
aAttributes.mTypes[aChannel] = (uint8_t)type;
|
|
|
|
switch (type) {
|
|
|
|
case SVG_FECOMPONENTTRANSFER_TYPE_LINEAR: {
|
|
|
|
aAttributes.mValues[aChannel].SetLength(2);
|
|
|
|
aAttributes.mValues[aChannel][kComponentTransferSlopeIndex] = slope;
|
|
|
|
aAttributes.mValues[aChannel][kComponentTransferInterceptIndex] =
|
|
|
|
intercept;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SVG_FECOMPONENTTRANSFER_TYPE_GAMMA: {
|
|
|
|
aAttributes.mValues[aChannel].SetLength(3);
|
|
|
|
aAttributes.mValues[aChannel][kComponentTransferAmplitudeIndex] =
|
|
|
|
amplitude;
|
|
|
|
aAttributes.mValues[aChannel][kComponentTransferExponentIndex] = exponent;
|
|
|
|
aAttributes.mValues[aChannel][kComponentTransferOffsetIndex] = offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE:
|
|
|
|
case SVG_FECOMPONENTTRANSFER_TYPE_TABLE: {
|
2018-09-26 20:07:41 +03:00
|
|
|
if (!tableValues.IsEmpty()) {
|
|
|
|
aAttributes.mValues[aChannel].AppendElements(&tableValues[0],
|
|
|
|
tableValues.Length());
|
|
|
|
}
|
2018-09-19 20:18:16 +03:00
|
|
|
break;
|
|
|
|
}
|
2005-09-07 02:30:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-28 22:10:48 +04:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-21 11:58:14 +03:00
|
|
|
// SVGElement methods
|
2006-07-28 22:10:48 +04:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::NumberListAttributesInfo
|
2013-02-12 13:56:55 +04:00
|
|
|
SVGComponentTransferFunctionElement::GetNumberListInfo() {
|
2010-12-03 19:40:23 +03:00
|
|
|
return NumberListAttributesInfo(mNumberListAttributes, sNumberListInfo,
|
2011-10-11 09:50:08 +04:00
|
|
|
ArrayLength(sNumberListInfo));
|
2010-12-03 19:40:23 +03:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::EnumAttributesInfo
|
2013-02-12 13:56:55 +04:00
|
|
|
SVGComponentTransferFunctionElement::GetEnumInfo() {
|
2007-09-18 16:09:26 +04:00
|
|
|
return EnumAttributesInfo(mEnumAttributes, sEnumInfo, ArrayLength(sEnumInfo));
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::NumberAttributesInfo
|
2013-02-12 13:56:55 +04:00
|
|
|
SVGComponentTransferFunctionElement::GetNumberInfo() {
|
2006-07-28 22:10:48 +04:00
|
|
|
return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
|
2011-10-11 09:50:08 +04:00
|
|
|
ArrayLength(sNumberInfo));
|
2006-07-28 22:10:48 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* virtual */
|
|
|
|
JSObject* SVGFEFuncRElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return SVGFEFuncRElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-02-12 14:10:24 +04:00
|
|
|
}
|
|
|
|
|
2013-02-12 13:56:55 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2018-12-21 14:43:29 +03:00
|
|
|
NS_IMPL_NS_NEW_SVG_ELEMENT(FEFuncR)
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2013-02-12 13:56:55 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEFuncRElement)
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* virtual */
|
|
|
|
JSObject* SVGFEFuncGElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return SVGFEFuncGElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-02-12 14:10:24 +04:00
|
|
|
}
|
|
|
|
|
2013-02-12 13:56:55 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2018-12-21 14:43:29 +03:00
|
|
|
NS_IMPL_NS_NEW_SVG_ELEMENT(FEFuncG)
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2013-02-12 13:56:55 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2013-02-12 13:56:55 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEFuncGElement)
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* virtual */
|
|
|
|
JSObject* SVGFEFuncBElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return SVGFEFuncBElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-02-12 14:10:24 +04:00
|
|
|
}
|
|
|
|
|
2013-02-12 13:56:55 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-12-21 14:43:29 +03:00
|
|
|
NS_IMPL_NS_NEW_SVG_ELEMENT(FEFuncB)
|
2013-02-12 13:56:55 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2013-02-12 13:56:55 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEFuncBElement)
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* virtual */
|
|
|
|
JSObject* SVGFEFuncAElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return SVGFEFuncAElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-02-12 14:10:24 +04:00
|
|
|
}
|
|
|
|
|
2013-02-12 13:56:55 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-12-21 14:43:29 +03:00
|
|
|
NS_IMPL_NS_NEW_SVG_ELEMENT(FEFuncA)
|
2013-02-12 13:56:55 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEFuncAElement)
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2013-03-25 10:26:05 +04:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
//
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::NumberInfo SVGFELightingElement::sNumberInfo[4] = {
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::surfaceScale, 1, false},
|
|
|
|
{nsGkAtoms::diffuseConstant, 1, false},
|
|
|
|
{nsGkAtoms::specularConstant, 1, false},
|
|
|
|
{nsGkAtoms::specularExponent, 1, false}};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::NumberPairInfo SVGFELightingElement::sNumberPairInfo[1] = {
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::kernelUnitLength, 0, 0}};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::StringInfo SVGFELightingElement::sStringInfo[2] = {
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::result, kNameSpaceID_None, true},
|
|
|
|
{nsGkAtoms::in, kNameSpaceID_None, true}};
|
2008-06-14 13:01:02 +04:00
|
|
|
|
2007-08-31 18:44:28 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
2007-06-27 23:02:58 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2018-12-20 11:01:54 +03:00
|
|
|
SVGFELightingElement::IsAttributeMapped(const nsAtom* name) const {
|
2007-07-26 10:57:42 +04:00
|
|
|
static const MappedAttributeEntry* const map[] = {sColorMap,
|
|
|
|
sLightingEffectsMap};
|
2007-06-27 23:02:58 +04:00
|
|
|
|
2011-12-18 14:09:27 +04:00
|
|
|
return FindAttributeDependence(name, map) ||
|
2018-12-20 11:01:54 +03:00
|
|
|
SVGFELightingElementBase::IsAttributeMapped(name);
|
2007-06-27 23:02:58 +04:00
|
|
|
}
|
|
|
|
|
2018-12-20 11:01:54 +03:00
|
|
|
void SVGFELightingElement::GetSourceImageNames(
|
2018-12-21 19:24:17 +03:00
|
|
|
nsTArray<SVGStringInfo>& aSources) {
|
|
|
|
aSources.AppendElement(SVGStringInfo(&mStringAttributes[IN1], this));
|
2008-02-18 10:29:00 +03:00
|
|
|
}
|
|
|
|
|
2018-12-20 11:01:54 +03:00
|
|
|
LightType SVGFELightingElement::ComputeLightAttributes(
|
2020-06-30 21:11:50 +03:00
|
|
|
SVGFilterInstance* aInstance, nsTArray<float>& aFloatAttributes) {
|
2013-03-14 01:41:20 +04:00
|
|
|
// find specified light
|
2011-09-27 11:54:58 +04:00
|
|
|
for (nsCOMPtr<nsIContent> child = nsINode::GetFirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (child->IsAnyOfSVGElements(nsGkAtoms::feDistantLight,
|
|
|
|
nsGkAtoms::fePointLight,
|
|
|
|
nsGkAtoms::feSpotLight)) {
|
2018-09-19 20:18:16 +03:00
|
|
|
return static_cast<SVGFELightElement*>(child.get())
|
|
|
|
->ComputeLightAttributes(aInstance, aFloatAttributes);
|
2007-06-27 23:02:58 +04:00
|
|
|
}
|
2007-07-26 10:57:42 +04:00
|
|
|
}
|
2007-06-27 23:02:58 +04:00
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
return LightType::None;
|
2013-11-27 15:25:29 +04:00
|
|
|
}
|
2007-06-27 23:02:58 +04:00
|
|
|
|
2018-12-20 11:01:54 +03:00
|
|
|
bool SVGFELightingElement::AddLightingAttributes(
|
2018-09-19 20:18:16 +03:00
|
|
|
mozilla::gfx::DiffuseLightingAttributes* aAttributes,
|
2020-06-30 21:11:50 +03:00
|
|
|
SVGFilterInstance* aInstance) {
|
2013-11-27 15:25:29 +04:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
|
|
|
if (!frame) {
|
2018-09-19 20:18:16 +03:00
|
|
|
return false;
|
2007-06-27 23:02:58 +04:00
|
|
|
}
|
|
|
|
|
2018-04-27 05:07:20 +03:00
|
|
|
const nsStyleSVGReset* styleSVGReset = frame->Style()->StyleSVGReset();
|
2020-03-09 17:16:17 +03:00
|
|
|
sRGBColor color(
|
|
|
|
sRGBColor::FromABGR(styleSVGReset->mLightingColor.CalcColor(frame)));
|
2014-10-17 15:53:16 +04:00
|
|
|
color.a = 1.f;
|
2013-11-27 15:25:29 +04:00
|
|
|
float surfaceScale = mNumberAttributes[SURFACE_SCALE].GetAnimValue();
|
|
|
|
Size kernelUnitLength = GetKernelUnitLength(
|
|
|
|
aInstance, &mNumberPairAttributes[KERNEL_UNIT_LENGTH]);
|
|
|
|
|
2017-01-19 16:07:25 +03:00
|
|
|
if (kernelUnitLength.width <= 0 || kernelUnitLength.height <= 0) {
|
|
|
|
// According to spec, A negative or zero value is an error. See link below
|
|
|
|
// for details.
|
|
|
|
// https://www.w3.org/TR/SVG/filters.html#feSpecularLightingKernelUnitLengthAttribute
|
2018-09-19 20:18:16 +03:00
|
|
|
return false;
|
2017-01-19 16:07:25 +03:00
|
|
|
}
|
|
|
|
|
2018-09-19 20:18:16 +03:00
|
|
|
aAttributes->mLightType =
|
|
|
|
ComputeLightAttributes(aInstance, aAttributes->mLightValues);
|
|
|
|
aAttributes->mSurfaceScale = surfaceScale;
|
|
|
|
aAttributes->mKernelUnitLength = kernelUnitLength;
|
|
|
|
aAttributes->mColor = color;
|
|
|
|
|
|
|
|
return true;
|
2007-06-27 23:02:58 +04:00
|
|
|
}
|
|
|
|
|
2018-12-20 11:01:54 +03:00
|
|
|
bool SVGFELightingElement::AttributeAffectsRendering(int32_t aNameSpaceID,
|
|
|
|
nsAtom* aAttribute) const {
|
|
|
|
return SVGFELightingElementBase::AttributeAffectsRendering(aNameSpaceID,
|
|
|
|
aAttribute) ||
|
2011-11-19 21:53:52 +04:00
|
|
|
(aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::in ||
|
|
|
|
aAttribute == nsGkAtoms::surfaceScale ||
|
|
|
|
aAttribute == nsGkAtoms::kernelUnitLength));
|
|
|
|
}
|
|
|
|
|
2008-06-14 13:01:02 +04:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-21 11:58:14 +03:00
|
|
|
// SVGElement methods
|
2008-06-14 13:01:02 +04:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::NumberAttributesInfo SVGFELightingElement::GetNumberInfo() {
|
2008-06-14 13:01:02 +04:00
|
|
|
return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
|
2011-10-11 09:50:08 +04:00
|
|
|
ArrayLength(sNumberInfo));
|
2008-06-14 13:01:02 +04:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::NumberPairAttributesInfo SVGFELightingElement::GetNumberPairInfo() {
|
2011-07-01 11:19:52 +04:00
|
|
|
return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
|
2011-10-11 09:50:08 +04:00
|
|
|
ArrayLength(sNumberPairInfo));
|
2011-07-01 11:19:52 +04:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::StringAttributesInfo SVGFELightingElement::GetStringInfo() {
|
2008-06-14 13:01:02 +04:00
|
|
|
return StringAttributesInfo(mStringAttributes, sStringInfo,
|
2011-10-11 09:50:08 +04:00
|
|
|
ArrayLength(sStringInfo));
|
2008-06-14 13:01:02 +04:00
|
|
|
}
|
2018-12-20 11:01:54 +03:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|