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 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1829 { | 1829 { |
1830 if (range.peek().id() == CSSValueNone) | 1830 if (range.peek().id() == CSSValueNone) |
1831 return consumeIdent(range); | 1831 return consumeIdent(range); |
1832 | 1832 |
1833 String url = consumeUrl(range); | 1833 String url = consumeUrl(range); |
1834 if (url.isNull()) | 1834 if (url.isNull()) |
1835 return nullptr; | 1835 return nullptr; |
1836 return CSSURIValue::create(url); | 1836 return CSSURIValue::create(url); |
1837 } | 1837 } |
1838 | 1838 |
| 1839 static PassRefPtrWillBeRawPtr<CSSValue> consumeFlexBasis(CSSParserTokenRange& ra
nge, CSSParserMode cssParserMode) |
| 1840 { |
| 1841 // FIXME: Support intrinsic dimensions too. |
| 1842 if (range.peek().id() == CSSValueAuto) |
| 1843 return consumeIdent(range); |
| 1844 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative); |
| 1845 } |
| 1846 |
1839 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty
ID unresolvedProperty) | 1847 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty
ID unresolvedProperty) |
1840 { | 1848 { |
1841 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 1849 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
1842 m_range.consumeWhitespace(); | 1850 m_range.consumeWhitespace(); |
1843 switch (property) { | 1851 switch (property) { |
1844 case CSSPropertyWillChange: | 1852 case CSSPropertyWillChange: |
1845 return consumeWillChange(m_range); | 1853 return consumeWillChange(m_range); |
1846 case CSSPropertyPage: | 1854 case CSSPropertyPage: |
1847 return consumePage(m_range); | 1855 return consumePage(m_range); |
1848 case CSSPropertyQuotes: | 1856 case CSSPropertyQuotes: |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1989 return consumeTransform(m_range, m_context.mode(), unresolvedProperty ==
CSSPropertyAliasWebkitTransform); | 1997 return consumeTransform(m_range, m_context.mode(), unresolvedProperty ==
CSSPropertyAliasWebkitTransform); |
1990 case CSSPropertyFill: | 1998 case CSSPropertyFill: |
1991 case CSSPropertyStroke: | 1999 case CSSPropertyStroke: |
1992 return consumePaint(m_range, m_context); | 2000 return consumePaint(m_range, m_context); |
1993 case CSSPropertyPaintOrder: | 2001 case CSSPropertyPaintOrder: |
1994 return consumePaintOrder(m_range); | 2002 return consumePaintOrder(m_range); |
1995 case CSSPropertyMarkerStart: | 2003 case CSSPropertyMarkerStart: |
1996 case CSSPropertyMarkerMid: | 2004 case CSSPropertyMarkerMid: |
1997 case CSSPropertyMarkerEnd: | 2005 case CSSPropertyMarkerEnd: |
1998 return consumeNoneOrURI(m_range); | 2006 return consumeNoneOrURI(m_range); |
| 2007 case CSSPropertyFlexBasis: |
| 2008 return consumeFlexBasis(m_range, m_context.mode()); |
| 2009 case CSSPropertyFlexGrow: |
| 2010 case CSSPropertyFlexShrink: |
| 2011 return consumeNumber(m_range, ValueRangeNonNegative); |
1999 default: | 2012 default: |
2000 return nullptr; | 2013 return nullptr; |
2001 } | 2014 } |
2002 } | 2015 } |
2003 | 2016 |
2004 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse
rTokenRange& range) | 2017 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse
rTokenRange& range) |
2005 { | 2018 { |
2006 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated
(); | 2019 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated
(); |
2007 | 2020 |
2008 do { | 2021 do { |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2385 ImplicitScope implicitScope(this); | 2398 ImplicitScope implicitScope(this); |
2386 for (size_t i = 0; i < shorthand.length(); ++i) { | 2399 for (size_t i = 0; i < shorthand.length(); ++i) { |
2387 if (longhands[i]) | 2400 if (longhands[i]) |
2388 addProperty(shorthandProperties[i], longhands[i].release(), importan
t); | 2401 addProperty(shorthandProperties[i], longhands[i].release(), importan
t); |
2389 else | 2402 else |
2390 addProperty(shorthandProperties[i], cssValuePool().createImplicitIni
tialValue(), important); | 2403 addProperty(shorthandProperties[i], cssValuePool().createImplicitIni
tialValue(), important); |
2391 } | 2404 } |
2392 return true; | 2405 return true; |
2393 } | 2406 } |
2394 | 2407 |
| 2408 bool CSSPropertyParser::consumeFlex(bool important) |
| 2409 { |
| 2410 ShorthandScope scope(this, CSSPropertyFlex); |
| 2411 static const double unsetValue = -1; |
| 2412 double flexGrow = unsetValue; |
| 2413 double flexShrink = unsetValue; |
| 2414 RefPtrWillBeRawPtr<CSSPrimitiveValue> flexBasis = nullptr; |
| 2415 |
| 2416 if (m_range.peek().id() == CSSValueNone) { |
| 2417 flexGrow = 0; |
| 2418 flexShrink = 0; |
| 2419 flexBasis = cssValuePool().createIdentifierValue(CSSValueAuto); |
| 2420 m_range.consumeIncludingWhitespace(); |
| 2421 } else { |
| 2422 unsigned index = 0; |
| 2423 while (!m_range.atEnd() && index++ < 3) { |
| 2424 double num; |
| 2425 if (consumeNumberRaw(m_range, num)) { |
| 2426 if (num < 0) |
| 2427 return false; |
| 2428 if (flexGrow == unsetValue) |
| 2429 flexGrow = num; |
| 2430 else if (flexShrink == unsetValue) |
| 2431 flexShrink = num; |
| 2432 else if (!num) // flex only allows a basis of 0 (sans units) if
flex-grow and flex-shrink values have already been set. |
| 2433 flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue:
:UnitType::Pixels); |
| 2434 else |
| 2435 return false; |
| 2436 } else if (!flexBasis) { |
| 2437 if (m_range.peek().id() == CSSValueAuto) |
| 2438 flexBasis = consumeIdent(m_range); |
| 2439 if (!flexBasis) |
| 2440 flexBasis = consumeLengthOrPercent(m_range, m_context.mode()
, ValueRangeNonNegative); |
| 2441 if (index == 2 && !m_range.atEnd()) |
| 2442 return false; |
| 2443 } |
| 2444 } |
| 2445 } |
| 2446 if (!m_range.atEnd()) |
| 2447 return false; |
| 2448 |
| 2449 if (flexGrow == unsetValue) |
| 2450 flexGrow = 1; |
| 2451 if (flexShrink == unsetValue) |
| 2452 flexShrink = 1; |
| 2453 if (!flexBasis) |
| 2454 flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::P
ercentage); |
| 2455 |
| 2456 addProperty(CSSPropertyFlexGrow, cssValuePool().createValue(clampTo<float>(f
lexGrow), CSSPrimitiveValue::UnitType::Number), important); |
| 2457 addProperty(CSSPropertyFlexShrink, cssValuePool().createValue(clampTo<float>
(flexShrink), CSSPrimitiveValue::UnitType::Number), important); |
| 2458 addProperty(CSSPropertyFlexBasis, flexBasis, important); |
| 2459 return true; |
| 2460 } |
| 2461 |
2395 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im
portant) | 2462 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im
portant) |
2396 { | 2463 { |
2397 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 2464 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
2398 | 2465 |
2399 m_range.consumeWhitespace(); | 2466 m_range.consumeWhitespace(); |
2400 CSSPropertyID oldShorthand = m_currentShorthand; | 2467 CSSPropertyID oldShorthand = m_currentShorthand; |
2401 // TODO(rob.buis): Remove this when the legacy property parser is gone | 2468 // TODO(rob.buis): Remove this when the legacy property parser is gone |
2402 m_currentShorthand = property; | 2469 m_currentShorthand = property; |
2403 switch (property) { | 2470 switch (property) { |
2404 case CSSPropertyWebkitMarginCollapse: { | 2471 case CSSPropertyWebkitMarginCollapse: { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2489 case CSSPropertyMarker: { | 2556 case CSSPropertyMarker: { |
2490 ImplicitScope implicitScope(this); | 2557 ImplicitScope implicitScope(this); |
2491 RefPtrWillBeRawPtr<CSSValue> marker = parseSingleValue(CSSPropertyMarker
Start); | 2558 RefPtrWillBeRawPtr<CSSValue> marker = parseSingleValue(CSSPropertyMarker
Start); |
2492 if (!marker || !m_range.atEnd()) | 2559 if (!marker || !m_range.atEnd()) |
2493 return false; | 2560 return false; |
2494 addProperty(CSSPropertyMarkerStart, marker, important); | 2561 addProperty(CSSPropertyMarkerStart, marker, important); |
2495 addProperty(CSSPropertyMarkerMid, marker, important); | 2562 addProperty(CSSPropertyMarkerMid, marker, important); |
2496 addProperty(CSSPropertyMarkerEnd, marker.release(), important); | 2563 addProperty(CSSPropertyMarkerEnd, marker.release(), important); |
2497 return true; | 2564 return true; |
2498 } | 2565 } |
| 2566 case CSSPropertyFlex: |
| 2567 return consumeFlex(important); |
| 2568 case CSSPropertyFlexFlow: |
| 2569 return consumeShorthandGreedily(flexFlowShorthand(), important); |
2499 default: | 2570 default: |
2500 m_currentShorthand = oldShorthand; | 2571 m_currentShorthand = oldShorthand; |
2501 return false; | 2572 return false; |
2502 } | 2573 } |
2503 } | 2574 } |
2504 | 2575 |
2505 } // namespace blink | 2576 } // namespace blink |
OLD | NEW |