Chromium Code Reviews| 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* style, 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 result = primitiveValue->computeLength<int>(style, style, 1.0 /* multipl ier */, true /* computingFontSize */); |
|
kenneth.r.christiansen
2013/08/07 10:49:28
Could we add some /* */ to know what it means, esp
rune
2013/08/07 11:46:09
Done.
| |
| 354 return true; | 354 return true; |
| 355 } | 355 } |
| 356 | 356 |
| 357 return false; | 357 return false; |
| 358 } | 358 } |
| 359 | 359 |
| 360 static bool deviceHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, Fr ame* frame, MediaFeaturePrefix op) | 360 static bool deviceHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, Fr ame* frame, MediaFeaturePrefix op) |
| 361 { | 361 { |
| 362 if (value) { | 362 if (value) { |
| 363 FloatRect sg = screenRect(frame->page()->mainFrame()->view()); | 363 FloatRect sg = screenRect(frame->page()->mainFrame()->view()); |
| 364 RenderStyle* rootStyle = frame->document()->documentElement()->renderSty le(); | |
| 365 int length; | 364 int length; |
| 366 long height = sg.height(); | 365 long height = sg.height(); |
| 367 InspectorInstrumentation::applyScreenHeightOverride(frame, &height); | 366 InspectorInstrumentation::applyScreenHeightOverride(frame, &height); |
| 368 return computeLength(value, !frame->document()->inQuirksMode(), style, r ootStyle, length) && compareValue(static_cast<int>(height), length, op); | 367 return computeLength(value, !frame->document()->inQuirksMode(), style, l ength) && compareValue(static_cast<int>(height), length, op); |
| 369 } | 368 } |
| 370 // ({,min-,max-}device-height) | 369 // ({,min-,max-}device-height) |
| 371 // assume if we have a device, assume non-zero | 370 // assume if we have a device, assume non-zero |
| 372 return true; | 371 return true; |
| 373 } | 372 } |
| 374 | 373 |
| 375 static bool deviceWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, Fra me* frame, MediaFeaturePrefix op) | 374 static bool deviceWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, Fra me* frame, MediaFeaturePrefix op) |
| 376 { | 375 { |
| 377 if (value) { | 376 if (value) { |
| 378 FloatRect sg = screenRect(frame->page()->mainFrame()->view()); | 377 FloatRect sg = screenRect(frame->page()->mainFrame()->view()); |
| 379 RenderStyle* rootStyle = frame->document()->documentElement()->renderSty le(); | |
| 380 int length; | 378 int length; |
| 381 long width = sg.width(); | 379 long width = sg.width(); |
| 382 InspectorInstrumentation::applyScreenWidthOverride(frame, &width); | 380 InspectorInstrumentation::applyScreenWidthOverride(frame, &width); |
| 383 return computeLength(value, !frame->document()->inQuirksMode(), style, r ootStyle, length) && compareValue(static_cast<int>(width), length, op); | 381 return computeLength(value, !frame->document()->inQuirksMode(), style, l ength) && compareValue(static_cast<int>(width), length, op); |
| 384 } | 382 } |
| 385 // ({,min-,max-}device-width) | 383 // ({,min-,max-}device-width) |
| 386 // assume if we have a device, assume non-zero | 384 // assume if we have a device, assume non-zero |
| 387 return true; | 385 return true; |
| 388 } | 386 } |
| 389 | 387 |
| 390 static bool heightMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* f rame, MediaFeaturePrefix op) | 388 static bool heightMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* f rame, MediaFeaturePrefix op) |
| 391 { | 389 { |
| 392 FrameView* view = frame->view(); | 390 FrameView* view = frame->view(); |
| 393 | 391 |
| 394 int height = viewportSize(view).height(); | 392 int height = viewportSize(view).height(); |
| 395 if (value) { | 393 if (value) { |
| 396 if (RenderView* renderView = frame->document()->renderView()) | 394 if (RenderView* renderView = frame->document()->renderView()) |
| 397 height = adjustForAbsoluteZoom(height, renderView); | 395 height = adjustForAbsoluteZoom(height, renderView); |
| 398 RenderStyle* rootStyle = frame->document()->documentElement()->renderSty le(); | |
| 399 int length; | 396 int length; |
| 400 return computeLength(value, !frame->document()->inQuirksMode(), style, r ootStyle, length) && compareValue(height, length, op); | 397 return computeLength(value, !frame->document()->inQuirksMode(), style, l ength) && compareValue(height, length, op); |
| 401 } | 398 } |
| 402 | 399 |
| 403 return height; | 400 return height; |
| 404 } | 401 } |
| 405 | 402 |
| 406 static bool widthMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* fr ame, MediaFeaturePrefix op) | 403 static bool widthMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* fr ame, MediaFeaturePrefix op) |
| 407 { | 404 { |
| 408 FrameView* view = frame->view(); | 405 FrameView* view = frame->view(); |
| 409 | 406 |
| 410 int width = viewportSize(view).width(); | 407 int width = viewportSize(view).width(); |
| 411 if (value) { | 408 if (value) { |
| 412 if (RenderView* renderView = frame->document()->renderView()) | 409 if (RenderView* renderView = frame->document()->renderView()) |
| 413 width = adjustForAbsoluteZoom(width, renderView); | 410 width = adjustForAbsoluteZoom(width, renderView); |
| 414 RenderStyle* rootStyle = frame->document()->documentElement()->renderSty le(); | |
| 415 int length; | 411 int length; |
| 416 return computeLength(value, !frame->document()->inQuirksMode(), style, r ootStyle, length) && compareValue(width, length, op); | 412 return computeLength(value, !frame->document()->inQuirksMode(), style, l ength) && compareValue(width, length, op); |
| 417 } | 413 } |
| 418 | 414 |
| 419 return width; | 415 return width; |
| 420 } | 416 } |
| 421 | 417 |
| 422 // rest of the functions are trampolines which set the prefix according to the m edia feature expression used | 418 // rest of the functions are trampolines which set the prefix according to the m edia feature expression used |
| 423 | 419 |
| 424 static bool minColorMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* frame, MediaFeaturePrefix) | 420 static bool minColorMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* frame, MediaFeaturePrefix) |
| 425 { | 421 { |
| 426 return colorMediaFeatureEval(value, style, frame, MinPrefix); | 422 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 | 684 // and let trampoline functions override the prefix if prefix is |
| 689 // used | 685 // used |
| 690 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); | 686 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); |
| 691 if (func) | 687 if (func) |
| 692 return func(expr->value(), m_style.get(), m_frame, NoPrefix); | 688 return func(expr->value(), m_style.get(), m_frame, NoPrefix); |
| 693 | 689 |
| 694 return false; | 690 return false; |
| 695 } | 691 } |
| 696 | 692 |
| 697 } // namespace | 693 } // namespace |
| OLD | NEW |