Commit Graph

248 Commits

Author SHA1 Message Date
Kazuki Sakamoto
0bb2955c5c CSSNodeCopyStyle API for Java and C#
Summary: Add CopyStyle API for Java and C#

Reviewed By: emilsjolander

Differential Revision: D4189954

fbshipit-source-id: 10759fdb27bf67350d3151614f7815aa09bf7e04
2016-11-17 09:22:37 -08:00
Kazuki Sakamoto
7e4bb732ff Introduce CSSNode.Create API
Summary:
Add a convenience construction method for CSSNode.

    CSSNode node = CSSNode.Create(
        positionType: CSSPositionType.Absolute,
        wrap: CSSWrap.Wrap,
        position: new Spacing(top:6, right:4),
        margin: new Spacing(bottom:5, left:3));

Reviewed By: emilsjolander

Differential Revision: D4193380

fbshipit-source-id: 30b917f64e92997355a76e3b11799883b86fb9de
2016-11-17 07:07:32 -08:00
Kazuki Sakamoto
667858990c Fix build
Summary: Fix C# build

Reviewed By: emilsjolander

Differential Revision: D4183287

fbshipit-source-id: 7dda449a940589de1d37f4024964a6512ab123e3
2016-11-15 17:37:34 -08:00
Kazuki Sakamoto
d80bac4234 Use LTR and RTL instead obsolete enums
Summary: Use LTR and RTL instead obsolete LeftToRight and RightToLeft enums

Reviewed By: emilsjolander

Differential Revision: D4175897

fbshipit-source-id: d22af46d3292f9ad1754f571e95cb64b11722f7b
2016-11-15 09:22:45 -08:00
Emil Sjolander
d1c555fede Autogenerate enum defenitions for all languages
Summary: Keeping enums in sync between all the different bindings is tedious and error prone. Getting one of the values in the incorrect order could lead to many hours of debugging as they are passed as ints to C. This diff adds a simple python script to generate these enums for all languages. This also makes it much easier to add support for more languages in the future

Reviewed By: gkassabli

Differential Revision: D4174263

fbshipit-source-id: 478961a8f683e196704d3c6ea1505a05c85fcb10
2016-11-15 08:52:59 -08:00
Fred Liu
204aba80b9 Revert D4157971: [csslayout] BREAKING - Fix sizing of container with child overflowing parent
Summary: This reverts commit 3cfae15ac8b65b70f01789444099ee684e1b099a

Differential Revision: D4157971

fbshipit-source-id: be055cf018fd39b3cee9af0bc777831fcf757190
2016-11-14 12:22:58 -08:00
Emil Sjolander
e6702e1168 Implement standard interface for toggling experimental features
Summary: We want to start experimenting with changes to the library in a more controlled and easier to measure manner. This diff adds the basics of an experiment layer to csslayout.

Reviewed By: gkassabli

Differential Revision: D4174260

fbshipit-source-id: ad3667183810c02833fba9a1276f89286e848fcd
2016-11-14 03:37:45 -08:00
Emil Sjolander
7a3df9999b BREAKING - Fix sizing of container with child overflowing parent
Summary:
Fixes issue brought up in https://github.com/facebook/react-native/issues/10603

The gist of the problem is that in css it is fine for a child to overflow a parent if it feels the need to, we were not respecting this.

Reviewed By: gkassabli

Differential Revision: D4157971

fbshipit-source-id: 3cfae15ac8b65b70f01789444099ee684e1b099a
2016-11-14 02:22:44 -08:00
Kazuki Sakamoto
e40af30fa5 Update .travis.yml for C# test
Summary: Closes https://github.com/facebook/css-layout/pull/246

Reviewed By: emilsjolander

Differential Revision: D4167133

Pulled By: splhack

fbshipit-source-id: d55c0ff5155311f4da859b12b6485b120dac480b
2016-11-11 09:07:44 -08:00
Emil Sjolander
aaa977f645 Fix flex within max size if max size is not constraint to
Summary: Previous fix for flex in max size constraint was not entirely correct and was missing a test case for the time when the max constraint is not applied. This diff addresses that.

Reviewed By: gkassabli

Differential Revision: D4162104

fbshipit-source-id: 08feba6cb4e789c9aa12179e2cdeadc66b011841
2016-11-11 08:07:42 -08:00
Kazuki Sakamoto
0dbbfc5910 Add convenient cast method for MeasureOutput.Make
Summary: Same as Java, it allows to use float and double values in Make arguments.

