2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-07-16 21:42:12 +00:00
|
|
|
|
|
|
|
#include "SVGLengthList.h"
|
2012-09-22 19:26:05 +00:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2010-07-16 21:42:12 +00:00
|
|
|
#include "nsString.h"
|
2012-09-22 19:26:05 +00:00
|
|
|
#include "nsSVGElement.h"
|
|
|
|
#include "SVGAnimatedLengthList.h"
|
|
|
|
#include "SVGContentUtils.h"
|
|
|
|
#include "SVGLength.h"
|
2010-07-16 21:42:12 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SVGLengthList::CopyFrom(const SVGLengthList& rhs)
|
|
|
|
{
|
2015-05-18 20:50:34 +00:00
|
|
|
if (!mLengths.SetCapacity(rhs.Length(), fallible)) {
|
2010-07-16 21:42:12 +00:00
|
|
|
// Yes, we do want fallible alloc here
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mLengths = rhs.mLengths;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGLengthList::GetValueAsString(nsAString& aValue) const
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t last = mLengths.Length() - 1;
|
|
|
|
for (uint32_t i = 0; i < mLengths.Length(); ++i) {
|
2010-07-16 21:42:12 +00:00
|
|
|
nsAutoString length;
|
|
|
|
mLengths[i].GetValueAsString(length);
|
|
|
|
// We ignore OOM, since it's not useful for us to return an error.
|
|
|
|
aValue.Append(length);
|
|
|
|
if (i != last) {
|
|
|
|
aValue.Append(' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SVGLengthList::SetValueFromString(const nsAString& aValue)
|
|
|
|
{
|
|
|
|
SVGLengthList temp;
|
|
|
|
|
2011-11-09 12:58:34 +00:00
|
|
|
nsCharSeparatedTokenizerTemplate<IsSVGWhitespace>
|
|
|
|
tokenizer(aValue, ',', nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL);
|
2010-07-16 21:42:12 +00:00
|
|
|
|
2011-11-09 12:58:34 +00:00
|
|
|
while (tokenizer.hasMoreTokens()) {
|
2010-07-16 21:42:12 +00:00
|
|
|
SVGLength length;
|
2011-11-09 12:58:34 +00:00
|
|
|
if (!length.SetValueFromString(tokenizer.nextToken())) {
|
2010-07-16 21:42:12 +00:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
if (!temp.AppendItem(length)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
2013-09-17 12:52:39 +00:00
|
|
|
if (tokenizer.separatorAfterCurrentToken()) {
|
2011-11-09 12:58:34 +00:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
|
|
|
|
}
|
2010-07-16 21:42:12 +00:00
|
|
|
return CopyFrom(temp);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-07-16 21:42:12 +00:00
|
|
|
SVGLengthList::operator==(const SVGLengthList& rhs) const
|
|
|
|
{
|
|
|
|
if (Length() != rhs.Length()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-07-16 21:42:12 +00:00
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < Length(); ++i) {
|
2010-07-16 21:42:12 +00:00
|
|
|
if (!(mLengths[i] == rhs.mLengths[i])) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-07-16 21:42:12 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-07-16 21:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|