private CSSPrimitiveValueImpl createPrimitiveValue(ITextRegion region, String propertyValue) { if (region == null) { return null; } CSSPrimitiveValueImpl value = null; String type = region.getType(); String text = propertyValue != null ? propertyValue : getText(region); if (isBlank(type)) { value = null; } else if (type == CSSRegionContexts.CSS_DECLARATION_VALUE_NUMBER || type == CSSRegionContexts.CSS_DECLARATION_VALUE_DIMENSION || type == CSSRegionContexts.CSS_DECLARATION_VALUE_PERCENTAGE) { value = createFloatValue(text, type); } else if (type == CSSRegionContexts.CSS_DECLARATION_VALUE_STRING || type == CSSRegionContexts.CSS_DECLARATION_VALUE_URI || type == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT || type == CSSRegionContexts.CSS_DECLARATION_VALUE_HASH) { value = createStringValue(text, type); } if (value == null) { value = createStringValue(text, type); } if (!fTempStructuredDocument && value != null) { value.setRangeRegion(fParentRegion, region, region); } return value; }
private CSSPrimitiveValueImpl createRectValue(ITextRegionList regions) { String funcName = getFunctionName(regions); if (funcName == null || !funcName.toLowerCase().equals("rect")) { // $NON-NLS-1$ return null; } String accepts[] = { CSSRegionContexts.CSS_DECLARATION_VALUE_NUMBER, CSSRegionContexts.CSS_DECLARATION_VALUE_DIMENSION, CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT }; // IDENT: // for // 'auto' ITextRegionList valueRegions = getFunctionParameters(regions, accepts); if (valueRegions.size() != 4) { return null; } RectImpl value = getRect(); if (value == null) { return null; } for (int i = 0; i < 4; i++) { ITextRegion region = valueRegions.get(i); CSSPrimitiveValueImpl childValue = null; switch (i) { case 0: childValue = (CSSPrimitiveValueImpl) value.getTop(); break; case 1: childValue = (CSSPrimitiveValueImpl) value.getRight(); break; case 2: childValue = (CSSPrimitiveValueImpl) value.getBottom(); break; case 3: childValue = (CSSPrimitiveValueImpl) value.getLeft(); break; default: break; } if (childValue == null) { return null; } String text = getText(region); String type = region.getType(); if (type == CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT) { setStringValue(childValue, text, type); } else { setFloatValue(childValue, text, type); } if (!fTempStructuredDocument) { childValue.setRangeRegion(fParentRegion, region, region); } } return value; }
private CSSPrimitiveValueImpl createRgbValue(ITextRegionList regions) { String funcName = getFunctionName(regions); if (funcName == null || !funcName.toLowerCase().equals("rgb")) { // $NON-NLS-1$ return null; } String accepts[] = { CSSRegionContexts.CSS_DECLARATION_VALUE_NUMBER, CSSRegionContexts.CSS_DECLARATION_VALUE_PERCENTAGE }; ITextRegionList valueRegions = getFunctionParameters(regions, accepts); if (valueRegions.size() != 3) { return null; } RGBColorImpl value = getRGBColor(); if (value == null) { return null; } for (int i = 0; i < 3; i++) { ITextRegion region = valueRegions.get(i); CSSPrimitiveValueImpl childValue = null; switch (i) { case 0: childValue = (CSSPrimitiveValueImpl) value.getRed(); break; case 1: childValue = (CSSPrimitiveValueImpl) value.getGreen(); break; case 2: childValue = (CSSPrimitiveValueImpl) value.getBlue(); break; default: break; } if (childValue == null) { return null; } setFloatValue(childValue, getText(region), region.getType()); if (!fTempStructuredDocument) { childValue.setRangeRegion(fParentRegion, region, region); } } return value; }
private CSSPrimitiveValueImpl createPrimitiveValue(ITextRegionList regions) { CSSPrimitiveValueImpl value = null; CSSUtil.stripSurroundingSpace(regions); if (regions.isEmpty()) { return null; } ITextRegion region = regions.get(0); if (region == null) { return null; } String type = region.getType(); if (type == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION) { String text = getText(region).toLowerCase(); if (text.equals("rgb(")) { // $NON-NLS-1$ value = createRgbValue(regions); } else if (text.equals("counter(")) { // $NON-NLS-1$ value = createCounterValue(regions); } else if (text.equals("counters(")) { // $NON-NLS-1$ value = createCountersValue(regions); } else if (text.equals("attr(")) { // $NON-NLS-1$ value = createAttrValue(regions); } else if (text.equals("format(")) { // $NON-NLS-1$ value = createFormatValue(regions); } else if (text.equals("local(")) { // $NON-NLS-1$ value = createLocalValue(regions); } else if (text.equals("rect(")) { // $NON-NLS-1$ value = createRectValue(regions); } if (value == null) { value = createStringValue(regions); } } else { value = createStringValue(regions); } if (!fTempStructuredDocument && value != null) { value.setRangeRegion(fParentRegion, regions.get(0), regions.get(regions.size() - 1)); } return value; }