Reviewed By: emilsjolander

Differential Revision: D4163347

fbshipit-source-id: f373247b3f37e7940a66044000cca2935068decf
2016-11-10 19:22:36 -08:00
Kazuki Sakamoto
c382d513fb Remove CSSAssertSetFailFunc
Summary: Remove CSSAssertSetFailFunc and use CSSLogLevelError for throwing managed exception.

Reviewed By: emilsjolander

Differential Revision: D4155452

fbshipit-source-id: 5a19c79a212f204d13064527fd6e5843bab76e6b
2016-11-09 17:38:10 -08:00
Kazuki Sakamoto
8a7183f465 Add tests for SetMeasureFunction
Summary: Add tests for checking C side asserts in managed

Reviewed By: emilsjolander

Differential Revision: D4154869

fbshipit-source-id: 5203db27eff963d46f188de448f607a24ed63fab
2016-11-09 13:23:00 -08:00
Emil Sjolander
ff602d4606 Absolute positioned items should apear inside padding but outside border
Summary:
Absolute positioned elements were not correctly respecting border / padding.

https://github.com/facebook/css-layout/issues/245
fixes #245

Reviewed By: gkassabli

Differential Revision: D4153332

fbshipit-source-id: 251e29e02018a433f60349b78c03feb121512797
2016-11-09 11:52:54 -08:00
Emil Sjolander
a253c6fbb7 Dont measure single flex grow+shrink child
Summary:
If there is a single child which is flex grow and flex shrink then instead of measuring and then shrinking we can just set the flex basis to zero as we know the final result will be that the child take up all remaining space.

This is a re-land of D4147298. I have updated the diff to check explicitly for exact measure mode to also handle at_most case correctly.

Reviewed By: gkassabli

Differential Revision: D4153133

fbshipit-source-id: 2333150a83857cc30078cc8d52761cbd00652830
2016-11-09 11:37:48 -08:00
Kazuki Sakamoto
863378d74e Sync Logger API
Summary: - Sync Logger API with C implementation

Reviewed By: emilsjolander

Differential Revision: D4143019

fbshipit-source-id: f20203320bad5b8f4b9cce01a5b2e7c615a4d923
2016-11-09 10:22:42 -08:00
Emil Sjolander
6a6efe0764 change default value of position styles
Summary: Default value for positions should be undefined not 0px. Fixing this leads to more correct tests.

Reviewed By: gkassabli

Differential Revision: D4153329

fbshipit-source-id: d0f194f9c47eac93d3815ec7e55568a1016bc7fe
2016-11-09 09:22:40 -08:00
Emil Sjolander
3e567fdcae Fix flex within max width constraint
Summary:
Max dimension constraints were not correctly passed down to children.

see https://github.com/facebook/css-layout/issues/230 for more info
fixes #230

Reviewed By: gkassabli

Differential Revision: D4147199

fbshipit-source-id: feb335eb8687a1b7939ee8cd8649e455e0c069a9
2016-11-08 09:53:00 -08:00
Emil Sjolander
1baa239389 Remove isTextNode optimization
Summary: Scrolling through feed and logging when this optimization is hit leads to... 0 logs. If anything this just adds to confusion. It was initially added due to instinct and not data, which was a mistake. I am happy to add some similar optimization in the future if we have data that it is useful in real world situations, currently it just leads to bugs and confusion though.

Reviewed By: astreet

Differential Revision: D4146785

fbshipit-source-id: e20d780fbd5759b8f38b809e8cadf29cedee82a8
2016-11-08 09:22:38 -08:00
Kazuki Sakamoto
ba2905dd1d Add C# test script for macOS
Summary: - Updated README and added bash script for testing C# on macOS

Reviewed By: emilsjolander

Differential Revision: D4142507

fbshipit-source-id: c682778e42d10242e02f3fdafe8a23f906bfabc5
2016-11-07 19:37:57 -08:00
Kazuki Sakamoto
3201e24780 Fix build and clean up
Summary:
- bit operation with long
- Clean up _measureOutput which is no longer needed
- Fix unittests (SetMeasureFunction, unused error)

Reviewed By: emilsjolander

Differential Revision: D4082401

fbshipit-source-id: b3b2dd002d108c5b43f36a4a73ce8e5233281b45
2016-10-27 11:53:11 -07:00
Emil Sjolander
46823878a5 BREAKING - Make first parameter of measure and print functions CSSNodeRef instead of just context
Summary: To perform some JNI optimizations for java we need a reference to the node in the measure function. This updates the API to provide the whole node as input instead of just the context.

