Line data Source code
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/SVGFESpecularLightingElement.h"
8 : #include "mozilla/dom/SVGFESpecularLightingElementBinding.h"
9 : #include "nsSVGUtils.h"
10 : #include "nsSVGFilterInstance.h"
11 :
12 0 : NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FESpecularLighting)
13 :
14 : using namespace mozilla::gfx;
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 : JSObject*
20 0 : SVGFESpecularLightingElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
21 : {
22 0 : return SVGFESpecularLightingElementBinding::Wrap(aCx, this, aGivenProto);
23 : }
24 :
25 : //----------------------------------------------------------------------
26 : // nsIDOMNode methods
27 :
28 0 : NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFESpecularLightingElement)
29 :
30 : already_AddRefed<SVGAnimatedString>
31 0 : SVGFESpecularLightingElement::In1()
32 : {
33 0 : return mStringAttributes[IN1].ToDOMAnimatedString(this);
34 : }
35 :
36 : already_AddRefed<SVGAnimatedNumber>
37 0 : SVGFESpecularLightingElement::SurfaceScale()
38 : {
39 0 : return mNumberAttributes[SURFACE_SCALE].ToDOMAnimatedNumber(this);
40 : }
41 :
42 : already_AddRefed<SVGAnimatedNumber>
43 0 : SVGFESpecularLightingElement::SpecularConstant()
44 : {
45 0 : return mNumberAttributes[SPECULAR_CONSTANT].ToDOMAnimatedNumber(this);
46 : }
47 :
48 : already_AddRefed<SVGAnimatedNumber>
49 0 : SVGFESpecularLightingElement::SpecularExponent()
50 : {
51 0 : return mNumberAttributes[SPECULAR_EXPONENT].ToDOMAnimatedNumber(this);
52 : }
53 :
54 : already_AddRefed<SVGAnimatedNumber>
55 0 : SVGFESpecularLightingElement::KernelUnitLengthX()
56 : {
57 : return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(
58 0 : nsSVGNumberPair::eFirst, this);
59 : }
60 :
61 : already_AddRefed<SVGAnimatedNumber>
62 0 : SVGFESpecularLightingElement::KernelUnitLengthY()
63 : {
64 : return mNumberPairAttributes[KERNEL_UNIT_LENGTH].ToDOMAnimatedNumber(
65 0 : nsSVGNumberPair::eSecond, this);
66 : }
67 :
68 : //----------------------------------------------------------------------
69 : // nsSVGElement methods
70 :
71 : FilterPrimitiveDescription
72 0 : SVGFESpecularLightingElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstance,
73 : const IntRect& aFilterSubregion,
74 : const nsTArray<bool>& aInputsAreTainted,
75 : nsTArray<RefPtr<SourceSurface>>& aInputImages)
76 : {
77 0 : float specularExponent = mNumberAttributes[SPECULAR_EXPONENT].GetAnimValue();
78 0 : float specularConstant = mNumberAttributes[SPECULAR_CONSTANT].GetAnimValue();
79 :
80 : // specification defined range (15.22)
81 0 : if (specularExponent < 1 || specularExponent > 128) {
82 0 : return FilterPrimitiveDescription(PrimitiveType::Empty);
83 : }
84 :
85 0 : FilterPrimitiveDescription descr(PrimitiveType::SpecularLighting);
86 0 : descr.Attributes().Set(eSpecularLightingSpecularConstant, specularConstant);
87 0 : descr.Attributes().Set(eSpecularLightingSpecularExponent, specularExponent);
88 0 : return AddLightingAttributes(descr, aInstance);
89 : }
90 :
91 : bool
92 0 : SVGFESpecularLightingElement::AttributeAffectsRendering(int32_t aNameSpaceID,
93 : nsIAtom* aAttribute) const
94 : {
95 0 : return SVGFESpecularLightingElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
96 0 : (aNameSpaceID == kNameSpaceID_None &&
97 0 : (aAttribute == nsGkAtoms::specularConstant ||
98 0 : aAttribute == nsGkAtoms::specularExponent));
99 : }
100 :
101 : } // namespace dom
102 : } // namespace mozilla
|