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

Unified Diff: Source/core/css/CSSStyleDeclaration.cpp

Issue 15834008: Auto-generate V8CSSStyleDeclaration::namedPropertyGetter (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/css/CSSStyleDeclaration.cpp
diff --git a/Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp b/Source/core/css/CSSStyleDeclaration.cpp
similarity index 57%
copy from Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp
copy to Source/core/css/CSSStyleDeclaration.cpp
index 252a7f7fb2a116a59bfcb6f0f9136553eb030a70..07f70e0778df7d0a80d569ff609fad92816e5a30 100644
--- a/Source/bindings/v8/custom/V8CSSStyleDeclarationCustom.cpp
+++ b/Source/core/css/CSSStyleDeclaration.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007-2011 Google Inc. All rights reserved.
+ * Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -29,29 +29,18 @@
*/
#include "config.h"
-#include "V8CSSStyleDeclaration.h"
+#include "core/css/CSSStyleDeclaration.h"
-#include "CSSPropertyNames.h"
#include "core/css/CSSParser.h"
#include "core/css/CSSPrimitiveValue.h"
-#include "core/css/CSSStyleDeclaration.h"
+#include "core/css/CSSStyleSheet.h"
#include "core/css/CSSValue.h"
+#include "core/dom/Document.h"
+#include "core/dom/DocumentStyleSheetCollection.h"
#include "core/dom/EventTarget.h"
+#include "core/html/HTMLStyleElement.h"
#include "core/page/RuntimeCSSEnabled.h"
-#include "bindings/v8/V8Binding.h"
-
-#include "wtf/ASCIICType.h"
-#include "wtf/PassRefPtr.h"
-#include "wtf/RefPtr.h"
-#include "wtf/StdLibExtras.h"
-#include "wtf/Vector.h"
-#include "wtf/text/StringBuilder.h"
-#include "wtf/text/StringConcatenate.h"
-
-using namespace WTF;
-using namespace std;
-
namespace WebCore {
// FIXME: Next two functions look lifted verbatim from JSCSSStyleDeclarationCustom. Please remove duplication.
@@ -83,15 +72,9 @@ static bool hasCSSPropertyNamePrefix(const String& propertyName, const char* pre
return false;
}
-class CSSPropertyInfo {
-public:
- CSSPropertyID propID;
- bool hadPixelOrPosPrefix;
-};
-
// When getting properties on CSSStyleDeclarations, the name used from
// Javascript and the actual name of the property are not the same, so
-// we have to do the following translation. The translation turns upper
+// we have to do the following translation. The translation turns upper
// case characters into lower case characters and inserts dashes to
// separate words.
//
@@ -100,9 +83,8 @@ public:
// Also, certain prefixes such as 'pos', 'css-' and 'pixel-' are stripped
// and the hadPixelOrPosPrefix out parameter is used to indicate whether or
// not the property name was prefixed with 'pos-' or 'pixel-'.
-static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName)
+CSSPropertyInfo* CSSStyleDeclaration::cssPropertyInfo(const String& propertyName)
{
- String propertyName = toWebCoreString(v8PropertyName);
typedef HashMap<String, CSSPropertyInfo*> CSSPropertyInfoMap;
DEFINE_STATIC_LOCAL(CSSPropertyInfoMap, map, ());
CSSPropertyInfo* propInfo = map.get(propertyName);
@@ -154,91 +136,35 @@ static CSSPropertyInfo* cssPropertyInfo(v8::Handle<v8::String> v8PropertyName)
return propInfo;
}
-v8::Handle<v8::Array> V8CSSStyleDeclaration::namedPropertyEnumerator(const v8::AccessorInfo& info)
-{
- typedef Vector<String, numCSSProperties - 1> PreAllocatedPropertyVector;
- DEFINE_STATIC_LOCAL(PreAllocatedPropertyVector, propertyNames, ());
- static unsigned propertyNamesLength = 0;
-
- if (propertyNames.isEmpty()) {
- for (int id = firstCSSProperty; id <= lastCSSProperty; ++id) {
- CSSPropertyID propertyId = static_cast<CSSPropertyID>(id);
- if (RuntimeCSSEnabled::isCSSPropertyEnabled(propertyId))
- propertyNames.append(getJSPropertyName(propertyId));
- }
- sort(propertyNames.begin(), propertyNames.end(), codePointCompareLessThan);
- propertyNamesLength = propertyNames.size();
- }
-
- v8::Handle<v8::Array> properties = v8::Array::New(propertyNamesLength);
- for (unsigned i = 0; i < propertyNamesLength; ++i) {
- String key = propertyNames.at(i);
- ASSERT(!key.isNull());
- properties->Set(v8Integer(i, info.GetIsolate()), v8String(key, info.GetIsolate()));
- }
-
- return properties;
-}
-
-v8::Handle<v8::Integer> V8CSSStyleDeclaration::namedPropertyQuery(v8::Local<v8::String> v8Name, const v8::AccessorInfo& info)
+void CSSStyleDeclaration::anonymousNamedGetter(const AtomicString& name, bool& returnValue1Enabled, String& returnValue1, bool& returnValue2Enabled, float& returnValue2)
{
- // NOTE: cssPropertyInfo lookups incur several mallocs.
- // Successful lookups have the same cost the first time, but are cached.
- if (cssPropertyInfo(v8Name))
- return v8Integer(0, info.GetIsolate());
-
- return v8::Handle<v8::Integer>();
-}
-
-v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
-{
- // First look for API defined attributes on the style declaration object.
- if (info.Holder()->HasRealNamedCallbackProperty(name))
- return v8Undefined();
-
// Search the style declaration.
CSSPropertyInfo* propInfo = cssPropertyInfo(name);
// Do not handle non-property names.
if (!propInfo)
- return v8Undefined();
+ return;
- CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder());
- RefPtr<CSSValue> cssValue = imp->getPropertyCSSValueInternal(static_cast<CSSPropertyID>(propInfo->propID));
+ RefPtr<CSSValue> cssValue = getPropertyCSSValueInternal(static_cast<CSSPropertyID>(propInfo->propID));
if (cssValue) {
- if (propInfo->hadPixelOrPosPrefix &&
- cssValue->isPrimitiveValue()) {
- return v8::Number::New(static_cast<CSSPrimitiveValue*>(
- cssValue.get())->getFloatValue(CSSPrimitiveValue::CSS_PX));
+ if (propInfo->hadPixelOrPosPrefix && cssValue->isPrimitiveValue()) {
+ returnValue2Enabled = true;
+ returnValue2 = static_cast<CSSPrimitiveValue*>(cssValue.get())->getFloatValue(CSSPrimitiveValue::CSS_PX);
+ return;
}
- return v8StringOrNull(cssValue->cssText(), info.GetIsolate());
+ // TODO support treatnullas
+// return v8StringOrNull(cssValue->cssText(), info.GetIsolate());
haraken 2013/05/24 06:03:05 I think it is already supported by [TreatReturnedN
kojih 2013/05/24 06:11:19 Ah this is just my old memo. I'll remove this.
+ returnValue1Enabled = true;
+ returnValue1 = cssValue->cssText();
+ return;
}
- String result = imp->getPropertyValueInternal(static_cast<CSSPropertyID>(propInfo->propID));
+ String result = getPropertyValueInternal(static_cast<CSSPropertyID>(propInfo->propID));
if (result.isNull())
- result = ""; // convert null to empty string.
-
- return v8String(result, info.GetIsolate());
-}
-
-v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
-{
- CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder());
- CSSPropertyInfo* propInfo = cssPropertyInfo(name);
- if (!propInfo)
- return v8Undefined();
-
- String propertyValue = toWebCoreStringWithNullCheck(value);
- if (propInfo->hadPixelOrPosPrefix)
- propertyValue.append("px");
-
- ExceptionCode ec = 0;
- imp->setPropertyInternal(static_cast<CSSPropertyID>(propInfo->propID), propertyValue, false, ec);
-
- if (ec)
- setDOMException(ec, info.GetIsolate());
+ result = ""; // convert null to empty string.
- return value;
+ returnValue1 = result;
+ returnValue1Enabled = true;
}
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698