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

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: Cleanup consumeFontWeight and consumeUrl 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 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 case CSSPropertyWebkitMinLogicalWidth: 737 case CSSPropertyWebkitMinLogicalWidth:
741 case CSSPropertyWebkitMinLogicalHeight: 738 case CSSPropertyWebkitMinLogicalHeight:
742 case CSSPropertyWebkitLogicalWidth: 739 case CSSPropertyWebkitLogicalWidth:
743 case CSSPropertyWebkitLogicalHeight: 740 case CSSPropertyWebkitLogicalHeight:
744 validPrimitive = (id == CSSValueAuto || validWidthOrHeight(value, unitle ss)); 741 validPrimitive = (id == CSSValueAuto || validWidthOrHeight(value, unitle ss));
745 break; 742 break;
746 743
747 case CSSPropertyFontSize: 744 case CSSPropertyFontSize:
748 return parseFontSize(important); 745 return parseFontSize(important);
749 746
750 case CSSPropertyFontVariant: // normal | small-caps | inherit
751 return parseFontVariant(important);
752
753 case CSSPropertyVerticalAlign: 747 case CSSPropertyVerticalAlign:
754 // baseline | sub | super | top | text-top | middle | bottom | text-bott om | 748 // baseline | sub | super | top | text-top | middle | bottom | text-bott om |
755 // <percentage> | <length> | inherit 749 // <percentage> | <length> | inherit
756 750
757 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle) 751 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle)
758 validPrimitive = true; 752 validPrimitive = true;
759 else 753 else
760 validPrimitive = validUnit(value, FLength | FPercent | FUnitlessQuir k); 754 validPrimitive = validUnit(value, FLength | FPercent | FUnitlessQuir k);
761 break; 755 break;
762 756
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 validPrimitive = true; 799 validPrimitive = true;
806 else 800 else
807 parsedValue = parseCounter(1); 801 parsedValue = parseCounter(1);
808 break; 802 break;
809 case CSSPropertyCounterReset: 803 case CSSPropertyCounterReset:
810 if (id == CSSValueNone) 804 if (id == CSSValueNone)
811 validPrimitive = true; 805 validPrimitive = true;
812 else 806 else
813 parsedValue = parseCounter(0); 807 parsedValue = parseCounter(0);
814 break; 808 break;
815 case CSSPropertyFontFamily:
816 // [[ <family-name> | <generic-family> ],]* [<family-name> | <generic-fa mily>] | inherit
817 {
818 parsedValue = parseFontFamily();
819 break;
820 }
821 809
822 case CSSPropertyTextDecoration: 810 case CSSPropertyTextDecoration:
823 // Fall through 'text-decoration-line' parsing if CSS 3 Text Decoration 811 // Fall through 'text-decoration-line' parsing if CSS 3 Text Decoration
824 // is disabled to match CSS 2.1 rules for parsing 'text-decoration'. 812 // is disabled to match CSS 2.1 rules for parsing 'text-decoration'.
825 if (RuntimeEnabledFeatures::css3TextDecorationsEnabled()) { 813 if (RuntimeEnabledFeatures::css3TextDecorationsEnabled()) {
826 // [ <text-decoration-line> || <text-decoration-style> || <text-deco ration-color> ] | inherit 814 // [ <text-decoration-line> || <text-decoration-style> || <text-deco ration-color> ] | inherit
827 return parseShorthand(CSSPropertyTextDecoration, textDecorationShort hand(), important); 815 return parseShorthand(CSSPropertyTextDecoration, textDecorationShort hand(), important);
828 } 816 }
829 case CSSPropertyWebkitTextDecorationsInEffect: 817 case CSSPropertyWebkitTextDecorationsInEffect:
830 case CSSPropertyTextDecorationLine: 818 case CSSPropertyTextDecorationLine:
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 case CSSPropertyWebkitTextEmphasisStyle: 1356 case CSSPropertyWebkitTextEmphasisStyle:
1369 parsedValue = parseTextEmphasisStyle(); 1357 parsedValue = parseTextEmphasisStyle();
1370 break; 1358 break;
1371 1359
1372 case CSSPropertyWebkitTextOrientation: 1360 case CSSPropertyWebkitTextOrientation:
1373 // FIXME: For now just support sideways, sideways-right, upright and ver tical-right. 1361 // FIXME: For now just support sideways, sideways-right, upright and ver tical-right.
1374 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSVa lueVerticalRight || id == CSSValueUpright) 1362 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSVa lueVerticalRight || id == CSSValueUpright)
1375 validPrimitive = true; 1363 validPrimitive = true;
1376 break; 1364 break;
1377 1365
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: 1366 case CSSPropertyWebkitClipPath:
1392 if (id == CSSValueNone) { 1367 if (id == CSSValueNone) {
1393 validPrimitive = true; 1368 validPrimitive = true;
1394 } else if (value->m_unit == CSSParserValue::Function) { 1369 } else if (value->m_unit == CSSParserValue::Function) {
1395 parsedValue = parseBasicShape(); 1370 parsedValue = parseBasicShape();
1396 } else if (value->unit() == CSSPrimitiveValue::UnitType::URI) { 1371 } else if (value->unit() == CSSPrimitiveValue::UnitType::URI) {
1397 parsedValue = CSSPrimitiveValue::create(value->string, CSSPrimitiveV alue::UnitType::URI); 1372 parsedValue = CSSPrimitiveValue::create(value->string, CSSPrimitiveV alue::UnitType::URI);
1398 addProperty(propId, parsedValue.release(), important); 1373 addProperty(propId, parsedValue.release(), important);
1399 return true; 1374 return true;
1400 } 1375 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 validPrimitive = false; 1413 validPrimitive = false;
1439 break; 1414 break;
1440 1415
1441 // These were not accepted by the new path above so we should return false. 1416 // These were not accepted by the new path above so we should return false.
1442 case CSSPropertyWebkitMarginCollapse: 1417 case CSSPropertyWebkitMarginCollapse:
1443 case CSSPropertyWillChange: 1418 case CSSPropertyWillChange:
1444 case CSSPropertyPage: 1419 case CSSPropertyPage:
1445 case CSSPropertyOverflow: 1420 case CSSPropertyOverflow:
1446 case CSSPropertyQuotes: 1421 case CSSPropertyQuotes:
1447 case CSSPropertyWebkitHighlight: 1422 case CSSPropertyWebkitHighlight:
1423 case CSSPropertyFontVariantLigatures:
1424 case CSSPropertyWebkitFontFeatureSettings:
1425 case CSSPropertyFontVariant:
1426 case CSSPropertyFontFamily:
1448 validPrimitive = false; 1427 validPrimitive = false;
1449 break; 1428 break;
1450 1429
1451 case CSSPropertyScrollSnapPointsX: 1430 case CSSPropertyScrollSnapPointsX:
1452 case CSSPropertyScrollSnapPointsY: 1431 case CSSPropertyScrollSnapPointsY:
1453 parsedValue = parseScrollSnapPoints(); 1432 parsedValue = parseScrollSnapPoints();
1454 break; 1433 break;
1455 case CSSPropertyScrollSnapCoordinate: 1434 case CSSPropertyScrollSnapCoordinate:
1456 parsedValue = parseScrollSnapCoordinate(); 1435 parsedValue = parseScrollSnapCoordinate();
1457 break; 1436 break;
(...skipping 3060 matching lines...) Expand 10 before | Expand all | Expand 10 after
4518 RefPtrWillBeRawPtr<CSSValueList> fontFamilyList = CSSValueList::createCommaS eparated(); 4497 RefPtrWillBeRawPtr<CSSValueList> fontFamilyList = CSSValueList::createCommaS eparated();
4519 fontFamilyList->append(cssValuePool().createFontFamilyValue(fontFamily)); 4498 fontFamilyList->append(cssValuePool().createFontFamilyValue(fontFamily));
4520 addProperty(CSSPropertyFontFamily, fontFamilyList.release(), important); 4499 addProperty(CSSPropertyFontFamily, fontFamilyList.release(), important);
4521 4500
4522 addProperty(CSSPropertyFontStretch, cssValuePool().createIdentifierValue(CSS ValueNormal), important); 4501 addProperty(CSSPropertyFontStretch, cssValuePool().createIdentifierValue(CSS ValueNormal), important);
4523 addProperty(CSSPropertyFontVariant, cssValuePool().createIdentifierValue(CSS ValueNormal), important); 4502 addProperty(CSSPropertyFontVariant, cssValuePool().createIdentifierValue(CSS ValueNormal), important);
4524 addProperty(CSSPropertyLineHeight, cssValuePool().createIdentifierValue(CSSV alueNormal), important); 4503 addProperty(CSSPropertyLineHeight, cssValuePool().createIdentifierValue(CSSV alueNormal), important);
4525 return true; 4504 return true;
4526 } 4505 }
4527 4506
4528 class FontFamilyValueBuilder {
4529 STACK_ALLOCATED();
4530 public:
4531 FontFamilyValueBuilder(CSSValueList* list)
4532 : m_list(list)
4533 {
4534 }
4535
4536 void add(const CSSParserString& string)
4537 {
4538 if (!m_builder.isEmpty())
4539 m_builder.append(' ');
4540
4541 if (string.is8Bit()) {
4542 m_builder.append(string.characters8(), string.length());
4543 return;
4544 }
4545
4546 m_builder.append(string.characters16(), string.length());
4547 }
4548
4549 void commit()
4550 {
4551 if (m_builder.isEmpty())
4552 return;
4553 m_list->append(cssValuePool().createFontFamilyValue(m_builder.toString() ));
4554 m_builder.clear();
4555 }
4556
4557 private:
4558 StringBuilder m_builder;
4559 RawPtrWillBeMember<CSSValueList> m_list;
4560 };
4561
4562 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseFontFamily() 4507 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseFontFamily()
4563 { 4508 {
4564 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated() ; 4509 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated() ;
4565 CSSParserValue* value = m_valueList->current(); 4510 CSSParserValue* value = m_valueList->current();
4566 4511
4567 FontFamilyValueBuilder familyBuilder(list.get()); 4512 FontFamilyValueBuilder familyBuilder(list.get());
4568 bool inFamily = false; 4513 bool inFamily = false;
4569 4514
4570 while (value) { 4515 while (value) {
4571 CSSParserValue* nextValue = m_valueList->next(); 4516 CSSParserValue* nextValue = m_valueList->next();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
4661 // <absolute-size> | <relative-size> | <length> | <percentage> | inherit 4606 // <absolute-size> | <relative-size> | <length> | <percentage> | inherit
4662 if (id >= CSSValueXxSmall && id <= CSSValueLarger) 4607 if (id >= CSSValueXxSmall && id <= CSSValueLarger)
4663 validPrimitive = true; 4608 validPrimitive = true;
4664 else 4609 else
4665 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg | (inShor thand() ? FUnknown : FUnitlessQuirk)); 4610 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg | (inShor thand() ? FUnknown : FUnitlessQuirk));
4666 if (validPrimitive && (!m_valueList->next() || inShorthand())) 4611 if (validPrimitive && (!m_valueList->next() || inShorthand()))
4667 addProperty(CSSPropertyFontSize, parseValidPrimitive(id, value), importa nt); 4612 addProperty(CSSPropertyFontSize, parseValidPrimitive(id, value), importa nt);
4668 return validPrimitive; 4613 return validPrimitive;
4669 } 4614 }
4670 4615
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) 4616 bool CSSPropertyParser::parseFontWeight(bool important)
4721 { 4617 {
4722 CSSParserValue* value = m_valueList->current(); 4618 CSSParserValue* value = m_valueList->current();
4723 if (value->id >= CSSValueNormal && value->id <= CSSValueLighter) { 4619 if (value->id >= CSSValueNormal && value->id <= CSSValueLighter) {
4724 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue( value->id), important); 4620 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue( value->id), important);
4725 return true; 4621 return true;
4726 } 4622 }
4727 if (value->unit() == CSSPrimitiveValue::UnitType::Number) { 4623 if (value->unit() == CSSPrimitiveValue::UnitType::Number) {
4728 int weight = static_cast<int>(value->fValue); 4624 int weight = static_cast<int>(value->fValue);
4729 if (!(weight % 100) && weight >= 100 && weight <= 900) { 4625 if (!(weight % 100) && weight >= 100 && weight <= 900) {
4730 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierVa lue(static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1)), important); 4626 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierVa lue(static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1)), important);
4731 return true; 4627 return true;
4732 } 4628 }
4733 } 4629 }
4734 return false; 4630 return false;
4735 } 4631 }
4736 4632
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) 4633 inline int CSSPropertyParser::colorIntFromValue(CSSParserValue* v)
4831 { 4634 {
4832 bool isPercent; 4635 bool isPercent;
4833 double value; 4636 double value;
4834 4637
4835 if (m_parsedCalculation) { 4638 if (m_parsedCalculation) {
4836 isPercent = m_parsedCalculation->category() == CalcPercent; 4639 isPercent = m_parsedCalculation->category() == CalcPercent;
4837 value = m_parsedCalculation->doubleValue(); 4640 value = m_parsedCalculation->doubleValue();
4838 m_parsedCalculation.release(); 4641 m_parsedCalculation.release();
4839 } else { 4642 } else {
(...skipping 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after
6959 } 6762 }
6960 return nullptr; 6763 return nullptr;
6961 } 6764 }
6962 6765
6963 if (!hasLengthOrPercentage) 6766 if (!hasLengthOrPercentage)
6964 return nullptr; 6767 return nullptr;
6965 6768
6966 return list.release(); 6769 return list.release();
6967 } 6770 }
6968 6771
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 ) 6772 bool CSSPropertyParser::parseCalculation(CSSParserValue* value, ValueRange range )
7074 { 6773 {
7075 ASSERT(isCalculation(value)); 6774 ASSERT(isCalculation(value));
7076 6775
7077 CSSParserTokenRange args = value->calcFunction->args; 6776 CSSParserTokenRange args = value->calcFunction->args;
7078 6777
7079 ASSERT(!m_parsedCalculation); 6778 ASSERT(!m_parsedCalculation);
7080 m_parsedCalculation = CSSCalcValue::create(args, range); 6779 m_parsedCalculation = CSSCalcValue::create(args, range);
7081 6780
7082 if (!m_parsedCalculation) 6781 if (!m_parsedCalculation)
7083 return false; 6782 return false;
7084 6783
7085 return true; 6784 return true;
7086 } 6785 }
7087 6786
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) 6787 bool CSSPropertyParser::parseViewportProperty(CSSPropertyID propId, bool importa nt)
7137 { 6788 {
7138 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_c ontext.mode())); 6789 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_c ontext.mode()));
7139 6790
7140 CSSParserValue* value = m_valueList->current(); 6791 CSSParserValue* value = m_valueList->current();
7141 if (!value) 6792 if (!value)
7142 return false; 6793 return false;
7143 6794
7144 CSSValueID id = value->id; 6795 CSSValueID id = value->id;
7145 bool validPrimitive = false; 6796 bool validPrimitive = false;
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
7786 } 7437 }
7787 } 7438 }
7788 7439
7789 if (!list->length()) 7440 if (!list->length())
7790 return nullptr; 7441 return nullptr;
7791 7442
7792 return list.release(); 7443 return list.release();
7793 } 7444 }
7794 7445
7795 } // namespace blink 7446 } // 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