diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTShadowViewTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTShadowViewTests.m index 0a07f108e62..91a1196c6e5 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTShadowViewTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTShadowViewTests.m @@ -29,7 +29,7 @@ [super setUp]; self.parentView = [self _shadowViewWithConfig:^(CSSNodeRef node) { - CSSNodeStyleSetFlexDirection(node, CSSFlexDirectionColumn); + CSSNodeStyleSetFlexDirection(node, YGFlexDirectionColumn); CSSNodeStyleSetWidth(node, 440); CSSNodeStyleSetHeight(node, 440); }]; @@ -56,8 +56,8 @@ RCTShadowView *centerView = [self _shadowViewWithConfig:^(CSSNodeRef node) { CSSNodeStyleSetFlex(node, 2); - CSSNodeStyleSetMargin(node, CSSEdgeLeft, 10); - CSSNodeStyleSetMargin(node, CSSEdgeRight, 10); + CSSNodeStyleSetMargin(node, YGEdgeLeft, 10); + CSSNodeStyleSetMargin(node, YGEdgeRight, 10); }]; RCTShadowView *rightView = [self _shadowViewWithConfig:^(CSSNodeRef node) { @@ -65,10 +65,10 @@ }]; RCTShadowView *mainView = [self _shadowViewWithConfig:^(CSSNodeRef node) { - CSSNodeStyleSetFlexDirection(node, CSSFlexDirectionRow); + CSSNodeStyleSetFlexDirection(node, YGFlexDirectionRow); CSSNodeStyleSetFlex(node, 2); - CSSNodeStyleSetMargin(node, CSSEdgeTop, 10); - CSSNodeStyleSetMargin(node, CSSEdgeBottom, 10); + CSSNodeStyleSetMargin(node, YGEdgeTop, 10); + CSSNodeStyleSetMargin(node, YGEdgeBottom, 10); }]; [mainView insertReactSubview:leftView atIndex:0]; @@ -83,10 +83,10 @@ CSSNodeStyleSetFlex(node, 1); }]; - CSSNodeStyleSetPadding(self.parentView.cssNode, CSSEdgeLeft, 10); - CSSNodeStyleSetPadding(self.parentView.cssNode, CSSEdgeTop, 10); - CSSNodeStyleSetPadding(self.parentView.cssNode, CSSEdgeRight, 10); - CSSNodeStyleSetPadding(self.parentView.cssNode, CSSEdgeBottom, 10); + CSSNodeStyleSetPadding(self.parentView.cssNode, YGEdgeLeft, 10); + CSSNodeStyleSetPadding(self.parentView.cssNode, YGEdgeTop, 10); + CSSNodeStyleSetPadding(self.parentView.cssNode, YGEdgeRight, 10); + CSSNodeStyleSetPadding(self.parentView.cssNode, YGEdgeBottom, 10); [self.parentView insertReactSubview:headerView atIndex:0]; [self.parentView insertReactSubview:mainView atIndex:1]; @@ -132,8 +132,8 @@ - (void)testAssignsSuggestedWidthDimension { [self _withShadowViewWithStyle:^(CSSNodeRef node) { - CSSNodeStyleSetPosition(node, CSSEdgeLeft, 0); - CSSNodeStyleSetPosition(node, CSSEdgeTop, 0); + CSSNodeStyleSetPosition(node, YGEdgeLeft, 0); + CSSNodeStyleSetPosition(node, YGEdgeTop, 0); CSSNodeStyleSetHeight(node, 10); } assertRelativeLayout:CGRectMake(0, 0, 3, 10) @@ -143,8 +143,8 @@ - (void)testAssignsSuggestedHeightDimension { [self _withShadowViewWithStyle:^(CSSNodeRef node) { - CSSNodeStyleSetPosition(node, CSSEdgeLeft, 0); - CSSNodeStyleSetPosition(node, CSSEdgeTop, 0); + CSSNodeStyleSetPosition(node, YGEdgeLeft, 0); + CSSNodeStyleSetPosition(node, YGEdgeTop, 0); CSSNodeStyleSetWidth(node, 10); } assertRelativeLayout:CGRectMake(0, 0, 10, 4) @@ -154,8 +154,8 @@ - (void)testDoesNotOverrideDimensionStyleWithSuggestedDimensions { [self _withShadowViewWithStyle:^(CSSNodeRef node) { - CSSNodeStyleSetPosition(node, CSSEdgeLeft, 0); - CSSNodeStyleSetPosition(node, CSSEdgeTop, 0); + CSSNodeStyleSetPosition(node, YGEdgeLeft, 0); + CSSNodeStyleSetPosition(node, YGEdgeTop, 0); CSSNodeStyleSetWidth(node, 10); CSSNodeStyleSetHeight(node, 10); } diff --git a/Libraries/Text/RCTShadowText.m b/Libraries/Text/RCTShadowText.m index 6046bdda937..dfa730134ca 100644 --- a/Libraries/Text/RCTShadowText.m +++ b/Libraries/Text/RCTShadowText.m @@ -39,7 +39,7 @@ CGFloat const RCTTextAutoSizeGranularity = 0.001f; CGFloat _effectiveLetterSpacing; } -static CSSSize RCTMeasure(CSSNodeRef node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) +static CSSSize RCTMeasure(CSSNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode) { RCTShadowText *shadowText = (__bridge RCTShadowText *)CSSNodeGetContext(node); NSTextStorage *textStorage = [shadowText buildTextStorageForWidth:width widthMode:widthMode]; @@ -114,7 +114,7 @@ static CSSSize RCTMeasure(CSSNodeRef node, float width, CSSMeasureMode widthMode NSNumber *parentTag = [[self reactSuperview] reactTag]; - NSTextStorage *textStorage = [self buildTextStorageForWidth:width widthMode:CSSMeasureModeExactly]; + NSTextStorage *textStorage = [self buildTextStorageForWidth:width widthMode:YGMeasureModeExactly]; CGRect textFrame = [self calculateTextFrame:textStorage]; BOOL selectable = _selectable; [applierBlocks addObject:^(NSDictionary *viewRegistry) { @@ -153,7 +153,7 @@ static CSSSize RCTMeasure(CSSNodeRef node, float width, CSSMeasureMode widthMode absolutePosition:(CGPoint)absolutePosition { // Run layout on subviews. - NSTextStorage *textStorage = [self buildTextStorageForWidth:self.frame.size.width widthMode:CSSMeasureModeExactly]; + NSTextStorage *textStorage = [self buildTextStorageForWidth:self.frame.size.width widthMode:YGMeasureModeExactly]; NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject; NSTextContainer *textContainer = layoutManager.textContainers.firstObject; NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer]; @@ -187,7 +187,7 @@ static CSSSize RCTMeasure(CSSNodeRef node, float width, CSSMeasureMode widthMode }]; } -- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(CSSMeasureMode)widthMode +- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(YGMeasureMode)widthMode { if (_cachedTextStorage && width == _cachedTextStorageWidth && widthMode == _cachedTextStorageWidthMode) { return _cachedTextStorage; @@ -208,7 +208,7 @@ static CSSSize RCTMeasure(CSSNodeRef node, float width, CSSMeasureMode widthMode } textContainer.maximumNumberOfLines = _numberOfLines; - textContainer.size = (CGSize){widthMode == CSSMeasureModeUndefined ? CGFLOAT_MAX : width, CGFLOAT_MAX}; + textContainer.size = (CGSize){widthMode == YGMeasureModeUndefined ? CGFLOAT_MAX : width, CGFLOAT_MAX}; [layoutManager addTextContainer:textContainer]; [layoutManager ensureLayoutForTextContainer:textContainer]; @@ -403,10 +403,10 @@ static CSSSize RCTMeasure(CSSNodeRef node, float width, CSSMeasureMode widthMode // We will climb up to the first node which style has been setted as non-inherit if (newTextAlign == NSTextAlignmentRight || newTextAlign == NSTextAlignmentLeft) { RCTShadowView *view = self; - while (view != nil && CSSNodeStyleGetDirection(view.cssNode) == CSSDirectionInherit) { + while (view != nil && CSSNodeStyleGetDirection(view.cssNode) == YGDirectionInherit) { view = [view reactSuperview]; } - if (view != nil && CSSNodeStyleGetDirection(view.cssNode) == CSSDirectionRTL) { + if (view != nil && CSSNodeStyleGetDirection(view.cssNode) == YGDirectionRTL) { if (newTextAlign == NSTextAlignmentRight) { newTextAlign = NSTextAlignmentLeft; } else if (newTextAlign == NSTextAlignmentLeft) { diff --git a/Libraries/Text/RCTTextManager.m b/Libraries/Text/RCTTextManager.m index 124f5480efe..d29fe61ba7a 100644 --- a/Libraries/Text/RCTTextManager.m +++ b/Libraries/Text/RCTTextManager.m @@ -35,7 +35,7 @@ static void collectDirtyNonTextDescendants(RCTShadowText *shadowView, NSMutableA @interface RCTShadowText (Private) -- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(CSSMeasureMode)widthMode; +- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(YGMeasureMode)widthMode; @end diff --git a/React/Base/RCTConvert.h b/React/Base/RCTConvert.h index 6c24058182b..be85ec4432b 100644 --- a/React/Base/RCTConvert.h +++ b/React/Base/RCTConvert.h @@ -109,13 +109,13 @@ typedef id NSPropertyList; + (NSPropertyList)NSPropertyList:(id)json; typedef BOOL css_backface_visibility_t; -+ (CSSOverflow)CSSOverflow:(id)json; ++ (YGOverflow)YGOverflow:(id)json; + (css_backface_visibility_t)css_backface_visibility_t:(id)json; -+ (CSSFlexDirection)CSSFlexDirection:(id)json; -+ (CSSJustify)CSSJustify:(id)json; -+ (CSSAlign)CSSAlign:(id)json; -+ (CSSPositionType)CSSPositionType:(id)json; -+ (CSSWrap)CSSWrap:(id)json; ++ (YGFlexDirection)YGFlexDirection:(id)json; ++ (YGJustify)YGJustify:(id)json; ++ (YGAlign)YGAlign:(id)json; ++ (YGPositionType)YGPositionType:(id)json; ++ (YGWrap)YGWrap:(id)json; + (RCTPointerEvents)RCTPointerEvents:(id)json; + (RCTAnimationType)RCTAnimationType:(id)json; diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index 64bb96d2050..01ee6ba96cc 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -614,44 +614,44 @@ RCT_ENUM_CONVERTER(css_backface_visibility_t, (@{ @"visible": @YES }), YES, boolValue) -RCT_ENUM_CONVERTER(CSSOverflow, (@{ - @"hidden": @(CSSOverflowHidden), - @"visible": @(CSSOverflowVisible), - @"scroll": @(CSSOverflowScroll), -}), CSSOverflowVisible, intValue) +RCT_ENUM_CONVERTER(YGOverflow, (@{ + @"hidden": @(YGOverflowHidden), + @"visible": @(YGOverflowVisible), + @"scroll": @(YGOverflowScroll), +}), YGOverflowVisible, intValue) -RCT_ENUM_CONVERTER(CSSFlexDirection, (@{ - @"row": @(CSSFlexDirectionRow), - @"row-reverse": @(CSSFlexDirectionRowReverse), - @"column": @(CSSFlexDirectionColumn), - @"column-reverse": @(CSSFlexDirectionColumnReverse) -}), CSSFlexDirectionColumn, intValue) +RCT_ENUM_CONVERTER(YGFlexDirection, (@{ + @"row": @(YGFlexDirectionRow), + @"row-reverse": @(YGFlexDirectionRowReverse), + @"column": @(YGFlexDirectionColumn), + @"column-reverse": @(YGFlexDirectionColumnReverse) +}), YGFlexDirectionColumn, intValue) -RCT_ENUM_CONVERTER(CSSJustify, (@{ - @"flex-start": @(CSSJustifyFlexStart), - @"flex-end": @(CSSJustifyFlexEnd), - @"center": @(CSSJustifyCenter), - @"space-between": @(CSSJustifySpaceBetween), - @"space-around": @(CSSJustifySpaceAround) -}), CSSJustifyFlexStart, intValue) +RCT_ENUM_CONVERTER(YGJustify, (@{ + @"flex-start": @(YGJustifyFlexStart), + @"flex-end": @(YGJustifyFlexEnd), + @"center": @(YGJustifyCenter), + @"space-between": @(YGJustifySpaceBetween), + @"space-around": @(YGJustifySpaceAround) +}), YGJustifyFlexStart, intValue) -RCT_ENUM_CONVERTER(CSSAlign, (@{ - @"flex-start": @(CSSAlignFlexStart), - @"flex-end": @(CSSAlignFlexEnd), - @"center": @(CSSAlignCenter), - @"auto": @(CSSAlignAuto), - @"stretch": @(CSSAlignStretch) -}), CSSAlignFlexStart, intValue) +RCT_ENUM_CONVERTER(YGAlign, (@{ + @"flex-start": @(YGAlignFlexStart), + @"flex-end": @(YGAlignFlexEnd), + @"center": @(YGAlignCenter), + @"auto": @(YGAlignAuto), + @"stretch": @(YGAlignStretch) +}), YGAlignFlexStart, intValue) -RCT_ENUM_CONVERTER(CSSPositionType, (@{ - @"absolute": @(CSSPositionTypeAbsolute), - @"relative": @(CSSPositionTypeRelative) -}), CSSPositionTypeRelative, intValue) +RCT_ENUM_CONVERTER(YGPositionType, (@{ + @"absolute": @(YGPositionTypeAbsolute), + @"relative": @(YGPositionTypeRelative) +}), YGPositionTypeRelative, intValue) -RCT_ENUM_CONVERTER(CSSWrap, (@{ - @"wrap": @(CSSWrapWrap), - @"nowrap": @(CSSWrapNoWrap) -}), CSSWrapNoWrap, intValue) +RCT_ENUM_CONVERTER(YGWrap, (@{ + @"wrap": @(YGWrapWrap), + @"nowrap": @(YGWrapNoWrap) +}), YGWrapNoWrap, intValue) RCT_ENUM_CONVERTER(RCTPointerEvents, (@{ @"none": @(RCTPointerEventsNone), diff --git a/React/CSSLayout/CSSEnums.h b/React/CSSLayout/CSSEnums.h new file mode 100644 index 00000000000..2a87abf9953 --- /dev/null +++ b/React/CSSLayout/CSSEnums.h @@ -0,0 +1,108 @@ +/** + * 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 YGFlexDirection { + YGFlexDirectionColumn, + YGFlexDirectionColumnReverse, + YGFlexDirectionRow, + YGFlexDirectionRowReverse, + YGFlexDirectionCount, +} YGFlexDirection; + +typedef enum YGMeasureMode { + YGMeasureModeUndefined, + YGMeasureModeExactly, + YGMeasureModeAtMost, + YGMeasureModeCount, +} YGMeasureMode; + +typedef enum YGPrintOptions { + YGPrintOptionsLayout = 1, + YGPrintOptionsStyle = 2, + YGPrintOptionsChildren = 4, + YGPrintOptionsCount, +} YGPrintOptions; + +typedef enum YGEdge { + YGEdgeLeft, + YGEdgeTop, + YGEdgeRight, + YGEdgeBottom, + YGEdgeStart, + YGEdgeEnd, + YGEdgeHorizontal, + YGEdgeVertical, + YGEdgeAll, + YGEdgeCount, +} YGEdge; + +typedef enum YGPositionType { + YGPositionTypeRelative, + YGPositionTypeAbsolute, + YGPositionTypeCount, +} YGPositionType; + +typedef enum YGDimension { + YGDimensionWidth, + YGDimensionHeight, + YGDimensionCount, +} YGDimension; + +typedef enum YGJustify { + YGJustifyFlexStart, + YGJustifyCenter, + YGJustifyFlexEnd, + YGJustifySpaceBetween, + YGJustifySpaceAround, + YGJustifyCount, +} YGJustify; + +typedef enum YGDirection { + YGDirectionInherit, + YGDirectionLTR, + YGDirectionRTL, + YGDirectionCount, +} YGDirection; + +typedef enum YGLogLevel { + YGLogLevelError, + YGLogLevelWarn, + YGLogLevelInfo, + YGLogLevelDebug, + YGLogLevelVerbose, + YGLogLevelCount, +} YGLogLevel; + +typedef enum YGWrap { + YGWrapNoWrap, + YGWrapWrap, + YGWrapCount, +} YGWrap; + +typedef enum YGOverflow { + YGOverflowVisible, + YGOverflowHidden, + YGOverflowScroll, + YGOverflowCount, +} YGOverflow; + +typedef enum YGExperimentalFeature { + YGExperimentalFeatureRounding, + YGExperimentalFeatureWebFlexBasis, + YGExperimentalFeatureCount, +} YGExperimentalFeature; + +typedef enum YGAlign { + YGAlignAuto, + YGAlignFlexStart, + YGAlignCenter, + YGAlignFlexEnd, + YGAlignStretch, + YGAlignCount, +} YGAlign; diff --git a/React/CSSLayout/CSSLayout.c b/React/CSSLayout/CSSLayout.c index 7067827a7d5..c41194a1ea1 100644 --- a/React/CSSLayout/CSSLayout.c +++ b/React/CSSLayout/CSSLayout.c @@ -33,8 +33,8 @@ __forceinline const float fmaxf(const float a, const float b) { typedef struct CSSCachedMeasurement { float availableWidth; float availableHeight; - CSSMeasureMode widthMeasureMode; - CSSMeasureMode heightMeasureMode; + YGMeasureMode widthMeasureMode; + YGMeasureMode heightMeasureMode; float computedWidth; float computedHeight; @@ -47,7 +47,7 @@ enum { CSS_MAX_CACHED_RESULT_COUNT = 16 }; typedef struct CSSLayout { float position[4]; float dimensions[2]; - CSSDirection direction; + YGDirection direction; uint32_t computedFlexBasisGeneration; float computedFlexBasis; @@ -55,7 +55,7 @@ typedef struct CSSLayout { // Instead of recomputing the entire layout every single time, we // cache some information to break early when nothing changed uint32_t generationCount; - CSSDirection lastParentDirection; + YGDirection lastParentDirection; uint32_t nextCachedMeasurementsIndex; CSSCachedMeasurement cachedMeasurements[CSS_MAX_CACHED_RESULT_COUNT]; @@ -65,23 +65,23 @@ typedef struct CSSLayout { } CSSLayout; typedef struct CSSStyle { - CSSDirection direction; - CSSFlexDirection flexDirection; - CSSJustify justifyContent; - CSSAlign alignContent; - CSSAlign alignItems; - CSSAlign alignSelf; - CSSPositionType positionType; - CSSWrap flexWrap; - CSSOverflow overflow; + YGDirection direction; + YGFlexDirection flexDirection; + YGJustify justifyContent; + YGAlign alignContent; + YGAlign alignItems; + YGAlign alignSelf; + YGPositionType positionType; + YGWrap flexWrap; + YGOverflow overflow; float flex; float flexGrow; float flexShrink; float flexBasis; - float margin[CSSEdgeCount]; - float position[CSSEdgeCount]; - float padding[CSSEdgeCount]; - float border[CSSEdgeCount]; + float margin[YGEdgeCount]; + float position[YGEdgeCount]; + float padding[YGEdgeCount]; + float border[YGEdgeCount]; float dimensions[2]; float minDimensions[2]; float maxDimensions[2]; @@ -115,25 +115,25 @@ CSSFree gCSSFree = &free; #ifdef ANDROID #include -static int _csslayoutAndroidLog(CSSLogLevel level, const char *format, va_list args) { - int androidLevel = CSSLogLevelDebug; +static int _csslayoutAndroidLog(YGLogLevel level, const char *format, va_list args) { + int androidLevel = YGLogLevelDebug; switch (level) { - case CSSLogLevelError: + case YGLogLevelError: androidLevel = ANDROID_LOG_ERROR; break; - case CSSLogLevelWarn: + case YGLogLevelWarn: androidLevel = ANDROID_LOG_WARN; break; - case CSSLogLevelInfo: + case YGLogLevelInfo: androidLevel = ANDROID_LOG_INFO; break; - case CSSLogLevelDebug: + case YGLogLevelDebug: androidLevel = ANDROID_LOG_DEBUG; break; - case CSSLogLevelVerbose: + case YGLogLevelVerbose: androidLevel = ANDROID_LOG_VERBOSE; break; - case CSSLogLevelCount: + case YGLogLevelCount: break; } const int result = __android_log_vprint(androidLevel, "css-layout", format, args); @@ -141,14 +141,14 @@ static int _csslayoutAndroidLog(CSSLogLevel level, const char *format, va_list a } static CSSLogger gLogger = &_csslayoutAndroidLog; #else -static int _csslayoutDefaultLog(CSSLogLevel level, const char *format, va_list args) { +static int _csslayoutDefaultLog(YGLogLevel level, const char *format, va_list args) { switch (level) { - case CSSLogLevelError: + case YGLogLevelError: return vfprintf(stderr, format, args); - case CSSLogLevelWarn: - case CSSLogLevelInfo: - case CSSLogLevelDebug: - case CSSLogLevelVerbose: + case YGLogLevelWarn: + case YGLogLevelInfo: + case YGLogLevelDebug: + case YGLogLevelVerbose: default: return vprintf(format, args); } @@ -156,31 +156,30 @@ static int _csslayoutDefaultLog(CSSLogLevel level, const char *format, va_list a static CSSLogger gLogger = &_csslayoutDefaultLog; #endif -static inline float computedEdgeValue(const float edges[CSSEdgeCount], - const CSSEdge edge, +static inline float computedEdgeValue(const float edges[YGEdgeCount], + const YGEdge edge, const float defaultValue) { - CSS_ASSERT(edge <= CSSEdgeEnd, "Cannot get computed value of multi-edge shorthands"); + CSS_ASSERT(edge <= YGEdgeEnd, "Cannot get computed value of multi-edge shorthands"); if (!CSSValueIsUndefined(edges[edge])) { return edges[edge]; } - if ((edge == CSSEdgeTop || edge == CSSEdgeBottom) && - !CSSValueIsUndefined(edges[CSSEdgeVertical])) { - return edges[CSSEdgeVertical]; + if ((edge == YGEdgeTop || edge == YGEdgeBottom) && !CSSValueIsUndefined(edges[YGEdgeVertical])) { + return edges[YGEdgeVertical]; } - if ((edge == CSSEdgeLeft || edge == CSSEdgeRight || edge == CSSEdgeStart || edge == CSSEdgeEnd) && - !CSSValueIsUndefined(edges[CSSEdgeHorizontal])) { - return edges[CSSEdgeHorizontal]; + if ((edge == YGEdgeLeft || edge == YGEdgeRight || edge == YGEdgeStart || edge == YGEdgeEnd) && + !CSSValueIsUndefined(edges[YGEdgeHorizontal])) { + return edges[YGEdgeHorizontal]; } - if (!CSSValueIsUndefined(edges[CSSEdgeAll])) { - return edges[CSSEdgeAll]; + if (!CSSValueIsUndefined(edges[YGEdgeAll])) { + return edges[YGEdgeAll]; } - if (edge == CSSEdgeStart || edge == CSSEdgeEnd) { - return CSSUndefined; + if (edge == YGEdgeStart || edge == YGEdgeEnd) { + return YGUndefined; } return defaultValue; @@ -242,50 +241,50 @@ void CSSNodeInit(const CSSNodeRef node) { node->hasNewLayout = true; node->isDirty = false; - node->style.flex = CSSUndefined; - node->style.flexGrow = CSSUndefined; - node->style.flexShrink = CSSUndefined; - node->style.flexBasis = CSSUndefined; + node->style.flex = YGUndefined; + node->style.flexGrow = YGUndefined; + node->style.flexShrink = YGUndefined; + node->style.flexBasis = YGUndefined; - node->style.alignItems = CSSAlignStretch; - node->style.alignContent = CSSAlignFlexStart; + node->style.alignItems = YGAlignStretch; + node->style.alignContent = YGAlignFlexStart; - node->style.direction = CSSDirectionInherit; - node->style.flexDirection = CSSFlexDirectionColumn; + node->style.direction = YGDirectionInherit; + node->style.flexDirection = YGFlexDirectionColumn; - node->style.overflow = CSSOverflowVisible; + node->style.overflow = YGOverflowVisible; // Some of the fields default to undefined and not 0 - node->style.dimensions[CSSDimensionWidth] = CSSUndefined; - node->style.dimensions[CSSDimensionHeight] = CSSUndefined; + node->style.dimensions[YGDimensionWidth] = YGUndefined; + node->style.dimensions[YGDimensionHeight] = YGUndefined; - node->style.minDimensions[CSSDimensionWidth] = CSSUndefined; - node->style.minDimensions[CSSDimensionHeight] = CSSUndefined; + node->style.minDimensions[YGDimensionWidth] = YGUndefined; + node->style.minDimensions[YGDimensionHeight] = YGUndefined; - node->style.maxDimensions[CSSDimensionWidth] = CSSUndefined; - node->style.maxDimensions[CSSDimensionHeight] = CSSUndefined; + node->style.maxDimensions[YGDimensionWidth] = YGUndefined; + node->style.maxDimensions[YGDimensionHeight] = YGUndefined; - for (CSSEdge edge = CSSEdgeLeft; edge < CSSEdgeCount; edge++) { - node->style.position[edge] = CSSUndefined; - node->style.margin[edge] = CSSUndefined; - node->style.padding[edge] = CSSUndefined; - node->style.border[edge] = CSSUndefined; + for (YGEdge edge = YGEdgeLeft; edge < YGEdgeCount; edge++) { + node->style.position[edge] = YGUndefined; + node->style.margin[edge] = YGUndefined; + node->style.padding[edge] = YGUndefined; + node->style.border[edge] = YGUndefined; } - node->style.aspectRatio = CSSUndefined; + node->style.aspectRatio = YGUndefined; - node->layout.dimensions[CSSDimensionWidth] = CSSUndefined; - node->layout.dimensions[CSSDimensionHeight] = CSSUndefined; + node->layout.dimensions[YGDimensionWidth] = YGUndefined; + node->layout.dimensions[YGDimensionHeight] = YGUndefined; // Such that the comparison is always going to be false - node->layout.lastParentDirection = (CSSDirection) -1; + node->layout.lastParentDirection = (YGDirection) -1; node->layout.nextCachedMeasurementsIndex = 0; - node->layout.computedFlexBasis = CSSUndefined; + node->layout.computedFlexBasis = YGUndefined; - node->layout.measuredDimensions[CSSDimensionWidth] = CSSUndefined; - node->layout.measuredDimensions[CSSDimensionHeight] = CSSUndefined; - node->layout.cachedLayout.widthMeasureMode = (CSSMeasureMode) -1; - node->layout.cachedLayout.heightMeasureMode = (CSSMeasureMode) -1; + node->layout.measuredDimensions[YGDimensionWidth] = YGUndefined; + node->layout.measuredDimensions[YGDimensionHeight] = YGUndefined; + node->layout.cachedLayout.widthMeasureMode = (YGMeasureMode) -1; + node->layout.cachedLayout.heightMeasureMode = (YGMeasureMode) -1; node->layout.cachedLayout.computedWidth = -1; node->layout.cachedLayout.computedHeight = -1; } @@ -293,7 +292,7 @@ void CSSNodeInit(const CSSNodeRef node) { static void _CSSNodeMarkDirty(const CSSNodeRef node) { if (!node->isDirty) { node->isDirty = true; - node->layout.computedFlexBasis = CSSUndefined; + node->layout.computedFlexBasis = YGUndefined; if (node->parent) { _CSSNodeMarkDirty(node->parent); } @@ -381,9 +380,9 @@ inline float CSSNodeStyleGetFlexBasis(const CSSNodeRef node) { return node->style.flexBasis; } if (!CSSValueIsUndefined(node->style.flex)) { - return node->style.flex > 0 ? 0 : CSSUndefined; + return node->style.flex > 0 ? 0 : YGUndefined; } - return CSSUndefined; + return YGUndefined; } void CSSNodeStyleSetFlex(const CSSNodeRef node, const float flex) { @@ -417,16 +416,16 @@ void CSSNodeStyleSetFlex(const CSSNodeRef node, const float flex) { return node->style.instanceName; \ } -#define CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName, defaultValue) \ - void CSSNodeStyleSet##name(const CSSNodeRef node, const CSSEdge edge, const type paramName) { \ - if (node->style.instanceName[edge] != paramName) { \ - node->style.instanceName[edge] = paramName; \ - _CSSNodeMarkDirty(node); \ - } \ - } \ - \ - type CSSNodeStyleGet##name(const CSSNodeRef node, const CSSEdge edge) { \ - return computedEdgeValue(node->style.instanceName, edge, defaultValue); \ +#define CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName, defaultValue) \ + void CSSNodeStyleSet##name(const CSSNodeRef node, const YGEdge edge, const type paramName) { \ + if (node->style.instanceName[edge] != paramName) { \ + node->style.instanceName[edge] = paramName; \ + _CSSNodeMarkDirty(node); \ + } \ + } \ + \ + type CSSNodeStyleGet##name(const CSSNodeRef node, const YGEdge edge) { \ + return computedEdgeValue(node->style.instanceName, edge, defaultValue); \ } #define CSS_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \ @@ -438,51 +437,51 @@ CSS_NODE_PROPERTY_IMPL(void *, Context, context, context); CSS_NODE_PROPERTY_IMPL(CSSPrintFunc, PrintFunc, printFunc, print); CSS_NODE_PROPERTY_IMPL(bool, HasNewLayout, hasNewLayout, hasNewLayout); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSDirection, Direction, direction, direction); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSFlexDirection, FlexDirection, flexDirection, flexDirection); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSJustify, JustifyContent, justifyContent, justifyContent); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSAlign, AlignContent, alignContent, alignContent); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSAlign, AlignItems, alignItems, alignItems); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSAlign, AlignSelf, alignSelf, alignSelf); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSPositionType, PositionType, positionType, positionType); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSWrap, FlexWrap, flexWrap, flexWrap); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSOverflow, Overflow, overflow, overflow); +CSS_NODE_STYLE_PROPERTY_IMPL(YGDirection, Direction, direction, direction); +CSS_NODE_STYLE_PROPERTY_IMPL(YGFlexDirection, FlexDirection, flexDirection, flexDirection); +CSS_NODE_STYLE_PROPERTY_IMPL(YGJustify, JustifyContent, justifyContent, justifyContent); +CSS_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignContent, alignContent, alignContent); +CSS_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignItems, alignItems, alignItems); +CSS_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignSelf, alignSelf, alignSelf); +CSS_NODE_STYLE_PROPERTY_IMPL(YGPositionType, PositionType, positionType, positionType); +CSS_NODE_STYLE_PROPERTY_IMPL(YGWrap, FlexWrap, flexWrap, flexWrap); +CSS_NODE_STYLE_PROPERTY_IMPL(YGOverflow, Overflow, overflow, overflow); CSS_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexGrow, flexGrow, flexGrow); CSS_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink); CSS_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexBasis, flexBasis, flexBasis); -CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Position, position, position, CSSUndefined); +CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Position, position, position, YGUndefined); CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Margin, margin, margin, 0); CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Padding, padding, padding, 0); CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Border, border, border, 0); -CSS_NODE_STYLE_PROPERTY_IMPL(float, Width, width, dimensions[CSSDimensionWidth]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, Height, height, dimensions[CSSDimensionHeight]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, MinWidth, minWidth, minDimensions[CSSDimensionWidth]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, MinHeight, minHeight, minDimensions[CSSDimensionHeight]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, MaxWidth, maxWidth, maxDimensions[CSSDimensionWidth]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, MaxHeight, maxHeight, maxDimensions[CSSDimensionHeight]); +CSS_NODE_STYLE_PROPERTY_IMPL(float, Width, width, dimensions[YGDimensionWidth]); +CSS_NODE_STYLE_PROPERTY_IMPL(float, Height, height, dimensions[YGDimensionHeight]); +CSS_NODE_STYLE_PROPERTY_IMPL(float, MinWidth, minWidth, minDimensions[YGDimensionWidth]); +CSS_NODE_STYLE_PROPERTY_IMPL(float, MinHeight, minHeight, minDimensions[YGDimensionHeight]); +CSS_NODE_STYLE_PROPERTY_IMPL(float, MaxWidth, maxWidth, maxDimensions[YGDimensionWidth]); +CSS_NODE_STYLE_PROPERTY_IMPL(float, MaxHeight, maxHeight, maxDimensions[YGDimensionHeight]); // Yoga specific properties, not compatible with flexbox specification CSS_NODE_STYLE_PROPERTY_IMPL(float, AspectRatio, aspectRatio, aspectRatio); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Left, position[CSSEdgeLeft]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Top, position[CSSEdgeTop]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Right, position[CSSEdgeRight]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Bottom, position[CSSEdgeBottom]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Width, dimensions[CSSDimensionWidth]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[CSSDimensionHeight]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(CSSDirection, Direction, direction); +CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Left, position[YGEdgeLeft]); +CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Top, position[YGEdgeTop]); +CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Right, position[YGEdgeRight]); +CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Bottom, position[YGEdgeBottom]); +CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Width, dimensions[YGDimensionWidth]); +CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[YGDimensionHeight]); +CSS_NODE_LAYOUT_PROPERTY_IMPL(YGDirection, Direction, direction); uint32_t gCurrentGenerationCount = 0; bool layoutNodeInternal(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSDirection parentDirection, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode, + const YGDirection parentDirection, + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode, const bool performLayout, const char *reason); @@ -499,19 +498,19 @@ static inline bool eq(const float a, const float b) { static void indent(const uint32_t n) { for (uint32_t i = 0; i < n; i++) { - CSSLog(CSSLogLevelDebug, " "); + CSSLog(YGLogLevelDebug, " "); } } static void printNumberIfNotZero(const char *str, const float number) { if (!eq(number, 0)) { - CSSLog(CSSLogLevelDebug, "%s: %g, ", str, number); + CSSLog(YGLogLevelDebug, "%s: %g, ", str, number); } } static void printNumberIfNotUndefined(const char *str, const float number) { if (!CSSValueIsUndefined(number)) { - CSSLog(CSSLogLevelDebug, "%s: %g, ", str, number); + CSSLog(YGLogLevelDebug, "%s: %g, ", str, number); } } @@ -520,370 +519,363 @@ static bool eqFour(const float four[4]) { } static void _CSSNodePrint(const CSSNodeRef node, - const CSSPrintOptions options, + const YGPrintOptions options, const uint32_t level) { indent(level); - CSSLog(CSSLogLevelDebug, "{"); + CSSLog(YGLogLevelDebug, "{"); if (node->print) { node->print(node); } - if (options & CSSPrintOptionsLayout) { - CSSLog(CSSLogLevelDebug, "layout: {"); - CSSLog(CSSLogLevelDebug, "width: %g, ", node->layout.dimensions[CSSDimensionWidth]); - CSSLog(CSSLogLevelDebug, "height: %g, ", node->layout.dimensions[CSSDimensionHeight]); - CSSLog(CSSLogLevelDebug, "top: %g, ", node->layout.position[CSSEdgeTop]); - CSSLog(CSSLogLevelDebug, "left: %g", node->layout.position[CSSEdgeLeft]); - CSSLog(CSSLogLevelDebug, "}, "); + if (options & YGPrintOptionsLayout) { + CSSLog(YGLogLevelDebug, "layout: {"); + CSSLog(YGLogLevelDebug, "width: %g, ", node->layout.dimensions[YGDimensionWidth]); + CSSLog(YGLogLevelDebug, "height: %g, ", node->layout.dimensions[YGDimensionHeight]); + CSSLog(YGLogLevelDebug, "top: %g, ", node->layout.position[YGEdgeTop]); + CSSLog(YGLogLevelDebug, "left: %g", node->layout.position[YGEdgeLeft]); + CSSLog(YGLogLevelDebug, "}, "); } - if (options & CSSPrintOptionsStyle) { - if (node->style.flexDirection == CSSFlexDirectionColumn) { - CSSLog(CSSLogLevelDebug, "flexDirection: 'column', "); - } else if (node->style.flexDirection == CSSFlexDirectionColumnReverse) { - CSSLog(CSSLogLevelDebug, "flexDirection: 'column-reverse', "); - } else if (node->style.flexDirection == CSSFlexDirectionRow) { - CSSLog(CSSLogLevelDebug, "flexDirection: 'row', "); - } else if (node->style.flexDirection == CSSFlexDirectionRowReverse) { - CSSLog(CSSLogLevelDebug, "flexDirection: 'row-reverse', "); + if (options & YGPrintOptionsStyle) { + if (node->style.flexDirection == YGFlexDirectionColumn) { + CSSLog(YGLogLevelDebug, "flexDirection: 'column', "); + } else if (node->style.flexDirection == YGFlexDirectionColumnReverse) { + CSSLog(YGLogLevelDebug, "flexDirection: 'column-reverse', "); + } else if (node->style.flexDirection == YGFlexDirectionRow) { + CSSLog(YGLogLevelDebug, "flexDirection: 'row', "); + } else if (node->style.flexDirection == YGFlexDirectionRowReverse) { + CSSLog(YGLogLevelDebug, "flexDirection: 'row-reverse', "); } - if (node->style.justifyContent == CSSJustifyCenter) { - CSSLog(CSSLogLevelDebug, "justifyContent: 'center', "); - } else if (node->style.justifyContent == CSSJustifyFlexEnd) { - CSSLog(CSSLogLevelDebug, "justifyContent: 'flex-end', "); - } else if (node->style.justifyContent == CSSJustifySpaceAround) { - CSSLog(CSSLogLevelDebug, "justifyContent: 'space-around', "); - } else if (node->style.justifyContent == CSSJustifySpaceBetween) { - CSSLog(CSSLogLevelDebug, "justifyContent: 'space-between', "); + if (node->style.justifyContent == YGJustifyCenter) { + CSSLog(YGLogLevelDebug, "justifyContent: 'center', "); + } else if (node->style.justifyContent == YGJustifyFlexEnd) { + CSSLog(YGLogLevelDebug, "justifyContent: 'flex-end', "); + } else if (node->style.justifyContent == YGJustifySpaceAround) { + CSSLog(YGLogLevelDebug, "justifyContent: 'space-around', "); + } else if (node->style.justifyContent == YGJustifySpaceBetween) { + CSSLog(YGLogLevelDebug, "justifyContent: 'space-between', "); } - if (node->style.alignItems == CSSAlignCenter) { - CSSLog(CSSLogLevelDebug, "alignItems: 'center', "); - } else if (node->style.alignItems == CSSAlignFlexEnd) { - CSSLog(CSSLogLevelDebug, "alignItems: 'flex-end', "); - } else if (node->style.alignItems == CSSAlignStretch) { - CSSLog(CSSLogLevelDebug, "alignItems: 'stretch', "); + if (node->style.alignItems == YGAlignCenter) { + CSSLog(YGLogLevelDebug, "alignItems: 'center', "); + } else if (node->style.alignItems == YGAlignFlexEnd) { + CSSLog(YGLogLevelDebug, "alignItems: 'flex-end', "); + } else if (node->style.alignItems == YGAlignStretch) { + CSSLog(YGLogLevelDebug, "alignItems: 'stretch', "); } - if (node->style.alignContent == CSSAlignCenter) { - CSSLog(CSSLogLevelDebug, "alignContent: 'center', "); - } else if (node->style.alignContent == CSSAlignFlexEnd) { - CSSLog(CSSLogLevelDebug, "alignContent: 'flex-end', "); - } else if (node->style.alignContent == CSSAlignStretch) { - CSSLog(CSSLogLevelDebug, "alignContent: 'stretch', "); + if (node->style.alignContent == YGAlignCenter) { + CSSLog(YGLogLevelDebug, "alignContent: 'center', "); + } else if (node->style.alignContent == YGAlignFlexEnd) { + CSSLog(YGLogLevelDebug, "alignContent: 'flex-end', "); + } else if (node->style.alignContent == YGAlignStretch) { + CSSLog(YGLogLevelDebug, "alignContent: 'stretch', "); } - if (node->style.alignSelf == CSSAlignFlexStart) { - CSSLog(CSSLogLevelDebug, "alignSelf: 'flex-start', "); - } else if (node->style.alignSelf == CSSAlignCenter) { - CSSLog(CSSLogLevelDebug, "alignSelf: 'center', "); - } else if (node->style.alignSelf == CSSAlignFlexEnd) { - CSSLog(CSSLogLevelDebug, "alignSelf: 'flex-end', "); - } else if (node->style.alignSelf == CSSAlignStretch) { - CSSLog(CSSLogLevelDebug, "alignSelf: 'stretch', "); + if (node->style.alignSelf == YGAlignFlexStart) { + CSSLog(YGLogLevelDebug, "alignSelf: 'flex-start', "); + } else if (node->style.alignSelf == YGAlignCenter) { + CSSLog(YGLogLevelDebug, "alignSelf: 'center', "); + } else if (node->style.alignSelf == YGAlignFlexEnd) { + CSSLog(YGLogLevelDebug, "alignSelf: 'flex-end', "); + } else if (node->style.alignSelf == YGAlignStretch) { + CSSLog(YGLogLevelDebug, "alignSelf: 'stretch', "); } printNumberIfNotUndefined("flexGrow", CSSNodeStyleGetFlexGrow(node)); printNumberIfNotUndefined("flexShrink", CSSNodeStyleGetFlexShrink(node)); printNumberIfNotUndefined("flexBasis", CSSNodeStyleGetFlexBasis(node)); - if (node->style.overflow == CSSOverflowHidden) { - CSSLog(CSSLogLevelDebug, "overflow: 'hidden', "); - } else if (node->style.overflow == CSSOverflowVisible) { - CSSLog(CSSLogLevelDebug, "overflow: 'visible', "); - } else if (node->style.overflow == CSSOverflowScroll) { - CSSLog(CSSLogLevelDebug, "overflow: 'scroll', "); + if (node->style.overflow == YGOverflowHidden) { + CSSLog(YGLogLevelDebug, "overflow: 'hidden', "); + } else if (node->style.overflow == YGOverflowVisible) { + CSSLog(YGLogLevelDebug, "overflow: 'visible', "); + } else if (node->style.overflow == YGOverflowScroll) { + CSSLog(YGLogLevelDebug, "overflow: 'scroll', "); } if (eqFour(node->style.margin)) { - printNumberIfNotZero("margin", computedEdgeValue(node->style.margin, CSSEdgeLeft, 0)); + printNumberIfNotZero("margin", computedEdgeValue(node->style.margin, YGEdgeLeft, 0)); } else { - printNumberIfNotZero("marginLeft", computedEdgeValue(node->style.margin, CSSEdgeLeft, 0)); - printNumberIfNotZero("marginRight", computedEdgeValue(node->style.margin, CSSEdgeRight, 0)); - printNumberIfNotZero("marginTop", computedEdgeValue(node->style.margin, CSSEdgeTop, 0)); - printNumberIfNotZero("marginBottom", computedEdgeValue(node->style.margin, CSSEdgeBottom, 0)); - printNumberIfNotZero("marginStart", computedEdgeValue(node->style.margin, CSSEdgeStart, 0)); - printNumberIfNotZero("marginEnd", computedEdgeValue(node->style.margin, CSSEdgeEnd, 0)); + printNumberIfNotZero("marginLeft", computedEdgeValue(node->style.margin, YGEdgeLeft, 0)); + printNumberIfNotZero("marginRight", computedEdgeValue(node->style.margin, YGEdgeRight, 0)); + printNumberIfNotZero("marginTop", computedEdgeValue(node->style.margin, YGEdgeTop, 0)); + printNumberIfNotZero("marginBottom", computedEdgeValue(node->style.margin, YGEdgeBottom, 0)); + printNumberIfNotZero("marginStart", computedEdgeValue(node->style.margin, YGEdgeStart, 0)); + printNumberIfNotZero("marginEnd", computedEdgeValue(node->style.margin, YGEdgeEnd, 0)); } if (eqFour(node->style.padding)) { - printNumberIfNotZero("padding", computedEdgeValue(node->style.padding, CSSEdgeLeft, 0)); + printNumberIfNotZero("padding", computedEdgeValue(node->style.padding, YGEdgeLeft, 0)); } else { - printNumberIfNotZero("paddingLeft", computedEdgeValue(node->style.padding, CSSEdgeLeft, 0)); - printNumberIfNotZero("paddingRight", computedEdgeValue(node->style.padding, CSSEdgeRight, 0)); - printNumberIfNotZero("paddingTop", computedEdgeValue(node->style.padding, CSSEdgeTop, 0)); + printNumberIfNotZero("paddingLeft", computedEdgeValue(node->style.padding, YGEdgeLeft, 0)); + printNumberIfNotZero("paddingRight", computedEdgeValue(node->style.padding, YGEdgeRight, 0)); + printNumberIfNotZero("paddingTop", computedEdgeValue(node->style.padding, YGEdgeTop, 0)); printNumberIfNotZero("paddingBottom", - computedEdgeValue(node->style.padding, CSSEdgeBottom, 0)); - printNumberIfNotZero("paddingStart", computedEdgeValue(node->style.padding, CSSEdgeStart, 0)); - printNumberIfNotZero("paddingEnd", computedEdgeValue(node->style.padding, CSSEdgeEnd, 0)); + computedEdgeValue(node->style.padding, YGEdgeBottom, 0)); + printNumberIfNotZero("paddingStart", computedEdgeValue(node->style.padding, YGEdgeStart, 0)); + printNumberIfNotZero("paddingEnd", computedEdgeValue(node->style.padding, YGEdgeEnd, 0)); } if (eqFour(node->style.border)) { - printNumberIfNotZero("borderWidth", computedEdgeValue(node->style.border, CSSEdgeLeft, 0)); + printNumberIfNotZero("borderWidth", computedEdgeValue(node->style.border, YGEdgeLeft, 0)); } else { - printNumberIfNotZero("borderLeftWidth", - computedEdgeValue(node->style.border, CSSEdgeLeft, 0)); + printNumberIfNotZero("borderLeftWidth", computedEdgeValue(node->style.border, YGEdgeLeft, 0)); printNumberIfNotZero("borderRightWidth", - computedEdgeValue(node->style.border, CSSEdgeRight, 0)); - printNumberIfNotZero("borderTopWidth", computedEdgeValue(node->style.border, CSSEdgeTop, 0)); + computedEdgeValue(node->style.border, YGEdgeRight, 0)); + printNumberIfNotZero("borderTopWidth", computedEdgeValue(node->style.border, YGEdgeTop, 0)); printNumberIfNotZero("borderBottomWidth", - computedEdgeValue(node->style.border, CSSEdgeBottom, 0)); + computedEdgeValue(node->style.border, YGEdgeBottom, 0)); printNumberIfNotZero("borderStartWidth", - computedEdgeValue(node->style.border, CSSEdgeStart, 0)); - printNumberIfNotZero("borderEndWidth", computedEdgeValue(node->style.border, CSSEdgeEnd, 0)); + computedEdgeValue(node->style.border, YGEdgeStart, 0)); + printNumberIfNotZero("borderEndWidth", computedEdgeValue(node->style.border, YGEdgeEnd, 0)); } - printNumberIfNotUndefined("width", node->style.dimensions[CSSDimensionWidth]); - printNumberIfNotUndefined("height", node->style.dimensions[CSSDimensionHeight]); - printNumberIfNotUndefined("maxWidth", node->style.maxDimensions[CSSDimensionWidth]); - printNumberIfNotUndefined("maxHeight", node->style.maxDimensions[CSSDimensionHeight]); - printNumberIfNotUndefined("minWidth", node->style.minDimensions[CSSDimensionWidth]); - printNumberIfNotUndefined("minHeight", node->style.minDimensions[CSSDimensionHeight]); + printNumberIfNotUndefined("width", node->style.dimensions[YGDimensionWidth]); + printNumberIfNotUndefined("height", node->style.dimensions[YGDimensionHeight]); + printNumberIfNotUndefined("maxWidth", node->style.maxDimensions[YGDimensionWidth]); + printNumberIfNotUndefined("maxHeight", node->style.maxDimensions[YGDimensionHeight]); + printNumberIfNotUndefined("minWidth", node->style.minDimensions[YGDimensionWidth]); + printNumberIfNotUndefined("minHeight", node->style.minDimensions[YGDimensionHeight]); - if (node->style.positionType == CSSPositionTypeAbsolute) { - CSSLog(CSSLogLevelDebug, "position: 'absolute', "); + if (node->style.positionType == YGPositionTypeAbsolute) { + CSSLog(YGLogLevelDebug, "position: 'absolute', "); } printNumberIfNotUndefined("left", - computedEdgeValue(node->style.position, CSSEdgeLeft, CSSUndefined)); + computedEdgeValue(node->style.position, YGEdgeLeft, YGUndefined)); printNumberIfNotUndefined("right", - computedEdgeValue(node->style.position, CSSEdgeRight, CSSUndefined)); + computedEdgeValue(node->style.position, YGEdgeRight, YGUndefined)); printNumberIfNotUndefined("top", - computedEdgeValue(node->style.position, CSSEdgeTop, CSSUndefined)); + computedEdgeValue(node->style.position, YGEdgeTop, YGUndefined)); printNumberIfNotUndefined("bottom", - computedEdgeValue(node->style.position, CSSEdgeBottom, CSSUndefined)); + computedEdgeValue(node->style.position, YGEdgeBottom, YGUndefined)); } const uint32_t childCount = CSSNodeListCount(node->children); - if (options & CSSPrintOptionsChildren && childCount > 0) { - CSSLog(CSSLogLevelDebug, "children: [\n"); + if (options & YGPrintOptionsChildren && childCount > 0) { + CSSLog(YGLogLevelDebug, "children: [\n"); for (uint32_t i = 0; i < childCount; i++) { _CSSNodePrint(CSSNodeGetChild(node, i), options, level + 1); } indent(level); - CSSLog(CSSLogLevelDebug, "]},\n"); + CSSLog(YGLogLevelDebug, "]},\n"); } else { - CSSLog(CSSLogLevelDebug, "},\n"); + CSSLog(YGLogLevelDebug, "},\n"); } } -void CSSNodePrint(const CSSNodeRef node, const CSSPrintOptions options) { +void CSSNodePrint(const CSSNodeRef node, const YGPrintOptions options) { _CSSNodePrint(node, options, 0); } -static const CSSEdge leading[4] = { - [CSSFlexDirectionColumn] = CSSEdgeTop, - [CSSFlexDirectionColumnReverse] = CSSEdgeBottom, - [CSSFlexDirectionRow] = CSSEdgeLeft, - [CSSFlexDirectionRowReverse] = CSSEdgeRight, +static const YGEdge leading[4] = { + [YGFlexDirectionColumn] = YGEdgeTop, + [YGFlexDirectionColumnReverse] = YGEdgeBottom, + [YGFlexDirectionRow] = YGEdgeLeft, + [YGFlexDirectionRowReverse] = YGEdgeRight, }; -static const CSSEdge trailing[4] = { - [CSSFlexDirectionColumn] = CSSEdgeBottom, - [CSSFlexDirectionColumnReverse] = CSSEdgeTop, - [CSSFlexDirectionRow] = CSSEdgeRight, - [CSSFlexDirectionRowReverse] = CSSEdgeLeft, +static const YGEdge trailing[4] = { + [YGFlexDirectionColumn] = YGEdgeBottom, + [YGFlexDirectionColumnReverse] = YGEdgeTop, + [YGFlexDirectionRow] = YGEdgeRight, + [YGFlexDirectionRowReverse] = YGEdgeLeft, }; -static const CSSEdge pos[4] = { - [CSSFlexDirectionColumn] = CSSEdgeTop, - [CSSFlexDirectionColumnReverse] = CSSEdgeBottom, - [CSSFlexDirectionRow] = CSSEdgeLeft, - [CSSFlexDirectionRowReverse] = CSSEdgeRight, +static const YGEdge pos[4] = { + [YGFlexDirectionColumn] = YGEdgeTop, + [YGFlexDirectionColumnReverse] = YGEdgeBottom, + [YGFlexDirectionRow] = YGEdgeLeft, + [YGFlexDirectionRowReverse] = YGEdgeRight, }; -static const CSSDimension dim[4] = { - [CSSFlexDirectionColumn] = CSSDimensionHeight, - [CSSFlexDirectionColumnReverse] = CSSDimensionHeight, - [CSSFlexDirectionRow] = CSSDimensionWidth, - [CSSFlexDirectionRowReverse] = CSSDimensionWidth, +static const YGDimension dim[4] = { + [YGFlexDirectionColumn] = YGDimensionHeight, + [YGFlexDirectionColumnReverse] = YGDimensionHeight, + [YGFlexDirectionRow] = YGDimensionWidth, + [YGFlexDirectionRowReverse] = YGDimensionWidth, }; -static inline bool isRowDirection(const CSSFlexDirection flexDirection) { - return flexDirection == CSSFlexDirectionRow || flexDirection == CSSFlexDirectionRowReverse; +static inline bool isRowDirection(const YGFlexDirection flexDirection) { + return flexDirection == YGFlexDirectionRow || flexDirection == YGFlexDirectionRowReverse; } -static inline bool isColumnDirection(const CSSFlexDirection flexDirection) { - return flexDirection == CSSFlexDirectionColumn || flexDirection == CSSFlexDirectionColumnReverse; +static inline bool isColumnDirection(const YGFlexDirection flexDirection) { + return flexDirection == YGFlexDirectionColumn || flexDirection == YGFlexDirectionColumnReverse; } -static inline float getLeadingMargin(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[CSSEdgeStart])) { - return node->style.margin[CSSEdgeStart]; +static inline float getLeadingMargin(const CSSNodeRef node, const YGFlexDirection axis) { + if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[YGEdgeStart])) { + return node->style.margin[YGEdgeStart]; } return computedEdgeValue(node->style.margin, leading[axis], 0); } -static float getTrailingMargin(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[CSSEdgeEnd])) { - return node->style.margin[CSSEdgeEnd]; +static float getTrailingMargin(const CSSNodeRef node, const YGFlexDirection axis) { + if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[YGEdgeEnd])) { + return node->style.margin[YGEdgeEnd]; } return computedEdgeValue(node->style.margin, trailing[axis], 0); } -static float getLeadingPadding(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[CSSEdgeStart]) && - node->style.padding[CSSEdgeStart] >= 0) { - return node->style.padding[CSSEdgeStart]; +static float getLeadingPadding(const CSSNodeRef node, const YGFlexDirection axis) { + if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[YGEdgeStart]) && + node->style.padding[YGEdgeStart] >= 0) { + return node->style.padding[YGEdgeStart]; } return fmaxf(computedEdgeValue(node->style.padding, leading[axis], 0), 0); } -static float getTrailingPadding(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[CSSEdgeEnd]) && - node->style.padding[CSSEdgeEnd] >= 0) { - return node->style.padding[CSSEdgeEnd]; +static float getTrailingPadding(const CSSNodeRef node, const YGFlexDirection axis) { + if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[YGEdgeEnd]) && + node->style.padding[YGEdgeEnd] >= 0) { + return node->style.padding[YGEdgeEnd]; } return fmaxf(computedEdgeValue(node->style.padding, trailing[axis], 0), 0); } -static float getLeadingBorder(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[CSSEdgeStart]) && - node->style.border[CSSEdgeStart] >= 0) { - return node->style.border[CSSEdgeStart]; +static float getLeadingBorder(const CSSNodeRef node, const YGFlexDirection axis) { + if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[YGEdgeStart]) && + node->style.border[YGEdgeStart] >= 0) { + return node->style.border[YGEdgeStart]; } return fmaxf(computedEdgeValue(node->style.border, leading[axis], 0), 0); } -static float getTrailingBorder(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[CSSEdgeEnd]) && - node->style.border[CSSEdgeEnd] >= 0) { - return node->style.border[CSSEdgeEnd]; +static float getTrailingBorder(const CSSNodeRef node, const YGFlexDirection axis) { + if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[YGEdgeEnd]) && + node->style.border[YGEdgeEnd] >= 0) { + return node->style.border[YGEdgeEnd]; } return fmaxf(computedEdgeValue(node->style.border, trailing[axis], 0), 0); } -static inline float getLeadingPaddingAndBorder(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline float getLeadingPaddingAndBorder(const CSSNodeRef node, const YGFlexDirection axis) { return getLeadingPadding(node, axis) + getLeadingBorder(node, axis); } -static inline float getTrailingPaddingAndBorder(const CSSNodeRef node, - const CSSFlexDirection axis) { +static inline float getTrailingPaddingAndBorder(const CSSNodeRef node, const YGFlexDirection axis) { return getTrailingPadding(node, axis) + getTrailingBorder(node, axis); } -static inline float getMarginAxis(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline float getMarginAxis(const CSSNodeRef node, const YGFlexDirection axis) { return getLeadingMargin(node, axis) + getTrailingMargin(node, axis); } -static inline float getPaddingAndBorderAxis(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline float getPaddingAndBorderAxis(const CSSNodeRef node, const YGFlexDirection axis) { return getLeadingPaddingAndBorder(node, axis) + getTrailingPaddingAndBorder(node, axis); } -static inline CSSAlign getAlignItem(const CSSNodeRef node, const CSSNodeRef child) { - return child->style.alignSelf == CSSAlignAuto ? node->style.alignItems : child->style.alignSelf; +static inline YGAlign getAlignItem(const CSSNodeRef node, const CSSNodeRef child) { + return child->style.alignSelf == YGAlignAuto ? node->style.alignItems : child->style.alignSelf; } -static inline CSSDirection resolveDirection(const CSSNodeRef node, - const CSSDirection parentDirection) { - if (node->style.direction == CSSDirectionInherit) { - return parentDirection > CSSDirectionInherit ? parentDirection : CSSDirectionLTR; +static inline YGDirection resolveDirection(const CSSNodeRef node, + const YGDirection parentDirection) { + if (node->style.direction == YGDirectionInherit) { + return parentDirection > YGDirectionInherit ? parentDirection : YGDirectionLTR; } else { return node->style.direction; } } -static inline CSSFlexDirection resolveAxis(const CSSFlexDirection flexDirection, - const CSSDirection direction) { - if (direction == CSSDirectionRTL) { - if (flexDirection == CSSFlexDirectionRow) { - return CSSFlexDirectionRowReverse; - } else if (flexDirection == CSSFlexDirectionRowReverse) { - return CSSFlexDirectionRow; +static inline YGFlexDirection resolveAxis(const YGFlexDirection flexDirection, + const YGDirection direction) { + if (direction == YGDirectionRTL) { + if (flexDirection == YGFlexDirectionRow) { + return YGFlexDirectionRowReverse; + } else if (flexDirection == YGFlexDirectionRowReverse) { + return YGFlexDirectionRow; } } return flexDirection; } -static CSSFlexDirection getCrossFlexDirection(const CSSFlexDirection flexDirection, - const CSSDirection direction) { - return isColumnDirection(flexDirection) ? resolveAxis(CSSFlexDirectionRow, direction) - : CSSFlexDirectionColumn; +static YGFlexDirection getCrossFlexDirection(const YGFlexDirection flexDirection, + const YGDirection direction) { + return isColumnDirection(flexDirection) ? resolveAxis(YGFlexDirectionRow, direction) + : YGFlexDirectionColumn; } static inline bool isFlex(const CSSNodeRef node) { - return (node->style.positionType == CSSPositionTypeRelative && + return (node->style.positionType == YGPositionTypeRelative && (node->style.flexGrow != 0 || node->style.flexShrink != 0 || node->style.flex != 0)); } -static inline float getDimWithMargin(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline float getDimWithMargin(const CSSNodeRef node, const YGFlexDirection axis) { return node->layout.measuredDimensions[dim[axis]] + getLeadingMargin(node, axis) + getTrailingMargin(node, axis); } -static inline bool isStyleDimDefined(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline bool isStyleDimDefined(const CSSNodeRef node, const YGFlexDirection axis) { const float value = node->style.dimensions[dim[axis]]; return !CSSValueIsUndefined(value) && value >= 0.0; } -static inline bool isLayoutDimDefined(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline bool isLayoutDimDefined(const CSSNodeRef node, const YGFlexDirection axis) { const float value = node->layout.measuredDimensions[dim[axis]]; return !CSSValueIsUndefined(value) && value >= 0.0; } -static inline bool isLeadingPosDefined(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline bool isLeadingPosDefined(const CSSNodeRef node, const YGFlexDirection axis) { return (isRowDirection(axis) && !CSSValueIsUndefined( - computedEdgeValue(node->style.position, CSSEdgeStart, CSSUndefined))) || - !CSSValueIsUndefined(computedEdgeValue(node->style.position, leading[axis], CSSUndefined)); + computedEdgeValue(node->style.position, YGEdgeStart, YGUndefined))) || + !CSSValueIsUndefined(computedEdgeValue(node->style.position, leading[axis], YGUndefined)); } -static inline bool isTrailingPosDefined(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline bool isTrailingPosDefined(const CSSNodeRef node, const YGFlexDirection axis) { return (isRowDirection(axis) && - !CSSValueIsUndefined( - computedEdgeValue(node->style.position, CSSEdgeEnd, CSSUndefined))) || - !CSSValueIsUndefined( - computedEdgeValue(node->style.position, trailing[axis], CSSUndefined)); + !CSSValueIsUndefined(computedEdgeValue(node->style.position, YGEdgeEnd, YGUndefined))) || + !CSSValueIsUndefined(computedEdgeValue(node->style.position, trailing[axis], YGUndefined)); } -static float getLeadingPosition(const CSSNodeRef node, const CSSFlexDirection axis) { +static float getLeadingPosition(const CSSNodeRef node, const YGFlexDirection axis) { if (isRowDirection(axis)) { - const float leadingPosition = - computedEdgeValue(node->style.position, CSSEdgeStart, CSSUndefined); + const float leadingPosition = computedEdgeValue(node->style.position, YGEdgeStart, YGUndefined); if (!CSSValueIsUndefined(leadingPosition)) { return leadingPosition; } } - const float leadingPosition = - computedEdgeValue(node->style.position, leading[axis], CSSUndefined); + const float leadingPosition = computedEdgeValue(node->style.position, leading[axis], YGUndefined); return CSSValueIsUndefined(leadingPosition) ? 0 : leadingPosition; } -static float getTrailingPosition(const CSSNodeRef node, const CSSFlexDirection axis) { +static float getTrailingPosition(const CSSNodeRef node, const YGFlexDirection axis) { if (isRowDirection(axis)) { - const float trailingPosition = - computedEdgeValue(node->style.position, CSSEdgeEnd, CSSUndefined); + const float trailingPosition = computedEdgeValue(node->style.position, YGEdgeEnd, YGUndefined); if (!CSSValueIsUndefined(trailingPosition)) { return trailingPosition; } } const float trailingPosition = - computedEdgeValue(node->style.position, trailing[axis], CSSUndefined); + computedEdgeValue(node->style.position, trailing[axis], YGUndefined); return CSSValueIsUndefined(trailingPosition) ? 0 : trailingPosition; } static float boundAxisWithinMinAndMax(const CSSNodeRef node, - const CSSFlexDirection axis, + const YGFlexDirection axis, const float value) { - float min = CSSUndefined; - float max = CSSUndefined; + float min = YGUndefined; + float max = YGUndefined; if (isColumnDirection(axis)) { - min = node->style.minDimensions[CSSDimensionHeight]; - max = node->style.maxDimensions[CSSDimensionHeight]; + min = node->style.minDimensions[YGDimensionHeight]; + max = node->style.maxDimensions[YGDimensionHeight]; } else if (isRowDirection(axis)) { - min = node->style.minDimensions[CSSDimensionWidth]; - max = node->style.maxDimensions[CSSDimensionWidth]; + min = node->style.minDimensions[YGDimensionWidth]; + max = node->style.maxDimensions[YGDimensionWidth]; } float boundValue = value; @@ -903,14 +895,14 @@ static float boundAxisWithinMinAndMax(const CSSNodeRef node, // below the // padding and border amount. static inline float boundAxis(const CSSNodeRef node, - const CSSFlexDirection axis, + const YGFlexDirection axis, const float value) { return fmaxf(boundAxisWithinMinAndMax(node, axis, value), getPaddingAndBorderAxis(node, axis)); } static void setTrailingPosition(const CSSNodeRef node, const CSSNodeRef child, - const CSSFlexDirection axis) { + const YGFlexDirection axis) { const float size = child->layout.measuredDimensions[dim[axis]]; child->layout.position[trailing[axis]] = node->layout.measuredDimensions[dim[axis]] - size - child->layout.position[pos[axis]]; @@ -918,31 +910,31 @@ static void setTrailingPosition(const CSSNodeRef node, // If both left and right are defined, then use left. Otherwise return // +left or -right depending on which is defined. -static float getRelativePosition(const CSSNodeRef node, const CSSFlexDirection axis) { +static float getRelativePosition(const CSSNodeRef node, const YGFlexDirection axis) { return isLeadingPosDefined(node, axis) ? getLeadingPosition(node, axis) : -getTrailingPosition(node, axis); } -static void constrainMaxSizeForMode(const float maxSize, CSSMeasureMode *mode, float *size) { +static void constrainMaxSizeForMode(const float maxSize, YGMeasureMode *mode, float *size) { switch (*mode) { - case CSSMeasureModeExactly: - case CSSMeasureModeAtMost: + case YGMeasureModeExactly: + case YGMeasureModeAtMost: *size = (CSSValueIsUndefined(maxSize) || *size < maxSize) ? *size : maxSize; break; - case CSSMeasureModeUndefined: + case YGMeasureModeUndefined: if (!CSSValueIsUndefined(maxSize)) { - *mode = CSSMeasureModeAtMost; + *mode = YGMeasureModeAtMost; *size = maxSize; } break; - case CSSMeasureModeCount: + case YGMeasureModeCount: break; } } -static void setPosition(const CSSNodeRef node, const CSSDirection direction) { - const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); - const CSSFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); +static void setPosition(const CSSNodeRef node, const YGDirection direction) { + const YGFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); + const YGFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); const float relativePositionMain = getRelativePosition(node, mainAxis); const float relativePositionCross = getRelativePosition(node, crossAxis); @@ -959,71 +951,71 @@ static void setPosition(const CSSNodeRef node, const CSSDirection direction) { static void computeChildFlexBasis(const CSSNodeRef node, const CSSNodeRef child, const float width, - const CSSMeasureMode widthMode, + const YGMeasureMode widthMode, const float height, - const CSSMeasureMode heightMode, - const CSSDirection direction) { - const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); + const YGMeasureMode heightMode, + const YGDirection direction) { + const YGFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); const bool isMainAxisRow = isRowDirection(mainAxis); float childWidth; float childHeight; - CSSMeasureMode childWidthMeasureMode; - CSSMeasureMode childHeightMeasureMode; + YGMeasureMode childWidthMeasureMode; + YGMeasureMode childHeightMeasureMode; - const bool isRowStyleDimDefined = isStyleDimDefined(child, CSSFlexDirectionRow); - const bool isColumnStyleDimDefined = isStyleDimDefined(child, CSSFlexDirectionColumn); + const bool isRowStyleDimDefined = isStyleDimDefined(child, YGFlexDirectionRow); + const bool isColumnStyleDimDefined = isStyleDimDefined(child, YGFlexDirectionColumn); if (!CSSValueIsUndefined(CSSNodeStyleGetFlexBasis(child)) && !CSSValueIsUndefined(isMainAxisRow ? width : height)) { if (CSSValueIsUndefined(child->layout.computedFlexBasis) || - (CSSLayoutIsExperimentalFeatureEnabled(CSSExperimentalFeatureWebFlexBasis) && + (CSSLayoutIsExperimentalFeatureEnabled(YGExperimentalFeatureWebFlexBasis) && child->layout.computedFlexBasisGeneration != gCurrentGenerationCount)) { child->layout.computedFlexBasis = fmaxf(CSSNodeStyleGetFlexBasis(child), getPaddingAndBorderAxis(child, mainAxis)); } } else if (isMainAxisRow && isRowStyleDimDefined) { // The width is definite, so use that as the flex basis. - child->layout.computedFlexBasis = fmaxf(child->style.dimensions[CSSDimensionWidth], - getPaddingAndBorderAxis(child, CSSFlexDirectionRow)); + child->layout.computedFlexBasis = fmaxf(child->style.dimensions[YGDimensionWidth], + getPaddingAndBorderAxis(child, YGFlexDirectionRow)); } else if (!isMainAxisRow && isColumnStyleDimDefined) { // The height is definite, so use that as the flex basis. - child->layout.computedFlexBasis = fmaxf(child->style.dimensions[CSSDimensionHeight], - getPaddingAndBorderAxis(child, CSSFlexDirectionColumn)); + child->layout.computedFlexBasis = fmaxf(child->style.dimensions[YGDimensionHeight], + getPaddingAndBorderAxis(child, YGFlexDirectionColumn)); } else { // Compute the flex basis and hypothetical main size (i.e. the clamped // flex basis). - childWidth = CSSUndefined; - childHeight = CSSUndefined; - childWidthMeasureMode = CSSMeasureModeUndefined; - childHeightMeasureMode = CSSMeasureModeUndefined; + childWidth = YGUndefined; + childHeight = YGUndefined; + childWidthMeasureMode = YGMeasureModeUndefined; + childHeightMeasureMode = YGMeasureModeUndefined; if (isRowStyleDimDefined) { childWidth = - child->style.dimensions[CSSDimensionWidth] + getMarginAxis(child, CSSFlexDirectionRow); - childWidthMeasureMode = CSSMeasureModeExactly; + child->style.dimensions[YGDimensionWidth] + getMarginAxis(child, YGFlexDirectionRow); + childWidthMeasureMode = YGMeasureModeExactly; } if (isColumnStyleDimDefined) { - childHeight = child->style.dimensions[CSSDimensionHeight] + - getMarginAxis(child, CSSFlexDirectionColumn); - childHeightMeasureMode = CSSMeasureModeExactly; + childHeight = + child->style.dimensions[YGDimensionHeight] + getMarginAxis(child, YGFlexDirectionColumn); + childHeightMeasureMode = YGMeasureModeExactly; } // The W3C spec doesn't say anything about the 'overflow' property, // but all major browsers appear to implement the following logic. - if ((!isMainAxisRow && node->style.overflow == CSSOverflowScroll) || - node->style.overflow != CSSOverflowScroll) { + if ((!isMainAxisRow && node->style.overflow == YGOverflowScroll) || + node->style.overflow != YGOverflowScroll) { if (CSSValueIsUndefined(childWidth) && !CSSValueIsUndefined(width)) { childWidth = width; - childWidthMeasureMode = CSSMeasureModeAtMost; + childWidthMeasureMode = YGMeasureModeAtMost; } } - if ((isMainAxisRow && node->style.overflow == CSSOverflowScroll) || - node->style.overflow != CSSOverflowScroll) { + if ((isMainAxisRow && node->style.overflow == YGOverflowScroll) || + node->style.overflow != YGOverflowScroll) { if (CSSValueIsUndefined(childHeight) && !CSSValueIsUndefined(height)) { childHeight = height; - childHeightMeasureMode = CSSMeasureModeAtMost; + childHeightMeasureMode = YGMeasureModeAtMost; } } @@ -1031,34 +1023,33 @@ static void computeChildFlexBasis(const CSSNodeRef node, // set the cross // axis to be measured exactly with the available inner width if (!isMainAxisRow && !CSSValueIsUndefined(width) && !isRowStyleDimDefined && - widthMode == CSSMeasureModeExactly && getAlignItem(node, child) == CSSAlignStretch) { + widthMode == YGMeasureModeExactly && getAlignItem(node, child) == YGAlignStretch) { childWidth = width; - childWidthMeasureMode = CSSMeasureModeExactly; + childWidthMeasureMode = YGMeasureModeExactly; } if (isMainAxisRow && !CSSValueIsUndefined(height) && !isColumnStyleDimDefined && - heightMode == CSSMeasureModeExactly && getAlignItem(node, child) == CSSAlignStretch) { + heightMode == YGMeasureModeExactly && getAlignItem(node, child) == YGAlignStretch) { childHeight = height; - childHeightMeasureMode = CSSMeasureModeExactly; + childHeightMeasureMode = YGMeasureModeExactly; } if (!CSSValueIsUndefined(child->style.aspectRatio)) { - if (!isMainAxisRow && childWidthMeasureMode == CSSMeasureModeExactly) { + if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) { child->layout.computedFlexBasis = fmaxf(childWidth * child->style.aspectRatio, - getPaddingAndBorderAxis(child, CSSFlexDirectionColumn)); + getPaddingAndBorderAxis(child, YGFlexDirectionColumn)); return; - } else if (isMainAxisRow && childHeightMeasureMode == CSSMeasureModeExactly) { - child->layout.computedFlexBasis = - fmaxf(childHeight * child->style.aspectRatio, - getPaddingAndBorderAxis(child, CSSFlexDirectionRow)); + } else if (isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) { + child->layout.computedFlexBasis = fmaxf(childHeight * child->style.aspectRatio, + getPaddingAndBorderAxis(child, YGFlexDirectionRow)); return; } } - constrainMaxSizeForMode(child->style.maxDimensions[CSSDimensionWidth], + constrainMaxSizeForMode(child->style.maxDimensions[YGDimensionWidth], &childWidthMeasureMode, &childWidth); - constrainMaxSizeForMode(child->style.maxDimensions[CSSDimensionHeight], + constrainMaxSizeForMode(child->style.maxDimensions[YGDimensionHeight], &childHeightMeasureMode, &childHeight); @@ -1073,8 +1064,8 @@ static void computeChildFlexBasis(const CSSNodeRef node, "measure"); child->layout.computedFlexBasis = - fmaxf(isMainAxisRow ? child->layout.measuredDimensions[CSSDimensionWidth] - : child->layout.measuredDimensions[CSSDimensionHeight], + fmaxf(isMainAxisRow ? child->layout.measuredDimensions[YGDimensionWidth] + : child->layout.measuredDimensions[YGDimensionHeight], getPaddingAndBorderAxis(child, mainAxis)); } @@ -1084,50 +1075,50 @@ static void computeChildFlexBasis(const CSSNodeRef node, static void absoluteLayoutChild(const CSSNodeRef node, const CSSNodeRef child, const float width, - const CSSMeasureMode widthMode, - const CSSDirection direction) { - const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); - const CSSFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); + const YGMeasureMode widthMode, + const YGDirection direction) { + const YGFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); + const YGFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); const bool isMainAxisRow = isRowDirection(mainAxis); - float childWidth = CSSUndefined; - float childHeight = CSSUndefined; - CSSMeasureMode childWidthMeasureMode = CSSMeasureModeUndefined; - CSSMeasureMode childHeightMeasureMode = CSSMeasureModeUndefined; + float childWidth = YGUndefined; + float childHeight = YGUndefined; + YGMeasureMode childWidthMeasureMode = YGMeasureModeUndefined; + YGMeasureMode childHeightMeasureMode = YGMeasureModeUndefined; - if (isStyleDimDefined(child, CSSFlexDirectionRow)) { + if (isStyleDimDefined(child, YGFlexDirectionRow)) { childWidth = - child->style.dimensions[CSSDimensionWidth] + getMarginAxis(child, CSSFlexDirectionRow); + child->style.dimensions[YGDimensionWidth] + getMarginAxis(child, YGFlexDirectionRow); } else { // If the child doesn't have a specified width, compute the width based // on the left/right // offsets if they're defined. - if (isLeadingPosDefined(child, CSSFlexDirectionRow) && - isTrailingPosDefined(child, CSSFlexDirectionRow)) { - childWidth = node->layout.measuredDimensions[CSSDimensionWidth] - - (getLeadingBorder(node, CSSFlexDirectionRow) + - getTrailingBorder(node, CSSFlexDirectionRow)) - - (getLeadingPosition(child, CSSFlexDirectionRow) + - getTrailingPosition(child, CSSFlexDirectionRow)); - childWidth = boundAxis(child, CSSFlexDirectionRow, childWidth); + if (isLeadingPosDefined(child, YGFlexDirectionRow) && + isTrailingPosDefined(child, YGFlexDirectionRow)) { + childWidth = node->layout.measuredDimensions[YGDimensionWidth] - + (getLeadingBorder(node, YGFlexDirectionRow) + + getTrailingBorder(node, YGFlexDirectionRow)) - + (getLeadingPosition(child, YGFlexDirectionRow) + + getTrailingPosition(child, YGFlexDirectionRow)); + childWidth = boundAxis(child, YGFlexDirectionRow, childWidth); } } - if (isStyleDimDefined(child, CSSFlexDirectionColumn)) { + if (isStyleDimDefined(child, YGFlexDirectionColumn)) { childHeight = - child->style.dimensions[CSSDimensionHeight] + getMarginAxis(child, CSSFlexDirectionColumn); + child->style.dimensions[YGDimensionHeight] + getMarginAxis(child, YGFlexDirectionColumn); } else { // If the child doesn't have a specified height, compute the height // based on the top/bottom // offsets if they're defined. - if (isLeadingPosDefined(child, CSSFlexDirectionColumn) && - isTrailingPosDefined(child, CSSFlexDirectionColumn)) { - childHeight = node->layout.measuredDimensions[CSSDimensionHeight] - - (getLeadingBorder(node, CSSFlexDirectionColumn) + - getTrailingBorder(node, CSSFlexDirectionColumn)) - - (getLeadingPosition(child, CSSFlexDirectionColumn) + - getTrailingPosition(child, CSSFlexDirectionColumn)); - childHeight = boundAxis(child, CSSFlexDirectionColumn, childHeight); + if (isLeadingPosDefined(child, YGFlexDirectionColumn) && + isTrailingPosDefined(child, YGFlexDirectionColumn)) { + childHeight = node->layout.measuredDimensions[YGDimensionHeight] - + (getLeadingBorder(node, YGFlexDirectionColumn) + + getTrailingBorder(node, YGFlexDirectionColumn)) - + (getLeadingPosition(child, YGFlexDirectionColumn) + + getTrailingPosition(child, YGFlexDirectionColumn)); + childHeight = boundAxis(child, YGFlexDirectionColumn, childHeight); } } @@ -1137,10 +1128,10 @@ static void absoluteLayoutChild(const CSSNodeRef node, if (!CSSValueIsUndefined(child->style.aspectRatio)) { if (CSSValueIsUndefined(childWidth)) { childWidth = fmaxf(childHeight * child->style.aspectRatio, - getPaddingAndBorderAxis(child, CSSFlexDirectionColumn)); + getPaddingAndBorderAxis(child, YGFlexDirectionColumn)); } else if (CSSValueIsUndefined(childHeight)) { childHeight = fmaxf(childWidth * child->style.aspectRatio, - getPaddingAndBorderAxis(child, CSSFlexDirectionRow)); + getPaddingAndBorderAxis(child, YGFlexDirectionRow)); } } } @@ -1148,17 +1139,17 @@ static void absoluteLayoutChild(const CSSNodeRef node, // If we're still missing one or the other dimension, measure the content. if (CSSValueIsUndefined(childWidth) || CSSValueIsUndefined(childHeight)) { childWidthMeasureMode = - CSSValueIsUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeExactly; + CSSValueIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeExactly; childHeightMeasureMode = - CSSValueIsUndefined(childHeight) ? CSSMeasureModeUndefined : CSSMeasureModeExactly; + CSSValueIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeExactly; // 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 && CSSValueIsUndefined(childWidth) && widthMode != CSSMeasureModeUndefined) { + if (!isMainAxisRow && CSSValueIsUndefined(childWidth) && widthMode != YGMeasureModeUndefined) { childWidth = width; - childWidthMeasureMode = CSSMeasureModeAtMost; + childWidthMeasureMode = YGMeasureModeAtMost; } layoutNodeInternal(child, @@ -1169,18 +1160,18 @@ static void absoluteLayoutChild(const CSSNodeRef node, childHeightMeasureMode, false, "abs-measure"); - childWidth = child->layout.measuredDimensions[CSSDimensionWidth] + - getMarginAxis(child, CSSFlexDirectionRow); - childHeight = child->layout.measuredDimensions[CSSDimensionHeight] + - getMarginAxis(child, CSSFlexDirectionColumn); + childWidth = child->layout.measuredDimensions[YGDimensionWidth] + + getMarginAxis(child, YGFlexDirectionRow); + childHeight = child->layout.measuredDimensions[YGDimensionHeight] + + getMarginAxis(child, YGFlexDirectionColumn); } layoutNodeInternal(child, childWidth, childHeight, direction, - CSSMeasureModeExactly, - CSSMeasureModeExactly, + YGMeasureModeExactly, + YGMeasureModeExactly, true, "abs-layout"); @@ -1202,47 +1193,46 @@ static void absoluteLayoutChild(const CSSNodeRef node, static void setMeasuredDimensionsForNodeWithMeasureFunc(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode) { + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode) { CSS_ASSERT(node->measure, "Expected node to have custom measure function"); - const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, CSSFlexDirectionRow); - const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSSFlexDirectionColumn); - const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); - const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); + const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, YGFlexDirectionRow); + const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, YGFlexDirectionColumn); + const float marginAxisRow = getMarginAxis(node, YGFlexDirectionRow); + const float marginAxisColumn = getMarginAxis(node, YGFlexDirectionColumn); const float innerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow; const float innerHeight = availableHeight - marginAxisColumn - paddingAndBorderAxisColumn; - if (widthMeasureMode == CSSMeasureModeExactly && heightMeasureMode == CSSMeasureModeExactly) { + if (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly) { // Don't bother sizing the text if both dimensions are already defined. - node->layout.measuredDimensions[CSSDimensionWidth] = - boundAxis(node, CSSFlexDirectionRow, availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, CSSFlexDirectionColumn, availableHeight - marginAxisColumn); + node->layout.measuredDimensions[YGDimensionWidth] = + boundAxis(node, YGFlexDirectionRow, availableWidth - marginAxisRow); + node->layout.measuredDimensions[YGDimensionHeight] = + boundAxis(node, YGFlexDirectionColumn, availableHeight - marginAxisColumn); } else if (innerWidth <= 0 || innerHeight <= 0) { // Don't bother sizing the text if there's no horizontal or vertical // space. - node->layout.measuredDimensions[CSSDimensionWidth] = boundAxis(node, CSSFlexDirectionRow, 0); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, CSSFlexDirectionColumn, 0); + node->layout.measuredDimensions[YGDimensionWidth] = boundAxis(node, YGFlexDirectionRow, 0); + node->layout.measuredDimensions[YGDimensionHeight] = boundAxis(node, YGFlexDirectionColumn, 0); } else { // Measure the text under the current constraints. const CSSSize measuredSize = node->measure(node, innerWidth, widthMeasureMode, innerHeight, heightMeasureMode); - node->layout.measuredDimensions[CSSDimensionWidth] = + node->layout.measuredDimensions[YGDimensionWidth] = boundAxis(node, - CSSFlexDirectionRow, - (widthMeasureMode == CSSMeasureModeUndefined || - widthMeasureMode == CSSMeasureModeAtMost) + YGFlexDirectionRow, + (widthMeasureMode == YGMeasureModeUndefined || + widthMeasureMode == YGMeasureModeAtMost) ? measuredSize.width + paddingAndBorderAxisRow : availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = + node->layout.measuredDimensions[YGDimensionHeight] = boundAxis(node, - CSSFlexDirectionColumn, - (heightMeasureMode == CSSMeasureModeUndefined || - heightMeasureMode == CSSMeasureModeAtMost) + YGFlexDirectionColumn, + (heightMeasureMode == YGMeasureModeUndefined || + heightMeasureMode == YGMeasureModeAtMost) ? measuredSize.height + paddingAndBorderAxisColumn : availableHeight - marginAxisColumn); } @@ -1253,25 +1243,25 @@ static void setMeasuredDimensionsForNodeWithMeasureFunc(const CSSNodeRef node, static void setMeasuredDimensionsForEmptyContainer(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode) { - const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, CSSFlexDirectionRow); - const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSSFlexDirectionColumn); - const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); - const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode) { + const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, YGFlexDirectionRow); + const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, YGFlexDirectionColumn); + const float marginAxisRow = getMarginAxis(node, YGFlexDirectionRow); + const float marginAxisColumn = getMarginAxis(node, YGFlexDirectionColumn); - node->layout.measuredDimensions[CSSDimensionWidth] = + node->layout.measuredDimensions[YGDimensionWidth] = boundAxis(node, - CSSFlexDirectionRow, - (widthMeasureMode == CSSMeasureModeUndefined || - widthMeasureMode == CSSMeasureModeAtMost) + YGFlexDirectionRow, + (widthMeasureMode == YGMeasureModeUndefined || + widthMeasureMode == YGMeasureModeAtMost) ? paddingAndBorderAxisRow : availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = + node->layout.measuredDimensions[YGDimensionHeight] = boundAxis(node, - CSSFlexDirectionColumn, - (heightMeasureMode == CSSMeasureModeUndefined || - heightMeasureMode == CSSMeasureModeAtMost) + YGFlexDirectionColumn, + (heightMeasureMode == YGMeasureModeUndefined || + heightMeasureMode == YGMeasureModeAtMost) ? paddingAndBorderAxisColumn : availableHeight - marginAxisColumn); } @@ -1279,25 +1269,25 @@ static void setMeasuredDimensionsForEmptyContainer(const CSSNodeRef node, static bool setMeasuredDimensionsIfEmptyOrFixedSize(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode) { - if ((widthMeasureMode == CSSMeasureModeAtMost && availableWidth <= 0) || - (heightMeasureMode == CSSMeasureModeAtMost && availableHeight <= 0) || - (widthMeasureMode == CSSMeasureModeExactly && heightMeasureMode == CSSMeasureModeExactly)) { - const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); - const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode) { + if ((widthMeasureMode == YGMeasureModeAtMost && availableWidth <= 0) || + (heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0) || + (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly)) { + const float marginAxisColumn = getMarginAxis(node, YGFlexDirectionColumn); + const float marginAxisRow = getMarginAxis(node, YGFlexDirectionRow); - node->layout.measuredDimensions[CSSDimensionWidth] = + node->layout.measuredDimensions[YGDimensionWidth] = boundAxis(node, - CSSFlexDirectionRow, - CSSValueIsUndefined(availableWidth) || (widthMeasureMode == CSSMeasureModeAtMost && availableWidth < 0) + YGFlexDirectionRow, + CSSValueIsUndefined(availableWidth) || (widthMeasureMode == YGMeasureModeAtMost && availableWidth < 0) ? 0 : availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = + node->layout.measuredDimensions[YGDimensionHeight] = boundAxis(node, - CSSFlexDirectionColumn, - CSSValueIsUndefined(availableHeight) || (heightMeasureMode == CSSMeasureModeAtMost && availableHeight < 0) + YGFlexDirectionColumn, + CSSValueIsUndefined(availableHeight) || (heightMeasureMode == YGMeasureModeAtMost && availableHeight < 0) ? 0 : availableHeight - marginAxisColumn); @@ -1373,7 +1363,7 @@ static bool setMeasuredDimensionsIfEmptyOrFixedSize(const CSSNodeRef node, // - node: current node to be sized and layed out // - availableWidth & availableHeight: available size to be used for sizing // the node -// or CSSUndefined if the size is not available; interpretation depends on +// or YGUndefined if the size is not available; interpretation depends on // layout // flags // - parentDirection: the inline (text) direction within the parent @@ -1410,33 +1400,33 @@ static bool setMeasuredDimensionsIfEmptyOrFixedSize(const CSSNodeRef node, // minimum main sizes (see above for details). Each of our measure modes maps // to a layout mode // from the spec (https://www.w3.org/TR/css3-sizing/#terms): -// - CSSMeasureModeUndefined: max content -// - CSSMeasureModeExactly: fill available -// - CSSMeasureModeAtMost: fit content +// - YGMeasureModeUndefined: max content +// - YGMeasureModeExactly: fill available +// - YGMeasureModeAtMost: fit content // // When calling layoutNodeImpl and layoutNodeInternal, if the caller passes // an available size of -// undefined then it must also pass a measure mode of CSSMeasureModeUndefined +// undefined then it must also pass a measure mode of YGMeasureModeUndefined // in that dimension. // static void layoutNodeImpl(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSDirection parentDirection, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode, + const YGDirection parentDirection, + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode, const bool performLayout) { - CSS_ASSERT(CSSValueIsUndefined(availableWidth) ? widthMeasureMode == CSSMeasureModeUndefined + CSS_ASSERT(CSSValueIsUndefined(availableWidth) ? widthMeasureMode == YGMeasureModeUndefined : true, "availableWidth is indefinite so widthMeasureMode must be " - "CSSMeasureModeUndefined"); - CSS_ASSERT(CSSValueIsUndefined(availableHeight) ? heightMeasureMode == CSSMeasureModeUndefined + "YGMeasureModeUndefined"); + CSS_ASSERT(CSSValueIsUndefined(availableHeight) ? heightMeasureMode == YGMeasureModeUndefined : true, "availableHeight is indefinite so heightMeasureMode must be " - "CSSMeasureModeUndefined"); + "YGMeasureModeUndefined"); // Set the resolved resolution in the node's layout. - const CSSDirection direction = resolveDirection(node, parentDirection); + const YGDirection direction = resolveDirection(node, parentDirection); node->layout.direction = direction; if (node->measure) { @@ -1461,11 +1451,11 @@ static void layoutNodeImpl(const CSSNodeRef node, } // STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM - const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); - const CSSFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); + const YGFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); + const YGFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); const bool isMainAxisRow = isRowDirection(mainAxis); - const CSSJustify justifyContent = node->style.justifyContent; - const bool isNodeFlexWrap = node->style.flexWrap == CSSWrapWrap; + const YGJustify justifyContent = node->style.justifyContent; + const bool isNodeFlexWrap = node->style.flexWrap == YGWrapWrap; CSSNodeRef firstAbsoluteChild = NULL; CSSNodeRef currentAbsoluteChild = NULL; @@ -1476,13 +1466,13 @@ static void layoutNodeImpl(const CSSNodeRef node, const float paddingAndBorderAxisMain = getPaddingAndBorderAxis(node, mainAxis); const float paddingAndBorderAxisCross = getPaddingAndBorderAxis(node, crossAxis); - const CSSMeasureMode measureModeMainDim = isMainAxisRow ? widthMeasureMode : heightMeasureMode; - const CSSMeasureMode measureModeCrossDim = isMainAxisRow ? heightMeasureMode : widthMeasureMode; + const YGMeasureMode measureModeMainDim = isMainAxisRow ? widthMeasureMode : heightMeasureMode; + const YGMeasureMode measureModeCrossDim = isMainAxisRow ? heightMeasureMode : widthMeasureMode; - const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, CSSFlexDirectionRow); - const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSSFlexDirectionColumn); - const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); - const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); + const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, YGFlexDirectionRow); + const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, YGFlexDirectionColumn); + const float marginAxisRow = getMarginAxis(node, YGFlexDirectionRow); + const float marginAxisColumn = getMarginAxis(node, YGFlexDirectionColumn); // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS const float availableInnerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow; @@ -1495,8 +1485,8 @@ static void layoutNodeImpl(const CSSNodeRef node, // computedFlexBasis to 0 instead of measuring and shrinking / flexing the child to exactly // match the remaining space CSSNodeRef singleFlexChild = NULL; - if ((isMainAxisRow && widthMeasureMode == CSSMeasureModeExactly) || - (!isMainAxisRow && heightMeasureMode == CSSMeasureModeExactly)) { + if ((isMainAxisRow && widthMeasureMode == YGMeasureModeExactly) || + (!isMainAxisRow && heightMeasureMode == YGMeasureModeExactly)) { for (uint32_t i = 0; i < childCount; i++) { const CSSNodeRef child = CSSNodeGetChild(node, i); if (singleFlexChild) { @@ -1517,13 +1507,13 @@ static void layoutNodeImpl(const CSSNodeRef node, if (performLayout) { // Set the initial position (relative to the parent). - const CSSDirection childDirection = resolveDirection(child, direction); + const YGDirection childDirection = resolveDirection(child, direction); setPosition(child, childDirection); } // Absolute-positioned children don't participate in flex layout. Add them // to a list that we can process later. - if (child->style.positionType == CSSPositionTypeAbsolute) { + if (child->style.positionType == YGPositionTypeAbsolute) { // Store a private linked list of absolutely positioned children // so that we can efficiently traverse them later. if (firstAbsoluteChild == NULL) { @@ -1590,7 +1580,7 @@ static void layoutNodeImpl(const CSSNodeRef node, const CSSNodeRef child = CSSNodeListGet(node->children, i); child->lineIndex = lineCount; - if (child->style.positionType != CSSPositionTypeAbsolute) { + if (child->style.positionType != YGPositionTypeAbsolute) { const float outerFlexBasis = child->layout.computedFlexBasis + getMarginAxis(child, mainAxis); @@ -1630,7 +1620,7 @@ static void layoutNodeImpl(const CSSNodeRef node, // If we don't need to measure the cross axis, we can skip the entire flex // step. - const bool canSkipFlex = !performLayout && measureModeCrossDim == CSSMeasureModeExactly; + const bool canSkipFlex = !performLayout && measureModeCrossDim == YGMeasureModeExactly; // In order to position the elements in the main axis, we have two // controls. The space between the beginning and the first element @@ -1785,73 +1775,73 @@ static void layoutNodeImpl(const CSSNodeRef node, float childWidth; float childHeight; - CSSMeasureMode childWidthMeasureMode; - CSSMeasureMode childHeightMeasureMode; + YGMeasureMode childWidthMeasureMode; + YGMeasureMode childHeightMeasureMode; if (isMainAxisRow) { - childWidth = updatedMainSize + getMarginAxis(currentRelativeChild, CSSFlexDirectionRow); - childWidthMeasureMode = CSSMeasureModeExactly; + childWidth = updatedMainSize + getMarginAxis(currentRelativeChild, YGFlexDirectionRow); + childWidthMeasureMode = YGMeasureModeExactly; if (!CSSValueIsUndefined(availableInnerCrossDim) && - !isStyleDimDefined(currentRelativeChild, CSSFlexDirectionColumn) && - heightMeasureMode == CSSMeasureModeExactly && - getAlignItem(node, currentRelativeChild) == CSSAlignStretch) { + !isStyleDimDefined(currentRelativeChild, YGFlexDirectionColumn) && + heightMeasureMode == YGMeasureModeExactly && + getAlignItem(node, currentRelativeChild) == YGAlignStretch) { childHeight = availableInnerCrossDim; - childHeightMeasureMode = CSSMeasureModeExactly; - } else if (!isStyleDimDefined(currentRelativeChild, CSSFlexDirectionColumn)) { + childHeightMeasureMode = YGMeasureModeExactly; + } else if (!isStyleDimDefined(currentRelativeChild, YGFlexDirectionColumn)) { childHeight = availableInnerCrossDim; childHeightMeasureMode = - CSSValueIsUndefined(childHeight) ? CSSMeasureModeUndefined : CSSMeasureModeAtMost; + CSSValueIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeAtMost; } else { - childHeight = currentRelativeChild->style.dimensions[CSSDimensionHeight] + - getMarginAxis(currentRelativeChild, CSSFlexDirectionColumn); - childHeightMeasureMode = CSSMeasureModeExactly; + childHeight = currentRelativeChild->style.dimensions[YGDimensionHeight] + + getMarginAxis(currentRelativeChild, YGFlexDirectionColumn); + childHeightMeasureMode = YGMeasureModeExactly; } } else { childHeight = - updatedMainSize + getMarginAxis(currentRelativeChild, CSSFlexDirectionColumn); - childHeightMeasureMode = CSSMeasureModeExactly; + updatedMainSize + getMarginAxis(currentRelativeChild, YGFlexDirectionColumn); + childHeightMeasureMode = YGMeasureModeExactly; if (!CSSValueIsUndefined(availableInnerCrossDim) && - !isStyleDimDefined(currentRelativeChild, CSSFlexDirectionRow) && - widthMeasureMode == CSSMeasureModeExactly && - getAlignItem(node, currentRelativeChild) == CSSAlignStretch) { + !isStyleDimDefined(currentRelativeChild, YGFlexDirectionRow) && + widthMeasureMode == YGMeasureModeExactly && + getAlignItem(node, currentRelativeChild) == YGAlignStretch) { childWidth = availableInnerCrossDim; - childWidthMeasureMode = CSSMeasureModeExactly; - } else if (!isStyleDimDefined(currentRelativeChild, CSSFlexDirectionRow)) { + childWidthMeasureMode = YGMeasureModeExactly; + } else if (!isStyleDimDefined(currentRelativeChild, YGFlexDirectionRow)) { childWidth = availableInnerCrossDim; childWidthMeasureMode = - CSSValueIsUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeAtMost; + CSSValueIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeAtMost; } else { - childWidth = currentRelativeChild->style.dimensions[CSSDimensionWidth] + - getMarginAxis(currentRelativeChild, CSSFlexDirectionRow); - childWidthMeasureMode = CSSMeasureModeExactly; + childWidth = currentRelativeChild->style.dimensions[YGDimensionWidth] + + getMarginAxis(currentRelativeChild, YGFlexDirectionRow); + childWidthMeasureMode = YGMeasureModeExactly; } } if (!CSSValueIsUndefined(currentRelativeChild->style.aspectRatio)) { - if (isMainAxisRow && childHeightMeasureMode != CSSMeasureModeExactly) { + if (isMainAxisRow && childHeightMeasureMode != YGMeasureModeExactly) { childHeight = fmaxf(childWidth * currentRelativeChild->style.aspectRatio, - getPaddingAndBorderAxis(currentRelativeChild, CSSFlexDirectionColumn)); - childHeightMeasureMode = CSSMeasureModeExactly; - } else if (!isMainAxisRow && childWidthMeasureMode != CSSMeasureModeExactly) { + getPaddingAndBorderAxis(currentRelativeChild, YGFlexDirectionColumn)); + childHeightMeasureMode = YGMeasureModeExactly; + } else if (!isMainAxisRow && childWidthMeasureMode != YGMeasureModeExactly) { childWidth = fmaxf(childHeight * currentRelativeChild->style.aspectRatio, - getPaddingAndBorderAxis(currentRelativeChild, CSSFlexDirectionRow)); - childWidthMeasureMode = CSSMeasureModeExactly; + getPaddingAndBorderAxis(currentRelativeChild, YGFlexDirectionRow)); + childWidthMeasureMode = YGMeasureModeExactly; } } - constrainMaxSizeForMode(currentRelativeChild->style.maxDimensions[CSSDimensionWidth], + constrainMaxSizeForMode(currentRelativeChild->style.maxDimensions[YGDimensionWidth], &childWidthMeasureMode, &childWidth); - constrainMaxSizeForMode(currentRelativeChild->style.maxDimensions[CSSDimensionHeight], + constrainMaxSizeForMode(currentRelativeChild->style.maxDimensions[YGDimensionHeight], &childHeightMeasureMode, &childHeight); const bool requiresStretchLayout = !isStyleDimDefined(currentRelativeChild, crossAxis) && - getAlignItem(node, currentRelativeChild) == CSSAlignStretch; + getAlignItem(node, currentRelativeChild) == YGAlignStretch; // Recursively call the layout algorithm for this child with the updated // main size. @@ -1882,7 +1872,7 @@ static void layoutNodeImpl(const CSSNodeRef node, // If we are using "at most" rules in the main axis. Calculate the remaining space when // constraint by the min size defined for the main axis. - if (measureModeMainDim == CSSMeasureModeAtMost && remainingFreeSpace > 0) { + if (measureModeMainDim == YGMeasureModeAtMost && remainingFreeSpace > 0) { if (!CSSValueIsUndefined(node->style.minDimensions[dim[mainAxis]]) && node->style.minDimensions[dim[mainAxis]] >= 0) { remainingFreeSpace = fmaxf(0, @@ -1894,26 +1884,26 @@ static void layoutNodeImpl(const CSSNodeRef node, } switch (justifyContent) { - case CSSJustifyCenter: + case YGJustifyCenter: leadingMainDim = remainingFreeSpace / 2; break; - case CSSJustifyFlexEnd: + case YGJustifyFlexEnd: leadingMainDim = remainingFreeSpace; break; - case CSSJustifySpaceBetween: + case YGJustifySpaceBetween: if (itemsOnLine > 1) { betweenMainDim = fmaxf(remainingFreeSpace, 0) / (itemsOnLine - 1); } else { betweenMainDim = 0; } break; - case CSSJustifySpaceAround: + case YGJustifySpaceAround: // Space on the edges is half of the space between elements betweenMainDim = remainingFreeSpace / itemsOnLine; leadingMainDim = betweenMainDim / 2; break; - case CSSJustifyFlexStart: - case CSSJustifyCount: + case YGJustifyFlexStart: + case YGJustifyCount: break; } @@ -1923,7 +1913,7 @@ static void layoutNodeImpl(const CSSNodeRef node, for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) { const CSSNodeRef child = CSSNodeListGet(node->children, i); - if (child->style.positionType == CSSPositionTypeAbsolute && + if (child->style.positionType == YGPositionTypeAbsolute && isLeadingPosDefined(child, mainAxis)) { if (performLayout) { // In case the child is position absolute and has left/top being @@ -1937,7 +1927,7 @@ static void layoutNodeImpl(const CSSNodeRef node, // Now that we placed the element, we need to update the variables. // We need to do that only for relative elements. Absolute elements // do not take part in that phase. - if (child->style.positionType == CSSPositionTypeRelative) { + if (child->style.positionType == YGPositionTypeRelative) { if (performLayout) { child->layout.position[pos[mainAxis]] += mainDim; } @@ -1969,19 +1959,19 @@ static void layoutNodeImpl(const CSSNodeRef node, mainDim += trailingPaddingAndBorderMain; float containerCrossAxis = availableInnerCrossDim; - if (measureModeCrossDim == CSSMeasureModeUndefined || - measureModeCrossDim == CSSMeasureModeAtMost) { + if (measureModeCrossDim == YGMeasureModeUndefined || + measureModeCrossDim == YGMeasureModeAtMost) { // Compute the cross axis from the max cross dimension of the children. containerCrossAxis = boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross) - paddingAndBorderAxisCross; - if (measureModeCrossDim == CSSMeasureModeAtMost) { + if (measureModeCrossDim == YGMeasureModeAtMost) { containerCrossAxis = fminf(containerCrossAxis, availableInnerCrossDim); } } // If there's no flex wrap, the cross dimension is defined by the container. - if (!isNodeFlexWrap && measureModeCrossDim == CSSMeasureModeExactly) { + if (!isNodeFlexWrap && measureModeCrossDim == YGMeasureModeExactly) { crossDim = availableInnerCrossDim; } @@ -1995,7 +1985,7 @@ static void layoutNodeImpl(const CSSNodeRef node, for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) { const CSSNodeRef child = CSSNodeListGet(node->children, i); - if (child->style.positionType == CSSPositionTypeAbsolute) { + if (child->style.positionType == YGPositionTypeAbsolute) { // If the child is absolutely positioned and has a // top/left/bottom/right // set, override all the previously computed positions to set it @@ -2014,36 +2004,36 @@ static void layoutNodeImpl(const CSSNodeRef node, // For a relative children, we're either using alignItems (parent) or // alignSelf (child) in order to determine the position in the cross // axis - const CSSAlign alignItem = getAlignItem(node, child); + const YGAlign alignItem = getAlignItem(node, child); // If the child uses align stretch, we need to lay it out one more // time, this time // forcing the cross-axis size to be the computed cross size for the // current line. - if (alignItem == CSSAlignStretch) { + if (alignItem == YGAlignStretch) { const bool isCrossSizeDefinite = - (isMainAxisRow && isStyleDimDefined(child, CSSFlexDirectionColumn)) || - (!isMainAxisRow && isStyleDimDefined(child, CSSFlexDirectionRow)); + (isMainAxisRow && isStyleDimDefined(child, YGFlexDirectionColumn)) || + (!isMainAxisRow && isStyleDimDefined(child, YGFlexDirectionRow)); float childWidth; float childHeight; - CSSMeasureMode childWidthMeasureMode = CSSMeasureModeExactly; - CSSMeasureMode childHeightMeasureMode = CSSMeasureModeExactly; + YGMeasureMode childWidthMeasureMode = YGMeasureModeExactly; + YGMeasureMode childHeightMeasureMode = YGMeasureModeExactly; if (isMainAxisRow) { childHeight = crossDim; - childWidth = child->layout.measuredDimensions[CSSDimensionWidth] + - getMarginAxis(child, CSSFlexDirectionRow); + childWidth = child->layout.measuredDimensions[YGDimensionWidth] + + getMarginAxis(child, YGFlexDirectionRow); } else { childWidth = crossDim; - childHeight = child->layout.measuredDimensions[CSSDimensionHeight] + - getMarginAxis(child, CSSFlexDirectionColumn); + childHeight = child->layout.measuredDimensions[YGDimensionHeight] + + getMarginAxis(child, YGFlexDirectionColumn); } - constrainMaxSizeForMode(child->style.maxDimensions[CSSDimensionWidth], + constrainMaxSizeForMode(child->style.maxDimensions[YGDimensionWidth], &childWidthMeasureMode, &childWidth); - constrainMaxSizeForMode(child->style.maxDimensions[CSSDimensionHeight], + constrainMaxSizeForMode(child->style.maxDimensions[YGDimensionHeight], &childHeightMeasureMode, &childHeight); @@ -2051,9 +2041,9 @@ static void layoutNodeImpl(const CSSNodeRef node, // no need to stretch. if (!isCrossSizeDefinite) { childWidthMeasureMode = - CSSValueIsUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeExactly; - childHeightMeasureMode = CSSValueIsUndefined(childHeight) ? CSSMeasureModeUndefined - : CSSMeasureModeExactly; + CSSValueIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeExactly; + childHeightMeasureMode = + CSSValueIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeExactly; layoutNodeInternal(child, childWidth, @@ -2064,12 +2054,12 @@ static void layoutNodeImpl(const CSSNodeRef node, true, "stretch"); } - } else if (alignItem != CSSAlignFlexStart) { + } else if (alignItem != YGAlignFlexStart) { const float remainingCrossDim = containerCrossAxis - getDimWithMargin(child, crossAxis); - if (alignItem == CSSAlignCenter) { + if (alignItem == YGAlignCenter) { leadingCrossDim += remainingCrossDim / 2; - } else { // CSSAlignFlexEnd + } else { // YGAlignFlexEnd leadingCrossDim += remainingCrossDim; } } @@ -2092,20 +2082,20 @@ static void layoutNodeImpl(const CSSNodeRef node, float currentLead = leadingPaddingAndBorderCross; switch (node->style.alignContent) { - case CSSAlignFlexEnd: + case YGAlignFlexEnd: currentLead += remainingAlignContentDim; break; - case CSSAlignCenter: + case YGAlignCenter: currentLead += remainingAlignContentDim / 2; break; - case CSSAlignStretch: + case YGAlignStretch: if (availableInnerCrossDim > totalLineCrossDim) { crossDimLead = (remainingAlignContentDim / lineCount); } break; - case CSSAlignAuto: - case CSSAlignFlexStart: - case CSSAlignCount: + case YGAlignAuto: + case YGAlignFlexStart: + case YGAlignCount: break; } @@ -2119,7 +2109,7 @@ static void layoutNodeImpl(const CSSNodeRef node, for (ii = startIndex; ii < childCount; ii++) { const CSSNodeRef child = CSSNodeListGet(node->children, ii); - if (child->style.positionType == CSSPositionTypeRelative) { + if (child->style.positionType == YGPositionTypeRelative) { if (child->lineIndex != i) { break; } @@ -2138,34 +2128,34 @@ static void layoutNodeImpl(const CSSNodeRef node, for (ii = startIndex; ii < endIndex; ii++) { const CSSNodeRef child = CSSNodeListGet(node->children, ii); - if (child->style.positionType == CSSPositionTypeRelative) { + if (child->style.positionType == YGPositionTypeRelative) { switch (getAlignItem(node, child)) { - case CSSAlignFlexStart: { + case YGAlignFlexStart: { child->layout.position[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis); break; } - case CSSAlignFlexEnd: { + case YGAlignFlexEnd: { child->layout.position[pos[crossAxis]] = currentLead + lineHeight - getTrailingMargin(child, crossAxis) - child->layout.measuredDimensions[dim[crossAxis]]; break; } - case CSSAlignCenter: { + case YGAlignCenter: { float childHeight = child->layout.measuredDimensions[dim[crossAxis]]; child->layout.position[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2; break; } - case CSSAlignStretch: { + case YGAlignStretch: { child->layout.position[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis); // TODO(prenaux): Correctly set the height of items with indefinite // (auto) crossAxis dimension. break; } - case CSSAlignAuto: - case CSSAlignCount: + case YGAlignAuto: + case YGAlignCount: break; } } @@ -2177,30 +2167,30 @@ static void layoutNodeImpl(const CSSNodeRef node, } // STEP 9: COMPUTING FINAL DIMENSIONS - node->layout.measuredDimensions[CSSDimensionWidth] = - boundAxis(node, CSSFlexDirectionRow, availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, CSSFlexDirectionColumn, availableHeight - marginAxisColumn); + node->layout.measuredDimensions[YGDimensionWidth] = + boundAxis(node, YGFlexDirectionRow, availableWidth - marginAxisRow); + node->layout.measuredDimensions[YGDimensionHeight] = + boundAxis(node, YGFlexDirectionColumn, availableHeight - marginAxisColumn); // If the user didn't specify a width or height for the node, set the // dimensions based on the children. - if (measureModeMainDim == CSSMeasureModeUndefined) { + if (measureModeMainDim == YGMeasureModeUndefined) { // Clamp the size to the min/max size, if specified, and make sure it // doesn't go below the padding and border amount. node->layout.measuredDimensions[dim[mainAxis]] = boundAxis(node, mainAxis, maxLineMainDim); - } else if (measureModeMainDim == CSSMeasureModeAtMost) { + } else if (measureModeMainDim == YGMeasureModeAtMost) { node->layout.measuredDimensions[dim[mainAxis]] = fmaxf(fminf(availableInnerMainDim + paddingAndBorderAxisMain, boundAxisWithinMinAndMax(node, mainAxis, maxLineMainDim)), paddingAndBorderAxisMain); } - if (measureModeCrossDim == CSSMeasureModeUndefined) { + if (measureModeCrossDim == YGMeasureModeUndefined) { // Clamp the size to the min/max size, if specified, and make sure it // doesn't go below the padding and border amount. node->layout.measuredDimensions[dim[crossAxis]] = boundAxis(node, crossAxis, totalLineCrossDim + paddingAndBorderAxisCross); - } else if (measureModeCrossDim == CSSMeasureModeAtMost) { + } else if (measureModeCrossDim == YGMeasureModeAtMost) { node->layout.measuredDimensions[dim[crossAxis]] = fmaxf(fminf(availableInnerCrossDim + paddingAndBorderAxisCross, boundAxisWithinMinAndMax(node, @@ -2219,9 +2209,9 @@ static void layoutNodeImpl(const CSSNodeRef node, // STEP 11: SETTING TRAILING POSITIONS FOR CHILDREN const bool needsMainTrailingPos = - mainAxis == CSSFlexDirectionRowReverse || mainAxis == CSSFlexDirectionColumnReverse; + mainAxis == YGFlexDirectionRowReverse || mainAxis == YGFlexDirectionColumnReverse; const bool needsCrossTrailingPos = - CSSFlexDirectionRowReverse || crossAxis == CSSFlexDirectionColumnReverse; + YGFlexDirectionRowReverse || crossAxis == YGFlexDirectionColumnReverse; // Set trailing position if necessary. if (needsMainTrailingPos || needsCrossTrailingPos) { @@ -2256,50 +2246,50 @@ static const char *getSpacer(const unsigned long level) { } } -static const char *getModeName(const CSSMeasureMode mode, const bool performLayout) { - const char *kMeasureModeNames[CSSMeasureModeCount] = {"UNDEFINED", "EXACTLY", "AT_MOST"}; - const char *kLayoutModeNames[CSSMeasureModeCount] = {"LAY_UNDEFINED", - "LAY_EXACTLY", - "LAY_AT_" - "MOST"}; +static const char *getModeName(const YGMeasureMode mode, const bool performLayout) { + const char *kMeasureModeNames[YGMeasureModeCount] = {"UNDEFINED", "EXACTLY", "AT_MOST"}; + const char *kLayoutModeNames[YGMeasureModeCount] = {"LAY_UNDEFINED", + "LAY_EXACTLY", + "LAY_AT_" + "MOST"}; - if (mode >= CSSMeasureModeCount) { + if (mode >= YGMeasureModeCount) { return ""; } return performLayout ? kLayoutModeNames[mode] : kMeasureModeNames[mode]; } -static inline bool newSizeIsExactAndMatchesOldMeasuredSize(CSSMeasureMode sizeMode, +static inline bool newSizeIsExactAndMatchesOldMeasuredSize(YGMeasureMode sizeMode, float size, float lastComputedSize) { - return sizeMode == CSSMeasureModeExactly && eq(size, lastComputedSize); + return sizeMode == YGMeasureModeExactly && eq(size, lastComputedSize); } -static inline bool oldSizeIsUnspecifiedAndStillFits(CSSMeasureMode sizeMode, +static inline bool oldSizeIsUnspecifiedAndStillFits(YGMeasureMode sizeMode, float size, - CSSMeasureMode lastSizeMode, + YGMeasureMode lastSizeMode, float lastComputedSize) { - return sizeMode == CSSMeasureModeAtMost && lastSizeMode == CSSMeasureModeUndefined && + return sizeMode == YGMeasureModeAtMost && lastSizeMode == YGMeasureModeUndefined && size >= lastComputedSize; } -static inline bool newMeasureSizeIsStricterAndStillValid(CSSMeasureMode sizeMode, +static inline bool newMeasureSizeIsStricterAndStillValid(YGMeasureMode sizeMode, float size, - CSSMeasureMode lastSizeMode, + YGMeasureMode lastSizeMode, float lastSize, float lastComputedSize) { - return lastSizeMode == CSSMeasureModeAtMost && sizeMode == CSSMeasureModeAtMost && + return lastSizeMode == YGMeasureModeAtMost && sizeMode == YGMeasureModeAtMost && lastSize > size && lastComputedSize <= size; } -bool CSSNodeCanUseCachedMeasurement(const CSSMeasureMode widthMode, +bool CSSNodeCanUseCachedMeasurement(const YGMeasureMode widthMode, const float width, - const CSSMeasureMode heightMode, + const YGMeasureMode heightMode, const float height, - const CSSMeasureMode lastWidthMode, + const YGMeasureMode lastWidthMode, const float lastWidth, - const CSSMeasureMode lastHeightMode, + const YGMeasureMode lastHeightMode, const float lastHeight, const float lastComputedWidth, const float lastComputedHeight, @@ -2347,9 +2337,9 @@ bool CSSNodeCanUseCachedMeasurement(const CSSMeasureMode widthMode, bool layoutNodeInternal(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSDirection parentDirection, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode, + const YGDirection parentDirection, + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode, const bool performLayout, const char *reason) { CSSLayout *layout = &node->layout; @@ -2363,8 +2353,8 @@ bool layoutNodeInternal(const CSSNodeRef node, if (needToVisitNode) { // Invalidate the cached results. layout->nextCachedMeasurementsIndex = 0; - layout->cachedLayout.widthMeasureMode = (CSSMeasureMode) -1; - layout->cachedLayout.heightMeasureMode = (CSSMeasureMode) -1; + layout->cachedLayout.widthMeasureMode = (YGMeasureMode) -1; + layout->cachedLayout.heightMeasureMode = (YGMeasureMode) -1; layout->cachedLayout.computedWidth = -1; layout->cachedLayout.computedHeight = -1; } @@ -2384,8 +2374,8 @@ bool layoutNodeInternal(const CSSNodeRef node, // expensive to measure, so it's worth avoiding redundant measurements if at // all possible. if (node->measure) { - const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); - const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); + const float marginAxisRow = getMarginAxis(node, YGFlexDirectionRow); + const float marginAxisColumn = getMarginAxis(node, YGFlexDirectionColumn); // First, try to use the layout cache. if (CSSNodeCanUseCachedMeasurement(widthMeasureMode, @@ -2441,8 +2431,8 @@ bool layoutNodeInternal(const CSSNodeRef node, } if (!needToVisitNode && cachedResults != NULL) { - layout->measuredDimensions[CSSDimensionWidth] = cachedResults->computedWidth; - layout->measuredDimensions[CSSDimensionHeight] = cachedResults->computedHeight; + layout->measuredDimensions[YGDimensionWidth] = cachedResults->computedWidth; + layout->measuredDimensions[YGDimensionHeight] = cachedResults->computedHeight; if (gPrintChanges && gPrintSkips) { printf("%s%d.{[skipped] ", getSpacer(gDepth), gDepth); @@ -2488,8 +2478,8 @@ bool layoutNodeInternal(const CSSNodeRef node, printf("wm: %s, hm: %s, d: (%f, %f) %s\n", getModeName(widthMeasureMode, performLayout), getModeName(heightMeasureMode, performLayout), - layout->measuredDimensions[CSSDimensionWidth], - layout->measuredDimensions[CSSDimensionHeight], + layout->measuredDimensions[YGDimensionWidth], + layout->measuredDimensions[YGDimensionHeight], reason); } @@ -2517,15 +2507,14 @@ bool layoutNodeInternal(const CSSNodeRef node, newCacheEntry->availableHeight = availableHeight; newCacheEntry->widthMeasureMode = widthMeasureMode; newCacheEntry->heightMeasureMode = heightMeasureMode; - newCacheEntry->computedWidth = layout->measuredDimensions[CSSDimensionWidth]; - newCacheEntry->computedHeight = layout->measuredDimensions[CSSDimensionHeight]; + newCacheEntry->computedWidth = layout->measuredDimensions[YGDimensionWidth]; + newCacheEntry->computedHeight = layout->measuredDimensions[YGDimensionHeight]; } } if (performLayout) { - node->layout.dimensions[CSSDimensionWidth] = node->layout.measuredDimensions[CSSDimensionWidth]; - node->layout.dimensions[CSSDimensionHeight] = - node->layout.measuredDimensions[CSSDimensionHeight]; + node->layout.dimensions[YGDimensionWidth] = node->layout.measuredDimensions[YGDimensionWidth]; + node->layout.dimensions[YGDimensionHeight] = node->layout.measuredDimensions[YGDimensionHeight]; node->hasNewLayout = true; node->isDirty = false; } @@ -2537,16 +2526,16 @@ bool layoutNodeInternal(const CSSNodeRef node, static void roundToPixelGrid(const CSSNodeRef node) { const float fractialLeft = - node->layout.position[CSSEdgeLeft] - floorf(node->layout.position[CSSEdgeLeft]); + node->layout.position[YGEdgeLeft] - floorf(node->layout.position[YGEdgeLeft]); const float fractialTop = - node->layout.position[CSSEdgeTop] - floorf(node->layout.position[CSSEdgeTop]); - node->layout.dimensions[CSSDimensionWidth] = - roundf(fractialLeft + node->layout.dimensions[CSSDimensionWidth]) - roundf(fractialLeft); - node->layout.dimensions[CSSDimensionHeight] = - roundf(fractialTop + node->layout.dimensions[CSSDimensionHeight]) - roundf(fractialTop); + node->layout.position[YGEdgeTop] - floorf(node->layout.position[YGEdgeTop]); + node->layout.dimensions[YGDimensionWidth] = + roundf(fractialLeft + node->layout.dimensions[YGDimensionWidth]) - roundf(fractialLeft); + node->layout.dimensions[YGDimensionHeight] = + roundf(fractialTop + node->layout.dimensions[YGDimensionHeight]) - roundf(fractialTop); - node->layout.position[CSSEdgeLeft] = roundf(node->layout.position[CSSEdgeLeft]); - node->layout.position[CSSEdgeTop] = roundf(node->layout.position[CSSEdgeTop]); + node->layout.position[YGEdgeLeft] = roundf(node->layout.position[YGEdgeLeft]); + node->layout.position[YGEdgeTop] = roundf(node->layout.position[YGEdgeTop]); const uint32_t childCount = CSSNodeListCount(node->children); for (uint32_t i = 0; i < childCount; i++) { @@ -2557,7 +2546,7 @@ static void roundToPixelGrid(const CSSNodeRef node) { void CSSNodeCalculateLayout(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSDirection parentDirection) { + const YGDirection parentDirection) { // Increment the generation count. This will force the recursive routine to // visit // all dirty nodes at least once. Subsequent visits will be skipped if the @@ -2567,29 +2556,29 @@ void CSSNodeCalculateLayout(const CSSNodeRef node, float width = availableWidth; float height = availableHeight; - CSSMeasureMode widthMeasureMode = CSSMeasureModeUndefined; - CSSMeasureMode heightMeasureMode = CSSMeasureModeUndefined; + YGMeasureMode widthMeasureMode = YGMeasureModeUndefined; + YGMeasureMode heightMeasureMode = YGMeasureModeUndefined; if (!CSSValueIsUndefined(width)) { - widthMeasureMode = CSSMeasureModeExactly; - } else if (isStyleDimDefined(node, CSSFlexDirectionRow)) { + widthMeasureMode = YGMeasureModeExactly; + } else if (isStyleDimDefined(node, YGFlexDirectionRow)) { width = - node->style.dimensions[dim[CSSFlexDirectionRow]] + getMarginAxis(node, CSSFlexDirectionRow); - widthMeasureMode = CSSMeasureModeExactly; - } else if (node->style.maxDimensions[CSSDimensionWidth] >= 0.0) { - width = node->style.maxDimensions[CSSDimensionWidth]; - widthMeasureMode = CSSMeasureModeAtMost; + node->style.dimensions[dim[YGFlexDirectionRow]] + getMarginAxis(node, YGFlexDirectionRow); + widthMeasureMode = YGMeasureModeExactly; + } else if (node->style.maxDimensions[YGDimensionWidth] >= 0.0) { + width = node->style.maxDimensions[YGDimensionWidth]; + widthMeasureMode = YGMeasureModeAtMost; } if (!CSSValueIsUndefined(height)) { - heightMeasureMode = CSSMeasureModeExactly; - } else if (isStyleDimDefined(node, CSSFlexDirectionColumn)) { - height = node->style.dimensions[dim[CSSFlexDirectionColumn]] + - getMarginAxis(node, CSSFlexDirectionColumn); - heightMeasureMode = CSSMeasureModeExactly; - } else if (node->style.maxDimensions[CSSDimensionHeight] >= 0.0) { - height = node->style.maxDimensions[CSSDimensionHeight]; - heightMeasureMode = CSSMeasureModeAtMost; + heightMeasureMode = YGMeasureModeExactly; + } else if (isStyleDimDefined(node, YGFlexDirectionColumn)) { + height = node->style.dimensions[dim[YGFlexDirectionColumn]] + + getMarginAxis(node, YGFlexDirectionColumn); + heightMeasureMode = YGMeasureModeExactly; + } else if (node->style.maxDimensions[YGDimensionHeight] >= 0.0) { + height = node->style.maxDimensions[YGDimensionHeight]; + heightMeasureMode = YGMeasureModeAtMost; } if (layoutNodeInternal(node, @@ -2603,12 +2592,12 @@ void CSSNodeCalculateLayout(const CSSNodeRef node, "l")) { setPosition(node, node->layout.direction); - if (CSSLayoutIsExperimentalFeatureEnabled(CSSExperimentalFeatureRounding)) { + if (CSSLayoutIsExperimentalFeatureEnabled(YGExperimentalFeatureRounding)) { roundToPixelGrid(node); } if (gPrintTree) { - CSSNodePrint(node, CSSPrintOptionsLayout | CSSPrintOptionsChildren | CSSPrintOptionsStyle); + CSSNodePrint(node, YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle); } } } @@ -2617,20 +2606,20 @@ void CSSLayoutSetLogger(CSSLogger logger) { gLogger = logger; } -void CSSLog(CSSLogLevel level, const char *format, ...) { +void CSSLog(YGLogLevel level, const char *format, ...) { va_list args; va_start(args, format); gLogger(level, format, args); va_end(args); } -static bool experimentalFeatures[CSSExperimentalFeatureCount + 1]; +static bool experimentalFeatures[YGExperimentalFeatureCount + 1]; -void CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeature feature, bool enabled) { +void CSSLayoutSetExperimentalFeatureEnabled(YGExperimentalFeature feature, bool enabled) { experimentalFeatures[feature] = enabled; } -inline bool CSSLayoutIsExperimentalFeatureEnabled(CSSExperimentalFeature feature) { +inline bool CSSLayoutIsExperimentalFeatureEnabled(YGExperimentalFeature feature) { return experimentalFeatures[feature]; } diff --git a/React/CSSLayout/CSSLayout.h b/React/CSSLayout/CSSLayout.h new file mode 100644 index 00000000000..62f5b16cc8c --- /dev/null +++ b/React/CSSLayout/CSSLayout.h @@ -0,0 +1,183 @@ +/** + * 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 +#include +#include +#include +#include +#include + +#ifndef __cplusplus +#include +#endif + +// Not defined in MSVC++ +#ifndef NAN +static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff}; +#define NAN (*(const float *) __nan) +#endif + +#define YGUndefined 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, + YGMeasureMode widthMode, + float height, + YGMeasureMode heightMode); +typedef void (*CSSPrintFunc)(CSSNodeRef node); +typedef int (*CSSLogger)(YGLogLevel 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 YGDirection 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 YGPrintOptions options); + +WIN_EXPORT bool CSSValueIsUndefined(const float value); + +WIN_EXPORT bool CSSNodeCanUseCachedMeasurement(const YGMeasureMode widthMode, + const float width, + const YGMeasureMode heightMode, + const float height, + const YGMeasureMode lastWidthMode, + const float lastWidth, + const YGMeasureMode 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 YGEdge edge, \ + const type paramName); \ + WIN_EXPORT type CSSNodeStyleGet##name(const CSSNodeRef node, const YGEdge 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(YGDirection, Direction, direction); +CSS_NODE_STYLE_PROPERTY(YGFlexDirection, FlexDirection, flexDirection); +CSS_NODE_STYLE_PROPERTY(YGJustify, JustifyContent, justifyContent); +CSS_NODE_STYLE_PROPERTY(YGAlign, AlignContent, alignContent); +CSS_NODE_STYLE_PROPERTY(YGAlign, AlignItems, alignItems); +CSS_NODE_STYLE_PROPERTY(YGAlign, AlignSelf, alignSelf); +CSS_NODE_STYLE_PROPERTY(YGPositionType, PositionType, positionType); +CSS_NODE_STYLE_PROPERTY(YGWrap, FlexWrap, flexWrap); +CSS_NODE_STYLE_PROPERTY(YGOverflow, 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); + +// Yoga specific properties, not compatible with flexbox specification +// Aspect ratio control the size of the undefined dimension of a node. +// - On a node with a set width/height aspect ratio control the size of the unset dimension +// - On a node with a set flex basis aspect ratio controls the size of the node in the cross axis if +// unset +// - On a node with a measure function aspect ratio works as though the measure function measures +// the flex basis +// - On a node with flex grow/shrink aspect ratio controls the size of the node in the cross axis if +// unset +// - Aspect ratio takes min/max dimensions into account +CSS_NODE_STYLE_PROPERTY(float, AspectRatio, aspectRatio); + +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(YGDirection, Direction); + +WIN_EXPORT void CSSLayoutSetLogger(CSSLogger logger); +WIN_EXPORT void CSSLog(YGLogLevel level, const char *message, ...); + +WIN_EXPORT void CSSLayoutSetExperimentalFeatureEnabled(YGExperimentalFeature feature, bool enabled); +WIN_EXPORT bool CSSLayoutIsExperimentalFeatureEnabled(YGExperimentalFeature feature); + +WIN_EXPORT void CSSLayoutSetMemoryFuncs(CSSMalloc cssMalloc, + CSSCalloc cssCalloc, + CSSRealloc cssRealloc, + CSSFree cssFree); + +CSS_EXTERN_C_END diff --git a/React/CSSLayout/CSSMacros.h b/React/CSSLayout/CSSMacros.h new file mode 100644 index 00000000000..f54a5b87d49 --- /dev/null +++ b/React/CSSLayout/CSSMacros.h @@ -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(YGLogLevelError, "%s", message); \ + CSS_ABORT(); \ + } +#endif diff --git a/React/Views/RCTRootShadowView.m b/React/Views/RCTRootShadowView.m index c3efd53d35e..ed427707a9c 100644 --- a/React/Views/RCTRootShadowView.m +++ b/React/Views/RCTRootShadowView.m @@ -21,7 +21,7 @@ self = [super init]; if (self) { if ([[RCTI18nUtil sharedInstance] isRTL]) { - CSSNodeStyleSetDirection(self.cssNode, CSSDirectionRTL); + CSSNodeStyleSetDirection(self.cssNode, YGDirectionRTL); } } return self; @@ -33,14 +33,14 @@ case RCTRootViewSizeFlexibilityNone: break; case RCTRootViewSizeFlexibilityWidth: - CSSNodeStyleSetWidth(self.cssNode, CSSUndefined); + CSSNodeStyleSetWidth(self.cssNode, YGUndefined); break; case RCTRootViewSizeFlexibilityHeight: - CSSNodeStyleSetHeight(self.cssNode, CSSUndefined); + CSSNodeStyleSetHeight(self.cssNode, YGUndefined); break; case RCTRootViewSizeFlexibilityWidthAndHeight: - CSSNodeStyleSetWidth(self.cssNode, CSSUndefined); - CSSNodeStyleSetHeight(self.cssNode, CSSUndefined); + CSSNodeStyleSetWidth(self.cssNode, YGUndefined); + CSSNodeStyleSetHeight(self.cssNode, YGUndefined); break; } } @@ -49,7 +49,7 @@ { [self applySizeConstraints]; - CSSNodeCalculateLayout(self.cssNode, CSSUndefined, CSSUndefined, CSSDirectionInherit); + CSSNodeCalculateLayout(self.cssNode, YGUndefined, YGUndefined, YGDirectionInherit); NSMutableSet *viewsWithNewFrame = [NSMutableSet set]; [self applyLayoutNode:self.cssNode viewsWithNewFrame:viewsWithNewFrame absolutePosition:CGPointZero]; diff --git a/React/Views/RCTScrollViewManager.m b/React/Views/RCTScrollViewManager.m index 181f7c7df64..91f5634f01c 100644 --- a/React/Views/RCTScrollViewManager.m +++ b/React/Views/RCTScrollViewManager.m @@ -87,8 +87,8 @@ RCT_EXPORT_VIEW_PROPERTY(onScrollAnimationEnd, RCTDirectEventBlock) // is set to from js we want to clip drawing or not. This piece of code ensures // that css-layout is always treating the contents of a scroll container as // overflow: 'scroll'. -RCT_CUSTOM_SHADOW_PROPERTY(overflow, CSSOverflow, RCTShadowView) { - view.overflow = CSSOverflowScroll; +RCT_CUSTOM_SHADOW_PROPERTY(overflow, YGOverflow, RCTShadowView) { + view.overflow = YGOverflowScroll; } RCT_EXPORT_METHOD(getContentSize:(nonnull NSNumber *)reactTag diff --git a/React/Views/RCTShadowView.h b/React/Views/RCTShadowView.h index 74ec6b44512..dd44ef0bda6 100644 --- a/React/Views/RCTShadowView.h +++ b/React/Views/RCTShadowView.h @@ -126,12 +126,12 @@ typedef void (^RCTApplierBlock)(NSDictionary *viewRegistry /** * Flexbox properties. All zero/disabled by default */ -@property (nonatomic, assign) CSSFlexDirection flexDirection; -@property (nonatomic, assign) CSSJustify justifyContent; -@property (nonatomic, assign) CSSAlign alignSelf; -@property (nonatomic, assign) CSSAlign alignItems; -@property (nonatomic, assign) CSSPositionType position; -@property (nonatomic, assign) CSSWrap flexWrap; +@property (nonatomic, assign) YGFlexDirection flexDirection; +@property (nonatomic, assign) YGJustify justifyContent; +@property (nonatomic, assign) YGAlign alignSelf; +@property (nonatomic, assign) YGAlign alignItems; +@property (nonatomic, assign) YGPositionType position; +@property (nonatomic, assign) YGWrap flexWrap; @property (nonatomic, assign) float flexGrow; @property (nonatomic, assign) float flexShrink; @@ -149,7 +149,7 @@ typedef void (^RCTApplierBlock)(NSDictionary *viewRegistry /** * Clipping properties */ -@property (nonatomic, assign) CSSOverflow overflow; +@property (nonatomic, assign) YGOverflow overflow; /** * Calculate property changes that need to be propagated to the view. diff --git a/React/Views/RCTShadowView.m b/React/Views/RCTShadowView.m index 07ac414f390..d1651657f78 100644 --- a/React/Views/RCTShadowView.m +++ b/React/Views/RCTShadowView.m @@ -60,43 +60,43 @@ static void RCTPrint(CSSNodeRef node) #define DEFINE_PROCESS_META_PROPS(type) \ static void RCTProcessMetaProps##type(const float metaProps[META_PROP_COUNT], CSSNodeRef node) { \ if (!CSSValueIsUndefined(metaProps[META_PROP_LEFT])) { \ - CSSNodeStyleSet##type(node, CSSEdgeStart, metaProps[META_PROP_LEFT]); \ + CSSNodeStyleSet##type(node, YGEdgeStart, metaProps[META_PROP_LEFT]); \ } else if (!CSSValueIsUndefined(metaProps[META_PROP_HORIZONTAL])) { \ - CSSNodeStyleSet##type(node, CSSEdgeStart, metaProps[META_PROP_HORIZONTAL]); \ + CSSNodeStyleSet##type(node, YGEdgeStart, metaProps[META_PROP_HORIZONTAL]); \ } else if (!CSSValueIsUndefined(metaProps[META_PROP_ALL])) { \ - CSSNodeStyleSet##type(node, CSSEdgeStart, metaProps[META_PROP_ALL]); \ + CSSNodeStyleSet##type(node, YGEdgeStart, metaProps[META_PROP_ALL]); \ } else { \ - CSSNodeStyleSet##type(node, CSSEdgeStart, 0); \ + CSSNodeStyleSet##type(node, YGEdgeStart, 0); \ } \ \ if (!CSSValueIsUndefined(metaProps[META_PROP_RIGHT])) { \ - CSSNodeStyleSet##type(node, CSSEdgeEnd, metaProps[META_PROP_RIGHT]); \ + CSSNodeStyleSet##type(node, YGEdgeEnd, metaProps[META_PROP_RIGHT]); \ } else if (!CSSValueIsUndefined(metaProps[META_PROP_HORIZONTAL])) { \ - CSSNodeStyleSet##type(node, CSSEdgeEnd, metaProps[META_PROP_HORIZONTAL]); \ + CSSNodeStyleSet##type(node, YGEdgeEnd, metaProps[META_PROP_HORIZONTAL]); \ } else if (!CSSValueIsUndefined(metaProps[META_PROP_ALL])) { \ - CSSNodeStyleSet##type(node, CSSEdgeEnd, metaProps[META_PROP_ALL]); \ + CSSNodeStyleSet##type(node, YGEdgeEnd, metaProps[META_PROP_ALL]); \ } else { \ - CSSNodeStyleSet##type(node, CSSEdgeEnd, 0); \ + CSSNodeStyleSet##type(node, YGEdgeEnd, 0); \ } \ \ if (!CSSValueIsUndefined(metaProps[META_PROP_TOP])) { \ - CSSNodeStyleSet##type(node, CSSEdgeTop, metaProps[META_PROP_TOP]); \ + CSSNodeStyleSet##type(node, YGEdgeTop, metaProps[META_PROP_TOP]); \ } else if (!CSSValueIsUndefined(metaProps[META_PROP_VERTICAL])) { \ - CSSNodeStyleSet##type(node, CSSEdgeTop, metaProps[META_PROP_VERTICAL]); \ + CSSNodeStyleSet##type(node, YGEdgeTop, metaProps[META_PROP_VERTICAL]); \ } else if (!CSSValueIsUndefined(metaProps[META_PROP_ALL])) { \ - CSSNodeStyleSet##type(node, CSSEdgeTop, metaProps[META_PROP_ALL]); \ + CSSNodeStyleSet##type(node, YGEdgeTop, metaProps[META_PROP_ALL]); \ } else { \ - CSSNodeStyleSet##type(node, CSSEdgeTop, 0); \ + CSSNodeStyleSet##type(node, YGEdgeTop, 0); \ } \ \ if (!CSSValueIsUndefined(metaProps[META_PROP_BOTTOM])) { \ - CSSNodeStyleSet##type(node, CSSEdgeBottom, metaProps[META_PROP_BOTTOM]); \ + CSSNodeStyleSet##type(node, YGEdgeBottom, metaProps[META_PROP_BOTTOM]); \ } else if (!CSSValueIsUndefined(metaProps[META_PROP_VERTICAL])) { \ - CSSNodeStyleSet##type(node, CSSEdgeBottom, metaProps[META_PROP_VERTICAL]); \ + CSSNodeStyleSet##type(node, YGEdgeBottom, metaProps[META_PROP_VERTICAL]); \ } else if (!CSSValueIsUndefined(metaProps[META_PROP_ALL])) { \ - CSSNodeStyleSet##type(node, CSSEdgeBottom, metaProps[META_PROP_ALL]); \ + CSSNodeStyleSet##type(node, YGEdgeBottom, metaProps[META_PROP_ALL]); \ } else { \ - CSSNodeStyleSet##type(node, CSSEdgeBottom, 0); \ + CSSNodeStyleSet##type(node, YGEdgeBottom, 0); \ } \ } @@ -261,14 +261,14 @@ DEFINE_PROCESS_META_PROPS(Border); } if (!CGRectEqualToRect(frame, _frame)) { - CSSNodeStyleSetPositionType(_cssNode, CSSPositionTypeAbsolute); + CSSNodeStyleSetPositionType(_cssNode, YGPositionTypeAbsolute); CSSNodeStyleSetWidth(_cssNode, frame.size.width); CSSNodeStyleSetHeight(_cssNode, frame.size.height); - CSSNodeStyleSetPosition(_cssNode, CSSEdgeLeft, frame.origin.x); - CSSNodeStyleSetPosition(_cssNode, CSSEdgeTop, frame.origin.y); + CSSNodeStyleSetPosition(_cssNode, YGEdgeLeft, frame.origin.x); + CSSNodeStyleSetPosition(_cssNode, YGEdgeTop, frame.origin.y); } - CSSNodeCalculateLayout(_cssNode, frame.size.width, frame.size.height, CSSDirectionInherit); + CSSNodeCalculateLayout(_cssNode, frame.size.width, frame.size.height, YGDirectionInherit); [self applyLayoutNode:_cssNode viewsWithNewFrame:viewsWithNewFrame absolutePosition:absolutePosition]; } @@ -304,12 +304,12 @@ DEFINE_PROCESS_META_PROPS(Border); { if ((self = [super init])) { - _frame = CGRectMake(0, 0, CSSUndefined, CSSUndefined); + _frame = CGRectMake(0, 0, YGUndefined, YGUndefined); for (unsigned int ii = 0; ii < META_PROP_COUNT; ii++) { - _paddingMetaProps[ii] = CSSUndefined; - _marginMetaProps[ii] = CSSUndefined; - _borderMetaProps[ii] = CSSUndefined; + _paddingMetaProps[ii] = YGUndefined; + _marginMetaProps[ii] = YGUndefined; + _borderMetaProps[ii] = YGUndefined; } _newView = YES; @@ -491,27 +491,27 @@ RCT_PADDING_PROPERTY(Right, RIGHT) - (UIEdgeInsets)paddingAsInsets { - if (CSSNodeLayoutGetDirection(_cssNode) == CSSDirectionRTL) { + if (CSSNodeLayoutGetDirection(_cssNode) == YGDirectionRTL) { return (UIEdgeInsets){ - CSSNodeStyleGetPadding(_cssNode, CSSEdgeTop), - !CSSValueIsUndefined(CSSNodeStyleGetPadding(_cssNode, CSSEdgeEnd)) ? - CSSNodeStyleGetPadding(_cssNode, CSSEdgeEnd) : - CSSNodeStyleGetPadding(_cssNode, CSSEdgeLeft), - CSSNodeStyleGetPadding(_cssNode, CSSEdgeBottom), - !CSSValueIsUndefined(CSSNodeStyleGetPadding(_cssNode, CSSEdgeStart)) ? - CSSNodeStyleGetPadding(_cssNode, CSSEdgeStart) : - CSSNodeStyleGetPadding(_cssNode, CSSEdgeRight) + CSSNodeStyleGetPadding(_cssNode, YGEdgeTop), + !CSSValueIsUndefined(CSSNodeStyleGetPadding(_cssNode, YGEdgeEnd)) ? + CSSNodeStyleGetPadding(_cssNode, YGEdgeEnd) : + CSSNodeStyleGetPadding(_cssNode, YGEdgeLeft), + CSSNodeStyleGetPadding(_cssNode, YGEdgeBottom), + !CSSValueIsUndefined(CSSNodeStyleGetPadding(_cssNode, YGEdgeStart)) ? + CSSNodeStyleGetPadding(_cssNode, YGEdgeStart) : + CSSNodeStyleGetPadding(_cssNode, YGEdgeRight) }; } else { return (UIEdgeInsets){ - CSSNodeStyleGetPadding(_cssNode, CSSEdgeTop), - !CSSValueIsUndefined(CSSNodeStyleGetPadding(_cssNode, CSSEdgeStart)) ? - CSSNodeStyleGetPadding(_cssNode, CSSEdgeStart) : - CSSNodeStyleGetPadding(_cssNode, CSSEdgeLeft), - CSSNodeStyleGetPadding(_cssNode, CSSEdgeBottom), - !CSSValueIsUndefined(CSSNodeStyleGetPadding(_cssNode, CSSEdgeEnd)) ? - CSSNodeStyleGetPadding(_cssNode, CSSEdgeEnd) : - CSSNodeStyleGetPadding(_cssNode, CSSEdgeRight) + CSSNodeStyleGetPadding(_cssNode, YGEdgeTop), + !CSSValueIsUndefined(CSSNodeStyleGetPadding(_cssNode, YGEdgeStart)) ? + CSSNodeStyleGetPadding(_cssNode, YGEdgeStart) : + CSSNodeStyleGetPadding(_cssNode, YGEdgeLeft), + CSSNodeStyleGetPadding(_cssNode, YGEdgeBottom), + !CSSValueIsUndefined(CSSNodeStyleGetPadding(_cssNode, YGEdgeEnd)) ? + CSSNodeStyleGetPadding(_cssNode, YGEdgeEnd) : + CSSNodeStyleGetPadding(_cssNode, YGEdgeRight) }; } } @@ -569,37 +569,37 @@ RCT_DIMENSION_PROPERTY(MaxHeight, maxHeight, MaxHeight) return CSSNodeStyleGetPosition(_cssNode, edge); \ } -RCT_POSITION_PROPERTY(Top, top, CSSEdgeTop) -RCT_POSITION_PROPERTY(Right, right, CSSEdgeEnd) -RCT_POSITION_PROPERTY(Bottom, bottom, CSSEdgeBottom) -RCT_POSITION_PROPERTY(Left, left, CSSEdgeStart) +RCT_POSITION_PROPERTY(Top, top, YGEdgeTop) +RCT_POSITION_PROPERTY(Right, right, YGEdgeEnd) +RCT_POSITION_PROPERTY(Bottom, bottom, YGEdgeBottom) +RCT_POSITION_PROPERTY(Left, left, YGEdgeStart) - (void)setFrame:(CGRect)frame { if (!CGRectEqualToRect(frame, _frame)) { _frame = frame; - CSSNodeStyleSetPosition(_cssNode, CSSEdgeLeft, CGRectGetMinX(frame)); - CSSNodeStyleSetPosition(_cssNode, CSSEdgeTop, CGRectGetMinY(frame)); + CSSNodeStyleSetPosition(_cssNode, YGEdgeLeft, CGRectGetMinX(frame)); + CSSNodeStyleSetPosition(_cssNode, YGEdgeTop, CGRectGetMinY(frame)); CSSNodeStyleSetWidth(_cssNode, CGRectGetWidth(frame)); CSSNodeStyleSetHeight(_cssNode, CGRectGetHeight(frame)); } } -static inline void RCTAssignSuggestedDimension(CSSNodeRef cssNode, CSSDimension dimension, CGFloat amount) +static inline void RCTAssignSuggestedDimension(CSSNodeRef cssNode, YGDimension dimension, CGFloat amount) { if (amount != UIViewNoIntrinsicMetric) { switch (dimension) { - case CSSDimensionWidth: + case YGDimensionWidth: if (isnan(CSSNodeStyleGetWidth(cssNode))) { CSSNodeStyleSetWidth(cssNode, amount); } break; - case CSSDimensionHeight: + case YGDimensionHeight: if (isnan(CSSNodeStyleGetHeight(cssNode))) { CSSNodeStyleSetHeight(cssNode, amount); } break; - case CSSDimensionCount: + case YGDimensionCount: break; } } @@ -608,15 +608,15 @@ static inline void RCTAssignSuggestedDimension(CSSNodeRef cssNode, CSSDimension - (void)setIntrinsicContentSize:(CGSize)size { if (CSSNodeStyleGetFlexGrow(_cssNode) == 0 && CSSNodeStyleGetFlexShrink(_cssNode) == 0) { - RCTAssignSuggestedDimension(_cssNode, CSSDimensionHeight, size.height); - RCTAssignSuggestedDimension(_cssNode, CSSDimensionWidth, size.width); + RCTAssignSuggestedDimension(_cssNode, YGDimensionHeight, size.height); + RCTAssignSuggestedDimension(_cssNode, YGDimensionWidth, size.width); } } - (void)setTopLeft:(CGPoint)topLeft { - CSSNodeStyleSetPosition(_cssNode, CSSEdgeLeft, topLeft.x); - CSSNodeStyleSetPosition(_cssNode, CSSEdgeTop, topLeft.y); + CSSNodeStyleSetPosition(_cssNode, YGEdgeLeft, topLeft.x); + CSSNodeStyleSetPosition(_cssNode, YGEdgeTop, topLeft.y); } - (void)setSize:(CGSize)size @@ -645,13 +645,13 @@ static inline void RCTAssignSuggestedDimension(CSSNodeRef cssNode, CSSDimension RCT_STYLE_PROPERTY(FlexGrow, flexGrow, FlexGrow, float) RCT_STYLE_PROPERTY(FlexShrink, flexShrink, FlexShrink, float) RCT_STYLE_PROPERTY(FlexBasis, flexBasis, FlexBasis, float) -RCT_STYLE_PROPERTY(FlexDirection, flexDirection, FlexDirection, CSSFlexDirection) -RCT_STYLE_PROPERTY(JustifyContent, justifyContent, JustifyContent, CSSJustify) -RCT_STYLE_PROPERTY(AlignSelf, alignSelf, AlignSelf, CSSAlign) -RCT_STYLE_PROPERTY(AlignItems, alignItems, AlignItems, CSSAlign) -RCT_STYLE_PROPERTY(Position, position, PositionType, CSSPositionType) -RCT_STYLE_PROPERTY(FlexWrap, flexWrap, FlexWrap, CSSWrap) -RCT_STYLE_PROPERTY(Overflow, overflow, Overflow, CSSOverflow) +RCT_STYLE_PROPERTY(FlexDirection, flexDirection, FlexDirection, YGFlexDirection) +RCT_STYLE_PROPERTY(JustifyContent, justifyContent, JustifyContent, YGJustify) +RCT_STYLE_PROPERTY(AlignSelf, alignSelf, AlignSelf, YGAlign) +RCT_STYLE_PROPERTY(AlignItems, alignItems, AlignItems, YGAlign) +RCT_STYLE_PROPERTY(Position, position, PositionType, YGPositionType) +RCT_STYLE_PROPERTY(FlexWrap, flexWrap, FlexWrap, YGWrap) +RCT_STYLE_PROPERTY(Overflow, overflow, Overflow, YGOverflow) RCT_STYLE_PROPERTY(AspectRatio, aspectRatio, AspectRatio, float) - (void)setBackgroundColor:(UIColor *)color diff --git a/React/Views/RCTViewManager.m b/React/Views/RCTViewManager.m index 8f20a6380a4..7cde34d3e26 100644 --- a/React/Views/RCTViewManager.m +++ b/React/Views/RCTViewManager.m @@ -109,10 +109,10 @@ RCT_REMAP_VIEW_PROPERTY(shadowColor, layer.shadowColor, CGColor) RCT_REMAP_VIEW_PROPERTY(shadowOffset, layer.shadowOffset, CGSize) RCT_REMAP_VIEW_PROPERTY(shadowOpacity, layer.shadowOpacity, float) RCT_REMAP_VIEW_PROPERTY(shadowRadius, layer.shadowRadius, CGFloat) -RCT_CUSTOM_VIEW_PROPERTY(overflow, CSSOverflow, RCTView) +RCT_CUSTOM_VIEW_PROPERTY(overflow, YGOverflow, RCTView) { if (json) { - view.clipsToBounds = [RCTConvert CSSOverflow:json] != CSSOverflowVisible; + view.clipsToBounds = [RCTConvert YGOverflow:json] != YGOverflowVisible; } else { view.clipsToBounds = defaultView.clipsToBounds; } @@ -288,15 +288,15 @@ RCT_EXPORT_SHADOW_PROPERTY(flex, float) RCT_EXPORT_SHADOW_PROPERTY(flexGrow, float) RCT_EXPORT_SHADOW_PROPERTY(flexShrink, float) RCT_EXPORT_SHADOW_PROPERTY(flexBasis, float) -RCT_EXPORT_SHADOW_PROPERTY(flexDirection, CSSFlexDirection) -RCT_EXPORT_SHADOW_PROPERTY(flexWrap, CSSWrap) -RCT_EXPORT_SHADOW_PROPERTY(justifyContent, CSSJustify) -RCT_EXPORT_SHADOW_PROPERTY(alignItems, CSSAlign) -RCT_EXPORT_SHADOW_PROPERTY(alignSelf, CSSAlign) -RCT_EXPORT_SHADOW_PROPERTY(position, CSSPositionType) +RCT_EXPORT_SHADOW_PROPERTY(flexDirection, YGFlexDirection) +RCT_EXPORT_SHADOW_PROPERTY(flexWrap, YGWrap) +RCT_EXPORT_SHADOW_PROPERTY(justifyContent, YGJustify) +RCT_EXPORT_SHADOW_PROPERTY(alignItems, YGAlign) +RCT_EXPORT_SHADOW_PROPERTY(alignSelf, YGAlign) +RCT_EXPORT_SHADOW_PROPERTY(position, YGPositionType) RCT_EXPORT_SHADOW_PROPERTY(aspectRatio, float) -RCT_EXPORT_SHADOW_PROPERTY(overflow, CSSOverflow) +RCT_EXPORT_SHADOW_PROPERTY(overflow, YGOverflow) RCT_EXPORT_SHADOW_PROPERTY(onLayout, RCTDirectEventBlock) diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSLogger.java b/ReactAndroid/src/main/java/com/facebook/csslayout/CSSLogger.java index d270e39fca3..c751768f3ab 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSLogger.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/CSSLogger.java @@ -13,10 +13,10 @@ import com.facebook.proguard.annotations.DoNotStrip; /** * Inteface for recieving logs from native layer. Use by setting CSSNode.setLogger(myLogger); - * See CSSLogLevel for the different log levels. + * See YogaLogLevel for the different log levels. */ @DoNotStrip public interface CSSLogger { @DoNotStrip - void log(CSSLogLevel level, String message); + void log(YogaLogLevel level, String message); } diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNode.java b/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNode.java index 47939fe6749..1fc2af87131 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNode.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNode.java @@ -39,13 +39,13 @@ public class CSSNode implements CSSNodeAPI { int feature, boolean enabled); public static void setExperimentalFeatureEnabled( - CSSExperimentalFeature feature, + YogaExperimentalFeature feature, boolean enabled) { jni_CSSLayoutSetExperimentalFeatureEnabled(feature.intValue(), enabled); } private static native boolean jni_CSSLayoutIsExperimentalFeatureEnabled(int feature); - public static boolean isExperimentalFeatureEnabled(CSSExperimentalFeature feature) { + public static boolean isExperimentalFeatureEnabled(YogaExperimentalFeature feature) { return jni_CSSLayoutIsExperimentalFeatureEnabled(feature.intValue()); } @@ -61,13 +61,13 @@ public class CSSNode implements CSSNodeAPI { private boolean mHasSetPosition = false; @DoNotStrip - private float mWidth = CSSConstants.UNDEFINED; + private float mWidth = YogaConstants.UNDEFINED; @DoNotStrip - private float mHeight = CSSConstants.UNDEFINED; + private float mHeight = YogaConstants.UNDEFINED; @DoNotStrip - private float mTop = CSSConstants.UNDEFINED; + private float mTop = YogaConstants.UNDEFINED; @DoNotStrip - private float mLeft = CSSConstants.UNDEFINED; + private float mLeft = YogaConstants.UNDEFINED; @DoNotStrip private int mLayoutDirection = 0; @@ -97,10 +97,10 @@ public class CSSNode implements CSSNodeAPI { mHasSetBorder = false; mHasSetPosition = false; - mWidth = CSSConstants.UNDEFINED; - mHeight = CSSConstants.UNDEFINED; - mTop = CSSConstants.UNDEFINED; - mLeft = CSSConstants.UNDEFINED; + mWidth = YogaConstants.UNDEFINED; + mHeight = YogaConstants.UNDEFINED; + mTop = YogaConstants.UNDEFINED; + mLeft = YogaConstants.UNDEFINED; mLayoutDirection = 0; mMeasureFunction = null; @@ -193,103 +193,103 @@ public class CSSNode implements CSSNodeAPI { private native int jni_CSSNodeStyleGetDirection(long nativePointer); @Override - public CSSDirection getStyleDirection() { - return CSSDirection.values()[jni_CSSNodeStyleGetDirection(mNativePointer)]; + public YogaDirection getStyleDirection() { + return YogaDirection.values()[jni_CSSNodeStyleGetDirection(mNativePointer)]; } private native void jni_CSSNodeStyleSetDirection(long nativePointer, int direction); @Override - public void setDirection(CSSDirection direction) { + public void setDirection(YogaDirection direction) { jni_CSSNodeStyleSetDirection(mNativePointer, direction.intValue()); } private native int jni_CSSNodeStyleGetFlexDirection(long nativePointer); @Override - public CSSFlexDirection getFlexDirection() { - return CSSFlexDirection.values()[jni_CSSNodeStyleGetFlexDirection(mNativePointer)]; + public YogaFlexDirection getFlexDirection() { + return YogaFlexDirection.values()[jni_CSSNodeStyleGetFlexDirection(mNativePointer)]; } private native void jni_CSSNodeStyleSetFlexDirection(long nativePointer, int flexDirection); @Override - public void setFlexDirection(CSSFlexDirection flexDirection) { + public void setFlexDirection(YogaFlexDirection flexDirection) { jni_CSSNodeStyleSetFlexDirection(mNativePointer, flexDirection.intValue()); } private native int jni_CSSNodeStyleGetJustifyContent(long nativePointer); @Override - public CSSJustify getJustifyContent() { - return CSSJustify.values()[jni_CSSNodeStyleGetJustifyContent(mNativePointer)]; + public YogaJustify getJustifyContent() { + return YogaJustify.values()[jni_CSSNodeStyleGetJustifyContent(mNativePointer)]; } private native void jni_CSSNodeStyleSetJustifyContent(long nativePointer, int justifyContent); @Override - public void setJustifyContent(CSSJustify justifyContent) { + public void setJustifyContent(YogaJustify justifyContent) { jni_CSSNodeStyleSetJustifyContent(mNativePointer, justifyContent.intValue()); } private native int jni_CSSNodeStyleGetAlignItems(long nativePointer); @Override - public CSSAlign getAlignItems() { - return CSSAlign.values()[jni_CSSNodeStyleGetAlignItems(mNativePointer)]; + public YogaAlign getAlignItems() { + return YogaAlign.values()[jni_CSSNodeStyleGetAlignItems(mNativePointer)]; } private native void jni_CSSNodeStyleSetAlignItems(long nativePointer, int alignItems); @Override - public void setAlignItems(CSSAlign alignItems) { + public void setAlignItems(YogaAlign alignItems) { jni_CSSNodeStyleSetAlignItems(mNativePointer, alignItems.intValue()); } private native int jni_CSSNodeStyleGetAlignSelf(long nativePointer); @Override - public CSSAlign getAlignSelf() { - return CSSAlign.values()[jni_CSSNodeStyleGetAlignSelf(mNativePointer)]; + public YogaAlign getAlignSelf() { + return YogaAlign.values()[jni_CSSNodeStyleGetAlignSelf(mNativePointer)]; } private native void jni_CSSNodeStyleSetAlignSelf(long nativePointer, int alignSelf); @Override - public void setAlignSelf(CSSAlign alignSelf) { + public void setAlignSelf(YogaAlign alignSelf) { jni_CSSNodeStyleSetAlignSelf(mNativePointer, alignSelf.intValue()); } private native int jni_CSSNodeStyleGetAlignContent(long nativePointer); @Override - public CSSAlign getAlignContent() { - return CSSAlign.values()[jni_CSSNodeStyleGetAlignContent(mNativePointer)]; + public YogaAlign getAlignContent() { + return YogaAlign.values()[jni_CSSNodeStyleGetAlignContent(mNativePointer)]; } private native void jni_CSSNodeStyleSetAlignContent(long nativePointer, int alignContent); @Override - public void setAlignContent(CSSAlign alignContent) { + public void setAlignContent(YogaAlign alignContent) { jni_CSSNodeStyleSetAlignContent(mNativePointer, alignContent.intValue()); } private native int jni_CSSNodeStyleGetPositionType(long nativePointer); @Override - public CSSPositionType getPositionType() { - return CSSPositionType.values()[jni_CSSNodeStyleGetPositionType(mNativePointer)]; + public YogaPositionType getPositionType() { + return YogaPositionType.values()[jni_CSSNodeStyleGetPositionType(mNativePointer)]; } private native void jni_CSSNodeStyleSetPositionType(long nativePointer, int positionType); @Override - public void setPositionType(CSSPositionType positionType) { + public void setPositionType(YogaPositionType positionType) { jni_CSSNodeStyleSetPositionType(mNativePointer, positionType.intValue()); } private native void jni_CSSNodeStyleSetFlexWrap(long nativePointer, int wrapType); @Override - public void setWrap(CSSWrap flexWrap) { + public void setWrap(YogaWrap flexWrap) { jni_CSSNodeStyleSetFlexWrap(mNativePointer, flexWrap.intValue()); } private native int jni_CSSNodeStyleGetOverflow(long nativePointer); @Override - public CSSOverflow getOverflow() { - return CSSOverflow.values()[jni_CSSNodeStyleGetOverflow(mNativePointer)]; + public YogaOverflow getOverflow() { + return YogaOverflow.values()[jni_CSSNodeStyleGetOverflow(mNativePointer)]; } private native void jni_CSSNodeStyleSetOverflow(long nativePointer, int overflow); @Override - public void setOverflow(CSSOverflow overflow) { + public void setOverflow(YogaOverflow overflow) { jni_CSSNodeStyleSetOverflow(mNativePointer, overflow.intValue()); } @@ -337,64 +337,64 @@ public class CSSNode implements CSSNodeAPI { private native float jni_CSSNodeStyleGetMargin(long nativePointer, int edge); @Override - public float getMargin(CSSEdge edge) { + public float getMargin(YogaEdge edge) { if (!mHasSetMargin) { - return edge.intValue() < CSSEdge.START.intValue() ? 0 : CSSConstants.UNDEFINED; + return edge.intValue() < YogaEdge.START.intValue() ? 0 : YogaConstants.UNDEFINED; } return jni_CSSNodeStyleGetMargin(mNativePointer, edge.intValue()); } private native void jni_CSSNodeStyleSetMargin(long nativePointer, int edge, float margin); @Override - public void setMargin(CSSEdge edge, float margin) { + public void setMargin(YogaEdge edge, float margin) { mHasSetMargin = true; jni_CSSNodeStyleSetMargin(mNativePointer, edge.intValue(), margin); } private native float jni_CSSNodeStyleGetPadding(long nativePointer, int edge); @Override - public float getPadding(CSSEdge edge) { + public float getPadding(YogaEdge edge) { if (!mHasSetPadding) { - return edge.intValue() < CSSEdge.START.intValue() ? 0 : CSSConstants.UNDEFINED; + return edge.intValue() < YogaEdge.START.intValue() ? 0 : YogaConstants.UNDEFINED; } return jni_CSSNodeStyleGetPadding(mNativePointer, edge.intValue()); } private native void jni_CSSNodeStyleSetPadding(long nativePointer, int edge, float padding); @Override - public void setPadding(CSSEdge edge, float padding) { + public void setPadding(YogaEdge edge, float padding) { mHasSetPadding = true; jni_CSSNodeStyleSetPadding(mNativePointer, edge.intValue(), padding); } private native float jni_CSSNodeStyleGetBorder(long nativePointer, int edge); @Override - public float getBorder(CSSEdge edge) { + public float getBorder(YogaEdge edge) { if (!mHasSetBorder) { - return edge.intValue() < CSSEdge.START.intValue() ? 0 : CSSConstants.UNDEFINED; + return edge.intValue() < YogaEdge.START.intValue() ? 0 : YogaConstants.UNDEFINED; } return jni_CSSNodeStyleGetBorder(mNativePointer, edge.intValue()); } private native void jni_CSSNodeStyleSetBorder(long nativePointer, int edge, float border); @Override - public void setBorder(CSSEdge edge, float border) { + public void setBorder(YogaEdge edge, float border) { mHasSetBorder = true; jni_CSSNodeStyleSetBorder(mNativePointer, edge.intValue(), border); } private native float jni_CSSNodeStyleGetPosition(long nativePointer, int edge); @Override - public float getPosition(CSSEdge edge) { + public float getPosition(YogaEdge edge) { if (!mHasSetPosition) { - return CSSConstants.UNDEFINED; + return YogaConstants.UNDEFINED; } return jni_CSSNodeStyleGetPosition(mNativePointer, edge.intValue()); } private native void jni_CSSNodeStyleSetPosition(long nativePointer, int edge, float position); @Override - public void setPosition(CSSEdge edge, float position) { + public void setPosition(YogaEdge edge, float position) { mHasSetPosition = true; jni_CSSNodeStyleSetPosition(mNativePointer, edge.intValue(), position); } @@ -502,8 +502,8 @@ public class CSSNode implements CSSNodeAPI { } @Override - public CSSDirection getLayoutDirection() { - return CSSDirection.values()[mLayoutDirection]; + public YogaDirection getLayoutDirection() { + return YogaDirection.values()[mLayoutDirection]; } private native void jni_CSSNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc); @@ -527,9 +527,9 @@ public class CSSNode implements CSSNodeAPI { return mMeasureFunction.measure( this, width, - CSSMeasureMode.values()[widthMode], + YogaMeasureMode.values()[widthMode], height, - CSSMeasureMode.values()[heightMode]); + YogaMeasureMode.values()[heightMode]); } @Override diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNodeAPI.java b/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNodeAPI.java index 8e5d19d5aaf..3c13015afff 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNodeAPI.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/CSSNodeAPI.java @@ -18,9 +18,9 @@ public interface CSSNodeAPI { long measure( CSSNodeAPI node, float width, - CSSMeasureMode widthMode, + YogaMeasureMode widthMode, float height, - CSSMeasureMode heightMode); + YogaMeasureMode heightMode); } int getChildCount(); @@ -37,21 +37,21 @@ public interface CSSNodeAPI { void dirty(); void markLayoutSeen(); void copyStyle(CSSNodeType srcNode); - CSSDirection getStyleDirection(); - void setDirection(CSSDirection direction); - CSSFlexDirection getFlexDirection(); - void setFlexDirection(CSSFlexDirection flexDirection); - CSSJustify getJustifyContent(); - void setJustifyContent(CSSJustify justifyContent); - CSSAlign getAlignItems(); - void setAlignItems(CSSAlign alignItems); - CSSAlign getAlignSelf(); - void setAlignSelf(CSSAlign alignSelf); - CSSAlign getAlignContent(); - void setAlignContent(CSSAlign alignContent); - CSSPositionType getPositionType(); - void setPositionType(CSSPositionType positionType); - void setWrap(CSSWrap flexWrap); + YogaDirection getStyleDirection(); + void setDirection(YogaDirection direction); + YogaFlexDirection getFlexDirection(); + void setFlexDirection(YogaFlexDirection flexDirection); + YogaJustify getJustifyContent(); + void setJustifyContent(YogaJustify justifyContent); + YogaAlign getAlignItems(); + void setAlignItems(YogaAlign alignItems); + YogaAlign getAlignSelf(); + void setAlignSelf(YogaAlign alignSelf); + YogaAlign getAlignContent(); + void setAlignContent(YogaAlign alignContent); + YogaPositionType getPositionType(); + void setPositionType(YogaPositionType positionType); + void setWrap(YogaWrap flexWrap); void setFlex(float flex); float getFlexGrow(); void setFlexGrow(float flexGrow); @@ -59,14 +59,14 @@ public interface CSSNodeAPI { void setFlexShrink(float flexShrink); float getFlexBasis(); void setFlexBasis(float flexBasis); - float getMargin(CSSEdge edge); - void setMargin(CSSEdge edge, float margin); - float getPadding(CSSEdge edge); - void setPadding(CSSEdge edge, float padding); - float getBorder(CSSEdge edge); - void setBorder(CSSEdge edge, float border); - float getPosition(CSSEdge edge); - void setPosition(CSSEdge edge, float position); + float getMargin(YogaEdge edge); + void setMargin(YogaEdge edge, float margin); + float getPadding(YogaEdge edge); + void setPadding(YogaEdge edge, float padding); + float getBorder(YogaEdge edge); + void setBorder(YogaEdge edge, float border); + float getPosition(YogaEdge edge); + void setPosition(YogaEdge edge, float position); float getWidth(); void setWidth(float width); float getHeight(); @@ -83,9 +83,9 @@ public interface CSSNodeAPI { float getLayoutY(); float getLayoutWidth(); float getLayoutHeight(); - CSSDirection getLayoutDirection(); - CSSOverflow getOverflow(); - void setOverflow(CSSOverflow overflow); + YogaDirection getLayoutDirection(); + YogaOverflow getOverflow(); + void setOverflow(YogaOverflow overflow); void setData(Object data); Object getData(); void reset(); diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSAlign.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaAlign.java similarity index 89% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSAlign.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaAlign.java index 4f4af8cbb2f..0ad384501ab 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSAlign.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaAlign.java @@ -12,7 +12,7 @@ package com.facebook.csslayout; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public enum CSSAlign { +public enum YogaAlign { AUTO(0), FLEX_START(1), CENTER(2), @@ -21,7 +21,7 @@ public enum CSSAlign { private int mIntValue; - CSSAlign(int intValue) { + YogaAlign(int intValue) { mIntValue = intValue; } @@ -29,7 +29,7 @@ public enum CSSAlign { return mIntValue; } - public static CSSAlign fromInt(int value) { + public static YogaAlign fromInt(int value) { switch (value) { case 0: return AUTO; case 1: return FLEX_START; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSConstants.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaConstants.java similarity index 94% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSConstants.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaConstants.java index 01a0d597d0d..03db3feb166 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSConstants.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaConstants.java @@ -9,7 +9,7 @@ package com.facebook.csslayout; -public class CSSConstants { +public class YogaConstants { public static final float UNDEFINED = Float.NaN; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSDimension.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaDimension.java similarity index 86% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSDimension.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaDimension.java index 77785ea65e6..a73f49c8ad1 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSDimension.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaDimension.java @@ -12,13 +12,13 @@ package com.facebook.csslayout; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public enum CSSDimension { +public enum YogaDimension { WIDTH(0), HEIGHT(1); private int mIntValue; - CSSDimension(int intValue) { + YogaDimension(int intValue) { mIntValue = intValue; } @@ -26,7 +26,7 @@ public enum CSSDimension { return mIntValue; } - public static CSSDimension fromInt(int value) { + public static YogaDimension fromInt(int value) { switch (value) { case 0: return WIDTH; case 1: return HEIGHT; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSDirection.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaDirection.java similarity index 87% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSDirection.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaDirection.java index 38916ea5a18..2c0473aae43 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSDirection.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaDirection.java @@ -12,14 +12,14 @@ package com.facebook.csslayout; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public enum CSSDirection { +public enum YogaDirection { INHERIT(0), LTR(1), RTL(2); private int mIntValue; - CSSDirection(int intValue) { + YogaDirection(int intValue) { mIntValue = intValue; } @@ -27,7 +27,7 @@ public enum CSSDirection { return mIntValue; } - public static CSSDirection fromInt(int value) { + public static YogaDirection fromInt(int value) { switch (value) { case 0: return INHERIT; case 1: return LTR; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSEdge.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaEdge.java similarity index 91% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSEdge.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaEdge.java index 8fe6a2fb1f6..811297f0b83 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSEdge.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaEdge.java @@ -12,7 +12,7 @@ package com.facebook.csslayout; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public enum CSSEdge { +public enum YogaEdge { LEFT(0), TOP(1), RIGHT(2), @@ -25,7 +25,7 @@ public enum CSSEdge { private int mIntValue; - CSSEdge(int intValue) { + YogaEdge(int intValue) { mIntValue = intValue; } @@ -33,7 +33,7 @@ public enum CSSEdge { return mIntValue; } - public static CSSEdge fromInt(int value) { + public static YogaEdge fromInt(int value) { switch (value) { case 0: return LEFT; case 1: return TOP; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSExperimentalFeature.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaExperimentalFeature.java similarity index 83% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSExperimentalFeature.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaExperimentalFeature.java index 3489e9192a0..f0d91f0b484 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSExperimentalFeature.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaExperimentalFeature.java @@ -12,13 +12,13 @@ package com.facebook.csslayout; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public enum CSSExperimentalFeature { +public enum YogaExperimentalFeature { ROUNDING(0), WEB_FLEX_BASIS(1); private int mIntValue; - CSSExperimentalFeature(int intValue) { + YogaExperimentalFeature(int intValue) { mIntValue = intValue; } @@ -26,7 +26,7 @@ public enum CSSExperimentalFeature { return mIntValue; } - public static CSSExperimentalFeature fromInt(int value) { + public static YogaExperimentalFeature fromInt(int value) { switch (value) { case 0: return ROUNDING; case 1: return WEB_FLEX_BASIS; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSFlexDirection.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaFlexDirection.java similarity index 86% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSFlexDirection.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaFlexDirection.java index 3047516dd96..b16128db10e 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSFlexDirection.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaFlexDirection.java @@ -12,7 +12,7 @@ package com.facebook.csslayout; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public enum CSSFlexDirection { +public enum YogaFlexDirection { COLUMN(0), COLUMN_REVERSE(1), ROW(2), @@ -20,7 +20,7 @@ public enum CSSFlexDirection { private int mIntValue; - CSSFlexDirection(int intValue) { + YogaFlexDirection(int intValue) { mIntValue = intValue; } @@ -28,7 +28,7 @@ public enum CSSFlexDirection { return mIntValue; } - public static CSSFlexDirection fromInt(int value) { + public static YogaFlexDirection fromInt(int value) { switch (value) { case 0: return COLUMN; case 1: return COLUMN_REVERSE; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSJustify.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaJustify.java similarity index 89% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSJustify.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaJustify.java index 2c9abc6b493..eb328dd4dd9 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSJustify.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaJustify.java @@ -12,7 +12,7 @@ package com.facebook.csslayout; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public enum CSSJustify { +public enum YogaJustify { FLEX_START(0), CENTER(1), FLEX_END(2), @@ -21,7 +21,7 @@ public enum CSSJustify { private int mIntValue; - CSSJustify(int intValue) { + YogaJustify(int intValue) { mIntValue = intValue; } @@ -29,7 +29,7 @@ public enum CSSJustify { return mIntValue; } - public static CSSJustify fromInt(int value) { + public static YogaJustify fromInt(int value) { switch (value) { case 0: return FLEX_START; case 1: return CENTER; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSLogLevel.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaLogLevel.java similarity index 88% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSLogLevel.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaLogLevel.java index 9d54b1ebf4c..75d74e08f79 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSLogLevel.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaLogLevel.java @@ -12,7 +12,7 @@ package com.facebook.csslayout; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public enum CSSLogLevel { +public enum YogaLogLevel { ERROR(0), WARN(1), INFO(2), @@ -21,7 +21,7 @@ public enum CSSLogLevel { private int mIntValue; - CSSLogLevel(int intValue) { + YogaLogLevel(int intValue) { mIntValue = intValue; } @@ -29,7 +29,7 @@ public enum CSSLogLevel { return mIntValue; } - public static CSSLogLevel fromInt(int value) { + public static YogaLogLevel fromInt(int value) { switch (value) { case 0: return ERROR; case 1: return WARN; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSMeasureMode.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaMeasureMode.java similarity index 86% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSMeasureMode.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaMeasureMode.java index 5b14c7ddd4e..6ea9d0381de 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSMeasureMode.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaMeasureMode.java @@ -12,14 +12,14 @@ package com.facebook.csslayout; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public enum CSSMeasureMode { +public enum YogaMeasureMode { UNDEFINED(0), EXACTLY(1), AT_MOST(2); private int mIntValue; - CSSMeasureMode(int intValue) { + YogaMeasureMode(int intValue) { mIntValue = intValue; } @@ -27,7 +27,7 @@ public enum CSSMeasureMode { return mIntValue; } - public static CSSMeasureMode fromInt(int value) { + public static YogaMeasureMode fromInt(int value) { switch (value) { case 0: return UNDEFINED; case 1: return EXACTLY; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSOverflow.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaOverflow.java similarity index 87% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSOverflow.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaOverflow.java index df6bedd7c15..0fa04bb4173 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSOverflow.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaOverflow.java @@ -12,14 +12,14 @@ package com.facebook.csslayout; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public enum CSSOverflow { +public enum YogaOverflow { VISIBLE(0), HIDDEN(1), SCROLL(2); private int mIntValue; - CSSOverflow(int intValue) { + YogaOverflow(int intValue) { mIntValue = intValue; } @@ -27,7 +27,7 @@ public enum CSSOverflow { return mIntValue; } - public static CSSOverflow fromInt(int value) { + public static YogaOverflow fromInt(int value) { switch (value) { case 0: return VISIBLE; case 1: return HIDDEN; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSPositionType.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaPositionType.java similarity index 85% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSPositionType.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaPositionType.java index 01eeece6aa0..0215c627615 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSPositionType.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaPositionType.java @@ -12,13 +12,13 @@ package com.facebook.csslayout; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public enum CSSPositionType { +public enum YogaPositionType { RELATIVE(0), ABSOLUTE(1); private int mIntValue; - CSSPositionType(int intValue) { + YogaPositionType(int intValue) { mIntValue = intValue; } @@ -26,7 +26,7 @@ public enum CSSPositionType { return mIntValue; } - public static CSSPositionType fromInt(int value) { + public static YogaPositionType fromInt(int value) { switch (value) { case 0: return RELATIVE; case 1: return ABSOLUTE; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSPrintOptions.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaPrintOptions.java similarity index 86% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSPrintOptions.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaPrintOptions.java index 49cbc25e439..fae22f0a9e2 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSPrintOptions.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaPrintOptions.java @@ -12,14 +12,14 @@ package com.facebook.csslayout; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public enum CSSPrintOptions { +public enum YogaPrintOptions { LAYOUT(1), STYLE(2), CHILDREN(4); private int mIntValue; - CSSPrintOptions(int intValue) { + YogaPrintOptions(int intValue) { mIntValue = intValue; } @@ -27,7 +27,7 @@ public enum CSSPrintOptions { return mIntValue; } - public static CSSPrintOptions fromInt(int value) { + public static YogaPrintOptions fromInt(int value) { switch (value) { case 1: return LAYOUT; case 2: return STYLE; diff --git a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSWrap.java b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaWrap.java similarity index 88% rename from ReactAndroid/src/main/java/com/facebook/csslayout/CSSWrap.java rename to ReactAndroid/src/main/java/com/facebook/csslayout/YogaWrap.java index 52a7aaf8aa6..8a371d5e527 100644 --- a/ReactAndroid/src/main/java/com/facebook/csslayout/CSSWrap.java +++ b/ReactAndroid/src/main/java/com/facebook/csslayout/YogaWrap.java @@ -12,13 +12,13 @@ package com.facebook.csslayout; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public enum CSSWrap { +public enum YogaWrap { NO_WRAP(0), WRAP(1); private int mIntValue; - CSSWrap(int intValue) { + YogaWrap(int intValue) { mIntValue = intValue; } @@ -26,7 +26,7 @@ public enum CSSWrap { return mIntValue; } - public static CSSWrap fromInt(int value) { + public static YogaWrap fromInt(int value) { switch (value) { case 0: return NO_WRAP; case 1: return WRAP; diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java index 4f9812ee9c2..464aef2bd09 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java @@ -6,13 +6,13 @@ import javax.annotation.Nullable; import java.util.Locale; -import com.facebook.csslayout.CSSAlign; -import com.facebook.csslayout.CSSConstants; -import com.facebook.csslayout.CSSFlexDirection; -import com.facebook.csslayout.CSSJustify; -import com.facebook.csslayout.CSSOverflow; -import com.facebook.csslayout.CSSPositionType; -import com.facebook.csslayout.CSSWrap; +import com.facebook.csslayout.YogaAlign; +import com.facebook.csslayout.YogaConstants; +import com.facebook.csslayout.YogaFlexDirection; +import com.facebook.csslayout.YogaJustify; +import com.facebook.csslayout.YogaOverflow; +import com.facebook.csslayout.YogaPositionType; +import com.facebook.csslayout.YogaWrap; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.annotations.ReactPropGroup; @@ -27,57 +27,57 @@ import com.facebook.react.uimanager.annotations.ReactPropGroup; */ public class LayoutShadowNode extends ReactShadowNode { - @ReactProp(name = ViewProps.WIDTH, defaultFloat = CSSConstants.UNDEFINED) + @ReactProp(name = ViewProps.WIDTH, defaultFloat = YogaConstants.UNDEFINED) public void setWidth(float width) { if (isVirtual()) { return; } - setStyleWidth(CSSConstants.isUndefined(width) ? width : PixelUtil.toPixelFromDIP(width)); + setStyleWidth(YogaConstants.isUndefined(width) ? width : PixelUtil.toPixelFromDIP(width)); } - @ReactProp(name = ViewProps.MIN_WIDTH, defaultFloat = CSSConstants.UNDEFINED) + @ReactProp(name = ViewProps.MIN_WIDTH, defaultFloat = YogaConstants.UNDEFINED) public void setMinWidth(float minWidth) { if (isVirtual()) { return; } setStyleMinWidth( - CSSConstants.isUndefined(minWidth) ? minWidth : PixelUtil.toPixelFromDIP(minWidth)); + YogaConstants.isUndefined(minWidth) ? minWidth : PixelUtil.toPixelFromDIP(minWidth)); } - @ReactProp(name = ViewProps.MAX_WIDTH, defaultFloat = CSSConstants.UNDEFINED) + @ReactProp(name = ViewProps.MAX_WIDTH, defaultFloat = YogaConstants.UNDEFINED) public void setMaxWidth(float maxWidth) { if (isVirtual()) { return; } setStyleMaxWidth( - CSSConstants.isUndefined(maxWidth) ? maxWidth : PixelUtil.toPixelFromDIP(maxWidth)); + YogaConstants.isUndefined(maxWidth) ? maxWidth : PixelUtil.toPixelFromDIP(maxWidth)); } - @ReactProp(name = ViewProps.HEIGHT, defaultFloat = CSSConstants.UNDEFINED) + @ReactProp(name = ViewProps.HEIGHT, defaultFloat = YogaConstants.UNDEFINED) public void setHeight(float height) { if (isVirtual()) { return; } setStyleHeight( - CSSConstants.isUndefined(height) ? height : PixelUtil.toPixelFromDIP(height)); + YogaConstants.isUndefined(height) ? height : PixelUtil.toPixelFromDIP(height)); } - @ReactProp(name = ViewProps.MIN_HEIGHT, defaultFloat = CSSConstants.UNDEFINED) + @ReactProp(name = ViewProps.MIN_HEIGHT, defaultFloat = YogaConstants.UNDEFINED) public void setMinHeight(float minHeight) { if (isVirtual()) { return; } setStyleMinHeight( - CSSConstants.isUndefined(minHeight) ? minHeight : PixelUtil.toPixelFromDIP(minHeight)); + YogaConstants.isUndefined(minHeight) ? minHeight : PixelUtil.toPixelFromDIP(minHeight)); } - @ReactProp(name = ViewProps.MAX_HEIGHT, defaultFloat = CSSConstants.UNDEFINED) + @ReactProp(name = ViewProps.MAX_HEIGHT, defaultFloat = YogaConstants.UNDEFINED) public void setMaxHeight(float maxHeight) { if (isVirtual()) { return; } setStyleMaxHeight( - CSSConstants.isUndefined(maxHeight) ? maxHeight : PixelUtil.toPixelFromDIP(maxHeight)); + YogaConstants.isUndefined(maxHeight) ? maxHeight : PixelUtil.toPixelFromDIP(maxHeight)); } @ReactProp(name = ViewProps.FLEX, defaultFloat = 0f) @@ -112,7 +112,7 @@ public class LayoutShadowNode extends ReactShadowNode { super.setFlexBasis(flexBasis); } - @ReactProp(name = ViewProps.ASPECT_RATIO, defaultFloat = CSSConstants.UNDEFINED) + @ReactProp(name = ViewProps.ASPECT_RATIO, defaultFloat = YogaConstants.UNDEFINED) public void setAspectRatio(float aspectRatio) { setStyleAspectRatio(aspectRatio); } @@ -123,7 +123,7 @@ public class LayoutShadowNode extends ReactShadowNode { return; } setFlexDirection( - flexDirection == null ? CSSFlexDirection.COLUMN : CSSFlexDirection.valueOf( + flexDirection == null ? YogaFlexDirection.COLUMN : YogaFlexDirection.valueOf( flexDirection.toUpperCase(Locale.US).replace("-", "_"))); } @@ -133,9 +133,9 @@ public class LayoutShadowNode extends ReactShadowNode { return; } if (flexWrap == null || flexWrap.equals("nowrap")) { - setFlexWrap(CSSWrap.NO_WRAP); + setFlexWrap(YogaWrap.NO_WRAP); } else if (flexWrap.equals("wrap")) { - setFlexWrap(CSSWrap.WRAP); + setFlexWrap(YogaWrap.WRAP); } else { throw new IllegalArgumentException("Unknown flexWrap value: " + flexWrap); } @@ -146,7 +146,7 @@ public class LayoutShadowNode extends ReactShadowNode { if (isVirtual()) { return; } - setAlignSelf(alignSelf == null ? CSSAlign.AUTO : CSSAlign.valueOf( + setAlignSelf(alignSelf == null ? YogaAlign.AUTO : YogaAlign.valueOf( alignSelf.toUpperCase(Locale.US).replace("-", "_"))); } @@ -156,7 +156,7 @@ public class LayoutShadowNode extends ReactShadowNode { return; } setAlignItems( - alignItems == null ? CSSAlign.STRETCH : CSSAlign.valueOf( + alignItems == null ? YogaAlign.STRETCH : YogaAlign.valueOf( alignItems.toUpperCase(Locale.US).replace("-", "_"))); } @@ -165,7 +165,7 @@ public class LayoutShadowNode extends ReactShadowNode { if (isVirtual()) { return; } - setJustifyContent(justifyContent == null ? CSSJustify.FLEX_START : CSSJustify.valueOf( + setJustifyContent(justifyContent == null ? YogaJustify.FLEX_START : YogaJustify.valueOf( justifyContent.toUpperCase(Locale.US).replace("-", "_"))); } @@ -174,7 +174,7 @@ public class LayoutShadowNode extends ReactShadowNode { if (isVirtual()) { return; } - setOverflow(overflow == null ? CSSOverflow.VISIBLE : CSSOverflow.valueOf( + setOverflow(overflow == null ? YogaOverflow.VISIBLE : YogaOverflow.valueOf( overflow.toUpperCase(Locale.US).replace("-", "_"))); } @@ -186,7 +186,7 @@ public class LayoutShadowNode extends ReactShadowNode { ViewProps.MARGIN_RIGHT, ViewProps.MARGIN_TOP, ViewProps.MARGIN_BOTTOM, - }, defaultFloat = CSSConstants.UNDEFINED) + }, defaultFloat = YogaConstants.UNDEFINED) public void setMargins(int index, float margin) { if (isVirtual()) { return; @@ -202,14 +202,14 @@ public class LayoutShadowNode extends ReactShadowNode { ViewProps.PADDING_RIGHT, ViewProps.PADDING_TOP, ViewProps.PADDING_BOTTOM, - }, defaultFloat = CSSConstants.UNDEFINED) + }, defaultFloat = YogaConstants.UNDEFINED) public void setPaddings(int index, float padding) { if (isVirtual()) { return; } setPadding( ViewProps.PADDING_MARGIN_SPACING_TYPES[index], - CSSConstants.isUndefined(padding) ? padding : PixelUtil.toPixelFromDIP(padding)); + YogaConstants.isUndefined(padding) ? padding : PixelUtil.toPixelFromDIP(padding)); } @ReactPropGroup(names = { @@ -218,7 +218,7 @@ public class LayoutShadowNode extends ReactShadowNode { ViewProps.BORDER_RIGHT_WIDTH, ViewProps.BORDER_TOP_WIDTH, ViewProps.BORDER_BOTTOM_WIDTH, - }, defaultFloat = CSSConstants.UNDEFINED) + }, defaultFloat = YogaConstants.UNDEFINED) public void setBorderWidths(int index, float borderWidth) { if (isVirtual()) { return; @@ -231,14 +231,14 @@ public class LayoutShadowNode extends ReactShadowNode { ViewProps.RIGHT, ViewProps.TOP, ViewProps.BOTTOM, - }, defaultFloat = CSSConstants.UNDEFINED) + }, defaultFloat = YogaConstants.UNDEFINED) public void setPositionValues(int index, float position) { if (isVirtual()) { return; } setPosition( ViewProps.POSITION_SPACING_TYPES[index], - CSSConstants.isUndefined(position) ? position : PixelUtil.toPixelFromDIP(position)); + YogaConstants.isUndefined(position) ? position : PixelUtil.toPixelFromDIP(position)); } @ReactProp(name = ViewProps.POSITION) @@ -246,8 +246,8 @@ public class LayoutShadowNode extends ReactShadowNode { if (isVirtual()) { return; } - CSSPositionType positionType = position == null ? - CSSPositionType.RELATIVE : CSSPositionType.valueOf(position.toUpperCase(Locale.US)); + YogaPositionType positionType = position == null ? + YogaPositionType.RELATIVE : YogaPositionType.valueOf(position.toUpperCase(Locale.US)); setPositionType(positionType); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java index 619821eead3..1887d38e07a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNode.java @@ -13,17 +13,17 @@ import javax.annotation.Nullable; import java.util.ArrayList; -import com.facebook.csslayout.CSSAlign; -import com.facebook.csslayout.CSSEdge; -import com.facebook.csslayout.CSSConstants; -import com.facebook.csslayout.CSSDirection; -import com.facebook.csslayout.CSSFlexDirection; -import com.facebook.csslayout.CSSJustify; +import com.facebook.csslayout.YogaAlign; +import com.facebook.csslayout.YogaEdge; +import com.facebook.csslayout.YogaConstants; +import com.facebook.csslayout.YogaDirection; +import com.facebook.csslayout.YogaFlexDirection; +import com.facebook.csslayout.YogaJustify; import com.facebook.csslayout.CSSNode; import com.facebook.csslayout.CSSNodeAPI; -import com.facebook.csslayout.CSSOverflow; -import com.facebook.csslayout.CSSPositionType; -import com.facebook.csslayout.CSSWrap; +import com.facebook.csslayout.YogaOverflow; +import com.facebook.csslayout.YogaPositionType; +import com.facebook.csslayout.YogaWrap; import com.facebook.infer.annotation.Assertions; import com.facebook.react.uimanager.annotations.ReactPropertyHolder; @@ -72,7 +72,7 @@ public class ReactShadowNode { private float mAbsoluteRight; private float mAbsoluteBottom; private final Spacing mDefaultPadding = new Spacing(0); - private final Spacing mPadding = new Spacing(CSSConstants.UNDEFINED); + private final Spacing mPadding = new Spacing(YogaConstants.UNDEFINED); private final CSSNode mCSSNode; public ReactShadowNode() { @@ -506,11 +506,11 @@ public class ReactShadowNode { return Math.round(mAbsoluteBottom - mAbsoluteTop); } - public final CSSDirection getLayoutDirection() { + public final YogaDirection getLayoutDirection() { return mCSSNode.getLayoutDirection(); } - public void setLayoutDirection(CSSDirection direction) { + public void setLayoutDirection(YogaDirection direction) { mCSSNode.setDirection(direction); } @@ -566,36 +566,36 @@ public class ReactShadowNode { mCSSNode.setAspectRatio(aspectRatio); } - public void setFlexDirection(CSSFlexDirection flexDirection) { + public void setFlexDirection(YogaFlexDirection flexDirection) { mCSSNode.setFlexDirection(flexDirection); } - public void setFlexWrap(CSSWrap wrap) { + public void setFlexWrap(YogaWrap wrap) { mCSSNode.setWrap(wrap); } - public void setAlignSelf(CSSAlign alignSelf) { + public void setAlignSelf(YogaAlign alignSelf) { mCSSNode.setAlignSelf(alignSelf); } - public void setAlignItems(CSSAlign alignItems) { + public void setAlignItems(YogaAlign alignItems) { mCSSNode.setAlignItems(alignItems); } - public void setJustifyContent(CSSJustify justifyContent) { + public void setJustifyContent(YogaJustify justifyContent) { mCSSNode.setJustifyContent(justifyContent); } - public void setOverflow(CSSOverflow overflow) { + public void setOverflow(YogaOverflow overflow) { mCSSNode.setOverflow(overflow); } public void setMargin(int spacingType, float margin) { - mCSSNode.setMargin(CSSEdge.fromInt(spacingType), margin); + mCSSNode.setMargin(YogaEdge.fromInt(spacingType), margin); } public final float getPadding(int spacingType) { - return mCSSNode.getPadding(CSSEdge.fromInt(spacingType)); + return mCSSNode.getPadding(YogaEdge.fromInt(spacingType)); } public void setDefaultPadding(int spacingType, float padding) { @@ -614,40 +614,40 @@ public class ReactShadowNode { spacingType == Spacing.RIGHT || spacingType == Spacing.START || spacingType == Spacing.END) { - if (CSSConstants.isUndefined(mPadding.getRaw(spacingType)) && - CSSConstants.isUndefined(mPadding.getRaw(Spacing.HORIZONTAL)) && - CSSConstants.isUndefined(mPadding.getRaw(Spacing.ALL))) { - mCSSNode.setPadding(CSSEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType)); + if (YogaConstants.isUndefined(mPadding.getRaw(spacingType)) && + YogaConstants.isUndefined(mPadding.getRaw(Spacing.HORIZONTAL)) && + YogaConstants.isUndefined(mPadding.getRaw(Spacing.ALL))) { + mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType)); } else { - mCSSNode.setPadding(CSSEdge.fromInt(spacingType), mPadding.getRaw(spacingType)); + mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mPadding.getRaw(spacingType)); } } else if (spacingType == Spacing.TOP || spacingType == Spacing.BOTTOM) { - if (CSSConstants.isUndefined(mPadding.getRaw(spacingType)) && - CSSConstants.isUndefined(mPadding.getRaw(Spacing.VERTICAL)) && - CSSConstants.isUndefined(mPadding.getRaw(Spacing.ALL))) { - mCSSNode.setPadding(CSSEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType)); + if (YogaConstants.isUndefined(mPadding.getRaw(spacingType)) && + YogaConstants.isUndefined(mPadding.getRaw(Spacing.VERTICAL)) && + YogaConstants.isUndefined(mPadding.getRaw(Spacing.ALL))) { + mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType)); } else { - mCSSNode.setPadding(CSSEdge.fromInt(spacingType), mPadding.getRaw(spacingType)); + mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mPadding.getRaw(spacingType)); } } else { - if (CSSConstants.isUndefined(mPadding.getRaw(spacingType))) { - mCSSNode.setPadding(CSSEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType)); + if (YogaConstants.isUndefined(mPadding.getRaw(spacingType))) { + mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mDefaultPadding.getRaw(spacingType)); } else { - mCSSNode.setPadding(CSSEdge.fromInt(spacingType), mPadding.getRaw(spacingType)); + mCSSNode.setPadding(YogaEdge.fromInt(spacingType), mPadding.getRaw(spacingType)); } } } } public void setBorder(int spacingType, float borderWidth) { - mCSSNode.setBorder(CSSEdge.fromInt(spacingType), borderWidth); + mCSSNode.setBorder(YogaEdge.fromInt(spacingType), borderWidth); } public void setPosition(int spacingType, float position) { - mCSSNode.setPosition(CSSEdge.fromInt(spacingType), position); + mCSSNode.setPosition(YogaEdge.fromInt(spacingType), position); } - public void setPositionType(CSSPositionType positionType) { + public void setPositionType(YogaPositionType positionType) { mCSSNode.setPositionType(positionType); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/Spacing.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/Spacing.java index e0d668cd9df..98c80531036 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/Spacing.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/Spacing.java @@ -9,7 +9,7 @@ package com.facebook.react.uimanager; -import com.facebook.csslayout.CSSConstants; +import com.facebook.csslayout.YogaConstants; import java.util.Arrays; @@ -96,7 +96,7 @@ public class Spacing { if (!FloatUtil.floatsEqual(mSpacing[spacingType], value)) { mSpacing[spacingType] = value; - if (CSSConstants.isUndefined(value)) { + if (YogaConstants.isUndefined(value)) { mValueFlags &= ~sFlagsMap[spacingType]; } else { mValueFlags |= sFlagsMap[spacingType]; @@ -120,7 +120,7 @@ public class Spacing { */ public float get(int spacingType) { float defaultValue = (spacingType == START || spacingType == END - ? CSSConstants.UNDEFINED + ? YogaConstants.UNDEFINED : mDefaultValue); if (mValueFlags == 0) { @@ -159,7 +159,7 @@ public class Spacing { * recycling {@link Spacing} instances. */ public void reset() { - Arrays.fill(mSpacing, CSSConstants.UNDEFINED); + Arrays.fill(mSpacing, YogaConstants.UNDEFINED); mHasAliasesSet = false; mValueFlags = 0; } @@ -178,15 +178,15 @@ public class Spacing { private static float[] newFullSpacingArray() { return new float[] { - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, - CSSConstants.UNDEFINED, + YogaConstants.UNDEFINED, + YogaConstants.UNDEFINED, + YogaConstants.UNDEFINED, + YogaConstants.UNDEFINED, + YogaConstants.UNDEFINED, + YogaConstants.UNDEFINED, + YogaConstants.UNDEFINED, + YogaConstants.UNDEFINED, + YogaConstants.UNDEFINED, }; } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java index e258f862e54..36525e27faf 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java @@ -14,7 +14,7 @@ import java.util.Arrays; import java.util.List; import com.facebook.common.logging.FLog; -import com.facebook.csslayout.CSSDirection; +import com.facebook.csslayout.YogaDirection; import com.facebook.infer.annotation.Assertions; import com.facebook.react.animation.Animation; import com.facebook.react.bridge.Arguments; @@ -84,7 +84,7 @@ public class UIImplementation { ReactShadowNode rootCSSNode = new ReactShadowNode(); I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance(); if (sharedI18nUtilInstance.isRTL(mReactContext)) { - rootCSSNode.setLayoutDirection(CSSDirection.RTL); + rootCSSNode.setLayoutDirection(YogaDirection.RTL); } rootCSSNode.setViewClassName("Root"); return rootCSSNode; diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTSurfaceViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTSurfaceViewManager.java index d4408bb7acf..0759bb6b9b0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTSurfaceViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTSurfaceViewManager.java @@ -9,7 +9,7 @@ package com.facebook.react.views.art; -import com.facebook.csslayout.CSSMeasureMode; +import com.facebook.csslayout.YogaMeasureMode; import com.facebook.csslayout.CSSNodeAPI; import com.facebook.csslayout.MeasureOutput; import com.facebook.react.module.annotations.ReactModule; @@ -31,9 +31,9 @@ public class ARTSurfaceViewManager extends public long measure( CSSNodeAPI node, float width, - CSSMeasureMode widthMode, + YogaMeasureMode widthMode, float height, - CSSMeasureMode heightMode) { + YogaMeasureMode heightMode) { throw new IllegalStateException("SurfaceView should have explicit width and height set"); } }; diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java index 62d0e4540bd..8d21a4450c2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java @@ -16,7 +16,7 @@ import java.util.Map; import android.graphics.Color; import android.graphics.PorterDuff.Mode; -import com.facebook.csslayout.CSSConstants; +import com.facebook.csslayout.YogaConstants; import com.facebook.drawee.backends.pipeline.Fresco; import com.facebook.drawee.controller.AbstractDraweeControllerBuilder; import com.facebook.react.bridge.JSApplicationIllegalArgumentException; @@ -116,9 +116,9 @@ public class ReactImageManager extends SimpleViewManager { ViewProps.BORDER_TOP_RIGHT_RADIUS, ViewProps.BORDER_BOTTOM_RIGHT_RADIUS, ViewProps.BORDER_BOTTOM_LEFT_RADIUS - }, defaultFloat = CSSConstants.UNDEFINED) + }, defaultFloat = YogaConstants.UNDEFINED) public void setBorderRadius(ReactImageView view, int index, float borderRadius) { - if (!CSSConstants.isUndefined(borderRadius)) { + if (!YogaConstants.isUndefined(borderRadius)) { borderRadius = PixelUtil.toPixelFromDIP(borderRadius); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java index 1f9fd77ce2c..b826198e967 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java @@ -30,7 +30,7 @@ import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; import com.facebook.common.util.UriUtil; -import com.facebook.csslayout.CSSConstants; +import com.facebook.csslayout.YogaConstants; import com.facebook.drawee.controller.AbstractDraweeControllerBuilder; import com.facebook.drawee.controller.BaseControllerListener; import com.facebook.drawee.controller.ControllerListener; @@ -150,7 +150,7 @@ public class ReactImageView extends GenericDraweeView { private int mBorderColor; private int mOverlayColor; private float mBorderWidth; - private float mBorderRadius = CSSConstants.UNDEFINED; + private float mBorderRadius = YogaConstants.UNDEFINED; private @Nullable float[] mBorderCornerRadii; private ScalingUtils.ScaleType mScaleType; private boolean mIsDirty; @@ -247,7 +247,7 @@ public class ReactImageView extends GenericDraweeView { public void setBorderRadius(float borderRadius, int position) { if (mBorderCornerRadii == null) { mBorderCornerRadii = new float[4]; - Arrays.fill(mBorderCornerRadii, CSSConstants.UNDEFINED); + Arrays.fill(mBorderCornerRadii, YogaConstants.UNDEFINED); } if (!FloatUtil.floatsEqual(mBorderCornerRadii[position], borderRadius)) { @@ -304,12 +304,12 @@ public class ReactImageView extends GenericDraweeView { } private void cornerRadii(float[] computedCorners) { - float defaultBorderRadius = !CSSConstants.isUndefined(mBorderRadius) ? mBorderRadius : 0; + float defaultBorderRadius = !YogaConstants.isUndefined(mBorderRadius) ? mBorderRadius : 0; - computedCorners[0] = mBorderCornerRadii != null && !CSSConstants.isUndefined(mBorderCornerRadii[0]) ? mBorderCornerRadii[0] : defaultBorderRadius; - computedCorners[1] = mBorderCornerRadii != null && !CSSConstants.isUndefined(mBorderCornerRadii[1]) ? mBorderCornerRadii[1] : defaultBorderRadius; - computedCorners[2] = mBorderCornerRadii != null && !CSSConstants.isUndefined(mBorderCornerRadii[2]) ? mBorderCornerRadii[2] : defaultBorderRadius; - computedCorners[3] = mBorderCornerRadii != null && !CSSConstants.isUndefined(mBorderCornerRadii[3]) ? mBorderCornerRadii[3] : defaultBorderRadius; + computedCorners[0] = mBorderCornerRadii != null && !YogaConstants.isUndefined(mBorderCornerRadii[0]) ? mBorderCornerRadii[0] : defaultBorderRadius; + computedCorners[1] = mBorderCornerRadii != null && !YogaConstants.isUndefined(mBorderCornerRadii[1]) ? mBorderCornerRadii[1] : defaultBorderRadius; + computedCorners[2] = mBorderCornerRadii != null && !YogaConstants.isUndefined(mBorderCornerRadii[2]) ? mBorderCornerRadii[2] : defaultBorderRadius; + computedCorners[3] = mBorderCornerRadii != null && !YogaConstants.isUndefined(mBorderCornerRadii[3]) ? mBorderCornerRadii[3] : defaultBorderRadius; } public void maybeUpdateView() { diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarShadowNode.java index fa606876a73..57da22acf67 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/progressbar/ProgressBarShadowNode.java @@ -19,7 +19,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ProgressBar; -import com.facebook.csslayout.CSSMeasureMode; +import com.facebook.csslayout.YogaMeasureMode; import com.facebook.csslayout.CSSNodeAPI; import com.facebook.csslayout.MeasureOutput; import com.facebook.react.uimanager.LayoutShadowNode; @@ -55,9 +55,9 @@ public class ProgressBarShadowNode extends LayoutShadowNode implements CSSNodeAP public long measure( CSSNodeAPI node, float width, - CSSMeasureMode widthMode, + YogaMeasureMode widthMode, float height, - CSSMeasureMode heightMode) { + YogaMeasureMode heightMode) { final int style = ReactProgressBarViewManager.getStyleFromString(getStyle()); if (!mMeasured.contains(style)) { ProgressBar progressBar = ReactProgressBarViewManager.createProgressBar(getThemedContext(), style); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderManager.java index a4abd4f2bad..e0fc0e7bae9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderManager.java @@ -15,7 +15,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.SeekBar; -import com.facebook.csslayout.CSSMeasureMode; +import com.facebook.csslayout.YogaMeasureMode; import com.facebook.csslayout.CSSNodeAPI; import com.facebook.csslayout.MeasureOutput; import com.facebook.react.bridge.ReactContext; @@ -53,9 +53,9 @@ public class ReactSliderManager extends SimpleViewManager { public long measure( CSSNodeAPI node, float width, - CSSMeasureMode widthMode, + YogaMeasureMode widthMode, float height, - CSSMeasureMode heightMode) { + YogaMeasureMode heightMode) { if (!mMeasured) { SeekBar reactSlider = new ReactSlider(getThemedContext(), null, STYLE); final int spec = View.MeasureSpec.makeMeasureSpec( diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchManager.java index 5c47cc48d15..8a88b5c6d1c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchManager.java @@ -14,7 +14,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; -import com.facebook.csslayout.CSSMeasureMode; +import com.facebook.csslayout.YogaMeasureMode; import com.facebook.csslayout.CSSNodeAPI; import com.facebook.csslayout.MeasureOutput; import com.facebook.react.bridge.ReactContext; @@ -47,9 +47,9 @@ public class ReactSwitchManager extends SimpleViewManager { public long measure( CSSNodeAPI node, float width, - CSSMeasureMode widthMode, + YogaMeasureMode widthMode, float height, - CSSMeasureMode heightMode) { + YogaMeasureMode heightMode) { if (!mMeasured) { // Create a switch with the default config and measure it; since we don't (currently) // support setting custom switch text, this is fine, as all switches will measure the same diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java index 8110c8d8282..dbeb4397064 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java @@ -30,9 +30,9 @@ import android.text.style.UnderlineSpan; import android.view.Gravity; import android.widget.TextView; -import com.facebook.csslayout.CSSDirection; -import com.facebook.csslayout.CSSConstants; -import com.facebook.csslayout.CSSMeasureMode; +import com.facebook.csslayout.YogaDirection; +import com.facebook.csslayout.YogaConstants; +import com.facebook.csslayout.YogaMeasureMode; import com.facebook.csslayout.CSSNodeAPI; import com.facebook.csslayout.MeasureOutput; import com.facebook.infer.annotation.Assertions; @@ -224,9 +224,9 @@ public class ReactTextShadowNode extends LayoutShadowNode { public long measure( CSSNodeAPI node, float width, - CSSMeasureMode widthMode, + YogaMeasureMode widthMode, float height, - CSSMeasureMode heightMode) { + YogaMeasureMode heightMode) { // TODO(5578671): Handle text direction (see View#getTextDirectionHeuristic) TextPaint textPaint = sTextPaintInstance; Layout layout; @@ -238,11 +238,11 @@ public class ReactTextShadowNode extends LayoutShadowNode { Layout.getDesiredWidth(text, textPaint) : Float.NaN; // technically, width should never be negative, but there is currently a bug in - boolean unconstrainedWidth = widthMode == CSSMeasureMode.UNDEFINED || width < 0; + boolean unconstrainedWidth = widthMode == YogaMeasureMode.UNDEFINED || width < 0; if (boring == null && (unconstrainedWidth || - (!CSSConstants.isUndefined(desiredWidth) && desiredWidth <= width))) { + (!YogaConstants.isUndefined(desiredWidth) && desiredWidth <= width))) { // Is used when the width is not known and the text is not boring, ie. if it contains // unicode characters. layout = new StaticLayout( @@ -369,7 +369,7 @@ public class ReactTextShadowNode extends LayoutShadowNode { // Return text alignment according to LTR or RTL style private int getTextAlign() { int textAlign = mTextAlign; - if (getLayoutDirection() == CSSDirection.RTL) { + if (getLayoutDirection() == YogaDirection.RTL) { if (textAlign == Gravity.RIGHT) { textAlign = Gravity.LEFT; } else if (textAlign == Gravity.LEFT) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java index 699494a389e..562576e0950 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewManager.java @@ -16,7 +16,7 @@ import android.text.TextUtils; import android.view.Gravity; import android.widget.TextView; -import com.facebook.csslayout.CSSConstants; +import com.facebook.csslayout.YogaConstants; import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.uimanager.BaseViewManager; @@ -102,9 +102,9 @@ public class ReactTextViewManager extends BaseViewManager>> 24); + float rgbComponent = color == null ? YogaConstants.UNDEFINED : (float) ((int)color & 0x00FFFFFF); + float alphaComponent = color == null ? YogaConstants.UNDEFINED : (float) ((int)color >>> 24); view.setBorderColor(SPACING_TYPES[index], rgbComponent, alphaComponent); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageShadowNode.java index 3b4f20660b7..a28e2ca5463 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageShadowNode.java @@ -18,7 +18,7 @@ import android.content.res.Resources; import android.net.Uri; import com.facebook.common.util.UriUtil; -import com.facebook.csslayout.CSSConstants; +import com.facebook.csslayout.YogaConstants; import com.facebook.drawee.controller.AbstractDraweeControllerBuilder; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.uimanager.ViewProps; @@ -35,8 +35,8 @@ public class FrescoBasedReactTextInlineImageShadowNode extends ReactTextInlineIm private @Nullable Uri mUri; private final AbstractDraweeControllerBuilder mDraweeControllerBuilder; private final @Nullable Object mCallerContext; - private float mWidth = CSSConstants.UNDEFINED; - private float mHeight = CSSConstants.UNDEFINED; + private float mWidth = YogaConstants.UNDEFINED; + private float mHeight = YogaConstants.UNDEFINED; public FrescoBasedReactTextInlineImageShadowNode( AbstractDraweeControllerBuilder draweeControllerBuilder, diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index 1b5dfc442cf..2e18a18d4f5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -28,7 +28,7 @@ import android.view.View; import android.view.inputmethod.EditorInfo; import android.widget.TextView; -import com.facebook.csslayout.CSSConstants; +import com.facebook.csslayout.YogaConstants; import com.facebook.infer.annotation.Assertions; import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.bridge.ReactContext; @@ -496,9 +496,9 @@ public class ReactTextInputManager extends BaseViewManager>> 24); + float rgbComponent = color == null ? YogaConstants.UNDEFINED : (float) ((int)color & 0x00FFFFFF); + float alphaComponent = color == null ? YogaConstants.UNDEFINED : (float) ((int)color >>> 24); view.setBorderColor(SPACING_TYPES[index], rgbComponent, alphaComponent); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java index 05bf39bbb7c..8dd1bdfef14 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java @@ -16,8 +16,8 @@ import android.util.TypedValue; import android.view.ViewGroup; import android.widget.EditText; -import com.facebook.csslayout.CSSDirection; -import com.facebook.csslayout.CSSMeasureMode; +import com.facebook.csslayout.YogaDirection; +import com.facebook.csslayout.YogaMeasureMode; import com.facebook.csslayout.CSSNodeAPI; import com.facebook.csslayout.MeasureOutput; import com.facebook.infer.annotation.Assertions; @@ -73,9 +73,9 @@ public class ReactTextInputShadowNode extends ReactTextShadowNode implements public long measure( CSSNodeAPI node, float width, - CSSMeasureMode widthMode, + YogaMeasureMode widthMode, float height, - CSSMeasureMode heightMode) { + YogaMeasureMode heightMode) { // measure() should never be called before setThemedContext() EditText editText = Assertions.assertNotNull(mEditText); @@ -122,7 +122,7 @@ public class ReactTextInputShadowNode extends ReactTextShadowNode implements super.onCollectExtraUpdates(uiViewOperationQueue); if (mComputedPadding != null) { float[] updatedPadding = mComputedPadding; - if (getLayoutDirection() == CSSDirection.RTL) { + if (getLayoutDirection() == YogaDirection.RTL) { updatedPadding = new float[] { getPadding(Spacing.END), getPadding(Spacing.TOP), diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.java index 14195a928ba..74aeb7b9718 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.java @@ -4,14 +4,14 @@ package com.facebook.react.views.view; import android.view.View; -import com.facebook.csslayout.CSSMeasureMode; +import com.facebook.csslayout.YogaMeasureMode; public class MeasureUtil { - public static int getMeasureSpec(float size, CSSMeasureMode mode) { - if (mode == CSSMeasureMode.EXACTLY) { + public static int getMeasureSpec(float size, YogaMeasureMode mode) { + if (mode == YogaMeasureMode.EXACTLY) { return View.MeasureSpec.makeMeasureSpec((int) size, View.MeasureSpec.EXACTLY); - } else if (mode == CSSMeasureMode.AT_MOST) { + } else if (mode == YogaMeasureMode.AT_MOST) { return View.MeasureSpec.makeMeasureSpec((int) size, View.MeasureSpec.AT_MOST); } else { return View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java index 2a253be514a..019d10c4a18 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java @@ -27,7 +27,7 @@ import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.os.Build; -import com.facebook.csslayout.CSSConstants; +import com.facebook.csslayout.YogaConstants; import com.facebook.react.common.annotations.VisibleForTesting; import com.facebook.react.uimanager.FloatUtil; import com.facebook.react.uimanager.Spacing; @@ -87,7 +87,7 @@ public class ReactViewBackgroundDrawable extends Drawable { private @Nullable RectF mTempRectForBorderRadius; private @Nullable RectF mTempRectForBorderRadiusOutline; private boolean mNeedUpdatePathForBorderRadius = false; - private float mBorderRadius = CSSConstants.UNDEFINED; + private float mBorderRadius = YogaConstants.UNDEFINED; /* Used by all types of background and for drawing borders */ private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); @@ -100,7 +100,7 @@ public class ReactViewBackgroundDrawable extends Drawable { public void draw(Canvas canvas) { updatePathEffect(); boolean roundedBorders = mBorderCornerRadii != null || - (!CSSConstants.isUndefined(mBorderRadius) && mBorderRadius > 0); + (!YogaConstants.isUndefined(mBorderRadius) && mBorderRadius > 0); if ((mBorderStyle == null || mBorderStyle == BorderStyle.SOLID) && !roundedBorders) { drawRectangularBackgroundWithBorders(canvas); @@ -145,7 +145,7 @@ public class ReactViewBackgroundDrawable extends Drawable { super.getOutline(outline); return; } - if ((!CSSConstants.isUndefined(mBorderRadius) && mBorderRadius > 0) || mBorderCornerRadii != null) { + if ((!YogaConstants.isUndefined(mBorderRadius) && mBorderRadius > 0) || mBorderCornerRadii != null) { updatePath(); outline.setConvexPath(mPathForBorderRadiusOutline); @@ -216,7 +216,7 @@ public class ReactViewBackgroundDrawable extends Drawable { public void setRadius(float radius, int position) { if (mBorderCornerRadii == null) { mBorderCornerRadii = new float[4]; - Arrays.fill(mBorderCornerRadii, CSSConstants.UNDEFINED); + Arrays.fill(mBorderCornerRadii, YogaConstants.UNDEFINED); } if (!FloatUtil.floatsEqual(mBorderCornerRadii[position], radius)) { @@ -277,11 +277,11 @@ public class ReactViewBackgroundDrawable extends Drawable { mTempRectForBorderRadius.inset(fullBorderWidth * 0.5f, fullBorderWidth * 0.5f); } - float defaultBorderRadius = !CSSConstants.isUndefined(mBorderRadius) ? mBorderRadius : 0; - float topLeftRadius = mBorderCornerRadii != null && !CSSConstants.isUndefined(mBorderCornerRadii[0]) ? mBorderCornerRadii[0] : defaultBorderRadius; - float topRightRadius = mBorderCornerRadii != null && !CSSConstants.isUndefined(mBorderCornerRadii[1]) ? mBorderCornerRadii[1] : defaultBorderRadius; - float bottomRightRadius = mBorderCornerRadii != null && !CSSConstants.isUndefined(mBorderCornerRadii[2]) ? mBorderCornerRadii[2] : defaultBorderRadius; - float bottomLeftRadius = mBorderCornerRadii != null && !CSSConstants.isUndefined(mBorderCornerRadii[3]) ? mBorderCornerRadii[3] : defaultBorderRadius; + float defaultBorderRadius = !YogaConstants.isUndefined(mBorderRadius) ? mBorderRadius : 0; + float topLeftRadius = mBorderCornerRadii != null && !YogaConstants.isUndefined(mBorderCornerRadii[0]) ? mBorderCornerRadii[0] : defaultBorderRadius; + float topRightRadius = mBorderCornerRadii != null && !YogaConstants.isUndefined(mBorderCornerRadii[1]) ? mBorderCornerRadii[1] : defaultBorderRadius; + float bottomRightRadius = mBorderCornerRadii != null && !YogaConstants.isUndefined(mBorderCornerRadii[2]) ? mBorderCornerRadii[2] : defaultBorderRadius; + float bottomLeftRadius = mBorderCornerRadii != null && !YogaConstants.isUndefined(mBorderCornerRadii[3]) ? mBorderCornerRadii[3] : defaultBorderRadius; mPathForBorderRadius.addRoundRect( mTempRectForBorderRadius, @@ -333,7 +333,7 @@ public class ReactViewBackgroundDrawable extends Drawable { * For rounded borders we use default "borderWidth" property. */ private float getFullBorderWidth() { - return (mBorderWidth != null && !CSSConstants.isUndefined(mBorderWidth.getRaw(Spacing.ALL))) ? + return (mBorderWidth != null && !YogaConstants.isUndefined(mBorderWidth.getRaw(Spacing.ALL))) ? mBorderWidth.getRaw(Spacing.ALL) : 0f; } @@ -342,9 +342,9 @@ public class ReactViewBackgroundDrawable extends Drawable { * {@link #getFullBorderWidth}. */ private int getFullBorderColor() { - float rgb = (mBorderRGB != null && !CSSConstants.isUndefined(mBorderRGB.getRaw(Spacing.ALL))) ? + float rgb = (mBorderRGB != null && !YogaConstants.isUndefined(mBorderRGB.getRaw(Spacing.ALL))) ? mBorderRGB.getRaw(Spacing.ALL) : DEFAULT_BORDER_RGB; - float alpha = (mBorderAlpha != null && !CSSConstants.isUndefined(mBorderAlpha.getRaw(Spacing.ALL))) ? + float alpha = (mBorderAlpha != null && !YogaConstants.isUndefined(mBorderAlpha.getRaw(Spacing.ALL))) ? mBorderAlpha.getRaw(Spacing.ALL) : DEFAULT_BORDER_ALPHA; return ReactViewBackgroundDrawable.colorFromAlphaAndRGBComponents(alpha, rgb); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java index a920c367e33..cc394758b9d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewManager.java @@ -19,7 +19,7 @@ import android.graphics.Rect; import android.os.Build; import android.view.View; -import com.facebook.csslayout.CSSConstants; +import com.facebook.csslayout.YogaConstants; import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; @@ -61,9 +61,9 @@ public class ReactViewManager extends ViewGroupManager { ViewProps.BORDER_TOP_RIGHT_RADIUS, ViewProps.BORDER_BOTTOM_RIGHT_RADIUS, ViewProps.BORDER_BOTTOM_LEFT_RADIUS - }, defaultFloat = CSSConstants.UNDEFINED) + }, defaultFloat = YogaConstants.UNDEFINED) public void setBorderRadius(ReactViewGroup view, int index, float borderRadius) { - if (!CSSConstants.isUndefined(borderRadius)) { + if (!YogaConstants.isUndefined(borderRadius)) { borderRadius = PixelUtil.toPixelFromDIP(borderRadius); } @@ -134,9 +134,9 @@ public class ReactViewManager extends ViewGroupManager { ViewProps.BORDER_RIGHT_WIDTH, ViewProps.BORDER_TOP_WIDTH, ViewProps.BORDER_BOTTOM_WIDTH, - }, defaultFloat = CSSConstants.UNDEFINED) + }, defaultFloat = YogaConstants.UNDEFINED) public void setBorderWidth(ReactViewGroup view, int index, float width) { - if (!CSSConstants.isUndefined(width)) { + if (!YogaConstants.isUndefined(width)) { width = PixelUtil.toPixelFromDIP(width); } view.setBorderWidth(SPACING_TYPES[index], width); @@ -146,8 +146,8 @@ public class ReactViewManager extends ViewGroupManager { "borderColor", "borderLeftColor", "borderRightColor", "borderTopColor", "borderBottomColor" }, customType = "Color") public void setBorderColor(ReactViewGroup view, int index, Integer color) { - float rgbComponent = color == null ? CSSConstants.UNDEFINED : (float) ((int)color & 0x00FFFFFF); - float alphaComponent = color == null ? CSSConstants.UNDEFINED : (float) ((int)color >>> 24); + float rgbComponent = color == null ? YogaConstants.UNDEFINED : (float) ((int)color & 0x00FFFFFF); + float alphaComponent = color == null ? YogaConstants.UNDEFINED : (float) ((int)color >>> 24); view.setBorderColor(SPACING_TYPES[index], rgbComponent, alphaComponent); } diff --git a/ReactAndroid/src/main/jni/first-party/csslayoutjni/jni/CSSJNI.cpp b/ReactAndroid/src/main/jni/first-party/csslayoutjni/jni/CSSJNI.cpp index 67946869b2a..1a01570d7b7 100644 --- a/ReactAndroid/src/main/jni/first-party/csslayoutjni/jni/CSSJNI.cpp +++ b/ReactAndroid/src/main/jni/first-party/csslayoutjni/jni/CSSJNI.cpp @@ -40,7 +40,7 @@ static void _jniTransferLayoutOutputsRecursive(CSSNodeRef root) { _jniTransferLayoutOutputsRecursive(CSSNodeGetChild(root, i)); } } else { - CSSLog(CSSLogLevelError, "Java CSSNode was GCed during layout calculation\n"); + CSSLog(YGLogLevelError, "Java CSSNode was GCed during layout calculation\n"); } } @@ -48,15 +48,15 @@ static void _jniPrint(CSSNodeRef node) { if (auto obj = jobjectContext(node)->lockLocal()) { cout << obj->toString() << endl; } else { - CSSLog(CSSLogLevelError, "Java CSSNode was GCed during layout calculation\n"); + CSSLog(YGLogLevelError, "Java CSSNode was GCed during layout calculation\n"); } } static CSSSize _jniMeasureFunc(CSSNodeRef node, float width, - CSSMeasureMode widthMode, + YGMeasureMode widthMode, float height, - CSSMeasureMode heightMode) { + YGMeasureMode heightMode) { if (auto obj = jobjectContext(node)->lockLocal()) { static auto measureFunc = findClassLocal("com/facebook/csslayout/CSSNode") ->getMethod("measure"); @@ -72,31 +72,31 @@ static CSSSize _jniMeasureFunc(CSSNodeRef node, return CSSSize{measuredWidth, measuredHeight}; } else { - CSSLog(CSSLogLevelError, "Java CSSNode was GCed during layout calculation\n"); + CSSLog(YGLogLevelError, "Java CSSNode was GCed during layout calculation\n"); return CSSSize{ - widthMode == CSSMeasureModeUndefined ? 0 : width, - heightMode == CSSMeasureModeUndefined ? 0 : height, + widthMode == YGMeasureModeUndefined ? 0 : width, + heightMode == YGMeasureModeUndefined ? 0 : height, }; } } -struct JCSSLogLevel : public JavaClass { - static constexpr auto kJavaDescriptor = "Lcom/facebook/csslayout/CSSLogLevel;"; +struct JYogaLogLevel : public JavaClass { + static constexpr auto kJavaDescriptor = "Lcom/facebook/csslayout/YogaLogLevel;"; }; static global_ref *jLogger; -static int _jniLog(CSSLogLevel level, const char *format, va_list args) { +static int _jniLog(YGLogLevel level, const char *format, va_list args) { char buffer[256]; int result = vsnprintf(buffer, sizeof(buffer), format, args); static auto logFunc = findClassLocal("com/facebook/csslayout/CSSLogger") - ->getMethod, jstring)>("log"); + ->getMethod, jstring)>("log"); static auto logLevelFromInt = - JCSSLogLevel::javaClassStatic()->getStaticMethod("fromInt"); + JYogaLogLevel::javaClassStatic()->getStaticMethod("fromInt"); logFunc(jLogger->get(), - logLevelFromInt(JCSSLogLevel::javaClassStatic(), static_cast(level)), + logLevelFromInt(JYogaLogLevel::javaClassStatic(), static_cast(level)), Environment::current()->NewStringUTF(buffer)); return result; @@ -123,18 +123,18 @@ void jni_CSSLayoutSetLogger(alias_ref clazz, alias_ref logger) void jni_CSSLog(alias_ref clazz, jint level, jstring message) { const char *nMessage = Environment::current()->GetStringUTFChars(message, 0); - CSSLog(static_cast(level), "%s", nMessage); + CSSLog(static_cast(level), "%s", nMessage); Environment::current()->ReleaseStringUTFChars(message, nMessage); } void jni_CSSLayoutSetExperimentalFeatureEnabled(alias_ref clazz, jint feature, jboolean enabled) { - CSSLayoutSetExperimentalFeatureEnabled(static_cast(feature), enabled); + CSSLayoutSetExperimentalFeatureEnabled(static_cast(feature), enabled); } jboolean jni_CSSLayoutIsExperimentalFeatureEnabled(alias_ref clazz, jint feature) { - return CSSLayoutIsExperimentalFeatureEnabled(static_cast(feature)); + return CSSLayoutIsExperimentalFeatureEnabled(static_cast(feature)); } jint jni_CSSNodeGetInstanceCount(alias_ref clazz) { @@ -176,8 +176,8 @@ void jni_CSSNodeRemoveChild(alias_ref, jlong nativePointer, jlong child void jni_CSSNodeCalculateLayout(alias_ref, jlong nativePointer) { const CSSNodeRef root = _jlong2CSSNodeRef(nativePointer); CSSNodeCalculateLayout(root, - CSSUndefined, - CSSUndefined, + YGUndefined, + YGUndefined, CSSNodeStyleGetDirection(_jlong2CSSNodeRef(nativePointer))); _jniTransferLayoutOutputsRecursive(root); } @@ -220,7 +220,7 @@ void jni_CSSNodeCopyStyle(alias_ref, jlong dstNativePointer, jlong srcN #define CSS_NODE_JNI_STYLE_EDGE_PROP(javatype, type, name) \ javatype jni_CSSNodeStyleGet##name(alias_ref, jlong nativePointer, jint edge) { \ return (javatype) CSSNodeStyleGet##name(_jlong2CSSNodeRef(nativePointer), \ - static_cast(edge)); \ + static_cast(edge)); \ } \ \ void jni_CSSNodeStyleSet##name(alias_ref, \ @@ -228,19 +228,19 @@ void jni_CSSNodeCopyStyle(alias_ref, jlong dstNativePointer, jlong srcN jint edge, \ javatype value) { \ CSSNodeStyleSet##name(_jlong2CSSNodeRef(nativePointer), \ - static_cast(edge), \ + static_cast(edge), \ static_cast(value)); \ } -CSS_NODE_JNI_STYLE_PROP(jint, CSSDirection, Direction); -CSS_NODE_JNI_STYLE_PROP(jint, CSSFlexDirection, FlexDirection); -CSS_NODE_JNI_STYLE_PROP(jint, CSSJustify, JustifyContent); -CSS_NODE_JNI_STYLE_PROP(jint, CSSAlign, AlignItems); -CSS_NODE_JNI_STYLE_PROP(jint, CSSAlign, AlignSelf); -CSS_NODE_JNI_STYLE_PROP(jint, CSSAlign, AlignContent); -CSS_NODE_JNI_STYLE_PROP(jint, CSSPositionType, PositionType); -CSS_NODE_JNI_STYLE_PROP(jint, CSSWrap, FlexWrap); -CSS_NODE_JNI_STYLE_PROP(jint, CSSOverflow, Overflow); +CSS_NODE_JNI_STYLE_PROP(jint, YGDirection, Direction); +CSS_NODE_JNI_STYLE_PROP(jint, YGFlexDirection, FlexDirection); +CSS_NODE_JNI_STYLE_PROP(jint, YGJustify, JustifyContent); +CSS_NODE_JNI_STYLE_PROP(jint, YGAlign, AlignItems); +CSS_NODE_JNI_STYLE_PROP(jint, YGAlign, AlignSelf); +CSS_NODE_JNI_STYLE_PROP(jint, YGAlign, AlignContent); +CSS_NODE_JNI_STYLE_PROP(jint, YGPositionType, PositionType); +CSS_NODE_JNI_STYLE_PROP(jint, YGWrap, FlexWrap); +CSS_NODE_JNI_STYLE_PROP(jint, YGOverflow, Overflow); void jni_CSSNodeStyleSetFlex(alias_ref, jlong nativePointer, jfloat value) { CSSNodeStyleSetFlex(_jlong2CSSNodeRef(nativePointer), static_cast(value)); diff --git a/ReactAndroid/src/test/java/com/facebook/react/uimanager/LayoutPropertyApplicatorTest.java b/ReactAndroid/src/test/java/com/facebook/react/uimanager/LayoutPropertyApplicatorTest.java index b350c5c03eb..453a6abb557 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/uimanager/LayoutPropertyApplicatorTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/uimanager/LayoutPropertyApplicatorTest.java @@ -11,11 +11,11 @@ package com.facebook.react.uimanager; import android.util.DisplayMetrics; -import com.facebook.csslayout.CSSAlign; -import com.facebook.csslayout.CSSConstants; -import com.facebook.csslayout.CSSFlexDirection; -import com.facebook.csslayout.CSSJustify; -import com.facebook.csslayout.CSSPositionType; +import com.facebook.csslayout.YogaAlign; +import com.facebook.csslayout.YogaConstants; +import com.facebook.csslayout.YogaFlexDirection; +import com.facebook.csslayout.YogaJustify; +import com.facebook.csslayout.YogaPositionType; import com.facebook.react.bridge.JavaOnlyMap; import org.junit.After; @@ -135,7 +135,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setPosition(eq(Spacing.BOTTOM), anyFloat()); verify(reactShadowNode).setPosition(eq(Spacing.END), anyFloat()); - verify(reactShadowNode).setPositionType(any(CSSPositionType.class)); + verify(reactShadowNode).setPositionType(any(YogaPositionType.class)); verify(map).getFloat("bottom", Float.NaN); verify(map).getFloat("right", Float.NaN); @@ -145,7 +145,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode, never()).setPosition(eq(Spacing.BOTTOM), anyFloat()); verify(reactShadowNode, never()).setPosition(eq(Spacing.END), anyFloat()); - verify(reactShadowNode, never()).setPositionType(any(CSSPositionType.class)); + verify(reactShadowNode, never()).setPositionType(any(YogaPositionType.class)); verify(map, never()).getFloat("bottom", Float.NaN); verify(map, never()).getFloat("right", Float.NaN); } @@ -158,7 +158,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setMargin(eq(Spacing.ALL), anyFloat()); - verify(map).getFloat("margin", CSSConstants.UNDEFINED); + verify(map).getFloat("margin", YogaConstants.UNDEFINED); // marginVertical reactShadowNode = spy(new LayoutShadowNode()); @@ -166,7 +166,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setMargin(eq(Spacing.VERTICAL), anyFloat()); - verify(map).getFloat("marginVertical", CSSConstants.UNDEFINED); + verify(map).getFloat("marginVertical", YogaConstants.UNDEFINED); // marginHorizontal reactShadowNode = spy(new LayoutShadowNode()); @@ -174,7 +174,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setMargin(eq(Spacing.HORIZONTAL), anyFloat()); - verify(map).getFloat("marginHorizontal", CSSConstants.UNDEFINED); + verify(map).getFloat("marginHorizontal", YogaConstants.UNDEFINED); // marginTop reactShadowNode = spy(new LayoutShadowNode()); @@ -182,7 +182,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setMargin(eq(Spacing.TOP), anyFloat()); - verify(map).getFloat("marginTop", CSSConstants.UNDEFINED); + verify(map).getFloat("marginTop", YogaConstants.UNDEFINED); // marginBottom reactShadowNode = spy(new LayoutShadowNode()); @@ -190,7 +190,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setMargin(eq(Spacing.BOTTOM), anyFloat()); - verify(map).getFloat("marginBottom", CSSConstants.UNDEFINED); + verify(map).getFloat("marginBottom", YogaConstants.UNDEFINED); // marginLeft reactShadowNode = spy(new LayoutShadowNode()); @@ -198,7 +198,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setMargin(eq(Spacing.START), anyFloat()); - verify(map).getFloat("marginLeft", CSSConstants.UNDEFINED); + verify(map).getFloat("marginLeft", YogaConstants.UNDEFINED); // marginRight reactShadowNode = spy(new LayoutShadowNode()); @@ -206,7 +206,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setMargin(eq(Spacing.END), anyFloat()); - verify(map).getFloat("marginRight", CSSConstants.UNDEFINED); + verify(map).getFloat("marginRight", YogaConstants.UNDEFINED); // no margin reactShadowNode = spy(new LayoutShadowNode()); @@ -214,7 +214,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode, never()).setMargin(anyInt(), anyFloat()); - verify(map, never()).getFloat("margin", CSSConstants.UNDEFINED); + verify(map, never()).getFloat("margin", YogaConstants.UNDEFINED); } @Test @@ -225,7 +225,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setPadding(eq(Spacing.ALL), anyFloat()); - verify(map).getFloat("padding", CSSConstants.UNDEFINED); + verify(map).getFloat("padding", YogaConstants.UNDEFINED); // paddingVertical reactShadowNode = spy(new LayoutShadowNode()); @@ -233,7 +233,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setPadding(eq(Spacing.VERTICAL), anyFloat()); - verify(map).getFloat("paddingVertical", CSSConstants.UNDEFINED); + verify(map).getFloat("paddingVertical", YogaConstants.UNDEFINED); // paddingHorizontal reactShadowNode = spy(new LayoutShadowNode()); @@ -241,7 +241,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setPadding(eq(Spacing.HORIZONTAL), anyFloat()); - verify(map).getFloat("paddingHorizontal", CSSConstants.UNDEFINED); + verify(map).getFloat("paddingHorizontal", YogaConstants.UNDEFINED); // paddingTop reactShadowNode = spy(new LayoutShadowNode()); @@ -249,7 +249,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setPadding(eq(Spacing.TOP), anyFloat()); - verify(map).getFloat("paddingTop", CSSConstants.UNDEFINED); + verify(map).getFloat("paddingTop", YogaConstants.UNDEFINED); // paddingBottom reactShadowNode = spy(new LayoutShadowNode()); @@ -257,7 +257,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setPadding(eq(Spacing.BOTTOM), anyFloat()); - verify(map).getFloat("paddingBottom", CSSConstants.UNDEFINED); + verify(map).getFloat("paddingBottom", YogaConstants.UNDEFINED); // paddingLeft reactShadowNode = spy(new LayoutShadowNode()); @@ -265,7 +265,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setPadding(eq(Spacing.START), anyFloat()); - verify(map).getFloat("paddingLeft", CSSConstants.UNDEFINED); + verify(map).getFloat("paddingLeft", YogaConstants.UNDEFINED); // paddingRight reactShadowNode = spy(new LayoutShadowNode()); @@ -273,7 +273,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode).setPadding(eq(Spacing.END), anyFloat()); - verify(map).getFloat("paddingRight", CSSConstants.UNDEFINED); + verify(map).getFloat("paddingRight", YogaConstants.UNDEFINED); // no padding reactShadowNode = spy(new LayoutShadowNode()); @@ -281,7 +281,7 @@ public class LayoutPropertyApplicatorTest { reactShadowNode.updateProperties(map); verify(reactShadowNode, never()).setPadding(anyInt(), anyFloat()); - verify(map, never()).getFloat("padding", CSSConstants.UNDEFINED); + verify(map, never()).getFloat("padding", YogaConstants.UNDEFINED); } @Test @@ -300,21 +300,21 @@ public class LayoutPropertyApplicatorTest { "relative"); reactShadowNode.updateProperties(map); - verify(reactShadowNode).setFlexDirection(CSSFlexDirection.COLUMN); - verify(reactShadowNode).setAlignSelf(CSSAlign.STRETCH); - verify(reactShadowNode).setAlignItems(CSSAlign.CENTER); - verify(reactShadowNode).setJustifyContent(CSSJustify.SPACE_BETWEEN); - verify(reactShadowNode).setPositionType(CSSPositionType.RELATIVE); + verify(reactShadowNode).setFlexDirection(YogaFlexDirection.COLUMN); + verify(reactShadowNode).setAlignSelf(YogaAlign.STRETCH); + verify(reactShadowNode).setAlignItems(YogaAlign.CENTER); + verify(reactShadowNode).setJustifyContent(YogaJustify.SPACE_BETWEEN); + verify(reactShadowNode).setPositionType(YogaPositionType.RELATIVE); reactShadowNode = spy(new LayoutShadowNode()); map = buildStyles(); reactShadowNode.updateProperties(map); - verify(reactShadowNode, never()).setFlexDirection(any(CSSFlexDirection.class)); - verify(reactShadowNode, never()).setAlignSelf(any(CSSAlign.class)); - verify(reactShadowNode, never()).setAlignItems(any(CSSAlign.class)); - verify(reactShadowNode, never()).setJustifyContent(any(CSSJustify.class)); - verify(reactShadowNode, never()).setPositionType(any(CSSPositionType.class)); + verify(reactShadowNode, never()).setFlexDirection(any(YogaFlexDirection.class)); + verify(reactShadowNode, never()).setAlignSelf(any(YogaAlign.class)); + verify(reactShadowNode, never()).setAlignItems(any(YogaAlign.class)); + verify(reactShadowNode, never()).setJustifyContent(any(YogaJustify.class)); + verify(reactShadowNode, never()).setPositionType(any(YogaPositionType.class)); } @Test @@ -361,11 +361,11 @@ public class LayoutPropertyApplicatorTest { verify(reactShadowNode).setPadding(Spacing.ALL, 10.f); verify(reactShadowNode).setMargin(Spacing.START, 10.f); verify(reactShadowNode).setBorder(Spacing.TOP, 10.f); - verify(reactShadowNode).setFlexDirection(CSSFlexDirection.ROW); - verify(reactShadowNode).setAlignSelf(CSSAlign.STRETCH); - verify(reactShadowNode).setAlignItems(CSSAlign.CENTER); - verify(reactShadowNode).setJustifyContent(CSSJustify.SPACE_BETWEEN); - verify(reactShadowNode).setPositionType(CSSPositionType.ABSOLUTE); + verify(reactShadowNode).setFlexDirection(YogaFlexDirection.ROW); + verify(reactShadowNode).setAlignSelf(YogaAlign.STRETCH); + verify(reactShadowNode).setAlignItems(YogaAlign.CENTER); + verify(reactShadowNode).setJustifyContent(YogaJustify.SPACE_BETWEEN); + verify(reactShadowNode).setPositionType(YogaPositionType.ABSOLUTE); map = buildStyles( "width", @@ -397,19 +397,19 @@ public class LayoutPropertyApplicatorTest { reset(reactShadowNode); reactShadowNode.updateProperties(map); - verify(reactShadowNode).setStyleWidth(CSSConstants.UNDEFINED); - verify(reactShadowNode).setStyleHeight(CSSConstants.UNDEFINED); - verify(reactShadowNode).setPosition(Spacing.START, CSSConstants.UNDEFINED); - verify(reactShadowNode).setPosition(Spacing.TOP, CSSConstants.UNDEFINED); + verify(reactShadowNode).setStyleWidth(YogaConstants.UNDEFINED); + verify(reactShadowNode).setStyleHeight(YogaConstants.UNDEFINED); + verify(reactShadowNode).setPosition(Spacing.START, YogaConstants.UNDEFINED); + verify(reactShadowNode).setPosition(Spacing.TOP, YogaConstants.UNDEFINED); verify(reactShadowNode).setFlex(0.f); - verify(reactShadowNode).setPadding(Spacing.ALL, CSSConstants.UNDEFINED); - verify(reactShadowNode).setMargin(Spacing.START, CSSConstants.UNDEFINED); - verify(reactShadowNode).setBorder(Spacing.TOP, CSSConstants.UNDEFINED); - verify(reactShadowNode).setFlexDirection(CSSFlexDirection.COLUMN); - verify(reactShadowNode).setAlignSelf(CSSAlign.AUTO); - verify(reactShadowNode).setAlignItems(CSSAlign.STRETCH); - verify(reactShadowNode).setJustifyContent(CSSJustify.FLEX_START); - verify(reactShadowNode).setPositionType(CSSPositionType.RELATIVE); + verify(reactShadowNode).setPadding(Spacing.ALL, YogaConstants.UNDEFINED); + verify(reactShadowNode).setMargin(Spacing.START, YogaConstants.UNDEFINED); + verify(reactShadowNode).setBorder(Spacing.TOP, YogaConstants.UNDEFINED); + verify(reactShadowNode).setFlexDirection(YogaFlexDirection.COLUMN); + verify(reactShadowNode).setAlignSelf(YogaAlign.AUTO); + verify(reactShadowNode).setAlignItems(YogaAlign.STRETCH); + verify(reactShadowNode).setJustifyContent(YogaJustify.FLEX_START); + verify(reactShadowNode).setPositionType(YogaPositionType.RELATIVE); } @Test diff --git a/ReactCommon/CSSLayout/CSSLayout/CSSEnums.h b/ReactCommon/CSSLayout/CSSLayout/CSSEnums.h index 94a6ba1b4a7..2a87abf9953 100644 --- a/ReactCommon/CSSLayout/CSSLayout/CSSEnums.h +++ b/ReactCommon/CSSLayout/CSSLayout/CSSEnums.h @@ -7,102 +7,102 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -typedef enum CSSOverflow { - CSSOverflowVisible, - CSSOverflowHidden, - CSSOverflowScroll, - CSSOverflowCount, -} CSSOverflow; +typedef enum YGFlexDirection { + YGFlexDirectionColumn, + YGFlexDirectionColumnReverse, + YGFlexDirectionRow, + YGFlexDirectionRowReverse, + YGFlexDirectionCount, +} YGFlexDirection; -typedef enum CSSJustify { - CSSJustifyFlexStart, - CSSJustifyCenter, - CSSJustifyFlexEnd, - CSSJustifySpaceBetween, - CSSJustifySpaceAround, - CSSJustifyCount, -} CSSJustify; +typedef enum YGMeasureMode { + YGMeasureModeUndefined, + YGMeasureModeExactly, + YGMeasureModeAtMost, + YGMeasureModeCount, +} YGMeasureMode; -typedef enum CSSFlexDirection { - CSSFlexDirectionColumn, - CSSFlexDirectionColumnReverse, - CSSFlexDirectionRow, - CSSFlexDirectionRowReverse, - CSSFlexDirectionCount, -} CSSFlexDirection; +typedef enum YGPrintOptions { + YGPrintOptionsLayout = 1, + YGPrintOptionsStyle = 2, + YGPrintOptionsChildren = 4, + YGPrintOptionsCount, +} YGPrintOptions; -typedef enum CSSAlign { - CSSAlignAuto, - CSSAlignFlexStart, - CSSAlignCenter, - CSSAlignFlexEnd, - CSSAlignStretch, - CSSAlignCount, -} CSSAlign; +typedef enum YGEdge { + YGEdgeLeft, + YGEdgeTop, + YGEdgeRight, + YGEdgeBottom, + YGEdgeStart, + YGEdgeEnd, + YGEdgeHorizontal, + YGEdgeVertical, + YGEdgeAll, + YGEdgeCount, +} YGEdge; -typedef enum CSSEdge { - CSSEdgeLeft, - CSSEdgeTop, - CSSEdgeRight, - CSSEdgeBottom, - CSSEdgeStart, - CSSEdgeEnd, - CSSEdgeHorizontal, - CSSEdgeVertical, - CSSEdgeAll, - CSSEdgeCount, -} CSSEdge; +typedef enum YGPositionType { + YGPositionTypeRelative, + YGPositionTypeAbsolute, + YGPositionTypeCount, +} YGPositionType; -typedef enum CSSWrap { - CSSWrapNoWrap, - CSSWrapWrap, - CSSWrapCount, -} CSSWrap; +typedef enum YGDimension { + YGDimensionWidth, + YGDimensionHeight, + YGDimensionCount, +} YGDimension; -typedef enum CSSDirection { - CSSDirectionInherit, - CSSDirectionLTR, - CSSDirectionRTL, - CSSDirectionCount, -} CSSDirection; +typedef enum YGJustify { + YGJustifyFlexStart, + YGJustifyCenter, + YGJustifyFlexEnd, + YGJustifySpaceBetween, + YGJustifySpaceAround, + YGJustifyCount, +} YGJustify; -typedef enum CSSExperimentalFeature { - CSSExperimentalFeatureRounding, - CSSExperimentalFeatureWebFlexBasis, - CSSExperimentalFeatureCount, -} CSSExperimentalFeature; +typedef enum YGDirection { + YGDirectionInherit, + YGDirectionLTR, + YGDirectionRTL, + YGDirectionCount, +} YGDirection; -typedef enum CSSLogLevel { - CSSLogLevelError, - CSSLogLevelWarn, - CSSLogLevelInfo, - CSSLogLevelDebug, - CSSLogLevelVerbose, - CSSLogLevelCount, -} CSSLogLevel; +typedef enum YGLogLevel { + YGLogLevelError, + YGLogLevelWarn, + YGLogLevelInfo, + YGLogLevelDebug, + YGLogLevelVerbose, + YGLogLevelCount, +} YGLogLevel; -typedef enum CSSDimension { - CSSDimensionWidth, - CSSDimensionHeight, - CSSDimensionCount, -} CSSDimension; +typedef enum YGWrap { + YGWrapNoWrap, + YGWrapWrap, + YGWrapCount, +} YGWrap; -typedef enum CSSMeasureMode { - CSSMeasureModeUndefined, - CSSMeasureModeExactly, - CSSMeasureModeAtMost, - CSSMeasureModeCount, -} CSSMeasureMode; +typedef enum YGOverflow { + YGOverflowVisible, + YGOverflowHidden, + YGOverflowScroll, + YGOverflowCount, +} YGOverflow; -typedef enum CSSPositionType { - CSSPositionTypeRelative, - CSSPositionTypeAbsolute, - CSSPositionTypeCount, -} CSSPositionType; +typedef enum YGExperimentalFeature { + YGExperimentalFeatureRounding, + YGExperimentalFeatureWebFlexBasis, + YGExperimentalFeatureCount, +} YGExperimentalFeature; -typedef enum CSSPrintOptions { - CSSPrintOptionsLayout = 1, - CSSPrintOptionsStyle = 2, - CSSPrintOptionsChildren = 4, - CSSPrintOptionsCount, -} CSSPrintOptions; +typedef enum YGAlign { + YGAlignAuto, + YGAlignFlexStart, + YGAlignCenter, + YGAlignFlexEnd, + YGAlignStretch, + YGAlignCount, +} YGAlign; diff --git a/ReactCommon/CSSLayout/CSSLayout/CSSLayout.c b/ReactCommon/CSSLayout/CSSLayout/CSSLayout.c index 7067827a7d5..c41194a1ea1 100644 --- a/ReactCommon/CSSLayout/CSSLayout/CSSLayout.c +++ b/ReactCommon/CSSLayout/CSSLayout/CSSLayout.c @@ -33,8 +33,8 @@ __forceinline const float fmaxf(const float a, const float b) { typedef struct CSSCachedMeasurement { float availableWidth; float availableHeight; - CSSMeasureMode widthMeasureMode; - CSSMeasureMode heightMeasureMode; + YGMeasureMode widthMeasureMode; + YGMeasureMode heightMeasureMode; float computedWidth; float computedHeight; @@ -47,7 +47,7 @@ enum { CSS_MAX_CACHED_RESULT_COUNT = 16 }; typedef struct CSSLayout { float position[4]; float dimensions[2]; - CSSDirection direction; + YGDirection direction; uint32_t computedFlexBasisGeneration; float computedFlexBasis; @@ -55,7 +55,7 @@ typedef struct CSSLayout { // Instead of recomputing the entire layout every single time, we // cache some information to break early when nothing changed uint32_t generationCount; - CSSDirection lastParentDirection; + YGDirection lastParentDirection; uint32_t nextCachedMeasurementsIndex; CSSCachedMeasurement cachedMeasurements[CSS_MAX_CACHED_RESULT_COUNT]; @@ -65,23 +65,23 @@ typedef struct CSSLayout { } CSSLayout; typedef struct CSSStyle { - CSSDirection direction; - CSSFlexDirection flexDirection; - CSSJustify justifyContent; - CSSAlign alignContent; - CSSAlign alignItems; - CSSAlign alignSelf; - CSSPositionType positionType; - CSSWrap flexWrap; - CSSOverflow overflow; + YGDirection direction; + YGFlexDirection flexDirection; + YGJustify justifyContent; + YGAlign alignContent; + YGAlign alignItems; + YGAlign alignSelf; + YGPositionType positionType; + YGWrap flexWrap; + YGOverflow overflow; float flex; float flexGrow; float flexShrink; float flexBasis; - float margin[CSSEdgeCount]; - float position[CSSEdgeCount]; - float padding[CSSEdgeCount]; - float border[CSSEdgeCount]; + float margin[YGEdgeCount]; + float position[YGEdgeCount]; + float padding[YGEdgeCount]; + float border[YGEdgeCount]; float dimensions[2]; float minDimensions[2]; float maxDimensions[2]; @@ -115,25 +115,25 @@ CSSFree gCSSFree = &free; #ifdef ANDROID #include -static int _csslayoutAndroidLog(CSSLogLevel level, const char *format, va_list args) { - int androidLevel = CSSLogLevelDebug; +static int _csslayoutAndroidLog(YGLogLevel level, const char *format, va_list args) { + int androidLevel = YGLogLevelDebug; switch (level) { - case CSSLogLevelError: + case YGLogLevelError: androidLevel = ANDROID_LOG_ERROR; break; - case CSSLogLevelWarn: + case YGLogLevelWarn: androidLevel = ANDROID_LOG_WARN; break; - case CSSLogLevelInfo: + case YGLogLevelInfo: androidLevel = ANDROID_LOG_INFO; break; - case CSSLogLevelDebug: + case YGLogLevelDebug: androidLevel = ANDROID_LOG_DEBUG; break; - case CSSLogLevelVerbose: + case YGLogLevelVerbose: androidLevel = ANDROID_LOG_VERBOSE; break; - case CSSLogLevelCount: + case YGLogLevelCount: break; } const int result = __android_log_vprint(androidLevel, "css-layout", format, args); @@ -141,14 +141,14 @@ static int _csslayoutAndroidLog(CSSLogLevel level, const char *format, va_list a } static CSSLogger gLogger = &_csslayoutAndroidLog; #else -static int _csslayoutDefaultLog(CSSLogLevel level, const char *format, va_list args) { +static int _csslayoutDefaultLog(YGLogLevel level, const char *format, va_list args) { switch (level) { - case CSSLogLevelError: + case YGLogLevelError: return vfprintf(stderr, format, args); - case CSSLogLevelWarn: - case CSSLogLevelInfo: - case CSSLogLevelDebug: - case CSSLogLevelVerbose: + case YGLogLevelWarn: + case YGLogLevelInfo: + case YGLogLevelDebug: + case YGLogLevelVerbose: default: return vprintf(format, args); } @@ -156,31 +156,30 @@ static int _csslayoutDefaultLog(CSSLogLevel level, const char *format, va_list a static CSSLogger gLogger = &_csslayoutDefaultLog; #endif -static inline float computedEdgeValue(const float edges[CSSEdgeCount], - const CSSEdge edge, +static inline float computedEdgeValue(const float edges[YGEdgeCount], + const YGEdge edge, const float defaultValue) { - CSS_ASSERT(edge <= CSSEdgeEnd, "Cannot get computed value of multi-edge shorthands"); + CSS_ASSERT(edge <= YGEdgeEnd, "Cannot get computed value of multi-edge shorthands"); if (!CSSValueIsUndefined(edges[edge])) { return edges[edge]; } - if ((edge == CSSEdgeTop || edge == CSSEdgeBottom) && - !CSSValueIsUndefined(edges[CSSEdgeVertical])) { - return edges[CSSEdgeVertical]; + if ((edge == YGEdgeTop || edge == YGEdgeBottom) && !CSSValueIsUndefined(edges[YGEdgeVertical])) { + return edges[YGEdgeVertical]; } - if ((edge == CSSEdgeLeft || edge == CSSEdgeRight || edge == CSSEdgeStart || edge == CSSEdgeEnd) && - !CSSValueIsUndefined(edges[CSSEdgeHorizontal])) { - return edges[CSSEdgeHorizontal]; + if ((edge == YGEdgeLeft || edge == YGEdgeRight || edge == YGEdgeStart || edge == YGEdgeEnd) && + !CSSValueIsUndefined(edges[YGEdgeHorizontal])) { + return edges[YGEdgeHorizontal]; } - if (!CSSValueIsUndefined(edges[CSSEdgeAll])) { - return edges[CSSEdgeAll]; + if (!CSSValueIsUndefined(edges[YGEdgeAll])) { + return edges[YGEdgeAll]; } - if (edge == CSSEdgeStart || edge == CSSEdgeEnd) { - return CSSUndefined; + if (edge == YGEdgeStart || edge == YGEdgeEnd) { + return YGUndefined; } return defaultValue; @@ -242,50 +241,50 @@ void CSSNodeInit(const CSSNodeRef node) { node->hasNewLayout = true; node->isDirty = false; - node->style.flex = CSSUndefined; - node->style.flexGrow = CSSUndefined; - node->style.flexShrink = CSSUndefined; - node->style.flexBasis = CSSUndefined; + node->style.flex = YGUndefined; + node->style.flexGrow = YGUndefined; + node->style.flexShrink = YGUndefined; + node->style.flexBasis = YGUndefined; - node->style.alignItems = CSSAlignStretch; - node->style.alignContent = CSSAlignFlexStart; + node->style.alignItems = YGAlignStretch; + node->style.alignContent = YGAlignFlexStart; - node->style.direction = CSSDirectionInherit; - node->style.flexDirection = CSSFlexDirectionColumn; + node->style.direction = YGDirectionInherit; + node->style.flexDirection = YGFlexDirectionColumn; - node->style.overflow = CSSOverflowVisible; + node->style.overflow = YGOverflowVisible; // Some of the fields default to undefined and not 0 - node->style.dimensions[CSSDimensionWidth] = CSSUndefined; - node->style.dimensions[CSSDimensionHeight] = CSSUndefined; + node->style.dimensions[YGDimensionWidth] = YGUndefined; + node->style.dimensions[YGDimensionHeight] = YGUndefined; - node->style.minDimensions[CSSDimensionWidth] = CSSUndefined; - node->style.minDimensions[CSSDimensionHeight] = CSSUndefined; + node->style.minDimensions[YGDimensionWidth] = YGUndefined; + node->style.minDimensions[YGDimensionHeight] = YGUndefined; - node->style.maxDimensions[CSSDimensionWidth] = CSSUndefined; - node->style.maxDimensions[CSSDimensionHeight] = CSSUndefined; + node->style.maxDimensions[YGDimensionWidth] = YGUndefined; + node->style.maxDimensions[YGDimensionHeight] = YGUndefined; - for (CSSEdge edge = CSSEdgeLeft; edge < CSSEdgeCount; edge++) { - node->style.position[edge] = CSSUndefined; - node->style.margin[edge] = CSSUndefined; - node->style.padding[edge] = CSSUndefined; - node->style.border[edge] = CSSUndefined; + for (YGEdge edge = YGEdgeLeft; edge < YGEdgeCount; edge++) { + node->style.position[edge] = YGUndefined; + node->style.margin[edge] = YGUndefined; + node->style.padding[edge] = YGUndefined; + node->style.border[edge] = YGUndefined; } - node->style.aspectRatio = CSSUndefined; + node->style.aspectRatio = YGUndefined; - node->layout.dimensions[CSSDimensionWidth] = CSSUndefined; - node->layout.dimensions[CSSDimensionHeight] = CSSUndefined; + node->layout.dimensions[YGDimensionWidth] = YGUndefined; + node->layout.dimensions[YGDimensionHeight] = YGUndefined; // Such that the comparison is always going to be false - node->layout.lastParentDirection = (CSSDirection) -1; + node->layout.lastParentDirection = (YGDirection) -1; node->layout.nextCachedMeasurementsIndex = 0; - node->layout.computedFlexBasis = CSSUndefined; + node->layout.computedFlexBasis = YGUndefined; - node->layout.measuredDimensions[CSSDimensionWidth] = CSSUndefined; - node->layout.measuredDimensions[CSSDimensionHeight] = CSSUndefined; - node->layout.cachedLayout.widthMeasureMode = (CSSMeasureMode) -1; - node->layout.cachedLayout.heightMeasureMode = (CSSMeasureMode) -1; + node->layout.measuredDimensions[YGDimensionWidth] = YGUndefined; + node->layout.measuredDimensions[YGDimensionHeight] = YGUndefined; + node->layout.cachedLayout.widthMeasureMode = (YGMeasureMode) -1; + node->layout.cachedLayout.heightMeasureMode = (YGMeasureMode) -1; node->layout.cachedLayout.computedWidth = -1; node->layout.cachedLayout.computedHeight = -1; } @@ -293,7 +292,7 @@ void CSSNodeInit(const CSSNodeRef node) { static void _CSSNodeMarkDirty(const CSSNodeRef node) { if (!node->isDirty) { node->isDirty = true; - node->layout.computedFlexBasis = CSSUndefined; + node->layout.computedFlexBasis = YGUndefined; if (node->parent) { _CSSNodeMarkDirty(node->parent); } @@ -381,9 +380,9 @@ inline float CSSNodeStyleGetFlexBasis(const CSSNodeRef node) { return node->style.flexBasis; } if (!CSSValueIsUndefined(node->style.flex)) { - return node->style.flex > 0 ? 0 : CSSUndefined; + return node->style.flex > 0 ? 0 : YGUndefined; } - return CSSUndefined; + return YGUndefined; } void CSSNodeStyleSetFlex(const CSSNodeRef node, const float flex) { @@ -417,16 +416,16 @@ void CSSNodeStyleSetFlex(const CSSNodeRef node, const float flex) { return node->style.instanceName; \ } -#define CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName, defaultValue) \ - void CSSNodeStyleSet##name(const CSSNodeRef node, const CSSEdge edge, const type paramName) { \ - if (node->style.instanceName[edge] != paramName) { \ - node->style.instanceName[edge] = paramName; \ - _CSSNodeMarkDirty(node); \ - } \ - } \ - \ - type CSSNodeStyleGet##name(const CSSNodeRef node, const CSSEdge edge) { \ - return computedEdgeValue(node->style.instanceName, edge, defaultValue); \ +#define CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName, defaultValue) \ + void CSSNodeStyleSet##name(const CSSNodeRef node, const YGEdge edge, const type paramName) { \ + if (node->style.instanceName[edge] != paramName) { \ + node->style.instanceName[edge] = paramName; \ + _CSSNodeMarkDirty(node); \ + } \ + } \ + \ + type CSSNodeStyleGet##name(const CSSNodeRef node, const YGEdge edge) { \ + return computedEdgeValue(node->style.instanceName, edge, defaultValue); \ } #define CSS_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \ @@ -438,51 +437,51 @@ CSS_NODE_PROPERTY_IMPL(void *, Context, context, context); CSS_NODE_PROPERTY_IMPL(CSSPrintFunc, PrintFunc, printFunc, print); CSS_NODE_PROPERTY_IMPL(bool, HasNewLayout, hasNewLayout, hasNewLayout); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSDirection, Direction, direction, direction); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSFlexDirection, FlexDirection, flexDirection, flexDirection); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSJustify, JustifyContent, justifyContent, justifyContent); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSAlign, AlignContent, alignContent, alignContent); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSAlign, AlignItems, alignItems, alignItems); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSAlign, AlignSelf, alignSelf, alignSelf); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSPositionType, PositionType, positionType, positionType); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSWrap, FlexWrap, flexWrap, flexWrap); -CSS_NODE_STYLE_PROPERTY_IMPL(CSSOverflow, Overflow, overflow, overflow); +CSS_NODE_STYLE_PROPERTY_IMPL(YGDirection, Direction, direction, direction); +CSS_NODE_STYLE_PROPERTY_IMPL(YGFlexDirection, FlexDirection, flexDirection, flexDirection); +CSS_NODE_STYLE_PROPERTY_IMPL(YGJustify, JustifyContent, justifyContent, justifyContent); +CSS_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignContent, alignContent, alignContent); +CSS_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignItems, alignItems, alignItems); +CSS_NODE_STYLE_PROPERTY_IMPL(YGAlign, AlignSelf, alignSelf, alignSelf); +CSS_NODE_STYLE_PROPERTY_IMPL(YGPositionType, PositionType, positionType, positionType); +CSS_NODE_STYLE_PROPERTY_IMPL(YGWrap, FlexWrap, flexWrap, flexWrap); +CSS_NODE_STYLE_PROPERTY_IMPL(YGOverflow, Overflow, overflow, overflow); CSS_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexGrow, flexGrow, flexGrow); CSS_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink); CSS_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexBasis, flexBasis, flexBasis); -CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Position, position, position, CSSUndefined); +CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Position, position, position, YGUndefined); CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Margin, margin, margin, 0); CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Padding, padding, padding, 0); CSS_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Border, border, border, 0); -CSS_NODE_STYLE_PROPERTY_IMPL(float, Width, width, dimensions[CSSDimensionWidth]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, Height, height, dimensions[CSSDimensionHeight]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, MinWidth, minWidth, minDimensions[CSSDimensionWidth]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, MinHeight, minHeight, minDimensions[CSSDimensionHeight]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, MaxWidth, maxWidth, maxDimensions[CSSDimensionWidth]); -CSS_NODE_STYLE_PROPERTY_IMPL(float, MaxHeight, maxHeight, maxDimensions[CSSDimensionHeight]); +CSS_NODE_STYLE_PROPERTY_IMPL(float, Width, width, dimensions[YGDimensionWidth]); +CSS_NODE_STYLE_PROPERTY_IMPL(float, Height, height, dimensions[YGDimensionHeight]); +CSS_NODE_STYLE_PROPERTY_IMPL(float, MinWidth, minWidth, minDimensions[YGDimensionWidth]); +CSS_NODE_STYLE_PROPERTY_IMPL(float, MinHeight, minHeight, minDimensions[YGDimensionHeight]); +CSS_NODE_STYLE_PROPERTY_IMPL(float, MaxWidth, maxWidth, maxDimensions[YGDimensionWidth]); +CSS_NODE_STYLE_PROPERTY_IMPL(float, MaxHeight, maxHeight, maxDimensions[YGDimensionHeight]); // Yoga specific properties, not compatible with flexbox specification CSS_NODE_STYLE_PROPERTY_IMPL(float, AspectRatio, aspectRatio, aspectRatio); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Left, position[CSSEdgeLeft]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Top, position[CSSEdgeTop]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Right, position[CSSEdgeRight]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Bottom, position[CSSEdgeBottom]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Width, dimensions[CSSDimensionWidth]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[CSSDimensionHeight]); -CSS_NODE_LAYOUT_PROPERTY_IMPL(CSSDirection, Direction, direction); +CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Left, position[YGEdgeLeft]); +CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Top, position[YGEdgeTop]); +CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Right, position[YGEdgeRight]); +CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Bottom, position[YGEdgeBottom]); +CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Width, dimensions[YGDimensionWidth]); +CSS_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[YGDimensionHeight]); +CSS_NODE_LAYOUT_PROPERTY_IMPL(YGDirection, Direction, direction); uint32_t gCurrentGenerationCount = 0; bool layoutNodeInternal(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSDirection parentDirection, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode, + const YGDirection parentDirection, + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode, const bool performLayout, const char *reason); @@ -499,19 +498,19 @@ static inline bool eq(const float a, const float b) { static void indent(const uint32_t n) { for (uint32_t i = 0; i < n; i++) { - CSSLog(CSSLogLevelDebug, " "); + CSSLog(YGLogLevelDebug, " "); } } static void printNumberIfNotZero(const char *str, const float number) { if (!eq(number, 0)) { - CSSLog(CSSLogLevelDebug, "%s: %g, ", str, number); + CSSLog(YGLogLevelDebug, "%s: %g, ", str, number); } } static void printNumberIfNotUndefined(const char *str, const float number) { if (!CSSValueIsUndefined(number)) { - CSSLog(CSSLogLevelDebug, "%s: %g, ", str, number); + CSSLog(YGLogLevelDebug, "%s: %g, ", str, number); } } @@ -520,370 +519,363 @@ static bool eqFour(const float four[4]) { } static void _CSSNodePrint(const CSSNodeRef node, - const CSSPrintOptions options, + const YGPrintOptions options, const uint32_t level) { indent(level); - CSSLog(CSSLogLevelDebug, "{"); + CSSLog(YGLogLevelDebug, "{"); if (node->print) { node->print(node); } - if (options & CSSPrintOptionsLayout) { - CSSLog(CSSLogLevelDebug, "layout: {"); - CSSLog(CSSLogLevelDebug, "width: %g, ", node->layout.dimensions[CSSDimensionWidth]); - CSSLog(CSSLogLevelDebug, "height: %g, ", node->layout.dimensions[CSSDimensionHeight]); - CSSLog(CSSLogLevelDebug, "top: %g, ", node->layout.position[CSSEdgeTop]); - CSSLog(CSSLogLevelDebug, "left: %g", node->layout.position[CSSEdgeLeft]); - CSSLog(CSSLogLevelDebug, "}, "); + if (options & YGPrintOptionsLayout) { + CSSLog(YGLogLevelDebug, "layout: {"); + CSSLog(YGLogLevelDebug, "width: %g, ", node->layout.dimensions[YGDimensionWidth]); + CSSLog(YGLogLevelDebug, "height: %g, ", node->layout.dimensions[YGDimensionHeight]); + CSSLog(YGLogLevelDebug, "top: %g, ", node->layout.position[YGEdgeTop]); + CSSLog(YGLogLevelDebug, "left: %g", node->layout.position[YGEdgeLeft]); + CSSLog(YGLogLevelDebug, "}, "); } - if (options & CSSPrintOptionsStyle) { - if (node->style.flexDirection == CSSFlexDirectionColumn) { - CSSLog(CSSLogLevelDebug, "flexDirection: 'column', "); - } else if (node->style.flexDirection == CSSFlexDirectionColumnReverse) { - CSSLog(CSSLogLevelDebug, "flexDirection: 'column-reverse', "); - } else if (node->style.flexDirection == CSSFlexDirectionRow) { - CSSLog(CSSLogLevelDebug, "flexDirection: 'row', "); - } else if (node->style.flexDirection == CSSFlexDirectionRowReverse) { - CSSLog(CSSLogLevelDebug, "flexDirection: 'row-reverse', "); + if (options & YGPrintOptionsStyle) { + if (node->style.flexDirection == YGFlexDirectionColumn) { + CSSLog(YGLogLevelDebug, "flexDirection: 'column', "); + } else if (node->style.flexDirection == YGFlexDirectionColumnReverse) { + CSSLog(YGLogLevelDebug, "flexDirection: 'column-reverse', "); + } else if (node->style.flexDirection == YGFlexDirectionRow) { + CSSLog(YGLogLevelDebug, "flexDirection: 'row', "); + } else if (node->style.flexDirection == YGFlexDirectionRowReverse) { + CSSLog(YGLogLevelDebug, "flexDirection: 'row-reverse', "); } - if (node->style.justifyContent == CSSJustifyCenter) { - CSSLog(CSSLogLevelDebug, "justifyContent: 'center', "); - } else if (node->style.justifyContent == CSSJustifyFlexEnd) { - CSSLog(CSSLogLevelDebug, "justifyContent: 'flex-end', "); - } else if (node->style.justifyContent == CSSJustifySpaceAround) { - CSSLog(CSSLogLevelDebug, "justifyContent: 'space-around', "); - } else if (node->style.justifyContent == CSSJustifySpaceBetween) { - CSSLog(CSSLogLevelDebug, "justifyContent: 'space-between', "); + if (node->style.justifyContent == YGJustifyCenter) { + CSSLog(YGLogLevelDebug, "justifyContent: 'center', "); + } else if (node->style.justifyContent == YGJustifyFlexEnd) { + CSSLog(YGLogLevelDebug, "justifyContent: 'flex-end', "); + } else if (node->style.justifyContent == YGJustifySpaceAround) { + CSSLog(YGLogLevelDebug, "justifyContent: 'space-around', "); + } else if (node->style.justifyContent == YGJustifySpaceBetween) { + CSSLog(YGLogLevelDebug, "justifyContent: 'space-between', "); } - if (node->style.alignItems == CSSAlignCenter) { - CSSLog(CSSLogLevelDebug, "alignItems: 'center', "); - } else if (node->style.alignItems == CSSAlignFlexEnd) { - CSSLog(CSSLogLevelDebug, "alignItems: 'flex-end', "); - } else if (node->style.alignItems == CSSAlignStretch) { - CSSLog(CSSLogLevelDebug, "alignItems: 'stretch', "); + if (node->style.alignItems == YGAlignCenter) { + CSSLog(YGLogLevelDebug, "alignItems: 'center', "); + } else if (node->style.alignItems == YGAlignFlexEnd) { + CSSLog(YGLogLevelDebug, "alignItems: 'flex-end', "); + } else if (node->style.alignItems == YGAlignStretch) { + CSSLog(YGLogLevelDebug, "alignItems: 'stretch', "); } - if (node->style.alignContent == CSSAlignCenter) { - CSSLog(CSSLogLevelDebug, "alignContent: 'center', "); - } else if (node->style.alignContent == CSSAlignFlexEnd) { - CSSLog(CSSLogLevelDebug, "alignContent: 'flex-end', "); - } else if (node->style.alignContent == CSSAlignStretch) { - CSSLog(CSSLogLevelDebug, "alignContent: 'stretch', "); + if (node->style.alignContent == YGAlignCenter) { + CSSLog(YGLogLevelDebug, "alignContent: 'center', "); + } else if (node->style.alignContent == YGAlignFlexEnd) { + CSSLog(YGLogLevelDebug, "alignContent: 'flex-end', "); + } else if (node->style.alignContent == YGAlignStretch) { + CSSLog(YGLogLevelDebug, "alignContent: 'stretch', "); } - if (node->style.alignSelf == CSSAlignFlexStart) { - CSSLog(CSSLogLevelDebug, "alignSelf: 'flex-start', "); - } else if (node->style.alignSelf == CSSAlignCenter) { - CSSLog(CSSLogLevelDebug, "alignSelf: 'center', "); - } else if (node->style.alignSelf == CSSAlignFlexEnd) { - CSSLog(CSSLogLevelDebug, "alignSelf: 'flex-end', "); - } else if (node->style.alignSelf == CSSAlignStretch) { - CSSLog(CSSLogLevelDebug, "alignSelf: 'stretch', "); + if (node->style.alignSelf == YGAlignFlexStart) { + CSSLog(YGLogLevelDebug, "alignSelf: 'flex-start', "); + } else if (node->style.alignSelf == YGAlignCenter) { + CSSLog(YGLogLevelDebug, "alignSelf: 'center', "); + } else if (node->style.alignSelf == YGAlignFlexEnd) { + CSSLog(YGLogLevelDebug, "alignSelf: 'flex-end', "); + } else if (node->style.alignSelf == YGAlignStretch) { + CSSLog(YGLogLevelDebug, "alignSelf: 'stretch', "); } printNumberIfNotUndefined("flexGrow", CSSNodeStyleGetFlexGrow(node)); printNumberIfNotUndefined("flexShrink", CSSNodeStyleGetFlexShrink(node)); printNumberIfNotUndefined("flexBasis", CSSNodeStyleGetFlexBasis(node)); - if (node->style.overflow == CSSOverflowHidden) { - CSSLog(CSSLogLevelDebug, "overflow: 'hidden', "); - } else if (node->style.overflow == CSSOverflowVisible) { - CSSLog(CSSLogLevelDebug, "overflow: 'visible', "); - } else if (node->style.overflow == CSSOverflowScroll) { - CSSLog(CSSLogLevelDebug, "overflow: 'scroll', "); + if (node->style.overflow == YGOverflowHidden) { + CSSLog(YGLogLevelDebug, "overflow: 'hidden', "); + } else if (node->style.overflow == YGOverflowVisible) { + CSSLog(YGLogLevelDebug, "overflow: 'visible', "); + } else if (node->style.overflow == YGOverflowScroll) { + CSSLog(YGLogLevelDebug, "overflow: 'scroll', "); } if (eqFour(node->style.margin)) { - printNumberIfNotZero("margin", computedEdgeValue(node->style.margin, CSSEdgeLeft, 0)); + printNumberIfNotZero("margin", computedEdgeValue(node->style.margin, YGEdgeLeft, 0)); } else { - printNumberIfNotZero("marginLeft", computedEdgeValue(node->style.margin, CSSEdgeLeft, 0)); - printNumberIfNotZero("marginRight", computedEdgeValue(node->style.margin, CSSEdgeRight, 0)); - printNumberIfNotZero("marginTop", computedEdgeValue(node->style.margin, CSSEdgeTop, 0)); - printNumberIfNotZero("marginBottom", computedEdgeValue(node->style.margin, CSSEdgeBottom, 0)); - printNumberIfNotZero("marginStart", computedEdgeValue(node->style.margin, CSSEdgeStart, 0)); - printNumberIfNotZero("marginEnd", computedEdgeValue(node->style.margin, CSSEdgeEnd, 0)); + printNumberIfNotZero("marginLeft", computedEdgeValue(node->style.margin, YGEdgeLeft, 0)); + printNumberIfNotZero("marginRight", computedEdgeValue(node->style.margin, YGEdgeRight, 0)); + printNumberIfNotZero("marginTop", computedEdgeValue(node->style.margin, YGEdgeTop, 0)); + printNumberIfNotZero("marginBottom", computedEdgeValue(node->style.margin, YGEdgeBottom, 0)); + printNumberIfNotZero("marginStart", computedEdgeValue(node->style.margin, YGEdgeStart, 0)); + printNumberIfNotZero("marginEnd", computedEdgeValue(node->style.margin, YGEdgeEnd, 0)); } if (eqFour(node->style.padding)) { - printNumberIfNotZero("padding", computedEdgeValue(node->style.padding, CSSEdgeLeft, 0)); + printNumberIfNotZero("padding", computedEdgeValue(node->style.padding, YGEdgeLeft, 0)); } else { - printNumberIfNotZero("paddingLeft", computedEdgeValue(node->style.padding, CSSEdgeLeft, 0)); - printNumberIfNotZero("paddingRight", computedEdgeValue(node->style.padding, CSSEdgeRight, 0)); - printNumberIfNotZero("paddingTop", computedEdgeValue(node->style.padding, CSSEdgeTop, 0)); + printNumberIfNotZero("paddingLeft", computedEdgeValue(node->style.padding, YGEdgeLeft, 0)); + printNumberIfNotZero("paddingRight", computedEdgeValue(node->style.padding, YGEdgeRight, 0)); + printNumberIfNotZero("paddingTop", computedEdgeValue(node->style.padding, YGEdgeTop, 0)); printNumberIfNotZero("paddingBottom", - computedEdgeValue(node->style.padding, CSSEdgeBottom, 0)); - printNumberIfNotZero("paddingStart", computedEdgeValue(node->style.padding, CSSEdgeStart, 0)); - printNumberIfNotZero("paddingEnd", computedEdgeValue(node->style.padding, CSSEdgeEnd, 0)); + computedEdgeValue(node->style.padding, YGEdgeBottom, 0)); + printNumberIfNotZero("paddingStart", computedEdgeValue(node->style.padding, YGEdgeStart, 0)); + printNumberIfNotZero("paddingEnd", computedEdgeValue(node->style.padding, YGEdgeEnd, 0)); } if (eqFour(node->style.border)) { - printNumberIfNotZero("borderWidth", computedEdgeValue(node->style.border, CSSEdgeLeft, 0)); + printNumberIfNotZero("borderWidth", computedEdgeValue(node->style.border, YGEdgeLeft, 0)); } else { - printNumberIfNotZero("borderLeftWidth", - computedEdgeValue(node->style.border, CSSEdgeLeft, 0)); + printNumberIfNotZero("borderLeftWidth", computedEdgeValue(node->style.border, YGEdgeLeft, 0)); printNumberIfNotZero("borderRightWidth", - computedEdgeValue(node->style.border, CSSEdgeRight, 0)); - printNumberIfNotZero("borderTopWidth", computedEdgeValue(node->style.border, CSSEdgeTop, 0)); + computedEdgeValue(node->style.border, YGEdgeRight, 0)); + printNumberIfNotZero("borderTopWidth", computedEdgeValue(node->style.border, YGEdgeTop, 0)); printNumberIfNotZero("borderBottomWidth", - computedEdgeValue(node->style.border, CSSEdgeBottom, 0)); + computedEdgeValue(node->style.border, YGEdgeBottom, 0)); printNumberIfNotZero("borderStartWidth", - computedEdgeValue(node->style.border, CSSEdgeStart, 0)); - printNumberIfNotZero("borderEndWidth", computedEdgeValue(node->style.border, CSSEdgeEnd, 0)); + computedEdgeValue(node->style.border, YGEdgeStart, 0)); + printNumberIfNotZero("borderEndWidth", computedEdgeValue(node->style.border, YGEdgeEnd, 0)); } - printNumberIfNotUndefined("width", node->style.dimensions[CSSDimensionWidth]); - printNumberIfNotUndefined("height", node->style.dimensions[CSSDimensionHeight]); - printNumberIfNotUndefined("maxWidth", node->style.maxDimensions[CSSDimensionWidth]); - printNumberIfNotUndefined("maxHeight", node->style.maxDimensions[CSSDimensionHeight]); - printNumberIfNotUndefined("minWidth", node->style.minDimensions[CSSDimensionWidth]); - printNumberIfNotUndefined("minHeight", node->style.minDimensions[CSSDimensionHeight]); + printNumberIfNotUndefined("width", node->style.dimensions[YGDimensionWidth]); + printNumberIfNotUndefined("height", node->style.dimensions[YGDimensionHeight]); + printNumberIfNotUndefined("maxWidth", node->style.maxDimensions[YGDimensionWidth]); + printNumberIfNotUndefined("maxHeight", node->style.maxDimensions[YGDimensionHeight]); + printNumberIfNotUndefined("minWidth", node->style.minDimensions[YGDimensionWidth]); + printNumberIfNotUndefined("minHeight", node->style.minDimensions[YGDimensionHeight]); - if (node->style.positionType == CSSPositionTypeAbsolute) { - CSSLog(CSSLogLevelDebug, "position: 'absolute', "); + if (node->style.positionType == YGPositionTypeAbsolute) { + CSSLog(YGLogLevelDebug, "position: 'absolute', "); } printNumberIfNotUndefined("left", - computedEdgeValue(node->style.position, CSSEdgeLeft, CSSUndefined)); + computedEdgeValue(node->style.position, YGEdgeLeft, YGUndefined)); printNumberIfNotUndefined("right", - computedEdgeValue(node->style.position, CSSEdgeRight, CSSUndefined)); + computedEdgeValue(node->style.position, YGEdgeRight, YGUndefined)); printNumberIfNotUndefined("top", - computedEdgeValue(node->style.position, CSSEdgeTop, CSSUndefined)); + computedEdgeValue(node->style.position, YGEdgeTop, YGUndefined)); printNumberIfNotUndefined("bottom", - computedEdgeValue(node->style.position, CSSEdgeBottom, CSSUndefined)); + computedEdgeValue(node->style.position, YGEdgeBottom, YGUndefined)); } const uint32_t childCount = CSSNodeListCount(node->children); - if (options & CSSPrintOptionsChildren && childCount > 0) { - CSSLog(CSSLogLevelDebug, "children: [\n"); + if (options & YGPrintOptionsChildren && childCount > 0) { + CSSLog(YGLogLevelDebug, "children: [\n"); for (uint32_t i = 0; i < childCount; i++) { _CSSNodePrint(CSSNodeGetChild(node, i), options, level + 1); } indent(level); - CSSLog(CSSLogLevelDebug, "]},\n"); + CSSLog(YGLogLevelDebug, "]},\n"); } else { - CSSLog(CSSLogLevelDebug, "},\n"); + CSSLog(YGLogLevelDebug, "},\n"); } } -void CSSNodePrint(const CSSNodeRef node, const CSSPrintOptions options) { +void CSSNodePrint(const CSSNodeRef node, const YGPrintOptions options) { _CSSNodePrint(node, options, 0); } -static const CSSEdge leading[4] = { - [CSSFlexDirectionColumn] = CSSEdgeTop, - [CSSFlexDirectionColumnReverse] = CSSEdgeBottom, - [CSSFlexDirectionRow] = CSSEdgeLeft, - [CSSFlexDirectionRowReverse] = CSSEdgeRight, +static const YGEdge leading[4] = { + [YGFlexDirectionColumn] = YGEdgeTop, + [YGFlexDirectionColumnReverse] = YGEdgeBottom, + [YGFlexDirectionRow] = YGEdgeLeft, + [YGFlexDirectionRowReverse] = YGEdgeRight, }; -static const CSSEdge trailing[4] = { - [CSSFlexDirectionColumn] = CSSEdgeBottom, - [CSSFlexDirectionColumnReverse] = CSSEdgeTop, - [CSSFlexDirectionRow] = CSSEdgeRight, - [CSSFlexDirectionRowReverse] = CSSEdgeLeft, +static const YGEdge trailing[4] = { + [YGFlexDirectionColumn] = YGEdgeBottom, + [YGFlexDirectionColumnReverse] = YGEdgeTop, + [YGFlexDirectionRow] = YGEdgeRight, + [YGFlexDirectionRowReverse] = YGEdgeLeft, }; -static const CSSEdge pos[4] = { - [CSSFlexDirectionColumn] = CSSEdgeTop, - [CSSFlexDirectionColumnReverse] = CSSEdgeBottom, - [CSSFlexDirectionRow] = CSSEdgeLeft, - [CSSFlexDirectionRowReverse] = CSSEdgeRight, +static const YGEdge pos[4] = { + [YGFlexDirectionColumn] = YGEdgeTop, + [YGFlexDirectionColumnReverse] = YGEdgeBottom, + [YGFlexDirectionRow] = YGEdgeLeft, + [YGFlexDirectionRowReverse] = YGEdgeRight, }; -static const CSSDimension dim[4] = { - [CSSFlexDirectionColumn] = CSSDimensionHeight, - [CSSFlexDirectionColumnReverse] = CSSDimensionHeight, - [CSSFlexDirectionRow] = CSSDimensionWidth, - [CSSFlexDirectionRowReverse] = CSSDimensionWidth, +static const YGDimension dim[4] = { + [YGFlexDirectionColumn] = YGDimensionHeight, + [YGFlexDirectionColumnReverse] = YGDimensionHeight, + [YGFlexDirectionRow] = YGDimensionWidth, + [YGFlexDirectionRowReverse] = YGDimensionWidth, }; -static inline bool isRowDirection(const CSSFlexDirection flexDirection) { - return flexDirection == CSSFlexDirectionRow || flexDirection == CSSFlexDirectionRowReverse; +static inline bool isRowDirection(const YGFlexDirection flexDirection) { + return flexDirection == YGFlexDirectionRow || flexDirection == YGFlexDirectionRowReverse; } -static inline bool isColumnDirection(const CSSFlexDirection flexDirection) { - return flexDirection == CSSFlexDirectionColumn || flexDirection == CSSFlexDirectionColumnReverse; +static inline bool isColumnDirection(const YGFlexDirection flexDirection) { + return flexDirection == YGFlexDirectionColumn || flexDirection == YGFlexDirectionColumnReverse; } -static inline float getLeadingMargin(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[CSSEdgeStart])) { - return node->style.margin[CSSEdgeStart]; +static inline float getLeadingMargin(const CSSNodeRef node, const YGFlexDirection axis) { + if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[YGEdgeStart])) { + return node->style.margin[YGEdgeStart]; } return computedEdgeValue(node->style.margin, leading[axis], 0); } -static float getTrailingMargin(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[CSSEdgeEnd])) { - return node->style.margin[CSSEdgeEnd]; +static float getTrailingMargin(const CSSNodeRef node, const YGFlexDirection axis) { + if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[YGEdgeEnd])) { + return node->style.margin[YGEdgeEnd]; } return computedEdgeValue(node->style.margin, trailing[axis], 0); } -static float getLeadingPadding(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[CSSEdgeStart]) && - node->style.padding[CSSEdgeStart] >= 0) { - return node->style.padding[CSSEdgeStart]; +static float getLeadingPadding(const CSSNodeRef node, const YGFlexDirection axis) { + if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[YGEdgeStart]) && + node->style.padding[YGEdgeStart] >= 0) { + return node->style.padding[YGEdgeStart]; } return fmaxf(computedEdgeValue(node->style.padding, leading[axis], 0), 0); } -static float getTrailingPadding(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[CSSEdgeEnd]) && - node->style.padding[CSSEdgeEnd] >= 0) { - return node->style.padding[CSSEdgeEnd]; +static float getTrailingPadding(const CSSNodeRef node, const YGFlexDirection axis) { + if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[YGEdgeEnd]) && + node->style.padding[YGEdgeEnd] >= 0) { + return node->style.padding[YGEdgeEnd]; } return fmaxf(computedEdgeValue(node->style.padding, trailing[axis], 0), 0); } -static float getLeadingBorder(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[CSSEdgeStart]) && - node->style.border[CSSEdgeStart] >= 0) { - return node->style.border[CSSEdgeStart]; +static float getLeadingBorder(const CSSNodeRef node, const YGFlexDirection axis) { + if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[YGEdgeStart]) && + node->style.border[YGEdgeStart] >= 0) { + return node->style.border[YGEdgeStart]; } return fmaxf(computedEdgeValue(node->style.border, leading[axis], 0), 0); } -static float getTrailingBorder(const CSSNodeRef node, const CSSFlexDirection axis) { - if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[CSSEdgeEnd]) && - node->style.border[CSSEdgeEnd] >= 0) { - return node->style.border[CSSEdgeEnd]; +static float getTrailingBorder(const CSSNodeRef node, const YGFlexDirection axis) { + if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[YGEdgeEnd]) && + node->style.border[YGEdgeEnd] >= 0) { + return node->style.border[YGEdgeEnd]; } return fmaxf(computedEdgeValue(node->style.border, trailing[axis], 0), 0); } -static inline float getLeadingPaddingAndBorder(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline float getLeadingPaddingAndBorder(const CSSNodeRef node, const YGFlexDirection axis) { return getLeadingPadding(node, axis) + getLeadingBorder(node, axis); } -static inline float getTrailingPaddingAndBorder(const CSSNodeRef node, - const CSSFlexDirection axis) { +static inline float getTrailingPaddingAndBorder(const CSSNodeRef node, const YGFlexDirection axis) { return getTrailingPadding(node, axis) + getTrailingBorder(node, axis); } -static inline float getMarginAxis(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline float getMarginAxis(const CSSNodeRef node, const YGFlexDirection axis) { return getLeadingMargin(node, axis) + getTrailingMargin(node, axis); } -static inline float getPaddingAndBorderAxis(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline float getPaddingAndBorderAxis(const CSSNodeRef node, const YGFlexDirection axis) { return getLeadingPaddingAndBorder(node, axis) + getTrailingPaddingAndBorder(node, axis); } -static inline CSSAlign getAlignItem(const CSSNodeRef node, const CSSNodeRef child) { - return child->style.alignSelf == CSSAlignAuto ? node->style.alignItems : child->style.alignSelf; +static inline YGAlign getAlignItem(const CSSNodeRef node, const CSSNodeRef child) { + return child->style.alignSelf == YGAlignAuto ? node->style.alignItems : child->style.alignSelf; } -static inline CSSDirection resolveDirection(const CSSNodeRef node, - const CSSDirection parentDirection) { - if (node->style.direction == CSSDirectionInherit) { - return parentDirection > CSSDirectionInherit ? parentDirection : CSSDirectionLTR; +static inline YGDirection resolveDirection(const CSSNodeRef node, + const YGDirection parentDirection) { + if (node->style.direction == YGDirectionInherit) { + return parentDirection > YGDirectionInherit ? parentDirection : YGDirectionLTR; } else { return node->style.direction; } } -static inline CSSFlexDirection resolveAxis(const CSSFlexDirection flexDirection, - const CSSDirection direction) { - if (direction == CSSDirectionRTL) { - if (flexDirection == CSSFlexDirectionRow) { - return CSSFlexDirectionRowReverse; - } else if (flexDirection == CSSFlexDirectionRowReverse) { - return CSSFlexDirectionRow; +static inline YGFlexDirection resolveAxis(const YGFlexDirection flexDirection, + const YGDirection direction) { + if (direction == YGDirectionRTL) { + if (flexDirection == YGFlexDirectionRow) { + return YGFlexDirectionRowReverse; + } else if (flexDirection == YGFlexDirectionRowReverse) { + return YGFlexDirectionRow; } } return flexDirection; } -static CSSFlexDirection getCrossFlexDirection(const CSSFlexDirection flexDirection, - const CSSDirection direction) { - return isColumnDirection(flexDirection) ? resolveAxis(CSSFlexDirectionRow, direction) - : CSSFlexDirectionColumn; +static YGFlexDirection getCrossFlexDirection(const YGFlexDirection flexDirection, + const YGDirection direction) { + return isColumnDirection(flexDirection) ? resolveAxis(YGFlexDirectionRow, direction) + : YGFlexDirectionColumn; } static inline bool isFlex(const CSSNodeRef node) { - return (node->style.positionType == CSSPositionTypeRelative && + return (node->style.positionType == YGPositionTypeRelative && (node->style.flexGrow != 0 || node->style.flexShrink != 0 || node->style.flex != 0)); } -static inline float getDimWithMargin(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline float getDimWithMargin(const CSSNodeRef node, const YGFlexDirection axis) { return node->layout.measuredDimensions[dim[axis]] + getLeadingMargin(node, axis) + getTrailingMargin(node, axis); } -static inline bool isStyleDimDefined(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline bool isStyleDimDefined(const CSSNodeRef node, const YGFlexDirection axis) { const float value = node->style.dimensions[dim[axis]]; return !CSSValueIsUndefined(value) && value >= 0.0; } -static inline bool isLayoutDimDefined(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline bool isLayoutDimDefined(const CSSNodeRef node, const YGFlexDirection axis) { const float value = node->layout.measuredDimensions[dim[axis]]; return !CSSValueIsUndefined(value) && value >= 0.0; } -static inline bool isLeadingPosDefined(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline bool isLeadingPosDefined(const CSSNodeRef node, const YGFlexDirection axis) { return (isRowDirection(axis) && !CSSValueIsUndefined( - computedEdgeValue(node->style.position, CSSEdgeStart, CSSUndefined))) || - !CSSValueIsUndefined(computedEdgeValue(node->style.position, leading[axis], CSSUndefined)); + computedEdgeValue(node->style.position, YGEdgeStart, YGUndefined))) || + !CSSValueIsUndefined(computedEdgeValue(node->style.position, leading[axis], YGUndefined)); } -static inline bool isTrailingPosDefined(const CSSNodeRef node, const CSSFlexDirection axis) { +static inline bool isTrailingPosDefined(const CSSNodeRef node, const YGFlexDirection axis) { return (isRowDirection(axis) && - !CSSValueIsUndefined( - computedEdgeValue(node->style.position, CSSEdgeEnd, CSSUndefined))) || - !CSSValueIsUndefined( - computedEdgeValue(node->style.position, trailing[axis], CSSUndefined)); + !CSSValueIsUndefined(computedEdgeValue(node->style.position, YGEdgeEnd, YGUndefined))) || + !CSSValueIsUndefined(computedEdgeValue(node->style.position, trailing[axis], YGUndefined)); } -static float getLeadingPosition(const CSSNodeRef node, const CSSFlexDirection axis) { +static float getLeadingPosition(const CSSNodeRef node, const YGFlexDirection axis) { if (isRowDirection(axis)) { - const float leadingPosition = - computedEdgeValue(node->style.position, CSSEdgeStart, CSSUndefined); + const float leadingPosition = computedEdgeValue(node->style.position, YGEdgeStart, YGUndefined); if (!CSSValueIsUndefined(leadingPosition)) { return leadingPosition; } } - const float leadingPosition = - computedEdgeValue(node->style.position, leading[axis], CSSUndefined); + const float leadingPosition = computedEdgeValue(node->style.position, leading[axis], YGUndefined); return CSSValueIsUndefined(leadingPosition) ? 0 : leadingPosition; } -static float getTrailingPosition(const CSSNodeRef node, const CSSFlexDirection axis) { +static float getTrailingPosition(const CSSNodeRef node, const YGFlexDirection axis) { if (isRowDirection(axis)) { - const float trailingPosition = - computedEdgeValue(node->style.position, CSSEdgeEnd, CSSUndefined); + const float trailingPosition = computedEdgeValue(node->style.position, YGEdgeEnd, YGUndefined); if (!CSSValueIsUndefined(trailingPosition)) { return trailingPosition; } } const float trailingPosition = - computedEdgeValue(node->style.position, trailing[axis], CSSUndefined); + computedEdgeValue(node->style.position, trailing[axis], YGUndefined); return CSSValueIsUndefined(trailingPosition) ? 0 : trailingPosition; } static float boundAxisWithinMinAndMax(const CSSNodeRef node, - const CSSFlexDirection axis, + const YGFlexDirection axis, const float value) { - float min = CSSUndefined; - float max = CSSUndefined; + float min = YGUndefined; + float max = YGUndefined; if (isColumnDirection(axis)) { - min = node->style.minDimensions[CSSDimensionHeight]; - max = node->style.maxDimensions[CSSDimensionHeight]; + min = node->style.minDimensions[YGDimensionHeight]; + max = node->style.maxDimensions[YGDimensionHeight]; } else if (isRowDirection(axis)) { - min = node->style.minDimensions[CSSDimensionWidth]; - max = node->style.maxDimensions[CSSDimensionWidth]; + min = node->style.minDimensions[YGDimensionWidth]; + max = node->style.maxDimensions[YGDimensionWidth]; } float boundValue = value; @@ -903,14 +895,14 @@ static float boundAxisWithinMinAndMax(const CSSNodeRef node, // below the // padding and border amount. static inline float boundAxis(const CSSNodeRef node, - const CSSFlexDirection axis, + const YGFlexDirection axis, const float value) { return fmaxf(boundAxisWithinMinAndMax(node, axis, value), getPaddingAndBorderAxis(node, axis)); } static void setTrailingPosition(const CSSNodeRef node, const CSSNodeRef child, - const CSSFlexDirection axis) { + const YGFlexDirection axis) { const float size = child->layout.measuredDimensions[dim[axis]]; child->layout.position[trailing[axis]] = node->layout.measuredDimensions[dim[axis]] - size - child->layout.position[pos[axis]]; @@ -918,31 +910,31 @@ static void setTrailingPosition(const CSSNodeRef node, // If both left and right are defined, then use left. Otherwise return // +left or -right depending on which is defined. -static float getRelativePosition(const CSSNodeRef node, const CSSFlexDirection axis) { +static float getRelativePosition(const CSSNodeRef node, const YGFlexDirection axis) { return isLeadingPosDefined(node, axis) ? getLeadingPosition(node, axis) : -getTrailingPosition(node, axis); } -static void constrainMaxSizeForMode(const float maxSize, CSSMeasureMode *mode, float *size) { +static void constrainMaxSizeForMode(const float maxSize, YGMeasureMode *mode, float *size) { switch (*mode) { - case CSSMeasureModeExactly: - case CSSMeasureModeAtMost: + case YGMeasureModeExactly: + case YGMeasureModeAtMost: *size = (CSSValueIsUndefined(maxSize) || *size < maxSize) ? *size : maxSize; break; - case CSSMeasureModeUndefined: + case YGMeasureModeUndefined: if (!CSSValueIsUndefined(maxSize)) { - *mode = CSSMeasureModeAtMost; + *mode = YGMeasureModeAtMost; *size = maxSize; } break; - case CSSMeasureModeCount: + case YGMeasureModeCount: break; } } -static void setPosition(const CSSNodeRef node, const CSSDirection direction) { - const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); - const CSSFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); +static void setPosition(const CSSNodeRef node, const YGDirection direction) { + const YGFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); + const YGFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); const float relativePositionMain = getRelativePosition(node, mainAxis); const float relativePositionCross = getRelativePosition(node, crossAxis); @@ -959,71 +951,71 @@ static void setPosition(const CSSNodeRef node, const CSSDirection direction) { static void computeChildFlexBasis(const CSSNodeRef node, const CSSNodeRef child, const float width, - const CSSMeasureMode widthMode, + const YGMeasureMode widthMode, const float height, - const CSSMeasureMode heightMode, - const CSSDirection direction) { - const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); + const YGMeasureMode heightMode, + const YGDirection direction) { + const YGFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); const bool isMainAxisRow = isRowDirection(mainAxis); float childWidth; float childHeight; - CSSMeasureMode childWidthMeasureMode; - CSSMeasureMode childHeightMeasureMode; + YGMeasureMode childWidthMeasureMode; + YGMeasureMode childHeightMeasureMode; - const bool isRowStyleDimDefined = isStyleDimDefined(child, CSSFlexDirectionRow); - const bool isColumnStyleDimDefined = isStyleDimDefined(child, CSSFlexDirectionColumn); + const bool isRowStyleDimDefined = isStyleDimDefined(child, YGFlexDirectionRow); + const bool isColumnStyleDimDefined = isStyleDimDefined(child, YGFlexDirectionColumn); if (!CSSValueIsUndefined(CSSNodeStyleGetFlexBasis(child)) && !CSSValueIsUndefined(isMainAxisRow ? width : height)) { if (CSSValueIsUndefined(child->layout.computedFlexBasis) || - (CSSLayoutIsExperimentalFeatureEnabled(CSSExperimentalFeatureWebFlexBasis) && + (CSSLayoutIsExperimentalFeatureEnabled(YGExperimentalFeatureWebFlexBasis) && child->layout.computedFlexBasisGeneration != gCurrentGenerationCount)) { child->layout.computedFlexBasis = fmaxf(CSSNodeStyleGetFlexBasis(child), getPaddingAndBorderAxis(child, mainAxis)); } } else if (isMainAxisRow && isRowStyleDimDefined) { // The width is definite, so use that as the flex basis. - child->layout.computedFlexBasis = fmaxf(child->style.dimensions[CSSDimensionWidth], - getPaddingAndBorderAxis(child, CSSFlexDirectionRow)); + child->layout.computedFlexBasis = fmaxf(child->style.dimensions[YGDimensionWidth], + getPaddingAndBorderAxis(child, YGFlexDirectionRow)); } else if (!isMainAxisRow && isColumnStyleDimDefined) { // The height is definite, so use that as the flex basis. - child->layout.computedFlexBasis = fmaxf(child->style.dimensions[CSSDimensionHeight], - getPaddingAndBorderAxis(child, CSSFlexDirectionColumn)); + child->layout.computedFlexBasis = fmaxf(child->style.dimensions[YGDimensionHeight], + getPaddingAndBorderAxis(child, YGFlexDirectionColumn)); } else { // Compute the flex basis and hypothetical main size (i.e. the clamped // flex basis). - childWidth = CSSUndefined; - childHeight = CSSUndefined; - childWidthMeasureMode = CSSMeasureModeUndefined; - childHeightMeasureMode = CSSMeasureModeUndefined; + childWidth = YGUndefined; + childHeight = YGUndefined; + childWidthMeasureMode = YGMeasureModeUndefined; + childHeightMeasureMode = YGMeasureModeUndefined; if (isRowStyleDimDefined) { childWidth = - child->style.dimensions[CSSDimensionWidth] + getMarginAxis(child, CSSFlexDirectionRow); - childWidthMeasureMode = CSSMeasureModeExactly; + child->style.dimensions[YGDimensionWidth] + getMarginAxis(child, YGFlexDirectionRow); + childWidthMeasureMode = YGMeasureModeExactly; } if (isColumnStyleDimDefined) { - childHeight = child->style.dimensions[CSSDimensionHeight] + - getMarginAxis(child, CSSFlexDirectionColumn); - childHeightMeasureMode = CSSMeasureModeExactly; + childHeight = + child->style.dimensions[YGDimensionHeight] + getMarginAxis(child, YGFlexDirectionColumn); + childHeightMeasureMode = YGMeasureModeExactly; } // The W3C spec doesn't say anything about the 'overflow' property, // but all major browsers appear to implement the following logic. - if ((!isMainAxisRow && node->style.overflow == CSSOverflowScroll) || - node->style.overflow != CSSOverflowScroll) { + if ((!isMainAxisRow && node->style.overflow == YGOverflowScroll) || + node->style.overflow != YGOverflowScroll) { if (CSSValueIsUndefined(childWidth) && !CSSValueIsUndefined(width)) { childWidth = width; - childWidthMeasureMode = CSSMeasureModeAtMost; + childWidthMeasureMode = YGMeasureModeAtMost; } } - if ((isMainAxisRow && node->style.overflow == CSSOverflowScroll) || - node->style.overflow != CSSOverflowScroll) { + if ((isMainAxisRow && node->style.overflow == YGOverflowScroll) || + node->style.overflow != YGOverflowScroll) { if (CSSValueIsUndefined(childHeight) && !CSSValueIsUndefined(height)) { childHeight = height; - childHeightMeasureMode = CSSMeasureModeAtMost; + childHeightMeasureMode = YGMeasureModeAtMost; } } @@ -1031,34 +1023,33 @@ static void computeChildFlexBasis(const CSSNodeRef node, // set the cross // axis to be measured exactly with the available inner width if (!isMainAxisRow && !CSSValueIsUndefined(width) && !isRowStyleDimDefined && - widthMode == CSSMeasureModeExactly && getAlignItem(node, child) == CSSAlignStretch) { + widthMode == YGMeasureModeExactly && getAlignItem(node, child) == YGAlignStretch) { childWidth = width; - childWidthMeasureMode = CSSMeasureModeExactly; + childWidthMeasureMode = YGMeasureModeExactly; } if (isMainAxisRow && !CSSValueIsUndefined(height) && !isColumnStyleDimDefined && - heightMode == CSSMeasureModeExactly && getAlignItem(node, child) == CSSAlignStretch) { + heightMode == YGMeasureModeExactly && getAlignItem(node, child) == YGAlignStretch) { childHeight = height; - childHeightMeasureMode = CSSMeasureModeExactly; + childHeightMeasureMode = YGMeasureModeExactly; } if (!CSSValueIsUndefined(child->style.aspectRatio)) { - if (!isMainAxisRow && childWidthMeasureMode == CSSMeasureModeExactly) { + if (!isMainAxisRow && childWidthMeasureMode == YGMeasureModeExactly) { child->layout.computedFlexBasis = fmaxf(childWidth * child->style.aspectRatio, - getPaddingAndBorderAxis(child, CSSFlexDirectionColumn)); + getPaddingAndBorderAxis(child, YGFlexDirectionColumn)); return; - } else if (isMainAxisRow && childHeightMeasureMode == CSSMeasureModeExactly) { - child->layout.computedFlexBasis = - fmaxf(childHeight * child->style.aspectRatio, - getPaddingAndBorderAxis(child, CSSFlexDirectionRow)); + } else if (isMainAxisRow && childHeightMeasureMode == YGMeasureModeExactly) { + child->layout.computedFlexBasis = fmaxf(childHeight * child->style.aspectRatio, + getPaddingAndBorderAxis(child, YGFlexDirectionRow)); return; } } - constrainMaxSizeForMode(child->style.maxDimensions[CSSDimensionWidth], + constrainMaxSizeForMode(child->style.maxDimensions[YGDimensionWidth], &childWidthMeasureMode, &childWidth); - constrainMaxSizeForMode(child->style.maxDimensions[CSSDimensionHeight], + constrainMaxSizeForMode(child->style.maxDimensions[YGDimensionHeight], &childHeightMeasureMode, &childHeight); @@ -1073,8 +1064,8 @@ static void computeChildFlexBasis(const CSSNodeRef node, "measure"); child->layout.computedFlexBasis = - fmaxf(isMainAxisRow ? child->layout.measuredDimensions[CSSDimensionWidth] - : child->layout.measuredDimensions[CSSDimensionHeight], + fmaxf(isMainAxisRow ? child->layout.measuredDimensions[YGDimensionWidth] + : child->layout.measuredDimensions[YGDimensionHeight], getPaddingAndBorderAxis(child, mainAxis)); } @@ -1084,50 +1075,50 @@ static void computeChildFlexBasis(const CSSNodeRef node, static void absoluteLayoutChild(const CSSNodeRef node, const CSSNodeRef child, const float width, - const CSSMeasureMode widthMode, - const CSSDirection direction) { - const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); - const CSSFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); + const YGMeasureMode widthMode, + const YGDirection direction) { + const YGFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); + const YGFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); const bool isMainAxisRow = isRowDirection(mainAxis); - float childWidth = CSSUndefined; - float childHeight = CSSUndefined; - CSSMeasureMode childWidthMeasureMode = CSSMeasureModeUndefined; - CSSMeasureMode childHeightMeasureMode = CSSMeasureModeUndefined; + float childWidth = YGUndefined; + float childHeight = YGUndefined; + YGMeasureMode childWidthMeasureMode = YGMeasureModeUndefined; + YGMeasureMode childHeightMeasureMode = YGMeasureModeUndefined; - if (isStyleDimDefined(child, CSSFlexDirectionRow)) { + if (isStyleDimDefined(child, YGFlexDirectionRow)) { childWidth = - child->style.dimensions[CSSDimensionWidth] + getMarginAxis(child, CSSFlexDirectionRow); + child->style.dimensions[YGDimensionWidth] + getMarginAxis(child, YGFlexDirectionRow); } else { // If the child doesn't have a specified width, compute the width based // on the left/right // offsets if they're defined. - if (isLeadingPosDefined(child, CSSFlexDirectionRow) && - isTrailingPosDefined(child, CSSFlexDirectionRow)) { - childWidth = node->layout.measuredDimensions[CSSDimensionWidth] - - (getLeadingBorder(node, CSSFlexDirectionRow) + - getTrailingBorder(node, CSSFlexDirectionRow)) - - (getLeadingPosition(child, CSSFlexDirectionRow) + - getTrailingPosition(child, CSSFlexDirectionRow)); - childWidth = boundAxis(child, CSSFlexDirectionRow, childWidth); + if (isLeadingPosDefined(child, YGFlexDirectionRow) && + isTrailingPosDefined(child, YGFlexDirectionRow)) { + childWidth = node->layout.measuredDimensions[YGDimensionWidth] - + (getLeadingBorder(node, YGFlexDirectionRow) + + getTrailingBorder(node, YGFlexDirectionRow)) - + (getLeadingPosition(child, YGFlexDirectionRow) + + getTrailingPosition(child, YGFlexDirectionRow)); + childWidth = boundAxis(child, YGFlexDirectionRow, childWidth); } } - if (isStyleDimDefined(child, CSSFlexDirectionColumn)) { + if (isStyleDimDefined(child, YGFlexDirectionColumn)) { childHeight = - child->style.dimensions[CSSDimensionHeight] + getMarginAxis(child, CSSFlexDirectionColumn); + child->style.dimensions[YGDimensionHeight] + getMarginAxis(child, YGFlexDirectionColumn); } else { // If the child doesn't have a specified height, compute the height // based on the top/bottom // offsets if they're defined. - if (isLeadingPosDefined(child, CSSFlexDirectionColumn) && - isTrailingPosDefined(child, CSSFlexDirectionColumn)) { - childHeight = node->layout.measuredDimensions[CSSDimensionHeight] - - (getLeadingBorder(node, CSSFlexDirectionColumn) + - getTrailingBorder(node, CSSFlexDirectionColumn)) - - (getLeadingPosition(child, CSSFlexDirectionColumn) + - getTrailingPosition(child, CSSFlexDirectionColumn)); - childHeight = boundAxis(child, CSSFlexDirectionColumn, childHeight); + if (isLeadingPosDefined(child, YGFlexDirectionColumn) && + isTrailingPosDefined(child, YGFlexDirectionColumn)) { + childHeight = node->layout.measuredDimensions[YGDimensionHeight] - + (getLeadingBorder(node, YGFlexDirectionColumn) + + getTrailingBorder(node, YGFlexDirectionColumn)) - + (getLeadingPosition(child, YGFlexDirectionColumn) + + getTrailingPosition(child, YGFlexDirectionColumn)); + childHeight = boundAxis(child, YGFlexDirectionColumn, childHeight); } } @@ -1137,10 +1128,10 @@ static void absoluteLayoutChild(const CSSNodeRef node, if (!CSSValueIsUndefined(child->style.aspectRatio)) { if (CSSValueIsUndefined(childWidth)) { childWidth = fmaxf(childHeight * child->style.aspectRatio, - getPaddingAndBorderAxis(child, CSSFlexDirectionColumn)); + getPaddingAndBorderAxis(child, YGFlexDirectionColumn)); } else if (CSSValueIsUndefined(childHeight)) { childHeight = fmaxf(childWidth * child->style.aspectRatio, - getPaddingAndBorderAxis(child, CSSFlexDirectionRow)); + getPaddingAndBorderAxis(child, YGFlexDirectionRow)); } } } @@ -1148,17 +1139,17 @@ static void absoluteLayoutChild(const CSSNodeRef node, // If we're still missing one or the other dimension, measure the content. if (CSSValueIsUndefined(childWidth) || CSSValueIsUndefined(childHeight)) { childWidthMeasureMode = - CSSValueIsUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeExactly; + CSSValueIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeExactly; childHeightMeasureMode = - CSSValueIsUndefined(childHeight) ? CSSMeasureModeUndefined : CSSMeasureModeExactly; + CSSValueIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeExactly; // 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 && CSSValueIsUndefined(childWidth) && widthMode != CSSMeasureModeUndefined) { + if (!isMainAxisRow && CSSValueIsUndefined(childWidth) && widthMode != YGMeasureModeUndefined) { childWidth = width; - childWidthMeasureMode = CSSMeasureModeAtMost; + childWidthMeasureMode = YGMeasureModeAtMost; } layoutNodeInternal(child, @@ -1169,18 +1160,18 @@ static void absoluteLayoutChild(const CSSNodeRef node, childHeightMeasureMode, false, "abs-measure"); - childWidth = child->layout.measuredDimensions[CSSDimensionWidth] + - getMarginAxis(child, CSSFlexDirectionRow); - childHeight = child->layout.measuredDimensions[CSSDimensionHeight] + - getMarginAxis(child, CSSFlexDirectionColumn); + childWidth = child->layout.measuredDimensions[YGDimensionWidth] + + getMarginAxis(child, YGFlexDirectionRow); + childHeight = child->layout.measuredDimensions[YGDimensionHeight] + + getMarginAxis(child, YGFlexDirectionColumn); } layoutNodeInternal(child, childWidth, childHeight, direction, - CSSMeasureModeExactly, - CSSMeasureModeExactly, + YGMeasureModeExactly, + YGMeasureModeExactly, true, "abs-layout"); @@ -1202,47 +1193,46 @@ static void absoluteLayoutChild(const CSSNodeRef node, static void setMeasuredDimensionsForNodeWithMeasureFunc(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode) { + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode) { CSS_ASSERT(node->measure, "Expected node to have custom measure function"); - const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, CSSFlexDirectionRow); - const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSSFlexDirectionColumn); - const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); - const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); + const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, YGFlexDirectionRow); + const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, YGFlexDirectionColumn); + const float marginAxisRow = getMarginAxis(node, YGFlexDirectionRow); + const float marginAxisColumn = getMarginAxis(node, YGFlexDirectionColumn); const float innerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow; const float innerHeight = availableHeight - marginAxisColumn - paddingAndBorderAxisColumn; - if (widthMeasureMode == CSSMeasureModeExactly && heightMeasureMode == CSSMeasureModeExactly) { + if (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly) { // Don't bother sizing the text if both dimensions are already defined. - node->layout.measuredDimensions[CSSDimensionWidth] = - boundAxis(node, CSSFlexDirectionRow, availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, CSSFlexDirectionColumn, availableHeight - marginAxisColumn); + node->layout.measuredDimensions[YGDimensionWidth] = + boundAxis(node, YGFlexDirectionRow, availableWidth - marginAxisRow); + node->layout.measuredDimensions[YGDimensionHeight] = + boundAxis(node, YGFlexDirectionColumn, availableHeight - marginAxisColumn); } else if (innerWidth <= 0 || innerHeight <= 0) { // Don't bother sizing the text if there's no horizontal or vertical // space. - node->layout.measuredDimensions[CSSDimensionWidth] = boundAxis(node, CSSFlexDirectionRow, 0); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, CSSFlexDirectionColumn, 0); + node->layout.measuredDimensions[YGDimensionWidth] = boundAxis(node, YGFlexDirectionRow, 0); + node->layout.measuredDimensions[YGDimensionHeight] = boundAxis(node, YGFlexDirectionColumn, 0); } else { // Measure the text under the current constraints. const CSSSize measuredSize = node->measure(node, innerWidth, widthMeasureMode, innerHeight, heightMeasureMode); - node->layout.measuredDimensions[CSSDimensionWidth] = + node->layout.measuredDimensions[YGDimensionWidth] = boundAxis(node, - CSSFlexDirectionRow, - (widthMeasureMode == CSSMeasureModeUndefined || - widthMeasureMode == CSSMeasureModeAtMost) + YGFlexDirectionRow, + (widthMeasureMode == YGMeasureModeUndefined || + widthMeasureMode == YGMeasureModeAtMost) ? measuredSize.width + paddingAndBorderAxisRow : availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = + node->layout.measuredDimensions[YGDimensionHeight] = boundAxis(node, - CSSFlexDirectionColumn, - (heightMeasureMode == CSSMeasureModeUndefined || - heightMeasureMode == CSSMeasureModeAtMost) + YGFlexDirectionColumn, + (heightMeasureMode == YGMeasureModeUndefined || + heightMeasureMode == YGMeasureModeAtMost) ? measuredSize.height + paddingAndBorderAxisColumn : availableHeight - marginAxisColumn); } @@ -1253,25 +1243,25 @@ static void setMeasuredDimensionsForNodeWithMeasureFunc(const CSSNodeRef node, static void setMeasuredDimensionsForEmptyContainer(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode) { - const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, CSSFlexDirectionRow); - const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSSFlexDirectionColumn); - const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); - const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode) { + const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, YGFlexDirectionRow); + const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, YGFlexDirectionColumn); + const float marginAxisRow = getMarginAxis(node, YGFlexDirectionRow); + const float marginAxisColumn = getMarginAxis(node, YGFlexDirectionColumn); - node->layout.measuredDimensions[CSSDimensionWidth] = + node->layout.measuredDimensions[YGDimensionWidth] = boundAxis(node, - CSSFlexDirectionRow, - (widthMeasureMode == CSSMeasureModeUndefined || - widthMeasureMode == CSSMeasureModeAtMost) + YGFlexDirectionRow, + (widthMeasureMode == YGMeasureModeUndefined || + widthMeasureMode == YGMeasureModeAtMost) ? paddingAndBorderAxisRow : availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = + node->layout.measuredDimensions[YGDimensionHeight] = boundAxis(node, - CSSFlexDirectionColumn, - (heightMeasureMode == CSSMeasureModeUndefined || - heightMeasureMode == CSSMeasureModeAtMost) + YGFlexDirectionColumn, + (heightMeasureMode == YGMeasureModeUndefined || + heightMeasureMode == YGMeasureModeAtMost) ? paddingAndBorderAxisColumn : availableHeight - marginAxisColumn); } @@ -1279,25 +1269,25 @@ static void setMeasuredDimensionsForEmptyContainer(const CSSNodeRef node, static bool setMeasuredDimensionsIfEmptyOrFixedSize(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode) { - if ((widthMeasureMode == CSSMeasureModeAtMost && availableWidth <= 0) || - (heightMeasureMode == CSSMeasureModeAtMost && availableHeight <= 0) || - (widthMeasureMode == CSSMeasureModeExactly && heightMeasureMode == CSSMeasureModeExactly)) { - const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); - const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode) { + if ((widthMeasureMode == YGMeasureModeAtMost && availableWidth <= 0) || + (heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0) || + (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly)) { + const float marginAxisColumn = getMarginAxis(node, YGFlexDirectionColumn); + const float marginAxisRow = getMarginAxis(node, YGFlexDirectionRow); - node->layout.measuredDimensions[CSSDimensionWidth] = + node->layout.measuredDimensions[YGDimensionWidth] = boundAxis(node, - CSSFlexDirectionRow, - CSSValueIsUndefined(availableWidth) || (widthMeasureMode == CSSMeasureModeAtMost && availableWidth < 0) + YGFlexDirectionRow, + CSSValueIsUndefined(availableWidth) || (widthMeasureMode == YGMeasureModeAtMost && availableWidth < 0) ? 0 : availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = + node->layout.measuredDimensions[YGDimensionHeight] = boundAxis(node, - CSSFlexDirectionColumn, - CSSValueIsUndefined(availableHeight) || (heightMeasureMode == CSSMeasureModeAtMost && availableHeight < 0) + YGFlexDirectionColumn, + CSSValueIsUndefined(availableHeight) || (heightMeasureMode == YGMeasureModeAtMost && availableHeight < 0) ? 0 : availableHeight - marginAxisColumn); @@ -1373,7 +1363,7 @@ static bool setMeasuredDimensionsIfEmptyOrFixedSize(const CSSNodeRef node, // - node: current node to be sized and layed out // - availableWidth & availableHeight: available size to be used for sizing // the node -// or CSSUndefined if the size is not available; interpretation depends on +// or YGUndefined if the size is not available; interpretation depends on // layout // flags // - parentDirection: the inline (text) direction within the parent @@ -1410,33 +1400,33 @@ static bool setMeasuredDimensionsIfEmptyOrFixedSize(const CSSNodeRef node, // minimum main sizes (see above for details). Each of our measure modes maps // to a layout mode // from the spec (https://www.w3.org/TR/css3-sizing/#terms): -// - CSSMeasureModeUndefined: max content -// - CSSMeasureModeExactly: fill available -// - CSSMeasureModeAtMost: fit content +// - YGMeasureModeUndefined: max content +// - YGMeasureModeExactly: fill available +// - YGMeasureModeAtMost: fit content // // When calling layoutNodeImpl and layoutNodeInternal, if the caller passes // an available size of -// undefined then it must also pass a measure mode of CSSMeasureModeUndefined +// undefined then it must also pass a measure mode of YGMeasureModeUndefined // in that dimension. // static void layoutNodeImpl(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSDirection parentDirection, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode, + const YGDirection parentDirection, + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode, const bool performLayout) { - CSS_ASSERT(CSSValueIsUndefined(availableWidth) ? widthMeasureMode == CSSMeasureModeUndefined + CSS_ASSERT(CSSValueIsUndefined(availableWidth) ? widthMeasureMode == YGMeasureModeUndefined : true, "availableWidth is indefinite so widthMeasureMode must be " - "CSSMeasureModeUndefined"); - CSS_ASSERT(CSSValueIsUndefined(availableHeight) ? heightMeasureMode == CSSMeasureModeUndefined + "YGMeasureModeUndefined"); + CSS_ASSERT(CSSValueIsUndefined(availableHeight) ? heightMeasureMode == YGMeasureModeUndefined : true, "availableHeight is indefinite so heightMeasureMode must be " - "CSSMeasureModeUndefined"); + "YGMeasureModeUndefined"); // Set the resolved resolution in the node's layout. - const CSSDirection direction = resolveDirection(node, parentDirection); + const YGDirection direction = resolveDirection(node, parentDirection); node->layout.direction = direction; if (node->measure) { @@ -1461,11 +1451,11 @@ static void layoutNodeImpl(const CSSNodeRef node, } // STEP 1: CALCULATE VALUES FOR REMAINDER OF ALGORITHM - const CSSFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); - const CSSFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); + const YGFlexDirection mainAxis = resolveAxis(node->style.flexDirection, direction); + const YGFlexDirection crossAxis = getCrossFlexDirection(mainAxis, direction); const bool isMainAxisRow = isRowDirection(mainAxis); - const CSSJustify justifyContent = node->style.justifyContent; - const bool isNodeFlexWrap = node->style.flexWrap == CSSWrapWrap; + const YGJustify justifyContent = node->style.justifyContent; + const bool isNodeFlexWrap = node->style.flexWrap == YGWrapWrap; CSSNodeRef firstAbsoluteChild = NULL; CSSNodeRef currentAbsoluteChild = NULL; @@ -1476,13 +1466,13 @@ static void layoutNodeImpl(const CSSNodeRef node, const float paddingAndBorderAxisMain = getPaddingAndBorderAxis(node, mainAxis); const float paddingAndBorderAxisCross = getPaddingAndBorderAxis(node, crossAxis); - const CSSMeasureMode measureModeMainDim = isMainAxisRow ? widthMeasureMode : heightMeasureMode; - const CSSMeasureMode measureModeCrossDim = isMainAxisRow ? heightMeasureMode : widthMeasureMode; + const YGMeasureMode measureModeMainDim = isMainAxisRow ? widthMeasureMode : heightMeasureMode; + const YGMeasureMode measureModeCrossDim = isMainAxisRow ? heightMeasureMode : widthMeasureMode; - const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, CSSFlexDirectionRow); - const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, CSSFlexDirectionColumn); - const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); - const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); + const float paddingAndBorderAxisRow = getPaddingAndBorderAxis(node, YGFlexDirectionRow); + const float paddingAndBorderAxisColumn = getPaddingAndBorderAxis(node, YGFlexDirectionColumn); + const float marginAxisRow = getMarginAxis(node, YGFlexDirectionRow); + const float marginAxisColumn = getMarginAxis(node, YGFlexDirectionColumn); // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS const float availableInnerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow; @@ -1495,8 +1485,8 @@ static void layoutNodeImpl(const CSSNodeRef node, // computedFlexBasis to 0 instead of measuring and shrinking / flexing the child to exactly // match the remaining space CSSNodeRef singleFlexChild = NULL; - if ((isMainAxisRow && widthMeasureMode == CSSMeasureModeExactly) || - (!isMainAxisRow && heightMeasureMode == CSSMeasureModeExactly)) { + if ((isMainAxisRow && widthMeasureMode == YGMeasureModeExactly) || + (!isMainAxisRow && heightMeasureMode == YGMeasureModeExactly)) { for (uint32_t i = 0; i < childCount; i++) { const CSSNodeRef child = CSSNodeGetChild(node, i); if (singleFlexChild) { @@ -1517,13 +1507,13 @@ static void layoutNodeImpl(const CSSNodeRef node, if (performLayout) { // Set the initial position (relative to the parent). - const CSSDirection childDirection = resolveDirection(child, direction); + const YGDirection childDirection = resolveDirection(child, direction); setPosition(child, childDirection); } // Absolute-positioned children don't participate in flex layout. Add them // to a list that we can process later. - if (child->style.positionType == CSSPositionTypeAbsolute) { + if (child->style.positionType == YGPositionTypeAbsolute) { // Store a private linked list of absolutely positioned children // so that we can efficiently traverse them later. if (firstAbsoluteChild == NULL) { @@ -1590,7 +1580,7 @@ static void layoutNodeImpl(const CSSNodeRef node, const CSSNodeRef child = CSSNodeListGet(node->children, i); child->lineIndex = lineCount; - if (child->style.positionType != CSSPositionTypeAbsolute) { + if (child->style.positionType != YGPositionTypeAbsolute) { const float outerFlexBasis = child->layout.computedFlexBasis + getMarginAxis(child, mainAxis); @@ -1630,7 +1620,7 @@ static void layoutNodeImpl(const CSSNodeRef node, // If we don't need to measure the cross axis, we can skip the entire flex // step. - const bool canSkipFlex = !performLayout && measureModeCrossDim == CSSMeasureModeExactly; + const bool canSkipFlex = !performLayout && measureModeCrossDim == YGMeasureModeExactly; // In order to position the elements in the main axis, we have two // controls. The space between the beginning and the first element @@ -1785,73 +1775,73 @@ static void layoutNodeImpl(const CSSNodeRef node, float childWidth; float childHeight; - CSSMeasureMode childWidthMeasureMode; - CSSMeasureMode childHeightMeasureMode; + YGMeasureMode childWidthMeasureMode; + YGMeasureMode childHeightMeasureMode; if (isMainAxisRow) { - childWidth = updatedMainSize + getMarginAxis(currentRelativeChild, CSSFlexDirectionRow); - childWidthMeasureMode = CSSMeasureModeExactly; + childWidth = updatedMainSize + getMarginAxis(currentRelativeChild, YGFlexDirectionRow); + childWidthMeasureMode = YGMeasureModeExactly; if (!CSSValueIsUndefined(availableInnerCrossDim) && - !isStyleDimDefined(currentRelativeChild, CSSFlexDirectionColumn) && - heightMeasureMode == CSSMeasureModeExactly && - getAlignItem(node, currentRelativeChild) == CSSAlignStretch) { + !isStyleDimDefined(currentRelativeChild, YGFlexDirectionColumn) && + heightMeasureMode == YGMeasureModeExactly && + getAlignItem(node, currentRelativeChild) == YGAlignStretch) { childHeight = availableInnerCrossDim; - childHeightMeasureMode = CSSMeasureModeExactly; - } else if (!isStyleDimDefined(currentRelativeChild, CSSFlexDirectionColumn)) { + childHeightMeasureMode = YGMeasureModeExactly; + } else if (!isStyleDimDefined(currentRelativeChild, YGFlexDirectionColumn)) { childHeight = availableInnerCrossDim; childHeightMeasureMode = - CSSValueIsUndefined(childHeight) ? CSSMeasureModeUndefined : CSSMeasureModeAtMost; + CSSValueIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeAtMost; } else { - childHeight = currentRelativeChild->style.dimensions[CSSDimensionHeight] + - getMarginAxis(currentRelativeChild, CSSFlexDirectionColumn); - childHeightMeasureMode = CSSMeasureModeExactly; + childHeight = currentRelativeChild->style.dimensions[YGDimensionHeight] + + getMarginAxis(currentRelativeChild, YGFlexDirectionColumn); + childHeightMeasureMode = YGMeasureModeExactly; } } else { childHeight = - updatedMainSize + getMarginAxis(currentRelativeChild, CSSFlexDirectionColumn); - childHeightMeasureMode = CSSMeasureModeExactly; + updatedMainSize + getMarginAxis(currentRelativeChild, YGFlexDirectionColumn); + childHeightMeasureMode = YGMeasureModeExactly; if (!CSSValueIsUndefined(availableInnerCrossDim) && - !isStyleDimDefined(currentRelativeChild, CSSFlexDirectionRow) && - widthMeasureMode == CSSMeasureModeExactly && - getAlignItem(node, currentRelativeChild) == CSSAlignStretch) { + !isStyleDimDefined(currentRelativeChild, YGFlexDirectionRow) && + widthMeasureMode == YGMeasureModeExactly && + getAlignItem(node, currentRelativeChild) == YGAlignStretch) { childWidth = availableInnerCrossDim; - childWidthMeasureMode = CSSMeasureModeExactly; - } else if (!isStyleDimDefined(currentRelativeChild, CSSFlexDirectionRow)) { + childWidthMeasureMode = YGMeasureModeExactly; + } else if (!isStyleDimDefined(currentRelativeChild, YGFlexDirectionRow)) { childWidth = availableInnerCrossDim; childWidthMeasureMode = - CSSValueIsUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeAtMost; + CSSValueIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeAtMost; } else { - childWidth = currentRelativeChild->style.dimensions[CSSDimensionWidth] + - getMarginAxis(currentRelativeChild, CSSFlexDirectionRow); - childWidthMeasureMode = CSSMeasureModeExactly; + childWidth = currentRelativeChild->style.dimensions[YGDimensionWidth] + + getMarginAxis(currentRelativeChild, YGFlexDirectionRow); + childWidthMeasureMode = YGMeasureModeExactly; } } if (!CSSValueIsUndefined(currentRelativeChild->style.aspectRatio)) { - if (isMainAxisRow && childHeightMeasureMode != CSSMeasureModeExactly) { + if (isMainAxisRow && childHeightMeasureMode != YGMeasureModeExactly) { childHeight = fmaxf(childWidth * currentRelativeChild->style.aspectRatio, - getPaddingAndBorderAxis(currentRelativeChild, CSSFlexDirectionColumn)); - childHeightMeasureMode = CSSMeasureModeExactly; - } else if (!isMainAxisRow && childWidthMeasureMode != CSSMeasureModeExactly) { + getPaddingAndBorderAxis(currentRelativeChild, YGFlexDirectionColumn)); + childHeightMeasureMode = YGMeasureModeExactly; + } else if (!isMainAxisRow && childWidthMeasureMode != YGMeasureModeExactly) { childWidth = fmaxf(childHeight * currentRelativeChild->style.aspectRatio, - getPaddingAndBorderAxis(currentRelativeChild, CSSFlexDirectionRow)); - childWidthMeasureMode = CSSMeasureModeExactly; + getPaddingAndBorderAxis(currentRelativeChild, YGFlexDirectionRow)); + childWidthMeasureMode = YGMeasureModeExactly; } } - constrainMaxSizeForMode(currentRelativeChild->style.maxDimensions[CSSDimensionWidth], + constrainMaxSizeForMode(currentRelativeChild->style.maxDimensions[YGDimensionWidth], &childWidthMeasureMode, &childWidth); - constrainMaxSizeForMode(currentRelativeChild->style.maxDimensions[CSSDimensionHeight], + constrainMaxSizeForMode(currentRelativeChild->style.maxDimensions[YGDimensionHeight], &childHeightMeasureMode, &childHeight); const bool requiresStretchLayout = !isStyleDimDefined(currentRelativeChild, crossAxis) && - getAlignItem(node, currentRelativeChild) == CSSAlignStretch; + getAlignItem(node, currentRelativeChild) == YGAlignStretch; // Recursively call the layout algorithm for this child with the updated // main size. @@ -1882,7 +1872,7 @@ static void layoutNodeImpl(const CSSNodeRef node, // If we are using "at most" rules in the main axis. Calculate the remaining space when // constraint by the min size defined for the main axis. - if (measureModeMainDim == CSSMeasureModeAtMost && remainingFreeSpace > 0) { + if (measureModeMainDim == YGMeasureModeAtMost && remainingFreeSpace > 0) { if (!CSSValueIsUndefined(node->style.minDimensions[dim[mainAxis]]) && node->style.minDimensions[dim[mainAxis]] >= 0) { remainingFreeSpace = fmaxf(0, @@ -1894,26 +1884,26 @@ static void layoutNodeImpl(const CSSNodeRef node, } switch (justifyContent) { - case CSSJustifyCenter: + case YGJustifyCenter: leadingMainDim = remainingFreeSpace / 2; break; - case CSSJustifyFlexEnd: + case YGJustifyFlexEnd: leadingMainDim = remainingFreeSpace; break; - case CSSJustifySpaceBetween: + case YGJustifySpaceBetween: if (itemsOnLine > 1) { betweenMainDim = fmaxf(remainingFreeSpace, 0) / (itemsOnLine - 1); } else { betweenMainDim = 0; } break; - case CSSJustifySpaceAround: + case YGJustifySpaceAround: // Space on the edges is half of the space between elements betweenMainDim = remainingFreeSpace / itemsOnLine; leadingMainDim = betweenMainDim / 2; break; - case CSSJustifyFlexStart: - case CSSJustifyCount: + case YGJustifyFlexStart: + case YGJustifyCount: break; } @@ -1923,7 +1913,7 @@ static void layoutNodeImpl(const CSSNodeRef node, for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) { const CSSNodeRef child = CSSNodeListGet(node->children, i); - if (child->style.positionType == CSSPositionTypeAbsolute && + if (child->style.positionType == YGPositionTypeAbsolute && isLeadingPosDefined(child, mainAxis)) { if (performLayout) { // In case the child is position absolute and has left/top being @@ -1937,7 +1927,7 @@ static void layoutNodeImpl(const CSSNodeRef node, // Now that we placed the element, we need to update the variables. // We need to do that only for relative elements. Absolute elements // do not take part in that phase. - if (child->style.positionType == CSSPositionTypeRelative) { + if (child->style.positionType == YGPositionTypeRelative) { if (performLayout) { child->layout.position[pos[mainAxis]] += mainDim; } @@ -1969,19 +1959,19 @@ static void layoutNodeImpl(const CSSNodeRef node, mainDim += trailingPaddingAndBorderMain; float containerCrossAxis = availableInnerCrossDim; - if (measureModeCrossDim == CSSMeasureModeUndefined || - measureModeCrossDim == CSSMeasureModeAtMost) { + if (measureModeCrossDim == YGMeasureModeUndefined || + measureModeCrossDim == YGMeasureModeAtMost) { // Compute the cross axis from the max cross dimension of the children. containerCrossAxis = boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross) - paddingAndBorderAxisCross; - if (measureModeCrossDim == CSSMeasureModeAtMost) { + if (measureModeCrossDim == YGMeasureModeAtMost) { containerCrossAxis = fminf(containerCrossAxis, availableInnerCrossDim); } } // If there's no flex wrap, the cross dimension is defined by the container. - if (!isNodeFlexWrap && measureModeCrossDim == CSSMeasureModeExactly) { + if (!isNodeFlexWrap && measureModeCrossDim == YGMeasureModeExactly) { crossDim = availableInnerCrossDim; } @@ -1995,7 +1985,7 @@ static void layoutNodeImpl(const CSSNodeRef node, for (uint32_t i = startOfLineIndex; i < endOfLineIndex; i++) { const CSSNodeRef child = CSSNodeListGet(node->children, i); - if (child->style.positionType == CSSPositionTypeAbsolute) { + if (child->style.positionType == YGPositionTypeAbsolute) { // If the child is absolutely positioned and has a // top/left/bottom/right // set, override all the previously computed positions to set it @@ -2014,36 +2004,36 @@ static void layoutNodeImpl(const CSSNodeRef node, // For a relative children, we're either using alignItems (parent) or // alignSelf (child) in order to determine the position in the cross // axis - const CSSAlign alignItem = getAlignItem(node, child); + const YGAlign alignItem = getAlignItem(node, child); // If the child uses align stretch, we need to lay it out one more // time, this time // forcing the cross-axis size to be the computed cross size for the // current line. - if (alignItem == CSSAlignStretch) { + if (alignItem == YGAlignStretch) { const bool isCrossSizeDefinite = - (isMainAxisRow && isStyleDimDefined(child, CSSFlexDirectionColumn)) || - (!isMainAxisRow && isStyleDimDefined(child, CSSFlexDirectionRow)); + (isMainAxisRow && isStyleDimDefined(child, YGFlexDirectionColumn)) || + (!isMainAxisRow && isStyleDimDefined(child, YGFlexDirectionRow)); float childWidth; float childHeight; - CSSMeasureMode childWidthMeasureMode = CSSMeasureModeExactly; - CSSMeasureMode childHeightMeasureMode = CSSMeasureModeExactly; + YGMeasureMode childWidthMeasureMode = YGMeasureModeExactly; + YGMeasureMode childHeightMeasureMode = YGMeasureModeExactly; if (isMainAxisRow) { childHeight = crossDim; - childWidth = child->layout.measuredDimensions[CSSDimensionWidth] + - getMarginAxis(child, CSSFlexDirectionRow); + childWidth = child->layout.measuredDimensions[YGDimensionWidth] + + getMarginAxis(child, YGFlexDirectionRow); } else { childWidth = crossDim; - childHeight = child->layout.measuredDimensions[CSSDimensionHeight] + - getMarginAxis(child, CSSFlexDirectionColumn); + childHeight = child->layout.measuredDimensions[YGDimensionHeight] + + getMarginAxis(child, YGFlexDirectionColumn); } - constrainMaxSizeForMode(child->style.maxDimensions[CSSDimensionWidth], + constrainMaxSizeForMode(child->style.maxDimensions[YGDimensionWidth], &childWidthMeasureMode, &childWidth); - constrainMaxSizeForMode(child->style.maxDimensions[CSSDimensionHeight], + constrainMaxSizeForMode(child->style.maxDimensions[YGDimensionHeight], &childHeightMeasureMode, &childHeight); @@ -2051,9 +2041,9 @@ static void layoutNodeImpl(const CSSNodeRef node, // no need to stretch. if (!isCrossSizeDefinite) { childWidthMeasureMode = - CSSValueIsUndefined(childWidth) ? CSSMeasureModeUndefined : CSSMeasureModeExactly; - childHeightMeasureMode = CSSValueIsUndefined(childHeight) ? CSSMeasureModeUndefined - : CSSMeasureModeExactly; + CSSValueIsUndefined(childWidth) ? YGMeasureModeUndefined : YGMeasureModeExactly; + childHeightMeasureMode = + CSSValueIsUndefined(childHeight) ? YGMeasureModeUndefined : YGMeasureModeExactly; layoutNodeInternal(child, childWidth, @@ -2064,12 +2054,12 @@ static void layoutNodeImpl(const CSSNodeRef node, true, "stretch"); } - } else if (alignItem != CSSAlignFlexStart) { + } else if (alignItem != YGAlignFlexStart) { const float remainingCrossDim = containerCrossAxis - getDimWithMargin(child, crossAxis); - if (alignItem == CSSAlignCenter) { + if (alignItem == YGAlignCenter) { leadingCrossDim += remainingCrossDim / 2; - } else { // CSSAlignFlexEnd + } else { // YGAlignFlexEnd leadingCrossDim += remainingCrossDim; } } @@ -2092,20 +2082,20 @@ static void layoutNodeImpl(const CSSNodeRef node, float currentLead = leadingPaddingAndBorderCross; switch (node->style.alignContent) { - case CSSAlignFlexEnd: + case YGAlignFlexEnd: currentLead += remainingAlignContentDim; break; - case CSSAlignCenter: + case YGAlignCenter: currentLead += remainingAlignContentDim / 2; break; - case CSSAlignStretch: + case YGAlignStretch: if (availableInnerCrossDim > totalLineCrossDim) { crossDimLead = (remainingAlignContentDim / lineCount); } break; - case CSSAlignAuto: - case CSSAlignFlexStart: - case CSSAlignCount: + case YGAlignAuto: + case YGAlignFlexStart: + case YGAlignCount: break; } @@ -2119,7 +2109,7 @@ static void layoutNodeImpl(const CSSNodeRef node, for (ii = startIndex; ii < childCount; ii++) { const CSSNodeRef child = CSSNodeListGet(node->children, ii); - if (child->style.positionType == CSSPositionTypeRelative) { + if (child->style.positionType == YGPositionTypeRelative) { if (child->lineIndex != i) { break; } @@ -2138,34 +2128,34 @@ static void layoutNodeImpl(const CSSNodeRef node, for (ii = startIndex; ii < endIndex; ii++) { const CSSNodeRef child = CSSNodeListGet(node->children, ii); - if (child->style.positionType == CSSPositionTypeRelative) { + if (child->style.positionType == YGPositionTypeRelative) { switch (getAlignItem(node, child)) { - case CSSAlignFlexStart: { + case YGAlignFlexStart: { child->layout.position[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis); break; } - case CSSAlignFlexEnd: { + case YGAlignFlexEnd: { child->layout.position[pos[crossAxis]] = currentLead + lineHeight - getTrailingMargin(child, crossAxis) - child->layout.measuredDimensions[dim[crossAxis]]; break; } - case CSSAlignCenter: { + case YGAlignCenter: { float childHeight = child->layout.measuredDimensions[dim[crossAxis]]; child->layout.position[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2; break; } - case CSSAlignStretch: { + case YGAlignStretch: { child->layout.position[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis); // TODO(prenaux): Correctly set the height of items with indefinite // (auto) crossAxis dimension. break; } - case CSSAlignAuto: - case CSSAlignCount: + case YGAlignAuto: + case YGAlignCount: break; } } @@ -2177,30 +2167,30 @@ static void layoutNodeImpl(const CSSNodeRef node, } // STEP 9: COMPUTING FINAL DIMENSIONS - node->layout.measuredDimensions[CSSDimensionWidth] = - boundAxis(node, CSSFlexDirectionRow, availableWidth - marginAxisRow); - node->layout.measuredDimensions[CSSDimensionHeight] = - boundAxis(node, CSSFlexDirectionColumn, availableHeight - marginAxisColumn); + node->layout.measuredDimensions[YGDimensionWidth] = + boundAxis(node, YGFlexDirectionRow, availableWidth - marginAxisRow); + node->layout.measuredDimensions[YGDimensionHeight] = + boundAxis(node, YGFlexDirectionColumn, availableHeight - marginAxisColumn); // If the user didn't specify a width or height for the node, set the // dimensions based on the children. - if (measureModeMainDim == CSSMeasureModeUndefined) { + if (measureModeMainDim == YGMeasureModeUndefined) { // Clamp the size to the min/max size, if specified, and make sure it // doesn't go below the padding and border amount. node->layout.measuredDimensions[dim[mainAxis]] = boundAxis(node, mainAxis, maxLineMainDim); - } else if (measureModeMainDim == CSSMeasureModeAtMost) { + } else if (measureModeMainDim == YGMeasureModeAtMost) { node->layout.measuredDimensions[dim[mainAxis]] = fmaxf(fminf(availableInnerMainDim + paddingAndBorderAxisMain, boundAxisWithinMinAndMax(node, mainAxis, maxLineMainDim)), paddingAndBorderAxisMain); } - if (measureModeCrossDim == CSSMeasureModeUndefined) { + if (measureModeCrossDim == YGMeasureModeUndefined) { // Clamp the size to the min/max size, if specified, and make sure it // doesn't go below the padding and border amount. node->layout.measuredDimensions[dim[crossAxis]] = boundAxis(node, crossAxis, totalLineCrossDim + paddingAndBorderAxisCross); - } else if (measureModeCrossDim == CSSMeasureModeAtMost) { + } else if (measureModeCrossDim == YGMeasureModeAtMost) { node->layout.measuredDimensions[dim[crossAxis]] = fmaxf(fminf(availableInnerCrossDim + paddingAndBorderAxisCross, boundAxisWithinMinAndMax(node, @@ -2219,9 +2209,9 @@ static void layoutNodeImpl(const CSSNodeRef node, // STEP 11: SETTING TRAILING POSITIONS FOR CHILDREN const bool needsMainTrailingPos = - mainAxis == CSSFlexDirectionRowReverse || mainAxis == CSSFlexDirectionColumnReverse; + mainAxis == YGFlexDirectionRowReverse || mainAxis == YGFlexDirectionColumnReverse; const bool needsCrossTrailingPos = - CSSFlexDirectionRowReverse || crossAxis == CSSFlexDirectionColumnReverse; + YGFlexDirectionRowReverse || crossAxis == YGFlexDirectionColumnReverse; // Set trailing position if necessary. if (needsMainTrailingPos || needsCrossTrailingPos) { @@ -2256,50 +2246,50 @@ static const char *getSpacer(const unsigned long level) { } } -static const char *getModeName(const CSSMeasureMode mode, const bool performLayout) { - const char *kMeasureModeNames[CSSMeasureModeCount] = {"UNDEFINED", "EXACTLY", "AT_MOST"}; - const char *kLayoutModeNames[CSSMeasureModeCount] = {"LAY_UNDEFINED", - "LAY_EXACTLY", - "LAY_AT_" - "MOST"}; +static const char *getModeName(const YGMeasureMode mode, const bool performLayout) { + const char *kMeasureModeNames[YGMeasureModeCount] = {"UNDEFINED", "EXACTLY", "AT_MOST"}; + const char *kLayoutModeNames[YGMeasureModeCount] = {"LAY_UNDEFINED", + "LAY_EXACTLY", + "LAY_AT_" + "MOST"}; - if (mode >= CSSMeasureModeCount) { + if (mode >= YGMeasureModeCount) { return ""; } return performLayout ? kLayoutModeNames[mode] : kMeasureModeNames[mode]; } -static inline bool newSizeIsExactAndMatchesOldMeasuredSize(CSSMeasureMode sizeMode, +static inline bool newSizeIsExactAndMatchesOldMeasuredSize(YGMeasureMode sizeMode, float size, float lastComputedSize) { - return sizeMode == CSSMeasureModeExactly && eq(size, lastComputedSize); + return sizeMode == YGMeasureModeExactly && eq(size, lastComputedSize); } -static inline bool oldSizeIsUnspecifiedAndStillFits(CSSMeasureMode sizeMode, +static inline bool oldSizeIsUnspecifiedAndStillFits(YGMeasureMode sizeMode, float size, - CSSMeasureMode lastSizeMode, + YGMeasureMode lastSizeMode, float lastComputedSize) { - return sizeMode == CSSMeasureModeAtMost && lastSizeMode == CSSMeasureModeUndefined && + return sizeMode == YGMeasureModeAtMost && lastSizeMode == YGMeasureModeUndefined && size >= lastComputedSize; } -static inline bool newMeasureSizeIsStricterAndStillValid(CSSMeasureMode sizeMode, +static inline bool newMeasureSizeIsStricterAndStillValid(YGMeasureMode sizeMode, float size, - CSSMeasureMode lastSizeMode, + YGMeasureMode lastSizeMode, float lastSize, float lastComputedSize) { - return lastSizeMode == CSSMeasureModeAtMost && sizeMode == CSSMeasureModeAtMost && + return lastSizeMode == YGMeasureModeAtMost && sizeMode == YGMeasureModeAtMost && lastSize > size && lastComputedSize <= size; } -bool CSSNodeCanUseCachedMeasurement(const CSSMeasureMode widthMode, +bool CSSNodeCanUseCachedMeasurement(const YGMeasureMode widthMode, const float width, - const CSSMeasureMode heightMode, + const YGMeasureMode heightMode, const float height, - const CSSMeasureMode lastWidthMode, + const YGMeasureMode lastWidthMode, const float lastWidth, - const CSSMeasureMode lastHeightMode, + const YGMeasureMode lastHeightMode, const float lastHeight, const float lastComputedWidth, const float lastComputedHeight, @@ -2347,9 +2337,9 @@ bool CSSNodeCanUseCachedMeasurement(const CSSMeasureMode widthMode, bool layoutNodeInternal(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSDirection parentDirection, - const CSSMeasureMode widthMeasureMode, - const CSSMeasureMode heightMeasureMode, + const YGDirection parentDirection, + const YGMeasureMode widthMeasureMode, + const YGMeasureMode heightMeasureMode, const bool performLayout, const char *reason) { CSSLayout *layout = &node->layout; @@ -2363,8 +2353,8 @@ bool layoutNodeInternal(const CSSNodeRef node, if (needToVisitNode) { // Invalidate the cached results. layout->nextCachedMeasurementsIndex = 0; - layout->cachedLayout.widthMeasureMode = (CSSMeasureMode) -1; - layout->cachedLayout.heightMeasureMode = (CSSMeasureMode) -1; + layout->cachedLayout.widthMeasureMode = (YGMeasureMode) -1; + layout->cachedLayout.heightMeasureMode = (YGMeasureMode) -1; layout->cachedLayout.computedWidth = -1; layout->cachedLayout.computedHeight = -1; } @@ -2384,8 +2374,8 @@ bool layoutNodeInternal(const CSSNodeRef node, // expensive to measure, so it's worth avoiding redundant measurements if at // all possible. if (node->measure) { - const float marginAxisRow = getMarginAxis(node, CSSFlexDirectionRow); - const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn); + const float marginAxisRow = getMarginAxis(node, YGFlexDirectionRow); + const float marginAxisColumn = getMarginAxis(node, YGFlexDirectionColumn); // First, try to use the layout cache. if (CSSNodeCanUseCachedMeasurement(widthMeasureMode, @@ -2441,8 +2431,8 @@ bool layoutNodeInternal(const CSSNodeRef node, } if (!needToVisitNode && cachedResults != NULL) { - layout->measuredDimensions[CSSDimensionWidth] = cachedResults->computedWidth; - layout->measuredDimensions[CSSDimensionHeight] = cachedResults->computedHeight; + layout->measuredDimensions[YGDimensionWidth] = cachedResults->computedWidth; + layout->measuredDimensions[YGDimensionHeight] = cachedResults->computedHeight; if (gPrintChanges && gPrintSkips) { printf("%s%d.{[skipped] ", getSpacer(gDepth), gDepth); @@ -2488,8 +2478,8 @@ bool layoutNodeInternal(const CSSNodeRef node, printf("wm: %s, hm: %s, d: (%f, %f) %s\n", getModeName(widthMeasureMode, performLayout), getModeName(heightMeasureMode, performLayout), - layout->measuredDimensions[CSSDimensionWidth], - layout->measuredDimensions[CSSDimensionHeight], + layout->measuredDimensions[YGDimensionWidth], + layout->measuredDimensions[YGDimensionHeight], reason); } @@ -2517,15 +2507,14 @@ bool layoutNodeInternal(const CSSNodeRef node, newCacheEntry->availableHeight = availableHeight; newCacheEntry->widthMeasureMode = widthMeasureMode; newCacheEntry->heightMeasureMode = heightMeasureMode; - newCacheEntry->computedWidth = layout->measuredDimensions[CSSDimensionWidth]; - newCacheEntry->computedHeight = layout->measuredDimensions[CSSDimensionHeight]; + newCacheEntry->computedWidth = layout->measuredDimensions[YGDimensionWidth]; + newCacheEntry->computedHeight = layout->measuredDimensions[YGDimensionHeight]; } } if (performLayout) { - node->layout.dimensions[CSSDimensionWidth] = node->layout.measuredDimensions[CSSDimensionWidth]; - node->layout.dimensions[CSSDimensionHeight] = - node->layout.measuredDimensions[CSSDimensionHeight]; + node->layout.dimensions[YGDimensionWidth] = node->layout.measuredDimensions[YGDimensionWidth]; + node->layout.dimensions[YGDimensionHeight] = node->layout.measuredDimensions[YGDimensionHeight]; node->hasNewLayout = true; node->isDirty = false; } @@ -2537,16 +2526,16 @@ bool layoutNodeInternal(const CSSNodeRef node, static void roundToPixelGrid(const CSSNodeRef node) { const float fractialLeft = - node->layout.position[CSSEdgeLeft] - floorf(node->layout.position[CSSEdgeLeft]); + node->layout.position[YGEdgeLeft] - floorf(node->layout.position[YGEdgeLeft]); const float fractialTop = - node->layout.position[CSSEdgeTop] - floorf(node->layout.position[CSSEdgeTop]); - node->layout.dimensions[CSSDimensionWidth] = - roundf(fractialLeft + node->layout.dimensions[CSSDimensionWidth]) - roundf(fractialLeft); - node->layout.dimensions[CSSDimensionHeight] = - roundf(fractialTop + node->layout.dimensions[CSSDimensionHeight]) - roundf(fractialTop); + node->layout.position[YGEdgeTop] - floorf(node->layout.position[YGEdgeTop]); + node->layout.dimensions[YGDimensionWidth] = + roundf(fractialLeft + node->layout.dimensions[YGDimensionWidth]) - roundf(fractialLeft); + node->layout.dimensions[YGDimensionHeight] = + roundf(fractialTop + node->layout.dimensions[YGDimensionHeight]) - roundf(fractialTop); - node->layout.position[CSSEdgeLeft] = roundf(node->layout.position[CSSEdgeLeft]); - node->layout.position[CSSEdgeTop] = roundf(node->layout.position[CSSEdgeTop]); + node->layout.position[YGEdgeLeft] = roundf(node->layout.position[YGEdgeLeft]); + node->layout.position[YGEdgeTop] = roundf(node->layout.position[YGEdgeTop]); const uint32_t childCount = CSSNodeListCount(node->children); for (uint32_t i = 0; i < childCount; i++) { @@ -2557,7 +2546,7 @@ static void roundToPixelGrid(const CSSNodeRef node) { void CSSNodeCalculateLayout(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSDirection parentDirection) { + const YGDirection parentDirection) { // Increment the generation count. This will force the recursive routine to // visit // all dirty nodes at least once. Subsequent visits will be skipped if the @@ -2567,29 +2556,29 @@ void CSSNodeCalculateLayout(const CSSNodeRef node, float width = availableWidth; float height = availableHeight; - CSSMeasureMode widthMeasureMode = CSSMeasureModeUndefined; - CSSMeasureMode heightMeasureMode = CSSMeasureModeUndefined; + YGMeasureMode widthMeasureMode = YGMeasureModeUndefined; + YGMeasureMode heightMeasureMode = YGMeasureModeUndefined; if (!CSSValueIsUndefined(width)) { - widthMeasureMode = CSSMeasureModeExactly; - } else if (isStyleDimDefined(node, CSSFlexDirectionRow)) { + widthMeasureMode = YGMeasureModeExactly; + } else if (isStyleDimDefined(node, YGFlexDirectionRow)) { width = - node->style.dimensions[dim[CSSFlexDirectionRow]] + getMarginAxis(node, CSSFlexDirectionRow); - widthMeasureMode = CSSMeasureModeExactly; - } else if (node->style.maxDimensions[CSSDimensionWidth] >= 0.0) { - width = node->style.maxDimensions[CSSDimensionWidth]; - widthMeasureMode = CSSMeasureModeAtMost; + node->style.dimensions[dim[YGFlexDirectionRow]] + getMarginAxis(node, YGFlexDirectionRow); + widthMeasureMode = YGMeasureModeExactly; + } else if (node->style.maxDimensions[YGDimensionWidth] >= 0.0) { + width = node->style.maxDimensions[YGDimensionWidth]; + widthMeasureMode = YGMeasureModeAtMost; } if (!CSSValueIsUndefined(height)) { - heightMeasureMode = CSSMeasureModeExactly; - } else if (isStyleDimDefined(node, CSSFlexDirectionColumn)) { - height = node->style.dimensions[dim[CSSFlexDirectionColumn]] + - getMarginAxis(node, CSSFlexDirectionColumn); - heightMeasureMode = CSSMeasureModeExactly; - } else if (node->style.maxDimensions[CSSDimensionHeight] >= 0.0) { - height = node->style.maxDimensions[CSSDimensionHeight]; - heightMeasureMode = CSSMeasureModeAtMost; + heightMeasureMode = YGMeasureModeExactly; + } else if (isStyleDimDefined(node, YGFlexDirectionColumn)) { + height = node->style.dimensions[dim[YGFlexDirectionColumn]] + + getMarginAxis(node, YGFlexDirectionColumn); + heightMeasureMode = YGMeasureModeExactly; + } else if (node->style.maxDimensions[YGDimensionHeight] >= 0.0) { + height = node->style.maxDimensions[YGDimensionHeight]; + heightMeasureMode = YGMeasureModeAtMost; } if (layoutNodeInternal(node, @@ -2603,12 +2592,12 @@ void CSSNodeCalculateLayout(const CSSNodeRef node, "l")) { setPosition(node, node->layout.direction); - if (CSSLayoutIsExperimentalFeatureEnabled(CSSExperimentalFeatureRounding)) { + if (CSSLayoutIsExperimentalFeatureEnabled(YGExperimentalFeatureRounding)) { roundToPixelGrid(node); } if (gPrintTree) { - CSSNodePrint(node, CSSPrintOptionsLayout | CSSPrintOptionsChildren | CSSPrintOptionsStyle); + CSSNodePrint(node, YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle); } } } @@ -2617,20 +2606,20 @@ void CSSLayoutSetLogger(CSSLogger logger) { gLogger = logger; } -void CSSLog(CSSLogLevel level, const char *format, ...) { +void CSSLog(YGLogLevel level, const char *format, ...) { va_list args; va_start(args, format); gLogger(level, format, args); va_end(args); } -static bool experimentalFeatures[CSSExperimentalFeatureCount + 1]; +static bool experimentalFeatures[YGExperimentalFeatureCount + 1]; -void CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeature feature, bool enabled) { +void CSSLayoutSetExperimentalFeatureEnabled(YGExperimentalFeature feature, bool enabled) { experimentalFeatures[feature] = enabled; } -inline bool CSSLayoutIsExperimentalFeatureEnabled(CSSExperimentalFeature feature) { +inline bool CSSLayoutIsExperimentalFeatureEnabled(YGExperimentalFeature feature) { return experimentalFeatures[feature]; } diff --git a/ReactCommon/CSSLayout/CSSLayout/CSSLayout.h b/ReactCommon/CSSLayout/CSSLayout/CSSLayout.h index e2dca0a7271..62f5b16cc8c 100644 --- a/ReactCommon/CSSLayout/CSSLayout/CSSLayout.h +++ b/ReactCommon/CSSLayout/CSSLayout/CSSLayout.h @@ -26,7 +26,7 @@ static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff}; #define NAN (*(const float *) __nan) #endif -#define CSSUndefined NAN +#define YGUndefined NAN #include "CSSEnums.h" #include "CSSMacros.h" @@ -41,11 +41,11 @@ typedef struct CSSSize { typedef struct CSSNode *CSSNodeRef; typedef CSSSize (*CSSMeasureFunc)(CSSNodeRef node, float width, - CSSMeasureMode widthMode, + YGMeasureMode widthMode, float height, - CSSMeasureMode heightMode); + YGMeasureMode heightMode); typedef void (*CSSPrintFunc)(CSSNodeRef node); -typedef int (*CSSLogger)(CSSLogLevel level, const char *format, va_list args); +typedef int (*CSSLogger)(YGLogLevel level, const char *format, va_list args); typedef void *(*CSSMalloc)(size_t size); typedef void *(*CSSCalloc)(size_t count, size_t size); @@ -70,7 +70,7 @@ WIN_EXPORT uint32_t CSSNodeChildCount(const CSSNodeRef node); WIN_EXPORT void CSSNodeCalculateLayout(const CSSNodeRef node, const float availableWidth, const float availableHeight, - const CSSDirection parentDirection); + const YGDirection parentDirection); // Mark a node as dirty. Only valid for nodes with a custom measure function // set. @@ -81,17 +81,17 @@ WIN_EXPORT void CSSNodeCalculateLayout(const CSSNodeRef node, 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 void CSSNodePrint(const CSSNodeRef node, const YGPrintOptions options); WIN_EXPORT bool CSSValueIsUndefined(const float value); -WIN_EXPORT bool CSSNodeCanUseCachedMeasurement(const CSSMeasureMode widthMode, +WIN_EXPORT bool CSSNodeCanUseCachedMeasurement(const YGMeasureMode widthMode, const float width, - const CSSMeasureMode heightMode, + const YGMeasureMode heightMode, const float height, - const CSSMeasureMode lastWidthMode, + const YGMeasureMode lastWidthMode, const float lastWidth, - const CSSMeasureMode lastHeightMode, + const YGMeasureMode lastHeightMode, const float lastHeight, const float lastComputedWidth, const float lastComputedHeight, @@ -110,9 +110,9 @@ WIN_EXPORT void CSSNodeCopyStyle(const CSSNodeRef dstNode, const CSSNodeRef srcN #define CSS_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \ WIN_EXPORT void CSSNodeStyleSet##name(const CSSNodeRef node, \ - const CSSEdge edge, \ + const YGEdge edge, \ const type paramName); \ - WIN_EXPORT type CSSNodeStyleGet##name(const CSSNodeRef node, const CSSEdge edge); + WIN_EXPORT type CSSNodeStyleGet##name(const CSSNodeRef node, const YGEdge edge); #define CSS_NODE_LAYOUT_PROPERTY(type, name) \ WIN_EXPORT type CSSNodeLayoutGet##name(const CSSNodeRef node); @@ -122,15 +122,15 @@ 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); +CSS_NODE_STYLE_PROPERTY(YGDirection, Direction, direction); +CSS_NODE_STYLE_PROPERTY(YGFlexDirection, FlexDirection, flexDirection); +CSS_NODE_STYLE_PROPERTY(YGJustify, JustifyContent, justifyContent); +CSS_NODE_STYLE_PROPERTY(YGAlign, AlignContent, alignContent); +CSS_NODE_STYLE_PROPERTY(YGAlign, AlignItems, alignItems); +CSS_NODE_STYLE_PROPERTY(YGAlign, AlignSelf, alignSelf); +CSS_NODE_STYLE_PROPERTY(YGPositionType, PositionType, positionType); +CSS_NODE_STYLE_PROPERTY(YGWrap, FlexWrap, flexWrap); +CSS_NODE_STYLE_PROPERTY(YGOverflow, Overflow, overflow); WIN_EXPORT void CSSNodeStyleSetFlex(const CSSNodeRef node, const float flex); CSS_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow); @@ -167,14 +167,13 @@ 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); +CSS_NODE_LAYOUT_PROPERTY(YGDirection, Direction); WIN_EXPORT void CSSLayoutSetLogger(CSSLogger logger); -WIN_EXPORT void CSSLog(CSSLogLevel level, const char *message, ...); +WIN_EXPORT void CSSLog(YGLogLevel level, const char *message, ...); -WIN_EXPORT void CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeature feature, - bool enabled); -WIN_EXPORT bool CSSLayoutIsExperimentalFeatureEnabled(CSSExperimentalFeature feature); +WIN_EXPORT void CSSLayoutSetExperimentalFeatureEnabled(YGExperimentalFeature feature, bool enabled); +WIN_EXPORT bool CSSLayoutIsExperimentalFeatureEnabled(YGExperimentalFeature feature); WIN_EXPORT void CSSLayoutSetMemoryFuncs(CSSMalloc cssMalloc, CSSCalloc cssCalloc, diff --git a/ReactCommon/CSSLayout/CSSLayout/CSSMacros.h b/ReactCommon/CSSLayout/CSSLayout/CSSMacros.h index 8d2375e5711..f54a5b87d49 100644 --- a/ReactCommon/CSSLayout/CSSLayout/CSSMacros.h +++ b/ReactCommon/CSSLayout/CSSLayout/CSSMacros.h @@ -34,9 +34,9 @@ #endif #ifndef CSS_ASSERT -#define CSS_ASSERT(X, message) \ - if (!(X)) { \ - CSSLog(CSSLogLevelError, "%s", message); \ - CSS_ABORT(); \ +#define CSS_ASSERT(X, message) \ + if (!(X)) { \ + CSSLog(YGLogLevelError, "%s", message); \ + CSS_ABORT(); \ } #endif