Fix and add tests for cssedge priority

Summary: While adding tests for CSSEdge I found that when setting both horizontal/vertical/all + left/right then left/right were not correctly overriding the others. This is now fixed and validated through added tests

Reviewed By: lucasr

Differential Revision: D3791106

fbshipit-source-id: 3e0c943f94218848a1fbf36e5ae48dbc720ea923
This commit is contained in:
Emil Sjolander
2016-08-31 08:02:40 -07:00
committed by Facebook Github Bot 2
parent 36eaae88e0
commit 583830b3df
2 changed files with 165 additions and 16 deletions

View File

@@ -479,8 +479,8 @@ static bool isColumnDirection(const CSSFlexDirection flexDirection) {
static float getLeadingMargin(const CSSNodeRef node, const CSSFlexDirection axis) {
if (isRowDirection(axis) &&
!CSSValueIsUndefined(computedEdgeValue(node->style.margin, CSSEdgeStart, 0))) {
return computedEdgeValue(node->style.margin, CSSEdgeStart, 0);
!CSSValueIsUndefined(node->style.margin[CSSEdgeStart])) {
return node->style.margin[CSSEdgeStart];
}
return computedEdgeValue(node->style.margin, leading[axis], 0);
@@ -488,8 +488,8 @@ static float getLeadingMargin(const CSSNodeRef node, const CSSFlexDirection axis
static float getTrailingMargin(const CSSNodeRef node, const CSSFlexDirection axis) {
if (isRowDirection(axis) &&
!CSSValueIsUndefined(computedEdgeValue(node->style.margin, CSSEdgeEnd, 0))) {
return computedEdgeValue(node->style.margin, CSSEdgeEnd, 0);
!CSSValueIsUndefined(node->style.margin[CSSEdgeEnd])) {
return node->style.margin[CSSEdgeEnd];
}
return computedEdgeValue(node->style.margin, trailing[axis], 0);
@@ -497,9 +497,9 @@ static float getTrailingMargin(const CSSNodeRef node, const CSSFlexDirection axi
static float getLeadingPadding(const CSSNodeRef node, const CSSFlexDirection axis) {
if (isRowDirection(axis) &&
!CSSValueIsUndefined(computedEdgeValue(node->style.padding, CSSEdgeStart, 0)) &&
computedEdgeValue(node->style.padding, CSSEdgeStart, 0) >= 0) {
return computedEdgeValue(node->style.padding, CSSEdgeStart, 0);
!CSSValueIsUndefined(node->style.padding[CSSEdgeStart]) &&
node->style.padding[CSSEdgeStart] >= 0) {
return node->style.padding[CSSEdgeStart];
}
if (computedEdgeValue(node->style.padding, leading[axis], 0) >= 0) {
@@ -511,9 +511,9 @@ static float getLeadingPadding(const CSSNodeRef node, const CSSFlexDirection axi
static float getTrailingPadding(const CSSNodeRef node, const CSSFlexDirection axis) {
if (isRowDirection(axis) &&
!CSSValueIsUndefined(computedEdgeValue(node->style.padding, CSSEdgeEnd, 0)) &&
computedEdgeValue(node->style.padding, CSSEdgeEnd, 0) >= 0) {
return computedEdgeValue(node->style.padding, CSSEdgeEnd, 0);
!CSSValueIsUndefined(node->style.padding[CSSEdgeEnd]) &&
node->style.padding[CSSEdgeEnd] >= 0) {
return node->style.padding[CSSEdgeEnd];
}
if (computedEdgeValue(node->style.padding, trailing[axis], 0) >= 0) {
@@ -525,9 +525,9 @@ static float getTrailingPadding(const CSSNodeRef node, const CSSFlexDirection ax
static float getLeadingBorder(const CSSNodeRef node, const CSSFlexDirection axis) {
if (isRowDirection(axis) &&
!CSSValueIsUndefined(computedEdgeValue(node->style.border, CSSEdgeStart, 0)) &&
computedEdgeValue(node->style.border, CSSEdgeStart, 0) >= 0) {
return computedEdgeValue(node->style.border, CSSEdgeStart, 0);
!CSSValueIsUndefined(node->style.border[CSSEdgeStart]) &&
node->style.border[CSSEdgeStart] >= 0) {
return node->style.border[CSSEdgeStart];
}
if (computedEdgeValue(node->style.border, leading[axis], 0) >= 0) {
@@ -539,9 +539,9 @@ static float getLeadingBorder(const CSSNodeRef node, const CSSFlexDirection axis
static float getTrailingBorder(const CSSNodeRef node, const CSSFlexDirection axis) {
if (isRowDirection(axis) &&
!CSSValueIsUndefined(computedEdgeValue(node->style.border, CSSEdgeEnd, 0)) &&
computedEdgeValue(node->style.border, CSSEdgeEnd, 0) >= 0) {
return computedEdgeValue(node->style.border, CSSEdgeEnd, 0);
!CSSValueIsUndefined(node->style.border[CSSEdgeEnd]) &&
node->style.border[CSSEdgeEnd] >= 0) {
return node->style.border[CSSEdgeEnd];
}
if (computedEdgeValue(node->style.border, trailing[axis], 0) >= 0) {

149
tests/CSSLayoutEdgeTest.cpp Normal file
View File

@@ -0,0 +1,149 @@
/**
* 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.
*/
#include <CSSLayout/CSSLayout.h>
#include <gtest/gtest.h>
TEST(CSSLayoutTest, start_overrides) {
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow);
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeStyleSetFlexGrow(root_child0, 1);
CSSNodeStyleSetMargin(root_child0, CSSEdgeStart, 10);
CSSNodeStyleSetMargin(root_child0, CSSEdgeLeft, 20);
CSSNodeStyleSetMargin(root_child0, CSSEdgeRight, 20);
CSSNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0));
ASSERT_EQ(20, CSSNodeLayoutGetRight(root_child0));
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL);
ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0));
ASSERT_EQ(10, CSSNodeLayoutGetRight(root_child0));
}
TEST(CSSLayoutTest, end_overrides) {
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow);
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeStyleSetFlexGrow(root_child0, 1);
CSSNodeStyleSetMargin(root_child0, CSSEdgeEnd, 10);
CSSNodeStyleSetMargin(root_child0, CSSEdgeLeft, 20);
CSSNodeStyleSetMargin(root_child0, CSSEdgeRight, 20);
CSSNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0));
ASSERT_EQ(10, CSSNodeLayoutGetRight(root_child0));
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL);
ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0));
ASSERT_EQ(20, CSSNodeLayoutGetRight(root_child0));
}
TEST(CSSLayoutTest, horizontal_overridden) {
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow);
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeStyleSetFlexGrow(root_child0, 1);
CSSNodeStyleSetMargin(root_child0, CSSEdgeHorizontal, 10);
CSSNodeStyleSetMargin(root_child0, CSSEdgeLeft, 20);
CSSNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0));
ASSERT_EQ(10, CSSNodeLayoutGetRight(root_child0));
}
TEST(CSSLayoutTest, vertical_overridden) {
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionColumn);
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeStyleSetFlexGrow(root_child0, 1);
CSSNodeStyleSetMargin(root_child0, CSSEdgeVertical, 10);
CSSNodeStyleSetMargin(root_child0, CSSEdgeTop, 20);
CSSNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child0));
ASSERT_EQ(10, CSSNodeLayoutGetBottom(root_child0));
}
TEST(CSSLayoutTest, horizontal_overrides_all) {
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionColumn);
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeStyleSetFlexGrow(root_child0, 1);
CSSNodeStyleSetMargin(root_child0, CSSEdgeHorizontal, 10);
CSSNodeStyleSetMargin(root_child0, CSSEdgeAll, 20);
CSSNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0));
ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child0));
ASSERT_EQ(10, CSSNodeLayoutGetRight(root_child0));
ASSERT_EQ(20, CSSNodeLayoutGetBottom(root_child0));
}
TEST(CSSLayoutTest, vertical_overrides_all) {
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionColumn);
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeStyleSetFlexGrow(root_child0, 1);
CSSNodeStyleSetMargin(root_child0, CSSEdgeVertical, 10);
CSSNodeStyleSetMargin(root_child0, CSSEdgeAll, 20);
CSSNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
ASSERT_EQ(20, CSSNodeLayoutGetLeft(root_child0));
ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0));
ASSERT_EQ(20, CSSNodeLayoutGetRight(root_child0));
ASSERT_EQ(10, CSSNodeLayoutGetBottom(root_child0));
}
TEST(CSSLayoutTest, all_overridden) {
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionColumn);
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
const CSSNodeRef root_child0 = CSSNodeNew();
CSSNodeStyleSetFlexGrow(root_child0, 1);
CSSNodeStyleSetMargin(root_child0, CSSEdgeLeft, 10);
CSSNodeStyleSetMargin(root_child0, CSSEdgeTop, 10);
CSSNodeStyleSetMargin(root_child0, CSSEdgeRight, 10);
CSSNodeStyleSetMargin(root_child0, CSSEdgeBottom, 10);
CSSNodeStyleSetMargin(root_child0, CSSEdgeAll, 20);
CSSNodeInsertChild(root, root_child0, 0);
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child0));
ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0));
ASSERT_EQ(10, CSSNodeLayoutGetRight(root_child0));
ASSERT_EQ(10, CSSNodeLayoutGetBottom(root_child0));
}