diff options
Diffstat (limited to 'WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp')
-rw-r--r-- | WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp | 95 |
1 files changed, 27 insertions, 68 deletions
diff --git a/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp b/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp index 0723410..3e68ce0 100644 --- a/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp +++ b/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,85 +30,48 @@ #include "CSSPrimitiveValue.h" #include "CSSStyleDeclaration.h" #include "CSSValue.h" +#include "DeprecatedString.h" #include "PlatformString.h" #include <kjs/string_object.h> -#include <wtf/ASCIICType.h> - -using namespace KJS; -using namespace WTF; namespace WebCore { -// Check for a CSS prefix. -// Passed prefix is all lowercase. -// First characters of property name may be upper or lowercase. -// Other characters in the prefix within the property name must be lowercase. -// The prefix within the property name must be followed by a capital letter. -static bool hasCSSPropertyNamePrefix(const Identifier& propertyName, const char* prefix) +using namespace KJS; + +static String cssPropertyName(const Identifier& propertyName, bool* hadPixelOrPosPrefix = 0) { -#ifndef NDEBUG - ASSERT(*prefix); - for (const char* p = prefix; *p; ++p) - ASSERT(isASCIILower(*p)); -#endif + DeprecatedString prop = propertyName; - unsigned length = propertyName.size(); - ASSERT(length); + int i = prop.length(); - if (toASCIILower(propertyName.data()[0].unicode()) != prefix[0]) - return false; + if (!i) + return prop; - for (unsigned i = 1; i < length; ++i) { - if (!prefix[i]) - return isASCIIUpper(propertyName.data()[i].unicode()); - if (propertyName.data()[0].unicode() != prefix[0]) - return false; + while (--i) { + ::UChar c = prop[i].unicode(); + if (c >= 'A' && c <= 'Z') + prop.insert(i, '-'); } - return false; -} -static String cssPropertyName(const Identifier& propertyName, bool* hadPixelOrPosPrefix = 0) -{ + prop = prop.lower(); + if (hadPixelOrPosPrefix) *hadPixelOrPosPrefix = false; - unsigned length = propertyName.size(); - if (!length) - return String(); - - Vector< ::UChar> name; - name.reserveCapacity(length); - - unsigned i = 0; - - if (hasCSSPropertyNamePrefix(propertyName, "css")) - i += 3; - else if (hasCSSPropertyNamePrefix(propertyName, "pixel")) { - i += 5; + if (prop.startsWith("css-")) + prop = prop.mid(4); + else if (prop.startsWith("pixel-")) { + prop = prop.mid(6); if (hadPixelOrPosPrefix) *hadPixelOrPosPrefix = true; - } else if (hasCSSPropertyNamePrefix(propertyName, "pos")) { - i += 3; + } else if (prop.startsWith("pos-")) { + prop = prop.mid(4); if (hadPixelOrPosPrefix) *hadPixelOrPosPrefix = true; - } else if (hasCSSPropertyNamePrefix(propertyName, "webkit") - || hasCSSPropertyNamePrefix(propertyName, "khtml") - || hasCSSPropertyNamePrefix(propertyName, "apple")) - name.append('-'); - - name.append(toASCIILower(propertyName.data()[i++].unicode())); - - for (; i < length; ++i) { - ::UChar c = propertyName.data()[i].unicode(); - if (!isASCIIUpper(c)) - name.append(c); - else { - name.append('-'); - name.append(toASCIILower(c)); - } - } + } else if (prop.startsWith("khtml-") || prop.startsWith("apple-") || prop.startsWith("webkit-")) + prop.insert(0, '-'); - return String::adopt(name); + return prop; } static bool isCSSPropertyName(const Identifier& propertyName) @@ -121,10 +84,7 @@ bool JSCSSStyleDeclaration::canGetItemsForName(ExecState*, CSSStyleDeclaration*, return isCSSPropertyName(propertyName); } -// FIXME: You can get these properties, and set them (see customPut below), -// but you should also be able to enumerate them. -JSValue* JSCSSStyleDeclaration::nameGetter(ExecState* exec, JSObject* originalObject, - const Identifier& propertyName, const PropertySlot& slot) +JSValue* JSCSSStyleDeclaration::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot) { JSCSSStyleDeclaration* thisObj = static_cast<JSCSSStyleDeclaration*>(slot.slotBase()); @@ -147,14 +107,13 @@ JSValue* JSCSSStyleDeclaration::nameGetter(ExecState* exec, JSObject* originalOb // Make the SVG 'filter' attribute undetectable, to avoid confusion with the IE 'filter' attribute. if (propertyName == "filter") - return new StringInstanceThatMasqueradesAsUndefined(exec->lexicalGlobalObject()->stringPrototype(), - thisObj->impl()->getPropertyValue(prop)); + return new StringInstanceThatMasqueradesAsUndefined(exec->lexicalGlobalObject()->stringPrototype(), thisObj->impl()->getPropertyValue(prop)); return jsString(thisObj->impl()->getPropertyValue(prop)); } -bool JSCSSStyleDeclaration::customPut(ExecState* exec, const Identifier& propertyName, JSValue* value) +bool JSCSSStyleDeclaration::customPut(ExecState* exec, const Identifier& propertyName, JSValue* value, int /*attr*/) { if (!isCSSPropertyName(propertyName)) return false; |