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

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

Issue 1348363004: Add consumeInteger/consumeLength (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix build 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 b = (unitflags & FFrequency); 166 b = (unitflags & FFrequency);
167 break; 167 break;
168 case CalcOther: 168 case CalcOther:
169 break; 169 break;
170 } 170 }
171 if (!b || releaseCalc == ReleaseParsedCalcValue) 171 if (!b || releaseCalc == ReleaseParsedCalcValue)
172 m_parsedCalculation.release(); 172 m_parsedCalculation.release();
173 return b; 173 return b;
174 } 174 }
175 175
176 inline bool CSSPropertyParser::shouldAcceptUnitLessValues(CSSParserValue* value, Units unitflags, CSSParserMode cssParserMode)
177 {
178 // Quirks mode for certain properties and presentation attributes accept uni t-less values for certain units.
179 return (unitflags & (FLength | FAngle))
180 && (!value->fValue // 0 can always be unitless.
181 || isUnitLessLengthParsingEnabledForMode(cssParserMode) // HTML and SVG attribute values can always be unitless.
182 || (cssParserMode == HTMLQuirksMode && (unitflags & FUnitlessQuirk)) );
183 }
184
185 inline bool isCalculation(CSSParserValue* value) 176 inline bool isCalculation(CSSParserValue* value)
186 { 177 {
187 return value->m_unit == CSSParserValue::CalcFunction; 178 return value->m_unit == CSSParserValue::CalcFunction;
188 } 179 }
189 180
190 bool CSSPropertyParser::validUnit(CSSParserValue* value, Units unitflags, CSSPar serMode cssParserMode, ReleaseParsedCalcValueCondition releaseCalc) 181 bool CSSPropertyParser::validUnit(CSSParserValue* value, Units unitflags, CSSPar serMode cssParserMode, ReleaseParsedCalcValueCondition releaseCalc)
191 { 182 {
192 if (isCalculation(value)) 183 if (isCalculation(value))
193 return validCalculationUnit(value, unitflags, releaseCalc); 184 return validCalculationUnit(value, unitflags, releaseCalc);
194 185
195 if (unitflags & FNonNeg && value->fValue < 0) 186 if (unitflags & FNonNeg && value->fValue < 0)
196 return false; 187 return false;
197 switch (value->unit()) { 188 switch (value->unit()) {
198 case CSSPrimitiveValue::UnitType::Number: 189 case CSSPrimitiveValue::UnitType::Number:
199 if (unitflags & FNumber) 190 if (unitflags & FNumber)
200 return true; 191 return true;
201 if (shouldAcceptUnitLessValues(value, unitflags, cssParserMode)) { 192 if (shouldAcceptUnitLessValues(value->fValue, unitflags, cssParserMode)) {
202 value->setUnit((unitflags & FLength) ? CSSPrimitiveValue::UnitType:: Pixels : CSSPrimitiveValue::UnitType::Degrees); 193 value->setUnit((unitflags & FLength) ? CSSPrimitiveValue::UnitType:: Pixels : CSSPrimitiveValue::UnitType::Degrees);
203 return true; 194 return true;
204 } 195 }
205 if ((unitflags & FInteger) && value->isInt) 196 if ((unitflags & FInteger) && value->isInt)
206 return true; 197 return true;
207 if ((unitflags & FPositiveInteger) && value->isInt && value->fValue > 0) 198 if ((unitflags & FPositiveInteger) && value->isInt && value->fValue > 0)
208 return true; 199 return true;
209 return false; 200 return false;
210 case CSSPrimitiveValue::UnitType::Percentage: 201 case CSSPrimitiveValue::UnitType::Percentage:
211 return unitflags & FPercent; 202 return unitflags & FPercent;
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 case CSSPropertyWebkitBorderEndWidth: 681 case CSSPropertyWebkitBorderEndWidth:
691 case CSSPropertyWebkitBorderBeforeWidth: 682 case CSSPropertyWebkitBorderBeforeWidth:
692 case CSSPropertyWebkitBorderAfterWidth: 683 case CSSPropertyWebkitBorderAfterWidth:
693 case CSSPropertyWebkitColumnRuleWidth: 684 case CSSPropertyWebkitColumnRuleWidth:
694 if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick) 685 if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
695 validPrimitive = true; 686 validPrimitive = true;
696 else 687 else
697 validPrimitive = validUnit(value, FLength | FNonNeg | unitless); 688 validPrimitive = validUnit(value, FLength | FNonNeg | unitless);
698 break; 689 break;
699 690
700 case CSSPropertyLetterSpacing: // normal | <length> | inherit
701 case CSSPropertyWordSpacing: // normal | <length> | inherit
702 if (id == CSSValueNormal)
703 validPrimitive = true;
704 else
705 validPrimitive = validUnit(value, FLength | FUnitlessQuirk);
706 break;
707
708 case CSSPropertyTextIndent: 691 case CSSPropertyTextIndent:
709 parsedValue = parseTextIndent(); 692 parsedValue = parseTextIndent();
710 break; 693 break;
711 694
712 case CSSPropertyPaddingTop: //// <padding-width> | inherit 695 case CSSPropertyPaddingTop: //// <padding-width> | inherit
713 case CSSPropertyPaddingRight: // Which is defined as 696 case CSSPropertyPaddingRight: // Which is defined as
714 case CSSPropertyPaddingBottom: // <length> | <percentage> 697 case CSSPropertyPaddingBottom: // <length> | <percentage>
715 case CSSPropertyPaddingLeft: //// 698 case CSSPropertyPaddingLeft: ////
716 unitless = FUnitlessQuirk; 699 unitless = FUnitlessQuirk;
717 // fall through 700 // fall through
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 break; 1418 break;
1436 1419
1437 // These were not accepted by the new path above so we should return false. 1420 // These were not accepted by the new path above so we should return false.
1438 case CSSPropertyWebkitMarginCollapse: 1421 case CSSPropertyWebkitMarginCollapse:
1439 case CSSPropertyWillChange: 1422 case CSSPropertyWillChange:
1440 case CSSPropertyPage: 1423 case CSSPropertyPage:
1441 case CSSPropertyOverflow: 1424 case CSSPropertyOverflow:
1442 case CSSPropertyQuotes: 1425 case CSSPropertyQuotes:
1443 case CSSPropertyWebkitHighlight: 1426 case CSSPropertyWebkitHighlight:
1444 case CSSPropertyFontVariantLigatures: 1427 case CSSPropertyFontVariantLigatures:
1428 case CSSPropertyLetterSpacing:
1429 case CSSPropertyWordSpacing:
1430
1445 validPrimitive = false; 1431 validPrimitive = false;
1446 break; 1432 break;
1447 1433
1448 case CSSPropertyScrollSnapPointsX: 1434 case CSSPropertyScrollSnapPointsX:
1449 case CSSPropertyScrollSnapPointsY: 1435 case CSSPropertyScrollSnapPointsY:
1450 parsedValue = parseScrollSnapPoints(); 1436 parsedValue = parseScrollSnapPoints();
1451 break; 1437 break;
1452 case CSSPropertyScrollSnapCoordinate: 1438 case CSSPropertyScrollSnapCoordinate:
1453 parsedValue = parseScrollSnapCoordinate(); 1439 parsedValue = parseScrollSnapCoordinate();
1454 break; 1440 break;
(...skipping 6279 matching lines...) Expand 10 before | Expand all | Expand 10 after
7734 } 7720 }
7735 } 7721 }
7736 7722
7737 if (!list->length()) 7723 if (!list->length())
7738 return nullptr; 7724 return nullptr;
7739 7725
7740 return list.release(); 7726 return list.release();
7741 } 7727 }
7742 7728
7743 } // namespace blink 7729 } // 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