Use const where possible
Summary: Use const where possible. This does not use const for all variables as that would require too much refactoring for one diff. It does however use const where currently possible as well as does some small refactoring to enable const usage in more locations. Striving for 100% const usage leads to code with is easier to reason about as a reference will always reference the same value. The compiler will also assist if you accidentally override a reference. Reviewed By: IanChilds Differential Revision: D3741999 fbshipit-source-id: 1ba7da5784c3047f2d4c03746890192f724aa65e
This commit is contained in:
committed by
Facebook Github Bot 6
parent
4bcefd8845
commit
ca72b2b796
File diff suppressed because it is too large
Load Diff
@@ -123,18 +123,18 @@ typedef void (*CSSPrintFunc)(void *context);
|
|||||||
|
|
||||||
// CSSNode
|
// CSSNode
|
||||||
CSSNodeRef CSSNodeNew();
|
CSSNodeRef CSSNodeNew();
|
||||||
void CSSNodeInit(CSSNodeRef node);
|
void CSSNodeInit(const CSSNodeRef node);
|
||||||
void CSSNodeFree(CSSNodeRef node);
|
void CSSNodeFree(const CSSNodeRef node);
|
||||||
|
|
||||||
void CSSNodeInsertChild(CSSNodeRef node, CSSNodeRef child, uint32_t index);
|
void CSSNodeInsertChild(const CSSNodeRef node, const CSSNodeRef child, const uint32_t index);
|
||||||
void CSSNodeRemoveChild(CSSNodeRef node, CSSNodeRef child);
|
void CSSNodeRemoveChild(const CSSNodeRef node, const CSSNodeRef child);
|
||||||
CSSNodeRef CSSNodeGetChild(CSSNodeRef node, uint32_t index);
|
CSSNodeRef CSSNodeGetChild(const CSSNodeRef node, const uint32_t index);
|
||||||
uint32_t CSSNodeChildCount(CSSNodeRef node);
|
uint32_t CSSNodeChildCount(const CSSNodeRef node);
|
||||||
|
|
||||||
void CSSNodeCalculateLayout(CSSNodeRef node,
|
void CSSNodeCalculateLayout(const CSSNodeRef node,
|
||||||
float availableWidth,
|
const float availableWidth,
|
||||||
float availableHeight,
|
const float availableHeight,
|
||||||
CSSDirection parentDirection);
|
const CSSDirection parentDirection);
|
||||||
|
|
||||||
// Mark a node as dirty. Only valid for nodes with a custom measure function
|
// Mark a node as dirty. Only valid for nodes with a custom measure function
|
||||||
// set.
|
// set.
|
||||||
@@ -142,26 +142,26 @@ void CSSNodeCalculateLayout(CSSNodeRef node,
|
|||||||
// measure functions
|
// measure functions
|
||||||
// depends on information not known to CSSLayout they must perform this dirty
|
// depends on information not known to CSSLayout they must perform this dirty
|
||||||
// marking manually.
|
// marking manually.
|
||||||
void CSSNodeMarkDirty(CSSNodeRef node);
|
void CSSNodeMarkDirty(const CSSNodeRef node);
|
||||||
bool CSSNodeIsDirty(CSSNodeRef node);
|
bool CSSNodeIsDirty(const CSSNodeRef node);
|
||||||
|
|
||||||
void CSSNodePrint(CSSNodeRef node, CSSPrintOptions options);
|
void CSSNodePrint(const CSSNodeRef node, const CSSPrintOptions options);
|
||||||
|
|
||||||
bool CSSValueIsUndefined(float value);
|
bool CSSValueIsUndefined(const float value);
|
||||||
|
|
||||||
#define CSS_NODE_PROPERTY(type, name, paramName) \
|
#define CSS_NODE_PROPERTY(type, name, paramName) \
|
||||||
void CSSNodeSet##name(CSSNodeRef node, type paramName); \
|
void CSSNodeSet##name(const CSSNodeRef node, type paramName); \
|
||||||
type CSSNodeGet##name(CSSNodeRef node);
|
type CSSNodeGet##name(const CSSNodeRef node);
|
||||||
|
|
||||||
#define CSS_NODE_STYLE_PROPERTY(type, name, paramName) \
|
#define CSS_NODE_STYLE_PROPERTY(type, name, paramName) \
|
||||||
void CSSNodeStyleSet##name(CSSNodeRef node, type paramName); \
|
void CSSNodeStyleSet##name(const CSSNodeRef node, const type paramName); \
|
||||||
type CSSNodeStyleGet##name(CSSNodeRef node);
|
type CSSNodeStyleGet##name(const CSSNodeRef node);
|
||||||
|
|
||||||
#define CSS_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
|
#define CSS_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
|
||||||
void CSSNodeStyleSet##name(CSSNodeRef node, CSSEdge edge, type paramName); \
|
void CSSNodeStyleSet##name(const CSSNodeRef node, const CSSEdge edge, const type paramName); \
|
||||||
type CSSNodeStyleGet##name(CSSNodeRef node, CSSEdge edge);
|
type CSSNodeStyleGet##name(const CSSNodeRef node, const CSSEdge edge);
|
||||||
|
|
||||||
#define CSS_NODE_LAYOUT_PROPERTY(type, name) type CSSNodeLayoutGet##name(CSSNodeRef node);
|
#define CSS_NODE_LAYOUT_PROPERTY(type, name) type CSSNodeLayoutGet##name(const CSSNodeRef node);
|
||||||
|
|
||||||
CSS_NODE_PROPERTY(void *, Context, context);
|
CSS_NODE_PROPERTY(void *, Context, context);
|
||||||
CSS_NODE_PROPERTY(CSSMeasureFunc, MeasureFunc, measureFunc);
|
CSS_NODE_PROPERTY(CSSMeasureFunc, MeasureFunc, measureFunc);
|
||||||
|
@@ -15,8 +15,8 @@ struct CSSNodeList {
|
|||||||
void **items;
|
void **items;
|
||||||
};
|
};
|
||||||
|
|
||||||
CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity) {
|
CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity) {
|
||||||
CSSNodeListRef list = malloc(sizeof(struct CSSNodeList));
|
const CSSNodeListRef list = malloc(sizeof(struct CSSNodeList));
|
||||||
CSS_ASSERT(list != NULL, "Could not allocate memory for list");
|
CSS_ASSERT(list != NULL, "Could not allocate memory for list");
|
||||||
|
|
||||||
list->capacity = initialCapacity;
|
list->capacity = initialCapacity;
|
||||||
@@ -27,20 +27,20 @@ CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity) {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSSNodeListFree(CSSNodeListRef list) {
|
void CSSNodeListFree(const CSSNodeListRef list) {
|
||||||
free(list->items);
|
free(list->items);
|
||||||
free(list);
|
free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t CSSNodeListCount(CSSNodeListRef list) {
|
uint32_t CSSNodeListCount(const CSSNodeListRef list) {
|
||||||
return list->count;
|
return list->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSSNodeListAdd(CSSNodeListRef list, CSSNodeRef node) {
|
void CSSNodeListAdd(const CSSNodeListRef list, const CSSNodeRef node) {
|
||||||
CSSNodeListInsert(list, node, list->count);
|
CSSNodeListInsert(list, node, list->count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, uint32_t index) {
|
void CSSNodeListInsert(const CSSNodeListRef list, const CSSNodeRef node, const uint32_t index) {
|
||||||
if (list->count == list->capacity) {
|
if (list->count == list->capacity) {
|
||||||
list->capacity *= 2;
|
list->capacity *= 2;
|
||||||
list->items = realloc(list->items, sizeof(void *) * list->capacity);
|
list->items = realloc(list->items, sizeof(void *) * list->capacity);
|
||||||
@@ -55,8 +55,8 @@ void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, uint32_t index) {
|
|||||||
list->items[index] = node;
|
list->items[index] = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, uint32_t index) {
|
CSSNodeRef CSSNodeListRemove(const CSSNodeListRef list, const uint32_t index) {
|
||||||
CSSNodeRef removed = list->items[index];
|
const CSSNodeRef removed = list->items[index];
|
||||||
list->items[index] = NULL;
|
list->items[index] = NULL;
|
||||||
|
|
||||||
for (uint32_t i = index; i < list->count - 1; i++) {
|
for (uint32_t i = index; i < list->count - 1; i++) {
|
||||||
@@ -68,7 +68,7 @@ CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, uint32_t index) {
|
|||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node) {
|
CSSNodeRef CSSNodeListDelete(const CSSNodeListRef list, const CSSNodeRef node) {
|
||||||
for (uint32_t i = 0; i < list->count; i++) {
|
for (uint32_t i = 0; i < list->count; i++) {
|
||||||
if (list->items[i] == node) {
|
if (list->items[i] == node) {
|
||||||
return CSSNodeListRemove(list, i);
|
return CSSNodeListRemove(list, i);
|
||||||
@@ -78,6 +78,6 @@ CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, uint32_t index) {
|
CSSNodeRef CSSNodeListGet(const CSSNodeListRef list, const uint32_t index) {
|
||||||
return list->items[index];
|
return list->items[index];
|
||||||
}
|
}
|
||||||
|
@@ -21,13 +21,13 @@ CSS_EXTERN_C_BEGIN
|
|||||||
|
|
||||||
typedef struct CSSNodeList *CSSNodeListRef;
|
typedef struct CSSNodeList *CSSNodeListRef;
|
||||||
|
|
||||||
CSSNodeListRef CSSNodeListNew(uint32_t initialCapacity);
|
CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity);
|
||||||
void CSSNodeListFree(CSSNodeListRef list);
|
void CSSNodeListFree(const CSSNodeListRef list);
|
||||||
uint32_t CSSNodeListCount(CSSNodeListRef list);
|
uint32_t CSSNodeListCount(const CSSNodeListRef list);
|
||||||
void CSSNodeListAdd(CSSNodeListRef list, CSSNodeRef node);
|
void CSSNodeListAdd(const CSSNodeListRef list, const CSSNodeRef node);
|
||||||
void CSSNodeListInsert(CSSNodeListRef list, CSSNodeRef node, uint32_t index);
|
void CSSNodeListInsert(const CSSNodeListRef list, const CSSNodeRef node, const uint32_t index);
|
||||||
CSSNodeRef CSSNodeListRemove(CSSNodeListRef list, uint32_t index);
|
CSSNodeRef CSSNodeListRemove(const CSSNodeListRef list, const uint32_t index);
|
||||||
CSSNodeRef CSSNodeListDelete(CSSNodeListRef list, CSSNodeRef node);
|
CSSNodeRef CSSNodeListDelete(const CSSNodeListRef list, const CSSNodeRef node);
|
||||||
CSSNodeRef CSSNodeListGet(CSSNodeListRef list, uint32_t index);
|
CSSNodeRef CSSNodeListGet(const CSSNodeListRef list, const uint32_t index);
|
||||||
|
|
||||||
CSS_EXTERN_C_END
|
CSS_EXTERN_C_END
|
||||||
|
@@ -14,12 +14,12 @@
|
|||||||
|
|
||||||
// Measure functions can be quite slow, for example when measuring text.
|
// Measure functions can be quite slow, for example when measuring text.
|
||||||
// Simulate this by sleeping for 1 millisecond.
|
// Simulate this by sleeping for 1 millisecond.
|
||||||
static CSSSize _measure(void *context,
|
static CSSSize _measure(const void *context,
|
||||||
float width,
|
const float width,
|
||||||
CSSMeasureMode widthMode,
|
const CSSMeasureMode widthMode,
|
||||||
float height,
|
const float height,
|
||||||
CSSMeasureMode heightMode) {
|
const CSSMeasureMode heightMode) {
|
||||||
struct timespec sleeptime = {0, 1000000};
|
const struct timespec sleeptime = {0, 1000000};
|
||||||
nanosleep(&sleeptime, NULL);
|
nanosleep(&sleeptime, NULL);
|
||||||
return (CSSSize){
|
return (CSSSize){
|
||||||
.width = widthMode == CSSMeasureModeUndefined ? 10 : width,
|
.width = widthMode == CSSMeasureModeUndefined ? 10 : width,
|
||||||
@@ -30,12 +30,12 @@ static CSSSize _measure(void *context,
|
|||||||
CSS_BENCHMARKS({
|
CSS_BENCHMARKS({
|
||||||
|
|
||||||
CSS_BENCHMARK("Stack with flex", {
|
CSS_BENCHMARK("Stack with flex", {
|
||||||
CSSNodeRef root = CSSNodeNew();
|
const CSSNodeRef root = CSSNodeNew();
|
||||||
CSSNodeStyleSetWidth(root, 100);
|
CSSNodeStyleSetWidth(root, 100);
|
||||||
CSSNodeStyleSetHeight(root, 100);
|
CSSNodeStyleSetHeight(root, 100);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 10; i++) {
|
for (uint32_t i = 0; i < 10; i++) {
|
||||||
CSSNodeRef child = CSSNodeNew();
|
const CSSNodeRef child = CSSNodeNew();
|
||||||
CSSNodeSetMeasureFunc(child, _measure);
|
CSSNodeSetMeasureFunc(child, _measure);
|
||||||
CSSNodeStyleSetFlex(child, 1);
|
CSSNodeStyleSetFlex(child, 1);
|
||||||
CSSNodeInsertChild(root, child, 0);
|
CSSNodeInsertChild(root, child, 0);
|
||||||
@@ -45,10 +45,10 @@ CSS_BENCHMARKS({
|
|||||||
});
|
});
|
||||||
|
|
||||||
CSS_BENCHMARK("Align stretch in undefined axis", {
|
CSS_BENCHMARK("Align stretch in undefined axis", {
|
||||||
CSSNodeRef root = CSSNodeNew();
|
const CSSNodeRef root = CSSNodeNew();
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 10; i++) {
|
for (uint32_t i = 0; i < 10; i++) {
|
||||||
CSSNodeRef child = CSSNodeNew();
|
const CSSNodeRef child = CSSNodeNew();
|
||||||
CSSNodeStyleSetHeight(child, 20);
|
CSSNodeStyleSetHeight(child, 20);
|
||||||
CSSNodeSetMeasureFunc(child, _measure);
|
CSSNodeSetMeasureFunc(child, _measure);
|
||||||
CSSNodeInsertChild(root, child, 0);
|
CSSNodeInsertChild(root, child, 0);
|
||||||
@@ -58,16 +58,16 @@ CSS_BENCHMARKS({
|
|||||||
});
|
});
|
||||||
|
|
||||||
CSS_BENCHMARK("Nested flex", {
|
CSS_BENCHMARK("Nested flex", {
|
||||||
CSSNodeRef root = CSSNodeNew();
|
const CSSNodeRef root = CSSNodeNew();
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 10; i++) {
|
for (uint32_t i = 0; i < 10; i++) {
|
||||||
CSSNodeRef child = CSSNodeNew();
|
const CSSNodeRef child = CSSNodeNew();
|
||||||
CSSNodeSetMeasureFunc(child, _measure);
|
CSSNodeSetMeasureFunc(child, _measure);
|
||||||
CSSNodeStyleSetFlex(child, 1);
|
CSSNodeStyleSetFlex(child, 1);
|
||||||
CSSNodeInsertChild(root, child, 0);
|
CSSNodeInsertChild(root, child, 0);
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < 10; ii++) {
|
for (uint32_t ii = 0; ii < 10; ii++) {
|
||||||
CSSNodeRef grandChild = CSSNodeNew();
|
const CSSNodeRef grandChild = CSSNodeNew();
|
||||||
CSSNodeSetMeasureFunc(grandChild, _measure);
|
CSSNodeSetMeasureFunc(grandChild, _measure);
|
||||||
CSSNodeStyleSetFlex(grandChild, 1);
|
CSSNodeStyleSetFlex(grandChild, 1);
|
||||||
CSSNodeInsertChild(child, grandChild, 0);
|
CSSNodeInsertChild(child, grandChild, 0);
|
||||||
|
@@ -89,7 +89,7 @@ function assertTestTree(node, nodeName, parentName) {
|
|||||||
|
|
||||||
function setupTestTree(node, nodeName, parentName, index) {
|
function setupTestTree(node, nodeName, parentName, index) {
|
||||||
var lines = [
|
var lines = [
|
||||||
'CSSNodeRef ' + nodeName + ' = CSSNodeNew();',
|
'const CSSNodeRef ' + nodeName + ' = CSSNodeNew();',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (var style in node.style) {
|
for (var style in node.style) {
|
||||||
|
@@ -100,15 +100,14 @@ static CSSSize _jniMeasureFunc(void *context,
|
|||||||
|
|
||||||
jlong measureResult =
|
jlong measureResult =
|
||||||
(*env)->CallLongMethod(env, context, measureID, width, widthMode, height, heightMode);
|
(*env)->CallLongMethod(env, context, measureID, width, widthMode, height, heightMode);
|
||||||
CSSSize size = {
|
|
||||||
|
return (CSSSize){
|
||||||
.width = (int32_t)(measureResult >> 32), .height = (int32_t) measureResult,
|
.width = (int32_t)(measureResult >> 32), .height = (int32_t) measureResult,
|
||||||
};
|
};
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CSS_NODE_JNI(jlong, CSSNodeNew(JNIEnv *env, jobject thiz) {
|
CSS_NODE_JNI(jlong, CSSNodeNew(JNIEnv *env, jobject thiz) {
|
||||||
CSSNodeRef node = CSSNodeNew();
|
const CSSNodeRef node = CSSNodeNew();
|
||||||
CSSNodeSetContext(node, (*env)->NewGlobalRef(env, thiz));
|
CSSNodeSetContext(node, (*env)->NewGlobalRef(env, thiz));
|
||||||
CSSNodeSetPrintFunc(node, _jniPrint);
|
CSSNodeSetPrintFunc(node, _jniPrint);
|
||||||
return (jlong)(intptr_t) node;
|
return (jlong)(intptr_t) node;
|
||||||
|
@@ -22,19 +22,19 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
TEST(CSSLayoutTest, flex_basis) {
|
TEST(CSSLayoutTest, flex_basis) {
|
||||||
CSSNodeRef root = CSSNodeNew();
|
const CSSNodeRef root = CSSNodeNew();
|
||||||
CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow);
|
CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow);
|
||||||
CSSNodeStyleSetWidth(root, 300);
|
CSSNodeStyleSetWidth(root, 300);
|
||||||
CSSNodeStyleSetHeight(root, 100);
|
CSSNodeStyleSetHeight(root, 100);
|
||||||
|
|
||||||
CSSNodeRef root_child0 = CSSNodeNew();
|
const CSSNodeRef root_child0 = CSSNodeNew();
|
||||||
CSSNodeStyleSetFlexGrow(root_child0, 1);
|
CSSNodeStyleSetFlexGrow(root_child0, 1);
|
||||||
CSSNodeStyleSetFlexBasis(root_child0, 100);
|
CSSNodeStyleSetFlexBasis(root_child0, 100);
|
||||||
CSSNodeStyleSetWidth(root_child0, 200);
|
CSSNodeStyleSetWidth(root_child0, 200);
|
||||||
CSSNodeStyleSetHeight(root_child0, 100);
|
CSSNodeStyleSetHeight(root_child0, 100);
|
||||||
CSSNodeInsertChild(root, root_child0, 0);
|
CSSNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
CSSNodeRef root_child1 = CSSNodeNew();
|
const CSSNodeRef root_child1 = CSSNodeNew();
|
||||||
CSSNodeStyleSetFlexGrow(root_child1, 1);
|
CSSNodeStyleSetFlexGrow(root_child1, 1);
|
||||||
CSSNodeStyleSetWidth(root_child1, 100);
|
CSSNodeStyleSetWidth(root_child1, 100);
|
||||||
CSSNodeStyleSetHeight(root_child1, 100);
|
CSSNodeStyleSetHeight(root_child1, 100);
|
||||||
|
@@ -26,11 +26,11 @@ __forceinline const float fminf(const float a, const float b) {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool eq(float a, float b) {
|
static bool eq(const float a, const float b) {
|
||||||
return fabs(a - b) < 0.0001;
|
return fabs(a - b) < 0.0001;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool are_layout_equal(CSSNode *a, CSSNode *b) {
|
static bool are_layout_equal(const CSSNodeRef a, const CSSNodeRef b) {
|
||||||
if (!eq(a->layout.dimensions[CSSDimensionWidth], b->layout.dimensions[CSSDimensionWidth]) ||
|
if (!eq(a->layout.dimensions[CSSDimensionWidth], b->layout.dimensions[CSSDimensionWidth]) ||
|
||||||
!eq(a->layout.dimensions[CSSDimensionHeight], b->layout.dimensions[CSSDimensionHeight]) ||
|
!eq(a->layout.dimensions[CSSDimensionHeight], b->layout.dimensions[CSSDimensionHeight]) ||
|
||||||
!eq(a->layout.position[CSSEdgeTop], b->layout.position[CSSEdgeTop]) ||
|
!eq(a->layout.position[CSSEdgeTop], b->layout.position[CSSEdgeTop]) ||
|
||||||
@@ -38,7 +38,7 @@ static bool are_layout_equal(CSSNode *a, CSSNode *b) {
|
|||||||
!eq(CSSNodeChildCount(a), CSSNodeChildCount(b))) {
|
!eq(CSSNodeChildCount(a), CSSNodeChildCount(b))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < CSSNodeChildCount(a); ++i) {
|
for (uint32_t i = 0; i < CSSNodeChildCount(a); ++i) {
|
||||||
if (!are_layout_equal(CSSNodeGetChild(a, i), CSSNodeGetChild(b, i))) {
|
if (!are_layout_equal(CSSNodeGetChild(a, i), CSSNodeGetChild(b, i))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -47,12 +47,14 @@ static bool are_layout_equal(CSSNode *a, CSSNode *b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CSSSize measure(void *context,
|
CSSSize measure(void *context,
|
||||||
float width,
|
float availableWidth,
|
||||||
CSSMeasureMode widthMode,
|
CSSMeasureMode widthMode,
|
||||||
float height,
|
float availableHeight,
|
||||||
CSSMeasureMode heightMode) {
|
CSSMeasureMode heightMode) {
|
||||||
const char *text = (const char *) context;
|
const char *text = (const char *) context;
|
||||||
CSSSize result;
|
CSSSize result;
|
||||||
|
float width = availableWidth;
|
||||||
|
float height = availableHeight;
|
||||||
if (strcmp(text, SMALL_TEXT) == 0) {
|
if (strcmp(text, SMALL_TEXT) == 0) {
|
||||||
if (widthMode == CSSMeasureModeUndefined) {
|
if (widthMode == CSSMeasureModeUndefined) {
|
||||||
width = 1000000;
|
width = 1000000;
|
||||||
@@ -108,18 +110,18 @@ CSSSize measure(void *context,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool test(CSSNode *style, CSSNode *expected_layout) {
|
bool test(const CSSNodeRef style, const CSSNodeRef expected_layout) {
|
||||||
CSSNodeCalculateLayout(style, CSSUndefined, CSSUndefined, (CSSDirection) -1);
|
CSSNodeCalculateLayout(style, CSSUndefined, CSSUndefined, (CSSDirection) -1);
|
||||||
return are_layout_equal(style, expected_layout);
|
return are_layout_equal(style, expected_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSNode *new_test_css_node(void) {
|
CSSNodeRef new_test_css_node() {
|
||||||
CSSNode *node = CSSNodeNew();
|
CSSNodeRef node = CSSNodeNew();
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_css_node_children(CSSNode *node, int childCount) {
|
void init_css_node_children(const CSSNodeRef node, const uint32_t childCount) {
|
||||||
for (int i = 0; i < childCount; ++i) {
|
for (uint32_t i = 0; i < childCount; ++i) {
|
||||||
CSSNodeInsertChild(node, new_test_css_node(), 0);
|
CSSNodeInsertChild(node, new_test_css_node(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,14 +33,14 @@
|
|||||||
|
|
||||||
CSS_EXTERN_C_BEGIN
|
CSS_EXTERN_C_BEGIN
|
||||||
|
|
||||||
bool test(CSSNode *style, CSSNode *expected_layout);
|
bool test(const CSSNodeRef style, const CSSNodeRef expected_layout);
|
||||||
CSSSize measure(void *context,
|
CSSSize measure(void *context,
|
||||||
float width,
|
float availableWidth,
|
||||||
CSSMeasureMode widthMode,
|
CSSMeasureMode widthMode,
|
||||||
float height,
|
float availableHeight,
|
||||||
CSSMeasureMode heightMode);
|
CSSMeasureMode heightMode);
|
||||||
void init_css_node_children(CSSNode *node, int childCount);
|
void init_css_node_children(const CSSNodeRef node, const uint32_t childCount);
|
||||||
CSSNode *new_test_css_node(void);
|
CSSNodeRef new_test_css_node();
|
||||||
|
|
||||||
CSS_EXTERN_C_END
|
CSS_EXTERN_C_END
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user