15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved.
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is free software; you can redistribute it and/or
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modify it under the terms of the GNU Library General Public
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * License as published by the Free Software Foundation; either
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * version 2 of the License, or (at your option) any later version.
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is distributed in the hope that it will be useful,
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * but WITHOUT ANY WARRANTY; without even the implied warranty of
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Library General Public License for more details.
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * You should have received a copy of the GNU Library General Public License
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * along with this library; see the file COPYING.LIB.  If not, write to
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Boston, MA 02110-1301, USA.
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef CSSParserValues_h
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define CSSParserValues_h
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
245d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#include "core/CSSValueKeywords.h"
2593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "core/css/CSSPrimitiveValue.h"
2653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/css/CSSSelector.h"
2753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/css/CSSValueList.h"
285267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "wtf/text/AtomicString.h"
295267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "wtf/text/WTFString.h"
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore {
325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CSSValue;
345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class QualifiedName;
355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)struct CSSParserString {
3793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void init(const LChar* characters, unsigned length)
385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_data.characters8 = characters;
405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_length = length;
415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_is8Bit = true;
425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
4493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void init(const UChar* characters, unsigned length)
455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_data.characters16 = characters;
475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_length = length;
485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_is8Bit = false;
495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void init(const String& string)
525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
5393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        init(string, 0, string.length());
5493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    }
5593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
5693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void init(const String& string, unsigned startOffset, unsigned length)
5793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    {
5893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        m_length = length;
59fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch        if (!m_length) {
60fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch            m_data.characters8 = 0;
61fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch            m_is8Bit = true;
62fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch            return;
63fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch        }
64fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch        if (string.is8Bit()) {
6593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            m_data.characters8 = const_cast<LChar*>(string.characters8()) + startOffset;
665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            m_is8Bit = true;
675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        } else {
68591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch            m_data.characters16 = const_cast<UChar*>(string.characters16()) + startOffset;
695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            m_is8Bit = false;
705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void clear()
745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_data.characters8 = 0;
765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        m_length = 0;
77591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        m_is8Bit = true;
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool is8Bit() const { return m_is8Bit; }
8193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    const LChar* characters8() const { ASSERT(is8Bit()); return m_data.characters8; }
8293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    const UChar* characters16() const { ASSERT(!is8Bit()); return m_data.characters16; }
835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    template <typename CharacterType>
8493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    const CharacterType* characters() const;
855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned length() const { return m_length; }
875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void setLength(unsigned length) { m_length = length; }
885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    UChar operator[](unsigned i) const
905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
91926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        ASSERT_WITH_SECURITY_IMPLICATION(i < m_length);
925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (is8Bit())
935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            return m_data.characters8[i];
945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return m_data.characters16[i];
955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
9753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    bool equalIgnoringCase(const char* str) const
985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
99d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        bool match = is8Bit() ? WTF::equalIgnoringCase(str, characters8(), length()) : WTF::equalIgnoringCase(str, characters16(), length());
100d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        if (!match)
101d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            return false;
102d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        ASSERT(strlen(str) >= length());
103d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        return str[length()] == '\0';
1045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
1055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
10693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    template <size_t strLength>
10793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    bool startsWithIgnoringCase(const char (&str)[strLength]) const
10893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    {
10993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        return startsWithIgnoringCase(str, strLength - 1);
11093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    }
11193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
11293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    bool startsWithIgnoringCase(const char* str, size_t strLength) const
11393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    {
11493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        if (length() < strLength)
11593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            return false;
11693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        return is8Bit() ? WTF::equalIgnoringCase(str, characters8(), strLength) : WTF::equalIgnoringCase(str, characters16(), strLength);
11793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    }
11893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
119591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    operator String() const { return is8Bit() ? String(m_data.characters8, m_length) : StringImpl::create8BitIfPossible(m_data.characters16, m_length); }
1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    operator AtomicString() const { return is8Bit() ? AtomicString(m_data.characters8, m_length) : AtomicString(m_data.characters16, m_length); }
1215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1229bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)    bool isFunction() const { return length() > 0 && (*this)[length() - 1] == '('; }
1239bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles)
1245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    union {
12593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        const LChar* characters8;
12693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        const UChar* characters16;
1275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    } m_data;
1285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned m_length;
1295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool m_is8Bit;
1305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
1315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
13251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)template <>
13351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)inline const LChar* CSSParserString::characters<LChar>() const { return characters8(); }
13451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
13551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)template <>
13651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)inline const UChar* CSSParserString::characters<UChar>() const { return characters16(); }
13751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
1385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)struct CSSParserFunction;
1395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)struct CSSParserValue {
1415267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    CSSValueID id;
1425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool isInt;
1435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    union {
1445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        double fValue;
1455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        int iValue;
1465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        CSSParserString string;
1475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        CSSParserFunction* function;
14851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        CSSParserValueList* valueList;
1495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    };
1505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    enum {
15151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Operator  = 0x100000,
15251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Function  = 0x100001,
15351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        ValueList = 0x100002,
15451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Q_EMS     = 0x100003,
1555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    };
1565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    int unit;
1575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
15893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    inline void setFromNumber(double value, int unit = CSSPrimitiveValue::CSS_NUMBER);
159521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)    inline void setFromFunction(CSSParserFunction*);
16051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    inline void setFromValueList(PassOwnPtr<CSSParserValueList>);
1615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
162d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    PassRefPtrWillBeRawPtr<CSSValue> createCSSValue();
1635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
1645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CSSParserValueList {
1665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WTF_MAKE_FAST_ALLOCATED;
1675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
1685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    CSSParserValueList()
1695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        : m_current(0)
1705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
1715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
1725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ~CSSParserValueList();
1735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void addValue(const CSSParserValue&);
1755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void insertValueAt(unsigned, const CSSParserValue&);
17609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    void stealValues(CSSParserValueList&);
1775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned size() const { return m_values.size(); }
1795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned currentIndex() { return m_current; }
1805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    CSSParserValue* current() { return m_current < m_values.size() ? &m_values[m_current] : 0; }
1815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    CSSParserValue* next() { ++m_current; return current(); }
1825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    CSSParserValue* previous()
1835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
1845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (!m_current)
1855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            return 0;
1865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        --m_current;
1875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return current();
1885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
189aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    void setCurrentIndex(unsigned index)
190aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    {
191aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch        ASSERT(index < m_values.size());
192aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch        if (index < m_values.size())
193aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch            m_current = index;
194aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch    }
1955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    CSSParserValue* valueAt(unsigned i) { return i < m_values.size() ? &m_values[i] : 0; }
1975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
198323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    void clearAndLeakValues() { m_values.clear(); m_current = 0;}
199323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    void destroyAndClear();
2005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)private:
2025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    unsigned m_current;
2035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    Vector<CSSParserValue, 4> m_values;
2045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
2055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)struct CSSParserFunction {
2075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    WTF_MAKE_FAST_ALLOCATED;
2085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
2095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    CSSParserString name;
2105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    OwnPtr<CSSParserValueList> args;
2115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
2125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CSSParserSelector {
21493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    WTF_MAKE_NONCOPYABLE(CSSParserSelector); WTF_MAKE_FAST_ALLOCATED;
2155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
2165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    CSSParserSelector();
217926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    explicit CSSParserSelector(const QualifiedName&);
2185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ~CSSParserSelector();
2195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    PassOwnPtr<CSSSelector> releaseSelector() { return m_selector.release(); }
2215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
22293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    CSSSelector::Relation relation() const { return m_selector->relation(); }
2235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void setValue(const AtomicString& value) { m_selector->setValue(value); }
2245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void setAttribute(const QualifiedName& value) { m_selector->setAttribute(value); }
2255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void setArgument(const AtomicString& value) { m_selector->setArgument(value); }
2265d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    void setMatch(CSSSelector::Match value) { m_selector->setMatch(value); }
2275d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    void setRelation(CSSSelector::Relation value) { m_selector->setRelation(value); }
2285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void setForPage() { m_selector->setForPage(); }
229df95704c49daea886ddad70775bda23618d6274dBen Murdoch    void setRelationIsAffectedByPseudoContent() { m_selector->setRelationIsAffectedByPseudoContent(); }
230df95704c49daea886ddad70775bda23618d6274dBen Murdoch    bool relationIsAffectedByPseudoContent() const { return m_selector->relationIsAffectedByPseudoContent(); }
2315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
232926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    void adoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectorVector);
233926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
23407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    bool hasHostPseudoSelector() const;
23507a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    bool isContentPseudoElement() const { return m_selector->isContentPseudoElement(); }
2365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    CSSSelector::PseudoType pseudoType() const { return m_selector->pseudoType(); }
2385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool isCustomPseudoElement() const { return m_selector->isCustomPseudoElement(); }
23907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch    bool crossesTreeScopes() const { return isCustomPseudoElement() || pseudoType() == CSSSelector::PseudoCue || pseudoType() == CSSSelector::PseudoShadow; }
2405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
241926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    bool isSimple() const;
24293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    bool hasShadowPseudo() const;
2435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    CSSParserSelector* tagHistory() const { return m_tagHistory.get(); }
2455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void setTagHistory(PassOwnPtr<CSSParserSelector> selector) { m_tagHistory = selector; }
246926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    void clearTagHistory() { m_tagHistory.clear(); }
2475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void insertTagHistory(CSSSelector::Relation before, PassOwnPtr<CSSParserSelector>, CSSSelector::Relation after);
2485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void appendTagHistory(CSSSelector::Relation, PassOwnPtr<CSSParserSelector>);
249926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    void prependTagSelector(const QualifiedName&, bool tagIsForNamespaceRule = false);
2505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)private:
2525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    OwnPtr<CSSSelector> m_selector;
2535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    OwnPtr<CSSParserSelector> m_tagHistory;
2545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
2555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
25693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)inline bool CSSParserSelector::hasShadowPseudo() const
25793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles){
25893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    return m_selector->relation() == CSSSelector::ShadowPseudo;
25993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}
26093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
26193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)inline void CSSParserValue::setFromNumber(double value, int unit)
2625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2635267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    id = CSSValueInvalid;
26493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    isInt = false;
26509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (std::isfinite(value))
26609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        fValue = value;
26709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    else
26809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        fValue = 0;
26993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    this->unit = unit;
2705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
272521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)inline void CSSParserValue::setFromFunction(CSSParserFunction* function)
273521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles){
274521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)    id = CSSValueInvalid;
275521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)    this->function = function;
276521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)    unit = Function;
2775d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    isInt = false;
278521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)}
279521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)
28051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)inline void CSSParserValue::setFromValueList(PassOwnPtr<CSSParserValueList> valueList)
28151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
28251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    id = CSSValueInvalid;
28351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    this->valueList = valueList.leakPtr();
28451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    unit = ValueList;
2855d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    isInt = false;
28651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
28751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
2885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif
291