Compare commits
375 Commits
v1.0.0
...
v2016.11.21.00
Author | SHA1 | Date | |
---|---|---|---|
|
b16c22a8f3 | ||
|
56ec33a463 | ||
|
367c3a28be | ||
|
653150a7c4 | ||
|
542fc50409 | ||
|
4f192481ee | ||
|
0bb2955c5c | ||
|
191ac98b89 | ||
|
32c175ac55 | ||
|
4b61cdccea | ||
|
b9c4c403a9 | ||
|
56aa279fef | ||
|
7e4bb732ff | ||
|
32ba5ae647 | ||
|
2fa6f5087d | ||
|
c2aac9f46e | ||
|
ef81d4b0c7 | ||
|
667858990c | ||
|
d80bac4234 | ||
|
d1c555fede | ||
|
ac4d0ab2a1 | ||
|
603321e1ab | ||
|
129437f49e | ||
|
204aba80b9 | ||
|
e6702e1168 | ||
|
b99172d28b | ||
|
7a3df9999b | ||
|
e0e88f97b6 | ||
|
b4d0e1a17c | ||
|
e40af30fa5 | ||
|
cd054ecf26 | ||
|
aaa977f645 | ||
|
70e01a4476 | ||
|
3e2c13f418 | ||
|
0dbbfc5910 | ||
|
f222d22ba8 | ||
|
087d1f3a82 | ||
|
c382d513fb | ||
|
8a7183f465 | ||
|
ff602d4606 | ||
|
f5912a97e4 | ||
|
a253c6fbb7 | ||
|
863378d74e | ||
|
f1fcd5e382 | ||
|
6a6efe0764 | ||
|
e54af5e854 | ||
|
502f3c7010 | ||
|
12ebaa56b6 | ||
|
3e567fdcae | ||
|
1baa239389 | ||
|
b50090a04e | ||
|
ba2905dd1d | ||
|
997088ffbb | ||
|
ffb90e6ff2 | ||
|
1c22a1aa53 | ||
|
7082734c6b | ||
|
366a61af8d | ||
|
18fe0959f0 | ||
|
1ffce3edb1 | ||
|
6165d7a2be | ||
|
01a3881426 | ||
|
9c1896043d | ||
|
0f822bbef2 | ||
|
e00e30ca15 | ||
|
b938017ccf | ||
|
630ae0972b | ||
|
d8662805d5 | ||
|
26e7490fc9 | ||
|
d94363ea7e | ||
|
af5e6771d7 | ||
|
ced779b259 | ||
|
a65e6930cf | ||
|
267e17f23a | ||
|
df6368e048 | ||
|
ba20d75992 | ||
|
620cb3f507 | ||
|
3201e24780 | ||
|
2cac77eaa1 | ||
|
46823878a5 | ||
|
b59ce09109 | ||
|
c34299edc9 | ||
|
1ba81d9ec7 | ||
|
d6d817c142 | ||
|
01c2ac3369 | ||
|
0cc1b83569 | ||
|
c8d77b2aae | ||
|
01507044b3 | ||
|
2168d68007 | ||
|
4d0e657653 | ||
|
4452c7be5c | ||
|
15f5c4cea5 | ||
|
97fef59f96 | ||
|
e9b9973cae | ||
|
69c374e74e | ||
|
4c57029a28 | ||
|
c28429efc8 | ||
|
ab4ce535b9 | ||
|
7fee10691c | ||
|
4d964bdbc3 | ||
|
ef538a45cd | ||
|
dc5e613285 | ||
|
1488f822c3 | ||
|
7673de823f | ||
|
26bcc1e072 | ||
|
2e090cb1c8 | ||
|
daed6f5b8a | ||
|
e4ad7d3c12 | ||
|
fa2ffc72a4 | ||
|
d1d9326fa4 | ||
|
9c3970dd75 | ||
|
6152ca46c8 | ||
|
9fb1b29f14 | ||
|
82dafa75cf | ||
|
eb4f1cdc96 | ||
|
501ed57784 | ||
|
bfb9b926b3 | ||
|
b21efa45e6 | ||
|
c619c0be5a | ||
|
63d3e8f3f3 | ||
|
770fa6d254 | ||
|
eedee80f25 | ||
|
0254e3e97f | ||
|
05ba3a2565 | ||
|
89440f630f | ||
|
832d07902e | ||
|
b45a7e3737 | ||
|
14009ec470 | ||
|
203e3dc9b8 | ||
|
7548164edb | ||
|
722bfb9032 | ||
|
2a8a4e10c6 | ||
|
8df9320f4c | ||
|
df6b4d3682 | ||
|
8939bcb96d | ||
|
d3fc24e842 | ||
|
7f6b942146 | ||
|
29fa232129 | ||
|
41b64478c4 | ||
|
23acf2156f | ||
|
1de914737a | ||
|
033658196f | ||
|
136ec25e8c | ||
|
62dba4c741 | ||
|
871a7cf310 | ||
|
cdf4ee1e59 | ||
|
588d2c91ba | ||
|
f61fbd269e | ||
|
d506e6ab94 | ||
|
56f6efdecf | ||
|
90844d62c5 | ||
|
c233bafeb2 | ||
|
b57abb2f60 | ||
|
56279110c0 | ||
|
01115b8bbd | ||
|
47bd1bb943 | ||
|
2870d3ce4d | ||
|
23f2878808 | ||
|
11f85ce91e | ||
|
1f300a58fb | ||
|
dbf3b11946 | ||
|
3b1515f2b7 | ||
|
6b16dc4060 | ||
|
9c93c7fc42 | ||
|
15d5cb0169 | ||
|
dba5faabb2 | ||
|
ff8f17ac99 | ||
|
017fb2c734 | ||
|
8fd14c710c | ||
|
1415a5d7fd | ||
|
2592894d2d | ||
|
dcaef7ecb0 | ||
|
2dcd8b4074 | ||
|
1951242a52 | ||
|
d4121401d7 | ||
|
0be3b1013f | ||
|
21a05417cd | ||
|
8fcb265830 | ||
|
64fffcb8f3 | ||
|
059384f277 | ||
|
57725e849a | ||
|
b51e832e4e | ||
|
d9191431ff | ||
|
251a499ba6 | ||
|
3c33184dbb | ||
|
583830b3df | ||
|
36eaae88e0 | ||
|
284634c880 | ||
|
94bbbde930 | ||
|
1051c39a59 | ||
|
1abb2d1714 | ||
|
c28148caff | ||
|
e3fa40e694 | ||
|
89c00a7a3b | ||
|
2808e547c6 | ||
|
8b4a61df1a | ||
|
43faff434a | ||
|
ea9a6ce06f | ||
|
beb51fac1b | ||
|
d33befeb98 | ||
|
2fc622adbd | ||
|
1fd3a16116 | ||
|
aa70125f6c | ||
|
9985e398b3 | ||
|
b629bcacab | ||
|
f65febb1af | ||
|
ccbfee3841 | ||
|
9eb75e27cc | ||
|
15afb4207c | ||
|
f1ae87cd73 | ||
|
e8465aee45 | ||
|
ca72b2b796 | ||
|
4bcefd8845 | ||
|
0672f5572f | ||
|
9d34b4e110 | ||
|
dab03cb800 | ||
|
dd2346f8ac | ||
|
dde2b349f2 | ||
|
7cd6305371 | ||
|
f28dacf280 | ||
|
a960203567 | ||
|
48e5304276 | ||
|
53ff4f59ca | ||
|
28bc42a988 | ||
|
c373056d80 | ||
|
f68521aa69 | ||
|
fdd5c8ce82 | ||
|
7a1e353404 | ||
|
6a44dbc43b | ||
|
597354a43b | ||
|
1ce14cd097 | ||
|
d125911894 | ||
|
e307dc22d1 | ||
|
916170f6ac | ||
|
57021eba9d | ||
|
a43b813517 | ||
|
e5a3f7bf5b | ||
|
af5b14335e | ||
|
118f64f206 | ||
|
450472766d | ||
|
759cb707a4 | ||
|
328db9ca1c | ||
|
f15b563166 | ||
|
7f27046cc5 | ||
|
faad5cdf4d | ||
|
256d080fd2 | ||
|
efe1595f0e | ||
|
9278ff462e | ||
|
b32d384337 | ||
|
f5caf93c6e | ||
|
c74eae50ac | ||
|
7af5e3d68d | ||
|
9689062f6c | ||
|
ac44d2ea6e | ||
|
9ab97af05d | ||
|
cdf18b9c2b | ||
|
c7d02257e3 | ||
|
c72321f8a9 | ||
|
a0805d0b90 | ||
|
5207b90420 | ||
|
5e7d95b403 | ||
|
041960fcbc | ||
|
46c842c71a | ||
|
b26794a375 | ||
|
8ffff2bfaf | ||
|
fdd8552c4e | ||
|
93809b69c8 | ||
|
667106e423 | ||
|
57874a1a9e | ||
|
8b7f353746 | ||
|
ca34ff4446 | ||
|
d878091c4b | ||
|
c4fa32cfd3 | ||
|
6e05325f08 | ||
|
a1f36b53f5 | ||
|
383d8a6b3d | ||
|
7b0c008300 | ||
|
45e595e6ae | ||
|
2a816bf5a7 | ||
|
71eb25d1cc | ||
|
c06752e052 | ||
|
bd92550d57 | ||
|
9260363fef | ||
|
9d62cee68b | ||
|
16f43dac87 | ||
|
8177bfe702 | ||
|
8779d942ea | ||
|
f3dd51ab97 | ||
|
b0d00ad338 | ||
|
7bd6b2b7dd | ||
|
68e0b0cc58 | ||
|
5b56be412c | ||
|
3454511947 | ||
|
b157ab4a00 | ||
|
8d5cdd4e6c | ||
|
425345aa8d | ||
|
dd8e5cd65d | ||
|
64704dd708 | ||
|
dc7059d340 | ||
|
acd295e470 | ||
|
5d5630d3c8 | ||
|
c9094f94d0 | ||
|
f3b6fb3be0 | ||
|
3d7bc48fa6 | ||
|
219bdaed15 | ||
|
f2aa5ba604 | ||
|
53769ccbc5 | ||
|
2733ebf1d0 | ||
|
45227c0b9a | ||
|
e848706911 | ||
|
79d7291906 | ||
|
bae4eb1830 | ||
|
609d4ae69d | ||
|
99c3a88df4 | ||
|
4364c6ebb2 | ||
|
73b1e63bd7 | ||
|
b7856ce26a | ||
|
f5eefe51f8 | ||
|
aac6694127 | ||
|
6e499300ff | ||
|
d3b702e1ad | ||
|
eb1d1726b9 | ||
|
8f7632bc7f | ||
|
d2e66a8d82 | ||
|
4b4cd06be2 | ||
|
a821f6c555 | ||
|
fbeef4542d | ||
|
f02fbfc10c | ||
|
e4c93e8c59 | ||
|
35bd01e3f2 | ||
|
040f0f3e7c | ||
|
af09213d1a | ||
|
538cb2e940 | ||
|
45f62c424c | ||
|
c33e255182 | ||
|
0f43977bb2 | ||
|
9b75493988 | ||
|
0faaabb78c | ||
|
e510c72111 | ||
|
57d41f3e35 | ||
|
e9d880a105 | ||
|
221510cfcf | ||
|
2636a4fbed | ||
|
7b2140d7f9 | ||
|
3042bac0bb | ||
|
5af85c5ef6 | ||
|
0f5d3ae8f0 | ||
|
39b45c65c1 | ||
|
948241b659 | ||
|
2cf795c118 | ||
|
9eb00949ae | ||
|
2e908bfdee | ||
|
cefd6ccb96 | ||
|
e280a577ae | ||
|
246005cc84 | ||
|
4ca2ea3466 | ||
|
4de0721a24 | ||
|
4ef24028be | ||
|
a353a11bf4 | ||
|
4a7936aa24 | ||
|
f51c2d004d | ||
|
e43a8b28d6 | ||
|
cf94d35b51 | ||
|
ebc56fee59 | ||
|
2120285467 | ||
|
765ff8463e | ||
|
2d869489ef | ||
|
909c14117f | ||
|
9a149c83ff | ||
|
2321165d53 | ||
|
d1a49a4f0b | ||
|
793220faf8 | ||
|
996f2a03d5 | ||
|
877a2838a6 | ||
|
1ab785b7a3 | ||
|
06c708053f |
2
.buckconfig
Normal file
2
.buckconfig
Normal file
@@ -0,0 +1,2 @@
|
||||
[cxx]
|
||||
gtest_dep = //lib/gtest:gtest
|
24
.eslintrc
24
.eslintrc
@@ -1,24 +0,0 @@
|
||||
{
|
||||
"browser": true,
|
||||
"shadow": true,
|
||||
"globals": {
|
||||
"jasmine": true,
|
||||
"describe": true,
|
||||
"beforeEach": true,
|
||||
"afterEach": true,
|
||||
"spyOn": true,
|
||||
"it": true,
|
||||
"xit": true,
|
||||
"expect": true,
|
||||
"require": true,
|
||||
"global": true,
|
||||
"__dirname": true,
|
||||
"module": true,
|
||||
"console": true,
|
||||
"setTimeout": true,
|
||||
"define": true
|
||||
},
|
||||
"rules": {
|
||||
"quotes": [2, "single"]
|
||||
}
|
||||
}
|
17
.gitignore
vendored
17
.gitignore
vendored
@@ -1,7 +1,10 @@
|
||||
a.out
|
||||
*.class
|
||||
/**/java/out/*
|
||||
/**/.idea/workspace.xml
|
||||
/lib/
|
||||
/node_modules/
|
||||
npm-debug.log
|
||||
.DS_STORE
|
||||
|
||||
/buck-cache/
|
||||
/buck-out/
|
||||
/.buckconfig.local
|
||||
/.buckd
|
||||
/gentest/test.html
|
||||
|
||||
# Visual studio code
|
||||
.vscode
|
||||
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "lib/gtest/googletest"]
|
||||
path = lib/gtest/googletest
|
||||
url = https://github.com/google/googletest.git
|
10
.hgignore
Normal file
10
.hgignore
Normal file
@@ -0,0 +1,10 @@
|
||||
.DS_STORE
|
||||
|
||||
/buck-cache/
|
||||
/buck-out/
|
||||
/.buckconfig.local
|
||||
/.buckd
|
||||
/gentest/test.html
|
||||
|
||||
# Visual studio code
|
||||
.vscode
|
36
.travis.yml
36
.travis.yml
@@ -1,14 +1,30 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.12"
|
||||
# Copyright (c) 2014-present, Facebook, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the BSD-style license found in the
|
||||
# LICENSE file in the root directory of this source tree. An additional grant
|
||||
# of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
sudo: false
|
||||
os: osx
|
||||
osx_image: xcode7.3
|
||||
language: cpp
|
||||
compiler: clang
|
||||
|
||||
before_install:
|
||||
- npm install grunt-cli -g
|
||||
- brew update
|
||||
- brew tap facebook/fb
|
||||
- brew install buck
|
||||
- brew cask install java
|
||||
- brew outdated xctool || brew upgrade xctool
|
||||
- brew install mono
|
||||
- export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
|
||||
- export PATH=$JAVA_HOME/bin:$PATH
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gcc
|
||||
|
||||
script:
|
||||
- buck test //:CSSLayout
|
||||
- buck test //java:java
|
||||
- buck test //CSSLayoutKit:CSSLayoutKit --config cxx.default_platform=iphonesimulator-x86_64 --config cxx.cflags=-DTRAVIS_CI
|
||||
- sh csharp/tests/Facebook.CSSLayout/test_macos.sh
|
||||
- buck run //benchmark:benchmark
|
||||
- git checkout HEAD^
|
||||
- buck run //benchmark:benchmark
|
||||
|
48
BUCK
Normal file
48
BUCK
Normal file
@@ -0,0 +1,48 @@
|
||||
# Copyright (c) 2014-present, Facebook, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the BSD-style license found in the
|
||||
# LICENSE file in the root directory of this source tree. An additional grant
|
||||
# of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
include_defs('//CSSLAYOUT_DEFS')
|
||||
|
||||
BASE_COMPILER_FLAGS = [
|
||||
'-fno-omit-frame-pointer',
|
||||
'-fexceptions',
|
||||
'-Wall',
|
||||
'-Werror',
|
||||
'-O3',
|
||||
]
|
||||
|
||||
GMOCK_OVERRIDE_FLAGS = [
|
||||
# gmock does not mark mocked methods as override, ignore the warnings in tests
|
||||
'-Wno-inconsistent-missing-override',
|
||||
]
|
||||
|
||||
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ['-std=c11']
|
||||
TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + ['-std=c++11']
|
||||
|
||||
cxx_library(
|
||||
name = 'CSSLayout',
|
||||
srcs = glob(['CSSLayout/*.c']),
|
||||
tests=[':tests'],
|
||||
exported_headers = subdir_glob([('', 'CSSLayout/*.h')]),
|
||||
header_namespace = '',
|
||||
force_static = True,
|
||||
compiler_flags = COMPILER_FLAGS,
|
||||
deps = [],
|
||||
visibility = ['PUBLIC'],
|
||||
)
|
||||
|
||||
cxx_test(
|
||||
name = 'tests',
|
||||
contacts = ['emilsj@fb.com'],
|
||||
srcs = glob(['tests/*.cpp']),
|
||||
compiler_flags = TEST_COMPILER_FLAGS,
|
||||
deps = [
|
||||
':CSSLayout',
|
||||
GTEST_TARGET,
|
||||
],
|
||||
visibility = ['PUBLIC'],
|
||||
)
|
@@ -29,9 +29,7 @@ disclosure of security bugs. In those cases, please go through the process
|
||||
outlined on that page and do not file a public issue.
|
||||
|
||||
## Coding Style
|
||||
* 2 spaces for indentation rather than tabs
|
||||
* 80 character line length
|
||||
* ...
|
||||
* format.sh
|
||||
|
||||
## License
|
||||
By contributing to css-layout, you agree that your contributions will be licensed
|
24
CSSLAYOUT_DEFS
Normal file
24
CSSLAYOUT_DEFS
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
CSSLAYOUT_ROOT = '//...'
|
||||
INFER_ANNOTATIONS_TARGET = '//lib/infer-annotations:infer-annotations'
|
||||
JSR_305_TARGET = '//lib/jsr-305:jsr-305'
|
||||
JUNIT_TARGET = '//lib/junit:junit'
|
||||
PROGRUARD_ANNOTATIONS_TARGET = '//java/com/facebook/proguard/annotations:annotations'
|
||||
SOLOADER_TARGET = '//lib/soloader:soloader'
|
||||
GTEST_TARGET = '//lib/gtest:gtest'
|
||||
JNI_TARGET = '//lib/jni:jni'
|
||||
FBJNI_TARGET = '//lib/fb:fbjni'
|
||||
|
||||
CXX_LIBRARY_WHITELIST = [
|
||||
'//lib/fb:fbjni',
|
||||
'//java:jni',
|
||||
]
|
||||
|
||||
def csslayout_dep(dep):
|
||||
return '//' + dep
|
||||
|
||||
class allow_unsafe_import:
|
||||
def __enter__(self):
|
||||
pass
|
||||
def __exit__(self, type, value, traceback):
|
||||
pass
|
106
CSSLayout/CSSEnums.h
Normal file
106
CSSLayout/CSSEnums.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
typedef enum CSSOverflow {
|
||||
CSSOverflowVisible,
|
||||
CSSOverflowHidden,
|
||||
CSSOverflowScroll,
|
||||
CSSOverflowCount,
|
||||
} CSSOverflow;
|
||||
|
||||
typedef enum CSSJustify {
|
||||
CSSJustifyFlexStart,
|
||||
CSSJustifyCenter,
|
||||
CSSJustifyFlexEnd,
|
||||
CSSJustifySpaceBetween,
|
||||
CSSJustifySpaceAround,
|
||||
CSSJustifyCount,
|
||||
} CSSJustify;
|
||||
|
||||
typedef enum CSSFlexDirection {
|
||||
CSSFlexDirectionColumn,
|
||||
CSSFlexDirectionColumnReverse,
|
||||
CSSFlexDirectionRow,
|
||||
CSSFlexDirectionRowReverse,
|
||||
CSSFlexDirectionCount,
|
||||
} CSSFlexDirection;
|
||||
|
||||
typedef enum CSSAlign {
|
||||
CSSAlignAuto,
|
||||
CSSAlignFlexStart,
|
||||
CSSAlignCenter,
|
||||
CSSAlignFlexEnd,
|
||||
CSSAlignStretch,
|
||||
CSSAlignCount,
|
||||
} CSSAlign;
|
||||
|
||||
typedef enum CSSEdge {
|
||||
CSSEdgeLeft,
|
||||
CSSEdgeTop,
|
||||
CSSEdgeRight,
|
||||
CSSEdgeBottom,
|
||||
CSSEdgeStart,
|
||||
CSSEdgeEnd,
|
||||
CSSEdgeHorizontal,
|
||||
CSSEdgeVertical,
|
||||
CSSEdgeAll,
|
||||
CSSEdgeCount,
|
||||
} CSSEdge;
|
||||
|
||||
typedef enum CSSWrap {
|
||||
CSSWrapNoWrap,
|
||||
CSSWrapWrap,
|
||||
CSSWrapCount,
|
||||
} CSSWrap;
|
||||
|
||||
typedef enum CSSDirection {
|
||||
CSSDirectionInherit,
|
||||
CSSDirectionLTR,
|
||||
CSSDirectionRTL,
|
||||
CSSDirectionCount,
|
||||
} CSSDirection;
|
||||
|
||||
typedef enum CSSExperimentalFeature {
|
||||
CSSExperimentalFeatureCount,
|
||||
} CSSExperimentalFeature;
|
||||
|
||||
typedef enum CSSLogLevel {
|
||||
CSSLogLevelError,
|
||||
CSSLogLevelWarn,
|
||||
CSSLogLevelInfo,
|
||||
CSSLogLevelDebug,
|
||||
CSSLogLevelVerbose,
|
||||
CSSLogLevelCount,
|
||||
} CSSLogLevel;
|
||||
|
||||
typedef enum CSSDimension {
|
||||
CSSDimensionWidth,
|
||||
CSSDimensionHeight,
|
||||
CSSDimensionCount,
|
||||
} CSSDimension;
|
||||
|
||||
typedef enum CSSMeasureMode {
|
||||
CSSMeasureModeUndefined,
|
||||
CSSMeasureModeExactly,
|
||||
CSSMeasureModeAtMost,
|
||||
CSSMeasureModeCount,
|
||||
} CSSMeasureMode;
|
||||
|
||||
typedef enum CSSPositionType {
|
||||
CSSPositionTypeRelative,
|
||||
CSSPositionTypeAbsolute,
|
||||
CSSPositionTypeCount,
|
||||
} CSSPositionType;
|
||||
|
||||
typedef enum CSSPrintOptions {
|
||||
CSSPrintOptionsLayout = 1,
|
||||
CSSPrintOptionsStyle = 2,
|
||||
CSSPrintOptionsChildren = 4,
|
||||
CSSPrintOptionsCount,
|
||||
} CSSPrintOptions;
|
2566
CSSLayout/CSSLayout.c
Normal file
2566
CSSLayout/CSSLayout.c
Normal file
File diff suppressed because it is too large
Load Diff
172
CSSLayout/CSSLayout.h
Normal file
172
CSSLayout/CSSLayout.h
Normal file
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
// Not defined in MSVC++
|
||||
#ifndef NAN
|
||||
static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
|
||||
#define NAN (*(const float *) __nan)
|
||||
#endif
|
||||
|
||||
#define CSSUndefined NAN
|
||||
|
||||
#include "CSSEnums.h"
|
||||
#include "CSSMacros.h"
|
||||
|
||||
CSS_EXTERN_C_BEGIN
|
||||
|
||||
typedef struct CSSSize {
|
||||
float width;
|
||||
float height;
|
||||
} CSSSize;
|
||||
|
||||
typedef struct CSSNode *CSSNodeRef;
|
||||
typedef CSSSize (*CSSMeasureFunc)(CSSNodeRef node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode);
|
||||
typedef void (*CSSPrintFunc)(CSSNodeRef node);
|
||||
typedef int (*CSSLogger)(CSSLogLevel level, const char *format, va_list args);
|
||||
|
||||
typedef void *(*CSSMalloc)(size_t size);
|
||||
typedef void *(*CSSCalloc)(size_t count, size_t size);
|
||||
typedef void *(*CSSRealloc)(void *ptr, size_t size);
|
||||
typedef void (*CSSFree)(void *ptr);
|
||||
|
||||
// CSSNode
|
||||
WIN_EXPORT CSSNodeRef CSSNodeNew(void);
|
||||
WIN_EXPORT void CSSNodeInit(const CSSNodeRef node);
|
||||
WIN_EXPORT void CSSNodeFree(const CSSNodeRef node);
|
||||
WIN_EXPORT void CSSNodeFreeRecursive(const CSSNodeRef node);
|
||||
WIN_EXPORT void CSSNodeReset(const CSSNodeRef node);
|
||||
WIN_EXPORT int32_t CSSNodeGetInstanceCount(void);
|
||||
|
||||
WIN_EXPORT void CSSNodeInsertChild(const CSSNodeRef node,
|
||||
const CSSNodeRef child,
|
||||
const uint32_t index);
|
||||
WIN_EXPORT void CSSNodeRemoveChild(const CSSNodeRef node, const CSSNodeRef child);
|
||||
WIN_EXPORT CSSNodeRef CSSNodeGetChild(const CSSNodeRef node, const uint32_t index);
|
||||
WIN_EXPORT uint32_t CSSNodeChildCount(const CSSNodeRef node);
|
||||
|
||||
WIN_EXPORT void CSSNodeCalculateLayout(const CSSNodeRef node,
|
||||
const float availableWidth,
|
||||
const float availableHeight,
|
||||
const CSSDirection parentDirection);
|
||||
|
||||
// Mark a node as dirty. Only valid for nodes with a custom measure function
|
||||
// set.
|
||||
// CSSLayout knows when to mark all other nodes as dirty but because nodes with
|
||||
// measure functions
|
||||
// depends on information not known to CSSLayout they must perform this dirty
|
||||
// marking manually.
|
||||
WIN_EXPORT void CSSNodeMarkDirty(const CSSNodeRef node);
|
||||
WIN_EXPORT bool CSSNodeIsDirty(const CSSNodeRef node);
|
||||
|
||||
WIN_EXPORT void CSSNodePrint(const CSSNodeRef node, const CSSPrintOptions options);
|
||||
|
||||
WIN_EXPORT bool CSSValueIsUndefined(const float value);
|
||||
|
||||
WIN_EXPORT bool CSSNodeCanUseCachedMeasurement(const CSSMeasureMode widthMode,
|
||||
const float width,
|
||||
const CSSMeasureMode heightMode,
|
||||
const float height,
|
||||
const CSSMeasureMode lastWidthMode,
|
||||
const float lastWidth,
|
||||
const CSSMeasureMode lastHeightMode,
|
||||
const float lastHeight,
|
||||
const float lastComputedWidth,
|
||||
const float lastComputedHeight,
|
||||
const float marginRow,
|
||||
const float marginColumn);
|
||||
|
||||
WIN_EXPORT void CSSNodeCopyStyle(const CSSNodeRef dstNode, const CSSNodeRef srcNode);
|
||||
|
||||
#define CSS_NODE_PROPERTY(type, name, paramName) \
|
||||
WIN_EXPORT void CSSNodeSet##name(const CSSNodeRef node, type paramName); \
|
||||
WIN_EXPORT type CSSNodeGet##name(const CSSNodeRef node);
|
||||
|
||||
#define CSS_NODE_STYLE_PROPERTY(type, name, paramName) \
|
||||
WIN_EXPORT void CSSNodeStyleSet##name(const CSSNodeRef node, const type paramName); \
|
||||
WIN_EXPORT type CSSNodeStyleGet##name(const CSSNodeRef node);
|
||||
|
||||
#define CSS_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
|
||||
WIN_EXPORT void CSSNodeStyleSet##name(const CSSNodeRef node, \
|
||||
const CSSEdge edge, \
|
||||
const type paramName); \
|
||||
WIN_EXPORT type CSSNodeStyleGet##name(const CSSNodeRef node, const CSSEdge edge);
|
||||
|
||||
#define CSS_NODE_LAYOUT_PROPERTY(type, name) \
|
||||
WIN_EXPORT type CSSNodeLayoutGet##name(const CSSNodeRef node);
|
||||
|
||||
CSS_NODE_PROPERTY(void *, Context, context);
|
||||
CSS_NODE_PROPERTY(CSSMeasureFunc, MeasureFunc, measureFunc);
|
||||
CSS_NODE_PROPERTY(CSSPrintFunc, PrintFunc, printFunc);
|
||||
CSS_NODE_PROPERTY(bool, HasNewLayout, hasNewLayout);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY(CSSDirection, Direction, direction);
|
||||
CSS_NODE_STYLE_PROPERTY(CSSFlexDirection, FlexDirection, flexDirection);
|
||||
CSS_NODE_STYLE_PROPERTY(CSSJustify, JustifyContent, justifyContent);
|
||||
CSS_NODE_STYLE_PROPERTY(CSSAlign, AlignContent, alignContent);
|
||||
CSS_NODE_STYLE_PROPERTY(CSSAlign, AlignItems, alignItems);
|
||||
CSS_NODE_STYLE_PROPERTY(CSSAlign, AlignSelf, alignSelf);
|
||||
CSS_NODE_STYLE_PROPERTY(CSSPositionType, PositionType, positionType);
|
||||
CSS_NODE_STYLE_PROPERTY(CSSWrap, FlexWrap, flexWrap);
|
||||
CSS_NODE_STYLE_PROPERTY(CSSOverflow, Overflow, overflow);
|
||||
|
||||
WIN_EXPORT void CSSNodeStyleSetFlex(const CSSNodeRef node, const float flex);
|
||||
CSS_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow);
|
||||
CSS_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
|
||||
CSS_NODE_STYLE_PROPERTY(float, FlexBasis, flexBasis);
|
||||
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY(float, Position, position);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY(float, Margin, margin);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY(float, Padding, padding);
|
||||
CSS_NODE_STYLE_EDGE_PROPERTY(float, Border, border);
|
||||
|
||||
CSS_NODE_STYLE_PROPERTY(float, Width, width);
|
||||
CSS_NODE_STYLE_PROPERTY(float, Height, height);
|
||||
CSS_NODE_STYLE_PROPERTY(float, MinWidth, minWidth);
|
||||
CSS_NODE_STYLE_PROPERTY(float, MinHeight, minHeight);
|
||||
CSS_NODE_STYLE_PROPERTY(float, MaxWidth, maxWidth);
|
||||
CSS_NODE_STYLE_PROPERTY(float, MaxHeight, maxHeight);
|
||||
|
||||
CSS_NODE_LAYOUT_PROPERTY(float, Left);
|
||||
CSS_NODE_LAYOUT_PROPERTY(float, Top);
|
||||
CSS_NODE_LAYOUT_PROPERTY(float, Right);
|
||||
CSS_NODE_LAYOUT_PROPERTY(float, Bottom);
|
||||
CSS_NODE_LAYOUT_PROPERTY(float, Width);
|
||||
CSS_NODE_LAYOUT_PROPERTY(float, Height);
|
||||
CSS_NODE_LAYOUT_PROPERTY(CSSDirection, Direction);
|
||||
|
||||
WIN_EXPORT void CSSLayoutSetLogger(CSSLogger logger);
|
||||
WIN_EXPORT void CSSLog(CSSLogLevel level, const char *message, ...);
|
||||
|
||||
WIN_EXPORT void CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeature feature,
|
||||
bool enabled);
|
||||
WIN_EXPORT bool CSSLayoutIsExperimentalFeatureEnabled(CSSExperimentalFeature feature);
|
||||
|
||||
WIN_EXPORT void CSSLayoutSetMemoryFuncs(CSSMalloc cssMalloc,
|
||||
CSSCalloc cssCalloc,
|
||||
CSSRealloc cssRealloc,
|
||||
CSSFree cssFree);
|
||||
|
||||
CSS_EXTERN_C_END
|
42
CSSLayout/CSSMacros.h
Normal file
42
CSSLayout/CSSMacros.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define CSS_EXTERN_C_BEGIN extern "C" {
|
||||
#define CSS_EXTERN_C_END }
|
||||
#else
|
||||
#define CSS_EXTERN_C_BEGIN
|
||||
#define CSS_EXTERN_C_END
|
||||
#endif
|
||||
|
||||
#ifdef _WINDLL
|
||||
#define WIN_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define WIN_EXPORT
|
||||
#endif
|
||||
|
||||
#ifndef FB_ASSERTIONS_ENABLED
|
||||
#define FB_ASSERTIONS_ENABLED 1
|
||||
#endif
|
||||
|
||||
#if FB_ASSERTIONS_ENABLED
|
||||
#define CSS_ABORT() abort()
|
||||
#else
|
||||
#define CSS_ABORT()
|
||||
#endif
|
||||
|
||||
#ifndef CSS_ASSERT
|
||||
#define CSS_ASSERT(X, message) \
|
||||
if (!(X)) { \
|
||||
CSSLog(CSSLogLevelError, "%s", message); \
|
||||
CSS_ABORT(); \
|
||||
}
|
||||
#endif
|
104
CSSLayout/CSSNodeList.c
Normal file
104
CSSLayout/CSSNodeList.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#include "CSSNodeList.h"
|
||||
|
||||
extern CSSMalloc gCSSMalloc;
|
||||
extern CSSRealloc gCSSRealloc;
|
||||
extern CSSFree gCSSFree;
|
||||
|
||||
struct CSSNodeList {
|
||||
uint32_t capacity;
|
||||
uint32_t count;
|
||||
CSSNodeRef *items;
|
||||
};
|
||||
|
||||
CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity) {
|
||||
const CSSNodeListRef list = gCSSMalloc(sizeof(struct CSSNodeList));
|
||||
CSS_ASSERT(list != NULL, "Could not allocate memory for list");
|
||||
|
||||
list->capacity = initialCapacity;
|
||||
list->count = 0;
|
||||
list->items = gCSSMalloc(sizeof(CSSNodeRef) * list->capacity);
|
||||
CSS_ASSERT(list->items != NULL, "Could not allocate memory for items");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void CSSNodeListFree(const CSSNodeListRef list) {
|
||||
if (list) {
|
||||
gCSSFree(list->items);
|
||||
gCSSFree(list);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t CSSNodeListCount(const CSSNodeListRef list) {
|
||||
if (list) {
|
||||
return list->count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CSSNodeListAdd(CSSNodeListRef *listp, const CSSNodeRef node) {
|
||||
if (!*listp) {
|
||||
*listp = CSSNodeListNew(4);
|
||||
}
|
||||
CSSNodeListInsert(listp, node, (*listp)->count);
|
||||
}
|
||||
|
||||
void CSSNodeListInsert(CSSNodeListRef *listp, const CSSNodeRef node, const uint32_t index) {
|
||||
if (!*listp) {
|
||||
*listp = CSSNodeListNew(4);
|
||||
}
|
||||
CSSNodeListRef list = *listp;
|
||||
|
||||
if (list->count == list->capacity) {
|
||||
list->capacity *= 2;
|
||||
list->items = gCSSRealloc(list->items, sizeof(CSSNodeRef) * list->capacity);
|
||||
CSS_ASSERT(list->items != NULL, "Could not extend allocation for items");
|
||||
}
|
||||
|
||||
for (uint32_t i = list->count; i > index; i--) {
|
||||
list->items[i] = list->items[i - 1];
|
||||
}
|
||||
|
||||
list->count++;
|
||||
list->items[index] = node;
|
||||
}
|
||||
|
||||
CSSNodeRef CSSNodeListRemove(const CSSNodeListRef list, const uint32_t index) {
|
||||
const CSSNodeRef removed = list->items[index];
|
||||
list->items[index] = NULL;
|
||||
|
||||
for (uint32_t i = index; i < list->count - 1; i++) {
|
||||
list->items[i] = list->items[i + 1];
|
||||
list->items[i + 1] = NULL;
|
||||
}
|
||||
|
||||
list->count--;
|
||||
return removed;
|
||||
}
|
||||
|
||||
CSSNodeRef CSSNodeListDelete(const CSSNodeListRef list, const CSSNodeRef node) {
|
||||
for (uint32_t i = 0; i < list->count; i++) {
|
||||
if (list->items[i] == node) {
|
||||
return CSSNodeListRemove(list, i);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CSSNodeRef CSSNodeListGet(const CSSNodeListRef list, const uint32_t index) {
|
||||
if (CSSNodeListCount(list) > 0) {
|
||||
return list->items[index];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
33
CSSLayout/CSSNodeList.h
Normal file
33
CSSLayout/CSSNodeList.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "CSSLayout.h"
|
||||
#include "CSSMacros.h"
|
||||
|
||||
CSS_EXTERN_C_BEGIN
|
||||
|
||||
typedef struct CSSNodeList *CSSNodeListRef;
|
||||
|
||||
CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity);
|
||||
void CSSNodeListFree(const CSSNodeListRef list);
|
||||
uint32_t CSSNodeListCount(const CSSNodeListRef list);
|
||||
void CSSNodeListAdd(CSSNodeListRef *listp, const CSSNodeRef node);
|
||||
void CSSNodeListInsert(CSSNodeListRef *listp, const CSSNodeRef node, const uint32_t index);
|
||||
CSSNodeRef CSSNodeListRemove(const CSSNodeListRef list, const uint32_t index);
|
||||
CSSNodeRef CSSNodeListDelete(const CSSNodeListRef list, const CSSNodeRef node);
|
||||
CSSNodeRef CSSNodeListGet(const CSSNodeListRef list, const uint32_t index);
|
||||
|
||||
CSS_EXTERN_C_END
|
59
CSSLayoutKit/BUCK
Normal file
59
CSSLayoutKit/BUCK
Normal file
@@ -0,0 +1,59 @@
|
||||
# Copyright (c) 2014-present, Facebook, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the BSD-style license found in the
|
||||
# LICENSE file in the root directory of this source tree. An additional grant
|
||||
# of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
include_defs('//CSSLAYOUT_DEFS')
|
||||
|
||||
UIKIT_CSSLAYOUT_COMPILER_FLAGS = [
|
||||
'-fobjc-arc',
|
||||
'-Wconditional-uninitialized',
|
||||
'-Wdangling-else',
|
||||
'-Wdeprecated-declarations',
|
||||
'-Wimplicit-retain-self',
|
||||
'-Wincomplete-implementation',
|
||||
'-Wobjc-method-access',
|
||||
'-Wobjc-missing-super-calls',
|
||||
'-Wmismatched-return-types',
|
||||
'-Wreturn-type',
|
||||
'-Wno-global-constructors',
|
||||
'-Wno-shadow',
|
||||
'-Wunused-const-variable',
|
||||
'-Wunused-function',
|
||||
'-Wunused-property-ivar',
|
||||
'-Wunused-result',
|
||||
'-Wunused-value',
|
||||
]
|
||||
|
||||
apple_library(
|
||||
name = 'CSSLayoutKit',
|
||||
compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS,
|
||||
tests = [':CSSLayoutKitTests'],
|
||||
srcs = glob(['*.m']),
|
||||
exported_headers = glob(['*.h']),
|
||||
frameworks = [
|
||||
'$SDKROOT/System/Library/Frameworks/Foundation.framework',
|
||||
'$SDKROOT/System/Library/Frameworks/UIKit.framework',
|
||||
],
|
||||
deps = [
|
||||
csslayout_dep(':CSSLayout'),
|
||||
],
|
||||
visibility = ['PUBLIC'],
|
||||
)
|
||||
|
||||
apple_test(
|
||||
name = 'CSSLayoutKitTests',
|
||||
compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS,
|
||||
info_plist = 'Tests/Info.plist',
|
||||
srcs = glob(['Tests/**/*.m']),
|
||||
frameworks = [
|
||||
'$SDKROOT/System/Library/Frameworks/CoreGraphics.framework',
|
||||
'$PLATFORM_DIR/Developer/Library/Frameworks/XCTest.framework',
|
||||
],
|
||||
deps = [
|
||||
':CSSLayoutKit',
|
||||
],
|
||||
visibility = ['PUBLIC'],
|
||||
)
|
202
CSSLayoutKit/Tests/CSSLayoutKitTests.m
Normal file
202
CSSLayoutKit/Tests/CSSLayoutKitTests.m
Normal file
@@ -0,0 +1,202 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "UIView+CSSLayout.h"
|
||||
|
||||
@interface CSSLayoutKitTests : XCTestCase
|
||||
@end
|
||||
|
||||
@implementation CSSLayoutKitTests
|
||||
|
||||
#ifndef TRAVIS_CI
|
||||
|
||||
- (void)testNodesAreDeallocedWithSingleView
|
||||
{
|
||||
XCTAssertEqual(0, CSSNodeGetInstanceCount());
|
||||
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[view css_setFlexBasis:1];
|
||||
XCTAssertEqual(1, CSSNodeGetInstanceCount());
|
||||
view = nil;
|
||||
|
||||
XCTAssertEqual(0, CSSNodeGetInstanceCount());
|
||||
}
|
||||
|
||||
- (void)testNodesAreDeallocedCascade
|
||||
{
|
||||
XCTAssertEqual(0, CSSNodeGetInstanceCount());
|
||||
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[view css_setFlexBasis:1];
|
||||
|
||||
for (int i=0; i<10; i++) {
|
||||
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[subview css_setFlexBasis:1];
|
||||
[view addSubview:subview];
|
||||
}
|
||||
XCTAssertEqual(11, CSSNodeGetInstanceCount());
|
||||
view = nil;
|
||||
|
||||
XCTAssertEqual(0, CSSNodeGetInstanceCount());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
- (void)testUsesFlexbox
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
XCTAssertFalse([view css_usesFlexbox]);
|
||||
|
||||
[view css_setUsesFlexbox:YES];
|
||||
XCTAssertTrue([view css_usesFlexbox]);
|
||||
|
||||
[view css_setUsesFlexbox:NO];
|
||||
XCTAssertFalse([view css_usesFlexbox]);
|
||||
}
|
||||
|
||||
- (void)testSizeThatFitsAsserts
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
dispatch_sync(dispatch_queue_create("com.facebook.CSSLayout.testing", DISPATCH_QUEUE_SERIAL), ^(void){
|
||||
XCTAssertThrows([view css_intrinsicSize]);
|
||||
});
|
||||
}
|
||||
|
||||
- (void)testSizeThatFitsSmoke
|
||||
{
|
||||
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[container css_setUsesFlexbox:YES];
|
||||
[container css_setFlexDirection:CSSFlexDirectionRow];
|
||||
[container css_setAlignItems:CSSAlignFlexStart];
|
||||
|
||||
UILabel *longTextLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
longTextLabel.text = @"This is a very very very very very very very very long piece of text.";
|
||||
longTextLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
||||
longTextLabel.numberOfLines = 1;
|
||||
[longTextLabel css_setUsesFlexbox:YES];
|
||||
[longTextLabel css_setFlexShrink:1];
|
||||
[container addSubview:longTextLabel];
|
||||
|
||||
UIView *textBadgeView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[textBadgeView css_setUsesFlexbox:YES];
|
||||
[textBadgeView css_setMargin:3.0 forEdge:CSSEdgeLeft];
|
||||
[textBadgeView css_setWidth:10];
|
||||
[textBadgeView css_setHeight:10];
|
||||
[container addSubview:textBadgeView];
|
||||
|
||||
const CGSize containerSize = [container css_intrinsicSize];
|
||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(514,21), containerSize), @"Size is actually %@", NSStringFromCGSize(containerSize));
|
||||
}
|
||||
|
||||
- (void)testFrameAndOriginPlacement
|
||||
{
|
||||
const CGSize containerSize = CGSizeMake(320, 50);
|
||||
|
||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
|
||||
[container css_setUsesFlexbox:YES];
|
||||
[container css_setFlexDirection:CSSFlexDirectionRow];
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[subview css_setUsesFlexbox:YES];
|
||||
[subview css_setFlexGrow:1];
|
||||
|
||||
[container addSubview:subview];
|
||||
}
|
||||
[container css_applyLayout];
|
||||
|
||||
XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:0].frame, [container.subviews objectAtIndex:1].frame));
|
||||
XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:1].frame, [container.subviews objectAtIndex:2].frame));
|
||||
XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:0].frame, [container.subviews objectAtIndex:2].frame));
|
||||
|
||||
CGFloat totalWidth = 0;
|
||||
for (UIView *view in container.subviews) {
|
||||
totalWidth += view.bounds.size.width;
|
||||
}
|
||||
|
||||
XCTAssertEqual(containerSize.width, totalWidth, @"The container's width is %.6f, the subviews take up %.6f", containerSize.width, totalWidth);
|
||||
}
|
||||
|
||||
- (void)testThatWeRespectIncludeInLayoutFlag
|
||||
{
|
||||
const CGSize containerSize = CGSizeMake(300, 50);
|
||||
|
||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
|
||||
[container css_setUsesFlexbox:YES];
|
||||
[container css_setFlexDirection:CSSFlexDirectionRow];
|
||||
|
||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[subview1 css_setUsesFlexbox:YES];
|
||||
[subview1 css_setFlexGrow:1];
|
||||
[container addSubview:subview1];
|
||||
|
||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[subview2 css_setUsesFlexbox:YES];
|
||||
[subview2 css_setFlexGrow:1];
|
||||
[container addSubview:subview2];
|
||||
|
||||
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[subview3 css_setUsesFlexbox:YES];
|
||||
[subview3 css_setFlexGrow:1];
|
||||
[container addSubview:subview3];
|
||||
|
||||
[container css_applyLayout];
|
||||
|
||||
for (UIView *view in container.subviews) {
|
||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(view.bounds.size));
|
||||
}
|
||||
|
||||
[subview3 css_setIncludeInLayout:NO];
|
||||
[container css_applyLayout];
|
||||
|
||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size));
|
||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size));
|
||||
|
||||
// We don't set the frame to zero, so, it should be set to what it was previously at.
|
||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview3.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview3.bounds.size));
|
||||
}
|
||||
|
||||
- (void)testThatViewNotIncludedInFirstLayoutPassAreIncludedInSecond
|
||||
{
|
||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
|
||||
[container css_setUsesFlexbox:YES];
|
||||
[container css_setFlexDirection:CSSFlexDirectionRow];
|
||||
|
||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[subview1 css_setUsesFlexbox:YES];
|
||||
[subview1 css_setFlexGrow:1];
|
||||
[container addSubview:subview1];
|
||||
|
||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[subview2 css_setUsesFlexbox:YES];
|
||||
[subview2 css_setFlexGrow:1];
|
||||
[container addSubview:subview2];
|
||||
|
||||
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
[subview3 css_setUsesFlexbox:YES];
|
||||
[subview3 css_setFlexGrow:1];
|
||||
[subview3 css_setIncludeInLayout:NO];
|
||||
[container addSubview:subview3];
|
||||
|
||||
[container css_applyLayout];
|
||||
|
||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size));
|
||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size));
|
||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeZero, subview3.bounds.size), @"Actual size %@", NSStringFromCGSize(subview3.bounds.size));
|
||||
|
||||
[subview3 css_setIncludeInLayout:YES];
|
||||
[container css_applyLayout];
|
||||
for (UIView *view in container.subviews) {
|
||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(view.bounds.size));
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
22
CSSLayoutKit/Tests/Info.plist
Normal file
22
CSSLayoutKit/Tests/Info.plist
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.facebook.${PRODUCT_NAME:rfc1034identifier}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
64
CSSLayoutKit/UIView+CSSLayout.h
Normal file
64
CSSLayoutKit/UIView+CSSLayout.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CSSLayout/CSSLayout.h>
|
||||
|
||||
@interface UIView (CSSLayout)
|
||||
|
||||
/**
|
||||
The property that decides if we should include this view when calculating layout. Defaults to YES.
|
||||
*/
|
||||
@property (nonatomic, readwrite, assign, setter=css_setIncludeInLayout:) BOOL css_includeInLayout;
|
||||
|
||||
/**
|
||||
The property that decides during layout/sizing whether or not css_* properties should be applied. Defaults to NO.
|
||||
*/
|
||||
@property (nonatomic, readwrite, assign, setter=css_setUsesFlexbox:) BOOL css_usesFlexbox;
|
||||
|
||||
- (void)css_setDirection:(CSSDirection)direction;
|
||||
- (void)css_setFlexDirection:(CSSFlexDirection)flexDirection;
|
||||
- (void)css_setJustifyContent:(CSSJustify)justifyContent;
|
||||
- (void)css_setAlignContent:(CSSAlign)alignContent;
|
||||
- (void)css_setAlignItems:(CSSAlign)alignItems;
|
||||
- (void)css_setAlignSelf:(CSSAlign)alignSelf;
|
||||
- (void)css_setPositionType:(CSSPositionType)positionType;
|
||||
- (void)css_setFlexWrap:(CSSWrap)flexWrap;
|
||||
|
||||
- (void)css_setFlexGrow:(CGFloat)flexGrow;
|
||||
- (void)css_setFlexShrink:(CGFloat)flexShrink;
|
||||
- (void)css_setFlexBasis:(CGFloat)flexBasis;
|
||||
|
||||
- (void)css_setPosition:(CGFloat)position forEdge:(CSSEdge)edge;
|
||||
- (void)css_setMargin:(CGFloat)margin forEdge:(CSSEdge)edge;
|
||||
- (void)css_setPadding:(CGFloat)padding forEdge:(CSSEdge)edge;
|
||||
|
||||
- (void)css_setWidth:(CGFloat)width;
|
||||
- (void)css_setHeight:(CGFloat)height;
|
||||
- (void)css_setMinWidth:(CGFloat)minWidth;
|
||||
- (void)css_setMinHeight:(CGFloat)minHeight;
|
||||
- (void)css_setMaxWidth:(CGFloat)maxWidth;
|
||||
- (void)css_setMaxHeight:(CGFloat)maxHeight;
|
||||
|
||||
/**
|
||||
Get the resolved direction of this node. This won't be CSSDirectionInherit
|
||||
*/
|
||||
- (CSSDirection)css_resolvedDirection;
|
||||
|
||||
/**
|
||||
Perform a layout calculation and update the frames of the views in the hierarchy with th results
|
||||
*/
|
||||
- (void)css_applyLayout;
|
||||
|
||||
/**
|
||||
Returns the size of the view if no constraints were given. This could equivalent to calling [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
|
||||
*/
|
||||
- (CGSize)css_intrinsicSize;
|
||||
|
||||
@end
|
349
CSSLayoutKit/UIView+CSSLayout.m
Normal file
349
CSSLayoutKit/UIView+CSSLayout.m
Normal file
@@ -0,0 +1,349 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import "UIView+CSSLayout.h"
|
||||
|
||||
#import <objc/runtime.h>
|
||||
|
||||
@interface CSSNodeBridge : NSObject
|
||||
@property (nonatomic, assign, readonly) CSSNodeRef cnode;
|
||||
@end
|
||||
|
||||
@implementation CSSNodeBridge
|
||||
- (instancetype)init
|
||||
{
|
||||
if ([super init]) {
|
||||
_cnode = CSSNodeNew();
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
CSSNodeFree(_cnode);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation UIView (CSSLayout)
|
||||
|
||||
- (BOOL)css_usesFlexbox
|
||||
{
|
||||
NSNumber *usesFlexbox = objc_getAssociatedObject(self, @selector(css_usesFlexbox));
|
||||
return [usesFlexbox boolValue];
|
||||
}
|
||||
|
||||
- (BOOL)css_includeInLayout
|
||||
{
|
||||
NSNumber *includeInLayout = objc_getAssociatedObject(self, @selector(css_includeInLayout));
|
||||
return (includeInLayout != nil) ? [includeInLayout boolValue] : YES;
|
||||
}
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
- (void)css_setIncludeInLayout:(BOOL)includeInLayout
|
||||
{
|
||||
objc_setAssociatedObject(
|
||||
self,
|
||||
@selector(css_includeInLayout),
|
||||
@(includeInLayout),
|
||||
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
- (void)css_setUsesFlexbox:(BOOL)enabled
|
||||
{
|
||||
objc_setAssociatedObject(
|
||||
self,
|
||||
@selector(css_usesFlexbox),
|
||||
@(enabled),
|
||||
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
- (void)css_setDirection:(CSSDirection)direction
|
||||
{
|
||||
CSSNodeStyleSetDirection([self cssNode], direction);
|
||||
}
|
||||
|
||||
- (void)css_setFlexDirection:(CSSFlexDirection)flexDirection
|
||||
{
|
||||
CSSNodeStyleSetFlexDirection([self cssNode], flexDirection);
|
||||
}
|
||||
|
||||
- (void)css_setJustifyContent:(CSSJustify)justifyContent
|
||||
{
|
||||
CSSNodeStyleSetJustifyContent([self cssNode], justifyContent);
|
||||
}
|
||||
|
||||
- (void)css_setAlignContent:(CSSAlign)alignContent
|
||||
{
|
||||
CSSNodeStyleSetAlignContent([self cssNode], alignContent);
|
||||
}
|
||||
|
||||
- (void)css_setAlignItems:(CSSAlign)alignItems
|
||||
{
|
||||
CSSNodeStyleSetAlignItems([self cssNode], alignItems);
|
||||
}
|
||||
|
||||
- (void)css_setAlignSelf:(CSSAlign)alignSelf
|
||||
{
|
||||
CSSNodeStyleSetAlignSelf([self cssNode], alignSelf);
|
||||
}
|
||||
|
||||
- (void)css_setPositionType:(CSSPositionType)positionType
|
||||
{
|
||||
CSSNodeStyleSetPositionType([self cssNode], positionType);
|
||||
}
|
||||
|
||||
- (void)css_setFlexWrap:(CSSWrap)flexWrap
|
||||
{
|
||||
CSSNodeStyleSetFlexWrap([self cssNode], flexWrap);
|
||||
}
|
||||
|
||||
- (void)css_setFlexGrow:(CGFloat)flexGrow
|
||||
{
|
||||
CSSNodeStyleSetFlexGrow([self cssNode], flexGrow);
|
||||
}
|
||||
|
||||
- (void)css_setFlexShrink:(CGFloat)flexShrink
|
||||
{
|
||||
CSSNodeStyleSetFlexShrink([self cssNode], flexShrink);
|
||||
}
|
||||
|
||||
- (void)css_setFlexBasis:(CGFloat)flexBasis
|
||||
{
|
||||
CSSNodeStyleSetFlexBasis([self cssNode], flexBasis);
|
||||
}
|
||||
|
||||
- (void)css_setPosition:(CGFloat)position forEdge:(CSSEdge)edge
|
||||
{
|
||||
CSSNodeStyleSetPosition([self cssNode], edge, position);
|
||||
}
|
||||
|
||||
- (void)css_setMargin:(CGFloat)margin forEdge:(CSSEdge)edge
|
||||
{
|
||||
CSSNodeStyleSetMargin([self cssNode], edge, margin);
|
||||
}
|
||||
|
||||
- (void)css_setPadding:(CGFloat)padding forEdge:(CSSEdge)edge
|
||||
{
|
||||
CSSNodeStyleSetPadding([self cssNode], edge, padding);
|
||||
}
|
||||
|
||||
- (void)css_setWidth:(CGFloat)width
|
||||
{
|
||||
CSSNodeStyleSetWidth([self cssNode], width);
|
||||
}
|
||||
|
||||
- (void)css_setHeight:(CGFloat)height
|
||||
{
|
||||
CSSNodeStyleSetHeight([self cssNode], height);
|
||||
}
|
||||
|
||||
- (void)css_setMinWidth:(CGFloat)minWidth
|
||||
{
|
||||
CSSNodeStyleSetMinWidth([self cssNode], minWidth);
|
||||
}
|
||||
|
||||
- (void)css_setMinHeight:(CGFloat)minHeight
|
||||
{
|
||||
CSSNodeStyleSetMinHeight([self cssNode], minHeight);
|
||||
}
|
||||
|
||||
- (void)css_setMaxWidth:(CGFloat)maxWidth
|
||||
{
|
||||
CSSNodeStyleSetMaxWidth([self cssNode], maxWidth);
|
||||
}
|
||||
|
||||
- (void)css_setMaxHeight:(CGFloat)maxHeight
|
||||
{
|
||||
CSSNodeStyleSetMaxHeight([self cssNode], maxHeight);
|
||||
}
|
||||
|
||||
#pragma mark - Layout and Sizing
|
||||
|
||||
- (CSSDirection)css_resolvedDirection
|
||||
{
|
||||
return CSSNodeLayoutGetDirection([self cssNode]);
|
||||
}
|
||||
|
||||
- (void)css_applyLayout
|
||||
{
|
||||
[self calculateLayoutWithSize:self.bounds.size];
|
||||
CSSApplyLayoutToViewHierarchy(self);
|
||||
}
|
||||
|
||||
- (CGSize)css_intrinsicSize
|
||||
{
|
||||
const CGSize constrainedSize = {
|
||||
.width = CSSUndefined,
|
||||
.height = CSSUndefined,
|
||||
};
|
||||
return [self calculateLayoutWithSize:constrainedSize];
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
- (CSSNodeRef)cssNode
|
||||
{
|
||||
CSSNodeBridge *node = objc_getAssociatedObject(self, @selector(cssNode));
|
||||
if (!node) {
|
||||
node = [CSSNodeBridge new];
|
||||
CSSNodeSetContext(node.cnode, (__bridge void *) self);
|
||||
objc_setAssociatedObject(self, @selector(cssNode), node, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
return node.cnode;
|
||||
}
|
||||
|
||||
- (CGSize)calculateLayoutWithSize:(CGSize)size
|
||||
{
|
||||
NSAssert([NSThread isMainThread], @"CSS Layout calculation must be done on main.");
|
||||
NSAssert([self css_usesFlexbox], @"CSS Layout is not enabled for this view.");
|
||||
|
||||
CSSAttachNodesFromViewHierachy(self);
|
||||
|
||||
const CSSNodeRef node = [self cssNode];
|
||||
CSSNodeCalculateLayout(
|
||||
node,
|
||||
size.width,
|
||||
size.height,
|
||||
CSSNodeStyleGetDirection(node));
|
||||
|
||||
return (CGSize) {
|
||||
.width = CSSNodeLayoutGetWidth(node),
|
||||
.height = CSSNodeLayoutGetHeight(node),
|
||||
};
|
||||
}
|
||||
|
||||
static CSSSize CSSMeasureView(
|
||||
CSSNodeRef node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode)
|
||||
{
|
||||
const CGFloat constrainedWidth = (widthMode == CSSMeasureModeUndefined) ? CGFLOAT_MAX : width;
|
||||
const CGFloat constrainedHeight = (heightMode == CSSMeasureModeUndefined) ? CGFLOAT_MAX: height;
|
||||
|
||||
UIView *view = (__bridge UIView*) CSSNodeGetContext(node);
|
||||
const CGSize sizeThatFits = [view sizeThatFits:(CGSize) {
|
||||
.width = constrainedWidth,
|
||||
.height = constrainedHeight,
|
||||
}];
|
||||
|
||||
return (CSSSize) {
|
||||
.width = CSSSanitizeMeasurement(constrainedWidth, sizeThatFits.width, widthMode),
|
||||
.height = CSSSanitizeMeasurement(constrainedHeight, sizeThatFits.height, heightMode),
|
||||
};
|
||||
}
|
||||
|
||||
static CGFloat CSSSanitizeMeasurement(
|
||||
CGFloat constrainedSize,
|
||||
CGFloat measuredSize,
|
||||
CSSMeasureMode measureMode)
|
||||
{
|
||||
CGFloat result;
|
||||
if (measureMode == CSSMeasureModeExactly) {
|
||||
result = constrainedSize;
|
||||
} else if (measureMode == CSSMeasureModeAtMost) {
|
||||
result = MIN(constrainedSize, measuredSize);
|
||||
} else {
|
||||
result = measuredSize;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void CSSAttachNodesFromViewHierachy(UIView *view) {
|
||||
CSSNodeRef node = [view cssNode];
|
||||
const BOOL usesFlexbox = [view css_usesFlexbox];
|
||||
const BOOL isLeaf = !usesFlexbox || view.subviews.count == 0;
|
||||
|
||||
// Only leaf nodes should have a measure function
|
||||
if (isLeaf) {
|
||||
CSSNodeSetMeasureFunc(node, CSSMeasureView);
|
||||
|
||||
// Clear any children
|
||||
while (CSSNodeChildCount(node) > 0) {
|
||||
CSSNodeRemoveChild(node, CSSNodeGetChild(node, 0));
|
||||
}
|
||||
} else {
|
||||
CSSNodeSetMeasureFunc(node, NULL);
|
||||
|
||||
NSUInteger numSubviewsInLayout = 0;
|
||||
// Add any children which were added since the last call to css_applyLayout
|
||||
for (NSUInteger i = 0; i < view.subviews.count; i++) {
|
||||
UIView *const subview = view.subviews[i];
|
||||
if (![subview css_includeInLayout]) {
|
||||
continue;
|
||||
}
|
||||
numSubviewsInLayout++;
|
||||
|
||||
CSSNodeRef childNode = [subview cssNode];
|
||||
if (CSSNodeChildCount(node) < i + 1 || CSSNodeGetChild(node, i) != childNode) {
|
||||
CSSNodeInsertChild(node, childNode, i);
|
||||
}
|
||||
CSSAttachNodesFromViewHierachy(subview);
|
||||
}
|
||||
|
||||
// Remove any children which were removed since the last call to css_applyLayout
|
||||
while (numSubviewsInLayout < CSSNodeChildCount(node)) {
|
||||
CSSNodeRemoveChild(node, CSSNodeGetChild(node, CSSNodeChildCount(node) - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static CGFloat CSSRoundPixelValue(CGFloat value)
|
||||
{
|
||||
static CGFloat scale;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^(){
|
||||
scale = [UIScreen mainScreen].scale;
|
||||
});
|
||||
|
||||
return round(value * scale) / scale;
|
||||
}
|
||||
|
||||
static void CSSApplyLayoutToViewHierarchy(UIView *view) {
|
||||
NSCAssert([NSThread isMainThread], @"Framesetting should only be done on the main thread.");
|
||||
if (![view css_includeInLayout]) {
|
||||
return;
|
||||
}
|
||||
|
||||
CSSNodeRef node = [view cssNode];
|
||||
const CGPoint topLeft = {
|
||||
CSSNodeLayoutGetLeft(node),
|
||||
CSSNodeLayoutGetTop(node),
|
||||
};
|
||||
|
||||
const CGPoint bottomRight = {
|
||||
topLeft.x + CSSNodeLayoutGetWidth(node),
|
||||
topLeft.y + CSSNodeLayoutGetHeight(node),
|
||||
};
|
||||
|
||||
view.frame = (CGRect) {
|
||||
.origin = {
|
||||
.x = CSSRoundPixelValue(topLeft.x),
|
||||
.y = CSSRoundPixelValue(topLeft.y),
|
||||
},
|
||||
.size = {
|
||||
.width = CSSRoundPixelValue(bottomRight.x) - CSSRoundPixelValue(topLeft.x),
|
||||
.height = CSSRoundPixelValue(bottomRight.y) - CSSRoundPixelValue(topLeft.y),
|
||||
},
|
||||
};
|
||||
|
||||
const BOOL isLeaf = ![view css_usesFlexbox] || view.subviews.count == 0;
|
||||
if (!isLeaf) {
|
||||
for (NSUInteger i = 0; i < view.subviews.count; i++) {
|
||||
CSSApplyLayoutToViewHierarchy(view.subviews[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
192
Gruntfile.js
192
Gruntfile.js
@@ -1,192 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function(grunt) {
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var isWindows = /^win/.test(process.platform);
|
||||
|
||||
require('load-grunt-tasks')(grunt);
|
||||
|
||||
// config
|
||||
var config = {
|
||||
delimiter: path.delimiter,
|
||||
libName: 'css-layout',
|
||||
distFolder: 'dist',
|
||||
srcFolder: 'src',
|
||||
testFolder: 'src/__tests__',
|
||||
javaLibFolder: 'src/java/lib',
|
||||
javaSource: 'src/java/tests/com/facebook/csslayout/*.java',
|
||||
javaTestFiles: 'org.junit.runner.JUnitCore com.facebook.csslayout.LayoutEngineTest com.facebook.csslayout.LayoutCachingTest com.facebook.csslayout.CSSNodeTest'
|
||||
};
|
||||
|
||||
// C compilation configuration
|
||||
if (isWindows) {
|
||||
// Windows build, assumes cl is in the path (see https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx).
|
||||
config.cTestOutput = 'c_test.exe';
|
||||
config.cTestCompile = 'cl -nologo -Zi -Tpsrc/__tests__/Layout-test.c -Tpsrc/Layout.c -Tpsrc/Layout-test-utils.c -link -incremental:no -out:"<%= config.cTestOutput %>"';
|
||||
config.cTestExecute = '<%= config.cTestOutput %>';
|
||||
config.cTestClean = ['<%= config.cTestOutput %>','*.obj','*.pdb'];
|
||||
}
|
||||
else {
|
||||
// GCC build (OSX, Linux, ...), assumes gcc is in the path.
|
||||
config.cTestOutput = 'c_test';
|
||||
config.cTestCompile = 'gcc -std=c99 -Werror -Wno-padded src/__tests__/Layout-test.c src/Layout.c src/Layout-test-utils.c -lm -o "./<%= config.cTestOutput %>"';
|
||||
config.cTestExecute = './<%= config.cTestOutput %>';
|
||||
config.cTestClean = ['<%= config.cTestOutput %>'];
|
||||
}
|
||||
|
||||
grunt.initConfig({
|
||||
config: config,
|
||||
|
||||
mkdir: {
|
||||
dist: {
|
||||
options: {
|
||||
create: ['<%= config.distFolder %>']
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
clean: {
|
||||
dist: ['<%= config.distFolder %>'],
|
||||
cTest: config.cTestClean,
|
||||
javaTest: ['**/*.class']
|
||||
},
|
||||
|
||||
eslint: {
|
||||
options: {
|
||||
configFile: '.eslintrc'
|
||||
},
|
||||
target: ['<%= config.srcFolder %>/Layout.js']
|
||||
},
|
||||
|
||||
includereplace: {
|
||||
options: {
|
||||
prefix: '// @@',
|
||||
},
|
||||
main: {
|
||||
src: '<%= config.srcFolder %>/<%= config.libName %>.js',
|
||||
dest: '<%= config.distFolder %>/<%= config.libName %>.js'
|
||||
}
|
||||
},
|
||||
|
||||
uglify: {
|
||||
options: {
|
||||
sourceMap: true,
|
||||
sourceMapIncludeSources: true
|
||||
},
|
||||
main: {
|
||||
files: {
|
||||
'<%= config.distFolder %>/<%= config.libName %>.min.js':
|
||||
['<%= config.distFolder %>/<%= config.libName %>.js']
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
karma: {
|
||||
main: {
|
||||
options: {
|
||||
files: [
|
||||
'<%= config.srcFolder %>/Layout.js',
|
||||
'<%= config.srcFolder %>/Layout-test-utils.js',
|
||||
'<%= config.testFolder %>/Layout-test.js',
|
||||
'<%= config.testFolder %>/Layout-consts-test.js'
|
||||
],
|
||||
browsers: ['Chrome'],
|
||||
frameworks: ['jasmine'],
|
||||
singleRun: true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
execute: {
|
||||
transpile: {
|
||||
src: ['<%= config.srcFolder %>/transpile.js']
|
||||
}
|
||||
},
|
||||
|
||||
concat: {
|
||||
options: {
|
||||
separator: '\n',
|
||||
// Replace all 'use strict' statements in the code with a single one at the top
|
||||
banner: [
|
||||
'/*',
|
||||
' * #define CSS_LAYOUT_IMPLEMENTATION',
|
||||
' * before you include this file in *one* C or C++ file to create the implementation.',
|
||||
' */\n'
|
||||
].join('\n'),
|
||||
process: function(src, filepath) {
|
||||
if (path.extname(filepath) === '.c') {
|
||||
return [
|
||||
'#ifdef CSS_LAYOUT_IMPLEMENTATION',
|
||||
src,
|
||||
'#endif // CSS_LAYOUT_IMPLEMENTATION'
|
||||
].join('\n')
|
||||
}
|
||||
else {
|
||||
return src;
|
||||
}
|
||||
},
|
||||
},
|
||||
dist: {
|
||||
src: ['<%= config.srcFolder %>/Layout.h', '<%= config.srcFolder %>/Layout.c'],
|
||||
dest: '<%= config.distFolder %>/css-layout.h',
|
||||
},
|
||||
},
|
||||
|
||||
shell: {
|
||||
cCompile: {
|
||||
command: config.cTestCompile
|
||||
},
|
||||
cTestExecute: {
|
||||
command: config.cTestExecute
|
||||
},
|
||||
javaCompile: {
|
||||
command: 'javac -cp <%= config.javaLibFolder %>/junit4.jar<%= config.delimiter %><%= config.javaLibFolder %>/jsr305.jar<%= config.delimiter %><%= config.javaLibFolder %>/infer-annotations-1.4.jar' + ' -sourcepath ./src/java/src<%= config.delimiter %>./src/java/tests' + ' <%= config.javaSource %>'
|
||||
},
|
||||
javaTestExecute: {
|
||||
command: 'java -cp ./src/java/src<%= config.delimiter %>./src/java/tests<%= config.delimiter %><%= config.javaLibFolder %>/junit4.jar<%= config.delimiter %><%= config.javaLibFolder %>/infer-annotations-1.4.jar <%= config.javaTestFiles %>'
|
||||
},
|
||||
javaPackage: {
|
||||
command: 'jar cf <%= config.distFolder %>/<%= config.libName %>.jar <%= config.javaSource %>'
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
files: ['src/Layout.js'],
|
||||
tasks: ['ci'],
|
||||
},
|
||||
});
|
||||
|
||||
// Compiles and runs the Java tests
|
||||
grunt.registerTask('test-java', ['shell:javaCompile', 'shell:javaTestExecute', 'clean:javaTest']);
|
||||
|
||||
// Compiles and runs the C tests
|
||||
grunt.registerTask('test-c', ['shell:cCompile', 'shell:cTestExecute', 'clean:cTest']);
|
||||
|
||||
// Transpiles the JavaScript to C and Java, running tests
|
||||
grunt.registerTask('transpile', ['execute:transpile', 'test-c', 'test-java']);
|
||||
|
||||
// Lints and tests the JavaScritp using Chrome
|
||||
grunt.registerTask('test-javascript', ['eslint', 'karma']);
|
||||
|
||||
// Packages the JavaScript as a single UMD module and minifies
|
||||
grunt.registerTask('package-javascript', ['includereplace', 'uglify']);
|
||||
|
||||
// Packages the Java as a JAR
|
||||
grunt.registerTask('package-java', ['shell:javaPackage']);
|
||||
|
||||
// Packages the C code as a single header
|
||||
grunt.registerTask('package-c', ['concat']);
|
||||
|
||||
// package all languages
|
||||
grunt.registerTask('package-all', ['package-javascript', 'package-java', 'package-c']);
|
||||
|
||||
// Default build, performs the full works!
|
||||
grunt.registerTask('build', ['test-javascript', 'transpile', 'clean:dist', 'mkdir:dist', 'package-all']);
|
||||
|
||||
// The JavaScript unit tests require Chrome (they need a faithful flexbox implementation
|
||||
// to test against), so under CI this step is skipped.
|
||||
grunt.registerTask('ci', ['eslint', 'transpile', 'clean:dist', 'mkdir:dist', 'package-all']);
|
||||
|
||||
grunt.registerTask('default', ['build']);
|
||||
};
|
2
LICENSE
2
LICENSE
@@ -2,7 +2,7 @@ BSD License
|
||||
|
||||
For css-layout software
|
||||
|
||||
Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||
Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
231
README.md
231
README.md
@@ -1,108 +1,16 @@
|
||||
css-layout [](https://travis-ci.org/facebook/css-layout)
|
||||
==========
|
||||
# CSSLayout [](https://travis-ci.org/facebook/css-layout)
|
||||
|
||||
This project implements a subset of CSS including flexbox and the box model using pure JavaScript, then transpiled to C and Java. The goal is to have a small standalone library to layout elements. It doesn't rely on the DOM at all.
|
||||
## Goals
|
||||
CSSLayout is a cross-platform implementation of flexbox. The goal of CSSLayout is allow native developers to have the same expressive layout system as developers developing for the modern web are used to. CSSLayout allows developers for web, android, iOS, and windows to use the same layout primitives across platforms. This saves time, increases collaboration between platform teams, and makes it easier for developers to work on multiple platforms.
|
||||
|
||||
The Java, C and JavaScript version of the code is available via [npm](https://www.npmjs.com/package/css-layout) or directly from the `dist` folder of this repo. The JavaScript version is also available via [cdnjs](https://cdnjs.com/libraries/css-layout).
|
||||
|
||||
In order to make sure that the code is correct, it is developed in JavaScript using TDD where each commit adds a unit test and the associated code to make it work. All the unit tests are tested against Chrome's implementation of CSS.
|
||||
|
||||
The JavaScript version has been implemented in a way that can be easily transpiled to C and Java via regexes. The layout function doesn't do any allocation nor uses any of the dynamic aspect of JavaScript. The tests are also transpiled to make sure that the implementations are correct everywhere.
|
||||
The goal of CSSLayout is not to re-implement all of css. CSSLayout only targets flexbox, and does not have any plans on implementing support for tables, floats, or any other css concepts. CSSLayout also does not plan on supporting styling properties which do not affect layout such as color or background properties.
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
## Differences from web
|
||||
CSSLayout tries to stay as close as possible to the web implementation of flexbox. There are however certain cases where CSSLayout differs from the web implementation.
|
||||
|
||||
A single function `computeLayout` is exposed that
|
||||
- takes a tree of nodes: `{ style: { ... }, children: [ nodes ] }`
|
||||
- computes the layout and writes it back to the node tree.
|
||||
|
||||
For example,
|
||||
|
||||
```javascript
|
||||
// create an initial tree of nodes
|
||||
var nodeTree = {
|
||||
"style": {
|
||||
"padding": 50
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"style": {
|
||||
"padding": 10,
|
||||
"alignSelf": "stretch"
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
// compute the layout
|
||||
computeLayout(nodeTree);
|
||||
|
||||
// the layout information is written back to the node tree, with
|
||||
// each node now having a layout property:
|
||||
|
||||
// JSON.stringify(nodeTree, null, 2);
|
||||
{
|
||||
"style": {
|
||||
"padding": 50
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"style": {
|
||||
"padding": 10,
|
||||
"alignSelf": "stretch"
|
||||
},
|
||||
"layout": {
|
||||
"width": 20,
|
||||
"height": 20,
|
||||
"top": 50,
|
||||
"left": 50,
|
||||
"right": 50,
|
||||
"bottom": 50,
|
||||
"direction": "ltr"
|
||||
},
|
||||
"children": [],
|
||||
"lineIndex": 0
|
||||
}
|
||||
],
|
||||
"layout": {
|
||||
"width": 120,
|
||||
"height": 120,
|
||||
"top": 0,
|
||||
"left": 0,
|
||||
"right": 0,
|
||||
"bottom": 0,
|
||||
"direction": "ltr"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Supported Attributes
|
||||
--------------------
|
||||
|
||||
Name | Value
|
||||
----:|------
|
||||
width, height | positive number
|
||||
minWidth, minHeight | positive number
|
||||
maxWidth, maxHeight | positive number
|
||||
left, right, top, bottom | number
|
||||
margin, marginLeft, marginRight, marginTop, marginBottom | number
|
||||
padding, paddingLeft, paddingRight, paddingTop, paddingBottom | positive number
|
||||
borderWidth, borderLeftWidth, borderRightWidth, borderTopWidth, borderBottomWidth | positive number
|
||||
flexDirection | 'column', 'row'
|
||||
justifyContent | 'flex-start', 'center', 'flex-end', 'space-between', 'space-around'
|
||||
alignItems, alignSelf, alignContent | 'flex-start', 'center', 'flex-end', 'stretch'
|
||||
flex | positive number
|
||||
flexWrap | 'wrap', 'nowrap'
|
||||
position | 'relative', 'absolute'
|
||||
|
||||
- `inherit` value is not implemented because it's a way to disambiguate between multiple colliding rules. This should be done in a pre-processing step, not in the actual layout algorithm.
|
||||
|
||||
|
||||
|
||||
Default values
|
||||
--------------
|
||||
Since we are only using flexbox, we can use defaults that are much more sensible. This is the configuration to use in order to get the same behavior using the DOM and CSS. You can try those default settings with the [following JSFiddle](http://jsfiddle.net/vjeux/y11txxv9/).
|
||||
### Default values
|
||||
CSSLayout has chosen to make changes to the default values of certain properties. These default values were chosen based on our usage of the library. When testing layout with tools such as JSFiddle you can apply the following css style to ensure the defaults match those of CSSLayout. Or fork the [following JSFiddle](http://jsfiddle.net/vjeux/y11txxv9/).
|
||||
|
||||
```css
|
||||
div, span {
|
||||
@@ -118,6 +26,7 @@ div, span {
|
||||
border: 0 solid black;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
min-width: 0;
|
||||
}
|
||||
```
|
||||
|
||||
@@ -126,15 +35,125 @@ div, span {
|
||||
- All the flex elements are oriented from top to bottom, left to right and do not shrink. This is how things are laid out using the default CSS settings and what you'd expect.
|
||||
- Everything is `position: relative`. This makes `position: absolute` target the direct parent and not some parent which is either `relative` or `absolute`. If you want to position an element relative to something else, you should move it in the DOM instead of relying of CSS. It also makes `top, left, right, bottom` do something when not specifying `position: absolute`.
|
||||
|
||||
Development
|
||||
-----------
|
||||
### Size units
|
||||
CSSLayout currently only supports pixel sizes. The reason being that we have not seen the need for any other units. We would like to support percentage units sometime in the future.
|
||||
|
||||
The core logic resides with `Layout.js`, which is transpiled into equivalent C and Java implementations.
|
||||
### -start and -end properties
|
||||
We think supporting RTL locales is very important. Therefor CSSLayout supports non-standards -start and -end suffixed versions of margin, padding, border, and position.
|
||||
|
||||
The JavaScript build process is managed via Grunt. The build performs linting, runs the tests against Chrome, transpiles and packages the code (JavaScript and Java) into the `dist` folder. For JavaScript, the build output uses the Universal Module Format (UMD) so that it can be used via AMD / RequireJS, CommonJS or included directly into an HTML page.
|
||||
|
||||
While developing you can just run the lint / Chrome-based tests a follows:
|
||||
## Usage
|
||||
|
||||
### C
|
||||
The full API can be found in `CSSLayout/CSSLayout.h`.
|
||||
|
||||
```c
|
||||
CSSNodeRef root = CSSNodeNew();
|
||||
CSSNodeStyleSetWidth(root, 100);
|
||||
CSSNodeStyleSetHeight(root, 100);
|
||||
|
||||
for (uint32_t i = 0; i < 10; i++) {
|
||||
CSSNodeRef child = CSSNodeNew();
|
||||
CSSNodeStyleSetHeight(child, 10);
|
||||
CSSNodeInsertChild(root, child, 0);
|
||||
}
|
||||
|
||||
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
|
||||
|
||||
// Get for resulting layout
|
||||
CSSNodeLayoutGetLeft(root);
|
||||
CSSNodeLayoutGetTop(root);
|
||||
CSSNodeLayoutGetWidth(root);
|
||||
CSSNodeLayoutGetHeight(root);
|
||||
```
|
||||
grunt test-javascript
|
||||
|
||||
### Java
|
||||
The full API can be found in `java/com/facebook/csslayout/CSSNode.java`.
|
||||
|
||||
```java
|
||||
CSSNode root = new CSSNode();
|
||||
root.setStyleWidth(100);
|
||||
root.setStyleHeight(100);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
CSSNode child = new CSSNode();
|
||||
child.setStyleHeight(10);
|
||||
root.addChildAt(child, 0);
|
||||
}
|
||||
|
||||
root.calculateLayout(new CSSLayoutContext());
|
||||
|
||||
// Get for resulting layout
|
||||
root.getLayoutX();
|
||||
root.getLayoutY();
|
||||
root.getLayoutWidth();
|
||||
root.getLayoutHeight();
|
||||
```
|
||||
|
||||
### UIKit
|
||||
The full API can be found in `CSSLayoutKit/UIView+CSSLayout.h`.
|
||||
|
||||
```objective-c
|
||||
UIView *root = [UIView new];
|
||||
[root css_setUsesFlexbox:YES];
|
||||
[root css_setWidth:100];
|
||||
[root css_setHeight:100];
|
||||
|
||||
for (NSUInteger i = 0; i < 10; i++) {
|
||||
UIView *child = [UIView new];
|
||||
[child css_setUsesFlexbox:YES];
|
||||
[child css_setHeight:10];
|
||||
[root addSubview:child];
|
||||
}
|
||||
|
||||
// Resulting layout will be set on the UIView hierarchy frames.
|
||||
[root css_applyLayout];
|
||||
```
|
||||
|
||||
### .NET
|
||||
The full API can be found in `csharp/Facebook.CSSLayout/CSSNode.cs`.
|
||||
|
||||
```csharp
|
||||
var root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var child = new CSSNode();
|
||||
child.StyleHeight = 10;
|
||||
root.Insert(0, child);
|
||||
}
|
||||
|
||||
// Get for resulting layout
|
||||
root.LayoutX;
|
||||
root.LayoutY;
|
||||
root.LayoutWidth;
|
||||
root.LayoutHeight;
|
||||
```
|
||||
|
||||
## Contributing
|
||||
To contribute to CSSLayout you need to first install [buck](https://buckbuild.com) which is the build system used by CSSLayout. CSSLayout is implemented in C with language bindings for Java, Objective-C, and .NET. When making changes to `CSSLayout/CSSLayout.h` please ensure to update `java/jni/CSSJNI.h`, `java/com/facebook/csslayout/CSSNode.java`, `uikit/CSSLayout/UIView+CSSLayout.m`, and `csharp/Facebook.CSSLayout/CSSNode.cs` to reflect the API change. Before submitting any code please run `format.sh` to ensure the code matches the project's code style.
|
||||
|
||||
Before making any larger changes to CSSLayout please open an issue with a RFC so the changes can be discussed first. Generally we are very open to changes and improvements that will benefit the community.
|
||||
|
||||
### Testing
|
||||
For any changes you make you should ensure that all the tests are passing. In case you make any fixes or additions to the library please also add at least one test to ensure we don't break anything in the future. Tests are located in `tests/CSSLayoutTest.cpp`. Run the tests by executing `buck test //:CSSLayout`.
|
||||
|
||||
Instead of manually writing a test which ensures parity with web implementations of flexbox you can run `gentest/gentest.rb` to generated a test for you. You can write html which you want to verify in CSSLayout, in `gentest/fixtures` folder, such as the following.
|
||||
|
||||
```html
|
||||
<div style="width: 100px; height: 100px; align-items: center;">
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
```
|
||||
|
||||
Run `gentest/gentest.rb` to generate test code and re-run `buck test //:CSSLayout` to validate the behavior. One test case will be generated for every root `div` in the input html.
|
||||
|
||||
You may need to install the latest watir-webdriver gem (`gem install watir-webdriver`) and [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/) to run `gentest/gentest.rb` Ruby script.
|
||||
|
||||
#### .NET
|
||||
.NET testing is not integrated in buck yet, you might need to set up .NET testing environment. We have a script which to launch C# test on macOS, `csharp/tests/Facebook.CSSLayout/test_macos.sh`.
|
||||
|
||||
### Benchmarks
|
||||
Benchmarks are located in `benchmarks/CSSBenchmark.c` and can be run with `buck run //benchmarks:benchmarks`. If you think your change has affected performance please run this before and after your change to validate that nothing has regressed.
|
||||
|
27
benchmark/BUCK
Normal file
27
benchmark/BUCK
Normal file
@@ -0,0 +1,27 @@
|
||||
# Copyright (c) 2014-present, Facebook, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the BSD-style license found in the
|
||||
# LICENSE file in the root directory of this source tree. An additional grant
|
||||
# of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
include_defs('//CSSLAYOUT_DEFS')
|
||||
|
||||
cxx_binary(
|
||||
name = 'benchmark',
|
||||
srcs = glob(['*.c']),
|
||||
headers = subdir_glob([('', '*.h')]),
|
||||
header_namespace = '',
|
||||
compiler_flags = [
|
||||
'-fno-omit-frame-pointer',
|
||||
'-fexceptions',
|
||||
'-Wall',
|
||||
'-Werror',
|
||||
'-O3',
|
||||
'-std=c11',
|
||||
],
|
||||
deps = [
|
||||
csslayout_dep(':CSSLayout'),
|
||||
],
|
||||
visibility = ['PUBLIC'],
|
||||
)
|
118
benchmark/CSSBenchmark.c
Normal file
118
benchmark/CSSBenchmark.c
Normal file
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#include "CSSBenchmark.h"
|
||||
|
||||
#include <CSSLayout/CSSLayout.h>
|
||||
|
||||
static CSSSize _measure(CSSNodeRef node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode) {
|
||||
return (CSSSize){
|
||||
.width = widthMode == CSSMeasureModeUndefined ? 10 : width,
|
||||
.height = heightMode == CSSMeasureModeUndefined ? 10 : width,
|
||||
};
|
||||
}
|
||||
|
||||
CSS_BENCHMARKS({
|
||||
|
||||
CSS_BENCHMARK("Stack with flex", {
|
||||
const CSSNodeRef root = CSSNodeNew();
|
||||
CSSNodeStyleSetWidth(root, 100);
|
||||
CSSNodeStyleSetHeight(root, 100);
|
||||
|
||||
for (uint32_t i = 0; i < 10; i++) {
|
||||
const CSSNodeRef child = CSSNodeNew();
|
||||
CSSNodeSetMeasureFunc(child, _measure);
|
||||
CSSNodeStyleSetFlex(child, 1);
|
||||
CSSNodeInsertChild(root, child, 0);
|
||||
}
|
||||
|
||||
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
|
||||
CSSNodeFreeRecursive(root);
|
||||
});
|
||||
|
||||
CSS_BENCHMARK("Align stretch in undefined axis", {
|
||||
const CSSNodeRef root = CSSNodeNew();
|
||||
|
||||
for (uint32_t i = 0; i < 10; i++) {
|
||||
const CSSNodeRef child = CSSNodeNew();
|
||||
CSSNodeStyleSetHeight(child, 20);
|
||||
CSSNodeSetMeasureFunc(child, _measure);
|
||||
CSSNodeInsertChild(root, child, 0);
|
||||
}
|
||||
|
||||
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
|
||||
CSSNodeFreeRecursive(root);
|
||||
});
|
||||
|
||||
CSS_BENCHMARK("Nested flex", {
|
||||
const CSSNodeRef root = CSSNodeNew();
|
||||
|
||||
for (uint32_t i = 0; i < 10; i++) {
|
||||
const CSSNodeRef child = CSSNodeNew();
|
||||
CSSNodeStyleSetFlex(child, 1);
|
||||
CSSNodeInsertChild(root, child, 0);
|
||||
|
||||
for (uint32_t ii = 0; ii < 10; ii++) {
|
||||
const CSSNodeRef grandChild = CSSNodeNew();
|
||||
CSSNodeSetMeasureFunc(grandChild, _measure);
|
||||
CSSNodeStyleSetFlex(grandChild, 1);
|
||||
CSSNodeInsertChild(child, grandChild, 0);
|
||||
}
|
||||
}
|
||||
|
||||
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
|
||||
CSSNodeFreeRecursive(root);
|
||||
});
|
||||
|
||||
CSS_BENCHMARK("Huge nested layout", {
|
||||
const CSSNodeRef root = CSSNodeNew();
|
||||
|
||||
for (uint32_t i = 0; i < 10; i++) {
|
||||
const CSSNodeRef child = CSSNodeNew();
|
||||
CSSNodeStyleSetFlexGrow(child, 1);
|
||||
CSSNodeStyleSetWidth(child, 10);
|
||||
CSSNodeStyleSetHeight(child, 10);
|
||||
CSSNodeInsertChild(root, child, 0);
|
||||
|
||||
for (uint32_t ii = 0; ii < 10; ii++) {
|
||||
const CSSNodeRef grandChild = CSSNodeNew();
|
||||
CSSNodeStyleSetFlexDirection(grandChild, CSSFlexDirectionRow);
|
||||
CSSNodeStyleSetFlexGrow(grandChild, 1);
|
||||
CSSNodeStyleSetWidth(grandChild, 10);
|
||||
CSSNodeStyleSetHeight(grandChild, 10);
|
||||
CSSNodeInsertChild(child, grandChild, 0);
|
||||
|
||||
for (uint32_t iii = 0; iii < 10; iii++) {
|
||||
const CSSNodeRef grandGrandChild = CSSNodeNew();
|
||||
CSSNodeStyleSetFlexGrow(grandGrandChild, 1);
|
||||
CSSNodeStyleSetWidth(grandGrandChild, 10);
|
||||
CSSNodeStyleSetHeight(grandGrandChild, 10);
|
||||
CSSNodeInsertChild(grandChild, grandGrandChild, 0);
|
||||
|
||||
for (uint32_t iii = 0; iii < 10; iii++) {
|
||||
const CSSNodeRef grandGrandGrandChild = CSSNodeNew();
|
||||
CSSNodeStyleSetFlexDirection(grandGrandGrandChild, CSSFlexDirectionRow);
|
||||
CSSNodeStyleSetFlexGrow(grandGrandGrandChild, 1);
|
||||
CSSNodeStyleSetWidth(grandGrandGrandChild, 10);
|
||||
CSSNodeStyleSetHeight(grandGrandGrandChild, 10);
|
||||
CSSNodeInsertChild(grandGrandChild, grandGrandGrandChild, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
|
||||
CSSNodeFreeRecursive(root);
|
||||
});
|
||||
|
||||
});
|
73
benchmark/CSSBenchmark.h
Normal file
73
benchmark/CSSBenchmark.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#define NUM_REPETITIONS 1000
|
||||
|
||||
#define CSS_BENCHMARKS(BLOCK) \
|
||||
int main(int argc, char const *argv[]) { \
|
||||
clock_t __start; \
|
||||
clock_t __endTimes[NUM_REPETITIONS]; \
|
||||
{ BLOCK } \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
#define CSS_BENCHMARK(NAME, BLOCK) \
|
||||
__start = clock(); \
|
||||
for (uint32_t __i = 0; __i < NUM_REPETITIONS; __i++) { \
|
||||
{ BLOCK } \
|
||||
__endTimes[__i] = clock(); \
|
||||
} \
|
||||
__printBenchmarkResult(NAME, __start, __endTimes);
|
||||
|
||||
int __compareDoubles(const void *a, const void *b) {
|
||||
double arg1 = *(const double *) a;
|
||||
double arg2 = *(const double *) b;
|
||||
|
||||
if (arg1 < arg2) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (arg1 > arg2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void __printBenchmarkResult(char *name, clock_t start, clock_t *endTimes) {
|
||||
double timesInMs[NUM_REPETITIONS];
|
||||
double mean = 0;
|
||||
clock_t lastEnd = start;
|
||||
for (uint32_t i = 0; i < NUM_REPETITIONS; i++) {
|
||||
timesInMs[i] = (endTimes[i] - lastEnd) / (double) CLOCKS_PER_SEC * 1000;
|
||||
lastEnd = endTimes[i];
|
||||
mean += timesInMs[i];
|
||||
}
|
||||
mean /= NUM_REPETITIONS;
|
||||
|
||||
qsort(timesInMs, NUM_REPETITIONS, sizeof(double), __compareDoubles);
|
||||
double median = timesInMs[NUM_REPETITIONS / 2];
|
||||
|
||||
double variance = 0;
|
||||
for (uint32_t i = 0; i < NUM_REPETITIONS; i++) {
|
||||
variance += pow(timesInMs[i] - mean, 2);
|
||||
}
|
||||
variance /= NUM_REPETITIONS;
|
||||
double stddev = sqrt(variance);
|
||||
|
||||
printf("%s: median: %lf ms, stddev: %lf ms\n", name, median, stddev);
|
||||
}
|
265
csharp/.gitignore
vendored
Normal file
265
csharp/.gitignore
vendored
Normal file
@@ -0,0 +1,265 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# DNX
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignoreable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
node_modules/
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
265
csharp/.hgignore
Normal file
265
csharp/.hgignore
Normal file
@@ -0,0 +1,265 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# DNX
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignoreable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
node_modules/
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
20
csharp/BUCK
Normal file
20
csharp/BUCK
Normal file
@@ -0,0 +1,20 @@
|
||||
# Copyright (c) 2014-present, Facebook, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the BSD-style license found in the
|
||||
# LICENSE file in the root directory of this source tree. An additional grant
|
||||
# of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
csharp_library(
|
||||
name = 'csslibnet46',
|
||||
dll_name = 'Facebook.CSSLayout.dll',
|
||||
framework_ver = 'net46',
|
||||
srcs = glob(['**/*.cs']),
|
||||
)
|
||||
|
||||
csharp_library(
|
||||
name = 'csslibnet45',
|
||||
dll_name = 'Facebook.CSSLayout.dll',
|
||||
framework_ver = 'net45',
|
||||
srcs = glob(['**/*.cs']),
|
||||
)
|
27
csharp/CSSLayout/CSSInterop.cpp
Normal file
27
csharp/CSSLayout/CSSInterop.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#include "CSSInterop.h"
|
||||
|
||||
static CSSInteropLoggerFunc gManagedFunc;
|
||||
|
||||
static int unmanagedLogger(CSSLogLevel level, const char *format, va_list args) {
|
||||
int result = 0;
|
||||
if (gManagedFunc) {
|
||||
char buffer[256];
|
||||
result = vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
(*gManagedFunc)(level, buffer);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void CSSInteropSetLogger(CSSInteropLoggerFunc managedFunc) {
|
||||
gManagedFunc = managedFunc;
|
||||
CSSLayoutSetLogger(&unmanagedLogger);
|
||||
}
|
20
csharp/CSSLayout/CSSInterop.h
Normal file
20
csharp/CSSLayout/CSSInterop.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <CSSLayout/CSSLayout.h>
|
||||
|
||||
CSS_EXTERN_C_BEGIN
|
||||
|
||||
typedef void (*CSSInteropLoggerFunc)(CSSLogLevel level, const char *message);
|
||||
|
||||
WIN_EXPORT void CSSInteropSetLogger(CSSInteropLoggerFunc managedFunc);
|
||||
|
||||
CSS_EXTERN_C_END
|
183
csharp/CSSLayout/CSSLayout.vcxproj
Executable file
183
csharp/CSSLayout/CSSLayout.vcxproj
Executable file
@@ -0,0 +1,183 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>CSSLayout</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;CSSLAYOUT_EXPORTS;CSS_ASSERT_FAIL_ENABLED;FB_ASSERTIONS_ENABLED=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;CSSLAYOUT_EXPORTS;CSS_ASSERT_FAIL_ENABLED;FB_ASSERTIONS_ENABLED=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;CSSLAYOUT_EXPORTS;CSS_ASSERT_FAIL_ENABLED;FB_ASSERTIONS_ENABLED=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;CSSLAYOUT_EXPORTS;CSS_ASSERT_FAIL_ENABLED;FB_ASSERTIONS_ENABLED=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)..\..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\CSSLayout\CSSLayout.h" />
|
||||
<ClInclude Include="..\..\CSSLayout\CSSMacros.h" />
|
||||
<ClInclude Include="..\..\CSSLayout\CSSNodeList.h" />
|
||||
<ClInclude Include="CSSInterop.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\CSSLayout\CSSLayout.c" />
|
||||
<ClCompile Include="..\..\CSSLayout\CSSNodeList.c" />
|
||||
<ClCompile Include="CSSInterop.cpp" />
|
||||
<ClCompile Include="dllmain.cpp">
|
||||
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
</PrecompiledHeader>
|
||||
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</CompileAsManaged>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
</PrecompiledHeader>
|
||||
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</CompileAsManaged>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
</PrecompiledHeader>
|
||||
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</CompileAsManaged>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="stdafx.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
54
csharp/CSSLayout/CSSLayout.vcxproj.filters
Executable file
54
csharp/CSSLayout/CSSLayout.vcxproj.filters
Executable file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="targetver.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\CSSLayout\CSSLayout.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\CSSLayout\CSSMacros.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\CSSLayout\CSSNodeList.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CSSInterop.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="dllmain.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\CSSLayout\CSSLayout.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\CSSLayout\CSSNodeList.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CSSInterop.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
27
csharp/CSSLayout/dllmain.cpp
Normal file
27
csharp/CSSLayout/dllmain.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
// dllmain.cpp : Defines the entry point for the DLL application.
|
||||
#include "stdafx.h"
|
||||
|
||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
{
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
17
csharp/CSSLayout/stdafx.cpp
Normal file
17
csharp/CSSLayout/stdafx.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// CSSLayout.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
25
csharp/CSSLayout/stdafx.h
Normal file
25
csharp/CSSLayout/stdafx.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "targetver.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
// Windows Header Files:
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
17
csharp/CSSLayout/targetver.h
Normal file
17
csharp/CSSLayout/targetver.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Including SDKDDKVer.h defines the highest available Windows platform.
|
||||
|
||||
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
|
||||
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
|
||||
|
||||
#include <SDKDDKVer.h>
|
46
csharp/Facebook.CSSLayout.sln
Normal file
46
csharp/Facebook.CSSLayout.sln
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CSSLayout", "CSSLayout\CSSLayout.vcxproj", "{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Facebook.CSSLayout", "Facebook.CSSLayout\Facebook.CSSLayout.xproj", "{75BB7605-E54B-4EDE-8F5A-FF1F24464236}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|Any CPU.ActiveCfg = Debug|Win32
|
||||
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|x64.Build.0 = Debug|x64
|
||||
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|x86.Build.0 = Debug|Win32
|
||||
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|Any CPU.ActiveCfg = Release|Win32
|
||||
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|x64.ActiveCfg = Release|x64
|
||||
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|x64.Build.0 = Release|x64
|
||||
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|x86.ActiveCfg = Release|Win32
|
||||
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|x86.Build.0 = Release|Win32
|
||||
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|x64.Build.0 = Release|Any CPU
|
||||
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
20
csharp/Facebook.CSSLayout/CSSAlign.cs
Normal file
20
csharp/Facebook.CSSLayout/CSSAlign.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public enum CSSAlign
|
||||
{
|
||||
Auto,
|
||||
FlexStart,
|
||||
Center,
|
||||
FlexEnd,
|
||||
Stretch,
|
||||
}
|
||||
}
|
21
csharp/Facebook.CSSLayout/CSSConstants.cs
Normal file
21
csharp/Facebook.CSSLayout/CSSConstants.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public static class CSSConstants
|
||||
{
|
||||
public const float Undefined = float.NaN;
|
||||
|
||||
public static bool IsUndefined(float value)
|
||||
{
|
||||
return float.IsNaN(value);
|
||||
}
|
||||
}
|
||||
}
|
22
csharp/Facebook.CSSLayout/CSSDIrection.cs
Normal file
22
csharp/Facebook.CSSLayout/CSSDIrection.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public enum CSSDirection
|
||||
{
|
||||
Inherit,
|
||||
LTR,
|
||||
RTL,
|
||||
[System.Obsolete("Use LTR instead")]
|
||||
LeftToRight = LTR,
|
||||
[System.Obsolete("Use RTL instead")]
|
||||
RightToLeft = RTL,
|
||||
}
|
||||
}
|
17
csharp/Facebook.CSSLayout/CSSDimension.cs
Normal file
17
csharp/Facebook.CSSLayout/CSSDimension.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public enum CSSDimension
|
||||
{
|
||||
Width,
|
||||
Height,
|
||||
}
|
||||
}
|
24
csharp/Facebook.CSSLayout/CSSEdge.cs
Normal file
24
csharp/Facebook.CSSLayout/CSSEdge.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public enum CSSEdge
|
||||
{
|
||||
Left,
|
||||
Top,
|
||||
Right,
|
||||
Bottom,
|
||||
Start,
|
||||
End,
|
||||
Horizontal,
|
||||
Vertical,
|
||||
All,
|
||||
}
|
||||
}
|
@@ -1,14 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
package com.facebook.csslayout;
|
||||
|
||||
public enum CSSPositionType {
|
||||
RELATIVE,
|
||||
ABSOLUTE,
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public enum CSSExperimentalFeature
|
||||
{
|
||||
}
|
||||
}
|
19
csharp/Facebook.CSSLayout/CSSFlexDirection.cs
Normal file
19
csharp/Facebook.CSSLayout/CSSFlexDirection.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public enum CSSFlexDirection
|
||||
{
|
||||
Column,
|
||||
ColumnReverse,
|
||||
Row,
|
||||
RowReverse,
|
||||
}
|
||||
}
|
20
csharp/Facebook.CSSLayout/CSSJustify.cs
Normal file
20
csharp/Facebook.CSSLayout/CSSJustify.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public enum CSSJustify
|
||||
{
|
||||
FlexStart,
|
||||
Center,
|
||||
FlexEnd,
|
||||
SpaceBetween,
|
||||
SpaceAround,
|
||||
}
|
||||
}
|
20
csharp/Facebook.CSSLayout/CSSLogLevel.cs
Normal file
20
csharp/Facebook.CSSLayout/CSSLogLevel.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public enum CSSLogLevel
|
||||
{
|
||||
Error,
|
||||
Warn,
|
||||
Info,
|
||||
Debug,
|
||||
Verbose,
|
||||
}
|
||||
}
|
45
csharp/Facebook.CSSLayout/CSSLogger.cs
Normal file
45
csharp/Facebook.CSSLayout/CSSLogger.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
internal static class CSSLogger
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void Func(CSSLogLevel level, string message);
|
||||
|
||||
private static bool _initialized;
|
||||
private static Func _managedLogger = null;
|
||||
|
||||
public static Func Logger = null;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
_managedLogger = (level, message) => {
|
||||
if (Logger != null)
|
||||
{
|
||||
Logger(level, message);
|
||||
}
|
||||
|
||||
if (level == CSSLogLevel.Error)
|
||||
{
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
};
|
||||
Native.CSSInteropSetLogger(_managedLogger);
|
||||
_initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
22
csharp/Facebook.CSSLayout/CSSMeasureFunc.cs
Normal file
22
csharp/Facebook.CSSLayout/CSSMeasureFunc.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate CSSSize CSSMeasureFunc(
|
||||
IntPtr node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode);
|
||||
}
|
18
csharp/Facebook.CSSLayout/CSSMeasureMode.cs
Normal file
18
csharp/Facebook.CSSLayout/CSSMeasureMode.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public enum CSSMeasureMode
|
||||
{
|
||||
Undefined,
|
||||
Exactly,
|
||||
AtMost,
|
||||
}
|
||||
}
|
234
csharp/Facebook.CSSLayout/CSSNode.Create.cs
Normal file
234
csharp/Facebook.CSSLayout/CSSNode.Create.cs
Normal file
@@ -0,0 +1,234 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public partial class CSSNode
|
||||
{
|
||||
public static CSSNode Create(
|
||||
CSSDirection? styleDirection = null,
|
||||
CSSFlexDirection? flexDirection = null,
|
||||
CSSJustify? justifyContent = null,
|
||||
CSSAlign? alignContent = null,
|
||||
CSSAlign? alignItems = null,
|
||||
CSSAlign? alignSelf = null,
|
||||
CSSPositionType? positionType = null,
|
||||
CSSWrap? wrap = null,
|
||||
CSSOverflow? overflow = null,
|
||||
float? flex = null,
|
||||
float? flexGrow = null,
|
||||
float? flexShrink = null,
|
||||
float? flexBasis = null,
|
||||
Spacing position = null,
|
||||
Spacing margin = null,
|
||||
Spacing padding = null,
|
||||
Spacing border = null,
|
||||
float? styleWidth = null,
|
||||
float? styleHeight = null,
|
||||
float? styleMaxWidth = null,
|
||||
float? styleMaxHeight = null,
|
||||
float? styleMinWidth = null,
|
||||
float? styleMinHeight = null)
|
||||
{
|
||||
CSSNode node = new CSSNode();
|
||||
|
||||
if (styleDirection.HasValue)
|
||||
{
|
||||
node.StyleDirection = styleDirection.Value;
|
||||
}
|
||||
|
||||
if (flexDirection.HasValue)
|
||||
{
|
||||
node.FlexDirection = flexDirection.Value;
|
||||
}
|
||||
|
||||
if (justifyContent.HasValue)
|
||||
{
|
||||
node.JustifyContent = justifyContent.Value;
|
||||
}
|
||||
|
||||
if (alignContent.HasValue)
|
||||
{
|
||||
node.AlignContent = alignContent.Value;
|
||||
}
|
||||
|
||||
if (alignItems.HasValue)
|
||||
{
|
||||
node.AlignItems = alignItems.Value;
|
||||
}
|
||||
|
||||
if (alignSelf.HasValue)
|
||||
{
|
||||
node.AlignSelf = alignSelf.Value;
|
||||
}
|
||||
|
||||
if (positionType.HasValue)
|
||||
{
|
||||
node.PositionType = positionType.Value;
|
||||
}
|
||||
|
||||
if (wrap.HasValue)
|
||||
{
|
||||
node.Wrap = wrap.Value;
|
||||
}
|
||||
|
||||
if (overflow.HasValue)
|
||||
{
|
||||
node.Overflow = overflow.Value;
|
||||
}
|
||||
|
||||
if (flex.HasValue)
|
||||
{
|
||||
node.Flex = flex.Value;
|
||||
}
|
||||
|
||||
if (flexGrow.HasValue)
|
||||
{
|
||||
node.FlexGrow = flexGrow.Value;
|
||||
}
|
||||
|
||||
if (flexShrink.HasValue)
|
||||
{
|
||||
node.FlexShrink = flexShrink.Value;
|
||||
}
|
||||
|
||||
if (flexBasis.HasValue)
|
||||
{
|
||||
node.FlexBasis = flexBasis.Value;
|
||||
}
|
||||
|
||||
if (position != null)
|
||||
{
|
||||
if (position.Top.HasValue)
|
||||
{
|
||||
node.SetPosition(CSSEdge.Top, position.Top.Value);
|
||||
}
|
||||
|
||||
if (position.Bottom.HasValue)
|
||||
{
|
||||
node.SetPosition(CSSEdge.Bottom, position.Bottom.Value);
|
||||
}
|
||||
|
||||
if (position.Left.HasValue)
|
||||
{
|
||||
node.SetPosition(CSSEdge.Left, position.Left.Value);
|
||||
}
|
||||
|
||||
if (position.Right.HasValue)
|
||||
{
|
||||
node.SetPosition(CSSEdge.Right, position.Right.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (margin != null)
|
||||
{
|
||||
if (margin.Top.HasValue)
|
||||
{
|
||||
node.SetMargin(CSSEdge.Top, margin.Top.Value);
|
||||
}
|
||||
|
||||
if (margin.Bottom.HasValue)
|
||||
{
|
||||
node.SetMargin(CSSEdge.Bottom, margin.Bottom.Value);
|
||||
}
|
||||
|
||||
if (margin.Left.HasValue)
|
||||
{
|
||||
node.SetMargin(CSSEdge.Left, margin.Left.Value);
|
||||
}
|
||||
|
||||
if (margin.Right.HasValue)
|
||||
{
|
||||
node.SetMargin(CSSEdge.Right, margin.Right.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (padding != null)
|
||||
{
|
||||
if (padding.Top.HasValue)
|
||||
{
|
||||
node.SetPadding(CSSEdge.Top, padding.Top.Value);
|
||||
}
|
||||
|
||||
if (padding.Bottom.HasValue)
|
||||
{
|
||||
node.SetPadding(CSSEdge.Bottom, padding.Bottom.Value);
|
||||
}
|
||||
|
||||
if (padding.Left.HasValue)
|
||||
{
|
||||
node.SetPadding(CSSEdge.Left, padding.Left.Value);
|
||||
}
|
||||
|
||||
if (padding.Right.HasValue)
|
||||
{
|
||||
node.SetPadding(CSSEdge.Right, padding.Right.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (border != null)
|
||||
{
|
||||
if (border.Top.HasValue)
|
||||
{
|
||||
node.SetBorder(CSSEdge.Top, border.Top.Value);
|
||||
}
|
||||
|
||||
if (border.Bottom.HasValue)
|
||||
{
|
||||
node.SetBorder(CSSEdge.Bottom, border.Bottom.Value);
|
||||
}
|
||||
|
||||
if (border.Left.HasValue)
|
||||
{
|
||||
node.SetBorder(CSSEdge.Left, border.Left.Value);
|
||||
}
|
||||
|
||||
if (border.Right.HasValue)
|
||||
{
|
||||
node.SetBorder(CSSEdge.Right, border.Right.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (styleWidth.HasValue)
|
||||
{
|
||||
node.StyleWidth = styleWidth.Value;
|
||||
}
|
||||
|
||||
if (styleHeight.HasValue)
|
||||
{
|
||||
node.StyleHeight = styleHeight.Value;
|
||||
}
|
||||
|
||||
if (styleMinWidth.HasValue)
|
||||
{
|
||||
node.StyleMinWidth = styleMinWidth.Value;
|
||||
}
|
||||
|
||||
if (styleMinHeight.HasValue)
|
||||
{
|
||||
node.StyleMinHeight = styleMinHeight.Value;
|
||||
}
|
||||
|
||||
if (styleMaxWidth.HasValue)
|
||||
{
|
||||
node.StyleMaxWidth = styleMaxWidth.Value;
|
||||
}
|
||||
|
||||
if (styleMaxHeight.HasValue)
|
||||
{
|
||||
node.StyleMaxHeight = styleMaxHeight.Value;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
571
csharp/Facebook.CSSLayout/CSSNode.cs
Normal file
571
csharp/Facebook.CSSLayout/CSSNode.cs
Normal file
@@ -0,0 +1,571 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public partial class CSSNode : IEnumerable<CSSNode>
|
||||
{
|
||||
private IntPtr _cssNode;
|
||||
private WeakReference _parent;
|
||||
private List<CSSNode> _children;
|
||||
private MeasureFunction _measureFunction;
|
||||
private CSSMeasureFunc _cssMeasureFunc;
|
||||
private object _data;
|
||||
|
||||
public CSSNode()
|
||||
{
|
||||
CSSLogger.Initialize();
|
||||
|
||||
_cssNode = Native.CSSNodeNew();
|
||||
if (_cssNode == IntPtr.Zero)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to allocate native memory");
|
||||
}
|
||||
}
|
||||
|
||||
~CSSNode()
|
||||
{
|
||||
Native.CSSNodeFree(_cssNode);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_measureFunction = null;
|
||||
_data = null;
|
||||
|
||||
Native.CSSNodeReset(_cssNode);
|
||||
}
|
||||
|
||||
public bool IsDirty
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeIsDirty(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void MarkDirty()
|
||||
{
|
||||
Native.CSSNodeMarkDirty(_cssNode);
|
||||
}
|
||||
|
||||
public bool HasNewLayout
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeGetHasNewLayout(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public void MarkHasNewLayout()
|
||||
{
|
||||
Native.CSSNodeSetHasNewLayout(_cssNode, true);
|
||||
}
|
||||
|
||||
public CSSNode Parent
|
||||
{
|
||||
get
|
||||
{
|
||||
return _parent != null ? _parent.Target as CSSNode : null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsMeasureDefined
|
||||
{
|
||||
get
|
||||
{
|
||||
return _measureFunction != null;
|
||||
}
|
||||
}
|
||||
|
||||
public void CopyStyle(CSSNode srcNode)
|
||||
{
|
||||
Native.CSSNodeCopyStyle(_cssNode, srcNode._cssNode);
|
||||
}
|
||||
|
||||
public CSSDirection StyleDirection
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetDirection(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetDirection(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSFlexDirection FlexDirection
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetFlexDirection(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetFlexDirection(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSJustify JustifyContent
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetJustifyContent(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetJustifyContent(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSAlign AlignItems
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetAlignItems(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetAlignItems(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSAlign AlignSelf
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetAlignSelf(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetAlignSelf(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSAlign AlignContent
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetAlignContent(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetAlignContent(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSPositionType PositionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetPositionType(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetPositionType(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSWrap Wrap
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetFlexWrap(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetFlexWrap(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float Flex
|
||||
{
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetFlex(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float FlexGrow
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetFlexGrow(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetFlexGrow(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float FlexShrink
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetFlexShrink(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetFlexShrink(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float FlexBasis
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetFlexBasis(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetFlexBasis(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetMargin(CSSEdge edge)
|
||||
{
|
||||
return Native.CSSNodeStyleGetMargin(_cssNode, edge);
|
||||
}
|
||||
|
||||
public void SetMargin(CSSEdge edge, float value)
|
||||
{
|
||||
Native.CSSNodeStyleSetMargin(_cssNode, edge, value);
|
||||
}
|
||||
|
||||
public float GetPadding(CSSEdge edge)
|
||||
{
|
||||
return Native.CSSNodeStyleGetPadding(_cssNode, edge);
|
||||
}
|
||||
|
||||
public void SetPadding(CSSEdge edge, float padding)
|
||||
{
|
||||
Native.CSSNodeStyleSetPadding(_cssNode, edge, padding);
|
||||
}
|
||||
|
||||
public float GetBorder(CSSEdge edge)
|
||||
{
|
||||
return Native.CSSNodeStyleGetBorder(_cssNode, edge);
|
||||
}
|
||||
|
||||
public void SetBorder(CSSEdge edge, float border)
|
||||
{
|
||||
Native.CSSNodeStyleSetBorder(_cssNode, edge, border);
|
||||
}
|
||||
|
||||
public float GetPosition(CSSEdge edge)
|
||||
{
|
||||
return Native.CSSNodeStyleGetPosition(_cssNode, edge);
|
||||
}
|
||||
|
||||
public void SetPosition(CSSEdge edge, float position)
|
||||
{
|
||||
Native.CSSNodeStyleSetPosition(_cssNode, edge, position);
|
||||
}
|
||||
|
||||
public float StyleWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetWidth(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetWidth(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float StyleHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetHeight(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetHeight(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float StyleMaxWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetMaxWidth(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetMaxWidth(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float StyleMaxHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetMaxHeight(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetMaxHeight(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float StyleMinWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetMinWidth(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetMinWidth(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float StyleMinHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetMinHeight(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetMinHeight(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float LayoutX
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeLayoutGetLeft(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public float LayoutY
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeLayoutGetTop(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public float LayoutWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeLayoutGetWidth(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public float LayoutHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeLayoutGetHeight(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSDirection LayoutDirection
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeLayoutGetDirection(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSOverflow Overflow
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.CSSNodeStyleGetOverflow(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.CSSNodeStyleSetOverflow(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public object Data
|
||||
{
|
||||
get
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_data = value;
|
||||
}
|
||||
}
|
||||
|
||||
public CSSNode this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return _children[index];
|
||||
}
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return _children != null ? _children.Count : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void MarkLayoutSeen()
|
||||
{
|
||||
Native.CSSNodeSetHasNewLayout(_cssNode, false);
|
||||
}
|
||||
|
||||
public bool ValuesEqual(float f1, float f2)
|
||||
{
|
||||
if (float.IsNaN(f1) || float.IsNaN(f2))
|
||||
{
|
||||
return float.IsNaN(f1) && float.IsNaN(f2);
|
||||
}
|
||||
|
||||
return Math.Abs(f2 - f1) < float.Epsilon;
|
||||
}
|
||||
|
||||
public void Insert(int index, CSSNode node)
|
||||
{
|
||||
if (_children == null)
|
||||
{
|
||||
_children = new List<CSSNode>(4);
|
||||
}
|
||||
_children.Insert(index, node);
|
||||
node._parent = new WeakReference(this);
|
||||
Native.CSSNodeInsertChild(_cssNode, node._cssNode, (uint)index);
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
var child = _children[index];
|
||||
child._parent = null;
|
||||
_children.RemoveAt(index);
|
||||
Native.CSSNodeRemoveChild(_cssNode, child._cssNode);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
if (_children != null)
|
||||
{
|
||||
while (_children.Count > 0)
|
||||
{
|
||||
RemoveAt(_children.Count-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int IndexOf(CSSNode node)
|
||||
{
|
||||
return _children != null ? _children.IndexOf(node) : -1;
|
||||
}
|
||||
|
||||
public void SetMeasureFunction(MeasureFunction measureFunction)
|
||||
{
|
||||
_measureFunction = measureFunction;
|
||||
_cssMeasureFunc = measureFunction != null ? MeasureInternal : (CSSMeasureFunc)null;
|
||||
Native.CSSNodeSetMeasureFunc(_cssNode, _cssMeasureFunc);
|
||||
}
|
||||
|
||||
public void CalculateLayout()
|
||||
{
|
||||
Native.CSSNodeCalculateLayout(
|
||||
_cssNode,
|
||||
CSSConstants.Undefined,
|
||||
CSSConstants.Undefined,
|
||||
Native.CSSNodeStyleGetDirection(_cssNode));
|
||||
}
|
||||
|
||||
private CSSSize MeasureInternal(
|
||||
IntPtr node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode)
|
||||
{
|
||||
if (_measureFunction == null)
|
||||
{
|
||||
throw new InvalidOperationException("Measure function is not defined.");
|
||||
}
|
||||
|
||||
long output = _measureFunction(this, width, widthMode, height, heightMode);
|
||||
return new CSSSize { width = MeasureOutput.GetWidth(output), height = MeasureOutput.GetHeight(output) };
|
||||
}
|
||||
|
||||
public string Print(CSSPrintOptions options =
|
||||
CSSPrintOptions.Layout|CSSPrintOptions.Style|CSSPrintOptions.Children)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
CSSLogger.Func orig = CSSLogger.Logger;
|
||||
CSSLogger.Logger = (level, message) => {sb.Append(message);};
|
||||
Native.CSSNodePrint(_cssNode, options);
|
||||
CSSLogger.Logger = orig;
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public IEnumerator<CSSNode> GetEnumerator()
|
||||
{
|
||||
return _children != null ? ((IEnumerable<CSSNode>)_children).GetEnumerator() :
|
||||
System.Linq.Enumerable.Empty<CSSNode>().GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return _children != null ? ((IEnumerable<CSSNode>)_children).GetEnumerator() :
|
||||
System.Linq.Enumerable.Empty<CSSNode>().GetEnumerator();
|
||||
}
|
||||
|
||||
public static int GetInstanceCount()
|
||||
{
|
||||
return Native.CSSNodeGetInstanceCount();
|
||||
}
|
||||
|
||||
public static void setExperimentalFeatureEnabled(
|
||||
CSSExperimentalFeature feature,
|
||||
bool enabled)
|
||||
{
|
||||
Native.CSSLayoutSetExperimentalFeatureEnabled(feature, enabled);
|
||||
}
|
||||
|
||||
public static bool isExperimentalFeatureEnabled(CSSExperimentalFeature feature)
|
||||
{
|
||||
return Native.CSSLayoutIsExperimentalFeatureEnabled(feature);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,17 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
package com.facebook.csslayout;
|
||||
|
||||
public enum CSSJustify {
|
||||
FLEX_START,
|
||||
CENTER,
|
||||
FLEX_END,
|
||||
SPACE_BETWEEN,
|
||||
SPACE_AROUND,
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public enum CSSOverflow
|
||||
{
|
||||
Visible,
|
||||
Hidden,
|
||||
Scroll,
|
||||
}
|
||||
}
|
@@ -1,16 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
package com.facebook.csslayout;
|
||||
|
||||
public enum CSSFlexDirection {
|
||||
COLUMN,
|
||||
COLUMN_REVERSE,
|
||||
ROW,
|
||||
ROW_REVERSE
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public enum CSSPositionType
|
||||
{
|
||||
Relative,
|
||||
Absolute,
|
||||
}
|
||||
}
|
18
csharp/Facebook.CSSLayout/CSSPrintOptions.cs
Normal file
18
csharp/Facebook.CSSLayout/CSSPrintOptions.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public enum CSSPrintOptions
|
||||
{
|
||||
Layout = 1,
|
||||
Style = 2,
|
||||
Children = 4,
|
||||
}
|
||||
}
|
20
csharp/Facebook.CSSLayout/CSSSize.cs
Normal file
20
csharp/Facebook.CSSLayout/CSSSize.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct CSSSize
|
||||
{
|
||||
public float width;
|
||||
public float height;
|
||||
}
|
||||
}
|
@@ -1,17 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
package com.facebook.csslayout;
|
||||
|
||||
public enum CSSAlign {
|
||||
AUTO,
|
||||
FLEX_START,
|
||||
CENTER,
|
||||
FLEX_END,
|
||||
STRETCH,
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public enum CSSWrap
|
||||
{
|
||||
NoWrap,
|
||||
Wrap,
|
||||
}
|
||||
}
|
21
csharp/Facebook.CSSLayout/Facebook.CSSLayout.xproj
Normal file
21
csharp/Facebook.CSSLayout/Facebook.CSSLayout.xproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>75bb7605-e54b-4ede-8f5a-ff1f24464236</ProjectGuid>
|
||||
<RootNamespace>Facebook.CSSLayout</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
18
csharp/Facebook.CSSLayout/MeasureFunction.cs
Normal file
18
csharp/Facebook.CSSLayout/MeasureFunction.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public delegate long MeasureFunction(
|
||||
CSSNode node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode);
|
||||
}
|
34
csharp/Facebook.CSSLayout/MeasureOutput.cs
Normal file
34
csharp/Facebook.CSSLayout/MeasureOutput.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public class MeasureOutput
|
||||
{
|
||||
public static long Make(double width, double height)
|
||||
{
|
||||
return Make((int) width, (int) height);
|
||||
}
|
||||
|
||||
public static long Make(int width, int height)
|
||||
{
|
||||
return (long)(((ulong) width) << 32 | ((uint) height));
|
||||
}
|
||||
|
||||
public static int GetWidth(long measureOutput)
|
||||
{
|
||||
return (int) (0xFFFFFFFF & (measureOutput >> 32));
|
||||
}
|
||||
|
||||
public static int GetHeight(long measureOutput)
|
||||
{
|
||||
return (int) (0xFFFFFFFF & measureOutput);
|
||||
}
|
||||
}
|
||||
}
|
280
csharp/Facebook.CSSLayout/Native.cs
Normal file
280
csharp/Facebook.CSSLayout/Native.cs
Normal file
@@ -0,0 +1,280 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
internal static class Native
|
||||
{
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
private const string DllName = "__Internal";
|
||||
#else
|
||||
private const string DllName = "CSSLayout";
|
||||
#endif
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSInteropSetLogger(
|
||||
[MarshalAs(UnmanagedType.FunctionPtr)] CSSLogger.Func func);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern IntPtr CSSNodeNew();
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeInit(IntPtr cssNode);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeFree(IntPtr cssNode);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeReset(IntPtr cssNode);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern int CSSNodeGetInstanceCount();
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSLayoutSetExperimentalFeatureEnabled(
|
||||
CSSExperimentalFeature feature,
|
||||
bool enabled);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern bool CSSLayoutIsExperimentalFeatureEnabled(
|
||||
CSSExperimentalFeature feature);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeInsertChild(IntPtr node, IntPtr child, uint index);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeRemoveChild(IntPtr node, IntPtr child);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern IntPtr CSSNodeGetChild(IntPtr node, uint index);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern uint CSSNodeChildCount(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeCalculateLayout(IntPtr node,
|
||||
float availableWidth,
|
||||
float availableHeight,
|
||||
CSSDirection parentDirection);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeMarkDirty(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
public static extern bool CSSNodeIsDirty(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodePrint(IntPtr node, CSSPrintOptions options);
|
||||
|
||||
[DllImport(DllName)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
public static extern bool CSSValueIsUndefined(float value);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeCopyStyle(IntPtr dstNode, IntPtr srcNode);
|
||||
|
||||
#region CSS_NODE_PROPERTY
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeSetContext(IntPtr node, IntPtr context);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern IntPtr CSSNodeGetContext(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeSetMeasureFunc(
|
||||
IntPtr node,
|
||||
[MarshalAs(UnmanagedType.FunctionPtr)] CSSMeasureFunc measureFunc);
|
||||
|
||||
[DllImport(DllName)]
|
||||
[return: MarshalAs(UnmanagedType.FunctionPtr)]
|
||||
public static extern CSSMeasureFunc CSSNodeGetMeasureFunc(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeSetHasNewLayout(IntPtr node, [MarshalAs(UnmanagedType.I1)] bool hasNewLayout);
|
||||
|
||||
[DllImport(DllName)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
public static extern bool CSSNodeGetHasNewLayout(IntPtr node);
|
||||
|
||||
#endregion
|
||||
|
||||
#region CSS_NODE_STYLE_PROPERTY
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetDirection(IntPtr node, CSSDirection direction);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSDirection CSSNodeStyleGetDirection(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetFlexDirection(IntPtr node, CSSFlexDirection flexDirection);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSFlexDirection CSSNodeStyleGetFlexDirection(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetJustifyContent(IntPtr node, CSSJustify justifyContent);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSJustify CSSNodeStyleGetJustifyContent(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetAlignContent(IntPtr node, CSSAlign alignContent);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSAlign CSSNodeStyleGetAlignContent(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetAlignItems(IntPtr node, CSSAlign alignItems);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSAlign CSSNodeStyleGetAlignItems(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetAlignSelf(IntPtr node, CSSAlign alignSelf);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSAlign CSSNodeStyleGetAlignSelf(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetPositionType(IntPtr node, CSSPositionType positionType);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSPositionType CSSNodeStyleGetPositionType(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetFlexWrap(IntPtr node, CSSWrap flexWrap);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSWrap CSSNodeStyleGetFlexWrap(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetOverflow(IntPtr node, CSSOverflow flexWrap);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSOverflow CSSNodeStyleGetOverflow(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetFlex(IntPtr node, float flex);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetFlexGrow(IntPtr node, float flexGrow);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetFlexGrow(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetFlexShrink(IntPtr node, float flexShrink);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetFlexShrink(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetFlexBasis(IntPtr node, float flexBasis);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetFlexBasis(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetWidth(IntPtr node, float width);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetWidth(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetHeight(IntPtr node, float height);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetHeight(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetMinWidth(IntPtr node, float minWidth);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetMinWidth(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetMinHeight(IntPtr node, float minHeight);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetMinHeight(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetMaxWidth(IntPtr node, float maxWidth);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetMaxWidth(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetMaxHeight(IntPtr node, float maxHeight);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetMaxHeight(IntPtr node);
|
||||
|
||||
#endregion
|
||||
|
||||
#region CSS_NODE_STYLE_EDGE_PROPERTY
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetPosition(IntPtr node, CSSEdge edge, float position);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetPosition(IntPtr node, CSSEdge edge);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetMargin(IntPtr node, CSSEdge edge, float margin);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetMargin(IntPtr node, CSSEdge edge);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetPadding(IntPtr node, CSSEdge edge, float padding);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetPadding(IntPtr node, CSSEdge edge);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetBorder(IntPtr node, CSSEdge edge, float border);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetBorder(IntPtr node, CSSEdge edge);
|
||||
|
||||
#endregion
|
||||
|
||||
#region CSS_NODE_LAYOUT_PROPERTY
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeLayoutGetLeft(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeLayoutGetTop(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeLayoutGetRight(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeLayoutGetBottom(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeLayoutGetWidth(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeLayoutGetHeight(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSDirection CSSNodeLayoutGetDirection(IntPtr node);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
32
csharp/Facebook.CSSLayout/Properties/AssemblyInfo.cs
Normal file
32
csharp/Facebook.CSSLayout/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Facebook, Inc.")]
|
||||
[assembly: AssemblyProduct("Facebook.CSSLayout")]
|
||||
[assembly: AssemblyTrademark("Copyright (c) 2014-present, Facebook, Inc.")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("75bb7605-e54b-4ede-8f5a-ff1f24464236")]
|
||||
|
||||
[assembly: NeutralResourcesLanguage("en")]
|
||||
|
||||
[assembly: AssemblyVersion("3.0.0.0")]
|
31
csharp/Facebook.CSSLayout/Spacing.cs
Normal file
31
csharp/Facebook.CSSLayout/Spacing.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public class Spacing
|
||||
{
|
||||
public float? Top;
|
||||
public float? Bottom;
|
||||
public float? Left;
|
||||
public float? Right;
|
||||
|
||||
public Spacing(
|
||||
float? top = null,
|
||||
float? bottom = null,
|
||||
float? left = null,
|
||||
float? right = null)
|
||||
{
|
||||
Top = top;
|
||||
Bottom = bottom;
|
||||
Left = left;
|
||||
Right = right;
|
||||
}
|
||||
}
|
||||
}
|
14
csharp/Facebook.CSSLayout/project.json
Normal file
14
csharp/Facebook.CSSLayout/project.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"language": "en",
|
||||
"version": "3.0.0-*",
|
||||
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.6.0"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"netstandard1.6": {
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
344
csharp/tests/Facebook.CSSLayout/CSSLayoutAbsolutePositionTest.cs
Normal file
344
csharp/tests/Facebook.CSSLayout/CSSLayoutAbsolutePositionTest.cs
Normal file
@@ -0,0 +1,344 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @Generated by gentest/gentest.sh with the following input
|
||||
*
|
||||
<div id="absolute_layout_width_height_start_top" style="width: 100px; height: 100px;">
|
||||
<div style="width:10px; height: 10px; position: absolute; start: 10px; top: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="absolute_layout_width_height_end_bottom" style="width: 100px; height: 100px;">
|
||||
<div style="width:10px; height: 10px; position: absolute; end: 10px; bottom: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="absolute_layout_start_top_end_bottom" style="width: 100px; height: 100px;">
|
||||
<div style="position: absolute; start: 10px; top: 10px; end: 10px; bottom: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="absolute_layout_width_height_start_top_end_bottom" style="width: 100px; height: 100px;">
|
||||
<div style="width:10px; height: 10px; position: absolute; start: 10px; top: 10px; end: 10px; bottom: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent" style="height: 50px; width: 50px; overflow: hidden; flex-direction: row;">
|
||||
<div style="position: absolute; start: 0px; top: 0px;">
|
||||
<div style="width: 100px; height: 100px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="absolute_layout_within_border" style="height:100px; width:100px; border-width: 10px; margin: 10px; padding: 10px;">
|
||||
<div style="position: absolute; width: 50px; height: 50px; left: 0px; top: 0px;"></div>
|
||||
<div style="position: absolute; width: 50px; height: 50px; right: 0px; bottom: 0px;"></div>
|
||||
</div>
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSLayoutAbsolutePositionTest
|
||||
{
|
||||
[Test]
|
||||
public void Test_absolute_layout_width_height_start_top()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.PositionType = CSSPositionType.Absolute;
|
||||
root_child0.SetPosition(CSSEdge.Start, 10);
|
||||
root_child0.SetPosition(CSSEdge.Top, 10);
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_absolute_layout_width_height_end_bottom()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.PositionType = CSSPositionType.Absolute;
|
||||
root_child0.SetPosition(CSSEdge.End, 10);
|
||||
root_child0.SetPosition(CSSEdge.Bottom, 10);
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80, root_child0.LayoutX);
|
||||
Assert.AreEqual(80, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(80, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_absolute_layout_start_top_end_bottom()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.PositionType = CSSPositionType.Absolute;
|
||||
root_child0.SetPosition(CSSEdge.Start, 10);
|
||||
root_child0.SetPosition(CSSEdge.Top, 10);
|
||||
root_child0.SetPosition(CSSEdge.End, 10);
|
||||
root_child0.SetPosition(CSSEdge.Bottom, 10);
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(80, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(80, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(80, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(80, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_absolute_layout_width_height_start_top_end_bottom()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.PositionType = CSSPositionType.Absolute;
|
||||
root_child0.SetPosition(CSSEdge.Start, 10);
|
||||
root_child0.SetPosition(CSSEdge.Top, 10);
|
||||
root_child0.SetPosition(CSSEdge.End, 10);
|
||||
root_child0.SetPosition(CSSEdge.Bottom, 10);
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.Overflow = CSSOverflow.Hidden;
|
||||
root.StyleWidth = 50;
|
||||
root.StyleHeight = 50;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.PositionType = CSSPositionType.Absolute;
|
||||
root_child0.SetPosition(CSSEdge.Start, 0);
|
||||
root_child0.SetPosition(CSSEdge.Top, 0);
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child0_child0 = new CSSNode();
|
||||
root_child0_child0.StyleWidth = 100;
|
||||
root_child0_child0.StyleHeight = 100;
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(50, root.LayoutWidth);
|
||||
Assert.AreEqual(50, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(50, root.LayoutWidth);
|
||||
Assert.AreEqual(50, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-50, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_absolute_layout_within_border()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.SetMargin(CSSEdge.Left, 10);
|
||||
root.SetMargin(CSSEdge.Top, 10);
|
||||
root.SetMargin(CSSEdge.Right, 10);
|
||||
root.SetMargin(CSSEdge.Bottom, 10);
|
||||
root.SetPadding(CSSEdge.Left, 10);
|
||||
root.SetPadding(CSSEdge.Top, 10);
|
||||
root.SetPadding(CSSEdge.Right, 10);
|
||||
root.SetPadding(CSSEdge.Bottom, 10);
|
||||
root.SetBorder(CSSEdge.Left, 10);
|
||||
root.SetBorder(CSSEdge.Top, 10);
|
||||
root.SetBorder(CSSEdge.Right, 10);
|
||||
root.SetBorder(CSSEdge.Bottom, 10);
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.PositionType = CSSPositionType.Absolute;
|
||||
root_child0.SetPosition(CSSEdge.Left, 0);
|
||||
root_child0.SetPosition(CSSEdge.Top, 0);
|
||||
root_child0.StyleWidth = 50;
|
||||
root_child0.StyleHeight = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.PositionType = CSSPositionType.Absolute;
|
||||
root_child1.SetPosition(CSSEdge.Right, 0);
|
||||
root_child1.SetPosition(CSSEdge.Bottom, 0);
|
||||
root_child1.StyleWidth = 50;
|
||||
root_child1.StyleHeight = 50;
|
||||
root.Insert(1, root_child1);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(10, root.LayoutX);
|
||||
Assert.AreEqual(10, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(40, root_child1.LayoutX);
|
||||
Assert.AreEqual(40, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child1.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(10, root.LayoutX);
|
||||
Assert.AreEqual(10, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(40, root_child1.LayoutX);
|
||||
Assert.AreEqual(40, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
450
csharp/tests/Facebook.CSSLayout/CSSLayoutAlignContentTest.cs
Normal file
450
csharp/tests/Facebook.CSSLayout/CSSLayoutAlignContentTest.cs
Normal file
@@ -0,0 +1,450 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @Generated by gentest/gentest.sh with the following input
|
||||
*
|
||||
<div id="align_content_flex_start" style="width: 100px; height: 100px; flex-wrap: wrap; flex-direction: column; align-content: flex-start;">
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_content_flex_end" style="width: 100px; height: 100px; flex-wrap: wrap; flex-direction: column; align-content: flex-end;">
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_content_center" style="width: 100px; height: 100px; flex-wrap: wrap; flex-direction: column; align-content: center;">
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_content_stretch" style="width: 100px; height: 100px; flex-wrap: wrap; flex-direction: column; align-content: stretch;">
|
||||
<div style="width: 50px;"></div>
|
||||
<div style="width: 50px;"></div>
|
||||
<div style="width: 50px;"></div>
|
||||
<div style="width: 50px;"></div>
|
||||
<div style="width: 50px;"></div>
|
||||
</div>
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSLayoutAlignContentTest
|
||||
{
|
||||
[Test]
|
||||
public void Test_align_content_flex_start()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.Wrap = CSSWrap.Wrap;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 50;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 50;
|
||||
root_child1.StyleHeight = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 50;
|
||||
root_child2.StyleHeight = 10;
|
||||
root.Insert(2, root_child2);
|
||||
|
||||
CSSNode root_child3 = new CSSNode();
|
||||
root_child3.StyleWidth = 50;
|
||||
root_child3.StyleHeight = 10;
|
||||
root.Insert(3, root_child3);
|
||||
|
||||
CSSNode root_child4 = new CSSNode();
|
||||
root_child4.StyleWidth = 50;
|
||||
root_child4.StyleHeight = 10;
|
||||
root.Insert(4, root_child4);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(20, root_child2.LayoutY);
|
||||
Assert.AreEqual(50, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child3.LayoutX);
|
||||
Assert.AreEqual(30, root_child3.LayoutY);
|
||||
Assert.AreEqual(50, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child3.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child4.LayoutX);
|
||||
Assert.AreEqual(40, root_child4.LayoutY);
|
||||
Assert.AreEqual(50, root_child4.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child4.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child2.LayoutX);
|
||||
Assert.AreEqual(20, root_child2.LayoutY);
|
||||
Assert.AreEqual(50, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child3.LayoutX);
|
||||
Assert.AreEqual(30, root_child3.LayoutY);
|
||||
Assert.AreEqual(50, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child3.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child4.LayoutX);
|
||||
Assert.AreEqual(40, root_child4.LayoutY);
|
||||
Assert.AreEqual(50, root_child4.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child4.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_content_flex_end()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.AlignContent = CSSAlign.FlexEnd;
|
||||
root.Wrap = CSSWrap.Wrap;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 50;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 50;
|
||||
root_child1.StyleHeight = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 50;
|
||||
root_child2.StyleHeight = 10;
|
||||
root.Insert(2, root_child2);
|
||||
|
||||
CSSNode root_child3 = new CSSNode();
|
||||
root_child3.StyleWidth = 50;
|
||||
root_child3.StyleHeight = 10;
|
||||
root.Insert(3, root_child3);
|
||||
|
||||
CSSNode root_child4 = new CSSNode();
|
||||
root_child4.StyleWidth = 50;
|
||||
root_child4.StyleHeight = 10;
|
||||
root.Insert(4, root_child4);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(20, root_child2.LayoutY);
|
||||
Assert.AreEqual(50, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child3.LayoutX);
|
||||
Assert.AreEqual(30, root_child3.LayoutY);
|
||||
Assert.AreEqual(50, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child3.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child4.LayoutX);
|
||||
Assert.AreEqual(40, root_child4.LayoutY);
|
||||
Assert.AreEqual(50, root_child4.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child4.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child2.LayoutX);
|
||||
Assert.AreEqual(20, root_child2.LayoutY);
|
||||
Assert.AreEqual(50, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child3.LayoutX);
|
||||
Assert.AreEqual(30, root_child3.LayoutY);
|
||||
Assert.AreEqual(50, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child3.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child4.LayoutX);
|
||||
Assert.AreEqual(40, root_child4.LayoutY);
|
||||
Assert.AreEqual(50, root_child4.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child4.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_content_center()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.AlignContent = CSSAlign.Center;
|
||||
root.Wrap = CSSWrap.Wrap;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 50;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 50;
|
||||
root_child1.StyleHeight = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 50;
|
||||
root_child2.StyleHeight = 10;
|
||||
root.Insert(2, root_child2);
|
||||
|
||||
CSSNode root_child3 = new CSSNode();
|
||||
root_child3.StyleWidth = 50;
|
||||
root_child3.StyleHeight = 10;
|
||||
root.Insert(3, root_child3);
|
||||
|
||||
CSSNode root_child4 = new CSSNode();
|
||||
root_child4.StyleWidth = 50;
|
||||
root_child4.StyleHeight = 10;
|
||||
root.Insert(4, root_child4);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(20, root_child2.LayoutY);
|
||||
Assert.AreEqual(50, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child3.LayoutX);
|
||||
Assert.AreEqual(30, root_child3.LayoutY);
|
||||
Assert.AreEqual(50, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child3.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child4.LayoutX);
|
||||
Assert.AreEqual(40, root_child4.LayoutY);
|
||||
Assert.AreEqual(50, root_child4.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child4.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child2.LayoutX);
|
||||
Assert.AreEqual(20, root_child2.LayoutY);
|
||||
Assert.AreEqual(50, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child3.LayoutX);
|
||||
Assert.AreEqual(30, root_child3.LayoutY);
|
||||
Assert.AreEqual(50, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child3.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child4.LayoutX);
|
||||
Assert.AreEqual(40, root_child4.LayoutY);
|
||||
Assert.AreEqual(50, root_child4.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child4.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_content_stretch()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.AlignContent = CSSAlign.Stretch;
|
||||
root.Wrap = CSSWrap.Wrap;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 50;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 50;
|
||||
root.Insert(2, root_child2);
|
||||
|
||||
CSSNode root_child3 = new CSSNode();
|
||||
root_child3.StyleWidth = 50;
|
||||
root.Insert(3, root_child3);
|
||||
|
||||
CSSNode root_child4 = new CSSNode();
|
||||
root_child4.StyleWidth = 50;
|
||||
root.Insert(4, root_child4);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(50, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child3.LayoutX);
|
||||
Assert.AreEqual(0, root_child3.LayoutY);
|
||||
Assert.AreEqual(50, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child3.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child4.LayoutX);
|
||||
Assert.AreEqual(0, root_child4.LayoutY);
|
||||
Assert.AreEqual(50, root_child4.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child4.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(50, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child3.LayoutX);
|
||||
Assert.AreEqual(0, root_child3.LayoutY);
|
||||
Assert.AreEqual(50, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child3.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child4.LayoutX);
|
||||
Assert.AreEqual(0, root_child4.LayoutY);
|
||||
Assert.AreEqual(50, root_child4.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child4.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
194
csharp/tests/Facebook.CSSLayout/CSSLayoutAlignItemsTest.cs
Normal file
194
csharp/tests/Facebook.CSSLayout/CSSLayoutAlignItemsTest.cs
Normal file
@@ -0,0 +1,194 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @Generated by gentest/gentest.sh with the following input
|
||||
*
|
||||
<div id="align_items_stretch" style="width: 100px; height: 100px;">
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_items_center" style="width: 100px; height: 100px; align-items: center;">
|
||||
<div style="height: 10px; width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_items_flex_start" style="width: 100px; height: 100px; align-items: flex-start;">
|
||||
<div style="height: 10px; width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_items_flex_end" style="width: 100px; height: 100px; align-items: flex-end;">
|
||||
<div style="height: 10px; width: 10px;"></div>
|
||||
</div>
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSLayoutAlignItemsTest
|
||||
{
|
||||
[Test]
|
||||
public void Test_align_items_stretch()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_items_center()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.AlignItems = CSSAlign.Center;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(45, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(45, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_items_flex_start()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.AlignItems = CSSAlign.FlexStart;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(90, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_items_flex_end()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.AlignItems = CSSAlign.FlexEnd;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(90, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
197
csharp/tests/Facebook.CSSLayout/CSSLayoutAlignSelfTest.cs
Normal file
197
csharp/tests/Facebook.CSSLayout/CSSLayoutAlignSelfTest.cs
Normal file
@@ -0,0 +1,197 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @Generated by gentest/gentest.sh with the following input
|
||||
*
|
||||
<div id="align_self_center" style="width:100px; height: 100px;">
|
||||
<div style="height: 10px; width: 10px; align-self: center;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_self_flex_end" style="width:100px; height: 100px;">
|
||||
<div style="height: 10px; width: 10px; align-self: flex-end;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_self_flex_start" style="width:100px; height: 100px;">
|
||||
<div style="height: 10px; width: 10px; align-self: flex-start;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_self_flex_end_override_flex_start" style="width:100px; height: 100px; align-items: flex-start;">
|
||||
<div style="height: 10px; width: 10px; align-self: flex-end;"></div>
|
||||
</div>
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSLayoutAlignSelfTest
|
||||
{
|
||||
[Test]
|
||||
public void Test_align_self_center()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.AlignSelf = CSSAlign.Center;
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(45, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(45, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_self_flex_end()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.AlignSelf = CSSAlign.FlexEnd;
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(90, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_self_flex_start()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.AlignSelf = CSSAlign.FlexStart;
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(90, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_self_flex_end_override_flex_start()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.AlignItems = CSSAlign.FlexStart;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.AlignSelf = CSSAlign.FlexEnd;
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(90, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
234
csharp/tests/Facebook.CSSLayout/CSSLayoutBorderTest.cs
Normal file
234
csharp/tests/Facebook.CSSLayout/CSSLayoutBorderTest.cs
Normal file
@@ -0,0 +1,234 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @Generated by gentest/gentest.sh with the following input
|
||||
*
|
||||
<div id="border_no_size" style="border-width: 10px;">
|
||||
</div>
|
||||
|
||||
<div id="border_container_match_child" style="border-width: 10px;">
|
||||
<div style="width: 10px; height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="border_flex_child" style="width: 100px; height: 100px; border-width: 10px;">
|
||||
<div style="width: 10px; flex-grow:1"></div>
|
||||
</div>
|
||||
|
||||
<div id="border_stretch_child" style="width: 100px; height: 100px; border-width: 10px;">
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="border_center_child" style="width: 100px; height: 100px; border-start-width: 10px; border-top-width: 10; border-end-width: 20px; border-bottom-width: 20px; align-items: center; justify-content: center;">
|
||||
<div style="height: 10px; width: 10px;"></div>
|
||||
</div>
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSLayoutBorderTest
|
||||
{
|
||||
[Test]
|
||||
public void Test_border_no_size()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.SetBorder(CSSEdge.Left, 10);
|
||||
root.SetBorder(CSSEdge.Top, 10);
|
||||
root.SetBorder(CSSEdge.Right, 10);
|
||||
root.SetBorder(CSSEdge.Bottom, 10);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(20, root.LayoutWidth);
|
||||
Assert.AreEqual(20, root.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(20, root.LayoutWidth);
|
||||
Assert.AreEqual(20, root.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_border_container_match_child()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.SetBorder(CSSEdge.Left, 10);
|
||||
root.SetBorder(CSSEdge.Top, 10);
|
||||
root.SetBorder(CSSEdge.Right, 10);
|
||||
root.SetBorder(CSSEdge.Bottom, 10);
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(30, root.LayoutWidth);
|
||||
Assert.AreEqual(30, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(30, root.LayoutWidth);
|
||||
Assert.AreEqual(30, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_border_flex_child()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.SetBorder(CSSEdge.Left, 10);
|
||||
root.SetBorder(CSSEdge.Top, 10);
|
||||
root.SetBorder(CSSEdge.Right, 10);
|
||||
root.SetBorder(CSSEdge.Bottom, 10);
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.StyleWidth = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(80, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(80, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_border_stretch_child()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.SetBorder(CSSEdge.Left, 10);
|
||||
root.SetBorder(CSSEdge.Top, 10);
|
||||
root.SetBorder(CSSEdge.Right, 10);
|
||||
root.SetBorder(CSSEdge.Bottom, 10);
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(80, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(80, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_border_center_child()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.JustifyContent = CSSJustify.Center;
|
||||
root.AlignItems = CSSAlign.Center;
|
||||
root.SetBorder(CSSEdge.Start, 10);
|
||||
root.SetBorder(CSSEdge.End, 20);
|
||||
root.SetBorder(CSSEdge.Bottom, 20);
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(40, root_child0.LayoutX);
|
||||
Assert.AreEqual(35, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child0.LayoutX);
|
||||
Assert.AreEqual(35, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
452
csharp/tests/Facebook.CSSLayout/CSSLayoutFlexDirectionTest.cs
Normal file
452
csharp/tests/Facebook.CSSLayout/CSSLayoutFlexDirectionTest.cs
Normal file
@@ -0,0 +1,452 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @Generated by gentest/gentest.sh with the following input
|
||||
*
|
||||
<div id="flex_direction_column_no_height" style="width: 100px">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_direction_row_no_width" style="height: 100px; flex-direction: row;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_direction_column" style="height: 100px; width: 100px;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_direction_row" style="height: 100px; width: 100px; flex-direction: row;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_direction_column_reverse" style="height: 100px; width: 100px; flex-direction: column-reverse;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_direction_row_reverse" style="height: 100px; width: 100px; flex-direction: row-reverse;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSLayoutFlexDirectionTest
|
||||
{
|
||||
[Test]
|
||||
public void Test_flex_direction_column_no_height()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleHeight = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleHeight = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(30, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(20, root_child2.LayoutY);
|
||||
Assert.AreEqual(100, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(30, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(20, root_child2.LayoutY);
|
||||
Assert.AreEqual(100, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_direction_row_no_width()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(30, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(20, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(30, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(20, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_direction_column()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleHeight = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleHeight = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(20, root_child2.LayoutY);
|
||||
Assert.AreEqual(100, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(20, root_child2.LayoutY);
|
||||
Assert.AreEqual(100, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_direction_row()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(20, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(90, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(70, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_direction_column_reverse()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.ColumnReverse;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleHeight = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleHeight = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(90, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(80, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(70, root_child2.LayoutY);
|
||||
Assert.AreEqual(100, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(90, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(80, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(70, root_child2.LayoutY);
|
||||
Assert.AreEqual(100, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_direction_row_reverse()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.RowReverse;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(90, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(70, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(20, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
460
csharp/tests/Facebook.CSSLayout/CSSLayoutFlexTest.cs
Normal file
460
csharp/tests/Facebook.CSSLayout/CSSLayoutFlexTest.cs
Normal file
@@ -0,0 +1,460 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @Generated by gentest/gentest.sh with the following input
|
||||
*
|
||||
<div id="flex_basis_flex_grow_column" style="width: 100px; height: 100px;">
|
||||
<div style="flex-basis: 50px; flex-grow: 1;"></div>
|
||||
<div style="flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_basis_flex_grow_row" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="flex-basis: 50px; flex-grow: 1;"></div>
|
||||
<div style="flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_basis_flex_shrink_column" style="width: 100px; height: 100px;">
|
||||
<div style="flex-basis: 100px; flex-shrink: 1;"></div>
|
||||
<div style="flex-basis: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_basis_flex_shrink_row" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="flex-basis: 100px; flex-shrink: 1;"></div>
|
||||
<div style="flex-basis: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_shrink_to_zero" style="height: 75px;">
|
||||
<div style="width: 50px; height: 50px; flex-shrink:0;"></div>
|
||||
<div style="width: 50px; height: 50px; flex-shrink:1;"></div>
|
||||
<div style="width: 50px; height: 50px; flex-shrink:0;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_basis_overrides_main_size" style="height: 100px; width: 100px;">
|
||||
<div style="height: 20px; flex-grow:1; flex-basis:50px;"></div>
|
||||
<div style="height: 10px; flex-grow:1;"></div>
|
||||
<div style="height: 10px; flex-grow:1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_grow_shrink_at_most" style="height: 100px; width: 100px;">
|
||||
<div>
|
||||
<div style="flex-grow:1; flex-shrink:1;"></div>
|
||||
</div>
|
||||
</div>
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSLayoutFlexTest
|
||||
{
|
||||
[Test]
|
||||
public void Test_flex_basis_flex_grow_column()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.FlexBasis = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.FlexGrow = 1;
|
||||
root.Insert(1, root_child1);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(75, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(75, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(25, root_child1.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(75, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(75, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(25, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_basis_flex_grow_row()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.FlexBasis = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.FlexGrow = 1;
|
||||
root.Insert(1, root_child1);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(75, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(75, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(25, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(25, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(75, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(25, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_basis_flex_shrink_column()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexShrink = 1;
|
||||
root_child0.FlexBasis = 100;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.FlexBasis = 50;
|
||||
root.Insert(1, root_child1);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(50, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child1.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(50, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_basis_flex_shrink_row()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexShrink = 1;
|
||||
root_child0.FlexBasis = 100;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.FlexBasis = 50;
|
||||
root.Insert(1, root_child1);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_shrink_to_zero()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleHeight = 75;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 50;
|
||||
root_child0.StyleHeight = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.FlexShrink = 1;
|
||||
root_child1.StyleWidth = 50;
|
||||
root_child1.StyleHeight = 50;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 50;
|
||||
root_child2.StyleHeight = 50;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(50, root.LayoutWidth);
|
||||
Assert.AreEqual(75, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(50, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(50, root_child2.LayoutY);
|
||||
Assert.AreEqual(50, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(50, root.LayoutWidth);
|
||||
Assert.AreEqual(75, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(50, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(50, root_child2.LayoutY);
|
||||
Assert.AreEqual(50, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_basis_overrides_main_size()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.FlexBasis = 50;
|
||||
root_child0.StyleHeight = 20;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.FlexGrow = 1;
|
||||
root_child1.StyleHeight = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.FlexGrow = 1;
|
||||
root_child2.StyleHeight = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(60, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(60, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(80, root_child2.LayoutY);
|
||||
Assert.AreEqual(100, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(60, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(60, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(80, root_child2.LayoutY);
|
||||
Assert.AreEqual(100, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_grow_shrink_at_most()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child0_child0 = new CSSNode();
|
||||
root_child0_child0.FlexGrow = 1;
|
||||
root_child0_child0.FlexShrink = 1;
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
389
csharp/tests/Facebook.CSSLayout/CSSLayoutFlexWrapTest.cs
Normal file
389
csharp/tests/Facebook.CSSLayout/CSSLayoutFlexWrapTest.cs
Normal file
@@ -0,0 +1,389 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @Generated by gentest/gentest.sh with the following input
|
||||
*
|
||||
<div id="wrap_column" style="height: 100px; flex-wrap: wrap">
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="wrap_row" style="width: 100px; flex-direction: row; flex-wrap: wrap">
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="wrap_row_align_items_flex_end" style="width: 100px; flex-direction: row; flex-wrap: wrap; align-items: flex-end;">
|
||||
<div style="height: 10px; width: 30px;"></div>
|
||||
<div style="height: 20px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="wrap_row_align_items_center" style="width: 100px; flex-direction: row; flex-wrap: wrap; align-items: center;">
|
||||
<div style="height: 10px; width: 30px;"></div>
|
||||
<div style="height: 20px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
</div>
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSLayoutFlexWrapTest
|
||||
{
|
||||
[Test]
|
||||
public void Test_wrap_column()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.Wrap = CSSWrap.Wrap;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 30;
|
||||
root_child0.StyleHeight = 30;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 30;
|
||||
root_child1.StyleHeight = 30;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 30;
|
||||
root_child2.StyleHeight = 30;
|
||||
root.Insert(2, root_child2);
|
||||
|
||||
CSSNode root_child3 = new CSSNode();
|
||||
root_child3.StyleWidth = 30;
|
||||
root_child3.StyleHeight = 30;
|
||||
root.Insert(3, root_child3);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(60, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(30, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(30, root_child1.LayoutY);
|
||||
Assert.AreEqual(30, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(60, root_child2.LayoutY);
|
||||
Assert.AreEqual(30, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(30, root_child3.LayoutX);
|
||||
Assert.AreEqual(0, root_child3.LayoutY);
|
||||
Assert.AreEqual(30, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child3.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(60, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(30, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(30, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(30, root_child1.LayoutX);
|
||||
Assert.AreEqual(30, root_child1.LayoutY);
|
||||
Assert.AreEqual(30, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(30, root_child2.LayoutX);
|
||||
Assert.AreEqual(60, root_child2.LayoutY);
|
||||
Assert.AreEqual(30, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child3.LayoutX);
|
||||
Assert.AreEqual(0, root_child3.LayoutY);
|
||||
Assert.AreEqual(30, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child3.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_wrap_row()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.Wrap = CSSWrap.Wrap;
|
||||
root.StyleWidth = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 30;
|
||||
root_child0.StyleHeight = 30;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 30;
|
||||
root_child1.StyleHeight = 30;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 30;
|
||||
root_child2.StyleHeight = 30;
|
||||
root.Insert(2, root_child2);
|
||||
|
||||
CSSNode root_child3 = new CSSNode();
|
||||
root_child3.StyleWidth = 30;
|
||||
root_child3.StyleHeight = 30;
|
||||
root.Insert(3, root_child3);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(60, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(30, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(30, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(30, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(60, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(30, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child3.LayoutX);
|
||||
Assert.AreEqual(30, root_child3.LayoutY);
|
||||
Assert.AreEqual(30, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child3.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(60, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(70, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(30, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(40, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(30, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(30, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(70, root_child3.LayoutX);
|
||||
Assert.AreEqual(30, root_child3.LayoutY);
|
||||
Assert.AreEqual(30, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child3.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_wrap_row_align_items_flex_end()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.AlignItems = CSSAlign.FlexEnd;
|
||||
root.Wrap = CSSWrap.Wrap;
|
||||
root.StyleWidth = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 30;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 30;
|
||||
root_child1.StyleHeight = 20;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 30;
|
||||
root_child2.StyleHeight = 30;
|
||||
root.Insert(2, root_child2);
|
||||
|
||||
CSSNode root_child3 = new CSSNode();
|
||||
root_child3.StyleWidth = 30;
|
||||
root_child3.StyleHeight = 30;
|
||||
root.Insert(3, root_child3);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(60, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(20, root_child0.LayoutY);
|
||||
Assert.AreEqual(30, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(30, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(30, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(60, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(30, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child3.LayoutX);
|
||||
Assert.AreEqual(30, root_child3.LayoutY);
|
||||
Assert.AreEqual(30, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child3.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(60, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(70, root_child0.LayoutX);
|
||||
Assert.AreEqual(20, root_child0.LayoutY);
|
||||
Assert.AreEqual(30, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(40, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(30, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(30, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(70, root_child3.LayoutX);
|
||||
Assert.AreEqual(30, root_child3.LayoutY);
|
||||
Assert.AreEqual(30, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child3.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_wrap_row_align_items_center()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.AlignItems = CSSAlign.Center;
|
||||
root.Wrap = CSSWrap.Wrap;
|
||||
root.StyleWidth = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 30;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 30;
|
||||
root_child1.StyleHeight = 20;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 30;
|
||||
root_child2.StyleHeight = 30;
|
||||
root.Insert(2, root_child2);
|
||||
|
||||
CSSNode root_child3 = new CSSNode();
|
||||
root_child3.StyleWidth = 30;
|
||||
root_child3.StyleHeight = 30;
|
||||
root.Insert(3, root_child3);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(60, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(30, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(30, root_child1.LayoutX);
|
||||
Assert.AreEqual(5, root_child1.LayoutY);
|
||||
Assert.AreEqual(30, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(60, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(30, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child3.LayoutX);
|
||||
Assert.AreEqual(30, root_child3.LayoutY);
|
||||
Assert.AreEqual(30, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child3.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(60, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(70, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(30, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(40, root_child1.LayoutX);
|
||||
Assert.AreEqual(5, root_child1.LayoutY);
|
||||
Assert.AreEqual(30, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(30, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(70, root_child3.LayoutX);
|
||||
Assert.AreEqual(30, root_child3.LayoutY);
|
||||
Assert.AreEqual(30, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(30, root_child3.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
746
csharp/tests/Facebook.CSSLayout/CSSLayoutJustifyContentTest.cs
Normal file
746
csharp/tests/Facebook.CSSLayout/CSSLayoutJustifyContentTest.cs
Normal file
@@ -0,0 +1,746 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @Generated by gentest/gentest.sh with the following input
|
||||
*
|
||||
<div id="justify_content_row_flex_start" style="width: 102px; height: 102px; flex-direction: row; justify-content: flex-start;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_row_flex_end" style="width: 102px; height: 102px; flex-direction: row; justify-content: flex-end;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_row_center" style="width: 102px; height: 102px; flex-direction: row; justify-content: center;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_row_space_between" style="width: 102px; height: 102px; flex-direction: row; justify-content: space-between;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_row_space_around" style="width: 102px; height: 102px; flex-direction: row; justify-content: space-around;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_column_flex_start" style="width: 102px; height: 102px; justify-content: flex-start;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="heigth: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_column_flex_end" style="width: 102px; height: 102px; justify-content: flex-end;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_column_center" style="width: 102px; height: 102px; justify-content: center;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_column_space_between" style="width: 102px; height: 102px; justify-content: space-between;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_column_space_around" style="width: 102px; height: 102px; justify-content: space-around;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSLayoutJustifyContentTest
|
||||
{
|
||||
[Test]
|
||||
public void Test_justify_content_row_flex_start()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.StyleWidth = 102;
|
||||
root.StyleHeight = 102;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(20, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(92, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(82, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(72, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_justify_content_row_flex_end()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.JustifyContent = CSSJustify.FlexEnd;
|
||||
root.StyleWidth = 102;
|
||||
root.StyleHeight = 102;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(72, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(82, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(92, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(20, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_justify_content_row_center()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.JustifyContent = CSSJustify.Center;
|
||||
root.StyleWidth = 102;
|
||||
root.StyleHeight = 102;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(36, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(46, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(56, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(56, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(46, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(36, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_justify_content_row_space_between()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.JustifyContent = CSSJustify.SpaceBetween;
|
||||
root.StyleWidth = 102;
|
||||
root.StyleHeight = 102;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(46, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(92, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(92, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(46, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_justify_content_row_space_around()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.JustifyContent = CSSJustify.SpaceAround;
|
||||
root.StyleWidth = 102;
|
||||
root.StyleHeight = 102;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(12, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(46, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(46, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(10, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(12, root_child2.LayoutX);
|
||||
Assert.AreEqual(0, root_child2.LayoutY);
|
||||
Assert.AreEqual(10, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(102, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_justify_content_column_flex_start()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 102;
|
||||
root.StyleHeight = 102;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleHeight = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(102, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(102, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(10, root_child2.LayoutY);
|
||||
Assert.AreEqual(102, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(102, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(10, root_child1.LayoutY);
|
||||
Assert.AreEqual(102, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(0, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(10, root_child2.LayoutY);
|
||||
Assert.AreEqual(102, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_justify_content_column_flex_end()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.JustifyContent = CSSJustify.FlexEnd;
|
||||
root.StyleWidth = 102;
|
||||
root.StyleHeight = 102;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleHeight = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleHeight = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(72, root_child0.LayoutY);
|
||||
Assert.AreEqual(102, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(82, root_child1.LayoutY);
|
||||
Assert.AreEqual(102, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(92, root_child2.LayoutY);
|
||||
Assert.AreEqual(102, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(72, root_child0.LayoutY);
|
||||
Assert.AreEqual(102, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(82, root_child1.LayoutY);
|
||||
Assert.AreEqual(102, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(92, root_child2.LayoutY);
|
||||
Assert.AreEqual(102, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_justify_content_column_center()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.JustifyContent = CSSJustify.Center;
|
||||
root.StyleWidth = 102;
|
||||
root.StyleHeight = 102;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleHeight = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleHeight = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(36, root_child0.LayoutY);
|
||||
Assert.AreEqual(102, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(46, root_child1.LayoutY);
|
||||
Assert.AreEqual(102, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(56, root_child2.LayoutY);
|
||||
Assert.AreEqual(102, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(36, root_child0.LayoutY);
|
||||
Assert.AreEqual(102, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(46, root_child1.LayoutY);
|
||||
Assert.AreEqual(102, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(56, root_child2.LayoutY);
|
||||
Assert.AreEqual(102, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_justify_content_column_space_between()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.JustifyContent = CSSJustify.SpaceBetween;
|
||||
root.StyleWidth = 102;
|
||||
root.StyleHeight = 102;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleHeight = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleHeight = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(102, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(46, root_child1.LayoutY);
|
||||
Assert.AreEqual(102, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(92, root_child2.LayoutY);
|
||||
Assert.AreEqual(102, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(102, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(46, root_child1.LayoutY);
|
||||
Assert.AreEqual(102, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(92, root_child2.LayoutY);
|
||||
Assert.AreEqual(102, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_justify_content_column_space_around()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.JustifyContent = CSSJustify.SpaceAround;
|
||||
root.StyleWidth = 102;
|
||||
root.StyleHeight = 102;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleHeight = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleHeight = 10;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(12, root_child0.LayoutY);
|
||||
Assert.AreEqual(102, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(46, root_child1.LayoutY);
|
||||
Assert.AreEqual(102, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(80, root_child2.LayoutY);
|
||||
Assert.AreEqual(102, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(102, root.LayoutWidth);
|
||||
Assert.AreEqual(102, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(12, root_child0.LayoutY);
|
||||
Assert.AreEqual(102, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(46, root_child1.LayoutY);
|
||||
Assert.AreEqual(102, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(80, root_child2.LayoutY);
|
||||
Assert.AreEqual(102, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
479
csharp/tests/Facebook.CSSLayout/CSSLayoutMarginTest.cs
Normal file
479
csharp/tests/Facebook.CSSLayout/CSSLayoutMarginTest.cs
Normal file
@@ -0,0 +1,479 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @Generated by gentest/gentest.sh with the following input
|
||||
*
|
||||
<div id="margin_start" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="width: 10px; margin-start: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_top" style="width: 100px; height: 100px;">
|
||||
<div style="height: 10px; margin-top: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_end" style="width: 100px; height: 100px; flex-direction: row; justify-content: flex-end;">
|
||||
<div style="width: 10px; margin-end: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_bottom" style="width: 100px; height: 100px; justify-content: flex-end;">
|
||||
<div style="height: 10px; margin-bottom: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_and_flex_row" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="margin-start: 10px; margin-end; 10px; flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_and_flex_column" style="width: 100px; height: 100px;">
|
||||
<div style="margin-top: 10px; margin-bottom; 10px; flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_and_stretch_row" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="margin-top: 10px; margin-bottom; 10px; flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_and_stretch_column" style="width: 100px; height: 100px;">
|
||||
<div style="margin-start: 10px; margin-end; 10px; flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_with_sibling_row" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="margin-end; 10px; flex-grow: 1;"></div>
|
||||
<div style="flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_with_sibling_column" style="width: 100px; height: 100px;">
|
||||
<div style="margin-bottom; 10px; flex-grow: 1;"></div>
|
||||
<div style="flex-grow: 1;"></div>
|
||||
</div>
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSLayoutMarginTest
|
||||
{
|
||||
[Test]
|
||||
public void Test_margin_start()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.SetMargin(CSSEdge.Start, 10);
|
||||
root_child0.StyleWidth = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_top()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.SetMargin(CSSEdge.Top, 10);
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_end()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.JustifyContent = CSSJustify.FlexEnd;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.SetMargin(CSSEdge.End, 10);
|
||||
root_child0.StyleWidth = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_bottom()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.JustifyContent = CSSJustify.FlexEnd;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.SetMargin(CSSEdge.Bottom, 10);
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(80, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(80, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_and_flex_row()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.SetMargin(CSSEdge.Start, 10);
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(90, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(90, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_and_flex_column()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.SetMargin(CSSEdge.Top, 10);
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(90, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(90, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_and_stretch_row()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.SetMargin(CSSEdge.Top, 10);
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(90, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(90, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_and_stretch_column()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.SetMargin(CSSEdge.Start, 10);
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(90, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(90, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_with_sibling_row()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexGrow = 1;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.FlexGrow = 1;
|
||||
root.Insert(1, root_child1);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_with_sibling_column()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexGrow = 1;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.FlexGrow = 1;
|
||||
root.Insert(1, root_child1);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(50, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child1.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(50, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
505
csharp/tests/Facebook.CSSLayout/CSSLayoutMinMaxDimensionTest.cs
Normal file
505
csharp/tests/Facebook.CSSLayout/CSSLayoutMinMaxDimensionTest.cs
Normal file
@@ -0,0 +1,505 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @Generated by gentest/gentest.sh with the following input
|
||||
*
|
||||
<div id="max_width" style="width: 100px; height: 100px;">
|
||||
<div style="height: 10px; max-width: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="max_height" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="width: 10px; max-height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="min_height" style="width: 100px; height: 100px;">
|
||||
<div style="flex-grow: 1; min-height: 60px;"></div>
|
||||
<div style="flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="min_width" style="width: 100px; height: 100px; flex-direction: row">
|
||||
<div style="flex-grow: 1; min-width: 60px;"></div>
|
||||
<div style="flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_min_max" style="max-height: 200px; min-height: 100px; width: 100px; justify-content: center;">
|
||||
<div style="width: 60px; height: 60px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_items_min_max" style="max-width: 200px; min-width: 100px; height: 100px; align-items: center;">
|
||||
<div style="width: 60px; height: 60px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_overflow_min_max" style="min-height: 100px; max-height: 110px; justify-content: center;">
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_grow_within_max_width" style="width: 200px; height: 100px;">
|
||||
<div style="flex-direction: row; max-width: 100px;">
|
||||
<div style="height: 20px; flex-grow: 1;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="flex_grow_within_constrained_max_width" style="width: 200px; height: 100px;">
|
||||
<div style="flex-direction: row; max-width: 300px;">
|
||||
<div style="height: 20px; flex-grow: 1;"></div>
|
||||
</div>
|
||||
</div>
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSLayoutMinMaxDimensionTest
|
||||
{
|
||||
[Test]
|
||||
public void Test_max_width()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleMaxWidth = 50;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_max_height()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleMaxHeight = 50;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(90, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_min_height()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.StyleMinHeight = 60;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.FlexGrow = 1;
|
||||
root.Insert(1, root_child1);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(80, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(80, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child1.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(80, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(80, root_child1.LayoutY);
|
||||
Assert.AreEqual(100, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_min_width()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.FlexDirection = CSSFlexDirection.Row;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.StyleMinWidth = 60;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.FlexGrow = 1;
|
||||
root.Insert(1, root_child1);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(80, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(20, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(20, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(80, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(0, root_child1.LayoutY);
|
||||
Assert.AreEqual(20, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_justify_content_min_max()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.JustifyContent = CSSJustify.Center;
|
||||
root.StyleWidth = 100;
|
||||
root.StyleMinHeight = 100;
|
||||
root.StyleMaxHeight = 200;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 60;
|
||||
root_child0.StyleHeight = 60;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(20, root_child0.LayoutY);
|
||||
Assert.AreEqual(60, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(60, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(40, root_child0.LayoutX);
|
||||
Assert.AreEqual(20, root_child0.LayoutY);
|
||||
Assert.AreEqual(60, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(60, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_items_min_max()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.AlignItems = CSSAlign.Center;
|
||||
root.StyleMinWidth = 100;
|
||||
root.StyleMaxWidth = 200;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 60;
|
||||
root_child0.StyleHeight = 60;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(20, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(60, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(60, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(20, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(60, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(60, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_justify_content_overflow_min_max()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.JustifyContent = CSSJustify.Center;
|
||||
root.StyleMinHeight = 100;
|
||||
root.StyleMaxHeight = 110;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 50;
|
||||
root_child0.StyleHeight = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child1 = new CSSNode();
|
||||
root_child1.StyleWidth = 50;
|
||||
root_child1.StyleHeight = 50;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
CSSNode root_child2 = new CSSNode();
|
||||
root_child2.StyleWidth = 50;
|
||||
root_child2.StyleHeight = 50;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(50, root.LayoutWidth);
|
||||
Assert.AreEqual(110, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(-20, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(30, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(80, root_child2.LayoutY);
|
||||
Assert.AreEqual(50, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(50, root.LayoutWidth);
|
||||
Assert.AreEqual(110, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(-20, root_child0.LayoutY);
|
||||
Assert.AreEqual(50, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child1.LayoutX);
|
||||
Assert.AreEqual(30, root_child1.LayoutY);
|
||||
Assert.AreEqual(50, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child2.LayoutX);
|
||||
Assert.AreEqual(80, root_child2.LayoutY);
|
||||
Assert.AreEqual(50, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(50, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_grow_within_max_width()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 200;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexDirection = CSSFlexDirection.Row;
|
||||
root_child0.StyleMaxWidth = 100;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child0_child0 = new CSSNode();
|
||||
root_child0_child0.FlexGrow = 1;
|
||||
root_child0_child0.StyleHeight = 20;
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(200, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child0_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(200, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(100, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(100, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child0_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_grow_within_constrained_max_width()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.StyleWidth = 200;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexDirection = CSSFlexDirection.Row;
|
||||
root_child0.StyleMaxWidth = 300;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
CSSNode root_child0_child0 = new CSSNode();
|
||||
root_child0_child0.FlexGrow = 1;
|
||||
root_child0_child0.StyleHeight = 20;
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(200, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(200, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(200, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child0_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(200, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0.LayoutY);
|
||||
Assert.AreEqual(200, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(200, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(20, root_child0_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
234
csharp/tests/Facebook.CSSLayout/CSSLayoutPaddingTest.cs
Normal file
234
csharp/tests/Facebook.CSSLayout/CSSLayoutPaddingTest.cs
Normal file
@@ -0,0 +1,234 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @Generated by gentest/gentest.sh with the following input
|
||||
*
|
||||
<div id="padding_no_size" style="padding: 10px;">
|
||||
</div>
|
||||
|
||||
<div id="padding_container_match_child" style="padding: 10px;">
|
||||
<div style="width: 10px; height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="padding_flex_child" style="width: 100px; height: 100px; padding: 10px;">
|
||||
<div style="width: 10px; flex-grow:1"></div>
|
||||
</div>
|
||||
|
||||
<div id="padding_stretch_child" style="width: 100px; height: 100px; padding: 10px;">
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="padding_center_child" style="width: 100px; height: 100px; padding-start: 10px; padding-top: 10; padding-end: 20px; padding-bottom: 20px; align-items: center; justify-content: center;">
|
||||
<div style="height: 10px; width: 10px;"></div>
|
||||
</div>
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSLayoutPaddingTest
|
||||
{
|
||||
[Test]
|
||||
public void Test_padding_no_size()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.SetPadding(CSSEdge.Left, 10);
|
||||
root.SetPadding(CSSEdge.Top, 10);
|
||||
root.SetPadding(CSSEdge.Right, 10);
|
||||
root.SetPadding(CSSEdge.Bottom, 10);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(20, root.LayoutWidth);
|
||||
Assert.AreEqual(20, root.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(20, root.LayoutWidth);
|
||||
Assert.AreEqual(20, root.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_padding_container_match_child()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.SetPadding(CSSEdge.Left, 10);
|
||||
root.SetPadding(CSSEdge.Top, 10);
|
||||
root.SetPadding(CSSEdge.Right, 10);
|
||||
root.SetPadding(CSSEdge.Bottom, 10);
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(30, root.LayoutWidth);
|
||||
Assert.AreEqual(30, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(30, root.LayoutWidth);
|
||||
Assert.AreEqual(30, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_padding_flex_child()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.SetPadding(CSSEdge.Left, 10);
|
||||
root.SetPadding(CSSEdge.Top, 10);
|
||||
root.SetPadding(CSSEdge.Right, 10);
|
||||
root.SetPadding(CSSEdge.Bottom, 10);
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.StyleWidth = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(80, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(80, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_padding_stretch_child()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.SetPadding(CSSEdge.Left, 10);
|
||||
root.SetPadding(CSSEdge.Top, 10);
|
||||
root.SetPadding(CSSEdge.Right, 10);
|
||||
root.SetPadding(CSSEdge.Bottom, 10);
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(80, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10, root_child0.LayoutX);
|
||||
Assert.AreEqual(10, root_child0.LayoutY);
|
||||
Assert.AreEqual(80, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_padding_center_child()
|
||||
{
|
||||
CSSNode root = new CSSNode();
|
||||
root.JustifyContent = CSSJustify.Center;
|
||||
root.AlignItems = CSSAlign.Center;
|
||||
root.SetPadding(CSSEdge.Start, 10);
|
||||
root.SetPadding(CSSEdge.End, 20);
|
||||
root.SetPadding(CSSEdge.Bottom, 20);
|
||||
root.StyleWidth = 100;
|
||||
root.StyleHeight = 100;
|
||||
|
||||
CSSNode root_child0 = new CSSNode();
|
||||
root_child0.StyleWidth = 10;
|
||||
root_child0.StyleHeight = 10;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = CSSDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(40, root_child0.LayoutX);
|
||||
Assert.AreEqual(35, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = CSSDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0, root.LayoutX);
|
||||
Assert.AreEqual(0, root.LayoutY);
|
||||
Assert.AreEqual(100, root.LayoutWidth);
|
||||
Assert.AreEqual(100, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(50, root_child0.LayoutX);
|
||||
Assert.AreEqual(35, root_child0.LayoutY);
|
||||
Assert.AreEqual(10, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
143
csharp/tests/Facebook.CSSLayout/CSSNodeCreateTest.cs
Normal file
143
csharp/tests/Facebook.CSSLayout/CSSNodeCreateTest.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
/**
|
||||
* Tests for {@link CSSNode}.
|
||||
*/
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSNodeCreateTest
|
||||
{
|
||||
[Test]
|
||||
public void TestSimple()
|
||||
{
|
||||
CSSNode nodeDefault = new CSSNode();
|
||||
CSSNode nodeCreated = CSSNode.Create(flexDirection: CSSFlexDirection.Row);
|
||||
Assert.AreEqual(CSSFlexDirection.Row, nodeCreated.FlexDirection);
|
||||
Assert.IsFalse(nodeDefault.IsDirty);
|
||||
nodeDefault.CopyStyle(nodeCreated);
|
||||
Assert.IsTrue(nodeDefault.IsDirty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSame()
|
||||
{
|
||||
CSSNode nodeDefault = new CSSNode();
|
||||
CSSNode nodeCreated = CSSNode.Create();
|
||||
Assert.IsFalse(nodeDefault.IsDirty);
|
||||
nodeDefault.CopyStyle(nodeCreated);
|
||||
Assert.IsFalse(nodeDefault.IsDirty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMultiple()
|
||||
{
|
||||
CSSNode node = CSSNode.Create(
|
||||
positionType: CSSPositionType.Absolute,
|
||||
wrap: CSSWrap.Wrap,
|
||||
position: new Spacing(top:6, right:4),
|
||||
margin: new Spacing(bottom:5, left:3));
|
||||
|
||||
Assert.AreEqual(CSSFlexDirection.Column, node.FlexDirection);
|
||||
Assert.AreEqual(CSSPositionType.Absolute, node.PositionType);
|
||||
Assert.AreEqual(CSSWrap.Wrap, node.Wrap);
|
||||
Assert.AreEqual(6, node.GetPosition(CSSEdge.Top));
|
||||
Assert.IsTrue(CSSConstants.IsUndefined(node.GetPosition(CSSEdge.Bottom)));
|
||||
Assert.AreEqual(4, node.GetPosition(CSSEdge.Right));
|
||||
Assert.IsTrue(CSSConstants.IsUndefined(node.GetPosition(CSSEdge.Left)));
|
||||
Assert.AreEqual(0, node.GetMargin(CSSEdge.Top));
|
||||
Assert.AreEqual(5, node.GetMargin(CSSEdge.Bottom));
|
||||
Assert.AreEqual(3, node.GetMargin(CSSEdge.Left));
|
||||
Assert.AreEqual(0, node.GetMargin(CSSEdge.Right));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFull()
|
||||
{
|
||||
CSSNode node = CSSNode.Create(
|
||||
styleDirection: CSSDirection.RTL,
|
||||
flexDirection: CSSFlexDirection.RowReverse,
|
||||
|
||||
justifyContent: CSSJustify.SpaceAround,
|
||||
alignContent: CSSAlign.Center,
|
||||
alignItems: CSSAlign.FlexEnd,
|
||||
alignSelf: CSSAlign.Stretch,
|
||||
|
||||
positionType: CSSPositionType.Absolute,
|
||||
wrap: CSSWrap.Wrap,
|
||||
overflow: CSSOverflow.Scroll,
|
||||
|
||||
flex: 1,
|
||||
flexGrow: 2,
|
||||
flexShrink: 3,
|
||||
flexBasis: 4,
|
||||
|
||||
position: new Spacing(top: 5, bottom: 6, left: 7, right: 8),
|
||||
margin: new Spacing(top: 9, bottom: 10, left: 11, right: 12),
|
||||
padding: new Spacing(top: 13, bottom: 14, left: 15, right: 16),
|
||||
border: new Spacing(top: 17, bottom: 18, left: 19, right: 20),
|
||||
|
||||
styleWidth: 21,
|
||||
styleHeight: 22,
|
||||
styleMinWidth: 23,
|
||||
styleMinHeight: 24,
|
||||
styleMaxWidth: 25,
|
||||
styleMaxHeight: 26);
|
||||
|
||||
Assert.AreEqual(CSSDirection.RTL, node.StyleDirection);
|
||||
Assert.AreEqual(CSSFlexDirection.RowReverse, node.FlexDirection);
|
||||
|
||||
Assert.AreEqual(CSSJustify.SpaceAround, node.JustifyContent);
|
||||
Assert.AreEqual(CSSAlign.Center, node.AlignContent);
|
||||
Assert.AreEqual(CSSAlign.FlexEnd, node.AlignItems);
|
||||
Assert.AreEqual(CSSAlign.Stretch, node.AlignSelf);
|
||||
|
||||
Assert.AreEqual(CSSPositionType.Absolute, node.PositionType);
|
||||
Assert.AreEqual(CSSWrap.Wrap, node.Wrap);
|
||||
Assert.AreEqual(CSSOverflow.Scroll, node.Overflow);
|
||||
|
||||
Assert.AreEqual(2, node.FlexGrow);
|
||||
Assert.AreEqual(3, node.FlexShrink);
|
||||
Assert.AreEqual(4, node.FlexBasis);
|
||||
node.FlexGrow = CSSConstants.Undefined;
|
||||
Assert.AreEqual(1, node.FlexGrow);
|
||||
|
||||
Assert.AreEqual(5, node.GetPosition(CSSEdge.Top));
|
||||
Assert.AreEqual(6, node.GetPosition(CSSEdge.Bottom));
|
||||
Assert.AreEqual(7, node.GetPosition(CSSEdge.Left));
|
||||
Assert.AreEqual(8, node.GetPosition(CSSEdge.Right));
|
||||
|
||||
Assert.AreEqual(9, node.GetMargin(CSSEdge.Top));
|
||||
Assert.AreEqual(10, node.GetMargin(CSSEdge.Bottom));
|
||||
Assert.AreEqual(11, node.GetMargin(CSSEdge.Left));
|
||||
Assert.AreEqual(12, node.GetMargin(CSSEdge.Right));
|
||||
|
||||
Assert.AreEqual(13, node.GetPadding(CSSEdge.Top));
|
||||
Assert.AreEqual(14, node.GetPadding(CSSEdge.Bottom));
|
||||
Assert.AreEqual(15, node.GetPadding(CSSEdge.Left));
|
||||
Assert.AreEqual(16, node.GetPadding(CSSEdge.Right));
|
||||
|
||||
Assert.AreEqual(17, node.GetBorder(CSSEdge.Top));
|
||||
Assert.AreEqual(18, node.GetBorder(CSSEdge.Bottom));
|
||||
Assert.AreEqual(19, node.GetBorder(CSSEdge.Left));
|
||||
Assert.AreEqual(20, node.GetBorder(CSSEdge.Right));
|
||||
|
||||
Assert.AreEqual(21, node.StyleWidth);
|
||||
Assert.AreEqual(22, node.StyleHeight);
|
||||
Assert.AreEqual(23, node.StyleMinWidth);
|
||||
Assert.AreEqual(24, node.StyleMinHeight);
|
||||
Assert.AreEqual(25, node.StyleMaxWidth);
|
||||
Assert.AreEqual(26, node.StyleMaxHeight);
|
||||
}
|
||||
}
|
||||
}
|
361
csharp/tests/Facebook.CSSLayout/CSSNodeTest.cs
Normal file
361
csharp/tests/Facebook.CSSLayout/CSSNodeTest.cs
Normal file
@@ -0,0 +1,361 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
/**
|
||||
* Tests for {@link CSSNode}.
|
||||
*/
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
[TestFixture]
|
||||
public class CSSNodeTest
|
||||
{
|
||||
[Test]
|
||||
public void TestAddChildGetParent()
|
||||
{
|
||||
CSSNode parent = new CSSNode();
|
||||
CSSNode child = new CSSNode();
|
||||
|
||||
Assert.IsNull(child.Parent);
|
||||
Assert.AreEqual(0, parent.Count);
|
||||
|
||||
parent.Insert(0, child);
|
||||
|
||||
Assert.AreEqual(1, parent.Count);
|
||||
Assert.AreEqual(child, parent[0]);
|
||||
Assert.AreEqual(parent, child.Parent);
|
||||
|
||||
parent.RemoveAt(0);
|
||||
|
||||
Assert.IsNull(child.Parent);
|
||||
Assert.AreEqual(0, parent.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestChildren()
|
||||
{
|
||||
CSSNode parent = new CSSNode();
|
||||
foreach (CSSNode node in parent) {
|
||||
Assert.Fail(node.ToString());
|
||||
}
|
||||
|
||||
CSSNode child0 = new CSSNode();
|
||||
Assert.AreEqual(-1, parent.IndexOf(child0));
|
||||
parent.Insert(0, child0);
|
||||
foreach (CSSNode node in parent) {
|
||||
Assert.AreEqual(0, parent.IndexOf(node));
|
||||
}
|
||||
|
||||
CSSNode child1 = new CSSNode();
|
||||
parent.Insert(1, child1);
|
||||
int index = 0;
|
||||
foreach (CSSNode node in parent) {
|
||||
Assert.AreEqual(index++, parent.IndexOf(node));
|
||||
}
|
||||
|
||||
parent.RemoveAt(0);
|
||||
Assert.AreEqual(-1, parent.IndexOf(child0));
|
||||
Assert.AreEqual(0, parent.IndexOf(child1));
|
||||
|
||||
parent.Clear();
|
||||
Assert.AreEqual(0, parent.Count);
|
||||
|
||||
parent.Clear();
|
||||
Assert.AreEqual(0, parent.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.NullReferenceException")]
|
||||
public void TestRemoveAtFromEmpty()
|
||||
{
|
||||
CSSNode parent = new CSSNode();
|
||||
parent.RemoveAt(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.ArgumentOutOfRangeException")]
|
||||
public void TestRemoveAtOutOfRange()
|
||||
{
|
||||
CSSNode parent = new CSSNode();
|
||||
CSSNode child = new CSSNode();
|
||||
parent.Insert(0, child);
|
||||
parent.RemoveAt(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.InvalidOperationException")]
|
||||
public void TestCannotAddChildToMultipleParents()
|
||||
{
|
||||
CSSNode parent1 = new CSSNode();
|
||||
CSSNode parent2 = new CSSNode();
|
||||
CSSNode child = new CSSNode();
|
||||
|
||||
parent1.Insert(0, child);
|
||||
parent2.Insert(0, child);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestReset()
|
||||
{
|
||||
int instanceCount = CSSNode.GetInstanceCount();
|
||||
CSSNode node = new CSSNode();
|
||||
Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount());
|
||||
node.Reset();
|
||||
Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount());
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.InvalidOperationException")]
|
||||
public void TestResetParent()
|
||||
{
|
||||
CSSNode parent = new CSSNode();
|
||||
CSSNode child = new CSSNode();
|
||||
parent.Insert(0, child);
|
||||
parent.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.InvalidOperationException")]
|
||||
public void TestResetChild()
|
||||
{
|
||||
CSSNode parent = new CSSNode();
|
||||
CSSNode child = new CSSNode();
|
||||
parent.Insert(0, child);
|
||||
child.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestClear()
|
||||
{
|
||||
int instanceCount = CSSNode.GetInstanceCount();
|
||||
CSSNode parent = new CSSNode();
|
||||
Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount());
|
||||
CSSNode child = new CSSNode();
|
||||
Assert.AreEqual(instanceCount + 2, CSSNode.GetInstanceCount());
|
||||
parent.Insert(0, child);
|
||||
Assert.AreEqual(1, parent.Count);
|
||||
Assert.AreEqual(parent, child.Parent);
|
||||
parent.Clear();
|
||||
Assert.AreEqual(0, parent.Count);
|
||||
Assert.IsNull(child.Parent);
|
||||
Assert.AreEqual(instanceCount + 2, CSSNode.GetInstanceCount());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMeasureFunc()
|
||||
{
|
||||
CSSNode node = new CSSNode();
|
||||
node.SetMeasureFunction((_, width, widthMode, height, heightMode) => {
|
||||
return MeasureOutput.Make(100, 150);
|
||||
});
|
||||
node.CalculateLayout();
|
||||
Assert.AreEqual(100, node.LayoutWidth);
|
||||
Assert.AreEqual(150, node.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMeasureFuncWithFloat()
|
||||
{
|
||||
CSSNode node = new CSSNode();
|
||||
node.SetMeasureFunction((_, width, widthMode, height, heightMode) => {
|
||||
return MeasureOutput.Make(123.4f, 81.7f);
|
||||
});
|
||||
node.CalculateLayout();
|
||||
Assert.AreEqual(123, node.LayoutWidth);
|
||||
Assert.AreEqual(81, node.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.InvalidOperationException")]
|
||||
public void TestChildWithMeasureFunc()
|
||||
{
|
||||
CSSNode node = new CSSNode();
|
||||
node.SetMeasureFunction((_, width, widthMode, height, heightMode) => {
|
||||
return MeasureOutput.Make(100, 150);
|
||||
});
|
||||
CSSNode child = new CSSNode();
|
||||
node.Insert(0, child);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.InvalidOperationException")]
|
||||
public void TestMeasureFuncWithChild()
|
||||
{
|
||||
CSSNode node = new CSSNode();
|
||||
CSSNode child = new CSSNode();
|
||||
node.Insert(0, child);
|
||||
node.SetMeasureFunction((_, width, widthMode, height, heightMode) => {
|
||||
return MeasureOutput.Make(100, 150);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPrint()
|
||||
{
|
||||
CSSNode parent = new CSSNode();
|
||||
parent.StyleWidth = 100;
|
||||
parent.StyleHeight = 120;
|
||||
CSSNode child0 = new CSSNode();
|
||||
child0.StyleWidth = 30;
|
||||
child0.StyleHeight = 40;
|
||||
CSSNode child1 = new CSSNode();
|
||||
child1.StyleWidth = 35;
|
||||
child1.StyleHeight = 45;
|
||||
parent.Insert(0, child0);
|
||||
parent.Insert(0, child1);
|
||||
parent.CalculateLayout();
|
||||
Assert.AreEqual(parent.Print(), "{layout: {width: 100, height: 120, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 100, height: 120, children: [\n {layout: {width: 35, height: 45, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 35, height: 45, },\n {layout: {width: 30, height: 40, top: 45, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 30, height: 40, },\n]},\n");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCopyStyle()
|
||||
{
|
||||
CSSNode node0 = new CSSNode();
|
||||
Assert.IsTrue(CSSConstants.IsUndefined(node0.StyleMaxHeight));
|
||||
|
||||
CSSNode node1 = new CSSNode();
|
||||
node1.StyleMaxHeight = 100;
|
||||
|
||||
node0.CopyStyle(node1);
|
||||
Assert.AreEqual(100, node0.StyleMaxHeight);
|
||||
}
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
private void ForceGC()
|
||||
{
|
||||
GC.Collect(GC.MaxGeneration);
|
||||
GC.WaitForPendingFinalizers();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDestructor()
|
||||
{
|
||||
ForceGC();
|
||||
int instanceCount = CSSNode.GetInstanceCount();
|
||||
TestDestructorForGC(instanceCount);
|
||||
ForceGC();
|
||||
Assert.AreEqual(instanceCount, CSSNode.GetInstanceCount());
|
||||
}
|
||||
|
||||
private void TestDestructorForGC(int instanceCount)
|
||||
{
|
||||
CSSNode node = new CSSNode();
|
||||
Assert.IsNotNull(node);
|
||||
Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount());
|
||||
node = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDestructorWithChildren()
|
||||
{
|
||||
ForceGC();
|
||||
int instanceCount = CSSNode.GetInstanceCount();
|
||||
TestDestructorWithChildrenForGC1(instanceCount);
|
||||
ForceGC();
|
||||
Assert.AreEqual(instanceCount, CSSNode.GetInstanceCount());
|
||||
}
|
||||
|
||||
private void TestDestructorWithChildrenForGC1(int instanceCount)
|
||||
{
|
||||
CSSNode node = new CSSNode();
|
||||
Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount());
|
||||
|
||||
TestDestructorWithChildrenForGC2(node, instanceCount + 1);
|
||||
ForceGC();
|
||||
Assert.AreEqual(instanceCount + 2, CSSNode.GetInstanceCount());
|
||||
|
||||
TestDestructorWithChildrenForGC2(node, instanceCount + 2);
|
||||
ForceGC();
|
||||
Assert.AreEqual(instanceCount + 3, CSSNode.GetInstanceCount());
|
||||
|
||||
node = null;
|
||||
}
|
||||
|
||||
private void TestDestructorWithChildrenForGC2(CSSNode parent, int instanceCount)
|
||||
{
|
||||
CSSNode child = new CSSNode();
|
||||
Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount());
|
||||
|
||||
parent.Insert(0, child);
|
||||
child = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestParentDestructor()
|
||||
{
|
||||
ForceGC();
|
||||
int instanceCount = CSSNode.GetInstanceCount();
|
||||
CSSNode child = new CSSNode();
|
||||
Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount());
|
||||
|
||||
TestParentDestructorForGC(child, instanceCount + 1);
|
||||
ForceGC();
|
||||
|
||||
Assert.IsNull(child.Parent);
|
||||
Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount());
|
||||
}
|
||||
|
||||
private void TestParentDestructorForGC(CSSNode child, int instanceCount)
|
||||
{
|
||||
CSSNode parent = new CSSNode();
|
||||
Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount());
|
||||
parent.Insert(0, child);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestClearWithChildDestructor()
|
||||
{
|
||||
ForceGC();
|
||||
int instanceCount = CSSNode.GetInstanceCount();
|
||||
CSSNode node = new CSSNode();
|
||||
Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount());
|
||||
TestClearWithChildDestructorForGC(node, instanceCount + 1);
|
||||
ForceGC();
|
||||
Assert.AreEqual(instanceCount + 2, CSSNode.GetInstanceCount());
|
||||
node.Clear();
|
||||
Assert.AreEqual(0, node.Count);
|
||||
ForceGC();
|
||||
Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount());
|
||||
}
|
||||
|
||||
private void TestClearWithChildDestructorForGC(CSSNode parent, int instanceCount)
|
||||
{
|
||||
CSSNode child = new CSSNode();
|
||||
Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount());
|
||||
parent.Insert(0, child);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMeasureFuncWithDestructor()
|
||||
{
|
||||
ForceGC();
|
||||
int instanceCount = CSSNode.GetInstanceCount();
|
||||
CSSNode parent = new CSSNode();
|
||||
Assert.AreEqual(instanceCount + 1, CSSNode.GetInstanceCount());
|
||||
TestMeasureFuncWithDestructorForGC(parent);
|
||||
ForceGC();
|
||||
Assert.AreEqual(instanceCount + 2, CSSNode.GetInstanceCount());
|
||||
parent.CalculateLayout();
|
||||
Assert.AreEqual(120, (int)parent.LayoutWidth);
|
||||
Assert.AreEqual(130, (int)parent.LayoutHeight);
|
||||
}
|
||||
|
||||
private void TestMeasureFuncWithDestructorForGC(CSSNode parent)
|
||||
{
|
||||
CSSNode child = new CSSNode();
|
||||
parent.Insert(0, child);
|
||||
child.SetMeasureFunction((_, width, widthMode, height, heightMode) => {
|
||||
return MeasureOutput.Make(120, 130);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
33
csharp/tests/Facebook.CSSLayout/test_macos.sh
Executable file
33
csharp/tests/Facebook.CSSLayout/test_macos.sh
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/bin/sh
|
||||
if clang --version >/dev/null 2>&1; then true; else
|
||||
echo "ERROR: Can't execute clang. You need to install Xcode and command line tools."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if mcs --version >/dev/null 2>&1; then true; else
|
||||
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."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if mono --version >/dev/null 2>&1; then true; else
|
||||
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."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$( dirname "$0" )"
|
||||
|
||||
NUNIT=NUnit-2.6.4/bin
|
||||
if [ -d $NUNIT \
|
||||
-a -f $NUNIT/nunit-console.exe \
|
||||
-a -f $NUNIT/lib/nunit-console-runner.dll \
|
||||
-a -f $NUNIT/lib/nunit.core.dll \
|
||||
-a -f $NUNIT/lib/nunit.core.interfaces.dll \
|
||||
-a -f $NUNIT/lib/nunit.util.dll ]; then true; else
|
||||
curl -L -O https://github.com/nunit/nunitv2/releases/download/2.6.4/NUnit-2.6.4.zip
|
||||
unzip -qq NUnit-2.6.4.zip
|
||||
rm NUnit-2.6.4.zip
|
||||
fi
|
||||
|
||||
clang -g -Wall -Wextra -dynamiclib -o libCSSLayout.dylib -I../../.. ../../../CSSLayout/*.c ../../CSSLayout/CSSInterop.cpp
|
||||
mcs -debug -t:library -r:$NUNIT/nunit.framework.dll -out:CSSLayoutTest.dll *.cs ../../../csharp/Facebook.CSSLayout/*cs
|
||||
MONO_PATH=$NUNIT mono --arch=64 --debug $NUNIT/nunit-console.exe CSSLayoutTest.dll
|
17
dist/README.md
vendored
17
dist/README.md
vendored
@@ -1,17 +0,0 @@
|
||||
Releases can be found on [npm](https://www.npmjs.com/package/css-layout).
|
||||
|
||||
#Release Process
|
||||
|
||||
```bash
|
||||
# Ensure that the local codebase is up to date
|
||||
git fetch upstream master && git checkout FETCH_HEAD
|
||||
|
||||
# increment the version number and tag the release
|
||||
npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease]
|
||||
|
||||
# push the the commit and tag back to upstream
|
||||
git push --tags upstream HEAD:master
|
||||
|
||||
# publish this new version to npm
|
||||
npm publish
|
||||
```
|
1315
dist/css-layout.h
vendored
1315
dist/css-layout.h
vendored
File diff suppressed because it is too large
Load Diff
BIN
dist/css-layout.jar
vendored
BIN
dist/css-layout.jar
vendored
Binary file not shown.
1009
dist/css-layout.js
vendored
1009
dist/css-layout.js
vendored
File diff suppressed because it is too large
Load Diff
2
dist/css-layout.min.js
vendored
2
dist/css-layout.min.js
vendored
File diff suppressed because one or more lines are too long
1
dist/css-layout.min.js.map
vendored
1
dist/css-layout.min.js.map
vendored
File diff suppressed because one or more lines are too long
182
enums.py
Normal file
182
enums.py
Normal file
@@ -0,0 +1,182 @@
|
||||
# Copyright (c) 2014-present, Facebook, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the BSD-style license found in the
|
||||
# LICENSE file in the root directory of this source tree. An additional grant
|
||||
# of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
import os
|
||||
|
||||
ENUMS = {
|
||||
'CSSDirection': [
|
||||
'Inherit',
|
||||
'LTR',
|
||||
'RTL',
|
||||
],
|
||||
'CSSFlexDirection': [
|
||||
'Column',
|
||||
'ColumnReverse',
|
||||
'Row',
|
||||
'RowReverse',
|
||||
],
|
||||
'CSSJustify': [
|
||||
'FlexStart',
|
||||
'Center',
|
||||
'FlexEnd',
|
||||
'SpaceBetween',
|
||||
'SpaceAround',
|
||||
],
|
||||
'CSSOverflow': [
|
||||
'Visible',
|
||||
'Hidden',
|
||||
'Scroll',
|
||||
],
|
||||
'CSSAlign': [
|
||||
'Auto',
|
||||
'FlexStart',
|
||||
'Center',
|
||||
'FlexEnd',
|
||||
'Stretch',
|
||||
],
|
||||
'CSSPositionType': [
|
||||
'Relative',
|
||||
'Absolute',
|
||||
],
|
||||
'CSSWrap': [
|
||||
'NoWrap',
|
||||
'Wrap',
|
||||
],
|
||||
'CSSMeasureMode': [
|
||||
'Undefined',
|
||||
'Exactly',
|
||||
'AtMost',
|
||||
],
|
||||
'CSSDimension': [
|
||||
'Width',
|
||||
'Height',
|
||||
],
|
||||
'CSSEdge': [
|
||||
'Left',
|
||||
'Top',
|
||||
'Right',
|
||||
'Bottom',
|
||||
'Start',
|
||||
'End',
|
||||
'Horizontal',
|
||||
'Vertical',
|
||||
'All',
|
||||
],
|
||||
'CSSLogLevel': [
|
||||
'Error',
|
||||
'Warn',
|
||||
'Info',
|
||||
'Debug',
|
||||
'Verbose',
|
||||
],
|
||||
'CSSExperimentalFeature': [],
|
||||
'CSSPrintOptions': [
|
||||
('Layout', 1),
|
||||
('Style', 2),
|
||||
('Children', 4),
|
||||
],
|
||||
}
|
||||
|
||||
LICENSE = """/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
"""
|
||||
|
||||
def to_java_upper(symbol):
|
||||
symbol = str(symbol)
|
||||
out = ''
|
||||
for i in range(0, len(symbol)):
|
||||
c = symbol[i]
|
||||
if str.istitle(c) and i is not 0 and not str.istitle(symbol[i - 1]):
|
||||
out += '_'
|
||||
out += c.upper()
|
||||
return out
|
||||
|
||||
|
||||
root = os.path.dirname(__file__)
|
||||
|
||||
# write out C header
|
||||
with open(root + '/CSSLayout/CSSEnums.h', 'w') as f:
|
||||
f.write(LICENSE)
|
||||
remaining = len(ENUMS)
|
||||
for name, values in ENUMS.items():
|
||||
f.write('typedef enum %s {\n' % name)
|
||||
for value in values:
|
||||
if isinstance(value, tuple):
|
||||
f.write(' %s%s = %d,\n' % (name, value[0], value[1]))
|
||||
else:
|
||||
f.write(' %s%s,\n' % (name, value))
|
||||
f.write(' %sCount,\n' % name)
|
||||
f.write('} %s;\n' % name)
|
||||
if remaining > 1:
|
||||
f.write('\n')
|
||||
remaining = remaining - 1
|
||||
|
||||
# write out java files
|
||||
for name, values in ENUMS.items():
|
||||
with open(root + '/java/com/facebook/csslayout/%s.java' % name, 'w') as f:
|
||||
f.write(LICENSE)
|
||||
f.write('package com.facebook.csslayout;\n\n')
|
||||
f.write('public enum %s {\n' % name)
|
||||
if len(values) > 0:
|
||||
for value in values:
|
||||
if isinstance(value, tuple):
|
||||
f.write(' %s(%d)' % (to_java_upper(value[0]), value[1]))
|
||||
else:
|
||||
f.write(' %s(%d)' % (to_java_upper(value), values.index(value)))
|
||||
if values.index(value) is len(values) - 1:
|
||||
f.write(';\n')
|
||||
else:
|
||||
f.write(',\n')
|
||||
else:
|
||||
f.write('__EMPTY(-1);')
|
||||
f.write('\n')
|
||||
f.write(' private int mIntValue;\n')
|
||||
f.write('\n')
|
||||
f.write(' %s(int intValue) {\n' % name)
|
||||
f.write(' mIntValue = intValue;\n')
|
||||
f.write(' }\n')
|
||||
f.write('\n')
|
||||
f.write(' public int intValue() {\n')
|
||||
f.write(' return mIntValue;\n')
|
||||
f.write(' }\n')
|
||||
f.write('\n')
|
||||
f.write(' public static %s fromInt(int value) {\n' % name)
|
||||
f.write(' switch (value) {\n')
|
||||
for value in values:
|
||||
if isinstance(value, tuple):
|
||||
f.write(' case %d: return %s;\n' % (value[1], to_java_upper(value[0])))
|
||||
else:
|
||||
f.write(' case %d: return %s;\n' % (values.index(value), to_java_upper(value)))
|
||||
f.write(' default: throw new IllegalArgumentException("Unkown enum value: " + value);\n')
|
||||
f.write(' }\n')
|
||||
f.write(' }\n')
|
||||
f.write('}\n')
|
||||
|
||||
# write out csharp files
|
||||
for name, values in ENUMS.items():
|
||||
with open(root + '/csharp/Facebook.CSSLayout/%s.cs' % name, 'w') as f:
|
||||
f.write(LICENSE)
|
||||
f.write('namespace Facebook.CSSLayout\n{\n')
|
||||
f.write(' public enum %s\n {\n' % name)
|
||||
for value in values:
|
||||
if isinstance(value, tuple):
|
||||
f.write(' %s = %d,\n' % (value[0], value[1]))
|
||||
else:
|
||||
f.write(' %s,\n' % value)
|
||||
f.write(' }\n')
|
||||
f.write('}\n')
|
35
format.sh
Executable file
35
format.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
clang-format \
|
||||
-style="{ \
|
||||
AlignAfterOpenBracket: Align, \
|
||||
AlignEscapedNewlinesLeft: true, \
|
||||
AlignOperands: true, \
|
||||
AllowAllParametersOfDeclarationOnNextLine: false, \
|
||||
AllowShortBlocksOnASingleLine: false, \
|
||||
AllowShortCaseLabelsOnASingleLine: false, \
|
||||
AllowShortFunctionsOnASingleLine: false, \
|
||||
AllowShortIfStatementsOnASingleLine: false, \
|
||||
AllowShortLoopsOnASingleLine: false, \
|
||||
BinPackArguments: false, \
|
||||
BinPackParameters: false, \
|
||||
BreakBeforeBraces: Attach, \
|
||||
ColumnLimit: 100, \
|
||||
ContinuationIndentWidth: 4, \
|
||||
IndentCaseLabels: true, \
|
||||
IndentWidth: 2, \
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false, \
|
||||
Language: Cpp, \
|
||||
PenaltyBreakBeforeFirstCallParameter: 100, \
|
||||
PenaltyBreakString: 1000, \
|
||||
PenaltyExcessCharacter: 100, \
|
||||
PenaltyReturnTypeOnItsOwnLine: 100, \
|
||||
PointerAlignment: Right, \
|
||||
SortIncludes: true, \
|
||||
SpaceAfterCStyleCast: true, \
|
||||
UseTab: Never, \
|
||||
}" "$@" \
|
||||
-i $(dirname $0)/CSSLayout/*.{h,c,cpp} \
|
||||
$(dirname $0)/tests/CSSLayoutTestUtils/*.{h,c,cpp} \
|
||||
$(dirname $0)/benchmarks/*.{h,c,cpp} \
|
||||
$(dirname $0)/java/jni/*.{h,c,cpp}
|
26
gentest/fixtures/CSSLayoutAbsolutePositionTest.html
Normal file
26
gentest/fixtures/CSSLayoutAbsolutePositionTest.html
Normal file
@@ -0,0 +1,26 @@
|
||||
<div id="absolute_layout_width_height_start_top" style="width: 100px; height: 100px;">
|
||||
<div style="width:10px; height: 10px; position: absolute; start: 10px; top: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="absolute_layout_width_height_end_bottom" style="width: 100px; height: 100px;">
|
||||
<div style="width:10px; height: 10px; position: absolute; end: 10px; bottom: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="absolute_layout_start_top_end_bottom" style="width: 100px; height: 100px;">
|
||||
<div style="position: absolute; start: 10px; top: 10px; end: 10px; bottom: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="absolute_layout_width_height_start_top_end_bottom" style="width: 100px; height: 100px;">
|
||||
<div style="width:10px; height: 10px; position: absolute; start: 10px; top: 10px; end: 10px; bottom: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent" style="height: 50px; width: 50px; overflow: hidden; flex-direction: row;">
|
||||
<div style="position: absolute; start: 0px; top: 0px;">
|
||||
<div style="width: 100px; height: 100px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="absolute_layout_within_border" style="height:100px; width:100px; border-width: 10px; margin: 10px; padding: 10px;">
|
||||
<div style="position: absolute; width: 50px; height: 50px; left: 0px; top: 0px;"></div>
|
||||
<div style="position: absolute; width: 50px; height: 50px; right: 0px; bottom: 0px;"></div>
|
||||
</div>
|
31
gentest/fixtures/CSSLayoutAlignContentTest.html
Normal file
31
gentest/fixtures/CSSLayoutAlignContentTest.html
Normal file
@@ -0,0 +1,31 @@
|
||||
<div id="align_content_flex_start" style="width: 100px; height: 100px; flex-wrap: wrap; flex-direction: column; align-content: flex-start;">
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_content_flex_end" style="width: 100px; height: 100px; flex-wrap: wrap; flex-direction: column; align-content: flex-end;">
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_content_center" style="width: 100px; height: 100px; flex-wrap: wrap; flex-direction: column; align-content: center;">
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
<div style="width: 50px; height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_content_stretch" style="width: 100px; height: 100px; flex-wrap: wrap; flex-direction: column; align-content: stretch;">
|
||||
<div style="width: 50px;"></div>
|
||||
<div style="width: 50px;"></div>
|
||||
<div style="width: 50px;"></div>
|
||||
<div style="width: 50px;"></div>
|
||||
<div style="width: 50px;"></div>
|
||||
</div>
|
15
gentest/fixtures/CSSLayoutAlignItemsTest.html
Normal file
15
gentest/fixtures/CSSLayoutAlignItemsTest.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<div id="align_items_stretch" style="width: 100px; height: 100px;">
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_items_center" style="width: 100px; height: 100px; align-items: center;">
|
||||
<div style="height: 10px; width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_items_flex_start" style="width: 100px; height: 100px; align-items: flex-start;">
|
||||
<div style="height: 10px; width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_items_flex_end" style="width: 100px; height: 100px; align-items: flex-end;">
|
||||
<div style="height: 10px; width: 10px;"></div>
|
||||
</div>
|
15
gentest/fixtures/CSSLayoutAlignSelfTest.html
Normal file
15
gentest/fixtures/CSSLayoutAlignSelfTest.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<div id="align_self_center" style="width:100px; height: 100px;">
|
||||
<div style="height: 10px; width: 10px; align-self: center;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_self_flex_end" style="width:100px; height: 100px;">
|
||||
<div style="height: 10px; width: 10px; align-self: flex-end;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_self_flex_start" style="width:100px; height: 100px;">
|
||||
<div style="height: 10px; width: 10px; align-self: flex-start;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_self_flex_end_override_flex_start" style="width:100px; height: 100px; align-items: flex-start;">
|
||||
<div style="height: 10px; width: 10px; align-self: flex-end;"></div>
|
||||
</div>
|
18
gentest/fixtures/CSSLayoutBorderTest.html
Normal file
18
gentest/fixtures/CSSLayoutBorderTest.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<div id="border_no_size" style="border-width: 10px;">
|
||||
</div>
|
||||
|
||||
<div id="border_container_match_child" style="border-width: 10px;">
|
||||
<div style="width: 10px; height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="border_flex_child" style="width: 100px; height: 100px; border-width: 10px;">
|
||||
<div style="width: 10px; flex-grow:1"></div>
|
||||
</div>
|
||||
|
||||
<div id="border_stretch_child" style="width: 100px; height: 100px; border-width: 10px;">
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="border_center_child" style="width: 100px; height: 100px; border-start-width: 10px; border-top-width: 10; border-end-width: 20px; border-bottom-width: 20px; align-items: center; justify-content: center;">
|
||||
<div style="height: 10px; width: 10px;"></div>
|
||||
</div>
|
35
gentest/fixtures/CSSLayoutFlexDirectionTest.html
Normal file
35
gentest/fixtures/CSSLayoutFlexDirectionTest.html
Normal file
@@ -0,0 +1,35 @@
|
||||
<div id="flex_direction_column_no_height" style="width: 100px">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_direction_row_no_width" style="height: 100px; flex-direction: row;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_direction_column" style="height: 100px; width: 100px;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_direction_row" style="height: 100px; width: 100px; flex-direction: row;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_direction_column_reverse" style="height: 100px; width: 100px; flex-direction: column-reverse;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_direction_row_reverse" style="height: 100px; width: 100px; flex-direction: row-reverse;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
37
gentest/fixtures/CSSLayoutFlexTest.html
Normal file
37
gentest/fixtures/CSSLayoutFlexTest.html
Normal file
@@ -0,0 +1,37 @@
|
||||
<div id="flex_basis_flex_grow_column" style="width: 100px; height: 100px;">
|
||||
<div style="flex-basis: 50px; flex-grow: 1;"></div>
|
||||
<div style="flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_basis_flex_grow_row" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="flex-basis: 50px; flex-grow: 1;"></div>
|
||||
<div style="flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_basis_flex_shrink_column" style="width: 100px; height: 100px;">
|
||||
<div style="flex-basis: 100px; flex-shrink: 1;"></div>
|
||||
<div style="flex-basis: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_basis_flex_shrink_row" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="flex-basis: 100px; flex-shrink: 1;"></div>
|
||||
<div style="flex-basis: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_shrink_to_zero" style="height: 75px;">
|
||||
<div style="width: 50px; height: 50px; flex-shrink:0;"></div>
|
||||
<div style="width: 50px; height: 50px; flex-shrink:1;"></div>
|
||||
<div style="width: 50px; height: 50px; flex-shrink:0;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_basis_overrides_main_size" style="height: 100px; width: 100px;">
|
||||
<div style="height: 20px; flex-grow:1; flex-basis:50px;"></div>
|
||||
<div style="height: 10px; flex-grow:1;"></div>
|
||||
<div style="height: 10px; flex-grow:1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_grow_shrink_at_most" style="height: 100px; width: 100px;">
|
||||
<div>
|
||||
<div style="flex-grow:1; flex-shrink:1;"></div>
|
||||
</div>
|
||||
</div>
|
27
gentest/fixtures/CSSLayoutFlexWrapTest.html
Normal file
27
gentest/fixtures/CSSLayoutFlexWrapTest.html
Normal file
@@ -0,0 +1,27 @@
|
||||
<div id="wrap_column" style="height: 100px; flex-wrap: wrap">
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="wrap_row" style="width: 100px; flex-direction: row; flex-wrap: wrap">
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="wrap_row_align_items_flex_end" style="width: 100px; flex-direction: row; flex-wrap: wrap; align-items: flex-end;">
|
||||
<div style="height: 10px; width: 30px;"></div>
|
||||
<div style="height: 20px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="wrap_row_align_items_center" style="width: 100px; flex-direction: row; flex-wrap: wrap; align-items: center;">
|
||||
<div style="height: 10px; width: 30px;"></div>
|
||||
<div style="height: 20px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
<div style="height: 30px; width: 30px;"></div>
|
||||
</div>
|
59
gentest/fixtures/CSSLayoutJustifyContentTest.html
Normal file
59
gentest/fixtures/CSSLayoutJustifyContentTest.html
Normal file
@@ -0,0 +1,59 @@
|
||||
<div id="justify_content_row_flex_start" style="width: 102px; height: 102px; flex-direction: row; justify-content: flex-start;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_row_flex_end" style="width: 102px; height: 102px; flex-direction: row; justify-content: flex-end;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_row_center" style="width: 102px; height: 102px; flex-direction: row; justify-content: center;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_row_space_between" style="width: 102px; height: 102px; flex-direction: row; justify-content: space-between;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_row_space_around" style="width: 102px; height: 102px; flex-direction: row; justify-content: space-around;">
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
<div style="width: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_column_flex_start" style="width: 102px; height: 102px; justify-content: flex-start;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="heigth: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_column_flex_end" style="width: 102px; height: 102px; justify-content: flex-end;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_column_center" style="width: 102px; height: 102px; justify-content: center;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_column_space_between" style="width: 102px; height: 102px; justify-content: space-between;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_column_space_around" style="width: 102px; height: 102px; justify-content: space-around;">
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
41
gentest/fixtures/CSSLayoutMarginTest.html
Normal file
41
gentest/fixtures/CSSLayoutMarginTest.html
Normal file
@@ -0,0 +1,41 @@
|
||||
<div id="margin_start" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="width: 10px; margin-start: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_top" style="width: 100px; height: 100px;">
|
||||
<div style="height: 10px; margin-top: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_end" style="width: 100px; height: 100px; flex-direction: row; justify-content: flex-end;">
|
||||
<div style="width: 10px; margin-end: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_bottom" style="width: 100px; height: 100px; justify-content: flex-end;">
|
||||
<div style="height: 10px; margin-bottom: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_and_flex_row" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="margin-start: 10px; margin-end; 10px; flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_and_flex_column" style="width: 100px; height: 100px;">
|
||||
<div style="margin-top: 10px; margin-bottom; 10px; flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_and_stretch_row" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="margin-top: 10px; margin-bottom; 10px; flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_and_stretch_column" style="width: 100px; height: 100px;">
|
||||
<div style="margin-start: 10px; margin-end; 10px; flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_with_sibling_row" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="margin-end; 10px; flex-grow: 1;"></div>
|
||||
<div style="flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="margin_with_sibling_column" style="width: 100px; height: 100px;">
|
||||
<div style="margin-bottom; 10px; flex-grow: 1;"></div>
|
||||
<div style="flex-grow: 1;"></div>
|
||||
</div>
|
43
gentest/fixtures/CSSLayoutMinMaxDimensionTest.html
Normal file
43
gentest/fixtures/CSSLayoutMinMaxDimensionTest.html
Normal file
@@ -0,0 +1,43 @@
|
||||
<div id="max_width" style="width: 100px; height: 100px;">
|
||||
<div style="height: 10px; max-width: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="max_height" style="width: 100px; height: 100px; flex-direction: row;">
|
||||
<div style="width: 10px; max-height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="min_height" style="width: 100px; height: 100px;">
|
||||
<div style="flex-grow: 1; min-height: 60px;"></div>
|
||||
<div style="flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="min_width" style="width: 100px; height: 100px; flex-direction: row">
|
||||
<div style="flex-grow: 1; min-width: 60px;"></div>
|
||||
<div style="flex-grow: 1;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_min_max" style="max-height: 200px; min-height: 100px; width: 100px; justify-content: center;">
|
||||
<div style="width: 60px; height: 60px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="align_items_min_max" style="max-width: 200px; min-width: 100px; height: 100px; align-items: center;">
|
||||
<div style="width: 60px; height: 60px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="justify_content_overflow_min_max" style="min-height: 100px; max-height: 110px; justify-content: center;">
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
<div style="width: 50px; height: 50px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="flex_grow_within_max_width" style="width: 200px; height: 100px;">
|
||||
<div style="flex-direction: row; max-width: 100px;">
|
||||
<div style="height: 20px; flex-grow: 1;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="flex_grow_within_constrained_max_width" style="width: 200px; height: 100px;">
|
||||
<div style="flex-direction: row; max-width: 300px;">
|
||||
<div style="height: 20px; flex-grow: 1;"></div>
|
||||
</div>
|
||||
</div>
|
18
gentest/fixtures/CSSLayoutPaddingTest.html
Normal file
18
gentest/fixtures/CSSLayoutPaddingTest.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<div id="padding_no_size" style="padding: 10px;">
|
||||
</div>
|
||||
|
||||
<div id="padding_container_match_child" style="padding: 10px;">
|
||||
<div style="width: 10px; height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="padding_flex_child" style="width: 100px; height: 100px; padding: 10px;">
|
||||
<div style="width: 10px; flex-grow:1"></div>
|
||||
</div>
|
||||
|
||||
<div id="padding_stretch_child" style="width: 100px; height: 100px; padding: 10px;">
|
||||
<div style="height: 10px;"></div>
|
||||
</div>
|
||||
|
||||
<div id="padding_center_child" style="width: 100px; height: 100px; padding-start: 10px; padding-top: 10; padding-end: 20px; padding-bottom: 20px; align-items: center; justify-content: center;">
|
||||
<div style="height: 10px; width: 10px;"></div>
|
||||
</div>
|
203
gentest/gentest-cpp.js
Normal file
203
gentest/gentest-cpp.js
Normal file
@@ -0,0 +1,203 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
var CPPEmitter = function() {
|
||||
Emitter.call(this, 'cpp', ' ');
|
||||
};
|
||||
|
||||
CPPEmitter.prototype = Object.create(Emitter.prototype, {
|
||||
constructor:{value:CPPEmitter},
|
||||
|
||||
emitPrologue:{value:function() {
|
||||
this.push([
|
||||
'#include <CSSLayout/CSSLayout.h>',
|
||||
'#include <gtest/gtest.h>',
|
||||
'',
|
||||
]);
|
||||
}},
|
||||
|
||||
emitTestPrologue:{value:function(name) {
|
||||
this.push('TEST(CSSLayoutTest, ' + name + ') {');
|
||||
this.pushIndent();
|
||||
}},
|
||||
|
||||
emitTestTreePrologue:{value:function(nodeName) {
|
||||
this.push('const CSSNodeRef ' + nodeName + ' = CSSNodeNew();');
|
||||
}},
|
||||
|
||||
emitTestEpilogue:{value:function() {
|
||||
this.push([
|
||||
'',
|
||||
'CSSNodeFreeRecursive(root);',
|
||||
]);
|
||||
this.popIndent();
|
||||
this.push([
|
||||
'}',
|
||||
'',
|
||||
]);
|
||||
}},
|
||||
|
||||
emitEpilogue:{value:function() {
|
||||
}},
|
||||
|
||||
AssertEQ:{value:function(v0, v1) {
|
||||
this.push('ASSERT_EQ(' + v0 + ', ' + v1 + ');');
|
||||
}},
|
||||
|
||||
CSSAlignAuto:{value:'CSSAlignAuto'},
|
||||
CSSAlignCenter:{value:'CSSAlignCenter'},
|
||||
CSSAlignFlexEnd:{value:'CSSAlignFlexEnd'},
|
||||
CSSAlignFlexStart:{value:'CSSAlignFlexStart'},
|
||||
CSSAlignStretch:{value:'CSSAlignStretch'},
|
||||
|
||||
CSSDirectionInherit:{value:'CSSDirectionInherit'},
|
||||
CSSDirectionLTR:{value:'CSSDirectionLTR'},
|
||||
CSSDirectionRTL:{value:'CSSDirectionRTL'},
|
||||
|
||||
CSSEdgeBottom:{value:'CSSEdgeBottom'},
|
||||
CSSEdgeEnd:{value:'CSSEdgeEnd'},
|
||||
CSSEdgeLeft:{value:'CSSEdgeLeft'},
|
||||
CSSEdgeRight:{value:'CSSEdgeRight'},
|
||||
CSSEdgeStart:{value:'CSSEdgeStart'},
|
||||
CSSEdgeTop:{value:'CSSEdgeTop'},
|
||||
|
||||
CSSFlexDirectionColumn:{value:'CSSFlexDirectionColumn'},
|
||||
CSSFlexDirectionColumnReverse:{value:'CSSFlexDirectionColumnReverse'},
|
||||
CSSFlexDirectionRow:{value:'CSSFlexDirectionRow'},
|
||||
CSSFlexDirectionRowReverse:{value:'CSSFlexDirectionRowReverse'},
|
||||
|
||||
CSSJustifyCenter:{value:'CSSJustifyCenter'},
|
||||
CSSJustifyFlexEnd:{value:'CSSJustifyFlexEnd'},
|
||||
CSSJustifyFlexStart:{value:'CSSJustifyFlexStart'},
|
||||
CSSJustifySpaceAround:{value:'CSSJustifySpaceAround'},
|
||||
CSSJustifySpaceBetween:{value:'CSSJustifySpaceBetween'},
|
||||
|
||||
CSSOverflowHidden:{value:'CSSOverflowHidden'},
|
||||
CSSOverflowVisible:{value:'CSSOverflowVisible'},
|
||||
|
||||
CSSPositionTypeAbsolute:{value:'CSSPositionTypeAbsolute'},
|
||||
CSSPositionTypeRelative:{value:'CSSPositionTypeRelative'},
|
||||
|
||||
CSSWrapNoWrap:{value:'CSSWrapNoWrap'},
|
||||
CSSWrapWrap:{value:'CSSWrapWrap'},
|
||||
|
||||
CSSUndefined:{value:'CSSUndefined'},
|
||||
|
||||
CSSNodeCalculateLayout:{value:function(node, dir) {
|
||||
this.push('CSSNodeCalculateLayout(' + node + ', CSSUndefined, CSSUndefined, ' + dir + ');');
|
||||
}},
|
||||
|
||||
CSSNodeInsertChild:{value:function(parentName, nodeName, index) {
|
||||
this.push('CSSNodeInsertChild(' + parentName + ', ' + nodeName + ', ' + index + ');');
|
||||
}},
|
||||
|
||||
CSSNodeLayoutGetLeft:{value:function(nodeName) {
|
||||
return 'CSSNodeLayoutGetLeft(' + nodeName + ')';
|
||||
}},
|
||||
|
||||
CSSNodeLayoutGetTop:{value:function(nodeName) {
|
||||
return 'CSSNodeLayoutGetTop(' + nodeName + ')';
|
||||
}},
|
||||
|
||||
CSSNodeLayoutGetWidth:{value:function(nodeName) {
|
||||
return 'CSSNodeLayoutGetWidth(' + nodeName + ')';
|
||||
}},
|
||||
|
||||
CSSNodeLayoutGetHeight:{value:function(nodeName) {
|
||||
return 'CSSNodeLayoutGetHeight(' + nodeName + ')';
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetAlignContent:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetAlignContent(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetAlignItems:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetAlignItems(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetAlignSelf:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetAlignSelf(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetBorder:{value:function(nodeName, edge, value) {
|
||||
this.push('CSSNodeStyleSetBorder(' + nodeName + ', ' + edge + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetDirection:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetDirection(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetFlexBasis:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetFlexBasis(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetFlexDirection:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetFlexDirection(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetFlexGrow:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetFlexGrow(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetFlexShrink:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetFlexShrink(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetFlexWrap:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetFlexWrap(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetHeight:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetHeight(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetJustifyContent:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetJustifyContent(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetMargin:{value:function(nodeName, edge, value) {
|
||||
this.push('CSSNodeStyleSetMargin(' + nodeName + ', ' + edge + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetMaxHeight:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetMaxHeight(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetMaxWidth:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetMaxWidth(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetMinHeight:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetMinHeight(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetMinWidth:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetMinWidth(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetOverflow:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetOverflow(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetPadding:{value:function(nodeName, edge, value) {
|
||||
this.push('CSSNodeStyleSetPadding(' + nodeName + ', ' + edge + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetPosition:{value:function(nodeName, edge, value) {
|
||||
this.push('CSSNodeStyleSetPosition(' + nodeName + ', ' + edge + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetPositionType:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetPositionType(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
|
||||
CSSNodeStyleSetWidth:{value:function(nodeName, value) {
|
||||
this.push('CSSNodeStyleSetWidth(' + nodeName + ', ' + value + ');');
|
||||
}},
|
||||
});
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user