Reviewed By: javache

Differential Revision: D4081544

fbshipit-source-id: d49679025cea027cf7b8482898de0a01fe0f9d40
2016-10-27 10:52:57 -07:00
Emil Sjolander
b59ce09109 BREAKING - Change measure() api to remove need for MeasureOutput allocation
Summary: This is an API breaking change done to allow us to avoid an allocation during measurement. Instead we do the same trick as is done when passing measure results to C, we path them into a long.

Reviewed By: splhack

Differential Revision: D4081037

fbshipit-source-id: 28adbcdd160cbd3f59a0fdd4b9f1200ae18678f1
2016-10-27 10:52:57 -07:00
Emil Sjolander
c34299edc9 Reset java state in jni reset method
Summary: This state was never reset when we switched to doing reset in C instead of re-allocating.

Differential Revision: D4081049

fbshipit-source-id: 0b9ad70339ad906ad5219ad2679329cfe2fd7abc
2016-10-26 07:37:47 -07:00
Kazuki Sakamoto
1ba81d9ec7 Prevent GC and avoid new
Summary:
- Prevent the GC from collecting MeasureInternal in order to call managed MeasureFunction properly from unmanaged
  - TestMeasureFuncWithDestructor will fail without the fix
- Avoid new as C implementation

Reviewed By: emilsjolander

Differential Revision: D4080765

