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/CSSCursorImageValue.h" | |
| 10 #include "core/css/CSSCustomIdentValue.h" | 11 #include "core/css/CSSCustomIdentValue.h" |
| 11 #include "core/css/CSSFontFaceSrcValue.h" | 12 #include "core/css/CSSFontFaceSrcValue.h" |
| 12 #include "core/css/CSSFontFeatureValue.h" | 13 #include "core/css/CSSFontFeatureValue.h" |
| 13 #include "core/css/CSSFunctionValue.h" | 14 #include "core/css/CSSFunctionValue.h" |
| 15 #include "core/css/CSSImageSetValue.h" | |
| 14 #include "core/css/CSSPathValue.h" | 16 #include "core/css/CSSPathValue.h" |
| 15 #include "core/css/CSSPrimitiveValueMappings.h" | 17 #include "core/css/CSSPrimitiveValueMappings.h" |
| 16 #include "core/css/CSSQuadValue.h" | 18 #include "core/css/CSSQuadValue.h" |
| 17 #include "core/css/CSSSVGDocumentValue.h" | 19 #include "core/css/CSSSVGDocumentValue.h" |
| 18 #include "core/css/CSSShadowValue.h" | 20 #include "core/css/CSSShadowValue.h" |
| 19 #include "core/css/CSSStringValue.h" | 21 #include "core/css/CSSStringValue.h" |
| 20 #include "core/css/CSSTimingFunctionValue.h" | 22 #include "core/css/CSSTimingFunctionValue.h" |
| 21 #include "core/css/CSSURIValue.h" | 23 #include "core/css/CSSURIValue.h" |
| 22 #include "core/css/CSSUnicodeRangeValue.h" | 24 #include "core/css/CSSUnicodeRangeValue.h" |
| 23 #include "core/css/CSSValuePair.h" | 25 #include "core/css/CSSValuePair.h" |
| (...skipping 1813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1837 } | 1839 } |
| 1838 | 1840 |
| 1839 static PassRefPtrWillBeRawPtr<CSSValue> consumeFlexBasis(CSSParserTokenRange& ra nge, CSSParserMode cssParserMode) | 1841 static PassRefPtrWillBeRawPtr<CSSValue> consumeFlexBasis(CSSParserTokenRange& ra nge, CSSParserMode cssParserMode) |
| 1840 { | 1842 { |
| 1841 // FIXME: Support intrinsic dimensions too. | 1843 // FIXME: Support intrinsic dimensions too. |
| 1842 if (range.peek().id() == CSSValueAuto) | 1844 if (range.peek().id() == CSSValueAuto) |
| 1843 return consumeIdent(range); | 1845 return consumeIdent(range); |
| 1844 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative); | 1846 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative); |
| 1845 } | 1847 } |
| 1846 | 1848 |
| 1849 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::consumeImageSet(CSSParserTok enRange functionArgs) | |
| 1850 { | |
| 1851 if (functionArgs.atEnd()) | |
| 1852 return nullptr; | |
| 1853 | |
| 1854 RefPtrWillBeRawPtr<CSSImageSetValue> imageSet = CSSImageSetValue::create(); | |
| 1855 | |
| 1856 while (!functionArgs.atEnd()) { | |
| 1857 AtomicString urlValue(consumeUrl(functionArgs)); | |
| 1858 if (urlValue.isNull()) | |
| 1859 return nullptr; | |
| 1860 | |
| 1861 RefPtrWillBeRawPtr<CSSValue> image = createCSSImageValueWithReferrer(url Value, completeURL(urlValue)); | |
| 1862 imageSet->append(image); | |
| 1863 | |
| 1864 const CSSParserToken& token = functionArgs.consumeIncludingWhitespace(); | |
| 1865 | |
| 1866 if (token.type() != DimensionToken) | |
| 1867 return nullptr; | |
| 1868 ASSERT(token.unitType() == CSSPrimitiveValue::UnitType::Unknown); | |
|
Timothy Loh
2015/11/20 04:09:07
This assertion doesn't look right, since we haven'
rwlbuis
2015/11/20 20:00:21
Done.
| |
| 1869 if (String(token.value()) != "x") | |
| 1870 return nullptr; | |
| 1871 double imageScaleFactor = token.numericValue(); | |
| 1872 if (imageScaleFactor <= 0) | |
| 1873 return nullptr; | |
| 1874 imageSet->append(cssValuePool().createValue(imageScaleFactor, CSSPrimiti veValue::UnitType::Number)); | |
| 1875 | |
| 1876 if (functionArgs.atEnd()) | |
| 1877 break; | |
| 1878 | |
| 1879 if (!consumeCommaIncludingWhitespace(functionArgs)) | |
| 1880 return nullptr; | |
| 1881 } | |
| 1882 return imageSet.release(); | |
| 1883 } | |
| 1884 | |
| 1885 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::consumeCursor(CSSParserToken Range& range) | |
| 1886 { | |
| 1887 RefPtrWillBeRawPtr<CSSValueList> list = nullptr; | |
| 1888 while (!range.atEnd()) { | |
| 1889 RefPtrWillBeRawPtr<CSSValue> image = nullptr; | |
| 1890 AtomicString uri(consumeUrl(range)); | |
| 1891 if (!uri.isNull()) { | |
| 1892 image = createCSSImageValueWithReferrer(uri, completeURL(uri)); | |
| 1893 } else if (range.peek().type() == FunctionToken && range.peek().function Id() == CSSValueWebkitImageSet) { | |
| 1894 image = consumeImageSet(consumeFunction(range)); | |
|
Timothy Loh
2015/11/20 04:09:07
Doesn't this mean that any invalid -webkit-image-s
rwlbuis
2015/11/20 20:00:21
I think I see what you mean. I guess we really nee
Timothy Loh
2015/12/02 23:59:10
Err this wouldn't be a behavior change, currently
| |
| 1895 if (!image) | |
| 1896 break; | |
| 1897 } else { | |
| 1898 break; | |
| 1899 } | |
| 1900 | |
| 1901 double num; | |
| 1902 IntPoint hotSpot(-1, -1); | |
| 1903 bool hotSpotSpecified = false; | |
| 1904 if (consumeNumberRaw(range, num)) { | |
| 1905 hotSpot.setX(int(num)); | |
| 1906 if (!consumeNumberRaw(range, num)) | |
| 1907 return nullptr; | |
| 1908 hotSpot.setY(int(num)); | |
| 1909 hotSpotSpecified = true; | |
| 1910 } | |
| 1911 | |
| 1912 if (!list) | |
| 1913 list = CSSValueList::createCommaSeparated(); | |
| 1914 | |
| 1915 if (image) | |
|
Timothy Loh
2015/11/20 04:09:07
looks like this is always true
rwlbuis
2015/11/20 20:00:21
Done.
| |
| 1916 list->append(CSSCursorImageValue::create(image, hotSpotSpecified, ho tSpot)); | |
| 1917 | |
| 1918 if (!consumeCommaIncludingWhitespace(range)) | |
| 1919 return nullptr; | |
| 1920 } | |
|
Timothy Loh
2015/11/20 04:09:06
blank line after here might be nice.
rwlbuis
2015/11/20 20:00:20
Done.
| |
| 1921 CSSValueID id = range.peek().id(); | |
| 1922 if (!range.atEnd() && m_context.useCounter()) { | |
| 1923 if (id == CSSValueWebkitZoomIn) | |
| 1924 m_context.useCounter()->count(UseCounter::PrefixedCursorZoomIn); | |
| 1925 else if (id == CSSValueWebkitZoomOut) | |
| 1926 m_context.useCounter()->count(UseCounter::PrefixedCursorZoomOut); | |
| 1927 } | |
| 1928 if (list) { | |
|
Timothy Loh
2015/11/20 04:09:07
Can we remove the copy-paste and fix the allowing
rwlbuis
2015/11/20 20:00:21
Done.
| |
| 1929 if (range.atEnd()) | |
| 1930 return nullptr; | |
| 1931 id = range.consumeIncludingWhitespace().id(); | |
| 1932 if (inQuirksMode() && id == CSSValueHand) // MSIE 5 compatibility :/ | |
| 1933 list->append(cssValuePool().createIdentifierValue(CSSValuePointer)); | |
| 1934 else if ((id >= CSSValueAuto && id <= CSSValueWebkitZoomOut) || id == CS SValueCopy || id == CSSValueNone) | |
| 1935 list->append(cssValuePool().createIdentifierValue(id)); | |
| 1936 return list.release(); | |
|
Timothy Loh
2015/11/20 04:09:06
If you didn't notice, we accept "cursor: url(a), b
Timothy Loh
2015/11/20 06:56:25
On the other hand, maybe it's better to keep behav
rwlbuis
2015/11/20 20:00:20
I kept the behavior as-is but removed the copy-pas
| |
| 1937 } | |
| 1938 if (!range.atEnd()) { | |
| 1939 id = range.consumeIncludingWhitespace().id(); | |
| 1940 if (inQuirksMode() && id == CSSValueHand) // MSIE 5 compatibility :/ | |
| 1941 return cssValuePool().createIdentifierValue(CSSValuePointer); | |
| 1942 if ((id >= CSSValueAuto && id <= CSSValueWebkitZoomOut) || id == CSSValu eCopy || id == CSSValueNone) | |
| 1943 return cssValuePool().createIdentifierValue(id); | |
| 1944 return nullptr; | |
| 1945 } | |
| 1946 ASSERT_NOT_REACHED(); | |
| 1947 return nullptr; | |
| 1948 } | |
| 1949 | |
| 1847 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) | 1950 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) |
| 1848 { | 1951 { |
| 1849 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 1952 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
| 1850 m_range.consumeWhitespace(); | 1953 m_range.consumeWhitespace(); |
| 1851 switch (property) { | 1954 switch (property) { |
| 1852 case CSSPropertyWillChange: | 1955 case CSSPropertyWillChange: |
| 1853 return consumeWillChange(m_range); | 1956 return consumeWillChange(m_range); |
| 1854 case CSSPropertyPage: | 1957 case CSSPropertyPage: |
| 1855 return consumePage(m_range); | 1958 return consumePage(m_range); |
| 1856 case CSSPropertyQuotes: | 1959 case CSSPropertyQuotes: |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2002 return consumePaintOrder(m_range); | 2105 return consumePaintOrder(m_range); |
| 2003 case CSSPropertyMarkerStart: | 2106 case CSSPropertyMarkerStart: |
| 2004 case CSSPropertyMarkerMid: | 2107 case CSSPropertyMarkerMid: |
| 2005 case CSSPropertyMarkerEnd: | 2108 case CSSPropertyMarkerEnd: |
| 2006 return consumeNoneOrURI(m_range); | 2109 return consumeNoneOrURI(m_range); |
| 2007 case CSSPropertyFlexBasis: | 2110 case CSSPropertyFlexBasis: |
| 2008 return consumeFlexBasis(m_range, m_context.mode()); | 2111 return consumeFlexBasis(m_range, m_context.mode()); |
| 2009 case CSSPropertyFlexGrow: | 2112 case CSSPropertyFlexGrow: |
| 2010 case CSSPropertyFlexShrink: | 2113 case CSSPropertyFlexShrink: |
| 2011 return consumeNumber(m_range, ValueRangeNonNegative); | 2114 return consumeNumber(m_range, ValueRangeNonNegative); |
| 2115 case CSSPropertyCursor: | |
| 2116 return consumeCursor(m_range); | |
| 2012 default: | 2117 default: |
| 2013 return nullptr; | 2118 return nullptr; |
| 2014 } | 2119 } |
| 2015 } | 2120 } |
| 2016 | 2121 |
| 2017 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) | 2122 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) |
| 2018 { | 2123 { |
| 2019 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 2124 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
| 2020 | 2125 |
| 2021 do { | 2126 do { |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2567 return consumeFlex(important); | 2672 return consumeFlex(important); |
| 2568 case CSSPropertyFlexFlow: | 2673 case CSSPropertyFlexFlow: |
| 2569 return consumeShorthandGreedily(flexFlowShorthand(), important); | 2674 return consumeShorthandGreedily(flexFlowShorthand(), important); |
| 2570 default: | 2675 default: |
| 2571 m_currentShorthand = oldShorthand; | 2676 m_currentShorthand = oldShorthand; |
| 2572 return false; | 2677 return false; |
| 2573 } | 2678 } |
| 2574 } | 2679 } |
| 2575 | 2680 |
| 2576 } // namespace blink | 2681 } // namespace blink |
| OLD | NEW |