- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Tue, 25 Sep 2012 19:51:28 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/properties/css1 In directory hutz:/tmp/cvs-serv23779/css1 Modified Files: Css1Style.java CssPadding.java CssPaddingBottom.java CssPaddingLeft.java CssPaddingRight.java CssPaddingTop.java Removed Files: CssPaddingSide.java Log Message: padding for CSS1/2/21 and CSS3 Index: CssPaddingTop.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssPaddingTop.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- CssPaddingTop.java 5 Jan 2010 13:49:45 -0000 1.4 +++ CssPaddingTop.java 25 Sep 2012 19:51:26 -0000 1.5 @@ -1,110 +1,49 @@ -// // $Id$ -// From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr) +// Author: Yves Lafon <ylafon@w3.org> // -// (c) COPYRIGHT MIT and INRIA, 1997. +// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.css.properties.css1; -import org.w3c.css.parser.CssStyle; -import org.w3c.css.properties.css.CssProperty; import org.w3c.css.util.ApplContext; import org.w3c.css.util.InvalidParamException; import org.w3c.css.values.CssExpression; /** - * <H4> - * 'padding-top' - * </H4> - * <P> - * <EM>Value:</EM> <length> | <percentage><BR> - * <EM>Initial:</EM> 0<BR> - * <EM>Applies to:</EM> all elements<BR> - * <EM>Inherited:</EM> no<BR> - * <EM>Percentage values:</EM> refer to parent element's width<BR> - * <P> - * This property sets the top padding of an element. - * <PRE> - * BLOCKQUOTE { padding-top: 0.3em } - * </PRE> - * <P> - * Padding values cannot be negative. - * @version $Revision$ + * @spec http://www.w3.org/TR/2008/REC-CSS1-20080411/#padding-top */ -public class CssPaddingTop extends CssPaddingSide { - - /** - * Create a new CssPaddingTop - */ - public CssPaddingTop() { - super(); - } - - /** - * Create a new CssPaddingTop with an another CssPaddingSide. - * - * @param another The another side. - */ - public CssPaddingTop(CssPaddingSide another) { - super(another); - } - - /** - * Create a new CssPaddingTop - * - * @param expression The expression for this property. - * @exception InvalidParamException Values are incorrect - */ - public CssPaddingTop(ApplContext ac, CssExpression expression, boolean check) - throws InvalidParamException { - super(ac, expression, check); - } - - public CssPaddingTop(ApplContext ac, CssExpression expression) - throws InvalidParamException { - this(ac, expression, false); - } - - /** - * Returns the name of this property - */ - public String getPropertyName() { - return "padding-top"; - } - - /** - * Add this property to the CssStyle. - * - * @param style The CssStyle - */ - public void addToStyle(ApplContext ac, CssStyle style) { - Css1Style style0 = (Css1Style) style; - if (style0.cssPadding.top != null) - style0.addRedefinitionWarning(ac, this); - style0.cssPadding.top = this; - } +public class CssPaddingTop extends org.w3c.css.properties.css.CssPaddingTop { - /** - * Get this property in the style. - * - * @param style The style where the property is - * @param resolve if true, resolve the style to find this property - */ - public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) { - if (resolve) { - return ((Css1Style) style).getPaddingTop(); - } else { - return ((Css1Style) style).cssPadding.getTop(); - } - } + /** + * Create a new CssPaddingTop + */ + public CssPaddingTop() { + } - /** - * Compares two properties for equality. - * - * @param value The other property. - */ - public boolean equals(CssProperty property) { - return (property instanceof CssPaddingTop && value.equals(((CssPaddingTop) property).value)); - } + /** + * Set the value of the property<br/> + * Does not check the number of values + * + * @param expression The expression for this property + * @throws org.w3c.css.util.InvalidParamException + * The expression is incorrect + */ + public CssPaddingTop(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } + /** + * Set the value of the property + * + * @param expression The expression for this property + * @param check set it to true to check the number of values + * @throws org.w3c.css.util.InvalidParamException + * The expression is incorrect + */ + public CssPaddingTop(ApplContext ac, CssExpression expression, + boolean check) throws InvalidParamException { + setByUser(); + CssPadding.checkValue(ac, expression, check, this); + } } Index: CssPaddingRight.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssPaddingRight.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- CssPaddingRight.java 5 Jan 2010 13:49:45 -0000 1.4 +++ CssPaddingRight.java 25 Sep 2012 19:51:26 -0000 1.5 @@ -1,112 +1,49 @@ -// // $Id$ -// From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr) +// Author: Yves Lafon <ylafon@w3.org> // -// (c) COPYRIGHT MIT and INRIA, 1997. +// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.css.properties.css1; -import org.w3c.css.parser.CssStyle; -import org.w3c.css.properties.css.CssProperty; import org.w3c.css.util.ApplContext; import org.w3c.css.util.InvalidParamException; import org.w3c.css.values.CssExpression; /** - * <H4> - * 'padding-right' - * </H4> - * <P> - * <EM>Value:</EM> <length> | <percentage><BR> - * <EM>Initial:</EM> 0<BR> - * <EM>Applies to:</EM> all elements<BR> - * <EM>Inherited:</EM> no<BR> - * <EM>Percentage values:</EM> refer to parent element's width<BR> - * <P> - * This property sets the right padding of an element. - * <PRE> - * BLOCKQUOTE { padding-right: 10px } - * </PRE> - * <P> - * Padding values cannot be negative. - * - * @version $Revision$ + * @spec http://www.w3.org/TR/2008/REC-CSS1-20080411/#padding-right */ -public class CssPaddingRight extends CssPaddingSide { - - /** - * Create a new CssPaddingRight - */ - public CssPaddingRight() { - super(); - } - - /** - * Create a new CssPaddingRight with an another CssPaddingSide - * - * @param another The another side - */ - public CssPaddingRight(CssPaddingSide another) { - super(another); - } - - /** - * Create a new CssPaddingRight - * - * @param expression The expression for this property. - * @exception InvalidParamException Values are incorrect - */ - public CssPaddingRight(ApplContext ac, CssExpression expression, boolean check) - throws InvalidParamException { - super(ac, expression, check); - } - - public CssPaddingRight(ApplContext ac, CssExpression expression) - throws InvalidParamException { - this(ac, expression, false); - } - - /** - * Returns the name of this property - */ - public String getPropertyName() { - return "padding-right"; - } - - /** - * Add this property to the CssStyle. - * - * @param style The CssStyle - */ - public void addToStyle(ApplContext ac, CssStyle style) { - Css1Style style0 = (Css1Style) style; - if (style0.cssPadding.right != null) - style0.addRedefinitionWarning(ac, this); - style0.cssPadding.right = this; - } +public class CssPaddingRight extends org.w3c.css.properties.css.CssPaddingRight { - /** - * Get this property in the style. - * - * @param style The style where the property is - * @param resolve if true, resolve the style to find this property - */ - public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) { - if (resolve) { - return ((Css1Style) style).getPaddingRight(); - } else { - return ((Css1Style) style).cssPadding.getRight(); - } - } + /** + * Create a new CssPaddingRight + */ + public CssPaddingRight() { + } - /** - * Compares two properties for equality. - * - * @param value The other property. - */ - public boolean equals(CssProperty property) { - return (property instanceof CssPaddingRight && - value.equals(((CssPaddingRight) property).value)); - } + /** + * Set the value of the property<br/> + * Does not check the number of values + * + * @param expression The expression for this property + * @throws org.w3c.css.util.InvalidParamException + * The expression is incorrect + */ + public CssPaddingRight(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } + /** + * Set the value of the property + * + * @param expression The expression for this property + * @param check set it to true to check the number of values + * @throws org.w3c.css.util.InvalidParamException + * The expression is incorrect + */ + public CssPaddingRight(ApplContext ac, CssExpression expression, + boolean check) throws InvalidParamException { + setByUser(); + CssPadding.checkValue(ac, expression, check, this); + } } --- CssPaddingSide.java DELETED --- Index: CssPaddingBottom.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssPaddingBottom.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- CssPaddingBottom.java 5 Jan 2010 13:49:45 -0000 1.4 +++ CssPaddingBottom.java 25 Sep 2012 19:51:26 -0000 1.5 @@ -1,111 +1,50 @@ -// // $Id$ -// From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr) +// Author: Yves Lafon <ylafon@w3.org> // -// (c) COPYRIGHT MIT and INRIA, 1997. +// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.css.properties.css1; -import org.w3c.css.parser.CssStyle; -import org.w3c.css.properties.css.CssProperty; import org.w3c.css.util.ApplContext; import org.w3c.css.util.InvalidParamException; import org.w3c.css.values.CssExpression; /** - * <H4> - * 'padding-bottom' - * </H4> - * <P> - * <EM>Value:</EM> <length> | <percentage><BR> - * <EM>Initial:</EM> 0<BR> - * <EM>Applies to:</EM> all elements<BR> - * <EM>Inherited:</EM> no<BR> - * <EM>Percentage values:</EM> refer to parent element's width<BR> - * <P> - * This property sets the bottom padding of an element. - * <PRE> - * BLOCKQUOTE { padding-bottom: 2em } - * </PRE> - * <P> - * Padding values cannot be negative. - * @version $Revision$ + * @spec http://www.w3.org/TR/2008/REC-CSS1-20080411/#padding-bottom */ -public class CssPaddingBottom extends CssPaddingSide { - - /** - * Create a new CssPaddingBottom - */ - public CssPaddingBottom() { - super(); - } - - /** - * Create a new CssPaddingBottom with an another CssPaddingSide - * - * @param another The another side. - */ - public CssPaddingBottom(CssPaddingSide another) { - super(another); - } - - /** - * Create a new CssPaddingBottom - * - * @param expression The expression for this property. - * @exception InvalidParamException Values are incorrect - */ - public CssPaddingBottom(ApplContext ac, CssExpression expression, - boolean check) throws InvalidParamException { - super(ac, expression, check); - } - - public CssPaddingBottom(ApplContext ac, CssExpression expression) - throws InvalidParamException { - this(ac, expression, false); - } - - /** - * Returns the name of this property - */ - public String getPropertyName() { - return "padding-bottom"; - } - - /** - * Add this property to the CssStyle. - * - * @param style The CssStyle - */ - public void addToStyle(ApplContext ac, CssStyle style) { - Css1Style style0 = (Css1Style) style; +public class CssPaddingBottom extends org.w3c.css.properties.css.CssPaddingBottom { - if (style0.cssPadding.bottom != null) - style0.addRedefinitionWarning(ac, this); - style0.cssPadding.bottom = this; - } + /** + * Create a new CssPaddingBottom + */ + public CssPaddingBottom() { + } - /** - * Get this property in the style. - * - * @param style The style where the property is - * @param resolve if true, resolve the style to find this property - */ - public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) { - if (resolve) { - return ((Css1Style) style).getPaddingBottom(); - } else { - return ((Css1Style) style).cssPadding.getBottom(); - } - } + /** + * Set the value of the property<br/> + * Does not check the number of values + * + * @param expression The expression for this property + * @throws org.w3c.css.util.InvalidParamException + * The expression is incorrect + */ + public CssPaddingBottom(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } - /** - * Compares two properties for equality. - * - * @param value The other property. - */ - public boolean equals(CssProperty property) { - return (property instanceof CssPaddingBottom && value.equals(((CssPaddingBottom) property).value)); - } + /** + * Set the value of the property + * + * @param expression The expression for this property + * @param check set it to true to check the number of values + * @throws org.w3c.css.util.InvalidParamException + * The expression is incorrect + */ + public CssPaddingBottom(ApplContext ac, CssExpression expression, + boolean check) throws InvalidParamException { + setByUser(); + CssPadding.checkValue(ac, expression, check, this); + } } Index: Css1Style.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/Css1Style.java,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- Css1Style.java 7 Sep 2012 14:55:24 -0000 1.34 +++ Css1Style.java 25 Sep 2012 19:51:25 -0000 1.35 @@ -17,6 +17,11 @@ import org.w3c.css.properties.css.CssTextAlign; import org.w3c.css.properties.css.CssTextDecoration; import org.w3c.css.properties.css.CssTextIndent; +import org.w3c.css.properties.css.CssPaddingLeft; +import org.w3c.css.properties.css.CssPaddingTop; +import org.w3c.css.properties.css.CssPaddingRight; +import org.w3c.css.properties.css.CssPaddingBottom; +import org.w3c.css.properties.css.CssPadding; import org.w3c.css.util.ApplContext; import org.w3c.css.util.InvalidParamException; @@ -97,7 +102,7 @@ /** * padding properties */ - public CssPadding cssPadding = new CssPadding(); + public org.w3c.css.properties.css.CssPadding cssPadding = new org.w3c.css.properties.css.CssPadding(); /** * border properties */ @@ -747,62 +752,62 @@ * Get the padding-top property */ public final CssPaddingTop getPaddingTop() { - if (cssPadding.top == null) { - cssPadding.top = + if (cssPadding.paddingTop == null) { + cssPadding.paddingTop = (CssPaddingTop) style.CascadingOrder(new CssPaddingTop(), style, selector); } - return cssPadding.top; + return cssPadding.paddingTop; } /** * Get the padding-right property */ public final CssPaddingRight getPaddingRight() { - if (cssPadding.right == null) { - cssPadding.right = + if (cssPadding.paddingRight == null) { + cssPadding.paddingRight = (CssPaddingRight) style.CascadingOrder(new CssPaddingRight(), style, selector); } - return cssPadding.right; + return cssPadding.paddingRight; } /** * Get the padding-bottom property */ public final CssPaddingBottom getPaddingBottom() { - if (cssPadding.bottom == null) { - cssPadding.bottom = + if (cssPadding.paddingBottom == null) { + cssPadding.paddingBottom = (CssPaddingBottom) style.CascadingOrder(new CssPaddingBottom(), style, selector); } - return cssPadding.bottom; + return cssPadding.paddingBottom; } /** * Get the padding-left property */ public final CssPaddingLeft getPaddingLeft() { - if (cssPadding.left == null) { - cssPadding.left = + if (cssPadding.paddingLeft == null) { + cssPadding.paddingLeft = (CssPaddingLeft) style.CascadingOrder(new CssPaddingLeft(), style, selector); } - return cssPadding.left; + return cssPadding.paddingLeft; } /** * Get the padding property */ public final CssPadding getPadding() { - if (cssPadding.top == null) - cssPadding.top = getPaddingTop(); - if (cssPadding.right == null) - cssPadding.right = getPaddingRight(); - if (cssPadding.bottom == null) - cssPadding.bottom = getPaddingBottom(); - if (cssPadding.left == null) - cssPadding.left = getPaddingLeft(); + if (cssPadding.paddingTop == null) + cssPadding.paddingTop = getPaddingTop(); + if (cssPadding.paddingRight == null) + cssPadding.paddingRight = getPaddingRight(); + if (cssPadding.paddingBottom == null) + cssPadding.paddingBottom = getPaddingBottom(); + if (cssPadding.paddingLeft == null) + cssPadding.paddingLeft = getPaddingLeft(); return cssPadding; } @@ -1671,13 +1676,13 @@ } checker.reset(); - if (cssPadding.getTop() != null) { - info = cssPadding.getTop(); - checker.compute(cssPadding.getTop().getValue()); + if (cssPadding.paddingTop != null) { + info = cssPadding.paddingTop; + checker.compute(cssPadding.paddingTop.value); } - if (cssPadding.getBottom() != null) { - info = cssPadding.getBottom(); - checker.compute(cssPadding.getBottom().getValue()); + if (cssPadding.paddingBottom != null) { + info = cssPadding.paddingBottom; + checker.compute(cssPadding.paddingBottom.value); } if (checker.isNotRobust()) { warnings.addWarning(new Warning(info.getSourceFile(), @@ -1687,13 +1692,13 @@ } checker.reset(); - if (cssPadding.getRight() != null) { - info = cssPadding.getRight(); - checker.compute(cssPadding.getRight().getValue()); + if (cssPadding.paddingRight != null) { + info = cssPadding.paddingRight; + checker.compute(cssPadding.paddingRight.value); } - if (cssPadding.getLeft() != null) { - info = cssPadding.getLeft(); - checker.compute(cssPadding.getLeft().getValue()); + if (cssPadding.paddingLeft != null) { + info = cssPadding.paddingLeft; + checker.compute(cssPadding.paddingLeft.value); } if (checker.isNotRobust()) { Index: CssPaddingLeft.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssPaddingLeft.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- CssPaddingLeft.java 5 Jan 2010 13:49:45 -0000 1.4 +++ CssPaddingLeft.java 25 Sep 2012 19:51:26 -0000 1.5 @@ -1,110 +1,50 @@ -// // $Id$ -// From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr) +// Author: Yves Lafon <ylafon@w3.org> // -// (c) COPYRIGHT MIT and INRIA, 1997. +// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012. // Please first read the full copyright statement in file COPYRIGHT.html package org.w3c.css.properties.css1; -import org.w3c.css.parser.CssStyle; -import org.w3c.css.properties.css.CssProperty; import org.w3c.css.util.ApplContext; import org.w3c.css.util.InvalidParamException; import org.w3c.css.values.CssExpression; /** - * <H4> - * <A NAME="padding-left">5.5.9 'padding-left'</A> - * </H4> - * <P> - * <EM>Value:</EM> <length> | <percentage><BR> - * <EM>Initial:</EM> 0<BR> - * <EM>Applies to:</EM> all elements<BR> - * <EM>Inherited:</EM> no<BR> - * <EM>Percentage values:</EM> refer to parent element's width<BR> - * <P> - * This property sets the left padding of an element. - * <PRE> - * BLOCKQUOTE { padding-left: 20% } - * </PRE> - * <P> - * Padding values cannot be negative. - * @version $Revision$ + * @spec http://www.w3.org/TR/2008/REC-CSS1-20080411/#padding-left */ -public class CssPaddingLeft extends CssPaddingSide { - - /** - * Create a new CssPaddingLeft - */ - public CssPaddingLeft() { - super(); - } - - /** - * Create a new CssPaddingLeft with an another CssPaddingSide - * @param another The another side. - */ - public CssPaddingLeft(CssPaddingSide another) { - super(another); - } - - /** - * Create a new CssPaddingLeft - * - * @param expression The expression for this property. - * @exception InvalidParamException Values are incorrect - */ - public CssPaddingLeft(ApplContext ac, CssExpression expression, boolean check) - throws InvalidParamException { - super(ac, expression, check); - } - - public CssPaddingLeft(ApplContext ac, CssExpression expression) - throws InvalidParamException { - this(ac, expression, false); - } - - /** - * Returns the name of this property - */ - public String getPropertyName() { - return "padding-left"; - } +public class CssPaddingLeft extends org.w3c.css.properties.css.CssPaddingLeft { - /** - * Add this property to the CssStyle. - * - * @param style The CssStyle - */ - public void addToStyle(ApplContext ac, CssStyle style) { - Css1Style style0 = (Css1Style) style; - if (style0.cssPadding.left != null) - style0.addRedefinitionWarning(ac, this); - style0.cssPadding.left = this; - } + /** + * Create a new CssPaddingLeft + */ + public CssPaddingLeft() { + } - /** - * Get this property in the style. - * - * @param style The style where the property is - * @param resolve if true, resolve the style to find this property - */ - public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) { - if (resolve) { - return ((Css1Style) style).getPaddingLeft(); - } else { - return ((Css1Style) style).cssPadding.getLeft(); - } - } + /** + * Set the value of the property<br/> + * Does not check the number of values + * + * @param expression The expression for this property + * @throws org.w3c.css.util.InvalidParamException + * The expression is incorrect + */ + public CssPaddingLeft(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } - /** - * Compares two properties for equality. - * - * @param value The other property. - */ - public boolean equals(CssProperty property) { - return (property instanceof CssPaddingLeft && - value.equals(((CssPaddingLeft) property).value)); - } + /** + * Set the value of the property + * + * @param expression The expression for this property + * @param check set it to true to check the number of values + * @throws org.w3c.css.util.InvalidParamException + * The expression is incorrect + */ + public CssPaddingLeft(ApplContext ac, CssExpression expression, + boolean check) throws InvalidParamException { + setByUser(); + CssPadding.checkValue(ac, expression, check, this); + } } Index: CssPadding.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssPadding.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- CssPadding.java 27 Sep 2011 08:15:45 -0000 1.6 +++ CssPadding.java 25 Sep 2012 19:51:26 -0000 1.7 @@ -1,348 +1,169 @@ -// // $Id$ -// From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr) +// Author: Yves Lafon <ylafon@w3.org> // -// (c) COPYRIGHT MIT and INRIA, 1997. +// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012. // Please first read the full copyright statement in file COPYRIGHT.html - package org.w3c.css.properties.css1; -import org.w3c.css.parser.CssSelectors; -import org.w3c.css.parser.CssStyle; import org.w3c.css.properties.css.CssProperty; import org.w3c.css.util.ApplContext; import org.w3c.css.util.InvalidParamException; import org.w3c.css.values.CssExpression; -import org.w3c.css.values.CssOperator; - -/** - * <H4> - * 'padding' - * </H4> - * <P> - * <EM>Value:</EM> [ <length> | <percentage> ]{1,4} <BR> - * <EM>Initial:</EM> 0<BR> - * <EM>Applies to:</EM> all elements<BR> - * <EM>Inherited:</EM> no<BR> - * <EM>Percentage values:</EM> refer to parent element's width<BR> - * <P> - * The 'padding' property is a shorthand property for setting 'padding-top', - * 'padding-right' 'padding-bottom' and 'padding-left' at the same place in - * the style sheet. - * <P> - * If four values are specified they apply to top, right, bottom and left - * respectively. If there is only one value, it applies to all sides, if there - * are two or three, the missing values are taken from the opposite side. - * <P> - * The surface of the padding area is set with the 'background' property: - * <PRE> - * H1 { - * background: white; - * padding: 1em 2em; - * } - * </PRE> - * <P> - * The example above sets a '1em' padding vertically ('padding-top' and - * 'padding-bottom') and a '2em' padding horizontally ('padding-right' and - * 'padding-left'). The 'em' unit is relative to the element's font size: '1em' - * is equal to the size of the font in use. - * <P> - * Padding values cannot be negative. - * @version $Revision$ - */ -public class CssPadding extends CssProperty implements CssOperator { - - CssPaddingTop top = null; - CssPaddingBottom bottom = null; - CssPaddingRight right = null; - CssPaddingLeft left = null; - - boolean inheritedValue; - - /** - * Create a new CssPadding - */ - public CssPadding() { - } +import org.w3c.css.values.CssLength; +import org.w3c.css.values.CssPercentage; +import org.w3c.css.values.CssTypes; +import org.w3c.css.values.CssValue; +import org.w3c.css.values.CssValueList; - /** - * Create a new CssPadding - * @param expression The expression for this property - * @exception InvalidParamException Values are incorrect - */ - public CssPadding(ApplContext ac, CssExpression expression, boolean check) - throws InvalidParamException { - //CssValue val = expression.floatValue(); - setByUser(); +import java.util.ArrayList; - /*if (val.equals(inherit)) { - inheritedValue = true; - top = new CssPaddingTop(); - top.value = inherit; - bottom = new CssPaddingBottom(); - bottom.value = inherit; - right = new CssPaddingRight(); - right.value = inherit; - left = new CssPaddingLeft(); - left.value = inherit; - }*/ +import static org.w3c.css.values.CssOperator.SPACE; - int count = expression.getCount(); +/** + * @spec http://www.w3.org/TR/2008/REC-CSS1-20080411/#padding + */ +public class CssPadding extends org.w3c.css.properties.css.CssPadding { - switch (count) { - case 1: - top = new CssPaddingTop(ac, expression); - /*bottom = new CssPaddingBottom(top); - right = new CssPaddingRight(top); - left = new CssPaddingLeft(top);*/ - break; - case 2: - if (expression.getOperator() != SPACE) - throw new InvalidParamException("operator", - ((new Character(expression.getOperator())).toString()), - ac); - if(expression.getValue().equals(inherit)) { - throw new InvalidParamException("unrecognize", ac); - } - top = new CssPaddingTop(ac, expression); - if(expression.getValue().equals(inherit)) { - throw new InvalidParamException("unrecognize", ac); - } - right = new CssPaddingRight(ac, expression); - /*bottom = new CssPaddingBottom(top); - left = new CssPaddingLeft(right);*/ - break; - case 3: - if (expression.getOperator() != SPACE) - throw new InvalidParamException("operator", - ((new Character(expression.getOperator())).toString()), - ac); - if(expression.getValue().equals(inherit)) { - throw new InvalidParamException("unrecognize", ac); - } - top = new CssPaddingTop(ac, expression); - if (expression.getOperator() != SPACE) - throw new InvalidParamException("operator", - ((new Character(expression.getOperator())).toString()), - ac); - if(expression.getValue().equals(inherit)) { - throw new InvalidParamException("unrecognize", ac); - } - right = new CssPaddingRight(ac, expression); - if(expression.getValue().equals(inherit)) { - throw new InvalidParamException("unrecognize", ac); - } - bottom = new CssPaddingBottom(ac, expression); - //left = new CssPaddingLeft(right); - break; - case 4: - if (expression.getOperator() != SPACE) - throw new InvalidParamException("operator", - ((new Character(expression.getOperator())).toString()), - ac); - if(expression.getValue().equals(inherit)) { - throw new InvalidParamException("unrecognize", ac); - } - top = new CssPaddingTop(ac, expression); - if (expression.getOperator() != SPACE) - throw new InvalidParamException("operator", - ((new Character(expression.getOperator())).toString()), - ac); - if(expression.getValue().equals(inherit)) { - throw new InvalidParamException("unrecognize", ac); - } - right = new CssPaddingRight(ac, expression); - if (expression.getOperator() != SPACE) - throw new InvalidParamException("operator", - ((new Character(expression.getOperator())).toString()), - ac); - if(expression.getValue().equals(inherit)) { - throw new InvalidParamException("unrecognize", ac); - } - bottom = new CssPaddingBottom(ac, expression); - if(expression.getValue().equals(inherit)) { - throw new InvalidParamException("unrecognize", ac); - } - left = new CssPaddingLeft(ac, expression); - break; - default: - if(check) { - throw new InvalidParamException("unrecognize", ac); - } + /** + * Create a new CssPadding + */ + public CssPadding() { } - } - public CssPadding(ApplContext ac, CssExpression expression) - throws InvalidParamException { - this(ac, expression, false); - } - /** - * Returns the value of this property - */ - public Object get() { - return top; - } - - /** - * Returns the top property - */ - public CssPaddingTop getTop() { - return top; - } - - /** - * Returns the right property - */ - public CssPaddingRight getRight() { - return right; - } + /** + * Set the value of the property<br/> + * Does not check the number of values + * + * @param expression The expression for this property + * @throws org.w3c.css.util.InvalidParamException + * The expression is incorrect + */ + public CssPadding(ApplContext ac, CssExpression expression) + throws InvalidParamException { + this(ac, expression, false); + } - /** - * Returns the bottom property - */ - public CssPaddingBottom getBottom() { - return bottom; - } + /** + * Set the value of the property + * + * @param expression The expression for this property + * @param check set it to true to check the number of values + * @throws org.w3c.css.util.InvalidParamException + * The expression is incorrect + */ + public CssPadding(ApplContext ac, CssExpression expression, + boolean check) throws InvalidParamException { + if (check && expression.getCount() > 4) { + throw new InvalidParamException("unrecognize", ac); + } + CssValue val; + char op; + ArrayList<CssValue> v = new ArrayList<CssValue>(); - /** - * Returns the left property - */ - public CssPaddingLeft getLeft() { - return left; - } + while (!expression.end()) { + val = expression.getValue(); + op = expression.getOperator(); - /** - * Returns the name of this property - */ - public String getPropertyName() { - return "padding"; - } + switch (val.getType()) { + case CssTypes.CSS_NUMBER: + case CssTypes.CSS_LENGTH: + CssLength l = val.getLength(); + l.checkPositiveness(ac, this); + v.add(val); + break; + case CssTypes.CSS_PERCENTAGE: + CssPercentage p = val.getPercentage(); + p.checkPositiveness(ac, this); + v.add(val); + break; + default: + throw new InvalidParamException("value", + val.toString(), + getPropertyName(), ac); + } + if (op != SPACE) { + throw new InvalidParamException("operator", + ((new Character(op)).toString()), ac); - /** - * Returns a string representation of the object. - */ - public String toString() { - if (inheritedValue) { - return inherit.toString(); - } - String result = ""; - // top should never be null - if(top != null) result += top; - if(right != null) result += " " + right; - if(bottom != null) result += " " + bottom; - if(left != null) result += " " + left; - return result; - /*if (right.value.equals(left.value)) { - if (top.value.equals(bottom.value)) { - if (top.value.equals(right.value)) { - return top.toString(); - } else { - return top + " " + right; + } + expression.next(); } - } else { - return top + " " + right + " " + bottom; - } - } else { - return top + " " + right + " " + bottom + " " + left; - }*/ - } - - /** - * Set this property to be important. - * Overrides this method for a macro - */ - public void setImportant() { - if(top != null) top.important = true; - if(right != null) right.important = true; - if(bottom != null) bottom.important = true; - if(left != null) left.important = true; - } - - /** - * Returns true if this property is important. - * Overrides this method for a macro - */ - public boolean getImportant() { - return ((top == null || top.important) && - (right == null || right.important) && - (bottom == null || bottom.important) && - (left == null || left.important)); - } + // now we check the number of values... + paddingBottom = new CssPaddingBottom(); + paddingLeft = new CssPaddingLeft(); + paddingTop = new CssPaddingTop(); + paddingRight = new CssPaddingRight(); - /** - * Set the context. - * Overrides this method for a macro - * - * @see org.w3c.css.css.CssCascadingOrder#order - * @see org.w3c.css.css.StyleSheetParser#handleRule - */ - public void setSelectors(CssSelectors selector) { - super.setSelectors(selector); - if (top != null) { - top.setSelectors(selector); - } - if (right != null) { - right.setSelectors(selector); - } - if (bottom != null) { - bottom.setSelectors(selector); - } - if (left != null) { - left.setSelectors(selector); + switch (v.size()) { + case 1: + paddingTop.value = v.get(0); + paddingRight.value = v.get(0); + paddingBottom.value = v.get(0); + paddingLeft.value = v.get(0); + break; + case 2: + paddingTop.value = v.get(0); + paddingRight.value = v.get(1); + paddingBottom.value = v.get(0); + paddingLeft.value = v.get(1); + break; + case 3: + paddingTop.value = v.get(0); + paddingRight.value = v.get(1); + paddingBottom.value = v.get(2); + paddingLeft.value = v.get(1); + break; + case 4: + paddingTop.value = v.get(0); + paddingRight.value = v.get(1); + paddingBottom.value = v.get(2); + paddingLeft.value = v.get(3); + break; + default: + // can't happen unless we are not checking + // the size + throw new InvalidParamException("unrecognize", ac); + } + value = new CssValueList(v); } - } - - /** - * Add this property to the CssStyle - * - * @param style The CssStyle - */ - public void addToStyle(ApplContext ac, CssStyle style) { - ((Css1Style) style).cssPadding.inheritedValue = inheritedValue; - if(top != null) top.addToStyle(ac, style); - if(right != null) right.addToStyle(ac, style); - if(bottom != null) bottom.addToStyle(ac, style); - if(left != null) left.addToStyle(ac, style); - } - /** - * Get this property in the style. - * - * @param style The style where the property is - * @param resolve if true, resolve the style to find this property - */ - public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) { - if (resolve) { - return ((Css1Style) style).getPadding(); - } else { - return ((Css1Style) style).cssPadding; - } - } + // for use by individual padding-* properties - /** - * Update the source file and the line. - * Overrides this method for a macro - * - * @param line The line number where this property is defined - * @param source The source file where this property is defined - */ - public void setInfo(int line, String source) { - super.setInfo(line, source); - if(top != null) top.setInfo(line, source); - if(right != null) right.setInfo(line, source); - if(bottom != null) bottom.setInfo(line, source); - if(left != null) left.setInfo(line, source); - } + protected static CssValue checkValue(ApplContext ac, + CssExpression expression, + boolean check, CssProperty caller) + throws InvalidParamException { + if (check && expression.getCount() > 1) { + throw new InvalidParamException("unrecognize", ac); + } + CssValue val; + char op; - /** - * Compares two properties for equality. - * - * @param value The other property. - */ - public boolean equals(CssProperty property) { - // @FIXME - return false; - } + val = expression.getValue(); + op = expression.getOperator(); + switch (val.getType()) { + case CssTypes.CSS_NUMBER: + case CssTypes.CSS_LENGTH: + CssLength l = val.getLength(); + l.checkPositiveness(ac, caller); + expression.next(); + return val; + case CssTypes.CSS_PERCENTAGE: + CssPercentage p = val.getPercentage(); + p.checkPositiveness(ac, caller); + return val; + case CssTypes.CSS_IDENT: + if (inherit.equals(val)) { + expression.next(); + return inherit; + } + // if not inherit, or not an ident + // let it flow to the exception + } + throw new InvalidParamException("value", + val.toString(), + caller.getPropertyName(), ac); + } }
Received on Tuesday, 25 September 2012 19:51:30 UTC