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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 static bool gridMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const M ediaValues&) | 324 static bool gridMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const M ediaValues&) |
325 { | 325 { |
326 // if output device is bitmap, grid: 0 == true | 326 // if output device is bitmap, grid: 0 == true |
327 // assume we have bitmap device | 327 // assume we have bitmap device |
328 float number; | 328 float number; |
329 if (value && numberValue(value, number)) | 329 if (value && numberValue(value, number)) |
330 return compareValue(static_cast<int>(number), 0, op); | 330 return compareValue(static_cast<int>(number), 0, op); |
331 return false; | 331 return false; |
332 } | 332 } |
333 | 333 |
334 static bool computeLengthWithoutStyle(CSSPrimitiveValue* primitiveValue, int def aultFontSize, int& result) | 334 static bool computeLength(CSSValue* value, const MediaValues& mediaValues, int& result) |
335 { | |
336 // We're running in a background thread, so RenderStyle is not available. | |
337 // Nevertheless, we can evaluate length MQs with em, rem or px units. | |
338 // FIXME: Learn to support more units here, or teach CSSPrimitiveValue about MediaValues. | |
339 unsigned short type = primitiveValue->primitiveType(); | |
340 int factor = 0; | |
341 if (type == CSSPrimitiveValue::CSS_EMS || type == CSSPrimitiveValue::CSS_REM S) { | |
342 if (defaultFontSize > 0) | |
343 factor = defaultFontSize; | |
344 else | |
345 return false; | |
346 } else if (type == CSSPrimitiveValue::CSS_PX) { | |
347 factor = 1; | |
348 } else { | |
349 return false; | |
350 } | |
351 result = roundForImpreciseConversion<int>(primitiveValue->getDoubleValue()*f actor); | |
352 return true; | |
353 } | |
354 | |
355 static bool computeLength(CSSValue* value, bool strict, RenderStyle* initialStyl e, int defaultFontSize, int& result) | |
356 { | 335 { |
357 if (!value->isPrimitiveValue()) | 336 if (!value->isPrimitiveValue()) |
358 return false; | 337 return false; |
359 | 338 |
360 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); | 339 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); |
361 | 340 |
362 if (primitiveValue->isNumber()) { | 341 if (primitiveValue->isNumber()) { |
363 result = primitiveValue->getIntValue(); | 342 result = primitiveValue->getIntValue(); |
364 return !strict || !result; | 343 return !mediaValues.strictMode() || !result; |
365 } | 344 } |
366 | 345 |
367 if (primitiveValue->isLength()) { | 346 if (primitiveValue->isLength()) { |
368 if (initialStyle) { | 347 if (mediaValues.style()) { |
369 // Relative (like EM) and root relative (like REM) units are always resolved against | 348 // Relative (like EM) and root relative (like REM) units are always resolved against |
370 // the initial values for media queries, hence the two initialStyle parameters. | 349 // the initial values for media queries, hence the two initialStyle parameters. |
371 // FIXME: We need to plumb viewport unit support down to here. | 350 // FIXME: We need to plumb viewport unit support down to here. |
372 result = primitiveValue->computeLength<int>(CSSToLengthConversionDat a(initialStyle, initialStyle, 0, 1.0 /* zoom */, true /* computingFontSize */)); | 351 result = primitiveValue->computeLength<int>(CSSToLengthConversionDat a(mediaValues.style(), mediaValues.style(), 0, 1.0 /* zoom */, true /* computing FontSize */)); |
eseidel
2014/04/08 16:51:28
Any time we have to comment args like this we shou
| |
373 } else { | 352 } else { |
374 return computeLengthWithoutStyle(primitiveValue, defaultFontSize, re sult); | 353 result = primitiveValue->computeLength<int>(CSSToLengthConversionDat a(&mediaValues, 1.0 /* zoom */, true /* computingFontSize */)); |
375 } | 354 } |
376 return true; | 355 return true; |
377 } | 356 } |
378 | 357 |
379 return false; | 358 return false; |
380 } | 359 } |
381 | 360 |
382 static bool deviceHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) | 361 static bool deviceHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) |
383 { | 362 { |
384 if (value) { | 363 if (value) { |
385 int length; | 364 int length; |
386 return computeLength(value, mediaValues.strictMode(), mediaValues.style( ), mediaValues.defaultFontSize(), length) | 365 return computeLength(value, mediaValues, length) |
387 && compareValue(static_cast<int>(mediaValues.deviceHeight()), length , op); | 366 && compareValue(static_cast<int>(mediaValues.deviceHeight()), length , op); |
388 } | 367 } |
389 // ({,min-,max-}device-height) | 368 // ({,min-,max-}device-height) |
390 // assume if we have a device, assume non-zero | 369 // assume if we have a device, assume non-zero |
391 return true; | 370 return true; |
392 } | 371 } |
393 | 372 |
394 static bool deviceWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) | 373 static bool deviceWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) |
395 { | 374 { |
396 if (value) { | 375 if (value) { |
397 int length; | 376 int length; |
398 return computeLength(value, mediaValues.strictMode(), mediaValues.style( ), mediaValues.defaultFontSize(), length) | 377 return computeLength(value, mediaValues, length) |
399 && compareValue(static_cast<int>(mediaValues.deviceWidth()), length, op); | 378 && compareValue(static_cast<int>(mediaValues.deviceWidth()), length, op); |
400 } | 379 } |
401 // ({,min-,max-}device-width) | 380 // ({,min-,max-}device-width) |
402 // assume if we have a device, assume non-zero | 381 // assume if we have a device, assume non-zero |
403 return true; | 382 return true; |
404 } | 383 } |
405 | 384 |
406 static bool heightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) | 385 static bool heightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) |
407 { | 386 { |
408 int height = mediaValues.viewportHeight(); | 387 int height = mediaValues.viewportHeight(); |
409 if (value) { | 388 if (value) { |
410 int length; | 389 int length; |
411 return computeLength(value, mediaValues.strictMode(), mediaValues.style( ), mediaValues.defaultFontSize(), length) | 390 return computeLength(value, mediaValues, length) |
412 && compareValue(height, length, op); | 391 && compareValue(height, length, op); |
413 } | 392 } |
414 | 393 |
415 return height; | 394 return height; |
416 } | 395 } |
417 | 396 |
418 static bool widthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) | 397 static bool widthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) |
419 { | 398 { |
420 int width = mediaValues.viewportWidth(); | 399 int width = mediaValues.viewportWidth(); |
421 if (value) { | 400 if (value) { |
422 int length; | 401 int length; |
423 return computeLength(value, mediaValues.strictMode(), mediaValues.style( ), mediaValues.defaultFontSize(), length) | 402 return computeLength(value, mediaValues, length) |
424 && compareValue(width, length, op); | 403 && compareValue(width, length, op); |
425 } | 404 } |
426 | 405 |
427 return width; | 406 return width; |
428 } | 407 } |
429 | 408 |
430 // Rest of the functions are trampolines which set the prefix according to the m edia feature expression used. | 409 // Rest of the functions are trampolines which set the prefix according to the m edia feature expression used. |
431 | 410 |
432 static bool minColorMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) | 411 static bool minColorMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
433 { | 412 { |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 // Call the media feature evaluation function. Assume no prefix and let | 654 // Call the media feature evaluation function. Assume no prefix and let |
676 // trampoline functions override the prefix if prefix is used. | 655 // trampoline functions override the prefix if prefix is used. |
677 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); | 656 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); |
678 if (func) | 657 if (func) |
679 return func(expr->value(), NoPrefix, *m_mediaValues); | 658 return func(expr->value(), NoPrefix, *m_mediaValues); |
680 | 659 |
681 return false; | 660 return false; |
682 } | 661 } |
683 | 662 |
684 } // namespace | 663 } // namespace |
OLD | NEW |