Reviewed by Sam.
- reduce use of DeprecatedString and memory allocations in processing of CSS
- remove unnecessary double -> float -> double trip in the CSS parser
- cleaned up names and structure in CSS grammar
* css/CSSGrammar.y: Remove getPropertyID and getValueID. Both are now in CSSParser.cpp
instead, and they now work on ParseString and String objects and don't require the caller
to put the string into a char*. Gave members of the %union more sensible names, removed
duplicates, and sorted into a logical order. Put the %expect back in, rather than leaving
it commented out.
* css/CSSParser.cpp:
(WebCore::equalIgnoringCase): Added.
(WebCore::hasPrefix): Added.
(WebCore::CSSParser::parseTransitionProperty): Changed to call the new cssPropertyID,
which obviates the need to call lower() and utf8() or to allocate memory at all. Also
used equalIgnoringCase rather than putting the value into a String just to compare it.
(WebCore::CSSParser::lex): Replaced convertASCIIToFloat with charactersToDouble. This change
along with the CSSGrammar.y change, removes the double -> float -> double round trip, and
affects the result of one layout test.
(WebCore::cssPropertyID): Added. Gets the property ID from the gperf hash table, but
without allocating any memory.
(WebCore::cssValueKeywordID): Ditto.
* css/CSSParser.h: Removed declaration for deprecatedString function (now used only in
CSSParser.cpp; soon to be deleted). Added cssPropertyID and cssValueKeywordID functions.
* css/CSSStyleDeclaration.cpp:
(WebCore::CSSStyleDeclaration::getPropertyCSSValue): Call cssPropertyID instead of propertyID.
(WebCore::CSSStyleDeclaration::getPropertyValue): Ditto.
(WebCore::CSSStyleDeclaration::getPropertyPriority): Ditto.
(WebCore::CSSStyleDeclaration::getPropertyShorthand): Ditto.
(WebCore::CSSStyleDeclaration::isPropertyImplicit): Ditto.
(WebCore::CSSStyleDeclaration::setProperty): Ditto.
(WebCore::CSSStyleDeclaration::removeProperty): Ditto.
(WebCore::CSSStyleDeclaration::isPropertyName): Ditto.
* css/CSSStyleDeclaration.h: Removed unnecessary includes, unnecessary Noncopyable boilerplate,
and the getPropertyID function declaration along with its associated apology comment.
* css/makevalues.pl: Generate constants instead of macros for CSS value numbers (but not an
enumeration, like properties, since you rarely have any reason to handle all values, but
often have a reason to handle all properties). Renamed the constant for the number of CSS
value keywords from CSS_VAL_TOTAL to numCSSValueKeywords, and added maxCSSValueKeywordLength.
* platform/text/String.cpp:
(WebCore::charactersToDouble): Made this function more efficient by using a stack buffer
rather than a CString.
LayoutTests:
Reviewed by Sam.
- generate new results for the one test that was altered by the
double -> float -> double trip taken by numeric values in the
CSS parser
This test appears under three different names in three different
parts of our test suite.
* platform/mac/css1/box_properties/acid_test-expected.checksum: Updated.
* platform/mac/css1/box_properties/acid_test-expected.png: Ditto.
* platform/mac/css1/box_properties/acid_test-expected.txt: Ditto.
* platform/mac/css2.1/t09-c5526c-display-00-e-expected.checksum: Ditto.
* platform/mac/css2.1/t09-c5526c-display-00-e-expected.png: Ditto.
* platform/mac/css2.1/t09-c5526c-display-00-e-expected.txt: Ditto.
* platform/mac/fast/block/basic/011-expected.checksum: Ditto.
* platform/mac/fast/block/basic/011-expected.png: Ditto.
* platform/mac/fast/block/basic/011-expected.txt: Ditto.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@30393
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2008-02-18 Darin Adler <darin@apple.com>
+
+ Reviewed by Sam.
+
+ - generate new results for the one test that was altered by the
+ double -> float -> double trip taken by numeric values in the
+ CSS parser
+
+ This test appears under three different names in three different
+ parts of our test suite.
+
+ * platform/mac/css1/box_properties/acid_test-expected.checksum: Updated.
+ * platform/mac/css1/box_properties/acid_test-expected.png: Ditto.
+ * platform/mac/css1/box_properties/acid_test-expected.txt: Ditto.
+ * platform/mac/css2.1/t09-c5526c-display-00-e-expected.checksum: Ditto.
+ * platform/mac/css2.1/t09-c5526c-display-00-e-expected.png: Ditto.
+ * platform/mac/css2.1/t09-c5526c-display-00-e-expected.txt: Ditto.
+ * platform/mac/fast/block/basic/011-expected.checksum: Ditto.
+ * platform/mac/fast/block/basic/011-expected.png: Ditto.
+ * platform/mac/fast/block/basic/011-expected.txt: Ditto.
+
2008-02-18 Dan Bernstein <mitz@apple.com>
- test for <rdar://problem/5736225> crash in svgFontAndFaceElementForFontData on digitalstrom.org/cms
-7b35526e2db3a84ab2cf05332f3c1c12
\ No newline at end of file
+1bf13919283ce2605db063e379040512
\ No newline at end of file
RenderBlock (anonymous) at (10,20) size 139x0
RenderInline {FORM} at (0,0) size 0x0
RenderText {#text} at (0,0) size 0x0
- RenderBlock (anonymous) at (10,20) size 139x38
- RenderBlock {P} at (0,0) size 139x19
+ RenderBlock (anonymous) at (10,20) size 139x40
+ RenderBlock {P} at (0,0) size 139x20
RenderText {#text} at (0,4) size 28x12
text run at (0,4) width 28: "bang "
RenderBlock {INPUT} at (31,3) size 12x13 [color=#000000]
RenderText {#text} at (0,0) size 0x0
- RenderBlock {P} at (0,19) size 139x19
+ RenderBlock {P} at (0,20) size 139x20
RenderText {#text} at (0,4) size 47x12
text run at (0,4) width 47: "whimper "
RenderBlock {INPUT} at (50,3) size 12x13 [color=#000000]
RenderText {#text} at (0,0) size 0x0
- RenderBlock (anonymous) at (10,58) size 139x0
+ RenderBlock (anonymous) at (10,60) size 139x0
RenderInline {FORM} at (0,0) size 0x0
RenderText {#text} at (0,0) size 0x0
RenderBlock (floating) {LI} at (259,0) size 80x120 [color=#000000] [bgcolor=#FFCC00] [border: (5px solid #000000)]
-25ed9975af1d56ff395d80fc87bacaac
\ No newline at end of file
+b1b10c7c970c0fde4b4424b4c4b147fc
\ No newline at end of file
RenderBlock (anonymous) at (10,20) size 139x0
RenderInline {FORM} at (0,0) size 0x0
RenderText {#text} at (0,0) size 0x0
- RenderBlock (anonymous) at (10,20) size 139x38
- RenderBlock {P} at (0,0) size 139x19
+ RenderBlock (anonymous) at (10,20) size 139x40
+ RenderBlock {P} at (0,0) size 139x20
RenderText {#text} at (0,4) size 28x12
text run at (0,4) width 28: "bang "
RenderBlock {INPUT} at (31,3) size 12x13 [color=#000000]
RenderText {#text} at (0,0) size 0x0
- RenderBlock {P} at (0,19) size 139x19
+ RenderBlock {P} at (0,20) size 139x20
RenderText {#text} at (0,4) size 47x12
text run at (0,4) width 47: "whimper "
RenderBlock {INPUT} at (50,3) size 12x13 [color=#000000]
RenderText {#text} at (0,0) size 0x0
- RenderBlock (anonymous) at (10,58) size 139x0
+ RenderBlock (anonymous) at (10,60) size 139x0
RenderInline {FORM} at (0,0) size 0x0
RenderText {#text} at (0,0) size 0x0
RenderBlock (floating) {LI} at (259,0) size 80x120 [color=#000000] [bgcolor=#FFCC00] [border: (5px solid #000000)]
-7b35526e2db3a84ab2cf05332f3c1c12
\ No newline at end of file
+1bf13919283ce2605db063e379040512
\ No newline at end of file
RenderBlock (anonymous) at (10,20) size 139x0
RenderInline {FORM} at (0,0) size 0x0
RenderText {#text} at (0,0) size 0x0
- RenderBlock (anonymous) at (10,20) size 139x38
- RenderBlock {P} at (0,0) size 139x19
+ RenderBlock (anonymous) at (10,20) size 139x40
+ RenderBlock {P} at (0,0) size 139x20
RenderText {#text} at (0,4) size 28x12
text run at (0,4) width 28: "bang "
RenderBlock {INPUT} at (31,3) size 12x13 [color=#000000]
RenderText {#text} at (0,0) size 0x0
- RenderBlock {P} at (0,19) size 139x19
+ RenderBlock {P} at (0,20) size 139x20
RenderText {#text} at (0,4) size 47x12
text run at (0,4) width 47: "whimper "
RenderBlock {INPUT} at (50,3) size 12x13 [color=#000000]
RenderText {#text} at (0,0) size 0x0
- RenderBlock (anonymous) at (10,58) size 139x0
+ RenderBlock (anonymous) at (10,60) size 139x0
RenderInline {FORM} at (0,0) size 0x0
RenderText {#text} at (0,0) size 0x0
RenderBlock (floating) {LI} at (259,0) size 80x120 [color=#000000] [bgcolor=#FFCC00] [border: (5px solid #000000)]
+2008-02-18 Darin Adler <darin@apple.com>
+
+ Reviewed by Sam.
+
+ - reduce use of DeprecatedString and memory allocations in processing of CSS
+ - remove unnecessary double -> float -> double trip in the CSS parser
+ - cleaned up names and structure in CSS grammar
+
+ * css/CSSGrammar.y: Remove getPropertyID and getValueID. Both are now in CSSParser.cpp
+ instead, and they now work on ParseString and String objects and don't require the caller
+ to put the string into a char*. Gave members of the %union more sensible names, removed
+ duplicates, and sorted into a logical order. Put the %expect back in, rather than leaving
+ it commented out.
+ * css/CSSParser.cpp:
+ (WebCore::equalIgnoringCase): Added.
+ (WebCore::hasPrefix): Added.
+ (WebCore::CSSParser::parseTransitionProperty): Changed to call the new cssPropertyID,
+ which obviates the need to call lower() and utf8() or to allocate memory at all. Also
+ used equalIgnoringCase rather than putting the value into a String just to compare it.
+ (WebCore::CSSParser::lex): Replaced convertASCIIToFloat with charactersToDouble. This change
+ along with the CSSGrammar.y change, removes the double -> float -> double round trip, and
+ affects the result of one layout test.
+ (WebCore::cssPropertyID): Added. Gets the property ID from the gperf hash table, but
+ without allocating any memory.
+ (WebCore::cssValueKeywordID): Ditto.
+ * css/CSSParser.h: Removed declaration for deprecatedString function (now used only in
+ CSSParser.cpp; soon to be deleted). Added cssPropertyID and cssValueKeywordID functions.
+
+ * css/CSSStyleDeclaration.cpp:
+ (WebCore::CSSStyleDeclaration::getPropertyCSSValue): Call cssPropertyID instead of propertyID.
+ (WebCore::CSSStyleDeclaration::getPropertyValue): Ditto.
+ (WebCore::CSSStyleDeclaration::getPropertyPriority): Ditto.
+ (WebCore::CSSStyleDeclaration::getPropertyShorthand): Ditto.
+ (WebCore::CSSStyleDeclaration::isPropertyImplicit): Ditto.
+ (WebCore::CSSStyleDeclaration::setProperty): Ditto.
+ (WebCore::CSSStyleDeclaration::removeProperty): Ditto.
+ (WebCore::CSSStyleDeclaration::isPropertyName): Ditto.
+ * css/CSSStyleDeclaration.h: Removed unnecessary includes, unnecessary Noncopyable boilerplate,
+ and the getPropertyID function declaration along with its associated apology comment.
+
+ * css/makevalues.pl: Generate constants instead of macros for CSS value numbers (but not an
+ enumeration, like properties, since you rarely have any reason to handle all values, but
+ often have a reason to handle all properties). Renamed the constant for the number of CSS
+ value keywords from CSS_VAL_TOTAL to numCSSValueKeywords, and added maxCSSValueKeywordLength.
+
+ * platform/text/String.cpp:
+ (WebCore::charactersToDouble): Made this function more efficient by using a stack buffer
+ rather than a CString.
+
2008-02-18 Dan Bernstein <mitz@apple.com>
Reviewed by Dave Hyatt.
%{
/*
- * This file is part of the KDE libraries
* Copyright (C) 2002-2003 Lars Knoll (knoll@kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
*
* This library is free software; you can redistribute it and/or
#include "CSSMediaRule.h"
#include "CSSParser.h"
-#include "CSSPrimitiveValue.h"
-#include "CSSRule.h"
#include "CSSRuleList.h"
#include "CSSSelector.h"
#include "CSSStyleSheet.h"
#include "Document.h"
#include "HTMLNames.h"
#include "MediaList.h"
-#include "MediaQuery.h"
-#include "MediaQueryExp.h"
-#include "PlatformString.h"
#include <stdlib.h>
#include <string.h>
using namespace WebCore;
using namespace HTMLNames;
-// The following file defines the function
-// const struct props *findProp(const char *word, int len)
-//
-// with 'props->id' a CSS property in the range from CSS_PROP_MIN to
-// (and including) CSS_PROP_TOTAL-1
-
-#include "CSSPropertyNames.c"
-#include "CSSValueKeywords.c"
-
-namespace WebCore {
-
-int getPropertyID(const char* tagStr, int len)
-{
- DeprecatedString prop;
-
- if (len && tagStr[0] == '-') {
- prop = DeprecatedString(tagStr, len);
- if (prop.startsWith("-apple-")) {
- prop = "-webkit-" + prop.mid(7);
- tagStr = prop.ascii();
- len++;
- } else if (prop.startsWith("-khtml-")) {
- prop = "-webkit-" + prop.mid(7);
- len++;
- tagStr = prop.ascii();
- }
-
- // Honor the use of old-style opacity (for Safari 1.1).
- if (prop == "-webkit-opacity") {
- const char * const opacity = "opacity";
- tagStr = opacity;
- len = strlen(opacity);
- }
- }
-
- const struct props* propsPtr = findProp(tagStr, len);
- if (!propsPtr)
- return 0;
-
- return propsPtr->id;
-}
-
-} // namespace WebCore
-
-static inline int getValueID(const char* tagStr, int len)
-{
- DeprecatedString prop;
- if (len && tagStr[0] == '-') {
- prop = DeprecatedString(tagStr, len);
- if (prop.startsWith("-apple-")) {
- prop = "-webkit-" + prop.mid(7);
- tagStr = prop.ascii();
- len++;
- } else if (prop.startsWith("-khtml-")) {
- prop = "-webkit-" + prop.mid(7);
- len++;
- tagStr = prop.ascii();
- }
- }
-
- const struct css_value* val = findValue(tagStr, len);
- if (!val)
- return 0;
-
- return val->id;
-}
-
#define YYENABLE_NLS 0
#define YYLTYPE_IS_TRIVIAL 1
#define YYMAXDEPTH 10000
#define YYDEBUG 0
+
// FIXME: Replace with %parse-param { CSSParser* parser } once we can depend on bison 2.x
#define YYPARSE_PARAM parser
%pure_parser
%union {
+ bool boolean;
+ char character;
+ int integer;
+ double number;
+ ParseString string;
+
CSSRule* rule;
- CSSSelector* selector;
- bool ok;
- MediaList *mediaList;
- CSSMediaRule* mediaRule;
CSSRuleList* ruleList;
- ParseString string;
- float val;
- int prop_id;
- int attribute;
+ CSSSelector* selector;
CSSSelector::Relation relation;
- bool b;
- int i;
- char tok;
- Value value;
- ValueList* valueList;
-
+ MediaList* mediaList;
MediaQuery* mediaQuery;
+ MediaQuery::Restrictor mediaQueryRestrictor;
MediaQueryExp* mediaQueryExp;
+ Value value;
+ ValueList* valueList;
Vector<MediaQueryExp*>* mediaQueryExpList;
- MediaQuery::Restrictor mediaQueryRestrictor;
}
%{
%}
-//%expect 37
+%expect 41
%left UNIMPORTANT_TOK
%token MEDIA_NOT
%token MEDIA_AND
-%token <val> QEMS
-%token <val> EMS
-%token <val> EXS
-%token <val> PXS
-%token <val> CMS
-%token <val> MMS
-%token <val> INS
-%token <val> PTS
-%token <val> PCS
-%token <val> DEGS
-%token <val> RADS
-%token <val> GRADS
-%token <val> MSECS
-%token <val> SECS
-%token <val> HERZ
-%token <val> KHERZ
+%token <number> QEMS
+%token <number> EMS
+%token <number> EXS
+%token <number> PXS
+%token <number> CMS
+%token <number> MMS
+%token <number> INS
+%token <number> PTS
+%token <number> PCS
+%token <number> DEGS
+%token <number> RADS
+%token <number> GRADS
+%token <number> MSECS
+%token <number> SECS
+%token <number> HERZ
+%token <number> KHERZ
%token <string> DIMEN
-%token <val> PERCENTAGE
-%token <val> FLOATTOKEN
-%token <val> INTEGER
+%token <number> PERCENTAGE
+%token <number> FLOATTOKEN
+%token <number> INTEGER
%token <string> URI
%token <string> FUNCTION
%type <ruleList> ruleset_list
-%type <prop_id> property
+%type <integer> property
%type <selector> specifier
%type <selector> specifier_list
%type <selector> attrib
%type <selector> pseudo
-%type <ok> declaration_list
-%type <ok> decl_list
-%type <ok> declaration
+%type <boolean> declaration_list
+%type <boolean> decl_list
+%type <boolean> declaration
-%type <b> prio
+%type <boolean> prio
-%type <i> match
-%type <i> unary_operator
-%type <tok> operator
+%type <integer> match
+%type <integer> unary_operator
+%type <character> operator
%type <valueList> expr
%type <value> term
media_query_exp_list:
media_query_exp {
- CSSParser* p = static_cast<CSSParser*>(parser);
- $$ = p->createFloatingMediaQueryExpList();
- $$->append(p->sinkFloatingMediaQueryExp($1));
+ CSSParser* p = static_cast<CSSParser*>(parser);
+ $$ = p->createFloatingMediaQueryExpList();
+ $$->append(p->sinkFloatingMediaQueryExp($1));
}
| media_query_exp_list media_query_exp {
- $$ = $1;
- $$->append(static_cast<CSSParser*>(parser)->sinkFloatingMediaQueryExp($2));
+ $$ = $1;
+ $$->append(static_cast<CSSParser*>(parser)->sinkFloatingMediaQueryExp($2));
}
;
property:
IDENT maybe_space {
- $1.lower();
- DeprecatedString str = deprecatedString($1);
- const char* s = str.ascii();
- int l = str.length();
- $$ = getPropertyID(s, l);
+ $$ = cssPropertyID($1);
}
;
| unary_operator unary_term { $$ = $2; $$.fValue *= $1; }
| STRING maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_STRING; }
| IDENT maybe_space {
- DeprecatedString str = deprecatedString($1);
- $$.id = getValueID(str.lower().latin1(), str.length());
+ $$.id = cssValueKeywordID($1);
$$.unit = CSSPrimitiveValue::CSS_IDENT;
$$.string = $1;
}
| UNICODERANGE maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_UNICODE_RANGE }
| hexcolor { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_RGBCOLOR; }
| '#' maybe_space { $$.id = 0; $$.string = ParseString(); $$.unit = CSSPrimitiveValue::CSS_RGBCOLOR; } /* Handle error case: "color: #;" */
-/* FIXME: according to the specs a function can have a unary_operator in front. I know no case where this makes sense */
+ /* FIXME: according to the specs a function can have a unary_operator in front. I know no case where this makes sense */
| function {
$$ = $1;
}
using namespace std;
using namespace WTF;
+#include "CSSPropertyNames.c"
+#include "CSSValueKeywords.c"
+
namespace WebCore {
+static bool equalIgnoringCase(const ParseString& a, const char* b)
+{
+ for (int i = 0; i < a.length; ++i) {
+ if (!b[i])
+ return false;
+ ASSERT(isASCIILower(b[i]));
+ if (toASCIILower(a.characters[i]) != b[i])
+ return false;
+ }
+ return !b[a.length];
+}
+
+static bool hasPrefix(const char* string, unsigned length, const char* prefix)
+{
+ for (unsigned i = 0; i < length; ++i) {
+ if (!prefix[i])
+ return true;
+ if (string[i] != prefix[i])
+ return false;
+ }
+ return false;
+}
+
ValueList::~ValueList()
{
size_t numValues = m_values.size();
PassRefPtr<CSSValue> CSSParser::parseTransitionProperty()
{
Value* value = valueList->current();
- if (value->unit == CSSPrimitiveValue::CSS_IDENT) {
- String str = domString(value->string);
- str.lower();
- if (str == "all")
- return new CSSPrimitiveValue(cAnimateAll);
- if (str == "none")
- return new CSSPrimitiveValue(cAnimateNone);
- CString propertyName = str.utf8();
- int result = getPropertyID(propertyName.data(), propertyName.length());
- if (result)
- return new CSSPrimitiveValue(result);
- }
+ if (value->unit != CSSPrimitiveValue::CSS_IDENT)
+ return 0;
+ int result = cssPropertyID(value->string);
+ if (result)
+ return new CSSPrimitiveValue(result);
+ if (equalIgnoringCase(value->string, "all"))
+ return new CSSPrimitiveValue(cAnimateAll);
+ if (equalIgnoringCase(value->string, "none"))
+ return new CSSPrimitiveValue(cAnimateNone);
return 0;
}
return true;
}
+static DeprecatedString deprecatedString(const ParseString& ps)
+{
+ return DeprecatedString(reinterpret_cast<const DeprecatedChar*>(ps.characters), ps.length);
+}
+
PassRefPtr<CSSValueList> CSSParser::parseFontFamily()
{
CSSValueList* list = new CSSValueList;
#include "CSSGrammar.h"
-static inline float convertASCIIToFloat(const UChar* characters, unsigned length)
-{
- Vector<char, 256> bytes(length + 1);
- for (unsigned i = 0; i < length; ++i)
- bytes[i] = characters[i];
- bytes[length] = 0;
- char* end;
- return narrowPrecisionToFloat(kjs_strtod(bytes.data(), &end));
-}
-
int CSSParser::lex(void* yylvalWithoutType)
{
YYSTYPE* yylval = static_cast<YYSTYPE*>(yylvalWithoutType);
length--;
case FLOATTOKEN:
case INTEGER:
- yylval->val = convertASCIIToFloat(t, length);
+ yylval->number = charactersToDouble(t, length);
break;
default:
return rule;
}
-DeprecatedString deprecatedString(const ParseString& ps)
+static int cssPropertyID(const UChar* propertyName, unsigned length)
{
- return DeprecatedString(reinterpret_cast<const DeprecatedChar*>(ps.characters), ps.length);
+ if (!length)
+ return 0;
+ if (length > maxCSSPropertyNameLength)
+ return 0;
+
+ char buffer[maxCSSPropertyNameLength + 1 + 1]; // 1 to turn "apple"/"khtml" into "webkit", 1 for null character
+
+ for (unsigned i = 0; i != length; ++i) {
+ UChar c = propertyName[i];
+ if (c == 0 || c >= 0x7F)
+ return 0; // illegal character
+ buffer[i] = toASCIILower(c);
+ }
+ buffer[length] = '\0';
+
+ const char* name = buffer;
+ if (buffer[0] == '-') {
+ // If the prefix is -apple- or -khtml-, change it to -webkit-.
+ // This makes the string one character longer.
+ if (hasPrefix(buffer, length, "-apple-") || hasPrefix(buffer, length, "-khtml-")) {
+ memmove(buffer + 7, buffer + 6, length + 1 - 6);
+ memcpy(buffer, "-webkit", 7);
+ ++length;
+ }
+
+ // Honor -webkit-opacity as a synonym for opacity.
+ // This was the only syntax that worked in Safari 1.1, and may be in use on some websites and widgets.
+ if (strcmp(buffer, "-webkit-opacity") == 0) {
+ const char * const opacity = "opacity";
+ name = opacity;
+ length = strlen(opacity);
+ }
+ }
+
+ const props* hashTableEntry = findProp(name, length);
+ return hashTableEntry ? hashTableEntry->id : 0;
+}
+
+int cssPropertyID(const String& string)
+{
+ return cssPropertyID(string.characters(), string.length());
+}
+
+int cssPropertyID(const ParseString& string)
+{
+ return cssPropertyID(string.characters, string.length);
+}
+
+int cssValueKeywordID(const ParseString& string)
+{
+ unsigned length = string.length;
+ if (!length)
+ return 0;
+ if (length > maxCSSValueKeywordLength)
+ return 0;
+
+ char buffer[maxCSSValueKeywordLength + 1 + 1]; // 1 to turn "apple"/"khtml" into "webkit", 1 for null character
+
+ for (unsigned i = 0; i != length; ++i) {
+ UChar c = string.characters[i];
+ if (c == 0 || c >= 0x7F)
+ return 0; // illegal character
+ buffer[i] = WTF::toASCIILower(c);
+ }
+ buffer[length] = '\0';
+
+ if (buffer[0] == '-') {
+ // If the prefix is -apple- or -khtml-, change it to -webkit-.
+ // This makes the string one character longer.
+ if (hasPrefix(buffer, length, "-apple-") || hasPrefix(buffer, length, "-khtml-")) {
+ memmove(buffer + 7, buffer + 6, length + 1 - 6);
+ memcpy(buffer, "-webkit", 7);
+ ++length;
+ }
+ }
+
+ const css_value* hashTableEntry = findValue(buffer, length);
+ return hashTableEntry ? hashTableEntry->id : 0;
}
#define YY_DECL int CSSParser::lex()
/*
- * This file is part of the DOM implementation for KDE.
- *
* Copyright (C) 2003 Lars Knoll (knoll@kde.org)
- * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
+ * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
int unit;
};
- DeprecatedString deprecatedString(const ParseString&);
-
static inline String domString(const ParseString& ps)
{
return String(ps.characters, ps.length);
friend class TransformOperationInfo;
};
+ int cssPropertyID(const ParseString&);
+ int cssPropertyID(const String&);
+ int cssValueKeywordID(const ParseString&);
+
} // namespace WebCore
#endif // CSSParser_h
-/**
+/*
* (C) 1999-2003 Lars Knoll (knoll@kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
#include "CSSStyleDeclaration.h"
#include "CSSMutableStyleDeclaration.h"
+#include "CSSParser.h"
#include "CSSProperty.h"
#include "CSSPropertyNames.h"
#include "CSSRule.h"
namespace WebCore {
-static int propertyID(const String& s)
-{
- char buffer[maxCSSPropertyNameLength];
-
- unsigned len = s.length();
- if (len > maxCSSPropertyNameLength)
- return 0;
-
- for (unsigned i = 0; i != len; ++i) {
- UChar c = s[i];
- if (c == 0 || c >= 0x7F)
- return 0; // illegal character
- buffer[i] = toASCIILower(c);
- }
-
- return getPropertyID(buffer, len);
-}
-
CSSStyleDeclaration::CSSStyleDeclaration(CSSRule* parent)
: StyleBase(parent)
{
PassRefPtr<CSSValue> CSSStyleDeclaration::getPropertyCSSValue(const String& propertyName)
{
- int propID = propertyID(propertyName);
+ int propID = cssPropertyID(propertyName);
if (!propID)
return 0;
return getPropertyCSSValue(propID);
String CSSStyleDeclaration::getPropertyValue(const String &propertyName)
{
- int propID = propertyID(propertyName);
+ int propID = cssPropertyID(propertyName);
if (!propID)
return String();
return getPropertyValue(propID);
String CSSStyleDeclaration::getPropertyPriority(const String& propertyName)
{
- int propID = propertyID(propertyName);
+ int propID = cssPropertyID(propertyName);
if (!propID)
return String();
return getPropertyPriority(propID) ? "important" : "";
String CSSStyleDeclaration::getPropertyShorthand(const String& propertyName)
{
- int propID = propertyID(propertyName);
+ int propID = cssPropertyID(propertyName);
if (!propID)
return String();
int shorthandID = getPropertyShorthand(propID);
bool CSSStyleDeclaration::isPropertyImplicit(const String& propertyName)
{
- int propID = propertyID(propertyName);
+ int propID = cssPropertyID(propertyName);
if (!propID)
return false;
return isPropertyImplicit(propID);
void CSSStyleDeclaration::setProperty(const String& propertyName, const String& value, const String& priority, ExceptionCode& ec)
{
- int propID = propertyID(propertyName);
- if (!propID)
- // FIXME: set exception?
+ int propID = cssPropertyID(propertyName);
+ if (!propID) {
+ // FIXME: Should we raise an exception here?
return;
+ }
bool important = priority.find("important", 0, false) != -1;
setProperty(propID, value, important, ec);
}
String CSSStyleDeclaration::removeProperty(const String& propertyName, ExceptionCode& ec)
{
- int propID = propertyID(propertyName);
+ int propID = cssPropertyID(propertyName);
if (!propID)
return String();
return removeProperty(propID, ec);
bool CSSStyleDeclaration::isPropertyName(const String& propertyName)
{
- return propertyID(propertyName);
+ return cssPropertyID(propertyName);
}
CSSRule* CSSStyleDeclaration::parentRule() const
/*
- * This file is part of the DOM implementation for KDE.
- *
* (C) 1999-2003 Lars Knoll (knoll@kde.org)
- * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
+ * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
#define CSSStyleDeclaration_h
#include "StyleBase.h"
-#include <wtf/PassRefPtr.h>
+#include <wtf/Forward.h>
namespace WebCore {
protected:
CSSStyleDeclaration(CSSRule* parentRule = 0);
-
-private:
- CSSStyleDeclaration(const CSSStyleDeclaration&);
- CSSStyleDeclaration& operator=(const CSSStyleDeclaration&);
};
-// Defined in CSSGrammar.y, but not in any header.
-// We have poor control over CSSGrammar.h generation, so just define it here for others to use.
-int getPropertyID(const char* str, int len);
-
} // namespace WebCore
#endif // CSSStyleDeclaration_h
print HEADER << "EOF";
/* This file is automatically generated from CSSValueKeywords.in by makevalues, do not edit */
-#ifndef CSSVALUES_H
-#define CSSVALUES_H
+#ifndef CSSValues_h
+#define CSSValues_h
-WebCore::String getValueName(unsigned short id);
-
-#define CSS_VAL_INVALID 0
-#define CSS_VAL_MIN 1
+const int CSS_VAL_INVALID = 0;
EOF
my $i = 1;
foreach my $name (@names) {
my $id = $name;
$id =~ s/-/_/g;
- print HEADER "#define CSS_VAL_" . uc($id) . " " . $i . "\n";
+ print HEADER "const int CSS_VAL_" . uc($id) . " = " . $i . ";\n";
$i = $i + 1;
if (length($name) > $maxLen) {
$maxLen = length($name);
}
}
-print HEADER "#define CSS_VAL_TOTAL " . $i . "\n";
-print HEADER "#endif\n";
+print HEADER "const int numCSSValueKeywords = " . $i . ";\n";
+print HEADER "const size_t maxCSSValueKeywordLength = " . $maxLen . ";\n";
+print HEADER << "EOF";
+
+const char* getValueName(unsigned short id);
+
+#endif
+EOF
close HEADER;
system("gperf -L ANSI-C -E -C -n -o -t --key-positions=\"*\" -NfindValue -Hhash_val -Wwordlist_value -D CSSValueKeywords.gperf > CSSValueKeywords.c");
print C << "EOF";
0
};
-String getValueName(unsigned short id)
+const char* getValueName(unsigned short id)
{
- if (id >= CSS_VAL_TOTAL || id <= 0)
- return String();
- return String(valueList[id]);
+ if (id >= numCSSValueKeywords || id <= 0)
+ return 0;
+ return valueList[id];
}
EOF
close C;
-
return 0.0;
}
- // FIXME: This should be made more efficient by using a fixed-sized stack buffer
- // to avoid the allocation.
+ Vector<char, 256> bytes(length + 1);
+ for (unsigned i = 0; i < length; ++i)
+ bytes[i] = data[i] < 0x7F ? data[i] : '?';
+ bytes[length] = '\0';
char* end;
- CString latin1String = Latin1Encoding().encode(data, length);
- double val = kjs_strtod(latin1String.data(), &end);
+ double val = kjs_strtod(bytes.data(), &end);
if (ok)
*ok = (end == 0 || *end == '\0');
return val;
#include "CString.h"
#include "CSSFontFaceRule.h"
#include "CSSFontFaceSrcValue.h"
+#include "CSSParser.h"
#include "CSSProperty.h"
#include "CSSPropertyNames.h"
#include "CSSStyleSelector.h"
{
}
-static inline void mapAttributeToCSSProperty(HashMap<AtomicStringImpl*, int>* propertyNameToIdMap, const QualifiedName& attrName, const char* cssPropertyName = 0)
+static void mapAttributeToCSSProperty(HashMap<AtomicStringImpl*, int>* propertyNameToIdMap, const QualifiedName& attrName)
{
- int propertyId = 0;
- if (cssPropertyName)
- propertyId = getPropertyID(cssPropertyName, strlen(cssPropertyName));
- else {
- CString propertyName = attrName.localName().domString().utf8();
- propertyId = getPropertyID(propertyName.data(), propertyName.length());
- }
- if (propertyId < 1)
- fprintf(stderr, "Failed to find property: %s\n", attrName.localName().domString().utf8().data());
+ int propertyId = cssPropertyID(attrName.localName());
ASSERT(propertyId > 0);
propertyNameToIdMap->set(attrName.localName().impl(), propertyId);
}
Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
2004, 2005, 2007 Rob Buis <buis@kde.org>
- This file is part of the KDE project
-
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
*/
#include "config.h"
-
#if ENABLE(SVG)
#include "SVGStyledElement.h"
#include "Attr.h"
+#include "CSSParser.h"
#include "CSSStyleSelector.h"
#include "CString.h"
#include "Document.h"
return false;
}
-static inline void mapAttributeToCSSProperty(HashMap<AtomicStringImpl*, int>* propertyNameToIdMap, const QualifiedName& attrName, const char* cssPropertyName = 0)
+static void mapAttributeToCSSProperty(HashMap<AtomicStringImpl*, int>* propertyNameToIdMap, const QualifiedName& attrName)
{
- int propertyId = 0;
- if (cssPropertyName)
- propertyId = getPropertyID(cssPropertyName, strlen(cssPropertyName));
- else {
- CString propertyName = attrName.localName().domString().utf8();
- propertyId = getPropertyID(propertyName.data(), propertyName.length());
- }
+ int propertyId = cssPropertyID(attrName.localName());
ASSERT(propertyId > 0);
propertyNameToIdMap->set(attrName.localName().impl(), propertyId);
}