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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/MediaQueryEvaluatorTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/css/MediaQueryEvaluator.cpp
diff --git a/third_party/WebKit/Source/core/css/MediaQueryEvaluator.cpp b/third_party/WebKit/Source/core/css/MediaQueryEvaluator.cpp
index 92f06db9a7cd19e5f68faa2f22a832b5fd6ecfd7..d720cb9a4023bee2e26f68e48029a854900b731a 100644
--- a/third_party/WebKit/Source/core/css/MediaQueryEvaluator.cpp
+++ b/third_party/WebKit/Source/core/css/MediaQueryEvaluator.cpp
@@ -173,6 +173,20 @@ bool compareValue(T a, T b, MediaFeaturePrefix op)
return false;
}
+bool compareDoubleValue(double a, double b, MediaFeaturePrefix op)
+{
+ const double precision = std::numeric_limits<double>::epsilon();
+ switch (op) {
+ case MinPrefix:
+ return a >= (b - precision);
+ case MaxPrefix:
+ return a <= (b + precision);
+ case NoPrefix:
+ return std::abs(a - b) <= precision;
+ }
+ return false;
+}
+
static bool compareAspectRatioValue(const MediaQueryExpValue& value, int width, int height, MediaFeaturePrefix op)
{
if (value.isRatio)
@@ -374,7 +388,7 @@ static bool computeLength(const MediaQueryExpValue& value, const MediaValues& me
static bool computeLengthAndCompare(const MediaQueryExpValue& value, MediaFeaturePrefix op, const MediaValues& mediaValues, double compareToValue)
{
double length;
- return computeLength(value, mediaValues, length) && compareValue(compareToValue, length, op);
+ return computeLength(value, mediaValues, length) && compareDoubleValue(compareToValue, length, op);
}
static bool deviceHeightMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePrefix op, const MediaValues& mediaValues)
« 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