Home | History | Annotate | Download | only in css
      1 /*
      2  * Copyright (C) 2003 Lars Knoll (knoll (at) kde.org)
      3  * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
      4  *
      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.
      9  *
     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.
     14  *
     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.
     19  */
     20 
     21 #include "config.h"
     22 #include "CSSParserValues.h"
     23 #include "CSSPrimitiveValue.h"
     24 #include "CSSFunctionValue.h"
     25 #include "CSSQuirkPrimitiveValue.h"
     26 
     27 namespace WebCore {
     28 
     29 bool CSSParserValue::isVariable() const
     30 {
     31     return unit == CSSPrimitiveValue::CSS_PARSER_VARIABLE_FUNCTION_SYNTAX;
     32 }
     33 
     34 CSSParserValueList::~CSSParserValueList()
     35 {
     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;
     40     }
     41 }
     42 
     43 void CSSParserValueList::addValue(const CSSParserValue& v)
     44 {
     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);
     48 }
     49 
     50 void CSSParserValueList::deleteValueAt(unsigned i)
     51 {
     52     if (m_values[i].isVariable())
     53         m_variablesCount--;
     54     m_values.remove(i);
     55 }
     56 
     57 PassRefPtr<CSSValue> CSSParserValue::createCSSValue()
     58 {
     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;
     81 }
     82 
     83 }
     84 
     85