1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "config.h"
6#include "core/animation/AnimationInputHelpers.h"
7
8#include "core/css/parser/CSSParser.h"
9#include "core/css/resolver/CSSToStyleMap.h"
10#include "wtf/text/StringBuilder.h"
11
12namespace blink {
13
14CSSPropertyID AnimationInputHelpers::keyframeAttributeToCSSPropertyID(const String& propertyName)
15{
16    // Disallow prefixed properties.
17    if (propertyName[0] == '-' || isASCIIUpper(propertyName[0]))
18        return CSSPropertyInvalid;
19    if (propertyName == "cssFloat")
20        return CSSPropertyFloat;
21    StringBuilder builder;
22    for (size_t i = 0; i < propertyName.length(); ++i) {
23        if (isASCIIUpper(propertyName[i]))
24            builder.append('-');
25        builder.append(propertyName[i]);
26    }
27    return cssPropertyID(builder.toString());
28}
29
30PassRefPtr<TimingFunction> AnimationInputHelpers::parseTimingFunction(const String& string)
31{
32    if (string.isEmpty())
33        return nullptr;
34
35    RefPtrWillBeRawPtr<CSSValue> value = CSSParser::parseSingleValue(CSSPropertyTransitionTimingFunction, string);
36    if (!value || value->isInitialValue() || value->isInheritedValue())
37        return nullptr;
38    CSSValueList* valueList = toCSSValueList(value.get());
39    if (valueList->length() > 1)
40        return nullptr;
41    return CSSToStyleMap::mapAnimationTimingFunction(valueList->item(0), true);
42}
43
44} // namespace blink
45