Ignore:
Timestamp:
Jun 27, 2012, 4:05:19 PM (13 years ago)
Author:
[email protected]
Message:

Split flex into flex-grow/flex-shrink/flex-basis
https://bugs.webkit.org/show_bug.cgi?id=86525

Reviewed by Ojan Vafai.

Source/WebCore:

Split flex into 3 separate properties per the spec:
http://dev.w3.org/csswg/css3-flexbox/#flex-components

Tests: css3/flexbox/flex-longhand-parsing.html

css3/flexbox/flex-property-parsing.html: Updated test results.

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore): -webkit-flex is no longer enumerable.
(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): Add new css property names and use
getCSSPropertyValuesForShorthandProperties for WebkitFlex. Also sort flex propery names.

  • css/CSSParser.cpp:

(WebCore::isValidKeywordPropertyAndValue): Fix indent.
(WebCore::CSSParser::parseValue): Add parsing for new properties and handle -webkit-flex: none.
(WebCore::CSSParser::parseFlex): Switch to new names (positive -> grow, negative -> shrink,
preferred size -> basis) and assign to longhand properties.

  • css/CSSParser.h:
  • css/CSSProperty.cpp:

(WebCore::CSSProperty::isInheritedProperty): Add new properties.

  • css/CSSPropertyNames.in: Add new properties.
  • css/StyleBuilder.cpp:

(WebCore::StyleBuilder::StyleBuilder): Delete special handling of applying flex and just use shorthand handlers.

  • css/StylePropertySet.cpp:

(WebCore::StylePropertySet::getPropertyValue): Add new shorthand.
(WebCore::StylePropertySet::asText):

  • css/StylePropertyShorthand.cpp:

(WebCore::webkitFlexShorthand): Add new shorthand.
(WebCore::shorthandForProperty):

  • css/StylePropertyShorthand.h:
  • css/StyleResolver.cpp:

(WebCore::StyleResolver::collectMatchingRulesForList): Add to list of properties applied by StyleBuilder.

LayoutTests:

