com.taobao.weex.dom.flex.CSSConstants Java Examples

The following examples show how to use com.taobao.weex.dom.flex.CSSConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WXDomUtils.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Get the content height of the dom.
 * @return the height of the dom that excludes top-padding, top-border-width, bottom-padding
 * and bottom-border-width.
 */
public static float getContentHeight(ImmutableDomObject domObject) {
  float rawHeight = domObject.getLayoutHeight();
  float topPadding, bottomPadding, topBorder, bottomBorder;
  Spacing padding = domObject.getPadding();
  Spacing border = domObject.getBorder();

  if (!CSSConstants.isUndefined((topPadding = padding.get(Spacing.TOP)))) {
    rawHeight -= topPadding;
  }
  if (!CSSConstants.isUndefined((bottomPadding = padding.get(Spacing.BOTTOM)))) {
    rawHeight -= bottomPadding;
  }

  if (!CSSConstants.isUndefined(topBorder = border.get(Spacing.TOP))) {
    rawHeight -= topBorder;
  }
  if (!CSSConstants.isUndefined(bottomBorder = border.get(Spacing.BOTTOM))) {
    rawHeight -= bottomBorder;
  }
  return rawHeight;
}
 
Example #2
Source File: WXTextDomObject.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
public void measure(CSSNode node, float width, @NonNull MeasureOutput measureOutput) {
  WXTextDomObject textDomObject = (WXTextDomObject) node;
  if (CSSConstants.isUndefined(width)) {
    width = node.cssstyle.maxWidth;
  }
  if(textDomObject.getTextWidth(textDomObject.mTextPaint,width,false)>0) {
    textDomObject.layout = textDomObject.createLayout(width, false, null);
    textDomObject.hasBeenMeasured = true;
    textDomObject.previousWidth = textDomObject.layout.getWidth();
    measureOutput.height = textDomObject.layout.getHeight();
    measureOutput.width = textDomObject.previousWidth;
  }else{
    measureOutput.height = 0;
    measureOutput.width = 0;
  }
}
 
Example #3
Source File: WXDomUtils.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Get the content height of the dom.
 * @return the height of the dom that excludes top-padding, top-border-width, bottom-padding
 * and bottom-border-width.
 */
public static float getContentHeight(ImmutableDomObject domObject) {
  float rawHeight = domObject.getLayoutHeight();
  float topPadding, bottomPadding, topBorder, bottomBorder;
  Spacing padding = domObject.getPadding();
  Spacing border = domObject.getBorder();

  if (!CSSConstants.isUndefined((topPadding = padding.get(Spacing.TOP)))) {
    rawHeight -= topPadding;
  }
  if (!CSSConstants.isUndefined((bottomPadding = padding.get(Spacing.BOTTOM)))) {
    rawHeight -= bottomPadding;
  }

  if (!CSSConstants.isUndefined(topBorder = border.get(Spacing.TOP))) {
    rawHeight -= topBorder;
  }
  if (!CSSConstants.isUndefined(bottomBorder = border.get(Spacing.BOTTOM))) {
    rawHeight -= bottomBorder;
  }
  return rawHeight;
}
 
Example #4
Source File: WXDomUtils.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Get the content width of the dom.
 * @return the width of the dom that excludes left-padding, left-border-width,
 * right-border-width and right-padding.
 */
public static float getContentWidth(ImmutableDomObject domObject) {
  float rawWidth = domObject.getLayoutWidth();
  float leftPadding, rightPadding, leftBorder, rightBorder;
  Spacing padding = domObject.getPadding();
  Spacing border = domObject.getBorder();

  if (!CSSConstants.isUndefined((leftPadding = padding.get(Spacing.LEFT)))) {
    rawWidth -= leftPadding;
  }
  if (!CSSConstants.isUndefined((rightPadding = padding.get(Spacing.RIGHT)))) {
    rawWidth -= rightPadding;
  }

  if (!CSSConstants.isUndefined(leftBorder = border.get(Spacing.LEFT))) {
    rawWidth -= leftBorder;
  }
  if (!CSSConstants.isUndefined(rightBorder = border.get(Spacing.RIGHT))) {
    rawWidth -= rightBorder;
  }
  return rawWidth;
}
 
