Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 case CSSPrimitiveValue::CSS_UNICODE_RANGE: | 105 case CSSPrimitiveValue::CSS_UNICODE_RANGE: |
| 106 case CSSPrimitiveValue::CSS_UNKNOWN: | 106 case CSSPrimitiveValue::CSS_UNKNOWN: |
| 107 case CSSPrimitiveValue::CSS_URI: | 107 case CSSPrimitiveValue::CSS_URI: |
| 108 return false; | 108 return false; |
| 109 } | 109 } |
| 110 | 110 |
| 111 ASSERT_NOT_REACHED(); | 111 ASSERT_NOT_REACHED(); |
| 112 return false; | 112 return false; |
| 113 } | 113 } |
| 114 | 114 |
| 115 CSSPrimitiveValue::UnitTable createUnitTable() | 115 typedef HashMap<String, CSSPrimitiveValue::UnitTypes> StringToUnitTable; |
| 116 | |
| 117 StringToUnitTable createStringToUnitTable() | |
| 116 { | 118 { |
| 117 CSSPrimitiveValue::UnitTable table; | 119 StringToUnitTable table; |
| 118 table.set(String("em"), CSSPrimitiveValue::CSS_EMS); | 120 table.set(String("em"), CSSPrimitiveValue::CSS_EMS); |
| 119 table.set(String("ex"), CSSPrimitiveValue::CSS_EXS); | 121 table.set(String("ex"), CSSPrimitiveValue::CSS_EXS); |
| 120 table.set(String("px"), CSSPrimitiveValue::CSS_PX); | 122 table.set(String("px"), CSSPrimitiveValue::CSS_PX); |
| 121 table.set(String("cm"), CSSPrimitiveValue::CSS_CM); | 123 table.set(String("cm"), CSSPrimitiveValue::CSS_CM); |
| 122 table.set(String("mm"), CSSPrimitiveValue::CSS_MM); | 124 table.set(String("mm"), CSSPrimitiveValue::CSS_MM); |
| 123 table.set(String("in"), CSSPrimitiveValue::CSS_IN); | 125 table.set(String("in"), CSSPrimitiveValue::CSS_IN); |
| 124 table.set(String("pt"), CSSPrimitiveValue::CSS_PT); | 126 table.set(String("pt"), CSSPrimitiveValue::CSS_PT); |
| 125 table.set(String("pc"), CSSPrimitiveValue::CSS_PC); | 127 table.set(String("pc"), CSSPrimitiveValue::CSS_PC); |
| 126 table.set(String("deg"), CSSPrimitiveValue::CSS_DEG); | 128 table.set(String("deg"), CSSPrimitiveValue::CSS_DEG); |
| 127 table.set(String("rad"), CSSPrimitiveValue::CSS_RAD); | 129 table.set(String("rad"), CSSPrimitiveValue::CSS_RAD); |
| 128 table.set(String("grad"), CSSPrimitiveValue::CSS_GRAD); | 130 table.set(String("grad"), CSSPrimitiveValue::CSS_GRAD); |
| 129 table.set(String("ms"), CSSPrimitiveValue::CSS_MS); | 131 table.set(String("ms"), CSSPrimitiveValue::CSS_MS); |
| 130 table.set(String("s"), CSSPrimitiveValue::CSS_S); | 132 table.set(String("s"), CSSPrimitiveValue::CSS_S); |
| 131 table.set(String("hz"), CSSPrimitiveValue::CSS_HZ); | 133 table.set(String("hz"), CSSPrimitiveValue::CSS_HZ); |
| 132 table.set(String("khz"), CSSPrimitiveValue::CSS_KHZ); | 134 table.set(String("khz"), CSSPrimitiveValue::CSS_KHZ); |
| 133 table.set(String("dpi"), CSSPrimitiveValue::CSS_DPI); | 135 table.set(String("dpi"), CSSPrimitiveValue::CSS_DPI); |
| 134 table.set(String("dpcm"), CSSPrimitiveValue::CSS_DPCM); | 136 table.set(String("dpcm"), CSSPrimitiveValue::CSS_DPCM); |
| 135 table.set(String("dppx"), CSSPrimitiveValue::CSS_DPPX); | 137 table.set(String("dppx"), CSSPrimitiveValue::CSS_DPPX); |
| 136 table.set(String("vw"), CSSPrimitiveValue::CSS_VW); | 138 table.set(String("vw"), CSSPrimitiveValue::CSS_VW); |
| 137 table.set(String("vh"), CSSPrimitiveValue::CSS_VH); | 139 table.set(String("vh"), CSSPrimitiveValue::CSS_VH); |
| 138 table.set(String("vmax"), CSSPrimitiveValue::CSS_VMIN); | 140 table.set(String("vmax"), CSSPrimitiveValue::CSS_VMIN); |
| 139 table.set(String("vmin"), CSSPrimitiveValue::CSS_VMAX); | 141 table.set(String("vmin"), CSSPrimitiveValue::CSS_VMAX); |
| 140 return table; | 142 return table; |
| 141 } | 143 } |
| 142 | 144 |
| 145 | |
| 143 CSSPrimitiveValue::UnitTypes CSSPrimitiveValue::fromName(const String& unit) | 146 CSSPrimitiveValue::UnitTypes CSSPrimitiveValue::fromName(const String& unit) |
| 144 { | 147 { |
| 145 DEFINE_STATIC_LOCAL(UnitTable, unitTable, (createUnitTable())); | 148 DEFINE_STATIC_LOCAL(StringToUnitTable, unitTable, (createStringToUnitTable() )); |
| 146 return unitTable.get(unit.lower()); | 149 return unitTable.get(unit.lower()); |
| 147 } | 150 } |
| 148 | 151 |
| 149 CSSPrimitiveValue::UnitCategory CSSPrimitiveValue::unitCategory(CSSPrimitiveValu e::UnitTypes type) | 152 CSSPrimitiveValue::UnitCategory CSSPrimitiveValue::unitCategory(CSSPrimitiveValu e::UnitTypes type) |
| 150 { | 153 { |
| 151 // Here we violate the spec (http://www.w3.org/TR/DOM-Level-2-Style/css.html #CSS-CSSPrimitiveValue) and allow conversions | 154 // Here we violate the spec (http://www.w3.org/TR/DOM-Level-2-Style/css.html #CSS-CSSPrimitiveValue) and allow conversions |
| 152 // between CSS_PX and relative lengths (see cssPixelsPerInch comment in core /css/CSSHelper.h for the topic treatment). | 155 // between CSS_PX and relative lengths (see cssPixelsPerInch comment in core /css/CSSHelper.h for the topic treatment). |
| 153 switch (type) { | 156 switch (type) { |
| 154 case CSS_NUMBER: | 157 case CSS_NUMBER: |
| 155 return CSSPrimitiveValue::UNumber; | 158 return CSSPrimitiveValue::UNumber; |
| (...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1049 | 1052 |
| 1050 return String::adopt(buffer); | 1053 return String::adopt(buffer); |
| 1051 } | 1054 } |
| 1052 | 1055 |
| 1053 template <unsigned characterCount> | 1056 template <unsigned characterCount> |
| 1054 ALWAYS_INLINE static String formatNumber(double number, const char (&characters) [characterCount]) | 1057 ALWAYS_INLINE static String formatNumber(double number, const char (&characters) [characterCount]) |
| 1055 { | 1058 { |
| 1056 return formatNumber(number, characters, characterCount - 1); | 1059 return formatNumber(number, characters, characterCount - 1); |
| 1057 } | 1060 } |
| 1058 | 1061 |
| 1062 static String formatNumber(double number, const String & str) | |
| 1063 { | |
| 1064 return formatNumber(number, str.ascii().data(), str.length()); | |
| 1065 } | |
| 1066 | |
| 1067 String CSSPrimitiveValue::unitTypeToString(UnitTypes type) | |
| 1068 { | |
| 1069 switch (type) { | |
| 1070 case CSS_NUMBER: | |
| 1071 case CSS_PARSER_INTEGER: | |
| 1072 return String(""); | |
| 1073 case CSS_PERCENTAGE: | |
| 1074 return String("%"); | |
| 1075 case CSS_EMS: | |
| 1076 return String("em"); | |
| 1077 case CSS_EXS: | |
| 1078 return String("ex"); | |
| 1079 case CSS_REMS: | |
| 1080 return String("rem"); | |
| 1081 case CSS_CHS: | |
| 1082 return String("ch"); | |
| 1083 case CSS_PX: | |
| 1084 return String("px"); | |
| 1085 case CSS_CM: | |
| 1086 return String("cm"); | |
| 1087 case CSS_DPPX: | |
| 1088 return String("dppx"); | |
| 1089 case CSS_DPI: | |
| 1090 return String("dpi"); | |
| 1091 case CSS_DPCM: | |
| 1092 return String("dpcm"); | |
| 1093 case CSS_MM: | |
| 1094 return String("mm"); | |
| 1095 case CSS_IN: | |
| 1096 return String("in"); | |
| 1097 case CSS_PT: | |
| 1098 return String("pt"); | |
| 1099 case CSS_PC: | |
| 1100 return String("pc"); | |
| 1101 case CSS_DEG: | |
| 1102 return String("deg"); | |
| 1103 case CSS_RAD: | |
| 1104 return String("rad"); | |
| 1105 case CSS_GRAD: | |
| 1106 return String("grad"); | |
| 1107 case CSS_MS: | |
| 1108 return String("ms"); | |
| 1109 case CSS_S: | |
| 1110 return String("s"); | |
| 1111 case CSS_HZ: | |
| 1112 return String("hz"); | |
| 1113 case CSS_KHZ: | |
| 1114 return String("khz"); | |
| 1115 case CSS_TURN: | |
| 1116 return String("turn"); | |
| 1117 default: | |
|
eseidel
2014/04/23 16:51:04
Are you sure you want a default? That will defeat
| |
| 1118 break; | |
| 1119 }; | |
| 1120 return String(); | |
| 1121 } | |
| 1122 | |
| 1059 String CSSPrimitiveValue::customCSSText(CSSTextFormattingFlags formattingFlag) c onst | 1123 String CSSPrimitiveValue::customCSSText(CSSTextFormattingFlags formattingFlag) c onst |
| 1060 { | 1124 { |
| 1061 // FIXME: return the original value instead of a generated one (e.g. color | 1125 // FIXME: return the original value instead of a generated one (e.g. color |
| 1062 // name if it was specified) - check what spec says about this | 1126 // name if it was specified) - check what spec says about this |
| 1063 | 1127 |
| 1064 if (m_hasCachedCSSText) { | 1128 if (m_hasCachedCSSText) { |
| 1065 ASSERT(cssTextCache().contains(this)); | 1129 ASSERT(cssTextCache().contains(this)); |
| 1066 return cssTextCache().get(this); | 1130 return cssTextCache().get(this); |
| 1067 } | 1131 } |
| 1068 | 1132 |
| 1069 String text; | 1133 String text; |
| 1070 switch (m_primitiveUnitType) { | 1134 switch (m_primitiveUnitType) { |
| 1071 case CSS_UNKNOWN: | 1135 case CSS_UNKNOWN: |
| 1072 // FIXME | 1136 // FIXME |
| 1073 break; | 1137 break; |
| 1074 case CSS_NUMBER: | 1138 case CSS_NUMBER: |
| 1075 case CSS_PARSER_INTEGER: | 1139 case CSS_PARSER_INTEGER: |
| 1076 text = formatNumber(m_value.num, ""); | |
| 1077 break; | |
| 1078 case CSS_PERCENTAGE: | 1140 case CSS_PERCENTAGE: |
| 1079 text = formatNumber(m_value.num, "%"); | |
| 1080 break; | |
| 1081 case CSS_EMS: | 1141 case CSS_EMS: |
| 1082 text = formatNumber(m_value.num, "em"); | |
| 1083 break; | |
| 1084 case CSS_EXS: | 1142 case CSS_EXS: |
| 1085 text = formatNumber(m_value.num, "ex"); | |
| 1086 break; | |
| 1087 case CSS_REMS: | 1143 case CSS_REMS: |
| 1088 text = formatNumber(m_value.num, "rem"); | |
| 1089 break; | |
| 1090 case CSS_CHS: | 1144 case CSS_CHS: |
| 1091 text = formatNumber(m_value.num, "ch"); | |
| 1092 break; | |
| 1093 case CSS_PX: | 1145 case CSS_PX: |
| 1094 text = formatNumber(m_value.num, "px"); | |
| 1095 break; | |
| 1096 case CSS_CM: | 1146 case CSS_CM: |
| 1097 text = formatNumber(m_value.num, "cm"); | |
| 1098 break; | |
| 1099 case CSS_DPPX: | 1147 case CSS_DPPX: |
| 1100 text = formatNumber(m_value.num, "dppx"); | |
| 1101 break; | |
| 1102 case CSS_DPI: | 1148 case CSS_DPI: |
| 1103 text = formatNumber(m_value.num, "dpi"); | |
| 1104 break; | |
| 1105 case CSS_DPCM: | 1149 case CSS_DPCM: |
| 1106 text = formatNumber(m_value.num, "dpcm"); | |
| 1107 break; | |
| 1108 case CSS_MM: | 1150 case CSS_MM: |
| 1109 text = formatNumber(m_value.num, "mm"); | |
| 1110 break; | |
| 1111 case CSS_IN: | 1151 case CSS_IN: |
| 1112 text = formatNumber(m_value.num, "in"); | |
| 1113 break; | |
| 1114 case CSS_PT: | 1152 case CSS_PT: |
| 1115 text = formatNumber(m_value.num, "pt"); | |
| 1116 break; | |
| 1117 case CSS_PC: | 1153 case CSS_PC: |
| 1118 text = formatNumber(m_value.num, "pc"); | |
| 1119 break; | |
| 1120 case CSS_DEG: | 1154 case CSS_DEG: |
| 1121 text = formatNumber(m_value.num, "deg"); | |
| 1122 break; | |
| 1123 case CSS_RAD: | 1155 case CSS_RAD: |
| 1124 text = formatNumber(m_value.num, "rad"); | |
| 1125 break; | |
| 1126 case CSS_GRAD: | 1156 case CSS_GRAD: |
| 1127 text = formatNumber(m_value.num, "grad"); | |
| 1128 break; | |
| 1129 case CSS_MS: | 1157 case CSS_MS: |
| 1130 text = formatNumber(m_value.num, "ms"); | |
| 1131 break; | |
| 1132 case CSS_S: | 1158 case CSS_S: |
| 1133 text = formatNumber(m_value.num, "s"); | |
| 1134 break; | |
| 1135 case CSS_HZ: | 1159 case CSS_HZ: |
| 1136 text = formatNumber(m_value.num, "hz"); | |
| 1137 break; | |
| 1138 case CSS_KHZ: | 1160 case CSS_KHZ: |
| 1139 text = formatNumber(m_value.num, "khz"); | |
| 1140 break; | |
| 1141 case CSS_TURN: | 1161 case CSS_TURN: |
| 1142 text = formatNumber(m_value.num, "turn"); | 1162 text = formatNumber(m_value.num, unitTypeToString((UnitTypes)m_primi tiveUnitType)); |
| 1143 break; | |
| 1144 case CSS_DIMENSION: | 1163 case CSS_DIMENSION: |
| 1145 // FIXME: We currently don't handle CSS_DIMENSION properly as we don 't store | 1164 // FIXME: We currently don't handle CSS_DIMENSION properly as we don 't store |
| 1146 // the actual dimension, just the numeric value as a string. | 1165 // the actual dimension, just the numeric value as a string. |
| 1147 break; | 1166 break; |
| 1148 case CSS_STRING: | 1167 case CSS_STRING: |
| 1149 text = formattingFlag == AlwaysQuoteCSSString ? quoteCSSString(m_val ue.string) : quoteCSSStringIfNeeded(m_value.string); | 1168 text = formattingFlag == AlwaysQuoteCSSString ? quoteCSSString(m_val ue.string) : quoteCSSStringIfNeeded(m_value.string); |
| 1150 break; | 1169 break; |
| 1151 case CSS_URI: | 1170 case CSS_URI: |
| 1152 text = "url(" + quoteCSSURLIfNeeded(m_value.string) + ")"; | 1171 text = "url(" + quoteCSSURLIfNeeded(m_value.string) + ")"; |
| 1153 break; | 1172 break; |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1424 case CSS_SHAPE: | 1443 case CSS_SHAPE: |
| 1425 visitor->trace(m_value.shape); | 1444 visitor->trace(m_value.shape); |
| 1426 break; | 1445 break; |
| 1427 default: | 1446 default: |
| 1428 break; | 1447 break; |
| 1429 } | 1448 } |
| 1430 CSSValue::traceAfterDispatch(visitor); | 1449 CSSValue::traceAfterDispatch(visitor); |
| 1431 } | 1450 } |
| 1432 | 1451 |
| 1433 } // namespace WebCore | 1452 } // namespace WebCore |
| OLD | NEW |