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
,
28 {nsGkAtoms::y
, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER
,
30 {nsGkAtoms::width
, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER
,
32 {nsGkAtoms::height
, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER
,
36 //----------------------------------------------------------------------
39 SVGForeignObjectElement::SVGForeignObjectElement(
40 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
41 : SVGGraphicsElement(std::move(aNodeInfo
)) {}
43 namespace SVGT
= SVGGeometryProperty::Tags
;
45 //----------------------------------------------------------------------
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 //----------------------------------------------------------------------
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
) {
80 // our 'x' and 'y' attributes:
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(
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
;
99 bool SVGForeignObjectElement::HasValidDimensions() const {
103 SVGGeometryProperty::ResolveAll
<SVGT::Width
, SVGT::Height
>(this, &width
,
105 MOZ_ASSERT(ok
, "SVGGeometryProperty::ResolveAll failed");
106 return width
> 0 && height
> 0;
109 //----------------------------------------------------------------------
110 // nsIContent methods
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(
130 return eCSSProperty_x
;
132 return eCSSProperty_y
;
134 return eCSSProperty_width
;
136 return eCSSProperty_height
;
138 MOZ_ASSERT_UNREACHABLE("Unknown attr enum");
139 return eCSSProperty_UNKNOWN
;
143 } // namespace mozilla::dom