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

Unified Diff: Source/core/css/MediaQueryEvaluator.cpp

Issue 240063003: Revert "A sizes attribute parser" (https://codereview.chromium.org/224733011) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | « Source/core/css/CSSPrimitiveValue.cpp ('k') | 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 a3b217793705074828d7ecc8b981047e28ee6c00..c44036ff8060f63c5377ff19a55505e6630220a6 100644
--- a/Source/core/css/MediaQueryEvaluator.cpp
+++ b/Source/core/css/MediaQueryEvaluator.cpp
@@ -40,7 +40,7 @@
#include "core/css/CSSToLengthConversionData.h"
#include "core/css/MediaList.h"
#include "core/css/MediaQuery.h"
-#include "core/css/MediaValuesDynamic.h"
+#include "core/css/MediaValues.h"
#include "core/css/resolver/MediaQueryResult.h"
#include "core/dom/NodeRenderStyle.h"
#include "core/frame/FrameHost.h"
@@ -85,7 +85,7 @@ MediaQueryEvaluator::MediaQueryEvaluator(const char* acceptedMediaType, bool med
MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, LocalFrame* frame, RenderStyle* style)
: m_mediaType(acceptedMediaType)
, m_expectedResult(false) // Doesn't matter when we have m_frame and m_style.
- , m_mediaValues(MediaValuesDynamic::create(frame, style))
+ , m_mediaValues(MediaValues::create(frame, style, MediaValues::DynamicMode))
{
}
@@ -331,7 +331,28 @@ static bool gridMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const M
return false;
}
-static bool computeLength(CSSValue* value, const MediaValues& mediaValues, int& result)
+static bool computeLengthWithoutStyle(CSSPrimitiveValue* primitiveValue, int defaultFontSize, int& result)
+{
+ // We're running in a background thread, so RenderStyle is not available.
+ // Nevertheless, we can evaluate length MQs with em, rem or px units.
+ // FIXME: Learn to support more units here, or teach CSSPrimitiveValue about MediaValues.
+ unsigned short type = primitiveValue->primitiveType();
+ int factor = 0;
+ if (type == CSSPrimitiveValue::CSS_EMS || type == CSSPrimitiveValue::CSS_REMS) {
+ if (defaultFontSize > 0)
+ factor = defaultFontSize;
+ else
+ return false;
+ } else if (type == CSSPrimitiveValue::CSS_PX) {
+ factor = 1;
+ } else {
+ return false;
+ }
+ result = roundForImpreciseConversion<int>(primitiveValue->getDoubleValue()*factor);
+ return true;
+}
+
+static bool computeLength(CSSValue* value, bool strict, RenderStyle* initialStyle, int defaultFontSize, int& result)
{
if (!value->isPrimitiveValue())
return false;
@@ -340,11 +361,20 @@ static bool computeLength(CSSValue* value, const MediaValues& mediaValues, int&
if (primitiveValue->isNumber()) {
result = primitiveValue->getIntValue();
- return !mediaValues.strictMode() || !result;
+ return !strict || !result;
}
- if (primitiveValue->isLength())
- return mediaValues.computeLength(primitiveValue->getDoubleValue(), primitiveValue->primitiveType(), result);
+ if (primitiveValue->isLength()) {
+ if (initialStyle) {
+ // Relative (like EM) and root relative (like REM) units are always resolved against
+ // the initial values for media queries, hence the two initialStyle parameters.
+ // FIXME: We need to plumb viewport unit support down to here.
+ result = primitiveValue->computeLength<int>(CSSToLengthConversionData(initialStyle, initialStyle, 0, 1.0 /* zoom */, true /* computingFontSize */));
+ } else {
+ return computeLengthWithoutStyle(primitiveValue, defaultFontSize, result);
+ }
+ return true;
+ }
return false;
}
@@ -353,7 +383,8 @@ static bool deviceHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op,
{
if (value) {
int length;
- return computeLength(value, mediaValues, length) && compareValue(static_cast<int>(mediaValues.deviceHeight()), length, op);
+ return computeLength(value, mediaValues.strictMode(), mediaValues.style(), mediaValues.defaultFontSize(), length)
+ && compareValue(static_cast<int>(mediaValues.deviceHeight()), length, op);
}
// ({,min-,max-}device-height)
// assume if we have a device, assume non-zero
@@ -364,7 +395,8 @@ static bool deviceWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op,
{
if (value) {
int length;
- return computeLength(value, mediaValues, length) && compareValue(static_cast<int>(mediaValues.deviceWidth()), length, op);
+ return computeLength(value, mediaValues.strictMode(), mediaValues.style(), mediaValues.defaultFontSize(), length)
+ && compareValue(static_cast<int>(mediaValues.deviceWidth()), length, op);
}
// ({,min-,max-}device-width)
// assume if we have a device, assume non-zero
@@ -376,7 +408,8 @@ static bool heightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const
int height = mediaValues.viewportHeight();
if (value) {
int length;
- return computeLength(value, mediaValues, length) && compareValue(height, length, op);
+ return computeLength(value, mediaValues.strictMode(), mediaValues.style(), mediaValues.defaultFontSize(), length)
+ && compareValue(height, length, op);
}
return height;
@@ -387,7 +420,8 @@ static bool widthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const
int width = mediaValues.viewportWidth();
if (value) {
int length;
- return computeLength(value, mediaValues, length) && compareValue(width, length, op);
+ return computeLength(value, mediaValues.strictMode(), mediaValues.style(), mediaValues.defaultFontSize(), length)
+ && compareValue(width, length, op);
}
return width;
@@ -632,7 +666,7 @@ static void createFunctionMap()
bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const
{
- if (!m_mediaValues || !m_mediaValues->hasValues())
+ if (!m_mediaValues)
return m_expectedResult;
if (!gFunctionMap)
« no previous file with comments | « Source/core/css/CSSPrimitiveValue.cpp ('k') | Source/core/css/MediaQueryEvaluatorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698