Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / MediaQueryExp.cpp
index 14348df..a6b1c5a 100644 (file)
 #include "core/css/MediaQueryExp.h"
 
 #include "core/css/CSSAspectRatioValue.h"
-#include "core/css/CSSParserValues.h"
 #include "core/css/CSSPrimitiveValue.h"
+#include "core/css/parser/CSSParserValues.h"
 #include "core/html/parser/HTMLParserIdioms.h"
 #include "platform/Decimal.h"
+#include "platform/RuntimeEnabledFeatures.h"
 #include "wtf/text/StringBuffer.h"
 #include "wtf/text/StringBuilder.h"
 
-namespace WebCore {
+namespace blink {
 
 using namespace MediaFeatureNames;
 
@@ -49,6 +50,7 @@ static inline bool featureWithCSSValueID(const String& mediaFeature, const CSSPa
 
     return mediaFeature == orientationMediaFeature
         || mediaFeature == pointerMediaFeature
+        || (mediaFeature == hoverMediaFeature && RuntimeEnabledFeatures::hoverMediaQueryKeywordsEnabled())
         || mediaFeature == scanMediaFeature;
 }
 
@@ -60,6 +62,9 @@ static inline bool featureWithValidIdent(const String& mediaFeature, CSSValueID
     if (mediaFeature == pointerMediaFeature)
         return ident == CSSValueNone || ident == CSSValueCoarse || ident == CSSValueFine;
 
+    if (mediaFeature == hoverMediaFeature && RuntimeEnabledFeatures::hoverMediaQueryKeywordsEnabled())
+        return ident == CSSValueNone || ident == CSSValueOnDemand || ident == CSSValueHover;
+
     if (mediaFeature == scanMediaFeature)
         return ident == CSSValueInterlace || ident == CSSValueProgressive;
 
@@ -67,9 +72,27 @@ static inline bool featureWithValidIdent(const String& mediaFeature, CSSValueID
     return false;
 }
 
+static bool positiveLengthUnit(const int unit)
+{
+    switch (unit) {
+    case CSSPrimitiveValue::CSS_EMS:
+    case CSSPrimitiveValue::CSS_EXS:
+    case CSSPrimitiveValue::CSS_PX:
+    case CSSPrimitiveValue::CSS_CM:
+    case CSSPrimitiveValue::CSS_MM:
+    case CSSPrimitiveValue::CSS_IN:
+    case CSSPrimitiveValue::CSS_PT:
+    case CSSPrimitiveValue::CSS_PC:
+    case CSSPrimitiveValue::CSS_REMS:
+    case CSSPrimitiveValue::CSS_CHS:
+        return true;
+    }
+    return false;
+}
+
 static inline bool featureWithValidPositiveLength(const String& mediaFeature, const CSSParserValue* value)
 {
-    if (!(((value->unit >= CSSPrimitiveValue::CSS_EMS && value->unit <= CSSPrimitiveValue::CSS_PC) || value->unit == CSSPrimitiveValue::CSS_REMS) || (value->unit == CSSPrimitiveValue::CSS_NUMBER && !(value->fValue))) || value->fValue < 0)
+    if (!(positiveLengthUnit(value->unit) || (value->unit == CSSPrimitiveValue::CSS_NUMBER && value->fValue == 0)) || value->fValue < 0)
         return false;
 
 
@@ -130,7 +153,7 @@ static inline bool featureWithZeroOrOne(const String& mediaFeature, const CSSPar
         return false;
 
     return mediaFeature == gridMediaFeature
-        || mediaFeature == hoverMediaFeature;
+        || (mediaFeature == hoverMediaFeature && !RuntimeEnabledFeatures::hoverMediaQueryKeywordsEnabled());
 }
 
 static inline bool featureWithAspectRatio(const String& mediaFeature)
@@ -219,7 +242,6 @@ PassOwnPtrWillBeRawPtr<MediaQueryExp> MediaQueryExp::createIfValid(const String&
                 expValue.value = value->fValue;
                 expValue.unit = (CSSPrimitiveValue::UnitType)value->unit;
                 expValue.isValue = true;
-                expValue.isInteger = value->isInt;
             } else if (featureWithPositiveInteger(lowerMediaFeature, value)
                 || featureWithPositiveNumber(lowerMediaFeature, value)
                 || featureWithZeroOrOne(lowerMediaFeature, value)) {
@@ -229,7 +251,6 @@ PassOwnPtrWillBeRawPtr<MediaQueryExp> MediaQueryExp::createIfValid(const String&
                 expValue.value = value->fValue;
                 expValue.unit = CSSPrimitiveValue::CSS_NUMBER;
                 expValue.isValue = true;
-                expValue.isInteger = value->isInt;
             }
 
             isValid = (expValue.isID || expValue.isValue);