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/SVGComponentTransferFunctionElement.h"
8 : #include "mozilla/dom/SVGFEComponentTransferElement.h"
9 : #include "mozilla/dom/SVGFEComponentTransferElementBinding.h"
10 : #include "nsSVGUtils.h"
11 : #include "mozilla/gfx/2D.h"
12 :
13 0 : NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEComponentTransfer)
14 :
15 : using namespace mozilla::gfx;;
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 : JSObject*
21 0 : SVGFEComponentTransferElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
22 : {
23 0 : return SVGFEComponentTransferElementBinding::Wrap(aCx, this, aGivenProto);
24 : }
25 :
26 : nsSVGElement::StringInfo SVGFEComponentTransferElement::sStringInfo[2] =
27 : {
28 : { &nsGkAtoms::result, kNameSpaceID_None, true },
29 : { &nsGkAtoms::in, kNameSpaceID_None, true }
30 : };
31 :
32 : //----------------------------------------------------------------------
33 : // nsIDOMNode methods
34 :
35 0 : NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEComponentTransferElement)
36 :
37 : already_AddRefed<SVGAnimatedString>
38 0 : SVGFEComponentTransferElement::In1()
39 : {
40 0 : return mStringAttributes[IN1].ToDOMAnimatedString(this);
41 : }
42 :
43 : //----------------------------------------------------------------------
44 : // nsSVGElement methods
45 :
46 : nsSVGElement::StringAttributesInfo
47 0 : SVGFEComponentTransferElement::GetStringInfo()
48 : {
49 : return StringAttributesInfo(mStringAttributes, sStringInfo,
50 0 : ArrayLength(sStringInfo));
51 : }
52 :
53 : //--------------------------------------------
54 :
55 : FilterPrimitiveDescription
56 0 : SVGFEComponentTransferElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstance,
57 : const IntRect& aFilterSubregion,
58 : const nsTArray<bool>& aInputsAreTainted,
59 : nsTArray<RefPtr<SourceSurface>>& aInputImages)
60 : {
61 0 : RefPtr<SVGComponentTransferFunctionElement> childForChannel[4];
62 :
63 0 : for (nsIContent* childContent = nsINode::GetFirstChild();
64 0 : childContent;
65 0 : childContent = childContent->GetNextSibling()) {
66 :
67 0 : RefPtr<SVGComponentTransferFunctionElement> child;
68 0 : CallQueryInterface(childContent,
69 0 : (SVGComponentTransferFunctionElement**)getter_AddRefs(child));
70 0 : if (child) {
71 0 : childForChannel[child->GetChannel()] = child;
72 : }
73 : }
74 :
75 : static const AttributeName attributeNames[4] = {
76 : eComponentTransferFunctionR,
77 : eComponentTransferFunctionG,
78 : eComponentTransferFunctionB,
79 : eComponentTransferFunctionA
80 : };
81 :
82 0 : FilterPrimitiveDescription descr(PrimitiveType::ComponentTransfer);
83 0 : for (int32_t i = 0; i < 4; i++) {
84 0 : if (childForChannel[i]) {
85 0 : descr.Attributes().Set(attributeNames[i], childForChannel[i]->ComputeAttributes());
86 : } else {
87 0 : AttributeMap functionAttributes;
88 : functionAttributes.Set(eComponentTransferFunctionType,
89 0 : (uint32_t)SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY);
90 0 : descr.Attributes().Set(attributeNames[i], functionAttributes);
91 : }
92 : }
93 0 : return descr;
94 : }
95 :
96 : bool
97 0 : SVGFEComponentTransferElement::AttributeAffectsRendering(int32_t aNameSpaceID,
98 : nsIAtom* aAttribute) const
99 : {
100 0 : return SVGFEComponentTransferElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
101 0 : (aNameSpaceID == kNameSpaceID_None &&
102 0 : aAttribute == nsGkAtoms::in);
103 : }
104 :
105 : void
106 0 : SVGFEComponentTransferElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
107 : {
108 0 : aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this));
109 0 : }
110 :
111 : } // namespace dom
112 : } // namespace mozilla
|