- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 06 Jan 2010 09:27:46 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/properties/css In directory hutz:/tmp/cvs-serv8530/org/w3c/css/properties/css Modified Files: CssBackground.java CssBackgroundPosition.java Log Message: progress on background CSS3 shorthand property Index: CssBackgroundPosition.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css/CssBackgroundPosition.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- CssBackgroundPosition.java 5 Jan 2010 19:49:50 -0000 1.2 +++ CssBackgroundPosition.java 6 Jan 2010 09:27:44 -0000 1.3 @@ -290,7 +290,7 @@ switch (nb_values) { case 1: // If only one value is specified, the second value - // is assumed to be �center�. + // is assumed to be 'center'. v.horizontal = v.value.get(0); if (v.horizontal.getType() == CssTypes.CSS_NUMBER) { v.horizontal = defaultPercent0; @@ -536,6 +536,4 @@ } - - } Index: CssBackground.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css/CssBackground.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- CssBackground.java 5 Jan 2010 19:49:50 -0000 1.2 +++ CssBackground.java 6 Jan 2010 09:27:44 -0000 1.3 @@ -12,11 +12,14 @@ import org.w3c.css.properties.css1.Css1Style; import org.w3c.css.util.ApplContext; import org.w3c.css.util.InvalidParamException; +import org.w3c.css.values.CssColor; import org.w3c.css.values.CssExpression; import org.w3c.css.values.CssValue; import org.w3c.css.values.CssValueList; -import static org.w3c.css.values.CssOperator.SLASH; +import java.util.ArrayList; + +import static org.w3c.css.values.CssOperator.COMMA; import static org.w3c.css.values.CssOperator.SPACE; /** @@ -59,7 +62,15 @@ */ public class CssBackground extends CssProperty { + private static final String propertyName = "background"; + + Object value; + + public CssColor _color; + + // TODO get rid of those public CssBackgroundColor color; + public CssBackgroundImage image; public CssBackgroundRepeat repeat; public CssBackgroundAttachment attachment; @@ -97,92 +108,62 @@ public CssBackground(ApplContext ac, CssExpression expression, boolean check) throws InvalidParamException { + setByUser(); CssValue val; + ArrayList<CssBackgroundValue> values; + CssBackgroundValue b_val = null; char op; - boolean find = true; - setByUser(); - - // if there are too many values -> error - if (check && expression.getCount() > 6) { - throw new InvalidParamException("unrecognize", ac); - } - - boolean manyValues = (expression.getCount() > 1); - while (find) { - find = false; + values = new ArrayList<CssBackgroundValue>(); + // we just accumulate values and check at validation + while (!expression.end()) { val = expression.getValue(); op = expression.getOperator(); - expression.next(); - if (val == null) { - break; - } - - // if there are many values, we can't have inherit as one of them - if (manyValues && val != null && val.equals(inherit)) { - throw new InvalidParamException("unrecognize", null, null, ac); - } - - if (color == null) { - try { - color = new CssBackgroundColor(ac, expression); - find = true; - } catch (InvalidParamException e) { - // nothing to do, image will test this value - } - } - if (!find && image == null) { - try { - image = new CssBackgroundImage(ac, expression); - find = true; - } catch (InvalidParamException e) { - // nothing to do, repeat will test this value - } - } - if (!find && repeat == null) { - try { - repeat = new CssBackgroundRepeat(ac, expression); - find = true; - } catch (InvalidParamException e) { - // nothing to do, attachment will test this value - } - } - if (!find && attachment == null) { - try { - attachment = new CssBackgroundAttachment(ac, expression); - find = true; - } catch (InvalidParamException e) { - // nothing to do, position will test this value + if (inherit.equals(val)) { + if (expression.getCount() > 1) { + throw new InvalidParamException("value", val, + getPropertyName(), ac); } + value = inherit; + expression.next(); + return; } - if (!find && position == null) { - try { - position = new CssBackgroundPosition(ac, expression); - find = true; - } catch (InvalidParamException e) { - // nothing to do - } + if (b_val == null) { + b_val = new CssBackgroundValue(); } - if (op != SPACE) { - if (op != SLASH) { + // we will check later + b_val.add(val); + expression.next(); + + if (!expression.end()) { + // incomplete value followed by a comma... it's complete! + if (op == COMMA) { + check(b_val, ac); + values.add(b_val); + b_val = null; + } else if (op != SPACE) { throw new InvalidParamException("operator", - ((new Character(op)).toString()), - ac); - } else { - //try { - size = new CssBackgroundSize(ac, expression); - sizedefined = true; - break; - //} catch (InvalidParamException e) { - // error! - //} + ((new Character(op)).toString()), ac); } } - if (check && !find && val != null) { - throw new InvalidParamException("unrecognize", ac); - } } + // if we reach the end in a value that can come in pair + if (b_val != null) { + check(b_val, ac); + values.add(b_val); + } + if (values.size() == 1) { + value = values.get(0); + } else { + value = values; + } + } + + public void check(CssBackgroundValue v, ApplContext ac) + throws InvalidParamException + { + // TODO have fun here... } /** @@ -213,51 +194,25 @@ /** * Returns the name of this property */ - public String getPropertyName() { - return "background"; + public final String getPropertyName() { + return propertyName; } /** * Returns a string representation of the object. */ public String toString() { - StringBuilder sb = new StringBuilder(); - boolean addspace = false; - if (color != null) { - sb.append(color); - addspace = true; - } - if (image != null) { - if (addspace) { - sb.append(' '); - } - sb.append(image); - addspace = true; - } - if (repeat != null) { - if (addspace) { - sb.append(' '); - } - sb.append(repeat); - addspace = true; - } - if (attachment != null) { - if (addspace) { - sb.append(' '); - } - sb.append(attachment); - addspace = true; - } - if (position != null) { - if (addspace) { - sb.append(' '); + if (value instanceof ArrayList) { + ArrayList v_list; + v_list = (ArrayList) value; + StringBuilder sb = new StringBuilder(); + for (Object val : v_list) { + sb.append(val.toString()).append(", "); } - sb.append(position); - } - if (sizedefined) { - sb.append('/').append(size); + sb.setLength(sb.length() - 2); + return sb.toString(); } - return sb.toString(); + return value.toString(); } /** @@ -265,6 +220,7 @@ * Overrides this method for a macro */ public void setImportant() { + super.setImportant(); if (color != null) { color.important = true; } @@ -283,18 +239,6 @@ } /** - * Returns true if this property is important. - * Overrides this method for a macro - */ - public boolean getImportant() { - return ((color == null || color.important) && - (image == null || image.important) && - (repeat == null || repeat.important) && - (attachment == null || attachment.important) && - (position == null || position.important)); - } - - /** * Print this property. * * @param printer The printer.
Received on Wednesday, 6 January 2010 09:27:48 UTC