Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / svg / SVGFEColorMatrixElement.cpp
blobf9de1116b798a910be6e73b1a10ad8467eb9f2fe
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/SVGFEColorMatrixElement.h"
9 #include "DOMSVGAnimatedNumberList.h"
10 #include "mozilla/dom/SVGFEColorMatrixElementBinding.h"
11 #include "mozilla/dom/Document.h"
12 #include "mozilla/dom/BindContext.h"
14 #define NUM_ENTRIES_IN_4x5_MATRIX 20
16 NS_IMPL_NS_NEW_SVG_ELEMENT(FEColorMatrix)
18 using namespace mozilla::gfx;
20 namespace mozilla::dom {
22 JSObject* SVGFEColorMatrixElement::WrapNode(JSContext* aCx,
23 JS::Handle<JSObject*> aGivenProto) {
24 return SVGFEColorMatrixElement_Binding::Wrap(aCx, this, aGivenProto);
27 SVGEnumMapping SVGFEColorMatrixElement::sTypeMap[] = {
28 {nsGkAtoms::matrix, SVG_FECOLORMATRIX_TYPE_MATRIX},
29 {nsGkAtoms::saturate, SVG_FECOLORMATRIX_TYPE_SATURATE},
30 {nsGkAtoms::hueRotate, SVG_FECOLORMATRIX_TYPE_HUE_ROTATE},
31 {nsGkAtoms::luminanceToAlpha, SVG_FECOLORMATRIX_TYPE_LUMINANCE_TO_ALPHA},
32 {nullptr, 0}};
34 SVGElement::EnumInfo SVGFEColorMatrixElement::sEnumInfo[1] = {
35 {nsGkAtoms::type, sTypeMap, SVG_FECOLORMATRIX_TYPE_MATRIX}};
37 SVGElement::StringInfo SVGFEColorMatrixElement::sStringInfo[2] = {
38 {nsGkAtoms::result, kNameSpaceID_None, true},
39 {nsGkAtoms::in, kNameSpaceID_None, true}};
41 SVGElement::NumberListInfo SVGFEColorMatrixElement::sNumberListInfo[1] = {
42 {nsGkAtoms::values}};
44 //----------------------------------------------------------------------
45 // nsINode methods
47 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEColorMatrixElement)
49 //----------------------------------------------------------------------
51 already_AddRefed<DOMSVGAnimatedString> SVGFEColorMatrixElement::In1() {
52 return mStringAttributes[IN1].ToDOMAnimatedString(this);
55 already_AddRefed<DOMSVGAnimatedEnumeration> SVGFEColorMatrixElement::Type() {
56 return mEnumAttributes[TYPE].ToDOMAnimatedEnum(this);
59 already_AddRefed<DOMSVGAnimatedNumberList> SVGFEColorMatrixElement::Values() {
60 return DOMSVGAnimatedNumberList::GetDOMWrapper(&mNumberListAttributes[VALUES],
61 this, VALUES);
64 void SVGFEColorMatrixElement::GetSourceImageNames(
65 nsTArray<SVGStringInfo>& aSources) {
66 aSources.AppendElement(SVGStringInfo(&mStringAttributes[IN1], this));
69 FilterPrimitiveDescription SVGFEColorMatrixElement::GetPrimitiveDescription(
70 SVGFilterInstance* aInstance, const IntRect& aFilterSubregion,
71 const nsTArray<bool>& aInputsAreTainted,
72 nsTArray<RefPtr<SourceSurface>>& aInputImages) {
73 uint32_t type = mEnumAttributes[TYPE].GetAnimValue();
74 const SVGNumberList& values = mNumberListAttributes[VALUES].GetAnimValue();
76 ColorMatrixAttributes atts;
77 if (!mNumberListAttributes[VALUES].IsExplicitlySet() &&
78 (type == SVG_FECOLORMATRIX_TYPE_MATRIX ||
79 type == SVG_FECOLORMATRIX_TYPE_SATURATE ||
80 type == SVG_FECOLORMATRIX_TYPE_HUE_ROTATE)) {
81 atts.mType = (uint32_t)SVG_FECOLORMATRIX_TYPE_MATRIX;
82 static const auto identityMatrix = std::array{
83 // clang-format off
84 1, 0, 0, 0, 0,
85 0, 1, 0, 0, 0,
86 0, 0, 1, 0, 0,
87 0, 0, 0, 1, 0
88 // clang-format on
90 atts.mValues.AppendElements(Span(identityMatrix));
91 } else {
92 atts.mType = type;
93 if (values.Length()) {
94 atts.mValues.AppendElements(&values[0], values.Length());
98 return FilterPrimitiveDescription(AsVariant(std::move(atts)));
101 bool SVGFEColorMatrixElement::AttributeAffectsRendering(
102 int32_t aNameSpaceID, nsAtom* aAttribute) const {
103 return SVGFEColorMatrixElementBase::AttributeAffectsRendering(aNameSpaceID,
104 aAttribute) ||
105 (aNameSpaceID == kNameSpaceID_None &&
106 (aAttribute == nsGkAtoms::in || aAttribute == nsGkAtoms::type ||
107 aAttribute == nsGkAtoms::values));
110 nsresult SVGFEColorMatrixElement::BindToTree(BindContext& aCtx,
111 nsINode& aParent) {
112 if (aCtx.InComposedDoc()) {
113 aCtx.OwnerDoc().SetUseCounter(eUseCounter_custom_feColorMatrix);
116 return SVGFEColorMatrixElementBase::BindToTree(aCtx, aParent);
119 //----------------------------------------------------------------------
120 // SVGElement methods
122 SVGElement::EnumAttributesInfo SVGFEColorMatrixElement::GetEnumInfo() {
123 return EnumAttributesInfo(mEnumAttributes, sEnumInfo, std::size(sEnumInfo));
126 SVGElement::StringAttributesInfo SVGFEColorMatrixElement::GetStringInfo() {
127 return StringAttributesInfo(mStringAttributes, sStringInfo,
128 std::size(sStringInfo));
131 SVGElement::NumberListAttributesInfo
132 SVGFEColorMatrixElement::GetNumberListInfo() {
133 return NumberListAttributesInfo(mNumberListAttributes, sNumberListInfo,
134 std::size(sNumberListInfo));
137 } // namespace mozilla::dom