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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 static bool gridMediaFeatureEval(CSSValue* value, RenderStyle*, Frame*, MediaFea
turePrefix op) | 330 static bool gridMediaFeatureEval(CSSValue* value, RenderStyle*, Frame*, MediaFea
turePrefix op) |
331 { | 331 { |
332 // if output device is bitmap, grid: 0 == true | 332 // if output device is bitmap, grid: 0 == true |
333 // assume we have bitmap device | 333 // assume we have bitmap device |
334 float number; | 334 float number; |
335 if (value && numberValue(value, number)) | 335 if (value && numberValue(value, number)) |
336 return compareValue(static_cast<int>(number), 0, op); | 336 return compareValue(static_cast<int>(number), 0, op); |
337 return false; | 337 return false; |
338 } | 338 } |
339 | 339 |
340 static bool computeLength(CSSValue* value, bool strict, RenderStyle* style, Rend
erStyle* rootStyle, int& result) | 340 static bool computeLength(CSSValue* value, bool strict, RenderStyle* initialStyl
e, int& result) |
341 { | 341 { |
342 if (!value->isPrimitiveValue()) | 342 if (!value->isPrimitiveValue()) |
343 return false; | 343 return false; |
344 | 344 |
345 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); | 345 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); |
346 | 346 |
347 if (primitiveValue->isNumber()) { | 347 if (primitiveValue->isNumber()) { |
348 result = primitiveValue->getIntValue(); | 348 result = primitiveValue->getIntValue(); |
349 return !strict || !result; | 349 return !strict || !result; |
350 } | 350 } |
351 | 351 |
352 if (primitiveValue->isLength()) { | 352 if (primitiveValue->isLength()) { |
353 result = primitiveValue->computeLength<int>(style, rootStyle, 1.0 /* mul
tiplier */, true /* computingFontSize */); | 353 // Relative (like EM) and root relative (like REM) units are always reso
lved against the initial values |
| 354 // for media queries, hence the two initialStyle parameters. |
| 355 result = primitiveValue->computeLength<int>(initialStyle, initialStyle,
1.0 /* multiplier */, true /* computingFontSize */); |
354 return true; | 356 return true; |
355 } | 357 } |
356 | 358 |
357 return false; | 359 return false; |
358 } | 360 } |
359 | 361 |
360 static bool deviceHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, Fr
ame* frame, MediaFeaturePrefix op) | 362 static bool deviceHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, Fr
ame* frame, MediaFeaturePrefix op) |
361 { | 363 { |
362 if (value) { | 364 if (value) { |
363 FloatRect sg = screenRect(frame->page()->mainFrame()->view()); | 365 FloatRect sg = screenRect(frame->page()->mainFrame()->view()); |
364 RenderStyle* rootStyle = frame->document()->documentElement()->renderSty
le(); | |
365 int length; | 366 int length; |
366 long height = sg.height(); | 367 long height = sg.height(); |
367 InspectorInstrumentation::applyScreenHeightOverride(frame, &height); | 368 InspectorInstrumentation::applyScreenHeightOverride(frame, &height); |
368 return computeLength(value, !frame->document()->inQuirksMode(), style, r
ootStyle, length) && compareValue(static_cast<int>(height), length, op); | 369 return computeLength(value, !frame->document()->inQuirksMode(), style, l
ength) && compareValue(static_cast<int>(height), length, op); |
369 } | 370 } |
370 // ({,min-,max-}device-height) | 371 // ({,min-,max-}device-height) |
371 // assume if we have a device, assume non-zero | 372 // assume if we have a device, assume non-zero |
372 return true; | 373 return true; |
373 } | 374 } |
374 | 375 |
375 static bool deviceWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, Fra
me* frame, MediaFeaturePrefix op) | 376 static bool deviceWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, Fra
me* frame, MediaFeaturePrefix op) |
376 { | 377 { |
377 if (value) { | 378 if (value) { |
378 FloatRect sg = screenRect(frame->page()->mainFrame()->view()); | 379 FloatRect sg = screenRect(frame->page()->mainFrame()->view()); |
379 RenderStyle* rootStyle = frame->document()->documentElement()->renderSty
le(); | |
380 int length; | 380 int length; |
381 long width = sg.width(); | 381 long width = sg.width(); |
382 InspectorInstrumentation::applyScreenWidthOverride(frame, &width); | 382 InspectorInstrumentation::applyScreenWidthOverride(frame, &width); |
383 return computeLength(value, !frame->document()->inQuirksMode(), style, r
ootStyle, length) && compareValue(static_cast<int>(width), length, op); | 383 return computeLength(value, !frame->document()->inQuirksMode(), style, l
ength) && compareValue(static_cast<int>(width), length, op); |
384 } | 384 } |
385 // ({,min-,max-}device-width) | 385 // ({,min-,max-}device-width) |
386 // assume if we have a device, assume non-zero | 386 // assume if we have a device, assume non-zero |
387 return true; | 387 return true; |
388 } | 388 } |
389 | 389 |
390 static bool heightMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* f
rame, MediaFeaturePrefix op) | 390 static bool heightMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* f
rame, MediaFeaturePrefix op) |
391 { | 391 { |
392 FrameView* view = frame->view(); | 392 FrameView* view = frame->view(); |
393 | 393 |
394 int height = viewportSize(view).height(); | 394 int height = viewportSize(view).height(); |
395 if (value) { | 395 if (value) { |
396 if (RenderView* renderView = frame->document()->renderView()) | 396 if (RenderView* renderView = frame->document()->renderView()) |
397 height = adjustForAbsoluteZoom(height, renderView); | 397 height = adjustForAbsoluteZoom(height, renderView); |
398 RenderStyle* rootStyle = frame->document()->documentElement()->renderSty
le(); | |
399 int length; | 398 int length; |
400 return computeLength(value, !frame->document()->inQuirksMode(), style, r
ootStyle, length) && compareValue(height, length, op); | 399 return computeLength(value, !frame->document()->inQuirksMode(), style, l
ength) && compareValue(height, length, op); |
401 } | 400 } |
402 | 401 |
403 return height; | 402 return height; |
404 } | 403 } |
405 | 404 |
406 static bool widthMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* fr
ame, MediaFeaturePrefix op) | 405 static bool widthMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* fr
ame, MediaFeaturePrefix op) |
407 { | 406 { |
408 FrameView* view = frame->view(); | 407 FrameView* view = frame->view(); |
409 | 408 |
410 int width = viewportSize(view).width(); | 409 int width = viewportSize(view).width(); |
411 if (value) { | 410 if (value) { |
412 if (RenderView* renderView = frame->document()->renderView()) | 411 if (RenderView* renderView = frame->document()->renderView()) |
413 width = adjustForAbsoluteZoom(width, renderView); | 412 width = adjustForAbsoluteZoom(width, renderView); |
414 RenderStyle* rootStyle = frame->document()->documentElement()->renderSty
le(); | |
415 int length; | 413 int length; |
416 return computeLength(value, !frame->document()->inQuirksMode(), style, r
ootStyle, length) && compareValue(width, length, op); | 414 return computeLength(value, !frame->document()->inQuirksMode(), style, l
ength) && compareValue(width, length, op); |
417 } | 415 } |
418 | 416 |
419 return width; | 417 return width; |
420 } | 418 } |
421 | 419 |
422 // rest of the functions are trampolines which set the prefix according to the m
edia feature expression used | 420 // rest of the functions are trampolines which set the prefix according to the m
edia feature expression used |
423 | 421 |
424 static bool minColorMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame*
frame, MediaFeaturePrefix) | 422 static bool minColorMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame*
frame, MediaFeaturePrefix) |
425 { | 423 { |
426 return colorMediaFeatureEval(value, style, frame, MinPrefix); | 424 return colorMediaFeatureEval(value, style, frame, MinPrefix); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 // and let trampoline functions override the prefix if prefix is | 686 // and let trampoline functions override the prefix if prefix is |
689 // used | 687 // used |
690 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); | 688 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); |
691 if (func) | 689 if (func) |
692 return func(expr->value(), m_style.get(), m_frame, NoPrefix); | 690 return func(expr->value(), m_style.get(), m_frame, NoPrefix); |
693 | 691 |
694 return false; | 692 return false; |
695 } | 693 } |
696 | 694 |
697 } // namespace | 695 } // namespace |
OLD | NEW |