[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Re: Patch to khtml/css/cssparser
From:       Andreas Schlapbach <schlpbch () iam ! unibe ! ch>
Date:       2001-04-01 18:05:55
[Download RAW message or body]

On Sun, 1 Apr 2001, Dirk Mueller wrote:

> Moin Andreas!
> 
> 
> > Yes, please tell me where I could help. May be something small (fixing a 
> > bug or so) to start with.
> 
> take a look at #23101 please. 
> 

Tha attached patch should fix the bug above plus other background
positioning issues. Note that in the current implementation, 

background-position: center right

would not be rendered correctly. This should be fixed by now.

I'm aware that it could be sped up by using 'case' instead of 'if's' but
IMHO the alg. seems to support all possible combinations of
keywords. Please comment on this.

Please also note that 'center' is very ambigous which makes a look ahead
necessary. 

Please review.

Andreas

P.S.: I would like to move the FontParser-Class into a seperate file
(called cssfontparser) to speed up compilation while testing. Any
objections?

--
  Andreas Schlapbach      schlpbch@iam.unibe.ch
  http://iamexwiwww.unibe.ch/studenten/schlpbch
                 "/home sweet /home."


["cssparser.cpp.patch" (TEXT/PLAIN)]

--- cssparser.orig.cpp	Sun Apr  1 21:33:53 2001
+++ cssparser.cpp	Sun Apr  1 21:53:51 2001
@@ -1209,47 +1209,117 @@
       break;
     case CSS_PROP_BACKGROUND_POSITION:
       {
-        // special handling of "background-position: center;"
-          const struct css_value *cssval = findValue(val, value.length());
-          if ( cssval && cssval->id == CSS_VAL_CENTER ) {
-              parsedValue = new CSSPrimitiveValueImpl( 50, CSSPrimitiveValue::CSS_PERCENTAGE );
-              CSSProperty *prop = new CSSProperty();
-              prop->m_id = CSS_PROP_KONQ_BGPOS_Y;
-              prop->setValue(parsedValue);
-              prop->m_bImportant = important;
-              propList->append(prop);
-          }
-          int properties[2] = { CSS_PROP_KONQ_BGPOS_X, CSS_PROP_KONQ_BGPOS_Y };
+#ifdef CSS_DEBUG
+        kdDebug( 6080 ) << "CSS_PROP_BACKGROUND_POSITION: " << val << endl;
+#endif
+	/* Problem: center is ambigous  
+	 * In case of 'center' center defines X and Y coords
+	 * In case of 'center top', center defines the Y coord
+	 * in case of 'center left', center defines the X coord
+	 *
+	 * -> Some sort of look ahead needs to be done
+	 */
+
+        const QString strVal = value.simplifyWhiteSpace();
+	const QStringList posList = QStringList::split(' ',strVal);
+
+ 	QString property1, property2;
+ 	if (!posList.isEmpty()) {
+	  property1 = posList[0].lower();
+#ifdef CSS_DEBUG
+	  kdDebug( 6080 ) << "prop 1: [" << property1 << "]" << endl;  
+#endif
+	  if (posList.count()==2) {
+	    property2 = posList[1].lower();
+#ifdef CSS_DEBUG
+	    kdDebug( 6080) << "prop 2: [" << property2 << "]" << endl;  
+#endif
+	  }
+	} else {
+          break;
+	}
+	
+	/* The section below can be speed up by using case on case
+	 * on CSS_VAL-*
+	 */
+	  
+	int valX=-1;
+	int valY=-1;
+	if (property1 == "center") {
+	  if (property2.isEmpty() || property2 == "center") {
+            valX = 50; valY = 50;	   
+	  } else  if (property2 == "top") {
+	    valX = 50; valY = 0;	   
+	  } else  if (property2 == "bottom") {
+	    valX = 50; valY = 100;	   
+	  } else  if (property2 == "left") {
+	    valX = 0; valY = 50;	   
+	  } else  if (property2 == "right") {
+	    valX = 100; valY = 50;	   
+	  }
+	} else if (property1 == "top") {
+	  valY = 0;
+	  if (property2.isEmpty() || property2 == "center") {
+	    valX = 50; 	   
+	  } else  if (property2 == "left") {
+	    valX = 0;	   
+	  } else  if (property2 == "right") {
+	    valX = 100; 	   
+	  }
+	} else if (property1 == "bottom") {
+	  valY = 100;
+	  if (property2.isEmpty() || property2 == "center") {
+	    valX = 50; 	   
+	  } else  if (property2 == "left") {
+	    valX = 0;
+	  } else  if (property2 == "right") {
+	    valX = 100;
+	  }
+	} else if (property1 == "left") {
+	  valX = 0;
+	  if (property2.isEmpty() || property2 == "center") {
+	    valY = 50; 	   
+	  } else  if (property2 == "top") {
+	    valY = 0;	   
+	  } else  if (property2 == "bottom") {
+	    valY = 100;	   
+	  }
+	} else if (property1 == "right") {
+	  valX = 100;
+	  if (property2.isEmpty() || property2 == "center") {
+	    valY = 50;	   
+	  } else  if (property2 == "top") {
+	    valY = 0;	   
+	  } else  if (property2 == "bottom") {
+	    valY = 100;	   
+	  }
+	}
+
+	/* CSS 14.2
+	 * Keywords cannot be combined with percentage values or length values.
+	 * -> No mix between keywords and other units.
+	 */
+	  
+	if (valX != -1 && valY != -1) {
+          setParsedValue( CSS_PROP_KONQ_BGPOS_X, important, propList, 
+		          new CSSPrimitiveValueImpl(valX, CSSPrimitiveValue::CSS_PERCENTAGE)); 	  
+	  setParsedValue( CSS_PROP_KONQ_BGPOS_Y, important, propList, 
+	                  new CSSPrimitiveValueImpl(valY, CSSPrimitiveValue::CSS_PERCENTAGE)); 	  
+	  // I don't like returning in the middle of a function, will fix later
+	  return true;
+	} else {
+	  int properties[2] = { CSS_PROP_KONQ_BGPOS_X, CSS_PROP_KONQ_BGPOS_Y };
           return parseShortHand(curP, endP, properties, 2, important, propList);
+	}
+        break;
       }
-      break;
     case CSS_PROP_KONQ_BGPOS_X:
     case CSS_PROP_KONQ_BGPOS_Y:
       {
-        const struct css_value *cssval = findValue(val, value.length());
-        int val = -1;
-        if (cssval)
-        {
-          switch( cssval->id ) {
-          case CSS_VAL_TOP:
-          case CSS_VAL_LEFT:
-            val = 0;
-            break;
-          case CSS_VAL_CENTER:
-            val = 50;
-            break;
-          case CSS_VAL_BOTTOM:
-          case CSS_VAL_RIGHT:
-            val = 100;
-            break;
-          default:
-            break;
-          }
-        }
-        if(val == -1)
-          parsedValue = parseUnit(curP, endP, PERCENT | NUMBER);
-        else if(!parsedValue)
-          parsedValue = new CSSPrimitiveValueImpl(val, CSSPrimitiveValue::CSS_PERCENTAGE);
+#ifdef CSS_DEBUG
+        kdDebug( 6080 ) << "CSS_PROP_KONQ_BGPOS_{X|Y}: " << val << endl;
+#endif
+        parsedValue = parseUnit(curP, endP, PERCENT | NUMBER);
         break;
       }
     case CSS_PROP_CURSOR:


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic