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

Side by Side Diff: Source/core/css/CSSPrimitiveValue.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
OLDNEW
1 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "core/rendering/style/RenderStyle.h" 42 #include "core/rendering/style/RenderStyle.h"
43 #include <wtf/ASCIICType.h> 43 #include <wtf/ASCIICType.h>
44 #include <wtf/DecimalNumber.h> 44 #include <wtf/DecimalNumber.h>
45 #include <wtf/StdLibExtras.h> 45 #include <wtf/StdLibExtras.h>
46 #include <wtf/text/StringBuffer.h> 46 #include <wtf/text/StringBuffer.h>
47 #include <wtf/text/StringBuilder.h> 47 #include <wtf/text/StringBuilder.h>
48 48
49 using namespace WTF; 49 using namespace WTF;
50 50
51 namespace WebCore { 51 namespace WebCore {
52 52
53 // Max/min values for CSS, needs to slightly smaller/larger than the true max/mi n values to allow for rounding without overflowing. 53 // Max/min values for CSS, needs to slightly smaller/larger than the true max/mi n values to allow for rounding without overflowing.
54 // Subtract two (rather than one) to allow for values to be converted to float a nd back without exceeding the LayoutUnit::max. 54 // Subtract two (rather than one) to allow for values to be converted to float a nd back without exceeding the LayoutUnit::max.
55 const int maxValueForCssLength = INT_MAX / kFixedPointDenominator - 2; 55 const int maxValueForCssLength = INT_MAX / kFixedPointDenominator - 2;
56 const int minValueForCssLength = INT_MIN / kFixedPointDenominator + 2; 56 const int minValueForCssLength = INT_MIN / kFixedPointDenominator + 2;
57 57
58 static inline bool isValidCSSUnitTypeForDoubleConversion(CSSPrimitiveValue::Unit Types unitType) 58 static inline bool isValidCSSUnitTypeForDoubleConversion(CSSPrimitiveValue::Unit Types unitType)
59 { 59 {
60 switch (unitType) { 60 switch (unitType) {
61 case CSSPrimitiveValue::CSS_CALC: 61 case CSSPrimitiveValue::CSS_CALC:
62 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER: 62 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER:
63 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_LENGTH: 63 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_LENGTH:
64 case CSSPrimitiveValue::CSS_CM: 64 case CSSPrimitiveValue::CSS_CM:
65 case CSSPrimitiveValue::CSS_DEG: 65 case CSSPrimitiveValue::CSS_DEG:
66 case CSSPrimitiveValue::CSS_DIMENSION: 66 case CSSPrimitiveValue::CSS_DIMENSION:
67 #if ENABLE(RESOLUTION_MEDIA_QUERY)
68 case CSSPrimitiveValue::CSS_DPPX: 67 case CSSPrimitiveValue::CSS_DPPX:
69 case CSSPrimitiveValue::CSS_DPI: 68 case CSSPrimitiveValue::CSS_DPI:
70 case CSSPrimitiveValue::CSS_DPCM: 69 case CSSPrimitiveValue::CSS_DPCM:
71 #endif
72 case CSSPrimitiveValue::CSS_EMS: 70 case CSSPrimitiveValue::CSS_EMS:
73 case CSSPrimitiveValue::CSS_EXS: 71 case CSSPrimitiveValue::CSS_EXS:
74 case CSSPrimitiveValue::CSS_GRAD: 72 case CSSPrimitiveValue::CSS_GRAD:
75 case CSSPrimitiveValue::CSS_HZ: 73 case CSSPrimitiveValue::CSS_HZ:
76 case CSSPrimitiveValue::CSS_IN: 74 case CSSPrimitiveValue::CSS_IN:
77 case CSSPrimitiveValue::CSS_KHZ: 75 case CSSPrimitiveValue::CSS_KHZ:
78 case CSSPrimitiveValue::CSS_MM: 76 case CSSPrimitiveValue::CSS_MM:
79 case CSSPrimitiveValue::CSS_MS: 77 case CSSPrimitiveValue::CSS_MS:
80 case CSSPrimitiveValue::CSS_NUMBER: 78 case CSSPrimitiveValue::CSS_NUMBER:
81 case CSSPrimitiveValue::CSS_PERCENTAGE: 79 case CSSPrimitiveValue::CSS_PERCENTAGE:
82 case CSSPrimitiveValue::CSS_PC: 80 case CSSPrimitiveValue::CSS_PC:
83 case CSSPrimitiveValue::CSS_PT: 81 case CSSPrimitiveValue::CSS_PT:
84 case CSSPrimitiveValue::CSS_PX: 82 case CSSPrimitiveValue::CSS_PX:
85 case CSSPrimitiveValue::CSS_RAD: 83 case CSSPrimitiveValue::CSS_RAD:
86 case CSSPrimitiveValue::CSS_REMS: 84 case CSSPrimitiveValue::CSS_REMS:
87 case CSSPrimitiveValue::CSS_CHS: 85 case CSSPrimitiveValue::CSS_CHS:
88 case CSSPrimitiveValue::CSS_S: 86 case CSSPrimitiveValue::CSS_S:
89 case CSSPrimitiveValue::CSS_TURN: 87 case CSSPrimitiveValue::CSS_TURN:
90 case CSSPrimitiveValue::CSS_VW: 88 case CSSPrimitiveValue::CSS_VW:
91 case CSSPrimitiveValue::CSS_VH: 89 case CSSPrimitiveValue::CSS_VH:
92 case CSSPrimitiveValue::CSS_VMIN: 90 case CSSPrimitiveValue::CSS_VMIN:
93 case CSSPrimitiveValue::CSS_VMAX: 91 case CSSPrimitiveValue::CSS_VMAX:
94 case CSSPrimitiveValue::CSS_FR: 92 case CSSPrimitiveValue::CSS_FR:
95 return true; 93 return true;
96 case CSSPrimitiveValue::CSS_ATTR: 94 case CSSPrimitiveValue::CSS_ATTR:
97 case CSSPrimitiveValue::CSS_COUNTER: 95 case CSSPrimitiveValue::CSS_COUNTER:
98 case CSSPrimitiveValue::CSS_COUNTER_NAME: 96 case CSSPrimitiveValue::CSS_COUNTER_NAME:
99 #if !ENABLE(RESOLUTION_MEDIA_QUERY)
100 case CSSPrimitiveValue::CSS_DPPX:
101 case CSSPrimitiveValue::CSS_DPI:
102 case CSSPrimitiveValue::CSS_DPCM:
103 #endif
104 case CSSPrimitiveValue::CSS_IDENT: 97 case CSSPrimitiveValue::CSS_IDENT:
105 case CSSPrimitiveValue::CSS_PAIR: 98 case CSSPrimitiveValue::CSS_PAIR:
106 case CSSPrimitiveValue::CSS_PARSER_HEXCOLOR: 99 case CSSPrimitiveValue::CSS_PARSER_HEXCOLOR:
107 case CSSPrimitiveValue::CSS_PARSER_IDENTIFIER: 100 case CSSPrimitiveValue::CSS_PARSER_IDENTIFIER:
108 case CSSPrimitiveValue::CSS_PARSER_INTEGER: 101 case CSSPrimitiveValue::CSS_PARSER_INTEGER:
109 case CSSPrimitiveValue::CSS_PARSER_OPERATOR: 102 case CSSPrimitiveValue::CSS_PARSER_OPERATOR:
110 case CSSPrimitiveValue::CSS_RECT: 103 case CSSPrimitiveValue::CSS_RECT:
111 case CSSPrimitiveValue::CSS_QUAD: 104 case CSSPrimitiveValue::CSS_QUAD:
112 case CSSPrimitiveValue::CSS_RGBCOLOR: 105 case CSSPrimitiveValue::CSS_RGBCOLOR:
113 case CSSPrimitiveValue::CSS_SHAPE: 106 case CSSPrimitiveValue::CSS_SHAPE:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 case CSSPrimitiveValue::CSS_TURN: 141 case CSSPrimitiveValue::CSS_TURN:
149 return CSSPrimitiveValue::UAngle; 142 return CSSPrimitiveValue::UAngle;
150 case CSSPrimitiveValue::CSS_HZ: 143 case CSSPrimitiveValue::CSS_HZ:
151 case CSSPrimitiveValue::CSS_KHZ: 144 case CSSPrimitiveValue::CSS_KHZ:
152 return CSSPrimitiveValue::UFrequency; 145 return CSSPrimitiveValue::UFrequency;
153 case CSSPrimitiveValue::CSS_VW: 146 case CSSPrimitiveValue::CSS_VW:
154 case CSSPrimitiveValue::CSS_VH: 147 case CSSPrimitiveValue::CSS_VH:
155 case CSSPrimitiveValue::CSS_VMIN: 148 case CSSPrimitiveValue::CSS_VMIN:
156 case CSSPrimitiveValue::CSS_VMAX: 149 case CSSPrimitiveValue::CSS_VMAX:
157 return CSSPrimitiveValue::UViewportPercentageLength; 150 return CSSPrimitiveValue::UViewportPercentageLength;
158 #if ENABLE(RESOLUTION_MEDIA_QUERY)
159 case CSSPrimitiveValue::CSS_DPPX: 151 case CSSPrimitiveValue::CSS_DPPX:
160 case CSSPrimitiveValue::CSS_DPI: 152 case CSSPrimitiveValue::CSS_DPI:
161 case CSSPrimitiveValue::CSS_DPCM: 153 case CSSPrimitiveValue::CSS_DPCM:
162 return CSSPrimitiveValue::UResolution; 154 return CSSPrimitiveValue::UResolution;
163 #endif
164 default: 155 default:
165 return CSSPrimitiveValue::UOther; 156 return CSSPrimitiveValue::UOther;
166 } 157 }
167 } 158 }
168 159
169 typedef HashMap<const CSSPrimitiveValue*, String> CSSTextCache; 160 typedef HashMap<const CSSPrimitiveValue*, String> CSSTextCache;
170 static CSSTextCache& cssTextCache() 161 static CSSTextCache& cssTextCache()
171 { 162 {
172 DEFINE_STATIC_LOCAL(CSSTextCache, cache, ()); 163 DEFINE_STATIC_LOCAL(CSSTextCache, cache, ());
173 return cache; 164 return cache;
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 case UPercent: 646 case UPercent:
656 return CSS_UNKNOWN; // Cannot convert between numbers and percent. 647 return CSS_UNKNOWN; // Cannot convert between numbers and percent.
657 case UTime: 648 case UTime:
658 return CSS_MS; 649 return CSS_MS;
659 case UAngle: 650 case UAngle:
660 return CSS_DEG; 651 return CSS_DEG;
661 case UFrequency: 652 case UFrequency:
662 return CSS_HZ; 653 return CSS_HZ;
663 case UViewportPercentageLength: 654 case UViewportPercentageLength:
664 return CSS_UNKNOWN; // Cannot convert between numbers and relative lengt hs. 655 return CSS_UNKNOWN; // Cannot convert between numbers and relative lengt hs.
665 #if ENABLE(RESOLUTION_MEDIA_QUERY)
666 case UResolution: 656 case UResolution:
667 return CSS_DPPX; 657 return CSS_DPPX;
668 #endif
669 default: 658 default:
670 return CSS_UNKNOWN; 659 return CSS_UNKNOWN;
671 } 660 }
672 } 661 }
673 662
674 bool CSSPrimitiveValue::getDoubleValueInternal(UnitTypes requestedUnitType, doub le* result) const 663 bool CSSPrimitiveValue::getDoubleValueInternal(UnitTypes requestedUnitType, doub le* result) const
675 { 664 {
676 if (!isValidCSSUnitTypeForDoubleConversion(static_cast<UnitTypes>(m_primitiv eUnitType)) || !isValidCSSUnitTypeForDoubleConversion(requestedUnitType)) 665 if (!isValidCSSUnitTypeForDoubleConversion(static_cast<UnitTypes>(m_primitiv eUnitType)) || !isValidCSSUnitTypeForDoubleConversion(requestedUnitType))
677 return false; 666 return false;
678 667
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 break; 863 break;
875 case CSS_CHS: 864 case CSS_CHS:
876 text = formatNumber(m_value.num, "ch"); 865 text = formatNumber(m_value.num, "ch");
877 break; 866 break;
878 case CSS_PX: 867 case CSS_PX:
879 text = formatNumber(m_value.num, "px"); 868 text = formatNumber(m_value.num, "px");
880 break; 869 break;
881 case CSS_CM: 870 case CSS_CM:
882 text = formatNumber(m_value.num, "cm"); 871 text = formatNumber(m_value.num, "cm");
883 break; 872 break;
884 #if ENABLE(RESOLUTION_MEDIA_QUERY)
885 case CSS_DPPX: 873 case CSS_DPPX:
886 text = formatNumber(m_value.num, "dppx"); 874 text = formatNumber(m_value.num, "dppx");
887 break; 875 break;
888 case CSS_DPI: 876 case CSS_DPI:
889 text = formatNumber(m_value.num, "dpi"); 877 text = formatNumber(m_value.num, "dpi");
890 break; 878 break;
891 case CSS_DPCM: 879 case CSS_DPCM:
892 text = formatNumber(m_value.num, "dpcm"); 880 text = formatNumber(m_value.num, "dpcm");
893 break; 881 break;
894 #endif
895 case CSS_MM: 882 case CSS_MM:
896 text = formatNumber(m_value.num, "mm"); 883 text = formatNumber(m_value.num, "mm");
897 break; 884 break;
898 case CSS_IN: 885 case CSS_IN:
899 text = formatNumber(m_value.num, "in"); 886 text = formatNumber(m_value.num, "in");
900 break; 887 break;
901 case CSS_PT: 888 case CSS_PT:
902 text = formatNumber(m_value.num, "pt"); 889 text = formatNumber(m_value.num, "pt");
903 break; 890 break;
904 case CSS_PC: 891 case CSS_PC:
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 case CSS_GRAD: 1154 case CSS_GRAD:
1168 case CSS_MS: 1155 case CSS_MS:
1169 case CSS_S: 1156 case CSS_S:
1170 case CSS_HZ: 1157 case CSS_HZ:
1171 case CSS_KHZ: 1158 case CSS_KHZ:
1172 case CSS_TURN: 1159 case CSS_TURN:
1173 case CSS_VW: 1160 case CSS_VW:
1174 case CSS_VH: 1161 case CSS_VH:
1175 case CSS_VMIN: 1162 case CSS_VMIN:
1176 case CSS_VMAX: 1163 case CSS_VMAX:
1177 #if ENABLE(RESOLUTION_MEDIA_QUERY)
1178 case CSS_DPPX: 1164 case CSS_DPPX:
1179 case CSS_DPI: 1165 case CSS_DPI:
1180 case CSS_DPCM: 1166 case CSS_DPCM:
1181 #endif
1182 result = CSSPrimitiveValue::create(m_value.num, static_cast<UnitTypes>(m _primitiveUnitType)); 1167 result = CSSPrimitiveValue::create(m_value.num, static_cast<UnitTypes>(m _primitiveUnitType));
1183 break; 1168 break;
1184 case CSS_IDENT: 1169 case CSS_IDENT:
1185 result = CSSPrimitiveValue::createIdentifier(m_value.ident); 1170 result = CSSPrimitiveValue::createIdentifier(m_value.ident);
1186 break; 1171 break;
1187 case CSS_RGBCOLOR: 1172 case CSS_RGBCOLOR:
1188 result = CSSPrimitiveValue::createColor(m_value.rgbcolor); 1173 result = CSSPrimitiveValue::createColor(m_value.rgbcolor);
1189 break; 1174 break;
1190 case CSS_DIMENSION: 1175 case CSS_DIMENSION:
1191 case CSS_UNKNOWN: 1176 case CSS_UNKNOWN:
(...skipping 18 matching lines...) Expand all
1210 case CSS_UNKNOWN: 1195 case CSS_UNKNOWN:
1211 return false; 1196 return false;
1212 case CSS_NUMBER: 1197 case CSS_NUMBER:
1213 case CSS_PARSER_INTEGER: 1198 case CSS_PARSER_INTEGER:
1214 case CSS_PERCENTAGE: 1199 case CSS_PERCENTAGE:
1215 case CSS_EMS: 1200 case CSS_EMS:
1216 case CSS_EXS: 1201 case CSS_EXS:
1217 case CSS_REMS: 1202 case CSS_REMS:
1218 case CSS_PX: 1203 case CSS_PX:
1219 case CSS_CM: 1204 case CSS_CM:
1220 #if ENABLE(RESOLUTION_MEDIA_QUERY)
1221 case CSS_DPPX: 1205 case CSS_DPPX:
1222 case CSS_DPI: 1206 case CSS_DPI:
1223 case CSS_DPCM: 1207 case CSS_DPCM:
1224 #endif
1225 case CSS_MM: 1208 case CSS_MM:
1226 case CSS_IN: 1209 case CSS_IN:
1227 case CSS_PT: 1210 case CSS_PT:
1228 case CSS_PC: 1211 case CSS_PC:
1229 case CSS_DEG: 1212 case CSS_DEG:
1230 case CSS_RAD: 1213 case CSS_RAD:
1231 case CSS_GRAD: 1214 case CSS_GRAD:
1232 case CSS_MS: 1215 case CSS_MS:
1233 case CSS_S: 1216 case CSS_S:
1234 case CSS_HZ: 1217 case CSS_HZ:
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 break; 1284 break;
1302 case CSS_CALC: 1285 case CSS_CALC:
1303 info.addMember(m_value.calc, "value.calc"); 1286 info.addMember(m_value.calc, "value.calc");
1304 break; 1287 break;
1305 default: 1288 default:
1306 break; 1289 break;
1307 } 1290 }
1308 } 1291 }
1309 1292
1310 } // namespace WebCore 1293 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698