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

Side by Side Diff: Source/core/css/parser/LegacyCSSPropertyParser.cpp

Issue 1331233003: Move parseFontFaceDescriptor to CSSPropertyParser.cpp (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Patch for review Created 5 years, 3 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 17 matching lines...) Expand all
28 #include "core/css/parser/CSSPropertyParser.h" 28 #include "core/css/parser/CSSPropertyParser.h"
29 29
30 #include "core/StylePropertyShorthand.h" 30 #include "core/StylePropertyShorthand.h"
31 #include "core/css/CSSBasicShapes.h" 31 #include "core/css/CSSBasicShapes.h"
32 #include "core/css/CSSBorderImage.h" 32 #include "core/css/CSSBorderImage.h"
33 #include "core/css/CSSCanvasValue.h" 33 #include "core/css/CSSCanvasValue.h"
34 #include "core/css/CSSContentDistributionValue.h" 34 #include "core/css/CSSContentDistributionValue.h"
35 #include "core/css/CSSCounterValue.h" 35 #include "core/css/CSSCounterValue.h"
36 #include "core/css/CSSCrossfadeValue.h" 36 #include "core/css/CSSCrossfadeValue.h"
37 #include "core/css/CSSCursorImageValue.h" 37 #include "core/css/CSSCursorImageValue.h"
38 #include "core/css/CSSFontFaceSrcValue.h"
39 #include "core/css/CSSFontFeatureValue.h"
40 #include "core/css/CSSFunctionValue.h" 38 #include "core/css/CSSFunctionValue.h"
41 #include "core/css/CSSGridLineNamesValue.h" 39 #include "core/css/CSSGridLineNamesValue.h"
42 #include "core/css/CSSImageSetValue.h" 40 #include "core/css/CSSImageSetValue.h"
43 #include "core/css/CSSImageValue.h" 41 #include "core/css/CSSImageValue.h"
44 #include "core/css/CSSPathValue.h" 42 #include "core/css/CSSPathValue.h"
45 #include "core/css/CSSPrimitiveValueMappings.h" 43 #include "core/css/CSSPrimitiveValueMappings.h"
46 #include "core/css/CSSProperty.h" 44 #include "core/css/CSSProperty.h"
47 #include "core/css/CSSPropertyMetadata.h" 45 #include "core/css/CSSPropertyMetadata.h"
48 #include "core/css/CSSQuadValue.h" 46 #include "core/css/CSSQuadValue.h"
49 #include "core/css/CSSReflectValue.h" 47 #include "core/css/CSSReflectValue.h"
50 #include "core/css/CSSSVGDocumentValue.h" 48 #include "core/css/CSSSVGDocumentValue.h"
51 #include "core/css/CSSShadowValue.h" 49 #include "core/css/CSSShadowValue.h"
52 #include "core/css/CSSTimingFunctionValue.h" 50 #include "core/css/CSSTimingFunctionValue.h"
53 #include "core/css/CSSUnicodeRangeValue.h"
54 #include "core/css/CSSValuePair.h" 51 #include "core/css/CSSValuePair.h"
55 #include "core/css/CSSValuePool.h" 52 #include "core/css/CSSValuePool.h"
56 #include "core/css/HashTools.h" 53 #include "core/css/HashTools.h"
57 #include "core/css/parser/CSSParserFastPaths.h" 54 #include "core/css/parser/CSSParserFastPaths.h"
58 #include "core/css/parser/CSSParserValues.h" 55 #include "core/css/parser/CSSParserValues.h"
59 #include "core/frame/UseCounter.h" 56 #include "core/frame/UseCounter.h"
60 #include "core/layout/LayoutTheme.h" 57 #include "core/layout/LayoutTheme.h"
61 #include "core/style/GridCoordinate.h" 58 #include "core/style/GridCoordinate.h"
62 #include "core/svg/SVGPathUtilities.h" 59 #include "core/svg/SVGPathUtilities.h"
63 #include "platform/RuntimeEnabledFeatures.h" 60 #include "platform/RuntimeEnabledFeatures.h"
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 if (id == CSSValueAuto) 450 if (id == CSSValueAuto)
454 validPrimitive = true; 451 validPrimitive = true;
455 else if (value->m_unit == CSSParserValue::Function) 452 else if (value->m_unit == CSSParserValue::Function)
456 parsedValue = parseClipShape(); 453 parsedValue = parseClipShape();
457 break; 454 break;
458 455
459 /* Start of supported CSS properties with validation. This is needed for par seShorthand to work 456 /* Start of supported CSS properties with validation. This is needed for par seShorthand to work
460 * correctly and allows optimization in blink::applyRule(..) 457 * correctly and allows optimization in blink::applyRule(..)
461 */ 458 */
462 459
463 case CSSPropertyTextAlign:
464 // left | right | center | justify | -webkit-left | -webkit-right | -web kit-center | -webkit-match-parent
465 // | start | end | <string> | inherit | -webkit-auto (converted to start )
466 // FIXME: <string> not supported right now
467 if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitMatchParent) || id == CSSValueStart || id == CSSValueEnd) {
468 validPrimitive = true;
469 }
470 break;
471
472 case CSSPropertyFontWeight: // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit 460 case CSSPropertyFontWeight: // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
473 return parseFontWeight(important) && !m_valueList->next(); 461 return parseFontWeight(important) && !m_valueList->next();
474 462
475 case CSSPropertyBorderSpacing: { 463 case CSSPropertyBorderSpacing: {
476 ShorthandScope scope(this, CSSPropertyBorderSpacing); 464 ShorthandScope scope(this, CSSPropertyBorderSpacing);
477 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important)) 465 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important))
478 return false; 466 return false;
479 if (!m_valueList->current()) { 467 if (!m_valueList->current()) {
480 CSSValue* value = m_parsedProperties.last().value(); 468 CSSValue* value = m_parsedProperties.last().value();
481 addProperty(CSSPropertyWebkitBorderVerticalSpacing, value, important ); 469 addProperty(CSSPropertyWebkitBorderVerticalSpacing, value, important );
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 case CSSPropertyWebkitMinLogicalWidth: 728 case CSSPropertyWebkitMinLogicalWidth:
741 case CSSPropertyWebkitMinLogicalHeight: 729 case CSSPropertyWebkitMinLogicalHeight:
742 case CSSPropertyWebkitLogicalWidth: 730 case CSSPropertyWebkitLogicalWidth:
743 case CSSPropertyWebkitLogicalHeight: 731 case CSSPropertyWebkitLogicalHeight:
744 validPrimitive = (id == CSSValueAuto || validWidthOrHeight(value, unitle ss)); 732 validPrimitive = (id == CSSValueAuto || validWidthOrHeight(value, unitle ss));
745 break; 733 break;
746 734
747 case CSSPropertyFontSize: 735 case CSSPropertyFontSize:
748 return parseFontSize(important); 736 return parseFontSize(important);
749 737
750 case CSSPropertyFontVariant: // normal | small-caps | inherit
751 return parseFontVariant(important);
752
753 case CSSPropertyVerticalAlign: 738 case CSSPropertyVerticalAlign:
754 // baseline | sub | super | top | text-top | middle | bottom | text-bott om | 739 // baseline | sub | super | top | text-top | middle | bottom | text-bott om |
755 // <percentage> | <length> | inherit 740 // <percentage> | <length> | inherit
756 741
757 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle) 742 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle)
758 validPrimitive = true; 743 validPrimitive = true;
759 else 744 else
760 validPrimitive = validUnit(value, FLength | FPercent | FUnitlessQuir k); 745 validPrimitive = validUnit(value, FLength | FPercent | FUnitlessQuir k);
761 break; 746 break;
762 747
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 1211
1227 case CSSPropertyWebkitColumnCount: 1212 case CSSPropertyWebkitColumnCount:
1228 parsedValue = parseColumnCount(); 1213 parsedValue = parseColumnCount();
1229 break; 1214 break;
1230 case CSSPropertyWebkitColumnGap: // normal | <length> 1215 case CSSPropertyWebkitColumnGap: // normal | <length>
1231 if (id == CSSValueNormal) 1216 if (id == CSSValueNormal)
1232 validPrimitive = true; 1217 validPrimitive = true;
1233 else 1218 else
1234 validPrimitive = validUnit(value, FLength | FNonNeg); 1219 validPrimitive = validUnit(value, FLength | FNonNeg);
1235 break; 1220 break;
1236 case CSSPropertyWebkitColumnSpan: // none | all | 1 (will be dropped in the unprefixed property)
1237 validPrimitive = id == CSSValueAll || id == CSSValueNone || (value->unit () == CSSPrimitiveValue::UnitType::Number && value->fValue == 1);
1238 break;
1239 case CSSPropertyWebkitColumnWidth: // auto | <length> 1221 case CSSPropertyWebkitColumnWidth: // auto | <length>
1240 parsedValue = parseColumnWidth(); 1222 parsedValue = parseColumnWidth();
1241 break; 1223 break;
1242 // End of CSS3 properties 1224 // End of CSS3 properties
1243 1225
1244 // Apple specific properties. These will never be standardized and are pure ly to 1226 // Apple specific properties. These will never be standardized and are pure ly to
1245 // support custom WebKit-based Apple applications. 1227 // support custom WebKit-based Apple applications.
1246 case CSSPropertyWebkitLineClamp: 1228 case CSSPropertyWebkitLineClamp:
1247 // When specifying number of lines, don't allow 0 as a valid value 1229 // When specifying number of lines, don't allow 0 as a valid value
1248 // When specifying either type of unit, require non-negative integers 1230 // When specifying either type of unit, require non-negative integers
1249 validPrimitive = (!id && !isCalculation(value) && validUnit(value, FInte ger | FPercent | FNonNeg) && (value->unit() == CSSPrimitiveValue::UnitType::Perc entage || value->fValue)); 1231 validPrimitive = (!id && !isCalculation(value) && validUnit(value, FInte ger | FPercent | FNonNeg) && (value->unit() == CSSPrimitiveValue::UnitType::Perc entage || value->fValue));
1250 break; 1232 break;
1251 1233
1252 case CSSPropertyWebkitFontSizeDelta: // <length> 1234 case CSSPropertyWebkitFontSizeDelta: // <length>
1253 validPrimitive = validUnit(value, FLength | FUnitlessQuirk); 1235 validPrimitive = validUnit(value, FLength | FUnitlessQuirk);
1254 break; 1236 break;
1255 1237
1256 case CSSPropertyWebkitHyphenateCharacter:
1257 case CSSPropertyWebkitLocale:
1258 if (id == CSSValueAuto) {
1259 validPrimitive = true;
1260 } else if (value->unit() == CSSPrimitiveValue::UnitType::String) {
1261 parsedValue = createPrimitiveStringValue(value);
1262 m_valueList->next();
1263 }
1264 break;
1265
1266 // End Apple-specific properties 1238 // End Apple-specific properties
1267 1239
1268 case CSSPropertyWebkitAppRegion: 1240 case CSSPropertyWebkitAppRegion:
1269 if (id >= CSSValueDrag && id <= CSSValueNoDrag) 1241 if (id >= CSSValueDrag && id <= CSSValueNoDrag)
1270 validPrimitive = true; 1242 validPrimitive = true;
1271 break; 1243 break;
1272 1244
1273 case CSSPropertyWebkitTapHighlightColor: 1245 case CSSPropertyWebkitTapHighlightColor:
1274 parsedValue = parseColor(m_valueList->current()); 1246 parsedValue = parseColor(m_valueList->current());
1275 if (parsedValue) 1247 if (parsedValue)
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 case CSSPropertyWebkitTextEmphasisStyle: 1340 case CSSPropertyWebkitTextEmphasisStyle:
1369 parsedValue = parseTextEmphasisStyle(); 1341 parsedValue = parseTextEmphasisStyle();
1370 break; 1342 break;
1371 1343
1372 case CSSPropertyWebkitTextOrientation: 1344 case CSSPropertyWebkitTextOrientation:
1373 // FIXME: For now just support sideways, sideways-right, upright and ver tical-right. 1345 // FIXME: For now just support sideways, sideways-right, upright and ver tical-right.
1374 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSVa lueVerticalRight || id == CSSValueUpright) 1346 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSVa lueVerticalRight || id == CSSValueUpright)
1375 validPrimitive = true; 1347 validPrimitive = true;
1376 break; 1348 break;
1377 1349
1378 case CSSPropertyWebkitFontFeatureSettings:
1379 if (id == CSSValueNormal)
1380 validPrimitive = true;
1381 else
1382 parsedValue = parseFontFeatureSettings();
1383 break;
1384
1385 case CSSPropertyFontVariantLigatures:
1386 if (id == CSSValueNormal)
1387 validPrimitive = true;
1388 else
1389 return parseFontVariantLigatures(important);
1390 break;
1391 case CSSPropertyWebkitClipPath: 1350 case CSSPropertyWebkitClipPath:
1392 if (id == CSSValueNone) { 1351 if (id == CSSValueNone) {
1393 validPrimitive = true; 1352 validPrimitive = true;
1394 } else if (value->m_unit == CSSParserValue::Function) { 1353 } else if (value->m_unit == CSSParserValue::Function) {
1395 parsedValue = parseBasicShape(); 1354 parsedValue = parseBasicShape();
1396 } else if (value->unit() == CSSPrimitiveValue::UnitType::URI) { 1355 } else if (value->unit() == CSSPrimitiveValue::UnitType::URI) {
1397 parsedValue = CSSPrimitiveValue::create(value->string, CSSPrimitiveV alue::UnitType::URI); 1356 parsedValue = CSSPrimitiveValue::create(value->string, CSSPrimitiveV alue::UnitType::URI);
1398 addProperty(propId, parsedValue.release(), important); 1357 addProperty(propId, parsedValue.release(), important);
1399 return true; 1358 return true;
1400 } 1359 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 validPrimitive = false; 1397 validPrimitive = false;
1439 break; 1398 break;
1440 1399
1441 // These were not accepted by the new path above so we should return false. 1400 // These were not accepted by the new path above so we should return false.
1442 case CSSPropertyWebkitMarginCollapse: 1401 case CSSPropertyWebkitMarginCollapse:
1443 case CSSPropertyWillChange: 1402 case CSSPropertyWillChange:
1444 case CSSPropertyPage: 1403 case CSSPropertyPage:
1445 case CSSPropertyOverflow: 1404 case CSSPropertyOverflow:
1446 case CSSPropertyQuotes: 1405 case CSSPropertyQuotes:
1447 case CSSPropertyWebkitHighlight: 1406 case CSSPropertyWebkitHighlight:
1407 case CSSPropertyWebkitFontFeatureSettings:
1408 case CSSPropertyFontVariantLigatures:
1409 case CSSPropertyFontVariant:
1410 case CSSPropertyWebkitColumnSpan:
1411 case CSSPropertyWebkitHyphenateCharacter:
1412 case CSSPropertyWebkitLocale:
1413 case CSSPropertyTextAlign:
1448 validPrimitive = false; 1414 validPrimitive = false;
1449 break; 1415 break;
1450 1416
1451 case CSSPropertyScrollSnapPointsX: 1417 case CSSPropertyScrollSnapPointsX:
1452 case CSSPropertyScrollSnapPointsY: 1418 case CSSPropertyScrollSnapPointsY:
1453 parsedValue = parseScrollSnapPoints(); 1419 parsedValue = parseScrollSnapPoints();
1454 break; 1420 break;
1455 case CSSPropertyScrollSnapCoordinate: 1421 case CSSPropertyScrollSnapCoordinate:
1456 parsedValue = parseScrollSnapCoordinate(); 1422 parsedValue = parseScrollSnapCoordinate();
1457 break; 1423 break;
(...skipping 3203 matching lines...) Expand 10 before | Expand all | Expand 10 after
4661 // <absolute-size> | <relative-size> | <length> | <percentage> | inherit 4627 // <absolute-size> | <relative-size> | <length> | <percentage> | inherit
4662 if (id >= CSSValueXxSmall && id <= CSSValueLarger) 4628 if (id >= CSSValueXxSmall && id <= CSSValueLarger)
4663 validPrimitive = true; 4629 validPrimitive = true;
4664 else 4630 else
4665 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg | (inShor thand() ? FUnknown : FUnitlessQuirk)); 4631 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg | (inShor thand() ? FUnknown : FUnitlessQuirk));
4666 if (validPrimitive && (!m_valueList->next() || inShorthand())) 4632 if (validPrimitive && (!m_valueList->next() || inShorthand()))
4667 addProperty(CSSPropertyFontSize, parseValidPrimitive(id, value), importa nt); 4633 addProperty(CSSPropertyFontSize, parseValidPrimitive(id, value), importa nt);
4668 return validPrimitive; 4634 return validPrimitive;
4669 } 4635 }
4670 4636
4671 bool CSSPropertyParser::parseFontVariant(bool important)
4672 {
4673 RefPtrWillBeRawPtr<CSSValueList> values = nullptr;
4674 if (m_valueList->size() > 1)
4675 values = CSSValueList::createCommaSeparated();
4676 bool expectComma = false;
4677 for (CSSParserValue* val = m_valueList->current(); val; val = m_valueList->c urrent()) {
4678 RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue = nullptr;
4679 if (!expectComma) {
4680 expectComma = true;
4681 if (val->id == CSSValueNormal || val->id == CSSValueSmallCaps)
4682 parsedValue = cssValuePool().createIdentifierValue(val->id);
4683 else if (val->id == CSSValueAll && !values) {
4684 // FIXME: CSSPropertyParser::parseFontVariant() implements
4685 // the old css3 draft:
4686 // http://www.w3.org/TR/2002/WD-css3-webfonts-20020802/#font-var iant
4687 // 'all' is only allowed in @font-face and with no other values. Make a value list to
4688 // indicate that we are in the @font-face case.
4689 values = CSSValueList::createCommaSeparated();
4690 parsedValue = cssValuePool().createIdentifierValue(val->id);
4691 }
4692 } else if (consumeComma(m_valueList)) {
4693 expectComma = false;
4694 continue;
4695 }
4696
4697 if (!parsedValue)
4698 return false;
4699
4700 m_valueList->next();
4701
4702 if (values)
4703 values->append(parsedValue.release());
4704 else {
4705 addProperty(CSSPropertyFontVariant, parsedValue.release(), important );
4706 return true;
4707 }
4708 }
4709
4710 if (values && values->length()) {
4711 if (m_ruleType != StyleRule::FontFace)
4712 return false;
4713 addProperty(CSSPropertyFontVariant, values.release(), important);
4714 return true;
4715 }
4716
4717 return false;
4718 }
4719
4720 bool CSSPropertyParser::parseFontWeight(bool important) 4637 bool CSSPropertyParser::parseFontWeight(bool important)
4721 { 4638 {
4722 CSSParserValue* value = m_valueList->current(); 4639 CSSParserValue* value = m_valueList->current();
4723 if (value->id >= CSSValueNormal && value->id <= CSSValueLighter) { 4640 if (value->id >= CSSValueNormal && value->id <= CSSValueLighter) {
4724 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue( value->id), important); 4641 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue( value->id), important);
4725 return true; 4642 return true;
4726 } 4643 }
4727 if (value->unit() == CSSPrimitiveValue::UnitType::Number) { 4644 if (value->unit() == CSSPrimitiveValue::UnitType::Number) {
4728 int weight = static_cast<int>(value->fValue); 4645 int weight = static_cast<int>(value->fValue);
4729 if (!(weight % 100) && weight >= 100 && weight <= 900) { 4646 if (!(weight % 100) && weight >= 100 && weight <= 900) {
4730 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierVa lue(static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1)), important); 4647 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierVa lue(static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1)), important);
4731 return true; 4648 return true;
4732 } 4649 }
4733 } 4650 }
4734 return false; 4651 return false;
4735 } 4652 }
4736 4653
4737 bool CSSPropertyParser::parseFontFaceSrcURI(CSSValueList* valueList)
4738 {
4739 RefPtrWillBeRawPtr<CSSFontFaceSrcValue> uriValue(CSSFontFaceSrcValue::create (completeURL(m_valueList->current()->string), m_context.shouldCheckContentSecuri tyPolicy()));
4740 uriValue->setReferrer(m_context.referrer());
4741
4742 CSSParserValue* value = m_valueList->next();
4743 if (!value || value->m_unit != CSSParserValue::Function || value->function-> id != CSSValueFormat) {
4744 valueList->append(uriValue.release());
4745 return true;
4746 }
4747
4748 // FIXME: http://www.w3.org/TR/2011/WD-css3-fonts-20111004/ says that format () contains a comma-separated list of strings,
4749 // but CSSFontFaceSrcValue stores only one format. Allowing one format for n ow.
4750 CSSParserValueList* args = value->function->args.get();
4751 if (!args || args->size() != 1 || (args->current()->unit() != CSSPrimitiveVa lue::UnitType::String && args->current()->m_unit != CSSParserValue::Identifier))
4752 return false;
4753 uriValue->setFormat(args->current()->string);
4754 valueList->append(uriValue.release());
4755 m_valueList->next();
4756 return true;
4757 }
4758
4759 bool CSSPropertyParser::parseFontFaceSrcLocal(CSSValueList* valueList)
4760 {
4761 CSSParserValueList* args = m_valueList->current()->function->args.get();
4762 if (!args || !args->size())
4763 return false;
4764 m_valueList->next();
4765
4766 ContentSecurityPolicyDisposition shouldCheckContentSecurityPolicy = m_contex t.shouldCheckContentSecurityPolicy();
4767 if (args->size() == 1 && args->current()->unit() == CSSPrimitiveValue::UnitT ype::String) {
4768 valueList->append(CSSFontFaceSrcValue::createLocal(args->current()->stri ng, shouldCheckContentSecurityPolicy));
4769 } else if (args->current()->m_unit == CSSParserValue::Identifier) {
4770 StringBuilder builder;
4771 for (CSSParserValue* localValue = args->current(); localValue; localValu e = args->next()) {
4772 if (localValue->m_unit != CSSParserValue::Identifier)
4773 return false;
4774 if (!builder.isEmpty())
4775 builder.append(' ');
4776 builder.append(localValue->string);
4777 }
4778 valueList->append(CSSFontFaceSrcValue::createLocal(builder.toString(), s houldCheckContentSecurityPolicy));
4779 } else
4780 return false;
4781
4782 return true;
4783 }
4784
4785 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseFontFaceSrc()
4786 {
4787 RefPtrWillBeRawPtr<CSSValueList> values(CSSValueList::createCommaSeparated() );
4788
4789 while (true) {
4790 CSSParserValue* value = m_valueList->current();
4791 if (!value)
4792 return nullptr;
4793 if (value->unit() == CSSPrimitiveValue::UnitType::URI) {
4794 if (!parseFontFaceSrcURI(values.get()))
4795 return nullptr;
4796 } else if (value->m_unit == CSSParserValue::Function && value->function- >id == CSSValueLocal) {
4797 if (!parseFontFaceSrcLocal(values.get()))
4798 return nullptr;
4799 } else {
4800 return nullptr;
4801 }
4802
4803 if (!m_valueList->current())
4804 return values.release();
4805 if (!consumeComma(m_valueList))
4806 return nullptr;
4807 }
4808 }
4809
4810 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseFontFaceUnicodeRang e()
4811 {
4812 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated ();
4813
4814 do {
4815 CSSParserValue* current = m_valueList->current();
4816 if (!current || current->m_unit != CSSParserValue::UnicodeRange)
4817 return nullptr;
4818
4819 UChar32 start = current->m_unicodeRange.start;
4820 UChar32 end = current->m_unicodeRange.end;
4821 if (start > end)
4822 return nullptr;
4823 values->append(CSSUnicodeRangeValue::create(start, end));
4824 m_valueList->next();
4825 } while (consumeComma(m_valueList));
4826
4827 return values.release();
4828 }
4829
4830 inline int CSSPropertyParser::colorIntFromValue(CSSParserValue* v) 4654 inline int CSSPropertyParser::colorIntFromValue(CSSParserValue* v)
4831 { 4655 {
4832 bool isPercent; 4656 bool isPercent;
4833 double value; 4657 double value;
4834 4658
4835 if (m_parsedCalculation) { 4659 if (m_parsedCalculation) {
4836 isPercent = m_parsedCalculation->category() == CalcPercent; 4660 isPercent = m_parsedCalculation->category() == CalcPercent;
4837 value = m_parsedCalculation->doubleValue(); 4661 value = m_parsedCalculation->doubleValue();
4838 m_parsedCalculation.release(); 4662 m_parsedCalculation.release();
4839 } else { 4663 } else {
(...skipping 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after
6959 } 6783 }
6960 return nullptr; 6784 return nullptr;
6961 } 6785 }
6962 6786
6963 if (!hasLengthOrPercentage) 6787 if (!hasLengthOrPercentage)
6964 return nullptr; 6788 return nullptr;
6965 6789
6966 return list.release(); 6790 return list.release();
6967 } 6791 }
6968 6792
6969 bool CSSPropertyParser::parseFontFeatureTag(CSSValueList* settings)
6970 {
6971 // Feature tag name consists of 4-letter characters.
6972 static const unsigned tagNameLength = 4;
6973
6974 CSSParserValue* value = m_valueList->current();
6975 // Feature tag name comes first
6976 if (value->unit() != CSSPrimitiveValue::UnitType::String)
6977 return false;
6978 if (value->string.length() != tagNameLength)
6979 return false;
6980 for (unsigned i = 0; i < tagNameLength; ++i) {
6981 // Limits the range of characters to 0x20-0x7E, following the tag name r ules defiend in the OpenType specification.
6982 UChar character = value->string[i];
6983 if (character < 0x20 || character > 0x7E)
6984 return false;
6985 }
6986
6987 AtomicString tag = value->string;
6988 int tagValue = 1;
6989 // Feature tag values could follow: <integer> | on | off
6990 value = m_valueList->next();
6991 if (value) {
6992 if (value->unit() == CSSPrimitiveValue::UnitType::Number && value->isInt && value->fValue >= 0) {
6993 tagValue = clampTo<int>(value->fValue);
6994 if (tagValue < 0)
6995 return false;
6996 m_valueList->next();
6997 } else if (value->id == CSSValueOn || value->id == CSSValueOff) {
6998 tagValue = value->id == CSSValueOn;
6999 m_valueList->next();
7000 }
7001 }
7002 settings->append(CSSFontFeatureValue::create(tag, tagValue));
7003 return true;
7004 }
7005
7006 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseFontFeatureSettings()
7007 {
7008 RefPtrWillBeRawPtr<CSSValueList> settings = CSSValueList::createCommaSeparat ed();
7009 while (true) {
7010 if (!m_valueList->current() || !parseFontFeatureTag(settings.get()))
7011 return nullptr;
7012 if (!m_valueList->current())
7013 break;
7014 if (!consumeComma(m_valueList))
7015 return nullptr;
7016 }
7017 return settings.release();
7018 }
7019
7020 bool CSSPropertyParser::parseFontVariantLigatures(bool important)
7021 {
7022 RefPtrWillBeRawPtr<CSSValueList> ligatureValues = CSSValueList::createSpaceS eparated();
7023 bool sawCommonLigaturesValue = false;
7024 bool sawDiscretionaryLigaturesValue = false;
7025 bool sawHistoricalLigaturesValue = false;
7026 bool sawContextualLigaturesValue = false;
7027
7028 for (CSSParserValue* value = m_valueList->current(); value; value = m_valueL ist->next()) {
7029 if (value->m_unit != CSSParserValue::Identifier)
7030 return false;
7031
7032 switch (value->id) {
7033 case CSSValueNoCommonLigatures:
7034 case CSSValueCommonLigatures:
7035 if (sawCommonLigaturesValue)
7036 return false;
7037 sawCommonLigaturesValue = true;
7038 ligatureValues->append(cssValuePool().createIdentifierValue(value->i d));
7039 break;
7040 case CSSValueNoDiscretionaryLigatures:
7041 case CSSValueDiscretionaryLigatures:
7042 if (sawDiscretionaryLigaturesValue)
7043 return false;
7044 sawDiscretionaryLigaturesValue = true;
7045 ligatureValues->append(cssValuePool().createIdentifierValue(value->i d));
7046 break;
7047 case CSSValueNoHistoricalLigatures:
7048 case CSSValueHistoricalLigatures:
7049 if (sawHistoricalLigaturesValue)
7050 return false;
7051 sawHistoricalLigaturesValue = true;
7052 ligatureValues->append(cssValuePool().createIdentifierValue(value->i d));
7053 break;
7054 case CSSValueNoContextual:
7055 case CSSValueContextual:
7056 if (sawContextualLigaturesValue)
7057 return false;
7058 sawContextualLigaturesValue = true;
7059 ligatureValues->append(cssValuePool().createIdentifierValue(value->i d));
7060 break;
7061 default:
7062 return false;
7063 }
7064 }
7065
7066 if (!ligatureValues->length())
7067 return false;
7068
7069 addProperty(CSSPropertyFontVariantLigatures, ligatureValues.release(), impor tant);
7070 return true;
7071 }
7072
7073 bool CSSPropertyParser::parseCalculation(CSSParserValue* value, ValueRange range ) 6793 bool CSSPropertyParser::parseCalculation(CSSParserValue* value, ValueRange range )
7074 { 6794 {
7075 ASSERT(isCalculation(value)); 6795 ASSERT(isCalculation(value));
7076 6796
7077 CSSParserTokenRange args = value->calcFunction->args; 6797 CSSParserTokenRange args = value->calcFunction->args;
7078 6798
7079 ASSERT(!m_parsedCalculation); 6799 ASSERT(!m_parsedCalculation);
7080 m_parsedCalculation = CSSCalcValue::create(args, range); 6800 m_parsedCalculation = CSSCalcValue::create(args, range);
7081 6801
7082 if (!m_parsedCalculation) 6802 if (!m_parsedCalculation)
7083 return false; 6803 return false;
7084 6804
7085 return true; 6805 return true;
7086 } 6806 }
7087 6807
7088 bool CSSPropertyParser::parseFontFaceDescriptor(CSSPropertyID propId)
7089 {
7090 CSSParserValue* value = m_valueList->current();
7091 ASSERT(value);
7092 CSSValueID id = value->id;
7093 RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr;
7094
7095 switch (propId) {
7096 case CSSPropertyFontFamily:
7097 // <family-name>
7098 // TODO(rwlbuis): check there is only one family-name
7099 parsedValue = parseFontFamily();
7100 break;
7101 case CSSPropertySrc: // This is a list of urls or local references.
7102 parsedValue = parseFontFaceSrc();
7103 break;
7104 case CSSPropertyUnicodeRange:
7105 parsedValue = parseFontFaceUnicodeRange();
7106 break;
7107 case CSSPropertyFontWeight: // normal | bold | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
7108 return parseFontWeight(false) && !m_valueList->next();
7109 case CSSPropertyFontStretch:
7110 case CSSPropertyFontStyle:
7111 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(propId, id))
7112 return false;
7113 addProperty(propId, cssValuePool().createIdentifierValue(id), false);
7114 return true;
7115 case CSSPropertyFontVariant: // normal | small-caps | inherit
7116 return parseFontVariant(false);
7117 case CSSPropertyWebkitFontFeatureSettings:
7118 if (id == CSSValueNormal) {
7119 parsedValue = cssValuePool().createIdentifierValue(CSSValueNormal);
7120 m_valueList->next();
7121 } else {
7122 parsedValue = parseFontFeatureSettings();
7123 }
7124 break;
7125 default:
7126 break;
7127 }
7128
7129 if (!parsedValue || m_valueList->current())
7130 return false;
7131
7132 addProperty(propId, parsedValue.release(), false);
7133 return true;
7134 }
7135
7136 bool CSSPropertyParser::parseViewportProperty(CSSPropertyID propId, bool importa nt) 6808 bool CSSPropertyParser::parseViewportProperty(CSSPropertyID propId, bool importa nt)
7137 { 6809 {
7138 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_c ontext.mode())); 6810 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_c ontext.mode()));
7139 6811
7140 CSSParserValue* value = m_valueList->current(); 6812 CSSParserValue* value = m_valueList->current();
7141 if (!value) 6813 if (!value)
7142 return false; 6814 return false;
7143 6815
7144 CSSValueID id = value->id; 6816 CSSValueID id = value->id;
7145 bool validPrimitive = false; 6817 bool validPrimitive = false;
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
7786 } 7458 }
7787 } 7459 }
7788 7460
7789 if (!list->length()) 7461 if (!list->length())
7790 return nullptr; 7462 return nullptr;
7791 7463
7792 return list.release(); 7464 return list.release();
7793 } 7465 }
7794 7466
7795 } // namespace blink 7467 } // namespace blink
OLDNEW
« Source/core/css/parser/CSSPropertyParser.cpp ('K') | « Source/core/css/parser/CSSPropertyParser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698