Example #5
Source File: WXTextDomObject.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
public void measure(CSSNode node, float width, @NonNull MeasureOutput measureOutput) {
  WXTextDomObject textDomObject = (WXTextDomObject) node;
  if (CSSConstants.isUndefined(width)) {
    width = node.cssstyle.maxWidth;
  }
  if(textDomObject.getTextWidth(textDomObject.mTextPaint,width,false)>0) {
    textDomObject.layout = textDomObject.createLayout(width, false, null);
    textDomObject.hasBeenMeasured = true;
    textDomObject.previousWidth = textDomObject.layout.getWidth();
    measureOutput.height = textDomObject.layout.getHeight();
    measureOutput.width = textDomObject.previousWidth;
  }else{
    measureOutput.height = 0;
    measureOutput.width = 0;
  }
}
 
Example #6
Source File: WXDomUtils.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Get the content width of the dom.
 * @return the width of the dom that excludes left-padding, left-border-width,
 * right-border-width and right-padding.
 */
public static float getContentWidth(ImmutableDomObject domObject) {
  float rawWidth = domObject.getLayoutWidth();
  float leftPadding, rightPadding, leftBorder, rightBorder;
  Spacing padding = domObject.getPadding();
  Spacing border = domObject.getBorder();

  if (!CSSConstants.isUndefined((leftPadding = padding.get(Spacing.LEFT)))) {
    rawWidth -= leftPadding;
  }
  if (!CSSConstants.isUndefined((rightPadding = padding.get(Spacing.RIGHT)))) {
    rawWidth -= rightPadding;
  }

  if (!CSSConstants.isUndefined(leftBorder = border.get(Spacing.LEFT))) {
    rawWidth -= leftBorder;
  }
  if (!CSSConstants.isUndefined(rightBorder = border.get(Spacing.RIGHT))) {
    rawWidth -= rightBorder;
  }
  return rawWidth;
}
 
Example #7
Source File: WXTextDomObject.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/** package **/ float getTextWidth(TextPaint textPaint,float outerWidth, boolean forceToDesired) {
  float textWidth;
  if (forceToDesired) {
    textWidth = outerWidth;
  } else {
    float desiredWidth = Layout.getDesiredWidth(spanned, textPaint);
    if (CSSConstants.isUndefined(outerWidth) || desiredWidth < outerWidth) {
      textWidth = desiredWidth;
    } else {
      textWidth = outerWidth;
    }
  }
  return textWidth;
}
 
Example #8
Source File: BasicEditTextDomObject.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public BasicEditTextDomObject() {
  super();
  mPaint.setTextSize(WXViewUtils.getRealPxByWidth(WXText.sDEFAULT_SIZE,getViewPortWidth()));
  setMeasureFunction(new MeasureFunction() {
    @Override
    public void measure(CSSNode node, float width, MeasureOutput measureOutput) {
      if (CSSConstants.isUndefined(width)) {
        width = node.cssstyle.maxWidth;
      }
      measureOutput.height = getMeasureHeight();
      measureOutput.width = width;
    }
  });
}
 
Example #9
Source File: BasicEditTextDomObject.java    From weex-uikit with MIT License 5 votes vote down vote up
public BasicEditTextDomObject() {
  super();
  mPaint.setTextSize(WXViewUtils.getRealPxByWidth(WXText.sDEFAULT_SIZE,getViewPortWidth()));
  setMeasureFunction(new MeasureFunction() {
    @Override
    public void measure(CSSNode node, float width, MeasureOutput measureOutput) {
      if (CSSConstants.isUndefined(width)) {
        width = node.cssstyle.maxWidth;
      }
      measureOutput.height = getMeasureHeight();
      measureOutput.width = width;
    }
  });
}
 
