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 "SVGTransformList.h"
8 #include "SVGTransformListParser.h"
15 SVGTransformList::GetConsolidationMatrix() const
17 // To benefit from Return Value Optimization and avoid copy constructor calls
18 // due to our use of return-by-value, we must return the exact same object
19 // from ALL return points. This function must only return THIS variable:
25 result
= mItems
[0].GetMatrix();
27 if (mItems
.Length() == 1)
30 for (uint32_t i
= 1; i
< mItems
.Length(); ++i
) {
31 result
.PreMultiply(mItems
[i
].GetMatrix());
38 SVGTransformList::CopyFrom(const SVGTransformList
& rhs
)
40 return CopyFrom(rhs
.mItems
);
44 SVGTransformList::CopyFrom(const nsTArray
<nsSVGTransform
>& aTransformArray
)
46 if (!mItems
.Assign(aTransformArray
, fallible
)) {
47 return NS_ERROR_OUT_OF_MEMORY
;
53 SVGTransformList::GetValueAsString(nsAString
& aValue
) const
56 uint32_t last
= mItems
.Length() - 1;
57 for (uint32_t i
= 0; i
< mItems
.Length(); ++i
) {
59 mItems
[i
].GetValueAsString(length
);
60 // We ignore OOM, since it's not useful for us to return an error.
61 aValue
.Append(length
);
69 SVGTransformList::SetValueFromString(const nsAString
& aValue
)
71 SVGTransformListParser
parser(aValue
);
72 if (!parser
.Parse()) {
73 // there was a parse error.
74 return NS_ERROR_DOM_SYNTAX_ERR
;
77 return CopyFrom(parser
.GetTransformList());
80 } // namespace mozilla