Bumping manifests a=b2g-bump
[gecko.git] / dom / svg / SVGTextContentElement.cpp
blob98eccac79790d766d963c9c721fdbc2d295f4744
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"
11 namespace mozilla {
12 namespace dom {
14 nsSVGEnumMapping SVGTextContentElement::sLengthAdjustMap[] = {
15 { &nsGkAtoms::spacing, SVG_LENGTHADJUST_SPACING },
16 { &nsGkAtoms::spacingAndGlyphs, SVG_LENGTHADJUST_SPACINGANDGLYPHS },
17 { nullptr, 0 }
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 }
30 SVGTextFrame*
31 SVGTextContentElement::GetSVGTextFrame()
33 nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
34 while (frame) {
35 SVGTextFrame* textFrame = do_QueryFrame(frame);
36 if (textFrame) {
37 return textFrame;
39 frame = frame->GetParent();
41 return nullptr;
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 //----------------------------------------------------------------------
58 int32_t
59 SVGTextContentElement::GetNumberOfChars()
61 SVGTextFrame* textFrame = GetSVGTextFrame();
62 return textFrame ? textFrame->GetNumberOfChars(this) : 0;
65 float
66 SVGTextContentElement::GetComputedTextLength()
68 SVGTextFrame* textFrame = GetSVGTextFrame();
69 return textFrame ? textFrame->GetComputedTextLength(this) : 0.0f;
72 void
73 SVGTextContentElement::SelectSubString(uint32_t charnum, uint32_t nchars, ErrorResult& rv)
75 SVGTextFrame* textFrame = GetSVGTextFrame();
76 if (!textFrame)
77 return;
79 rv = textFrame->SelectSubString(this, charnum, nchars);
82 float
83 SVGTextContentElement::GetSubStringLength(uint32_t charnum, uint32_t nchars, ErrorResult& rv)
85 SVGTextFrame* textFrame = GetSVGTextFrame();
86 if (!textFrame)
87 return 0.0f;
89 float length = 0.0f;
90 rv = textFrame->GetSubStringLength(this, charnum, nchars, &length);
91 return length;
94 already_AddRefed<nsISVGPoint>
95 SVGTextContentElement::GetStartPositionOfChar(uint32_t charnum, ErrorResult& rv)
97 SVGTextFrame* textFrame = GetSVGTextFrame();
98 if (!textFrame) {
99 rv.Throw(NS_ERROR_FAILURE);
100 return nullptr;
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();
112 if (!textFrame) {
113 rv.Throw(NS_ERROR_FAILURE);
114 return nullptr;
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();
127 if (!textFrame) {
128 rv.Throw(NS_ERROR_FAILURE);
129 return nullptr;
132 nsRefPtr<SVGIRect> rect;
133 rv = textFrame->GetExtentOfChar(this, charnum, getter_AddRefs(rect));
134 return rect.forget();
137 float
138 SVGTextContentElement::GetRotationOfChar(uint32_t charnum, ErrorResult& rv)
140 SVGTextFrame* textFrame = GetSVGTextFrame();
142 if (!textFrame) {
143 rv.Throw(NS_ERROR_FAILURE);
144 return 0.0f;
147 float rotation;
148 rv = textFrame->GetRotationOfChar(this, charnum, &rotation);
149 return rotation;
152 int32_t
153 SVGTextContentElement::GetCharNumAtPosition(nsISVGPoint& aPoint)
155 SVGTextFrame* textFrame = GetSVGTextFrame();
156 return textFrame ? textFrame->GetCharNumAtPosition(this, &aPoint) : -1;
159 } // namespace dom
160 } // namespace mozilla