Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: Source/core/css/CSSComputedStyleDeclaration.cpp

Issue 636993002: [CSS Grid Layout] Upgrade justify-content parsing to CSS3 Box Alignment spec. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Using a custom CSSValue to simplify parsing and style building. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004 Zack Rusin <zack@kde.org> 2 * Copyright (C) 2004 Zack Rusin <zack@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2011 Sencha, Inc. All rights reserved. 6 * Copyright (C) 2011 Sencha, Inc. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 1527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 { 1538 {
1539 if (position != ItemPositionAuto) 1539 if (position != ItemPositionAuto)
1540 return position; 1540 return position;
1541 1541
1542 bool isFlexOrGrid = element && element->computedStyle() 1542 bool isFlexOrGrid = element && element->computedStyle()
1543 && element->computedStyle()->isDisplayFlexibleOrGridBox(); 1543 && element->computedStyle()->isDisplayFlexibleOrGridBox();
1544 1544
1545 return isFlexOrGrid ? ItemPositionStretch : ItemPositionStart; 1545 return isFlexOrGrid ? ItemPositionStretch : ItemPositionStart;
1546 } 1546 }
1547 1547
1548 static void resolveAlignmentContentAuto(RenderStyle& style)
1549 {
1550 if (style.justifyContent() != ContentPositionAuto || style.justifyContentDis tribution() != ContentDistributionDefault)
1551 return;
1552
1553 // Block Containers: For table cells, the behavior of the 'auto' depends on the computed
1554 // value of 'vertical-align', otherwise behaves as 'start'.
1555 // Flex Containers: 'auto' computes to 'stretch'.
1556 // Grid Containers: 'auto' computes to 'start', and 'stretch' behaves like ' start'.
1557 if (style.isDisplayFlexibleBox()) {
1558 style.setJustifyContent(ContentPositionFlexStart);
1559 } else {
1560 style.setJustifyContent(ContentPositionStart);
Julien - ping for review 2014/10/28 17:23:04 Mutating the RenderStyle is not an option AFAICT:
jfernandez 2014/10/29 11:03:04 Agree. Actually, this logic is not needed since th
1561 }
1562 }
1563
1548 static PassRefPtrWillBeRawPtr<CSSValueList> valueForItemPositionWithOverflowAlig nment(ItemPosition itemPosition, OverflowAlignment overflowAlignment, ItemPositi onType positionType) 1564 static PassRefPtrWillBeRawPtr<CSSValueList> valueForItemPositionWithOverflowAlig nment(ItemPosition itemPosition, OverflowAlignment overflowAlignment, ItemPositi onType positionType)
1549 { 1565 {
1550 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createSpaceSeparated (); 1566 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createSpaceSeparated ();
1551 if (positionType == LegacyPosition) 1567 if (positionType == LegacyPosition)
1552 result->append(CSSPrimitiveValue::createIdentifier(CSSValueLegacy)); 1568 result->append(CSSPrimitiveValue::createIdentifier(CSSValueLegacy));
1553 result->append(CSSPrimitiveValue::create(itemPosition)); 1569 result->append(CSSPrimitiveValue::create(itemPosition));
1554 if (itemPosition >= ItemPositionCenter && overflowAlignment != OverflowAlign mentDefault) 1570 if (itemPosition >= ItemPositionCenter && overflowAlignment != OverflowAlign mentDefault)
1555 result->append(CSSPrimitiveValue::create(overflowAlignment)); 1571 result->append(CSSPrimitiveValue::create(overflowAlignment));
1556 ASSERT(result->length() <= 2); 1572 ASSERT(result->length() <= 2);
1557 return result.release(); 1573 return result.release();
1558 } 1574 }
1559 1575
1576 static PassRefPtrWillBeRawPtr<CSSValueList> valueForContentPositionAndDistributi onWithOverflowAlignment(ContentPosition position, OverflowAlignment overflowAlig nment, ContentDistributionType distribution)
1577 {
1578 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createSpaceSeparated ();
1579 if (distribution != ContentDistributionDefault)
1580 result->append(CSSPrimitiveValue::create(distribution));
1581 if (distribution == ContentDistributionDefault || position != ContentPositio nAuto)
1582 result->append(CSSPrimitiveValue::create(position));
1583 if ((position >= ContentPositionCenter || distribution != ContentDistributio nDefault) && overflowAlignment != OverflowAlignmentDefault)
1584 result->append(CSSPrimitiveValue::create(overflowAlignment));
1585 ASSERT(result->length() > 0);
1586 ASSERT(result->length() <= 3);
1587 return result.release();
1588 }
1589
1560 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValu e(CSSPropertyID propertyID, EUpdateLayout updateLayout) const 1590 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValu e(CSSPropertyID propertyID, EUpdateLayout updateLayout) const
1561 { 1591 {
1562 Node* styledNode = this->styledNode(); 1592 Node* styledNode = this->styledNode();
1563 if (!styledNode) 1593 if (!styledNode)
1564 return nullptr; 1594 return nullptr;
1565 RenderObject* renderer = styledNode->renderer(); 1595 RenderObject* renderer = styledNode->renderer();
1566 RefPtr<RenderStyle> style; 1596 RefPtr<RenderStyle> style;
1567 1597
1568 if (updateLayout) { 1598 if (updateLayout) {
1569 Document& document = styledNode->document(); 1599 Document& document = styledNode->document();
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 return cssValuePool().createValue(style->flexDirection()); 1867 return cssValuePool().createValue(style->flexDirection());
1838 case CSSPropertyFlexFlow: 1868 case CSSPropertyFlexFlow:
1839 return valuesForShorthandProperty(flexFlowShorthand()); 1869 return valuesForShorthandProperty(flexFlowShorthand());
1840 case CSSPropertyFlexGrow: 1870 case CSSPropertyFlexGrow:
1841 return cssValuePool().createValue(style->flexGrow()); 1871 return cssValuePool().createValue(style->flexGrow());
1842 case CSSPropertyFlexShrink: 1872 case CSSPropertyFlexShrink:
1843 return cssValuePool().createValue(style->flexShrink()); 1873 return cssValuePool().createValue(style->flexShrink());
1844 case CSSPropertyFlexWrap: 1874 case CSSPropertyFlexWrap:
1845 return cssValuePool().createValue(style->flexWrap()); 1875 return cssValuePool().createValue(style->flexWrap());
1846 case CSSPropertyJustifyContent: 1876 case CSSPropertyJustifyContent:
1847 return cssValuePool().createValue(style->justifyContent()); 1877 resolveAlignmentContentAuto(*style);
1878 return valueForContentPositionAndDistributionWithOverflowAlignment(s tyle->justifyContent(), style->justifyContentOverflowAlignment(), style->justify ContentDistribution());
1848 case CSSPropertyOrder: 1879 case CSSPropertyOrder:
1849 return cssValuePool().createValue(style->order(), CSSPrimitiveValue: :CSS_NUMBER); 1880 return cssValuePool().createValue(style->order(), CSSPrimitiveValue: :CSS_NUMBER);
1850 case CSSPropertyFloat: 1881 case CSSPropertyFloat:
1851 if (style->display() != NONE && style->hasOutOfFlowPosition()) 1882 if (style->display() != NONE && style->hasOutOfFlowPosition())
1852 return cssValuePool().createIdentifierValue(CSSValueNone); 1883 return cssValuePool().createIdentifierValue(CSSValueNone);
1853 return cssValuePool().createValue(style->floating()); 1884 return cssValuePool().createValue(style->floating());
1854 case CSSPropertyFont: { 1885 case CSSPropertyFont: {
1855 RefPtrWillBeRawPtr<CSSFontValue> computedFont = CSSFontValue::create (); 1886 RefPtrWillBeRawPtr<CSSFontValue> computedFont = CSSFontValue::create ();
1856 computedFont->style = valueForFontStyle(*style); 1887 computedFont->style = valueForFontStyle(*style);
1857 computedFont->variant = valueForFontVariant(*style); 1888 computedFont->variant = valueForFontVariant(*style);
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
2992 return list.release(); 3023 return list.release();
2993 } 3024 }
2994 3025
2995 void CSSComputedStyleDeclaration::trace(Visitor* visitor) 3026 void CSSComputedStyleDeclaration::trace(Visitor* visitor)
2996 { 3027 {
2997 visitor->trace(m_node); 3028 visitor->trace(m_node);
2998 CSSStyleDeclaration::trace(visitor); 3029 CSSStyleDeclaration::trace(visitor);
2999 } 3030 }
3000 3031
3001 } // namespace blink 3032 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698