Bug 1265584 [wpt PR 11167] - [Gecko Bug 1265584] Move wptrunner marionette usage...
[gecko.git] / dom / svg / SVGTransformList.cpp
blobc6c4eefafee92770529117af12756345560e4ded
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"
9 #include "nsString.h"
10 #include "nsError.h"
12 namespace mozilla {
14 gfxMatrix
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:
20 gfxMatrix result;
22 if (mItems.IsEmpty())
23 return result;
25 result = mItems[0].GetMatrix();
27 if (mItems.Length() == 1)
28 return result;
30 for (uint32_t i = 1; i < mItems.Length(); ++i) {
31 result.PreMultiply(mItems[i].GetMatrix());
34 return result;
37 nsresult
38 SVGTransformList::CopyFrom(const SVGTransformList& rhs)
40 return CopyFrom(rhs.mItems);
43 nsresult
44 SVGTransformList::CopyFrom(const nsTArray<nsSVGTransform>& aTransformArray)
46 if (!mItems.Assign(aTransformArray, fallible)) {
47 return NS_ERROR_OUT_OF_MEMORY;
49 return NS_OK;
52 void
53 SVGTransformList::GetValueAsString(nsAString& aValue) const
55 aValue.Truncate();
56 uint32_t last = mItems.Length() - 1;
57 for (uint32_t i = 0; i < mItems.Length(); ++i) {
58 nsAutoString length;
59 mItems[i].GetValueAsString(length);
60 // We ignore OOM, since it's not useful for us to return an error.
61 aValue.Append(length);
62 if (i != last) {
63 aValue.Append(' ');
68 nsresult
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