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

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp

Issue 1915763002: CSS conic gradient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months 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 // 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 "core/css/parser/CSSPropertyParser.h" 5 #include "core/css/parser/CSSPropertyParser.h"
6 6
7 #include "core/StylePropertyShorthand.h" 7 #include "core/StylePropertyShorthand.h"
8 #include "core/css/CSSBasicShapeValues.h" 8 #include "core/css/CSSBasicShapeValues.h"
9 #include "core/css/CSSBorderImage.h" 9 #include "core/css/CSSBorderImage.h"
10 #include "core/css/CSSContentDistributionValue.h" 10 #include "core/css/CSSContentDistributionValue.h"
(...skipping 2006 matching lines...) Expand 10 before | Expand all | Expand 10 after
2017 CSSGradientColorStop stop; 2017 CSSGradientColorStop stop;
2018 while (consumeCommaIncludingWhitespace(args)) { 2018 while (consumeCommaIncludingWhitespace(args)) {
2019 if (!consumeDeprecatedGradientColorStop(args, stop, cssParserMode)) 2019 if (!consumeDeprecatedGradientColorStop(args, stop, cssParserMode))
2020 return nullptr; 2020 return nullptr;
2021 result->addStop(stop); 2021 result->addStop(stop);
2022 } 2022 }
2023 2023
2024 return result; 2024 return result;
2025 } 2025 }
2026 2026
2027 static bool consumeGradientColorStops(CSSParserTokenRange& range, CSSParserMode cssParserMode, CSSGradientValue* gradient) 2027 static bool consumeGradientColorStops(CSSParserTokenRange& range, CSSParserMode cssParserMode, CSSGradientValue* gradient,
2028 CSSPrimitiveValue* (*consumePositionFunc)(CSSParserTokenRange&, CSSParserMod e, ValueRange, UnitlessQuirk))
2028 { 2029 {
2029 bool supportsColorHints = gradient->gradientType() == CSSLinearGradient || g radient->gradientType() == CSSRadialGradient; 2030 bool supportsColorHints = gradient->gradientType() == CSSLinearGradient || g radient->gradientType() == CSSRadialGradient;
2030 2031
2031 // The first color stop cannot be a color hint. 2032 // The first color stop cannot be a color hint.
2032 bool previousStopWasColorHint = true; 2033 bool previousStopWasColorHint = true;
2033 do { 2034 do {
2034 CSSGradientColorStop stop; 2035 CSSGradientColorStop stop;
2035 stop.m_color = consumeColor(range, cssParserMode); 2036 stop.m_color = consumeColor(range, cssParserMode);
2036 // Two hints in a row are not allowed. 2037 // Two hints in a row are not allowed.
2037 if (!stop.m_color && (!supportsColorHints || previousStopWasColorHint)) 2038 if (!stop.m_color && (!supportsColorHints || previousStopWasColorHint))
2038 return false; 2039 return false;
2039 previousStopWasColorHint = !stop.m_color; 2040 previousStopWasColorHint = !stop.m_color;
2040 stop.m_position = consumeLengthOrPercent(range, cssParserMode, ValueRang eAll); 2041 // stop.m_position = consumeLengthOrPercent(range, cssParserMode, ValueRa ngeAll);
2042 stop.m_position = consumePositionFunc(range, cssParserMode, ValueRangeAl l, UnitlessQuirk::Forbid);
2041 if (!stop.m_color && !stop.m_position) 2043 if (!stop.m_color && !stop.m_position)
2042 return false; 2044 return false;
2043 gradient->addStop(stop); 2045 gradient->addStop(stop);
2044 } while (consumeCommaIncludingWhitespace(range)); 2046 } while (consumeCommaIncludingWhitespace(range));
2045 2047
2046 // The last color stop cannot be a color hint. 2048 // The last color stop cannot be a color hint.
2047 if (previousStopWasColorHint) 2049 if (previousStopWasColorHint)
2048 return false; 2050 return false;
2049 2051
2050 // Must have 2 or more stops to be valid. 2052 // Must have 2 or more stops to be valid.
(...skipping 29 matching lines...) Expand all
2080 verticalSize = consumeLengthOrPercent(args, cssParserMode, ValueRang eAll); 2082 verticalSize = consumeLengthOrPercent(args, cssParserMode, ValueRang eAll);
2081 if (!verticalSize) 2083 if (!verticalSize)
2082 return nullptr; 2084 return nullptr;
2083 consumeCommaIncludingWhitespace(args); 2085 consumeCommaIncludingWhitespace(args);
2084 result->setEndHorizontalSize(horizontalSize); 2086 result->setEndHorizontalSize(horizontalSize);
2085 result->setEndVerticalSize(verticalSize); 2087 result->setEndVerticalSize(verticalSize);
2086 } 2088 }
2087 } else { 2089 } else {
2088 consumeCommaIncludingWhitespace(args); 2090 consumeCommaIncludingWhitespace(args);
2089 } 2091 }
2090 if (!consumeGradientColorStops(args, cssParserMode, result)) 2092 if (!consumeGradientColorStops(args, cssParserMode, result, consumeLengthOrP ercent))
2091 return nullptr; 2093 return nullptr;
2092 2094
2093 return result; 2095 return result;
2094 } 2096 }
2095 2097
2096 static CSSValue* consumeRadialGradient(CSSParserTokenRange& args, CSSParserMode cssParserMode, CSSGradientRepeat repeating) 2098 static CSSValue* consumeRadialGradient(CSSParserTokenRange& args, CSSParserMode cssParserMode, CSSGradientRepeat repeating)
2097 { 2099 {
2098 CSSRadialGradientValue* result = CSSRadialGradientValue::create(repeating, C SSRadialGradient); 2100 CSSRadialGradientValue* result = CSSRadialGradientValue::create(repeating, C SSRadialGradient);
2099 2101
2100 CSSPrimitiveValue* shape = nullptr; 2102 CSSPrimitiveValue* shape = nullptr;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 return nullptr; 2165 return nullptr;
2164 result->setFirstX(centerX); 2166 result->setFirstX(centerX);
2165 result->setFirstY(centerY); 2167 result->setFirstY(centerY);
2166 // Right now, CSS radial gradients have the same start and end centers. 2168 // Right now, CSS radial gradients have the same start and end centers.
2167 result->setSecondX(centerX); 2169 result->setSecondX(centerX);
2168 result->setSecondY(centerY); 2170 result->setSecondY(centerY);
2169 } 2171 }
2170 2172
2171 if ((shape || sizeKeyword || horizontalSize || centerX || centerY) && !consu meCommaIncludingWhitespace(args)) 2173 if ((shape || sizeKeyword || horizontalSize || centerX || centerY) && !consu meCommaIncludingWhitespace(args))
2172 return nullptr; 2174 return nullptr;
2173 if (!consumeGradientColorStops(args, cssParserMode, result)) 2175 if (!consumeGradientColorStops(args, cssParserMode, result, consumeLengthOrP ercent))
2174 return nullptr; 2176 return nullptr;
2175 return result; 2177 return result;
2176 } 2178 }
2177 2179
2178 static CSSValue* consumeLinearGradient(CSSParserTokenRange& args, CSSParserMode cssParserMode, CSSGradientRepeat repeating, CSSGradientType gradientType) 2180 static CSSValue* consumeLinearGradient(CSSParserTokenRange& args, CSSParserMode cssParserMode, CSSGradientRepeat repeating, CSSGradientType gradientType)
2179 { 2181 {
2180 CSSLinearGradientValue* result = CSSLinearGradientValue::create(repeating, g radientType); 2182 CSSLinearGradientValue* result = CSSLinearGradientValue::create(repeating, g radientType);
2181 2183
2182 bool expectComma = true; 2184 bool expectComma = true;
2183 CSSPrimitiveValue* angle = consumeAngle(args); 2185 CSSPrimitiveValue* angle = consumeAngle(args);
(...skipping 12 matching lines...) Expand all
2196 } 2198 }
2197 2199
2198 result->setFirstX(endX); 2200 result->setFirstX(endX);
2199 result->setFirstY(endY); 2201 result->setFirstY(endY);
2200 } else { 2202 } else {
2201 expectComma = false; 2203 expectComma = false;
2202 } 2204 }
2203 2205
2204 if (expectComma && !consumeCommaIncludingWhitespace(args)) 2206 if (expectComma && !consumeCommaIncludingWhitespace(args))
2205 return nullptr; 2207 return nullptr;
2206 if (!consumeGradientColorStops(args, cssParserMode, result)) 2208 if (!consumeGradientColorStops(args, cssParserMode, result, consumeLengthOrP ercent))
2207 return nullptr; 2209 return nullptr;
2208 return result; 2210 return result;
2209 } 2211 }
2210 2212
2213 static CSSValue* consumeConicGradient(CSSParserTokenRange& args, CSSParserMode c ssParserMode, CSSGradientRepeat repeating)
2214 {
2215 CSSConicGradientValue* result = CSSConicGradientValue::create(repeating);
2216
2217 CSSValue* centerX = nullptr;
2218 CSSValue* centerY = nullptr;
2219
2220 if (args.peek().id() == CSSValueAt) {
2221 args.consumeIncludingWhitespace();
2222 consumePosition(args, cssParserMode, UnitlessQuirk::Forbid, centerX, cen terY);
2223 if (!(centerX && centerY))
2224 return nullptr;
2225 result->setFirstX(centerX);
2226 result->setFirstY(centerY);
2227 }
2228
2229 if ((centerX || centerY) && !consumeCommaIncludingWhitespace(args))
2230 return nullptr;
2231
2232 if (!consumeGradientColorStops(args, cssParserMode, result, consumeLengthOrP ercent))
2233 return nullptr;
2234
2235 return result;
2236 }
2237
2211 static CSSValue* consumeImageOrNone(CSSParserTokenRange&, CSSParserContext); 2238 static CSSValue* consumeImageOrNone(CSSParserTokenRange&, CSSParserContext);
2212 2239
2213 static CSSValue* consumeCrossFade(CSSParserTokenRange& args, CSSParserContext co ntext) 2240 static CSSValue* consumeCrossFade(CSSParserTokenRange& args, CSSParserContext co ntext)
2214 { 2241 {
2215 CSSValue* fromImageValue = consumeImageOrNone(args, context); 2242 CSSValue* fromImageValue = consumeImageOrNone(args, context);
2216 if (!fromImageValue || !consumeCommaIncludingWhitespace(args)) 2243 if (!fromImageValue || !consumeCommaIncludingWhitespace(args))
2217 return nullptr; 2244 return nullptr;
2218 CSSValue* toImageValue = consumeImageOrNone(args, context); 2245 CSSValue* toImageValue = consumeImageOrNone(args, context);
2219 if (!toImageValue || !consumeCommaIncludingWhitespace(args)) 2246 if (!toImageValue || !consumeCommaIncludingWhitespace(args))
2220 return nullptr; 2247 return nullptr;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2277 context.useCounter()->count(UseCounter::DeprecatedWebKitRadialGradie nt); 2304 context.useCounter()->count(UseCounter::DeprecatedWebKitRadialGradie nt);
2278 result = consumeDeprecatedRadialGradient(args, context.mode(), NonRepeat ing); 2305 result = consumeDeprecatedRadialGradient(args, context.mode(), NonRepeat ing);
2279 } else if (id == CSSValueWebkitRepeatingRadialGradient) { 2306 } else if (id == CSSValueWebkitRepeatingRadialGradient) {
2280 if (context.useCounter()) 2307 if (context.useCounter())
2281 context.useCounter()->count(UseCounter::DeprecatedWebKitRepeatingRad ialGradient); 2308 context.useCounter()->count(UseCounter::DeprecatedWebKitRepeatingRad ialGradient);
2282 result = consumeDeprecatedRadialGradient(args, context.mode(), Repeating ); 2309 result = consumeDeprecatedRadialGradient(args, context.mode(), Repeating );
2283 } else if (id == CSSValueWebkitCrossFade) { 2310 } else if (id == CSSValueWebkitCrossFade) {
2284 result = consumeCrossFade(args, context); 2311 result = consumeCrossFade(args, context);
2285 } else if (id == CSSValuePaint) { 2312 } else if (id == CSSValuePaint) {
2286 result = RuntimeEnabledFeatures::cssPaintAPIEnabled() ? consumePaint(arg s, context) : nullptr; 2313 result = RuntimeEnabledFeatures::cssPaintAPIEnabled() ? consumePaint(arg s, context) : nullptr;
2314 } else if (id == CSSValueConicGradient) {
2315 result = consumeConicGradient(args, context.mode(), NonRepeating);
2316 } else if (id == CSSValueRepeatingConicGradient) {
2317 result = consumeConicGradient(args, context.mode(), Repeating);
2287 } 2318 }
2288 if (!result || !args.atEnd()) 2319 if (!result || !args.atEnd())
2289 return nullptr; 2320 return nullptr;
2290 range = rangeCopy; 2321 range = rangeCopy;
2291 return result; 2322 return result;
2292 } 2323 }
2293 2324
2294 static bool isGeneratedImage(CSSValueID id) 2325 static bool isGeneratedImage(CSSValueID id)
2295 { 2326 {
2296 return id == CSSValueLinearGradient || id == CSSValueRadialGradient 2327 return id == CSSValueLinearGradient || id == CSSValueRadialGradient
2297 || id == CSSValueRepeatingLinearGradient || id == CSSValueRepeatingRadia lGradient 2328 || id == CSSValueRepeatingLinearGradient || id == CSSValueRepeatingRadia lGradient
2298 || id == CSSValueWebkitLinearGradient || id == CSSValueWebkitRadialGradi ent 2329 || id == CSSValueWebkitLinearGradient || id == CSSValueWebkitRadialGradi ent
2299 || id == CSSValueWebkitRepeatingLinearGradient || id == CSSValueWebkitRe peatingRadialGradient 2330 || id == CSSValueWebkitRepeatingLinearGradient || id == CSSValueWebkitRe peatingRadialGradient
2300 || id == CSSValueWebkitGradient || id == CSSValueWebkitCrossFade || id = = CSSValuePaint; 2331 || id == CSSValueWebkitGradient || id == CSSValueWebkitCrossFade || id = = CSSValuePaint
2332 || id == CSSValueConicGradient || id == CSSValueRepeatingConicGradient;
2301 } 2333 }
2302 2334
2303 static CSSValue* consumeImage(CSSParserTokenRange& range, CSSParserContext conte xt) 2335 static CSSValue* consumeImage(CSSParserTokenRange& range, CSSParserContext conte xt)
2304 { 2336 {
2305 AtomicString uri(consumeUrl(range)); 2337 AtomicString uri(consumeUrl(range));
2306 if (!uri.isNull()) 2338 if (!uri.isNull())
2307 return createCSSImageValueWithReferrer(uri, context); 2339 return createCSSImageValueWithReferrer(uri, context);
2308 if (range.peek().type() == FunctionToken) { 2340 if (range.peek().type() == FunctionToken) {
2309 CSSValueID id = range.peek().functionId(); 2341 CSSValueID id = range.peek().functionId();
2310 if (id == CSSValueWebkitImageSet) 2342 if (id == CSSValueWebkitImageSet)
(...skipping 2656 matching lines...) Expand 10 before | Expand all | Expand 10 after
4967 return consumeGridTemplateShorthand(important); 4999 return consumeGridTemplateShorthand(important);
4968 case CSSPropertyGrid: 5000 case CSSPropertyGrid:
4969 return consumeGridShorthand(important); 5001 return consumeGridShorthand(important);
4970 default: 5002 default:
4971 m_currentShorthand = oldShorthand; 5003 m_currentShorthand = oldShorthand;
4972 return false; 5004 return false;
4973 } 5005 }
4974 } 5006 }
4975 5007
4976 } // namespace blink 5008 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSValueKeywords.in ('k') | third_party/WebKit/Source/platform/graphics/Gradient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698