2009-01-14 20:38:07 -08: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/. */
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
#include "nsSMILParserUtils.h"
|
|
|
|
#include "nsISMILAttr.h"
|
|
|
|
#include "nsSMILValue.h"
|
|
|
|
#include "nsSMILTimeValue.h"
|
2010-01-12 12:00:49 -08:00
|
|
|
#include "nsSMILTimeValueSpecParams.h"
|
2009-01-14 20:38:07 -08:00
|
|
|
#include "nsSMILTypes.h"
|
|
|
|
#include "nsSMILRepeatCount.h"
|
2010-01-12 12:00:49 -08:00
|
|
|
#include "nsContentUtils.h"
|
2009-01-14 20:38:07 -08:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "prdtoa.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "prlong.h"
|
2010-05-04 07:43:48 -07:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2013-03-18 20:18:45 -07:00
|
|
|
using namespace mozilla::dom;
|
2009-01-14 20:38:07 -08:00
|
|
|
//------------------------------------------------------------------------------
|
2010-01-12 12:00:49 -08:00
|
|
|
// Helper functions and Constants
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t MSEC_PER_SEC = 1000;
|
|
|
|
const uint32_t MSEC_PER_MIN = 1000 * 60;
|
|
|
|
const uint32_t MSEC_PER_HOUR = 1000 * 60 * 60;
|
|
|
|
const int32_t DECIMAL_BASE = 10;
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2010-08-27 23:41:05 -07:00
|
|
|
#define ACCESSKEY_PREFIX_LC NS_LITERAL_STRING("accesskey(") // SMIL2+
|
|
|
|
#define ACCESSKEY_PREFIX_CC NS_LITERAL_STRING("accessKey(") // SVG/SMIL ANIM
|
2010-01-12 12:00:49 -08:00
|
|
|
#define REPEAT_PREFIX NS_LITERAL_STRING("repeat(")
|
|
|
|
#define WALLCLOCK_PREFIX NS_LITERAL_STRING("wallclock(")
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
// NS_IS_SPACE relies on isspace which may return true for \xB and \xC but
|
|
|
|
// SMILANIM does not consider these characters to be whitespace.
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool
|
2010-01-12 12:00:49 -08:00
|
|
|
IsSpace(const PRUnichar c)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
return (c == 0x9 || c == 0xA || c == 0xD || c == 0x20);
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
template<class T>
|
2009-01-14 20:38:07 -08:00
|
|
|
inline void
|
2010-01-12 12:00:49 -08:00
|
|
|
SkipBeginWsp(T& aStart, T aEnd)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
while (aStart != aEnd && IsSpace(*aStart)) {
|
|
|
|
++aStart;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
inline void
|
|
|
|
SkipBeginEndWsp(const PRUnichar*& aStart, const PRUnichar*& aEnd)
|
|
|
|
{
|
|
|
|
SkipBeginWsp(aStart, aEnd);
|
|
|
|
while (aEnd != aStart && IsSpace(*(aEnd - 1))) {
|
|
|
|
--aEnd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
double
|
|
|
|
GetFloat(const char*& aStart, const char* aEnd, nsresult* aErrorCode)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
char* floatEnd;
|
2010-01-12 12:00:49 -08:00
|
|
|
double value = PR_strtod(aStart, &floatEnd);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
nsresult rv;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
if (floatEnd == aStart || floatEnd > aEnd) {
|
2009-01-14 20:38:07 -08:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
} else {
|
2010-01-12 12:00:49 -08:00
|
|
|
aStart = floatEnd;
|
|
|
|
rv = NS_OK;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aErrorCode) {
|
|
|
|
*aErrorCode = rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
size_t
|
2012-08-22 08:56:38 -07:00
|
|
|
GetUnsignedInt(const nsAString& aStr, uint32_t& aResult)
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
|
|
|
NS_ConvertUTF16toUTF8 cstr(aStr);
|
|
|
|
const char* str = cstr.get();
|
|
|
|
|
|
|
|
char* rest;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t value = strtol(str, &rest, DECIMAL_BASE);
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
if (rest == str || value < 0)
|
|
|
|
return 0;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
aResult = static_cast<uint32_t>(value);
|
2010-01-12 12:00:49 -08:00
|
|
|
return rest - str;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
GetUnsignedIntAndEndParen(const nsAString& aStr, uint32_t& aResult)
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
|
|
|
size_t intLen = GetUnsignedInt(aStr, aResult);
|
|
|
|
|
|
|
|
const PRUnichar* start = aStr.BeginReading();
|
|
|
|
const PRUnichar* end = aStr.EndReading();
|
|
|
|
|
|
|
|
// Make sure the string is only digit+')'
|
|
|
|
if (intLen == 0 || start + intLen + 1 != end || *(start + intLen) != ')')
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool
|
2010-01-12 12:00:49 -08:00
|
|
|
ConsumeSubstring(const char*& aStart, const char* aEnd, const char* aSubstring)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2013-05-07 20:40:12 -07:00
|
|
|
size_t substrLen = strlen(aSubstring);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
if (static_cast<size_t>(aEnd - aStart) < substrLen)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool result = false;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
if (PL_strstr(aStart, aSubstring) == aStart) {
|
|
|
|
aStart += substrLen;
|
2011-10-17 07:59:28 -07:00
|
|
|
result = true;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-01-12 12:00:49 -08:00
|
|
|
ParseClockComponent(const char*& aStart,
|
|
|
|
const char* aEnd,
|
|
|
|
double& aResult,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool& aIsReal,
|
|
|
|
bool& aCouldBeMin,
|
|
|
|
bool& aCouldBeSec)
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
const char* begin = aStart;
|
|
|
|
double value = GetFloat(aStart, aEnd, &rv);
|
|
|
|
|
|
|
|
// Check a number was found
|
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
// Check that it's not expressed in exponential form
|
|
|
|
size_t len = aStart - begin;
|
2012-07-30 07:20:58 -07:00
|
|
|
bool isExp = (PL_strnpbrk(begin, "eE", len) != nullptr);
|
2010-01-12 12:00:49 -08:00
|
|
|
if (isExp)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
// Don't allow real numbers of the form "23."
|
|
|
|
if (*(aStart - 1) == '.')
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
// Number looks good
|
|
|
|
aResult = value;
|
|
|
|
|
|
|
|
// Set some flags so we can check this number is valid once we know
|
|
|
|
// whether it's an hour, minute string etc.
|
2012-07-30 07:20:58 -07:00
|
|
|
aIsReal = (PL_strnchr(begin, '.', len) != nullptr);
|
2010-01-12 12:00:49 -08:00
|
|
|
aCouldBeMin = (value < 60.0 && (len == 2));
|
|
|
|
aCouldBeSec = (value < 60.0 ||
|
|
|
|
(value == 60.0 && begin[0] == '5')); // Take care of rounding error
|
|
|
|
aCouldBeSec &= (len >= 2 &&
|
|
|
|
(begin[2] == '\0' || begin[2] == '.' || IsSpace(begin[2])));
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-01-12 12:00:49 -08:00
|
|
|
ParseMetricMultiplicand(const char*& aStart,
|
|
|
|
const char* aEnd,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t& multiplicand)
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool result = false;
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
size_t len = aEnd - aStart;
|
|
|
|
const char* cur = aStart;
|
|
|
|
|
|
|
|
if (len) {
|
|
|
|
switch (*cur++)
|
|
|
|
{
|
|
|
|
case 'h':
|
|
|
|
multiplicand = MSEC_PER_HOUR;
|
2011-10-17 07:59:28 -07:00
|
|
|
result = true;
|
2010-01-12 12:00:49 -08:00
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
if (len >= 2) {
|
|
|
|
if (*cur == 's') {
|
|
|
|
++cur;
|
|
|
|
multiplicand = 1;
|
2011-10-17 07:59:28 -07:00
|
|
|
result = true;
|
2010-01-12 12:00:49 -08:00
|
|
|
} else if (len >= 3 && *cur++ == 'i' && *cur++ == 'n') {
|
|
|
|
multiplicand = MSEC_PER_MIN;
|
2011-10-17 07:59:28 -07:00
|
|
|
result = true;
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
multiplicand = MSEC_PER_SEC;
|
2011-10-17 07:59:28 -07:00
|
|
|
result = true;
|
2010-01-12 12:00:49 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
aStart = cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
nsresult
|
|
|
|
ParseOptionalOffset(const nsAString& aSpec, nsSMILTimeValueSpecParams& aResult)
|
|
|
|
{
|
|
|
|
if (aSpec.IsEmpty()) {
|
|
|
|
aResult.mOffset.SetMillis(0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSpec.First() != '+' && aSpec.First() != '-')
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-11-30 15:45:28 -08:00
|
|
|
return nsSMILParserUtils::ParseClockValue(aSpec, &aResult.mOffset,
|
|
|
|
nsSMILParserUtils::kClockValueAllowSign);
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ParseAccessKey(const nsAString& aSpec, nsSMILTimeValueSpecParams& aResult)
|
|
|
|
{
|
2010-08-27 23:41:05 -07:00
|
|
|
NS_ABORT_IF_FALSE(StringBeginsWith(aSpec, ACCESSKEY_PREFIX_CC) ||
|
|
|
|
StringBeginsWith(aSpec, ACCESSKEY_PREFIX_LC),
|
2010-01-12 12:00:49 -08:00
|
|
|
"Calling ParseAccessKey on non-accesskey-type spec");
|
|
|
|
|
|
|
|
nsSMILTimeValueSpecParams result;
|
|
|
|
result.mType = nsSMILTimeValueSpecParams::ACCESSKEY;
|
|
|
|
|
2010-08-27 23:41:05 -07:00
|
|
|
NS_ABORT_IF_FALSE(
|
|
|
|
ACCESSKEY_PREFIX_LC.Length() == ACCESSKEY_PREFIX_CC.Length(),
|
|
|
|
"Case variations for accesskey prefix differ in length");
|
|
|
|
const PRUnichar* start = aSpec.BeginReading() + ACCESSKEY_PREFIX_LC.Length();
|
2010-01-12 12:00:49 -08:00
|
|
|
const PRUnichar* end = aSpec.EndReading();
|
|
|
|
|
|
|
|
// Expecting at least <accesskey> + ')'
|
|
|
|
if (end - start < 2)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t c = *start++;
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
// Process 32-bit codepoints
|
|
|
|
if (NS_IS_HIGH_SURROGATE(c)) {
|
|
|
|
if (end - start < 2) // Expecting at least low-surrogate + ')'
|
|
|
|
return NS_ERROR_FAILURE;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t lo = *start++;
|
2010-01-12 12:00:49 -08:00
|
|
|
if (!NS_IS_LOW_SURROGATE(lo))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
c = SURROGATE_TO_UCS4(c, lo);
|
|
|
|
// XML 1.1 says that 0xFFFE and 0xFFFF are not valid characters
|
|
|
|
} else if (NS_IS_LOW_SURROGATE(c) || c == 0xFFFE || c == 0xFFFF) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.mRepeatIterationOrAccessKey = c;
|
|
|
|
|
|
|
|
if (*start++ != ')')
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
SkipBeginWsp(start, end);
|
2010-01-28 01:51:03 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
nsresult rv = ParseOptionalOffset(Substring(start, end), result);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
aResult = result;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PRUnichar*
|
2011-09-28 23:19:26 -07:00
|
|
|
GetTokenEnd(const nsAString& aStr, bool aBreakOnDot)
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
2011-07-14 13:29:37 -07:00
|
|
|
const PRUnichar* tokenEnd = aStr.BeginReading();
|
2010-01-12 12:00:49 -08:00
|
|
|
const PRUnichar* const end = aStr.EndReading();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool escape = false;
|
2010-01-12 12:00:49 -08:00
|
|
|
while (tokenEnd != end) {
|
|
|
|
PRUnichar c = *tokenEnd;
|
|
|
|
if (IsSpace(c) ||
|
|
|
|
(!escape && (c == '+' || c == '-' || (aBreakOnDot && c == '.')))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
escape = (!escape && c == '\\');
|
|
|
|
++tokenEnd;
|
|
|
|
}
|
|
|
|
return tokenEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Unescape(nsAString& aStr)
|
|
|
|
{
|
|
|
|
const PRUnichar* read = aStr.BeginReading();
|
|
|
|
const PRUnichar* const end = aStr.EndReading();
|
|
|
|
PRUnichar* write = aStr.BeginWriting();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool escape = false;
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
while (read != end) {
|
|
|
|
NS_ABORT_IF_FALSE(write <= read, "Writing past where we've read");
|
|
|
|
if (!escape && *read == '\\') {
|
2011-10-17 07:59:28 -07:00
|
|
|
escape = true;
|
2010-01-12 12:00:49 -08:00
|
|
|
++read;
|
|
|
|
} else {
|
|
|
|
*write++ = *read++;
|
2011-10-17 07:59:28 -07:00
|
|
|
escape = false;
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aStr.SetLength(write - aStr.BeginReading());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ParseElementBaseTimeValueSpec(const nsAString& aSpec,
|
|
|
|
nsSMILTimeValueSpecParams& aResult)
|
|
|
|
{
|
|
|
|
nsSMILTimeValueSpecParams result;
|
|
|
|
|
|
|
|
//
|
|
|
|
// The spec will probably look something like one of these
|
|
|
|
//
|
|
|
|
// element-name.begin
|
|
|
|
// element-name.event-name
|
|
|
|
// event-name
|
|
|
|
// element-name.repeat(3)
|
|
|
|
// event\.name
|
|
|
|
//
|
2010-08-18 03:20:24 -07:00
|
|
|
// Technically `repeat(3)' is permitted but the behaviour in this case is not
|
|
|
|
// defined (for SMIL Animation) so we don't support it here.
|
|
|
|
//
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
const PRUnichar* tokenStart = aSpec.BeginReading();
|
2011-10-17 07:59:28 -07:00
|
|
|
const PRUnichar* tokenEnd = GetTokenEnd(aSpec, true);
|
2010-01-12 12:00:49 -08:00
|
|
|
nsAutoString token(Substring(tokenStart, tokenEnd));
|
|
|
|
Unescape(token);
|
|
|
|
|
|
|
|
if (token.IsEmpty())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Whether the token is an id-ref or event-symbol it should be a valid NCName
|
2011-10-17 07:59:28 -07:00
|
|
|
if (NS_FAILED(nsContentUtils::CheckQName(token, false)))
|
2010-01-12 12:00:49 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Parse the second token if there is one
|
|
|
|
if (tokenEnd != aSpec.EndReading() && *tokenEnd == '.') {
|
|
|
|
result.mDependentElemID = do_GetAtom(token);
|
|
|
|
|
|
|
|
tokenStart = ++tokenEnd;
|
2011-10-17 07:59:28 -07:00
|
|
|
tokenEnd = GetTokenEnd(Substring(tokenStart, aSpec.EndReading()), false);
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
// Don't unescape the token unless we need to and not until after we've
|
|
|
|
// tested it
|
|
|
|
const nsAString& rawToken2 = Substring(tokenStart, tokenEnd);
|
|
|
|
|
|
|
|
// element-name.begin
|
|
|
|
if (rawToken2.Equals(NS_LITERAL_STRING("begin"))) {
|
|
|
|
result.mType = nsSMILTimeValueSpecParams::SYNCBASE;
|
2011-10-17 07:59:28 -07:00
|
|
|
result.mSyncBegin = true;
|
2010-01-12 12:00:49 -08:00
|
|
|
// element-name.end
|
|
|
|
} else if (rawToken2.Equals(NS_LITERAL_STRING("end"))) {
|
|
|
|
result.mType = nsSMILTimeValueSpecParams::SYNCBASE;
|
2011-10-17 07:59:28 -07:00
|
|
|
result.mSyncBegin = false;
|
2010-01-12 12:00:49 -08:00
|
|
|
// element-name.repeat(digit+)
|
|
|
|
} else if (StringBeginsWith(rawToken2, REPEAT_PREFIX)) {
|
|
|
|
result.mType = nsSMILTimeValueSpecParams::REPEAT;
|
|
|
|
if (!GetUnsignedIntAndEndParen(
|
|
|
|
Substring(tokenStart + REPEAT_PREFIX.Length(), tokenEnd),
|
|
|
|
result.mRepeatIterationOrAccessKey))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
// element-name.event-symbol
|
|
|
|
} else {
|
|
|
|
nsAutoString token2(rawToken2);
|
|
|
|
Unescape(token2);
|
|
|
|
result.mType = nsSMILTimeValueSpecParams::EVENT;
|
|
|
|
if (token2.IsEmpty() ||
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_FAILED(nsContentUtils::CheckQName(token2, false)))
|
2010-01-12 12:00:49 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
result.mEventSymbol = do_GetAtom(token2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// event-symbol
|
|
|
|
result.mType = nsSMILTimeValueSpecParams::EVENT;
|
|
|
|
result.mEventSymbol = do_GetAtom(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We've reached the end of the token, so we should now be either looking at
|
|
|
|
// a '+', '-', or the end.
|
|
|
|
const PRUnichar* specEnd = aSpec.EndReading();
|
|
|
|
SkipBeginWsp(tokenEnd, specEnd);
|
2010-01-28 01:51:03 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
nsresult rv = ParseOptionalOffset(Substring(tokenEnd, specEnd), result);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aResult = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
} // end anonymous namespace block
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILParserUtils::ParseKeySplines(const nsAString& aSpec,
|
|
|
|
nsTArray<double>& aSplineArray)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 spec(aSpec);
|
2010-01-12 12:00:49 -08:00
|
|
|
const char* start = spec.BeginReading();
|
|
|
|
const char* end = spec.EndReading();
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
SkipBeginWsp(start, end);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (start != end)
|
|
|
|
{
|
|
|
|
double value = GetFloat(start, end, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (value > 1.0 || value < 0.0) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aSplineArray.AppendElement(value)) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
SkipBeginWsp(start, end);
|
2009-01-14 20:38:07 -08:00
|
|
|
if (start == end)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i % 4) {
|
|
|
|
if (*start == ',') {
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (*start != ';') {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
SkipBeginWsp(start, end);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i % 4) {
|
|
|
|
rv = NS_ERROR_FAILURE; // wrong number of points
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-04-28 16:00:54 -07:00
|
|
|
nsSMILParserUtils::ParseSemicolonDelimitedProgressList(const nsAString& aSpec,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNonDecreasing,
|
2010-04-28 16:00:54 -07:00
|
|
|
nsTArray<double>& aArray)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 spec(aSpec);
|
2010-01-12 12:00:49 -08:00
|
|
|
const char* start = spec.BeginReading();
|
|
|
|
const char* end = spec.EndReading();
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
SkipBeginWsp(start, end);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
double previousValue = -1.0;
|
|
|
|
|
|
|
|
while (start != end) {
|
|
|
|
double value = GetFloat(start, end, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
2010-04-28 16:00:54 -07:00
|
|
|
if (value > 1.0 || value < 0.0 ||
|
|
|
|
(aNonDecreasing && value < previousValue)) {
|
2009-01-14 20:38:07 -08:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-28 16:00:54 -07:00
|
|
|
if (!aArray.AppendElement(value)) {
|
2009-01-14 20:38:07 -08:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
previousValue = value;
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
SkipBeginWsp(start, end);
|
2009-01-14 20:38:07 -08:00
|
|
|
if (start == end)
|
|
|
|
break;
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
if (*start++ != ';') {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
SkipBeginWsp(start, end);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-04-28 16:00:53 -07:00
|
|
|
// Helper class for ParseValues
|
|
|
|
class SMILValueParser : public nsSMILParserUtils::GenericValueParser
|
|
|
|
{
|
|
|
|
public:
|
2013-03-18 20:18:45 -07:00
|
|
|
SMILValueParser(const SVGAnimationElement* aSrcElement,
|
2010-04-28 16:00:53 -07:00
|
|
|
const nsISMILAttr* aSMILAttr,
|
|
|
|
nsTArray<nsSMILValue>* aValuesArray,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aPreventCachingOfSandwich) :
|
2010-04-28 16:00:53 -07:00
|
|
|
mSrcElement(aSrcElement),
|
|
|
|
mSMILAttr(aSMILAttr),
|
|
|
|
mValuesArray(aValuesArray),
|
2010-06-23 17:30:55 -07:00
|
|
|
mPreventCachingOfSandwich(aPreventCachingOfSandwich)
|
2010-04-28 16:00:53 -07:00
|
|
|
{}
|
|
|
|
|
|
|
|
virtual nsresult Parse(const nsAString& aValueStr) {
|
|
|
|
nsSMILValue newValue;
|
2012-02-13 10:24:51 -08:00
|
|
|
bool tmpPreventCachingOfSandwich = false;
|
2010-06-23 17:30:55 -07:00
|
|
|
nsresult rv = mSMILAttr->ValueFromString(aValueStr, mSrcElement, newValue,
|
|
|
|
tmpPreventCachingOfSandwich);
|
2010-04-28 16:00:53 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!mValuesArray->AppendElement(newValue)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2010-06-23 17:30:55 -07:00
|
|
|
if (tmpPreventCachingOfSandwich) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*mPreventCachingOfSandwich = true;
|
2010-04-28 16:00:53 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
protected:
|
2013-03-18 20:18:45 -07:00
|
|
|
const SVGAnimationElement* mSrcElement;
|
2010-04-28 16:00:53 -07:00
|
|
|
const nsISMILAttr* mSMILAttr;
|
|
|
|
nsTArray<nsSMILValue>* mValuesArray;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* mPreventCachingOfSandwich;
|
2010-04-28 16:00:53 -07:00
|
|
|
};
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
nsresult
|
|
|
|
nsSMILParserUtils::ParseValues(const nsAString& aSpec,
|
2013-03-18 20:18:45 -07:00
|
|
|
const SVGAnimationElement* aSrcElement,
|
2009-07-15 11:33:31 -07:00
|
|
|
const nsISMILAttr& aAttribute,
|
2010-02-20 13:13:11 -08:00
|
|
|
nsTArray<nsSMILValue>& aValuesArray,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool& aPreventCachingOfSandwich)
|
2010-04-28 16:00:53 -07:00
|
|
|
{
|
|
|
|
// Assume all results can be cached, until we find one that can't.
|
2011-10-17 07:59:28 -07:00
|
|
|
aPreventCachingOfSandwich = false;
|
2010-04-28 16:00:53 -07:00
|
|
|
SMILValueParser valueParser(aSrcElement, &aAttribute,
|
2010-06-23 17:30:55 -07:00
|
|
|
&aValuesArray, &aPreventCachingOfSandwich);
|
2010-04-28 16:00:53 -07:00
|
|
|
return ParseValuesGeneric(aSpec, valueParser);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILParserUtils::ParseValuesGeneric(const nsAString& aSpec,
|
|
|
|
GenericValueParser& aParser)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-05-04 07:43:48 -07:00
|
|
|
nsCharSeparatedTokenizer tokenizer(aSpec, ';');
|
|
|
|
if (!tokenizer.hasMoreTokens()) { // Empty list
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-05-04 07:43:48 -07:00
|
|
|
while (tokenizer.hasMoreTokens()) {
|
|
|
|
nsresult rv = aParser.Parse(tokenizer.nextToken());
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
2010-05-04 07:43:48 -07:00
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-05-04 07:43:48 -07:00
|
|
|
return NS_OK;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSMILParserUtils::ParseRepeatCount(const nsAString& aSpec,
|
|
|
|
nsSMILRepeatCount& aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 spec(aSpec);
|
2010-01-12 12:00:49 -08:00
|
|
|
const char* start = spec.BeginReading();
|
|
|
|
const char* end = spec.EndReading();
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
SkipBeginWsp(start, end);
|
2009-07-15 11:33:31 -07:00
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
if (start != end)
|
|
|
|
{
|
|
|
|
if (ConsumeSubstring(start, end, "indefinite")) {
|
|
|
|
aResult.SetIndefinite();
|
|
|
|
} else {
|
|
|
|
double value = GetFloat(start, end, &rv);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
/* Repeat counts must be > 0 */
|
|
|
|
if (value <= 0.0) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
} else {
|
|
|
|
aResult = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for trailing junk */
|
2010-01-12 12:00:49 -08:00
|
|
|
SkipBeginWsp(start, end);
|
2009-01-14 20:38:07 -08:00
|
|
|
if (start != end) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Empty spec */
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aResult.Unset();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
nsresult
|
|
|
|
nsSMILParserUtils::ParseTimeValueSpecParams(const nsAString& aSpec,
|
|
|
|
nsSMILTimeValueSpecParams& aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
const PRUnichar* start = aSpec.BeginReading();
|
|
|
|
const PRUnichar* end = aSpec.EndReading();
|
|
|
|
|
|
|
|
SkipBeginEndWsp(start, end);
|
|
|
|
if (start == end)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
const nsAString &spec = Substring(start, end);
|
|
|
|
|
|
|
|
// offset type
|
|
|
|
if (*start == '+' || *start == '-' || NS_IsAsciiDigit(*start)) {
|
2011-11-30 15:45:28 -08:00
|
|
|
rv = ParseClockValue(spec, &aResult.mOffset,
|
|
|
|
nsSMILParserUtils::kClockValueAllowSign);
|
2010-01-12 12:00:49 -08:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aResult.mType = nsSMILTimeValueSpecParams::OFFSET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// indefinite
|
|
|
|
else if (spec.Equals(NS_LITERAL_STRING("indefinite"))) {
|
|
|
|
aResult.mType = nsSMILTimeValueSpecParams::INDEFINITE;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// wallclock type
|
|
|
|
else if (StringBeginsWith(spec, WALLCLOCK_PREFIX)) {
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// accesskey type
|
2010-08-27 23:41:05 -07:00
|
|
|
else if (StringBeginsWith(spec, ACCESSKEY_PREFIX_LC) ||
|
|
|
|
StringBeginsWith(spec, ACCESSKEY_PREFIX_CC)) {
|
2010-01-12 12:00:49 -08:00
|
|
|
rv = ParseAccessKey(spec, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
// event, syncbase, or repeat
|
|
|
|
else {
|
|
|
|
rv = ParseElementBaseTimeValueSpec(spec, aResult);
|
|
|
|
}
|
2010-01-28 01:51:03 -08:00
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
nsresult
|
|
|
|
nsSMILParserUtils::ParseClockValue(const nsAString& aSpec,
|
2009-07-15 11:33:31 -07:00
|
|
|
nsSMILTimeValue* aResult,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags, // = 0
|
2012-07-30 07:20:58 -07:00
|
|
|
bool* aIsMedia) // = nullptr
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
nsSMILTime offset = 0L;
|
|
|
|
double component = 0.0;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int8_t sign = 0;
|
|
|
|
uint8_t colonCount = 0;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2011-11-30 15:45:28 -08:00
|
|
|
// Indicates we have started parsing a clock-value (not including the optional
|
|
|
|
// +/- that precedes the clock-value) or keyword ("media", "indefinite")
|
2011-09-28 23:19:26 -07:00
|
|
|
bool started = false;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t metricMultiplicand = MSEC_PER_SEC;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool numIsReal = false;
|
|
|
|
bool prevNumCouldBeMin = false;
|
|
|
|
bool numCouldBeMin = false;
|
|
|
|
bool numCouldBeSec = false;
|
|
|
|
bool isIndefinite = false;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
if (aIsMedia) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsMedia = false;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 spec(aSpec);
|
2010-01-12 12:00:49 -08:00
|
|
|
const char* start = spec.BeginReading();
|
|
|
|
const char* end = spec.EndReading();
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
while (start != end) {
|
|
|
|
if (IsSpace(*start)) {
|
2011-11-30 15:45:28 -08:00
|
|
|
++start;
|
2009-01-14 20:38:07 -08:00
|
|
|
if (started) {
|
|
|
|
break;
|
|
|
|
}
|
2011-11-30 15:45:28 -08:00
|
|
|
} else if (!started && (aFlags & kClockValueAllowSign) &&
|
|
|
|
(*start == '+' || *start == '-')) {
|
|
|
|
// check sign has not already been set (e.g. ++10s)
|
2009-01-14 20:38:07 -08:00
|
|
|
if (sign != 0) {
|
2011-11-15 11:56:32 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
sign = (*start == '+') ? 1 : -1;
|
|
|
|
++start;
|
|
|
|
// The NS_IS_DIGIT etc. macros are not locale-specific
|
|
|
|
} else if (NS_IS_DIGIT(*start)) {
|
|
|
|
prevNumCouldBeMin = numCouldBeMin;
|
|
|
|
|
|
|
|
if (!ParseClockComponent(start, end, component, numIsReal, numCouldBeMin,
|
2011-11-30 15:45:28 -08:00
|
|
|
numCouldBeSec)) {
|
2011-11-15 11:56:32 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2011-11-30 15:45:28 -08:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
started = true;
|
2011-11-30 15:45:28 -08:00
|
|
|
} else if (started && *start == ':') {
|
2009-01-14 20:38:07 -08:00
|
|
|
++colonCount;
|
|
|
|
|
|
|
|
// Neither minutes nor hours can be reals
|
|
|
|
if (numIsReal) {
|
2011-11-15 11:56:32 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Can't have more than two colons
|
|
|
|
if (colonCount > 2) {
|
2011-11-15 11:56:32 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Multiply the offset by 60 and add the last accumulated component
|
2011-11-15 11:56:32 -08:00
|
|
|
offset = offset * 60 + nsSMILTime(component);
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
component = 0.0;
|
|
|
|
++start;
|
|
|
|
} else if (NS_IS_ALPHA(*start)) {
|
|
|
|
if (colonCount > 0) {
|
2011-11-15 11:56:32 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2011-11-30 15:45:28 -08:00
|
|
|
if (!started && (aFlags & kClockValueAllowIndefinite) &&
|
|
|
|
ConsumeSubstring(start, end, "indefinite")) {
|
2009-01-14 20:38:07 -08:00
|
|
|
// We set a separate flag because we don't know what the state of the
|
|
|
|
// passed in time value is and we shouldn't change it in the case of a
|
|
|
|
// bad input string (so we can't initialise it to 0ms for example).
|
2011-10-17 07:59:28 -07:00
|
|
|
isIndefinite = true;
|
2009-01-14 20:38:07 -08:00
|
|
|
if (aResult) {
|
|
|
|
aResult->SetIndefinite();
|
|
|
|
}
|
2011-11-30 15:45:28 -08:00
|
|
|
started = true;
|
|
|
|
} else if (!started && aIsMedia &&
|
|
|
|
ConsumeSubstring(start, end, "media")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsMedia = true;
|
2011-11-30 15:45:28 -08:00
|
|
|
started = true;
|
2009-01-14 20:38:07 -08:00
|
|
|
} else if (!ParseMetricMultiplicand(start, end, metricMultiplicand)) {
|
2011-11-15 11:56:32 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing must come after the string except whitespace
|
|
|
|
break;
|
|
|
|
} else {
|
2011-11-15 11:56:32 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-30 15:45:28 -08:00
|
|
|
// Whitespace/empty string
|
2009-01-14 20:38:07 -08:00
|
|
|
if (!started) {
|
2011-11-15 11:56:32 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process remainder of string (if any) to ensure it is only trailing
|
|
|
|
// whitespace (embedded whitespace is not allowed)
|
2010-01-12 12:00:49 -08:00
|
|
|
SkipBeginWsp(start, end);
|
2009-01-14 20:38:07 -08:00
|
|
|
if (start != end) {
|
2011-11-15 11:56:32 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// No more processing required if the value was "indefinite" or "media".
|
2011-11-15 11:56:32 -08:00
|
|
|
if (isIndefinite || (aIsMedia && *aIsMedia)) {
|
2009-01-14 20:38:07 -08:00
|
|
|
return NS_OK;
|
2011-11-15 11:56:32 -08:00
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
// If there is more than one colon then the previous component must be a
|
|
|
|
// correctly formatted minute (i.e. two digits between 00 and 59) and the
|
|
|
|
// latest component must be a correctly formatted second (i.e. two digits
|
|
|
|
// before the .)
|
|
|
|
if (colonCount > 0 && (!prevNumCouldBeMin || !numCouldBeSec)) {
|
2011-11-15 11:56:32 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2011-11-15 11:56:32 -08:00
|
|
|
// Tack on the last component
|
|
|
|
if (colonCount > 0) {
|
2011-11-30 15:45:28 -08:00
|
|
|
offset *= 60 * 1000;
|
2011-11-15 11:56:32 -08:00
|
|
|
component *= 1000;
|
|
|
|
// rounding
|
|
|
|
component = (component >= 0) ? component + 0.5 : component - 0.5;
|
|
|
|
offset += nsSMILTime(component);
|
|
|
|
} else {
|
|
|
|
component *= metricMultiplicand;
|
|
|
|
// rounding
|
|
|
|
component = (component >= 0) ? component + 0.5 : component - 0.5;
|
|
|
|
offset = nsSMILTime(component);
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2011-11-15 11:56:32 -08:00
|
|
|
// we haven't applied the sign yet so if the result is negative we must have
|
|
|
|
// overflowed
|
|
|
|
if (offset < 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2011-11-15 11:56:32 -08:00
|
|
|
if (aResult) {
|
|
|
|
if (sign == -1) {
|
|
|
|
offset = -offset;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
2011-11-15 11:56:32 -08:00
|
|
|
aResult->SetMillis(offset);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2011-11-15 11:56:32 -08:00
|
|
|
return NS_OK;
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2009-10-02 14:37:25 -07:00
|
|
|
nsSMILParserUtils::CheckForNegativeNumber(const nsAString& aStr)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t absValLocation = -1;
|
2009-10-02 14:37:25 -07:00
|
|
|
|
|
|
|
nsAString::const_iterator start, end;
|
|
|
|
aStr.BeginReading(start);
|
|
|
|
aStr.EndReading(end);
|
|
|
|
|
|
|
|
// Skip initial whitespace
|
2010-01-12 12:00:49 -08:00
|
|
|
SkipBeginWsp(start, end);
|
2009-10-02 14:37:25 -07:00
|
|
|
|
|
|
|
// Check for dash
|
|
|
|
if (start != end && *start == '-') {
|
|
|
|
++start;
|
|
|
|
// Check for numeric character
|
|
|
|
if (start != end && NS_IS_DIGIT(*start)) {
|
|
|
|
absValLocation = start.get() - start.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return absValLocation;
|
|
|
|
}
|