2010-07-16 14:42:12 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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 14:42:12 -07:00
|
|
|
|
|
|
|
#include "SVGLengthList.h"
|
2012-09-22 12:26:05 -07:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2010-07-16 14:42:12 -07:00
|
|
|
#include "nsString.h"
|
2012-09-22 12:26:05 -07:00
|
|
|
#include "nsSVGElement.h"
|
|
|
|
#include "SVGAnimatedLengthList.h"
|
|
|
|
#include "SVGContentUtils.h"
|
|
|
|
#include "SVGLength.h"
|
2010-07-16 14:42:12 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SVGLengthList::CopyFrom(const SVGLengthList& rhs)
|
|
|
|
{
|
|
|
|
if (!mLengths.SetCapacity(rhs.Length())) {
|
|
|
|
// 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 08:56:38 -07:00
|
|
|
uint32_t last = mLengths.Length() - 1;
|
|
|
|
for (uint32_t i = 0; i < mLengths.Length(); ++i) {
|
2010-07-16 14:42:12 -07: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 04:58:34 -08:00
|
|
|
nsCharSeparatedTokenizerTemplate<IsSVGWhitespace>
|
|
|
|
tokenizer(aValue, ',', nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL);
|
2010-07-16 14:42:12 -07:00
|
|
|
|
2011-11-09 04:58:34 -08:00
|
|
|
while (tokenizer.hasMoreTokens()) {
|
2010-07-16 14:42:12 -07:00
|
|
|
SVGLength length;
|
2011-11-09 04:58:34 -08:00
|
|
|
if (!length.SetValueFromString(tokenizer.nextToken())) {
|
2010-07-16 14:42:12 -07:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
if (!temp.AppendItem(length)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
2013-09-17 05:52:39 -07:00
|
|
|
if (tokenizer.separatorAfterCurrentToken()) {
|
2011-11-09 04:58:34 -08:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
|
|
|
|
}
|
2010-07-16 14:42:12 -07:00
|
|
|
return CopyFrom(temp);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-07-16 14:42:12 -07:00
|
|
|
SVGLengthList::operator==(const SVGLengthList& rhs) const
|
|
|
|
{
|
|
|
|
if (Length() != rhs.Length()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-07-16 14:42:12 -07:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < Length(); ++i) {
|
2010-07-16 14:42:12 -07:00
|
|
|
if (!(mLengths[i] == rhs.mLengths[i])) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-07-16 14:42:12 -07:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-07-16 14:42:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|