public static LexicalUnit parseComma( final LexicalUnit value ) { if ( value == null ) { return null; } LexicalUnit maybeComma = value.getNextLexicalUnit(); if ( maybeComma == null ) { return null; } if ( maybeComma.getLexicalUnitType() == LexicalUnit.SAC_OPERATOR_COMMA ) { return maybeComma.getNextLexicalUnit(); } return null; }
private static Value valueOf(LexicalUnit value) { switch (value.getLexicalUnitType()) { case LexicalUnit.SAC_ATTR: return new IdentValue("attr(" + value.getStringValue() + ")"); case LexicalUnit.SAC_IDENT: return new IdentValue(escapeIdent(value.getStringValue())); case LexicalUnit.SAC_STRING_VALUE: return new StringValue(value.getStringValue()); case LexicalUnit.SAC_RGBCOLOR: return colorValue(value.getParameters()); case LexicalUnit.SAC_INTEGER: return new NumberValue(value.getIntegerValue()); case LexicalUnit.SAC_REAL: return new NumberValue(value.getFloatValue()); case LexicalUnit.SAC_CENTIMETER: case LexicalUnit.SAC_DEGREE: case LexicalUnit.SAC_RADIAN: case LexicalUnit.SAC_SECOND: return new NumberValue(value.getFloatValue(), value.getDimensionUnitText()); case LexicalUnit.SAC_URI: return new IdentValue("url(" + value.getStringValue() + ")"); case LexicalUnit.SAC_OPERATOR_COMMA: return new TokenValue(","); case LexicalUnit.SAC_COUNTERS_FUNCTION: case LexicalUnit.SAC_FUNCTION: { if (value.getFunctionName().equals(VALUE_FUNCTION_NAME)) {
/** * Return an integer value from 0-255 for a component of an RGB color. * * @param color typed value from the CSS parser, which may be an INTEGER or a * PERCENTAGE * @return integer value from 0-255 * @throws IllegalArgumentException if the color is not an INTEGER or * PERCENTAGE value */ private static int getRgbComponentValue(LexicalUnit color) { switch (color.getLexicalUnitType()) { case LexicalUnit.SAC_INTEGER: return Math.min(color.getIntegerValue(), 255); case LexicalUnit.SAC_PERCENTAGE: return (int) Math.min(color.getFloatValue() * 255, 255); default: throw new CSSException(CSSException.SAC_SYNTAX_ERR, "RGB component value must be integer or percentage, was " + color, null); } }
private static String parseAttributeType( LexicalUnit unit ) { if ( unit == null ) { return null; } if ( unit.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) { return unit.getStringValue(); } return null; }
private Value createICCNamedColorValue(LexicalUnit lu, Value v) { lu = lu.getParameters(); expectIdent(lu); String profileName = lu.getStringValue(); lu = lu.getNextLexicalUnit(); expectComma(lu); lu = lu.getNextLexicalUnit(); expectIdent(lu); String colorName = lu.getStringValue(); ICCNamedColor icc = new ICCNamedColor(profileName, colorName); lu = lu.getNextLexicalUnit(); return icc; }
Float percent = null; String color = null; nextUnit = nextUnit.getNextLexicalUnit(); if( nextUnit != null && nextUnit.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION ) String function = nextUnit.getFunctionName(); if( "from".equals( function ) ) { percent = Float.valueOf( 0f ); LexicalUnit colorUnit = nextUnit.getParameters(); color = readGradientColor( colorUnit ); } else if( "to".equals( function ) ) { percent = Float.valueOf( 100f ); LexicalUnit colorUnit = nextUnit.getParameters(); color = readGradientColor( colorUnit ); } else if( "color-stop".equals( function ) ) { LexicalUnit percentUnit = nextUnit.getParameters(); percent = readGradientPercent( percentUnit ); LexicalUnit colorUnit = percentUnit.getNextLexicalUnit().getNextLexicalUnit(); color = readGradientColor( colorUnit ); } else { throw new IllegalArgumentException( msg ); nextUnit = nextUnit.getNextLexicalUnit();
/** * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}. */ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { if (lu.getLexicalUnitType() == LexicalUnit.SAC_RGBCOLOR) { lu = lu.getParameters(); Value red = createColorComponent(lu); lu = lu.getNextLexicalUnit().getNextLexicalUnit(); Value green = createColorComponent(lu); lu = lu.getNextLexicalUnit().getNextLexicalUnit(); Value blue = createColorComponent(lu); return createRGBColor(red, green, blue); } return super.createValue(lu, engine); }
public String getCssText() { // TODO: All LexicalUnit.SAC_OPERATOR_* except for COMMA left undone for // now as it's not even clear whether they should be treated as measures // see bug #278139 switch (value.getLexicalUnitType()) { case LexicalUnit.SAC_INTEGER: return String.valueOf(value.getIntegerValue()); case LexicalUnit.SAC_REAL: return String.valueOf(value.getFloatValue()); case LexicalUnit.SAC_PERCENTAGE: case LexicalUnit.SAC_PIXEL: case LexicalUnit.SAC_CENTIMETER: case LexicalUnit.SAC_EM: case LexicalUnit.SAC_EX: case LexicalUnit.SAC_PICA: case LexicalUnit.SAC_POINT: case LexicalUnit.SAC_INCH: case LexicalUnit.SAC_DEGREE: return String.valueOf(value.getFloatValue()) + value.getDimensionUnitText(); case LexicalUnit.SAC_URI: return "url(" + value.getStringValue() + ")"; case LexicalUnit.SAC_OPERATOR_COMMA: return ","; case LexicalUnit.SAC_INHERIT: return "inherit"; } return value.getStringValue(); } }
public CSSValue createValue( StyleKey name, LexicalUnit value ) { if ( value.getLexicalUnitType() != LexicalUnit.SAC_PERCENTAGE ) { return null; } return CSSNumericValue.createValue ( CSSNumericType.PERCENTAGE, value.getFloatValue() ); } }
public CSSValue createValue( StyleKey name, LexicalUnit value ) { if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) { String ident = value.getStringValue(); if ( ident.equalsIgnoreCase( "auto" ) ) { return CSSAutoValue.getInstance(); } return null; } if ( value.getLexicalUnitType() != LexicalUnit.SAC_DEGREE ) { return null; } return CSSNumericValue.createValue( CSSNumericType.DEG, value.getFloatValue() ); } }
public RGBColorImpl(LexicalUnit lexicalUnit) { LexicalUnit nextUnit = lexicalUnit.getParameters(); red = new Measure(nextUnit); nextUnit = nextUnit.getNextLexicalUnit().getNextLexicalUnit(); green = new Measure(nextUnit); nextUnit = nextUnit.getNextLexicalUnit().getNextLexicalUnit(); blue = new Measure(nextUnit); }
public CSSValue createValue( StyleKey name, LexicalUnit value ) { if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) { final String stringValue = value.getStringValue(); if ( stringValue.equalsIgnoreCase( "auto" ) ) { return CSSAutoValue.getInstance(); } } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION ) { if ( value.getFunctionName().equalsIgnoreCase( "inset-rect" ) ) { return getRectangle( CSSRectangleType.INSET_RECT, value.getParameters() ); } return null; } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_RECT_FUNCTION ) { return getRectangle( CSSRectangleType.RECT, value.getParameters() ); } return null; }
CssColor color = CssColor.BLACK; LexicalUnit nextUnit = unit; short type = nextUnit.getLexicalUnitType(); if( type == LexicalUnit.SAC_IDENT ) { String value = nextUnit.getStringValue(); if( NONE.equals( value ) ) { result = CssShadow.NONE; inset = true; nextUnit = nextUnit.getNextLexicalUnit(); spread = nextValue.intValue(); nextUnit = nextUnit.getNextLexicalUnit(); type = nextUnit.getLexicalUnitType(); if( type == LexicalUnit.SAC_FUNCTION && "rgba".equals( nextUnit.getFunctionName() ) ) { color = readColorRgba( nextUnit ); } else {
public CSSValue createValue( StyleKey name, LexicalUnit value ) { if ( value.getLexicalUnitType() == LexicalUnit.SAC_INTEGER ) { return CSSNumericValue.createValue( CSSNumericType.NUMBER, value.getIntegerValue() ); } return null; }
public CSSValue createValue( StyleKey name, LexicalUnit value ) { if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) { if ( value.getStringValue().equalsIgnoreCase( "auto" ) ) { return CSSAutoValue.getInstance(); } return null; } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_INTEGER ) { return CSSNumericValue.createValue( CSSNumericType.NUMBER, value.getIntegerValue() ); } return null; } }
static CssImage readBackgroundImage( LexicalUnit unit, ResourceLoader loader ) { CssImage result = null; short type = unit.getLexicalUnitType(); if( type == LexicalUnit.SAC_URI ) { String value = unit.getStringValue(); result = CssImage.valueOf( value, loader ); } else if( type == LexicalUnit.SAC_IDENT ) { String value = unit.getStringValue(); if( NONE.equals( value ) ) { result = CssImage.NONE; } } else if( type == LexicalUnit.SAC_FUNCTION ) { String function = unit.getFunctionName(); if( "gradient".equals( function ) ) { result = readGradient( unit ); } } if( result == null ) { throw new IllegalArgumentException( "Failed to parse image " + toString( unit ) ); } return result; }
/** * Convert a LexicalUnit list into a List of Values. */ private static void extractValueOf(List<Value> accumulator, LexicalUnit value) { do { accumulator.add(valueOf(value)); value = value.getNextLexicalUnit(); } while (value != null); }
private static float getAmountValue(LexicalUnitImpl color) { LexicalUnit next = color.getNextLexicalUnit(); float amount = 10f; if (next != null && next.getNextLexicalUnit() != null) { next = next.getNextLexicalUnit(); amount = next.getFloatValue(); } return amount; }
static CssColor readColor( LexicalUnit unit ) { CssColor result = null; short type = unit.getLexicalUnitType(); if( type == LexicalUnit.SAC_RGBCOLOR ) { result = readColorRgb( unit ); } else if( type == LexicalUnit.SAC_FUNCTION && "rgba".equals( unit.getFunctionName() ) ) { result = readColorRgba( unit ); } else if( type == LexicalUnit.SAC_FUNCTION && "rgb".equals( unit.getFunctionName() ) ) { throw new IllegalArgumentException( "Failed to parse rgb() function" ); } else if( type == LexicalUnit.SAC_IDENT ) { result = readColorNamed( unit ); } else if( type == LexicalUnit.SAC_INHERIT ) { result = CssColor.TRANSPARENT; } if( result == null ) { throw new IllegalArgumentException( "Failed to parse color " + toString( unit ) ); } return result; }
private boolean isIdentOrNumber(LexicalUnit lu) { short type = lu.getLexicalUnitType(); switch (type) { case LexicalUnit.SAC_IDENT: case LexicalUnit.SAC_INTEGER: return true; default: return false; } }