Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: Source/core/css/MediaQueryEvaluator.cpp

Issue 644813005: Floating point MQs should not match. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 static bool gridMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePr efix op, const MediaValues&) 319 static bool gridMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePr efix op, const MediaValues&)
320 { 320 {
321 // if output device is bitmap, grid: 0 == true 321 // if output device is bitmap, grid: 0 == true
322 // assume we have bitmap device 322 // assume we have bitmap device
323 float number; 323 float number;
324 if (value.isValid() && numberValue(value, number)) 324 if (value.isValid() && numberValue(value, number))
325 return compareValue(static_cast<int>(number), 0, op); 325 return compareValue(static_cast<int>(number), 0, op);
326 return false; 326 return false;
327 } 327 }
328 328
329 static bool computeLength(const MediaQueryExpValue& value, const MediaValues& me diaValues, int& result) 329 static bool computeLength(const MediaQueryExpValue& value, const MediaValues& me diaValues, float& result)
330 { 330 {
331 if (!value.isValue) 331 if (!value.isValue)
332 return false; 332 return false;
333 333
334 if (value.unit == CSSPrimitiveValue::CSS_NUMBER) { 334 if (value.unit == CSSPrimitiveValue::CSS_NUMBER) {
335 result = clampTo<int>(value.value); 335 result = clampTo<int>(value.value);
336 return !mediaValues.strictMode() || !result; 336 return !mediaValues.strictMode() || !result;
337 } 337 }
338 338
339 if (CSSPrimitiveValue::isLength(value.unit)) 339 if (CSSPrimitiveValue::isLength(value.unit))
340 return mediaValues.computeLength(value.value, value.unit, result); 340 return mediaValues.computeLength(value.value, value.unit, result);
341 return false; 341 return false;
342 } 342 }
343 343
344 static bool deviceHeightMediaFeatureEval(const MediaQueryExpValue& value, MediaF eaturePrefix op, const MediaValues& mediaValues) 344 static bool deviceHeightMediaFeatureEval(const MediaQueryExpValue& value, MediaF eaturePrefix op, const MediaValues& mediaValues)
345 { 345 {
346 if (value.isValid()) { 346 if (value.isValid()) {
347 int length; 347 float length;
348 return computeLength(value, mediaValues, length) && compareValue(static_ cast<int>(mediaValues.deviceHeight()), length, op); 348 return computeLength(value, mediaValues, length) && compareValue(static_ cast<float>(mediaValues.deviceHeight()), length, op);
349 } 349 }
350 // ({,min-,max-}device-height) 350 // ({,min-,max-}device-height)
351 // assume if we have a device, assume non-zero 351 // assume if we have a device, assume non-zero
352 return true; 352 return true;
353 } 353 }
354 354
355 static bool deviceWidthMediaFeatureEval(const MediaQueryExpValue& value, MediaFe aturePrefix op, const MediaValues& mediaValues) 355 static bool deviceWidthMediaFeatureEval(const MediaQueryExpValue& value, MediaFe aturePrefix op, const MediaValues& mediaValues)
356 { 356 {
357 if (value.isValid()) { 357 if (value.isValid()) {
358 int length; 358 float length;
359 return computeLength(value, mediaValues, length) && compareValue(static_ cast<int>(mediaValues.deviceWidth()), length, op); 359 return computeLength(value, mediaValues, length) && compareValue(static_ cast<float>(mediaValues.deviceWidth()), length, op);
360 } 360 }
361 // ({,min-,max-}device-width) 361 // ({,min-,max-}device-width)
362 // assume if we have a device, assume non-zero 362 // assume if we have a device, assume non-zero
363 return true; 363 return true;
364 } 364 }
365 365
366 static bool heightMediaFeatureEval(const MediaQueryExpValue& value, MediaFeature Prefix op, const MediaValues& mediaValues) 366 static bool heightMediaFeatureEval(const MediaQueryExpValue& value, MediaFeature Prefix op, const MediaValues& mediaValues)
367 { 367 {
368 int height = mediaValues.viewportHeight(); 368 float height = mediaValues.viewportHeight();
369 if (value.isValid()) { 369 if (value.isValid()) {
370 int length; 370 float length;
371 return computeLength(value, mediaValues, length) && compareValue(height, length, op); 371 return computeLength(value, mediaValues, length) && compareValue(height, length, op);
372 } 372 }
373 373
374 return height; 374 return height;
375 } 375 }
376 376
377 static bool widthMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatureP refix op, const MediaValues& mediaValues) 377 static bool widthMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatureP refix op, const MediaValues& mediaValues)
378 { 378 {
379 int width = mediaValues.viewportWidth(); 379 float width = mediaValues.viewportWidth();
380 if (value.isValid()) { 380 if (value.isValid()) {
381 int length; 381 float length;
382 return computeLength(value, mediaValues, length) && compareValue(width, length, op); 382 return computeLength(value, mediaValues, length) && compareValue(width, length, op);
383 } 383 }
384 384
385 return width; 385 return width;
386 } 386 }
387 387
388 // Rest of the functions are trampolines which set the prefix according to the m edia feature expression used. 388 // Rest of the functions are trampolines which set the prefix according to the m edia feature expression used.
389 389
390 static bool minColorMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatu rePrefix, const MediaValues& mediaValues) 390 static bool minColorMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatu rePrefix, const MediaValues& mediaValues)
391 { 391 {
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 // Call the media feature evaluation function. Assume no prefix and let 653 // Call the media feature evaluation function. Assume no prefix and let
654 // trampoline functions override the prefix if prefix is used. 654 // trampoline functions override the prefix if prefix is used.
655 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); 655 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl());
656 if (func) 656 if (func)
657 return func(expr->expValue(), NoPrefix, *m_mediaValues); 657 return func(expr->expValue(), NoPrefix, *m_mediaValues);
658 658
659 return false; 659 return false;
660 } 660 }
661 661
662 } // namespace 662 } // namespace
OLDNEW
« no previous file with comments | « no previous file | Source/core/css/MediaQueryEvaluatorTest.cpp » ('j') | Source/core/css/MediaQueryEvaluatorTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698