fbshipit-source-id: d58fa18f6f74012aeda5dd15dfa7ceb0b64584d0
2016-10-26 06:52:41 -07:00
Lukas Wöhrl
c8d77b2aae Remove children from the end to prevent copying over
Summary:
This PR leads to removing the children from the end. [So we don't have the overhead of copying them to the front](dcaef7ecb0/CSSLayout/CSSNodeList.c (L62)).
Closes https://github.com/facebook/css-layout/pull/233

Reviewed By: emilsjolander

Differential Revision: D4075905

Pulled By: splhack

fbshipit-source-id: d8b460badb01bfc6ea647004c799395b9cab9e7c
2016-10-25 12:22:48 -07:00
Kazuki Sakamoto
2168d68007 Update CSSNodeFree for C#, Java and Objective-C
Summary:
- Update CSSNodeFree to unlink parent and children for C#, Java and Objective-C bindings finalizer.
- [C#] Fix build (Fix #232)
- [C#] Add Clear API for convenience as CSSNodeFreeRecursive.
- [C#] Revise and add unit tests

Reviewed By: emilsjolander

Differential Revision: D4069655

fbshipit-source-id: 1fd764059784d7968af38b6aaf7fb6f70fdee8ee
2016-10-25 07:52:39 -07:00
Kazuki Sakamoto
4452c7be5c Remove no longer needed Spacing.cs
Summary: - Remove no longer needed Spacing.cs

Reviewed By: emilsjolander

Differential Revision: D4073539

fbshipit-source-id: 916cf85119c6bac3d516de5396ea3ba7b0af1475
2016-10-25 07:08:00 -07:00
Emil Sjolander
e9b9973cae Dont create a spacing object for returning margin, padding, border, and position
Summary: The current implementation was made out of simplicity and to keep the same API as before. Now that the java version of csslayout is deprecated it is time to change the API to make the calls more efficient for the JNI version. This diff with reduce allocations as well as reduce the number of JNI calls done.

Differential Revision: D4050773

fbshipit-source-id: 3fd04c27f887a36875e455b5404a17154ac18f91
2016-10-24 10:37:51 -07:00
Emil Sjolander
69c374e74e Simplify memory model between managed and unmanaged memory
Summary: Instead of having different lifetimes for java and c memory we can can tie them together and make them much easier to manage. This also leads to automatically pooling native memory if pooling java memory.

Differential Revision: D4051454

fbshipit-source-id: 8f5d010be520b3d1c981a7f85e5e6d95773ea6c1
2016-10-24 10:37:51 -07:00
Emil Sjolander
4c57029a28 Remove flex shorthand getter because it doesnt make a lot of sense
Summary: It doesn't make sense to have a getter for the shorthand as it is the computed flexGrow and flexShrink values that you should care about.

Reviewed By: gkassabli

Differential Revision: D4064674

fbshipit-source-id: 69935b85042020b4e8c61a393c1be8f4d42a6674
2016-10-24 03:37:49 -07:00
Kazuki Sakamoto
ef538a45cd Add generated tests
Summary: - Add Java and C# test code generated by gentest

Reviewed By: emilsjolander

Differential Revision: D4065904

fbshipit-source-id: c0d489f37ee0a3132185636812057dc95725d59a
2016-10-23 10:37:39 -07:00
mattpodwysocki
1488f822c3 Fix C# delegate calling conventions
Summary:
When using CSS-Layout in a C# UWP project in x86, by default the MSVC compiler defaults the delegate calling convention to cdecl, while .NET assumes that all delegates are declared using stdcall.  This causes a problem when invoking such as this error:

```
Run-Time Check Failure #0 - The value of ESP was not properly saved across
a function call.  This is usually a result of calling a function declared with one
calling convention with a function pointer declared with a different calling
convention.
```

This PR changes the calling convention in the C# code to reflect cdecl by using the `UnmanagedFunctionPointer` attribute and setting the calling convention to `CallingConvention.Cdecl`.

```csharp
 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  public delegate CSSSize CSSMeasureFunc(
        IntPtr context,
        float width,
        CSSMeasureMode widthMode,
        float height,
        CSSMeasureMode heightMode);
```

I have updated all calls as well to other functions.  I
Closes https://github.com/facebook/css-layout/pull/231

Reviewed By: emilsjolander

Differential Revision: D4063437

Pulled By: splhack

fbshipit-source-id: b1069a1b9f675d2623a64a1c5f3189292a18a646
2016-10-22 09:52:42 -07:00
Kazuki Sakamoto
daed6f5b8a Introduce CSSLayoutSetLogger to pass the print result to C# side
Summary:
- CSSLayoutSetLogger
  - Problem: Unity or other logging system can't use printf output
  - Solution: Add CSSLogger to pass CSSNodePrint result to UnityEngine.Debug.Log or other logging system via CSSLogger function for debugging purpose

Reviewed By: emilsjolander

Differential Revision: D4027044

fbshipit-source-id: 90e2e449260888770f71fa7ea790ca9764d91c44
2016-10-19 11:08:08 -07:00
Kazuki Sakamoto
832d07902e Modify unittest
Summary:
- Disable destructor tests in Unity Editor, seems GC is flaky.
- Use current native instance counts

Reviewed By: emilsjolander

Differential Revision: D4018951

fbshipit-source-id: a57f0e1fa5a46e7de0b88235124d437d20e4082b
2016-10-14 07:08:29 -07:00
Kazuki Sakamoto
7548164edb Clean up MeasureFunc and PrintFunc
Summary:
- Remove unneeded instance variables
- Simplify MeasureFunc call
- Add unittest

Reviewed By: emilsjolander

Differential Revision: D4013176

fbshipit-source-id: 4cdfa3ac3ad60a6bac5cda10644376ee9c46300b
2016-10-13 08:07:58 -07:00
Kazuki Sakamoto
722bfb9032 Align C# implementation with Java
Summary:
- Align C# implementation with Java JNI implementation
  - No need to call init(reinit)
  - Rename Initialize and Reset
- Add unittests

Reviewed By: emilsjolander

Differential Revision: D4009351

fbshipit-source-id: 191ddec30b0c8518eb0d76c0579afe909b673fac
2016-10-13 08:07:58 -07:00
Kazuki Sakamoto
d3fc24e842 Implement SetPosition
Summary: Implement missing SetPosition method in CSSNode

Reviewed By: emilsjolander

Differential Revision: D4006153

fbshipit-source-id: 488263965c2b3b2bd46f3ac58575776a748e3eb9
2016-10-12 09:22:54 -07:00
Emil Sjolander
871a7cf310 Move csharp tests into csharp folder
Summary: Move csharp tests into csharp/tests instead of tests. I feel like it makes more sense to have tests next to source. This is similar to how the C version has it as well.

Reviewed By: splhack

Differential Revision: D3993002

fbshipit-source-id: d9241f8ce7707c17a49c17fea2cce9959d52697d
2016-10-11 07:08:10 -07:00
Kazuki Sakamoto
56f6efdecf Introduce CSSAssertSetFailFunc and CSSAsserFail to throw managed exception
Summary:
- Define CSS_ASSERT_FAIL_ENABLED for P/Invoke (Visual Studio project already has it)
- Pass managed delegate pointer to unmanaged side via P/Invoke.
- CSSAssertFail will call the managed delegate when assert failed.
- The delegate will throw managed exception.

Reviewed By: emilsjolander

Differential Revision: D3982084

fbshipit-source-id: 058a87c10ca89238362be4d8759cc00dd0c9b376
2016-10-07 12:38:08 -07:00
Kazuki Sakamoto
90844d62c5 WeakReference for parent
Summary: - Use WeakReference for parent to avoid circular reference although GC will treat it

Reviewed By: emilsjolander

Differential Revision: D3982520

fbshipit-source-id: b0f6764aa4df3da53be51f6cb4fe2994d989afdf
2016-10-07 11:23:00 -07:00
Kazuki Sakamoto
c233bafeb2 Introduce CSSNodeGetInstanceCount API
Summary:
- Add CSSNodeGetInstanceCount API to get the number of native instances.
- It makes testing easy.

Reviewed By: emilsjolander

Differential Revision: D3981990

fbshipit-source-id: 98005ae1fc21d4c8802f24030fff9ffb00bd292d
2016-10-07 11:23:00 -07:00
Kazuki Sakamoto
b57abb2f60 Remove unused GCHandle
Summary:
- Unused _context GCHandle prevent calling CSSNode destructor.
- CSSNode C# impl will retain children node when calling CSSNodeInsertChild, so the lifetime of C# object is the same as the lifetime of native instance.

Reviewed By: emilsjolander

Differential Revision: D3981697

fbshipit-source-id: 71f0f7be97fd694d27934d7d07deb64ee08b2840
2016-10-07 11:22:59 -07:00
Kazuki Sakamoto
47bd1bb943 Align C# implementation with Java and Dispose pattern
Summary:
- Align C# implementation with Java JNI implementation
  - AssertNativeInstance
    - is this instance disposed?
    - does this instance have native instance pointer?
- Align Dispose and destructor with Dispose pattern
  - https://msdn.microsoft.com/en-us/library/fs2xkftw(v=vs.110).aspx

    if (disposing)
    {
      Free maanged objects here
    }
    Free unmanaged objects here
    disposed = true;

Reviewed By: emilsjolander

Differential Revision: D3977015

fbshipit-source-id: 023cf5b15aacfada14a85c321576aa81d7f95125
2016-10-06 06:08:05 -07:00
Kazuki Sakamoto
2870d3ce4d Remove .dll from DllName for other platforms
Summary:
- Different platforms have different naming conventions
  - http://www.mono-project.com/docs/advanced/pinvoke/#library-names
- Unity iOS requires special name `__Internal`
  - https://docs.unity3d.com/Manual/PluginsForIOS.html

Reviewed By: emilsjolander

Differential Revision: D3976369

fbshipit-source-id: 4c1d7fe226c5c2a89531ee1c2ee8b47df847b3e4
2016-10-06 06:08:05 -07:00
mattpodwysocki
23f2878808 rocket: fix P/Invoke sig for bool
Summary:
Fixes the `bool` marshaling issue as describe on [MSDN](https://blogs.msdn.microsoft.com/jaredpar/2008/10/14/pinvoke-and-bool-or-should-i-say-bool/) so C# will now act properly.
Closes https://github.com/facebook/css-layout/pull/226

Reviewed By: IanChilds

Differential Revision: D3967349

Pulled By: emilsjolander

fbshipit-source-id: f61d3bb39eb1b0b6e749629825234615b425e930
2016-10-05 02:37:55 -07:00
mattpodwysocki
9c93c7fc42 Removes unnecessary CSSLayoutContext param from CalculateLayout
Summary:
Closes #222 for the `csharp` implementation which does not use the `CSSLayoutContext` parameter in the `CalculateLayout` method call.
Closes https://github.com/facebook/css-layout/pull/223

Reviewed By: lucasr

Differential Revision: D3918948

Pulled By: emilsjolander

fbshipit-source-id: 8708e08b226500727e33d131ed880bb7e077c08e
2016-09-27 04:37:37 -07:00
mattpodwysocki
ff8f17ac99 Introducing .NET version of css-layout using P/Invoke
Summary:
This version of the css-layout project includes support for .NET projects.  Up in the air is how many configurations of .NET projects we allow for, such as Portable Class Libraries, Universal Windows Platform, .NET Core, etc.  Still needs integration with Buck.
Closes https://github.com/facebook/css-layout/pull/220

Reviewed By: lucasr

Differential Revision: D3909367

Pulled By: emilsjolander

fbshipit-source-id: aaaa9c4ff2d3452649f256c3268cf873cf33a0b9
2016-09-22 16:37:46 -07:00