Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(620)

Side by Side Diff: Source/core/css/CSSPrimitiveValue.cpp

Issue 240453010: Avoid use of CSSValue in MediaQueryExp and MediaQueryEvaluator (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix previous patch Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/css/CSSPrimitiveValue.h ('k') | Source/core/css/MediaList.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 char* characters)
1063 {
1064 return formatNumber(number, characters, strlen(characters));
1065 }
1066
1067 const char* CSSPrimitiveValue::unitTypeToString(UnitTypes type)
1068 {
1069 switch (type) {
1070 case CSS_NUMBER:
1071 case CSS_PARSER_INTEGER:
1072 return "";
1073 case CSS_PERCENTAGE:
1074 return "%";
1075 case CSS_EMS:
1076 return "em";
1077 case CSS_EXS:
1078 return "ex";
1079 case CSS_REMS:
1080 return "rem";
1081 case CSS_CHS:
1082 return "ch";
1083 case CSS_PX:
1084 return "px";
1085 case CSS_CM:
1086 return "cm";
1087 case CSS_DPPX:
1088 return "dppx";
1089 case CSS_DPI:
1090 return "dpi";
1091 case CSS_DPCM:
1092 return "dpcm";
1093 case CSS_MM:
1094 return "mm";
1095 case CSS_IN:
1096 return "in";
1097 case CSS_PT:
1098 return "pt";
1099 case CSS_PC:
1100 return "pc";
1101 case CSS_DEG:
1102 return "deg";
1103 case CSS_RAD:
1104 return "rad";
1105 case CSS_GRAD:
1106 return "grad";
1107 case CSS_MS:
1108 return "ms";
1109 case CSS_S:
1110 return "s";
1111 case CSS_HZ:
1112 return "hz";
1113 case CSS_KHZ:
1114 return "khz";
1115 case CSS_TURN:
1116 return "turn";
1117 case CSS_FR:
1118 return "fr";
1119 case CSS_VW:
1120 return "vw";
1121 case CSS_VH:
1122 return "vh";
1123 case CSS_VMIN:
1124 return "vmin";
1125 case CSS_VMAX:
1126 return "vmax";
1127 case CSS_UNKNOWN:
1128 case CSS_DIMENSION:
1129 case CSS_STRING:
1130 case CSS_URI:
1131 case CSS_VALUE_ID:
1132 case CSS_PROPERTY_ID:
1133 case CSS_ATTR:
1134 case CSS_COUNTER_NAME:
1135 case CSS_COUNTER:
1136 case CSS_RECT:
1137 case CSS_QUAD:
1138 case CSS_RGBCOLOR:
1139 case CSS_PARSER_HEXCOLOR:
1140 case CSS_PAIR:
1141 case CSS_PARSER_OPERATOR:
1142 case CSS_PARSER_IDENTIFIER:
1143 case CSS_CALC:
1144 case CSS_SHAPE:
1145 case CSS_IDENT:
1146 case CSS_UNICODE_RANGE:
1147 case CSS_CALC_PERCENTAGE_WITH_NUMBER:
1148 case CSS_CALC_PERCENTAGE_WITH_LENGTH:
1149 break;
1150 };
1151 ASSERT_NOT_REACHED();
1152 return "";
1153 }
1154
1059 String CSSPrimitiveValue::customCSSText(CSSTextFormattingFlags formattingFlag) c onst 1155 String CSSPrimitiveValue::customCSSText(CSSTextFormattingFlags formattingFlag) c onst
1060 { 1156 {
1061 // FIXME: return the original value instead of a generated one (e.g. color 1157 // 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 1158 // name if it was specified) - check what spec says about this
1063 1159
1064 if (m_hasCachedCSSText) { 1160 if (m_hasCachedCSSText) {
1065 ASSERT(cssTextCache().contains(this)); 1161 ASSERT(cssTextCache().contains(this));
1066 return cssTextCache().get(this); 1162 return cssTextCache().get(this);
1067 } 1163 }
1068 1164
1069 String text; 1165 String text;
1070 switch (m_primitiveUnitType) { 1166 switch (m_primitiveUnitType) {
1071 case CSS_UNKNOWN: 1167 case CSS_UNKNOWN:
1072 // FIXME 1168 // FIXME
1073 break; 1169 break;
1074 case CSS_NUMBER: 1170 case CSS_NUMBER:
1075 case CSS_PARSER_INTEGER: 1171 case CSS_PARSER_INTEGER:
1076 text = formatNumber(m_value.num, "");
1077 break;
1078 case CSS_PERCENTAGE: 1172 case CSS_PERCENTAGE:
1079 text = formatNumber(m_value.num, "%");
1080 break;
1081 case CSS_EMS: 1173 case CSS_EMS:
1082 text = formatNumber(m_value.num, "em");
1083 break;
1084 case CSS_EXS: 1174 case CSS_EXS:
1085 text = formatNumber(m_value.num, "ex");
1086 break;
1087 case CSS_REMS: 1175 case CSS_REMS:
1088 text = formatNumber(m_value.num, "rem");
1089 break;
1090 case CSS_CHS: 1176 case CSS_CHS:
1091 text = formatNumber(m_value.num, "ch");
1092 break;
1093 case CSS_PX: 1177 case CSS_PX:
1094 text = formatNumber(m_value.num, "px");
1095 break;
1096 case CSS_CM: 1178 case CSS_CM:
1097 text = formatNumber(m_value.num, "cm");
1098 break;
1099 case CSS_DPPX: 1179 case CSS_DPPX:
1100 text = formatNumber(m_value.num, "dppx");
1101 break;
1102 case CSS_DPI: 1180 case CSS_DPI:
1103 text = formatNumber(m_value.num, "dpi");
1104 break;
1105 case CSS_DPCM: 1181 case CSS_DPCM:
1106 text = formatNumber(m_value.num, "dpcm");
1107 break;
1108 case CSS_MM: 1182 case CSS_MM:
1109 text = formatNumber(m_value.num, "mm");
1110 break;
1111 case CSS_IN: 1183 case CSS_IN:
1112 text = formatNumber(m_value.num, "in");
1113 break;
1114 case CSS_PT: 1184 case CSS_PT:
1115 text = formatNumber(m_value.num, "pt");
1116 break;
1117 case CSS_PC: 1185 case CSS_PC:
1118 text = formatNumber(m_value.num, "pc");
1119 break;
1120 case CSS_DEG: 1186 case CSS_DEG:
1121 text = formatNumber(m_value.num, "deg");
1122 break;
1123 case CSS_RAD: 1187 case CSS_RAD:
1124 text = formatNumber(m_value.num, "rad");
1125 break;
1126 case CSS_GRAD: 1188 case CSS_GRAD:
1127 text = formatNumber(m_value.num, "grad");
1128 break;
1129 case CSS_MS: 1189 case CSS_MS:
1130 text = formatNumber(m_value.num, "ms");
1131 break;
1132 case CSS_S: 1190 case CSS_S:
1133 text = formatNumber(m_value.num, "s");
1134 break;
1135 case CSS_HZ: 1191 case CSS_HZ:
1136 text = formatNumber(m_value.num, "hz");
1137 break;
1138 case CSS_KHZ: 1192 case CSS_KHZ:
1139 text = formatNumber(m_value.num, "khz");
1140 break;
1141 case CSS_TURN: 1193 case CSS_TURN:
1142 text = formatNumber(m_value.num, "turn"); 1194 case CSS_FR:
1143 break; 1195 case CSS_VW:
1196 case CSS_VH:
1197 case CSS_VMIN:
1198 case CSS_VMAX:
1199 text = formatNumber(m_value.num, unitTypeToString((UnitTypes)m_primi tiveUnitType));
1144 case CSS_DIMENSION: 1200 case CSS_DIMENSION:
1145 // FIXME: We currently don't handle CSS_DIMENSION properly as we don 't store 1201 // 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. 1202 // the actual dimension, just the numeric value as a string.
1147 break; 1203 break;
1148 case CSS_STRING: 1204 case CSS_STRING:
1149 text = formattingFlag == AlwaysQuoteCSSString ? quoteCSSString(m_val ue.string) : quoteCSSStringIfNeeded(m_value.string); 1205 text = formattingFlag == AlwaysQuoteCSSString ? quoteCSSString(m_val ue.string) : quoteCSSStringIfNeeded(m_value.string);
1150 break; 1206 break;
1151 case CSS_URI: 1207 case CSS_URI:
1152 text = "url(" + quoteCSSURLIfNeeded(m_value.string) + ")"; 1208 text = "url(" + quoteCSSURLIfNeeded(m_value.string) + ")";
1153 break; 1209 break;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 break; 1257 break;
1202 case CSS_RGBCOLOR: 1258 case CSS_RGBCOLOR:
1203 case CSS_PARSER_HEXCOLOR: { 1259 case CSS_PARSER_HEXCOLOR: {
1204 RGBA32 rgbColor = m_value.rgbcolor; 1260 RGBA32 rgbColor = m_value.rgbcolor;
1205 if (m_primitiveUnitType == CSS_PARSER_HEXCOLOR) 1261 if (m_primitiveUnitType == CSS_PARSER_HEXCOLOR)
1206 Color::parseHexColor(m_value.string, rgbColor); 1262 Color::parseHexColor(m_value.string, rgbColor);
1207 Color color(rgbColor); 1263 Color color(rgbColor);
1208 text = color.serializedAsCSSComponentValue(); 1264 text = color.serializedAsCSSComponentValue();
1209 break; 1265 break;
1210 } 1266 }
1211 case CSS_FR:
1212 text = formatNumber(m_value.num, "fr");
1213 break;
1214 case CSS_PAIR: 1267 case CSS_PAIR:
1215 text = getPairValue()->cssText(); 1268 text = getPairValue()->cssText();
1216 break; 1269 break;
1217 case CSS_PARSER_OPERATOR: { 1270 case CSS_PARSER_OPERATOR: {
1218 char c = static_cast<char>(m_value.parserOperator); 1271 char c = static_cast<char>(m_value.parserOperator);
1219 text = String(&c, 1U); 1272 text = String(&c, 1U);
1220 break; 1273 break;
1221 } 1274 }
1222 case CSS_PARSER_IDENTIFIER: 1275 case CSS_PARSER_IDENTIFIER:
1223 text = quoteCSSStringIfNeeded(m_value.string); 1276 text = quoteCSSStringIfNeeded(m_value.string);
1224 break; 1277 break;
1225 case CSS_CALC: 1278 case CSS_CALC:
1226 text = m_value.calc->cssText(); 1279 text = m_value.calc->cssText();
1227 break; 1280 break;
1228 case CSS_SHAPE: 1281 case CSS_SHAPE:
1229 text = m_value.shape->cssText(); 1282 text = m_value.shape->cssText();
1230 break; 1283 break;
1231 case CSS_VW:
1232 text = formatNumber(m_value.num, "vw");
1233 break;
1234 case CSS_VH:
1235 text = formatNumber(m_value.num, "vh");
1236 break;
1237 case CSS_VMIN:
1238 text = formatNumber(m_value.num, "vmin");
1239 break;
1240 case CSS_VMAX:
1241 text = formatNumber(m_value.num, "vmax");
1242 break;
1243 } 1284 }
1244 1285
1245 ASSERT(!cssTextCache().contains(this)); 1286 ASSERT(!cssTextCache().contains(this));
1246 cssTextCache().set(this, text); 1287 cssTextCache().set(this, text);
1247 m_hasCachedCSSText = true; 1288 m_hasCachedCSSText = true;
1248 return text; 1289 return text;
1249 } 1290 }
1250 1291
1251 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPrimitiveValue::cloneForCSSOM() con st 1292 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPrimitiveValue::cloneForCSSOM() con st
1252 { 1293 {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 case CSS_SHAPE: 1465 case CSS_SHAPE:
1425 visitor->trace(m_value.shape); 1466 visitor->trace(m_value.shape);
1426 break; 1467 break;
1427 default: 1468 default:
1428 break; 1469 break;
1429 } 1470 }
1430 CSSValue::traceAfterDispatch(visitor); 1471 CSSValue::traceAfterDispatch(visitor);
1431 } 1472 }
1432 1473
1433 } // namespace WebCore 1474 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/CSSPrimitiveValue.h ('k') | Source/core/css/MediaList.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698