OLD | NEW |
---|---|
1 /* | 1 /* |
2 * CSS Media Query | 2 * CSS Media Query |
3 * | 3 * |
4 * Copyright (C) 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>. | 4 * Copyright (C) 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>. |
5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
6 * Copyright (C) 2013 Apple Inc. All rights reserved. | 6 * Copyright (C) 2013 Apple Inc. All rights reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
10 * are met: | 10 * are met: |
(...skipping 14 matching lines...) Expand all Loading... | |
25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 */ | 28 */ |
29 | 29 |
30 #include "config.h" | 30 #include "config.h" |
31 #include "core/css/MediaQueryExp.h" | 31 #include "core/css/MediaQueryExp.h" |
32 | 32 |
33 #include "CSSValueKeywords.h" | 33 #include "CSSValueKeywords.h" |
34 #include "core/css/CSSAspectRatioValue.h" | 34 #include "core/css/CSSAspectRatioValue.h" |
35 #include "core/css/parser/BisonCSSParser.h" | 35 #include "core/css/CSSParserValues.h" |
36 #include "core/css/CSSPrimitiveValue.h" | 36 #include "core/css/CSSPrimitiveValue.h" |
37 #include "core/html/parser/HTMLParserIdioms.h" | |
37 #include "wtf/text/StringBuilder.h" | 38 #include "wtf/text/StringBuilder.h" |
38 | 39 |
39 namespace WebCore { | 40 namespace WebCore { |
40 | 41 |
41 static inline bool featureWithCSSValueID(const AtomicString& mediaFeature, const CSSParserValue* value) | 42 using namespace MediaFeatureNames; |
43 | |
44 // Since the comparisons we do here are on static strings and since most of the strings are not equal, | |
45 // we use this function to only compare the StringImpl addresses. | |
46 static inline bool stringImplEquals(const String& mediaFeature, const String& ot herMediaFeature) | |
47 { | |
48 return (mediaFeature.impl() == otherMediaFeature.impl()); | |
49 } | |
abarth-chromium
2014/03/06 16:59:58
I'm still not convinced this optimization is impor
abarth-chromium
2014/03/06 17:05:45
Maybe add a general equal codepath that checks isA
| |
50 | |
51 static inline bool featureWithCSSValueID(const String& mediaFeature, const CSSPa rserValue* value) | |
42 { | 52 { |
43 if (!value->id) | 53 if (!value->id) |
44 return false; | 54 return false; |
45 | 55 |
46 return mediaFeature == MediaFeatureNames::orientationMediaFeature | 56 return stringImplEquals(mediaFeature, orientationMediaFeature) |
47 || mediaFeature == MediaFeatureNames::viewModeMediaFeature | 57 || stringImplEquals(mediaFeature, viewModeMediaFeature) |
48 || mediaFeature == MediaFeatureNames::pointerMediaFeature | 58 || stringImplEquals(mediaFeature, pointerMediaFeature) |
49 || mediaFeature == MediaFeatureNames::scanMediaFeature; | 59 || stringImplEquals(mediaFeature, scanMediaFeature); |
50 } | 60 } |
51 | 61 |
52 static inline bool featureWithValidIdent(const AtomicString& mediaFeature, CSSVa lueID ident) | 62 static inline bool featureWithValidIdent(const String& mediaFeature, CSSValueID ident) |
53 { | 63 { |
54 if (mediaFeature == MediaFeatureNames::orientationMediaFeature) | 64 if (stringImplEquals(mediaFeature, orientationMediaFeature)) |
55 return ident == CSSValuePortrait || ident == CSSValueLandscape; | 65 return ident == CSSValuePortrait || ident == CSSValueLandscape; |
56 | 66 |
57 if (mediaFeature == MediaFeatureNames::viewModeMediaFeature) { | 67 if (stringImplEquals(mediaFeature, viewModeMediaFeature)) { |
58 switch (ident) { | 68 switch (ident) { |
59 case CSSValueWindowed: | 69 case CSSValueWindowed: |
60 case CSSValueFloating: | 70 case CSSValueFloating: |
61 case CSSValueFullscreen: | 71 case CSSValueFullscreen: |
62 case CSSValueMaximized: | 72 case CSSValueMaximized: |
63 case CSSValueMinimized: | 73 case CSSValueMinimized: |
64 return true; | 74 return true; |
65 default: | 75 default: |
66 return false; | 76 return false; |
67 } | 77 } |
68 } | 78 } |
69 | 79 |
70 if (mediaFeature == MediaFeatureNames::pointerMediaFeature) | 80 if (stringImplEquals(mediaFeature, pointerMediaFeature)) |
71 return ident == CSSValueNone || ident == CSSValueCoarse || ident == CSSV alueFine; | 81 return ident == CSSValueNone || ident == CSSValueCoarse || ident == CSSV alueFine; |
72 | 82 |
73 if (mediaFeature == MediaFeatureNames::scanMediaFeature) | 83 if (stringImplEquals(mediaFeature, scanMediaFeature)) |
74 return ident == CSSValueInterlace || ident == CSSValueProgressive; | 84 return ident == CSSValueInterlace || ident == CSSValueProgressive; |
75 | 85 |
76 ASSERT_NOT_REACHED(); | 86 ASSERT_NOT_REACHED(); |
77 return false; | 87 return false; |
78 } | 88 } |
79 | 89 |
80 static inline bool featureWithValidPositiveLength(const AtomicString& mediaFeatu re, const CSSParserValue* value) | 90 static inline bool featureWithValidPositiveLength(const String& mediaFeature, co nst CSSParserValue* value) |
81 { | 91 { |
82 if (!(((value->unit >= CSSPrimitiveValue::CSS_EMS && value->unit <= CSSPrimi tiveValue::CSS_PC) || value->unit == CSSPrimitiveValue::CSS_REMS) || (value->uni t == CSSPrimitiveValue::CSS_NUMBER && !(value->fValue))) || value->fValue < 0) | 92 if (!(((value->unit >= CSSPrimitiveValue::CSS_EMS && value->unit <= CSSPrimi tiveValue::CSS_PC) || value->unit == CSSPrimitiveValue::CSS_REMS) || (value->uni t == CSSPrimitiveValue::CSS_NUMBER && !(value->fValue))) || value->fValue < 0) |
83 return false; | 93 return false; |
84 | 94 |
85 return mediaFeature == MediaFeatureNames::heightMediaFeature | 95 |
86 || mediaFeature == MediaFeatureNames::maxHeightMediaFeature | 96 return stringImplEquals(mediaFeature, heightMediaFeature) |
87 || mediaFeature == MediaFeatureNames::minHeightMediaFeature | 97 || stringImplEquals(mediaFeature, maxHeightMediaFeature) |
88 || mediaFeature == MediaFeatureNames::widthMediaFeature | 98 || stringImplEquals(mediaFeature, minHeightMediaFeature) |
89 || mediaFeature == MediaFeatureNames::maxWidthMediaFeature | 99 || stringImplEquals(mediaFeature, widthMediaFeature) |
90 || mediaFeature == MediaFeatureNames::minWidthMediaFeature | 100 || stringImplEquals(mediaFeature, maxWidthMediaFeature) |
91 || mediaFeature == MediaFeatureNames::deviceHeightMediaFeature | 101 || stringImplEquals(mediaFeature, minWidthMediaFeature) |
92 || mediaFeature == MediaFeatureNames::maxDeviceHeightMediaFeature | 102 || stringImplEquals(mediaFeature, deviceHeightMediaFeature) |
93 || mediaFeature == MediaFeatureNames::minDeviceHeightMediaFeature | 103 || stringImplEquals(mediaFeature, maxDeviceHeightMediaFeature) |
94 || mediaFeature == MediaFeatureNames::deviceWidthMediaFeature | 104 || stringImplEquals(mediaFeature, minDeviceHeightMediaFeature) |
95 || mediaFeature == MediaFeatureNames::maxDeviceWidthMediaFeature | 105 || stringImplEquals(mediaFeature, deviceWidthMediaFeature) |
96 || mediaFeature == MediaFeatureNames::minDeviceWidthMediaFeature; | 106 || stringImplEquals(mediaFeature, minDeviceWidthMediaFeature) |
107 || stringImplEquals(mediaFeature, maxDeviceWidthMediaFeature); | |
97 } | 108 } |
98 | 109 |
99 static inline bool featureWithValidDensity(const AtomicString& mediaFeature, con st CSSParserValue* value) | 110 static inline bool featureWithValidDensity(const String& mediaFeature, const CSS ParserValue* value) |
100 { | 111 { |
101 if ((value->unit != CSSPrimitiveValue::CSS_DPPX && value->unit != CSSPrimiti veValue::CSS_DPI && value->unit != CSSPrimitiveValue::CSS_DPCM) || value->fValue <= 0) | 112 if ((value->unit != CSSPrimitiveValue::CSS_DPPX && value->unit != CSSPrimiti veValue::CSS_DPI && value->unit != CSSPrimitiveValue::CSS_DPCM) || value->fValue <= 0) |
102 return false; | 113 return false; |
103 | 114 |
104 return mediaFeature == MediaFeatureNames::resolutionMediaFeature | 115 return stringImplEquals(mediaFeature, resolutionMediaFeature) |
105 || mediaFeature == MediaFeatureNames::maxResolutionMediaFeature | 116 || stringImplEquals(mediaFeature, minResolutionMediaFeature) |
106 || mediaFeature == MediaFeatureNames::minResolutionMediaFeature; | 117 || stringImplEquals(mediaFeature, maxResolutionMediaFeature); |
107 } | 118 } |
108 | 119 |
109 static inline bool featureWithPositiveInteger(const AtomicString& mediaFeature, const CSSParserValue* value) | 120 static inline bool featureWithPositiveInteger(const String& mediaFeature, const CSSParserValue* value) |
110 { | 121 { |
111 if (!value->isInt || value->fValue < 0) | 122 if (!value->isInt || value->fValue < 0) |
112 return false; | 123 return false; |
113 | 124 |
114 return mediaFeature == MediaFeatureNames::colorMediaFeature | 125 return stringImplEquals(mediaFeature, colorMediaFeature) |
115 || mediaFeature == MediaFeatureNames::maxColorMediaFeature | 126 || stringImplEquals(mediaFeature, maxColorMediaFeature) |
116 || mediaFeature == MediaFeatureNames::minColorMediaFeature | 127 || stringImplEquals(mediaFeature, minColorMediaFeature) |
117 || mediaFeature == MediaFeatureNames::colorIndexMediaFeature | 128 || stringImplEquals(mediaFeature, colorIndexMediaFeature) |
118 || mediaFeature == MediaFeatureNames::maxColorIndexMediaFeature | 129 || stringImplEquals(mediaFeature, maxColorIndexMediaFeature) |
119 || mediaFeature == MediaFeatureNames::minColorIndexMediaFeature | 130 || stringImplEquals(mediaFeature, minColorIndexMediaFeature) |
120 || mediaFeature == MediaFeatureNames::monochromeMediaFeature | 131 || stringImplEquals(mediaFeature, monochromeMediaFeature) |
121 || mediaFeature == MediaFeatureNames::minMonochromeMediaFeature | 132 || stringImplEquals(mediaFeature, maxMonochromeMediaFeature) |
122 || mediaFeature == MediaFeatureNames::maxMonochromeMediaFeature; | 133 || stringImplEquals(mediaFeature, minMonochromeMediaFeature); |
123 } | 134 } |
124 | 135 |
125 static inline bool featureWithPositiveNumber(const AtomicString& mediaFeature, c onst CSSParserValue* value) | 136 static inline bool featureWithPositiveNumber(const String& mediaFeature, const C SSParserValue* value) |
126 { | 137 { |
127 if (value->unit != CSSPrimitiveValue::CSS_NUMBER || value->fValue < 0) | 138 if (value->unit != CSSPrimitiveValue::CSS_NUMBER || value->fValue < 0) |
128 return false; | 139 return false; |
129 | 140 |
130 return mediaFeature == MediaFeatureNames::transform2dMediaFeature | 141 return stringImplEquals(mediaFeature, transform2dMediaFeature) |
131 || mediaFeature == MediaFeatureNames::transform3dMediaFeature | 142 || stringImplEquals(mediaFeature, transform3dMediaFeature) |
132 || mediaFeature == MediaFeatureNames::animationMediaFeature | 143 || stringImplEquals(mediaFeature, animationMediaFeature) |
133 || mediaFeature == MediaFeatureNames::devicePixelRatioMediaFeature | 144 || stringImplEquals(mediaFeature, devicePixelRatioMediaFeature) |
134 || mediaFeature == MediaFeatureNames::maxDevicePixelRatioMediaFeature | 145 || stringImplEquals(mediaFeature, maxDevicePixelRatioMediaFeature) |
135 || mediaFeature == MediaFeatureNames::minDevicePixelRatioMediaFeature; | 146 || stringImplEquals(mediaFeature, minDevicePixelRatioMediaFeature); |
136 } | 147 } |
137 | 148 |
138 static inline bool featureWithZeroOrOne(const AtomicString& mediaFeature, const CSSParserValue* value) | 149 static inline bool featureWithZeroOrOne(const String& mediaFeature, const CSSPar serValue* value) |
139 { | 150 { |
140 if (!value->isInt || !(value->fValue == 1 || !value->fValue)) | 151 if (!value->isInt || !(value->fValue == 1 || !value->fValue)) |
141 return false; | 152 return false; |
142 | 153 |
143 return mediaFeature == MediaFeatureNames::gridMediaFeature | 154 return stringImplEquals(mediaFeature, gridMediaFeature) |
144 || mediaFeature == MediaFeatureNames::hoverMediaFeature; | 155 || stringImplEquals(mediaFeature, hoverMediaFeature); |
145 } | 156 } |
146 | 157 |
147 static inline bool featureWithAspectRatio(const AtomicString& mediaFeature) | 158 static inline bool featureWithAspectRatio(const String& mediaFeature) |
148 { | 159 { |
149 return mediaFeature == MediaFeatureNames::aspectRatioMediaFeature | 160 return stringImplEquals(mediaFeature, aspectRatioMediaFeature) |
150 || mediaFeature == MediaFeatureNames::deviceAspectRatioMediaFeature | 161 || stringImplEquals(mediaFeature, deviceAspectRatioMediaFeature) |
151 || mediaFeature == MediaFeatureNames::minAspectRatioMediaFeature | 162 || stringImplEquals(mediaFeature, minAspectRatioMediaFeature) |
152 || mediaFeature == MediaFeatureNames::maxAspectRatioMediaFeature | 163 || stringImplEquals(mediaFeature, maxAspectRatioMediaFeature) |
153 || mediaFeature == MediaFeatureNames::minDeviceAspectRatioMediaFeature | 164 || stringImplEquals(mediaFeature, minDeviceAspectRatioMediaFeature) |
154 || mediaFeature == MediaFeatureNames::maxDeviceAspectRatioMediaFeature; | 165 || stringImplEquals(mediaFeature, maxDeviceAspectRatioMediaFeature); |
155 } | 166 } |
156 | 167 |
157 static inline bool featureWithoutValue(const AtomicString& mediaFeature) | 168 static inline bool featureWithoutValue(const String& mediaFeature) |
158 { | 169 { |
159 // Media features that are prefixed by min/max cannot be used without a valu e. | 170 // Media features that are prefixed by min/max cannot be used without a valu e. |
160 return mediaFeature == MediaFeatureNames::monochromeMediaFeature | 171 return stringImplEquals(mediaFeature, monochromeMediaFeature) |
161 || mediaFeature == MediaFeatureNames::colorMediaFeature | 172 || stringImplEquals(mediaFeature, colorMediaFeature) |
162 || mediaFeature == MediaFeatureNames::colorIndexMediaFeature | 173 || stringImplEquals(mediaFeature, colorIndexMediaFeature) |
163 || mediaFeature == MediaFeatureNames::gridMediaFeature | 174 || stringImplEquals(mediaFeature, gridMediaFeature) |
164 || mediaFeature == MediaFeatureNames::heightMediaFeature | 175 || stringImplEquals(mediaFeature, heightMediaFeature) |
165 || mediaFeature == MediaFeatureNames::widthMediaFeature | 176 || stringImplEquals(mediaFeature, widthMediaFeature) |
166 || mediaFeature == MediaFeatureNames::deviceHeightMediaFeature | 177 || stringImplEquals(mediaFeature, deviceHeightMediaFeature) |
167 || mediaFeature == MediaFeatureNames::deviceWidthMediaFeature | 178 || stringImplEquals(mediaFeature, deviceWidthMediaFeature) |
168 || mediaFeature == MediaFeatureNames::orientationMediaFeature | 179 || stringImplEquals(mediaFeature, orientationMediaFeature) |
169 || mediaFeature == MediaFeatureNames::aspectRatioMediaFeature | 180 || stringImplEquals(mediaFeature, aspectRatioMediaFeature) |
170 || mediaFeature == MediaFeatureNames::deviceAspectRatioMediaFeature | 181 || stringImplEquals(mediaFeature, deviceAspectRatioMediaFeature) |
171 || mediaFeature == MediaFeatureNames::hoverMediaFeature | 182 || stringImplEquals(mediaFeature, hoverMediaFeature) |
172 || mediaFeature == MediaFeatureNames::transform2dMediaFeature | 183 || stringImplEquals(mediaFeature, transform2dMediaFeature) |
173 || mediaFeature == MediaFeatureNames::transform3dMediaFeature | 184 || stringImplEquals(mediaFeature, transform3dMediaFeature) |
174 || mediaFeature == MediaFeatureNames::animationMediaFeature | 185 || stringImplEquals(mediaFeature, animationMediaFeature) |
175 || mediaFeature == MediaFeatureNames::viewModeMediaFeature | 186 || stringImplEquals(mediaFeature, viewModeMediaFeature) |
176 || mediaFeature == MediaFeatureNames::pointerMediaFeature | 187 || stringImplEquals(mediaFeature, pointerMediaFeature) |
177 || mediaFeature == MediaFeatureNames::devicePixelRatioMediaFeature | 188 || stringImplEquals(mediaFeature, devicePixelRatioMediaFeature) |
178 || mediaFeature == MediaFeatureNames::resolutionMediaFeature | 189 || stringImplEquals(mediaFeature, resolutionMediaFeature) |
179 || mediaFeature == MediaFeatureNames::scanMediaFeature; | 190 || stringImplEquals(mediaFeature, scanMediaFeature); |
180 } | 191 } |
181 | 192 |
182 bool MediaQueryExp::isViewportDependent() const | 193 bool MediaQueryExp::isViewportDependent() const |
183 { | 194 { |
184 return m_mediaFeature == MediaFeatureNames::widthMediaFeature | 195 return stringImplEquals(m_mediaFeature, widthMediaFeature) |
185 || m_mediaFeature == MediaFeatureNames::heightMediaFeature | 196 || stringImplEquals(m_mediaFeature, heightMediaFeature) |
186 || m_mediaFeature == MediaFeatureNames::minWidthMediaFeature | 197 || stringImplEquals(m_mediaFeature, minWidthMediaFeature) |
187 || m_mediaFeature == MediaFeatureNames::minHeightMediaFeature | 198 || stringImplEquals(m_mediaFeature, minHeightMediaFeature) |
188 || m_mediaFeature == MediaFeatureNames::maxWidthMediaFeature | 199 || stringImplEquals(m_mediaFeature, maxWidthMediaFeature) |
189 || m_mediaFeature == MediaFeatureNames::maxHeightMediaFeature | 200 || stringImplEquals(m_mediaFeature, maxHeightMediaFeature) |
190 || m_mediaFeature == MediaFeatureNames::orientationMediaFeature | 201 || stringImplEquals(m_mediaFeature, orientationMediaFeature) |
191 || m_mediaFeature == MediaFeatureNames::aspectRatioMediaFeature | 202 || stringImplEquals(m_mediaFeature, aspectRatioMediaFeature) |
192 || m_mediaFeature == MediaFeatureNames::minAspectRatioMediaFeature | 203 || stringImplEquals(m_mediaFeature, minAspectRatioMediaFeature) |
193 || m_mediaFeature == MediaFeatureNames::devicePixelRatioMediaFeature | 204 || stringImplEquals(m_mediaFeature, devicePixelRatioMediaFeature) |
194 || m_mediaFeature == MediaFeatureNames::resolutionMediaFeature | 205 || stringImplEquals(m_mediaFeature, resolutionMediaFeature) |
195 || m_mediaFeature == MediaFeatureNames::maxAspectRatioMediaFeature; | 206 || stringImplEquals(m_mediaFeature, maxAspectRatioMediaFeature); |
196 } | 207 } |
197 | 208 |
198 MediaQueryExp::MediaQueryExp(const MediaQueryExp& other) | 209 MediaQueryExp::MediaQueryExp(const MediaQueryExp& other) |
199 : m_mediaFeature(other.mediaFeature()) | 210 : m_mediaFeature(other.mediaFeature()) |
200 , m_value(other.value()) | 211 , m_value(other.value()) |
201 { | 212 { |
202 } | 213 } |
203 | 214 |
204 MediaQueryExp::MediaQueryExp(const AtomicString& mediaFeature, PassRefPtrWillBeR awPtr<CSSValue> value) | 215 MediaQueryExp::MediaQueryExp(const String& mediaFeature, PassRefPtrWillBeRawPtr< CSSValue> value) |
205 : m_mediaFeature(mediaFeature) | 216 : m_mediaFeature(mediaFeature) |
206 , m_value(value) | 217 , m_value(value) |
207 { | 218 { |
208 } | 219 } |
209 | 220 |
210 PassOwnPtrWillBeRawPtr<MediaQueryExp> MediaQueryExp::create(const AtomicString& mediaFeature, CSSParserValueList* valueList) | 221 PassOwnPtrWillBeRawPtr<MediaQueryExp> MediaQueryExp::create(const String& mediaF eature, CSSParserValueList* valueList) |
211 { | 222 { |
212 RefPtrWillBeRawPtr<CSSValue> cssValue; | 223 RefPtrWillBeRawPtr<CSSValue> cssValue; |
213 bool isValid = false; | 224 bool isValid = false; |
225 String lowerMediaFeature = attemptStaticStringCreation(mediaFeature.lower()) ; | |
214 | 226 |
215 // Create value for media query expression that must have 1 or more values. | 227 // Create value for media query expression that must have 1 or more values. |
216 if (valueList) { | 228 if (valueList && valueList->size() > 0) { |
217 if (valueList->size() == 1) { | 229 if (valueList->size() == 1) { |
218 CSSParserValue* value = valueList->current(); | 230 CSSParserValue* value = valueList->current(); |
219 | 231 |
220 if (featureWithCSSValueID(mediaFeature, value)) { | 232 if (featureWithCSSValueID(lowerMediaFeature, value)) { |
221 // Media features that use CSSValueIDs. | 233 // Media features that use CSSValueIDs. |
222 cssValue = CSSPrimitiveValue::createIdentifier(value->id); | 234 cssValue = CSSPrimitiveValue::createIdentifier(value->id); |
223 if (!featureWithValidIdent(mediaFeature, toCSSPrimitiveValue(css Value.get())->getValueID())) | 235 if (!featureWithValidIdent(lowerMediaFeature, toCSSPrimitiveValu e(cssValue.get())->getValueID())) |
224 cssValue.clear(); | 236 cssValue.clear(); |
225 } else if (featureWithValidDensity(mediaFeature, value)) { | 237 } else if (featureWithValidDensity(lowerMediaFeature, value)) { |
226 // Media features that must have non-negative <density>, ie. dpp x, dpi or dpcm. | 238 // Media features that must have non-negative <density>, ie. dpp x, dpi or dpcm. |
227 cssValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiv eValue::UnitTypes) value->unit); | 239 cssValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiv eValue::UnitTypes) value->unit); |
228 } else if (featureWithValidPositiveLength(mediaFeature, value)) { | 240 } else if (featureWithValidPositiveLength(lowerMediaFeature, value)) { |
229 // Media features that must have non-negative <lenght> or number value. | 241 // Media features that must have non-negative <lenght> or number value. |
230 cssValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiv eValue::UnitTypes) value->unit); | 242 cssValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiv eValue::UnitTypes) value->unit); |
231 } else if (featureWithPositiveInteger(mediaFeature, value)) { | 243 } else if (featureWithPositiveInteger(lowerMediaFeature, value)) { |
232 // Media features that must have non-negative integer value. | 244 // Media features that must have non-negative integer value. |
233 cssValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitive Value::CSS_NUMBER); | 245 cssValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitive Value::CSS_NUMBER); |
234 } else if (featureWithPositiveNumber(mediaFeature, value)) { | 246 } else if (featureWithPositiveNumber(lowerMediaFeature, value)) { |
235 // Media features that must have non-negative number value. | 247 // Media features that must have non-negative number value. |
236 cssValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitive Value::CSS_NUMBER); | 248 cssValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitive Value::CSS_NUMBER); |
237 } else if (featureWithZeroOrOne(mediaFeature, value)) { | 249 } else if (featureWithZeroOrOne(lowerMediaFeature, value)) { |
238 // Media features that must have (0|1) value. | 250 // Media features that must have (0|1) value. |
239 cssValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitive Value::CSS_NUMBER); | 251 cssValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitive Value::CSS_NUMBER); |
240 } | 252 } |
241 | 253 |
242 isValid = cssValue; | 254 isValid = cssValue; |
243 | 255 |
244 } else if (valueList->size() == 3 && featureWithAspectRatio(mediaFeature )) { | 256 } else if (valueList->size() == 3 && featureWithAspectRatio(lowerMediaFe ature)) { |
245 // Create list of values. | 257 // Create list of values. |
246 // Currently accepts only <integer>/<integer>. | 258 // Currently accepts only <integer>/<integer>. |
247 // Applicable to device-aspect-ratio and aspec-ratio. | 259 // Applicable to device-aspect-ratio and aspec-ratio. |
248 isValid = true; | 260 isValid = true; |
249 float numeratorValue = 0; | 261 float numeratorValue = 0; |
250 float denominatorValue = 0; | 262 float denominatorValue = 0; |
251 // The aspect-ratio must be <integer> (whitespace)? / (whitespace)? <integer>. | 263 // The aspect-ratio must be <integer> (whitespace)? / (whitespace)? <integer>. |
252 for (unsigned i = 0; i < 3; ++i, valueList->next()) { | 264 for (unsigned i = 0; i < 3; ++i, valueList->next()) { |
253 const CSSParserValue* value = valueList->current(); | 265 const CSSParserValue* value = valueList->current(); |
254 if (i != 1 && value->unit == CSSPrimitiveValue::CSS_NUMBER && va lue->fValue > 0 && value->isInt) { | 266 if (i != 1 && value->unit == CSSPrimitiveValue::CSS_NUMBER && va lue->fValue > 0 && value->isInt) { |
255 if (!i) | 267 if (!i) |
256 numeratorValue = value->fValue; | 268 numeratorValue = value->fValue; |
257 else | 269 else |
258 denominatorValue = value->fValue; | 270 denominatorValue = value->fValue; |
259 } else if (i == 1 && value->unit == CSSParserValue::Operator && value->iValue == '/') { | 271 } else if (i == 1 && value->unit == CSSParserValue::Operator && value->iValue == '/') { |
260 continue; | 272 continue; |
261 } else { | 273 } else { |
262 isValid = false; | 274 isValid = false; |
263 break; | 275 break; |
264 } | 276 } |
265 } | 277 } |
266 | 278 |
267 if (isValid) | 279 if (isValid) |
268 cssValue = CSSAspectRatioValue::create(numeratorValue, denominat orValue); | 280 cssValue = CSSAspectRatioValue::create(numeratorValue, denominat orValue); |
269 } | 281 } |
270 } else if (featureWithoutValue(mediaFeature)) { | 282 } else if (featureWithoutValue(lowerMediaFeature)) { |
271 isValid = true; | 283 isValid = true; |
272 } | 284 } |
273 | 285 |
274 if (!isValid) | 286 if (!isValid) |
275 return nullptr; | 287 return nullptr; |
276 | 288 |
277 return adoptPtrWillBeNoop(new MediaQueryExp(mediaFeature, cssValue)); | 289 return adoptPtrWillBeNoop(new MediaQueryExp(lowerMediaFeature, cssValue)); |
278 } | 290 } |
279 | 291 |
280 MediaQueryExp::~MediaQueryExp() | 292 MediaQueryExp::~MediaQueryExp() |
281 { | 293 { |
282 } | 294 } |
283 | 295 |
284 String MediaQueryExp::serialize() const | 296 String MediaQueryExp::serialize() const |
285 { | 297 { |
286 StringBuilder result; | 298 StringBuilder result; |
287 result.append("("); | 299 result.append("("); |
288 result.append(m_mediaFeature.lower()); | 300 result.append(m_mediaFeature.lower()); |
289 if (m_value) { | 301 if (m_value) { |
290 result.append(": "); | 302 result.append(": "); |
291 result.append(m_value->cssText()); | 303 result.append(m_value->cssText()); |
292 } | 304 } |
293 result.append(")"); | 305 result.append(")"); |
294 | 306 |
295 return result.toString(); | 307 return result.toString(); |
296 } | 308 } |
297 | 309 |
298 } // namespace | 310 } // namespace |
OLD | NEW |