/src/mozilla-central/dom/svg/SVGTransformList.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "SVGTransformList.h" |
8 | | #include "SVGTransformListParser.h" |
9 | | #include "nsString.h" |
10 | | #include "nsError.h" |
11 | | |
12 | | namespace mozilla { |
13 | | |
14 | | gfxMatrix |
15 | | SVGTransformList::GetConsolidationMatrix() const |
16 | 0 | { |
17 | 0 | // To benefit from Return Value Optimization and avoid copy constructor calls |
18 | 0 | // due to our use of return-by-value, we must return the exact same object |
19 | 0 | // from ALL return points. This function must only return THIS variable: |
20 | 0 | gfxMatrix result; |
21 | 0 |
|
22 | 0 | if (mItems.IsEmpty()) |
23 | 0 | return result; |
24 | 0 | |
25 | 0 | result = mItems[0].GetMatrix(); |
26 | 0 |
|
27 | 0 | if (mItems.Length() == 1) |
28 | 0 | return result; |
29 | 0 | |
30 | 0 | for (uint32_t i = 1; i < mItems.Length(); ++i) { |
31 | 0 | result.PreMultiply(mItems[i].GetMatrix()); |
32 | 0 | } |
33 | 0 |
|
34 | 0 | return result; |
35 | 0 | } |
36 | | |
37 | | nsresult |
38 | | SVGTransformList::CopyFrom(const SVGTransformList& rhs) |
39 | 0 | { |
40 | 0 | return CopyFrom(rhs.mItems); |
41 | 0 | } |
42 | | |
43 | | nsresult |
44 | | SVGTransformList::CopyFrom(const nsTArray<nsSVGTransform>& aTransformArray) |
45 | 0 | { |
46 | 0 | if (!mItems.Assign(aTransformArray, fallible)) { |
47 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
48 | 0 | } |
49 | 0 | return NS_OK; |
50 | 0 | } |
51 | | |
52 | | void |
53 | | SVGTransformList::GetValueAsString(nsAString& aValue) const |
54 | 0 | { |
55 | 0 | aValue.Truncate(); |
56 | 0 | uint32_t last = mItems.Length() - 1; |
57 | 0 | for (uint32_t i = 0; i < mItems.Length(); ++i) { |
58 | 0 | nsAutoString length; |
59 | 0 | mItems[i].GetValueAsString(length); |
60 | 0 | // We ignore OOM, since it's not useful for us to return an error. |
61 | 0 | aValue.Append(length); |
62 | 0 | if (i != last) { |
63 | 0 | aValue.Append(' '); |
64 | 0 | } |
65 | 0 | } |
66 | 0 | } |
67 | | |
68 | | nsresult |
69 | | SVGTransformList::SetValueFromString(const nsAString& aValue) |
70 | 0 | { |
71 | 0 | SVGTransformListParser parser(aValue); |
72 | 0 | if (!parser.Parse()) { |
73 | 0 | // there was a parse error. |
74 | 0 | return NS_ERROR_DOM_SYNTAX_ERR; |
75 | 0 | } |
76 | 0 | |
77 | 0 | return CopyFrom(parser.GetTransformList()); |
78 | 0 | } |
79 | | |
80 | | } // namespace mozilla |