Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / css / CSSParserValues.cpp
blob55ecb7fdfe02c6e61afc3c8c98c210f59a856d8e
1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #include "config.h"
22 #include "CSSParserValues.h"
23 #include "CSSPrimitiveValue.h"
24 #include "CSSFunctionValue.h"
25 #include "CSSQuirkPrimitiveValue.h"
27 namespace WebCore {
29 bool CSSParserValue::isVariable() const
31 return unit == CSSPrimitiveValue::CSS_PARSER_VARIABLE_FUNCTION_SYNTAX;
34 CSSParserValueList::~CSSParserValueList()
36 size_t numValues = m_values.size();
37 for (size_t i = 0; i < numValues; i++) {
38 if (m_values[i].unit == CSSParserValue::Function)
39 delete m_values[i].function;
43 void CSSParserValueList::addValue(const CSSParserValue& v)
45 if (v.unit == CSSPrimitiveValue::CSS_PARSER_VARIABLE_FUNCTION_SYNTAX) // isVariable() is not inlined. This is hot.
46 m_variablesCount++;
47 m_values.append(v);
50 void CSSParserValueList::deleteValueAt(unsigned i)
52 if (m_values[i].isVariable())
53 m_variablesCount--;
54 m_values.remove(i);
57 PassRefPtr<CSSValue> CSSParserValue::createCSSValue()
59 RefPtr<CSSValue> parsedValue;
60 if (id)
61 parsedValue = CSSPrimitiveValue::createIdentifier(id);
62 else if (unit == CSSPrimitiveValue::CSS_IDENT)
63 parsedValue = CSSPrimitiveValue::create(string, CSSPrimitiveValue::CSS_PARSER_IDENTIFIER);
64 else if (unit == CSSPrimitiveValue::CSS_NUMBER && isInt)
65 parsedValue = CSSPrimitiveValue::create(fValue, CSSPrimitiveValue::CSS_PARSER_INTEGER);
66 else if (unit == CSSParserValue::Operator) {
67 RefPtr<CSSPrimitiveValue> primitiveValue = CSSPrimitiveValue::createIdentifier(iValue);
68 primitiveValue->setPrimitiveType(CSSPrimitiveValue::CSS_PARSER_OPERATOR);
69 parsedValue = primitiveValue;
70 } else if (unit == CSSParserValue::Function)
71 parsedValue = CSSFunctionValue::create(function);
72 else if (unit == CSSPrimitiveValue::CSS_STRING || unit == CSSPrimitiveValue::CSS_URI || unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR || isVariable())
73 parsedValue = CSSPrimitiveValue::create(string, (CSSPrimitiveValue::UnitTypes)unit);
74 else if (unit >= CSSPrimitiveValue::CSS_NUMBER && unit <= CSSPrimitiveValue::CSS_KHZ)
75 parsedValue = CSSPrimitiveValue::create(fValue, (CSSPrimitiveValue::UnitTypes)unit);
76 else if (unit >= CSSPrimitiveValue::CSS_TURN && unit <= CSSPrimitiveValue::CSS_REMS) // CSS3 Values and Units
77 parsedValue = CSSPrimitiveValue::create(fValue, (CSSPrimitiveValue::UnitTypes)unit);
78 else if (unit >= CSSParserValue::Q_EMS)
79 parsedValue = CSSQuirkPrimitiveValue::create(fValue, CSSPrimitiveValue::CSS_EMS);
80 return parsedValue;