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
This commit is contained in:
committed by
Facebook Github Bot
parent
b59ce09109
commit
46823878a5
@@ -456,7 +456,7 @@ static void _CSSNodePrint(const CSSNodeRef node,
|
||||
gLogger("{");
|
||||
|
||||
if (node->print) {
|
||||
node->print(node->context);
|
||||
node->print(node);
|
||||
}
|
||||
|
||||
if (options & CSSPrintOptionsLayout) {
|
||||
@@ -1263,7 +1263,7 @@ static void layoutNodeImpl(const CSSNodeRef node,
|
||||
} else {
|
||||
// Measure the text under the current constraints.
|
||||
const CSSSize measuredSize =
|
||||
node->measure(node->context, innerWidth, widthMeasureMode, innerHeight, heightMeasureMode);
|
||||
node->measure(node, innerWidth, widthMeasureMode, innerHeight, heightMeasureMode);
|
||||
|
||||
node->layout.measuredDimensions[CSSDimensionWidth] =
|
||||
boundAxis(node,
|
||||
@@ -2284,7 +2284,7 @@ bool layoutNodeInternal(const CSSNodeRef node,
|
||||
if (gPrintChanges && gPrintSkips) {
|
||||
printf("%s%d.{[skipped] ", getSpacer(gDepth), gDepth);
|
||||
if (node->print) {
|
||||
node->print(node->context);
|
||||
node->print(node);
|
||||
}
|
||||
printf("wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n",
|
||||
getModeName(widthMeasureMode, performLayout),
|
||||
@@ -2299,7 +2299,7 @@ bool layoutNodeInternal(const CSSNodeRef node,
|
||||
if (gPrintChanges) {
|
||||
printf("%s%d.{%s", getSpacer(gDepth), gDepth, needToVisitNode ? "*" : "");
|
||||
if (node->print) {
|
||||
node->print(node->context);
|
||||
node->print(node);
|
||||
}
|
||||
printf("wm: %s, hm: %s, aw: %f ah: %f %s\n",
|
||||
getModeName(widthMeasureMode, performLayout),
|
||||
@@ -2320,7 +2320,7 @@ bool layoutNodeInternal(const CSSNodeRef node,
|
||||
if (gPrintChanges) {
|
||||
printf("%s%d.}%s", getSpacer(gDepth), gDepth, needToVisitNode ? "*" : "");
|
||||
if (node->print) {
|
||||
node->print(node->context);
|
||||
node->print(node);
|
||||
}
|
||||
printf("wm: %s, hm: %s, d: (%f, %f) %s\n",
|
||||
getModeName(widthMeasureMode, performLayout),
|
||||
|
@@ -116,12 +116,12 @@ typedef struct CSSSize {
|
||||
} CSSSize;
|
||||
|
||||
typedef struct CSSNode *CSSNodeRef;
|
||||
typedef CSSSize (*CSSMeasureFunc)(void *context,
|
||||
typedef CSSSize (*CSSMeasureFunc)(CSSNodeRef node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode);
|
||||
typedef void (*CSSPrintFunc)(void *context);
|
||||
typedef void (*CSSPrintFunc)(CSSNodeRef node);
|
||||
typedef int (*CSSLogger)(const char *format, ...);
|
||||
|
||||
#ifdef CSS_ASSERT_FAIL_ENABLED
|
||||
|
@@ -11,7 +11,7 @@
|
||||
|
||||
#include <CSSLayout/CSSLayout.h>
|
||||
|
||||
static CSSSize _measure(void *context,
|
||||
static CSSSize _measure(CSSNodeRef node
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
|
@@ -14,7 +14,7 @@ namespace Facebook.CSSLayout
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate CSSSize CSSMeasureFunc(
|
||||
IntPtr context,
|
||||
IntPtr node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
|
@@ -532,7 +532,7 @@ namespace Facebook.CSSLayout
|
||||
}
|
||||
|
||||
private CSSSize MeasureInternal(
|
||||
IntPtr context,
|
||||
IntPtr node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
|
@@ -14,17 +14,17 @@
|
||||
using namespace facebook::jni;
|
||||
using namespace std;
|
||||
|
||||
static void _jniPrint(void *context) {
|
||||
auto obj = adopt_local(Environment::current()->NewLocalRef(reinterpret_cast<jweak>(context)));
|
||||
static void _jniPrint(CSSNodeRef node) {
|
||||
auto obj = adopt_local(Environment::current()->NewLocalRef(reinterpret_cast<jweak>(CSSNodeGetContext(node))));
|
||||
cout << obj->toString() << endl;
|
||||
}
|
||||
|
||||
static CSSSize _jniMeasureFunc(void *context,
|
||||
static CSSSize _jniMeasureFunc(CSSNodeRef node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode) {
|
||||
auto obj = adopt_local(Environment::current()->NewLocalRef(reinterpret_cast<jweak>(context)));
|
||||
auto obj = adopt_local(Environment::current()->NewLocalRef(reinterpret_cast<jweak>(CSSNodeGetContext(node))));
|
||||
static auto measureFunc =
|
||||
obj->getClass()->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure");
|
||||
const auto measureResult = measureFunc(obj, width, widthMode, height, heightMode);
|
||||
|
@@ -10,13 +10,13 @@
|
||||
#include <CSSLayout/CSSLayout.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
static CSSSize _measureMax(void *context,
|
||||
static CSSSize _measureMax(CSSNodeRef node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode) {
|
||||
|
||||
int *measureCount = (int *)context;
|
||||
int *measureCount = (int *)CSSNodeGetContext(node);
|
||||
*measureCount = *measureCount + 1;
|
||||
return CSSSize {
|
||||
.width = widthMode == CSSMeasureModeUndefined ? 10 : width,
|
||||
@@ -24,13 +24,13 @@ static CSSSize _measureMax(void *context,
|
||||
};
|
||||
}
|
||||
|
||||
static CSSSize _measureMin(void *context,
|
||||
static CSSSize _measureMin(CSSNodeRef node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode) {
|
||||
|
||||
int *measureCount = (int *)context;
|
||||
int *measureCount = (int *)CSSNodeGetContext(node);
|
||||
*measureCount = *measureCount + 1;
|
||||
return CSSSize {
|
||||
.width = widthMode == CSSMeasureModeUndefined || (widthMode == CSSMeasureModeAtMost && width > 10) ? 10 : width,
|
||||
|
@@ -22,12 +22,12 @@ struct _MeasureConstraintList {
|
||||
struct _MeasureConstraint *constraints;
|
||||
};
|
||||
|
||||
static CSSSize _measure(void *context,
|
||||
static CSSSize _measure(CSSNodeRef node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode) {
|
||||
struct _MeasureConstraintList *constraintList = (struct _MeasureConstraintList *)context;
|
||||
struct _MeasureConstraintList *constraintList = (struct _MeasureConstraintList *)CSSNodeGetContext(node);
|
||||
struct _MeasureConstraint *constraints = constraintList->constraints;
|
||||
uint32_t currentIndex = constraintList->length;
|
||||
(&constraints[currentIndex])->width = width;
|
||||
|
@@ -10,12 +10,12 @@
|
||||
#include <CSSLayout/CSSLayout.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
static CSSSize _measure(void *context,
|
||||
static CSSSize _measure(CSSNodeRef node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode) {
|
||||
int *measureCount = (int *)context;
|
||||
int *measureCount = (int *)CSSNodeGetContext(node);
|
||||
*measureCount = *measureCount + 1;
|
||||
return CSSSize {
|
||||
.width = widthMode == CSSMeasureModeUndefined ? 10 : width,
|
||||
|
@@ -206,7 +206,7 @@ static void _updateFrameRecursive(UIView *view);
|
||||
#pragma mark - Private
|
||||
|
||||
static CSSSize _measure(
|
||||
void *context,
|
||||
CSSNodeRef node,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
@@ -222,7 +222,7 @@ static CSSSize _measure(
|
||||
};
|
||||
}
|
||||
|
||||
UIView *view = (__bridge UIView*) context;
|
||||
UIView *view = (__bridge UIView*) CSSNodeGetContext(node);
|
||||
const CGSize sizeThatFits = [view sizeThatFits:(CGSize) {
|
||||
.width = widthMode == CSSMeasureModeUndefined ? CGFLOAT_MAX : width,
|
||||
.height = heightMode == CSSMeasureModeUndefined ? CGFLOAT_MAX : height,
|
||||
|
Reference in New Issue
Block a user