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 12 matching lines...) Expand all Loading... |
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
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 "core/css/CSSPrimitiveValue.h" | |
34 #include "core/css/parser/CSSParserToken.h" | 33 #include "core/css/parser/CSSParserToken.h" |
35 #include "core/html/parser/HTMLParserIdioms.h" | 34 #include "core/html/parser/HTMLParserIdioms.h" |
36 #include "platform/Decimal.h" | 35 #include "platform/Decimal.h" |
37 #include "platform/RuntimeEnabledFeatures.h" | 36 #include "platform/RuntimeEnabledFeatures.h" |
38 #include "wtf/text/StringBuffer.h" | 37 #include "wtf/text/StringBuffer.h" |
39 #include "wtf/text/StringBuilder.h" | 38 #include "wtf/text/StringBuilder.h" |
40 | 39 |
41 namespace blink { | 40 namespace blink { |
42 | 41 |
43 using namespace MediaFeatureNames; | 42 using namespace MediaFeatureNames; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 , m_expValue(other.expValue()) | 181 , m_expValue(other.expValue()) |
183 { | 182 { |
184 } | 183 } |
185 | 184 |
186 MediaQueryExp::MediaQueryExp(const String& mediaFeature, const MediaQueryExpValu
e& expValue) | 185 MediaQueryExp::MediaQueryExp(const String& mediaFeature, const MediaQueryExpValu
e& expValue) |
187 : m_mediaFeature(mediaFeature) | 186 : m_mediaFeature(mediaFeature) |
188 , m_expValue(expValue) | 187 , m_expValue(expValue) |
189 { | 188 { |
190 } | 189 } |
191 | 190 |
192 CSSValueID cssValueKeywordID(const CSSParserString&); | |
193 | |
194 PassOwnPtrWillBeRawPtr<MediaQueryExp> MediaQueryExp::createIfValid(const String&
mediaFeature, const Vector<CSSParserToken, 4>& tokenList) | 191 PassOwnPtrWillBeRawPtr<MediaQueryExp> MediaQueryExp::createIfValid(const String&
mediaFeature, const Vector<CSSParserToken, 4>& tokenList) |
195 { | 192 { |
196 ASSERT(!mediaFeature.isNull()); | 193 ASSERT(!mediaFeature.isNull()); |
197 | 194 |
198 MediaQueryExpValue expValue; | 195 MediaQueryExpValue expValue; |
199 String lowerMediaFeature = attemptStaticStringCreation(mediaFeature.lower())
; | 196 String lowerMediaFeature = attemptStaticStringCreation(mediaFeature.lower())
; |
200 | 197 |
201 // Create value for media query expression that must have 1 or more values. | 198 // Create value for media query expression that must have 1 or more values. |
202 if (tokenList.size() == 0 && featureWithoutValue(lowerMediaFeature)) { | 199 if (tokenList.size() == 0 && featureWithoutValue(lowerMediaFeature)) { |
203 // Valid, creates a MediaQueryExp with an 'invalid' MediaQueryExpValue | 200 // Valid, creates a MediaQueryExp with an 'invalid' MediaQueryExpValue |
204 } else if (tokenList.size() == 1) { | 201 } else if (tokenList.size() == 1) { |
205 CSSParserToken token = tokenList.first(); | 202 CSSParserToken token = tokenList.first(); |
206 | 203 |
207 if (token.type() == IdentToken) { | 204 if (token.type() == IdentToken) { |
208 CSSValueID ident = cssValueKeywordID(token.value()); | 205 CSSValueID ident = token.id(); |
209 if (!featureWithValidIdent(lowerMediaFeature, ident)) | 206 if (!featureWithValidIdent(lowerMediaFeature, ident)) |
210 return nullptr; | 207 return nullptr; |
211 expValue.id = ident; | 208 expValue.id = ident; |
212 expValue.unit = CSSPrimitiveValue::UnitType::ValueID; | 209 expValue.unit = CSSPrimitiveValue::UnitType::ValueID; |
213 expValue.isID = true; | 210 expValue.isID = true; |
214 } else if (token.type() == NumberToken || token.type() == PercentageToke
n || token.type() == DimensionToken) { | 211 } else if (token.type() == NumberToken || token.type() == PercentageToke
n || token.type() == DimensionToken) { |
215 // Check for numeric token types since it is only safe for these typ
es to call numericValue. | 212 // Check for numeric token types since it is only safe for these typ
es to call numericValue. |
216 if (featureWithValidDensity(lowerMediaFeature, token) | 213 if (featureWithValidDensity(lowerMediaFeature, token) |
217 || featureWithValidPositiveLength(lowerMediaFeature, token)) { | 214 || featureWithValidPositiveLength(lowerMediaFeature, token)) { |
218 // Media features that must have non-negative <density>, ie. dpp
x, dpi or dpcm, | 215 // Media features that must have non-negative <density>, ie. dpp
x, dpi or dpcm, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 output.append('/'); | 296 output.append('/'); |
300 output.append(printNumber(denominator)); | 297 output.append(printNumber(denominator)); |
301 } else if (isID) { | 298 } else if (isID) { |
302 output.append(getValueName(id)); | 299 output.append(getValueName(id)); |
303 } | 300 } |
304 | 301 |
305 return output.toString(); | 302 return output.toString(); |
306 } | 303 } |
307 | 304 |
308 } // namespace | 305 } // namespace |
OLD | NEW |