Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / svg / SVGLengthList.cpp
blob9f3cfa39a55133ceb8b474c0be2ad5c0ba2b5073
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 "SVGLengthList.h"
8 #include "nsCharSeparatedTokenizer.h"
9 #include "nsContentUtils.h"
10 #include "nsError.h"
11 #include "nsString.h"
12 #include "SVGElement.h"
13 #include "SVGAnimatedLengthList.h"
14 #include "SVGContentUtils.h"
15 #include "SVGLength.h"
17 namespace mozilla {
19 nsresult SVGLengthList::CopyFrom(const SVGLengthList& rhs) {
20 if (!mLengths.Assign(rhs.mLengths, fallible)) {
21 return NS_ERROR_OUT_OF_MEMORY;
23 return NS_OK;
26 void SVGLengthList::GetValueAsString(nsAString& aValue) const {
27 aValue.Truncate();
28 uint32_t last = mLengths.Length() - 1;
29 for (uint32_t i = 0; i < mLengths.Length(); ++i) {
30 nsAutoString length;
31 mLengths[i].GetValueAsString(length);
32 // We ignore OOM, since it's not useful for us to return an error.
33 aValue.Append(length);
34 if (i != last) {
35 aValue.Append(' ');
40 nsresult SVGLengthList::SetValueFromString(const nsAString& aValue) {
41 SVGLengthList temp;
43 nsCharSeparatedTokenizerTemplate<nsContentUtils::IsHTMLWhitespace,
44 nsTokenizerFlags::SeparatorOptional>
45 tokenizer(aValue, ',');
47 while (tokenizer.hasMoreTokens()) {
48 SVGLength length;
49 if (!length.SetValueFromString(tokenizer.nextToken())) {
50 return NS_ERROR_DOM_SYNTAX_ERR;
52 if (!temp.AppendItem(length)) {
53 return NS_ERROR_OUT_OF_MEMORY;
56 if (tokenizer.separatorAfterCurrentToken()) {
57 return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
59 mLengths = std::move(temp.mLengths);
60 return NS_OK;
63 bool SVGLengthList::operator==(const SVGLengthList& rhs) const {
64 if (Length() != rhs.Length()) {
65 return false;
67 for (uint32_t i = 0; i < Length(); ++i) {
68 if (!(mLengths[i] == rhs.mLengths[i])) {
69 return false;
72 return true;
75 } // namespace mozilla