Using YGPositionTypeAbsolute value where we compare absolute vs relative

Summary:
Now Yoga.cpp does not use the `YGPositionTypeRelative` value/constant, it uses `YGPositionTypeAbsolute` instead.
Now `YGPositionType` can only be `YGPositionTypeRelative` or `YGPositionTypeAbsolute`, so expressions `x == YGPositionTypeRelative` and `x != YGPositionTypeAbsolute` are equivalent.
The reasoning behind the change is that in all cases we actually check a node to be (or not to be) `absolute`, not `relative`. This will make a difference in the coming diffs in the stack when we will introduce a new value for the type: `static`.

We need to differentiate `static` and `relative` values t implement the `stacking context` feature in the W3C-compliant way (to fix bugs and avoid developer confusion). Read more here:
https://developer.mozilla.org/en-US/docs/Web/CSS/position

Changelog: [Internal] Internal change in Yoga.

Reviewed By: SidharthGuglani

Differential Revision: D22386733

fbshipit-source-id: 8e2c2b88b404660639f845783c8f93f0c62c0fbb
This commit is contained in:
Valentin Shergin
2020-07-14 15:20:24 -07:00
committed by Facebook GitHub Bot
parent a93e5d63c9
commit 0767f4d105
2 changed files with 10 additions and 7 deletions

View File

@@ -307,6 +307,9 @@ void YGNode::setPosition(
const YGFlexDirection crossAxis =
YGFlexDirectionCross(mainAxis, directionRespectingRoot);
// Here we should check for `YGPositionTypeStatic` and in this case zero inset
// properties (left, right, top, bottom, begin, end).
// https://www.w3.org/TR/css-position-3/#valdef-position-static
const YGFloatOptional relativePositionMain =
relativePosition(mainAxis, mainSize);
const YGFloatOptional relativePositionCross =
@@ -440,7 +443,7 @@ float YGNode::resolveFlexShrink() const {
bool YGNode::isNodeFlexible() {
return (
(style_.positionType() == YGPositionTypeRelative) &&
(style_.positionType() != YGPositionTypeAbsolute) &&
(resolveFlexGrow() != 0 || resolveFlexShrink() != 0));
}

View File

@@ -1131,7 +1131,7 @@ static bool YGIsBaselineLayout(const YGNodeRef node) {
const uint32_t childCount = YGNodeGetChildCount(node);
for (uint32_t i = 0; i < childCount; i++) {
const YGNodeRef child = YGNodeGetChild(node, i);
if (child->getStyle().positionType() == YGPositionTypeRelative &&
if (child->getStyle().positionType() != YGPositionTypeAbsolute &&
child->getStyle().alignSelf() == YGAlignBaseline) {
return true;
}
@@ -2505,7 +2505,7 @@ static void YGJustifyMainAxis(
i < collectedFlexItemsValues.endOfLineIndex;
i++) {
const YGNodeRef child = node->getChild(i);
if (child->getStyle().positionType() == YGPositionTypeRelative) {
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) {
numberOfAutoMarginsOnCurrentLine++;
}
@@ -2589,7 +2589,7 @@ static void YGJustifyMainAxis(
// 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 (childStyle.positionType() == YGPositionTypeRelative) {
if (childStyle.positionType() != YGPositionTypeAbsolute) {
if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) {
collectedFlexItemsValues.mainDim +=
collectedFlexItemsValues.remainingFreeSpace /
@@ -3311,7 +3311,7 @@ static void YGNodelayoutImpl(
if (child->getStyle().display() == YGDisplayNone) {
continue;
}
if (child->getStyle().positionType() == YGPositionTypeRelative) {
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
if (child->getLineIndex() != i) {
break;
}
@@ -3353,7 +3353,7 @@ static void YGNodelayoutImpl(
if (child->getStyle().display() == YGDisplayNone) {
continue;
}
if (child->getStyle().positionType() == YGPositionTypeRelative) {
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
switch (YGNodeAlignItem(node, child)) {
case YGAlignFlexStart: {
child->setLayoutPosition(
@@ -3544,7 +3544,7 @@ static void YGNodelayoutImpl(
if (performLayout && node->getStyle().flexWrap() == YGWrapWrapReverse) {
for (uint32_t i = 0; i < childCount; i++) {
const YGNodeRef child = YGNodeGetChild(node, i);
if (child->getStyle().positionType() == YGPositionTypeRelative) {
if (child->getStyle().positionType() != YGPositionTypeAbsolute) {
child->setLayoutPosition(
node->getLayout().measuredDimensions[dim[crossAxis]] -
child->getLayout().position[pos[crossAxis]] -