| OLD | NEW |
| 1 /* | 1 /* |
| 2 * CSS Media Query | 2 * CSS Media Query |
| 3 * | 3 * |
| 4 * Copyright (C) 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>. | 4 * Copyright (C) 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>. |
| 5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 5 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
| 6 * Copyright (C) 2013 Apple Inc. All rights reserved. | 6 * Copyright (C) 2013 Apple Inc. All rights reserved. |
| 7 * | 7 * |
| 8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
| 10 * are met: | 10 * are met: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #include "config.h" | 30 #include "config.h" |
| 31 #include "core/css/MediaQueryExp.h" | 31 #include "core/css/MediaQueryExp.h" |
| 32 | 32 |
| 33 #include "CSSValueKeywords.h" | 33 #include "CSSValueKeywords.h" |
| 34 #include "core/css/CSSAspectRatioValue.h" | 34 #include "core/css/CSSAspectRatioValue.h" |
| 35 #include "core/css/parser/BisonCSSParser.h" | 35 #include "core/css/CSSParserValues.h" |
| 36 #include "core/css/CSSPrimitiveValue.h" | 36 #include "core/css/CSSPrimitiveValue.h" |
| 37 #include "core/html/parser/HTMLParserIdioms.h" |
| 37 #include "wtf/text/StringBuilder.h" | 38 #include "wtf/text/StringBuilder.h" |
| 38 | 39 |
| 39 namespace WebCore { | 40 namespace WebCore { |
| 40 | 41 |
| 41 static inline bool featureWithCSSValueID(const AtomicString& mediaFeature, const
CSSParserValue* value) | 42 using namespace MediaFeatureNames; |
| 43 |
| 44 static inline bool featureWithCSSValueID(const String& mediaFeature, const CSSPa
rserValue* value) |
| 42 { | 45 { |
| 43 if (!value->id) | 46 if (!value->id) |
| 44 return false; | 47 return false; |
| 45 | 48 |
| 46 return mediaFeature == MediaFeatureNames::orientationMediaFeature | 49 return mediaFeature == orientationMediaFeature |
| 47 || mediaFeature == MediaFeatureNames::viewModeMediaFeature | 50 || mediaFeature == viewModeMediaFeature |
| 48 || mediaFeature == MediaFeatureNames::pointerMediaFeature | 51 || mediaFeature == pointerMediaFeature |
| 49 || mediaFeature == MediaFeatureNames::scanMediaFeature; | 52 || mediaFeature == scanMediaFeature; |
| 50 } | 53 } |
| 51 | 54 |
| 52 static inline bool featureWithValidIdent(const AtomicString& mediaFeature, CSSVa
lueID ident) | 55 static inline bool featureWithValidIdent(const String& mediaFeature, CSSValueID
ident) |
| 53 { | 56 { |
| 54 if (mediaFeature == MediaFeatureNames::orientationMediaFeature) | 57 if (mediaFeature == orientationMediaFeature) |
| 55 return ident == CSSValuePortrait || ident == CSSValueLandscape; | 58 return ident == CSSValuePortrait || ident == CSSValueLandscape; |
| 56 | 59 |
| 57 if (mediaFeature == MediaFeatureNames::viewModeMediaFeature) { | 60 if (mediaFeature == viewModeMediaFeature) { |
| 58 switch (ident) { | 61 switch (ident) { |
| 59 case CSSValueWindowed: | 62 case CSSValueWindowed: |
| 60 case CSSValueFloating: | 63 case CSSValueFloating: |
| 61 case CSSValueFullscreen: | 64 case CSSValueFullscreen: |
| 62 case CSSValueMaximized: | 65 case CSSValueMaximized: |
| 63 case CSSValueMinimized: | 66 case CSSValueMinimized: |
| 64 return true; | 67 return true; |
| 65 default: | 68 default: |
| 66 return false; | 69 return false; |
| 67 } | 70 } |
| 68 } | 71 } |
| 69 | 72 |
| 70 if (mediaFeature == MediaFeatureNames::pointerMediaFeature) | 73 if (mediaFeature == pointerMediaFeature) |
| 71 return ident == CSSValueNone || ident == CSSValueCoarse || ident == CSSV
alueFine; | 74 return ident == CSSValueNone || ident == CSSValueCoarse || ident == CSSV
alueFine; |
| 72 | 75 |
| 73 if (mediaFeature == MediaFeatureNames::scanMediaFeature) | 76 if (mediaFeature == scanMediaFeature) |
| 74 return ident == CSSValueInterlace || ident == CSSValueProgressive; | 77 return ident == CSSValueInterlace || ident == CSSValueProgressive; |
| 75 | 78 |
| 76 ASSERT_NOT_REACHED(); | 79 ASSERT_NOT_REACHED(); |
| 77 return false; | 80 return false; |
| 78 } | 81 } |
| 79 | 82 |
| 80 static inline bool featureWithValidPositiveLength(const AtomicString& mediaFeatu
re, const CSSParserValue* value) | 83 static inline bool featureWithValidPositiveLength(const String& mediaFeature, co
nst CSSParserValue* value) |
| 81 { | 84 { |
| 82 if (!(((value->unit >= CSSPrimitiveValue::CSS_EMS && value->unit <= CSSPrimi
tiveValue::CSS_PC) || value->unit == CSSPrimitiveValue::CSS_REMS) || (value->uni
t == CSSPrimitiveValue::CSS_NUMBER && !(value->fValue))) || value->fValue < 0) | 85 if (!(((value->unit >= CSSPrimitiveValue::CSS_EMS && value->unit <= CSSPrimi
tiveValue::CSS_PC) || value->unit == CSSPrimitiveValue::CSS_REMS) || (value->uni
t == CSSPrimitiveValue::CSS_NUMBER && !(value->fValue))) || value->fValue < 0) |
| 83 return false; | 86 return false; |
| 84 | 87 |
| 85 return mediaFeature == MediaFeatureNames::heightMediaFeature | 88 |
| 86 || mediaFeature == MediaFeatureNames::maxHeightMediaFeature | 89 return mediaFeature == heightMediaFeature |
| 87 || mediaFeature == MediaFeatureNames::minHeightMediaFeature | 90 || mediaFeature == maxHeightMediaFeature |
| 88 || mediaFeature == MediaFeatureNames::widthMediaFeature | 91 || mediaFeature == minHeightMediaFeature |
| 89 || mediaFeature == MediaFeatureNames::maxWidthMediaFeature | 92 || mediaFeature == widthMediaFeature |
| 90 || mediaFeature == MediaFeatureNames::minWidthMediaFeature | 93 || mediaFeature == maxWidthMediaFeature |
| 91 || mediaFeature == MediaFeatureNames::deviceHeightMediaFeature | 94 || mediaFeature == minWidthMediaFeature |
| 92 || mediaFeature == MediaFeatureNames::maxDeviceHeightMediaFeature | 95 || mediaFeature == deviceHeightMediaFeature |
| 93 || mediaFeature == MediaFeatureNames::minDeviceHeightMediaFeature | 96 || mediaFeature == maxDeviceHeightMediaFeature |
| 94 || mediaFeature == MediaFeatureNames::deviceWidthMediaFeature | 97 || mediaFeature == minDeviceHeightMediaFeature |
| 95 || mediaFeature == MediaFeatureNames::maxDeviceWidthMediaFeature | 98 || mediaFeature == deviceWidthMediaFeature |
| 96 || mediaFeature == MediaFeatureNames::minDeviceWidthMediaFeature; | 99 || mediaFeature == minDeviceWidthMediaFeature |
| 100 || mediaFeature == maxDeviceWidthMediaFeature; |
| 97 } | 101 } |
| 98 | 102 |
| 99 static inline bool featureWithValidDensity(const AtomicString& mediaFeature, con
st CSSParserValue* value) | 103 static inline bool featureWithValidDensity(const String& mediaFeature, const CSS
ParserValue* value) |
| 100 { | 104 { |
| 101 if ((value->unit != CSSPrimitiveValue::CSS_DPPX && value->unit != CSSPrimiti
veValue::CSS_DPI && value->unit != CSSPrimitiveValue::CSS_DPCM) || value->fValue
<= 0) | 105 if ((value->unit != CSSPrimitiveValue::CSS_DPPX && value->unit != CSSPrimiti
veValue::CSS_DPI && value->unit != CSSPrimitiveValue::CSS_DPCM) || value->fValue
<= 0) |
| 102 return false; | 106 return false; |
| 103 | 107 |
| 104 return mediaFeature == MediaFeatureNames::resolutionMediaFeature | 108 return mediaFeature == resolutionMediaFeature |
| 105 || mediaFeature == MediaFeatureNames::maxResolutionMediaFeature | 109 || mediaFeature == minResolutionMediaFeature |
| 106 || mediaFeature == MediaFeatureNames::minResolutionMediaFeature; | 110 || mediaFeature == maxResolutionMediaFeature; |
| 107 } | 111 } |
| 108 | 112 |
| 109 static inline bool featureWithPositiveInteger(const AtomicString& mediaFeature,
const CSSParserValue* value) | 113 static inline bool featureWithPositiveInteger(const String& mediaFeature, const
CSSParserValue* value) |
| 110 { | 114 { |
| 111 if (!value->isInt || value->fValue < 0) | 115 if (!value->isInt || value->fValue < 0) |
| 112 return false; | 116 return false; |
| 113 | 117 |
| 114 return mediaFeature == MediaFeatureNames::colorMediaFeature | 118 return mediaFeature == colorMediaFeature |
| 115 || mediaFeature == MediaFeatureNames::maxColorMediaFeature | 119 || mediaFeature == maxColorMediaFeature |
| 116 || mediaFeature == MediaFeatureNames::minColorMediaFeature | 120 || mediaFeature == minColorMediaFeature |
| 117 || mediaFeature == MediaFeatureNames::colorIndexMediaFeature | 121 || mediaFeature == colorIndexMediaFeature |
| 118 || mediaFeature == MediaFeatureNames::maxColorIndexMediaFeature | 122 || mediaFeature == maxColorIndexMediaFeature |
| 119 || mediaFeature == MediaFeatureNames::minColorIndexMediaFeature | 123 || mediaFeature == minColorIndexMediaFeature |
| 120 || mediaFeature == MediaFeatureNames::monochromeMediaFeature | 124 || mediaFeature == monochromeMediaFeature |
| 121 || mediaFeature == MediaFeatureNames::minMonochromeMediaFeature | 125 || mediaFeature == maxMonochromeMediaFeature |
| 122 || mediaFeature == MediaFeatureNames::maxMonochromeMediaFeature; | 126 || mediaFeature == minMonochromeMediaFeature; |
| 123 } | 127 } |
| 124 | 128 |
| 125 static inline bool featureWithPositiveNumber(const AtomicString& mediaFeature, c
onst CSSParserValue* value) | 129 static inline bool featureWithPositiveNumber(const String& mediaFeature, const C
SSParserValue* value) |
| 126 { | 130 { |
| 127 if (value->unit != CSSPrimitiveValue::CSS_NUMBER || value->fValue < 0) | 131 if (value->unit != CSSPrimitiveValue::CSS_NUMBER || value->fValue < 0) |
| 128 return false; | 132 return false; |
| 129 | 133 |
| 130 return mediaFeature == MediaFeatureNames::transform2dMediaFeature | 134 return mediaFeature == transform2dMediaFeature |
| 131 || mediaFeature == MediaFeatureNames::transform3dMediaFeature | 135 || mediaFeature == transform3dMediaFeature |
| 132 || mediaFeature == MediaFeatureNames::animationMediaFeature | 136 || mediaFeature == animationMediaFeature |
| 133 || mediaFeature == MediaFeatureNames::devicePixelRatioMediaFeature | 137 || mediaFeature == devicePixelRatioMediaFeature |
| 134 || mediaFeature == MediaFeatureNames::maxDevicePixelRatioMediaFeature | 138 || mediaFeature == maxDevicePixelRatioMediaFeature |
| 135 || mediaFeature == MediaFeatureNames::minDevicePixelRatioMediaFeature; | 139 || mediaFeature == minDevicePixelRatioMediaFeature; |
| 136 } | 140 } |
| 137 | 141 |
| 138 static inline bool featureWithZeroOrOne(const AtomicString& mediaFeature, const
CSSParserValue* value) | 142 static inline bool featureWithZeroOrOne(const String& mediaFeature, const CSSPar
serValue* value) |
| 139 { | 143 { |
| 140 if (!value->isInt || !(value->fValue == 1 || !value->fValue)) | 144 if (!value->isInt || !(value->fValue == 1 || !value->fValue)) |
| 141 return false; | 145 return false; |
| 142 | 146 |
| 143 return mediaFeature == MediaFeatureNames::gridMediaFeature | 147 return mediaFeature == gridMediaFeature |
| 144 || mediaFeature == MediaFeatureNames::hoverMediaFeature; | 148 || mediaFeature == hoverMediaFeature; |
| 145 } | 149 } |
| 146 | 150 |
| 147 static inline bool featureWithAspectRatio(const AtomicString& mediaFeature) | 151 static inline bool featureWithAspectRatio(const String& mediaFeature) |
| 148 { | 152 { |
| 149 return mediaFeature == MediaFeatureNames::aspectRatioMediaFeature | 153 return mediaFeature == aspectRatioMediaFeature |
| 150 || mediaFeature == MediaFeatureNames::deviceAspectRatioMediaFeature | 154 || mediaFeature == deviceAspectRatioMediaFeature |
| 151 || mediaFeature == MediaFeatureNames::minAspectRatioMediaFeature | 155 || mediaFeature == minAspectRatioMediaFeature |
| 152 || mediaFeature == MediaFeatureNames::maxAspectRatioMediaFeature | 156 || mediaFeature == maxAspectRatioMediaFeature |
| 153 || mediaFeature == MediaFeatureNames::minDeviceAspectRatioMediaFeature | 157 || mediaFeature == minDeviceAspectRatioMediaFeature |
| 154 || mediaFeature == MediaFeatureNames::maxDeviceAspectRatioMediaFeature; | 158 || mediaFeature == maxDeviceAspectRatioMediaFeature; |
| 155 } | 159 } |
| 156 | 160 |
| 157 static inline bool featureWithoutValue(const AtomicString& mediaFeature) | 161 static inline bool featureWithoutValue(const String& mediaFeature) |
| 158 { | 162 { |
| 159 // Media features that are prefixed by min/max cannot be used without a valu
e. | 163 // Media features that are prefixed by min/max cannot be used without a valu
e. |
| 160 return mediaFeature == MediaFeatureNames::monochromeMediaFeature | 164 return mediaFeature == monochromeMediaFeature |
| 161 || mediaFeature == MediaFeatureNames::colorMediaFeature | 165 || mediaFeature == colorMediaFeature |
| 162 || mediaFeature == MediaFeatureNames::colorIndexMediaFeature | 166 || mediaFeature == colorIndexMediaFeature |
| 163 || mediaFeature == MediaFeatureNames::gridMediaFeature | 167 || mediaFeature == gridMediaFeature |
| 164 || mediaFeature == MediaFeatureNames::heightMediaFeature | 168 || mediaFeature == heightMediaFeature |
| 165 || mediaFeature == MediaFeatureNames::widthMediaFeature | 169 || mediaFeature == widthMediaFeature |
| 166 || mediaFeature == MediaFeatureNames::deviceHeightMediaFeature | 170 || mediaFeature == deviceHeightMediaFeature |
| 167 || mediaFeature == MediaFeatureNames::deviceWidthMediaFeature | 171 || mediaFeature == deviceWidthMediaFeature |
| 168 || mediaFeature == MediaFeatureNames::orientationMediaFeature | 172 || mediaFeature == orientationMediaFeature |
| 169 || mediaFeature == MediaFeatureNames::aspectRatioMediaFeature | 173 || mediaFeature == aspectRatioMediaFeature |
| 170 || mediaFeature == MediaFeatureNames::deviceAspectRatioMediaFeature | 174 || mediaFeature == deviceAspectRatioMediaFeature |
| 171 || mediaFeature == MediaFeatureNames::hoverMediaFeature | 175 || mediaFeature == hoverMediaFeature |
| 172 || mediaFeature == MediaFeatureNames::transform2dMediaFeature | 176 || mediaFeature == transform2dMediaFeature |
| 173 || mediaFeature == MediaFeatureNames::transform3dMediaFeature | 177 || mediaFeature == transform3dMediaFeature |
| 174 || mediaFeature == MediaFeatureNames::animationMediaFeature | 178 || mediaFeature == animationMediaFeature |
| 175 || mediaFeature == MediaFeatureNames::viewModeMediaFeature | 179 || mediaFeature == viewModeMediaFeature |
| 176 || mediaFeature == MediaFeatureNames::pointerMediaFeature | 180 || mediaFeature == pointerMediaFeature |
| 177 || mediaFeature == MediaFeatureNames::devicePixelRatioMediaFeature | 181 || mediaFeature == devicePixelRatioMediaFeature |
| 178 || mediaFeature == MediaFeatureNames::resolutionMediaFeature | 182 || mediaFeature == resolutionMediaFeature |
| 179 || mediaFeature == MediaFeatureNames::scanMediaFeature; | 183 || mediaFeature == scanMediaFeature; |
| 180 } | 184 } |
| 181 | 185 |
| 182 bool MediaQueryExp::isViewportDependent() const | 186 bool MediaQueryExp::isViewportDependent() const |
| 183 { | 187 { |
| 184 return m_mediaFeature == MediaFeatureNames::widthMediaFeature | 188 return m_mediaFeature == widthMediaFeature |
| 185 || m_mediaFeature == MediaFeatureNames::heightMediaFeature | 189 || m_mediaFeature == heightMediaFeature |
| 186 || m_mediaFeature == MediaFeatureNames::minWidthMediaFeature | 190 || m_mediaFeature == minWidthMediaFeature |
| 187 || m_mediaFeature == MediaFeatureNames::minHeightMediaFeature | 191 || m_mediaFeature == minHeightMediaFeature |
| 188 || m_mediaFeature == MediaFeatureNames::maxWidthMediaFeature | 192 || m_mediaFeature == maxWidthMediaFeature |
| 189 || m_mediaFeature == MediaFeatureNames::maxHeightMediaFeature | 193 || m_mediaFeature == maxHeightMediaFeature |
| 190 || m_mediaFeature == MediaFeatureNames::orientationMediaFeature | 194 || m_mediaFeature == orientationMediaFeature |
| 191 || m_mediaFeature == MediaFeatureNames::aspectRatioMediaFeature | 195 || m_mediaFeature == aspectRatioMediaFeature |
| 192 || m_mediaFeature == MediaFeatureNames::minAspectRatioMediaFeature | 196 || m_mediaFeature == minAspectRatioMediaFeature |
| 193 || m_mediaFeature == MediaFeatureNames::devicePixelRatioMediaFeature | 197 || m_mediaFeature == devicePixelRatioMediaFeature |
| 194 || m_mediaFeature == MediaFeatureNames::resolutionMediaFeature | 198 || m_mediaFeature == resolutionMediaFeature |
| 195 || m_mediaFeature == MediaFeatureNames::maxAspectRatioMediaFeature; | 199 || m_mediaFeature == maxAspectRatioMediaFeature; |
| 196 } | 200 } |
| 197 | 201 |
| 198 MediaQueryExp::MediaQueryExp(const MediaQueryExp& other) | 202 MediaQueryExp::MediaQueryExp(const MediaQueryExp& other) |
| 199 : m_mediaFeature(other.mediaFeature()) | 203 : m_mediaFeature(other.mediaFeature()) |
| 200 , m_value(other.value()) | 204 , m_value(other.value()) |
| 201 { | 205 { |
| 202 } | 206 } |
| 203 | 207 |
| 204 MediaQueryExp::MediaQueryExp(const AtomicString& mediaFeature, PassRefPtrWillBeR
awPtr<CSSValue> value) | 208 MediaQueryExp::MediaQueryExp(const String& mediaFeature, PassRefPtrWillBeRawPtr<
CSSValue> value) |
| 205 : m_mediaFeature(mediaFeature) | 209 : m_mediaFeature(mediaFeature) |
| 206 , m_value(value) | 210 , m_value(value) |
| 207 { | 211 { |
| 208 } | 212 } |
| 209 | 213 |
| 210 PassOwnPtrWillBeRawPtr<MediaQueryExp> MediaQueryExp::create(const AtomicString&
mediaFeature, CSSParserValueList* valueList) | 214 PassOwnPtrWillBeRawPtr<MediaQueryExp> MediaQueryExp::create(const String& mediaF
eature, CSSParserValueList* valueList) |
| 211 { | 215 { |
| 212 RefPtrWillBeRawPtr<CSSValue> cssValue; | 216 RefPtrWillBeRawPtr<CSSValue> cssValue; |
| 213 bool isValid = false; | 217 bool isValid = false; |
| 218 String lowerMediaFeature = attemptStaticStringCreation(mediaFeature.lower())
; |
| 214 | 219 |
| 215 // Create value for media query expression that must have 1 or more values. | 220 // Create value for media query expression that must have 1 or more values. |
| 216 if (valueList) { | 221 if (valueList && valueList->size() > 0) { |
| 217 if (valueList->size() == 1) { | 222 if (valueList->size() == 1) { |
| 218 CSSParserValue* value = valueList->current(); | 223 CSSParserValue* value = valueList->current(); |
| 219 | 224 |
| 220 if (featureWithCSSValueID(mediaFeature, value)) { | 225 if (featureWithCSSValueID(lowerMediaFeature, value)) { |
| 221 // Media features that use CSSValueIDs. | 226 // Media features that use CSSValueIDs. |
| 222 cssValue = CSSPrimitiveValue::createIdentifier(value->id); | 227 cssValue = CSSPrimitiveValue::createIdentifier(value->id); |
| 223 if (!featureWithValidIdent(mediaFeature, toCSSPrimitiveValue(css
Value.get())->getValueID())) | 228 if (!featureWithValidIdent(lowerMediaFeature, toCSSPrimitiveValu
e(cssValue.get())->getValueID())) |
| 224 cssValue.clear(); | 229 cssValue.clear(); |
| 225 } else if (featureWithValidDensity(mediaFeature, value)) { | 230 } else if (featureWithValidDensity(lowerMediaFeature, value)) { |
| 226 // Media features that must have non-negative <density>, ie. dpp
x, dpi or dpcm. | 231 // Media features that must have non-negative <density>, ie. dpp
x, dpi or dpcm. |
| 227 cssValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiv
eValue::UnitTypes) value->unit); | 232 cssValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiv
eValue::UnitTypes) value->unit); |
| 228 } else if (featureWithValidPositiveLength(mediaFeature, value)) { | 233 } else if (featureWithValidPositiveLength(lowerMediaFeature, value))
{ |
| 229 // Media features that must have non-negative <lenght> or number
value. | 234 // Media features that must have non-negative <lenght> or number
value. |
| 230 cssValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiv
eValue::UnitTypes) value->unit); | 235 cssValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiv
eValue::UnitTypes) value->unit); |
| 231 } else if (featureWithPositiveInteger(mediaFeature, value)) { | 236 } else if (featureWithPositiveInteger(lowerMediaFeature, value)) { |
| 232 // Media features that must have non-negative integer value. | 237 // Media features that must have non-negative integer value. |
| 233 cssValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitive
Value::CSS_NUMBER); | 238 cssValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitive
Value::CSS_NUMBER); |
| 234 } else if (featureWithPositiveNumber(mediaFeature, value)) { | 239 } else if (featureWithPositiveNumber(lowerMediaFeature, value)) { |
| 235 // Media features that must have non-negative number value. | 240 // Media features that must have non-negative number value. |
| 236 cssValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitive
Value::CSS_NUMBER); | 241 cssValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitive
Value::CSS_NUMBER); |
| 237 } else if (featureWithZeroOrOne(mediaFeature, value)) { | 242 } else if (featureWithZeroOrOne(lowerMediaFeature, value)) { |
| 238 // Media features that must have (0|1) value. | 243 // Media features that must have (0|1) value. |
| 239 cssValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitive
Value::CSS_NUMBER); | 244 cssValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitive
Value::CSS_NUMBER); |
| 240 } | 245 } |
| 241 | 246 |
| 242 isValid = cssValue; | 247 isValid = cssValue; |
| 243 | 248 |
| 244 } else if (valueList->size() == 3 && featureWithAspectRatio(mediaFeature
)) { | 249 } else if (valueList->size() == 3 && featureWithAspectRatio(lowerMediaFe
ature)) { |
| 245 // Create list of values. | 250 // Create list of values. |
| 246 // Currently accepts only <integer>/<integer>. | 251 // Currently accepts only <integer>/<integer>. |
| 247 // Applicable to device-aspect-ratio and aspec-ratio. | 252 // Applicable to device-aspect-ratio and aspec-ratio. |
| 248 isValid = true; | 253 isValid = true; |
| 249 float numeratorValue = 0; | 254 float numeratorValue = 0; |
| 250 float denominatorValue = 0; | 255 float denominatorValue = 0; |
| 251 // The aspect-ratio must be <integer> (whitespace)? / (whitespace)?
<integer>. | 256 // The aspect-ratio must be <integer> (whitespace)? / (whitespace)?
<integer>. |
| 252 for (unsigned i = 0; i < 3; ++i, valueList->next()) { | 257 for (unsigned i = 0; i < 3; ++i, valueList->next()) { |
| 253 const CSSParserValue* value = valueList->current(); | 258 const CSSParserValue* value = valueList->current(); |
| 254 if (i != 1 && value->unit == CSSPrimitiveValue::CSS_NUMBER && va
lue->fValue > 0 && value->isInt) { | 259 if (i != 1 && value->unit == CSSPrimitiveValue::CSS_NUMBER && va
lue->fValue > 0 && value->isInt) { |
| 255 if (!i) | 260 if (!i) |
| 256 numeratorValue = value->fValue; | 261 numeratorValue = value->fValue; |
| 257 else | 262 else |
| 258 denominatorValue = value->fValue; | 263 denominatorValue = value->fValue; |
| 259 } else if (i == 1 && value->unit == CSSParserValue::Operator &&
value->iValue == '/') { | 264 } else if (i == 1 && value->unit == CSSParserValue::Operator &&
value->iValue == '/') { |
| 260 continue; | 265 continue; |
| 261 } else { | 266 } else { |
| 262 isValid = false; | 267 isValid = false; |
| 263 break; | 268 break; |
| 264 } | 269 } |
| 265 } | 270 } |
| 266 | 271 |
| 267 if (isValid) | 272 if (isValid) |
| 268 cssValue = CSSAspectRatioValue::create(numeratorValue, denominat
orValue); | 273 cssValue = CSSAspectRatioValue::create(numeratorValue, denominat
orValue); |
| 269 } | 274 } |
| 270 } else if (featureWithoutValue(mediaFeature)) { | 275 } else if (featureWithoutValue(lowerMediaFeature)) { |
| 271 isValid = true; | 276 isValid = true; |
| 272 } | 277 } |
| 273 | 278 |
| 274 if (!isValid) | 279 if (!isValid) |
| 275 return nullptr; | 280 return nullptr; |
| 276 | 281 |
| 277 return adoptPtrWillBeNoop(new MediaQueryExp(mediaFeature, cssValue)); | 282 return adoptPtrWillBeNoop(new MediaQueryExp(lowerMediaFeature, cssValue)); |
| 278 } | 283 } |
| 279 | 284 |
| 280 MediaQueryExp::~MediaQueryExp() | 285 MediaQueryExp::~MediaQueryExp() |
| 281 { | 286 { |
| 282 } | 287 } |
| 283 | 288 |
| 284 String MediaQueryExp::serialize() const | 289 String MediaQueryExp::serialize() const |
| 285 { | 290 { |
| 286 StringBuilder result; | 291 StringBuilder result; |
| 287 result.append("("); | 292 result.append("("); |
| 288 result.append(m_mediaFeature.lower()); | 293 result.append(m_mediaFeature.lower()); |
| 289 if (m_value) { | 294 if (m_value) { |
| 290 result.append(": "); | 295 result.append(": "); |
| 291 result.append(m_value->cssText()); | 296 result.append(m_value->cssText()); |
| 292 } | 297 } |
| 293 result.append(")"); | 298 result.append(")"); |
| 294 | 299 |
| 295 return result.toString(); | 300 return result.toString(); |
| 296 } | 301 } |
| 297 | 302 |
| 298 } // namespace | 303 } // namespace |
| OLD | NEW |