2014-10-29 08:01:22 -07:00
|
|
|
/**
|
2016-07-25 06:31:32 -07:00
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
2014-10-29 08:01:22 -07:00
|
|
|
* 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.
|
|
|
|
*/
|
2016-07-25 06:31:32 -07:00
|
|
|
|
2014-09-18 15:15:21 -07:00
|
|
|
package com.facebook.csslayout;
|
|
|
|
|
2015-10-05 16:26:59 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
2014-09-18 15:15:21 -07:00
|
|
|
/**
|
2016-10-12 02:49:37 -07:00
|
|
|
* The CSS style definition for a {@link CSSNodeDEPRECATED}.
|
2014-09-18 15:15:21 -07:00
|
|
|
*/
|
|
|
|
public class CSSStyle {
|
|
|
|
|
2015-10-05 16:26:59 +01:00
|
|
|
public CSSDirection direction;
|
|
|
|
public CSSFlexDirection flexDirection;
|
|
|
|
public CSSJustify justifyContent;
|
|
|
|
public CSSAlign alignContent;
|
|
|
|
public CSSAlign alignItems;
|
|
|
|
public CSSAlign alignSelf;
|
|
|
|
public CSSPositionType positionType;
|
|
|
|
public CSSWrap flexWrap;
|
Alter layout engine to conform closer to W3C spec
The primary goals of this change are:
- Better conformance to the W3C flexbox standard (https://www.w3.org/TR/css-flexbox-1/)
and a clear articulation of the areas where it deviates from the spec.
- Support for flex-shrink.
- Conformance with layout effects of "overflow: hidden".
Specifically, here are the limitations of this implementation as compared to the W3C
flexbox standard (this is also documented in Layout.js):
- Display property is always assumed to be 'flex' except for Text nodes, which
are assumed to be 'inline-flex'.
- The 'zIndex' property (or any form of z ordering) is not supported. Nodes are
stacked in document order.
- The 'order' property is not supported. The order of flex items is always defined
by document order.
- The 'visibility' property is always assumed to be 'visible'. Values of 'collapse'
and 'hidden' are not supported.
- The 'wrap' property supports only 'nowrap' (which is the default) or 'wrap'. The
rarely-used 'wrap-reverse' is not supported.
- Rather than allowing arbitrary combinations of flexGrow, flexShrink and
flexBasis, this algorithm supports only the three most common combinations:
- flex: 0 is equiavlent to flex: 0 0 auto
- flex: n (where n is a positive value) is equivalent to flex: n 0 0
- flex: -1 (or any negative value) is equivalent to flex: 0 1 auto
- Margins cannot be specified as 'auto'. They must be specified in terms of pixel
values, and the default value is 0.
- The 'baseline' value is not supported for alignItems and alignSelf properties.
- Values of width, maxWidth, minWidth, height, maxHeight and minHeight must be
specified as pixel values, not as percentages.
- There is no support for calculation of dimensions based on intrinsic aspect ratios
(e.g. images).
- There is no support for forced breaks.
- It does not support vertical inline directions (top-to-bottom or bottom-to-top text).
And here is how the implementation deviates from the standard (this is also documented in
Layout.js):
- Section 4.5 of the spec indicates that all flex items have a default minimum
main size. For text blocks, for example, this is the width of the widest word.
Calculating the minimum width is expensive, so we forego it and assume a default
minimum main size of 0.
- Min/Max sizes in the main axis are not honored when resolving flexible lengths.
- The spec indicates that the default value for 'flexDirection' is 'row', but
the algorithm below assumes a default of 'column'.
2016-04-26 16:35:46 -07:00
|
|
|
public CSSOverflow overflow;
|
2016-08-23 04:36:55 -07:00
|
|
|
public float flexGrow;
|
|
|
|
public float flexShrink;
|
|
|
|
public float flexBasis;
|
2014-09-18 15:15:21 -07:00
|
|
|
|
2015-05-14 13:59:13 +01:00
|
|
|
public Spacing margin = new Spacing();
|
|
|
|
public Spacing padding = new Spacing();
|
|
|
|
public Spacing border = new Spacing();
|
2016-08-18 03:15:51 -07:00
|
|
|
public Spacing position = new Spacing(CSSConstants.UNDEFINED);
|
2014-09-18 15:15:21 -07:00
|
|
|
|
2015-10-05 16:26:59 +01:00
|
|
|
public float[] dimensions = new float[2];
|
2015-03-31 17:27:13 +08:00
|
|
|
|
|
|
|
public float minWidth = CSSConstants.UNDEFINED;
|
|
|
|
public float minHeight = CSSConstants.UNDEFINED;
|
|
|
|
|
|
|
|
public float maxWidth = CSSConstants.UNDEFINED;
|
|
|
|
public float maxHeight = CSSConstants.UNDEFINED;
|
2015-10-05 16:26:59 +01:00
|
|
|
|
|
|
|
CSSStyle() {
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
direction = CSSDirection.INHERIT;
|
|
|
|
flexDirection = CSSFlexDirection.COLUMN;
|
|
|
|
justifyContent = CSSJustify.FLEX_START;
|
|
|
|
alignContent = CSSAlign.FLEX_START;
|
|
|
|
alignItems = CSSAlign.STRETCH;
|
|
|
|
alignSelf = CSSAlign.AUTO;
|
|
|
|
positionType = CSSPositionType.RELATIVE;
|
2016-11-15 08:42:33 -08:00
|
|
|
flexWrap = CSSWrap.NO_WRAP;
|
Alter layout engine to conform closer to W3C spec
The primary goals of this change are:
- Better conformance to the W3C flexbox standard (https://www.w3.org/TR/css-flexbox-1/)
and a clear articulation of the areas where it deviates from the spec.
- Support for flex-shrink.
- Conformance with layout effects of "overflow: hidden".
Specifically, here are the limitations of this implementation as compared to the W3C
flexbox standard (this is also documented in Layout.js):
- Display property is always assumed to be 'flex' except for Text nodes, which
are assumed to be 'inline-flex'.
- The 'zIndex' property (or any form of z ordering) is not supported. Nodes are
stacked in document order.
- The 'order' property is not supported. The order of flex items is always defined
by document order.
- The 'visibility' property is always assumed to be 'visible'. Values of 'collapse'
and 'hidden' are not supported.
- The 'wrap' property supports only 'nowrap' (which is the default) or 'wrap'. The
rarely-used 'wrap-reverse' is not supported.
- Rather than allowing arbitrary combinations of flexGrow, flexShrink and
flexBasis, this algorithm supports only the three most common combinations:
- flex: 0 is equiavlent to flex: 0 0 auto
- flex: n (where n is a positive value) is equivalent to flex: n 0 0
- flex: -1 (or any negative value) is equivalent to flex: 0 1 auto
- Margins cannot be specified as 'auto'. They must be specified in terms of pixel
values, and the default value is 0.
- The 'baseline' value is not supported for alignItems and alignSelf properties.
- Values of width, maxWidth, minWidth, height, maxHeight and minHeight must be
specified as pixel values, not as percentages.
- There is no support for calculation of dimensions based on intrinsic aspect ratios
(e.g. images).
- There is no support for forced breaks.
- It does not support vertical inline directions (top-to-bottom or bottom-to-top text).
And here is how the implementation deviates from the standard (this is also documented in
Layout.js):
- Section 4.5 of the spec indicates that all flex items have a default minimum
main size. For text blocks, for example, this is the width of the widest word.
Calculating the minimum width is expensive, so we forego it and assume a default
minimum main size of 0.
- Min/Max sizes in the main axis are not honored when resolving flexible lengths.
- The spec indicates that the default value for 'flexDirection' is 'row', but
the algorithm below assumes a default of 'column'.
2016-04-26 16:35:46 -07:00
|
|
|
overflow = CSSOverflow.VISIBLE;
|
2016-08-23 04:36:55 -07:00
|
|
|
flexGrow = 0;
|
|
|
|
flexShrink = 0;
|
|
|
|
flexBasis = CSSConstants.UNDEFINED;
|
2015-10-05 16:26:59 +01:00
|
|
|
|
2016-07-28 14:43:40 -07:00
|
|
|
margin.reset();
|
2015-10-05 16:26:59 +01:00
|
|
|
padding.reset();
|
|
|
|
border.reset();
|
2016-07-28 14:43:40 -07:00
|
|
|
position.reset();
|
|
|
|
|
2015-10-05 16:26:59 +01:00
|
|
|
Arrays.fill(dimensions, CSSConstants.UNDEFINED);
|
|
|
|
|
|
|
|
minWidth = CSSConstants.UNDEFINED;
|
|
|
|
minHeight = CSSConstants.UNDEFINED;
|
|
|
|
|
|
|
|
maxWidth = CSSConstants.UNDEFINED;
|
|
|
|
maxHeight = CSSConstants.UNDEFINED;
|
|
|
|
}
|
2014-09-18 15:15:21 -07:00
|
|
|
}
|