Bug 1890793: Assert CallArgs::newTarget is not gray. r=spidermonkey-reviewers,sfink...
[gecko.git] / dom / svg / SVGTransformList.cpp
blob244ca61c854ac60843732245160d4c6e8ed36b48
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 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:
18 gfxMatrix result;
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());
30 return result;
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;
42 return NS_OK;
45 void SVGTransformList::GetValueAsString(nsAString& aValue) const {
46 aValue.Truncate();
47 uint32_t last = mItems.Length() - 1;
48 for (uint32_t i = 0; i < mItems.Length(); ++i) {
49 nsAutoString length;
50 mItems[i].GetValueAsString(length);
51 // We ignore OOM, since it's not useful for us to return an error.
52 aValue.Append(length);
53 if (i != last) {
54 aValue.Append(' ');
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