| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007-2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2007-2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 unsigned length = propertyName.length(); | 75 unsigned length = propertyName.length(); |
| 76 for (unsigned i = 1; i < length; ++i) { | 76 for (unsigned i = 1; i < length; ++i) { |
| 77 if (!prefix[i]) | 77 if (!prefix[i]) |
| 78 return isASCIIUpper(propertyName[i]); | 78 return isASCIIUpper(propertyName[i]); |
| 79 if (propertyName[i] != prefix[i]) | 79 if (propertyName[i] != prefix[i]) |
| 80 return false; | 80 return false; |
| 81 } | 81 } |
| 82 return false; | 82 return false; |
| 83 } | 83 } |
| 84 | 84 |
| 85 class CSSPropertyInfo { | 85 struct CSSPropertyInfo { |
| 86 public: | 86 unsigned propID: 30; // CSSPropertyID |
| 87 CSSPropertyID propID; | 87 unsigned nameWithDash: 1; |
| 88 unsigned nameWithCssPrefix: 1; |
| 88 }; | 89 }; |
| 89 | 90 |
| 90 // When getting properties on CSSStyleDeclarations, the name used from | 91 // When getting properties on CSSStyleDeclarations, the name used from |
| 91 // Javascript and the actual name of the property are not the same, so | 92 // Javascript and the actual name of the property are not the same, so |
| 92 // we have to do the following translation. The translation turns upper | 93 // we have to do the following translation. The translation turns upper |
| 93 // case characters into lower case characters and inserts dashes to | 94 // case characters into lower case characters and inserts dashes to |
| 94 // separate words. | 95 // separate words. |
| 95 // | 96 // |
| 96 // Example: 'backgroundPositionY' -> 'background-position-y' | 97 // Example: 'backgroundPositionY' -> 'background-position-y' |
| 97 // | 98 // |
| 98 // Also, certain prefixes such as 'css-' are stripped. | 99 // Also, certain prefixes such as 'css-' are stripped. |
| 99 static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName) | 100 static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName) |
| 100 { | 101 { |
| 101 String propertyName = toWebCoreString(v8PropertyName); | 102 String propertyName = toWebCoreString(v8PropertyName); |
| 102 typedef HashMap<String, CSSPropertyInfo*> CSSPropertyInfoMap; | 103 typedef HashMap<String, CSSPropertyInfo*> CSSPropertyInfoMap; |
| 103 DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ()); | 104 DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ()); |
| 104 CSSPropertyInfo* propInfo = map.get(propertyName); | 105 CSSPropertyInfo* propInfo = map.get(propertyName); |
| 105 if (!propInfo) { | 106 if (!propInfo) { |
| 106 unsigned length = propertyName.length(); | 107 unsigned length = propertyName.length(); |
| 107 if (!length) | 108 if (!length) |
| 108 return 0; | 109 return 0; |
| 109 | 110 |
| 110 StringBuilder builder; | 111 StringBuilder builder; |
| 111 builder.reserveCapacity(length); | 112 builder.reserveCapacity(length); |
| 112 | 113 |
| 113 unsigned i = 0; | 114 unsigned i = 0; |
| 115 bool hasSeenDash = false; |
| 116 bool hasSeenCssPrefix = false; |
| 114 | 117 |
| 115 if (hasCSSPropertyNamePrefix(propertyName, "css")) | 118 if (hasCSSPropertyNamePrefix(propertyName, "css")) { |
| 119 hasSeenCssPrefix = true; |
| 116 i += 3; | 120 i += 3; |
| 117 else if (hasCSSPropertyNamePrefix(propertyName, "webkit")) | 121 } else if (hasCSSPropertyNamePrefix(propertyName, "webkit")) { |
| 118 builder.append('-'); | 122 builder.append('-'); |
| 119 else if (isASCIIUpper(propertyName[0])) | 123 } else if (isASCIIUpper(propertyName[0])) { |
| 120 return 0; | 124 return 0; |
| 125 } |
| 121 | 126 |
| 122 builder.append(toASCIILower(propertyName[i++])); | 127 builder.append(toASCIILower(propertyName[i++])); |
| 123 | 128 |
| 124 for (; i < length; ++i) { | 129 for (; i < length; ++i) { |
| 125 UChar c = propertyName[i]; | 130 UChar c = propertyName[i]; |
| 126 if (!isASCIIUpper(c)) | 131 if (!isASCIIUpper(c)) { |
| 132 if (c == '-') |
| 133 hasSeenDash = true; |
| 127 builder.append(c); | 134 builder.append(c); |
| 135 } |
| 128 else { | 136 else { |
| 129 builder.append('-'); | 137 builder.append('-'); |
| 130 builder.append(toASCIILower(c)); | 138 builder.append(toASCIILower(c)); |
| 131 } | 139 } |
| 132 } | 140 } |
| 133 | 141 |
| 134 String propName = builder.toString(); | 142 String propName = builder.toString(); |
| 135 CSSPropertyID propertyID = cssPropertyID(propName); | 143 CSSPropertyID propertyID = cssPropertyID(propName); |
| 136 if (propertyID && RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID)) { | 144 if (propertyID && RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID)) { |
| 137 propInfo = new CSSPropertyInfo(); | 145 propInfo = new CSSPropertyInfo(); |
| 138 propInfo->propID = propertyID; | 146 propInfo->propID = propertyID; |
| 147 propInfo->nameWithDash = hasSeenDash; |
| 148 propInfo->nameWithCssPrefix = hasSeenCssPrefix; |
| 139 map.add(propertyName, propInfo); | 149 map.add(propertyName, propInfo); |
| 140 } | 150 } |
| 141 } | 151 } |
| 152 |
| 153 if (propInfo) { |
| 154 if (propInfo->nameWithDash) |
| 155 UseCounter::count(activeDOMWindow(), UseCounter::CSSStyleDeclaration
PropertyName); |
| 156 if (propInfo->propID == CSSPropertyFloat && !propInfo->nameWithCssPrefix
) |
| 157 UseCounter::count(activeDOMWindow(), UseCounter::CSSStyleDeclaration
FloatPropertyName); |
| 158 } |
| 159 |
| 142 return propInfo; | 160 return propInfo; |
| 143 } | 161 } |
| 144 | 162 |
| 145 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall
backInfo<v8::Array>& info) | 163 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall
backInfo<v8::Array>& info) |
| 146 { | 164 { |
| 147 typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector; | 165 typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector; |
| 148 DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ()); | 166 DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ()); |
| 149 static unsigned propertyNamesLength = 0; | 167 static unsigned propertyNamesLength = 0; |
| 150 | 168 |
| 151 if (propertyNames.isEmpty()) { | 169 if (propertyNames.isEmpty()) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 ExceptionState es(info.GetIsolate()); | 235 ExceptionState es(info.GetIsolate()); |
| 218 imp->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prope
rtyValue, false, es); | 236 imp->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prope
rtyValue, false, es); |
| 219 | 237 |
| 220 if (es.throwIfNeeded()) | 238 if (es.throwIfNeeded()) |
| 221 return; | 239 return; |
| 222 | 240 |
| 223 v8SetReturnValue(info, value); | 241 v8SetReturnValue(info, value); |
| 224 } | 242 } |
| 225 | 243 |
| 226 } // namespace WebCore | 244 } // namespace WebCore |
| OLD | NEW |