Changeset 273627 in webkit for trunk/Source/WebCore/css/CSSStyleDeclaration.cpp
- Timestamp:
- Feb 27, 2021, 11:51:44 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/css/CSSStyleDeclaration.cpp
r273592 r273627 44 44 namespace { 45 45 46 enum class PropertyNamePrefix { 47 None, 48 Epub, 49 Pixel, 50 Pos, 51 WebKit 52 }; 46 enum class PropertyNamePrefix { None, Epub, WebKit }; 53 47 54 48 template<size_t prefixCStringLength> … … 93 87 if (matchesCSSPropertyNamePrefix(propertyName, "epub")) 94 88 return PropertyNamePrefix::Epub; 95 break;96 case 'p':97 if (matchesCSSPropertyNamePrefix(propertyName, "pos"))98 return PropertyNamePrefix::Pos;99 if (matchesCSSPropertyNamePrefix(propertyName, "pixel"))100 return PropertyNamePrefix::Pixel;101 89 break; 102 90 case 'w': … … 132 120 } 133 121 134 struct CSSPropertyInfo { 135 CSSPropertyID propertyID; 136 bool hadPixelOrPosPrefix; 137 }; 138 139 static CSSPropertyInfo parseJavaScriptCSSPropertyName(const AtomString& propertyName) 140 { 141 using CSSPropertyInfoMap = HashMap<String, CSSPropertyInfo>; 142 static NeverDestroyed<CSSPropertyInfoMap> propertyInfoCache; 143 144 CSSPropertyInfo propertyInfo = { CSSPropertyInvalid, false }; 122 static CSSPropertyID parseJavaScriptCSSPropertyName(const AtomString& propertyName) 123 { 124 using CSSPropertyIDMap = HashMap<String, CSSPropertyID>; 125 static NeverDestroyed<CSSPropertyIDMap> propertyIDCache; 145 126 146 127 auto* propertyNameString = propertyName.impl(); 147 128 if (!propertyNameString) 148 return propertyInfo; 129 return CSSPropertyInvalid; 130 149 131 unsigned length = propertyNameString->length(); 150 132 if (!length) 151 return propertyInfo; 152 153 propertyInfo = propertyInfoCache.get().get(propertyNameString); 154 if (propertyInfo.propertyID) 155 return propertyInfo; 156 157 bool hadPixelOrPosPrefix = false; 133 return CSSPropertyInvalid; 134 135 if (auto id = propertyIDCache.get().get(propertyNameString)) 136 return id; 158 137 159 138 constexpr size_t bufferSize = maxCSSPropertyNameLength + 1; … … 163 142 164 143 unsigned i = 0; 165 // Prefixes Pixel and Pos are ignored.166 // Prefixes Apple, KHTML and Webkit are transposed to "-webkit-".167 // The prefix "Epub" becomes "-epub-".168 144 switch (propertyNamePrefix(*propertyNameString)) { 169 145 case PropertyNamePrefix::None: 170 146 if (isASCIIUpper((*propertyNameString)[0])) 171 return propertyInfo; 172 break; 173 case PropertyNamePrefix::Pixel: 174 i += 5; 175 hadPixelOrPosPrefix = true; 176 break; 177 case PropertyNamePrefix::Pos: 178 i += 3; 179 hadPixelOrPosPrefix = true; 147 return CSSPropertyInvalid; 180 148 break; 181 149 case PropertyNamePrefix::Epub: … … 196 164 size_t propertySizeLeft = length - i; 197 165 if (propertySizeLeft > bufferSizeLeft) 198 return propertyInfo;166 return CSSPropertyInvalid; 199 167 200 168 for (; i < length; ++i) { 201 169 UChar c = (*propertyNameString)[i]; 202 170 if (!c || !isASCII(c)) 203 return propertyInfo; // illegal character171 return CSSPropertyInvalid; // illegal character 204 172 if (isASCIIUpper(c)) { 205 173 size_t bufferSizeLeft = stringEnd - bufferPtr; 206 174 size_t propertySizeLeft = length - i + 1; 207 175 if (propertySizeLeft > bufferSizeLeft) 208 return propertyInfo;176 return CSSPropertyInvalid; 209 177 *bufferPtr++ = '-'; 210 178 *bufferPtr++ = toASCIILowerUnchecked(c); … … 221 189 #endif 222 190 223 auto* hashTableEntry = findProperty(name, outputLength); 224 if (auto propertyID = hashTableEntry ? hashTableEntry->id : 0) { 225 auto id = static_cast<CSSPropertyID>(propertyID); 226 propertyInfo.hadPixelOrPosPrefix = hadPixelOrPosPrefix; 227 propertyInfo.propertyID = id; 228 propertyInfoCache.get().add(propertyNameString, propertyInfo); 229 } 230 return propertyInfo; 231 } 232 233 static CSSPropertyInfo propertyInfoFromJavaScriptCSSPropertyName(const AtomString& propertyName, const Settings* settings) 234 { 235 auto propertyInfo = parseJavaScriptCSSPropertyName(propertyName); 236 auto id = propertyInfo.propertyID; 191 auto hashTableEntry = findProperty(name, outputLength); 192 if (!hashTableEntry) 193 return CSSPropertyInvalid; 194 195 auto id = static_cast<CSSPropertyID>(hashTableEntry->id); 196 if (!id) 197 return CSSPropertyInvalid; 198 199 propertyIDCache.get().add(propertyNameString, id); 200 return id; 201 } 202 203 static CSSPropertyID propertyIDFromJavaScriptCSSPropertyName(const AtomString& propertyName, const Settings* settings) 204 { 205 auto id = parseJavaScriptCSSPropertyName(propertyName); 237 206 if (!isEnabledCSSProperty(id) || !isCSSPropertyEnabledBySettings(id, settings)) 238 return { CSSPropertyInvalid, false };239 return propertyInfo;207 return CSSPropertyInvalid; 208 return id; 240 209 } 241 210 … … 244 213 CSSPropertyID CSSStyleDeclaration::getCSSPropertyIDFromJavaScriptPropertyName(const AtomString& propertyName) 245 214 { 246 return propertyInfoFromJavaScriptCSSPropertyName(propertyName, nullptr).propertyID; 215 // FIXME: This is going to return incorrect results for css properties disabled by Settings. 216 return propertyIDFromJavaScriptCSSPropertyName(propertyName, nullptr); 247 217 } 248 218 … … 254 224 Optional<Variant<String, double>> CSSStyleDeclaration::namedItem(const AtomString& propertyName) 255 225 { 256 auto propertyInfo = propertyInfoFromJavaScriptCSSPropertyName(propertyName, settings()); 257 if (!propertyInfo.propertyID) 226 // FIXME: This is going to return incorrect results for css properties disabled by Settings if settings() returns nullptr. 227 auto propertyID = propertyIDFromJavaScriptCSSPropertyName(propertyName, settings()); 228 if (!propertyID) 258 229 return WTF::nullopt; 259 230 260 auto value = getPropertyCSSValueInternal(propertyInfo.propertyID); 261 if (!value) { 262 // If the property is a shorthand property (such as "padding"), it can only be accessed using getPropertyValue. 263 return Variant<String, double> { getPropertyValueInternal(propertyInfo.propertyID) }; 264 } 265 266 if (propertyInfo.hadPixelOrPosPrefix && is<CSSPrimitiveValue>(*value)) { 267 // Call this version of the getter so that, e.g., pixelTop returns top as a number 268 // in pixel units and posTop should does the same _if_ this is a positioned element. 269 // FIXME: If not a positioned element, MSIE documentation says posTop should return 0; this rule is not implemented. 270 return Variant<String, double> { downcast<CSSPrimitiveValue>(*value).floatValue(CSSUnitType::CSS_PX) }; 271 } 272 273 return Variant<String, double> { value->cssText() }; 231 if (auto value = getPropertyCSSValueInternal(propertyID)) 232 return Variant<String, double> { value->cssText() }; 233 234 // If the property is a shorthand property (such as "padding"), it can only be accessed using getPropertyValue. 235 return Variant<String, double> { getPropertyValueInternal(propertyID) }; 274 236 } 275 237 276 238 ExceptionOr<void> CSSStyleDeclaration::setNamedItem(const AtomString& propertyName, String value, bool& propertySupported) 277 239 { 278 auto propertyInfo = propertyInfoFromJavaScriptCSSPropertyName(propertyName, settings()); 279 if (!propertyInfo.propertyID) { 240 // FIXME: This is going to return incorrect results for css properties disabled by Settings if settings() returns nullptr. 241 auto propertyID = propertyIDFromJavaScriptCSSPropertyName(propertyName, settings()); 242 if (!propertyID) { 280 243 propertySupported = false; 281 244 return { }; … … 283 246 284 247 propertySupported = true; 285 286 if (propertyInfo.hadPixelOrPosPrefix)287 value.append("px");288 248 289 249 bool important = false; … … 296 256 } 297 257 298 auto setPropertyInternalResult = setPropertyInternal(propertyI nfo.propertyID, value, important);258 auto setPropertyInternalResult = setPropertyInternal(propertyID, value, important); 299 259 if (setPropertyInternalResult.hasException()) 300 260 return setPropertyInternalResult.releaseException();
Note:
See TracChangeset
for help on using the changeset viewer.