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

Side by Side Diff: sky/engine/core/css/parser/CSSPropertyParser.cpp

Issue 1214633005: Remove CSS clients of ImageResource (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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 /* 1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
9 * Copyright (C) 2012 Intel Corporation. All rights reserved. 9 * Copyright (C) 2012 Intel Corporation. All rights reserved.
10 * 10 *
(...skipping 16 matching lines...) Expand all
27 #include "sky/engine/core/css/parser/CSSPropertyParser.h" 27 #include "sky/engine/core/css/parser/CSSPropertyParser.h"
28 28
29 // FIXME: Way too many! 29 // FIXME: Way too many!
30 #include <limits.h> 30 #include <limits.h>
31 #include "gen/sky/core/CSSValueKeywords.h" 31 #include "gen/sky/core/CSSValueKeywords.h"
32 #include "gen/sky/core/StylePropertyShorthand.h" 32 #include "gen/sky/core/StylePropertyShorthand.h"
33 #include "gen/sky/platform/RuntimeEnabledFeatures.h" 33 #include "gen/sky/platform/RuntimeEnabledFeatures.h"
34 #include "sky/engine/core/css/CSSAspectRatioValue.h" 34 #include "sky/engine/core/css/CSSAspectRatioValue.h"
35 #include "sky/engine/core/css/CSSBasicShapes.h" 35 #include "sky/engine/core/css/CSSBasicShapes.h"
36 #include "sky/engine/core/css/CSSBorderImage.h" 36 #include "sky/engine/core/css/CSSBorderImage.h"
37 #include "sky/engine/core/css/CSSCrossfadeValue.h"
38 #include "sky/engine/core/css/CSSFontFaceSrcValue.h" 37 #include "sky/engine/core/css/CSSFontFaceSrcValue.h"
39 #include "sky/engine/core/css/CSSFontFeatureValue.h" 38 #include "sky/engine/core/css/CSSFontFeatureValue.h"
40 #include "sky/engine/core/css/CSSFunctionValue.h" 39 #include "sky/engine/core/css/CSSFunctionValue.h"
41 #include "sky/engine/core/css/CSSGradientValue.h" 40 #include "sky/engine/core/css/CSSGradientValue.h"
42 #include "sky/engine/core/css/CSSImageSetValue.h"
43 #include "sky/engine/core/css/CSSImageValue.h"
44 #include "sky/engine/core/css/CSSInheritedValue.h" 41 #include "sky/engine/core/css/CSSInheritedValue.h"
45 #include "sky/engine/core/css/CSSInitialValue.h" 42 #include "sky/engine/core/css/CSSInitialValue.h"
46 #include "sky/engine/core/css/CSSLineBoxContainValue.h" 43 #include "sky/engine/core/css/CSSLineBoxContainValue.h"
47 #include "sky/engine/core/css/CSSPrimitiveValue.h" 44 #include "sky/engine/core/css/CSSPrimitiveValue.h"
48 #include "sky/engine/core/css/CSSPropertyMetadata.h" 45 #include "sky/engine/core/css/CSSPropertyMetadata.h"
49 #include "sky/engine/core/css/CSSPropertySourceData.h" 46 #include "sky/engine/core/css/CSSPropertySourceData.h"
50 #include "sky/engine/core/css/CSSSelector.h" 47 #include "sky/engine/core/css/CSSSelector.h"
51 #include "sky/engine/core/css/CSSShadowValue.h" 48 #include "sky/engine/core/css/CSSShadowValue.h"
52 #include "sky/engine/core/css/CSSTimingFunctionValue.h" 49 #include "sky/engine/core/css/CSSTimingFunctionValue.h"
53 #include "sky/engine/core/css/CSSTransformValue.h" 50 #include "sky/engine/core/css/CSSTransformValue.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 || (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrim itiveValue::CSS_DPCM)); 294 || (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrim itiveValue::CSS_DPCM));
298 return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveVal ue::UnitType>(value->unit)); 295 return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveVal ue::UnitType>(value->unit));
299 } 296 }
300 297
301 inline PassRefPtr<CSSPrimitiveValue> CSSPropertyParser::createPrimitiveStringVal ue(CSSParserValue* value) 298 inline PassRefPtr<CSSPrimitiveValue> CSSPropertyParser::createPrimitiveStringVal ue(CSSParserValue* value)
302 { 299 {
303 ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPri mitiveValue::CSS_IDENT); 300 ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPri mitiveValue::CSS_IDENT);
304 return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRI NG); 301 return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRI NG);
305 } 302 }
306 303
307 inline PassRefPtr<CSSValue> CSSPropertyParser::createCSSImageValueWithReferrer(c onst String& rawValue, const KURL& url)
308 {
309 RefPtr<CSSValue> imageValue = CSSImageValue::create(rawValue, url);
310 toCSSImageValue(imageValue.get())->setReferrer(m_context.referrer());
311 return imageValue;
312 }
313
314 static inline bool isComma(CSSParserValue* value) 304 static inline bool isComma(CSSParserValue* value)
315 { 305 {
316 return value && value->unit == CSSParserValue::Operator && value->iValue == ','; 306 return value && value->unit == CSSParserValue::Operator && value->iValue == ',';
317 } 307 }
318 308
319 static bool consumeComma(CSSParserValueList* valueList) 309 static bool consumeComma(CSSParserValueList* valueList)
320 { 310 {
321 if (!isComma(valueList->current())) 311 if (!isComma(valueList->current()))
322 return false; 312 return false;
323 valueList->next(); 313 valueList->next();
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 return result; 564 return result;
575 } 565 }
576 case CSSPropertyObjectPosition: 566 case CSSPropertyObjectPosition:
577 ASSERT(RuntimeEnabledFeatures::objectFitPositionEnabled()); 567 ASSERT(RuntimeEnabledFeatures::objectFitPositionEnabled());
578 parsedValue = parseObjectPosition(); 568 parsedValue = parseObjectPosition();
579 break; 569 break;
580 case CSSPropertyBorderImageSource: 570 case CSSPropertyBorderImageSource:
581 if (id == CSSValueNone) { 571 if (id == CSSValueNone) {
582 parsedValue = cssValuePool().createIdentifierValue(CSSValueNone); 572 parsedValue = cssValuePool().createIdentifierValue(CSSValueNone);
583 m_valueList->next(); 573 m_valueList->next();
584 } else if (value->unit == CSSPrimitiveValue::CSS_URI) {
585 parsedValue = createCSSImageValueWithReferrer(value->string, complet eURL(value->string));
586 m_valueList->next();
587 } else if (isGeneratedImageValue(value)) { 574 } else if (isGeneratedImageValue(value)) {
588 if (parseGeneratedImage(m_valueList, parsedValue)) 575 if (parseGeneratedImage(m_valueList, parsedValue))
589 m_valueList->next(); 576 m_valueList->next();
590 else 577 else
591 return false; 578 return false;
592 } 579 }
593 else if (value->unit == CSSParserValue::Function && equalIgnoringCase(va lue->function->name, "-webkit-image-set(")) {
594 parsedValue = parseImageSet(m_valueList);
595 if (!parsedValue)
596 return false;
597 m_valueList->next();
598 }
599 break; 580 break;
600 581
601 case CSSPropertyWebkitTextStrokeWidth: 582 case CSSPropertyWebkitTextStrokeWidth:
602 case CSSPropertyOutlineWidth: // <border-width> | inherit 583 case CSSPropertyOutlineWidth: // <border-width> | inherit
603 case CSSPropertyBorderTopWidth: //// <border-width> | inherit 584 case CSSPropertyBorderTopWidth: //// <border-width> | inherit
604 case CSSPropertyBorderRightWidth: // Which is defined as 585 case CSSPropertyBorderRightWidth: // Which is defined as
605 case CSSPropertyBorderBottomWidth: // thin | medium | thick | <length> 586 case CSSPropertyBorderBottomWidth: // thin | medium | thick | <length>
606 case CSSPropertyBorderLeftWidth: 587 case CSSPropertyBorderLeftWidth:
607 case CSSPropertyWebkitBorderStartWidth: 588 case CSSPropertyWebkitBorderStartWidth:
608 case CSSPropertyWebkitBorderEndWidth: 589 case CSSPropertyWebkitBorderEndWidth:
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 return cssValuePool().createIdentifierValue(id); 1556 return cssValuePool().createIdentifierValue(id);
1576 return parseColor(); 1557 return parseColor();
1577 } 1558 }
1578 1559
1579 bool CSSPropertyParser::parseFillImage(CSSParserValueList* valueList, RefPtr<CSS Value>& value) 1560 bool CSSPropertyParser::parseFillImage(CSSParserValueList* valueList, RefPtr<CSS Value>& value)
1580 { 1561 {
1581 if (valueList->current()->id == CSSValueNone) { 1562 if (valueList->current()->id == CSSValueNone) {
1582 value = cssValuePool().createIdentifierValue(CSSValueNone); 1563 value = cssValuePool().createIdentifierValue(CSSValueNone);
1583 return true; 1564 return true;
1584 } 1565 }
1585 if (valueList->current()->unit == CSSPrimitiveValue::CSS_URI) {
1586 value = createCSSImageValueWithReferrer(valueList->current()->string, co mpleteURL(valueList->current()->string));
1587 return true;
1588 }
1589 1566
1590 if (isGeneratedImageValue(valueList->current())) 1567 if (isGeneratedImageValue(valueList->current()))
1591 return parseGeneratedImage(valueList, value); 1568 return parseGeneratedImage(valueList, value);
1592 1569
1593 if (valueList->current()->unit == CSSParserValue::Function && equalIgnoringC ase(valueList->current()->function->name, "-webkit-image-set(")) {
1594 value = parseImageSet(m_valueList);
1595 if (value)
1596 return true;
1597 }
1598
1599 return false; 1570 return false;
1600 } 1571 }
1601 1572
1602 PassRefPtr<CSSValue> CSSPropertyParser::parseFillPositionX(CSSParserValueList* v alueList) 1573 PassRefPtr<CSSValue> CSSPropertyParser::parseFillPositionX(CSSParserValueList* v alueList)
1603 { 1574 {
1604 int id = valueList->current()->id; 1575 int id = valueList->current()->id;
1605 if (id == CSSValueLeft || id == CSSValueRight || id == CSSValueCenter) { 1576 if (id == CSSValueLeft || id == CSSValueRight || id == CSSValueCenter) {
1606 int percent = 0; 1577 int percent = 0;
1607 if (id == CSSValueRight) 1578 if (id == CSSValueRight)
1608 percent = 100; 1579 percent = 100;
(...skipping 2625 matching lines...) Expand 10 before | Expand all | Expand 10 after
4234 bool BorderImageParseContext::buildFromParser(CSSPropertyParser& parser, CSSProp ertyID propId, BorderImageParseContext& context) 4205 bool BorderImageParseContext::buildFromParser(CSSPropertyParser& parser, CSSProp ertyID propId, BorderImageParseContext& context)
4235 { 4206 {
4236 CSSPropertyParser::ShorthandScope scope(&parser, propId); 4207 CSSPropertyParser::ShorthandScope scope(&parser, propId);
4237 while (CSSParserValue* val = parser.m_valueList->current()) { 4208 while (CSSParserValue* val = parser.m_valueList->current()) {
4238 context.setCanAdvance(false); 4209 context.setCanAdvance(false);
4239 4210
4240 if (!context.canAdvance() && context.allowForwardSlashOperator() && isFo rwardSlashOperator(val)) 4211 if (!context.canAdvance() && context.allowForwardSlashOperator() && isFo rwardSlashOperator(val))
4241 context.commitForwardSlashOperator(); 4212 context.commitForwardSlashOperator();
4242 4213
4243 if (!context.canAdvance() && context.allowImage()) { 4214 if (!context.canAdvance() && context.allowImage()) {
4244 if (val->unit == CSSPrimitiveValue::CSS_URI) { 4215 if (isGeneratedImageValue(val)) {
4245 context.commitImage(parser.createCSSImageValueWithReferrer(val-> string, parser.m_context.completeURL(val->string)));
4246 } else if (isGeneratedImageValue(val)) {
4247 RefPtr<CSSValue> value = nullptr; 4216 RefPtr<CSSValue> value = nullptr;
4248 if (parser.parseGeneratedImage(parser.m_valueList, value)) 4217 if (parser.parseGeneratedImage(parser.m_valueList, value))
4249 context.commitImage(value.release()); 4218 context.commitImage(value.release());
4250 else 4219 else
4251 return false; 4220 return false;
4252 } else if (val->unit == CSSParserValue::Function && equalIgnoringCas e(val->function->name, "-webkit-image-set(")) {
4253 RefPtr<CSSValue> value = parser.parseImageSet(parser.m_valueList );
4254 if (value)
4255 context.commitImage(value.release());
4256 else
4257 return false;
4258 } else if (val->id == CSSValueNone) 4221 } else if (val->id == CSSValueNone)
4259 context.commitImage(cssValuePool().createIdentifierValue(CSSValu eNone)); 4222 context.commitImage(cssValuePool().createIdentifierValue(CSSValu eNone));
4260 } 4223 }
4261 4224
4262 if (!context.canAdvance() && context.allowImageSlice()) { 4225 if (!context.canAdvance() && context.allowImageSlice()) {
4263 RefPtr<CSSBorderImageSliceValue> imageSlice = nullptr; 4226 RefPtr<CSSBorderImageSliceValue> imageSlice = nullptr;
4264 if (parser.parseBorderImageSlice(propId, imageSlice)) 4227 if (parser.parseBorderImageSlice(propId, imageSlice))
4265 context.commitImageSlice(imageSlice.release()); 4228 context.commitImageSlice(imageSlice.release());
4266 } 4229 }
4267 4230
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
4939 4902
4940 if (equalIgnoringCase(val->function->name, "repeating-linear-gradient(")) 4903 if (equalIgnoringCase(val->function->name, "repeating-linear-gradient("))
4941 return parseLinearGradient(valueList, value, Repeating); 4904 return parseLinearGradient(valueList, value, Repeating);
4942 4905
4943 if (equalIgnoringCase(val->function->name, "radial-gradient(")) 4906 if (equalIgnoringCase(val->function->name, "radial-gradient("))
4944 return parseRadialGradient(valueList, value, NonRepeating); 4907 return parseRadialGradient(valueList, value, NonRepeating);
4945 4908
4946 if (equalIgnoringCase(val->function->name, "repeating-radial-gradient(")) 4909 if (equalIgnoringCase(val->function->name, "repeating-radial-gradient("))
4947 return parseRadialGradient(valueList, value, Repeating); 4910 return parseRadialGradient(valueList, value, Repeating);
4948 4911
4949 if (equalIgnoringCase(val->function->name, "-webkit-cross-fade("))
4950 return parseCrossfade(valueList, value);
4951
4952 return false; 4912 return false;
4953 } 4913 }
4954 4914
4955 bool CSSPropertyParser::parseCrossfade(CSSParserValueList* valueList, RefPtr<CSS Value>& crossfade)
4956 {
4957 // Walk the arguments.
4958 CSSParserValueList* args = valueList->current()->function->args.get();
4959 if (!args || args->size() != 5)
4960 return false;
4961 RefPtr<CSSValue> fromImageValue = nullptr;
4962 RefPtr<CSSValue> toImageValue = nullptr;
4963
4964 // The first argument is the "from" image. It is a fill image.
4965 if (!args->current() || !parseFillImage(args, fromImageValue))
4966 return false;
4967 args->next();
4968
4969 if (!consumeComma(args))
4970 return false;
4971
4972 // The second argument is the "to" image. It is a fill image.
4973 if (!args->current() || !parseFillImage(args, toImageValue))
4974 return false;
4975 args->next();
4976
4977 if (!consumeComma(args))
4978 return false;
4979
4980 // The third argument is the crossfade value. It is a percentage or a fracti onal number.
4981 RefPtr<CSSPrimitiveValue> percentage = nullptr;
4982 CSSParserValue* value = args->current();
4983 if (!value)
4984 return false;
4985
4986 if (value->unit == CSSPrimitiveValue::CSS_PERCENTAGE)
4987 percentage = cssValuePool().createValue(clampTo<double>(value->fValue / 100, 0, 1), CSSPrimitiveValue::CSS_NUMBER);
4988 else if (value->unit == CSSPrimitiveValue::CSS_NUMBER)
4989 percentage = cssValuePool().createValue(clampTo<double>(value->fValue, 0 , 1), CSSPrimitiveValue::CSS_NUMBER);
4990 else
4991 return false;
4992
4993 RefPtr<CSSCrossfadeValue> result = CSSCrossfadeValue::create(fromImageValue, toImageValue);
4994 result->setPercentage(percentage);
4995
4996 crossfade = result;
4997
4998 return true;
4999 }
5000
5001 PassRefPtr<CSSValue> CSSPropertyParser::parseImageSet(CSSParserValueList* valueL ist)
5002 {
5003 CSSParserValue* function = valueList->current();
5004
5005 if (function->unit != CSSParserValue::Function)
5006 return nullptr;
5007
5008 CSSParserValueList* functionArgs = valueList->current()->function->args.get( );
5009 if (!functionArgs || !functionArgs->size() || !functionArgs->current())
5010 return nullptr;
5011
5012 RefPtr<CSSImageSetValue> imageSet = CSSImageSetValue::create();
5013
5014 while (functionArgs->current()) {
5015 CSSParserValue* arg = functionArgs->current();
5016 if (arg->unit != CSSPrimitiveValue::CSS_URI)
5017 return nullptr;
5018
5019 RefPtr<CSSValue> image = createCSSImageValueWithReferrer(arg->string, co mpleteURL(arg->string));
5020 imageSet->append(image);
5021
5022 arg = functionArgs->next();
5023 if (!arg || arg->unit != CSSPrimitiveValue::CSS_DIMENSION)
5024 return nullptr;
5025
5026 double imageScaleFactor = 0;
5027 const String& string = arg->string;
5028 unsigned length = string.length();
5029 if (!length)
5030 return nullptr;
5031 if (string.is8Bit()) {
5032 const LChar* start = string.characters8();
5033 parseDouble(start, start + length, 'x', imageScaleFactor);
5034 } else {
5035 const UChar* start = string.characters16();
5036 parseDouble(start, start + length, 'x', imageScaleFactor);
5037 }
5038 if (imageScaleFactor <= 0)
5039 return nullptr;
5040 imageSet->append(cssValuePool().createValue(imageScaleFactor, CSSPrimiti veValue::CSS_NUMBER));
5041 functionArgs->next();
5042
5043 // If there are no more arguments, we're done.
5044 if (!functionArgs->current())
5045 break;
5046
5047 // If there are more arguments, they should be after a comma.
5048 if (!consumeComma(functionArgs))
5049 return nullptr;
5050 }
5051
5052 return imageSet.release();
5053 }
5054
5055 PassRefPtr<CSSValue> CSSPropertyParser::parseWillChange() 4915 PassRefPtr<CSSValue> CSSPropertyParser::parseWillChange()
5056 { 4916 {
5057 RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated(); 4917 RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
5058 if (m_valueList->current()->id == CSSValueAuto) { 4918 if (m_valueList->current()->id == CSSValueAuto) {
5059 // FIXME: This will be read back as an empty string instead of auto 4919 // FIXME: This will be read back as an empty string instead of auto
5060 return values.release(); 4920 return values.release();
5061 } 4921 }
5062 4922
5063 // Every comma-separated list of CSS_IDENTs is a valid will-change value, 4923 // Every comma-separated list of CSS_IDENTs is a valid will-change value,
5064 // unless the list includes an explicitly disallowed CSS_IDENT. 4924 // unless the list includes an explicitly disallowed CSS_IDENT.
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
5824 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); 5684 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n");
5825 } 5685 }
5826 5686
5827 bool CSSPropertyParser::isSystemColor(int id) 5687 bool CSSPropertyParser::isSystemColor(int id)
5828 { 5688 {
5829 // FIXME(sky): remove 5689 // FIXME(sky): remove
5830 return false; 5690 return false;
5831 } 5691 }
5832 5692
5833 } // namespace blink 5693 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/parser/CSSPropertyParser.h ('k') | sky/engine/core/css/resolver/AnimatedStyleBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698