Ignore:
Timestamp:
May 30, 2016, 1:14:31 AM (10 years ago)
Author:
jfernandez@igalia.com
Message:

[CSS Box Alignment] New CSS Value 'normal' for Self Alignment
https://bugs.webkit.org/show_bug.cgi?id=156254

Reviewed by Darin Adler.

Source/WebCore:

The Box Alignment specification defines a new value 'normal' to be used
as default for the different layout models, which will define the
specific behavior for each case. This patch adds a new CSS value in the
parsing logic and adapts the Self Alignment properties to the new
value.

The 'auto' value is no longer valid for the 'align-items' property and
the Computed Value will be always the specified value. Hence, I removed
the StyleResolver logic because is not required now; the specific
behavior of the 'normal' value will be resolved at layout time.

Additionally, this patch updates the layout logic as well, for both
Flexbox and Grid layout models.

Test: css3/parse-alignment-of-root-elements.html

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::resolveLegacyJustifyItems): Added.
(WebCore::resolveJustifyItemsAuto): Added.
(WebCore::resolveJustifySelfAuto): Added.
(WebCore::resolveAlignSelfAuto): Added.
(WebCore::valueForItemPositionWithOverflowAlignment): Using a StyleSelfAlignmentData argument.
(WebCore::ComputedStyleExtractor::propertyValue): Using the new resolving functions.

  • css/CSSParser.cpp:

(WebCore::CSSParser::parseItemPositionOverflowPosition): A new value 'normal' is now valid.

  • css/CSSPrimitiveValueMappings.h:

(WebCore::CSSPrimitiveValue::CSSPrimitiveValue): Mappings for the new value 'normal'.
(WebCore::CSSPrimitiveValue::operator ItemPosition): Mappings for the new value 'normal'.

  • css/CSSPropertyNames.in:
  • css/StyleResolver.cpp:

(WebCore::StyleResolver::adjustRenderStyle): We don't need to resolve 'legacy" keyword.

  • rendering/RenderBox.cpp:

(WebCore::flexItemHasStretchAlignment):
(WebCore::RenderBox::hasStretchedLogicalWidth):

  • rendering/RenderFlexibleBox.cpp:

(WebCore::RenderFlexibleBox::styleDidChange):
(WebCore::RenderFlexibleBox::alignmentForChild):
(WebCore::contentAlignmentNormalBehaviorFlexibleBox):
(WebCore::RenderFlexibleBox::layoutAndPlaceChildren):
(WebCore::RenderFlexibleBox::layoutColumnReverse):
(WebCore::RenderFlexibleBox::alignFlexLines):
(WebCore::RenderFlexibleBox::alignChildren):

  • rendering/RenderGrid.cpp:

(WebCore::defaultAlignmentChangedToStretchInRowAxis):
(WebCore::defaultAlignmentChangedFromStretchInRowAxis):
(WebCore::defaultAlignmentChangedFromStretchInColumnAxis):
(WebCore::selfAlignmentChangedToStretchInRowAxis):
(WebCore::selfAlignmentChangedFromStretchInRowAxis):
(WebCore::selfAlignmentChangedFromStretchInColumnAxis):
(WebCore::contentAlignmentNormalBehaviorGrid):
(WebCore::RenderGrid::applyStretchAlignmentToTracksIfNeeded):
(WebCore::RenderGrid::needToStretchChildLogicalHeight):
(WebCore::RenderGrid::applyStretchAlignmentToChildIfNeeded):
(WebCore::RenderGrid::columnAxisPositionForChild):
(WebCore::RenderGrid::rowAxisPositionForChild):
(WebCore::RenderGrid::columnAxisOffsetForChild):
(WebCore::RenderGrid::rowAxisOffsetForChild):
(WebCore::RenderGrid::computeContentPositionAndDistributionOffset):

  • rendering/style/RenderStyle.cpp:

(WebCore::resolvedSelfAlignment):
(WebCore::RenderStyle::resolvedAlignItems):
(WebCore::RenderStyle::resolvedAlignSelf):
(WebCore::RenderStyle::resolvedJustifyItems):
(WebCore::RenderStyle::resolvedJustifySelf):

  • rendering/style/RenderStyle.h:
  • rendering/style/RenderStyleConstants.h:
  • rendering/style/StyleRareNonInheritedData.cpp:

(WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData): align-items uses now a different initial function.

LayoutTests:

Changes in the already defined tests for the alignment properties to
consider the new CSS value 'normal', which is the default for align-items
and the value to resolve 'auto' when there is no parent.

