#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
+#include "core/frame/UseCounter.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/compositing/RenderLayerCompositor.h"
#include "core/rendering/style/RenderStyle.h"
#include "platform/PlatformScreen.h"
+#include "platform/RuntimeEnabledFeatures.h"
#include "platform/geometry/FloatRect.h"
#include "wtf/HashMap.h"
-namespace WebCore {
+namespace blink {
using namespace MediaFeatureNames;
{
}
-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())
{
}
{
}
-bool MediaQueryEvaluator::mediaTypeMatch(const String& mediaTypeToMatch) const
+const String MediaQueryEvaluator::mediaType() const
{
- return mediaTypeToMatch.isEmpty()
- || equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all)
- || equalIgnoringCase(mediaTypeToMatch, m_mediaType);
+ // If a static mediaType was given by the constructor, we use it here.
+ if (!m_mediaType.isEmpty())
+ return m_mediaType;
+ // Otherwise, we get one from mediaValues (which may be dynamic or cached).
+ if (m_mediaValues)
+ return m_mediaValues->mediaType();
+ return nullAtom;
}
-bool MediaQueryEvaluator::mediaTypeMatchSpecific(const char* mediaTypeToMatch) const
+bool MediaQueryEvaluator::mediaTypeMatch(const String& mediaTypeToMatch) const
{
- // Like mediaTypeMatch, but without the special cases for "" and "all".
- ASSERT(mediaTypeToMatch);
- ASSERT(mediaTypeToMatch[0] != '\0');
- ASSERT(!equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all));
- return equalIgnoringCase(mediaTypeToMatch, m_mediaType);
+ return mediaTypeToMatch.isEmpty()
+ || equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all)
+ || equalIgnoringCase(mediaTypeToMatch, mediaType());
}
static bool applyRestrictor(MediaQuery::Restrictor r, bool value)
// 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.
if (pointer == MediaValues::UnknownPointer)
return false;
- float number = 1;
- if (value.isValid()) {
- if (!numberValue(value, number))
+ // FIXME: Remove the old code once we're sure this doesn't break anything significant.
+ if (RuntimeEnabledFeatures::hoverMediaQueryKeywordsEnabled()) {
+ if (!value.isValid())
+ return pointer != MediaValues::NoPointer;
+
+ if (!value.isID)
return false;
- }
- return (pointer == MediaValues::NoPointer && !number)
- || (pointer == MediaValues::TouchPointer && !number)
- || (pointer == MediaValues::MousePointer && number == 1);
+ return (pointer == MediaValues::NoPointer && value.id == CSSValueNone)
+ || (pointer == MediaValues::TouchPointer && value.id == CSSValueOnDemand)
+ || (pointer == MediaValues::MousePointer && value.id == CSSValueHover);
+ } else {
+ float number = 1;
+ if (value.isValid()) {
+ if (!numberValue(value, number))
+ return false;
+ }
+
+ return (pointer == MediaValues::NoPointer && !number)
+ || (pointer == MediaValues::TouchPointer && !number)
+ || (pointer == MediaValues::MousePointer && number == 1);
+ }
}
static bool pointerMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePrefix, const MediaValues& mediaValues)
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())