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

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

Issue 1148873005: Parsing CSS properties for scroll snap points (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address review feedback Created 5 years, 6 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 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 addProperty(propId1, val1.release(), important); 720 addProperty(propId1, val1.release(), important);
721 if (val2) 721 if (val2)
722 addProperty(propId2, val2.release(), important); 722 addProperty(propId2, val2.release(), important);
723 } 723 }
724 result = true; 724 result = true;
725 } 725 }
726 m_implicitShorthand = false; 726 m_implicitShorthand = false;
727 return result; 727 return result;
728 } 728 }
729 case CSSPropertyObjectPosition: 729 case CSSPropertyObjectPosition:
730 parsedValue = parseObjectPosition(); 730 parsedValue = parsePosition();
731 break; 731 break;
732 case CSSPropertyListStyleImage: // <uri> | none | inherit 732 case CSSPropertyListStyleImage: // <uri> | none | inherit
733 case CSSPropertyBorderImageSource: 733 case CSSPropertyBorderImageSource:
734 case CSSPropertyWebkitMaskBoxImageSource: 734 case CSSPropertyWebkitMaskBoxImageSource:
735 if (id == CSSValueNone) { 735 if (id == CSSValueNone) {
736 parsedValue = cssValuePool().createIdentifierValue(CSSValueNone); 736 parsedValue = cssValuePool().createIdentifierValue(CSSValueNone);
737 m_valueList->next(); 737 m_valueList->next();
738 } else if (value->unit == CSSPrimitiveValue::CSS_URI) { 738 } else if (value->unit == CSSPrimitiveValue::CSS_URI) {
739 parsedValue = createCSSImageValueWithReferrer(value->string, complet eURL(value->string)); 739 parsedValue = createCSSImageValueWithReferrer(value->string, complet eURL(value->string));
740 m_valueList->next(); 740 m_valueList->next();
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 // Properties below are validated inside parseViewportProperty, because we 1488 // Properties below are validated inside parseViewportProperty, because we
1489 // check for parser state. We need to invalidate if someone adds them outsid e 1489 // check for parser state. We need to invalidate if someone adds them outsid e
1490 // a @viewport rule. 1490 // a @viewport rule.
1491 case CSSPropertyMaxZoom: 1491 case CSSPropertyMaxZoom:
1492 case CSSPropertyMinZoom: 1492 case CSSPropertyMinZoom:
1493 case CSSPropertyOrientation: 1493 case CSSPropertyOrientation:
1494 case CSSPropertyUserZoom: 1494 case CSSPropertyUserZoom:
1495 validPrimitive = false; 1495 validPrimitive = false;
1496 break; 1496 break;
1497 1497
1498 case CSSPropertyScrollSnapPointsX:
1499 case CSSPropertyScrollSnapPointsY:
1500 parsedValue = parseScrollSnapPoints();
1501 break;
1502 case CSSPropertyScrollSnapCoordinate:
1503 parsedValue = parseScrollSnapCoordinate();
1504 break;
1505 case CSSPropertyScrollSnapDestination:
1506 parsedValue = parsePosition();
1507 break;
1508
1498 default: 1509 default:
1499 return parseSVGValue(propId, important); 1510 return parseSVGValue(propId, important);
1500 } 1511 }
1501 1512
1502 if (validPrimitive) { 1513 if (validPrimitive) {
1503 parsedValue = parseValidPrimitive(id, value); 1514 parsedValue = parseValidPrimitive(id, value);
1504 m_valueList->next(); 1515 m_valueList->next();
1505 } 1516 }
1506 ASSERT(!m_parsedCalculation); 1517 ASSERT(!m_parsedCalculation);
1507 if (parsedValue) { 1518 if (parsedValue) {
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
2001 break; 2012 break;
2002 } 2013 }
2003 default: { 2014 default: {
2004 return false; 2015 return false;
2005 } 2016 }
2006 } 2017 }
2007 2018
2008 return true; 2019 return true;
2009 } 2020 }
2010 2021
2022 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseScrollSnapPoints()
2023 {
2024 CSSParserValue* value = m_valueList->current();
2025
2026 if (value->id == CSSValueNone) {
2027 m_valueList->next();
2028 return cssValuePool().createIdentifierValue(CSSValueNone);
2029 }
2030
2031 if (value->unit == CSSParserValue::Function && value->function->id == CSSVal ueRepeat) {
2032 // The spec defines the following grammar: repeat( <length>)
2033 CSSParserValueList* arguments = value->function->args.get();
2034 if (!arguments || arguments->size() != 1)
2035 return nullptr;
2036
2037 CSSParserValue* repeatValue = arguments->valueAt(0);
2038 if (!validUnit(repeatValue, FNonNeg | FLength | FPercent))
2039 return nullptr;
2040
2041 RefPtrWillBeRawPtr<CSSFunctionValue> result = CSSFunctionValue::create(C SSValueRepeat);
2042 result->append(parseValidPrimitive(repeatValue->id, repeatValue));
2043 m_valueList->next();
2044 return result.release();
2045 }
2046
2047 return nullptr;
2048 }
2049
2050 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseScrollSnapCoordinate()
2051 {
2052 if (m_valueList->current()->id == CSSValueNone) {
2053 m_valueList->next();
2054 return cssValuePool().createIdentifierValue(CSSValueNone);
2055 }
2056
2057 return parsePositionList(m_valueList);
2058 }
2059
2011 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parsePage() 2060 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parsePage()
2012 { 2061 {
2013 CSSParserValue* value = m_valueList->current(); 2062 CSSParserValue* value = m_valueList->current();
2014 m_valueList->next(); 2063 m_valueList->next();
2015 ASSERT(value); 2064 ASSERT(value);
2016 2065
2017 if (value->id == CSSValueAuto) 2066 if (value->id == CSSValueAuto)
2018 return cssValuePool().createIdentifierValue(value->id); 2067 return cssValuePool().createIdentifierValue(value->id);
2019 if (value->unit == CSSPrimitiveValue::CSS_IDENT) 2068 if (value->unit == CSSPrimitiveValue::CSS_IDENT)
2020 return createPrimitiveCustomIdentValue(value); 2069 return createPrimitiveCustomIdentValue(value);
(...skipping 3526 matching lines...) Expand 10 before | Expand all | Expand 10 after
5547 flexShrink = 1; 5596 flexShrink = 1;
5548 if (!flexBasis) 5597 if (!flexBasis)
5549 flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PERCENT AGE); 5598 flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PERCENT AGE);
5550 5599
5551 addProperty(CSSPropertyFlexGrow, cssValuePool().createValue(clampTo<float>(f lexGrow), CSSPrimitiveValue::CSS_NUMBER), important); 5600 addProperty(CSSPropertyFlexGrow, cssValuePool().createValue(clampTo<float>(f lexGrow), CSSPrimitiveValue::CSS_NUMBER), important);
5552 addProperty(CSSPropertyFlexShrink, cssValuePool().createValue(clampTo<float> (flexShrink), CSSPrimitiveValue::CSS_NUMBER), important); 5601 addProperty(CSSPropertyFlexShrink, cssValuePool().createValue(clampTo<float> (flexShrink), CSSPrimitiveValue::CSS_NUMBER), important);
5553 addProperty(CSSPropertyFlexBasis, flexBasis, important); 5602 addProperty(CSSPropertyFlexBasis, flexBasis, important);
5554 return true; 5603 return true;
5555 } 5604 }
5556 5605
5557 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseObjectPosition() 5606 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parsePosition()
5558 { 5607 {
5559 RefPtrWillBeRawPtr<CSSValue> xValue = nullptr; 5608 RefPtrWillBeRawPtr<CSSValue> xValue = nullptr;
5560 RefPtrWillBeRawPtr<CSSValue> yValue = nullptr; 5609 RefPtrWillBeRawPtr<CSSValue> yValue = nullptr;
5561 parseFillPosition(m_valueList, xValue, yValue); 5610 parseFillPosition(m_valueList, xValue, yValue);
5562 if (!xValue || !yValue) 5611 if (!xValue || !yValue)
5563 return nullptr; 5612 return nullptr;
5564 return createPrimitiveValuePair(toCSSPrimitiveValue(xValue.get()), toCSSPrim itiveValue(yValue.get()), Pair::KeepIdenticalValues); 5613 return createPrimitiveValuePair(toCSSPrimitiveValue(xValue.get()), toCSSPrim itiveValue(yValue.get()), Pair::KeepIdenticalValues);
5565 } 5614 }
5566 5615
5616 // Parses a list of comma separated positions. i.e., <position>#
5617 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parsePositionList(CSSPar serValueList* args)
5618 {
5619 RefPtrWillBeRawPtr<CSSValueList> positions = CSSValueList::createCommaSepara ted();
5620 for (CSSParserValue* argument = args->current(); argument; argument = args-> next()) {
Timothy Loh 2015/06/04 03:58:26 I think this won't do exactly what you want (I thi
majidvp 2015/06/04 22:41:40 Done.
5621 RefPtrWillBeRawPtr<CSSValue> xValue = nullptr;
5622 RefPtrWillBeRawPtr<CSSValue> yValue = nullptr;
5623 // parseFillPosition below should consume arguments until it reaches
5624 // a comma or end of the list
5625 parseFillPosition(args, xValue, yValue);
5626
5627 if (!xValue || !yValue)
5628 return nullptr;
5629
5630 RefPtrWillBeRawPtr<CSSValue> position = createPrimitiveValuePair(toCSSPr imitiveValue(xValue.get()), toCSSPrimitiveValue(yValue.get()), Pair::KeepIdentic alValues);
5631 positions->append(position);
5632 }
5633
5634 return positions.release();
5635 }
5636
5567 class BorderImageParseContext { 5637 class BorderImageParseContext {
5568 STACK_ALLOCATED(); 5638 STACK_ALLOCATED();
5569 public: 5639 public:
5570 BorderImageParseContext() 5640 BorderImageParseContext()
5571 : m_canAdvance(false) 5641 : m_canAdvance(false)
5572 , m_allowCommit(true) 5642 , m_allowCommit(true)
5573 , m_allowImage(true) 5643 , m_allowImage(true)
5574 , m_allowImageSlice(true) 5644 , m_allowImageSlice(true)
5575 , m_allowRepeat(true) 5645 , m_allowRepeat(true)
5576 , m_allowForwardSlashOperator(false) 5646 , m_allowForwardSlashOperator(false)
(...skipping 1571 matching lines...) Expand 10 before | Expand all | Expand 10 after
7148 RefPtrWillBeRawPtr<CSSFunctionValue> filterValue = parseBuiltinFilte rArguments(args, filterType); 7218 RefPtrWillBeRawPtr<CSSFunctionValue> filterValue = parseBuiltinFilte rArguments(args, filterType);
7149 if (!filterValue) 7219 if (!filterValue)
7150 return nullptr; 7220 return nullptr;
7151 7221
7152 list->append(filterValue); 7222 list->append(filterValue);
7153 } 7223 }
7154 } 7224 }
7155 7225
7156 return list.release(); 7226 return list.release();
7157 } 7227 }
7228
7158 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseTransformOrigin() 7229 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseTransformOrigin()
7159 { 7230 {
7160 CSSParserValue* value = m_valueList->current(); 7231 CSSParserValue* value = m_valueList->current();
7161 CSSValueID id = value->id; 7232 CSSValueID id = value->id;
7162 RefPtrWillBeRawPtr<CSSValue> xValue = nullptr; 7233 RefPtrWillBeRawPtr<CSSValue> xValue = nullptr;
7163 RefPtrWillBeRawPtr<CSSValue> yValue = nullptr; 7234 RefPtrWillBeRawPtr<CSSValue> yValue = nullptr;
7164 RefPtrWillBeRawPtr<CSSValue> zValue = nullptr; 7235 RefPtrWillBeRawPtr<CSSValue> zValue = nullptr;
7165 if (id == CSSValueLeft || id == CSSValueRight) { 7236 if (id == CSSValueLeft || id == CSSValueRight) {
7166 xValue = cssValuePool().createIdentifierValue(id); 7237 xValue = cssValuePool().createIdentifierValue(id);
7167 } else if (id == CSSValueTop || id == CSSValueBottom) { 7238 } else if (id == CSSValueTop || id == CSSValueBottom) {
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
8400 } 8471 }
8401 } 8472 }
8402 8473
8403 if (!list->length()) 8474 if (!list->length())
8404 return nullptr; 8475 return nullptr;
8405 8476
8406 return list.release(); 8477 return list.release();
8407 } 8478 }
8408 8479
8409 } // namespace blink 8480 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698