Added a new test to verify the Self-Alignment properties work as expected
with root elements.

  • css3/flexbox/css-properties-expected.txt:
  • css3/flexbox/css-properties.html:
  • css3/parse-align-items-expected.txt:
  • css3/parse-align-items.html:
  • css3/parse-align-self-expected.txt:
  • css3/parse-align-self.html:
  • css3/parse-alignment-of-root-elements-expected.txt: Added.
  • css3/parse-alignment-of-root-elements.html: Added.
  • fast/css/getComputedStyle/computed-style-expected.txt:
  • fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
  • fast/css/parse-justify-items-expected.txt:
  • fast/css/parse-justify-items.html:
  • fast/css/parse-justify-self-expected.txt:
  • fast/css/parse-justify-self.html:
  • fast/css/resources/alignment-parsing-utils.js:
  • svg/css/getComputedStyle-basic-expected.txt:

(checkBadValues):

  • svg/css/getComputedStyle-basic-expected.txt:
File:
1 edited

Legend:

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

    r201290 r201498  
    22762276}
    22772277
    2278 static ItemPosition resolveContainerAlignmentAuto(ItemPosition position, RenderObject* element)
    2279 {
    2280     if (position != ItemPositionAuto || !element)
    2281         return position;
    2282 
    2283     return element->style().isDisplayFlexibleOrGridBox() ? ItemPositionStretch : ItemPositionStart;
    2284 }
    2285 
    2286 static ItemPosition resolveSelfAlignmentAuto(ItemPosition position, OverflowAlignment& overflow, RenderObject* element)
    2287 {
    2288     if (position != ItemPositionAuto || !element || element->isOutOfFlowPositioned())
    2289         return position;
    2290 
    2291     RenderBlock* parent = element->containingBlock();
    2292     if (!parent)
    2293         return ItemPositionStart;
    2294 
    2295     overflow = parent->style().alignItemsOverflowAlignment();
    2296     return resolveContainerAlignmentAuto(parent->style().alignItemsPosition(), parent);
     2278static StyleSelfAlignmentData resolveLegacyJustifyItems(const StyleSelfAlignmentData& data)
     2279{
     2280    if (data.positionType() == LegacyPosition)
     2281        return { data.position(), OverflowAlignmentDefault };
     2282    return data;
     2283}
     2284
     2285static StyleSelfAlignmentData resolveJustifyItemsAuto(const StyleSelfAlignmentData& data, Node* parent)
     2286{
     2287    if (data.position() != ItemPositionAuto)
     2288        return data;
     2289
     2290    // If the inherited value of justify-items includes the 'legacy' keyword, 'auto' computes to the inherited value.
     2291    const auto& inheritedValue = (!parent || !parent->computedStyle()) ? RenderStyle::initialDefaultAlignment() : parent->computedStyle()->justifyItems();
     2292    if (inheritedValue.positionType() == LegacyPosition)
     2293        return inheritedValue;
     2294    if (inheritedValue.position() == ItemPositionAuto)
     2295        return resolveJustifyItemsAuto(inheritedValue, parent->parentNode());
     2296    return { ItemPositionNormal, OverflowAlignmentDefault };
     2297}
     2298
     2299static StyleSelfAlignmentData resolveJustifySelfAuto(const StyleSelfAlignmentData& data, Node* parent)
     2300{
     2301    if (data.position() != ItemPositionAuto)
     2302        return data;
     2303
     2304    // The 'auto' keyword computes to the computed value of justify-items on the parent or 'normal' if the box has no parent.
     2305    if (!parent || !parent->computedStyle())
     2306        return { ItemPositionNormal, OverflowAlignmentDefault };
     2307    return resolveLegacyJustifyItems(resolveJustifyItemsAuto(parent->computedStyle()->justifyItems(), parent->parentNode()));
     2308}
     2309
     2310static StyleSelfAlignmentData resolveAlignSelfAuto(const StyleSelfAlignmentData& data, Node* parent)
     2311{
     2312    if (data.position() != ItemPositionAuto)
     2313        return data;
     2314
     2315    // The 'auto' keyword computes to the computed value of align-items on the parent or 'normal' if the box has no parent.
     2316    if (!parent || !parent->computedStyle())
     2317        return { ItemPositionNormal, OverflowAlignmentDefault };
     2318    return parent->computedStyle()->alignItems();
    22972319}
    22982320
     
    23772399#endif
    23782400
    2379 static RefPtr<CSSValueList> valueForItemPositionWithOverflowAlignment(ItemPosition itemPosition, OverflowAlignment overflowAlignment, ItemPositionType positionType)
     2401static Ref<CSSValueList> valueForItemPositionWithOverflowAlignment(const StyleSelfAlignmentData& data)
    23802402{
    23812403    auto& cssValuePool = CSSValuePool::singleton();
    2382     RefPtr<CSSValueList> result = CSSValueList::createSpaceSeparated();
    2383     if (positionType == LegacyPosition)
    2384         result->append(CSSPrimitiveValue::createIdentifier(CSSValueLegacy));
    2385     result->append(cssValuePool.createValue(itemPosition));
    2386     if (overflowAlignment != OverflowAlignmentDefault)
    2387         result->append(cssValuePool.createValue(overflowAlignment));
    2388     ASSERT(result->length() <= 2);
     2404    auto result = CSSValueList::createSpaceSeparated();
     2405    if (data.positionType() == LegacyPosition)
     2406        result.get().append(cssValuePool.createIdentifierValue(CSSValueLegacy));
     2407    result.get().append(cssValuePool.createValue(data.position()));
     2408    if (data.position() >= ItemPositionCenter && data.overflow() != OverflowAlignmentDefault)
     2409        result.get().append(cssValuePool.createValue(data.overflow()));
     2410    ASSERT(result.get().length() <= 2);
    23892411    return result;
    23902412}
    23912413
    2392 static RefPtr<CSSValueList> valueForContentPositionAndDistributionWithOverflowAlignment(const StyleContentAlignmentData& data)
    2393 {
    2394     RefPtr<CSSValueList> result = CSSValueList::createSpaceSeparated();
     2414static Ref<CSSValueList> valueForContentPositionAndDistributionWithOverflowAlignment(const StyleContentAlignmentData& data)
     2415{
     2416    auto& cssValuePool = CSSValuePool::singleton();
     2417    auto result = CSSValueList::createSpaceSeparated();
    23952418    if (data.distribution() != ContentDistributionDefault)
    2396         result->append(CSSPrimitiveValue::create(data.distribution()));
     2419        result.get().append(cssValuePool.createValue(data.distribution()));
    23972420    if (data.distribution() == ContentDistributionDefault || data.position() != ContentPositionNormal)
    2398         result->append(CSSPrimitiveValue::create(data.position()));
     2421        result.get().append(cssValuePool.createValue(data.position()));
    23992422    if ((data.position() >= ContentPositionCenter || data.distribution() != ContentDistributionDefault) && data.overflow() != OverflowAlignmentDefault)
    2400         result->append(CSSPrimitiveValue::create(data.overflow()));
    2401     ASSERT(result->length() > 0);
    2402     ASSERT(result->length() <= 3);
     2423        result.get().append(cssValuePool.createValue(data.overflow()));
     2424    ASSERT(result.get().length() > 0);
     2425    ASSERT(result.get().length() <= 3);
    24032426    return result;
    24042427}
     
    27802803            return valueForContentPositionAndDistributionWithOverflowAlignment(style->alignContent());
    27812804        case CSSPropertyAlignItems:
    2782             return valueForItemPositionWithOverflowAlignment(resolveContainerAlignmentAuto(style->alignItemsPosition(), renderer), style->alignItemsOverflowAlignment(), NonLegacyPosition);
    2783         case CSSPropertyAlignSelf: {
    2784             OverflowAlignment overflow = style->alignSelfOverflowAlignment();
    2785             ItemPosition alignSelf = resolveSelfAlignmentAuto(style->alignSelfPosition(), overflow, renderer);
    2786             return valueForItemPositionWithOverflowAlignment(alignSelf, overflow, NonLegacyPosition);
    2787         }
     2805            return valueForItemPositionWithOverflowAlignment(style->alignItems());
     2806        case CSSPropertyAlignSelf:
     2807            return valueForItemPositionWithOverflowAlignment(resolveAlignSelfAuto(style->alignSelf(), styledNode->parentNode()));
    27882808        case CSSPropertyFlex:
    27892809            return getCSSPropertyValuesForShorthandProperties(flexShorthand());
     
    28032823            return valueForContentPositionAndDistributionWithOverflowAlignment(style->justifyContent());
    28042824        case CSSPropertyJustifyItems:
    2805             return valueForItemPositionWithOverflowAlignment(resolveContainerAlignmentAuto(style->justifyItemsPosition(), renderer), style->justifyItemsOverflowAlignment(), style->justifyItemsPositionType());
    2806         case CSSPropertyJustifySelf: {
    2807             OverflowAlignment overflow = style->justifySelfOverflowAlignment();
    2808             ItemPosition justifySelf = resolveSelfAlignmentAuto(style->justifySelfPosition(), overflow, renderer);
    2809             return valueForItemPositionWithOverflowAlignment(justifySelf, overflow, NonLegacyPosition);
    2810         }
     2825            return valueForItemPositionWithOverflowAlignment(resolveJustifyItemsAuto(style->justifyItems(), styledNode->parentNode()));
     2826        case CSSPropertyJustifySelf:
     2827            return valueForItemPositionWithOverflowAlignment(resolveJustifySelfAuto(style->justifySelf(), styledNode->parentNode()));
    28112828        case CSSPropertyOrder:
    28122829            return cssValuePool.createValue(style->order(), CSSPrimitiveValue::CSS_NUMBER);
Note: See TracChangeset for help on using the changeset viewer.