Example #10
Source File: WXTextDomObject.java    From weex-uikit with MIT License 5 votes vote down vote up
/** package **/ float getTextWidth(TextPaint textPaint,float outerWidth, boolean forceToDesired) {
  float textWidth;
  if (forceToDesired) {
    textWidth = outerWidth;
  } else {
    float desiredWidth = Layout.getDesiredWidth(spanned, textPaint);
    if (CSSConstants.isUndefined(outerWidth) || desiredWidth < outerWidth) {
      textWidth = desiredWidth;
    } else {
      textWidth = outerWidth;
    }
  }
  return textWidth;
}
 
Example #11
Source File: WXTextDomObject.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
public void measure(CSSNode node, float width, MeasureOutput measureOutput) {
  WXTextDomObject textDomObject = (WXTextDomObject) node;
  if (CSSConstants.isUndefined(width)) {
    width = node.cssstyle.maxWidth;
  }
  textDomObject.updateLayout(width,false);
  textDomObject.hasBeenMeasured = true;
  textDomObject.previousWidth = textDomObject.layout.getWidth();
  measureOutput.height = textDomObject.layout.getHeight();
  measureOutput.width = textDomObject.previousWidth;
}
 
Example #12
Source File: WXTextDomObject.java    From weex with Apache License 2.0 5 votes vote down vote up
private float getTextContentWidth(){
  float rawWidth=getLayoutWidth(), left, right;
  Spacing padding=getPadding();
  if(!CSSConstants.isUndefined((left=padding.get(Spacing.LEFT)))){
    rawWidth-=left;
  }
  if(!CSSConstants.isUndefined((right=padding.get(Spacing.RIGHT)))){
    rawWidth-=right;
  }
  return rawWidth;
}
 
Example #13
Source File: WXBackgroundDrawable.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas) {

  updatePathEffect();
  boolean roundedBorders = mBorderCornerRadii != null ||
  (!CSSConstants.isUndefined(mBorderRadius) && mBorderRadius > 0);

  if ((mBorderStyle == null || mBorderStyle == BorderStyle.SOLID) && !roundedBorders) {
    drawRectangularBackgroundWithBorders(canvas);
  }else{
    drawRoundedBackgroundWithBorders(canvas);
  }
}
 
Example #14
Source File: WXBackgroundDrawable.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
public void getOutline(@NonNull Outline outline) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    super.getOutline(outline);
  } else {
    if ((!CSSConstants.isUndefined(mBorderRadius) && mBorderRadius > 0) || mBorderCornerRadii != null) {
      updatePath();

      outline.setConvexPath(mPathForBorderRadiusOutline);
    } else {
      outline.setRect(getBounds());
    }
  }

}
 
Example #15
Source File: WXBackgroundDrawable.java    From weex with Apache License 2.0 5 votes vote down vote up
public void setRadius(float radius, int position) {
  if (mBorderCornerRadii == null) {
    mBorderCornerRadii = new float[4];
    Arrays.fill(mBorderCornerRadii, CSSConstants.UNDEFINED);
  }

  if (!FloatUtil.floatsEqual(mBorderCornerRadii[position], radius)) {
    mBorderCornerRadii[position] = radius;
    mNeedUpdatePathForBorderRadius = true;
    invalidateSelf();
  }
}
 
Example #16
Source File: WXBackgroundDrawable.java    From weex with Apache License 2.0 4 votes vote down vote up
/**
 * For rounded borders we use default "borderWidth" property.
 */
private float getFullBorderWidth() {
  return (mBorderWidth != null && !CSSConstants.isUndefined(mBorderWidth.getRaw(Spacing.ALL))) ?
         mBorderWidth.getRaw(Spacing.ALL) : 0f;
}
 
Example #17
Source File: WXBackgroundDrawable.java    From weex with Apache License 2.0 4 votes vote down vote up
/**
 * We use this method for getting color for rounded borders only similarly as for
 * {@link #getFullBorderWidth}.
 */
private int getFullBorderColor() {
  return (mBorderColor != null && !CSSConstants.isUndefined(mBorderColor.getRaw(Spacing.ALL))) ?
         (int) (long) mBorderColor.getRaw(Spacing.ALL) : DEFAULT_BORDER_COLOR;
}