| Index: Source/core/css/parser/CSSToken.cpp
|
| diff --git a/Source/core/css/parser/CSSToken.cpp b/Source/core/css/parser/CSSToken.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3e497467cfee29aba34c1d545688420b8dceaa8a
|
| --- /dev/null
|
| +++ b/Source/core/css/parser/CSSToken.cpp
|
| @@ -0,0 +1,132 @@
|
| +/*
|
| + * Copyright (C) 2013 Google Inc. All rights reserved.
|
| + *
|
| + * Redistribution and use in source and binary forms, with or without
|
| + * modification, are permitted provided that the following conditions are
|
| + * met:
|
| + *
|
| + * * Redistributions of source code must retain the above copyright
|
| + * notice, this list of conditions and the following disclaimer.
|
| + * * Redistributions in binary form must reproduce the above
|
| + * copyright notice, this list of conditions and the following disclaimer
|
| + * in the documentation and/or other materials provided with the
|
| + * distribution.
|
| + * * Neither the name of Google Inc. nor the names of its
|
| + * contributors may be used to endorse or promote products derived from
|
| + * this software without specific prior written permission.
|
| + *
|
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| + */
|
| +
|
| +#include "config.h"
|
| +#include "core/css/parser/CSSToken.h"
|
| +
|
| +#include "wtf/HashMap.h"
|
| +#include "wtf/text/StringHash.h"
|
| +
|
| +namespace WebCore {
|
| +
|
| +typedef HashMap<String, CSSPrimitiveValue::UnitTypes> UnitTable;
|
| +
|
| +UnitTable createUnitTable()
|
| +{
|
| + UnitTable table;
|
| + table.set(String("em"), CSSPrimitiveValue::CSS_EMS);
|
| + table.set(String("ex"), CSSPrimitiveValue::CSS_EXS);
|
| + table.set(String("px"), CSSPrimitiveValue::CSS_PX);
|
| + table.set(String("cm"), CSSPrimitiveValue::CSS_CM);
|
| + table.set(String("mm"), CSSPrimitiveValue::CSS_MM);
|
| + table.set(String("in"), CSSPrimitiveValue::CSS_IN);
|
| + table.set(String("pt"), CSSPrimitiveValue::CSS_PT);
|
| + table.set(String("pc"), CSSPrimitiveValue::CSS_PC);
|
| + table.set(String("deg"), CSSPrimitiveValue::CSS_DEG);
|
| + table.set(String("rad"), CSSPrimitiveValue::CSS_RAD);
|
| + table.set(String("grad"), CSSPrimitiveValue::CSS_GRAD);
|
| + table.set(String("ms"), CSSPrimitiveValue::CSS_MS);
|
| + table.set(String("s"), CSSPrimitiveValue::CSS_S);
|
| + table.set(String("hz"), CSSPrimitiveValue::CSS_HZ);
|
| + table.set(String("khz"), CSSPrimitiveValue::CSS_KHZ);
|
| + return table;
|
| +}
|
| +
|
| +static UnitTable* getUnitTable()
|
| +{
|
| + // Allocating to avoid exit time desctructor
|
| + static UnitTable* unitTable = new UnitTable(createUnitTable());
|
| + return unitTable;
|
| +}
|
| +
|
| +CSSToken::CSSToken(CSSTokenType type)
|
| + : m_type(type)
|
| + , m_delimiter(0)
|
| + , m_unit(CSSPrimitiveValue::CSS_UNKNOWN)
|
| +{
|
| +}
|
| +
|
| +// Just a helper used for Delim tokens.
|
| +CSSToken::CSSToken(CSSTokenType type, UChar c)
|
| + : m_type(type)
|
| + , m_delimiter(c)
|
| + , m_unit(CSSPrimitiveValue::CSS_UNKNOWN)
|
| +{
|
| + ASSERT(m_type == DelimToken);
|
| +}
|
| +
|
| +CSSToken::CSSToken(CSSTokenType type, String value)
|
| + : m_type(type)
|
| + , m_value(value)
|
| + , m_delimiter(0)
|
| + , m_unit(CSSPrimitiveValue::CSS_UNKNOWN)
|
| +{
|
| +}
|
| +
|
| +CSSToken::CSSToken(CSSTokenType type, String name, HashTokenType hashType)
|
| + : m_type(type)
|
| + , m_value(name)
|
| + , m_hashTokenType(hashType)
|
| + , m_delimiter(0)
|
| + , m_unit(CSSPrimitiveValue::CSS_UNKNOWN)
|
| +{
|
| + ASSERT(m_type == HashToken);
|
| +}
|
| +
|
| +CSSToken::CSSToken(CSSTokenType type, String value, double numericValue, NumericValueType numericValueType)
|
| + : m_type(type)
|
| + , m_value(value)
|
| + , m_delimiter(0)
|
| + , m_numericValueType(numericValueType)
|
| + , m_numericValue(numericValue)
|
| + , m_unit(CSSPrimitiveValue::CSS_NUMBER)
|
| +{
|
| + ASSERT(type == NumberToken);
|
| +}
|
| +
|
| +void CSSToken::convertToDimensionWithUnit(String unit)
|
| +{
|
| + ASSERT(m_type == NumberToken);
|
| + m_type = DimensionToken;
|
| + StringImpl* lowerUnit = unit.lower().impl();
|
| + if (getUnitTable()->contains(lowerUnit))
|
| + m_unit = getUnitTable()->get(lowerUnit);
|
| + else
|
| + m_unit = CSSPrimitiveValue::CSS_UNKNOWN;
|
| +}
|
| +
|
| +void CSSToken::convertToPercentage()
|
| +{
|
| + ASSERT(m_type == NumberToken);
|
| + m_type = PercentageToken;
|
| + m_unit = CSSPrimitiveValue::CSS_PERCENTAGE;
|
| +}
|
| +
|
| +} // namespace WebCore
|
|
|