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

Unified 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: Brought everything back to double. DRYed up computeLength calls. Added tests. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/core/css/MediaQueryEvaluatorTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/MediaQueryEvaluator.cpp
diff --git a/Source/core/css/MediaQueryEvaluator.cpp b/Source/core/css/MediaQueryEvaluator.cpp
index 7a3b245983d1403c1591a3c0bace57dad15ab948..1e803c4cb6adbf2a8d9dcc2e8a75c1d50b163d98 100644
--- a/Source/core/css/MediaQueryEvaluator.cpp
+++ b/Source/core/css/MediaQueryEvaluator.cpp
@@ -326,7 +326,7 @@ static bool gridMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePr
return false;
}
-static bool computeLength(const MediaQueryExpValue& value, const MediaValues& mediaValues, int& result)
+static bool computeLength(const MediaQueryExpValue& value, const MediaValues& mediaValues, double& result)
{
if (!value.isValue)
return false;
@@ -341,12 +341,17 @@ static bool computeLength(const MediaQueryExpValue& value, const MediaValues& me
return false;
}
+static bool computeLengthAndCompare(const MediaQueryExpValue& value, MediaFeaturePrefix op, const MediaValues& mediaValues, double compareToValue)
+{
+ double length;
+ return computeLength(value, mediaValues, length) && compareValue(compareToValue, length, op);
+}
+
static bool deviceHeightMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePrefix op, const MediaValues& mediaValues)
{
- if (value.isValid()) {
- int length;
- return computeLength(value, mediaValues, length) && compareValue(static_cast<int>(mediaValues.deviceHeight()), length, op);
- }
+ if (value.isValid())
+ return computeLengthAndCompare(value, op, mediaValues, mediaValues.deviceHeight());
+
// ({,min-,max-}device-height)
// assume if we have a device, assume non-zero
return true;
@@ -354,10 +359,9 @@ static bool deviceHeightMediaFeatureEval(const MediaQueryExpValue& value, MediaF
static bool deviceWidthMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePrefix op, const MediaValues& mediaValues)
{
- if (value.isValid()) {
- int length;
- return computeLength(value, mediaValues, length) && compareValue(static_cast<int>(mediaValues.deviceWidth()), length, op);
- }
+ if (value.isValid())
+ return computeLengthAndCompare(value, op, mediaValues, mediaValues.deviceWidth());
+
// ({,min-,max-}device-width)
// assume if we have a device, assume non-zero
return true;
@@ -366,10 +370,8 @@ static bool deviceWidthMediaFeatureEval(const MediaQueryExpValue& value, MediaFe
static bool heightMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePrefix op, const MediaValues& mediaValues)
{
int height = mediaValues.viewportHeight();
- if (value.isValid()) {
- int length;
- return computeLength(value, mediaValues, length) && compareValue(height, length, op);
- }
+ if (value.isValid())
+ return computeLengthAndCompare(value, op, mediaValues, height);
return height;
}
@@ -377,10 +379,8 @@ static bool heightMediaFeatureEval(const MediaQueryExpValue& value, MediaFeature
static bool widthMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePrefix op, const MediaValues& mediaValues)
{
int width = mediaValues.viewportWidth();
- if (value.isValid()) {
- int length;
- return computeLength(value, mediaValues, length) && compareValue(width, length, op);
- }
+ if (value.isValid())
+ return computeLengthAndCompare(value, op, mediaValues, width);
return width;
}
« no previous file with comments | « no previous file | Source/core/css/MediaQueryEvaluatorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698