Bug 1663089 [wpt PR 25399] - idle-detection: Implement requestPermission() method...
[gecko.git] / dom / svg / SVGForeignObjectElement.cpp
blob981e54165add4ff1bfba1ebf0212841950b3738e
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/SVGForeignObjectElement.h"
9 #include "mozilla/AlreadyAddRefed.h"
10 #include "mozilla/ArrayUtils.h"
11 #include "mozilla/dom/SVGDocument.h"
12 #include "mozilla/dom/SVGForeignObjectElementBinding.h"
13 #include "mozilla/dom/SVGLengthBinding.h"
14 #include "SVGGeometryProperty.h"
16 NS_IMPL_NS_NEW_SVG_ELEMENT(ForeignObject)
18 namespace mozilla {
19 namespace dom {
21 JSObject* SVGForeignObjectElement::WrapNode(JSContext* aCx,
22 JS::Handle<JSObject*> aGivenProto) {
23 return SVGForeignObjectElement_Binding::Wrap(aCx, this, aGivenProto);
26 SVGElement::LengthInfo SVGForeignObjectElement::sLengthInfo[4] = {
27 {nsGkAtoms::x, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
28 SVGContentUtils::X},
29 {nsGkAtoms::y, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
30 SVGContentUtils::Y},
31 {nsGkAtoms::width, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
32 SVGContentUtils::X},
33 {nsGkAtoms::height, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
34 SVGContentUtils::Y},
37 //----------------------------------------------------------------------
38 // Implementation
40 SVGForeignObjectElement::SVGForeignObjectElement(
41 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
42 : SVGGraphicsElement(std::move(aNodeInfo)) {}
44 namespace SVGT = SVGGeometryProperty::Tags;
46 //----------------------------------------------------------------------
47 // nsINode methods
49 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGForeignObjectElement)
51 //----------------------------------------------------------------------
53 already_AddRefed<DOMSVGAnimatedLength> SVGForeignObjectElement::X() {
54 return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this);
57 already_AddRefed<DOMSVGAnimatedLength> SVGForeignObjectElement::Y() {
58 return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this);
61 already_AddRefed<DOMSVGAnimatedLength> SVGForeignObjectElement::Width() {
62 return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this);
65 already_AddRefed<DOMSVGAnimatedLength> SVGForeignObjectElement::Height() {
66 return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this);
69 //----------------------------------------------------------------------
70 // SVGElement methods
72 /* virtual */
73 gfxMatrix SVGForeignObjectElement::PrependLocalTransformsTo(
74 const gfxMatrix& aMatrix, SVGTransformTypes aWhich) const {
75 // 'transform' attribute:
76 gfxMatrix fromUserSpace =
77 SVGGraphicsElement::PrependLocalTransformsTo(aMatrix, aWhich);
78 if (aWhich == eUserSpaceToParent) {
79 return fromUserSpace;
81 // our 'x' and 'y' attributes:
82 float x, y;
84 if (!SVGGeometryProperty::ResolveAll<SVGT::X, SVGT::Y>(this, &x, &y)) {
85 // This function might be called for element in display:none subtree
86 // (e.g. getScreenCTM), we fall back to use SVG attributes.
87 const_cast<SVGForeignObjectElement*>(this)->GetAnimatedLengthValues(
88 &x, &y, nullptr);
91 gfxMatrix toUserSpace = gfxMatrix::Translation(x, y);
92 if (aWhich == eChildToUserSpace) {
93 return toUserSpace * aMatrix;
95 MOZ_ASSERT(aWhich == eAllTransforms, "Unknown TransformTypes");
96 return toUserSpace * fromUserSpace;
99 /* virtual */
100 bool SVGForeignObjectElement::HasValidDimensions() const {
101 float width, height;
103 DebugOnly<bool> ok =
104 SVGGeometryProperty::ResolveAll<SVGT::Width, SVGT::Height>(
105 const_cast<SVGForeignObjectElement*>(this), &width, &height);
106 MOZ_ASSERT(ok, "SVGGeometryProperty::ResolveAll failed");
107 return width > 0 && height > 0;
110 //----------------------------------------------------------------------
111 // nsIContent methods
113 NS_IMETHODIMP_(bool)
114 SVGForeignObjectElement::IsAttributeMapped(const nsAtom* name) const {
115 static const MappedAttributeEntry* const map[] = {sFEFloodMap,
116 sFiltersMap,
117 sFontSpecificationMap,
118 sGradientStopMap,
119 sLightingEffectsMap,
120 sMarkersMap,
121 sTextContentElementsMap,
122 sViewportsMap};
124 return IsInLengthInfo(name, sLengthInfo) ||
125 FindAttributeDependence(name, map) ||
126 SVGGraphicsElement::IsAttributeMapped(name);
129 //----------------------------------------------------------------------
130 // SVGElement methods
132 SVGElement::LengthAttributesInfo SVGForeignObjectElement::GetLengthInfo() {
133 return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
134 ArrayLength(sLengthInfo));
137 nsCSSPropertyID SVGForeignObjectElement::GetCSSPropertyIdForAttrEnum(
138 uint8_t aAttrEnum) {
139 switch (aAttrEnum) {
140 case ATTR_X:
141 return eCSSProperty_x;
142 case ATTR_Y:
143 return eCSSProperty_y;
144 case ATTR_WIDTH:
145 return eCSSProperty_width;
146 case ATTR_HEIGHT:
147 return eCSSProperty_height;
148 default:
149 MOZ_ASSERT_UNREACHABLE("Unknown attr enum");
150 return eCSSProperty_UNKNOWN;
154 } // namespace dom
155 } // namespace mozilla