[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

rjw rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:53:04 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit d22930a0d6578cb5dee0e08a293c68a071817039
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Jul 28 20:43:31 2004 +0000

            We're changing the way color is specified as a parameter in the
            <canvas> API.  Colors are now specified using the CSS color
            functions (or old style names or "#").  For example
            'context.setStrokeColor ("rgba(128,128,128,0.5)")'.  Most of the
            patch is cleanup of duplicated code in cssparser.cpp and a new
            static function that'll crank up the CSS parser to parse the
            color. This patch leaves the old mechanisms in place for now, so
            we don't break any existing gadgets.
    
            Reviewed by John.
    
            * WebCore.pbproj/project.pbxproj:
            * khtml/css/cssparser.cpp:
            (CSSParser::CSSParser):
            (CSSParser::setupParser):
            (CSSParser::parseSheet):
            (CSSParser::parseRule):
            (CSSParser::parseValue):
            (CSSParser::parseColor):
            (CSSParser::parseDeclaration):
            * khtml/css/cssparser.h:
            * khtml/ecma/kjs_html.cpp:
            (KJS::Context2DFunction::tryCall):
    
            * kwq/KWQColor.h:
            (QColor::alpha):
    	Added alpha() function to QColor, use instead of quirky
    	qAlpha() global function.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@7144 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index b086a64..f460673 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,34 @@
+2004-07-28  Richard Williamson   <rjw at apple.com>
+
+        We're changing the way color is specified as a parameter in the
+        <canvas> API.  Colors are now specified using the CSS color
+        functions (or old style names or "#").  For example
+        'context.setStrokeColor ("rgba(128,128,128,0.5)")'.  Most of the
+        patch is cleanup of duplicated code in cssparser.cpp and a new
+        static function that'll crank up the CSS parser to parse the
+        color. This patch leaves the old mechanisms in place for now, so
+        we don't break any existing gadgets.
+
+        Reviewed by John.
+
+        * WebCore.pbproj/project.pbxproj:
+        * khtml/css/cssparser.cpp:
+        (CSSParser::CSSParser):
+        (CSSParser::setupParser):
+        (CSSParser::parseSheet):
+        (CSSParser::parseRule):
+        (CSSParser::parseValue):
+        (CSSParser::parseColor):
+        (CSSParser::parseDeclaration):
+        * khtml/css/cssparser.h:
+        * khtml/ecma/kjs_html.cpp:
+        (KJS::Context2DFunction::tryCall):
+
+        * kwq/KWQColor.h:
+        (QColor::alpha):
+	Added alpha() function to QColor, use instead of quirky
+	qAlpha() global function.
+
 2004-07-28  Ken Kocienda  <kocienda at apple.com>
 
         Reviewed by Trey
diff --git a/WebCore/WebCore.pbproj/project.pbxproj b/WebCore/WebCore.pbproj/project.pbxproj
index 20cbeb1..8acc777 100644
--- a/WebCore/WebCore.pbproj/project.pbxproj
+++ b/WebCore/WebCore.pbproj/project.pbxproj
@@ -13,7 +13,7 @@
 				GCC_ENABLE_FIX_AND_CONTINUE = YES;
 				GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
 				GCC_OPTIMIZATION_LEVEL = 0;
-				INSTALL_PATH = "@executable_path/../Frameworks";
+				INSTALL_PATH_MODIFIED_BY_SCRIPT_DO_NOT_COMMIT = "@executable_path/../Frameworks";
 				OPTIMIZATION_CFLAGS = "-O0";
 				OTHER_LDFLAGS = "-seg1addr $(LOCAL_SEG1_ADDR)";
 				SECTORDER_FLAGS = "";
@@ -25,7 +25,7 @@
 		014CEA450018CDF011CA2923 = {
 			buildSettings = {
 				COPY_PHASE_STRIP = YES;
-				INSTALL_PATH = "@executable_path/../Frameworks";
+				INSTALL_PATH_MODIFIED_BY_SCRIPT_DO_NOT_COMMIT = "@executable_path/../Frameworks";
 				OTHER_LDFLAGS = "-seg1addr $(LOCAL_SEG1_ADDR)";
 				SECTORDER_FLAGS = "";
 			};
@@ -142,7 +142,7 @@
 				FRAMEWORK_VERSION = A;
 				GCC_TREAT_WARNINGS_AS_ERRORS = YES;
 				HEADER_SEARCH_PATHS = "ForwardingHeaders /usr/include/libxml2";
-				INSTALL_PATH = /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks;
+				INSTALL_PATH_MODIFIED_BY_SCRIPT_DO_NOT_COMMIT = /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks;
 				LIBRARY_SEARCH_PATHS = "";
 				LOCAL_SEG1_ADDR = 0x9000000;
 				MACOSX_DEPLOYMENT_TARGET = 10.2;
@@ -10231,7 +10231,7 @@
 		F58C8A07025BD3BC018635CA = {
 			buildSettings = {
 				GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
-				INSTALL_PATH = "@executable_path/../Frameworks";
+				INSTALL_PATH_MODIFIED_BY_SCRIPT_DO_NOT_COMMIT = "@executable_path/../Frameworks";
 				OTHER_LDFLAGS = "-seg1addr $(LOCAL_SEG1_ADDR)";
 				SECTORDER_FLAGS = "";
 			};
diff --git a/WebCore/khtml/css/cssparser.cpp b/WebCore/khtml/css/cssparser.cpp
index 17c047e..86ce8bd 100644
--- a/WebCore/khtml/css/cssparser.cpp
+++ b/WebCore/khtml/css/cssparser.cpp
@@ -35,6 +35,7 @@
 #include "cssproperties.h"
 #include "cssvalues.h"
 #include "misc/helper.h"
+#include "xml/dom_docimpl.h"
 #include "csshelper.h"
 using namespace DOM;
 
@@ -95,6 +96,7 @@ CSSParser::CSSParser( bool strictParsing )
     numParsedProperties = 0;
     maxParsedProperties = 32;
 
+    data = 0;
     valueList = 0;
     rule = 0;
     id = 0;
@@ -133,21 +135,36 @@ void ParseString::lower()
         string[i] = QChar(string[i]).lower().unicode();
 }
 
-void CSSParser::parseSheet( CSSStyleSheetImpl *sheet, const DOMString &string )
+void CSSParser::setupParser(const char *prefix, const DOMString &string, const char *suffix)
 {
-    styleElement = sheet;
-    defaultNamespace = anyNamespace; // Reset the default namespace.
+    int length = string.length() + strlen(prefix) + strlen(suffix) + 2;
     
-    int length = string.length() + 3;
     data = (unsigned short *)malloc( length *sizeof( unsigned short ) );
-    memcpy( data, string.unicode(), string.length()*sizeof( unsigned short) );
+    for ( unsigned int i = 0; i < strlen(prefix); i++ )
+	data[i] = prefix[i];
+    
+    memcpy( data + strlen( prefix ), string.unicode(), string.length()*sizeof( unsigned short) );
+
+    unsigned int start = strlen( prefix ) + string.length();
+    unsigned int end = start + strlen(suffix);
+    for ( unsigned int i = start; i < end; i++ )
+        data[i] = suffix[i-start];
+
     data[length-1] = 0;
     data[length-2] = 0;
-    data[length-3] = ' ';
+
     yy_hold_char = 0;
     yyleng = 0;
     yytext = yy_c_buf_p = data;
     yy_hold_char = *yy_c_buf_p;
+}
+
+void CSSParser::parseSheet( CSSStyleSheetImpl *sheet, const DOMString &string )
+{
+    styleElement = sheet;
+    defaultNamespace = anyNamespace; // Reset the default namespace.
+    
+    setupParser ("", string, "");
 
 #ifdef CSS_DEBUG
     kdDebug( 6080 ) << ">>>>>>> start parsing style sheet" << endl;
@@ -168,21 +185,7 @@ CSSRuleImpl *CSSParser::parseRule( DOM::CSSStyleSheetImpl *sheet, const DOM::DOM
 {
     styleElement = sheet;
     
-    const char khtml_rule[] = "@-khtml-rule{";
-    int length = string.length() + 4 + strlen(khtml_rule);
-    data = (unsigned short *)malloc( length *sizeof( unsigned short ) );
-    for ( unsigned int i = 0; i < strlen(khtml_rule); i++ )
-	data[i] = khtml_rule[i];
-    memcpy( data + strlen( khtml_rule ), string.unicode(), string.length()*sizeof( unsigned short) );
-    // qDebug("parse string = '%s'", QConstString( (const QChar *)data, length ).string().latin1() );
-    data[length-1] = 0;
-    data[length-2] = 0;
-    data[length-3] = ' ';
-    data[length-4] = '}';
-    yy_hold_char = 0;
-    yyleng = 0;
-    yytext = yy_c_buf_p = data;
-    yy_hold_char = *yy_c_buf_p;
+    setupParser ("@-khtml-rule{", string, "} ");
 
     CSSParser *old = currentParser;
     currentParser = this;
@@ -205,21 +208,7 @@ bool CSSParser::parseValue( DOM::CSSStyleDeclarationImpl *declaration, int _id,
 
     styleElement = declaration->stylesheet();
 
-    const char khtml_value[] = "@-khtml-value{";
-    int length = string.length() + 4 + strlen(khtml_value);
-    data = (unsigned short *)malloc( length *sizeof( unsigned short ) );
-    for ( unsigned int i = 0; i < strlen(khtml_value); i++ )
-	data[i] = khtml_value[i];
-    memcpy( data + strlen( khtml_value ), string.unicode(), string.length()*sizeof( unsigned short) );
-    data[length-1] = 0;
-    data[length-2] = 0;
-    data[length-3] = ' ';
-    data[length-4] = '}';
-    // qDebug("parse string = '%s'", QConstString( (const QChar *)data, length ).string().latin1() );
-    yy_hold_char = 0;
-    yyleng = 0;
-    yytext = yy_c_buf_p = data;
-    yy_hold_char = *yy_c_buf_p;
+    setupParser ("@-khtml-value{", string, "} ");
 
     id = _id;
     important = _important;
@@ -245,6 +234,57 @@ bool CSSParser::parseValue( DOM::CSSStyleDeclarationImpl *declaration, int _id,
     return ok;
 }
 
+QRgb CSSParser::parseColor( const DOM::DOMString &string )
+{
+    QRgb color = 0;
+    DOM::CSSStyleDeclarationImpl *dummyStyleDeclaration = new DOM::CSSStyleDeclarationImpl(0);
+    
+    dummyStyleDeclaration->ref();
+
+    DOM::CSSParser parser(true);
+
+    // First try creating a color specified by name or the "#" syntax.
+    if (!parser.parseColor(string.string(), color)) {
+    
+        // Now try to create a color from the rgb() or rgba() syntax.
+        bool ok = parser.parseColor(dummyStyleDeclaration, string);
+        if ( ok ) {
+            CSSValueImpl *value = parser.parsedProperties[0]->value();
+            if (value->cssValueType() == DOM::CSSValue::CSS_PRIMITIVE_VALUE) {
+                DOM::CSSPrimitiveValueImpl *primitiveValue = static_cast<DOM::CSSPrimitiveValueImpl *>(value);
+                color = primitiveValue->getRGBColorValue();
+            }
+        }
+    
+    }
+    
+    dummyStyleDeclaration->deref();
+    
+    return color;
+}
+
+bool CSSParser::parseColor( DOM::CSSStyleDeclarationImpl *declaration, const DOM::DOMString &string )
+{
+    styleElement = declaration->stylesheet();
+
+    setupParser ( "@-khtml-decls{color:", string, "} ");
+
+    CSSParser *old = currentParser;
+    currentParser = this;
+    cssyyparse( this );
+    currentParser = old;
+
+    delete rule;
+    rule = 0;
+
+    bool ok = false;
+    if ( numParsedProperties && parsedProperties[0]->m_id == CSS_PROP_COLOR) {
+	ok = true;
+    }
+
+    return ok;
+}
+
 bool CSSParser::parseDeclaration( DOM::CSSStyleDeclarationImpl *declaration, const DOM::DOMString &string )
 {
 #ifdef CSS_DEBUG
@@ -253,21 +293,7 @@ bool CSSParser::parseDeclaration( DOM::CSSStyleDeclarationImpl *declaration, con
 
     styleElement = declaration->stylesheet();
 
-    const char khtml_decls[] = "@-khtml-decls{";
-    int length = string.length() + 4 + strlen(khtml_decls);
-    data = (unsigned short *)malloc( length *sizeof( unsigned short ) );
-    for ( unsigned int i = 0; i < strlen(khtml_decls); i++ )
-	data[i] = khtml_decls[i];
-    memcpy( data + strlen( khtml_decls ), string.unicode(), string.length()*sizeof( unsigned short) );
-    data[length-1] = 0;
-    data[length-2] = 0;
-    data[length-3] = ' ';
-    data[length-4] = '}';
-    // qDebug("parse string = '%s'", QConstString( (const QChar *)data, length ).string().latin1() );
-    yy_hold_char = 0;
-    yyleng = 0;
-    yytext = yy_c_buf_p = data;
-    yy_hold_char = *yy_c_buf_p;
+    setupParser ( "@-khtml-decls{", string, "} ");
 
     CSSParser *old = currentParser;
     currentParser = this;
@@ -290,6 +316,7 @@ bool CSSParser::parseDeclaration( DOM::CSSStyleDeclarationImpl *declaration, con
     return ok;
 }
 
+
 void CSSParser::addProperty( int propId, CSSValueImpl *value, bool important )
 {
     CSSProperty *prop = new CSSProperty;
diff --git a/WebCore/khtml/css/cssparser.h b/WebCore/khtml/css/cssparser.h
index e2b4b35..3e80f66 100644
--- a/WebCore/khtml/css/cssparser.h
+++ b/WebCore/khtml/css/cssparser.h
@@ -34,6 +34,7 @@ namespace DOM {
     class CSSRuleImpl;
     class CSSStyleRuleImpl;
     class DocumentImpl;
+    class NodeImpl;
     class CSSValueImpl;
     class CSSValueListImpl;
     class CSSPrimitiveValueImpl;
@@ -110,6 +111,8 @@ namespace DOM {
 	DOM::CSSRuleImpl *parseRule( DOM::CSSStyleSheetImpl *sheet, const DOM::DOMString &string );
 	bool parseValue( DOM::CSSStyleDeclarationImpl *decls, int id, const DOM::DOMString &string,
 			 bool _important );
+        static QRgb CSSParser::parseColor( const DOM::DOMString &string );
+	bool parseColor( DOM::CSSStyleDeclarationImpl *declaration, const DOM::DOMString &string );
 	bool parseDeclaration( DOM::CSSStyleDeclarationImpl *decls, const DOM::DOMString &string );
 
 	static CSSParser *current() { return currentParser; }
@@ -160,8 +163,10 @@ namespace DOM {
 	int token() { return yyTok; }
 	unsigned short *text( int *length);
 	int lex();
+        
     private:
-
+        void setupParser(const char *prefix, const DOMString &string, const char *suffix);
+        
 	unsigned short *data;
 	unsigned short *yytext;
 	unsigned short *yy_c_buf_p;
diff --git a/WebCore/khtml/ecma/kjs_html.cpp b/WebCore/khtml/ecma/kjs_html.cpp
index 7038505..3ae15dd 100644
--- a/WebCore/khtml/ecma/kjs_html.cpp
+++ b/WebCore/khtml/ecma/kjs_html.cpp
@@ -53,6 +53,7 @@
 #include <kdebug.h>
 
 #include "cssparser.h"
+#include "css_stylesheetimpl.h"
 
 #include "qcolor.h"
 #include "qpixmap.h"
@@ -3411,11 +3412,11 @@ Value KJS::Context2DFunction::tryCall(ExecState *exec, Object &thisObj, const Li
             int numArgs = args.size();
             switch (numArgs) {
                 case 1: {
-                    if (args[0].type() == StringType) {
-                        QRgb rgb = 0;
-                        DOM::CSSParser::parseColor(args[0].toString(exec).qstring(), rgb);
-                        QColor color(rgb);
-                        CGContextSetRGBStrokeColor(drawingContext, color.red(), color.green(), color.blue(), 1.);
+                    if (args[0].type() == StringType) {                    
+                        QRgb color = DOM::CSSParser::parseColor(args[0].toString(exec).string());
+                        QColor qc(color);
+                        CGContextSetRGBStrokeColor(drawingContext, qc.red()/255., qc.green()/255., qc.blue()/255., qc.alpha()/255.);
+
                     }
                     else {
                         float g = (float)args[0].toNumber(exec);
@@ -3426,10 +3427,9 @@ Value KJS::Context2DFunction::tryCall(ExecState *exec, Object &thisObj, const Li
                 case 2: {
                     float a = args[1].toNumber(exec);
                     if (args[0].type() == StringType) {
-                        QRgb rgb = 0;
-                        DOM::CSSParser::parseColor(args[0].toString(exec).qstring(), rgb);
-                        QColor color(rgb);
-                        CGContextSetRGBStrokeColor(drawingContext, color.red(), color.green(), color.blue(), a);
+                        QRgb color = DOM::CSSParser::parseColor(args[0].toString(exec).string());
+                        QColor qc(color);
+                        CGContextSetRGBStrokeColor(drawingContext, qc.red()/255., qc.green()/255., qc.blue()/255., a);
                     }
                     else {
                         float g = (float)args[0].toNumber(exec);
@@ -3473,10 +3473,9 @@ Value KJS::Context2DFunction::tryCall(ExecState *exec, Object &thisObj, const Li
             switch (numArgs) {
                 case 1: {
                     if (args[0].type() == StringType) {
-                        QRgb rgb = 0;
-                        DOM::CSSParser::parseColor(args[0].toString(exec).qstring(), rgb);
-                        QColor color(rgb);
-                        CGContextSetRGBFillColor(drawingContext, color.red(), color.green(), color.blue(), 1.);
+                        QRgb color = DOM::CSSParser::parseColor(args[0].toString(exec).string());
+                        QColor qc(color);
+                        CGContextSetRGBFillColor(drawingContext, qc.red()/255., qc.green()/255., qc.blue()/255., qc.alpha()/255.);
                     }
                     else {
                         float g = (float)args[0].toNumber(exec);
@@ -3487,10 +3486,9 @@ Value KJS::Context2DFunction::tryCall(ExecState *exec, Object &thisObj, const Li
                 case 2: {
                     float a = args[1].toNumber(exec);
                     if (args[0].type() == StringType) {
-                        QRgb rgb = 0;
-                        DOM::CSSParser::parseColor(args[0].toString(exec).qstring(), rgb);
-                        QColor color(rgb);
-                        CGContextSetRGBFillColor(drawingContext, color.red(), color.green(), color.blue(), a);
+                        QRgb color = DOM::CSSParser::parseColor(args[0].toString(exec).string());
+                        QColor qc(color);
+                        CGContextSetRGBFillColor(drawingContext, qc.red()/255., qc.green()/255., qc.blue()/255., a);
                     }
                     else {
                         float g = (float)args[0].toNumber(exec);
@@ -3805,12 +3803,11 @@ Value KJS::Context2DFunction::tryCall(ExecState *exec, Object &thisObj, const Li
                 switch (numArgs - 3) {
                     case 1: {
                         if (args[3].type() == StringType) {
-                            QRgb rgb = 0;
-                            DOM::CSSParser::parseColor(args[3].toString(exec).qstring(), rgb);
-                            QColor color(rgb);
-                            components[0] = color.red();
-                            components[1] = color.green();
-                            components[2] = color.blue();
+                            QRgb color = DOM::CSSParser::parseColor(args[3].toString(exec).string());
+                            QColor qc(color);
+                            components[0] = qc.red()/255.;
+                            components[1] = qc.green()/255.;
+                            components[2] = qc.blue()/255.;
                             components[3] = 1.0f;
                             colorSpace = CGColorSpaceCreateDeviceRGB();
                         }
@@ -3824,12 +3821,11 @@ Value KJS::Context2DFunction::tryCall(ExecState *exec, Object &thisObj, const Li
                     case 2: {
                         float a = args[4].toNumber(exec);
                         if (args[3].type() == StringType) {
-                            QRgb rgb = 0;
-                            DOM::CSSParser::parseColor(args[3].toString(exec).qstring(), rgb);
-                            QColor color(rgb);
-                            components[0] = color.red();
-                            components[1] = color.green();
-                            components[2] = color.blue();
+                            QRgb color = DOM::CSSParser::parseColor(args[3].toString(exec).string());
+                            QColor qc(color);
+                            components[0] = qc.red()/255.;
+                            components[1] = qc.green()/255.;
+                            components[2] = qc.blue()/255.;
                             components[3] = a;
                             colorSpace = CGColorSpaceCreateDeviceRGB();
                         }
diff --git a/WebCore/kwq/KWQColor.h b/WebCore/kwq/KWQColor.h
index d914720..b9364dc 100644
--- a/WebCore/kwq/KWQColor.h
+++ b/WebCore/kwq/KWQColor.h
@@ -55,6 +55,7 @@ public:
     int red() const { return (color >> 16) & 0xFF; }
     int green() const { return (color >> 8) & 0xFF; }
     int blue() const { return color & 0xFF; }
+    int alpha() const { return (color >> 24) & 0xFF; }
     QRgb rgb() const { return color & 0xFFFFFFFF; } // Preserve the alpha.
     void setRgb(int r, int g, int b) { color = qRgb(r, g, b); valid = true; }
     void setRgb(int rgb) { color = rgb; valid = true; /* Alpha may be set. Preserve it. */ }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list