diff --git a/BUCK b/BUCK index 956fb103..0875cbd3 100644 --- a/BUCK +++ b/BUCK @@ -33,6 +33,19 @@ cxx_library( visibility = ['PUBLIC'], ) +cxx_library( + name = 'CSSLayout_jni', + soname = 'libcsslayout.so', + srcs = glob(['java/jni/*.c']), + exported_headers = subdir_glob([('', 'java/jni/*.h')]), + header_namespace = '', + compiler_flags = COMPILER_FLAGS, + deps = [ + ':CSSLayout' + ], + visibility = ['PUBLIC'], +) + cxx_binary( name = 'benchmark', srcs = glob(['benchmarks/*.c']), @@ -72,13 +85,16 @@ cxx_test( java_library( name = 'CSSLayout_java', - srcs = glob(['java/**/*.java']), + srcs = glob(['java/com/facebook/csslayout/*.java']), tests=[':CSSLayout_java_tests'], source = '1.7', target = '1.7', deps = [ + ':CSSLayout_jni', INFER_ANNOTATIONS_TARGET, JSR_305_TARGET, + PROGRUARD_ANNOTATIONS_TARGET, + SOLOADER_TARGET, ], visibility = ['PUBLIC'], ) diff --git a/CSSLAYOUT_DEFS b/CSSLAYOUT_DEFS index 29559bc8..397e437c 100644 --- a/CSSLAYOUT_DEFS +++ b/CSSLAYOUT_DEFS @@ -3,5 +3,7 @@ CSSLAYOUT_ROOT = '//...' INFER_ANNOTATIONS_TARGET = '//lib/infer-annotations:infer-annotations' JSR_305_TARGET = '//lib/jsr-305:jsr-305' JUNIT_TARGET = '//lib/junit:junit' +PROGRUARD_ANNOTATIONS_TARGET = '//java/com/facebook/proguard/annotations:annotations' +SOLOADER_TARGET = '//lib/soloader:soloader' GTEST_TARGET = '//lib/gtest:gtest' GTEST_DL_URL = 'https://github.com/google/googletest/archive/release-1.7.0.zip' diff --git a/CSSLayout/CSSLayout.c b/CSSLayout/CSSLayout.c index 31b752e4..20c55fe1 100644 --- a/CSSLayout/CSSLayout.c +++ b/CSSLayout/CSSLayout.c @@ -27,7 +27,7 @@ __forceinline const float fmaxf(const float a, const float b) { CSSNodeRef CSSNodeNew() { CSSNodeRef node = calloc(1, sizeof(CSSNode)); - CSS_ASSERT(node != NULL, "Could not allocate memory for node"); + CSS_ASSERT(node, "Could not allocate memory for node"); CSSNodeInit(node); return node; @@ -123,6 +123,10 @@ void CSSNodeMarkDirty(CSSNodeRef node) { _CSSNodeMarkDirty(node); } +bool CSSNodeIsDirty(CSSNodeRef node) { + return node->isDirty; +} + #define CSS_NODE_PROPERTY_IMPL(type, name, paramName, instanceName) \ void CSSNodeSet##name(CSSNodeRef node, type paramName) { \ node->instanceName = paramName; \ @@ -130,7 +134,7 @@ void CSSNodeSet##name(CSSNodeRef node, type paramName) { \ \ type CSSNodeGet##name(CSSNodeRef node) { \ return node->instanceName; \ -} \ +} #define CSS_NODE_STYLE_PROPERTY_IMPL(type, name, paramName, instanceName) \ void CSSNodeStyleSet##name(CSSNodeRef node, type paramName) { \ @@ -142,12 +146,12 @@ void CSSNodeStyleSet##name(CSSNodeRef node, type paramName) { \ \ type CSSNodeStyleGet##name(CSSNodeRef node) { \ return node->style.instanceName; \ -} \ +} #define CSS_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \ type CSSNodeLayoutGet##name(CSSNodeRef node) { \ return node->layout.instanceName; \ -} \ +} CSS_NODE_PROPERTY_IMPL(void*, Context, context, context); CSS_NODE_PROPERTY_IMPL(CSSMeasureFunc, MeasureFunc, measureFunc, measure); @@ -211,8 +215,15 @@ CSS_NODE_LAYOUT_PROPERTY_IMPL(CSSDirection, Direction, direction); uint32_t gCurrentGenerationCount = 0; -bool layoutNodeInternal(CSSNode* node, float availableWidth, float availableHeight, CSSDirection parentDirection, - CSSMeasureMode widthMeasureMode, CSSMeasureMode heightMeasureMode, bool performLayout, char* reason); +bool layoutNodeInternal( + CSSNode* node, + float availableWidth, + float availableHeight, + CSSDirection parentDirection, + CSSMeasureMode widthMeasureMode, + CSSMeasureMode heightMeasureMode, + bool performLayout, + char* reason); bool isUndefined(float value) { return isnan(value); diff --git a/CSSLayout/CSSLayout.h b/CSSLayout/CSSLayout.h index 9d5af32a..8c46cea3 100644 --- a/CSSLayout/CSSLayout.h +++ b/CSSLayout/CSSLayout.h @@ -136,6 +136,7 @@ void CSSNodeCalculateLayout( // CSSLayout knows when to mark all other nodes as dirty but because nodes with measure functions // depends on information not known to CSSLayout they must perform this dirty marking manually. void CSSNodeMarkDirty(CSSNodeRef node); +bool CSSNodeIsDirty(CSSNodeRef node); void CSSNodePrint(CSSNodeRef node, CSSPrintOptions options); diff --git a/java/com/facebook/csslayout/CSSNode.java b/java/com/facebook/csslayout/CSSNode.java index a06639ae..3ea3b2c5 100644 --- a/java/com/facebook/csslayout/CSSNode.java +++ b/java/com/facebook/csslayout/CSSNode.java @@ -28,9 +28,9 @@ import static com.facebook.csslayout.Spacing.TOP; * A CSS Node. It has a style object you can manipulate at {@link #style}. After calling * {@link #calculateLayout()}, {@link #layout} will be filled with the results of the layout. */ -public class CSSNode { +public class CSSNode implements CSSNodeAPI { - private static enum LayoutState { + private enum LayoutState { /** * Some property of this node or its children has changes and the current values in * {@link #layout} are not valid. @@ -49,24 +49,14 @@ public class CSSNode { UP_TO_DATE, } - public static interface MeasureFunction { - - /** - * Should measure the given node and put the result in the given MeasureOutput. - * - * NB: measure is NOT guaranteed to be threadsafe/re-entrant safe! - */ - public void measure(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode, MeasureOutput measureOutput); - } - // VisibleForTesting - /*package*/ final CSSStyle style = new CSSStyle(); - /*package*/ final CSSLayout layout = new CSSLayout(); - /*package*/ final CachedCSSLayout lastLayout = new CachedCSSLayout(); + final CSSStyle style = new CSSStyle(); + final CSSLayout layout = new CSSLayout(); + final CachedCSSLayout lastLayout = new CachedCSSLayout(); public int lineIndex = 0; - /*package*/ CSSNode nextChild; + CSSNode nextChild; private @Nullable ArrayList mChildren; private @Nullable CSSNode mParent; @@ -74,15 +64,23 @@ public class CSSNode { private LayoutState mLayoutState = LayoutState.DIRTY; private boolean mIsTextNode = false; + @Override + public void init() { + reset(); + } + + @Override public int getChildCount() { return mChildren == null ? 0 : mChildren.size(); } + @Override public CSSNode getChildAt(int i) { Assertions.assertNotNull(mChildren); return mChildren.get(i); } + @Override public void addChildAt(CSSNode child, int i) { if (child.mParent != null) { throw new IllegalStateException("Child already has a parent, it must be removed first."); @@ -97,6 +95,7 @@ public class CSSNode { dirty(); } + @Override public CSSNode removeChildAt(int i) { Assertions.assertNotNull(mChildren); CSSNode removed = mChildren.remove(i); @@ -105,6 +104,7 @@ public class CSSNode { return removed; } + @Override public @Nullable CSSNode getParent() { return mParent; } @@ -112,11 +112,13 @@ public class CSSNode { /** * @return the index of the given child, or -1 if the child doesn't exist in this node. */ + @Override public int indexOf(CSSNode child) { Assertions.assertNotNull(mChildren); return mChildren.indexOf(child); } + @Override public void setMeasureFunction(MeasureFunction measureFunction) { if (mMeasureFunction != measureFunction) { mMeasureFunction = measureFunction; @@ -124,19 +126,22 @@ public class CSSNode { } } + @Override public boolean isMeasureDefined() { return mMeasureFunction != null; } + @Override public void setIsTextNode(boolean isTextNode) { mIsTextNode = isTextNode; } + @Override public boolean isTextNode() { return mIsTextNode; } - /*package*/ MeasureOutput measure(MeasureOutput measureOutput, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) { + MeasureOutput measure(MeasureOutput measureOutput, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) { if (!isMeasureDefined()) { throw new RuntimeException("Measure function isn't defined!"); } @@ -149,6 +154,7 @@ public class CSSNode { /** * Performs the actual layout and saves the results in {@link #layout} */ + @Override public void calculateLayout(CSSLayoutContext layoutContext) { LayoutEngine.layoutNode(layoutContext, this, CSSConstants.UNDEFINED, CSSConstants.UNDEFINED, null); } @@ -156,18 +162,21 @@ public class CSSNode { /** * See {@link LayoutState#DIRTY}. */ - protected boolean isDirty() { + @Override + public boolean isDirty() { return mLayoutState == LayoutState.DIRTY; } /** * See {@link LayoutState#HAS_NEW_LAYOUT}. */ + @Override public boolean hasNewLayout() { return mLayoutState == LayoutState.HAS_NEW_LAYOUT; } - protected void dirty() { + @Override + public void dirty() { if (mLayoutState == LayoutState.DIRTY) { return; } else if (mLayoutState == LayoutState.HAS_NEW_LAYOUT) { @@ -181,7 +190,7 @@ public class CSSNode { } } - /*package*/ void markHasNewLayout() { + void markHasNewLayout() { mLayoutState = LayoutState.HAS_NEW_LAYOUT; } @@ -190,6 +199,7 @@ public class CSSNode { * to {@link #hasNewLayout()} will return false until this node is laid out with new parameters. * You must call this each time the layout is generated if the node has a new layout. */ + @Override public void markLayoutSeen() { if (!hasNewLayout()) { throw new IllegalStateException("Expected node to have a new layout to be seen!"); @@ -227,17 +237,20 @@ public class CSSNode { return sb.toString(); } - protected boolean valuesEqual(float f1, float f2) { + @Override + public boolean valuesEqual(float f1, float f2) { return FloatUtil.floatsEqual(f1, f2); } /** * Get this node's direction, as defined in the style. */ + @Override public CSSDirection getStyleDirection() { return style.direction; } + @Override public void setDirection(CSSDirection direction) { if (style.direction != direction) { style.direction = direction; @@ -248,10 +261,12 @@ public class CSSNode { /** * Get this node's flex direction, as defined by style. */ + @Override public CSSFlexDirection getFlexDirection() { return style.flexDirection; } + @Override public void setFlexDirection(CSSFlexDirection flexDirection) { if (style.flexDirection != flexDirection) { style.flexDirection = flexDirection; @@ -262,10 +277,12 @@ public class CSSNode { /** * Get this node's justify content, as defined by style. */ + @Override public CSSJustify getJustifyContent() { return style.justifyContent; } + @Override public void setJustifyContent(CSSJustify justifyContent) { if (style.justifyContent != justifyContent) { style.justifyContent = justifyContent; @@ -276,10 +293,12 @@ public class CSSNode { /** * Get this node's align items, as defined by style. */ + @Override public CSSAlign getAlignItems() { return style.alignItems; } + @Override public void setAlignItems(CSSAlign alignItems) { if (style.alignItems != alignItems) { style.alignItems = alignItems; @@ -290,10 +309,12 @@ public class CSSNode { /** * Get this node's align items, as defined by style. */ + @Override public CSSAlign getAlignSelf() { return style.alignSelf; } + @Override public void setAlignSelf(CSSAlign alignSelf) { if (style.alignSelf != alignSelf) { style.alignSelf = alignSelf; @@ -304,10 +325,12 @@ public class CSSNode { /** * Get this node's position type, as defined by style. */ + @Override public CSSPositionType getPositionType() { return style.positionType; } + @Override public void setPositionType(CSSPositionType positionType) { if (style.positionType != positionType) { style.positionType = positionType; @@ -315,6 +338,7 @@ public class CSSNode { } } + @Override public void setWrap(CSSWrap flexWrap) { if (style.flexWrap != flexWrap) { style.flexWrap = flexWrap; @@ -325,10 +349,12 @@ public class CSSNode { /** * Get this node's flex, as defined by style. */ + @Override public float getFlex() { return style.flex; } + @Override public void setFlex(float flex) { if (!valuesEqual(style.flex, flex)) { style.flex = flex; @@ -339,10 +365,12 @@ public class CSSNode { /** * Get this node's margin, as defined by style + default margin. */ + @Override public Spacing getMargin() { return style.margin; } + @Override public void setMargin(int spacingType, float margin) { if (style.margin.set(spacingType, margin)) { dirty(); @@ -352,10 +380,12 @@ public class CSSNode { /** * Get this node's padding, as defined by style + default padding. */ + @Override public Spacing getPadding() { return style.padding; } + @Override public void setPadding(int spacingType, float padding) { if (style.padding.set(spacingType, padding)) { dirty(); @@ -365,10 +395,12 @@ public class CSSNode { /** * Get this node's border, as defined by style. */ + @Override public Spacing getBorder() { return style.border; } + @Override public void setBorder(int spacingType, float border) { if (style.border.set(spacingType, border)) { dirty(); @@ -378,10 +410,12 @@ public class CSSNode { /** * Get this node's position, as defined by style. */ - public Spacing getPositionValue() { + @Override + public Spacing getPositionValue() { return style.position; } + @Override public void setPositionValue(int spacingType, float position) { if (style.position.set(spacingType, position)) { dirty(); @@ -391,10 +425,12 @@ public class CSSNode { /** * Get this node's position top, as defined by style. */ + @Override public float getPositionTop() { return style.position.get(TOP); } + @Override public void setPositionTop(float positionTop) { setPositionValue(TOP, positionTop); } @@ -402,10 +438,12 @@ public class CSSNode { /** * Get this node's position bottom, as defined by style. */ + @Override public float getPositionBottom() { return style.position.get(BOTTOM); } + @Override public void setPositionBottom(float positionBottom) { setPositionValue(BOTTOM, positionBottom); } @@ -413,10 +451,12 @@ public class CSSNode { /** * Get this node's position left, as defined by style. */ + @Override public float getPositionLeft() { return style.position.get(LEFT); } + @Override public void setPositionLeft(float positionLeft) { setPositionValue(LEFT, positionLeft); } @@ -424,10 +464,12 @@ public class CSSNode { /** * Get this node's position right, as defined by style. */ + @Override public float getPositionRight() { return style.position.get(RIGHT); } + @Override public void setPositionRight(float positionRight) { setPositionValue(RIGHT, positionRight); } @@ -435,10 +477,12 @@ public class CSSNode { /** * Get this node's width, as defined in the style. */ + @Override public float getStyleWidth() { return style.dimensions[DIMENSION_WIDTH]; } + @Override public void setStyleWidth(float width) { if (!valuesEqual(style.dimensions[DIMENSION_WIDTH], width)) { style.dimensions[DIMENSION_WIDTH] = width; @@ -449,10 +493,12 @@ public class CSSNode { /** * Get this node's height, as defined in the style. */ + @Override public float getStyleHeight() { return style.dimensions[DIMENSION_HEIGHT]; } + @Override public void setStyleHeight(float height) { if (!valuesEqual(style.dimensions[DIMENSION_HEIGHT], height)) { style.dimensions[DIMENSION_HEIGHT] = height; @@ -463,10 +509,12 @@ public class CSSNode { /** * Get this node's max width, as defined in the style */ + @Override public float getStyleMaxWidth() { return style.maxWidth; } + @Override public void setStyleMaxWidth(float maxWidth) { if (!valuesEqual(style.maxWidth, maxWidth)) { style.maxWidth = maxWidth; @@ -477,10 +525,12 @@ public class CSSNode { /** * Get this node's min width, as defined in the style */ + @Override public float getStyleMinWidth() { return style.minWidth; } + @Override public void setStyleMinWidth(float minWidth) { if (!valuesEqual(style.minWidth, minWidth)) { style.minWidth = minWidth; @@ -491,10 +541,12 @@ public class CSSNode { /** * Get this node's max height, as defined in the style */ + @Override public float getStyleMaxHeight() { return style.maxHeight; } + @Override public void setStyleMaxHeight(float maxHeight) { if (!valuesEqual(style.maxHeight, maxHeight)) { style.maxHeight = maxHeight; @@ -505,10 +557,12 @@ public class CSSNode { /** * Get this node's min height, as defined in the style */ + @Override public float getStyleMinHeight() { return style.minHeight; } + @Override public void setStyleMinHeight(float minHeight) { if (!valuesEqual(style.minHeight, minHeight)) { style.minHeight = minHeight; @@ -516,22 +570,27 @@ public class CSSNode { } } + @Override public float getLayoutX() { return layout.position[POSITION_LEFT]; } + @Override public float getLayoutY() { return layout.position[POSITION_TOP]; } + @Override public float getLayoutWidth() { return layout.dimensions[DIMENSION_WIDTH]; } + @Override public float getLayoutHeight() { return layout.dimensions[DIMENSION_HEIGHT]; } + @Override public CSSDirection getLayoutDirection() { return layout.direction; } @@ -539,6 +598,7 @@ public class CSSNode { /** * Set a default padding (left/top/right/bottom) for this node. */ + @Override public void setDefaultPadding(int spacingType, float padding) { if (style.padding.setDefault(spacingType, padding)) { dirty(); @@ -548,10 +608,12 @@ public class CSSNode { /** * Get this node's overflow property, as defined in the style */ + @Override public CSSOverflow getOverflow() { return style.overflow; } + @Override public void setOverflow(CSSOverflow overflow) { if (style.overflow != overflow) { style.overflow = overflow; @@ -563,6 +625,7 @@ public class CSSNode { * Resets this instance to its default state. This method is meant to be used when * recycling {@link CSSNode} instances. */ + @Override public void reset() { if (mParent != null || (mChildren != null && mChildren.size() > 0)) { throw new IllegalStateException("You should not reset an attached CSSNode"); diff --git a/java/com/facebook/csslayout/CSSNodeAPI.java b/java/com/facebook/csslayout/CSSNodeAPI.java new file mode 100644 index 00000000..765b135b --- /dev/null +++ b/java/com/facebook/csslayout/CSSNodeAPI.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +package com.facebook.csslayout; + +public interface CSSNodeAPI { + + interface MeasureFunction { + void measure( + CSSNodeAPI node, + float width, + CSSMeasureMode widthMode, + float height, + CSSMeasureMode heightMode, + MeasureOutput measureOutput); + } + + int getChildCount(); + CSSNodeType getChildAt(int i); + void addChildAt(CSSNodeType child, int i); + CSSNodeType removeChildAt(int i); + CSSNodeType getParent(); + int indexOf(CSSNodeType child); + void setMeasureFunction(MeasureFunction measureFunction); + boolean isMeasureDefined(); + void setIsTextNode(boolean isTextNode); + boolean isTextNode(); + void calculateLayout(CSSLayoutContext layoutContext); + boolean isDirty(); + boolean hasNewLayout(); + void dirty(); + void markLayoutSeen(); + boolean valuesEqual(float f1, float f2); + CSSDirection getStyleDirection(); + void setDirection(CSSDirection direction); + CSSFlexDirection getFlexDirection(); + void setFlexDirection(CSSFlexDirection flexDirection); + CSSJustify getJustifyContent(); + void setJustifyContent(CSSJustify justifyContent); + CSSAlign getAlignItems(); + void setAlignItems(CSSAlign alignItems); + CSSAlign getAlignSelf(); + void setAlignSelf(CSSAlign alignSelf); + CSSPositionType getPositionType(); + void setPositionType(CSSPositionType positionType); + void setWrap(CSSWrap flexWrap); + float getFlex(); + void setFlex(float flex); + Spacing getMargin(); + void setMargin(int spacingType, float margin); + Spacing getPadding(); + void setPadding(int spacingType, float padding); + Spacing getBorder(); + void setBorder(int spacingType, float border); + Spacing getPositionValue(); + void setPositionValue(int spacingType, float position); + float getPositionTop(); + void setPositionTop(float positionTop); + float getPositionBottom(); + void setPositionBottom(float positionBottom); + float getPositionLeft(); + void setPositionLeft(float positionLeft); + float getPositionRight(); + void setPositionRight(float positionRight); + float getStyleWidth(); + void setStyleWidth(float width); + float getStyleHeight(); + void setStyleHeight(float height); + float getStyleMaxWidth(); + void setStyleMaxWidth(float maxWidth); + float getStyleMinWidth(); + void setStyleMinWidth(float minWidth); + float getStyleMaxHeight(); + void setStyleMaxHeight(float maxHeight); + float getStyleMinHeight(); + void setStyleMinHeight(float minHeight); + float getLayoutX(); + float getLayoutY(); + float getLayoutWidth(); + float getLayoutHeight(); + CSSDirection getLayoutDirection(); + void setDefaultPadding(int spacingType, float padding); + CSSOverflow getOverflow(); + void setOverflow(CSSOverflow overflow); + void init(); + void reset(); +} diff --git a/java/com/facebook/csslayout/CSSNodeJNI.java b/java/com/facebook/csslayout/CSSNodeJNI.java new file mode 100644 index 00000000..b6a37fe5 --- /dev/null +++ b/java/com/facebook/csslayout/CSSNodeJNI.java @@ -0,0 +1,715 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +package com.facebook.csslayout; + +import javax.annotation.Nullable; + +import java.util.List; +import java.util.ArrayList; + +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.soloader.SoLoader; + +public class CSSNodeJNI implements CSSNodeAPI { + + static { + SoLoader.loadLibrary("csslayout"); + } + + private CSSNodeJNI mParent; + private List mChildren; + private MeasureFunction mMeasureFunction; + private int mNativePointer; + + private void assertNativeInstance() { + if (mNativePointer == 0) { + throw new IllegalStateException("Null native pointer"); + } + } + + private native int jni_CSSNodeNew(); + @Override + public void init() { + if (mNativePointer != 0) { + throw new IllegalStateException("Allready initialized node"); + } + + mNativePointer = jni_CSSNodeNew(); + mChildren = new ArrayList<>(4); + } + + private native void jni_CSSNodeFree(int nativePointer); + @Override + public void reset() { + assertNativeInstance(); + + jni_CSSNodeFree(mNativePointer); + mNativePointer = 0; + mChildren = null; + mParent = null; + mMeasureFunction = null; + } + + @Override + public int getChildCount() { + return mChildren.size(); + } + + @Override + public CSSNodeJNI getChildAt(int i) { + return mChildren.get(i); + } + + private native void jni_CSSNodeInsertChild(int nativePointer, int childPointer, int index); + @Override + public void addChildAt(CSSNodeJNI child, int i) { + assertNativeInstance(); + + mChildren.add(i, child); + child.mParent = this; + jni_CSSNodeInsertChild(mNativePointer, child.mNativePointer, i); + } + + private native void jni_CSSNodeRemoveChild(int nativePointer, int childPointer); + @Override + public CSSNodeJNI removeChildAt(int i) { + assertNativeInstance(); + + final CSSNodeJNI child = mChildren.remove(i); + child.mParent = null; + jni_CSSNodeRemoveChild(mNativePointer, child.mNativePointer); + return child; + } + + @Override + public @Nullable CSSNodeJNI getParent() { + return mParent; + } + + @Override + public int indexOf(CSSNodeJNI child) { + return mChildren.indexOf(child); + } + + private native void jni_CSSNodeSetIsTextNode(int nativePointer, boolean isTextNode); + @Override + public void setIsTextNode(boolean isTextNode) { + assertNativeInstance(); + jni_CSSNodeSetIsTextNode(mNativePointer, isTextNode); + } + + private native boolean jni_CSSNodeGetIsTextNode(int nativePointer); + @Override + public boolean isTextNode() { + assertNativeInstance(); + return jni_CSSNodeGetIsTextNode(mNativePointer); + } + + private native void jni_CSSNodeCalculateLayout(int nativePointer); + @Override + public void calculateLayout(CSSLayoutContext layoutContext) { + assertNativeInstance(); + jni_CSSNodeCalculateLayout(mNativePointer); + } + + private native boolean jni_CSSNodeHasNewLayout(int nativePointer); + @Override + public boolean hasNewLayout() { + assertNativeInstance(); + return jni_CSSNodeHasNewLayout(mNativePointer); + } + + private native void jni_CSSNodeMarkDirty(int nativePointer); + @Override + public void dirty() { + assertNativeInstance(); + jni_CSSNodeMarkDirty(mNativePointer); + } + + private native boolean jni_CSSNodeIsDirty(int nativePointer); + @Override + public boolean isDirty() { + return jni_CSSNodeIsDirty(mNativePointer); + } + + private native void jni_CSSNodeMarkLayoutSeen(int nativePointer); + @Override + public void markLayoutSeen() { + assertNativeInstance(); + jni_CSSNodeMarkLayoutSeen(mNativePointer); + } + + private native int jni_CSSNodeStyleGetDirection(int nativePointer); + @Override + public CSSDirection getStyleDirection() { + assertNativeInstance(); + return CSSDirection.values()[jni_CSSNodeStyleGetDirection(mNativePointer)]; + } + + private native void jni_CSSNodeStyleSetDirection(int nativePointer, int direction); + @Override + public void setDirection(CSSDirection direction) { + assertNativeInstance(); + jni_CSSNodeStyleSetDirection(mNativePointer, direction.ordinal()); + } + + private native int jni_CSSNodeLayoutGetDirection(int nativePointer); + @Override + public CSSDirection getLayoutDirection() { + assertNativeInstance(); + return CSSDirection.values()[jni_CSSNodeLayoutGetDirection(mNativePointer)]; + } + + private native int jni_CSSNodeStyleGetFlexDirection(int nativePointer); + @Override + public CSSFlexDirection getFlexDirection() { + assertNativeInstance(); + return CSSFlexDirection.values()[jni_CSSNodeStyleGetFlexDirection(mNativePointer)]; + } + + private native void jni_CSSNodeStyleSetFlexDirection(int nativePointer, int flexDirection); + @Override + public void setFlexDirection(CSSFlexDirection flexDirection) { + assertNativeInstance(); + jni_CSSNodeStyleSetFlexDirection(mNativePointer, flexDirection.ordinal()); + } + + private native int jni_CSSNodeStyleGetJustifyContent(int nativePointer); + @Override + public CSSJustify getJustifyContent() { + assertNativeInstance(); + return CSSJustify.values()[jni_CSSNodeStyleGetJustifyContent(mNativePointer)]; + } + + private native void jni_CSSNodeStyleSetJustifyContent(int nativePointer, int justifyContent); + @Override + public void setJustifyContent(CSSJustify justifyContent) { + assertNativeInstance(); + jni_CSSNodeStyleSetJustifyContent(mNativePointer, justifyContent.ordinal()); + } + + private native int jni_CSSNodeStyleGetAlignItems(int nativePointer); + @Override + public CSSAlign getAlignItems() { + assertNativeInstance(); + return CSSAlign.values()[jni_CSSNodeStyleGetAlignItems(mNativePointer)]; + } + + private native void jni_CSSNodeStyleSetAlignItems(int nativePointer, int alignItems); + @Override + public void setAlignItems(CSSAlign alignItems) { + assertNativeInstance(); + jni_CSSNodeStyleSetAlignItems(mNativePointer, alignItems.ordinal()); + } + + private native int jni_CSSNodeStyleGetAlignSelf(int nativePointer); + @Override + public CSSAlign getAlignSelf() { + assertNativeInstance(); + return CSSAlign.values()[jni_CSSNodeStyleGetAlignSelf(mNativePointer)]; + } + + private native void jni_CSSNodeStyleSetAlignSelf(int nativePointer, int alignSelf); + @Override + public void setAlignSelf(CSSAlign alignSelf) { + assertNativeInstance(); + jni_CSSNodeStyleSetAlignSelf(mNativePointer, alignSelf.ordinal()); + } + + private native int jni_CSSNodeStyleGetPositionType(int nativePointer); + @Override + public CSSPositionType getPositionType() { + assertNativeInstance(); + return CSSPositionType.values()[jni_CSSNodeStyleGetPositionType(mNativePointer)]; + } + + private native void jni_CSSNodeStyleSetPositionType(int nativePointer, int positionType); + @Override + public void setPositionType(CSSPositionType positionType) { + assertNativeInstance(); + jni_CSSNodeStyleSetPositionType(mNativePointer, positionType.ordinal()); + } + + private native void jni_CSSNodeStyleSetFlexWrap(int nativePointer, int wrapType); + @Override + public void setWrap(CSSWrap flexWrap) { + assertNativeInstance(); + jni_CSSNodeStyleSetFlexWrap(mNativePointer, flexWrap.ordinal()); + } + + private native int jni_CSSNodeStyleGetOverflow(int nativePointer); + @Override + public CSSOverflow getOverflow() { + assertNativeInstance(); + return CSSOverflow.values()[jni_CSSNodeStyleGetOverflow(mNativePointer)]; + } + + private native void jni_CSSNodeStyleSetOverflow(int nativePointer, int overflow); + @Override + public void setOverflow(CSSOverflow overflow) { + assertNativeInstance(); + jni_CSSNodeStyleSetOverflow(mNativePointer, overflow.ordinal()); + } + + private native float jni_CSSNodeStyleGetFlex(int nativePointer); + @Override + public float getFlex() { + assertNativeInstance(); + return jni_CSSNodeStyleGetFlex(mNativePointer); + } + + private native void jni_CSSNodeStyleSetFlex(int nativePointer, float flex); + @Override + public void setFlex(float flex) { + assertNativeInstance(); + jni_CSSNodeStyleSetFlex(mNativePointer, flex); + } + + private native float jni_CSSNodeStyleGetMarginLeft(int nativePointer); + private native float jni_CSSNodeStyleGetMarginTop(int nativePointer); + private native float jni_CSSNodeStyleGetMarginRight(int nativePointer); + private native float jni_CSSNodeStyleGetMarginBottom(int nativePointer); + private native float jni_CSSNodeStyleGetMarginStart(int nativePointer); + private native float jni_CSSNodeStyleGetMarginEnd(int nativePointer); + @Override + public Spacing getMargin() { + assertNativeInstance(); + Spacing margin = new Spacing(); + margin.set(Spacing.LEFT, jni_CSSNodeStyleGetMarginLeft(mNativePointer)); + margin.set(Spacing.TOP, jni_CSSNodeStyleGetMarginTop(mNativePointer)); + margin.set(Spacing.RIGHT, jni_CSSNodeStyleGetMarginRight(mNativePointer)); + margin.set(Spacing.BOTTOM, jni_CSSNodeStyleGetMarginBottom(mNativePointer)); + margin.set(Spacing.START, jni_CSSNodeStyleGetMarginStart(mNativePointer)); + margin.set(Spacing.END, jni_CSSNodeStyleGetMarginEnd(mNativePointer)); + return margin; + } + + private native void jni_CSSNodeStyleSetMarginLeft(int nativePointer, float marginLeft); + private native void jni_CSSNodeStyleSetMarginTop(int nativePointer, float marginTop); + private native void jni_CSSNodeStyleSetMarginRight(int nativePointer, float marginRight); + private native void jni_CSSNodeStyleSetMarginBottom(int nativePointer, float marginBottom); + private native void jni_CSSNodeStyleSetMarginStart(int nativePointer, float marginStart); + private native void jni_CSSNodeStyleSetMarginEnd(int nativePointer, float marginEnd); + @Override + public void setMargin(int spacingType, float margin) { + assertNativeInstance(); + switch (spacingType) { + case Spacing.LEFT: + jni_CSSNodeStyleSetMarginLeft(mNativePointer, margin); + break; + case Spacing.TOP: + jni_CSSNodeStyleSetMarginTop(mNativePointer, margin); + break; + case Spacing.RIGHT: + jni_CSSNodeStyleSetMarginRight(mNativePointer, margin); + break; + case Spacing.BOTTOM: + jni_CSSNodeStyleSetMarginBottom(mNativePointer, margin); + break; + case Spacing.START: + jni_CSSNodeStyleSetMarginStart(mNativePointer, margin); + break; + case Spacing.END: + jni_CSSNodeStyleSetMarginEnd(mNativePointer, margin); + break; + case Spacing.HORIZONTAL: + jni_CSSNodeStyleSetMarginLeft(mNativePointer, margin); + jni_CSSNodeStyleSetMarginRight(mNativePointer, margin); + jni_CSSNodeStyleSetMarginStart(mNativePointer, margin); + jni_CSSNodeStyleSetMarginEnd(mNativePointer, margin); + break; + case Spacing.VERTICAL: + jni_CSSNodeStyleSetMarginTop(mNativePointer, margin); + jni_CSSNodeStyleSetMarginBottom(mNativePointer, margin); + break; + case Spacing.ALL: + jni_CSSNodeStyleSetMarginLeft(mNativePointer, margin); + jni_CSSNodeStyleSetMarginRight(mNativePointer, margin); + jni_CSSNodeStyleSetMarginStart(mNativePointer, margin); + jni_CSSNodeStyleSetMarginEnd(mNativePointer, margin); + jni_CSSNodeStyleSetMarginTop(mNativePointer, margin); + jni_CSSNodeStyleSetMarginBottom(mNativePointer, margin); + break; + } + } + + private native float jni_CSSNodeStyleGetPaddingLeft(int nativePointer); + private native float jni_CSSNodeStyleGetPaddingTop(int nativePointer); + private native float jni_CSSNodeStyleGetPaddingRight(int nativePointer); + private native float jni_CSSNodeStyleGetPaddingBottom(int nativePointer); + private native float jni_CSSNodeStyleGetPaddingStart(int nativePointer); + private native float jni_CSSNodeStyleGetPaddingEnd(int nativePointer); + @Override + public Spacing getPadding() { + assertNativeInstance(); + Spacing padding = new Spacing(); + padding.set(Spacing.LEFT, jni_CSSNodeStyleGetPaddingLeft(mNativePointer)); + padding.set(Spacing.TOP, jni_CSSNodeStyleGetPaddingTop(mNativePointer)); + padding.set(Spacing.RIGHT, jni_CSSNodeStyleGetPaddingRight(mNativePointer)); + padding.set(Spacing.BOTTOM, jni_CSSNodeStyleGetPaddingBottom(mNativePointer)); + padding.set(Spacing.START, jni_CSSNodeStyleGetPaddingStart(mNativePointer)); + padding.set(Spacing.END, jni_CSSNodeStyleGetPaddingEnd(mNativePointer)); + return padding; + } + + private native void jni_CSSNodeStyleSetPaddingLeft(int nativePointer, float paddingLeft); + private native void jni_CSSNodeStyleSetPaddingTop(int nativePointer, float paddingTop); + private native void jni_CSSNodeStyleSetPaddingRight(int nativePointer, float paddingRight); + private native void jni_CSSNodeStyleSetPaddingBottom(int nativePointer, float paddingBottom); + private native void jni_CSSNodeStyleSetPaddingStart(int nativePointer, float paddingStart); + private native void jni_CSSNodeStyleSetPaddingEnd(int nativePointer, float paddingEnd); + @Override + public void setPadding(int spacingType, float padding) { + assertNativeInstance(); + switch (spacingType) { + case Spacing.LEFT: + jni_CSSNodeStyleSetPaddingLeft(mNativePointer, padding); + break; + case Spacing.TOP: + jni_CSSNodeStyleSetPaddingTop(mNativePointer, padding); + break; + case Spacing.RIGHT: + jni_CSSNodeStyleSetPaddingRight(mNativePointer, padding); + break; + case Spacing.BOTTOM: + jni_CSSNodeStyleSetPaddingBottom(mNativePointer, padding); + break; + case Spacing.START: + jni_CSSNodeStyleSetPaddingStart(mNativePointer, padding); + break; + case Spacing.END: + jni_CSSNodeStyleSetPaddingEnd(mNativePointer, padding); + break; + case Spacing.HORIZONTAL: + jni_CSSNodeStyleSetPaddingLeft(mNativePointer, padding); + jni_CSSNodeStyleSetPaddingRight(mNativePointer, padding); + jni_CSSNodeStyleSetPaddingStart(mNativePointer, padding); + jni_CSSNodeStyleSetPaddingEnd(mNativePointer, padding); + break; + case Spacing.VERTICAL: + jni_CSSNodeStyleSetPaddingTop(mNativePointer, padding); + jni_CSSNodeStyleSetPaddingBottom(mNativePointer, padding); + break; + case Spacing.ALL: + jni_CSSNodeStyleSetPaddingLeft(mNativePointer, padding); + jni_CSSNodeStyleSetPaddingRight(mNativePointer, padding); + jni_CSSNodeStyleSetPaddingStart(mNativePointer, padding); + jni_CSSNodeStyleSetPaddingEnd(mNativePointer, padding); + jni_CSSNodeStyleSetPaddingTop(mNativePointer, padding); + jni_CSSNodeStyleSetPaddingBottom(mNativePointer, padding); + break; + } + } + + @Override + public void setDefaultPadding(int spacingType, float padding) { + // TODO + } + + private native float jni_CSSNodeStyleGetBorderLeft(int nativePointer); + private native float jni_CSSNodeStyleGetBorderTop(int nativePointer); + private native float jni_CSSNodeStyleGetBorderRight(int nativePointer); + private native float jni_CSSNodeStyleGetBorderBottom(int nativePointer); + private native float jni_CSSNodeStyleGetBorderStart(int nativePointer); + private native float jni_CSSNodeStyleGetBorderEnd(int nativePointer); + @Override + public Spacing getBorder() { + assertNativeInstance(); + Spacing border = new Spacing(); + border.set(Spacing.LEFT, jni_CSSNodeStyleGetBorderLeft(mNativePointer)); + border.set(Spacing.TOP, jni_CSSNodeStyleGetBorderTop(mNativePointer)); + border.set(Spacing.RIGHT, jni_CSSNodeStyleGetBorderRight(mNativePointer)); + border.set(Spacing.BOTTOM, jni_CSSNodeStyleGetBorderBottom(mNativePointer)); + border.set(Spacing.START, jni_CSSNodeStyleGetBorderStart(mNativePointer)); + border.set(Spacing.END, jni_CSSNodeStyleGetBorderEnd(mNativePointer)); + return border; + } + + private native void jni_CSSNodeStyleSetBorderLeft(int nativePointer, float borderLeft); + private native void jni_CSSNodeStyleSetBorderTop(int nativePointer, float borderTop); + private native void jni_CSSNodeStyleSetBorderRight(int nativePointer, float borderRight); + private native void jni_CSSNodeStyleSetBorderBottom(int nativePointer, float borderBottom); + private native void jni_CSSNodeStyleSetBorderStart(int nativePointer, float borderStart); + private native void jni_CSSNodeStyleSetBorderEnd(int nativePointer, float borderEnd); + @Override + public void setBorder(int spacingType, float border) { + assertNativeInstance(); + switch (spacingType) { + case Spacing.LEFT: + jni_CSSNodeStyleSetBorderLeft(mNativePointer, border); + break; + case Spacing.TOP: + jni_CSSNodeStyleSetBorderTop(mNativePointer, border); + break; + case Spacing.RIGHT: + jni_CSSNodeStyleSetBorderRight(mNativePointer, border); + break; + case Spacing.BOTTOM: + jni_CSSNodeStyleSetBorderBottom(mNativePointer, border); + break; + case Spacing.START: + jni_CSSNodeStyleSetBorderStart(mNativePointer, border); + break; + case Spacing.END: + jni_CSSNodeStyleSetBorderEnd(mNativePointer, border); + break; + case Spacing.HORIZONTAL: + jni_CSSNodeStyleSetBorderLeft(mNativePointer, border); + jni_CSSNodeStyleSetBorderRight(mNativePointer, border); + jni_CSSNodeStyleSetBorderStart(mNativePointer, border); + jni_CSSNodeStyleSetBorderEnd(mNativePointer, border); + break; + case Spacing.VERTICAL: + jni_CSSNodeStyleSetBorderTop(mNativePointer, border); + jni_CSSNodeStyleSetBorderBottom(mNativePointer, border); + break; + case Spacing.ALL: + jni_CSSNodeStyleSetBorderLeft(mNativePointer, border); + jni_CSSNodeStyleSetBorderRight(mNativePointer, border); + jni_CSSNodeStyleSetBorderStart(mNativePointer, border); + jni_CSSNodeStyleSetBorderEnd(mNativePointer, border); + jni_CSSNodeStyleSetBorderTop(mNativePointer, border); + jni_CSSNodeStyleSetBorderBottom(mNativePointer, border); + break; + } + } + + @Override + public Spacing getPositionValue() { + Spacing position = new Spacing(); + position.set(Spacing.LEFT, getPositionLeft()); + position.set(Spacing.TOP, getPositionTop()); + position.set(Spacing.RIGHT, getPositionRight()); + position.set(Spacing.BOTTOM, getPositionBottom()); + return position; + } + + @Override + public void setPositionValue(int spacingType, float position) { + switch (spacingType) { + case Spacing.LEFT: + setPositionLeft(position); + break; + case Spacing.TOP: + setPositionTop(position); + break; + case Spacing.RIGHT: + setPositionRight(position); + break; + case Spacing.BOTTOM: + setPositionBottom(position); + break; + } + } + + private native float jni_CSSNodeStyleGetPositionTop(int nativePointer); + @Override + public float getPositionTop() { + assertNativeInstance(); + return jni_CSSNodeStyleGetPositionTop(mNativePointer); + } + + private native void jni_CSSNodeStyleSetPositionTop(int nativePointer, float positionTop); + @Override + public void setPositionTop(float positionTop) { + assertNativeInstance(); + jni_CSSNodeStyleSetPositionTop(mNativePointer, positionTop); + } + + private native float jni_CSSNodeStyleGetPositionBottom(int nativePointer); + @Override + public float getPositionBottom() { + assertNativeInstance(); + return jni_CSSNodeStyleGetPositionBottom(mNativePointer); + } + + private native void jni_CSSNodeStyleSetPositionBottom(int nativePointer, float positionBottom); + @Override + public void setPositionBottom(float positionBottom) { + assertNativeInstance(); + jni_CSSNodeStyleSetPositionBottom(mNativePointer, positionBottom); + } + + private native float jni_CSSNodeStyleGetPositionLeft(int nativePointer); + @Override + public float getPositionLeft() { + assertNativeInstance(); + return jni_CSSNodeStyleGetPositionLeft(mNativePointer); + } + + private native void jni_CSSNodeStyleSetPositionLeft(int nativePointer, float positionLeft); + @Override + public void setPositionLeft(float positionLeft) { + assertNativeInstance(); + jni_CSSNodeStyleSetPositionLeft(mNativePointer, positionLeft); + } + + private native float jni_CSSNodeStyleGetPositionRight(int nativePointer); + @Override + public float getPositionRight() { + assertNativeInstance(); + return jni_CSSNodeStyleGetPositionRight(mNativePointer); + } + + private native void jni_CSSNodeStyleSetPositionRight(int nativePointer, float positionRight); + @Override + public void setPositionRight(float positionRight) { + assertNativeInstance(); + jni_CSSNodeStyleSetPositionRight(mNativePointer, positionRight); + } + + private native float jni_CSSNodeStyleGetWidth(int nativePointer); + @Override + public float getStyleWidth() { + assertNativeInstance(); + return jni_CSSNodeStyleGetWidth(mNativePointer); + } + + private native void jni_CSSNodeStyleSetWidth(int nativePointer, float width); + @Override + public void setStyleWidth(float width) { + assertNativeInstance(); + jni_CSSNodeStyleSetWidth(mNativePointer, width); + } + + private native float jni_CSSNodeStyleGetHeight(int nativePointer); + @Override + public float getStyleHeight() { + assertNativeInstance(); + return jni_CSSNodeStyleGetHeight(mNativePointer); + } + + private native void jni_CSSNodeStyleSetHeight(int nativePointer, float height); + @Override + public void setStyleHeight(float height) { + assertNativeInstance(); + jni_CSSNodeStyleSetHeight(mNativePointer, height); + } + + private native float jni_CSSNodeStyleGetMinWidth(int nativePointer); + @Override + public float getStyleMinWidth() { + assertNativeInstance(); + return jni_CSSNodeStyleGetMinWidth(mNativePointer); + } + + private native void jni_CSSNodeStyleSetMinWidth(int nativePointer, float minWidth); + @Override + public void setStyleMinWidth(float minWidth) { + assertNativeInstance(); + jni_CSSNodeStyleSetMinWidth(mNativePointer, minWidth); + } + + private native float jni_CSSNodeStyleGetMinHeight(int nativePointer); + @Override + public float getStyleMinHeight() { + assertNativeInstance(); + return jni_CSSNodeStyleGetMinHeight(mNativePointer); + } + + private native void jni_CSSNodeStyleSetMinHeight(int nativePointer, float minHeight); + @Override + public void setStyleMinHeight(float minHeight) { + assertNativeInstance(); + jni_CSSNodeStyleSetMinHeight(mNativePointer, minHeight); + } + + private native float jni_CSSNodeStyleGetMaxWidth(int nativePointer); + @Override + public float getStyleMaxWidth() { + assertNativeInstance(); + return jni_CSSNodeStyleGetMaxWidth(mNativePointer); + } + + private native void jni_CSSNodeStyleSetMaxWidth(int nativePointer, float maxWidth); + @Override + public void setStyleMaxWidth(float maxWidth) { + assertNativeInstance(); + jni_CSSNodeStyleSetMaxWidth(mNativePointer, maxWidth); + } + + private native float jni_CSSNodeStyleGetMaxHeight(int nativePointer); + @Override + public float getStyleMaxHeight() { + assertNativeInstance(); + return jni_CSSNodeStyleGetMaxHeight(mNativePointer); + } + + private native void jni_CSSNodeStyleSetMaxHeight(int nativePointer, float maxheight); + @Override + public void setStyleMaxHeight(float maxheight) { + assertNativeInstance(); + jni_CSSNodeStyleSetMaxHeight(mNativePointer, maxheight); + } + + private native float jni_CSSNodeLayoutGetLeft(int nativePointer); + @Override + public float getLayoutX() { + assertNativeInstance(); + return jni_CSSNodeLayoutGetLeft(mNativePointer); + } + + private native float jni_CSSNodeLayoutGetTop(int nativePointer); + @Override + public float getLayoutY() { + assertNativeInstance(); + return jni_CSSNodeLayoutGetTop(mNativePointer); + } + + private native float jni_CSSNodeLayoutGetWidth(int nativePointer); + @Override + public float getLayoutWidth() { + assertNativeInstance(); + return jni_CSSNodeLayoutGetWidth(mNativePointer); + } + + private native float jni_CSSNodeLayoutGetHeight(int nativePointer); + @Override + public float getLayoutHeight() { + assertNativeInstance(); + return jni_CSSNodeLayoutGetHeight(mNativePointer); + } + + private native void jni_CSSNodeSetHasMeasureFunc(int nativePointer, boolean hasMeasureFunc); + @Override + public void setMeasureFunction(MeasureFunction measureFunction) { + assertNativeInstance(); + mMeasureFunction = measureFunction; + jni_CSSNodeSetHasMeasureFunc(mNativePointer, measureFunction != null); + } + + @DoNotStrip + public long measure(float width, int widthMode, float height, int heightMode) { + assertNativeInstance(); + if (!isMeasureDefined()) { + throw new RuntimeException("Measure function isn't defined!"); + } + + MeasureOutput output = new MeasureOutput(); + mMeasureFunction.measure( + this, + width, + CSSMeasureMode.values()[widthMode], + height, + CSSMeasureMode.values()[heightMode], + output); + return ((long) output.width) << 32 | ((long) output.height); + } + + @Override + public boolean isMeasureDefined() { + return mMeasureFunction != null; + } + + @Override + public boolean valuesEqual(float f1, float f2) { + return FloatUtil.floatsEqual(f1, f2); + } +} diff --git a/java/com/facebook/proguard/annotations/BUCK b/java/com/facebook/proguard/annotations/BUCK new file mode 100644 index 00000000..f9bfb1a5 --- /dev/null +++ b/java/com/facebook/proguard/annotations/BUCK @@ -0,0 +1,17 @@ +# Copyright (c) 2014-present, Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. + +include_defs('//CSSLAYOUT_DEFS') + +java_library( + name = 'annotations', + srcs = glob(['*.java']), + source = '1.7', + target = '1.7', + deps = [], + visibility = [CSSLAYOUT_ROOT], +) diff --git a/java/com/facebook/proguard/annotations/DoNotStrip.java b/java/com/facebook/proguard/annotations/DoNotStrip.java new file mode 100644 index 00000000..1e124a63 --- /dev/null +++ b/java/com/facebook/proguard/annotations/DoNotStrip.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +package com.facebook.proguard.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.RetentionPolicy.CLASS; + +@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR }) +@Retention(CLASS) +public @interface DoNotStrip { } diff --git a/java/jni/CSSJNI.c b/java/jni/CSSJNI.c new file mode 100644 index 00000000..a2e79124 --- /dev/null +++ b/java/jni/CSSJNI.c @@ -0,0 +1,173 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include +#include + +#define JNI_VERSION JNI_VERSION_1_6 + +#define CSS_NODE_JNI(type, func) JNIEXPORT type JNICALL Java_com_facebook_csslayout_CSSNodeJNI_jni_1##func + +#define CSS_NODE_JNI_STYLE_PROP(javatype, type, name) \ +CSS_NODE_JNI(javatype, CSSNodeStyleGet##name(JNIEnv *env, jobject instance, jint nativePointer) { \ + return (javatype) CSSNodeStyleGet##name((CSSNodeRef) nativePointer); \ +}) \ + \ +CSS_NODE_JNI(void, CSSNodeStyleSet##name(JNIEnv *env, jobject instance, jint nativePointer, javatype value) { \ + CSSNodeStyleSet##name((CSSNodeRef) nativePointer, (type) value); \ +}) + +#define CSS_NODE_JNI_LAYOUT_PROP(javatype, type, name) \ +CSS_NODE_JNI(javatype, CSSNodeLayoutGet##name(JNIEnv *env, jobject instance, jint nativePointer) { \ + return (javatype) CSSNodeLayoutGet##name((CSSNodeRef) nativePointer); \ +}) + +static JavaVM* jvm = NULL; + +jint JNI_OnLoad(JavaVM* vm, void* reserved) { + jvm = vm; + return JNI_VERSION; +} + +static void _jniPrint(void *context) { + JNIEnv *env = NULL; + CSS_ASSERT((*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION) == JNI_OK, "Must have valid jni env"); + + jclass cssNodeClass = (*env)->FindClass(env, "com/facebook/csslayout/CSSNodeJNI"); + CSS_ASSERT(cssNodeClass, "Could not find CSSNode class"); + + jmethodID toStringID = (*env)->GetMethodID(env, cssNodeClass, "toString", "()Ljava/lang/String"); + CSS_ASSERT(toStringID, "Could not find toString method"); + + jstring javaString = (jstring) (*env)->CallObjectMethod(env, context, toStringID); + const char *nativeString = (*env)->GetStringUTFChars(env, javaString, 0); + printf("%s\n", nativeString); + + (*env)->ReleaseStringUTFChars(env, javaString, nativeString); +} + +static CSSSize _jniMeasureFunc(void *context, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) { + JNIEnv *env = NULL; + CSS_ASSERT((*jvm)->GetEnv(jvm, (void**) &env, JNI_VERSION) == JNI_OK, "Must have valid jni env"); + + jclass cssNodeClass = (*env)->FindClass(env, "com/facebook/csslayout/CSSNodeJNI"); + CSS_ASSERT(cssNodeClass, "Could not find CSSNode class"); + + jmethodID measureID = (*env)->GetMethodID(env, cssNodeClass, "measure", "(FIFI)J"); + CSS_ASSERT(measureID, "Could not find measure method"); + + jlong measureResult = (*env)->CallLongMethod(env, context, measureID, width, widthMode, height, heightMode); + CSSSize size = { + .width = (int32_t) (measureResult >> 32), + .height = (int32_t) measureResult, + }; + + return size; +} + +CSS_NODE_JNI(jint, CSSNodeNew(JNIEnv *env, jobject thiz) { + CSSNodeRef node = CSSNodeNew(); + CSSNodeSetContext(node, (*env)->NewGlobalRef(env, thiz)); + CSSNodeSetPrintFunc(node, _jniPrint); + return (jint) node; +}) + +CSS_NODE_JNI(void, CSSNodeFree(JNIEnv *env, jobject thiz, jint nativePointer) { + (*env)->DeleteGlobalRef(env, (jobject) CSSNodeGetContext((CSSNodeRef) nativePointer)); + CSSNodeFree((CSSNodeRef) nativePointer); +}) + +CSS_NODE_JNI(void, CSSNodeInsertChild(JNIEnv *env, jobject thiz, jint nativePointer, jint childPointer, jint index) { + CSSNodeInsertChild((CSSNodeRef) nativePointer, (CSSNodeRef) childPointer, index); +}) + +CSS_NODE_JNI(void, CSSNodeRemoveChild(JNIEnv *env, jobject thiz, jint nativePointer, jint childPointer) { + CSSNodeRemoveChild((CSSNodeRef) nativePointer, (CSSNodeRef) childPointer); +}) + +CSS_NODE_JNI(void, CSSNodeCalculateLayout(JNIEnv *env, jobject thiz, jint nativePointer) { + CSSNodeCalculateLayout((CSSNodeRef) nativePointer, NAN, NAN, CSSNodeStyleGetDirection(((CSSNodeRef) nativePointer))); +}) + +CSS_NODE_JNI(void, CSSNodeMarkDirty(JNIEnv *env, jobject thiz, jint nativePointer) { + CSSNodeMarkDirty((CSSNodeRef) nativePointer); +}) + +CSS_NODE_JNI(jboolean, CSSNodeIsDirty(JNIEnv *env, jobject instance, jint nativePointer) { + return (jboolean) CSSNodeIsDirty((CSSNodeRef) nativePointer); +}) + +CSS_NODE_JNI(void, CSSNodeSetHasMeasureFunc(JNIEnv *env, jobject thiz, jint nativePointer, jboolean hasMeasureFunc) { + CSSNodeSetMeasureFunc((CSSNodeRef) nativePointer, hasMeasureFunc ? _jniMeasureFunc : NULL); +}) + +CSS_NODE_JNI(void, CSSNodeSetIsTextNode(JNIEnv *env, jobject instance, jint nativePointer, jboolean isTextNode) { + CSSNodeSetIsTextnode((CSSNodeRef) nativePointer, isTextNode); +}) + +CSS_NODE_JNI(jboolean, CSSNodeGetIsTextNode(JNIEnv *env, jobject instance, jint nativePointer) { + return (jboolean) CSSNodeGetIsTextnode((CSSNodeRef) nativePointer); +}) + +CSS_NODE_JNI(jboolean, CSSNodeHasNewLayout(JNIEnv *env, jobject instance, jint nativePointer) { + return (jboolean) CSSNodeGetHasNewLayout((CSSNodeRef) nativePointer); +}) + +CSS_NODE_JNI(void, CSSNodeMarkLayoutSeen(JNIEnv *env, jobject instance, jint nativePointer) { + CSSNodeSetHasNewLayout((CSSNodeRef) nativePointer, false); +}) + +CSS_NODE_JNI_STYLE_PROP(jint, CSSDirection, Direction); +CSS_NODE_JNI_STYLE_PROP(jint, CSSFlexDirection, FlexDirection); +CSS_NODE_JNI_STYLE_PROP(jint, CSSJustify, JustifyContent); +CSS_NODE_JNI_STYLE_PROP(jint, CSSAlign, AlignItems); +CSS_NODE_JNI_STYLE_PROP(jint, CSSAlign, AlignSelf); +CSS_NODE_JNI_STYLE_PROP(jint, CSSPositionType, PositionType); +CSS_NODE_JNI_STYLE_PROP(jint, CSSWrapType, FlexWrap); +CSS_NODE_JNI_STYLE_PROP(jint, CSSOverflow, Overflow); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, Flex); + +CSS_NODE_JNI_STYLE_PROP(jfloat, float, MarginLeft); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, MarginTop); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, MarginRight); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, MarginBottom); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, MarginStart); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, MarginEnd); + +CSS_NODE_JNI_STYLE_PROP(jfloat, float, PaddingLeft); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, PaddingTop); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, PaddingRight); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, PaddingBottom); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, PaddingStart); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, PaddingEnd); + +CSS_NODE_JNI_STYLE_PROP(jfloat, float, BorderLeft); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, BorderTop); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, BorderRight); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, BorderBottom); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, BorderStart); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, BorderEnd); + +CSS_NODE_JNI_STYLE_PROP(jfloat, float, PositionLeft); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, PositionTop); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, PositionRight); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, PositionBottom); + +CSS_NODE_JNI_STYLE_PROP(jfloat, float, Width); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, MinWidth); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, MaxWidth); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, Height); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, MinHeight); +CSS_NODE_JNI_STYLE_PROP(jfloat, float, MaxHeight); + +CSS_NODE_JNI_LAYOUT_PROP(jfloat, float, Width); +CSS_NODE_JNI_LAYOUT_PROP(jfloat, float, Height); +CSS_NODE_JNI_LAYOUT_PROP(jfloat, float, Left); +CSS_NODE_JNI_LAYOUT_PROP(jfloat, float, Top); +CSS_NODE_JNI_LAYOUT_PROP(jint, CSSDirection, Direction); diff --git a/lib/soloader/BUCK b/lib/soloader/BUCK new file mode 100644 index 00000000..f61f7f6b --- /dev/null +++ b/lib/soloader/BUCK @@ -0,0 +1,20 @@ +# Copyright (c) 2014-present, Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. + +include_defs('//CSSLAYOUT_DEFS') + +android_prebuilt_aar( + name = 'soloader', + aar = ':soloader-binary-aar', + visibility = [CSSLAYOUT_ROOT], +) + +remote_file( + name = 'soloader-binary-aar', + url = 'mvn:com.facebook.soloader:soloader:aar:0.1.0', + sha1 = '918573465c94c6bc9bad48ef259f1e0cd6543c1b', +) diff --git a/tests/java/com/facebook/csslayout/LayoutCachingTest.java b/tests/java/com/facebook/csslayout/LayoutCachingTest.java index 78cd8a72..66dccabc 100644 --- a/tests/java/com/facebook/csslayout/LayoutCachingTest.java +++ b/tests/java/com/facebook/csslayout/LayoutCachingTest.java @@ -222,9 +222,9 @@ public class LayoutCachingTest { root.calculateLayout(layoutContext); markLayoutAppliedForTree(root); - c1.setMeasureFunction(new CSSNode.MeasureFunction() { + c1.setMeasureFunction(new CSSNodeAPI.MeasureFunction() { @Override - public void measure(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode, MeasureOutput measureOutput) { + public void measure(CSSNodeAPI node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode, MeasureOutput measureOutput) { measureOutput.width = 100; measureOutput.height = 20; } diff --git a/tests/java/com/facebook/csslayout/LayoutEngineTest.java b/tests/java/com/facebook/csslayout/LayoutEngineTest.java index 5eccd463..a6bc9efe 100644 --- a/tests/java/com/facebook/csslayout/LayoutEngineTest.java +++ b/tests/java/com/facebook/csslayout/LayoutEngineTest.java @@ -24,11 +24,11 @@ import static com.facebook.csslayout.CSSLayout.DIMENSION_HEIGHT; */ public class LayoutEngineTest { - private static final CSSNode.MeasureFunction sTestMeasureFunction = + private static final CSSNodeAPI.MeasureFunction sTestMeasureFunction = new CSSNode.MeasureFunction() { @Override - public void measure(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode, MeasureOutput measureOutput) { + public void measure(CSSNodeAPI node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode, MeasureOutput measureOutput) { TestCSSNode testNode = (TestCSSNode) node; if (testNode.context.equals(TestConstants.SMALL_TEXT)) { if (widthMode == CSSMeasureMode.UNDEFINED) {