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

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

Issue 1398553002: Move counter-increment/counter-reset handling into CSSPropertyParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/css/parser/CSSPropertyParser.h" 6 #include "core/css/parser/CSSPropertyParser.h"
7 7
8 #include "core/StylePropertyShorthand.h" 8 #include "core/StylePropertyShorthand.h"
9 #include "core/css/CSSCalculationValue.h" 9 #include "core/css/CSSCalculationValue.h"
10 #include "core/css/CSSCustomIdentValue.h" 10 #include "core/css/CSSCustomIdentValue.h"
11 #include "core/css/CSSFontFaceSrcValue.h" 11 #include "core/css/CSSFontFaceSrcValue.h"
12 #include "core/css/CSSFontFeatureValue.h" 12 #include "core/css/CSSFontFeatureValue.h"
13 #include "core/css/CSSPrimitiveValueMappings.h" 13 #include "core/css/CSSPrimitiveValueMappings.h"
14 #include "core/css/CSSStringValue.h" 14 #include "core/css/CSSStringValue.h"
15 #include "core/css/CSSURIValue.h" 15 #include "core/css/CSSURIValue.h"
16 #include "core/css/CSSUnicodeRangeValue.h" 16 #include "core/css/CSSUnicodeRangeValue.h"
17 #include "core/css/CSSValuePair.h"
17 #include "core/css/CSSValuePool.h" 18 #include "core/css/CSSValuePool.h"
18 #include "core/css/FontFace.h" 19 #include "core/css/FontFace.h"
19 #include "core/css/parser/CSSParserFastPaths.h" 20 #include "core/css/parser/CSSParserFastPaths.h"
20 #include "core/css/parser/CSSParserValues.h" 21 #include "core/css/parser/CSSParserValues.h"
21 #include "core/frame/UseCounter.h" 22 #include "core/frame/UseCounter.h"
22 #include "core/layout/LayoutTheme.h" 23 #include "core/layout/LayoutTheme.h"
23 #include "wtf/text/StringBuilder.h" 24 #include "wtf/text/StringBuilder.h"
24 25
25 namespace blink { 26 namespace blink {
26 27
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 CSSPrimitiveValue::UnitType unitType = m_calcValue->isInt() ? CSSPrimiti veValue::UnitType::Integer : CSSPrimitiveValue::UnitType::Number; 162 CSSPrimitiveValue::UnitType unitType = m_calcValue->isInt() ? CSSPrimiti veValue::UnitType::Integer : CSSPrimitiveValue::UnitType::Number;
162 return cssValuePool().createValue(m_calcValue->doubleValue(), unitType); 163 return cssValuePool().createValue(m_calcValue->doubleValue(), unitType);
163 } 164 }
164 165
165 private: 166 private:
166 CSSParserTokenRange& m_sourceRange; 167 CSSParserTokenRange& m_sourceRange;
167 CSSParserTokenRange m_range; 168 CSSParserTokenRange m_range;
168 RefPtrWillBeMember<CSSCalcValue> m_calcValue; 169 RefPtrWillBeMember<CSSCalcValue> m_calcValue;
169 }; 170 };
170 171
171 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeInteger(CSSParserTokenRa nge& range, CSSParserMode cssParserMode, double minimumValue = std::numeric_limi ts<int>::min()) 172 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeInteger(CSSParserTokenRa nge& range, CSSParserMode cssParserMode, double minimumValue = std::numeric_limi ts<int>::lowest())
172 { 173 {
173 const CSSParserToken& token = range.peek(); 174 const CSSParserToken& token = range.peek();
174 if (token.type() == NumberToken) { 175 if (token.type() == NumberToken) {
175 if (token.numericValueType() == NumberValueType || token.numericValue() < minimumValue) 176 if (token.numericValueType() == NumberValueType || token.numericValue() < minimumValue)
176 return nullptr; 177 return nullptr;
177 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), token.unitType()); 178 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), token.unitType());
178 } 179 }
179 CalcParser calcParser(range); 180 CalcParser calcParser(range);
180 if (const CSSCalcValue* calculation = calcParser.value()) { 181 if (const CSSCalcValue* calculation = calcParser.value()) {
181 if (calculation->category() != CalcNumber || !calculation->isInt()) 182 if (calculation->category() != CalcNumber || !calculation->isInt())
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 for (unsigned i = 0; i < 3; i++) { // 3 dimensions of rotation 622 for (unsigned i = 0; i < 3; i++) { // 3 dimensions of rotation
622 RefPtrWillBeRawPtr<CSSValue> dimension = consumeNumber(range, ValueRange All); 623 RefPtrWillBeRawPtr<CSSValue> dimension = consumeNumber(range, ValueRange All);
623 if (!dimension) 624 if (!dimension)
624 return nullptr; 625 return nullptr;
625 list->append(dimension.release()); 626 list->append(dimension.release());
626 } 627 }
627 628
628 return list.release(); 629 return list.release();
629 } 630 }
630 631
632 static PassRefPtrWillBeRawPtr<CSSValue> consumeCounter(CSSParserTokenRange& rang e, CSSParserMode cssParserMode, int defaultValue)
633 {
634 if (range.peek().id() == CSSValueNone)
635 return consumeIdent(range);
636
637 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated() ;
Timothy Loh 2015/10/08 23:13:56 TODO to create a space-separated value list here :
638 do {
639 if (range.peek().type() != IdentToken)
Timothy Loh 2015/10/08 23:13:56 btw I'd prefer this as follows RefPtr..<CSSCustom
640 return nullptr;
641 RefPtrWillBeRawPtr<CSSCustomIdentValue> counterName = consumeCustomIdent (range);
642 int i = defaultValue;
643 if (RefPtrWillBeRawPtr<CSSPrimitiveValue> counterValue = consumeInteger( range, cssParserMode, std::numeric_limits<double>::lowest()))
Timothy Loh 2015/10/08 23:13:56 How about (don't need to pass in the limit if it's
rwlbuis 2015/10/09 02:31:12 Sorry, should have mentioned the s/min/lowest chan
644 i = clampTo<int>(counterValue->getDoubleValue());
645 list->append(CSSValuePair::create(counterName.release(),
646 cssValuePool().createValue(i, CSSPrimitiveValue::UnitType::Number),
647 CSSValuePair::DropIdenticalValues));
648 } while (!range.atEnd());
649 return list.release();
650 }
651
631 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) 652 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId)
632 { 653 {
633 m_range.consumeWhitespace(); 654 m_range.consumeWhitespace();
634 switch (propId) { 655 switch (propId) {
635 case CSSPropertyWillChange: 656 case CSSPropertyWillChange:
636 return consumeWillChange(m_range); 657 return consumeWillChange(m_range);
637 case CSSPropertyPage: 658 case CSSPropertyPage:
638 return consumePage(m_range); 659 return consumePage(m_range);
639 case CSSPropertyQuotes: 660 case CSSPropertyQuotes:
640 return consumeQuotes(m_range); 661 return consumeQuotes(m_range);
(...skipping 16 matching lines...) Expand all
657 return consumeTabSize(m_range, m_context.mode()); 678 return consumeTabSize(m_range, m_context.mode());
658 case CSSPropertyFontSize: 679 case CSSPropertyFontSize:
659 return consumeFontSize(m_range, m_context.mode(), UnitlessQuirk::Allow); 680 return consumeFontSize(m_range, m_context.mode(), UnitlessQuirk::Allow);
660 case CSSPropertyLineHeight: 681 case CSSPropertyLineHeight:
661 return consumeLineHeight(m_range, m_context.mode()); 682 return consumeLineHeight(m_range, m_context.mode());
662 case CSSPropertyRotate: 683 case CSSPropertyRotate:
663 return consumeRotation(m_range); 684 return consumeRotation(m_range);
664 case CSSPropertyWebkitBorderHorizontalSpacing: 685 case CSSPropertyWebkitBorderHorizontalSpacing:
665 case CSSPropertyWebkitBorderVerticalSpacing: 686 case CSSPropertyWebkitBorderVerticalSpacing:
666 return consumeLength(m_range, m_context.mode(), ValueRangeNonNegative); 687 return consumeLength(m_range, m_context.mode(), ValueRangeNonNegative);
688 case CSSPropertyCounterIncrement:
689 case CSSPropertyCounterReset:
690 return consumeCounter(m_range, m_context.mode(), propId == CSSPropertyCo unterIncrement ? 1 : 0);
667 default: 691 default:
668 return nullptr; 692 return nullptr;
669 } 693 }
670 } 694 }
671 695
672 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) 696 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range)
673 { 697 {
674 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); 698 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated ();
675 699
676 do { 700 do {
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 } 985 }
962 case CSSPropertyBorderSpacing: 986 case CSSPropertyBorderSpacing:
963 return consumeBorderSpacing(important); 987 return consumeBorderSpacing(important);
964 default: 988 default:
965 m_currentShorthand = oldShorthand; 989 m_currentShorthand = oldShorthand;
966 return false; 990 return false;
967 } 991 }
968 } 992 }
969 993
970 } // namespace blink 994 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698