Dont go down through JNI to figure out that no margin/padding/border/position was set

Differential Revision: D4080909

fbshipit-source-id: 7eb1885c615191055aa21e3435c6fbc652b883ae
This commit is contained in:
Emil Sjolander 2016-10-26 02:57:07 -07:00 committed by Facebook Github Bot
parent c144bbfb7e
commit 2df4faaf15
1 changed files with 25 additions and 0 deletions

View File

@ -40,6 +40,11 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
private long mNativePointer; private long mNativePointer;
private Object mData; private Object mData;
private boolean mHasSetPadding = false;
private boolean mHasSetMargin = false;
private boolean mHasSetBorder = false;
private boolean mHasSetPosition = false;
private native long jni_CSSNodeNew(); private native long jni_CSSNodeNew();
public CSSNode() { public CSSNode() {
mNativePointer = jni_CSSNodeNew(); mNativePointer = jni_CSSNodeNew();
@ -63,6 +68,10 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
private native void jni_CSSNodeReset(long nativePointer); private native void jni_CSSNodeReset(long nativePointer);
@Override @Override
public void reset() { public void reset() {
mHasSetPadding = false;
mHasSetMargin = false;
mHasSetBorder = false;
mHasSetPosition = false;
jni_CSSNodeReset(mNativePointer); jni_CSSNodeReset(mNativePointer);
} }
@ -304,48 +313,64 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
private native float jni_CSSNodeStyleGetMargin(long nativePointer, int edge); private native float jni_CSSNodeStyleGetMargin(long nativePointer, int edge);
@Override @Override
public float getMargin(int spacingType) { public float getMargin(int spacingType) {
if (!mHasSetMargin) {
return spacingType < Spacing.START ? 0 : CSSConstants.UNDEFINED;
}
return jni_CSSNodeStyleGetMargin(mNativePointer, spacingType); return jni_CSSNodeStyleGetMargin(mNativePointer, spacingType);
} }
private native void jni_CSSNodeStyleSetMargin(long nativePointer, int edge, float margin); private native void jni_CSSNodeStyleSetMargin(long nativePointer, int edge, float margin);
@Override @Override
public void setMargin(int spacingType, float margin) { public void setMargin(int spacingType, float margin) {
mHasSetMargin = true;
jni_CSSNodeStyleSetMargin(mNativePointer, spacingType, margin); jni_CSSNodeStyleSetMargin(mNativePointer, spacingType, margin);
} }
private native float jni_CSSNodeStyleGetPadding(long nativePointer, int edge); private native float jni_CSSNodeStyleGetPadding(long nativePointer, int edge);
@Override @Override
public float getPadding(int spacingType) { public float getPadding(int spacingType) {
if (!mHasSetPadding) {
return spacingType < Spacing.START ? 0 : CSSConstants.UNDEFINED;
}
return jni_CSSNodeStyleGetPadding(mNativePointer, spacingType); return jni_CSSNodeStyleGetPadding(mNativePointer, spacingType);
} }
private native void jni_CSSNodeStyleSetPadding(long nativePointer, int edge, float padding); private native void jni_CSSNodeStyleSetPadding(long nativePointer, int edge, float padding);
@Override @Override
public void setPadding(int spacingType, float padding) { public void setPadding(int spacingType, float padding) {
mHasSetPadding = true;
jni_CSSNodeStyleSetPadding(mNativePointer, spacingType, padding); jni_CSSNodeStyleSetPadding(mNativePointer, spacingType, padding);
} }
private native float jni_CSSNodeStyleGetBorder(long nativePointer, int edge); private native float jni_CSSNodeStyleGetBorder(long nativePointer, int edge);
@Override @Override
public float getBorder(int spacingType) { public float getBorder(int spacingType) {
if (!mHasSetBorder) {
return spacingType < Spacing.START ? 0 : CSSConstants.UNDEFINED;
}
return jni_CSSNodeStyleGetBorder(mNativePointer, spacingType); return jni_CSSNodeStyleGetBorder(mNativePointer, spacingType);
} }
private native void jni_CSSNodeStyleSetBorder(long nativePointer, int edge, float border); private native void jni_CSSNodeStyleSetBorder(long nativePointer, int edge, float border);
@Override @Override
public void setBorder(int spacingType, float border) { public void setBorder(int spacingType, float border) {
mHasSetBorder = true;
jni_CSSNodeStyleSetBorder(mNativePointer, spacingType, border); jni_CSSNodeStyleSetBorder(mNativePointer, spacingType, border);
} }
private native float jni_CSSNodeStyleGetPosition(long nativePointer, int edge); private native float jni_CSSNodeStyleGetPosition(long nativePointer, int edge);
@Override @Override
public float getPosition(int spacingType) { public float getPosition(int spacingType) {
if (!mHasSetPosition) {
return CSSConstants.UNDEFINED;
}
return jni_CSSNodeStyleGetPosition(mNativePointer, spacingType); return jni_CSSNodeStyleGetPosition(mNativePointer, spacingType);
} }
private native void jni_CSSNodeStyleSetPosition(long nativePointer, int edge, float position); private native void jni_CSSNodeStyleSetPosition(long nativePointer, int edge, float position);
@Override @Override
public void setPosition(int spacingType, float position) { public void setPosition(int spacingType, float position) {
mHasSetPosition = true;
jni_CSSNodeStyleSetPosition(mNativePointer, spacingType, position); jni_CSSNodeStyleSetPosition(mNativePointer, spacingType, position);
} }