├── .buckconfig ├── .gitignore ├── .gitmodules ├── .hgignore ├── .travis.yml ├── BUCK ├── CONTRIBUTING ├── CSSLayout ├── CSSEnums.h ├── CSSLayout.cpp ├── CSSLayout.h ├── CSSMacros.h ├── CSSNodeList.cpp └── CSSNodeList.h ├── CSSLayoutKit ├── BUCK ├── Tests │ ├── CSSLayoutKitTests.m │ └── Info.plist ├── UIView+CSSLayout.h └── UIView+CSSLayout.m ├── LICENSE ├── PATENTS ├── README.md ├── YOGA_DEFS ├── benchmark ├── BUCK ├── CSSBenchmark.c └── CSSBenchmark.h ├── csharp ├── .gitignore ├── .hgignore ├── BUCK ├── CSSLayout │ ├── CSSInterop.cpp │ ├── CSSInterop.h │ ├── CSSLayout.vcxproj │ ├── CSSLayout.vcxproj.filters │ ├── dllmain.cpp │ ├── stdafx.cpp │ ├── stdafx.h │ └── targetver.h ├── Facebook.CSSLayout.sln ├── Facebook.CSSLayout │ ├── CSSAlign.cs │ ├── CSSConstants.cs │ ├── CSSDIrection.cs │ ├── CSSDimension.cs │ ├── CSSEdge.cs │ ├── CSSExperimentalFeature.cs │ ├── CSSFlexDirection.cs │ ├── CSSJustify.cs │ ├── CSSLogLevel.cs │ ├── CSSLogger.cs │ ├── CSSMeasureFunc.cs │ ├── CSSMeasureMode.cs │ ├── CSSNode.Create.cs │ ├── CSSNode.cs │ ├── CSSOverflow.cs │ ├── CSSPositionType.cs │ ├── CSSPrintOptions.cs │ ├── CSSSize.cs │ ├── CSSWrap.cs │ ├── Facebook.CSSLayout.xproj │ ├── MeasureFunction.cs │ ├── MeasureOutput.cs │ ├── Native.bindings.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Spacing.cs │ └── project.json └── tests │ └── Facebook.CSSLayout │ ├── CSSLayoutAbsolutePositionTest.cs │ ├── CSSLayoutAlignContentTest.cs │ ├── CSSLayoutAlignItemsTest.cs │ ├── CSSLayoutAlignSelfTest.cs │ ├── CSSLayoutBorderTest.cs │ ├── CSSLayoutFlexDirectionTest.cs │ ├── CSSLayoutFlexTest.cs │ ├── CSSLayoutFlexWrapTest.cs │ ├── CSSLayoutJustifyContentTest.cs │ ├── CSSLayoutMarginTest.cs │ ├── CSSLayoutMinMaxDimensionTest.cs │ ├── CSSLayoutPaddingTest.cs │ ├── CSSLayoutRoundingTest.cs │ ├── CSSNodeCreateTest.cs │ ├── CSSNodeTest.cs │ └── test_macos.sh ├── enums.py ├── format.sh ├── gentest ├── fixtures │ ├── CSSLayoutAbsolutePositionTest.html │ ├── CSSLayoutAlignContentTest.html │ ├── CSSLayoutAlignItemsTest.html │ ├── CSSLayoutAlignSelfTest.html │ ├── CSSLayoutBorderTest.html │ ├── CSSLayoutFlexDirectionTest.html │ ├── CSSLayoutFlexTest.html │ ├── CSSLayoutFlexWrapTest.html │ ├── CSSLayoutJustifyContentTest.html │ ├── CSSLayoutMarginTest.html │ ├── CSSLayoutMinMaxDimensionTest.html │ ├── CSSLayoutPaddingTest.html │ └── CSSLayoutRoundingTest.html ├── gentest-cpp.js ├── gentest-cs.js ├── gentest-java.js ├── gentest.js ├── gentest.rb └── test-template.html ├── java ├── BUCK ├── com │ └── facebook │ │ ├── csslayout │ │ ├── CSSAlign.java │ │ ├── CSSConstants.java │ │ ├── CSSDimension.java │ │ ├── CSSDirection.java │ │ ├── CSSEdge.java │ │ ├── CSSExperimentalFeature.java │ │ ├── CSSFlexDirection.java │ │ ├── CSSJustify.java │ │ ├── CSSLogLevel.java │ │ ├── CSSLogger.java │ │ ├── CSSMeasureMode.java │ │ ├── CSSNode.java │ │ ├── CSSNodeAPI.java │ │ ├── CSSOverflow.java │ │ ├── CSSPositionType.java │ │ ├── CSSPrintOptions.java │ │ ├── CSSWrap.java │ │ └── MeasureOutput.java │ │ └── proguard │ │ └── annotations │ │ ├── BUCK │ │ └── DoNotStrip.java ├── jni │ └── CSSJNI.cpp └── tests │ └── com │ └── facebook │ └── csslayout │ ├── CSSLayoutAbsolutePositionTest.java │ ├── CSSLayoutAlignContentTest.java │ ├── CSSLayoutAlignItemsTest.java │ ├── CSSLayoutAlignSelfTest.java │ ├── CSSLayoutBorderTest.java │ ├── CSSLayoutFlexDirectionTest.java │ ├── CSSLayoutFlexTest.java │ ├── CSSLayoutFlexWrapTest.java │ ├── CSSLayoutJustifyContentTest.java │ ├── CSSLayoutMarginTest.java │ ├── CSSLayoutMinMaxDimensionTest.java │ ├── CSSLayoutPaddingTest.java │ ├── CSSLayoutRoundingTest.java │ └── CSSNodeTest.java ├── lib ├── fb │ ├── BUCK │ ├── Doxyfile │ ├── assert.cpp │ ├── include │ │ ├── fb │ │ │ ├── ALog.h │ │ │ ├── Countable.h │ │ │ ├── Doxyfile │ │ │ ├── Environment.h │ │ │ ├── ProgramLocation.h │ │ │ ├── RefPtr.h │ │ │ ├── StaticInitialized.h │ │ │ ├── ThreadLocal.h │ │ │ ├── assert.h │ │ │ ├── fbjni.h │ │ │ ├── fbjni │ │ │ │ ├── Boxed.h │ │ │ │ ├── ByteBuffer.h │ │ │ │ ├── Common.h │ │ │ │ ├── Context.h │ │ │ │ ├── CoreClasses-inl.h │ │ │ │ ├── CoreClasses.h │ │ │ │ ├── Exceptions.h │ │ │ │ ├── File.h │ │ │ │ ├── Hybrid.h │ │ │ │ ├── Iterator-inl.h │ │ │ │ ├── Iterator.h │ │ │ │ ├── JThread.h │ │ │ │ ├── Meta-forward.h │ │ │ │ ├── Meta-inl.h │ │ │ │ ├── Meta.h │ │ │ │ ├── MetaConvert.h │ │ │ │ ├── NativeRunnable.h │ │ │ │ ├── ReferenceAllocators-inl.h │ │ │ │ ├── ReferenceAllocators.h │ │ │ │ ├── References-forward.h │ │ │ │ ├── References-inl.h │ │ │ │ ├── References.h │ │ │ │ ├── Registration-inl.h │ │ │ │ ├── Registration.h │ │ │ │ └── TypeTraits.h │ │ │ ├── log.h │ │ │ ├── lyra.h │ │ │ ├── noncopyable.h │ │ │ ├── nonmovable.h │ │ │ └── visibility.h │ │ └── jni │ │ │ ├── Countable.h │ │ │ ├── GlobalReference.h │ │ │ ├── LocalReference.h │ │ │ ├── LocalString.h │ │ │ ├── Registration.h │ │ │ ├── WeakReference.h │ │ │ └── jni_helpers.h │ ├── jni │ │ ├── ByteBuffer.cpp │ │ ├── Countable.cpp │ │ ├── Environment.cpp │ │ ├── Exceptions.cpp │ │ ├── Hybrid.cpp │ │ ├── LocalString.cpp │ │ ├── OnLoad.cpp │ │ ├── References.cpp │ │ ├── WeakReference.cpp │ │ ├── fbjni.cpp │ │ ├── java │ │ │ ├── CppException.java │ │ │ ├── CppSystemErrorException.java │ │ │ └── UnknownCppException.java │ │ └── jni_helpers.cpp │ ├── log.cpp │ ├── lyra │ │ └── lyra.cpp │ └── onload.cpp ├── gtest │ └── BUCK ├── infer-annotations │ ├── BUCK │ └── infer-annotations-1.4.jar ├── jni │ ├── BUCK │ ├── jni.h │ └── real │ │ └── jni.h ├── jsr-305 │ ├── BUCK │ └── jsr305.jar ├── junit │ ├── BUCK │ └── junit4.jar └── soloader │ ├── BUCK │ └── soloader-0.1.0.aar ├── platforms └── VS2010 │ ├── CSSLayout.sln │ ├── CSSLayout │ └── CSSLayout.vcxproj │ ├── gtest-1.8 │ ├── include │ │ └── gtest │ │ │ ├── gtest-death-test.h │ │ │ ├── gtest-message.h │ │ │ ├── gtest-param-test.h │ │ │ ├── gtest-param-test.h.pump │ │ │ ├── gtest-printers.h │ │ │ ├── gtest-spi.h │ │ │ ├── gtest-test-part.h │ │ │ ├── gtest-typed-test.h │ │ │ ├── gtest.h │ │ │ ├── gtest_pred_impl.h │ │ │ ├── gtest_prod.h │ │ │ └── internal │ │ │ ├── custom │ │ │ ├── gtest-port.h │ │ │ ├── gtest-printers.h │ │ │ └── gtest.h │ │ │ ├── gtest-death-test-internal.h │ │ │ ├── gtest-filepath.h │ │ │ ├── gtest-internal.h │ │ │ ├── gtest-linked_ptr.h │ │ │ ├── gtest-param-util-generated.h │ │ │ ├── gtest-param-util-generated.h.pump │ │ │ ├── gtest-param-util.h │ │ │ ├── gtest-port-arch.h │ │ │ ├── gtest-port.h │ │ │ ├── gtest-string.h │ │ │ ├── gtest-tuple.h │ │ │ ├── gtest-tuple.h.pump │ │ │ ├── gtest-type-util.h │ │ │ └── gtest-type-util.h.pump │ └── lib │ │ ├── gtest.lib │ │ └── gtestd.lib │ └── tests │ ├── main.cpp │ └── tests.vcxproj └── tests ├── CSSLayoutAbsolutePositionTest.cpp ├── CSSLayoutAlignContentTest.cpp ├── CSSLayoutAlignItemsTest.cpp ├── CSSLayoutAlignSelfTest.cpp ├── CSSLayoutAspectRatioTest.cpp ├── CSSLayoutBorderTest.cpp ├── CSSLayoutDefaultValuesTest.cpp ├── CSSLayoutDirtyMarkingTest.cpp ├── CSSLayoutEdgeTest.cpp ├── CSSLayoutFlexDirectionTest.cpp ├── CSSLayoutFlexTest.cpp ├── CSSLayoutFlexWrapTest.cpp ├── CSSLayoutJustifyContentTest.cpp ├── CSSLayoutMarginTest.cpp ├── CSSLayoutMeasureCacheTest.cpp ├── CSSLayoutMeasureModeTest.cpp ├── CSSLayoutMeasureTest.cpp ├── CSSLayoutMemoryFuncTest.cpp ├── CSSLayoutMinMaxDimensionTest.cpp ├── CSSLayoutPaddingTest.cpp ├── CSSLayoutRelayoutTest.cpp ├── CSSLayoutRoundingMeasureFuncTest.cpp ├── CSSLayoutRoundingTest.cpp └── CSSLayoutStyleTest.cpp /.buckconfig: -------------------------------------------------------------------------------- 1 | [cxx] 2 | gtest_dep = //lib/gtest:gtest 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | 3 | /buck-cache/ 4 | /buck-out/ 5 | /.buckconfig.local 6 | /.buckd 7 | /gentest/test.html 8 | 9 | # Visual studio code 10 | .vscode 11 | 12 | # Unity stuff 13 | /platforms/VS2010/bin/ 14 | *.opensdf 15 | *.sdf 16 | *.suo 17 | *.vcxproj.filters 18 | *.vcxproj.user 19 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/gtest/googletest"] 2 | path = lib/gtest/googletest 3 | url = https://github.com/google/googletest.git 4 | -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | 3 | /buck-cache/ 4 | /buck-out/ 5 | /.buckconfig.local 6 | /.buckd 7 | /gentest/test.html 8 | 9 | # Visual studio code 10 | .vscode 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | os: osx 9 | osx_image: xcode7.3 10 | language: cpp 11 | compiler: clang 12 | 13 | before_install: 14 | - brew update 15 | - brew tap facebook/fb 16 | - brew install buck 17 | - brew cask install java 18 | - brew outdated xctool || brew upgrade xctool 19 | - brew install mono 20 | - export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) 21 | - export PATH=$JAVA_HOME/bin:$PATH 22 | 23 | script: 24 | - buck test //:CSSLayout 25 | - buck test //java:java 26 | - buck test //CSSLayoutKit:CSSLayoutKit --config cxx.default_platform=iphonesimulator-x86_64 --config cxx.cflags=-DTRAVIS_CI 27 | - sh csharp/tests/Facebook.CSSLayout/test_macos.sh 28 | - buck run //benchmark:benchmark 29 | - git checkout HEAD^ 30 | - buck run //benchmark:benchmark 31 | -------------------------------------------------------------------------------- /BUCK: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | include_defs('//YOGA_DEFS') 9 | 10 | BASE_COMPILER_FLAGS = [ 11 | '-fno-omit-frame-pointer', 12 | '-fexceptions', 13 | '-Wall', 14 | '-Werror', 15 | '-O3', 16 | ] 17 | 18 | GMOCK_OVERRIDE_FLAGS = [ 19 | # gmock does not mark mocked methods as override, ignore the warnings in tests 20 | '-Wno-inconsistent-missing-override', 21 | ] 22 | 23 | COMPILER_FLAGS = BASE_COMPILER_FLAGS + ['-std=c11', '-fPIC'] 24 | TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + ['-std=c++11'] 25 | 26 | cxx_library( 27 | name = 'CSSLayout', 28 | srcs = glob(['CSSLayout/*.c']), 29 | tests=[':tests'], 30 | exported_headers = subdir_glob([('', 'CSSLayout/*.h')]), 31 | header_namespace = '', 32 | compiler_flags = COMPILER_FLAGS, 33 | deps = [] if THIS_IS_FBOBJC else [ 34 | csslayout_dep('lib/fb:ndklog'), 35 | ], 36 | visibility = ['PUBLIC'], 37 | ) 38 | 39 | cxx_test( 40 | name = 'tests', 41 | contacts = ['emilsj@fb.com'], 42 | srcs = glob(['tests/*.cpp']), 43 | compiler_flags = TEST_COMPILER_FLAGS, 44 | deps = [ 45 | ':CSSLayout', 46 | GTEST_TARGET, 47 | ], 48 | visibility = ['PUBLIC'], 49 | ) 50 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | # Contributing to css-layout 2 | We want to make contributing to this project as easy and transparent as 3 | possible. 4 | 5 | ## Our Development Process 6 | All the development is happening on GitHub first and we have internal tools to sync down to Facebook codebase. 7 | 8 | ## Pull Requests 9 | We actively welcome your pull requests. 10 | 1. Fork the repo and create your branch from `master`. 11 | 2. If you've added code that should be tested, add tests 12 | 3. If you've changed APIs, update the documentation. 13 | 4. Ensure the test suite passes. 14 | 5. Make sure your code lints. 15 | 6. If you haven't already, complete the Contributor License Agreement ("CLA"). 16 | 17 | ## Contributor License Agreement ("CLA") 18 | In order to accept your pull request, we need you to submit a CLA. You only need 19 | to do this once to work on any of Facebook's open source projects. 20 | 21 | Complete your CLA here: 22 | 23 | ## Issues 24 | We use GitHub issues to track public bugs. Please ensure your description is 25 | clear and has sufficient instructions to be able to reproduce the issue. 26 | 27 | Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe 28 | disclosure of security bugs. In those cases, please go through the process 29 | outlined on that page and do not file a public issue. 30 | 31 | ## Coding Style 32 | * format.sh 33 | 34 | ## License 35 | By contributing to css-layout, you agree that your contributions will be licensed 36 | under its BSD license. 37 | -------------------------------------------------------------------------------- /CSSLayout/CSSEnums.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | typedef enum CSSOverflow { 11 | CSSOverflowVisible, 12 | CSSOverflowHidden, 13 | CSSOverflowScroll, 14 | CSSOverflowCount, 15 | } CSSOverflow; 16 | 17 | typedef enum CSSJustify { 18 | CSSJustifyFlexStart, 19 | CSSJustifyCenter, 20 | CSSJustifyFlexEnd, 21 | CSSJustifySpaceBetween, 22 | CSSJustifySpaceAround, 23 | CSSJustifyCount, 24 | } CSSJustify; 25 | 26 | typedef enum CSSFlexDirection { 27 | CSSFlexDirectionColumn, 28 | CSSFlexDirectionColumnReverse, 29 | CSSFlexDirectionRow, 30 | CSSFlexDirectionRowReverse, 31 | CSSFlexDirectionCount, 32 | } CSSFlexDirection; 33 | 34 | typedef enum CSSAlign { 35 | CSSAlignAuto, 36 | CSSAlignFlexStart, 37 | CSSAlignCenter, 38 | CSSAlignFlexEnd, 39 | CSSAlignStretch, 40 | CSSAlignCount, 41 | } CSSAlign; 42 | 43 | typedef enum CSSEdge { 44 | CSSEdgeLeft, 45 | CSSEdgeTop, 46 | CSSEdgeRight, 47 | CSSEdgeBottom, 48 | CSSEdgeStart, 49 | CSSEdgeEnd, 50 | CSSEdgeHorizontal, 51 | CSSEdgeVertical, 52 | CSSEdgeAll, 53 | CSSEdgeCount, 54 | } CSSEdge; 55 | 56 | typedef enum CSSWrap { 57 | CSSWrapNoWrap, 58 | CSSWrapWrap, 59 | CSSWrapCount, 60 | } CSSWrap; 61 | 62 | typedef enum CSSDirection { 63 | CSSDirectionInherit, 64 | CSSDirectionLTR, 65 | CSSDirectionRTL, 66 | CSSDirectionCount, 67 | } CSSDirection; 68 | 69 | typedef enum CSSExperimentalFeature { 70 | CSSExperimentalFeatureRounding, 71 | CSSExperimentalFeatureWebFlexBasis, 72 | CSSExperimentalFeatureCount, 73 | } CSSExperimentalFeature; 74 | 75 | typedef enum CSSLogLevel { 76 | CSSLogLevelError, 77 | CSSLogLevelWarn, 78 | CSSLogLevelInfo, 79 | CSSLogLevelDebug, 80 | CSSLogLevelVerbose, 81 | CSSLogLevelCount, 82 | } CSSLogLevel; 83 | 84 | typedef enum CSSDimension { 85 | CSSDimensionWidth, 86 | CSSDimensionHeight, 87 | CSSDimensionCount, 88 | } CSSDimension; 89 | 90 | typedef enum CSSMeasureMode { 91 | CSSMeasureModeUndefined, 92 | CSSMeasureModeExactly, 93 | CSSMeasureModeAtMost, 94 | CSSMeasureModeCount, 95 | } CSSMeasureMode; 96 | 97 | typedef enum CSSPositionType { 98 | CSSPositionTypeRelative, 99 | CSSPositionTypeAbsolute, 100 | CSSPositionTypeCount, 101 | } CSSPositionType; 102 | 103 | typedef enum CSSPrintOptions { 104 | CSSPrintOptionsLayout = 1, 105 | CSSPrintOptionsStyle = 2, 106 | CSSPrintOptionsChildren = 4, 107 | CSSPrintOptionsCount, 108 | } CSSPrintOptions; 109 | -------------------------------------------------------------------------------- /CSSLayout/CSSMacros.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #ifdef __cplusplus 13 | #define CSS_EXTERN_C_BEGIN extern "C" { 14 | #define CSS_EXTERN_C_END } 15 | #else 16 | #define CSS_EXTERN_C_BEGIN 17 | #define CSS_EXTERN_C_END 18 | #endif 19 | 20 | // BEGIN_UNITY @joce 11-01-2016 DontExportSymbols 21 | //#ifdef _WINDLL 22 | #if defined(_WINDLL) && !defined(UNITY_EDITOR) 23 | // END_UNITY 24 | #define WIN_EXPORT __declspec(dllexport) 25 | #else 26 | #define WIN_EXPORT 27 | #endif 28 | 29 | #ifndef FB_ASSERTIONS_ENABLED 30 | #define FB_ASSERTIONS_ENABLED 1 31 | #endif 32 | 33 | #if FB_ASSERTIONS_ENABLED 34 | #define CSS_ABORT() abort() 35 | #else 36 | #define CSS_ABORT() 37 | #endif 38 | 39 | #ifndef CSS_ASSERT 40 | #define CSS_ASSERT(X, message) \ 41 | if (!(X)) { \ 42 | CSSLog(CSSLogLevelError, "%s", message); \ 43 | CSS_ABORT(); \ 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /CSSLayout/CSSNodeList.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "CSSLayout.h" 18 | #include "CSSMacros.h" 19 | 20 | CSS_EXTERN_C_BEGIN 21 | 22 | typedef struct CSSNodeList *CSSNodeListRef; 23 | 24 | CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity); 25 | void CSSNodeListFree(const CSSNodeListRef list); 26 | uint32_t CSSNodeListCount(const CSSNodeListRef list); 27 | void CSSNodeListAdd(CSSNodeListRef *listp, const CSSNodeRef node); 28 | void CSSNodeListInsert(CSSNodeListRef *listp, const CSSNodeRef node, const uint32_t index); 29 | CSSNodeRef CSSNodeListRemove(const CSSNodeListRef list, const uint32_t index); 30 | CSSNodeRef CSSNodeListDelete(const CSSNodeListRef list, const CSSNodeRef node); 31 | CSSNodeRef CSSNodeListGet(const CSSNodeListRef list, const uint32_t index); 32 | 33 | CSS_EXTERN_C_END 34 | -------------------------------------------------------------------------------- /CSSLayoutKit/BUCK: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | include_defs('//YOGA_DEFS') 9 | 10 | UIKIT_CSSLAYOUT_COMPILER_FLAGS = [ 11 | '-fobjc-arc', 12 | '-Wconditional-uninitialized', 13 | '-Wdangling-else', 14 | '-Wdeprecated-declarations', 15 | '-Wimplicit-retain-self', 16 | '-Wincomplete-implementation', 17 | '-Wobjc-method-access', 18 | '-Wobjc-missing-super-calls', 19 | '-Wmismatched-return-types', 20 | '-Wreturn-type', 21 | '-Wno-global-constructors', 22 | '-Wno-shadow', 23 | '-Wunused-const-variable', 24 | '-Wunused-function', 25 | '-Wunused-property-ivar', 26 | '-Wunused-result', 27 | '-Wunused-value', 28 | ] 29 | 30 | apple_library( 31 | name = 'CSSLayoutKit', 32 | compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS, 33 | tests = [':CSSLayoutKitTests'], 34 | srcs = glob(['*.m']), 35 | exported_headers = glob(['*.h']), 36 | frameworks = [ 37 | '$SDKROOT/System/Library/Frameworks/Foundation.framework', 38 | '$SDKROOT/System/Library/Frameworks/UIKit.framework', 39 | ], 40 | deps = [ 41 | csslayout_dep(':CSSLayout'), 42 | ], 43 | visibility = ['PUBLIC'], 44 | ) 45 | 46 | apple_test( 47 | name = 'CSSLayoutKitTests', 48 | compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS, 49 | info_plist = 'Tests/Info.plist', 50 | srcs = glob(['Tests/**/*.m']), 51 | frameworks = [ 52 | '$SDKROOT/System/Library/Frameworks/CoreGraphics.framework', 53 | '$PLATFORM_DIR/Developer/Library/Frameworks/XCTest.framework', 54 | ], 55 | deps = [ 56 | ':CSSLayoutKit', 57 | ], 58 | visibility = ['PUBLIC'], 59 | ) 60 | -------------------------------------------------------------------------------- /CSSLayoutKit/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.facebook.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /CSSLayoutKit/UIView+CSSLayout.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | #import 12 | 13 | @interface UIView (CSSLayout) 14 | 15 | /** 16 | The property that decides if we should include this view when calculating layout. Defaults to YES. 17 | */ 18 | @property (nonatomic, readwrite, assign, setter=css_setIncludeInLayout:) BOOL css_includeInLayout; 19 | 20 | /** 21 | The property that decides during layout/sizing whether or not css_* properties should be applied. Defaults to NO. 22 | */ 23 | @property (nonatomic, readwrite, assign, setter=css_setUsesFlexbox:) BOOL css_usesFlexbox; 24 | 25 | - (void)css_setDirection:(CSSDirection)direction; 26 | - (void)css_setFlexDirection:(CSSFlexDirection)flexDirection; 27 | - (void)css_setJustifyContent:(CSSJustify)justifyContent; 28 | - (void)css_setAlignContent:(CSSAlign)alignContent; 29 | - (void)css_setAlignItems:(CSSAlign)alignItems; 30 | - (void)css_setAlignSelf:(CSSAlign)alignSelf; 31 | - (void)css_setPositionType:(CSSPositionType)positionType; 32 | - (void)css_setFlexWrap:(CSSWrap)flexWrap; 33 | 34 | - (void)css_setFlexGrow:(CGFloat)flexGrow; 35 | - (void)css_setFlexShrink:(CGFloat)flexShrink; 36 | - (void)css_setFlexBasis:(CGFloat)flexBasis; 37 | 38 | - (void)css_setPosition:(CGFloat)position forEdge:(CSSEdge)edge; 39 | - (void)css_setMargin:(CGFloat)margin forEdge:(CSSEdge)edge; 40 | - (void)css_setPadding:(CGFloat)padding forEdge:(CSSEdge)edge; 41 | 42 | - (void)css_setWidth:(CGFloat)width; 43 | - (void)css_setHeight:(CGFloat)height; 44 | - (void)css_setMinWidth:(CGFloat)minWidth; 45 | - (void)css_setMinHeight:(CGFloat)minHeight; 46 | - (void)css_setMaxWidth:(CGFloat)maxWidth; 47 | - (void)css_setMaxHeight:(CGFloat)maxHeight; 48 | 49 | // Yoga specific properties, not compatible with flexbox specification 50 | - (void)css_setAspectRatio:(CGFloat)aspectRatio; 51 | 52 | /** 53 | Get the resolved direction of this node. This won't be CSSDirectionInherit 54 | */ 55 | - (CSSDirection)css_resolvedDirection; 56 | 57 | /** 58 | Perform a layout calculation and update the frames of the views in the hierarchy with th results 59 | */ 60 | - (void)css_applyLayout; 61 | 62 | /** 63 | Returns the size of the view if no constraints were given. This could equivalent to calling [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; 64 | */ 65 | - (CGSize)css_intrinsicSize; 66 | 67 | /** 68 | Returns the number of children that are using Flexbox. 69 | */ 70 | - (NSUInteger)css_numberOfChildren; 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD License 2 | 3 | For css-layout software 4 | 5 | Copyright (c) 2014-present, Facebook, Inc. All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | * Neither the name Facebook nor the names of its contributors may be used to 18 | endorse or promote products derived from this software without specific 19 | prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 25 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /PATENTS: -------------------------------------------------------------------------------- 1 | Additional Grant of Patent Rights Version 2 2 | 3 | "Software" means the CSS Layout software distributed by Facebook, Inc. 4 | 5 | Facebook, Inc. (“Facebook”) hereby grants to each recipient of the Software 6 | (“you”) a perpetual, worldwide, royalty-free, non-exclusive, irrevocable 7 | (subject to the termination provision below) license under any Necessary 8 | Claims, to make, have made, use, sell, offer to sell, import, and otherwise 9 | transfer the Software. For avoidance of doubt, no license is granted under 10 | Facebook's rights in any patent claims that are infringed by (i) modifications 11 | to the Software made by you or any third party or (ii) the Software in 12 | combination with any software or other technology. 13 | 14 | The license granted hereunder will terminate, automatically and without notice, 15 | if you (or any of your subsidiaries, corporate affiliates or agents) initiate 16 | directly or indirectly, or take a direct financial interest in, any Patent 17 | Assertion: (i) against Facebook or any of its subsidiaries or corporate 18 | affiliates, (ii) against any party if such Patent Assertion arises in whole or 19 | in part from any software, technology, product or service of Facebook or any of 20 | its subsidiaries or corporate affiliates, or (iii) against any party relating 21 | to the Software. Notwithstanding the foregoing, if Facebook or any of its 22 | subsidiaries or corporate affiliates files a lawsuit alleging patent 23 | infringement against you in the first instance, and you respond by filing a 24 | patent infringement counterclaim in that lawsuit against that party that is 25 | unrelated to the Software, the license granted hereunder will not terminate 26 | under section (i) of this paragraph due to such counterclaim. 27 | 28 | A "Necessary Claim" is a claim of a patent owned by Facebook that is 29 | necessarily infringed by the Software standing alone. 30 | 31 | A "Patent Assertion" is any lawsuit or other action alleging direct, indirect, 32 | or contributory infringement or inducement to infringe any patent, including a 33 | cross-claim or counterclaim. 34 | -------------------------------------------------------------------------------- /YOGA_DEFS: -------------------------------------------------------------------------------- 1 | 2 | CSSLAYOUT_ROOT = '//...' 3 | INFER_ANNOTATIONS_TARGET = '//lib/infer-annotations:infer-annotations' 4 | JSR_305_TARGET = '//lib/jsr-305:jsr-305' 5 | JUNIT_TARGET = '//lib/junit:junit' 6 | PROGRUARD_ANNOTATIONS_TARGET = '//java/com/facebook/proguard/annotations:annotations' 7 | SOLOADER_TARGET = '//lib/soloader:soloader' 8 | GTEST_TARGET = '//lib/gtest:gtest' 9 | JNI_TARGET = '//lib/jni:jni' 10 | FBJNI_TARGET = '//lib/fb:fbjni' 11 | 12 | THIS_IS_FBOBJC = False 13 | 14 | CXX_LIBRARY_WHITELIST = [ 15 | '//:CSSLayout', 16 | '//lib/fb:fbjni', 17 | '//java:jni', 18 | ] 19 | 20 | def csslayout_dep(dep): 21 | return '//' + dep 22 | 23 | class allow_unsafe_import: 24 | def __enter__(self): 25 | pass 26 | def __exit__(self, type, value, traceback): 27 | pass 28 | -------------------------------------------------------------------------------- /benchmark/BUCK: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | include_defs('//YOGA_DEFS') 9 | 10 | cxx_binary( 11 | name = 'benchmark', 12 | srcs = glob(['*.c']), 13 | headers = subdir_glob([('', '*.h')]), 14 | header_namespace = '', 15 | compiler_flags = [ 16 | '-fno-omit-frame-pointer', 17 | '-fexceptions', 18 | '-Wall', 19 | '-Werror', 20 | '-O3', 21 | '-std=c11', 22 | ], 23 | deps = [ 24 | csslayout_dep(':CSSLayout'), 25 | ], 26 | visibility = ['PUBLIC'], 27 | ) 28 | -------------------------------------------------------------------------------- /benchmark/CSSBenchmark.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #define NUM_REPETITIONS 1000 19 | 20 | #define CSS_BENCHMARKS(BLOCK) \ 21 | int main(int argc, char const *argv[]) { \ 22 | clock_t __start; \ 23 | clock_t __endTimes[NUM_REPETITIONS]; \ 24 | { BLOCK } \ 25 | return 0; \ 26 | } 27 | 28 | #define CSS_BENCHMARK(NAME, BLOCK) \ 29 | __start = clock(); \ 30 | for (uint32_t __i = 0; __i < NUM_REPETITIONS; __i++) { \ 31 | { BLOCK } \ 32 | __endTimes[__i] = clock(); \ 33 | } \ 34 | __printBenchmarkResult(NAME, __start, __endTimes); 35 | 36 | int __compareDoubles(const void *a, const void *b) { 37 | double arg1 = *(const double *) a; 38 | double arg2 = *(const double *) b; 39 | 40 | if (arg1 < arg2) { 41 | return -1; 42 | } 43 | 44 | if (arg1 > arg2) { 45 | return 1; 46 | } 47 | 48 | return 0; 49 | } 50 | 51 | void __printBenchmarkResult(char *name, clock_t start, clock_t *endTimes) { 52 | double timesInMs[NUM_REPETITIONS]; 53 | double mean = 0; 54 | clock_t lastEnd = start; 55 | for (uint32_t i = 0; i < NUM_REPETITIONS; i++) { 56 | timesInMs[i] = (endTimes[i] - lastEnd) / (double) CLOCKS_PER_SEC * 1000; 57 | lastEnd = endTimes[i]; 58 | mean += timesInMs[i]; 59 | } 60 | mean /= NUM_REPETITIONS; 61 | 62 | qsort(timesInMs, NUM_REPETITIONS, sizeof(double), __compareDoubles); 63 | double median = timesInMs[NUM_REPETITIONS / 2]; 64 | 65 | double variance = 0; 66 | for (uint32_t i = 0; i < NUM_REPETITIONS; i++) { 67 | variance += pow(timesInMs[i] - mean, 2); 68 | } 69 | variance /= NUM_REPETITIONS; 70 | double stddev = sqrt(variance); 71 | 72 | printf("%s: median: %lf ms, stddev: %lf ms\n", name, median, stddev); 73 | } 74 | -------------------------------------------------------------------------------- /csharp/BUCK: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | csharp_library( 9 | name = 'csslibnet46', 10 | dll_name = 'Facebook.CSSLayout.dll', 11 | framework_ver = 'net46', 12 | srcs = glob(['**/*.cs']), 13 | ) 14 | 15 | csharp_library( 16 | name = 'csslibnet45', 17 | dll_name = 'Facebook.CSSLayout.dll', 18 | framework_ver = 'net45', 19 | srcs = glob(['**/*.cs']), 20 | ) 21 | -------------------------------------------------------------------------------- /csharp/CSSLayout/CSSInterop.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include "CSSInterop.h" 11 | 12 | static CSSInteropLoggerFunc gManagedFunc; 13 | 14 | static int unmanagedLogger(CSSLogLevel level, const char *format, va_list args) { 15 | int result = 0; 16 | if (gManagedFunc) { 17 | char buffer[256]; 18 | result = vsnprintf(buffer, sizeof(buffer), format, args); 19 | (*gManagedFunc)(level, buffer); 20 | } 21 | return result; 22 | } 23 | 24 | void CSSInteropSetLogger(CSSInteropLoggerFunc managedFunc) { 25 | gManagedFunc = managedFunc; 26 | CSSLayoutSetLogger(&unmanagedLogger); 27 | } 28 | -------------------------------------------------------------------------------- /csharp/CSSLayout/CSSInterop.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | CSS_EXTERN_C_BEGIN 15 | 16 | typedef void (*CSSInteropLoggerFunc)(CSSLogLevel level, const char *message); 17 | 18 | WIN_EXPORT void CSSInteropSetLogger(CSSInteropLoggerFunc managedFunc); 19 | 20 | CSS_EXTERN_C_END 21 | -------------------------------------------------------------------------------- /csharp/CSSLayout/CSSLayout.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | -------------------------------------------------------------------------------- /csharp/CSSLayout/dllmain.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // dllmain.cpp : Defines the entry point for the DLL application. 11 | #include "stdafx.h" 12 | 13 | BOOL APIENTRY DllMain( HMODULE hModule, 14 | DWORD ul_reason_for_call, 15 | LPVOID lpReserved 16 | ) 17 | { 18 | switch (ul_reason_for_call) 19 | { 20 | case DLL_PROCESS_ATTACH: 21 | case DLL_THREAD_ATTACH: 22 | case DLL_THREAD_DETACH: 23 | case DLL_PROCESS_DETACH: 24 | break; 25 | } 26 | return TRUE; 27 | } 28 | -------------------------------------------------------------------------------- /csharp/CSSLayout/stdafx.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // stdafx.cpp : source file that includes just the standard includes 11 | // CSSLayout.pch will be the pre-compiled header 12 | // stdafx.obj will contain the pre-compiled type information 13 | 14 | #include "stdafx.h" 15 | 16 | // TODO: reference any additional headers you need in STDAFX.H 17 | // and not in this file 18 | -------------------------------------------------------------------------------- /csharp/CSSLayout/stdafx.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // stdafx.h : include file for standard system include files, 11 | // or project specific include files that are used frequently, but 12 | // are changed infrequently 13 | // 14 | 15 | #pragma once 16 | 17 | #include "targetver.h" 18 | 19 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 20 | // Windows Header Files: 21 | #include 22 | 23 | 24 | 25 | // TODO: reference additional headers your program requires here 26 | -------------------------------------------------------------------------------- /csharp/CSSLayout/targetver.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | // Including SDKDDKVer.h defines the highest available Windows platform. 13 | 14 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 15 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 16 | 17 | #include 18 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CSSLayout", "CSSLayout\CSSLayout.vcxproj", "{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}" 7 | EndProject 8 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Facebook.CSSLayout", "Facebook.CSSLayout\Facebook.CSSLayout.xproj", "{75BB7605-E54B-4EDE-8F5A-FF1F24464236}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|Any CPU.ActiveCfg = Debug|Win32 21 | {0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|x64.ActiveCfg = Debug|x64 22 | {0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|x64.Build.0 = Debug|x64 23 | {0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|x86.ActiveCfg = Debug|Win32 24 | {0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|x86.Build.0 = Debug|Win32 25 | {0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|Any CPU.ActiveCfg = Release|Win32 26 | {0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|x64.ActiveCfg = Release|x64 27 | {0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|x64.Build.0 = Release|x64 28 | {0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|x86.ActiveCfg = Release|Win32 29 | {0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|x86.Build.0 = Release|Win32 30 | {75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|x64.ActiveCfg = Debug|Any CPU 33 | {75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|x64.Build.0 = Debug|Any CPU 34 | {75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|x86.ActiveCfg = Debug|Any CPU 35 | {75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|x86.Build.0 = Debug|Any CPU 36 | {75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|x64.ActiveCfg = Release|Any CPU 39 | {75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|x64.Build.0 = Release|Any CPU 40 | {75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|x86.ActiveCfg = Release|Any CPU 41 | {75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|x86.Build.0 = Release|Any CPU 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | EndGlobal 47 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSAlign.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal enum CSSAlign 16 | { 17 | Auto, 18 | FlexStart, 19 | Center, 20 | FlexEnd, 21 | Stretch, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSConstants.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal static class CSSConstants 16 | { 17 | public const float Undefined = float.NaN; 18 | 19 | public static bool IsUndefined(float value) 20 | { 21 | return float.IsNaN(value); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSDIrection.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal enum CSSDirection 16 | { 17 | Inherit, 18 | LTR, 19 | RTL, 20 | [System.Obsolete("Use LTR instead")] 21 | LeftToRight = LTR, 22 | [System.Obsolete("Use RTL instead")] 23 | RightToLeft = RTL, 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSDimension.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal enum CSSDimension 16 | { 17 | Width, 18 | Height, 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSEdge.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal enum CSSEdge 16 | { 17 | Left, 18 | Top, 19 | Right, 20 | Bottom, 21 | Start, 22 | End, 23 | Horizontal, 24 | Vertical, 25 | All, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSExperimentalFeature.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-21-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal enum CSSExperimentalFeature 16 | { 17 | Rounding, 18 | WebFlexBasis, 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSFlexDirection.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal enum CSSFlexDirection 16 | { 17 | Column, 18 | ColumnReverse, 19 | Row, 20 | RowReverse, 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSJustify.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal enum CSSJustify 16 | { 17 | FlexStart, 18 | Center, 19 | FlexEnd, 20 | SpaceBetween, 21 | SpaceAround, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSLogLevel.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal enum CSSLogLevel 16 | { 17 | Error, 18 | Warn, 19 | Info, 20 | Debug, 21 | Verbose, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSLogger.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | using System; 11 | using System.Runtime.InteropServices; 12 | 13 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 14 | //namespace Facebook.CSSLayout 15 | namespace UnityEngine.CSSLayout 16 | // END_UNITY 17 | { 18 | internal static class CSSLogger 19 | { 20 | // TODO we don't support the logging feature yet 21 | 22 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 23 | public delegate void Func(CSSLogLevel level, string message); 24 | // 25 | // private static bool _initialized; 26 | // private static Func _managedLogger = null; 27 | // 28 | public static Func Logger = null; 29 | 30 | public static void Initialize() 31 | { 32 | // if (!_initialized) 33 | // { 34 | // _managedLogger = (level, message) => { 35 | // if (Logger != null) 36 | // { 37 | // Logger(level, message); 38 | // } 39 | // 40 | // if (level == CSSLogLevel.Error) 41 | // { 42 | // throw new InvalidOperationException(message); 43 | // } 44 | // }; 45 | // Native.CSSInteropSetLogger(_managedLogger); 46 | // _initialized = true; 47 | // } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSMeasureFunc.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | using System; 11 | using System.Runtime.InteropServices; 12 | 13 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 14 | //namespace Facebook.CSSLayout 15 | namespace UnityEngine.CSSLayout 16 | // END_UNITY 17 | { 18 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 19 | internal delegate CSSSize CSSMeasureFunc( 20 | IntPtr node, 21 | float width, 22 | CSSMeasureMode widthMode, 23 | float height, 24 | CSSMeasureMode heightMode); 25 | } 26 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSMeasureMode.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal enum CSSMeasureMode 16 | { 17 | Undefined, 18 | Exactly, 19 | AtMost, 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSOverflow.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal enum CSSOverflow 16 | { 17 | Visible, 18 | Hidden, 19 | Scroll, 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSPositionType.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal enum CSSPositionType 16 | { 17 | Relative, 18 | Absolute, 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSPrintOptions.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal enum CSSPrintOptions 16 | { 17 | Layout = 1, 18 | Style = 2, 19 | Children = 4, 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSSize.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | using System.Runtime.InteropServices; 11 | 12 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 13 | //namespace Facebook.CSSLayout 14 | namespace UnityEngine.CSSLayout 15 | // END_UNITY 16 | { 17 | [StructLayout(LayoutKind.Sequential)] 18 | internal struct CSSSize 19 | { 20 | public float width; 21 | public float height; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/CSSWrap.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal enum CSSWrap 16 | { 17 | NoWrap, 18 | Wrap, 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/Facebook.CSSLayout.xproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 10 | 75bb7605-e54b-4ede-8f5a-ff1f24464236 11 | Facebook.CSSLayout 12 | .\obj 13 | .\bin\ 14 | v4.5.2 15 | 16 | 17 | 18 | 2.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/MeasureFunction.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | // BEGIN_UNITY @joce 11-21-2016 CompileForC#Bindings 16 | //internal delegate long MeasureFunction( 17 | internal delegate long MeasureFunction( 18 | // END_UNITY 19 | CSSNode node, 20 | float width, 21 | CSSMeasureMode widthMode, 22 | float height, 23 | CSSMeasureMode heightMode); 24 | } 25 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/MeasureOutput.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-07-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal class MeasureOutput 16 | { 17 | public static long Make(double width, double height) 18 | { 19 | return Make((int) width, (int) height); 20 | } 21 | 22 | public static long Make(int width, int height) 23 | { 24 | return (long)(((ulong) width) << 32 | ((uint) height)); 25 | } 26 | 27 | public static int GetWidth(long measureOutput) 28 | { 29 | return (int) (0xFFFFFFFF & (measureOutput >> 32)); 30 | } 31 | 32 | public static int GetHeight(long measureOutput) 33 | { 34 | return (int) (0xFFFFFFFF & measureOutput); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | using System.Reflection; 11 | using System.Resources; 12 | using System.Runtime.InteropServices; 13 | 14 | // General Information about an assembly is controlled through the following 15 | // set of attributes. Change these attribute values to modify the information 16 | // associated with an assembly. 17 | [assembly: AssemblyConfiguration("")] 18 | [assembly: AssemblyCompany("Facebook, Inc.")] 19 | [assembly: AssemblyProduct("Facebook.CSSLayout")] 20 | [assembly: AssemblyTrademark("Copyright (c) 2014-present, Facebook, Inc.")] 21 | 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | [assembly: ComVisible(false)] 26 | 27 | // The following GUID is for the ID of the typelib if this project is exposed to COM 28 | [assembly: Guid("75bb7605-e54b-4ede-8f5a-ff1f24464236")] 29 | 30 | [assembly: NeutralResourcesLanguage("en")] 31 | 32 | [assembly: AssemblyVersion("3.0.0.0")] 33 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/Spacing.cs: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | // BEGIN_UNITY @joce 11-21-2016 CompileForC#Bindings 11 | //namespace Facebook.CSSLayout 12 | namespace UnityEngine.CSSLayout 13 | // END_UNITY 14 | { 15 | internal class Spacing 16 | { 17 | public float? Top; 18 | public float? Bottom; 19 | public float? Left; 20 | public float? Right; 21 | 22 | public Spacing( 23 | float? top = null, 24 | float? bottom = null, 25 | float? left = null, 26 | float? right = null) 27 | { 28 | Top = top; 29 | Bottom = bottom; 30 | Left = left; 31 | Right = right; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /csharp/Facebook.CSSLayout/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "language": "en", 3 | "version": "3.0.0-*", 4 | 5 | "dependencies": { 6 | "NETStandard.Library": "1.6.0" 7 | }, 8 | 9 | "frameworks": { 10 | "netstandard1.6": { 11 | "imports": "dnxcore50" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /csharp/tests/Facebook.CSSLayout/test_macos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if clang --version >/dev/null 2>&1; then true; else 3 | echo "ERROR: Can't execute clang. You need to install Xcode and command line tools." 4 | exit 1 5 | fi 6 | 7 | if mcs --version >/dev/null 2>&1; then true; else 8 | echo "ERROR: Can't execute mcs. You need to install Mono from http://www.mono-project.com/download/ and re-login to apply PATH environment." 9 | exit 1 10 | fi 11 | 12 | if mono --version >/dev/null 2>&1; then true; else 13 | echo "ERROR: Can't execute mono64. You need to install Mono from http://www.mono-project.com/download/ and re-login to apply PATH environment." 14 | exit 1 15 | fi 16 | 17 | cd "$( dirname "$0" )" 18 | 19 | NUNIT=NUnit-2.6.4/bin 20 | if [ -d $NUNIT \ 21 | -a -f $NUNIT/nunit-console.exe \ 22 | -a -f $NUNIT/lib/nunit-console-runner.dll \ 23 | -a -f $NUNIT/lib/nunit.core.dll \ 24 | -a -f $NUNIT/lib/nunit.core.interfaces.dll \ 25 | -a -f $NUNIT/lib/nunit.util.dll ]; then true; else 26 | curl -L -O https://github.com/nunit/nunitv2/releases/download/2.6.4/NUnit-2.6.4.zip 27 | unzip -qq NUnit-2.6.4.zip 28 | rm NUnit-2.6.4.zip 29 | fi 30 | 31 | clang -g -Wall -Wextra -dynamiclib -o libCSSLayout.dylib -I../../.. ../../../CSSLayout/*.c ../../CSSLayout/CSSInterop.cpp 32 | mcs -debug -t:library -r:$NUNIT/nunit.framework.dll -out:CSSLayoutTest.dll *.cs ../../../csharp/Facebook.CSSLayout/*cs 33 | MONO_PATH=$NUNIT mono --arch=64 --debug $NUNIT/nunit-console.exe CSSLayoutTest.dll 34 | -------------------------------------------------------------------------------- /format.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | clang-format \ 4 | -style="{ \ 5 | AlignAfterOpenBracket: Align, \ 6 | AlignEscapedNewlinesLeft: true, \ 7 | AlignOperands: true, \ 8 | AllowAllParametersOfDeclarationOnNextLine: false, \ 9 | AllowShortBlocksOnASingleLine: false, \ 10 | AllowShortCaseLabelsOnASingleLine: false, \ 11 | AllowShortFunctionsOnASingleLine: false, \ 12 | AllowShortIfStatementsOnASingleLine: false, \ 13 | AllowShortLoopsOnASingleLine: false, \ 14 | BinPackArguments: false, \ 15 | BinPackParameters: false, \ 16 | BreakBeforeBraces: Attach, \ 17 | ColumnLimit: 100, \ 18 | ContinuationIndentWidth: 4, \ 19 | IndentCaseLabels: true, \ 20 | IndentWidth: 2, \ 21 | KeepEmptyLinesAtTheStartOfBlocks: false, \ 22 | Language: Cpp, \ 23 | PenaltyBreakBeforeFirstCallParameter: 100, \ 24 | PenaltyBreakString: 1000, \ 25 | PenaltyExcessCharacter: 100, \ 26 | PenaltyReturnTypeOnItsOwnLine: 100, \ 27 | PointerAlignment: Right, \ 28 | SortIncludes: true, \ 29 | SpaceAfterCStyleCast: true, \ 30 | UseTab: Never, \ 31 | }" "$@" \ 32 | -i $(dirname $0)/CSSLayout/*.{h,c,cpp} \ 33 | $(dirname $0)/tests/CSSLayoutTestUtils/*.{h,c,cpp} \ 34 | $(dirname $0)/benchmarks/*.{h,c,cpp} \ 35 | $(dirname $0)/java/jni/*.{h,c,cpp} 36 | -------------------------------------------------------------------------------- /gentest/fixtures/CSSLayoutAbsolutePositionTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 5 |
6 |
7 |
8 | 9 |
10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 |
18 |
19 |
20 |
21 |
22 | 23 |
24 |
25 |
26 |
27 | -------------------------------------------------------------------------------- /gentest/fixtures/CSSLayoutAlignContentTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | 9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | 17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | 25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | -------------------------------------------------------------------------------- /gentest/fixtures/CSSLayoutAlignItemsTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 5 |
6 |
7 |
8 | 9 |
10 |
11 |
12 | 13 |
14 |
15 |
16 | -------------------------------------------------------------------------------- /gentest/fixtures/CSSLayoutAlignSelfTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 5 |
6 |
7 |
8 | 9 |
10 |
11 |
12 | 13 |
14 |
15 |
16 | -------------------------------------------------------------------------------- /gentest/fixtures/CSSLayoutBorderTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 |
6 |
7 | 8 |
9 |
10 |
11 | 12 |
13 |
14 |
15 | 16 |
17 |
18 |
19 | -------------------------------------------------------------------------------- /gentest/fixtures/CSSLayoutFlexDirectionTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 | 7 |
8 |
9 |
10 |
11 |
12 | 13 |
14 |
15 |
16 |
17 |
18 | 19 |
20 |
21 |
22 |
23 |
24 | 25 |
26 |
27 |
28 |
29 |
30 | 31 |
32 |
33 |
34 |
35 |
36 | -------------------------------------------------------------------------------- /gentest/fixtures/CSSLayoutFlexTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 | 6 |
7 |
8 |
9 |
10 | 11 |
12 |
13 |
14 |
15 | 16 |
17 |
18 |
19 |
20 | 21 |
22 |
23 |
24 |
25 |
26 | 27 |
28 |
29 |
30 |
31 |
32 | 33 |
34 |
35 |
36 |
37 |
38 | -------------------------------------------------------------------------------- /gentest/fixtures/CSSLayoutFlexWrapTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 |
7 | 8 |
9 |
10 |
11 |
12 |
13 |
14 | 15 |
16 |
17 |
18 |
19 |
20 |
21 | 22 |
23 |
24 |
25 |
26 |
27 |
28 | -------------------------------------------------------------------------------- /gentest/fixtures/CSSLayoutJustifyContentTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 | 7 |
8 |
9 |
10 |
11 |
12 | 13 |
14 |
15 |
16 |
17 |
18 | 19 |
20 |
21 |
22 |
23 |
24 | 25 |
26 |
27 |
28 |
29 |
30 | 31 |
32 |
33 |
34 |
35 |
36 | 37 |
38 |
39 |
40 |
41 |
42 | 43 |
44 |
45 |
46 |
47 |
48 | 49 |
50 |
51 |
52 |
53 |
54 | 55 |
56 |
57 |
58 |
59 |
60 | -------------------------------------------------------------------------------- /gentest/fixtures/CSSLayoutMarginTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 5 |
6 |
7 |
8 | 9 |
10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 |
18 |
19 |
20 | 21 |
22 |
23 |
24 | 25 |
26 |
27 |
28 | 29 |
30 |
31 |
32 | 33 |
34 |
35 |
36 |
37 | 38 |
39 |
40 |
41 |
42 | -------------------------------------------------------------------------------- /gentest/fixtures/CSSLayoutMinMaxDimensionTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 5 |
6 |
7 |
8 | 9 |
10 |
11 |
12 |
13 | 14 |
15 |
16 |
17 |
18 | 19 |
20 |
21 |
22 | 23 |
24 |
25 |
26 | 27 |
28 |
29 |
30 |
31 |
32 | 33 |
34 |
35 |
36 |
37 |
38 | 39 |
40 |
41 |
42 |
43 |
44 | -------------------------------------------------------------------------------- /gentest/fixtures/CSSLayoutPaddingTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 |
6 |
7 | 8 |
9 |
10 |
11 | 12 |
13 |
14 |
15 | 16 |
17 |
18 |
19 | 20 |
21 |
22 |
23 | -------------------------------------------------------------------------------- /gentest/fixtures/CSSLayoutRoundingTest.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 | 7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | 15 |
16 |
17 |
18 |
19 |
20 | 21 |
22 |
23 |
24 |
25 |
26 | 27 |
28 |
29 |
30 |
31 |
32 | 33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | 42 |
43 |
44 |
45 |
46 |
47 | 48 |
49 |
50 |
51 |
52 |
53 | 54 |
55 |
56 |
57 |
58 |
59 | 60 |
61 |
62 |
63 |
64 |
65 | -------------------------------------------------------------------------------- /gentest/gentest.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'watir-webdriver' 4 | require 'fileutils' 5 | 6 | caps = Selenium::WebDriver::Remote::Capabilities.chrome( 7 | "loggingPrefs"=>{ 8 | "browser"=>"ALL", 9 | "performance"=>"ALL" 10 | } 11 | ) 12 | browser = Watir::Browser.new(:chrome, :desired_capabilities => caps) 13 | Dir.chdir(File.dirname($0)) 14 | 15 | Dir['fixtures/*.html'].each do |file| 16 | fixture = File.read(file) 17 | name = File.basename(file, '.*') 18 | puts "Generate #{name}" 19 | 20 | ltr_fixture = fixture.gsub('start', 'left') 21 | .gsub('end', 'right') 22 | .gsub('flex-left', 'flex-start') 23 | .gsub('flex-right', 'flex-end') 24 | 25 | rtl_fixture = fixture.gsub('start', 'right') 26 | .gsub('end', 'left') 27 | .gsub('flex-right', 'flex-start') 28 | .gsub('flex-left', 'flex-end') 29 | 30 | template = File.open('test-template.html').read 31 | f = File.open('test.html', 'w') 32 | f.write sprintf(template, name, ltr_fixture, rtl_fixture, fixture) 33 | f.close 34 | FileUtils.copy('test.html', "#{name}.html") if $DEBUG 35 | 36 | browser.goto('file://' + Dir.pwd + '/test.html') 37 | logs = browser.driver.manage.logs.get(:browser) 38 | 39 | f = File.open("../tests/#{name}.cpp", 'w') 40 | f.write eval(logs[0].message.sub(/^[^"]*/, '')) 41 | f.close 42 | 43 | f = File.open("../java/tests/com/facebook/csslayout/#{name}.java", 'w') 44 | f.write eval(logs[1].message.sub(/^[^"]*/, '')).sub('CSSNodeLayoutTest', name) 45 | f.close 46 | 47 | f = File.open("../csharp/tests/Facebook.CSSLayout/#{name}.cs", 'w') 48 | f.write eval(logs[2].message.sub(/^[^"]*/, '')).sub('CSSNodeLayoutTest', name) 49 | f.close 50 | end 51 | File.delete('test.html') 52 | browser.close 53 | -------------------------------------------------------------------------------- /gentest/test-template.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %s 6 | 7 | 8 | 9 | 10 | 11 | 48 | 49 | 50 | 51 |
52 | 53 | %s 54 | 55 |
56 |
57 |
58 | 59 | %s 60 | 61 |
62 |
63 | 64 |
65 | 66 | %s 67 | 68 |
69 | 70 | 71 | -------------------------------------------------------------------------------- /java/BUCK: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | include_defs('//YOGA_DEFS') 9 | 10 | cxx_library( 11 | name = 'jni', 12 | soname = 'libcsslayout.$(ext)', 13 | srcs = glob(['jni/*.cpp']), 14 | header_namespace = '', 15 | compiler_flags = [ 16 | '-fno-omit-frame-pointer', 17 | '-fexceptions', 18 | '-fPIC', 19 | '-Wall', 20 | '-Werror', 21 | '-O3', 22 | '-std=c++11', 23 | ], 24 | deps = [ 25 | FBJNI_TARGET, 26 | JNI_TARGET, 27 | csslayout_dep(':CSSLayout'), 28 | ], 29 | visibility = ['PUBLIC'], 30 | ) 31 | 32 | java_library( 33 | name = 'java', 34 | srcs = glob(['com/facebook/csslayout/*.java']), 35 | tests=[ 36 | csslayout_dep('java:tests'), 37 | ], 38 | source = '1.7', 39 | target = '1.7', 40 | deps = [ 41 | ':jni', 42 | INFER_ANNOTATIONS_TARGET, 43 | JSR_305_TARGET, 44 | PROGRUARD_ANNOTATIONS_TARGET, 45 | SOLOADER_TARGET, 46 | ], 47 | visibility = ['PUBLIC'], 48 | ) 49 | 50 | java_test( 51 | name = 'tests', 52 | srcs = glob(['tests/**/*.java']), 53 | use_cxx_libraries = True, 54 | cxx_library_whitelist = CXX_LIBRARY_WHITELIST, 55 | deps = [ 56 | ':java', 57 | JUNIT_TARGET, 58 | ], 59 | visibility = ['PUBLIC'], 60 | ) 61 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSAlign.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum CSSAlign { 16 | AUTO(0), 17 | FLEX_START(1), 18 | CENTER(2), 19 | FLEX_END(3), 20 | STRETCH(4); 21 | 22 | private int mIntValue; 23 | 24 | CSSAlign(int intValue) { 25 | mIntValue = intValue; 26 | } 27 | 28 | public int intValue() { 29 | return mIntValue; 30 | } 31 | 32 | public static CSSAlign fromInt(int value) { 33 | switch (value) { 34 | case 0: return AUTO; 35 | case 1: return FLEX_START; 36 | case 2: return CENTER; 37 | case 3: return FLEX_END; 38 | case 4: return STRETCH; 39 | default: throw new IllegalArgumentException("Unkown enum value: " + value); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | public class CSSConstants { 13 | 14 | public static final float UNDEFINED = Float.NaN; 15 | 16 | public static boolean isUndefined(float value) { 17 | return Float.compare(value, UNDEFINED) == 0; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSDimension.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum CSSDimension { 16 | WIDTH(0), 17 | HEIGHT(1); 18 | 19 | private int mIntValue; 20 | 21 | CSSDimension(int intValue) { 22 | mIntValue = intValue; 23 | } 24 | 25 | public int intValue() { 26 | return mIntValue; 27 | } 28 | 29 | public static CSSDimension fromInt(int value) { 30 | switch (value) { 31 | case 0: return WIDTH; 32 | case 1: return HEIGHT; 33 | default: throw new IllegalArgumentException("Unkown enum value: " + value); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSDirection.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum CSSDirection { 16 | INHERIT(0), 17 | LTR(1), 18 | RTL(2); 19 | 20 | private int mIntValue; 21 | 22 | CSSDirection(int intValue) { 23 | mIntValue = intValue; 24 | } 25 | 26 | public int intValue() { 27 | return mIntValue; 28 | } 29 | 30 | public static CSSDirection fromInt(int value) { 31 | switch (value) { 32 | case 0: return INHERIT; 33 | case 1: return LTR; 34 | case 2: return RTL; 35 | default: throw new IllegalArgumentException("Unkown enum value: " + value); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSEdge.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum CSSEdge { 16 | LEFT(0), 17 | TOP(1), 18 | RIGHT(2), 19 | BOTTOM(3), 20 | START(4), 21 | END(5), 22 | HORIZONTAL(6), 23 | VERTICAL(7), 24 | ALL(8); 25 | 26 | private int mIntValue; 27 | 28 | CSSEdge(int intValue) { 29 | mIntValue = intValue; 30 | } 31 | 32 | public int intValue() { 33 | return mIntValue; 34 | } 35 | 36 | public static CSSEdge fromInt(int value) { 37 | switch (value) { 38 | case 0: return LEFT; 39 | case 1: return TOP; 40 | case 2: return RIGHT; 41 | case 3: return BOTTOM; 42 | case 4: return START; 43 | case 5: return END; 44 | case 6: return HORIZONTAL; 45 | case 7: return VERTICAL; 46 | case 8: return ALL; 47 | default: throw new IllegalArgumentException("Unkown enum value: " + value); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSExperimentalFeature.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum CSSExperimentalFeature { 16 | ROUNDING(0), 17 | WEB_FLEX_BASIS(1); 18 | 19 | private int mIntValue; 20 | 21 | CSSExperimentalFeature(int intValue) { 22 | mIntValue = intValue; 23 | } 24 | 25 | public int intValue() { 26 | return mIntValue; 27 | } 28 | 29 | public static CSSExperimentalFeature fromInt(int value) { 30 | switch (value) { 31 | case 0: return ROUNDING; 32 | case 1: return WEB_FLEX_BASIS; 33 | default: throw new IllegalArgumentException("Unkown enum value: " + value); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSFlexDirection.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum CSSFlexDirection { 16 | COLUMN(0), 17 | COLUMN_REVERSE(1), 18 | ROW(2), 19 | ROW_REVERSE(3); 20 | 21 | private int mIntValue; 22 | 23 | CSSFlexDirection(int intValue) { 24 | mIntValue = intValue; 25 | } 26 | 27 | public int intValue() { 28 | return mIntValue; 29 | } 30 | 31 | public static CSSFlexDirection fromInt(int value) { 32 | switch (value) { 33 | case 0: return COLUMN; 34 | case 1: return COLUMN_REVERSE; 35 | case 2: return ROW; 36 | case 3: return ROW_REVERSE; 37 | default: throw new IllegalArgumentException("Unkown enum value: " + value); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSJustify.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum CSSJustify { 16 | FLEX_START(0), 17 | CENTER(1), 18 | FLEX_END(2), 19 | SPACE_BETWEEN(3), 20 | SPACE_AROUND(4); 21 | 22 | private int mIntValue; 23 | 24 | CSSJustify(int intValue) { 25 | mIntValue = intValue; 26 | } 27 | 28 | public int intValue() { 29 | return mIntValue; 30 | } 31 | 32 | public static CSSJustify fromInt(int value) { 33 | switch (value) { 34 | case 0: return FLEX_START; 35 | case 1: return CENTER; 36 | case 2: return FLEX_END; 37 | case 3: return SPACE_BETWEEN; 38 | case 4: return SPACE_AROUND; 39 | default: throw new IllegalArgumentException("Unkown enum value: " + value); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSLogLevel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum CSSLogLevel { 16 | ERROR(0), 17 | WARN(1), 18 | INFO(2), 19 | DEBUG(3), 20 | VERBOSE(4); 21 | 22 | private int mIntValue; 23 | 24 | CSSLogLevel(int intValue) { 25 | mIntValue = intValue; 26 | } 27 | 28 | public int intValue() { 29 | return mIntValue; 30 | } 31 | 32 | public static CSSLogLevel fromInt(int value) { 33 | switch (value) { 34 | case 0: return ERROR; 35 | case 1: return WARN; 36 | case 2: return INFO; 37 | case 3: return DEBUG; 38 | case 4: return VERBOSE; 39 | default: throw new IllegalArgumentException("Unkown enum value: " + value); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSLogger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | /** 15 | * Inteface for recieving logs from native layer. Use by setting CSSNode.setLogger(myLogger); 16 | * See CSSLogLevel for the different log levels. 17 | */ 18 | @DoNotStrip 19 | public interface CSSLogger { 20 | @DoNotStrip 21 | void log(CSSLogLevel level, String message); 22 | } 23 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSMeasureMode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum CSSMeasureMode { 16 | UNDEFINED(0), 17 | EXACTLY(1), 18 | AT_MOST(2); 19 | 20 | private int mIntValue; 21 | 22 | CSSMeasureMode(int intValue) { 23 | mIntValue = intValue; 24 | } 25 | 26 | public int intValue() { 27 | return mIntValue; 28 | } 29 | 30 | public static CSSMeasureMode fromInt(int value) { 31 | switch (value) { 32 | case 0: return UNDEFINED; 33 | case 1: return EXACTLY; 34 | case 2: return AT_MOST; 35 | default: throw new IllegalArgumentException("Unkown enum value: " + value); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSNodeAPI.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | public interface CSSNodeAPI { 13 | 14 | interface MeasureFunction { 15 | /** 16 | * Return a value created by MeasureOutput.make(width, height); 17 | */ 18 | long measure( 19 | CSSNodeAPI node, 20 | float width, 21 | CSSMeasureMode widthMode, 22 | float height, 23 | CSSMeasureMode heightMode); 24 | } 25 | 26 | int getChildCount(); 27 | CSSNodeType getChildAt(int i); 28 | void addChildAt(CSSNodeType child, int i); 29 | CSSNodeType removeChildAt(int i); 30 | CSSNodeType getParent(); 31 | int indexOf(CSSNodeType child); 32 | void setMeasureFunction(MeasureFunction measureFunction); 33 | boolean isMeasureDefined(); 34 | void calculateLayout(); 35 | boolean isDirty(); 36 | boolean hasNewLayout(); 37 | void dirty(); 38 | void markLayoutSeen(); 39 | void copyStyle(CSSNodeType srcNode); 40 | CSSDirection getStyleDirection(); 41 | void setDirection(CSSDirection direction); 42 | CSSFlexDirection getFlexDirection(); 43 | void setFlexDirection(CSSFlexDirection flexDirection); 44 | CSSJustify getJustifyContent(); 45 | void setJustifyContent(CSSJustify justifyContent); 46 | CSSAlign getAlignItems(); 47 | void setAlignItems(CSSAlign alignItems); 48 | CSSAlign getAlignSelf(); 49 | void setAlignSelf(CSSAlign alignSelf); 50 | CSSAlign getAlignContent(); 51 | void setAlignContent(CSSAlign alignContent); 52 | CSSPositionType getPositionType(); 53 | void setPositionType(CSSPositionType positionType); 54 | void setWrap(CSSWrap flexWrap); 55 | void setFlex(float flex); 56 | float getFlexGrow(); 57 | void setFlexGrow(float flexGrow); 58 | float getFlexShrink(); 59 | void setFlexShrink(float flexShrink); 60 | float getFlexBasis(); 61 | void setFlexBasis(float flexBasis); 62 | float getMargin(CSSEdge edge); 63 | void setMargin(CSSEdge edge, float margin); 64 | float getPadding(CSSEdge edge); 65 | void setPadding(CSSEdge edge, float padding); 66 | float getBorder(CSSEdge edge); 67 | void setBorder(CSSEdge edge, float border); 68 | float getPosition(CSSEdge edge); 69 | void setPosition(CSSEdge edge, float position); 70 | float getWidth(); 71 | void setWidth(float width); 72 | float getHeight(); 73 | void setHeight(float height); 74 | float getMaxWidth(); 75 | void setMaxWidth(float maxWidth); 76 | float getMinWidth(); 77 | void setMinWidth(float minWidth); 78 | float getMaxHeight(); 79 | void setMaxHeight(float maxHeight); 80 | float getMinHeight(); 81 | void setMinHeight(float minHeight); 82 | float getLayoutX(); 83 | float getLayoutY(); 84 | float getLayoutWidth(); 85 | float getLayoutHeight(); 86 | CSSDirection getLayoutDirection(); 87 | CSSOverflow getOverflow(); 88 | void setOverflow(CSSOverflow overflow); 89 | void setData(Object data); 90 | Object getData(); 91 | void reset(); 92 | } 93 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSOverflow.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum CSSOverflow { 16 | VISIBLE(0), 17 | HIDDEN(1), 18 | SCROLL(2); 19 | 20 | private int mIntValue; 21 | 22 | CSSOverflow(int intValue) { 23 | mIntValue = intValue; 24 | } 25 | 26 | public int intValue() { 27 | return mIntValue; 28 | } 29 | 30 | public static CSSOverflow fromInt(int value) { 31 | switch (value) { 32 | case 0: return VISIBLE; 33 | case 1: return HIDDEN; 34 | case 2: return SCROLL; 35 | default: throw new IllegalArgumentException("Unkown enum value: " + value); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSPositionType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum CSSPositionType { 16 | RELATIVE(0), 17 | ABSOLUTE(1); 18 | 19 | private int mIntValue; 20 | 21 | CSSPositionType(int intValue) { 22 | mIntValue = intValue; 23 | } 24 | 25 | public int intValue() { 26 | return mIntValue; 27 | } 28 | 29 | public static CSSPositionType fromInt(int value) { 30 | switch (value) { 31 | case 0: return RELATIVE; 32 | case 1: return ABSOLUTE; 33 | default: throw new IllegalArgumentException("Unkown enum value: " + value); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSPrintOptions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum CSSPrintOptions { 16 | LAYOUT(1), 17 | STYLE(2), 18 | CHILDREN(4); 19 | 20 | private int mIntValue; 21 | 22 | CSSPrintOptions(int intValue) { 23 | mIntValue = intValue; 24 | } 25 | 26 | public int intValue() { 27 | return mIntValue; 28 | } 29 | 30 | public static CSSPrintOptions fromInt(int value) { 31 | switch (value) { 32 | case 1: return LAYOUT; 33 | case 2: return STYLE; 34 | case 4: return CHILDREN; 35 | default: throw new IllegalArgumentException("Unkown enum value: " + value); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/CSSWrap.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public enum CSSWrap { 16 | NO_WRAP(0), 17 | WRAP(1); 18 | 19 | private int mIntValue; 20 | 21 | CSSWrap(int intValue) { 22 | mIntValue = intValue; 23 | } 24 | 25 | public int intValue() { 26 | return mIntValue; 27 | } 28 | 29 | public static CSSWrap fromInt(int value) { 30 | switch (value) { 31 | case 0: return NO_WRAP; 32 | case 1: return WRAP; 33 | default: throw new IllegalArgumentException("Unkown enum value: " + value); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /java/com/facebook/csslayout/MeasureOutput.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | /** 13 | * Helpers for building measure output value. 14 | */ 15 | public class MeasureOutput { 16 | 17 | public static long make(float width, float height) { 18 | return make((int) width, (int) height); 19 | } 20 | 21 | public static long make(int width, int height) { 22 | return ((long) width) << 32 | ((long) height); 23 | } 24 | 25 | public static int getWidth(long measureOutput) { 26 | return (int) (0xFFFFFFFF & (measureOutput >> 32)); 27 | } 28 | 29 | public static int getHeight(long measureOutput) { 30 | return (int) (0xFFFFFFFF & measureOutput); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /java/com/facebook/proguard/annotations/BUCK: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | include_defs('//YOGA_DEFS') 9 | 10 | java_library( 11 | name = 'annotations', 12 | srcs = glob(['*.java']), 13 | source = '1.7', 14 | target = '1.7', 15 | deps = [], 16 | visibility = [CSSLAYOUT_ROOT], 17 | ) 18 | -------------------------------------------------------------------------------- /java/com/facebook/proguard/annotations/DoNotStrip.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.proguard.annotations; 11 | 12 | import java.lang.annotation.ElementType; 13 | import java.lang.annotation.Retention; 14 | import java.lang.annotation.Target; 15 | 16 | import static java.lang.annotation.RetentionPolicy.CLASS; 17 | 18 | @Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR }) 19 | @Retention(CLASS) 20 | public @interface DoNotStrip { } 21 | -------------------------------------------------------------------------------- /java/tests/com/facebook/csslayout/CSSNodeTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.csslayout; 11 | 12 | import org.junit.Test; 13 | 14 | import static org.junit.Assert.assertEquals; 15 | import static org.junit.Assert.assertTrue; 16 | 17 | public class CSSNodeTest { 18 | 19 | @Test 20 | public void testInit() { 21 | final int refCount = CSSNode.jni_CSSNodeGetInstanceCount(); 22 | final CSSNode node = new CSSNode(); 23 | assertEquals(refCount + 1, CSSNode.jni_CSSNodeGetInstanceCount()); 24 | } 25 | 26 | @Test 27 | public void testMeasure() { 28 | final CSSNode node = new CSSNode(); 29 | node.setMeasureFunction(new CSSNodeAPI.MeasureFunction() { 30 | public long measure( 31 | CSSNodeAPI node, 32 | float width, 33 | CSSMeasureMode widthMode, 34 | float height, 35 | CSSMeasureMode heightMode) { 36 | return MeasureOutput.make(100, 100); 37 | } 38 | }); 39 | node.calculateLayout(); 40 | assertEquals(100, (int) node.getLayoutWidth()); 41 | assertEquals(100, (int) node.getLayoutHeight()); 42 | } 43 | 44 | private CSSLogLevel mLogLevel; 45 | private String mLogMessage; 46 | 47 | @Test 48 | public void testLogger() { 49 | CSSNode.setLogger(new CSSLogger() { 50 | public void log(CSSLogLevel level, String message) { 51 | mLogLevel = level; 52 | mLogMessage = message; 53 | } 54 | }); 55 | CSSNode.jni_CSSLog(CSSLogLevel.DEBUG.intValue(), "Hello"); 56 | assertEquals(CSSLogLevel.DEBUG, mLogLevel); 57 | assertEquals("Hello", mLogMessage); 58 | } 59 | 60 | @Test 61 | public void testUpdateLogger() { 62 | CSSNode.setLogger(new CSSLogger() { 63 | public void log(CSSLogLevel level, String message) {} 64 | }); 65 | CSSNode.setLogger(new CSSLogger() { 66 | public void log(CSSLogLevel level, String message) { 67 | mLogLevel = level; 68 | mLogMessage = message; 69 | } 70 | }); 71 | CSSNode.jni_CSSLog(CSSLogLevel.VERBOSE.intValue(), "Flexbox"); 72 | assertEquals(CSSLogLevel.VERBOSE, mLogLevel); 73 | assertEquals("Flexbox", mLogMessage); 74 | } 75 | 76 | @Test 77 | public void testCopyStyle() { 78 | final CSSNode node0 = new CSSNode(); 79 | assertTrue(CSSConstants.isUndefined(node0.getMaxHeight())); 80 | 81 | final CSSNode node1 = new CSSNode(); 82 | node1.setMaxHeight(100); 83 | 84 | node0.copyStyle(node1); 85 | assertEquals(100, (int) node0.getMaxHeight()); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /lib/fb/BUCK: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | include_defs('//YOGA_DEFS') 9 | 10 | prebuilt_cxx_library( 11 | name = 'ndklog', 12 | header_only = True, 13 | exported_platform_linker_flags = [ 14 | ('android.*', ['-llog']), 15 | ], 16 | visibility = [CSSLAYOUT_ROOT], 17 | ) 18 | 19 | cxx_library( 20 | name = 'fbjni', 21 | srcs = glob(['**/*.cpp']), 22 | exported_headers = subdir_glob([('include', '**/*.h')]), 23 | header_namespace = '', 24 | compiler_flags = [ 25 | '-DLOG_TAG=\"libfb\"', 26 | '-DDISABLE_CPUCAP', 27 | '-DDISABLE_XPLAT', 28 | '-DHAVE_POSIX_CLOCKS', 29 | '-fno-omit-frame-pointer', 30 | '-fexceptions', 31 | '-frtti', 32 | '-Wall', 33 | '-Werror', 34 | '-Wno-unused-parameter', 35 | '-std=c++11', 36 | ], 37 | deps = [ 38 | ':ndklog', 39 | JNI_TARGET, 40 | ], 41 | visibility = ['PUBLIC'], 42 | ) 43 | -------------------------------------------------------------------------------- /lib/fb/Doxyfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "Facebook Android Support" 2 | JAVADOC_AUTOBRIEF = YES 3 | EXTRACT_ALL = YES 4 | RECURSIVE = YES 5 | EXCLUDE = tests 6 | EXCLUDE_PATTERNS = *.cpp 7 | GENERATE_HTML = YES 8 | GENERATE_LATEX = NO 9 | ENABLE_PREPROCESSING = YES 10 | HIDE_UNDOC_MEMBERS = YES 11 | HIDE_SCOPE_NAMES = YES 12 | HIDE_FRIEND_COMPOUNDS = YES 13 | HIDE_UNDOC_CLASSES = YES 14 | SHOW_INCLUDE_FILES = NO 15 | #ENABLED_SECTIONS = INTERNAL 16 | -------------------------------------------------------------------------------- /lib/fb/assert.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace facebook { 17 | 18 | #define ASSERT_BUF_SIZE 4096 19 | static char sAssertBuf[ASSERT_BUF_SIZE]; 20 | static AssertHandler gAssertHandler; 21 | 22 | void assertInternal(const char* formatstr ...) { 23 | va_list va_args; 24 | va_start(va_args, formatstr); 25 | vsnprintf(sAssertBuf, sizeof(sAssertBuf), formatstr, va_args); 26 | va_end(va_args); 27 | if (gAssertHandler != NULL) { 28 | gAssertHandler(sAssertBuf); 29 | } 30 | FBLOG(LOG_FATAL, "fbassert", "%s", sAssertBuf); 31 | // crash at this specific address so that we can find our crashes easier 32 | *(int*)0xdeadb00c = 0; 33 | // let the compiler know we won't reach the end of the function 34 | __builtin_unreachable(); 35 | } 36 | 37 | void setAssertHandler(AssertHandler assertHandler) { 38 | gAssertHandler = assertHandler; 39 | } 40 | 41 | } // namespace facebook 42 | -------------------------------------------------------------------------------- /lib/fb/include/fb/ALog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | /** @file ALog.h 11 | * 12 | * Very simple android only logging. Define LOG_TAG to enable the macros. 13 | */ 14 | 15 | #pragma once 16 | 17 | #ifdef __ANDROID__ 18 | 19 | #include 20 | 21 | namespace facebook { 22 | namespace alog { 23 | 24 | template 25 | inline void log(int level, const char* tag, const char* msg, ARGS... args) noexcept { 26 | __android_log_print(level, tag, msg, args...); 27 | } 28 | 29 | template 30 | inline void log(int level, const char* tag, const char* msg) noexcept { 31 | __android_log_write(level, tag, msg); 32 | } 33 | 34 | template 35 | inline void logv(const char* tag, const char* msg, ARGS... args) noexcept { 36 | log(ANDROID_LOG_VERBOSE, tag, msg, args...); 37 | } 38 | 39 | template 40 | inline void logd(const char* tag, const char* msg, ARGS... args) noexcept { 41 | log(ANDROID_LOG_DEBUG, tag, msg, args...); 42 | } 43 | 44 | template 45 | inline void logi(const char* tag, const char* msg, ARGS... args) noexcept { 46 | log(ANDROID_LOG_INFO, tag, msg, args...); 47 | } 48 | 49 | template 50 | inline void logw(const char* tag, const char* msg, ARGS... args) noexcept { 51 | log(ANDROID_LOG_WARN, tag, msg, args...); 52 | } 53 | 54 | template 55 | inline void loge(const char* tag, const char* msg, ARGS... args) noexcept { 56 | log(ANDROID_LOG_ERROR, tag, msg, args...); 57 | } 58 | 59 | template 60 | inline void logf(const char* tag, const char* msg, ARGS... args) noexcept { 61 | log(ANDROID_LOG_FATAL, tag, msg, args...); 62 | } 63 | 64 | 65 | #ifdef LOG_TAG 66 | # define ALOGV(...) ::facebook::alog::logv(LOG_TAG, __VA_ARGS__) 67 | # define ALOGD(...) ::facebook::alog::logd(LOG_TAG, __VA_ARGS__) 68 | # define ALOGI(...) ::facebook::alog::logi(LOG_TAG, __VA_ARGS__) 69 | # define ALOGW(...) ::facebook::alog::logw(LOG_TAG, __VA_ARGS__) 70 | # define ALOGE(...) ::facebook::alog::loge(LOG_TAG, __VA_ARGS__) 71 | # define ALOGF(...) ::facebook::alog::logf(LOG_TAG, __VA_ARGS__) 72 | #endif 73 | 74 | }} 75 | 76 | #else 77 | # define ALOGV(...) ((void)0) 78 | # define ALOGD(...) ((void)0) 79 | # define ALOGI(...) ((void)0) 80 | # define ALOGW(...) ((void)0) 81 | # define ALOGE(...) ((void)0) 82 | # define ALOGF(...) ((void)0) 83 | #endif 84 | -------------------------------------------------------------------------------- /lib/fb/include/fb/Countable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace facebook { 18 | 19 | class Countable : public noncopyable, public nonmovable { 20 | public: 21 | // RefPtr expects refcount to start at 0 22 | Countable() : m_refcount(0) {} 23 | virtual ~Countable() 24 | { 25 | FBASSERT(m_refcount == 0); 26 | } 27 | 28 | private: 29 | void ref() { 30 | ++m_refcount; 31 | } 32 | 33 | void unref() { 34 | if (0 == --m_refcount) { 35 | delete this; 36 | } 37 | } 38 | 39 | bool hasOnlyOneRef() const { 40 | return m_refcount == 1; 41 | } 42 | 43 | template friend class RefPtr; 44 | std::atomic m_refcount; 45 | }; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /lib/fb/include/fb/Doxyfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "Facebook JNI" 2 | PROJECT_BRIEF = "Helper library to provide safe and convenient access to JNI with very low overhead" 3 | JAVADOC_AUTOBRIEF = YES 4 | EXTRACT_ALL = YES 5 | RECURSIVE = YES 6 | EXCLUDE = tests Asserts.h Countable.h GlobalReference.h LocalReference.h LocalString.h Registration.h WeakReference.h jni_helpers.h Environment.h 7 | EXCLUDE_PATTERNS = *-inl.h *.cpp 8 | GENERATE_HTML = YES 9 | GENERATE_LATEX = NO 10 | ENABLE_PREPROCESSING = YES 11 | HIDE_UNDOC_MEMBERS = YES 12 | HIDE_SCOPE_NAMES = YES 13 | HIDE_FRIEND_COMPOUNDS = YES 14 | HIDE_UNDOC_CLASSES = YES 15 | SHOW_INCLUDE_FILES = NO 16 | PREDEFINED = LOG_TAG=fbjni 17 | EXAMPLE_PATH = samples 18 | #ENABLED_SECTIONS = INTERNAL 19 | -------------------------------------------------------------------------------- /lib/fb/include/fb/Environment.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace facebook { 18 | namespace jni { 19 | 20 | // Keeps a thread-local reference to the current thread's JNIEnv. 21 | struct Environment { 22 | // May be null if this thread isn't attached to the JVM 23 | FBEXPORT static JNIEnv* current(); 24 | static void initialize(JavaVM* vm); 25 | 26 | // There are subtle issues with calling the next functions directly. It is 27 | // much better to always use a ThreadScope to manage attaching/detaching for 28 | // you. 29 | FBEXPORT static JNIEnv* ensureCurrentThreadIsAttached(); 30 | FBEXPORT static void detachCurrentThread(); 31 | }; 32 | 33 | /** 34 | * RAII Object that attaches a thread to the JVM. Failing to detach from a thread before it 35 | * exits will cause a crash, as will calling Detach an extra time, and this guard class helps 36 | * keep that straight. In addition, it remembers whether it performed the attach or not, so it 37 | * is safe to nest it with itself or with non-fbjni code that manages the attachment correctly. 38 | * 39 | * Potential concerns: 40 | * - Attaching to the JVM is fast (~100us on MotoG), but ideally you would attach while the 41 | * app is not busy. 42 | * - Having a thread detach at arbitrary points is not safe in Dalvik; you need to be sure that 43 | * there is no Java code on the current stack or you run the risk of a crash like: 44 | * ERROR: detaching thread with interp frames (count=18) 45 | * (More detail at https://groups.google.com/forum/#!topic/android-ndk/2H8z5grNqjo) 46 | * ThreadScope won't do a detach if the thread was already attached before the guard is 47 | * instantiated, but there's probably some usage that could trip this up. 48 | * - Newly attached C++ threads only get the bootstrap class loader -- i.e. java language 49 | * classes, not any of our application's classes. This will be different behavior than threads 50 | * that were initiated on the Java side. A workaround is to pass a global reference for a 51 | * class or instance to the new thread; this bypasses the need for the class loader. 52 | * (See http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html#attach_current_thread) 53 | * If you need access to the application's classes, you can use ThreadScope::WithClassLoader. 54 | */ 55 | class FBEXPORT ThreadScope { 56 | public: 57 | ThreadScope(); 58 | ThreadScope(ThreadScope&) = delete; 59 | ThreadScope(ThreadScope&&) = default; 60 | ThreadScope& operator=(ThreadScope&) = delete; 61 | ThreadScope& operator=(ThreadScope&&) = delete; 62 | ~ThreadScope(); 63 | 64 | /** 65 | * This runs the closure in a scope with fbjni's classloader. This should be 66 | * the same classloader as the rest of the application and thus anything 67 | * running in the closure will have access to the same classes as in a normal 68 | * java-create thread. 69 | */ 70 | static void WithClassLoader(std::function&& runnable); 71 | 72 | static void OnLoad(); 73 | private: 74 | bool attachedWithThisScope_; 75 | }; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /lib/fb/include/fb/ProgramLocation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | #include 12 | #include 13 | #include 14 | 15 | namespace facebook { 16 | 17 | #define FROM_HERE facebook::ProgramLocation(__FUNCTION__, __FILE__, __LINE__) 18 | 19 | class ProgramLocation { 20 | public: 21 | ProgramLocation() : m_functionName("Unspecified"), m_fileName("Unspecified"), m_lineNumber(0) {} 22 | 23 | ProgramLocation(const char* functionName, const char* fileName, int line) : 24 | m_functionName(functionName), 25 | m_fileName(fileName), 26 | m_lineNumber(line) 27 | {} 28 | 29 | const char* functionName() const { return m_functionName; } 30 | const char* fileName() const { return m_fileName; } 31 | int lineNumber() const { return m_lineNumber; } 32 | 33 | std::string asFormattedString() const { 34 | std::stringstream str; 35 | str << "Function " << m_functionName << " in file " << m_fileName << ":" << m_lineNumber; 36 | return str.str(); 37 | } 38 | 39 | bool operator==(const ProgramLocation& other) const { 40 | // Assumes that the strings are static 41 | return (m_functionName == other.m_functionName) && (m_fileName == other.m_fileName) && m_lineNumber == other.m_lineNumber; 42 | } 43 | 44 | private: 45 | const char* m_functionName; 46 | const char* m_fileName; 47 | int m_lineNumber; 48 | }; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /lib/fb/include/fb/StaticInitialized.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | #include 12 | #include 13 | 14 | namespace facebook { 15 | 16 | // Class that lets you declare a global but does not add a static constructor 17 | // to the binary. Eventually I'd like to have this auto-initialize in a 18 | // multithreaded environment but for now it's easiest just to use manual 19 | // initialization. 20 | template 21 | class StaticInitialized { 22 | public: 23 | constexpr StaticInitialized() : 24 | m_instance(nullptr) 25 | {} 26 | 27 | template 28 | void initialize(Args&&... arguments) { 29 | FBASSERT(!m_instance); 30 | m_instance = new T(std::forward(arguments)...); 31 | } 32 | 33 | T* operator->() const { 34 | return m_instance; 35 | } 36 | private: 37 | T* m_instance; 38 | }; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /lib/fb/include/fb/ThreadLocal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace facebook { 18 | 19 | /////////////////////////////////////////////////////////////////////////////// 20 | 21 | /** 22 | * A thread-local object is a "global" object within a thread. This is useful 23 | * for writing apartment-threaded code, where nothing is actullay shared 24 | * between different threads (hence no locking) but those variables are not 25 | * on stack in local scope. To use it, just do something like this, 26 | * 27 | * ThreadLocal static_object; 28 | * static_object->data_ = ...; 29 | * static_object->doSomething(); 30 | * 31 | * ThreadLocal static_number; 32 | * int value = *static_number; 33 | * 34 | * So, syntax-wise it's similar to pointers. T can be primitive types, and if 35 | * it's a class, there has to be a default constructor. 36 | */ 37 | template 38 | class ThreadLocal { 39 | public: 40 | /** 41 | * Constructor that has to be called from a thread-neutral place. 42 | */ 43 | ThreadLocal() : 44 | m_key(0), 45 | m_cleanup(OnThreadExit) { 46 | initialize(); 47 | } 48 | 49 | /** 50 | * As above but with a custom cleanup function 51 | */ 52 | typedef void (*CleanupFunction)(void* obj); 53 | explicit ThreadLocal(CleanupFunction cleanup) : 54 | m_key(0), 55 | m_cleanup(cleanup) { 56 | FBASSERT(cleanup); 57 | initialize(); 58 | } 59 | 60 | /** 61 | * Access object's member or method through this operator overload. 62 | */ 63 | T *operator->() const { 64 | return get(); 65 | } 66 | 67 | T &operator*() const { 68 | return *get(); 69 | } 70 | 71 | T *get() const { 72 | return (T*)pthread_getspecific(m_key); 73 | } 74 | 75 | T* release() { 76 | T* obj = get(); 77 | pthread_setspecific(m_key, NULL); 78 | return obj; 79 | } 80 | 81 | void reset(T* other = NULL) { 82 | T* old = (T*)pthread_getspecific(m_key); 83 | if (old != other) { 84 | FBASSERT(m_cleanup); 85 | m_cleanup(old); 86 | pthread_setspecific(m_key, other); 87 | } 88 | } 89 | 90 | private: 91 | void initialize() { 92 | int ret = pthread_key_create(&m_key, m_cleanup); 93 | if (ret != 0) { 94 | const char *msg = "(unknown error)"; 95 | switch (ret) { 96 | case EAGAIN: 97 | msg = "PTHREAD_KEYS_MAX (1024) is exceeded"; 98 | break; 99 | case ENOMEM: 100 | msg = "Out-of-memory"; 101 | break; 102 | } 103 | (void) msg; 104 | FBASSERTMSGF(0, "pthread_key_create failed: %d %s", ret, msg); 105 | } 106 | } 107 | 108 | static void OnThreadExit(void *obj) { 109 | if (NULL != obj) { 110 | delete (T*)obj; 111 | } 112 | } 113 | 114 | pthread_key_t m_key; 115 | CleanupFunction m_cleanup; 116 | }; 117 | 118 | } 119 | -------------------------------------------------------------------------------- /lib/fb/include/fb/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #ifndef FBASSERT_H 11 | #define FBASSERT_H 12 | 13 | #include 14 | 15 | namespace facebook { 16 | #define ENABLE_FBASSERT 1 17 | 18 | #if ENABLE_FBASSERT 19 | #define FBASSERTMSGF(expr, msg, ...) !(expr) ? facebook::assertInternal("Assert (%s:%d): " msg, __FILE__, __LINE__, ##__VA_ARGS__) : (void) 0 20 | #else 21 | #define FBASSERTMSGF(expr, msg, ...) 22 | #endif // ENABLE_FBASSERT 23 | 24 | #define FBASSERT(expr) FBASSERTMSGF(expr, "%s", #expr) 25 | 26 | #define FBCRASH(msg, ...) facebook::assertInternal("Fatal error (%s:%d): " msg, __FILE__, __LINE__, ##__VA_ARGS__) 27 | #define FBUNREACHABLE() facebook::assertInternal("This code should be unreachable (%s:%d)", __FILE__, __LINE__) 28 | 29 | FBEXPORT void assertInternal(const char* formatstr, ...) __attribute__((noreturn)); 30 | 31 | // This allows storing the assert message before the current process terminates due to a crash 32 | typedef void (*AssertHandler)(const char* message); 33 | void setAssertHandler(AssertHandler assertHandler); 34 | 35 | } // namespace facebook 36 | #endif // FBASSERT_H 37 | -------------------------------------------------------------------------------- /lib/fb/include/fb/fbjni.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | -------------------------------------------------------------------------------- /lib/fb/include/fb/fbjni/Boxed.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "CoreClasses.h" 13 | 14 | namespace facebook { 15 | namespace jni { 16 | 17 | namespace detail { 18 | template 19 | struct JPrimitive : JavaClass { 20 | using typename JavaClass::javaobject; 21 | using JavaClass::javaClassStatic; 22 | static local_ref valueOf(jprim val) { 23 | static auto cls = javaClassStatic(); 24 | static auto method = 25 | cls->template getStaticMethod("valueOf"); 26 | return method(cls, val); 27 | } 28 | jprim value() const { 29 | static auto method = 30 | javaClassStatic()->template getMethod(T::kValueMethod); 31 | return method(this->self()); 32 | } 33 | }; 34 | 35 | } // namespace detail 36 | 37 | 38 | #define DEFINE_BOXED_PRIMITIVE(LITTLE, BIG) \ 39 | struct J ## BIG : detail::JPrimitive { \ 40 | static auto constexpr kJavaDescriptor = "Ljava/lang/" #BIG ";"; \ 41 | static auto constexpr kValueMethod = #LITTLE "Value"; \ 42 | j ## LITTLE LITTLE ## Value() const { \ 43 | return value(); \ 44 | } \ 45 | }; \ 46 | inline local_ref autobox(j ## LITTLE val) { \ 47 | return J ## BIG::valueOf(val); \ 48 | } 49 | 50 | DEFINE_BOXED_PRIMITIVE(boolean, Boolean) 51 | DEFINE_BOXED_PRIMITIVE(byte, Byte) 52 | DEFINE_BOXED_PRIMITIVE(char, Character) 53 | DEFINE_BOXED_PRIMITIVE(short, Short) 54 | DEFINE_BOXED_PRIMITIVE(int, Integer) 55 | DEFINE_BOXED_PRIMITIVE(long, Long) 56 | DEFINE_BOXED_PRIMITIVE(float, Float) 57 | DEFINE_BOXED_PRIMITIVE(double, Double) 58 | 59 | #undef DEFINE_BOXED_PRIMITIVE 60 | 61 | inline local_ref autobox(alias_ref val) { 62 | return make_local(val); 63 | } 64 | 65 | }} 66 | 67 | -------------------------------------------------------------------------------- /lib/fb/include/fb/fbjni/ByteBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | #include "CoreClasses.h" 15 | #include "References-forward.h" 16 | 17 | namespace facebook { 18 | namespace jni { 19 | 20 | // JNI's NIO support has some awkward preconditions and error reporting. This 21 | // class provides much more user-friendly access. 22 | class FBEXPORT JByteBuffer : public JavaClass { 23 | public: 24 | static constexpr const char* kJavaDescriptor = "Ljava/nio/ByteBuffer;"; 25 | 26 | static local_ref wrapBytes(uint8_t* data, size_t size); 27 | 28 | bool isDirect(); 29 | 30 | uint8_t* getDirectBytes(); 31 | size_t getDirectSize(); 32 | }; 33 | 34 | }} 35 | -------------------------------------------------------------------------------- /lib/fb/include/fb/fbjni/Common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | /** @file Common.h 11 | * 12 | * Defining the stuff that don't deserve headers of their own... 13 | */ 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #ifdef FBJNI_DEBUG_REFS 25 | # ifdef __ANDROID__ 26 | # include 27 | # else 28 | # include 29 | # endif 30 | #endif 31 | 32 | // If a pending JNI Java exception is found, wraps it in a JniException object and throws it as 33 | // a C++ exception. 34 | #define FACEBOOK_JNI_THROW_PENDING_EXCEPTION() \ 35 | ::facebook::jni::throwPendingJniExceptionAsCppException() 36 | 37 | // If the condition is true, throws a JniException object, which wraps the pending JNI Java 38 | // exception if any. If no pending exception is found, throws a JniException object that wraps a 39 | // RuntimeException throwable.  40 | #define FACEBOOK_JNI_THROW_EXCEPTION_IF(CONDITION) \ 41 | ::facebook::jni::throwCppExceptionIf(CONDITION) 42 | 43 | /// @cond INTERNAL 44 | 45 | namespace facebook { 46 | namespace jni { 47 | 48 | FBEXPORT void throwPendingJniExceptionAsCppException(); 49 | FBEXPORT void throwCppExceptionIf(bool condition); 50 | 51 | [[noreturn]] FBEXPORT void throwNewJavaException(jthrowable); 52 | [[noreturn]] FBEXPORT void throwNewJavaException(const char* throwableName, const char* msg); 53 | template 54 | [[noreturn]] void throwNewJavaException(const char* throwableName, const char* fmt, Args... args); 55 | 56 | 57 | /** 58 | * This needs to be called at library load time, typically in your JNI_OnLoad method. 59 | * 60 | * The intended use is to return the result of initialize() directly 61 | * from JNI_OnLoad and to do nothing else there. Library specific 62 | * initialization code should go in the function passed to initialize 63 | * (which can be, and probably should be, a C++ lambda). This approach 64 | * provides correct error handling and translation errors during 65 | * initialization into Java exceptions when appropriate. 66 | * 67 | * Failure to call this will cause your code to crash in a remarkably 68 | * unhelpful way (typically a segfault) while trying to handle an exception 69 | * which occurs later. 70 | */ 71 | FBEXPORT jint initialize(JavaVM*, std::function&&) noexcept; 72 | 73 | namespace internal { 74 | 75 | /** 76 | * Retrieve a pointer the JNI environment of the current thread. 77 | * 78 | * @pre The current thread must be attached to the VM 79 | */ 80 | inline JNIEnv* getEnv() noexcept { 81 | // TODO(T6594868) Benchmark against raw JNI access 82 | return Environment::current(); 83 | } 84 | 85 | // Define to get extremely verbose logging of references and to enable reference stats 86 | #ifdef FBJNI_DEBUG_REFS 87 | template 88 | inline void dbglog(const char* msg, Args... args) { 89 | # ifdef __ANDROID__ 90 | __android_log_print(ANDROID_LOG_VERBOSE, "fbjni_dbg", msg, args...); 91 | # else 92 | std::fprintf(stderr, msg, args...); 93 | # endif 94 | } 95 | 96 | #else 97 | 98 | template 99 | inline void dbglog(const char*, Args...) { 100 | } 101 | 102 | #endif 103 | 104 | }}} 105 | 106 | /// @endcond 107 | -------------------------------------------------------------------------------- /lib/fb/include/fb/fbjni/Context.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "CoreClasses.h" 13 | #include "File.h" 14 | 15 | namespace facebook { 16 | namespace jni { 17 | 18 | class AContext : public JavaClass { 19 | public: 20 | static constexpr const char* kJavaDescriptor = "Landroid/content/Context;"; 21 | 22 | // Define a method that calls into the represented Java class 23 | local_ref getCacheDir() { 24 | static auto method = getClass()->getMethod("getCacheDir"); 25 | return method(self()); 26 | } 27 | 28 | local_ref getFilesDir() { 29 | static auto method = getClass()->getMethod("getFilesDir"); 30 | return method(self()); 31 | } 32 | }; 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/fb/include/fb/fbjni/File.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "CoreClasses.h" 13 | 14 | namespace facebook { 15 | namespace jni { 16 | 17 | class JFile : public JavaClass { 18 | public: 19 | static constexpr const char* kJavaDescriptor = "Ljava/io/File;"; 20 | 21 | // Define a method that calls into the represented Java class 22 | std::string getAbsolutePath() { 23 | static auto method = getClass()->getMethod("getAbsolutePath"); 24 | return method(self())->toStdString(); 25 | } 26 | 27 | }; 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/fb/include/fb/fbjni/JThread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "CoreClasses.h" 13 | #include "NativeRunnable.h" 14 | 15 | namespace facebook { 16 | namespace jni { 17 | 18 | class JThread : public JavaClass { 19 | public: 20 | static constexpr const char* kJavaDescriptor = "Ljava/lang/Thread;"; 21 | 22 | void start() { 23 | static auto method = javaClassStatic()->getMethod("start"); 24 | method(self()); 25 | } 26 | 27 | void join() { 28 | static auto method = javaClassStatic()->getMethod("join"); 29 | method(self()); 30 | } 31 | 32 | static local_ref create(std::function&& runnable) { 33 | auto jrunnable = JNativeRunnable::newObjectCxxArgs(std::move(runnable)); 34 | return newInstance(static_ref_cast(jrunnable)); 35 | } 36 | }; 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lib/fb/include/fb/fbjni/Meta-forward.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | namespace facebook { 13 | namespace jni { 14 | 15 | template 16 | class JMethod; 17 | template 18 | class JStaticMethod; 19 | template 20 | class JNonvirtualMethod; 21 | template 22 | struct JConstructor; 23 | template 24 | class JField; 25 | template 26 | class JStaticField; 27 | 28 | /// Type traits for Java types (currently providing Java type descriptors) 29 | template 30 | struct jtype_traits; 31 | 32 | /// Type traits for Java methods (currently providing Java type descriptors) 33 | template 34 | struct jmethod_traits; 35 | 36 | }} 37 | -------------------------------------------------------------------------------- /lib/fb/include/fb/fbjni/MetaConvert.h: -------------------------------------------------------------------------------- 1 | // Copyright 2004-present Facebook. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include "Common.h" 8 | #include "References.h" 9 | 10 | namespace facebook { 11 | namespace jni { 12 | 13 | namespace detail { 14 | 15 | // In order to avoid potentially filling the jni locals table, 16 | // temporary objects (right now, this is just jstrings) need to be 17 | // released. This is done by returning a holder which autoconverts to 18 | // jstring. 19 | template 20 | inline T callToJni(T&& t) { 21 | return t; 22 | } 23 | 24 | template 25 | inline JniType callToJni(local_ref&& sref) { 26 | return sref.get(); 27 | } 28 | 29 | // Normally, pass through types unmolested. 30 | template 31 | struct Convert { 32 | typedef T jniType; 33 | static jniType fromJni(jniType t) { 34 | return t; 35 | } 36 | static jniType toJniRet(jniType t) { 37 | return t; 38 | } 39 | static jniType toCall(jniType t) { 40 | return t; 41 | } 42 | }; 43 | 44 | // This is needed for return conversion 45 | template <> 46 | struct Convert { 47 | typedef void jniType; 48 | }; 49 | 50 | // jboolean is an unsigned char, not a bool. Allow it to work either way. 51 | template<> 52 | struct Convert { 53 | typedef jboolean jniType; 54 | static bool fromJni(jniType t) { 55 | return t; 56 | } 57 | static jniType toJniRet(bool t) { 58 | return t; 59 | } 60 | static jniType toCall(bool t) { 61 | return t; 62 | } 63 | }; 64 | 65 | // convert to alias_ref from T 66 | template 67 | struct Convert> { 68 | typedef JniType jniType; 69 | static alias_ref fromJni(jniType t) { 70 | return wrap_alias(t); 71 | } 72 | static jniType toJniRet(alias_ref t) { 73 | return t.get(); 74 | } 75 | static jniType toCall(alias_ref t) { 76 | return t.get(); 77 | } 78 | }; 79 | 80 | // convert return from local_ref 81 | template 82 | struct Convert> { 83 | typedef JniType jniType; 84 | // No automatic synthesis of local_ref 85 | static jniType toJniRet(local_ref t) { 86 | return t.release(); 87 | } 88 | static jniType toCall(local_ref t) { 89 | return t.get(); 90 | } 91 | }; 92 | 93 | // convert return from global_ref 94 | template 95 | struct Convert> { 96 | typedef JniType jniType; 97 | // No automatic synthesis of global_ref 98 | static jniType toJniRet(global_ref t) { 99 | return t.get(); 100 | } 101 | static jniType toCall(global_ref t) { 102 | return t.get(); 103 | } 104 | }; 105 | 106 | template struct jni_sig_from_cxx_t; 107 | template 108 | struct jni_sig_from_cxx_t { 109 | using JniRet = typename Convert::type>::jniType; 110 | using JniSig = JniRet(typename Convert::type>::jniType...); 111 | }; 112 | 113 | template 114 | using jni_sig_from_cxx = typename jni_sig_from_cxx_t::JniSig; 115 | 116 | } // namespace detail 117 | 118 | template 119 | struct jmethod_traits_from_cxx : jmethod_traits> { 120 | }; 121 | 122 | }} 123 | -------------------------------------------------------------------------------- /lib/fb/include/fb/fbjni/NativeRunnable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "CoreClasses.h" 13 | #include "Hybrid.h" 14 | #include "Registration.h" 15 | 16 | #include 17 | 18 | namespace facebook { 19 | namespace jni { 20 | 21 | struct JRunnable : public JavaClass { 22 | static auto constexpr kJavaDescriptor = "Ljava/lang/Runnable;"; 23 | }; 24 | 25 | struct JNativeRunnable : public HybridClass { 26 | public: 27 | static auto constexpr kJavaDescriptor = "Lcom/facebook/jni/NativeRunnable;"; 28 | 29 | JNativeRunnable(std::function&& runnable) : runnable_(std::move(runnable)) {} 30 | 31 | static void OnLoad() { 32 | registerHybrid({ 33 | makeNativeMethod("run", JNativeRunnable::run), 34 | }); 35 | } 36 | 37 | void run() { 38 | runnable_(); 39 | } 40 | 41 | private: 42 | std::function runnable_; 43 | }; 44 | 45 | 46 | } // namespace jni 47 | } // namespace facebook 48 | -------------------------------------------------------------------------------- /lib/fb/include/fb/fbjni/ReferenceAllocators.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | /** 11 | * @file ReferenceAllocators.h 12 | * 13 | * Reference allocators are used to create and delete various classes of JNI references (local, 14 | * global, and weak global). 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "Common.h" 22 | 23 | namespace facebook { namespace jni { 24 | 25 | /// Allocator that handles local references 26 | class FBEXPORT LocalReferenceAllocator { 27 | public: 28 | jobject newReference(jobject original) const; 29 | void deleteReference(jobject reference) const noexcept; 30 | bool verifyReference(jobject reference) const noexcept; 31 | }; 32 | 33 | /// Allocator that handles global references 34 | class FBEXPORT GlobalReferenceAllocator { 35 | public: 36 | jobject newReference(jobject original) const; 37 | void deleteReference(jobject reference) const noexcept; 38 | bool verifyReference(jobject reference) const noexcept; 39 | }; 40 | 41 | /// Allocator that handles weak global references 42 | class FBEXPORT WeakGlobalReferenceAllocator { 43 | public: 44 | jobject newReference(jobject original) const; 45 | void deleteReference(jobject reference) const noexcept; 46 | bool verifyReference(jobject reference) const noexcept; 47 | }; 48 | 49 | /// @cond INTERNAL 50 | namespace internal { 51 | 52 | /** 53 | * @return true iff env->GetObjectRefType is expected to work properly. 54 | */ 55 | FBEXPORT bool doesGetObjectRefTypeWork(); 56 | 57 | } 58 | /// @endcond 59 | 60 | }} 61 | 62 | #include "ReferenceAllocators-inl.h" 63 | -------------------------------------------------------------------------------- /lib/fb/include/fb/fbjni/References-forward.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "ReferenceAllocators.h" 13 | 14 | namespace facebook { 15 | namespace jni { 16 | 17 | template 18 | class JObjectWrapper; 19 | 20 | namespace detail { 21 | struct JObjectBase { 22 | jobject get() const noexcept; 23 | void set(jobject reference) noexcept; 24 | jobject this_; 25 | }; 26 | 27 | // RefReprType maps a type to the representation used by fbjni smart references. 28 | template 29 | struct RefReprType; 30 | 31 | template 32 | struct JavaObjectType; 33 | 34 | template 35 | struct ReprAccess; 36 | } 37 | 38 | // Given T, either a jobject-like type or a JavaClass-derived type, ReprType 39 | // is the corresponding JavaClass-derived type and JniType is the 40 | // jobject-like type. 41 | template 42 | using ReprType = typename detail::RefReprType::type; 43 | 44 | template 45 | using JniType = typename detail::JavaObjectType::type; 46 | 47 | template 48 | class base_owned_ref; 49 | 50 | template 51 | class basic_strong_ref; 52 | 53 | template 54 | class weak_ref; 55 | 56 | template 57 | class alias_ref; 58 | 59 | /// A smart unique reference owning a local JNI reference 60 | template 61 | using local_ref = basic_strong_ref; 62 | 63 | /// A smart unique reference owning a global JNI reference 64 | template 65 | using global_ref = basic_strong_ref; 66 | 67 | }} // namespace facebook::jni 68 | -------------------------------------------------------------------------------- /lib/fb/include/fb/noncopyable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | namespace facebook { 13 | 14 | struct noncopyable { 15 | noncopyable(const noncopyable&) = delete; 16 | noncopyable& operator=(const noncopyable&) = delete; 17 | protected: 18 | noncopyable() = default; 19 | }; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /lib/fb/include/fb/nonmovable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | namespace facebook { 13 | 14 | struct nonmovable { 15 | nonmovable(nonmovable&&) = delete; 16 | nonmovable& operator=(nonmovable&&) = delete; 17 | protected: 18 | nonmovable() = default; 19 | }; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /lib/fb/include/fb/visibility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #define FBEXPORT __attribute__((visibility("default"))) 13 | -------------------------------------------------------------------------------- /lib/fb/include/jni/Countable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | namespace facebook { 19 | namespace jni { 20 | 21 | FBEXPORT const RefPtr& countableFromJava(JNIEnv* env, jobject obj); 22 | 23 | template RefPtr extractRefPtr(JNIEnv* env, jobject obj) { 24 | return static_cast>(countableFromJava(env, obj)); 25 | } 26 | 27 | template RefPtr extractPossiblyNullRefPtr(JNIEnv* env, jobject obj) { 28 | return obj ? extractRefPtr(env, obj) : nullptr; 29 | } 30 | 31 | FBEXPORT void setCountableForJava(JNIEnv* env, jobject obj, RefPtr&& countable); 32 | 33 | void CountableOnLoad(JNIEnv* env); 34 | 35 | } } 36 | 37 | -------------------------------------------------------------------------------- /lib/fb/include/jni/GlobalReference.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | 19 | namespace facebook { namespace jni { 20 | 21 | template 22 | class GlobalReference { 23 | static_assert(std::is_convertible::value, 24 | "GlobalReference instantiated with type that is not " 25 | "convertible to jobject"); 26 | 27 | public: 28 | explicit GlobalReference(T globalReference) : 29 | reference_(globalReference? Environment::current()->NewGlobalRef(globalReference) : nullptr) { 30 | } 31 | 32 | ~GlobalReference() { 33 | reset(); 34 | } 35 | 36 | GlobalReference() : 37 | reference_(nullptr) { 38 | } 39 | 40 | // enable move constructor and assignment 41 | GlobalReference(GlobalReference&& rhs) : 42 | reference_(std::move(rhs.reference_)) { 43 | rhs.reference_ = nullptr; 44 | } 45 | 46 | GlobalReference& operator=(GlobalReference&& rhs) { 47 | if (this != &rhs) { 48 | reset(); 49 | reference_ = std::move(rhs.reference_); 50 | rhs.reference_ = nullptr; 51 | } 52 | return *this; 53 | } 54 | 55 | GlobalReference(const GlobalReference& rhs) : 56 | reference_{} { 57 | reset(rhs.get()); 58 | } 59 | 60 | GlobalReference& operator=(const GlobalReference& rhs) { 61 | if (this == &rhs) { 62 | return *this; 63 | } 64 | reset(rhs.get()); 65 | return *this; 66 | } 67 | 68 | explicit operator bool() const { 69 | return (reference_ != nullptr); 70 | } 71 | 72 | T get() const { 73 | return reinterpret_cast(reference_); 74 | } 75 | 76 | void reset(T globalReference = nullptr) { 77 | if (reference_) { 78 | Environment::current()->DeleteGlobalRef(reference_); 79 | } 80 | if (globalReference) { 81 | reference_ = Environment::current()->NewGlobalRef(globalReference); 82 | } else { 83 | reference_ = nullptr; 84 | } 85 | } 86 | 87 | private: 88 | jobject reference_; 89 | }; 90 | 91 | }} 92 | -------------------------------------------------------------------------------- /lib/fb/include/jni/LocalReference.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | 19 | namespace facebook { 20 | namespace jni { 21 | 22 | template 23 | struct LocalReferenceDeleter { 24 | static_assert(std::is_convertible::value, 25 | "LocalReferenceDeleter instantiated with type that is not convertible to jobject"); 26 | void operator()(T localReference) { 27 | if (localReference != nullptr) { 28 | Environment::current()->DeleteLocalRef(localReference); 29 | } 30 | } 31 | }; 32 | 33 | template 34 | using LocalReference = 35 | std::unique_ptr::type, LocalReferenceDeleter>; 36 | 37 | } } 38 | -------------------------------------------------------------------------------- /lib/fb/include/jni/LocalString.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace facebook { 19 | namespace jni { 20 | 21 | namespace detail { 22 | 23 | void utf8ToModifiedUTF8(const uint8_t* bytes, size_t len, uint8_t* modified, size_t modifiedLength); 24 | size_t modifiedLength(const std::string& str); 25 | size_t modifiedLength(const uint8_t* str, size_t* length); 26 | std::string modifiedUTF8ToUTF8(const uint8_t* modified, size_t len) noexcept; 27 | std::string utf16toUTF8(const uint16_t* utf16Bytes, size_t len) noexcept; 28 | 29 | } 30 | 31 | // JNI represents strings encoded with modified version of UTF-8. The difference between UTF-8 and 32 | // Modified UTF-8 is that the latter support only 1-byte, 2-byte, and 3-byte formats. Supplementary 33 | // character (4 bytes in unicode) needs to be represented in the form of surrogate pairs. To create 34 | // a Modified UTF-8 surrogate pair that Dalvik would understand we take 4-byte unicode character, 35 | // encode it with UTF-16 which gives us two 2 byte chars (surrogate pair) and then we encode each 36 | // pair as UTF-8. This result in 2 x 3 byte characters. To convert modified UTF-8 to standard 37 | // UTF-8, this mus tbe reversed. 38 | // 39 | // The second difference is that Modified UTF-8 is encoding NUL byte in 2-byte format. 40 | // 41 | // In order to avoid complex error handling, only a minimum of validity checking is done to avoid 42 | // crashing. If the input is invalid, the output may be invalid as well. 43 | // 44 | // Relevant links: 45 | // - http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html 46 | // - https://docs.oracle.com/javase/6/docs/api/java/io/DataInput.html#modified-utf-8 47 | 48 | class FBEXPORT LocalString { 49 | public: 50 | // Assumes UTF8 encoding and make a required convertion to modified UTF-8 when the string 51 | // contains unicode supplementary characters. 52 | explicit LocalString(const std::string& str); 53 | explicit LocalString(const char* str); 54 | jstring string() const { 55 | return m_string; 56 | } 57 | ~LocalString(); 58 | private: 59 | jstring m_string; 60 | }; 61 | 62 | // JString to UTF16 extractor using RAII idiom 63 | class JStringUtf16Extractor { 64 | public: 65 | JStringUtf16Extractor(JNIEnv* env, jstring javaString) 66 | : env_(env) 67 | , javaString_(javaString) 68 | , utf16String_(nullptr) { 69 | if (env_ && javaString_) { 70 | utf16String_ = env_->GetStringCritical(javaString_, nullptr); 71 | } 72 | } 73 | 74 | ~JStringUtf16Extractor() { 75 | if (utf16String_) { 76 | env_->ReleaseStringCritical(javaString_, utf16String_); 77 | } 78 | } 79 | 80 | operator const jchar* () const { 81 | return utf16String_; 82 | } 83 | 84 | private: 85 | JNIEnv* env_; 86 | jstring javaString_; 87 | const jchar* utf16String_; 88 | }; 89 | 90 | // The string from JNI is converted to standard UTF-8 if the string contains supplementary 91 | // characters. 92 | FBEXPORT std::string fromJString(JNIEnv* env, jstring str); 93 | 94 | } } 95 | -------------------------------------------------------------------------------- /lib/fb/include/jni/Registration.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | #include 12 | #include 13 | #include 14 | 15 | namespace facebook { 16 | namespace jni { 17 | 18 | static inline void registerNatives(JNIEnv* env, jclass cls, std::initializer_list methods) { 19 | auto result = env->RegisterNatives(cls, methods.begin(), methods.size()); 20 | FBASSERT(result == 0); 21 | } 22 | 23 | static inline void registerNatives(JNIEnv* env, const char* cls, std::initializer_list list) { 24 | registerNatives(env, env->FindClass(cls), list); 25 | } 26 | 27 | } } 28 | -------------------------------------------------------------------------------- /lib/fb/include/jni/WeakReference.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | namespace facebook { 19 | namespace jni { 20 | 21 | class FBEXPORT WeakReference : public Countable { 22 | public: 23 | typedef RefPtr Ptr; 24 | WeakReference(jobject strongRef); 25 | ~WeakReference(); 26 | jweak weakRef() { 27 | return m_weakReference; 28 | } 29 | 30 | private: 31 | jweak m_weakReference; 32 | }; 33 | 34 | // This class is intended to take a weak reference and turn it into a strong 35 | // local reference. Consequently, it should only be allocated on the stack. 36 | class FBEXPORT ResolvedWeakReference : public noncopyable { 37 | public: 38 | ResolvedWeakReference(jobject weakRef); 39 | ResolvedWeakReference(const RefPtr& weakRef); 40 | ~ResolvedWeakReference(); 41 | 42 | operator jobject () { 43 | return m_strongReference; 44 | } 45 | 46 | explicit operator bool () { 47 | return m_strongReference != nullptr; 48 | } 49 | 50 | private: 51 | jobject m_strongReference; 52 | }; 53 | 54 | } } 55 | 56 | -------------------------------------------------------------------------------- /lib/fb/jni/ByteBuffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace facebook { 17 | namespace jni { 18 | 19 | namespace { 20 | local_ref createEmpty() { 21 | static auto cls = JByteBuffer::javaClassStatic(); 22 | static auto meth = cls->getStaticMethod("allocateDirect"); 23 | return meth(cls, 0); 24 | } 25 | } 26 | 27 | local_ref JByteBuffer::wrapBytes(uint8_t* data, size_t size) { 28 | // env->NewDirectByteBuffer requires that size is positive. Android's 29 | // dalvik returns an invalid result and Android's art aborts if size == 0. 30 | // Workaround this by using a slow path through Java in that case. 31 | if (!size) { 32 | return createEmpty(); 33 | } 34 | auto res = adopt_local(static_cast(Environment::current()->NewDirectByteBuffer(data, size))); 35 | FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); 36 | if (!res) { 37 | throw std::runtime_error("Direct byte buffers are unsupported."); 38 | } 39 | return res; 40 | } 41 | 42 | uint8_t* JByteBuffer::getDirectBytes() { 43 | if (!self()) { 44 | throwNewJavaException("java/lang/NullPointerException", "java.lang.NullPointerException"); 45 | } 46 | void* bytes = Environment::current()->GetDirectBufferAddress(self()); 47 | FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); 48 | if (!bytes) { 49 | throw std::runtime_error( 50 | isDirect() ? 51 | "Attempt to get direct bytes of non-direct byte buffer." : 52 | "Error getting direct bytes of byte buffer."); 53 | } 54 | return static_cast(bytes); 55 | } 56 | 57 | size_t JByteBuffer::getDirectSize() { 58 | if (!self()) { 59 | throwNewJavaException("java/lang/NullPointerException", "java.lang.NullPointerException"); 60 | } 61 | int size = Environment::current()->GetDirectBufferCapacity(self()); 62 | FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); 63 | if (size < 0) { 64 | throw std::runtime_error( 65 | isDirect() ? 66 | "Attempt to get direct size of non-direct byte buffer." : 67 | "Error getting direct size of byte buffer."); 68 | } 69 | return static_cast(size); 70 | } 71 | 72 | bool JByteBuffer::isDirect() { 73 | static auto meth = javaClassStatic()->getMethod("isDirect"); 74 | return meth(self()); 75 | } 76 | 77 | }} 78 | -------------------------------------------------------------------------------- /lib/fb/jni/Countable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace facebook { 16 | namespace jni { 17 | 18 | static jfieldID gCountableNativePtr; 19 | 20 | static RefPtr* rawCountableFromJava(JNIEnv* env, jobject obj) { 21 | FBASSERT(obj); 22 | return reinterpret_cast*>(env->GetLongField(obj, gCountableNativePtr)); 23 | } 24 | 25 | const RefPtr& countableFromJava(JNIEnv* env, jobject obj) { 26 | FBASSERT(obj); 27 | return *rawCountableFromJava(env, obj); 28 | } 29 | 30 | void setCountableForJava(JNIEnv* env, jobject obj, RefPtr&& countable) { 31 | int oldValue = env->GetLongField(obj, gCountableNativePtr); 32 | FBASSERTMSGF(oldValue == 0, "Cannot reinitialize object; expected nullptr, got %x", oldValue); 33 | 34 | FBASSERT(countable); 35 | uintptr_t fieldValue = (uintptr_t) new RefPtr(std::move(countable)); 36 | env->SetLongField(obj, gCountableNativePtr, fieldValue); 37 | } 38 | 39 | /** 40 | * NB: THREAD SAFETY (this comment also exists at Countable.java) 41 | * 42 | * This method deletes the corresponding native object on whatever thread the method is called 43 | * on. In the common case when this is called by Countable#finalize(), this will be called on the 44 | * system finalizer thread. If you manually call dispose on the Java object, the native object 45 | * will be deleted synchronously on that thread. 46 | */ 47 | void dispose(JNIEnv* env, jobject obj) { 48 | // Grab the pointer 49 | RefPtr* countable = rawCountableFromJava(env, obj); 50 | if (!countable) { 51 | // That was easy. 52 | return; 53 | } 54 | 55 | // Clear out the old value to avoid double-frees 56 | env->SetLongField(obj, gCountableNativePtr, 0); 57 | 58 | delete countable; 59 | } 60 | 61 | void CountableOnLoad(JNIEnv* env) { 62 | jclass countable = env->FindClass("com/facebook/jni/Countable"); 63 | gCountableNativePtr = env->GetFieldID(countable, "mInstance", "J"); 64 | registerNatives(env, countable, { 65 | { "dispose", "()V", (void*) dispose }, 66 | }); 67 | } 68 | 69 | } } 70 | -------------------------------------------------------------------------------- /lib/fb/jni/Hybrid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include "fb/fbjni.h" 11 | 12 | 13 | namespace facebook { 14 | namespace jni { 15 | 16 | namespace detail { 17 | 18 | void HybridData::setNativePointer(std::unique_ptr new_value) { 19 | static auto pointerField = getClass()->getField("mNativePointer"); 20 | auto* old_value = reinterpret_cast(getFieldValue(pointerField)); 21 | if (new_value) { 22 | // Modify should only ever be called once with a non-null 23 | // new_value. If this happens again it's a programmer error, so 24 | // blow up. 25 | FBASSERTMSGF(old_value == 0, "Attempt to set C++ native pointer twice"); 26 | } else if (old_value == 0) { 27 | return; 28 | } 29 | // delete on a null pointer is defined to be a noop. 30 | delete old_value; 31 | // This releases ownership from the unique_ptr, and passes the pointer, and 32 | // ownership of it, to HybridData which is managed by the java GC. The 33 | // finalizer on hybridData calls resetNative which will delete the object, if 34 | // resetNative has not already been called. 35 | setFieldValue(pointerField, reinterpret_cast(new_value.release())); 36 | } 37 | 38 | BaseHybridClass* HybridData::getNativePointer() { 39 | static auto pointerField = getClass()->getField("mNativePointer"); 40 | auto* value = reinterpret_cast(getFieldValue(pointerField)); 41 | if (!value) { 42 | throwNewJavaException("java/lang/NullPointerException", "java.lang.NullPointerException"); 43 | } 44 | return value; 45 | } 46 | 47 | local_ref HybridData::create() { 48 | return newInstance(); 49 | } 50 | 51 | } 52 | 53 | namespace { 54 | void resetNative(alias_ref jthis) { 55 | jthis->setNativePointer(nullptr); 56 | } 57 | } 58 | 59 | void HybridDataOnLoad() { 60 | registerNatives("com/facebook/jni/HybridData", { 61 | makeNativeMethod("resetNative", resetNative), 62 | }); 63 | } 64 | 65 | }} 66 | -------------------------------------------------------------------------------- /lib/fb/jni/OnLoad.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace facebook::jni; 16 | 17 | void initialize_fbjni() { 18 | CountableOnLoad(Environment::current()); 19 | HybridDataOnLoad(); 20 | JNativeRunnable::OnLoad(); 21 | ThreadScope::OnLoad(); 22 | } 23 | -------------------------------------------------------------------------------- /lib/fb/jni/References.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | 12 | namespace facebook { 13 | namespace jni { 14 | 15 | JniLocalScope::JniLocalScope(JNIEnv* env, jint capacity) 16 | : env_(env) { 17 | hasFrame_ = false; 18 | auto pushResult = env->PushLocalFrame(capacity); 19 | FACEBOOK_JNI_THROW_EXCEPTION_IF(pushResult < 0); 20 | hasFrame_ = true; 21 | } 22 | 23 | JniLocalScope::~JniLocalScope() { 24 | if (hasFrame_) { 25 | env_->PopLocalFrame(nullptr); 26 | } 27 | } 28 | 29 | namespace internal { 30 | 31 | // Default implementation always returns true. 32 | // Platform-specific sources can override this. 33 | bool doesGetObjectRefTypeWork() __attribute__ ((weak)); 34 | bool doesGetObjectRefTypeWork() { 35 | return true; 36 | } 37 | 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lib/fb/jni/WeakReference.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | namespace facebook { 14 | namespace jni { 15 | 16 | WeakReference::WeakReference(jobject strongRef) : 17 | m_weakReference(Environment::current()->NewWeakGlobalRef(strongRef)) 18 | { 19 | } 20 | 21 | WeakReference::~WeakReference() { 22 | auto env = Environment::current(); 23 | FBASSERTMSGF(env, "Attempt to delete jni::WeakReference from non-JNI thread"); 24 | env->DeleteWeakGlobalRef(m_weakReference); 25 | } 26 | 27 | ResolvedWeakReference::ResolvedWeakReference(jobject weakRef) : 28 | m_strongReference(Environment::current()->NewLocalRef(weakRef)) 29 | { 30 | } 31 | 32 | ResolvedWeakReference::ResolvedWeakReference(const RefPtr& weakRef) : 33 | m_strongReference(Environment::current()->NewLocalRef(weakRef->weakRef())) 34 | { 35 | } 36 | 37 | ResolvedWeakReference::~ResolvedWeakReference() { 38 | if (m_strongReference) 39 | Environment::current()->DeleteLocalRef(m_strongReference); 40 | } 41 | 42 | } } 43 | 44 | -------------------------------------------------------------------------------- /lib/fb/jni/java/CppException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.jni; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public class CppException extends RuntimeException { 16 | @DoNotStrip 17 | public CppException(String message) { 18 | super(message); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/fb/jni/java/CppSystemErrorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.jni; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public class CppSystemErrorException extends CppException { 16 | int errorCode; 17 | 18 | @DoNotStrip 19 | public CppSystemErrorException(String message, int errorCode) { 20 | super(message); 21 | this.errorCode = errorCode; 22 | } 23 | 24 | public int getErrorCode() { 25 | return errorCode; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/fb/jni/java/UnknownCppException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | package com.facebook.jni; 11 | 12 | import com.facebook.proguard.annotations.DoNotStrip; 13 | 14 | @DoNotStrip 15 | public class UnknownCppException extends CppException { 16 | @DoNotStrip 17 | public UnknownCppException() { 18 | super("Unknown"); 19 | } 20 | 21 | @DoNotStrip 22 | public UnknownCppException(String message) { 23 | super(message); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/fb/log.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #define LOG_BUFFER_SIZE 4096 16 | static LogHandler gLogHandler; 17 | 18 | void setLogHandler(LogHandler logHandler) { 19 | gLogHandler = logHandler; 20 | } 21 | 22 | int fb_printLog(int prio, const char *tag, const char *fmt, ...) { 23 | char logBuffer[LOG_BUFFER_SIZE]; 24 | 25 | va_list va_args; 26 | va_start(va_args, fmt); 27 | int result = vsnprintf(logBuffer, sizeof(logBuffer), fmt, va_args); 28 | va_end(va_args); 29 | if (gLogHandler != NULL) { 30 | gLogHandler(prio, tag, logBuffer); 31 | } 32 | __android_log_write(prio, tag, logBuffer); 33 | return result; 34 | } 35 | 36 | void logPrintByDelims(int priority, const char* tag, const char* delims, 37 | const char* msg, ...) 38 | { 39 | va_list ap; 40 | char buf[32768]; 41 | char* context; 42 | char* tok; 43 | 44 | va_start(ap, msg); 45 | vsnprintf(buf, sizeof(buf), msg, ap); 46 | va_end(ap); 47 | 48 | tok = strtok_r(buf, delims, &context); 49 | 50 | if (!tok) { 51 | return; 52 | } 53 | 54 | do { 55 | __android_log_write(priority, tag, tok); 56 | } while ((tok = strtok_r(NULL, delims, &context))); 57 | } 58 | 59 | #ifndef ANDROID 60 | 61 | // Implementations of the basic android logging functions for non-android platforms. 62 | 63 | static char logTagChar(int prio) { 64 | switch (prio) { 65 | default: 66 | case ANDROID_LOG_UNKNOWN: 67 | case ANDROID_LOG_DEFAULT: 68 | case ANDROID_LOG_SILENT: 69 | return ' '; 70 | case ANDROID_LOG_VERBOSE: 71 | return 'V'; 72 | case ANDROID_LOG_DEBUG: 73 | return 'D'; 74 | case ANDROID_LOG_INFO: 75 | return 'I'; 76 | case ANDROID_LOG_WARN: 77 | return 'W'; 78 | case ANDROID_LOG_ERROR: 79 | return 'E'; 80 | case ANDROID_LOG_FATAL: 81 | return 'F'; 82 | } 83 | } 84 | 85 | int __android_log_write(int prio, const char *tag, const char *text) { 86 | return fprintf(stderr, "[%c/%.16s] %s\n", logTagChar(prio), tag, text); 87 | } 88 | 89 | int __android_log_print(int prio, const char *tag, const char *fmt, ...) { 90 | va_list ap; 91 | va_start(ap, fmt); 92 | 93 | int res = fprintf(stderr, "[%c/%.16s] ", logTagChar(prio), tag); 94 | res += vfprintf(stderr, "%s\n", ap); 95 | 96 | va_end(ap); 97 | return res; 98 | } 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /lib/fb/lyra/lyra.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2004-present Facebook. All Rights Reserved. 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | namespace facebook { 15 | namespace lyra { 16 | 17 | namespace { 18 | 19 | class IosFlagsSaver { 20 | ios_base& ios_; 21 | ios_base::fmtflags flags_; 22 | 23 | public: 24 | IosFlagsSaver(ios_base& ios) 25 | : ios_(ios), 26 | flags_(ios.flags()) 27 | {} 28 | 29 | ~IosFlagsSaver() { 30 | ios_.flags(flags_); 31 | } 32 | }; 33 | 34 | struct BacktraceState { 35 | size_t skip; 36 | vector& stackTrace; 37 | }; 38 | 39 | _Unwind_Reason_Code unwindCallback(struct _Unwind_Context* context, void* arg) { 40 | BacktraceState* state = reinterpret_cast(arg); 41 | auto absoluteProgramCounter = 42 | reinterpret_cast(_Unwind_GetIP(context)); 43 | 44 | if (state->skip > 0) { 45 | --state->skip; 46 | return _URC_NO_REASON; 47 | } 48 | 49 | if (state->stackTrace.size() == state->stackTrace.capacity()) { 50 | return _URC_END_OF_STACK; 51 | } 52 | 53 | state->stackTrace.push_back(absoluteProgramCounter); 54 | 55 | return _URC_NO_REASON; 56 | } 57 | 58 | void captureBacktrace(size_t skip, vector& stackTrace) { 59 | // Beware of a bug on some platforms, which makes the trace loop until the 60 | // buffer is full when it reaches a noexcept function. It seems to be fixed in 61 | // newer versions of gcc. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56846 62 | // TODO(t10738439): Investigate workaround for the stack trace bug 63 | BacktraceState state = {skip, stackTrace}; 64 | _Unwind_Backtrace(unwindCallback, &state); 65 | } 66 | } 67 | 68 | void getStackTrace(vector& stackTrace, size_t skip) { 69 | stackTrace.clear(); 70 | captureBacktrace(skip + 1, stackTrace); 71 | } 72 | 73 | // TODO(t10737622): Improve on-device symbolification 74 | void getStackTraceSymbols(vector& symbols, 75 | const vector& trace) { 76 | symbols.clear(); 77 | symbols.reserve(trace.size()); 78 | 79 | for (size_t i = 0; i < trace.size(); ++i) { 80 | Dl_info info; 81 | if (dladdr(trace[i], &info)) { 82 | symbols.emplace_back(trace[i], info.dli_fbase, info.dli_saddr, 83 | info.dli_fname ? info.dli_fname : "", 84 | info.dli_sname ? info.dli_sname : ""); 85 | } 86 | } 87 | } 88 | 89 | ostream& operator<<(ostream& out, const StackTraceElement& elm) { 90 | IosFlagsSaver flags{out}; 91 | 92 | // TODO(t10748683): Add build id to the output 93 | out << "{dso=" << elm.libraryName() << " offset=" << hex 94 | << showbase << elm.libraryOffset(); 95 | 96 | if (!elm.functionName().empty()) { 97 | out << " func=" << elm.functionName() << "()+" << elm.functionOffset(); 98 | } 99 | 100 | out << " build-id=" << hex << setw(8) << 0 101 | << "}"; 102 | 103 | return out; 104 | } 105 | 106 | // TODO(t10737667): The implement a tool that parse the stack trace and 107 | // symbolicate it 108 | ostream& operator<<(ostream& out, const vector& trace) { 109 | IosFlagsSaver flags{out}; 110 | 111 | auto i = 0; 112 | out << "Backtrace:\n"; 113 | for (auto& elm : trace) { 114 | out << " #" << dec << setfill('0') << setw(2) << i++ << " " << elm << '\n'; 115 | } 116 | 117 | return out; 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /lib/fb/onload.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | #ifndef DISABLE_CPUCAP 12 | #include 13 | #endif 14 | #include 15 | 16 | using namespace facebook::jni; 17 | 18 | void initialize_xplatinit(); 19 | void initialize_fbjni(); 20 | 21 | JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { 22 | return facebook::jni::initialize(vm, [] { 23 | initialize_fbjni(); 24 | #ifndef DISABLE_XPLAT 25 | initialize_xplatinit(); 26 | #endif 27 | #ifndef DISABLE_CPUCAP 28 | initialize_cpucapabilities(); 29 | #endif 30 | }); 31 | } 32 | -------------------------------------------------------------------------------- /lib/gtest/BUCK: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | include_defs('//YOGA_DEFS') 9 | 10 | COMPILER_FLAGS = [ 11 | '-std=c++11', 12 | '-Wno-missing-prototypes', 13 | ] 14 | 15 | cxx_library( 16 | name = 'gtest', 17 | srcs = glob(['googletest/googletest/src/*.cc']), 18 | exported_headers = subdir_glob([ 19 | ('googletest/googletest/include', '**/*.h'), 20 | ('googletest/googletest', 'src/*.h'), 21 | ('googletest/googletest', 'src/*.cc'), 22 | ]), 23 | header_namespace = '', 24 | compiler_flags = COMPILER_FLAGS, 25 | deps = [], 26 | visibility = [CSSLAYOUT_ROOT], 27 | ) 28 | -------------------------------------------------------------------------------- /lib/infer-annotations/BUCK: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | include_defs('//YOGA_DEFS') 9 | 10 | prebuilt_jar( 11 | name = 'infer-annotations-jar', 12 | binary_jar = 'infer-annotations-1.4.jar', 13 | ) 14 | 15 | java_library( 16 | name = 'infer-annotations', 17 | exported_deps = [ 18 | ':infer-annotations-jar', 19 | ], 20 | visibility = [CSSLAYOUT_ROOT], 21 | ) 22 | -------------------------------------------------------------------------------- /lib/infer-annotations/infer-annotations-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/css-layout/6e56ce21135da6724b827d23fb53dd42b5338048/lib/infer-annotations/infer-annotations-1.4.jar -------------------------------------------------------------------------------- /lib/jni/BUCK: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | cxx_library( 9 | name = 'jni', 10 | force_static = True, 11 | header_namespace = '', 12 | exported_headers = [ 13 | 'jni.h', 14 | 'real/jni.h', 15 | ], 16 | visibility = ['PUBLIC'], 17 | ) 18 | -------------------------------------------------------------------------------- /lib/jni/jni.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #pragma once 11 | 12 | #ifdef __ANDROID__ 13 | #include_next 14 | #else 15 | #include "real/jni.h" 16 | #endif 17 | -------------------------------------------------------------------------------- /lib/jsr-305/BUCK: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | include_defs('//YOGA_DEFS') 9 | 10 | prebuilt_jar( 11 | name = 'jsr305-jar', 12 | binary_jar = 'jsr305.jar', 13 | ) 14 | 15 | java_library( 16 | name = 'jsr-305', 17 | exported_deps = [ 18 | ':jsr305-jar', 19 | ], 20 | visibility = [CSSLAYOUT_ROOT], 21 | ) 22 | -------------------------------------------------------------------------------- /lib/jsr-305/jsr305.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/css-layout/6e56ce21135da6724b827d23fb53dd42b5338048/lib/jsr-305/jsr305.jar -------------------------------------------------------------------------------- /lib/junit/BUCK: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | include_defs('//YOGA_DEFS') 9 | 10 | prebuilt_jar( 11 | name = 'junit-jar', 12 | binary_jar = 'junit4.jar', 13 | ) 14 | 15 | java_library( 16 | name = 'junit', 17 | exported_deps = [ 18 | ':junit-jar', 19 | ], 20 | visibility = [CSSLAYOUT_ROOT], 21 | ) 22 | -------------------------------------------------------------------------------- /lib/junit/junit4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/css-layout/6e56ce21135da6724b827d23fb53dd42b5338048/lib/junit/junit4.jar -------------------------------------------------------------------------------- /lib/soloader/BUCK: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014-present, Facebook, Inc. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the BSD-style license found in the 5 | # LICENSE file in the root directory of this source tree. An additional grant 6 | # of patent rights can be found in the PATENTS file in the same directory. 7 | 8 | include_defs('//YOGA_DEFS') 9 | 10 | android_prebuilt_aar( 11 | name = 'soloader', 12 | aar = 'soloader-0.1.0.aar', 13 | visibility = [CSSLAYOUT_ROOT], 14 | ) 15 | -------------------------------------------------------------------------------- /lib/soloader/soloader-0.1.0.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/css-layout/6e56ce21135da6724b827d23fb53dd42b5338048/lib/soloader/soloader-0.1.0.aar -------------------------------------------------------------------------------- /platforms/VS2010/CSSLayout.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CSSLayout", "CSSLayout\CSSLayout.vcxproj", "{DBF8C164-E459-46F1-94F5-EEA80BBC7E52}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tests", "tests\tests.vcxproj", "{836D1042-2131-4501-87FF-B9CFD369C2B0}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {DBF8C164-E459-46F1-94F5-EEA80BBC7E52} = {DBF8C164-E459-46F1-94F5-EEA80BBC7E52} 9 | EndProjectSection 10 | EndProject 11 | Global 12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 13 | Debug|Win32 = Debug|Win32 14 | Release|Win32 = Release|Win32 15 | EndGlobalSection 16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 17 | {DBF8C164-E459-46F1-94F5-EEA80BBC7E52}.Debug|Win32.ActiveCfg = Debug|Win32 18 | {DBF8C164-E459-46F1-94F5-EEA80BBC7E52}.Debug|Win32.Build.0 = Debug|Win32 19 | {DBF8C164-E459-46F1-94F5-EEA80BBC7E52}.Release|Win32.ActiveCfg = Release|Win32 20 | {DBF8C164-E459-46F1-94F5-EEA80BBC7E52}.Release|Win32.Build.0 = Release|Win32 21 | {836D1042-2131-4501-87FF-B9CFD369C2B0}.Debug|Win32.ActiveCfg = Debug|Win32 22 | {836D1042-2131-4501-87FF-B9CFD369C2B0}.Debug|Win32.Build.0 = Debug|Win32 23 | {836D1042-2131-4501-87FF-B9CFD369C2B0}.Release|Win32.ActiveCfg = Release|Win32 24 | {836D1042-2131-4501-87FF-B9CFD369C2B0}.Release|Win32.Build.0 = Release|Win32 25 | EndGlobalSection 26 | GlobalSection(SolutionProperties) = preSolution 27 | HideSolutionNode = FALSE 28 | EndGlobalSection 29 | EndGlobal 30 | -------------------------------------------------------------------------------- /platforms/VS2010/gtest-1.8/include/gtest/gtest_prod.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: wan@google.com (Zhanyong Wan) 31 | // 32 | // Google C++ Testing Framework definitions useful in production code. 33 | 34 | #ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 35 | #define GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 36 | 37 | // When you need to test the private or protected members of a class, 38 | // use the FRIEND_TEST macro to declare your tests as friends of the 39 | // class. For example: 40 | // 41 | // class MyClass { 42 | // private: 43 | // void MyMethod(); 44 | // FRIEND_TEST(MyClassTest, MyMethod); 45 | // }; 46 | // 47 | // class MyClassTest : public testing::Test { 48 | // // ... 49 | // }; 50 | // 51 | // TEST_F(MyClassTest, MyMethod) { 52 | // // Can call MyClass::MyMethod() here. 53 | // } 54 | 55 | #define FRIEND_TEST(test_case_name, test_name)\ 56 | friend class test_case_name##_##test_name##_Test 57 | 58 | #endif // GTEST_INCLUDE_GTEST_GTEST_PROD_H_ 59 | -------------------------------------------------------------------------------- /platforms/VS2010/gtest-1.8/include/gtest/internal/custom/gtest-port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Injection point for custom user configurations. 31 | // The following macros can be defined: 32 | // 33 | // Flag related macros: 34 | // GTEST_FLAG(flag_name) 35 | // GTEST_USE_OWN_FLAGFILE_FLAG_ - Define to 0 when the system provides its 36 | // own flagfile flag parsing. 37 | // GTEST_DECLARE_bool_(name) 38 | // GTEST_DECLARE_int32_(name) 39 | // GTEST_DECLARE_string_(name) 40 | // GTEST_DEFINE_bool_(name, default_val, doc) 41 | // GTEST_DEFINE_int32_(name, default_val, doc) 42 | // GTEST_DEFINE_string_(name, default_val, doc) 43 | // 44 | // Test filtering: 45 | // GTEST_TEST_FILTER_ENV_VAR_ - The name of an environment variable that 46 | // will be used if --GTEST_FLAG(test_filter) 47 | // is not provided. 48 | // 49 | // Logging: 50 | // GTEST_LOG_(severity) 51 | // GTEST_CHECK_(condition) 52 | // Functions LogToStderr() and FlushInfoLog() have to be provided too. 53 | // 54 | // Threading: 55 | // GTEST_HAS_NOTIFICATION_ - Enabled if Notification is already provided. 56 | // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ - Enabled if Mutex and ThreadLocal are 57 | // already provided. 58 | // Must also provide GTEST_DECLARE_STATIC_MUTEX_(mutex) and 59 | // GTEST_DEFINE_STATIC_MUTEX_(mutex) 60 | // 61 | // GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) 62 | // GTEST_LOCK_EXCLUDED_(locks) 63 | // 64 | // ** Custom implementation starts here ** 65 | 66 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 67 | #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 68 | 69 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 70 | -------------------------------------------------------------------------------- /platforms/VS2010/gtest-1.8/include/gtest/internal/custom/gtest-printers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // This file provides an injection point for custom printers in a local 31 | // installation of gTest. 32 | // It will be included from gtest-printers.h and the overrides in this file 33 | // will be visible to everyone. 34 | // See documentation at gtest/gtest-printers.h for details on how to define a 35 | // custom printer. 36 | // 37 | // ** Custom implementation starts here ** 38 | 39 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 40 | #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 41 | 42 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 43 | -------------------------------------------------------------------------------- /platforms/VS2010/gtest-1.8/include/gtest/internal/custom/gtest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Injection point for custom user configurations. 31 | // The following macros can be defined: 32 | // 33 | // GTEST_OS_STACK_TRACE_GETTER_ - The name of an implementation of 34 | // OsStackTraceGetterInterface. 35 | // 36 | // ** Custom implementation starts here ** 37 | 38 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 39 | #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 40 | 41 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 42 | -------------------------------------------------------------------------------- /platforms/VS2010/gtest-1.8/include/gtest/internal/gtest-port-arch.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // The Google C++ Testing Framework (Google Test) 31 | // 32 | // This header file defines the GTEST_OS_* macro. 33 | // It is separate from gtest-port.h so that custom/gtest-port.h can include it. 34 | 35 | #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ 36 | #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ 37 | 38 | // Determines the platform on which Google Test is compiled. 39 | #ifdef __CYGWIN__ 40 | # define GTEST_OS_CYGWIN 1 41 | #elif defined __SYMBIAN32__ 42 | # define GTEST_OS_SYMBIAN 1 43 | #elif defined _WIN32 44 | # define GTEST_OS_WINDOWS 1 45 | # ifdef _WIN32_WCE 46 | # define GTEST_OS_WINDOWS_MOBILE 1 47 | # elif defined(__MINGW__) || defined(__MINGW32__) 48 | # define GTEST_OS_WINDOWS_MINGW 1 49 | # elif defined(WINAPI_FAMILY) 50 | # include 51 | # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 52 | # define GTEST_OS_WINDOWS_DESKTOP 1 53 | # elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) 54 | # define GTEST_OS_WINDOWS_PHONE 1 55 | # elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) 56 | # define GTEST_OS_WINDOWS_RT 1 57 | # else 58 | // WINAPI_FAMILY defined but no known partition matched. 59 | // Default to desktop. 60 | # define GTEST_OS_WINDOWS_DESKTOP 1 61 | # endif 62 | # else 63 | # define GTEST_OS_WINDOWS_DESKTOP 1 64 | # endif // _WIN32_WCE 65 | #elif defined __APPLE__ 66 | # define GTEST_OS_MAC 1 67 | # if TARGET_OS_IPHONE 68 | # define GTEST_OS_IOS 1 69 | # endif 70 | #elif defined __FreeBSD__ 71 | # define GTEST_OS_FREEBSD 1 72 | #elif defined __linux__ 73 | # define GTEST_OS_LINUX 1 74 | # if defined __ANDROID__ 75 | # define GTEST_OS_LINUX_ANDROID 1 76 | # endif 77 | #elif defined __MVS__ 78 | # define GTEST_OS_ZOS 1 79 | #elif defined(__sun) && defined(__SVR4) 80 | # define GTEST_OS_SOLARIS 1 81 | #elif defined(_AIX) 82 | # define GTEST_OS_AIX 1 83 | #elif defined(__hpux) 84 | # define GTEST_OS_HPUX 1 85 | #elif defined __native_client__ 86 | # define GTEST_OS_NACL 1 87 | #elif defined __OpenBSD__ 88 | # define GTEST_OS_OPENBSD 1 89 | #elif defined __QNX__ 90 | # define GTEST_OS_QNX 1 91 | #endif // __CYGWIN__ 92 | 93 | #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ 94 | -------------------------------------------------------------------------------- /platforms/VS2010/gtest-1.8/lib/gtest.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/css-layout/6e56ce21135da6724b827d23fb53dd42b5338048/platforms/VS2010/gtest-1.8/lib/gtest.lib -------------------------------------------------------------------------------- /platforms/VS2010/gtest-1.8/lib/gtestd.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/css-layout/6e56ce21135da6724b827d23fb53dd42b5338048/platforms/VS2010/gtest-1.8/lib/gtestd.lib -------------------------------------------------------------------------------- /platforms/VS2010/tests/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "gtest/gtest.h" 4 | 5 | int main(int argc, char **argv) { 6 | printf("Running main() from main.cpp\n"); 7 | printf("Compiled on %s at %s\n", __DATE__, __TIME__); 8 | testing::InitGoogleTest(&argc, argv); 9 | return RUN_ALL_TESTS(); 10 | } -------------------------------------------------------------------------------- /tests/CSSLayoutDirtyMarkingTest.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | TEST(CSSLayoutTest, dirty_propagation) { 14 | const CSSNodeRef root = CSSNodeNew(); 15 | CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); 16 | CSSNodeStyleSetWidth(root, 100); 17 | CSSNodeStyleSetHeight(root, 100); 18 | 19 | const CSSNodeRef root_child0 = CSSNodeNew(); 20 | CSSNodeStyleSetWidth(root_child0, 50); 21 | CSSNodeStyleSetHeight(root_child0, 20); 22 | CSSNodeInsertChild(root, root_child0, 0); 23 | 24 | const CSSNodeRef root_child1 = CSSNodeNew(); 25 | CSSNodeStyleSetWidth(root_child1, 50); 26 | CSSNodeStyleSetHeight(root_child1, 20); 27 | CSSNodeInsertChild(root, root_child1, 1); 28 | 29 | CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); 30 | 31 | CSSNodeStyleSetWidth(root_child0, 20); 32 | 33 | EXPECT_TRUE(CSSNodeIsDirty(root_child0)); 34 | EXPECT_FALSE(CSSNodeIsDirty(root_child1)); 35 | EXPECT_TRUE(CSSNodeIsDirty(root)); 36 | 37 | CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); 38 | 39 | EXPECT_FALSE(CSSNodeIsDirty(root_child0)); 40 | EXPECT_FALSE(CSSNodeIsDirty(root_child1)); 41 | EXPECT_FALSE(CSSNodeIsDirty(root)); 42 | 43 | CSSNodeFreeRecursive(root); 44 | } 45 | 46 | TEST(CSSLayoutTest, dirty_propagation_only_if_prop_changed) { 47 | const CSSNodeRef root = CSSNodeNew(); 48 | CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); 49 | CSSNodeStyleSetWidth(root, 100); 50 | CSSNodeStyleSetHeight(root, 100); 51 | 52 | const CSSNodeRef root_child0 = CSSNodeNew(); 53 | CSSNodeStyleSetWidth(root_child0, 50); 54 | CSSNodeStyleSetHeight(root_child0, 20); 55 | CSSNodeInsertChild(root, root_child0, 0); 56 | 57 | const CSSNodeRef root_child1 = CSSNodeNew(); 58 | CSSNodeStyleSetWidth(root_child1, 50); 59 | CSSNodeStyleSetHeight(root_child1, 20); 60 | CSSNodeInsertChild(root, root_child1, 1); 61 | 62 | CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); 63 | 64 | CSSNodeStyleSetWidth(root_child0, 50); 65 | 66 | EXPECT_FALSE(CSSNodeIsDirty(root_child0)); 67 | EXPECT_FALSE(CSSNodeIsDirty(root_child1)); 68 | EXPECT_FALSE(CSSNodeIsDirty(root)); 69 | 70 | CSSNodeFreeRecursive(root); 71 | } 72 | 73 | TEST(CSSLayoutTest, dirty_node_only_if_children_are_actually_removed) { 74 | const CSSNodeRef root = CSSNodeNew(); 75 | CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart); 76 | CSSNodeStyleSetWidth(root, 50); 77 | CSSNodeStyleSetHeight(root, 50); 78 | 79 | const CSSNodeRef child0 = CSSNodeNew(); 80 | CSSNodeStyleSetWidth(child0, 50); 81 | CSSNodeStyleSetHeight(child0, 25); 82 | CSSNodeInsertChild(root, child0, 0); 83 | 84 | CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); 85 | 86 | const CSSNodeRef child1 = CSSNodeNew(); 87 | CSSNodeRemoveChild(root, child1); 88 | EXPECT_FALSE(CSSNodeIsDirty(root)); 89 | CSSNodeFree(child1); 90 | 91 | CSSNodeRemoveChild(root, child0); 92 | EXPECT_TRUE(CSSNodeIsDirty(root)); 93 | CSSNodeFree(child0); 94 | 95 | CSSNodeFreeRecursive(root); 96 | } 97 | -------------------------------------------------------------------------------- /tests/CSSLayoutMeasureTest.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | static CSSSize _measure(CSSNodeRef node, 14 | float width, 15 | CSSMeasureMode widthMode, 16 | float height, 17 | CSSMeasureMode heightMode) { 18 | int *measureCount = (int*) CSSNodeGetContext(node); 19 | if (measureCount) { 20 | (*measureCount)++; 21 | } 22 | // BEGIN_UNITY @joce 10-26-2016 CompileForVS2010 23 | // return CSSSize { 24 | // .width = 10, 25 | // .height = 10, 26 | // }; 27 | CSSSize size; 28 | size.width = 10; 29 | size.height = 10; 30 | return size; 31 | // END_UNITY 32 | } 33 | 34 | TEST(CSSLayoutTest, dont_measure_single_grow_shrink_child) { 35 | const CSSNodeRef root = CSSNodeNew(); 36 | CSSNodeStyleSetWidth(root, 100); 37 | CSSNodeStyleSetHeight(root, 100); 38 | 39 | int measureCount = 0; 40 | 41 | const CSSNodeRef root_child0 = CSSNodeNew(); 42 | CSSNodeSetContext(root_child0, &measureCount); 43 | CSSNodeSetMeasureFunc(root_child0, _measure); 44 | CSSNodeStyleSetFlexGrow(root_child0, 1); 45 | CSSNodeStyleSetFlexShrink(root_child0, 1); 46 | CSSNodeInsertChild(root, root_child0, 0); 47 | 48 | CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); 49 | 50 | ASSERT_EQ(0, measureCount); 51 | 52 | CSSNodeFreeRecursive(root); 53 | } 54 | 55 | #if GTEST_HAS_DEATH_TEST 56 | TEST(CSSLayoutTest, cannot_add_child_to_node_with_measure_func) { 57 | const CSSNodeRef root = CSSNodeNew(); 58 | CSSNodeSetMeasureFunc(root, _measure); 59 | 60 | const CSSNodeRef root_child0 = CSSNodeNew(); 61 | ASSERT_DEATH(CSSNodeInsertChild(root, root_child0, 0), "Cannot add child.*"); 62 | CSSNodeFree(root_child0); 63 | CSSNodeFreeRecursive(root); 64 | } 65 | 66 | TEST(CSSLayoutTest, cannot_add_nonnull_measure_func_to_non_leaf_node) { 67 | const CSSNodeRef root = CSSNodeNew(); 68 | const CSSNodeRef root_child0 = CSSNodeNew(); 69 | CSSNodeInsertChild(root, root_child0, 0); 70 | 71 | ASSERT_DEATH(CSSNodeSetMeasureFunc(root, _measure), "Cannot set measure function.*"); 72 | CSSNodeFreeRecursive(root); 73 | } 74 | 75 | TEST(CSSLayoutTest, can_nullify_measure_func_on_any_node) { 76 | const CSSNodeRef root = CSSNodeNew(); 77 | CSSNodeInsertChild(root, CSSNodeNew(), 0); 78 | 79 | CSSNodeSetMeasureFunc(root, NULL); 80 | ASSERT_TRUE(CSSNodeGetMeasureFunc(root) == NULL); 81 | CSSNodeFreeRecursive(root); 82 | } 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /tests/CSSLayoutMemoryFuncTest.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | extern int32_t gNodeInstanceCount; 14 | 15 | static int testMallocCount; 16 | static int testCallocCount; 17 | static int testReallocCount; 18 | static int testFreeCount; 19 | 20 | static void *testMalloc(size_t size) { 21 | testMallocCount++; 22 | return malloc(size); 23 | } 24 | 25 | static void *testCalloc(size_t count, size_t size) { 26 | testCallocCount++; 27 | return calloc(count, size); 28 | } 29 | 30 | static void *testRealloc(void *ptr, size_t size) { 31 | testReallocCount++; 32 | return realloc(ptr, size); 33 | } 34 | 35 | static void testFree(void *ptr) { 36 | testFreeCount++; 37 | free(ptr); 38 | } 39 | 40 | TEST(CSSLayoutTest, memory_func_default) { 41 | gNodeInstanceCount = 0; // Reset CSSNode instance count for memory func test 42 | CSSLayoutSetMemoryFuncs(NULL, NULL, NULL, NULL); 43 | const CSSNodeRef root = CSSNodeNew(); 44 | const CSSNodeRef root_child0 = CSSNodeNew(); 45 | CSSNodeInsertChild(root, root_child0, 0); 46 | CSSNodeFreeRecursive(root); 47 | } 48 | 49 | TEST(CSSLayoutTest, memory_func_test_funcs) { 50 | gNodeInstanceCount = 0; // Reset CSSNode instance count for memory func test 51 | CSSLayoutSetMemoryFuncs(&testMalloc, &testCalloc, &testRealloc, &testFree); 52 | const CSSNodeRef root = CSSNodeNew(); 53 | for (int i = 0; i < 10; i++) { 54 | const CSSNodeRef child = CSSNodeNew(); 55 | CSSNodeInsertChild(root, child, 0); 56 | } 57 | CSSNodeFreeRecursive(root); 58 | ASSERT_NE(testMallocCount, 0); 59 | ASSERT_NE(testCallocCount, 0); 60 | ASSERT_NE(testReallocCount, 0); 61 | ASSERT_NE(testFreeCount, 0); 62 | CSSLayoutSetMemoryFuncs(NULL, NULL, NULL, NULL); 63 | } 64 | 65 | #if GTEST_HAS_DEATH_TEST 66 | TEST(CSSLayoutTest, memory_func_assert_zero_nodes) { 67 | gNodeInstanceCount = 0; // Reset CSSNode instance count for memory func test 68 | const CSSNodeRef root = CSSNodeNew(); 69 | ASSERT_DEATH(CSSLayoutSetMemoryFuncs(&testMalloc, &testCalloc, &testRealloc, &testFree), "Cannot set memory functions: all node must be freed first"); 70 | CSSNodeFreeRecursive(root); 71 | } 72 | 73 | TEST(CSSLayoutTest, memory_func_assert_all_non_null) { 74 | gNodeInstanceCount = 0; // Reset CSSNode instance count for memory func test 75 | ASSERT_DEATH(CSSLayoutSetMemoryFuncs(NULL, &testCalloc, &testRealloc, &testFree), "Cannot set memory functions: functions must be all NULL or Non-NULL"); 76 | } 77 | #endif 78 | -------------------------------------------------------------------------------- /tests/CSSLayoutRelayoutTest.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | TEST(CSSLayoutTest, dont_cache_computed_flex_basis_between_layouts) { 14 | CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeatureWebFlexBasis, true); 15 | 16 | const CSSNodeRef root = CSSNodeNew(); 17 | 18 | const CSSNodeRef root_child0 = CSSNodeNew(); 19 | CSSNodeStyleSetHeight(root_child0, 10); 20 | CSSNodeStyleSetFlexBasis(root_child0, 20); 21 | CSSNodeInsertChild(root, root_child0, 0); 22 | 23 | CSSNodeCalculateLayout(root, 100, CSSUndefined, CSSDirectionLTR); 24 | CSSNodeCalculateLayout(root, 100, 100, CSSDirectionLTR); 25 | 26 | ASSERT_FLOAT_EQ(20, CSSNodeLayoutGetHeight(root_child0)); 27 | 28 | CSSNodeFreeRecursive(root); 29 | 30 | CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeatureWebFlexBasis, false); 31 | } 32 | -------------------------------------------------------------------------------- /tests/CSSLayoutRoundingMeasureFuncTest.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | static CSSSize _measureFloor(CSSNodeRef node, 14 | float width, 15 | CSSMeasureMode widthMode, 16 | float height, 17 | CSSMeasureMode heightMode) { 18 | 19 | return CSSSize{ 20 | width = 10.2, 21 | height = 10.2, 22 | }; 23 | } 24 | 25 | static CSSSize _measureCeil(CSSNodeRef node, 26 | float width, 27 | CSSMeasureMode widthMode, 28 | float height, 29 | CSSMeasureMode heightMode) { 30 | 31 | return CSSSize{ 32 | width = 10.5, 33 | height = 10.5, 34 | }; 35 | } 36 | 37 | TEST(CSSLayoutTest, rounding_feature_with_custom_measure_func_floor) { 38 | CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeatureRounding, true); 39 | 40 | const CSSNodeRef root = CSSNodeNew(); 41 | 42 | const CSSNodeRef root_child0 = CSSNodeNew(); 43 | CSSNodeSetMeasureFunc(root_child0, _measureFloor); 44 | CSSNodeInsertChild(root, root_child0, 0); 45 | 46 | CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); 47 | 48 | ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetWidth(root_child0)); 49 | ASSERT_FLOAT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); 50 | 51 | CSSNodeFreeRecursive(root); 52 | 53 | CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeatureRounding, false); 54 | } 55 | 56 | TEST(CSSLayoutTest, rounding_feature_with_custom_measure_func_ceil) { 57 | CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeatureRounding, true); 58 | 59 | const CSSNodeRef root = CSSNodeNew(); 60 | 61 | const CSSNodeRef root_child0 = CSSNodeNew(); 62 | CSSNodeSetMeasureFunc(root_child0, _measureCeil); 63 | CSSNodeInsertChild(root, root_child0, 0); 64 | 65 | CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); 66 | 67 | ASSERT_FLOAT_EQ(11, CSSNodeLayoutGetWidth(root_child0)); 68 | ASSERT_FLOAT_EQ(11, CSSNodeLayoutGetHeight(root_child0)); 69 | 70 | CSSNodeFreeRecursive(root); 71 | 72 | CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeatureRounding, false); 73 | } 74 | -------------------------------------------------------------------------------- /tests/CSSLayoutStyleTest.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | TEST(CSSLayoutTest, copy_style_same) { 14 | const CSSNodeRef node0 = CSSNodeNew(); 15 | const CSSNodeRef node1 = CSSNodeNew(); 16 | ASSERT_FALSE(CSSNodeIsDirty(node0)); 17 | 18 | CSSNodeCopyStyle(node0, node1); 19 | ASSERT_FALSE(CSSNodeIsDirty(node0)); 20 | 21 | CSSNodeFree(node0); 22 | CSSNodeFree(node1); 23 | } 24 | 25 | TEST(CSSLayoutTest, copy_style_modified) { 26 | const CSSNodeRef node0 = CSSNodeNew(); 27 | ASSERT_FALSE(CSSNodeIsDirty(node0)); 28 | ASSERT_EQ(CSSFlexDirectionColumn, CSSNodeStyleGetFlexDirection(node0)); 29 | ASSERT_TRUE(CSSValueIsUndefined(CSSNodeStyleGetMaxHeight(node0))); 30 | 31 | const CSSNodeRef node1 = CSSNodeNew(); 32 | CSSNodeStyleSetFlexDirection(node1, CSSFlexDirectionRow); 33 | CSSNodeStyleSetMaxHeight(node1, 10); 34 | 35 | CSSNodeCopyStyle(node0, node1); 36 | ASSERT_TRUE(CSSNodeIsDirty(node0)); 37 | ASSERT_EQ(CSSFlexDirectionRow, CSSNodeStyleGetFlexDirection(node0)); 38 | ASSERT_FLOAT_EQ(10, CSSNodeStyleGetMaxHeight(node0)); 39 | 40 | CSSNodeFree(node0); 41 | CSSNodeFree(node1); 42 | } 43 | 44 | TEST(CSSLayoutTest, copy_style_modified_same) { 45 | const CSSNodeRef node0 = CSSNodeNew(); 46 | CSSNodeStyleSetFlexDirection(node0, CSSFlexDirectionRow); 47 | CSSNodeStyleSetMaxHeight(node0, 10); 48 | CSSNodeCalculateLayout(node0, CSSUndefined, CSSUndefined, CSSDirectionLTR); 49 | ASSERT_FALSE(CSSNodeIsDirty(node0)); 50 | 51 | const CSSNodeRef node1 = CSSNodeNew(); 52 | CSSNodeStyleSetFlexDirection(node1, CSSFlexDirectionRow); 53 | CSSNodeStyleSetMaxHeight(node1, 10); 54 | 55 | CSSNodeCopyStyle(node0, node1); 56 | ASSERT_FALSE(CSSNodeIsDirty(node0)); 57 | 58 | CSSNodeFree(node0); 59 | CSSNodeFree(node1); 60 | } 61 | --------------------------------------------------------------------------------