Chromium Code Reviews| Index: Source/core/css/CSSPrimitiveValue.cpp |
| diff --git a/Source/core/css/CSSPrimitiveValue.cpp b/Source/core/css/CSSPrimitiveValue.cpp |
| index 3e8650402d00f0b210d388a06343b4215de8ccc1..a9b589057bb78ccaac9983684ac3d1b576ca8fea 100644 |
| --- a/Source/core/css/CSSPrimitiveValue.cpp |
| +++ b/Source/core/css/CSSPrimitiveValue.cpp |
| @@ -112,9 +112,11 @@ static inline bool isValidCSSUnitTypeForDoubleConversion(CSSPrimitiveValue::Unit |
| return false; |
| } |
| -CSSPrimitiveValue::UnitTable createUnitTable() |
| +typedef HashMap<String, CSSPrimitiveValue::UnitTypes> StringToUnitTable; |
| + |
| +StringToUnitTable createStringToUnitTable() |
| { |
| - CSSPrimitiveValue::UnitTable table; |
| + StringToUnitTable table; |
| table.set(String("em"), CSSPrimitiveValue::CSS_EMS); |
| table.set(String("ex"), CSSPrimitiveValue::CSS_EXS); |
| table.set(String("px"), CSSPrimitiveValue::CSS_PX); |
| @@ -140,9 +142,10 @@ CSSPrimitiveValue::UnitTable createUnitTable() |
| return table; |
| } |
| + |
| CSSPrimitiveValue::UnitTypes CSSPrimitiveValue::fromName(const String& unit) |
| { |
| - DEFINE_STATIC_LOCAL(UnitTable, unitTable, (createUnitTable())); |
| + DEFINE_STATIC_LOCAL(StringToUnitTable, unitTable, (createStringToUnitTable())); |
| return unitTable.get(unit.lower()); |
| } |
| @@ -1056,6 +1059,67 @@ ALWAYS_INLINE static String formatNumber(double number, const char (&characters) |
| return formatNumber(number, characters, characterCount - 1); |
| } |
| +static String formatNumber(double number, const String & str) |
| +{ |
| + return formatNumber(number, str.ascii().data(), str.length()); |
| +} |
| + |
| +String CSSPrimitiveValue::unitTypeToString(UnitTypes type) |
| +{ |
| + switch (type) { |
| + case CSS_NUMBER: |
| + case CSS_PARSER_INTEGER: |
| + return String(""); |
| + case CSS_PERCENTAGE: |
| + return String("%"); |
| + case CSS_EMS: |
| + return String("em"); |
| + case CSS_EXS: |
| + return String("ex"); |
| + case CSS_REMS: |
| + return String("rem"); |
| + case CSS_CHS: |
| + return String("ch"); |
| + case CSS_PX: |
| + return String("px"); |
| + case CSS_CM: |
| + return String("cm"); |
| + case CSS_DPPX: |
| + return String("dppx"); |
| + case CSS_DPI: |
| + return String("dpi"); |
| + case CSS_DPCM: |
| + return String("dpcm"); |
| + case CSS_MM: |
| + return String("mm"); |
| + case CSS_IN: |
| + return String("in"); |
| + case CSS_PT: |
| + return String("pt"); |
| + case CSS_PC: |
| + return String("pc"); |
| + case CSS_DEG: |
| + return String("deg"); |
| + case CSS_RAD: |
| + return String("rad"); |
| + case CSS_GRAD: |
| + return String("grad"); |
| + case CSS_MS: |
| + return String("ms"); |
| + case CSS_S: |
| + return String("s"); |
| + case CSS_HZ: |
| + return String("hz"); |
| + case CSS_KHZ: |
| + return String("khz"); |
| + case CSS_TURN: |
| + return String("turn"); |
| + default: |
|
eseidel
2014/04/23 16:51:04
Are you sure you want a default? That will defeat
|
| + break; |
| + }; |
| + return String(); |
| +} |
| + |
| String CSSPrimitiveValue::customCSSText(CSSTextFormattingFlags formattingFlag) const |
| { |
| // FIXME: return the original value instead of a generated one (e.g. color |
| @@ -1073,74 +1137,29 @@ String CSSPrimitiveValue::customCSSText(CSSTextFormattingFlags formattingFlag) c |
| break; |
| case CSS_NUMBER: |
| case CSS_PARSER_INTEGER: |
| - text = formatNumber(m_value.num, ""); |
| - break; |
| case CSS_PERCENTAGE: |
| - text = formatNumber(m_value.num, "%"); |
| - break; |
| case CSS_EMS: |
| - text = formatNumber(m_value.num, "em"); |
| - break; |
| case CSS_EXS: |
| - text = formatNumber(m_value.num, "ex"); |
| - break; |
| case CSS_REMS: |
| - text = formatNumber(m_value.num, "rem"); |
| - break; |
| case CSS_CHS: |
| - text = formatNumber(m_value.num, "ch"); |
| - break; |
| case CSS_PX: |
| - text = formatNumber(m_value.num, "px"); |
| - break; |
| case CSS_CM: |
| - text = formatNumber(m_value.num, "cm"); |
| - break; |
| case CSS_DPPX: |
| - text = formatNumber(m_value.num, "dppx"); |
| - break; |
| case CSS_DPI: |
| - text = formatNumber(m_value.num, "dpi"); |
| - break; |
| case CSS_DPCM: |
| - text = formatNumber(m_value.num, "dpcm"); |
| - break; |
| case CSS_MM: |
| - text = formatNumber(m_value.num, "mm"); |
| - break; |
| case CSS_IN: |
| - text = formatNumber(m_value.num, "in"); |
| - break; |
| case CSS_PT: |
| - text = formatNumber(m_value.num, "pt"); |
| - break; |
| case CSS_PC: |
| - text = formatNumber(m_value.num, "pc"); |
| - break; |
| case CSS_DEG: |
| - text = formatNumber(m_value.num, "deg"); |
| - break; |
| case CSS_RAD: |
| - text = formatNumber(m_value.num, "rad"); |
| - break; |
| case CSS_GRAD: |
| - text = formatNumber(m_value.num, "grad"); |
| - break; |
| case CSS_MS: |
| - text = formatNumber(m_value.num, "ms"); |
| - break; |
| case CSS_S: |
| - text = formatNumber(m_value.num, "s"); |
| - break; |
| case CSS_HZ: |
| - text = formatNumber(m_value.num, "hz"); |
| - break; |
| case CSS_KHZ: |
| - text = formatNumber(m_value.num, "khz"); |
| - break; |
| case CSS_TURN: |
| - text = formatNumber(m_value.num, "turn"); |
| - break; |
| + text = formatNumber(m_value.num, unitTypeToString((UnitTypes)m_primitiveUnitType)); |
| case CSS_DIMENSION: |
| // FIXME: We currently don't handle CSS_DIMENSION properly as we don't store |
| // the actual dimension, just the numeric value as a string. |