| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
| 35 #include "bindings/core/v8/V8Binding.h" | 35 #include "bindings/core/v8/V8Binding.h" |
| 36 #include "core/CSSPropertyNames.h" | 36 #include "core/CSSPropertyNames.h" |
| 37 #include "core/css/CSSPrimitiveValue.h" | 37 #include "core/css/CSSPrimitiveValue.h" |
| 38 #include "core/css/CSSPropertyMetadata.h" | 38 #include "core/css/CSSPropertyMetadata.h" |
| 39 #include "core/css/CSSStyleDeclaration.h" | 39 #include "core/css/CSSStyleDeclaration.h" |
| 40 #include "core/css/CSSValue.h" | 40 #include "core/css/CSSValue.h" |
| 41 #include "core/css/parser/CSSParser.h" | 41 #include "core/css/parser/CSSParser.h" |
| 42 #include "core/events/EventTarget.h" | 42 #include "core/events/EventTarget.h" |
| 43 #include "core/frame/UseCounter.h" |
| 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" |
| 50 | 51 |
| 51 using namespace WTF; | 52 using namespace WTF; |
| 52 | 53 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 76 if (propertyName[i] != prefix[i]) | 77 if (propertyName[i] != prefix[i]) |
| 77 return false; | 78 return false; |
| 78 } | 79 } |
| 79 return false; | 80 return false; |
| 80 } | 81 } |
| 81 | 82 |
| 82 struct CSSPropertyInfo { | 83 struct CSSPropertyInfo { |
| 83 CSSPropertyID propID; | 84 CSSPropertyID propID; |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 static CSSPropertyID cssResolvedPropertyID(const String& propertyName) | 87 static CSSPropertyID cssResolvedPropertyID(const String& propertyName, v8::Isola
te* isolate) |
| 87 { | 88 { |
| 88 unsigned length = propertyName.length(); | 89 unsigned length = propertyName.length(); |
| 89 if (!length) | 90 if (!length) |
| 90 return CSSPropertyInvalid; | 91 return CSSPropertyInvalid; |
| 91 | 92 |
| 92 StringBuilder builder; | 93 StringBuilder builder; |
| 93 builder.reserveCapacity(length); | 94 builder.reserveCapacity(length); |
| 94 | 95 |
| 95 unsigned i = 0; | 96 unsigned i = 0; |
| 96 bool hasSeenDash = false; | 97 bool hasSeenDash = false; |
| 97 | 98 |
| 98 if (hasCSSPropertyNamePrefix(propertyName, "css")) | 99 if (hasCSSPropertyNamePrefix(propertyName, "css")) { |
| 99 i += 3; | 100 i += 3; |
| 100 else if (hasCSSPropertyNamePrefix(propertyName, "webkit")) | 101 // getComputedStyle(elem).cssX is a non-standard behaviour |
| 102 // Measure this behaviour as CSSXGetComputedStyleQueries. |
| 103 UseCounter::count(callingExecutionContext(isolate), UseCounter::CSSXGetC
omputedStyleQueries); |
| 104 } else if (hasCSSPropertyNamePrefix(propertyName, "webkit")) |
| 101 builder.append('-'); | 105 builder.append('-'); |
| 102 else if (isASCIIUpper(propertyName[0])) | 106 else if (isASCIIUpper(propertyName[0])) |
| 103 return CSSPropertyInvalid; | 107 return CSSPropertyInvalid; |
| 104 | 108 |
| 105 bool hasSeenUpper = isASCIIUpper(propertyName[i]); | 109 bool hasSeenUpper = isASCIIUpper(propertyName[i]); |
| 106 | 110 |
| 107 builder.append(toASCIILower(propertyName[i++])); | 111 builder.append(toASCIILower(propertyName[i++])); |
| 108 | 112 |
| 109 for (; i < length; ++i) { | 113 for (; i < length; ++i) { |
| 110 UChar c = propertyName[i]; | 114 UChar c = propertyName[i]; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 129 | 133 |
| 130 // When getting properties on CSSStyleDeclarations, the name used from | 134 // When getting properties on CSSStyleDeclarations, the name used from |
| 131 // Javascript and the actual name of the property are not the same, so | 135 // Javascript and the actual name of the property are not the same, so |
| 132 // we have to do the following translation. The translation turns upper | 136 // we have to do the following translation. The translation turns upper |
| 133 // case characters into lower case characters and inserts dashes to | 137 // case characters into lower case characters and inserts dashes to |
| 134 // separate words. | 138 // separate words. |
| 135 // | 139 // |
| 136 // Example: 'backgroundPositionY' -> 'background-position-y' | 140 // Example: 'backgroundPositionY' -> 'background-position-y' |
| 137 // | 141 // |
| 138 // Also, certain prefixes such as 'css-' are stripped. | 142 // Also, certain prefixes such as 'css-' are stripped. |
| 139 static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName) | 143 static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName, v
8::Isolate* isolate) |
| 140 { | 144 { |
| 141 String propertyName = toCoreString(v8PropertyName); | 145 String propertyName = toCoreString(v8PropertyName); |
| 142 typedef HashMap<String, CSSPropertyInfo*> CSSPropertyInfoMap; | 146 typedef HashMap<String, CSSPropertyInfo*> CSSPropertyInfoMap; |
| 143 DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ()); | 147 DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ()); |
| 144 CSSPropertyInfo* propInfo = map.get(propertyName); | 148 CSSPropertyInfo* propInfo = map.get(propertyName); |
| 145 if (!propInfo) { | 149 if (!propInfo) { |
| 146 propInfo = new CSSPropertyInfo(); | 150 propInfo = new CSSPropertyInfo(); |
| 147 propInfo->propID = cssResolvedPropertyID(propertyName); | 151 propInfo->propID = cssResolvedPropertyID(propertyName, isolate); |
| 148 map.add(propertyName, propInfo); | 152 map.add(propertyName, propInfo); |
| 149 } | 153 } |
| 150 if (!propInfo->propID) | 154 if (!propInfo->propID) |
| 151 return 0; | 155 return 0; |
| 152 ASSERT(CSSPropertyMetadata::isEnabledProperty(propInfo->propID)); | 156 ASSERT(CSSPropertyMetadata::isEnabledProperty(propInfo->propID)); |
| 153 return propInfo; | 157 return propInfo; |
| 154 } | 158 } |
| 155 | 159 |
| 156 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall
backInfo<v8::Array>& info) | 160 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall
backInfo<v8::Array>& info) |
| 157 { | 161 { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 176 properties->Set(v8::Integer::New(info.GetIsolate(), i), v8String(info.Ge
tIsolate(), key)); | 180 properties->Set(v8::Integer::New(info.GetIsolate(), i), v8String(info.Ge
tIsolate(), key)); |
| 177 } | 181 } |
| 178 | 182 |
| 179 v8SetReturnValue(info, properties); | 183 v8SetReturnValue(info, properties); |
| 180 } | 184 } |
| 181 | 185 |
| 182 void V8CSSStyleDeclaration::namedPropertyQueryCustom(v8::Local<v8::String> v8Nam
e, const v8::PropertyCallbackInfo<v8::Integer>& info) | 186 void V8CSSStyleDeclaration::namedPropertyQueryCustom(v8::Local<v8::String> v8Nam
e, const v8::PropertyCallbackInfo<v8::Integer>& info) |
| 183 { | 187 { |
| 184 // NOTE: cssPropertyInfo lookups incur several mallocs. | 188 // NOTE: cssPropertyInfo lookups incur several mallocs. |
| 185 // Successful lookups have the same cost the first time, but are cached. | 189 // Successful lookups have the same cost the first time, but are cached. |
| 186 if (cssPropertyInfo(v8Name)) { | 190 if (cssPropertyInfo(v8Name, info.GetIsolate())) { |
| 187 v8SetReturnValueInt(info, 0); | 191 v8SetReturnValueInt(info, 0); |
| 188 return; | 192 return; |
| 189 } | 193 } |
| 190 } | 194 } |
| 191 | 195 |
| 192 void V8CSSStyleDeclaration::namedPropertyGetterCustom(v8::Local<v8::String> name
, const v8::PropertyCallbackInfo<v8::Value>& info) | 196 void V8CSSStyleDeclaration::namedPropertyGetterCustom(v8::Local<v8::String> name
, const v8::PropertyCallbackInfo<v8::Value>& info) |
| 193 { | 197 { |
| 194 // First look for API defined attributes on the style declaration object. | 198 // First look for API defined attributes on the style declaration object. |
| 195 if (info.Holder()->HasRealNamedCallbackProperty(name)) | 199 if (info.Holder()->HasRealNamedCallbackProperty(name)) |
| 196 return; | 200 return; |
| 197 | 201 |
| 198 // Search the style declaration. | 202 // Search the style declaration. |
| 199 CSSPropertyInfo* propInfo = cssPropertyInfo(name); | 203 CSSPropertyInfo* propInfo = cssPropertyInfo(name, info.GetIsolate()); |
| 200 | 204 |
| 201 // Do not handle non-property names. | 205 // Do not handle non-property names. |
| 202 if (!propInfo) | 206 if (!propInfo) |
| 203 return; | 207 return; |
| 204 | 208 |
| 205 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); | 209 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); |
| 206 RefPtrWillBeRawPtr<CSSValue> cssValue = impl->getPropertyCSSValueInternal(st
atic_cast<CSSPropertyID>(propInfo->propID)); | 210 RefPtrWillBeRawPtr<CSSValue> cssValue = impl->getPropertyCSSValueInternal(st
atic_cast<CSSPropertyID>(propInfo->propID)); |
| 207 if (cssValue) { | 211 if (cssValue) { |
| 208 v8SetReturnValueStringOrNull(info, cssValue->cssText(), info.GetIsolate(
)); | 212 v8SetReturnValueStringOrNull(info, cssValue->cssText(), info.GetIsolate(
)); |
| 209 return; | 213 return; |
| 210 } | 214 } |
| 211 | 215 |
| 212 String result = impl->getPropertyValueInternal(static_cast<CSSPropertyID>(pr
opInfo->propID)); | 216 String result = impl->getPropertyValueInternal(static_cast<CSSPropertyID>(pr
opInfo->propID)); |
| 213 v8SetReturnValueString(info, result, info.GetIsolate()); | 217 v8SetReturnValueString(info, result, info.GetIsolate()); |
| 214 } | 218 } |
| 215 | 219 |
| 216 void V8CSSStyleDeclaration::namedPropertySetterCustom(v8::Local<v8::String> name
, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | 220 void V8CSSStyleDeclaration::namedPropertySetterCustom(v8::Local<v8::String> name
, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
| 217 { | 221 { |
| 218 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); | 222 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); |
| 219 CSSPropertyInfo* propInfo = cssPropertyInfo(name); | 223 CSSPropertyInfo* propInfo = cssPropertyInfo(name, info.GetIsolate()); |
| 220 if (!propInfo) | 224 if (!propInfo) |
| 221 return; | 225 return; |
| 222 | 226 |
| 223 TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, propertyValue, value)
; | 227 TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, propertyValue, value)
; |
| 224 ExceptionState exceptionState(ExceptionState::SetterContext, getPropertyName
(static_cast<CSSPropertyID>(propInfo->propID)), "CSSStyleDeclaration", info.Hold
er(), info.GetIsolate()); | 228 ExceptionState exceptionState(ExceptionState::SetterContext, getPropertyName
(static_cast<CSSPropertyID>(propInfo->propID)), "CSSStyleDeclaration", info.Hold
er(), info.GetIsolate()); |
| 225 impl->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prop
ertyValue, false, exceptionState); | 229 impl->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prop
ertyValue, false, exceptionState); |
| 226 | 230 |
| 227 if (exceptionState.throwIfNeeded()) | 231 if (exceptionState.throwIfNeeded()) |
| 228 return; | 232 return; |
| 229 | 233 |
| 230 v8SetReturnValue(info, value); | 234 v8SetReturnValue(info, value); |
| 231 } | 235 } |
| 232 | 236 |
| 233 } // namespace blink | 237 } // namespace blink |
| OLD | NEW |