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

Side by Side Diff: Source/core/css/CSSParser.cpp

Issue 14408004: Fix incorrect evaluation of resolution media queries (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 7 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
« no previous file with comments | « Source/core/css/CSSParser.h ('k') | Source/core/css/CSSPrimitiveValue.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 case CSSPrimitiveValue::CSS_MS: 1598 case CSSPrimitiveValue::CSS_MS:
1599 case CSSPrimitiveValue::CSS_S: 1599 case CSSPrimitiveValue::CSS_S:
1600 b = (unitflags & FTime); 1600 b = (unitflags & FTime);
1601 break; 1601 break;
1602 case CSSPrimitiveValue::CSS_DEG: 1602 case CSSPrimitiveValue::CSS_DEG:
1603 case CSSPrimitiveValue::CSS_RAD: 1603 case CSSPrimitiveValue::CSS_RAD:
1604 case CSSPrimitiveValue::CSS_GRAD: 1604 case CSSPrimitiveValue::CSS_GRAD:
1605 case CSSPrimitiveValue::CSS_TURN: 1605 case CSSPrimitiveValue::CSS_TURN:
1606 b = (unitflags & FAngle); 1606 b = (unitflags & FAngle);
1607 break; 1607 break;
1608 #if ENABLE(RESOLUTION_MEDIA_QUERY)
1609 case CSSPrimitiveValue::CSS_DPPX: 1608 case CSSPrimitiveValue::CSS_DPPX:
1610 case CSSPrimitiveValue::CSS_DPI: 1609 case CSSPrimitiveValue::CSS_DPI:
1611 case CSSPrimitiveValue::CSS_DPCM: 1610 case CSSPrimitiveValue::CSS_DPCM:
1612 b = (unitflags & FResolution); 1611 b = (unitflags & FResolution);
1613 break; 1612 break;
1614 #endif
1615 case CSSPrimitiveValue::CSS_HZ: 1613 case CSSPrimitiveValue::CSS_HZ:
1616 case CSSPrimitiveValue::CSS_KHZ: 1614 case CSSPrimitiveValue::CSS_KHZ:
1617 case CSSPrimitiveValue::CSS_DIMENSION: 1615 case CSSPrimitiveValue::CSS_DIMENSION:
1618 default: 1616 default:
1619 break; 1617 break;
1620 } 1618 }
1621 if (b && unitflags & FNonNeg && value->fValue < 0) 1619 if (b && unitflags & FNonNeg && value->fValue < 0)
1622 b = false; 1620 b = false;
1623 return b; 1621 return b;
1624 } 1622 }
1625 1623
1626 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSP arserValue* value) 1624 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSP arserValue* value)
1627 { 1625 {
1628 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME) 1626 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME)
1629 return createPrimitiveVariableNameValue(value); 1627 return createPrimitiveVariableNameValue(value);
1630 1628
1631 if (m_parsedCalculation) { 1629 if (m_parsedCalculation) {
1632 ASSERT(isCalculation(value)); 1630 ASSERT(isCalculation(value));
1633 return CSSPrimitiveValue::create(m_parsedCalculation.release()); 1631 return CSSPrimitiveValue::create(m_parsedCalculation.release());
1634 } 1632 }
1635 1633
1636 #if ENABLE(RESOLUTION_MEDIA_QUERY)
1637 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPr imitiveValue::CSS_KHZ) 1634 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPr imitiveValue::CSS_KHZ)
1638 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrim itiveValue::CSS_CHS) 1635 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrim itiveValue::CSS_CHS)
1639 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimit iveValue::CSS_VMAX) 1636 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimit iveValue::CSS_VMAX)
1640 || (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrim itiveValue::CSS_DPCM)); 1637 || (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrim itiveValue::CSS_DPCM));
1641 #else
1642 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPr imitiveValue::CSS_KHZ)
1643 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrim itiveValue::CSS_CHS)
1644 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimit iveValue::CSS_VMAX));
1645 #endif
1646 return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveVal ue::UnitTypes>(value->unit)); 1638 return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveVal ue::UnitTypes>(value->unit));
1647 } 1639 }
1648 1640
1649 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveStringValue(CSSPa rserValue* value) 1641 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveStringValue(CSSPa rserValue* value)
1650 { 1642 {
1651 ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPri mitiveValue::CSS_IDENT); 1643 ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPri mitiveValue::CSS_IDENT);
1652 return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRI NG); 1644 return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRI NG);
1653 } 1645 }
1654 1646
1655 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveVariableNameValue (CSSParserValue* value) 1647 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveVariableNameValue (CSSParserValue* value)
(...skipping 27 matching lines...) Expand all
1683 if (identifier) 1675 if (identifier)
1684 return cssValuePool().createIdentifierValue(identifier); 1676 return cssValuePool().createIdentifierValue(identifier);
1685 if (value->unit == CSSPrimitiveValue::CSS_STRING) 1677 if (value->unit == CSSPrimitiveValue::CSS_STRING)
1686 return createPrimitiveStringValue(value); 1678 return createPrimitiveStringValue(value);
1687 if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimit iveValue::CSS_KHZ) 1679 if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimit iveValue::CSS_KHZ)
1688 return createPrimitiveNumericValue(value); 1680 return createPrimitiveNumericValue(value);
1689 if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiv eValue::CSS_CHS) 1681 if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiv eValue::CSS_CHS)
1690 return createPrimitiveNumericValue(value); 1682 return createPrimitiveNumericValue(value);
1691 if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveV alue::CSS_VMAX) 1683 if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveV alue::CSS_VMAX)
1692 return createPrimitiveNumericValue(value); 1684 return createPrimitiveNumericValue(value);
1693 #if ENABLE(RESOLUTION_MEDIA_QUERY)
1694 if (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiv eValue::CSS_DPCM) 1685 if (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiv eValue::CSS_DPCM)
1695 return createPrimitiveNumericValue(value); 1686 return createPrimitiveNumericValue(value);
1696 #endif
1697 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME) 1687 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME)
1698 return createPrimitiveVariableNameValue(value); 1688 return createPrimitiveVariableNameValue(value);
1699 if (value->unit >= CSSParserValue::Q_EMS) 1689 if (value->unit >= CSSParserValue::Q_EMS)
1700 return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPr imitiveValue::CSS_EMS); 1690 return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPr imitiveValue::CSS_EMS);
1701 if (isCalculation(value)) 1691 if (isCalculation(value))
1702 return CSSPrimitiveValue::create(m_parsedCalculation.release()); 1692 return CSSPrimitiveValue::create(m_parsedCalculation.release());
1703 1693
1704 return 0; 1694 return 0;
1705 } 1695 }
1706 1696
(...skipping 8190 matching lines...) Expand 10 before | Expand all | Expand 10 after
9897 case 'c': 9887 case 'c':
9898 if (length == 2 && isASCIIAlphaCaselessEqual(type[1], 'm')) 9888 if (length == 2 && isASCIIAlphaCaselessEqual(type[1], 'm'))
9899 m_token = CMS; 9889 m_token = CMS;
9900 else if (length == 2 && isASCIIAlphaCaselessEqual(type[1], 'h')) 9890 else if (length == 2 && isASCIIAlphaCaselessEqual(type[1], 'h'))
9901 m_token = CHS; 9891 m_token = CHS;
9902 return; 9892 return;
9903 9893
9904 case 'd': 9894 case 'd':
9905 if (length == 3 && isASCIIAlphaCaselessEqual(type[1], 'e') && isASCIIAlp haCaselessEqual(type[2], 'g')) 9895 if (length == 3 && isASCIIAlphaCaselessEqual(type[1], 'e') && isASCIIAlp haCaselessEqual(type[2], 'g'))
9906 m_token = DEGS; 9896 m_token = DEGS;
9907 #if ENABLE(RESOLUTION_MEDIA_QUERY)
9908 else if (length > 2 && isASCIIAlphaCaselessEqual(type[1], 'p')) { 9897 else if (length > 2 && isASCIIAlphaCaselessEqual(type[1], 'p')) {
9909 if (length == 4) { 9898 if (length == 4) {
9910 // There is a discussion about the name of this unit on www-styl e. 9899 // There is a discussion about the name of this unit on www-styl e.
9911 // Keep this compile time guard in place until that is resolved. 9900 // Keep this compile time guard in place until that is resolved.
9912 // http://lists.w3.org/Archives/Public/www-style/2012May/0915.ht ml 9901 // http://lists.w3.org/Archives/Public/www-style/2012May/0915.ht ml
9913 if (isASCIIAlphaCaselessEqual(type[2], 'p') && isASCIIAlphaCasel essEqual(type[3], 'x')) 9902 if (isASCIIAlphaCaselessEqual(type[2], 'p') && isASCIIAlphaCasel essEqual(type[3], 'x'))
9914 m_token = DPPX; 9903 m_token = DPPX;
9915 else if (isASCIIAlphaCaselessEqual(type[2], 'c') && isASCIIAlpha CaselessEqual(type[3], 'm')) 9904 else if (isASCIIAlphaCaselessEqual(type[2], 'c') && isASCIIAlpha CaselessEqual(type[3], 'm'))
9916 m_token = DPCM; 9905 m_token = DPCM;
9917 } else if (length == 3 && isASCIIAlphaCaselessEqual(type[2], 'i')) 9906 } else if (length == 3 && isASCIIAlphaCaselessEqual(type[2], 'i'))
9918 m_token = DPI; 9907 m_token = DPI;
9919 } 9908 }
9920 #endif
9921 return; 9909 return;
9922 9910
9923 case 'e': 9911 case 'e':
9924 if (length == 2) { 9912 if (length == 2) {
9925 if (isASCIIAlphaCaselessEqual(type[1], 'm')) 9913 if (isASCIIAlphaCaselessEqual(type[1], 'm'))
9926 m_token = EMS; 9914 m_token = EMS;
9927 else if (isASCIIAlphaCaselessEqual(type[1], 'x')) 9915 else if (isASCIIAlphaCaselessEqual(type[1], 'x'))
9928 m_token = EXS; 9916 m_token = EXS;
9929 } 9917 }
9930 return; 9918 return;
(...skipping 1746 matching lines...) Expand 10 before | Expand all | Expand 10 after
11677 { 11665 {
11678 // The tokenizer checks for the construct of an+b. 11666 // The tokenizer checks for the construct of an+b.
11679 // However, since the {ident} rule precedes the {nth} rule, some of those 11667 // However, since the {ident} rule precedes the {nth} rule, some of those
11680 // tokens are identified as string literal. Furthermore we need to accept 11668 // tokens are identified as string literal. Furthermore we need to accept
11681 // "odd" and "even" which does not match to an+b. 11669 // "odd" and "even" which does not match to an+b.
11682 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") 11670 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even")
11683 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); 11671 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n");
11684 } 11672 }
11685 11673
11686 } 11674 }
OLDNEW
« no previous file with comments | « Source/core/css/CSSParser.h ('k') | Source/core/css/CSSPrimitiveValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698