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
)
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
,
29 {nsGkAtoms::y
, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER
,
31 {nsGkAtoms::width
, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER
,
33 {nsGkAtoms::height
, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER
,
37 //----------------------------------------------------------------------
40 SVGForeignObjectElement::SVGForeignObjectElement(
41 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
42 : SVGGraphicsElement(std::move(aNodeInfo
)) {}
44 namespace SVGT
= SVGGeometryProperty::Tags
;
46 //----------------------------------------------------------------------
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 //----------------------------------------------------------------------
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
) {
81 // our 'x' and 'y' attributes:
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(
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
;
100 bool SVGForeignObjectElement::HasValidDimensions() const {
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
114 SVGForeignObjectElement::IsAttributeMapped(const nsAtom
* name
) const {
115 static const MappedAttributeEntry
* const map
[] = {sFEFloodMap
,
117 sFontSpecificationMap
,
121 sTextContentElementsMap
,
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(
141 return eCSSProperty_x
;
143 return eCSSProperty_y
;
145 return eCSSProperty_width
;
147 return eCSSProperty_height
;
149 MOZ_ASSERT_UNREACHABLE("Unknown attr enum");
150 return eCSSProperty_UNKNOWN
;
155 } // namespace mozilla