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

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

Issue 335313003: MediaQueryEvaluator getting mediaType from MediaValues (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed a bug and added tests Created 6 years, 6 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
Index: Source/core/css/MediaQueryEvaluator.cpp
diff --git a/Source/core/css/MediaQueryEvaluator.cpp b/Source/core/css/MediaQueryEvaluator.cpp
index 90c28183a7406df21179b465971eb9ff19aae990..4f30e7bbd8fcbce21cb77c83a95ff3589b17f3a0 100644
--- a/Source/core/css/MediaQueryEvaluator.cpp
+++ b/Source/core/css/MediaQueryEvaluator.cpp
@@ -71,28 +71,20 @@ MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult)
{
}
-MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, bool mediaFeatureResult)
- : m_mediaType(acceptedMediaType)
- , m_expectedResult(mediaFeatureResult)
-{
-}
-
MediaQueryEvaluator::MediaQueryEvaluator(const char* acceptedMediaType, bool mediaFeatureResult)
: m_mediaType(acceptedMediaType)
, m_expectedResult(mediaFeatureResult)
{
}
-MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, LocalFrame* frame)
- : m_mediaType(acceptedMediaType)
- , m_expectedResult(false) // Doesn't matter when we have m_frame and m_style.
+MediaQueryEvaluator::MediaQueryEvaluator(LocalFrame* frame)
+ : m_expectedResult(false) // Doesn't matter when we have m_frame and m_style.
, m_mediaValues(MediaValues::createDynamicIfFrameExists(frame))
{
}
-MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, const MediaValues& mediaValues)
- : m_mediaType(acceptedMediaType)
- , m_expectedResult(false) // Doesn't matter when we have mediaValues.
+MediaQueryEvaluator::MediaQueryEvaluator(const MediaValues& mediaValues)
+ : m_expectedResult(false) // Doesn't matter when we have mediaValues.
, m_mediaValues(mediaValues.copy())
{
}
@@ -101,11 +93,20 @@ MediaQueryEvaluator::~MediaQueryEvaluator()
{
}
+const String MediaQueryEvaluator::mediaType() const
+{
+ if (!m_mediaType.isEmpty())
+ return m_mediaType;
+ if (m_mediaValues.get())
esprehn 2014/06/27 08:10:32 You don't need to call .get(), there's an overload
+ return m_mediaValues->mediaType();
+ return nullAtom;
+}
+
bool MediaQueryEvaluator::mediaTypeMatch(const String& mediaTypeToMatch) const
{
return mediaTypeToMatch.isEmpty()
|| equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all)
- || equalIgnoringCase(mediaTypeToMatch, m_mediaType);
+ || equalIgnoringCase(mediaTypeToMatch, mediaType());
}
bool MediaQueryEvaluator::mediaTypeMatchSpecific(const char* mediaTypeToMatch) const
@@ -114,7 +115,7 @@ bool MediaQueryEvaluator::mediaTypeMatchSpecific(const char* mediaTypeToMatch) c
ASSERT(mediaTypeToMatch);
ASSERT(mediaTypeToMatch[0] != '\0');
ASSERT(!equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all));
- return equalIgnoringCase(mediaTypeToMatch, m_mediaType);
+ return equalIgnoringCase(mediaTypeToMatch, mediaType());
}
static bool applyRestrictor(MediaQuery::Restrictor r, bool value)
@@ -269,9 +270,9 @@ static bool evalResolution(const MediaQueryExpValue& value, MediaFeaturePrefix o
// this method only got called if this media type matches the one defined
// in the query. Thus, if if the document's media type is "print", the
// media type of the query will either be "print" or "all".
- if (mediaValues.screenMediaType()) {
+ if (equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::screen)) {
actualResolution = clampTo<float>(mediaValues.devicePixelRatio());
- } else if (mediaValues.printMediaType()) {
+ } else if (equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::print)) {
// The resolution of images while printing should not depend on the DPI
// of the screen. Until we support proper ways of querying this info
// we use 300px which is considered minimum for current printers.
@@ -567,7 +568,8 @@ static bool pointerMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatur
static bool scanMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePrefix, const MediaValues& mediaValues)
{
- if (!mediaValues.scanMediaType())
+ // Scan only applies to 'tv' media.
+ if (!equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::tv))
return false;
if (!value.isValid())

Powered by Google App Engine
This is Rietveld 408576698