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

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

Issue 1904523002: Fix double comparisons for Media Queries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unreachable build error Created 4 years, 8 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/MediaQueryEvaluatorTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 case MinPrefix: 166 case MinPrefix:
167 return a >= b; 167 return a >= b;
168 case MaxPrefix: 168 case MaxPrefix:
169 return a <= b; 169 return a <= b;
170 case NoPrefix: 170 case NoPrefix:
171 return a == b; 171 return a == b;
172 } 172 }
173 return false; 173 return false;
174 } 174 }
175 175
176 bool compareDoubleValue(double a, double b, MediaFeaturePrefix op)
177 {
178 const double precision = std::numeric_limits<double>::epsilon();
179 switch (op) {
180 case MinPrefix:
181 return a >= (b - precision);
182 case MaxPrefix:
183 return a <= (b + precision);
184 case NoPrefix:
185 return std::abs(a - b) <= precision;
186 }
187 return false;
188 }
189
176 static bool compareAspectRatioValue(const MediaQueryExpValue& value, int width, int height, MediaFeaturePrefix op) 190 static bool compareAspectRatioValue(const MediaQueryExpValue& value, int width, int height, MediaFeaturePrefix op)
177 { 191 {
178 if (value.isRatio) 192 if (value.isRatio)
179 return compareValue(width * static_cast<int>(value.denominator), height * static_cast<int>(value.numerator), op); 193 return compareValue(width * static_cast<int>(value.denominator), height * static_cast<int>(value.numerator), op);
180 194
181 return false; 195 return false;
182 } 196 }
183 197
184 static bool numberValue(const MediaQueryExpValue& value, float& result) 198 static bool numberValue(const MediaQueryExpValue& value, float& result)
185 { 199 {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 381 }
368 382
369 if (CSSPrimitiveValue::isLength(value.unit)) 383 if (CSSPrimitiveValue::isLength(value.unit))
370 return mediaValues.computeLength(value.value, value.unit, result); 384 return mediaValues.computeLength(value.value, value.unit, result);
371 return false; 385 return false;
372 } 386 }
373 387
374 static bool computeLengthAndCompare(const MediaQueryExpValue& value, MediaFeatur ePrefix op, const MediaValues& mediaValues, double compareToValue) 388 static bool computeLengthAndCompare(const MediaQueryExpValue& value, MediaFeatur ePrefix op, const MediaValues& mediaValues, double compareToValue)
375 { 389 {
376 double length; 390 double length;
377 return computeLength(value, mediaValues, length) && compareValue(compareToVa lue, length, op); 391 return computeLength(value, mediaValues, length) && compareDoubleValue(compa reToValue, length, op);
378 } 392 }
379 393
380 static bool deviceHeightMediaFeatureEval(const MediaQueryExpValue& value, MediaF eaturePrefix op, const MediaValues& mediaValues) 394 static bool deviceHeightMediaFeatureEval(const MediaQueryExpValue& value, MediaF eaturePrefix op, const MediaValues& mediaValues)
381 { 395 {
382 if (value.isValid()) 396 if (value.isValid())
383 return computeLengthAndCompare(value, op, mediaValues, mediaValues.devic eHeight()); 397 return computeLengthAndCompare(value, op, mediaValues, mediaValues.devic eHeight());
384 398
385 // ({,min-,max-}device-height) 399 // ({,min-,max-}device-height)
386 // assume if we have a device, assume non-zero 400 // assume if we have a device, assume non-zero
387 return true; 401 return true;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 // Call the media feature evaluation function. Assume no prefix and let 679 // Call the media feature evaluation function. Assume no prefix and let
666 // trampoline functions override the prefix if prefix is used. 680 // trampoline functions override the prefix if prefix is used.
667 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); 681 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl());
668 if (func) 682 if (func)
669 return func(expr->expValue(), NoPrefix, *m_mediaValues); 683 return func(expr->expValue(), NoPrefix, *m_mediaValues);
670 684
671 return false; 685 return false;
672 } 686 }
673 687
674 } // namespace blink 688 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/MediaQueryEvaluatorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698