resolveValue method

  1. @override
dynamic resolveValue(
  1. String propertyName,
  2. String propertyValue, {
  3. String? baseHref,
})
override

Resolve the style value.

Implementation

@override
dynamic resolveValue(String propertyName, String propertyValue, { String? baseHref }) {
  bool uiCommandTracked = false;
  if (enableWebFProfileTracking) {
    if (!WebFProfiler.instance.currentPipeline.containsActiveUICommand()) {
      WebFProfiler.instance.startTrackUICommand();
      uiCommandTracked = true;
    }
    WebFProfiler.instance.startTrackUICommandStep('$this.renderStyle.resolveValue');
  }
  RenderStyle renderStyle = this;

  if (propertyValue == INITIAL) {
    propertyValue = CSSInitialValues[propertyName] ?? propertyValue;
  }

  // Process CSSVariable.
  dynamic value = CSSVariable.tryParse(renderStyle, propertyValue);
  if (value != null) {
    if (enableWebFProfileTracking) {
      WebFProfiler.instance.finishTrackUICommandStep();
      if (uiCommandTracked) {
        WebFProfiler.instance.finishTrackUICommand();
      }
    }
    return value;
  }

  switch (propertyName) {
    case DISPLAY:
      value = CSSDisplayMixin.resolveDisplay(propertyValue);
      break;
    case OVERFLOW_X:
    case OVERFLOW_Y:
      value = CSSOverflowMixin.resolveOverflowType(propertyValue);
      break;
    case POSITION:
      value = CSSPositionMixin.resolvePositionType(propertyValue);
      break;
    case Z_INDEX:
      value = int.tryParse(propertyValue);
      break;
    case TOP:
    case LEFT:
    case BOTTOM:
    case RIGHT:
    case FLEX_BASIS:
    case WIDTH:
    case MIN_WIDTH:
    case MAX_WIDTH:
    case HEIGHT:
    case MIN_HEIGHT:
    case MAX_HEIGHT:
    case X:
    case Y:
    case RX:
    case RY:
    case CX:
    case CY:
    case R:
    case X1:
    case X2:
    case Y1:
    case Y2:
    case STROKE_WIDTH:
      value = CSSLength.resolveLength(propertyValue, renderStyle, propertyName);
      break;
    case PADDING_TOP:
    case MARGIN_TOP:
      List<String?>? values = CSSStyleProperty.getEdgeValues(propertyValue);
      if (values != null && values[0] != null) {
        value = CSSLength.resolveLength(values[0]!, renderStyle, propertyName);
      } else {
        value = CSSLength.resolveLength(propertyValue, renderStyle, propertyName);
      }
      break;
    case MARGIN_RIGHT:
    case PADDING_RIGHT:
      List<String?>? values = CSSStyleProperty.getEdgeValues(propertyValue);
      if (values != null && values[1] != null) {
        value = CSSLength.resolveLength(values[1]!, renderStyle, propertyName);
      } else {
        value = CSSLength.resolveLength(propertyValue, renderStyle, propertyName);
      }
      break;
    case PADDING_BOTTOM:
    case MARGIN_BOTTOM:
      List<String?>? values = CSSStyleProperty.getEdgeValues(propertyValue);
      if (values != null && values[2] != null) {
        value = CSSLength.resolveLength(values[2]!, renderStyle, propertyName);
      } else {
        value = CSSLength.resolveLength(propertyValue, renderStyle, propertyName);
      }
      break;
    case PADDING_LEFT:
    case MARGIN_LEFT:
      List<String?>? values = CSSStyleProperty.getEdgeValues(propertyValue);
      if (values != null && values[3] != null) {
        value = CSSLength.resolveLength(values[3]!, renderStyle, propertyName);
      } else {
        value = CSSLength.resolveLength(propertyValue, renderStyle, propertyName);
      }
      break;
    case FLEX_DIRECTION:
      value = CSSFlexboxMixin.resolveFlexDirection(propertyValue);
      break;
    case FLEX_WRAP:
      value = CSSFlexboxMixin.resolveFlexWrap(propertyValue);
      break;
    case ALIGN_CONTENT:
      value = CSSFlexboxMixin.resolveAlignContent(propertyValue);
      break;
    case ALIGN_ITEMS:
      value = CSSFlexboxMixin.resolveAlignItems(propertyValue);
      break;
    case JUSTIFY_CONTENT:
      value = CSSFlexboxMixin.resolveJustifyContent(propertyValue);
      break;
    case ALIGN_SELF:
      value = CSSFlexboxMixin.resolveAlignSelf(propertyValue);
      break;
    case FLEX_GROW:
      value = CSSFlexboxMixin.resolveFlexGrow(propertyValue);
      break;
    case FLEX_SHRINK:
      value = CSSFlexboxMixin.resolveFlexShrink(propertyValue);
      break;
    case SLIVER_DIRECTION:
      value = CSSSliverMixin.resolveAxis(propertyValue);
      break;
    case TEXT_ALIGN:
      value = CSSTextMixin.resolveTextAlign(propertyValue);
      break;
    case BACKGROUND_ATTACHMENT:
      value = CSSBackground.resolveBackgroundAttachment(propertyValue);
      break;
    case BACKGROUND_IMAGE:
      value = CSSBackground.resolveBackgroundImage(
          propertyValue, renderStyle, propertyName, renderStyle.target.ownerDocument.controller, baseHref);
      break;
    case BACKGROUND_REPEAT:
      value = CSSBackground.resolveBackgroundRepeat(propertyValue);
      break;
    case BACKGROUND_POSITION_X:
      value = CSSPosition.resolveBackgroundPosition(propertyValue, renderStyle, propertyName, true);
      break;
    case BACKGROUND_POSITION_Y:
      value = CSSPosition.resolveBackgroundPosition(propertyValue, renderStyle, propertyName, false);
      break;
    case BACKGROUND_SIZE:
      value = CSSBackground.resolveBackgroundSize(propertyValue, renderStyle, propertyName);
      break;
    case BACKGROUND_CLIP:
      value = CSSBackground.resolveBackgroundClip(propertyValue);
      break;
    case BACKGROUND_ORIGIN:
      value = CSSBackground.resolveBackgroundOrigin(propertyValue);
      break;
    case BORDER_LEFT_WIDTH:
    case BORDER_TOP_WIDTH:
    case BORDER_RIGHT_WIDTH:
    case BORDER_BOTTOM_WIDTH:
      value = CSSBorderSide.resolveBorderWidth(propertyValue, renderStyle, propertyName);
      break;
    case BORDER_LEFT_STYLE:
    case BORDER_TOP_STYLE:
    case BORDER_RIGHT_STYLE:
    case BORDER_BOTTOM_STYLE:
      value = CSSBorderSide.resolveBorderStyle(propertyValue);
      break;
    case COLOR:
    case CARETCOLOR:
    case BACKGROUND_COLOR:
    case TEXT_DECORATION_COLOR:
    case BORDER_LEFT_COLOR:
    case BORDER_TOP_COLOR:
    case BORDER_RIGHT_COLOR:
    case BORDER_BOTTOM_COLOR:
      value = CSSColor.resolveColor(propertyValue, renderStyle, propertyName);
      break;
    case STROKE:
    case FILL:
      value = CSSPaint.parsePaint(propertyValue, renderStyle: renderStyle);
      break;
    case BOX_SHADOW:
      value = CSSBoxShadow.parseBoxShadow(propertyValue, renderStyle, propertyName);
      break;
    case BORDER_TOP_LEFT_RADIUS:
    case BORDER_TOP_RIGHT_RADIUS:
    case BORDER_BOTTOM_LEFT_RADIUS:
    case BORDER_BOTTOM_RIGHT_RADIUS:
      value = CSSBorderRadius.parseBorderRadius(propertyValue, renderStyle, propertyName);
      break;
    case OPACITY:
      value = CSSOpacityMixin.resolveOpacity(propertyValue);
      break;
    case VISIBILITY:
      value = CSSVisibilityMixin.resolveVisibility(propertyValue);
      break;
    case CONTENT_VISIBILITY:
      value = CSSContentVisibilityMixin.resolveContentVisibility(propertyValue);
      break;
    case TRANSFORM:
      value = CSSTransformMixin.resolveTransform(propertyValue);
      break;
    case FILTER:
      value = CSSFunction.parseFunction(propertyValue);
      break;
    case TRANSFORM_ORIGIN:
      value = CSSOrigin.parseOrigin(propertyValue, renderStyle, propertyName);
      break;
    case OBJECT_FIT:
      value = CSSObjectFitMixin.resolveBoxFit(propertyValue);
      break;
    case OBJECT_POSITION:
      value = CSSObjectPositionMixin.resolveObjectPosition(propertyValue);
      break;
    case TEXT_DECORATION_LINE:
      value = CSSText.resolveTextDecorationLine(propertyValue);
      break;
    case TEXT_DECORATION_STYLE:
      value = CSSText.resolveTextDecorationStyle(propertyValue);
      break;
    case FONT_WEIGHT:
      value = CSSText.resolveFontWeight(propertyValue);
      break;
    case FONT_SIZE:
      value = CSSText.resolveFontSize(propertyValue, renderStyle, propertyName);
      break;
    case FONT_STYLE:
      value = CSSText.resolveFontStyle(propertyValue);
      break;
    case FONT_FAMILY:
      value = CSSText.resolveFontFamilyFallback(propertyValue);
      break;
    case LINE_HEIGHT:
      value = CSSText.resolveLineHeight(propertyValue, renderStyle, propertyName);
      break;
    case LETTER_SPACING:
      value = CSSText.resolveSpacing(propertyValue, renderStyle, propertyName);
      break;
    case WORD_SPACING:
      value = CSSText.resolveSpacing(propertyValue, renderStyle, propertyName);
      break;
    case TEXT_SHADOW:
      value = CSSText.resolveTextShadow(propertyValue, renderStyle, propertyName);
      break;
    case WHITE_SPACE:
      value = CSSText.resolveWhiteSpace(propertyValue);
      break;
    case TEXT_OVERFLOW:
      // Overflow will affect text-overflow ellipsis taking effect
      value = CSSText.resolveTextOverflow(propertyValue);
      break;
    case LINE_CLAMP:
      value = CSSText.parseLineClamp(propertyValue);
      break;
    case VERTICAL_ALIGN:
      value = CSSInlineMixin.resolveVerticalAlign(propertyValue);
      break;
    // Transition
    case TRANSITION_DELAY:
    case TRANSITION_DURATION:
    case TRANSITION_TIMING_FUNCTION:
    case TRANSITION_PROPERTY:
      value = CSSStyleProperty.getMultipleValues(propertyValue);
      break;
    // Animation
    case ANIMATION_DELAY:
    case ANIMATION_DIRECTION:
    case ANIMATION_DURATION:
    case ANIMATION_FILL_MODE:
    case ANIMATION_ITERATION_COUNT:
    case ANIMATION_NAME:
    case ANIMATION_PLAY_STATE:
    case ANIMATION_TIMING_FUNCTION:
      value = CSSStyleProperty.getMultipleValues(propertyValue);
      break;
    case D:
      value = CSSPath.parseValue(propertyValue);
      break;
    case FILL_RULE:
      value = CSSSvgMixin.resolveFillRule(propertyValue);
      break;
    case STROKE_LINECAP:
      value = CSSSvgMixin.resolveStrokeLinecap(propertyValue);
      break;
    case STROKE_LINEJOIN:
      value = CSSSvgMixin.resolveStrokeLinejoin(propertyValue);
      break;
  }

  if (enableWebFProfileTracking) {
    WebFProfiler.instance.finishTrackUICommandStep();
    if (uiCommandTracked) {
      WebFProfiler.instance.finishTrackUICommand();
    }
  }

  // --x: foo;
  // Directly passing the value, not to resolve now.
  if (CSSVariable.isVariable(propertyName)) {
    return propertyValue;
  }

  return value;
}