Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / dom / svg / SVGForeignObjectElement.cpp
blobe6fb81f2c3e3c564fdeabfe8aa6d354f685a24e5
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::dom {
20 JSObject* SVGForeignObjectElement::WrapNode(JSContext* aCx,
21 JS::Handle<JSObject*> aGivenProto) {
22 return SVGForeignObjectElement_Binding::Wrap(aCx, this, aGivenProto);
25 SVGElement::LengthInfo SVGForeignObjectElement::sLengthInfo[4] = {
26 {nsGkAtoms::x, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
27 SVGContentUtils::X},
28 {nsGkAtoms::y, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
29 SVGContentUtils::Y},
30 {nsGkAtoms::width, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
31 SVGContentUtils::X},
32 {nsGkAtoms::height, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
33 SVGContentUtils::Y},
36 //----------------------------------------------------------------------
37 // Implementation
39 SVGForeignObjectElement::SVGForeignObjectElement(
40 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
41 : SVGGraphicsElement(std::move(aNodeInfo)) {}
43 namespace SVGT = SVGGeometryProperty::Tags;
45 //----------------------------------------------------------------------
46 // nsINode methods
48 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGForeignObjectElement)
50 //----------------------------------------------------------------------
52 already_AddRefed<DOMSVGAnimatedLength> SVGForeignObjectElement::X() {
53 return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this);
56 already_AddRefed<DOMSVGAnimatedLength> SVGForeignObjectElement::Y() {
57 return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this);
60 already_AddRefed<DOMSVGAnimatedLength> SVGForeignObjectElement::Width() {
61 return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this);
64 already_AddRefed<DOMSVGAnimatedLength> SVGForeignObjectElement::Height() {
65 return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this);
68 //----------------------------------------------------------------------
69 // SVGElement methods
71 /* virtual */
72 gfxMatrix SVGForeignObjectElement::PrependLocalTransformsTo(
73 const gfxMatrix& aMatrix, SVGTransformTypes aWhich) const {
74 // 'transform' attribute:
75 gfxMatrix fromUserSpace =
76 SVGGraphicsElement::PrependLocalTransformsTo(aMatrix, aWhich);
77 if (aWhich == eUserSpaceToParent) {
78 return fromUserSpace;
80 // our 'x' and 'y' attributes:
81 float x, y;
83 if (!SVGGeometryProperty::ResolveAll<SVGT::X, SVGT::Y>(this, &x, &y)) {
84 // This function might be called for element in display:none subtree
85 // (e.g. getScreenCTM), we fall back to use SVG attributes.
86 const_cast<SVGForeignObjectElement*>(this)->GetAnimatedLengthValues(
87 &x, &y, nullptr);
90 gfxMatrix toUserSpace = gfxMatrix::Translation(x, y);
91 if (aWhich == eChildToUserSpace) {
92 return toUserSpace * aMatrix;
94 MOZ_ASSERT(aWhich == eAllTransforms, "Unknown TransformTypes");
95 return toUserSpace * fromUserSpace;
98 /* virtual */
99 bool SVGForeignObjectElement::HasValidDimensions() const {
100 float width, height;
102 DebugOnly<bool> ok =
103 SVGGeometryProperty::ResolveAll<SVGT::Width, SVGT::Height>(this, &width,
104 &height);
105 MOZ_ASSERT(ok, "SVGGeometryProperty::ResolveAll failed");
106 return width > 0 && height > 0;
109 //----------------------------------------------------------------------
110 // nsIContent methods
112 NS_IMETHODIMP_(bool)
113 SVGForeignObjectElement::IsAttributeMapped(const nsAtom* name) const {
114 return IsInLengthInfo(name, sLengthInfo) ||
115 SVGGraphicsElement::IsAttributeMapped(name);
118 //----------------------------------------------------------------------
119 // SVGElement methods
121 SVGElement::LengthAttributesInfo SVGForeignObjectElement::GetLengthInfo() {
122 return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
123 ArrayLength(sLengthInfo));
126 nsCSSPropertyID SVGForeignObjectElement::GetCSSPropertyIdForAttrEnum(
127 uint8_t aAttrEnum) {
128 switch (aAttrEnum) {
129 case ATTR_X:
130 return eCSSProperty_x;
131 case ATTR_Y:
132 return eCSSProperty_y;
133 case ATTR_WIDTH:
134 return eCSSProperty_width;
135 case ATTR_HEIGHT:
136 return eCSSProperty_height;
137 default:
138 MOZ_ASSERT_UNREACHABLE("Unknown attr enum");
139 return eCSSProperty_UNKNOWN;
143 } // namespace mozilla::dom