Chromium Code Reviews| 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 19 matching lines...) Expand all Loading... | |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "V8CSSStyleDeclaration.h" | 32 #include "V8CSSStyleDeclaration.h" |
| 33 | 33 |
| 34 #include "CSSPropertyNames.h" | 34 #include "CSSPropertyNames.h" |
| 35 #include "core/css/CSSParser.h" | 35 #include "core/css/CSSParser.h" |
| 36 #include "core/css/CSSPrimitiveValue.h" | 36 #include "core/css/CSSPrimitiveValue.h" |
| 37 #include "core/css/CSSStyleDeclaration.h" | 37 #include "core/css/CSSStyleDeclaration.h" |
| 38 #include "core/css/CSSValue.h" | 38 #include "core/css/CSSValue.h" |
| 39 #include "core/dom/EventTarget.h" | 39 #include "core/dom/EventTarget.h" |
| 40 #include "core/page/RuntimeCSSEnabled.h" | |
| 40 | 41 |
| 41 #include "bindings/v8/V8Binding.h" | 42 #include "bindings/v8/V8Binding.h" |
| 42 | 43 |
| 43 #include "wtf/ASCIICType.h" | 44 #include "wtf/ASCIICType.h" |
| 44 #include "wtf/PassRefPtr.h" | 45 #include "wtf/PassRefPtr.h" |
| 45 #include "wtf/RefPtr.h" | 46 #include "wtf/RefPtr.h" |
| 46 #include "wtf/StdLibExtras.h" | 47 #include "wtf/StdLibExtras.h" |
| 47 #include "wtf/Vector.h" | 48 #include "wtf/Vector.h" |
| 48 #include "wtf/text/StringBuilder.h" | 49 #include "wtf/text/StringBuilder.h" |
| 49 #include "wtf/text/StringConcatenate.h" | 50 #include "wtf/text/StringConcatenate.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 // Javascript and the actual name of the property are not the same, so | 93 // Javascript and the actual name of the property are not the same, so |
| 93 // we have to do the following translation. The translation turns upper | 94 // we have to do the following translation. The translation turns upper |
| 94 // case characters into lower case characters and inserts dashes to | 95 // case characters into lower case characters and inserts dashes to |
| 95 // separate words. | 96 // separate words. |
| 96 // | 97 // |
| 97 // Example: 'backgroundPositionY' -> 'background-position-y' | 98 // Example: 'backgroundPositionY' -> 'background-position-y' |
| 98 // | 99 // |
| 99 // Also, certain prefixes such as 'pos', 'css-' and 'pixel-' are stripped | 100 // Also, certain prefixes such as 'pos', 'css-' and 'pixel-' are stripped |
| 100 // and the hadPixelOrPosPrefix out parameter is used to indicate whether or | 101 // and the hadPixelOrPosPrefix out parameter is used to indicate whether or |
| 101 // not the property name was prefixed with 'pos-' or 'pixel-'. | 102 // not the property name was prefixed with 'pos-' or 'pixel-'. |
| 102 static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String>v8PropertyName) | 103 static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName) |
| 103 { | 104 { |
| 104 String propertyName = toWebCoreString(v8PropertyName); | 105 String propertyName = toWebCoreString(v8PropertyName); |
| 105 typedef HashMap<String, CSSPropertyInfo*> CSSPropertyInfoMap; | 106 typedef HashMap<String, CSSPropertyInfo*> CSSPropertyInfoMap; |
| 106 DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ()); | 107 DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ()); |
| 107 CSSPropertyInfo* propInfo = map.get(propertyName); | 108 CSSPropertyInfo* propInfo = map.get(propertyName); |
| 108 if (!propInfo) { | 109 if (!propInfo) { |
| 109 unsigned length = propertyName.length(); | 110 unsigned length = propertyName.length(); |
| 110 bool hadPixelOrPosPrefix = false; | 111 bool hadPixelOrPosPrefix = false; |
| 111 if (!length) | 112 if (!length) |
| 112 return 0; | 113 return 0; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 134 for (; i < length; ++i) { | 135 for (; i < length; ++i) { |
| 135 UChar c = propertyName[i]; | 136 UChar c = propertyName[i]; |
| 136 if (!isASCIIUpper(c)) | 137 if (!isASCIIUpper(c)) |
| 137 builder.append(c); | 138 builder.append(c); |
| 138 else | 139 else |
| 139 builder.append(makeString('-', toASCIILower(c))); | 140 builder.append(makeString('-', toASCIILower(c))); |
| 140 } | 141 } |
| 141 | 142 |
| 142 String propName = builder.toString(); | 143 String propName = builder.toString(); |
| 143 CSSPropertyID propertyID = cssPropertyID(propName); | 144 CSSPropertyID propertyID = cssPropertyID(propName); |
| 144 if (propertyID) { | 145 if (propertyID && RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID)) { |
| 145 propInfo = new CSSPropertyInfo(); | 146 propInfo = new CSSPropertyInfo(); |
| 146 propInfo->hadPixelOrPosPrefix = hadPixelOrPosPrefix; | 147 propInfo->hadPixelOrPosPrefix = hadPixelOrPosPrefix; |
| 147 propInfo->propID = propertyID; | 148 propInfo->propID = propertyID; |
| 148 map.add(propertyName, propInfo); | 149 map.add(propertyName, propInfo); |
| 149 } | 150 } |
| 150 } | 151 } |
| 151 return propInfo; | 152 return propInfo; |
| 152 } | 153 } |
| 153 | 154 |
| 154 v8::Handle<v8::Array> V8CSSStyleDeclaration::namedPropertyEnumerator(const v8::A ccessorInfo& info) | 155 v8::Handle<v8::Array> V8CSSStyleDeclaration::namedPropertyEnumerator(const v8::A ccessorInfo& info) |
| 155 { | 156 { |
| 156 typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector; | 157 typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector; |
| 157 DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ()); | 158 DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ()); |
| 158 static unsigned propertyNamesLength = 0; | 159 static unsigned propertyNamesLength = 0; |
| 159 | 160 |
| 160 if (propertyNames.isEmpty()) { | 161 if (propertyNames.isEmpty()) { |
| 161 for (int id = firstCSSProperty; id < firstCSSProperty + numCSSProperties ; ++id) | 162 for (int id = firstCSSProperty; id < firstCSSProperty + numCSSProperties ; ++id) { |
|
mitica
2013/04/24 06:24:25
It would probably be better to use lastCSSProperty
| |
| 162 propertyNames.append(getJSPropertyName(static_cast<CSSPropertyID>(id ))); | 163 CSSPropertyID propertyId = static_cast<CSSPropertyID>(id); |
| 164 if (RuntimeCSSEnabled::isCSSPropertyEnabled(propertyId)) | |
| 165 propertyNames.append(getJSPropertyName(propertyId)); | |
| 166 } | |
| 163 sort(propertyNames.begin(), propertyNames.end(), codePointCompareLessTha n); | 167 sort(propertyNames.begin(), propertyNames.end(), codePointCompareLessTha n); |
| 164 propertyNamesLength = propertyNames.size(); | 168 propertyNamesLength = propertyNames.size(); |
| 165 } | 169 } |
| 166 | 170 |
| 167 v8::Handle<v8::Array> properties = v8::Array::New(propertyNamesLength); | 171 v8::Handle<v8::Array> properties = v8::Array::New(propertyNamesLength); |
| 168 for (unsigned i = 0; i < propertyNamesLength; ++i) { | 172 for (unsigned i = 0; i < propertyNamesLength; ++i) { |
| 169 String key = propertyNames.at(i); | 173 String key = propertyNames.at(i); |
| 170 ASSERT(!key.isNull()); | 174 ASSERT(!key.isNull()); |
| 171 properties->Set(v8Integer(i, info.GetIsolate()), v8String(key, info.GetI solate())); | 175 properties->Set(v8Integer(i, info.GetIsolate()), v8String(key, info.GetI solate())); |
| 172 } | 176 } |
| 173 | 177 |
| 174 return properties; | 178 return properties; |
| 175 } | 179 } |
| 176 | 180 |
| 177 v8::Handle<v8::Integer> V8CSSStyleDeclaration::namedPropertyQuery(v8::Local<v8:: String> v8Name, const v8::AccessorInfo& info) | 181 v8::Handle<v8::Integer> V8CSSStyleDeclaration::namedPropertyQuery(v8::Local<v8:: String> v8Name, const v8::AccessorInfo& info) |
| 178 { | 182 { |
| 183 // NOTE: cssPropertyInfo lookups incur several mallocs. | |
| 184 // Successful lookups have the same cost the first time, but are cached. | |
| 179 if (cssPropertyInfo(v8Name)) | 185 if (cssPropertyInfo(v8Name)) |
| 180 return v8Integer(0, info.GetIsolate()); | 186 return v8Integer(0, info.GetIsolate()); |
| 181 | 187 |
| 182 return v8::Handle<v8::Integer>(); | 188 return v8::Handle<v8::Integer>(); |
| 183 } | 189 } |
| 184 | 190 |
| 185 v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertyGetter(v8::Local<v8::S tring> name, const v8::AccessorInfo& info) | 191 v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertyGetter(v8::Local<v8::S tring> name, const v8::AccessorInfo& info) |
| 186 { | 192 { |
| 187 // First look for API defined attributes on the style declaration object. | 193 // First look for API defined attributes on the style declaration object. |
| 188 if (info.Holder()->HasRealNamedCallbackProperty(name)) | 194 if (info.Holder()->HasRealNamedCallbackProperty(name)) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 ExceptionCode ec = 0; | 233 ExceptionCode ec = 0; |
| 228 imp->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prope rtyValue, false, ec); | 234 imp->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prope rtyValue, false, ec); |
| 229 | 235 |
| 230 if (ec) | 236 if (ec) |
| 231 setDOMException(ec, info.GetIsolate()); | 237 setDOMException(ec, info.GetIsolate()); |
| 232 | 238 |
| 233 return value; | 239 return value; |
| 234 } | 240 } |
| 235 | 241 |
| 236 } // namespace WebCore | 242 } // namespace WebCore |
| OLD | NEW |