BREAKING - Fix unconstraint sizing in main axis

Summary:
@public
Introduce `overflow:scroll` so that scrolling can be implemented without the current overflow:visible hackiness. Currently we use AT_MOST to measure in the cross axis but not in the main axis. This was done to enable scrolling containers where children are not constraint in the main axis by their parent. This caused problems for non-scrolling containers though as it meant that their children cannot be measured correctly in the main axis. Introducing `overflow:scroll` fixes this.

Reviewed By: astreet

Differential Revision: D3855801

fbshipit-source-id: 6077b0bcb68fe5ddd4aa22926acab40ff4d83949
This commit is contained in:
Emil Sjolander
2016-09-14 09:00:26 -07:00
committed by Facebook Github Bot 0
parent 0be3b1013f
commit d4121401d7
4 changed files with 28 additions and 36 deletions

View File

@@ -451,6 +451,8 @@ print_css_node_rec(const CSSNodeRef node, const CSSPrintOptions options, const u
printf("overflow: 'hidden', "); printf("overflow: 'hidden', ");
} else if (node->style.overflow == CSSOverflowVisible) { } else if (node->style.overflow == CSSOverflowVisible) {
printf("overflow: 'visible', "); printf("overflow: 'visible', ");
} else if (node->style.overflow == CSSOverflowScroll) {
printf("overflow: 'scroll', ");
} }
if (four_equal(node->style.margin)) { if (four_equal(node->style.margin)) {
@@ -555,8 +557,7 @@ static bool isColumnDirection(const CSSFlexDirection flexDirection) {
} }
static float getLeadingMargin(const CSSNodeRef node, const CSSFlexDirection axis) { static float getLeadingMargin(const CSSNodeRef node, const CSSFlexDirection axis) {
if (isRowDirection(axis) && if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[CSSEdgeStart])) {
!CSSValueIsUndefined(node->style.margin[CSSEdgeStart])) {
return node->style.margin[CSSEdgeStart]; return node->style.margin[CSSEdgeStart];
} }
@@ -564,8 +565,7 @@ static float getLeadingMargin(const CSSNodeRef node, const CSSFlexDirection axis
} }
static float getTrailingMargin(const CSSNodeRef node, const CSSFlexDirection axis) { static float getTrailingMargin(const CSSNodeRef node, const CSSFlexDirection axis) {
if (isRowDirection(axis) && if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.margin[CSSEdgeEnd])) {
!CSSValueIsUndefined(node->style.margin[CSSEdgeEnd])) {
return node->style.margin[CSSEdgeEnd]; return node->style.margin[CSSEdgeEnd];
} }
@@ -573,8 +573,7 @@ static float getTrailingMargin(const CSSNodeRef node, const CSSFlexDirection axi
} }
static float getLeadingPadding(const CSSNodeRef node, const CSSFlexDirection axis) { static float getLeadingPadding(const CSSNodeRef node, const CSSFlexDirection axis) {
if (isRowDirection(axis) && if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[CSSEdgeStart]) &&
!CSSValueIsUndefined(node->style.padding[CSSEdgeStart]) &&
node->style.padding[CSSEdgeStart] >= 0) { node->style.padding[CSSEdgeStart] >= 0) {
return node->style.padding[CSSEdgeStart]; return node->style.padding[CSSEdgeStart];
} }
@@ -587,8 +586,7 @@ static float getLeadingPadding(const CSSNodeRef node, const CSSFlexDirection axi
} }
static float getTrailingPadding(const CSSNodeRef node, const CSSFlexDirection axis) { static float getTrailingPadding(const CSSNodeRef node, const CSSFlexDirection axis) {
if (isRowDirection(axis) && if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.padding[CSSEdgeEnd]) &&
!CSSValueIsUndefined(node->style.padding[CSSEdgeEnd]) &&
node->style.padding[CSSEdgeEnd] >= 0) { node->style.padding[CSSEdgeEnd] >= 0) {
return node->style.padding[CSSEdgeEnd]; return node->style.padding[CSSEdgeEnd];
} }
@@ -601,8 +599,7 @@ static float getTrailingPadding(const CSSNodeRef node, const CSSFlexDirection ax
} }
static float getLeadingBorder(const CSSNodeRef node, const CSSFlexDirection axis) { static float getLeadingBorder(const CSSNodeRef node, const CSSFlexDirection axis) {
if (isRowDirection(axis) && if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[CSSEdgeStart]) &&
!CSSValueIsUndefined(node->style.border[CSSEdgeStart]) &&
node->style.border[CSSEdgeStart] >= 0) { node->style.border[CSSEdgeStart] >= 0) {
return node->style.border[CSSEdgeStart]; return node->style.border[CSSEdgeStart];
} }
@@ -615,8 +612,7 @@ static float getLeadingBorder(const CSSNodeRef node, const CSSFlexDirection axis
} }
static float getTrailingBorder(const CSSNodeRef node, const CSSFlexDirection axis) { static float getTrailingBorder(const CSSNodeRef node, const CSSFlexDirection axis) {
if (isRowDirection(axis) && if (isRowDirection(axis) && !CSSValueIsUndefined(node->style.border[CSSEdgeEnd]) &&
!CSSValueIsUndefined(node->style.border[CSSEdgeEnd]) &&
node->style.border[CSSEdgeEnd] >= 0) { node->style.border[CSSEdgeEnd] >= 0) {
return node->style.border[CSSEdgeEnd]; return node->style.border[CSSEdgeEnd];
} }
@@ -1140,21 +1136,17 @@ static void layoutNodeImpl(const CSSNodeRef node,
childHeightMeasureMode = CSSMeasureModeExactly; childHeightMeasureMode = CSSMeasureModeExactly;
} }
// According to the spec, if the main size is not definite and the
// child's inline axis is parallel to the main axis (i.e. it's
// horizontal), the child should be sized using "UNDEFINED" in
// the main size. Otherwise use "AT_MOST" in the cross axis.
if (!isMainAxisRow && CSSValueIsUndefined(childWidth) &&
!CSSValueIsUndefined(availableInnerWidth)) {
childWidth = availableInnerWidth;
childWidthMeasureMode = CSSMeasureModeAtMost;
}
// The W3C spec doesn't say anything about the 'overflow' property, // The W3C spec doesn't say anything about the 'overflow' property,
// but all major browsers appear to implement the following logic. // but all major browsers appear to implement the following logic.
if (node->style.overflow == CSSOverflowHidden) { if ((!isMainAxisRow && node->style.overflow == CSSOverflowScroll) || node->style.overflow != CSSOverflowScroll) {
if (isMainAxisRow && CSSValueIsUndefined(childHeight) && if (CSSValueIsUndefined(childWidth) && !CSSValueIsUndefined(availableInnerWidth)) {
!CSSValueIsUndefined(availableInnerHeight)) { childWidth = availableInnerWidth;
childWidthMeasureMode = CSSMeasureModeAtMost;
}
}
if ((isMainAxisRow && node->style.overflow == CSSOverflowScroll) || node->style.overflow != CSSOverflowScroll) {
if (CSSValueIsUndefined(childHeight) && !CSSValueIsUndefined(availableInnerHeight)) {
childHeight = availableInnerHeight; childHeight = availableInnerHeight;
childHeightMeasureMode = CSSMeasureModeAtMost; childHeightMeasureMode = CSSMeasureModeAtMost;
} }

View File

@@ -55,6 +55,7 @@ typedef enum CSSJustify {
typedef enum CSSOverflow { typedef enum CSSOverflow {
CSSOverflowVisible, CSSOverflowVisible,
CSSOverflowHidden, CSSOverflowHidden,
CSSOverflowScroll,
} CSSOverflow; } CSSOverflow;
// Note: auto is only a valid value for alignSelf. It is NOT a valid value for // Note: auto is only a valid value for alignSelf. It is NOT a valid value for

View File

@@ -12,4 +12,5 @@ package com.facebook.csslayout;
public enum CSSOverflow { public enum CSSOverflow {
VISIBLE, VISIBLE,
HIDDEN, HIDDEN,
SCROLL,
} }

View File

@@ -715,19 +715,17 @@ public class LayoutEngine {
childHeightMeasureMode = CSSMeasureMode.EXACTLY; childHeightMeasureMode = CSSMeasureMode.EXACTLY;
} }
// 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 && Float.isNaN(childWidth) && !Float.isNaN(availableInnerWidth)) {
childWidth = availableInnerWidth;
childWidthMeasureMode = CSSMeasureMode.AT_MOST;
}
// The W3C spec doesn't say anything about the 'overflow' property, // The W3C spec doesn't say anything about the 'overflow' property,
// but all major browsers appear to implement the following logic. // but all major browsers appear to implement the following logic.
if (node.style.overflow == CSSOverflow.HIDDEN) { if ((!isMainAxisRow && node.style.overflow == CSSOverflow.SCROLL) || node.style.overflow != CSSOverflow.SCROLL) {
if (isMainAxisRow && Float.isNaN(childHeight) && !Float.isNaN(availableInnerHeight)) { if (Float.isNaN(childWidth) && !Float.isNaN(availableInnerWidth)) {
childWidth = availableInnerWidth;
childWidthMeasureMode = CSSMeasureMode.AT_MOST;
}
}
if ((isMainAxisRow && node.style.overflow == CSSOverflow.SCROLL) || node.style.overflow != CSSOverflow.SCROLL) {
if (Float.isNaN(childHeight) && !Float.isNaN(availableInnerHeight)) {
childHeight = availableInnerHeight; childHeight = availableInnerHeight;
childHeightMeasureMode = CSSMeasureMode.AT_MOST; childHeightMeasureMode = CSSMeasureMode.AT_MOST;
} }