If -webkit-flex is set to none, when the user reads the value back out, it is
now 0 0 auto. 'none' is for convenience, not an actual value.

  • css3/flexbox/flex-longhand-parsing-expected.txt:
  • css3/flexbox/flex-longhand-parsing.html: Test flex-grow, flex-shrink and flex-basis.
  • css3/flexbox/flex-property-parsing-expected.txt:
  • css3/flexbox/flex-property-parsing.html: Update results for 'none'.
  • fast/css/getComputedStyle/computed-style-expected.txt:
  • fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
  • fast/css/getComputedStyle/resources/property-names.js: Remove -webkit-flex since it's no longer enumerable.
  • svg/css/getComputedStyle-basic-expected.txt:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/StyleBuilder.cpp

    r121349 r121380  
    17151715        return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue);
    17161716    }
    1717 };
    1718 
    1719 class ApplyPropertyFlex {
    1720 public:
    1721     static void applyInheritValue(StyleResolver* styleResolver)
    1722     {
    1723         ApplyPropertyDefaultBase<float, &RenderStyle::flexGrow, float, &RenderStyle::setFlexGrow, float, &RenderStyle::initialFlexGrow>::applyInheritValue(styleResolver);
    1724         ApplyPropertyDefaultBase<float, &RenderStyle::flexShrink, float, &RenderStyle::setFlexShrink, float, &RenderStyle::initialFlexShrink>::applyInheritValue(styleResolver);
    1725         ApplyPropertyDefaultBase<Length, &RenderStyle::flexBasis, Length, &RenderStyle::setFlexBasis, Length, &RenderStyle::initialFlexBasis>::applyInheritValue(styleResolver);
    1726     }
    1727 
    1728     static void applyInitialValue(StyleResolver* styleResolver)
    1729     {
    1730         styleResolver->style()->setFlexGrow(RenderStyle::initialFlexGrow());
    1731         styleResolver->style()->setFlexShrink(RenderStyle::initialFlexShrink());
    1732         styleResolver->style()->setFlexBasis(RenderStyle::initialFlexBasis());
    1733     }
    1734 
    1735     static void applyValue(StyleResolver* styleResolver, CSSValue* value)
    1736     {
    1737         if (value->isPrimitiveValue()) {
    1738             CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    1739             if (primitiveValue->getIdent() == CSSValueNone) {
    1740                 styleResolver->style()->setFlexGrow(0);
    1741                 styleResolver->style()->setFlexShrink(0);
    1742                 styleResolver->style()->setFlexBasis(Length(Auto));
    1743             }
    1744             return;
    1745         }
    1746 
    1747         if (!value->isValueList())
    1748             return;
    1749         CSSValueList* valueList = static_cast<CSSValueList*>(value);
    1750         if (valueList->length() != 3)
    1751             return;
    1752 
    1753         float flexValue = 0;
    1754         if (!getFlexValue(valueList->itemWithoutBoundsCheck(0), flexValue))
    1755             return;
    1756         styleResolver->style()->setFlexGrow(flexValue);
    1757 
    1758         if (!getFlexValue(valueList->itemWithoutBoundsCheck(1), flexValue))
    1759             return;
    1760         styleResolver->style()->setFlexShrink(flexValue);
    1761 
    1762         ApplyPropertyLength<&RenderStyle::flexBasis, &RenderStyle::setFlexBasis, &RenderStyle::initialFlexBasis, AutoEnabled>::applyValue(styleResolver, valueList->itemWithoutBoundsCheck(2));
    1763     }
    1764 
    1765     static PropertyHandler createHandler()
    1766     {
    1767         return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue);
    1768     }
    1769 private:
    1770     static bool getFlexValue(CSSValue* value, float& flexValue)
    1771     {
    1772         if (!value->isPrimitiveValue())
    1773             return false;
    1774         CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    1775         if (!primitiveValue->isNumber())
    1776             return false;
    1777         flexValue = primitiveValue->getFloatValue();
    1778         return true;
    1779     }
    1780 
    17811717};
    17821718
     
    20311967    setPropertyHandler(CSSPropertyWebkitAlignItems, ApplyPropertyDefault<EAlignItems, &RenderStyle::alignItems, EAlignItems, &RenderStyle::setAlignItems, EAlignItems, &RenderStyle::initialAlignItems>::createHandler());
    20321968    setPropertyHandler(CSSPropertyWebkitAlignSelf, ApplyPropertyDefault<EAlignItems, &RenderStyle::alignSelf, EAlignItems, &RenderStyle::setAlignSelf, EAlignItems, &RenderStyle::initialAlignSelf>::createHandler());
    2033     setPropertyHandler(CSSPropertyWebkitFlex, ApplyPropertyFlex::createHandler());
     1969    setPropertyHandler(CSSPropertyWebkitFlexBasis, ApplyPropertyLength<&RenderStyle::flexBasis, &RenderStyle::setFlexBasis, &RenderStyle::initialFlexBasis, AutoEnabled>::createHandler());
    20341970    setPropertyHandler(CSSPropertyWebkitFlexDirection, ApplyPropertyDefault<EFlexDirection, &RenderStyle::flexDirection, EFlexDirection, &RenderStyle::setFlexDirection, EFlexDirection, &RenderStyle::initialFlexDirection>::createHandler());
    2035     setPropertyHandler(CSSPropertyWebkitFlexFlow, ApplyPropertyExpanding<SuppressValue, CSSPropertyWebkitFlexDirection, CSSPropertyWebkitFlexWrap>::createHandler());
     1971    setPropertyHandler(CSSPropertyWebkitFlexGrow, ApplyPropertyDefault<float, &RenderStyle::flexGrow, float, &RenderStyle::setFlexGrow, float, &RenderStyle::initialFlexGrow>::createHandler());
     1972    setPropertyHandler(CSSPropertyWebkitFlexShrink, ApplyPropertyDefault<float, &RenderStyle::flexShrink, float, &RenderStyle::setFlexShrink, float, &RenderStyle::initialFlexShrink>::createHandler());
    20361973    setPropertyHandler(CSSPropertyWebkitFlexWrap, ApplyPropertyDefault<EFlexWrap, &RenderStyle::flexWrap, EFlexWrap, &RenderStyle::setFlexWrap, EFlexWrap, &RenderStyle::initialFlexWrap>::createHandler());
    20371974    setPropertyHandler(CSSPropertyWebkitJustifyContent, ApplyPropertyDefault<EJustifyContent, &RenderStyle::justifyContent, EJustifyContent, &RenderStyle::setJustifyContent, EJustifyContent, &RenderStyle::initialJustifyContent>::createHandler());
Note: See TracChangeset for help on using the changeset viewer.