Changeset 30391 in webkit


Ignore:
Timestamp:
Feb 18, 2008, 5:12:12 PM (17 years ago)
Author:
Darin Adler
Message:

Reviewed by Sam.

  • bindings/js/JSCSSStyleDeclarationCustom.cpp: (WebCore::hasCSSPropertyNamePrefix): Added. (WebCore::cssPropertyName): Reimplement to not use DeprecatedString. Also made faster by using a Vector<UChar> and eliminating all the string operations.
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/WebCore/ChangeLog

    r30389 r30391  
     12008-02-18  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Sam.
     4
     5        * bindings/js/JSCSSStyleDeclarationCustom.cpp:
     6        (WebCore::hasCSSPropertyNamePrefix): Added.
     7        (WebCore::cssPropertyName): Reimplement to not use DeprecatedString. Also made faster
     8        by using a Vector<UChar> and eliminating all the string operations.
     9
    1102008-02-18  Stephanie Lewis  <slewis@apple.com>
    211
  • TabularUnified trunk/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp

    r29663 r30391  
    11/*
    2  * Copyright (C) 2007 Apple Inc. All rights reserved.
     2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3131#include "CSSStyleDeclaration.h"
    3232#include "CSSValue.h"
    33 #include "DeprecatedString.h"
    3433#include "PlatformString.h"
    3534#include <kjs/string_object.h>
     35#include <wtf/ASCIICType.h>
     36
     37using namespace KJS;
     38using namespace WTF;
    3639
    3740namespace WebCore {
    3841
    39 using namespace KJS;
     42// Check for a CSS prefix.
     43// Passed prefix is all lowercase.
     44// First characters of property name may be upper or lowercase.
     45// Other characters in the prefix within the property name must be lowercase.
     46// The prefix within the property name must be followed by a capital letter.
     47static bool hasCSSPropertyNamePrefix(const Identifier& propertyName, const char* prefix)
     48{
     49#ifndef NDEBUG
     50    ASSERT(*prefix);
     51    for (const char* p = prefix; *p; ++p)
     52        ASSERT(isASCIILower(*p));
     53#endif
     54
     55    unsigned length = propertyName.size();
     56    ASSERT(length);
     57
     58    if (toASCIILower(propertyName.data()[0].unicode()) != prefix[0])
     59        return false;
     60
     61    for (unsigned i = 1; i < length; ++i) {
     62        if (!prefix[i])
     63            return isASCIIUpper(propertyName.data()[i].unicode());
     64        if (propertyName.data()[0].unicode() != prefix[0])
     65            return false;
     66    }
     67    return false;
     68}
    4069
    4170static String cssPropertyName(const Identifier& propertyName, bool* hadPixelOrPosPrefix = 0)
    4271{
    43     DeprecatedString prop = propertyName;
    44 
    45     int i = prop.length();
    46 
    47     if (!i)
    48         return prop;
    49 
    50     while (--i) {
    51         ::UChar c = prop[i].unicode();
    52         if (c >= 'A' && c <= 'Z')
    53             prop.insert(i, '-');
    54     }
    55 
    56     prop = prop.lower();
    57 
    5872    if (hadPixelOrPosPrefix)
    5973        *hadPixelOrPosPrefix = false;
    6074
    61     if (prop.startsWith("css-"))
    62         prop = prop.mid(4);
    63     else if (prop.startsWith("pixel-")) {
    64         prop = prop.mid(6);
     75    unsigned length = propertyName.size();
     76    if (!length)
     77        return String();
     78
     79    Vector< ::UChar> name;
     80    name.reserveCapacity(length);
     81
     82    unsigned i = 0;
     83
     84    if (hasCSSPropertyNamePrefix(propertyName, "css"))
     85        i += 3;
     86    else if (hasCSSPropertyNamePrefix(propertyName, "pixel")) {
     87        i += 5;
    6588        if (hadPixelOrPosPrefix)
    6689            *hadPixelOrPosPrefix = true;
    67     } else if (prop.startsWith("pos-")) {
    68         prop = prop.mid(4);
     90    } else if (hasCSSPropertyNamePrefix(propertyName, "pos")) {
     91        i += 3;
    6992        if (hadPixelOrPosPrefix)
    7093            *hadPixelOrPosPrefix = true;
    71     } else if (prop.startsWith("khtml-") || prop.startsWith("apple-") || prop.startsWith("webkit-"))
    72         prop.insert(0, '-');
     94    } else if (hasCSSPropertyNamePrefix(propertyName, "webkit")
     95            || hasCSSPropertyNamePrefix(propertyName, "khtml")
     96            || hasCSSPropertyNamePrefix(propertyName, "apple"))
     97        name.append('-');
    7398
    74     return prop;
     99    name.append(toASCIILower(propertyName.data()[i++].unicode()));
     100
     101    for (; i < length; ++i) {
     102        ::UChar c = propertyName.data()[i].unicode();
     103        if (!isASCIIUpper(c))
     104            name.append(c);
     105        else {
     106            name.append('-');
     107            name.append(toASCIILower(c));
     108        }
     109    }
     110
     111    return String::adopt(name);
    75112}
    76113
     
    85122}
    86123
    87 JSValue* JSCSSStyleDeclaration::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
     124// FIXME: You can get these properties, and set them (see customPut below),
     125// but you should also be able the enumerate them.
     126JSValue* JSCSSStyleDeclaration::nameGetter(ExecState* exec, JSObject* originalObject,
     127    const Identifier& propertyName, const PropertySlot& slot)
    88128{
    89129    JSCSSStyleDeclaration* thisObj = static_cast<JSCSSStyleDeclaration*>(slot.slotBase());
     
    108148    // Make the SVG 'filter' attribute undetectable, to avoid confusion with the IE 'filter' attribute.
    109149    if (propertyName == "filter")
    110         return new StringInstanceThatMasqueradesAsUndefined(exec->lexicalGlobalObject()->stringPrototype(), thisObj->impl()->getPropertyValue(prop));
     150        return new StringInstanceThatMasqueradesAsUndefined(exec->lexicalGlobalObject()->stringPrototype(),
     151            thisObj->impl()->getPropertyValue(prop));
    111152
    112153    return jsString(thisObj->impl()->getPropertyValue(prop));
Note: See TracChangeset for help on using the changeset viewer.