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) |
| 88 { |
| 89 unsigned length = propertyName.length(); |
| 90 if (!length) |
| 91 return CSSPropertyInvalid; |
| 92 |
| 93 StringBuilder builder; |
| 94 builder.reserveCapacity(length); |
| 95 |
| 96 unsigned i = 0; |
| 97 bool hasSeenDash = false; |
| 98 |
| 99 if (hasCSSPropertyNamePrefix(propertyName, "css")) |
| 100 i += 3; |
| 101 else if (hasCSSPropertyNamePrefix(propertyName, "webkit")) |
| 102 builder.append('-'); |
| 103 else if (isASCIIUpper(propertyName[0])) |
| 104 return CSSPropertyInvalid; |
| 105 |
| 106 bool hasSeenUpper = isASCIIUpper(propertyName[i]); |
| 107 |
| 108 builder.append(toASCIILower(propertyName[i++])); |
| 109 |
| 110 for (; i < length; ++i) { |
| 111 UChar c = propertyName[i]; |
| 112 if (!isASCIIUpper(c)) { |
| 113 if (c == '-') |
| 114 hasSeenDash = true; |
| 115 builder.append(c); |
| 116 } else { |
| 117 hasSeenUpper = true; |
| 118 builder.append('-'); |
| 119 builder.append(toASCIILower(c)); |
| 120 } |
| 121 } |
| 122 |
| 123 // Reject names containing both dashes and upper-case characters, such as "b
order-rightColor". |
| 124 if (hasSeenDash && hasSeenUpper) |
| 125 return CSSPropertyInvalid; |
| 126 |
| 127 String propName = builder.toString(); |
| 128 return cssPropertyID(propName); |
| 129 } |
| 130 |
87 // When getting properties on CSSStyleDeclarations, the name used from | 131 // When getting properties on CSSStyleDeclarations, the name used from |
88 // Javascript and the actual name of the property are not the same, so | 132 // Javascript and the actual name of the property are not the same, so |
89 // we have to do the following translation. The translation turns upper | 133 // we have to do the following translation. The translation turns upper |
90 // case characters into lower case characters and inserts dashes to | 134 // case characters into lower case characters and inserts dashes to |
91 // separate words. | 135 // separate words. |
92 // | 136 // |
93 // Example: 'backgroundPositionY' -> 'background-position-y' | 137 // Example: 'backgroundPositionY' -> 'background-position-y' |
94 // | 138 // |
95 // Also, certain prefixes such as 'css-' are stripped. | 139 // Also, certain prefixes such as 'css-' are stripped. |
96 static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName) | 140 static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName) |
97 { | 141 { |
98 String propertyName = toCoreString(v8PropertyName); | 142 String propertyName = toCoreString(v8PropertyName); |
99 typedef HashMap<String, CSSPropertyInfo*> CSSPropertyInfoMap; | 143 typedef HashMap<String, CSSPropertyInfo*> CSSPropertyInfoMap; |
100 DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ()); | 144 DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ()); |
101 CSSPropertyInfo* propInfo = map.get(propertyName); | 145 CSSPropertyInfo* propInfo = map.get(propertyName); |
102 if (!propInfo) { | 146 if (!propInfo) { |
103 unsigned length = propertyName.length(); | 147 propInfo = new CSSPropertyInfo(); |
104 if (!length) | 148 propInfo->propID = cssResolvedPropertyID(propertyName); |
105 return 0; | 149 map.add(propertyName, propInfo); |
106 | |
107 StringBuilder builder; | |
108 builder.reserveCapacity(length); | |
109 | |
110 unsigned i = 0; | |
111 bool hasSeenDash = false; | |
112 | |
113 if (hasCSSPropertyNamePrefix(propertyName, "css")) | |
114 i += 3; | |
115 else if (hasCSSPropertyNamePrefix(propertyName, "webkit")) | |
116 builder.append('-'); | |
117 else if (isASCIIUpper(propertyName[0])) | |
118 return 0; | |
119 | |
120 bool hasSeenUpper = isASCIIUpper(propertyName[i]); | |
121 | |
122 builder.append(toASCIILower(propertyName[i++])); | |
123 | |
124 for (; i < length; ++i) { | |
125 UChar c = propertyName[i]; | |
126 if (!isASCIIUpper(c)) { | |
127 if (c == '-') | |
128 hasSeenDash = true; | |
129 builder.append(c); | |
130 } | |
131 else { | |
132 hasSeenUpper = true; | |
133 builder.append('-'); | |
134 builder.append(toASCIILower(c)); | |
135 } | |
136 } | |
137 | |
138 // Reject names containing both dashes and upper-case characters, such a
s "border-rightColor". | |
139 if (hasSeenDash && hasSeenUpper) | |
140 return 0; | |
141 | |
142 String propName = builder.toString(); | |
143 CSSPropertyID propertyID = cssPropertyID(propName); | |
144 if (propertyID && RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID)) { | |
145 propInfo = new CSSPropertyInfo(); | |
146 propInfo->propID = propertyID; | |
147 map.add(propertyName, propInfo); | |
148 } | |
149 } | 150 } |
150 return propInfo; | 151 if (propInfo->propID && RuntimeCSSEnabled::isCSSPropertyEnabled(propInfo->pr
opID)) |
| 152 return propInfo; |
| 153 return 0; |
151 } | 154 } |
152 | 155 |
153 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall
backInfo<v8::Array>& info) | 156 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall
backInfo<v8::Array>& info) |
154 { | 157 { |
155 typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector; | 158 typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector; |
156 DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ()); | 159 DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ()); |
157 static unsigned propertyNamesLength = 0; | 160 static unsigned propertyNamesLength = 0; |
158 | 161 |
159 if (propertyNames.isEmpty()) { | 162 if (propertyNames.isEmpty()) { |
160 for (int id = firstCSSProperty; id <= lastCSSProperty; ++id) { | 163 for (int id = firstCSSProperty; id <= lastCSSProperty; ++id) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 ExceptionState exceptionState(ExceptionState::SetterContext, getPropertyName
(static_cast<CSSPropertyID>(propInfo->propID)), "CSSStyleDeclaration", info.Hold
er(), info.GetIsolate()); | 227 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); | 228 impl->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), prop
ertyValue, false, exceptionState); |
226 | 229 |
227 if (exceptionState.throwIfNeeded()) | 230 if (exceptionState.throwIfNeeded()) |
228 return; | 231 return; |
229 | 232 |
230 v8SetReturnValue(info, value); | 233 v8SetReturnValue(info, value); |
231 } | 234 } |
232 | 235 |
233 } // namespace WebCore | 236 } // namespace WebCore |
OLD | NEW |