Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/css/parser/CSSPropertyParser.h" | 6 #include "core/css/parser/CSSPropertyParser.h" |
| 7 | 7 |
| 8 #include "core/StylePropertyShorthand.h" | 8 #include "core/StylePropertyShorthand.h" |
| 9 #include "core/css/CSSCalculationValue.h" | 9 #include "core/css/CSSCalculationValue.h" |
| 10 #include "core/css/CSSCustomIdentValue.h" | 10 #include "core/css/CSSCustomIdentValue.h" |
| (...skipping 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1818 paintOrderList->append(stroke.release()); | 1818 paintOrderList->append(stroke.release()); |
| 1819 } | 1819 } |
| 1820 break; | 1820 break; |
| 1821 default: | 1821 default: |
| 1822 ASSERT_NOT_REACHED(); | 1822 ASSERT_NOT_REACHED(); |
| 1823 } | 1823 } |
| 1824 | 1824 |
| 1825 return paintOrderList.release(); | 1825 return paintOrderList.release(); |
| 1826 } | 1826 } |
| 1827 | 1827 |
| 1828 static PassRefPtrWillBeRawPtr<CSSValue> consumeFlexBasis(CSSParserTokenRange& ra nge, CSSParserMode cssParserMode) | |
| 1829 { | |
| 1830 // FIXME: Support intrinsic dimensions too. | |
| 1831 if (range.peek().id() == CSSValueAuto) | |
| 1832 return consumeIdent(range); | |
| 1833 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative); | |
| 1834 } | |
| 1835 | |
| 1828 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) | 1836 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) |
| 1829 { | 1837 { |
| 1830 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 1838 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
| 1831 m_range.consumeWhitespace(); | 1839 m_range.consumeWhitespace(); |
| 1832 switch (property) { | 1840 switch (property) { |
| 1833 case CSSPropertyWillChange: | 1841 case CSSPropertyWillChange: |
| 1834 return consumeWillChange(m_range); | 1842 return consumeWillChange(m_range); |
| 1835 case CSSPropertyPage: | 1843 case CSSPropertyPage: |
| 1836 return consumePage(m_range); | 1844 return consumePage(m_range); |
| 1837 case CSSPropertyQuotes: | 1845 case CSSPropertyQuotes: |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1974 return consumeLength(m_range, m_context.mode(), ValueRangeAll); | 1982 return consumeLength(m_range, m_context.mode(), ValueRangeAll); |
| 1975 case CSSPropertyOutlineWidth: | 1983 case CSSPropertyOutlineWidth: |
| 1976 return consumeLineWidth(m_range, m_context.mode()); | 1984 return consumeLineWidth(m_range, m_context.mode()); |
| 1977 case CSSPropertyTransform: | 1985 case CSSPropertyTransform: |
| 1978 return consumeTransform(m_range, m_context.mode(), unresolvedProperty == CSSPropertyAliasWebkitTransform); | 1986 return consumeTransform(m_range, m_context.mode(), unresolvedProperty == CSSPropertyAliasWebkitTransform); |
| 1979 case CSSPropertyFill: | 1987 case CSSPropertyFill: |
| 1980 case CSSPropertyStroke: | 1988 case CSSPropertyStroke: |
| 1981 return consumePaint(m_range, m_context); | 1989 return consumePaint(m_range, m_context); |
| 1982 case CSSPropertyPaintOrder: | 1990 case CSSPropertyPaintOrder: |
| 1983 return consumePaintOrder(m_range); | 1991 return consumePaintOrder(m_range); |
| 1992 case CSSPropertyFlexBasis: | |
| 1993 return consumeFlexBasis(m_range, m_context.mode()); | |
| 1994 case CSSPropertyFlexGrow: | |
| 1995 case CSSPropertyFlexShrink: | |
| 1996 return consumeNumber(m_range, ValueRangeNonNegative); | |
| 1984 default: | 1997 default: |
| 1985 return nullptr; | 1998 return nullptr; |
| 1986 } | 1999 } |
| 1987 } | 2000 } |
| 1988 | 2001 |
| 1989 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) | 2002 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) |
| 1990 { | 2003 { |
| 1991 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 2004 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
| 1992 | 2005 |
| 1993 do { | 2006 do { |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2370 ImplicitScope implicitScope(this); | 2383 ImplicitScope implicitScope(this); |
| 2371 for (size_t i = 0; i < shorthand.length(); ++i) { | 2384 for (size_t i = 0; i < shorthand.length(); ++i) { |
| 2372 if (longhands[i]) | 2385 if (longhands[i]) |
| 2373 addProperty(shorthandProperties[i], longhands[i].release(), importan t); | 2386 addProperty(shorthandProperties[i], longhands[i].release(), importan t); |
| 2374 else | 2387 else |
| 2375 addProperty(shorthandProperties[i], cssValuePool().createImplicitIni tialValue(), important); | 2388 addProperty(shorthandProperties[i], cssValuePool().createImplicitIni tialValue(), important); |
| 2376 } | 2389 } |
| 2377 return true; | 2390 return true; |
| 2378 } | 2391 } |
| 2379 | 2392 |
| 2393 bool CSSPropertyParser::consumeFlex(bool important) | |
| 2394 { | |
| 2395 ShorthandScope scope(this, CSSPropertyFlex); | |
| 2396 static const double unsetValue = -1; | |
| 2397 double flexGrow = unsetValue; | |
| 2398 double flexShrink = unsetValue; | |
| 2399 RefPtrWillBeRawPtr<CSSPrimitiveValue> flexBasis = nullptr; | |
| 2400 | |
| 2401 if (m_range.peek().id() == CSSValueNone) { | |
| 2402 flexGrow = flexShrink = 0; | |
|
Timothy Loh
2015/11/19 05:36:59
Isn't this against the style guide? At least I nev
| |
| 2403 flexBasis = cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 2404 m_range.consumeIncludingWhitespace(); | |
| 2405 } else { | |
| 2406 unsigned index = 0; | |
| 2407 while (!m_range.atEnd() && index++ < 3) { | |
|
Timothy Loh
2015/11/19 05:36:59
I'd prefer a regular for loop here. I got a bit co
| |
| 2408 double num; | |
| 2409 if (consumeNumberRaw(m_range, num)) { | |
| 2410 if (num < 0) | |
| 2411 return false; | |
| 2412 if (flexGrow == unsetValue) | |
| 2413 flexGrow = num; | |
| 2414 else if (flexShrink == unsetValue) | |
| 2415 flexShrink = num; | |
| 2416 else if (!num) // flex only allows a basis of 0 (sans units) if flex-grow and flex-shrink values have already been set. | |
| 2417 flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue: :UnitType::Pixels); | |
| 2418 else | |
| 2419 return false; | |
| 2420 } else if (!flexBasis) { | |
| 2421 if (m_range.peek().id() == CSSValueAuto) | |
| 2422 flexBasis = consumeIdent(m_range); | |
| 2423 if (!flexBasis) | |
|
Timothy Loh
2015/11/19 05:36:59
Better to just write "else"
| |
| 2424 flexBasis = consumeLengthOrPercent(m_range, m_context.mode() , ValueRangeNonNegative); | |
| 2425 if (flexBasis && index == 2 && !m_range.atEnd()) | |
|
Timothy Loh
2015/11/19 05:36:59
I guess this doesn't need to check flexBasis, I th
| |
| 2426 return false; | |
| 2427 } | |
| 2428 } | |
| 2429 } | |
| 2430 if (!m_range.atEnd()) | |
| 2431 return false; | |
| 2432 | |
| 2433 if (flexGrow == unsetValue) | |
| 2434 flexGrow = 1; | |
| 2435 if (flexShrink == unsetValue) | |
| 2436 flexShrink = 1; | |
| 2437 if (!flexBasis) | |
| 2438 flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::P ercentage); | |
| 2439 | |
| 2440 addProperty(CSSPropertyFlexGrow, cssValuePool().createValue(clampTo<float>(f lexGrow), CSSPrimitiveValue::UnitType::Number), important); | |
| 2441 addProperty(CSSPropertyFlexShrink, cssValuePool().createValue(clampTo<float> (flexShrink), CSSPrimitiveValue::UnitType::Number), important); | |
| 2442 addProperty(CSSPropertyFlexBasis, flexBasis, important); | |
| 2443 return true; | |
| 2444 } | |
| 2445 | |
| 2380 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) | 2446 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) |
| 2381 { | 2447 { |
| 2382 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 2448 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
| 2383 | 2449 |
| 2384 m_range.consumeWhitespace(); | 2450 m_range.consumeWhitespace(); |
| 2385 CSSPropertyID oldShorthand = m_currentShorthand; | 2451 CSSPropertyID oldShorthand = m_currentShorthand; |
| 2386 // TODO(rob.buis): Remove this when the legacy property parser is gone | 2452 // TODO(rob.buis): Remove this when the legacy property parser is gone |
| 2387 m_currentShorthand = property; | 2453 m_currentShorthand = property; |
| 2388 switch (property) { | 2454 switch (property) { |
| 2389 case CSSPropertyWebkitMarginCollapse: { | 2455 case CSSPropertyWebkitMarginCollapse: { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2464 case CSSPropertyWebkitBorderStart: | 2530 case CSSPropertyWebkitBorderStart: |
| 2465 return consumeShorthandGreedily(webkitBorderStartShorthand(), important) ; | 2531 return consumeShorthandGreedily(webkitBorderStartShorthand(), important) ; |
| 2466 case CSSPropertyWebkitBorderEnd: | 2532 case CSSPropertyWebkitBorderEnd: |
| 2467 return consumeShorthandGreedily(webkitBorderEndShorthand(), important); | 2533 return consumeShorthandGreedily(webkitBorderEndShorthand(), important); |
| 2468 case CSSPropertyWebkitBorderBefore: | 2534 case CSSPropertyWebkitBorderBefore: |
| 2469 return consumeShorthandGreedily(webkitBorderBeforeShorthand(), important ); | 2535 return consumeShorthandGreedily(webkitBorderBeforeShorthand(), important ); |
| 2470 case CSSPropertyWebkitBorderAfter: | 2536 case CSSPropertyWebkitBorderAfter: |
| 2471 return consumeShorthandGreedily(webkitBorderAfterShorthand(), important) ; | 2537 return consumeShorthandGreedily(webkitBorderAfterShorthand(), important) ; |
| 2472 case CSSPropertyWebkitTextStroke: | 2538 case CSSPropertyWebkitTextStroke: |
| 2473 return consumeShorthandGreedily(webkitTextStrokeShorthand(), important); | 2539 return consumeShorthandGreedily(webkitTextStrokeShorthand(), important); |
| 2540 case CSSPropertyFlex: | |
| 2541 return consumeFlex(important); | |
| 2542 case CSSPropertyFlexFlow: | |
| 2543 return consumeShorthandGreedily(flexFlowShorthand(), important); | |
| 2474 default: | 2544 default: |
| 2475 m_currentShorthand = oldShorthand; | 2545 m_currentShorthand = oldShorthand; |
| 2476 return false; | 2546 return false; |
| 2477 } | 2547 } |
| 2478 } | 2548 } |
| 2479 | 2549 |
| 2480 } // namespace blink | 2550 } // namespace blink |
| OLD | NEW |