OLD | NEW |
1 /* | 1 /* |
2 * CSS Media Query Evaluator | 2 * CSS Media Query Evaluator |
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) 2013 Apple Inc. All rights reserved. | 5 * Copyright (C) 2013 Apple Inc. All rights reserved. |
6 * Copyright (C) 2013 Intel Corporation. All rights reserved. | 6 * Copyright (C) 2013 Intel Corporation. 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 109 } |
110 | 110 |
111 bool MediaQueryEvaluator::eval( | 111 bool MediaQueryEvaluator::eval( |
112 const MediaQuery* query, | 112 const MediaQuery* query, |
113 MediaQueryResultList* viewportDependentMediaQueryResults, | 113 MediaQueryResultList* viewportDependentMediaQueryResults, |
114 MediaQueryResultList* deviceDependentMediaQueryResults) const { | 114 MediaQueryResultList* deviceDependentMediaQueryResults) const { |
115 if (!mediaTypeMatch(query->mediaType())) | 115 if (!mediaTypeMatch(query->mediaType())) |
116 return applyRestrictor(query->restrictor(), false); | 116 return applyRestrictor(query->restrictor(), false); |
117 | 117 |
118 const ExpressionHeapVector& expressions = query->expressions(); | 118 const ExpressionHeapVector& expressions = query->expressions(); |
119 // Iterate through expressions, stop if any of them eval to false (AND semanti
cs). | 119 // Iterate through expressions, stop if any of them eval to false (AND |
| 120 // semantics). |
120 size_t i = 0; | 121 size_t i = 0; |
121 for (; i < expressions.size(); ++i) { | 122 for (; i < expressions.size(); ++i) { |
122 bool exprResult = eval(expressions.at(i).get()); | 123 bool exprResult = eval(expressions.at(i).get()); |
123 if (viewportDependentMediaQueryResults && | 124 if (viewportDependentMediaQueryResults && |
124 expressions.at(i)->isViewportDependent()) | 125 expressions.at(i)->isViewportDependent()) |
125 viewportDependentMediaQueryResults->append( | 126 viewportDependentMediaQueryResults->append( |
126 new MediaQueryResult(*expressions.at(i), exprResult)); | 127 new MediaQueryResult(*expressions.at(i), exprResult)); |
127 if (deviceDependentMediaQueryResults && | 128 if (deviceDependentMediaQueryResults && |
128 expressions.at(i)->isDeviceDependent()) | 129 expressions.at(i)->isDeviceDependent()) |
129 deviceDependentMediaQueryResults->append( | 130 deviceDependentMediaQueryResults->append( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 if (value.isValid()) | 210 if (value.isValid()) |
210 return numberValue(value, number) && | 211 return numberValue(value, number) && |
211 compareValue(bitsPerComponent, static_cast<int>(number), op); | 212 compareValue(bitsPerComponent, static_cast<int>(number), op); |
212 | 213 |
213 return bitsPerComponent != 0; | 214 return bitsPerComponent != 0; |
214 } | 215 } |
215 | 216 |
216 static bool colorIndexMediaFeatureEval(const MediaQueryExpValue& value, | 217 static bool colorIndexMediaFeatureEval(const MediaQueryExpValue& value, |
217 MediaFeaturePrefix op, | 218 MediaFeaturePrefix op, |
218 const MediaValues&) { | 219 const MediaValues&) { |
219 // FIXME: We currently assume that we do not support indexed displays, as it i
s unknown | 220 // FIXME: We currently assume that we do not support indexed displays, as it |
220 // how to retrieve the information if the display mode is indexed. This matche
s Firefox. | 221 // is unknown how to retrieve the information if the display mode is indexed. |
| 222 // This matches Firefox. |
221 if (!value.isValid()) | 223 if (!value.isValid()) |
222 return false; | 224 return false; |
223 | 225 |
224 // Acording to spec, if the device does not use a color lookup table, the valu
e is zero. | 226 // Acording to spec, if the device does not use a color lookup table, the |
| 227 // value is zero. |
225 float number; | 228 float number; |
226 return numberValue(value, number) && | 229 return numberValue(value, number) && |
227 compareValue(0, static_cast<int>(number), op); | 230 compareValue(0, static_cast<int>(number), op); |
228 } | 231 } |
229 | 232 |
230 static bool monochromeMediaFeatureEval(const MediaQueryExpValue& value, | 233 static bool monochromeMediaFeatureEval(const MediaQueryExpValue& value, |
231 MediaFeaturePrefix op, | 234 MediaFeaturePrefix op, |
232 const MediaValues& mediaValues) { | 235 const MediaValues& mediaValues) { |
233 if (!mediaValues.monochromeBitsPerComponent()) { | 236 if (!mediaValues.monochromeBitsPerComponent()) { |
234 if (value.isValid()) { | 237 if (value.isValid()) { |
235 float number; | 238 float number; |
236 return numberValue(value, number) && | 239 return numberValue(value, number) && |
237 compareValue(0, static_cast<int>(number), op); | 240 compareValue(0, static_cast<int>(number), op); |
238 } | 241 } |
239 return false; | 242 return false; |
240 } | 243 } |
241 | 244 |
242 return colorMediaFeatureEval(value, op, mediaValues); | 245 return colorMediaFeatureEval(value, op, mediaValues); |
243 } | 246 } |
244 | 247 |
245 static bool displayModeMediaFeatureEval(const MediaQueryExpValue& value, | 248 static bool displayModeMediaFeatureEval(const MediaQueryExpValue& value, |
246 MediaFeaturePrefix, | 249 MediaFeaturePrefix, |
247 const MediaValues& mediaValues) { | 250 const MediaValues& mediaValues) { |
248 // isValid() is false if there is no parameter. Without parameter we should re
turn true to indicate that | 251 // isValid() is false if there is no parameter. Without parameter we should |
249 // displayModeMediaFeature is enabled in the browser. | 252 // return true to indicate that displayModeMediaFeature is enabled in the |
| 253 // browser. |
250 if (!value.isValid()) | 254 if (!value.isValid()) |
251 return true; | 255 return true; |
252 | 256 |
253 if (!value.isID) | 257 if (!value.isID) |
254 return false; | 258 return false; |
255 | 259 |
256 WebDisplayMode mode = mediaValues.displayMode(); | 260 WebDisplayMode mode = mediaValues.displayMode(); |
257 switch (value.id) { | 261 switch (value.id) { |
258 case CSSValueFullscreen: | 262 case CSSValueFullscreen: |
259 return mode == WebDisplayModeFullscreen; | 263 return mode == WebDisplayModeFullscreen; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 310 |
307 // ({,min-,max-}device-aspect-ratio) | 311 // ({,min-,max-}device-aspect-ratio) |
308 // assume if we have a device, its aspect ratio is non-zero. | 312 // assume if we have a device, its aspect ratio is non-zero. |
309 return true; | 313 return true; |
310 } | 314 } |
311 | 315 |
312 static bool evalResolution(const MediaQueryExpValue& value, | 316 static bool evalResolution(const MediaQueryExpValue& value, |
313 MediaFeaturePrefix op, | 317 MediaFeaturePrefix op, |
314 const MediaValues& mediaValues) { | 318 const MediaValues& mediaValues) { |
315 // According to MQ4, only 'screen', 'print' and 'speech' may match. | 319 // According to MQ4, only 'screen', 'print' and 'speech' may match. |
316 // FIXME: What should speech match? https://www.w3.org/Style/CSS/Tracker/issue
s/348 | 320 // FIXME: What should speech match? |
| 321 // https://www.w3.org/Style/CSS/Tracker/issues/348 |
317 float actualResolution = 0; | 322 float actualResolution = 0; |
318 | 323 |
319 // This checks the actual media type applied to the document, and we know | 324 // This checks the actual media type applied to the document, and we know |
320 // this method only got called if this media type matches the one defined | 325 // this method only got called if this media type matches the one defined |
321 // in the query. Thus, if if the document's media type is "print", the | 326 // in the query. Thus, if if the document's media type is "print", the |
322 // media type of the query will either be "print" or "all". | 327 // media type of the query will either be "print" or "all". |
323 if (equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::screen)) { | 328 if (equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::screen)) { |
324 actualResolution = clampTo<float>(mediaValues.devicePixelRatio()); | 329 actualResolution = clampTo<float>(mediaValues.devicePixelRatio()); |
325 } else if (equalIgnoringCase(mediaValues.mediaType(), | 330 } else if (equalIgnoringCase(mediaValues.mediaType(), |
326 MediaTypeNames::print)) { | 331 MediaTypeNames::print)) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 static bool widthMediaFeatureEval(const MediaQueryExpValue& value, | 457 static bool widthMediaFeatureEval(const MediaQueryExpValue& value, |
453 MediaFeaturePrefix op, | 458 MediaFeaturePrefix op, |
454 const MediaValues& mediaValues) { | 459 const MediaValues& mediaValues) { |
455 double width = mediaValues.viewportWidth(); | 460 double width = mediaValues.viewportWidth(); |
456 if (value.isValid()) | 461 if (value.isValid()) |
457 return computeLengthAndCompare(value, op, mediaValues, width); | 462 return computeLengthAndCompare(value, op, mediaValues, width); |
458 | 463 |
459 return width; | 464 return width; |
460 } | 465 } |
461 | 466 |
462 // Rest of the functions are trampolines which set the prefix according to the m
edia feature expression used. | 467 // Rest of the functions are trampolines which set the prefix according to the |
| 468 // media feature expression used. |
463 | 469 |
464 static bool minColorMediaFeatureEval(const MediaQueryExpValue& value, | 470 static bool minColorMediaFeatureEval(const MediaQueryExpValue& value, |
465 MediaFeaturePrefix, | 471 MediaFeaturePrefix, |
466 const MediaValues& mediaValues) { | 472 const MediaValues& mediaValues) { |
467 return colorMediaFeatureEval(value, MinPrefix, mediaValues); | 473 return colorMediaFeatureEval(value, MinPrefix, mediaValues); |
468 } | 474 } |
469 | 475 |
470 static bool maxColorMediaFeatureEval(const MediaQueryExpValue& value, | 476 static bool maxColorMediaFeatureEval(const MediaQueryExpValue& value, |
471 MediaFeaturePrefix, | 477 MediaFeaturePrefix, |
472 const MediaValues& mediaValues) { | 478 const MediaValues& mediaValues) { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 // Call the media feature evaluation function. Assume no prefix and let | 748 // Call the media feature evaluation function. Assume no prefix and let |
743 // trampoline functions override the prefix if prefix is used. | 749 // trampoline functions override the prefix if prefix is used. |
744 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); | 750 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); |
745 if (func) | 751 if (func) |
746 return func(expr->expValue(), NoPrefix, *m_mediaValues); | 752 return func(expr->expValue(), NoPrefix, *m_mediaValues); |
747 | 753 |
748 return false; | 754 return false; |
749 } | 755 } |
750 | 756 |
751 } // namespace blink | 757 } // namespace blink |
OLD | NEW |