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 973623002: Fix serialization of content property to always quote (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add another method Created 5 years, 9 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
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 case CSSPrimitiveValue::CSS_COUNTER: 91 case CSSPrimitiveValue::CSS_COUNTER:
92 case CSSPrimitiveValue::CSS_COUNTER_NAME: 92 case CSSPrimitiveValue::CSS_COUNTER_NAME:
93 case CSSPrimitiveValue::CSS_IDENT: 93 case CSSPrimitiveValue::CSS_IDENT:
94 case CSSPrimitiveValue::CSS_PROPERTY_ID: 94 case CSSPrimitiveValue::CSS_PROPERTY_ID:
95 case CSSPrimitiveValue::CSS_VALUE_ID: 95 case CSSPrimitiveValue::CSS_VALUE_ID:
96 case CSSPrimitiveValue::CSS_PAIR: 96 case CSSPrimitiveValue::CSS_PAIR:
97 case CSSPrimitiveValue::CSS_RECT: 97 case CSSPrimitiveValue::CSS_RECT:
98 case CSSPrimitiveValue::CSS_QUAD: 98 case CSSPrimitiveValue::CSS_QUAD:
99 case CSSPrimitiveValue::CSS_RGBCOLOR: 99 case CSSPrimitiveValue::CSS_RGBCOLOR:
100 case CSSPrimitiveValue::CSS_SHAPE: 100 case CSSPrimitiveValue::CSS_SHAPE:
101 case CSSPrimitiveValue::CSS_CUSTOM_IDENT:
101 case CSSPrimitiveValue::CSS_STRING: 102 case CSSPrimitiveValue::CSS_STRING:
102 case CSSPrimitiveValue::CSS_UNICODE_RANGE: 103 case CSSPrimitiveValue::CSS_UNICODE_RANGE:
103 case CSSPrimitiveValue::CSS_UNKNOWN: 104 case CSSPrimitiveValue::CSS_UNKNOWN:
104 case CSSPrimitiveValue::CSS_URI: 105 case CSSPrimitiveValue::CSS_URI:
105 return false; 106 return false;
106 } 107 }
107 108
108 ASSERT_NOT_REACHED(); 109 ASSERT_NOT_REACHED();
109 return false; 110 return false;
110 } 111 }
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 } 445 }
445 446
446 CSSPrimitiveValue::~CSSPrimitiveValue() 447 CSSPrimitiveValue::~CSSPrimitiveValue()
447 { 448 {
448 cleanup(); 449 cleanup();
449 } 450 }
450 451
451 void CSSPrimitiveValue::cleanup() 452 void CSSPrimitiveValue::cleanup()
452 { 453 {
453 switch (static_cast<UnitType>(m_primitiveUnitType)) { 454 switch (static_cast<UnitType>(m_primitiveUnitType)) {
455 case CSS_CUSTOM_IDENT:
454 case CSS_STRING: 456 case CSS_STRING:
455 case CSS_URI: 457 case CSS_URI:
456 case CSS_ATTR: 458 case CSS_ATTR:
457 case CSS_COUNTER_NAME: 459 case CSS_COUNTER_NAME:
458 if (m_value.string) 460 if (m_value.string)
459 m_value.string->deref(); 461 m_value.string->deref();
460 break; 462 break;
461 case CSS_COUNTER: 463 case CSS_COUNTER:
462 // We must not call deref() when oilpan is enabled because m_value.count er is traced. 464 // We must not call deref() when oilpan is enabled because m_value.count er is traced.
463 #if !ENABLE(OILPAN) 465 #if !ENABLE(OILPAN)
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 case LengthUnitTypeCount: 923 case LengthUnitTypeCount:
922 break; 924 break;
923 } 925 }
924 ASSERT_NOT_REACHED(); 926 ASSERT_NOT_REACHED();
925 return CSSPrimitiveValue::CSS_UNKNOWN; 927 return CSSPrimitiveValue::CSS_UNKNOWN;
926 } 928 }
927 929
928 String CSSPrimitiveValue::getStringValue() const 930 String CSSPrimitiveValue::getStringValue() const
929 { 931 {
930 switch (m_primitiveUnitType) { 932 switch (m_primitiveUnitType) {
931 case CSS_STRING: 933 case CSS_CUSTOM_IDENT:
932 case CSS_ATTR: 934 case CSS_STRING:
933 case CSS_URI: 935 case CSS_ATTR:
934 return m_value.string; 936 case CSS_URI:
935 case CSS_VALUE_ID: 937 return m_value.string;
936 return valueName(m_value.valueID); 938 case CSS_VALUE_ID:
937 case CSS_PROPERTY_ID: 939 return valueName(m_value.valueID);
938 return propertyName(m_value.propertyID); 940 case CSS_PROPERTY_ID:
939 default: 941 return propertyName(m_value.propertyID);
940 break; 942 default:
943 break;
941 } 944 }
942 945
943 return String(); 946 return String();
944 } 947 }
945 948
946 static String formatNumber(double number, const char* suffix, unsigned suffixLen gth) 949 static String formatNumber(double number, const char* suffix, unsigned suffixLen gth)
947 { 950 {
948 Decimal decimal = Decimal::fromDouble(number); 951 Decimal decimal = Decimal::fromDouble(number);
949 String result = decimal.toString(); 952 String result = decimal.toString();
950 result.append(suffix, suffixLength); 953 result.append(suffix, suffixLength);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 return "fr"; 1018 return "fr";
1016 case CSS_VW: 1019 case CSS_VW:
1017 return "vw"; 1020 return "vw";
1018 case CSS_VH: 1021 case CSS_VH:
1019 return "vh"; 1022 return "vh";
1020 case CSS_VMIN: 1023 case CSS_VMIN:
1021 return "vmin"; 1024 return "vmin";
1022 case CSS_VMAX: 1025 case CSS_VMAX:
1023 return "vmax"; 1026 return "vmax";
1024 case CSS_UNKNOWN: 1027 case CSS_UNKNOWN:
1028 case CSS_CUSTOM_IDENT:
1025 case CSS_STRING: 1029 case CSS_STRING:
1026 case CSS_URI: 1030 case CSS_URI:
1027 case CSS_VALUE_ID: 1031 case CSS_VALUE_ID:
1028 case CSS_PROPERTY_ID: 1032 case CSS_PROPERTY_ID:
1029 case CSS_ATTR: 1033 case CSS_ATTR:
1030 case CSS_COUNTER_NAME: 1034 case CSS_COUNTER_NAME:
1031 case CSS_COUNTER: 1035 case CSS_COUNTER:
1032 case CSS_RECT: 1036 case CSS_RECT:
1033 case CSS_QUAD: 1037 case CSS_QUAD:
1034 case CSS_RGBCOLOR: 1038 case CSS_RGBCOLOR:
1035 case CSS_PAIR: 1039 case CSS_PAIR:
1036 case CSS_CALC: 1040 case CSS_CALC:
1037 case CSS_SHAPE: 1041 case CSS_SHAPE:
1038 case CSS_IDENT: 1042 case CSS_IDENT:
1039 case CSS_UNICODE_RANGE: 1043 case CSS_UNICODE_RANGE:
1040 case CSS_CALC_PERCENTAGE_WITH_NUMBER: 1044 case CSS_CALC_PERCENTAGE_WITH_NUMBER:
1041 case CSS_CALC_PERCENTAGE_WITH_LENGTH: 1045 case CSS_CALC_PERCENTAGE_WITH_LENGTH:
1042 break; 1046 break;
1043 }; 1047 };
1044 ASSERT_NOT_REACHED(); 1048 ASSERT_NOT_REACHED();
1045 return ""; 1049 return "";
1046 } 1050 }
1047 1051
1048 String CSSPrimitiveValue::customCSSText(CSSTextFormattingFlags formattingFlag) c onst 1052 String CSSPrimitiveValue::customCSSText() const
1049 { 1053 {
1050 if (m_hasCachedCSSText) { 1054 if (m_hasCachedCSSText) {
1051 ASSERT(cssTextCache().contains(this)); 1055 ASSERT(cssTextCache().contains(this));
1052 return cssTextCache().get(this); 1056 return cssTextCache().get(this);
1053 } 1057 }
1054 1058
1055 String text; 1059 String text;
1056 switch (m_primitiveUnitType) { 1060 switch (m_primitiveUnitType) {
1057 case CSS_UNKNOWN: 1061 case CSS_UNKNOWN:
1058 // FIXME 1062 // FIXME
(...skipping 21 matching lines...) Expand all
1080 case CSS_HZ: 1084 case CSS_HZ:
1081 case CSS_KHZ: 1085 case CSS_KHZ:
1082 case CSS_TURN: 1086 case CSS_TURN:
1083 case CSS_FR: 1087 case CSS_FR:
1084 case CSS_VW: 1088 case CSS_VW:
1085 case CSS_VH: 1089 case CSS_VH:
1086 case CSS_VMIN: 1090 case CSS_VMIN:
1087 case CSS_VMAX: 1091 case CSS_VMAX:
1088 text = formatNumber(m_value.num, unitTypeToString((UnitType)m_primit iveUnitType)); 1092 text = formatNumber(m_value.num, unitTypeToString((UnitType)m_primit iveUnitType));
1089 break; 1093 break;
1094 case CSS_CUSTOM_IDENT:
1095 text = quoteCSSStringIfNeeded(m_value.string);
1096 break;
1090 case CSS_STRING: 1097 case CSS_STRING:
1091 text = formattingFlag == AlwaysQuoteCSSString ? quoteCSSString(m_val ue.string) : quoteCSSStringIfNeeded(m_value.string); 1098 text = quoteCSSString(m_value.string);
1092 break; 1099 break;
1093 case CSS_URI: 1100 case CSS_URI:
1094 text = "url(" + quoteCSSURLIfNeeded(m_value.string) + ")"; 1101 text = "url(" + quoteCSSURLIfNeeded(m_value.string) + ")";
1095 break; 1102 break;
1096 case CSS_VALUE_ID: 1103 case CSS_VALUE_ID:
1097 text = valueName(m_value.valueID); 1104 text = valueName(m_value.valueID);
1098 break; 1105 break;
1099 case CSS_PROPERTY_ID: 1106 case CSS_PROPERTY_ID:
1100 text = propertyName(m_value.propertyID); 1107 text = propertyName(m_value.propertyID);
1101 break; 1108 break;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 case CSS_VW: 1202 case CSS_VW:
1196 case CSS_VH: 1203 case CSS_VH:
1197 case CSS_VMIN: 1204 case CSS_VMIN:
1198 case CSS_VMAX: 1205 case CSS_VMAX:
1199 case CSS_FR: 1206 case CSS_FR:
1200 return m_value.num == other.m_value.num; 1207 return m_value.num == other.m_value.num;
1201 case CSS_PROPERTY_ID: 1208 case CSS_PROPERTY_ID:
1202 return propertyName(m_value.propertyID) == propertyName(other.m_value.pr opertyID); 1209 return propertyName(m_value.propertyID) == propertyName(other.m_value.pr opertyID);
1203 case CSS_VALUE_ID: 1210 case CSS_VALUE_ID:
1204 return valueName(m_value.valueID) == valueName(other.m_value.valueID); 1211 return valueName(m_value.valueID) == valueName(other.m_value.valueID);
1212 case CSS_CUSTOM_IDENT:
1205 case CSS_STRING: 1213 case CSS_STRING:
1206 case CSS_URI: 1214 case CSS_URI:
1207 case CSS_ATTR: 1215 case CSS_ATTR:
1208 case CSS_COUNTER_NAME: 1216 case CSS_COUNTER_NAME:
1209 return equal(m_value.string, other.m_value.string); 1217 return equal(m_value.string, other.m_value.string);
1210 case CSS_COUNTER: 1218 case CSS_COUNTER:
1211 return m_value.counter && other.m_value.counter && m_value.counter->equa ls(*other.m_value.counter); 1219 return m_value.counter && other.m_value.counter && m_value.counter->equa ls(*other.m_value.counter);
1212 case CSS_RECT: 1220 case CSS_RECT:
1213 return m_value.rect && other.m_value.rect && m_value.rect->equals(*other .m_value.rect); 1221 return m_value.rect && other.m_value.rect && m_value.rect->equals(*other .m_value.rect);
1214 case CSS_QUAD: 1222 case CSS_QUAD:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 visitor->trace(m_value.shape); 1256 visitor->trace(m_value.shape);
1249 break; 1257 break;
1250 default: 1258 default:
1251 break; 1259 break;
1252 } 1260 }
1253 #endif 1261 #endif
1254 CSSValue::traceAfterDispatch(visitor); 1262 CSSValue::traceAfterDispatch(visitor);
1255 } 1263 }
1256 1264
1257 } // namespace blink 1265 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698