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

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: Address review comments 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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 459
463 case CSSPropertyTextAlign: 460 case CSSPropertyTextAlign:
464 // left | right | center | justify | -webkit-left | -webkit-right | -web kit-center | -webkit-match-parent 461 // left | right | center | justify | -webkit-left | -webkit-right | -web kit-center | -webkit-match-parent
465 // | start | end | <string> | inherit | -webkit-auto (converted to start ) 462 // | start | end | <string> | inherit | -webkit-auto (converted to start )
466 // FIXME: <string> not supported right now 463 // FIXME: <string> not supported right now
467 if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitMatchParent) || id == CSSValueStart || id == CSSValueEnd) { 464 if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitMatchParent) || id == CSSValueStart || id == CSSValueEnd) {
468 validPrimitive = true; 465 validPrimitive = true;
469 } 466 }
470 break; 467 break;
471 468
472 case CSSPropertyFontWeight: // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
473 return parseFontWeight(important) && !m_valueList->next();
474
475 case CSSPropertyBorderSpacing: { 469 case CSSPropertyBorderSpacing: {
476 ShorthandScope scope(this, CSSPropertyBorderSpacing); 470 ShorthandScope scope(this, CSSPropertyBorderSpacing);
477 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important)) 471 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important))
478 return false; 472 return false;
479 if (!m_valueList->current()) { 473 if (!m_valueList->current()) {
480 CSSValue* value = m_parsedProperties.last().value(); 474 CSSValue* value = m_parsedProperties.last().value();
481 addProperty(CSSPropertyWebkitBorderVerticalSpacing, value, important ); 475 addProperty(CSSPropertyWebkitBorderVerticalSpacing, value, important );
482 return true; 476 return true;
483 } 477 }
484 if (!parseValue(CSSPropertyWebkitBorderVerticalSpacing, important)) 478 if (!parseValue(CSSPropertyWebkitBorderVerticalSpacing, important))
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 case CSSPropertyWebkitMinLogicalWidth: 734 case CSSPropertyWebkitMinLogicalWidth:
741 case CSSPropertyWebkitMinLogicalHeight: 735 case CSSPropertyWebkitMinLogicalHeight:
742 case CSSPropertyWebkitLogicalWidth: 736 case CSSPropertyWebkitLogicalWidth:
743 case CSSPropertyWebkitLogicalHeight: 737 case CSSPropertyWebkitLogicalHeight:
744 validPrimitive = (id == CSSValueAuto || validWidthOrHeight(value, unitle ss)); 738 validPrimitive = (id == CSSValueAuto || validWidthOrHeight(value, unitle ss));
745 break; 739 break;
746 740
747 case CSSPropertyFontSize: 741 case CSSPropertyFontSize:
748 return parseFontSize(important); 742 return parseFontSize(important);
749 743
750 case CSSPropertyFontVariant: // normal | small-caps | inherit
751 return parseFontVariant(important);
752
753 case CSSPropertyVerticalAlign: 744 case CSSPropertyVerticalAlign:
754 // baseline | sub | super | top | text-top | middle | bottom | text-bott om | 745 // baseline | sub | super | top | text-top | middle | bottom | text-bott om |
755 // <percentage> | <length> | inherit 746 // <percentage> | <length> | inherit
756 747
757 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle) 748 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle)
758 validPrimitive = true; 749 validPrimitive = true;
759 else 750 else
760 validPrimitive = validUnit(value, FLength | FPercent | FUnitlessQuir k); 751 validPrimitive = validUnit(value, FLength | FPercent | FUnitlessQuir k);
761 break; 752 break;
762 753
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 validPrimitive = true; 796 validPrimitive = true;
806 else 797 else
807 parsedValue = parseCounter(1); 798 parsedValue = parseCounter(1);
808 break; 799 break;
809 case CSSPropertyCounterReset: 800 case CSSPropertyCounterReset:
810 if (id == CSSValueNone) 801 if (id == CSSValueNone)
811 validPrimitive = true; 802 validPrimitive = true;
812 else 803 else
813 parsedValue = parseCounter(0); 804 parsedValue = parseCounter(0);
814 break; 805 break;
815 case CSSPropertyFontFamily:
816 // [[ <family-name> | <generic-family> ],]* [<family-name> | <generic-fa mily>] | inherit
817 {
818 parsedValue = parseFontFamily();
819 break;
820 }
821 806
822 case CSSPropertyTextDecoration: 807 case CSSPropertyTextDecoration:
823 // Fall through 'text-decoration-line' parsing if CSS 3 Text Decoration 808 // Fall through 'text-decoration-line' parsing if CSS 3 Text Decoration
824 // is disabled to match CSS 2.1 rules for parsing 'text-decoration'. 809 // is disabled to match CSS 2.1 rules for parsing 'text-decoration'.
825 if (RuntimeEnabledFeatures::css3TextDecorationsEnabled()) { 810 if (RuntimeEnabledFeatures::css3TextDecorationsEnabled()) {
826 // [ <text-decoration-line> || <text-decoration-style> || <text-deco ration-color> ] | inherit 811 // [ <text-decoration-line> || <text-decoration-style> || <text-deco ration-color> ] | inherit
827 return parseShorthand(CSSPropertyTextDecoration, textDecorationShort hand(), important); 812 return parseShorthand(CSSPropertyTextDecoration, textDecorationShort hand(), important);
828 } 813 }
829 case CSSPropertyWebkitTextDecorationsInEffect: 814 case CSSPropertyWebkitTextDecorationsInEffect:
830 case CSSPropertyTextDecorationLine: 815 case CSSPropertyTextDecorationLine:
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 case CSSPropertyWebkitTextEmphasisStyle: 1354 case CSSPropertyWebkitTextEmphasisStyle:
1370 parsedValue = parseTextEmphasisStyle(); 1355 parsedValue = parseTextEmphasisStyle();
1371 break; 1356 break;
1372 1357
1373 case CSSPropertyWebkitTextOrientation: 1358 case CSSPropertyWebkitTextOrientation:
1374 // FIXME: For now just support sideways, sideways-right, upright and ver tical-right. 1359 // FIXME: For now just support sideways, sideways-right, upright and ver tical-right.
1375 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSVa lueVerticalRight || id == CSSValueUpright) 1360 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSVa lueVerticalRight || id == CSSValueUpright)
1376 validPrimitive = true; 1361 validPrimitive = true;
1377 break; 1362 break;
1378 1363
1379 case CSSPropertyWebkitFontFeatureSettings:
1380 if (id == CSSValueNormal)
1381 validPrimitive = true;
1382 else
1383 parsedValue = parseFontFeatureSettings();
1384 break;
1385
1386 case CSSPropertyWebkitClipPath: 1364 case CSSPropertyWebkitClipPath:
1387 if (id == CSSValueNone) { 1365 if (id == CSSValueNone) {
1388 validPrimitive = true; 1366 validPrimitive = true;
1389 } else if (value->m_unit == CSSParserValue::Function) { 1367 } else if (value->m_unit == CSSParserValue::Function) {
1390 parsedValue = parseBasicShape(); 1368 parsedValue = parseBasicShape();
1391 } else if (value->unit() == CSSPrimitiveValue::UnitType::URI) { 1369 } else if (value->unit() == CSSPrimitiveValue::UnitType::URI) {
1392 parsedValue = CSSPrimitiveValue::create(value->string, CSSPrimitiveV alue::UnitType::URI); 1370 parsedValue = CSSPrimitiveValue::create(value->string, CSSPrimitiveV alue::UnitType::URI);
1393 addProperty(propId, parsedValue.release(), important); 1371 addProperty(propId, parsedValue.release(), important);
1394 return true; 1372 return true;
1395 } 1373 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 break; 1413 break;
1436 1414
1437 // These were not accepted by the new path above so we should return false. 1415 // These were not accepted by the new path above so we should return false.
1438 case CSSPropertyWebkitMarginCollapse: 1416 case CSSPropertyWebkitMarginCollapse:
1439 case CSSPropertyWillChange: 1417 case CSSPropertyWillChange:
1440 case CSSPropertyPage: 1418 case CSSPropertyPage:
1441 case CSSPropertyOverflow: 1419 case CSSPropertyOverflow:
1442 case CSSPropertyQuotes: 1420 case CSSPropertyQuotes:
1443 case CSSPropertyWebkitHighlight: 1421 case CSSPropertyWebkitHighlight:
1444 case CSSPropertyFontVariantLigatures: 1422 case CSSPropertyFontVariantLigatures:
1423 case CSSPropertyWebkitFontFeatureSettings:
1424 case CSSPropertyFontVariant:
1425 case CSSPropertyFontFamily:
1426 case CSSPropertyFontWeight:
1445 validPrimitive = false; 1427 validPrimitive = false;
1446 break; 1428 break;
1447 1429
1448 case CSSPropertyScrollSnapPointsX: 1430 case CSSPropertyScrollSnapPointsX:
1449 case CSSPropertyScrollSnapPointsY: 1431 case CSSPropertyScrollSnapPointsY:
1450 parsedValue = parseScrollSnapPoints(); 1432 parsedValue = parseScrollSnapPoints();
1451 break; 1433 break;
1452 case CSSPropertyScrollSnapCoordinate: 1434 case CSSPropertyScrollSnapCoordinate:
1453 parsedValue = parseScrollSnapCoordinate(); 1435 parsedValue = parseScrollSnapCoordinate();
1454 break; 1436 break;
(...skipping 3203 matching lines...) Expand 10 before | Expand all | Expand 10 after
4658 // <absolute-size> | <relative-size> | <length> | <percentage> | inherit 4640 // <absolute-size> | <relative-size> | <length> | <percentage> | inherit
4659 if (id >= CSSValueXxSmall && id <= CSSValueLarger) 4641 if (id >= CSSValueXxSmall && id <= CSSValueLarger)
4660 validPrimitive = true; 4642 validPrimitive = true;
4661 else 4643 else
4662 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg | (inShor thand() ? FUnknown : FUnitlessQuirk)); 4644 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg | (inShor thand() ? FUnknown : FUnitlessQuirk));
4663 if (validPrimitive && (!m_valueList->next() || inShorthand())) 4645 if (validPrimitive && (!m_valueList->next() || inShorthand()))
4664 addProperty(CSSPropertyFontSize, parseValidPrimitive(id, value), importa nt); 4646 addProperty(CSSPropertyFontSize, parseValidPrimitive(id, value), importa nt);
4665 return validPrimitive; 4647 return validPrimitive;
4666 } 4648 }
4667 4649
4668 bool CSSPropertyParser::parseFontVariant(bool important)
4669 {
4670 RefPtrWillBeRawPtr<CSSValueList> values = nullptr;
4671 if (m_valueList->size() > 1)
4672 values = CSSValueList::createCommaSeparated();
4673 bool expectComma = false;
4674 for (CSSParserValue* val = m_valueList->current(); val; val = m_valueList->c urrent()) {
4675 RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue = nullptr;
4676 if (!expectComma) {
4677 expectComma = true;
4678 if (val->id == CSSValueNormal || val->id == CSSValueSmallCaps)
4679 parsedValue = cssValuePool().createIdentifierValue(val->id);
4680 else if (val->id == CSSValueAll && !values) {
4681 // FIXME: CSSPropertyParser::parseFontVariant() implements
4682 // the old css3 draft:
4683 // http://www.w3.org/TR/2002/WD-css3-webfonts-20020802/#font-var iant
4684 // 'all' is only allowed in @font-face and with no other values. Make a value list to
4685 // indicate that we are in the @font-face case.
4686 values = CSSValueList::createCommaSeparated();
4687 parsedValue = cssValuePool().createIdentifierValue(val->id);
4688 }
4689 } else if (consumeComma(m_valueList)) {
4690 expectComma = false;
4691 continue;
4692 }
4693
4694 if (!parsedValue)
4695 return false;
4696
4697 m_valueList->next();
4698
4699 if (values)
4700 values->append(parsedValue.release());
4701 else {
4702 addProperty(CSSPropertyFontVariant, parsedValue.release(), important );
4703 return true;
4704 }
4705 }
4706
4707 if (values && values->length()) {
4708 if (m_ruleType != StyleRule::FontFace)
4709 return false;
4710 addProperty(CSSPropertyFontVariant, values.release(), important);
4711 return true;
4712 }
4713
4714 return false;
4715 }
4716
4717 bool CSSPropertyParser::parseFontWeight(bool important) 4650 bool CSSPropertyParser::parseFontWeight(bool important)
4718 { 4651 {
4719 CSSParserValue* value = m_valueList->current(); 4652 CSSParserValue* value = m_valueList->current();
4720 if (value->id >= CSSValueNormal && value->id <= CSSValueLighter) { 4653 if (value->id >= CSSValueNormal && value->id <= CSSValueLighter) {
4721 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue( value->id), important); 4654 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue( value->id), important);
4722 return true; 4655 return true;
4723 } 4656 }
4724 if (value->unit() == CSSPrimitiveValue::UnitType::Number) { 4657 if (value->unit() == CSSPrimitiveValue::UnitType::Number) {
4725 int weight = static_cast<int>(value->fValue); 4658 int weight = static_cast<int>(value->fValue);
4726 if (!(weight % 100) && weight >= 100 && weight <= 900) { 4659 if (!(weight % 100) && weight >= 100 && weight <= 900) {
4727 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierVa lue(static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1)), important); 4660 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierVa lue(static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1)), important);
4728 return true; 4661 return true;
4729 } 4662 }
4730 } 4663 }
4731 return false; 4664 return false;
4732 } 4665 }
4733 4666
4734 bool CSSPropertyParser::parseFontFaceSrcURI(CSSValueList* valueList)
4735 {
4736 RefPtrWillBeRawPtr<CSSFontFaceSrcValue> uriValue(CSSFontFaceSrcValue::create (completeURL(m_valueList->current()->string), m_context.shouldCheckContentSecuri tyPolicy()));
4737 uriValue->setReferrer(m_context.referrer());
4738
4739 CSSParserValue* value = m_valueList->next();
4740 if (!value || value->m_unit != CSSParserValue::Function || value->function-> id != CSSValueFormat) {
4741 valueList->append(uriValue.release());
4742 return true;
4743 }
4744
4745 // FIXME: http://www.w3.org/TR/2011/WD-css3-fonts-20111004/ says that format () contains a comma-separated list of strings,
4746 // but CSSFontFaceSrcValue stores only one format. Allowing one format for n ow.
4747 CSSParserValueList* args = value->function->args.get();
4748 if (!args || args->size() != 1 || (args->current()->unit() != CSSPrimitiveVa lue::UnitType::String && args->current()->m_unit != CSSParserValue::Identifier))
4749 return false;
4750 uriValue->setFormat(args->current()->string);
4751 valueList->append(uriValue.release());
4752 m_valueList->next();
4753 return true;
4754 }
4755
4756 bool CSSPropertyParser::parseFontFaceSrcLocal(CSSValueList* valueList)
4757 {
4758 CSSParserValueList* args = m_valueList->current()->function->args.get();
4759 if (!args || !args->size())
4760 return false;
4761 m_valueList->next();
4762
4763 ContentSecurityPolicyDisposition shouldCheckContentSecurityPolicy = m_contex t.shouldCheckContentSecurityPolicy();
4764 if (args->size() == 1 && args->current()->unit() == CSSPrimitiveValue::UnitT ype::String) {
4765 valueList->append(CSSFontFaceSrcValue::createLocal(args->current()->stri ng, shouldCheckContentSecurityPolicy));
4766 } else if (args->current()->m_unit == CSSParserValue::Identifier) {
4767 StringBuilder builder;
4768 for (CSSParserValue* localValue = args->current(); localValue; localValu e = args->next()) {
4769 if (localValue->m_unit != CSSParserValue::Identifier)
4770 return false;
4771 if (!builder.isEmpty())
4772 builder.append(' ');
4773 builder.append(localValue->string);
4774 }
4775 valueList->append(CSSFontFaceSrcValue::createLocal(builder.toString(), s houldCheckContentSecurityPolicy));
4776 } else
4777 return false;
4778
4779 return true;
4780 }
4781
4782 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseFontFaceSrc()
4783 {
4784 RefPtrWillBeRawPtr<CSSValueList> values(CSSValueList::createCommaSeparated() );
4785
4786 while (true) {
4787 CSSParserValue* value = m_valueList->current();
4788 if (!value)
4789 return nullptr;
4790 if (value->unit() == CSSPrimitiveValue::UnitType::URI) {
4791 if (!parseFontFaceSrcURI(values.get()))
4792 return nullptr;
4793 } else if (value->m_unit == CSSParserValue::Function && value->function- >id == CSSValueLocal) {
4794 if (!parseFontFaceSrcLocal(values.get()))
4795 return nullptr;
4796 } else {
4797 return nullptr;
4798 }
4799
4800 if (!m_valueList->current())
4801 return values.release();
4802 if (!consumeComma(m_valueList))
4803 return nullptr;
4804 }
4805 }
4806
4807 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseFontFaceUnicodeRang e()
4808 {
4809 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated ();
4810
4811 do {
4812 CSSParserValue* current = m_valueList->current();
4813 if (!current || current->m_unit != CSSParserValue::UnicodeRange)
4814 return nullptr;
4815
4816 UChar32 start = current->m_unicodeRange.start;
4817 UChar32 end = current->m_unicodeRange.end;
4818 if (start > end)
4819 return nullptr;
4820 values->append(CSSUnicodeRangeValue::create(start, end));
4821 m_valueList->next();
4822 } while (consumeComma(m_valueList));
4823
4824 return values.release();
4825 }
4826
4827 inline int CSSPropertyParser::colorIntFromValue(CSSParserValue* v) 4667 inline int CSSPropertyParser::colorIntFromValue(CSSParserValue* v)
4828 { 4668 {
4829 bool isPercent; 4669 bool isPercent;
4830 double value; 4670 double value;
4831 4671
4832 if (m_parsedCalculation) { 4672 if (m_parsedCalculation) {
4833 isPercent = m_parsedCalculation->category() == CalcPercent; 4673 isPercent = m_parsedCalculation->category() == CalcPercent;
4834 value = m_parsedCalculation->doubleValue(); 4674 value = m_parsedCalculation->doubleValue();
4835 m_parsedCalculation.release(); 4675 m_parsedCalculation.release();
4836 } else { 4676 } else {
(...skipping 2116 matching lines...) Expand 10 before | Expand all | Expand 10 after
6953 } 6793 }
6954 return nullptr; 6794 return nullptr;
6955 } 6795 }
6956 6796
6957 if (!hasLengthOrPercentage) 6797 if (!hasLengthOrPercentage)
6958 return nullptr; 6798 return nullptr;
6959 6799
6960 return list.release(); 6800 return list.release();
6961 } 6801 }
6962 6802
6963 bool CSSPropertyParser::parseFontFeatureTag(CSSValueList* settings)
6964 {
6965 // Feature tag name consists of 4-letter characters.
6966 static const unsigned tagNameLength = 4;
6967
6968 CSSParserValue* value = m_valueList->current();
6969 // Feature tag name comes first
6970 if (value->unit() != CSSPrimitiveValue::UnitType::String)
6971 return false;
6972 if (value->string.length() != tagNameLength)
6973 return false;
6974 for (unsigned i = 0; i < tagNameLength; ++i) {
6975 // Limits the range of characters to 0x20-0x7E, following the tag name r ules defiend in the OpenType specification.
6976 UChar character = value->string[i];
6977 if (character < 0x20 || character > 0x7E)
6978 return false;
6979 }
6980
6981 AtomicString tag = value->string;
6982 int tagValue = 1;
6983 // Feature tag values could follow: <integer> | on | off
6984 value = m_valueList->next();
6985 if (value) {
6986 if (value->unit() == CSSPrimitiveValue::UnitType::Number && value->isInt && value->fValue >= 0) {
6987 tagValue = clampTo<int>(value->fValue);
6988 if (tagValue < 0)
6989 return false;
6990 m_valueList->next();
6991 } else if (value->id == CSSValueOn || value->id == CSSValueOff) {
6992 tagValue = value->id == CSSValueOn;
6993 m_valueList->next();
6994 }
6995 }
6996 settings->append(CSSFontFeatureValue::create(tag, tagValue));
6997 return true;
6998 }
6999
7000 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseFontFeatureSettings()
7001 {
7002 RefPtrWillBeRawPtr<CSSValueList> settings = CSSValueList::createCommaSeparat ed();
7003 while (true) {
7004 if (!m_valueList->current() || !parseFontFeatureTag(settings.get()))
7005 return nullptr;
7006 if (!m_valueList->current())
7007 break;
7008 if (!consumeComma(m_valueList))
7009 return nullptr;
7010 }
7011 return settings.release();
7012 }
7013
7014 bool CSSPropertyParser::parseCalculation(CSSParserValue* value, ValueRange range ) 6803 bool CSSPropertyParser::parseCalculation(CSSParserValue* value, ValueRange range )
7015 { 6804 {
7016 ASSERT(isCalculation(value)); 6805 ASSERT(isCalculation(value));
7017 6806
7018 CSSParserTokenRange args = value->calcFunction->args; 6807 CSSParserTokenRange args = value->calcFunction->args;
7019 6808
7020 ASSERT(!m_parsedCalculation); 6809 ASSERT(!m_parsedCalculation);
7021 m_parsedCalculation = CSSCalcValue::create(args, range); 6810 m_parsedCalculation = CSSCalcValue::create(args, range);
7022 6811
7023 if (!m_parsedCalculation) 6812 if (!m_parsedCalculation)
7024 return false; 6813 return false;
7025 6814
7026 return true; 6815 return true;
7027 } 6816 }
7028 6817
7029 bool CSSPropertyParser::parseFontFaceDescriptor(CSSPropertyID propId)
7030 {
7031 CSSParserValue* value = m_valueList->current();
7032 ASSERT(value);
7033 CSSValueID id = value->id;
7034 RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr;
7035
7036 switch (propId) {
7037 case CSSPropertyFontFamily:
7038 // <family-name>
7039 // TODO(rwlbuis): check there is only one family-name
7040 parsedValue = parseFontFamily();
7041 break;
7042 case CSSPropertySrc: // This is a list of urls or local references.
7043 parsedValue = parseFontFaceSrc();
7044 break;
7045 case CSSPropertyUnicodeRange:
7046 parsedValue = parseFontFaceUnicodeRange();
7047 break;
7048 case CSSPropertyFontWeight: // normal | bold | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
7049 return parseFontWeight(false) && !m_valueList->next();
7050 case CSSPropertyFontStretch:
7051 case CSSPropertyFontStyle:
7052 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(propId, id))
7053 return false;
7054 addProperty(propId, cssValuePool().createIdentifierValue(id), false);
7055 return true;
7056 case CSSPropertyFontVariant: // normal | small-caps | inherit
7057 return parseFontVariant(false);
7058 case CSSPropertyWebkitFontFeatureSettings:
7059 if (id == CSSValueNormal) {
7060 parsedValue = cssValuePool().createIdentifierValue(CSSValueNormal);
7061 m_valueList->next();
7062 } else {
7063 parsedValue = parseFontFeatureSettings();
7064 }
7065 break;
7066 default:
7067 break;
7068 }
7069
7070 if (!parsedValue || m_valueList->current())
7071 return false;
7072
7073 addProperty(propId, parsedValue.release(), false);
7074 return true;
7075 }
7076
7077 bool CSSPropertyParser::parseViewportProperty(CSSPropertyID propId, bool importa nt) 6818 bool CSSPropertyParser::parseViewportProperty(CSSPropertyID propId, bool importa nt)
7078 { 6819 {
7079 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_c ontext.mode())); 6820 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_c ontext.mode()));
7080 6821
7081 CSSParserValue* value = m_valueList->current(); 6822 CSSParserValue* value = m_valueList->current();
7082 if (!value) 6823 if (!value)
7083 return false; 6824 return false;
7084 6825
7085 CSSValueID id = value->id; 6826 CSSValueID id = value->id;
7086 bool validPrimitive = false; 6827 bool validPrimitive = false;
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
7727 } 7468 }
7728 } 7469 }
7729 7470
7730 if (!list->length()) 7471 if (!list->length())
7731 return nullptr; 7472 return nullptr;
7732 7473
7733 return list.release(); 7474 return list.release();
7734 } 7475 }
7735 7476
7736 } // namespace blink 7477 } // 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