コード例 #1
0
  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;
  }
コード例 #2
0
 private CSSPrimitiveValueImpl createFloatValue(String text, String type) {
   FloatInfo info = new FloatInfo(text);
   CSSPrimitiveValueImpl value = getCSSPrimitiveValue(info.getValueType());
   if (value != null) {
     value.setValue(info.getValue());
   }
   return value;
 }
コード例 #3
0
  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;
  }
コード例 #4
0
 private CSSPrimitiveValueImpl createStringValue(String text, String type) {
   short valueType = getStringValueType(text, type);
   CSSPrimitiveValueImpl value = getCSSPrimitiveValue(valueType);
   if (value != null) {
     if (valueType == CSSPrimitiveValue.CSS_URI) {
       text = CSSUtil.extractUriContents(text);
     } else if (valueType == CSSPrimitiveValue.CSS_STRING) {
       text = CSSUtil.extractStringContents(text);
     }
     value.setValue(text);
   }
   return value;
 }
コード例 #5
0
  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;
  }
コード例 #6
0
  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;
  }
コード例 #7
0
  private CSSPrimitiveValueImpl createLocalValue(ITextRegionList regions) {
    String funcName = getFunctionName(regions);
    if (funcName == null || !funcName.toLowerCase().equals("local")) { // $NON-NLS-1$
      return null;
    }
    String accepts[] = {CSSRegionContexts.CSS_DECLARATION_VALUE_STRING};
    ITextRegionList valueRegions = getFunctionParameters(regions, accepts);
    if (valueRegions.size() != 1) {
      return null;
    }

    CSSPrimitiveValueImpl value = getCSSPrimitiveValue(ICSSPrimitiveValue.CSS_LOCAL);
    if (value == null) {
      return null;
    }

    ITextRegion region = valueRegions.get(0);
    value.setValue(CSSUtil.extractStringContents(getText(region)));

    return value;
  }
コード例 #8
0
  private CSSPrimitiveValueImpl createAttrValue(ITextRegionList regions) {
    String funcName = getFunctionName(regions);
    if (funcName == null || !funcName.toLowerCase().equals("attr")) { // $NON-NLS-1$
      return null;
    }
    String accepts[] = {CSSRegionContexts.CSS_DECLARATION_VALUE_IDENT};
    ITextRegionList valueRegions = getFunctionParameters(regions, accepts);
    if (valueRegions.size() != 1) {
      return null;
    }

    CSSPrimitiveValueImpl value = getCSSPrimitiveValue(CSSPrimitiveValue.CSS_ATTR);
    if (value == null) {
      return null;
    }

    ITextRegion region = valueRegions.get(0);
    value.setValue(getText(region));

    return value;
  }
コード例 #9
0
 private void setStringValue(CSSPrimitiveValueImpl value, String text, String type) {
   short valueType = getStringValueType(text, type);
   value.setStringValue(valueType, text);
 }
コード例 #10
0
 private void setFloatValue(CSSPrimitiveValueImpl value, String text, String type) {
   FloatInfo info = new FloatInfo(text);
   value.setFloatValue(info.getValueType(), info.getValue());
 }