Skip to content

Commit

Permalink
Prefix isUndefined with "CSS"
Browse files Browse the repository at this point in the history
Summary:
Consistently namespace all of css-layout's public C API with "CSS". The only function that needed to be renamed was isUndefined, which I renamed to CSSValueIsUndefined.

Fixes facebook#210.
Closes facebook/yoga#211

Reviewed By: lucasr

Differential Revision: D3674922

Pulled By: emilsjolander

fbshipit-source-id: 1752f477bde45586db112fe2654d0404cc52e1d1
  • Loading branch information
ide authored and Facebook Github Bot 2 committed Aug 5, 2016
1 parent 4e3b484 commit f8f7a15
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 72 deletions.
4 changes: 2 additions & 2 deletions Libraries/Text/RCTShadowText.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ - (void)applyLayoutToChildren:(CSSNodeRef)node
CSSNodeRef childNode = child.cssNode;
float width = CSSNodeStyleGetWidth(childNode);
float height = CSSNodeStyleGetHeight(childNode);
if (isUndefined(width) || isUndefined(height)) {
if (CSSValueIsUndefined(width) || CSSValueIsUndefined(height)) {
RCTLogError(@"Views nested within a <Text> must have a width and height");
}
UIFont *font = [textStorage attribute:NSFontAttributeName atIndex:range.location effectiveRange:nil];
Expand Down Expand Up @@ -293,7 +293,7 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily
} else {
float width = CSSNodeStyleGetWidth(child.cssNode);
float height = CSSNodeStyleGetHeight(child.cssNode);
if (isUndefined(width) || isUndefined(height)) {
if (CSSValueIsUndefined(width) || CSSValueIsUndefined(height)) {
RCTLogError(@"Views nested within a <Text> must have a width and height");
}
NSTextAttachment *attachment = [NSTextAttachment new];
Expand Down
90 changes: 45 additions & 45 deletions React/CSSLayout/CSSLayout.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ bool layoutNodeInternal(CSSNode *node,
bool performLayout,
char *reason);

bool isUndefined(float value) { return isnan(value); }
bool CSSValueIsUndefined(float value) { return isnan(value); }

static bool eq(float a, float b) {
if (isUndefined(a)) {
return isUndefined(b);
if (CSSValueIsUndefined(a)) {
return CSSValueIsUndefined(b);
}
return fabs(a - b) < 0.0001;
}
Expand Down Expand Up @@ -448,23 +448,23 @@ static float getFlexShrinkFactor(CSSNode *node) {
}

static float getLeadingMargin(CSSNode *node, CSSFlexDirection axis) {
if (isRowDirection(axis) && !isUndefined(node->style.margin[CSSPositionStart])) {
if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[CSSPositionStart])) {
return node->style.margin[CSSPositionStart];
}

return node->style.margin[leading[axis]];
}

static float getTrailingMargin(CSSNode *node, CSSFlexDirection axis) {
if (isRowDirection(axis) && !isUndefined(node->style.margin[CSSPositionEnd])) {
if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[CSSPositionEnd])) {
return node->style.margin[CSSPositionEnd];
}

return node->style.margin[trailing[axis]];
}

static float getLeadingPadding(CSSNode *node, CSSFlexDirection axis) {
if (isRowDirection(axis) && !isUndefined(node->style.padding[CSSPositionStart])
if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[CSSPositionStart])
&& node->style.padding[CSSPositionStart] >= 0) {
return node->style.padding[CSSPositionStart];
}
Expand All @@ -477,7 +477,7 @@ static float getLeadingPadding(CSSNode *node, CSSFlexDirection axis) {
}

static float getTrailingPadding(CSSNode *node, CSSFlexDirection axis) {
if (isRowDirection(axis) && !isUndefined(node->style.padding[CSSPositionEnd])
if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[CSSPositionEnd])
&& node->style.padding[CSSPositionEnd] >= 0) {
return node->style.padding[CSSPositionEnd];
}
Expand All @@ -490,7 +490,7 @@ static float getTrailingPadding(CSSNode *node, CSSFlexDirection axis) {
}

static float getLeadingBorder(CSSNode *node, CSSFlexDirection axis) {
if (isRowDirection(axis) && !isUndefined(node->style.border[CSSPositionStart])
if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[CSSPositionStart])
&& node->style.border[CSSPositionStart] >= 0) {
return node->style.border[CSSPositionStart];
}
Expand All @@ -503,7 +503,7 @@ static float getLeadingBorder(CSSNode *node, CSSFlexDirection axis) {
}

static float getTrailingBorder(CSSNode *node, CSSFlexDirection axis) {
if (isRowDirection(axis) && !isUndefined(node->style.border[CSSPositionEnd])
if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[CSSPositionEnd])
&& node->style.border[CSSPositionEnd] >= 0) {
return node->style.border[CSSPositionEnd];
}
Expand Down Expand Up @@ -586,41 +586,41 @@ static float getDimWithMargin(CSSNode *node, CSSFlexDirection axis) {

static bool isStyleDimDefined(CSSNode *node, CSSFlexDirection axis) {
float value = node->style.dimensions[dim[axis]];
return !isUndefined(value) && value >= 0.0;
return !CSSValueIsUndefined(value) && value >= 0.0;
}

static bool isLayoutDimDefined(CSSNode *node, CSSFlexDirection axis) {
float value = node->layout.measuredDimensions[dim[axis]];
return !isUndefined(value) && value >= 0.0;
return !CSSValueIsUndefined(value) && value >= 0.0;
}

static bool isLeadingPosDefined(CSSNode *node, CSSFlexDirection axis) {
return (isRowDirection(axis) && !isUndefined(node->style.position[CSSPositionStart]))
|| !isUndefined(node->style.position[leading[axis]]);
return (isRowDirection(axis) && !CSSValueIsUndefined(node->style.position[CSSPositionStart]))
|| !CSSValueIsUndefined(node->style.position[leading[axis]]);
}

static bool isTrailingPosDefined(CSSNode *node, CSSFlexDirection axis) {
return (isRowDirection(axis) && !isUndefined(node->style.position[CSSPositionEnd]))
|| !isUndefined(node->style.position[trailing[axis]]);
return (isRowDirection(axis) && !CSSValueIsUndefined(node->style.position[CSSPositionEnd]))
|| !CSSValueIsUndefined(node->style.position[trailing[axis]]);
}

static bool isMeasureDefined(CSSNode *node) { return node->measure; }

static float getLeadingPosition(CSSNode *node, CSSFlexDirection axis) {
if (isRowDirection(axis) && !isUndefined(node->style.position[CSSPositionStart])) {
if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.position[CSSPositionStart])) {
return node->style.position[CSSPositionStart];
}
if (!isUndefined(node->style.position[leading[axis]])) {
if (!CSSValueIsUndefined(node->style.position[leading[axis]])) {
return node->style.position[leading[axis]];
}
return 0;
}

static float getTrailingPosition(CSSNode *node, CSSFlexDirection axis) {
if (isRowDirection(axis) && !isUndefined(node->style.position[CSSPositionEnd])) {
if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.position[CSSPositionEnd])) {
return node->style.position[CSSPositionEnd];
}
if (!isUndefined(node->style.position[trailing[axis]])) {
if (!CSSValueIsUndefined(node->style.position[trailing[axis]])) {
return node->style.position[trailing[axis]];
}
return 0;
Expand All @@ -640,10 +640,10 @@ static float boundAxisWithinMinAndMax(CSSNode *node, CSSFlexDirection axis, floa

float boundValue = value;

if (!isUndefined(max) && max >= 0.0 && boundValue > max) {
if (!CSSValueIsUndefined(max) && max >= 0.0 && boundValue > max) {
boundValue = max;
}
if (!isUndefined(min) && min >= 0.0 && boundValue < min) {
if (!CSSValueIsUndefined(min) && min >= 0.0 && boundValue < min) {
boundValue = min;
}

Expand Down Expand Up @@ -806,10 +806,10 @@ static void layoutNodeImpl(CSSNode *node,
CSSMeasureMode heightMeasureMode,
bool performLayout) {

CSS_ASSERT(isUndefined(availableWidth) ? widthMeasureMode == CSSMeasureModeUndefined : true,
CSS_ASSERT(CSSValueIsUndefined(availableWidth) ? widthMeasureMode == CSSMeasureModeUndefined : true,
"availableWidth is indefinite so widthMeasureMode must be "
"CSSMeasureModeUndefined");
CSS_ASSERT(isUndefined(availableHeight) ? heightMeasureMode == CSSMeasureModeUndefined : true,
CSS_ASSERT(CSSValueIsUndefined(availableHeight) ? heightMeasureMode == CSSMeasureModeUndefined : true,
"availableHeight is indefinite so heightMeasureMode must be "
"CSSMeasureModeUndefined");

Expand Down Expand Up @@ -898,13 +898,13 @@ static void layoutNodeImpl(CSSNode *node,
if (widthMeasureMode == CSSMeasureModeAtMost && availableWidth <= 0) {
node->layout.measuredDimensions[CSSDimensionWidth] = boundAxis(node, CSSFlexDirectionRow, 0);
node->layout.measuredDimensions[CSSDimensionHeight] = boundAxis(node, CSSFlexDirectionColumn,
isUndefined(availableHeight) ? 0 : (availableHeight - marginAxisColumn));
CSSValueIsUndefined(availableHeight) ? 0 : (availableHeight - marginAxisColumn));
return;
}

if (heightMeasureMode == CSSMeasureModeAtMost && availableHeight <= 0) {
node->layout.measuredDimensions[CSSDimensionWidth] = boundAxis(node, CSSFlexDirectionRow,
isUndefined(availableWidth) ? 0 : (availableWidth - marginAxisRow));
CSSValueIsUndefined(availableWidth) ? 0 : (availableWidth - marginAxisRow));
node->layout.measuredDimensions[CSSDimensionHeight]
= boundAxis(node, CSSFlexDirectionColumn, 0);
return;
Expand Down Expand Up @@ -988,7 +988,7 @@ static void layoutNodeImpl(CSSNode *node,
// The height is definite, so use that as the flex basis.
child->layout.flexBasis = fmaxf(child->style.dimensions[CSSDimensionHeight],
getPaddingAndBorderAxis(child, CSSFlexDirectionColumn));
} else if (!isFlexBasisAuto(child) && !isUndefined(availableInnerMainDim)) {
} else if (!isFlexBasisAuto(child) && !CSSValueIsUndefined(availableInnerMainDim)) {

// If the basis isn't 'auto', it is assumed to be zero.
child->layout.flexBasis = fmaxf(0, getPaddingAndBorderAxis(child, mainAxis));
Expand Down Expand Up @@ -1016,15 +1016,15 @@ static void layoutNodeImpl(CSSNode *node,
// child's inline axis is parallel to the main axis (i.e. it's
// horizontal), the child should be sized using "UNDEFINED" in
// the main size. Otherwise use "AT_MOST" in the cross axis.
if (!isMainAxisRow && isUndefined(childWidth) && !isUndefined(availableInnerWidth)) {
if (!isMainAxisRow && CSSValueIsUndefined(childWidth) && !CSSValueIsUndefined(availableInnerWidth)) {
childWidth = availableInnerWidth;
childWidthMeasureMode = CSSMeasureModeAtMost;
}

// The W3C spec doesn't say anything about the 'overflow' property,
// but all major browsers appear to implement the following logic.
if (node->style.overflow == CSSOverflowHidden) {
if (isMainAxisRow && isUndefined(childHeight) && !isUndefined(availableInnerHeight)) {
if (isMainAxisRow && CSSValueIsUndefined(childHeight) && !CSSValueIsUndefined(availableInnerHeight)) {
childHeight = availableInnerHeight;
childHeightMeasureMode = CSSMeasureModeAtMost;
}
Expand All @@ -1033,14 +1033,14 @@ static void layoutNodeImpl(CSSNode *node,
// If child has no defined size in the cross axis and is set to stretch,
// set the cross
// axis to be measured exactly with the available inner width
if (!isMainAxisRow && !isUndefined(availableInnerWidth)
if (!isMainAxisRow && !CSSValueIsUndefined(availableInnerWidth)
&& !isStyleDimDefined(child, CSSFlexDirectionRow)
&& widthMeasureMode == CSSMeasureModeExactly
&& getAlignItem(node, child) == CSSAlignStretch) {
childWidth = availableInnerWidth;
childWidthMeasureMode = CSSMeasureModeExactly;
}
if (isMainAxisRow && !isUndefined(availableInnerHeight)
if (isMainAxisRow && !CSSValueIsUndefined(availableInnerHeight)
&& !isStyleDimDefined(child, CSSFlexDirectionColumn)
&& heightMeasureMode == CSSMeasureModeExactly
&& getAlignItem(node, child) == CSSAlignStretch) {
Expand Down Expand Up @@ -1157,7 +1157,7 @@ static void layoutNodeImpl(CSSNode *node,
// If the main dimension size isn't known, it is computed based on
// the line length, so there's no more space left to distribute.
float remainingFreeSpace = 0;
if (!isUndefined(availableInnerMainDim)) {
if (!CSSValueIsUndefined(availableInnerMainDim)) {
remainingFreeSpace = availableInnerMainDim - sizeConsumedOnCurrentLine;
} else if (sizeConsumedOnCurrentLine < 0) {
// availableInnerMainDim is indefinite which means the node is being sized
Expand Down Expand Up @@ -1287,7 +1287,7 @@ static void layoutNodeImpl(CSSNode *node,
childWidth = updatedMainSize + getMarginAxis(currentRelativeChild, CSSFlexDirectionRow);
childWidthMeasureMode = CSSMeasureModeExactly;

if (!isUndefined(availableInnerCrossDim)
if (!CSSValueIsUndefined(availableInnerCrossDim)
&& !isStyleDimDefined(currentRelativeChild, CSSFlexDirectionColumn)
&& heightMeasureMode == CSSMeasureModeExactly
&& getAlignItem(node, currentRelativeChild) == CSSAlignStretch) {
Expand All @@ -1296,7 +1296,7 @@ static void layoutNodeImpl(CSSNode *node,
} else if (!isStyleDimDefined(currentRelativeChild, CSSFlexDirectionColumn)) {
childHeight = availableInnerCrossDim;
childHeightMeasureMode
= isUndefined(childHeight) ? CSSMeasureModeUndefined : CSSMeasureModeAtMost;
= CSSValueIsUndefined(childHeight) ? CSSMeasureModeUndefined : CSSMeasureModeAtMost;
} else {
childHeight = currentRelativeChild->style.dimensions[CSSDimensionHeight]
+ getMarginAxis(currentRelativeChild, CSSFlexDirectionColumn);
Expand All @@ -1307,7 +1307,7 @@ static void layoutNodeImpl(CSSNode *node,
= updatedMainSize + getMarginAxis(currentRelativeChild, CSSFlexDirectionColumn);
childHeightMeasureMode = CSSMeasureModeExactly;

if (!isUndefined(availableInnerCrossDim)
if (!CSSValueIsUndefined(availableInnerCrossDim)
&& !isStyleDimDefined(currentRelativeChild, CSSFlexDirectionRow)
&& widthMeasureMode == CSSMeasureModeExactly
&& getAlignItem(node, currentRelativeChild) == CSSAlignStretch) {
Expand All @@ -1316,7 +1316,7 @@ static void layoutNodeImpl(CSSNode *node,
} else if (!isStyleDimDefined(currentRelativeChild, CSSFlexDirectionRow)) {
childWidth = availableInnerCrossDim;
childWidthMeasureMode
= isUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeAtMost;
= CSSValueIsUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeAtMost;
} else {
childWidth = currentRelativeChild->style.dimensions[CSSDimensionWidth]
+ getMarginAxis(currentRelativeChild, CSSFlexDirectionRow);
Expand Down Expand Up @@ -1493,9 +1493,9 @@ static void layoutNodeImpl(CSSNode *node,
// no need to stretch.
if (!isCrossSizeDefinite) {
childWidthMeasureMode
= isUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeExactly;
= CSSValueIsUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeExactly;
childHeightMeasureMode
= isUndefined(childHeight) ? CSSMeasureModeUndefined : CSSMeasureModeExactly;
= CSSValueIsUndefined(childHeight) ? CSSMeasureModeUndefined : CSSMeasureModeExactly;
layoutNodeInternal(child, childWidth, childHeight, direction, childWidthMeasureMode,
childHeightMeasureMode, true, "stretch");
}
Expand Down Expand Up @@ -1525,7 +1525,7 @@ static void layoutNodeImpl(CSSNode *node,
}

// STEP 8: MULTI-LINE CONTENT ALIGNMENT
if (lineCount > 1 && performLayout && !isUndefined(availableInnerCrossDim)) {
if (lineCount > 1 && performLayout && !CSSValueIsUndefined(availableInnerCrossDim)) {
float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim;

float crossDimLead = 0;
Expand Down Expand Up @@ -1675,25 +1675,25 @@ static void layoutNodeImpl(CSSNode *node,
}

// If we're still missing one or the other dimension, measure the content.
if (isUndefined(childWidth) || isUndefined(childHeight)) {
if (CSSValueIsUndefined(childWidth) || CSSValueIsUndefined(childHeight)) {
childWidthMeasureMode
= isUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeExactly;
= CSSValueIsUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeExactly;
childHeightMeasureMode
= isUndefined(childHeight) ? CSSMeasureModeUndefined : CSSMeasureModeExactly;
= CSSValueIsUndefined(childHeight) ? CSSMeasureModeUndefined : CSSMeasureModeExactly;

// According to the spec, if the main size is not definite and the
// child's inline axis is parallel to the main axis (i.e. it's
// horizontal), the child should be sized using "UNDEFINED" in
// the main size. Otherwise use "AT_MOST" in the cross axis.
if (!isMainAxisRow && isUndefined(childWidth) && !isUndefined(availableInnerWidth)) {
if (!isMainAxisRow && CSSValueIsUndefined(childWidth) && !CSSValueIsUndefined(availableInnerWidth)) {
childWidth = availableInnerWidth;
childWidthMeasureMode = CSSMeasureModeAtMost;
}

// The W3C spec doesn't say anything about the 'overflow' property,
// but all major browsers appear to implement the following logic.
if (node->style.overflow == CSSOverflowHidden) {
if (isMainAxisRow && isUndefined(childHeight) && !isUndefined(availableInnerHeight)) {
if (isMainAxisRow && CSSValueIsUndefined(childHeight) && !CSSValueIsUndefined(availableInnerHeight)) {
childHeight = availableInnerHeight;
childHeightMeasureMode = CSSMeasureModeAtMost;
}
Expand Down Expand Up @@ -2051,7 +2051,7 @@ void CSSNodeCalculateLayout(
CSSMeasureMode widthMeasureMode = CSSMeasureModeUndefined;
CSSMeasureMode heightMeasureMode = CSSMeasureModeUndefined;

if (!isUndefined(availableWidth)) {
if (!CSSValueIsUndefined(availableWidth)) {
widthMeasureMode = CSSMeasureModeExactly;
} else if (isStyleDimDefined(node, CSSFlexDirectionRow)) {
availableWidth = node->style.dimensions[dim[CSSFlexDirectionRow]]
Expand All @@ -2062,7 +2062,7 @@ void CSSNodeCalculateLayout(
widthMeasureMode = CSSMeasureModeAtMost;
}

if (!isUndefined(availableHeight)) {
if (!CSSValueIsUndefined(availableHeight)) {
heightMeasureMode = CSSMeasureModeExactly;
} else if (isStyleDimDefined(node, CSSFlexDirectionColumn)) {
availableHeight = node->style.dimensions[dim[CSSFlexDirectionColumn]]
Expand Down
2 changes: 1 addition & 1 deletion React/CSSLayout/CSSLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool CSSNodeIsDirty(CSSNodeRef node);

void CSSNodePrint(CSSNodeRef node, CSSPrintOptions options);

bool isUndefined(float value);
bool CSSValueIsUndefined(float value);

#define CSS_NODE_PROPERTY(type, name, paramName) \
void CSSNodeSet##name(CSSNodeRef node, type paramName); \
Expand Down
Loading

0 comments on commit f8f7a15

Please sign in to comment.