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 
     24 #include "CSSPrimitiveValue.h"
     25 #include "CSSFunctionValue.h"
     26 #include "CSSQuirkPrimitiveValue.h"
     27 #include "CSSSelector.h"
     28 #include "CSSSelectorList.h"
     29 
     30 namespace WebCore {
     31 
     32 using namespace WTF;
     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     m_values.append(v);
     46 }
     47 
     48 void CSSParserValueList::insertValueAt(unsigned i, const CSSParserValue& v)
     49 {
     50     m_values.insert(i, v);
     51 }
     52 
     53 void CSSParserValueList::deleteValueAt(unsigned i)
     54 {
     55     m_values.remove(i);
     56 }
     57 
     58 void CSSParserValueList::extend(CSSParserValueList& valueList)
     59 {
     60     for (unsigned int i = 0; i < valueList.size(); ++i)
     61         m_values.append(*(valueList.valueAt(i)));
     62 }
     63 
     64 PassRefPtr<CSSValue> CSSParserValue::createCSSValue()
     65 {
     66     RefPtr<CSSValue> parsedValue;
     67     if (id)
     68         parsedValue = CSSPrimitiveValue::createIdentifier(id);
     69     else if (unit == CSSPrimitiveValue::CSS_IDENT)
     70         parsedValue = CSSPrimitiveValue::create(string, CSSPrimitiveValue::CSS_PARSER_IDENTIFIER);
     71     else if (unit == CSSPrimitiveValue::CSS_NUMBER && isInt)
     72         parsedValue = CSSPrimitiveValue::create(fValue, CSSPrimitiveValue::CSS_PARSER_INTEGER);
     73     else if (unit == CSSParserValue::Operator) {
     74         RefPtr<CSSPrimitiveValue> primitiveValue = CSSPrimitiveValue::createIdentifier(iValue);
     75         primitiveValue->setPrimitiveType(CSSPrimitiveValue::CSS_PARSER_OPERATOR);
     76         parsedValue = primitiveValue;
     77     } else if (unit == CSSParserValue::Function)
     78         parsedValue = CSSFunctionValue::create(function);
     79     else if (unit == CSSPrimitiveValue::CSS_STRING || unit == CSSPrimitiveValue::CSS_URI || unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR)
     80         parsedValue = CSSPrimitiveValue::create(string, (CSSPrimitiveValue::UnitTypes)unit);
     81     else if (unit >= CSSPrimitiveValue::CSS_NUMBER && unit <= CSSPrimitiveValue::CSS_KHZ)
     82         parsedValue = CSSPrimitiveValue::create(fValue, (CSSPrimitiveValue::UnitTypes)unit);
     83     else if (unit >= CSSPrimitiveValue::CSS_TURN && unit <= CSSPrimitiveValue::CSS_REMS) // CSS3 Values and Units
     84         parsedValue = CSSPrimitiveValue::create(fValue, (CSSPrimitiveValue::UnitTypes)unit);
     85     else if (unit >= CSSParserValue::Q_EMS)
     86         parsedValue = CSSQuirkPrimitiveValue::create(fValue, CSSPrimitiveValue::CSS_EMS);
     87     return parsedValue;
     88 }
     89 
     90 CSSParserSelector::CSSParserSelector()
     91     : m_selector(adoptPtr(fastNew<CSSSelector>()))
     92 {
     93 }
     94 
     95 CSSParserSelector::~CSSParserSelector()
     96 {
     97     if (!m_tagHistory)
     98         return;
     99     Vector<CSSParserSelector*, 16> toDelete;
    100     CSSParserSelector* selector = m_tagHistory.leakPtr();
    101     while (true) {
    102         toDelete.append(selector);
    103         CSSParserSelector* next = selector->m_tagHistory.leakPtr();
    104         if (!next)
    105             break;
    106         selector = next;
    107     }
    108     deleteAllValues(toDelete);
    109 }
    110 
    111 void CSSParserSelector::adoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectorVector)
    112 {
    113     CSSSelectorList* selectorList = fastNew<CSSSelectorList>();
    114     selectorList->adoptSelectorVector(selectorVector);
    115     m_selector->setSelectorList(adoptPtr(selectorList));
    116 }
    117 }
    118 
    119