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"
14 gfxMatrix
SVGTransformList::GetConsolidationMatrix() const {
15 // To benefit from Return Value Optimization and avoid copy constructor calls
16 // due to our use of return-by-value, we must return the exact same object
17 // from ALL return points. This function must only return THIS variable:
20 if (mItems
.IsEmpty()) return result
;
22 result
= mItems
[0].GetMatrix();
24 if (mItems
.Length() == 1) return result
;
26 for (uint32_t i
= 1; i
< mItems
.Length(); ++i
) {
27 result
.PreMultiply(mItems
[i
].GetMatrix());
33 nsresult
SVGTransformList::CopyFrom(const SVGTransformList
& rhs
) {
34 return CopyFrom(rhs
.mItems
);
37 nsresult
SVGTransformList::CopyFrom(
38 const nsTArray
<SVGTransform
>& aTransformArray
) {
39 if (!mItems
.Assign(aTransformArray
, fallible
)) {
40 return NS_ERROR_OUT_OF_MEMORY
;
45 void SVGTransformList::GetValueAsString(nsAString
& aValue
) const {
47 uint32_t last
= mItems
.Length() - 1;
48 for (uint32_t i
= 0; i
< mItems
.Length(); ++i
) {
50 mItems
[i
].GetValueAsString(length
);
51 // We ignore OOM, since it's not useful for us to return an error.
52 aValue
.Append(length
);
59 nsresult
SVGTransformList::SetValueFromString(const nsAString
& aValue
) {
60 SVGTransformListParser
parser(aValue
);
61 if (!parser
.Parse()) {
62 // there was a parse error.
63 return NS_ERROR_DOM_SYNTAX_ERR
;
66 return CopyFrom(parser
.GetTransformList());
69 } // namespace mozilla