Chromium Code Reviews| 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); | |
|
eseidel
2014/03/11 20:14:19
Should this funtion be on CSSPrimtiveValue? If we
Yoav Weiss
2014/03/12 20:39:00
Maybe the best way to do that is through some CSSU
eseidel
2014/03/13 00:49:36
OK. Just file a bug and table that for a later CL
| |
| 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 DEFINE_STATIC_LOCAL(UnitTable, unitTable, (createUnitTable())); | |
| 46 return unitTable; | |
| 47 } | |
| 48 | |
| 49 MediaQueryToken::MediaQueryToken(MediaQueryTokenType type) | |
| 50 : m_type(type) | |
| 51 , m_delimiter(0) | |
| 52 , m_unit(CSSPrimitiveValue::CSS_UNKNOWN) | |
| 53 { | |
| 54 } | |
| 55 | |
| 56 // Just a helper used for Delimiter tokens. | |
| 57 MediaQueryToken::MediaQueryToken(MediaQueryTokenType type, UChar c) | |
| 58 : m_type(type) | |
| 59 , m_delimiter(c) | |
| 60 , m_unit(CSSPrimitiveValue::CSS_UNKNOWN) | |
| 61 { | |
| 62 ASSERT(m_type == DelimiterToken); | |
| 63 } | |
| 64 | |
| 65 MediaQueryToken::MediaQueryToken(MediaQueryTokenType type, String value) | |
| 66 : m_type(type) | |
| 67 , m_value(value) | |
| 68 , m_delimiter(0) | |
| 69 , m_unit(CSSPrimitiveValue::CSS_UNKNOWN) | |
| 70 { | |
| 71 } | |
| 72 | |
| 73 MediaQueryToken::MediaQueryToken(MediaQueryTokenType type, double numericValue, NumericValueType numericValueType) | |
| 74 : m_type(type) | |
| 75 , m_delimiter(0) | |
| 76 , m_numericValueType(numericValueType) | |
| 77 , m_numericValue(numericValue) | |
| 78 , m_unit(CSSPrimitiveValue::CSS_NUMBER) | |
| 79 { | |
| 80 ASSERT(type == NumberToken); | |
| 81 } | |
| 82 | |
| 83 void MediaQueryToken::convertToDimensionWithUnit(String unit) | |
| 84 { | |
| 85 ASSERT(m_type == NumberToken); | |
| 86 m_type = DimensionToken; | |
| 87 m_unit = getUnitTable().get(unit.lower()); | |
| 88 } | |
| 89 | |
| 90 void MediaQueryToken::convertToPercentage() | |
| 91 { | |
| 92 ASSERT(m_type == NumberToken); | |
| 93 m_type = PercentageToken; | |
| 94 m_unit = CSSPrimitiveValue::CSS_PERCENTAGE; | |
| 95 } | |
| 96 | |
| 97 } // namespace WebCore | |
| OLD | NEW |