1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "mozilla/dom/SVGTextContentElement.h"
7 #include "nsISVGPoint.h"
8 #include "SVGTextFrame.h"
9 #include "mozilla/dom/SVGIRect.h"
14 nsSVGEnumMapping
SVGTextContentElement::sLengthAdjustMap
[] = {
15 { &nsGkAtoms::spacing
, SVG_LENGTHADJUST_SPACING
},
16 { &nsGkAtoms::spacingAndGlyphs
, SVG_LENGTHADJUST_SPACINGANDGLYPHS
},
20 nsSVGElement::EnumInfo
SVGTextContentElement::sEnumInfo
[1] =
22 { &nsGkAtoms::lengthAdjust
, sLengthAdjustMap
, SVG_LENGTHADJUST_SPACING
}
25 nsSVGElement::LengthInfo
SVGTextContentElement::sLengthInfo
[1] =
27 { &nsGkAtoms::textLength
, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER
, SVGContentUtils::XY
}
31 SVGTextContentElement::GetSVGTextFrame()
33 nsIFrame
* frame
= GetPrimaryFrame(Flush_Layout
);
35 SVGTextFrame
* textFrame
= do_QueryFrame(frame
);
39 frame
= frame
->GetParent();
44 already_AddRefed
<SVGAnimatedLength
>
45 SVGTextContentElement::TextLength()
47 return LengthAttributes()[TEXTLENGTH
].ToDOMAnimatedLength(this);
50 already_AddRefed
<SVGAnimatedEnumeration
>
51 SVGTextContentElement::LengthAdjust()
53 return EnumAttributes()[LENGTHADJUST
].ToDOMAnimatedEnum(this);
56 //----------------------------------------------------------------------
59 SVGTextContentElement::GetNumberOfChars()
61 SVGTextFrame
* textFrame
= GetSVGTextFrame();
62 return textFrame
? textFrame
->GetNumberOfChars(this) : 0;
66 SVGTextContentElement::GetComputedTextLength()
68 SVGTextFrame
* textFrame
= GetSVGTextFrame();
69 return textFrame
? textFrame
->GetComputedTextLength(this) : 0.0f
;
73 SVGTextContentElement::SelectSubString(uint32_t charnum
, uint32_t nchars
, ErrorResult
& rv
)
75 SVGTextFrame
* textFrame
= GetSVGTextFrame();
79 rv
= textFrame
->SelectSubString(this, charnum
, nchars
);
83 SVGTextContentElement::GetSubStringLength(uint32_t charnum
, uint32_t nchars
, ErrorResult
& rv
)
85 SVGTextFrame
* textFrame
= GetSVGTextFrame();
90 rv
= textFrame
->GetSubStringLength(this, charnum
, nchars
, &length
);
94 already_AddRefed
<nsISVGPoint
>
95 SVGTextContentElement::GetStartPositionOfChar(uint32_t charnum
, ErrorResult
& rv
)
97 SVGTextFrame
* textFrame
= GetSVGTextFrame();
99 rv
.Throw(NS_ERROR_FAILURE
);
103 nsCOMPtr
<nsISVGPoint
> point
;
104 rv
= textFrame
->GetStartPositionOfChar(this, charnum
, getter_AddRefs(point
));
105 return point
.forget();
108 already_AddRefed
<nsISVGPoint
>
109 SVGTextContentElement::GetEndPositionOfChar(uint32_t charnum
, ErrorResult
& rv
)
111 SVGTextFrame
* textFrame
= GetSVGTextFrame();
113 rv
.Throw(NS_ERROR_FAILURE
);
117 nsCOMPtr
<nsISVGPoint
> point
;
118 rv
= textFrame
->GetEndPositionOfChar(this, charnum
, getter_AddRefs(point
));
119 return point
.forget();
122 already_AddRefed
<SVGIRect
>
123 SVGTextContentElement::GetExtentOfChar(uint32_t charnum
, ErrorResult
& rv
)
125 SVGTextFrame
* textFrame
= GetSVGTextFrame();
128 rv
.Throw(NS_ERROR_FAILURE
);
132 nsRefPtr
<SVGIRect
> rect
;
133 rv
= textFrame
->GetExtentOfChar(this, charnum
, getter_AddRefs(rect
));
134 return rect
.forget();
138 SVGTextContentElement::GetRotationOfChar(uint32_t charnum
, ErrorResult
& rv
)
140 SVGTextFrame
* textFrame
= GetSVGTextFrame();
143 rv
.Throw(NS_ERROR_FAILURE
);
148 rv
= textFrame
->GetRotationOfChar(this, charnum
, &rotation
);
153 SVGTextContentElement::GetCharNumAtPosition(nsISVGPoint
& aPoint
)
155 SVGTextFrame
* textFrame
= GetSVGTextFrame();
156 return textFrame
? textFrame
->GetCharNumAtPosition(this, &aPoint
) : -1;
160 } // namespace mozilla