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

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 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 case CSSPrimitiveValue::CSS_MS: 1605 case CSSPrimitiveValue::CSS_MS:
1606 case CSSPrimitiveValue::CSS_S: 1606 case CSSPrimitiveValue::CSS_S:
1607 b = (unitflags & FTime); 1607 b = (unitflags & FTime);
1608 break; 1608 break;
1609 case CSSPrimitiveValue::CSS_DEG: 1609 case CSSPrimitiveValue::CSS_DEG:
1610 case CSSPrimitiveValue::CSS_RAD: 1610 case CSSPrimitiveValue::CSS_RAD:
1611 case CSSPrimitiveValue::CSS_GRAD: 1611 case CSSPrimitiveValue::CSS_GRAD:
1612 case CSSPrimitiveValue::CSS_TURN: 1612 case CSSPrimitiveValue::CSS_TURN:
1613 b = (unitflags & FAngle); 1613 b = (unitflags & FAngle);
1614 break; 1614 break;
1615 #if ENABLE(RESOLUTION_MEDIA_QUERY)
1616 case CSSPrimitiveValue::CSS_DPPX: 1615 case CSSPrimitiveValue::CSS_DPPX:
1617 case CSSPrimitiveValue::CSS_DPI: 1616 case CSSPrimitiveValue::CSS_DPI:
1618 case CSSPrimitiveValue::CSS_DPCM: 1617 case CSSPrimitiveValue::CSS_DPCM:
1619 b = (unitflags & FResolution); 1618 b = (unitflags & FResolution);
1620 break; 1619 break;
1621 #endif
1622 case CSSPrimitiveValue::CSS_HZ: 1620 case CSSPrimitiveValue::CSS_HZ:
1623 case CSSPrimitiveValue::CSS_KHZ: 1621 case CSSPrimitiveValue::CSS_KHZ:
1624 case CSSPrimitiveValue::CSS_DIMENSION: 1622 case CSSPrimitiveValue::CSS_DIMENSION:
1625 default: 1623 default:
1626 break; 1624 break;
1627 } 1625 }
1628 if (b && unitflags & FNonNeg && value->fValue < 0) 1626 if (b && unitflags & FNonNeg && value->fValue < 0)
1629 b = false; 1627 b = false;
1630 return b; 1628 return b;
1631 } 1629 }
1632 1630
1633 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSP arserValue* value) 1631 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSP arserValue* value)
1634 { 1632 {
1635 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME) 1633 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME)
1636 return createPrimitiveVariableNameValue(value); 1634 return createPrimitiveVariableNameValue(value);
1637 1635
1638 if (m_parsedCalculation) { 1636 if (m_parsedCalculation) {
1639 ASSERT(isCalculation(value)); 1637 ASSERT(isCalculation(value));
1640 return CSSPrimitiveValue::create(m_parsedCalculation.release()); 1638 return CSSPrimitiveValue::create(m_parsedCalculation.release());
1641 } 1639 }
1642 1640
1643 #if ENABLE(RESOLUTION_MEDIA_QUERY)
1644 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPr imitiveValue::CSS_KHZ) 1641 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPr imitiveValue::CSS_KHZ)
1645 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrim itiveValue::CSS_CHS) 1642 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrim itiveValue::CSS_CHS)
1646 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimit iveValue::CSS_VMAX) 1643 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimit iveValue::CSS_VMAX)
1647 || (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrim itiveValue::CSS_DPCM)); 1644 || (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrim itiveValue::CSS_DPCM));
1648 #else
1649 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPr imitiveValue::CSS_KHZ)
1650 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrim itiveValue::CSS_CHS)
1651 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimit iveValue::CSS_VMAX));
1652 #endif
1653 return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveVal ue::UnitTypes>(value->unit)); 1645 return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveVal ue::UnitTypes>(value->unit));
1654 } 1646 }
1655 1647
1656 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveStringValue(CSSPa rserValue* value) 1648 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveStringValue(CSSPa rserValue* value)
1657 { 1649 {
1658 ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPri mitiveValue::CSS_IDENT); 1650 ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPri mitiveValue::CSS_IDENT);
1659 return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRI NG); 1651 return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRI NG);
1660 } 1652 }
1661 1653
1662 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveVariableNameValue (CSSParserValue* value) 1654 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveVariableNameValue (CSSParserValue* value)
(...skipping 27 matching lines...) Expand all
1690 if (identifier) 1682 if (identifier)
1691 return cssValuePool().createIdentifierValue(identifier); 1683 return cssValuePool().createIdentifierValue(identifier);
1692 if (value->unit == CSSPrimitiveValue::CSS_STRING) 1684 if (value->unit == CSSPrimitiveValue::CSS_STRING)
1693 return createPrimitiveStringValue(value); 1685 return createPrimitiveStringValue(value);
1694 if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimit iveValue::CSS_KHZ) 1686 if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimit iveValue::CSS_KHZ)
1695 return createPrimitiveNumericValue(value); 1687 return createPrimitiveNumericValue(value);
1696 if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiv eValue::CSS_CHS) 1688 if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiv eValue::CSS_CHS)
1697 return createPrimitiveNumericValue(value); 1689 return createPrimitiveNumericValue(value);
1698 if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveV alue::CSS_VMAX) 1690 if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveV alue::CSS_VMAX)
1699 return createPrimitiveNumericValue(value); 1691 return createPrimitiveNumericValue(value);
1700 #if ENABLE(RESOLUTION_MEDIA_QUERY)
1701 if (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiv eValue::CSS_DPCM) 1692 if (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiv eValue::CSS_DPCM)
1702 return createPrimitiveNumericValue(value); 1693 return createPrimitiveNumericValue(value);
1703 #endif
1704 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME) 1694 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME)
1705 return createPrimitiveVariableNameValue(value); 1695 return createPrimitiveVariableNameValue(value);
1706 if (value->unit >= CSSParserValue::Q_EMS) 1696 if (value->unit >= CSSParserValue::Q_EMS)
1707 return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPr imitiveValue::CSS_EMS); 1697 return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPr imitiveValue::CSS_EMS);
1708 if (isCalculation(value)) 1698 if (isCalculation(value))
1709 return CSSPrimitiveValue::create(m_parsedCalculation.release()); 1699 return CSSPrimitiveValue::create(m_parsedCalculation.release());
1710 1700
1711 return 0; 1701 return 0;
1712 } 1702 }
1713 1703
(...skipping 8193 matching lines...) Expand 10 before | Expand all | Expand 10 after
9907 case 'c': 9897 case 'c':
9908 if (length == 2 && isASCIIAlphaCaselessEqual(type[1], 'm')) 9898 if (length == 2 && isASCIIAlphaCaselessEqual(type[1], 'm'))
9909 m_token = CMS; 9899 m_token = CMS;
9910 else if (length == 2 && isASCIIAlphaCaselessEqual(type[1], 'h')) 9900 else if (length == 2 && isASCIIAlphaCaselessEqual(type[1], 'h'))
9911 m_token = CHS; 9901 m_token = CHS;
9912 return; 9902 return;
9913 9903
9914 case 'd': 9904 case 'd':
9915 if (length == 3 && isASCIIAlphaCaselessEqual(type[1], 'e') && isASCIIAlp haCaselessEqual(type[2], 'g')) 9905 if (length == 3 && isASCIIAlphaCaselessEqual(type[1], 'e') && isASCIIAlp haCaselessEqual(type[2], 'g'))
9916 m_token = DEGS; 9906 m_token = DEGS;
9917 #if ENABLE(RESOLUTION_MEDIA_QUERY)
9918 else if (length > 2 && isASCIIAlphaCaselessEqual(type[1], 'p')) { 9907 else if (length > 2 && isASCIIAlphaCaselessEqual(type[1], 'p')) {
9919 if (length == 4) { 9908 if (length == 4) {
9920 // There is a discussion about the name of this unit on www-styl e. 9909 // There is a discussion about the name of this unit on www-styl e.
9921 // Keep this compile time guard in place until that is resolved. 9910 // Keep this compile time guard in place until that is resolved.
johnme 2013/05/07 15:46:29 Hmm. Tab, can you comment on the current status of
9922 // http://lists.w3.org/Archives/Public/www-style/2012May/0915.ht ml 9911 // http://lists.w3.org/Archives/Public/www-style/2012May/0915.ht ml
9923 if (isASCIIAlphaCaselessEqual(type[2], 'p') && isASCIIAlphaCasel essEqual(type[3], 'x')) 9912 if (isASCIIAlphaCaselessEqual(type[2], 'p') && isASCIIAlphaCasel essEqual(type[3], 'x'))
9924 m_token = DPPX; 9913 m_token = DPPX;
9925 else if (isASCIIAlphaCaselessEqual(type[2], 'c') && isASCIIAlpha CaselessEqual(type[3], 'm')) 9914 else if (isASCIIAlphaCaselessEqual(type[2], 'c') && isASCIIAlpha CaselessEqual(type[3], 'm'))
9926 m_token = DPCM; 9915 m_token = DPCM;
9927 } else if (length == 3 && isASCIIAlphaCaselessEqual(type[2], 'i')) 9916 } else if (length == 3 && isASCIIAlphaCaselessEqual(type[2], 'i'))
9928 m_token = DPI; 9917 m_token = DPI;
9929 } 9918 }
9930 #endif
9931 return; 9919 return;
9932 9920
9933 case 'e': 9921 case 'e':
9934 if (length == 2) { 9922 if (length == 2) {
9935 if (isASCIIAlphaCaselessEqual(type[1], 'm')) 9923 if (isASCIIAlphaCaselessEqual(type[1], 'm'))
9936 m_token = EMS; 9924 m_token = EMS;
9937 else if (isASCIIAlphaCaselessEqual(type[1], 'x')) 9925 else if (isASCIIAlphaCaselessEqual(type[1], 'x'))
9938 m_token = EXS; 9926 m_token = EXS;
9939 } 9927 }
9940 return; 9928 return;
(...skipping 1746 matching lines...) Expand 10 before | Expand all | Expand 10 after
11687 { 11675 {
11688 // The tokenizer checks for the construct of an+b. 11676 // The tokenizer checks for the construct of an+b.
11689 // However, since the {ident} rule precedes the {nth} rule, some of those 11677 // However, since the {ident} rule precedes the {nth} rule, some of those
11690 // tokens are identified as string literal. Furthermore we need to accept 11678 // tokens are identified as string literal. Furthermore we need to accept
11691 // "odd" and "even" which does not match to an+b. 11679 // "odd" and "even" which does not match to an+b.
11692 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") 11680 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even")
11693 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); 11681 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n");
11694 } 11682 }
11695 11683
11696 } 11684 }
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