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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 if (propertyName[i] != prefix[i]) | 77 if (propertyName[i] != prefix[i]) |
78 return false; | 78 return false; |
79 } | 79 } |
80 return false; | 80 return false; |
81 } | 81 } |
82 | 82 |
83 struct CSSPropertyInfo { | 83 struct CSSPropertyInfo { |
84 CSSPropertyID propID; | 84 CSSPropertyID propID; |
85 }; | 85 }; |
86 | 86 |
87 static CSSPropertyID cssResolvedPropertyID(const String& propertyName, v8::Isola
te* isolate) | 87 static CSSPropertyID parseCSSPropertyID(const String& propertyName, v8::Isolate*
isolate) |
88 { | 88 { |
89 unsigned length = propertyName.length(); | 89 unsigned length = propertyName.length(); |
90 if (!length) | 90 if (!length) |
91 return CSSPropertyInvalid; | 91 return CSSPropertyInvalid; |
92 | 92 |
93 StringBuilder builder; | 93 StringBuilder builder; |
94 builder.reserveCapacity(length); | 94 builder.reserveCapacity(length); |
95 | 95 |
96 unsigned i = 0; | 96 unsigned i = 0; |
97 bool hasSeenDash = false; | 97 bool hasSeenDash = false; |
(...skipping 23 matching lines...) Expand all Loading... |
121 builder.append('-'); | 121 builder.append('-'); |
122 builder.append(toASCIILower(c)); | 122 builder.append(toASCIILower(c)); |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 // Reject names containing both dashes and upper-case characters, such as "b
order-rightColor". | 126 // Reject names containing both dashes and upper-case characters, such as "b
order-rightColor". |
127 if (hasSeenDash && hasSeenUpper) | 127 if (hasSeenDash && hasSeenUpper) |
128 return CSSPropertyInvalid; | 128 return CSSPropertyInvalid; |
129 | 129 |
130 String propName = builder.toString(); | 130 String propName = builder.toString(); |
131 return cssPropertyID(propName); | 131 return unresolvedCSSPropertyID(propName); |
132 } | 132 } |
133 | 133 |
134 // When getting properties on CSSStyleDeclarations, the name used from | 134 // When getting properties on CSSStyleDeclarations, the name used from |
135 // 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 |
136 // we have to do the following translation. The translation turns upper | 136 // we have to do the following translation. The translation turns upper |
137 // case characters into lower case characters and inserts dashes to | 137 // case characters into lower case characters and inserts dashes to |
138 // separate words. | 138 // separate words. |
139 // | 139 // |
140 // Example: 'backgroundPositionY' -> 'background-position-y' | 140 // Example: 'backgroundPositionY' -> 'background-position-y' |
141 // | 141 // |
142 // Also, certain prefixes such as 'css-' are stripped. | 142 // Also, certain prefixes such as 'css-' are stripped. |
143 static CSSPropertyInfo* cssPropertyInfo(v8::Local<v8::String> v8PropertyName, v8
::Isolate* isolate) | 143 static CSSPropertyInfo* cssPropertyInfo(v8::Local<v8::String> v8PropertyName, v8
::Isolate* isolate) |
144 { | 144 { |
145 String propertyName = toCoreString(v8PropertyName); | 145 String propertyName = toCoreString(v8PropertyName); |
146 typedef HashMap<String, CSSPropertyInfo*> CSSPropertyInfoMap; | 146 typedef HashMap<String, CSSPropertyInfo*> CSSPropertyInfoMap; |
147 DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ()); | 147 DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ()); |
148 CSSPropertyInfo* propInfo = map.get(propertyName); | 148 CSSPropertyInfo* propInfo = map.get(propertyName); |
149 if (!propInfo) { | 149 if (!propInfo) { |
150 propInfo = new CSSPropertyInfo(); | 150 propInfo = new CSSPropertyInfo(); |
151 propInfo->propID = cssResolvedPropertyID(propertyName, isolate); | 151 propInfo->propID = parseCSSPropertyID(propertyName, isolate); |
152 map.add(propertyName, propInfo); | 152 map.add(propertyName, propInfo); |
153 } | 153 } |
154 if (!propInfo->propID) | 154 if (!propInfo->propID) |
155 return 0; | 155 return 0; |
156 ASSERT(CSSPropertyMetadata::isEnabledProperty(propInfo->propID)); | 156 ASSERT(CSSPropertyMetadata::isEnabledProperty(propInfo->propID)); |
157 return propInfo; | 157 return propInfo; |
158 } | 158 } |
159 | 159 |
160 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall
backInfo<v8::Array>& info) | 160 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall
backInfo<v8::Array>& info) |
161 { | 161 { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 196 } |
197 | 197 |
198 void V8CSSStyleDeclaration::namedPropertyGetterCustom(v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) | 198 void V8CSSStyleDeclaration::namedPropertyGetterCustom(v8::Local<v8::Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) |
199 { | 199 { |
200 // Search the style declaration. | 200 // Search the style declaration. |
201 CSSPropertyInfo* propInfo = cssPropertyInfo(name.As<v8::String>(), info.GetI
solate()); | 201 CSSPropertyInfo* propInfo = cssPropertyInfo(name.As<v8::String>(), info.GetI
solate()); |
202 | 202 |
203 // Do not handle non-property names. | 203 // Do not handle non-property names. |
204 if (!propInfo) | 204 if (!propInfo) |
205 return; | 205 return; |
| 206 CSSPropertyID resolvedProperty = resolveCSSPropertyID(propInfo->propID); |
206 | 207 |
207 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); | 208 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); |
208 RefPtrWillBeRawPtr<CSSValue> cssValue = impl->getPropertyCSSValueInternal(st
atic_cast<CSSPropertyID>(propInfo->propID)); | 209 RefPtrWillBeRawPtr<CSSValue> cssValue = impl->getPropertyCSSValueInternal(re
solvedProperty); |
209 if (cssValue) { | 210 if (cssValue) { |
210 v8SetReturnValueStringOrNull(info, cssValue->cssText(), info.GetIsolate(
)); | 211 v8SetReturnValueStringOrNull(info, cssValue->cssText(), info.GetIsolate(
)); |
211 return; | 212 return; |
212 } | 213 } |
213 | 214 |
214 String result = impl->getPropertyValueInternal(static_cast<CSSPropertyID>(pr
opInfo->propID)); | 215 String result = impl->getPropertyValueInternal(resolvedProperty); |
215 v8SetReturnValueString(info, result, info.GetIsolate()); | 216 v8SetReturnValueString(info, result, info.GetIsolate()); |
216 } | 217 } |
217 | 218 |
218 void V8CSSStyleDeclaration::namedPropertySetterCustom(v8::Local<v8::Name> name,
v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | 219 void V8CSSStyleDeclaration::namedPropertySetterCustom(v8::Local<v8::Name> name,
v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
219 { | 220 { |
220 if (!name->IsString()) | 221 if (!name->IsString()) |
221 return; | 222 return; |
222 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); | 223 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); |
223 CSSPropertyInfo* propInfo = cssPropertyInfo(name.As<v8::String>(), info.GetI
solate()); | 224 CSSPropertyInfo* propInfo = cssPropertyInfo(name.As<v8::String>(), info.GetI
solate()); |
224 if (!propInfo) | 225 if (!propInfo) |
225 return; | 226 return; |
226 | 227 |
227 TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, propertyValue, value)
; | 228 TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, propertyValue, value)
; |
228 ExceptionState exceptionState(ExceptionState::SetterContext, getPropertyName
(static_cast<CSSPropertyID>(propInfo->propID)), "CSSStyleDeclaration", info.Hold
er(), info.GetIsolate()); | 229 ExceptionState exceptionState(ExceptionState::SetterContext, getPropertyName
(resolveCSSPropertyID(propInfo->propID)), "CSSStyleDeclaration", info.Holder(),
info.GetIsolate()); |
229 impl->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prop
ertyValue, false, exceptionState); | 230 impl->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prop
ertyValue, false, exceptionState); |
230 | 231 |
231 if (exceptionState.throwIfNeeded()) | 232 if (exceptionState.throwIfNeeded()) |
232 return; | 233 return; |
233 | 234 |
234 v8SetReturnValue(info, value); | 235 v8SetReturnValue(info, value); |
235 } | 236 } |
236 | 237 |
237 } // namespace blink | 238 } // namespace blink |
OLD | NEW |