OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/css/parser/MediaQueryToken.h" |
| 7 |
| 8 #include "wtf/HashMap.h" |
| 9 #include "wtf/text/StringHash.h" |
| 10 |
| 11 namespace WebCore { |
| 12 |
| 13 typedef HashMap<String, CSSPrimitiveValue::UnitTypes> UnitTable; |
| 14 |
| 15 UnitTable createUnitTable() |
| 16 { |
| 17 UnitTable table; |
| 18 table.set(String("em"), CSSPrimitiveValue::CSS_EMS); |
| 19 table.set(String("ex"), CSSPrimitiveValue::CSS_EXS); |
| 20 table.set(String("px"), CSSPrimitiveValue::CSS_PX); |
| 21 table.set(String("cm"), CSSPrimitiveValue::CSS_CM); |
| 22 table.set(String("mm"), CSSPrimitiveValue::CSS_MM); |
| 23 table.set(String("in"), CSSPrimitiveValue::CSS_IN); |
| 24 table.set(String("pt"), CSSPrimitiveValue::CSS_PT); |
| 25 table.set(String("pc"), CSSPrimitiveValue::CSS_PC); |
| 26 table.set(String("deg"), CSSPrimitiveValue::CSS_DEG); |
| 27 table.set(String("rad"), CSSPrimitiveValue::CSS_RAD); |
| 28 table.set(String("grad"), CSSPrimitiveValue::CSS_GRAD); |
| 29 table.set(String("ms"), CSSPrimitiveValue::CSS_MS); |
| 30 table.set(String("s"), CSSPrimitiveValue::CSS_S); |
| 31 table.set(String("hz"), CSSPrimitiveValue::CSS_HZ); |
| 32 table.set(String("khz"), CSSPrimitiveValue::CSS_KHZ); |
| 33 table.set(String("dpi"), CSSPrimitiveValue::CSS_DPI); |
| 34 table.set(String("dpcm"), CSSPrimitiveValue::CSS_DPCM); |
| 35 table.set(String("dppx"), CSSPrimitiveValue::CSS_DPPX); |
| 36 table.set(String("vw"), CSSPrimitiveValue::CSS_VW); |
| 37 table.set(String("vh"), CSSPrimitiveValue::CSS_VH); |
| 38 table.set(String("vmax"), CSSPrimitiveValue::CSS_VMIN); |
| 39 table.set(String("vmin"), CSSPrimitiveValue::CSS_VMAX); |
| 40 return table; |
| 41 } |
| 42 |
| 43 static UnitTable* getUnitTable() |
| 44 { |
| 45 // Allocating to avoid exit time desctructor |
| 46 static UnitTable* unitTable = new UnitTable(createUnitTable()); |
| 47 return unitTable; |
| 48 } |
| 49 |
| 50 MediaQueryToken::MediaQueryToken(MediaQueryTokenType type) |
| 51 : m_type(type) |
| 52 , m_delimiter(0) |
| 53 , m_unit(CSSPrimitiveValue::CSS_UNKNOWN) |
| 54 { |
| 55 } |
| 56 |
| 57 // Just a helper used for Delim tokens. |
| 58 MediaQueryToken::MediaQueryToken(MediaQueryTokenType type, UChar c) |
| 59 : m_type(type) |
| 60 , m_delimiter(c) |
| 61 , m_unit(CSSPrimitiveValue::CSS_UNKNOWN) |
| 62 { |
| 63 ASSERT(m_type == DelimToken); |
| 64 } |
| 65 |
| 66 MediaQueryToken::MediaQueryToken(MediaQueryTokenType type, String value) |
| 67 : m_type(type) |
| 68 , m_value(value) |
| 69 , m_delimiter(0) |
| 70 , m_unit(CSSPrimitiveValue::CSS_UNKNOWN) |
| 71 { |
| 72 } |
| 73 |
| 74 MediaQueryToken::MediaQueryToken(MediaQueryTokenType type, double numericValue,
NumericValueType numericValueType) |
| 75 : m_type(type) |
| 76 , m_delimiter(0) |
| 77 , m_numericValueType(numericValueType) |
| 78 , m_numericValue(numericValue) |
| 79 , m_unit(CSSPrimitiveValue::CSS_NUMBER) |
| 80 { |
| 81 ASSERT(type == NumberToken); |
| 82 } |
| 83 |
| 84 void MediaQueryToken::convertToDimensionWithUnit(String unit) |
| 85 { |
| 86 ASSERT(m_type == NumberToken); |
| 87 m_type = DimensionToken; |
| 88 m_unit = getUnitTable()->get(unit.lower()); |
| 89 } |
| 90 |
| 91 void MediaQueryToken::convertToPercentage() |
| 92 { |
| 93 ASSERT(m_type == NumberToken); |
| 94 m_type = PercentageToken; |
| 95 m_unit = CSSPrimitiveValue::CSS_PERCENTAGE; |
| 96 } |
| 97 |
| 98 } // namespace WebCore |
OLD | NEW |