| Index: Source/core/css/CSSPrimitiveValue.cpp
|
| diff --git a/Source/core/css/CSSPrimitiveValue.cpp b/Source/core/css/CSSPrimitiveValue.cpp
|
| index 3e8650402d00f0b210d388a06343b4215de8ccc1..ff8dfa72a5c34d5d6359a3c706946a0fa64400cc 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,99 @@ ALWAYS_INLINE static String formatNumber(double number, const char (&characters)
|
| return formatNumber(number, characters, characterCount - 1);
|
| }
|
|
|
| +static String formatNumber(double number, const char* characters)
|
| +{
|
| + return formatNumber(number, characters, strlen(characters));
|
| +}
|
| +
|
| +const char* CSSPrimitiveValue::unitTypeToString(UnitTypes type)
|
| +{
|
| + switch (type) {
|
| + case CSS_NUMBER:
|
| + case CSS_PARSER_INTEGER:
|
| + return "";
|
| + case CSS_PERCENTAGE:
|
| + return "%";
|
| + case CSS_EMS:
|
| + return "em";
|
| + case CSS_EXS:
|
| + return "ex";
|
| + case CSS_REMS:
|
| + return "rem";
|
| + case CSS_CHS:
|
| + return "ch";
|
| + case CSS_PX:
|
| + return "px";
|
| + case CSS_CM:
|
| + return "cm";
|
| + case CSS_DPPX:
|
| + return "dppx";
|
| + case CSS_DPI:
|
| + return "dpi";
|
| + case CSS_DPCM:
|
| + return "dpcm";
|
| + case CSS_MM:
|
| + return "mm";
|
| + case CSS_IN:
|
| + return "in";
|
| + case CSS_PT:
|
| + return "pt";
|
| + case CSS_PC:
|
| + return "pc";
|
| + case CSS_DEG:
|
| + return "deg";
|
| + case CSS_RAD:
|
| + return "rad";
|
| + case CSS_GRAD:
|
| + return "grad";
|
| + case CSS_MS:
|
| + return "ms";
|
| + case CSS_S:
|
| + return "s";
|
| + case CSS_HZ:
|
| + return "hz";
|
| + case CSS_KHZ:
|
| + return "khz";
|
| + case CSS_TURN:
|
| + return "turn";
|
| + case CSS_FR:
|
| + return "fr";
|
| + case CSS_VW:
|
| + return "vw";
|
| + case CSS_VH:
|
| + return "vh";
|
| + case CSS_VMIN:
|
| + return "vmin";
|
| + case CSS_VMAX:
|
| + return "vmax";
|
| + case CSS_UNKNOWN:
|
| + case CSS_DIMENSION:
|
| + case CSS_STRING:
|
| + case CSS_URI:
|
| + case CSS_VALUE_ID:
|
| + case CSS_PROPERTY_ID:
|
| + case CSS_ATTR:
|
| + case CSS_COUNTER_NAME:
|
| + case CSS_COUNTER:
|
| + case CSS_RECT:
|
| + case CSS_QUAD:
|
| + case CSS_RGBCOLOR:
|
| + case CSS_PARSER_HEXCOLOR:
|
| + case CSS_PAIR:
|
| + case CSS_PARSER_OPERATOR:
|
| + case CSS_PARSER_IDENTIFIER:
|
| + case CSS_CALC:
|
| + case CSS_SHAPE:
|
| + case CSS_IDENT:
|
| + case CSS_UNICODE_RANGE:
|
| + case CSS_CALC_PERCENTAGE_WITH_NUMBER:
|
| + case CSS_CALC_PERCENTAGE_WITH_LENGTH:
|
| + break;
|
| + };
|
| + ASSERT_NOT_REACHED();
|
| + return "";
|
| +}
|
| +
|
| String CSSPrimitiveValue::customCSSText(CSSTextFormattingFlags formattingFlag) const
|
| {
|
| // FIXME: return the original value instead of a generated one (e.g. color
|
| @@ -1073,74 +1169,34 @@ 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;
|
| + case CSS_FR:
|
| + case CSS_VW:
|
| + case CSS_VH:
|
| + case CSS_VMIN:
|
| + case CSS_VMAX:
|
| + 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.
|
| @@ -1208,9 +1264,6 @@ String CSSPrimitiveValue::customCSSText(CSSTextFormattingFlags formattingFlag) c
|
| text = color.serializedAsCSSComponentValue();
|
| break;
|
| }
|
| - case CSS_FR:
|
| - text = formatNumber(m_value.num, "fr");
|
| - break;
|
| case CSS_PAIR:
|
| text = getPairValue()->cssText();
|
| break;
|
| @@ -1228,18 +1281,6 @@ String CSSPrimitiveValue::customCSSText(CSSTextFormattingFlags formattingFlag) c
|
| case CSS_SHAPE:
|
| text = m_value.shape->cssText();
|
| break;
|
| - case CSS_VW:
|
| - text = formatNumber(m_value.num, "vw");
|
| - break;
|
| - case CSS_VH:
|
| - text = formatNumber(m_value.num, "vh");
|
| - break;
|
| - case CSS_VMIN:
|
| - text = formatNumber(m_value.num, "vmin");
|
| - break;
|
| - case CSS_VMAX:
|
| - text = formatNumber(m_value.num, "vmax");
|
| - break;
|
| }
|
|
|
| ASSERT(!cssTextCache().contains(this));
|
|
|