/src/mozilla-central/dom/svg/SVGFEDropShadowElement.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "mozilla/dom/SVGFEDropShadowElement.h" |
8 | | #include "mozilla/dom/SVGFEDropShadowElementBinding.h" |
9 | | #include "nsIFrame.h" |
10 | | #include "nsSVGFilterInstance.h" |
11 | | |
12 | | NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEDropShadow) |
13 | | |
14 | | using namespace mozilla::gfx; |
15 | | |
16 | | namespace mozilla { |
17 | | namespace dom { |
18 | | |
19 | | JSObject* |
20 | | SVGFEDropShadowElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
21 | 0 | { |
22 | 0 | return SVGFEDropShadowElement_Binding::Wrap(aCx, this, aGivenProto); |
23 | 0 | } |
24 | | |
25 | | nsSVGElement::NumberInfo SVGFEDropShadowElement::sNumberInfo[2] = |
26 | | { |
27 | | { &nsGkAtoms::dx, 2, false }, |
28 | | { &nsGkAtoms::dy, 2, false } |
29 | | }; |
30 | | |
31 | | nsSVGElement::NumberPairInfo SVGFEDropShadowElement::sNumberPairInfo[1] = |
32 | | { |
33 | | { &nsGkAtoms::stdDeviation, 2, 2 } |
34 | | }; |
35 | | |
36 | | nsSVGElement::StringInfo SVGFEDropShadowElement::sStringInfo[2] = |
37 | | { |
38 | | { &nsGkAtoms::result, kNameSpaceID_None, true }, |
39 | | { &nsGkAtoms::in, kNameSpaceID_None, true } |
40 | | }; |
41 | | |
42 | | //---------------------------------------------------------------------- |
43 | | // nsINode methods |
44 | | |
45 | | NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEDropShadowElement) |
46 | | |
47 | | //---------------------------------------------------------------------- |
48 | | |
49 | | already_AddRefed<SVGAnimatedString> |
50 | | SVGFEDropShadowElement::In1() |
51 | 0 | { |
52 | 0 | return mStringAttributes[IN1].ToDOMAnimatedString(this); |
53 | 0 | } |
54 | | |
55 | | already_AddRefed<SVGAnimatedNumber> |
56 | | SVGFEDropShadowElement::Dx() |
57 | 0 | { |
58 | 0 | return mNumberAttributes[DX].ToDOMAnimatedNumber(this); |
59 | 0 | } |
60 | | |
61 | | already_AddRefed<SVGAnimatedNumber> |
62 | | SVGFEDropShadowElement::Dy() |
63 | 0 | { |
64 | 0 | return mNumberAttributes[DY].ToDOMAnimatedNumber(this); |
65 | 0 | } |
66 | | |
67 | | already_AddRefed<SVGAnimatedNumber> |
68 | | SVGFEDropShadowElement::StdDeviationX() |
69 | 0 | { |
70 | 0 | return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber(nsSVGNumberPair::eFirst, this); |
71 | 0 | } |
72 | | |
73 | | already_AddRefed<SVGAnimatedNumber> |
74 | | SVGFEDropShadowElement::StdDeviationY() |
75 | 0 | { |
76 | 0 | return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber(nsSVGNumberPair::eSecond, this); |
77 | 0 | } |
78 | | |
79 | | void |
80 | | SVGFEDropShadowElement::SetStdDeviation(float stdDeviationX, float stdDeviationY) |
81 | 0 | { |
82 | 0 | mNumberPairAttributes[STD_DEV].SetBaseValues(stdDeviationX, stdDeviationY, this); |
83 | 0 | } |
84 | | |
85 | | FilterPrimitiveDescription |
86 | | SVGFEDropShadowElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstance, |
87 | | const IntRect& aFilterSubregion, |
88 | | const nsTArray<bool>& aInputsAreTainted, |
89 | | nsTArray<RefPtr<SourceSurface>>& aInputImages) |
90 | 0 | { |
91 | 0 | float stdX = aInstance->GetPrimitiveNumber(SVGContentUtils::X, |
92 | 0 | &mNumberPairAttributes[STD_DEV], |
93 | 0 | nsSVGNumberPair::eFirst); |
94 | 0 | float stdY = aInstance->GetPrimitiveNumber(SVGContentUtils::Y, |
95 | 0 | &mNumberPairAttributes[STD_DEV], |
96 | 0 | nsSVGNumberPair::eSecond); |
97 | 0 | if (stdX < 0 || stdY < 0) { |
98 | 0 | return FilterPrimitiveDescription(); |
99 | 0 | } |
100 | 0 | |
101 | 0 | IntPoint offset(int32_t(aInstance->GetPrimitiveNumber( |
102 | 0 | SVGContentUtils::X, &mNumberAttributes[DX])), |
103 | 0 | int32_t(aInstance->GetPrimitiveNumber( |
104 | 0 | SVGContentUtils::Y, &mNumberAttributes[DY]))); |
105 | 0 |
|
106 | 0 | DropShadowAttributes atts; |
107 | 0 | atts.mStdDeviation = Size(stdX, stdY); |
108 | 0 | atts.mOffset = offset; |
109 | 0 |
|
110 | 0 | nsIFrame* frame = GetPrimaryFrame(); |
111 | 0 | if (frame) { |
112 | 0 | const nsStyleSVGReset* styleSVGReset = frame->Style()->StyleSVGReset(); |
113 | 0 | Color color(Color::FromABGR(styleSVGReset->mFloodColor.CalcColor(frame))); |
114 | 0 | color.a *= styleSVGReset->mFloodOpacity; |
115 | 0 | atts.mColor = color; |
116 | 0 | } else { |
117 | 0 | atts.mColor = Color(); |
118 | 0 | } |
119 | 0 | return FilterPrimitiveDescription(AsVariant(std::move(atts))); |
120 | 0 | } |
121 | | |
122 | | bool |
123 | | SVGFEDropShadowElement::AttributeAffectsRendering(int32_t aNameSpaceID, |
124 | | nsAtom* aAttribute) const |
125 | 0 | { |
126 | 0 | return SVGFEDropShadowElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) || |
127 | 0 | (aNameSpaceID == kNameSpaceID_None && |
128 | 0 | (aAttribute == nsGkAtoms::in || |
129 | 0 | aAttribute == nsGkAtoms::stdDeviation || |
130 | 0 | aAttribute == nsGkAtoms::dx || |
131 | 0 | aAttribute == nsGkAtoms::dy)); |
132 | 0 | } |
133 | | |
134 | | void |
135 | | SVGFEDropShadowElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources) |
136 | 0 | { |
137 | 0 | aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this)); |
138 | 0 | } |
139 | | |
140 | | //---------------------------------------------------------------------- |
141 | | // nsIContent methods |
142 | | |
143 | | NS_IMETHODIMP_(bool) |
144 | | SVGFEDropShadowElement::IsAttributeMapped(const nsAtom* name) const |
145 | 0 | { |
146 | 0 | static const MappedAttributeEntry* const map[] = { |
147 | 0 | sFEFloodMap |
148 | 0 | }; |
149 | 0 |
|
150 | 0 | return FindAttributeDependence(name, map) || |
151 | 0 | SVGFEDropShadowElementBase::IsAttributeMapped(name); |
152 | 0 | } |
153 | | |
154 | | //---------------------------------------------------------------------- |
155 | | // nsSVGElement methods |
156 | | |
157 | | nsSVGElement::NumberAttributesInfo |
158 | | SVGFEDropShadowElement::GetNumberInfo() |
159 | 0 | { |
160 | 0 | return NumberAttributesInfo(mNumberAttributes, sNumberInfo, |
161 | 0 | ArrayLength(sNumberInfo)); |
162 | 0 | } |
163 | | |
164 | | nsSVGElement::NumberPairAttributesInfo |
165 | | SVGFEDropShadowElement::GetNumberPairInfo() |
166 | 0 | { |
167 | 0 | return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo, |
168 | 0 | ArrayLength(sNumberPairInfo)); |
169 | 0 | } |
170 | | |
171 | | nsSVGElement::StringAttributesInfo |
172 | | SVGFEDropShadowElement::GetStringInfo() |
173 | 0 | { |
174 | 0 | return StringAttributesInfo(mStringAttributes, sStringInfo, |
175 | 0 | ArrayLength(sStringInfo)); |
176 | 0 | } |
177 | | |
178 | | } // namespace dom |
179 | | } // namespace mozilla |