Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(869)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/custom/V8CSSStyleDeclarationCustom.cpp

Issue 1607653002: Remove getComputedStyle(e).css* properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary property name prefix check Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 21 matching lines...) Expand all
32 32
33 #include "bindings/core/v8/ExceptionState.h" 33 #include "bindings/core/v8/ExceptionState.h"
34 #include "bindings/core/v8/V8Binding.h" 34 #include "bindings/core/v8/V8Binding.h"
35 #include "core/CSSPropertyNames.h" 35 #include "core/CSSPropertyNames.h"
36 #include "core/css/CSSPrimitiveValue.h" 36 #include "core/css/CSSPrimitiveValue.h"
37 #include "core/css/CSSPropertyMetadata.h" 37 #include "core/css/CSSPropertyMetadata.h"
38 #include "core/css/CSSStyleDeclaration.h" 38 #include "core/css/CSSStyleDeclaration.h"
39 #include "core/css/CSSValue.h" 39 #include "core/css/CSSValue.h"
40 #include "core/css/parser/CSSParser.h" 40 #include "core/css/parser/CSSParser.h"
41 #include "core/events/EventTarget.h" 41 #include "core/events/EventTarget.h"
42 #include "core/frame/UseCounter.h"
43 #include "wtf/ASCIICType.h" 42 #include "wtf/ASCIICType.h"
44 #include "wtf/PassRefPtr.h" 43 #include "wtf/PassRefPtr.h"
45 #include "wtf/RefPtr.h" 44 #include "wtf/RefPtr.h"
46 #include "wtf/StdLibExtras.h" 45 #include "wtf/StdLibExtras.h"
47 #include "wtf/Vector.h" 46 #include "wtf/Vector.h"
48 #include "wtf/text/StringBuilder.h" 47 #include "wtf/text/StringBuilder.h"
49 #include "wtf/text/StringConcatenate.h" 48 #include "wtf/text/StringConcatenate.h"
50 #include <algorithm> 49 #include <algorithm>
51 50
52 using namespace WTF; 51 using namespace WTF;
(...skipping 20 matching lines...) Expand all
73 unsigned length = propertyName.length(); 72 unsigned length = propertyName.length();
74 for (unsigned i = 1; i < length; ++i) { 73 for (unsigned i = 1; i < length; ++i) {
75 if (!prefix[i]) 74 if (!prefix[i])
76 return isASCIIUpper(propertyName[i]); 75 return isASCIIUpper(propertyName[i]);
77 if (propertyName[i] != prefix[i]) 76 if (propertyName[i] != prefix[i])
78 return false; 77 return false;
79 } 78 }
80 return false; 79 return false;
81 } 80 }
82 81
83 static CSSPropertyID parseCSSPropertyID(v8::Isolate* isolate, const String& prop ertyName) 82 static CSSPropertyID parseCSSPropertyID(const String& propertyName)
84 { 83 {
85 unsigned length = propertyName.length(); 84 unsigned length = propertyName.length();
86 if (!length) 85 if (!length)
87 return CSSPropertyInvalid; 86 return CSSPropertyInvalid;
88 87
89 StringBuilder builder; 88 StringBuilder builder;
90 builder.reserveCapacity(length); 89 builder.reserveCapacity(length);
91 90
92 unsigned i = 0; 91 unsigned i = 0;
93 bool hasSeenDash = false; 92 bool hasSeenDash = false;
94 93
95 if (hasCSSPropertyNamePrefix(propertyName, "css")) { 94 if (hasCSSPropertyNamePrefix(propertyName, "webkit"))
96 i += 3;
97 // getComputedStyle(elem).cssX is a non-standard behaviour
98 // Measure this behaviour as CSSXGetComputedStyleQueries.
99 UseCounter::countDeprecationIfNotPrivateScript(isolate, currentExecution Context(isolate), UseCounter::CSSXGetComputedStyleQueries);
100 } else if (hasCSSPropertyNamePrefix(propertyName, "webkit"))
101 builder.append('-'); 95 builder.append('-');
102 else if (isASCIIUpper(propertyName[0])) 96 else if (isASCIIUpper(propertyName[0]))
103 return CSSPropertyInvalid; 97 return CSSPropertyInvalid;
104 98
105 bool hasSeenUpper = isASCIIUpper(propertyName[i]); 99 bool hasSeenUpper = isASCIIUpper(propertyName[i]);
106 100
107 builder.append(toASCIILower(propertyName[i++])); 101 builder.append(toASCIILower(propertyName[i++]));
108 102
109 for (; i < length; ++i) { 103 for (; i < length; ++i) {
110 UChar c = propertyName[i]; 104 UChar c = propertyName[i];
(...skipping 18 matching lines...) Expand all
129 123
130 // When getting properties on CSSStyleDeclarations, the name used from 124 // When getting properties on CSSStyleDeclarations, the name used from
131 // Javascript and the actual name of the property are not the same, so 125 // 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 126 // we have to do the following translation. The translation turns upper
133 // case characters into lower case characters and inserts dashes to 127 // case characters into lower case characters and inserts dashes to
134 // separate words. 128 // separate words.
135 // 129 //
136 // Example: 'backgroundPositionY' -> 'background-position-y' 130 // Example: 'backgroundPositionY' -> 'background-position-y'
137 // 131 //
138 // Also, certain prefixes such as 'css-' are stripped. 132 // Also, certain prefixes such as 'css-' are stripped.
139 static CSSPropertyID cssPropertyInfo(v8::Local<v8::String> v8PropertyName, v8::I solate* isolate) 133 static CSSPropertyID cssPropertyInfo(v8::Local<v8::String> v8PropertyName)
140 { 134 {
141 String propertyName = toCoreString(v8PropertyName); 135 String propertyName = toCoreString(v8PropertyName);
142 typedef HashMap<String, CSSPropertyID> CSSPropertyIDMap; 136 typedef HashMap<String, CSSPropertyID> CSSPropertyIDMap;
143 DEFINE_STATIC_LOCAL(CSSPropertyIDMap, map, ()); 137 DEFINE_STATIC_LOCAL(CSSPropertyIDMap, map, ());
144 CSSPropertyIDMap::iterator iter = map.find(propertyName); 138 CSSPropertyIDMap::iterator iter = map.find(propertyName);
145 if (iter != map.end()) 139 if (iter != map.end())
146 return iter->value; 140 return iter->value;
147 141
148 CSSPropertyID unresolvedProperty = parseCSSPropertyID(isolate, propertyName) ; 142 CSSPropertyID unresolvedProperty = parseCSSPropertyID(propertyName);
149 map.add(propertyName, unresolvedProperty); 143 map.add(propertyName, unresolvedProperty);
150 ASSERT(!unresolvedProperty || CSSPropertyMetadata::isEnabledProperty(unresol vedProperty)); 144 ASSERT(!unresolvedProperty || CSSPropertyMetadata::isEnabledProperty(unresol vedProperty));
151 return unresolvedProperty; 145 return unresolvedProperty;
152 } 146 }
153 147
154 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall backInfo<v8::Array>& info) 148 void V8CSSStyleDeclaration::namedPropertyEnumeratorCustom(const v8::PropertyCall backInfo<v8::Array>& info)
155 { 149 {
156 typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector; 150 typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector;
157 DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ()); 151 DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ());
158 static unsigned propertyNamesLength = 0; 152 static unsigned propertyNamesLength = 0;
(...skipping 20 matching lines...) Expand all
179 173
180 v8SetReturnValue(info, properties); 174 v8SetReturnValue(info, properties);
181 } 175 }
182 176
183 void V8CSSStyleDeclaration::namedPropertyQueryCustom(v8::Local<v8::Name> v8Name, const v8::PropertyCallbackInfo<v8::Integer>& info) 177 void V8CSSStyleDeclaration::namedPropertyQueryCustom(v8::Local<v8::Name> v8Name, const v8::PropertyCallbackInfo<v8::Integer>& info)
184 { 178 {
185 if (!v8Name->IsString()) 179 if (!v8Name->IsString())
186 return; 180 return;
187 // NOTE: cssPropertyInfo lookups incur several mallocs. 181 // NOTE: cssPropertyInfo lookups incur several mallocs.
188 // Successful lookups have the same cost the first time, but are cached. 182 // Successful lookups have the same cost the first time, but are cached.
189 if (cssPropertyInfo(v8Name.As<v8::String>(), info.GetIsolate())) { 183 if (cssPropertyInfo(v8Name.As<v8::String>())) {
190 v8SetReturnValueInt(info, 0); 184 v8SetReturnValueInt(info, 0);
191 return; 185 return;
192 } 186 }
193 } 187 }
194 188
195 void V8CSSStyleDeclaration::namedPropertyGetterCustom(v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) 189 void V8CSSStyleDeclaration::namedPropertyGetterCustom(v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info)
196 { 190 {
197 // Search the style declaration. 191 // Search the style declaration.
198 CSSPropertyID unresolvedProperty = cssPropertyInfo(name.As<v8::String>(), in fo.GetIsolate()); 192 CSSPropertyID unresolvedProperty = cssPropertyInfo(name.As<v8::String>());
199 193
200 // Do not handle non-property names. 194 // Do not handle non-property names.
201 if (!unresolvedProperty) 195 if (!unresolvedProperty)
202 return; 196 return;
203 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty); 197 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty);
204 198
205 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); 199 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder());
206 // TODO(leviw): This API doesn't support custom properties. 200 // TODO(leviw): This API doesn't support custom properties.
207 RefPtrWillBeRawPtr<CSSValue> cssValue = impl->getPropertyCSSValueInternal(re solvedProperty); 201 RefPtrWillBeRawPtr<CSSValue> cssValue = impl->getPropertyCSSValueInternal(re solvedProperty);
208 if (cssValue) { 202 if (cssValue) {
209 v8SetReturnValueStringOrNull(info, cssValue->cssText(), info.GetIsolate( )); 203 v8SetReturnValueStringOrNull(info, cssValue->cssText(), info.GetIsolate( ));
210 return; 204 return;
211 } 205 }
212 206
213 String result = impl->getPropertyValueInternal(resolvedProperty); 207 String result = impl->getPropertyValueInternal(resolvedProperty);
214 v8SetReturnValueString(info, result, info.GetIsolate()); 208 v8SetReturnValueString(info, result, info.GetIsolate());
215 } 209 }
216 210
217 void V8CSSStyleDeclaration::namedPropertySetterCustom(v8::Local<v8::Name> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) 211 void V8CSSStyleDeclaration::namedPropertySetterCustom(v8::Local<v8::Name> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
218 { 212 {
219 if (!name->IsString()) 213 if (!name->IsString())
220 return; 214 return;
221 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); 215 CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder());
222 CSSPropertyID unresolvedProperty = cssPropertyInfo(name.As<v8::String>(), in fo.GetIsolate()); 216 CSSPropertyID unresolvedProperty = cssPropertyInfo(name.As<v8::String>());
223 if (!unresolvedProperty) 217 if (!unresolvedProperty)
224 return; 218 return;
225 219
226 TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, propertyValue, value) ; 220 TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, propertyValue, value) ;
227 ExceptionState exceptionState(ExceptionState::SetterContext, getPropertyName (resolveCSSPropertyID(unresolvedProperty)), "CSSStyleDeclaration", info.Holder() , info.GetIsolate()); 221 ExceptionState exceptionState(ExceptionState::SetterContext, getPropertyName (resolveCSSPropertyID(unresolvedProperty)), "CSSStyleDeclaration", info.Holder() , info.GetIsolate());
228 // TODO(leviw): This API doesn't support custom properties. 222 // TODO(leviw): This API doesn't support custom properties.
229 impl->setPropertyInternal(unresolvedProperty, String(), propertyValue, false , exceptionState); 223 impl->setPropertyInternal(unresolvedProperty, String(), propertyValue, false , exceptionState);
230 224
231 if (exceptionState.throwIfNeeded()) 225 if (exceptionState.throwIfNeeded())
232 return; 226 return;
233 227
234 v8SetReturnValue(info, value); 228 v8SetReturnValue(info, value);
235 } 229 }
236 230
237 } // namespace blink 231 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698