Chromium Code Reviews| Index: Source/core/css/parser/MediaQueryToken.cpp |
| diff --git a/Source/core/css/parser/MediaQueryToken.cpp b/Source/core/css/parser/MediaQueryToken.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..796d4a7296fc966792a79bfcce00b1e354781f9e |
| --- /dev/null |
| +++ b/Source/core/css/parser/MediaQueryToken.cpp |
| @@ -0,0 +1,98 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "core/css/parser/MediaQueryToken.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); |
| + table.set(String("dpi"), CSSPrimitiveValue::CSS_DPI); |
| + table.set(String("dpcm"), CSSPrimitiveValue::CSS_DPCM); |
| + table.set(String("dppx"), CSSPrimitiveValue::CSS_DPPX); |
| + table.set(String("vw"), CSSPrimitiveValue::CSS_VW); |
| + table.set(String("vh"), CSSPrimitiveValue::CSS_VH); |
| + table.set(String("vmax"), CSSPrimitiveValue::CSS_VMIN); |
| + table.set(String("vmin"), CSSPrimitiveValue::CSS_VMAX); |
| + return table; |
| +} |
| + |
| +static UnitTable* getUnitTable() |
| +{ |
| + // Allocating to avoid exit time desctructor |
| + static UnitTable* unitTable = new UnitTable(createUnitTable()); |
|
kenneth.r.christiansen
2014/03/08 22:37:47
Why not use the common macro for this?
|
| + return unitTable; |
| +} |
| + |
| +MediaQueryToken::MediaQueryToken(MediaQueryTokenType type) |
| + : m_type(type) |
| + , m_delimiter(0) |
| + , m_unit(CSSPrimitiveValue::CSS_UNKNOWN) |
| +{ |
| +} |
| + |
| +// Just a helper used for Delim tokens. |
| +MediaQueryToken::MediaQueryToken(MediaQueryTokenType type, UChar c) |
| + : m_type(type) |
| + , m_delimiter(c) |
| + , m_unit(CSSPrimitiveValue::CSS_UNKNOWN) |
| +{ |
| + ASSERT(m_type == DelimToken); |
| +} |
| + |
| +MediaQueryToken::MediaQueryToken(MediaQueryTokenType type, String value) |
| + : m_type(type) |
| + , m_value(value) |
| + , m_delimiter(0) |
| + , m_unit(CSSPrimitiveValue::CSS_UNKNOWN) |
| +{ |
| +} |
| + |
| +MediaQueryToken::MediaQueryToken(MediaQueryTokenType type, double numericValue, NumericValueType numericValueType) |
| + : m_type(type) |
| + , m_delimiter(0) |
| + , m_numericValueType(numericValueType) |
| + , m_numericValue(numericValue) |
| + , m_unit(CSSPrimitiveValue::CSS_NUMBER) |
| +{ |
| + ASSERT(type == NumberToken); |
| +} |
| + |
| +void MediaQueryToken::convertToDimensionWithUnit(String unit) |
| +{ |
| + ASSERT(m_type == NumberToken); |
| + m_type = DimensionToken; |
| + m_unit = getUnitTable()->get(unit.lower()); |
| +} |
| + |
| +void MediaQueryToken::convertToPercentage() |
| +{ |
| + ASSERT(m_type == NumberToken); |
| + m_type = PercentageToken; |
| + m_unit = CSSPrimitiveValue::CSS_PERCENTAGE; |
| +} |
| + |
| +} // namespace WebCore |