Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / dom / svg / SVGFEDropShadowElement.cpp
blob275f6003b1a24830fc429d2a8cca8fca3a74e030
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/SVGFEDropShadowElement.h"
8 #include "mozilla/dom/SVGFEDropShadowElementBinding.h"
9 #include "mozilla/SVGFilterInstance.h"
10 #include "nsIFrame.h"
12 NS_IMPL_NS_NEW_SVG_ELEMENT(FEDropShadow)
14 using namespace mozilla::gfx;
16 namespace mozilla::dom {
18 JSObject* SVGFEDropShadowElement::WrapNode(JSContext* aCx,
19 JS::Handle<JSObject*> aGivenProto) {
20 return SVGFEDropShadowElement_Binding::Wrap(aCx, this, aGivenProto);
23 SVGElement::NumberInfo SVGFEDropShadowElement::sNumberInfo[2] = {
24 {nsGkAtoms::dx, 2, false}, {nsGkAtoms::dy, 2, false}};
26 SVGElement::NumberPairInfo SVGFEDropShadowElement::sNumberPairInfo[1] = {
27 {nsGkAtoms::stdDeviation, 2, 2}};
29 SVGElement::StringInfo SVGFEDropShadowElement::sStringInfo[2] = {
30 {nsGkAtoms::result, kNameSpaceID_None, true},
31 {nsGkAtoms::in, kNameSpaceID_None, true}};
33 //----------------------------------------------------------------------
34 // nsINode methods
36 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEDropShadowElement)
38 //----------------------------------------------------------------------
40 already_AddRefed<DOMSVGAnimatedString> SVGFEDropShadowElement::In1() {
41 return mStringAttributes[IN1].ToDOMAnimatedString(this);
44 already_AddRefed<DOMSVGAnimatedNumber> SVGFEDropShadowElement::Dx() {
45 return mNumberAttributes[DX].ToDOMAnimatedNumber(this);
48 already_AddRefed<DOMSVGAnimatedNumber> SVGFEDropShadowElement::Dy() {
49 return mNumberAttributes[DY].ToDOMAnimatedNumber(this);
52 already_AddRefed<DOMSVGAnimatedNumber> SVGFEDropShadowElement::StdDeviationX() {
53 return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber(
54 SVGAnimatedNumberPair::eFirst, this);
57 already_AddRefed<DOMSVGAnimatedNumber> SVGFEDropShadowElement::StdDeviationY() {
58 return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber(
59 SVGAnimatedNumberPair::eSecond, this);
62 void SVGFEDropShadowElement::SetStdDeviation(float stdDeviationX,
63 float stdDeviationY) {
64 mNumberPairAttributes[STD_DEV].SetBaseValues(stdDeviationX, stdDeviationY,
65 this);
68 FilterPrimitiveDescription SVGFEDropShadowElement::GetPrimitiveDescription(
69 SVGFilterInstance* aInstance, const IntRect& aFilterSubregion,
70 const nsTArray<bool>& aInputsAreTainted,
71 nsTArray<RefPtr<SourceSurface>>& aInputImages) {
72 float stdX = aInstance->GetPrimitiveNumber(SVGContentUtils::X,
73 &mNumberPairAttributes[STD_DEV],
74 SVGAnimatedNumberPair::eFirst);
75 float stdY = aInstance->GetPrimitiveNumber(SVGContentUtils::Y,
76 &mNumberPairAttributes[STD_DEV],
77 SVGAnimatedNumberPair::eSecond);
78 if (stdX < 0 || stdY < 0) {
79 return FilterPrimitiveDescription();
82 Point offset(
83 aInstance->GetPrimitiveNumber(SVGContentUtils::X, &mNumberAttributes[DX]),
84 aInstance->GetPrimitiveNumber(SVGContentUtils::Y,
85 &mNumberAttributes[DY]));
87 DropShadowAttributes atts;
88 atts.mStdDeviation = Size(stdX, stdY);
89 atts.mOffset = offset;
91 nsIFrame* frame = GetPrimaryFrame();
92 if (frame) {
93 const nsStyleSVGReset* styleSVGReset = frame->Style()->StyleSVGReset();
94 sRGBColor color(
95 sRGBColor::FromABGR(styleSVGReset->mFloodColor.CalcColor(frame)));
96 color.a *= styleSVGReset->mFloodOpacity;
97 atts.mColor = color;
98 } else {
99 atts.mColor = sRGBColor();
101 return FilterPrimitiveDescription(AsVariant(std::move(atts)));
104 bool SVGFEDropShadowElement::AttributeAffectsRendering(
105 int32_t aNameSpaceID, nsAtom* aAttribute) const {
106 return SVGFEDropShadowElementBase::AttributeAffectsRendering(aNameSpaceID,
107 aAttribute) ||
108 (aNameSpaceID == kNameSpaceID_None &&
109 (aAttribute == nsGkAtoms::in ||
110 aAttribute == nsGkAtoms::stdDeviation ||
111 aAttribute == nsGkAtoms::dx || aAttribute == nsGkAtoms::dy));
114 void SVGFEDropShadowElement::GetSourceImageNames(
115 nsTArray<SVGStringInfo>& aSources) {
116 aSources.AppendElement(SVGStringInfo(&mStringAttributes[IN1], this));
119 //----------------------------------------------------------------------
120 // SVGElement methods
122 SVGElement::NumberAttributesInfo SVGFEDropShadowElement::GetNumberInfo() {
123 return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
124 ArrayLength(sNumberInfo));
127 SVGElement::NumberPairAttributesInfo
128 SVGFEDropShadowElement::GetNumberPairInfo() {
129 return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
130 ArrayLength(sNumberPairInfo));
133 SVGElement::StringAttributesInfo SVGFEDropShadowElement::GetStringInfo() {
134 return StringAttributesInfo(mStringAttributes, sStringInfo,
135 ArrayLength(sStringInfo));
138 } // namespace mozilla::dom