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 21 matching lines...) Expand all Loading... | |
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/CSSParser.h" | 35 #include "core/css/CSSParser.h" |
36 #include "core/css/CSSPrimitiveValue.h" | 36 #include "core/css/CSSPrimitiveValue.h" |
37 #include "core/dom/WebCoreMemoryInstrumentation.h" | 37 #include "core/dom/WebCoreMemoryInstrumentation.h" |
38 #include "wtf/text/StringBuilder.h" | 38 #include "wtf/text/StringBuilder.h" |
39 | 39 |
40 namespace WebCore { | 40 namespace WebCore { |
41 | 41 |
42 static inline bool featureWithCSSValueID(const AtomicString& mediaFeature, const CSSParserValue* value) | 42 static inline bool featureWithCSSValueID(const String& mediaFeature, const CSSPa rserValue* value) |
43 { | 43 { |
44 if (!value->id) | 44 if (!value->id) |
45 return false; | 45 return false; |
46 | 46 |
47 return mediaFeature == MediaFeatureNames::orientationMediaFeature | 47 return mediaFeature == MediaFeatureNames::orientationMediaFeature |
48 || mediaFeature == MediaFeatureNames::viewModeMediaFeature | 48 || mediaFeature == MediaFeatureNames::viewModeMediaFeature |
49 || mediaFeature == MediaFeatureNames::pointerMediaFeature | 49 || mediaFeature == MediaFeatureNames::pointerMediaFeature |
50 || mediaFeature == MediaFeatureNames::scanMediaFeature; | 50 || mediaFeature == MediaFeatureNames::scanMediaFeature; |
51 } | 51 } |
52 | 52 |
53 static inline bool featureWithValidIdent(const AtomicString& mediaFeature, CSSVa lueID ident) | 53 static inline bool featureWithValidIdent(const String& mediaFeature, CSSValueID ident) |
54 { | 54 { |
55 if (mediaFeature == MediaFeatureNames::orientationMediaFeature) | 55 if (mediaFeature == MediaFeatureNames::orientationMediaFeature) |
56 return ident == CSSValuePortrait || ident == CSSValueLandscape; | 56 return ident == CSSValuePortrait || ident == CSSValueLandscape; |
57 | 57 |
58 if (mediaFeature == MediaFeatureNames::viewModeMediaFeature) { | 58 if (mediaFeature == MediaFeatureNames::viewModeMediaFeature) { |
59 switch (ident) { | 59 switch (ident) { |
60 case CSSValueWindowed: | 60 case CSSValueWindowed: |
61 case CSSValueFloating: | 61 case CSSValueFloating: |
62 case CSSValueFullscreen: | 62 case CSSValueFullscreen: |
63 case CSSValueMaximized: | 63 case CSSValueMaximized: |
64 case CSSValueMinimized: | 64 case CSSValueMinimized: |
65 return true; | 65 return true; |
66 default: | 66 default: |
67 return false; | 67 return false; |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 if (mediaFeature == MediaFeatureNames::pointerMediaFeature) | 71 if (mediaFeature == MediaFeatureNames::pointerMediaFeature) |
72 return ident == CSSValueNone || ident == CSSValueCoarse || ident == CSSV alueFine; | 72 return ident == CSSValueNone || ident == CSSValueCoarse || ident == CSSV alueFine; |
73 | 73 |
74 if (mediaFeature == MediaFeatureNames::scanMediaFeature) | 74 if (mediaFeature == MediaFeatureNames::scanMediaFeature) |
75 return ident == CSSValueInterlace || ident == CSSValueProgressive; | 75 return ident == CSSValueInterlace || ident == CSSValueProgressive; |
76 | 76 |
77 ASSERT_NOT_REACHED(); | 77 ASSERT_NOT_REACHED(); |
78 return false; | 78 return false; |
79 } | 79 } |
80 | 80 |
81 static inline bool featureWithValidPositiveLenghtOrNumber(const AtomicString& me diaFeature, const CSSParserValue* value) | 81 static inline bool featureWithValidPositiveLenghtOrNumber(const String& mediaFea ture, const CSSParserValue* value) |
82 { | 82 { |
83 if (!(((value->unit >= CSSPrimitiveValue::CSS_EMS && value->unit <= CSSPrimi tiveValue::CSS_PC) || value->unit == CSSPrimitiveValue::CSS_REMS) || value->unit == CSSPrimitiveValue::CSS_NUMBER) || value->fValue < 0) | 83 if (!(((value->unit >= CSSPrimitiveValue::CSS_EMS && value->unit <= CSSPrimi tiveValue::CSS_PC) || value->unit == CSSPrimitiveValue::CSS_REMS) || value->unit == CSSPrimitiveValue::CSS_NUMBER) || value->fValue < 0) |
84 return false; | 84 return false; |
85 | 85 |
86 return mediaFeature == MediaFeatureNames::heightMediaFeature | 86 return mediaFeature == MediaFeatureNames::heightMediaFeature |
87 || mediaFeature == MediaFeatureNames::maxHeightMediaFeature | 87 || mediaFeature == MediaFeatureNames::maxHeightMediaFeature |
88 || mediaFeature == MediaFeatureNames::minHeightMediaFeature | 88 || mediaFeature == MediaFeatureNames::minHeightMediaFeature |
89 || mediaFeature == MediaFeatureNames::widthMediaFeature | 89 || mediaFeature == MediaFeatureNames::widthMediaFeature |
90 || mediaFeature == MediaFeatureNames::maxWidthMediaFeature | 90 || mediaFeature == MediaFeatureNames::maxWidthMediaFeature |
91 || mediaFeature == MediaFeatureNames::minWidthMediaFeature | 91 || mediaFeature == MediaFeatureNames::minWidthMediaFeature |
92 || mediaFeature == MediaFeatureNames::deviceHeightMediaFeature | 92 || mediaFeature == MediaFeatureNames::deviceHeightMediaFeature |
93 || mediaFeature == MediaFeatureNames::maxDeviceHeightMediaFeature | 93 || mediaFeature == MediaFeatureNames::maxDeviceHeightMediaFeature |
94 || mediaFeature == MediaFeatureNames::minDeviceHeightMediaFeature | 94 || mediaFeature == MediaFeatureNames::minDeviceHeightMediaFeature |
95 || mediaFeature == MediaFeatureNames::deviceWidthMediaFeature | 95 || mediaFeature == MediaFeatureNames::deviceWidthMediaFeature |
96 || mediaFeature == MediaFeatureNames::maxDeviceWidthMediaFeature | 96 || mediaFeature == MediaFeatureNames::maxDeviceWidthMediaFeature |
97 || mediaFeature == MediaFeatureNames::minDeviceWidthMediaFeature; | 97 || mediaFeature == MediaFeatureNames::minDeviceWidthMediaFeature; |
98 } | 98 } |
99 | 99 |
100 static inline bool featureWithValidDensity(const AtomicString& mediaFeature, con st CSSParserValue* value) | 100 static inline bool featureWithValidDensity(const String& mediaFeature, const CSS ParserValue* value) |
101 { | 101 { |
102 if ((value->unit != CSSPrimitiveValue::CSS_DPPX && value->unit != CSSPrimiti veValue::CSS_DPI && value->unit != CSSPrimitiveValue::CSS_DPCM) || value->fValue <= 0) | 102 if ((value->unit != CSSPrimitiveValue::CSS_DPPX && value->unit != CSSPrimiti veValue::CSS_DPI && value->unit != CSSPrimitiveValue::CSS_DPCM) || value->fValue <= 0) |
103 return false; | 103 return false; |
104 | 104 |
105 return mediaFeature == MediaFeatureNames::resolutionMediaFeature | 105 return mediaFeature == MediaFeatureNames::resolutionMediaFeature |
106 || mediaFeature == MediaFeatureNames::maxResolutionMediaFeature | 106 || mediaFeature == MediaFeatureNames::maxResolutionMediaFeature |
107 || mediaFeature == MediaFeatureNames::minResolutionMediaFeature; | 107 || mediaFeature == MediaFeatureNames::minResolutionMediaFeature; |
108 } | 108 } |
109 | 109 |
110 static inline bool featureWithPositiveInteger(const AtomicString& mediaFeature, const CSSParserValue* value) | 110 static inline bool featureWithPositiveInteger(const String& mediaFeature, const CSSParserValue* value) |
111 { | 111 { |
112 if (!value->isInt || value->fValue < 0) | 112 if (!value->isInt || value->fValue < 0) |
113 return false; | 113 return false; |
114 | 114 |
115 return mediaFeature == MediaFeatureNames::colorMediaFeature | 115 return mediaFeature == MediaFeatureNames::colorMediaFeature |
116 || mediaFeature == MediaFeatureNames::maxColorMediaFeature | 116 || mediaFeature == MediaFeatureNames::maxColorMediaFeature |
117 || mediaFeature == MediaFeatureNames::minColorMediaFeature | 117 || mediaFeature == MediaFeatureNames::minColorMediaFeature |
118 || mediaFeature == MediaFeatureNames::colorIndexMediaFeature | 118 || mediaFeature == MediaFeatureNames::colorIndexMediaFeature |
119 || mediaFeature == MediaFeatureNames::maxColorIndexMediaFeature | 119 || mediaFeature == MediaFeatureNames::maxColorIndexMediaFeature |
120 || mediaFeature == MediaFeatureNames::minColorIndexMediaFeature | 120 || mediaFeature == MediaFeatureNames::minColorIndexMediaFeature |
121 || mediaFeature == MediaFeatureNames::monochromeMediaFeature | 121 || mediaFeature == MediaFeatureNames::monochromeMediaFeature |
122 || mediaFeature == MediaFeatureNames::minMonochromeMediaFeature | 122 || mediaFeature == MediaFeatureNames::minMonochromeMediaFeature |
123 || mediaFeature == MediaFeatureNames::maxMonochromeMediaFeature; | 123 || mediaFeature == MediaFeatureNames::maxMonochromeMediaFeature; |
124 } | 124 } |
125 | 125 |
126 static inline bool featureWithPositiveNumber(const AtomicString& mediaFeature, c onst CSSParserValue* value) | 126 static inline bool featureWithPositiveNumber(const String& mediaFeature, const C SSParserValue* value) |
127 { | 127 { |
128 if (value->unit != CSSPrimitiveValue::CSS_NUMBER || value->fValue < 0) | 128 if (value->unit != CSSPrimitiveValue::CSS_NUMBER || value->fValue < 0) |
129 return false; | 129 return false; |
130 | 130 |
131 return mediaFeature == MediaFeatureNames::transform2dMediaFeature | 131 return mediaFeature == MediaFeatureNames::transform2dMediaFeature |
132 || mediaFeature == MediaFeatureNames::transform3dMediaFeature | 132 || mediaFeature == MediaFeatureNames::transform3dMediaFeature |
133 || mediaFeature == MediaFeatureNames::deprecatedTransitionMediaFeature | 133 || mediaFeature == MediaFeatureNames::deprecatedTransitionMediaFeature |
134 || mediaFeature == MediaFeatureNames::animationMediaFeature | 134 || mediaFeature == MediaFeatureNames::animationMediaFeature |
135 || mediaFeature == MediaFeatureNames::devicePixelRatioMediaFeature | 135 || mediaFeature == MediaFeatureNames::devicePixelRatioMediaFeature |
136 || mediaFeature == MediaFeatureNames::maxDevicePixelRatioMediaFeature | 136 || mediaFeature == MediaFeatureNames::maxDevicePixelRatioMediaFeature |
137 || mediaFeature == MediaFeatureNames::minDevicePixelRatioMediaFeature; | 137 || mediaFeature == MediaFeatureNames::minDevicePixelRatioMediaFeature; |
138 } | 138 } |
139 | 139 |
140 static inline bool featureWithZeroOrOne(const AtomicString& mediaFeature, const CSSParserValue* value) | 140 static inline bool featureWithZeroOrOne(const String& mediaFeature, const CSSPar serValue* value) |
141 { | 141 { |
142 if (!value->isInt || !(value->fValue == 1 || !value->fValue)) | 142 if (!value->isInt || !(value->fValue == 1 || !value->fValue)) |
143 return false; | 143 return false; |
144 | 144 |
145 return mediaFeature == MediaFeatureNames::gridMediaFeature | 145 return mediaFeature == MediaFeatureNames::gridMediaFeature |
146 || mediaFeature == MediaFeatureNames::hoverMediaFeature; | 146 || mediaFeature == MediaFeatureNames::hoverMediaFeature; |
147 } | 147 } |
148 | 148 |
149 static inline bool featureWithAspectRatio(const AtomicString& mediaFeature) | 149 static inline bool featureWithAspectRatio(const String& mediaFeature) |
150 { | 150 { |
151 return mediaFeature == MediaFeatureNames::aspectRatioMediaFeature | 151 return mediaFeature == MediaFeatureNames::aspectRatioMediaFeature |
152 || mediaFeature == MediaFeatureNames::deviceAspectRatioMediaFeature | 152 || mediaFeature == MediaFeatureNames::deviceAspectRatioMediaFeature |
153 || mediaFeature == MediaFeatureNames::minAspectRatioMediaFeature | 153 || mediaFeature == MediaFeatureNames::minAspectRatioMediaFeature |
154 || mediaFeature == MediaFeatureNames::maxAspectRatioMediaFeature | 154 || mediaFeature == MediaFeatureNames::maxAspectRatioMediaFeature |
155 || mediaFeature == MediaFeatureNames::minDeviceAspectRatioMediaFeature | 155 || mediaFeature == MediaFeatureNames::minDeviceAspectRatioMediaFeature |
156 || mediaFeature == MediaFeatureNames::maxDeviceAspectRatioMediaFeature; | 156 || mediaFeature == MediaFeatureNames::maxDeviceAspectRatioMediaFeature; |
157 } | 157 } |
158 | 158 |
159 static inline bool featureWithoutValue(const AtomicString& mediaFeature) | 159 static inline bool featureWithoutValue(const String& mediaFeature) |
160 { | 160 { |
161 // Media features that are prefixed by min/max cannot be used without a valu e. | 161 // Media features that are prefixed by min/max cannot be used without a valu e. |
162 return mediaFeature == MediaFeatureNames::monochromeMediaFeature | 162 return mediaFeature == MediaFeatureNames::monochromeMediaFeature |
163 || mediaFeature == MediaFeatureNames::colorMediaFeature | 163 || mediaFeature == MediaFeatureNames::colorMediaFeature |
164 || mediaFeature == MediaFeatureNames::colorIndexMediaFeature | 164 || mediaFeature == MediaFeatureNames::colorIndexMediaFeature |
165 || mediaFeature == MediaFeatureNames::gridMediaFeature | 165 || mediaFeature == MediaFeatureNames::gridMediaFeature |
166 || mediaFeature == MediaFeatureNames::heightMediaFeature | 166 || mediaFeature == MediaFeatureNames::heightMediaFeature |
167 || mediaFeature == MediaFeatureNames::widthMediaFeature | 167 || mediaFeature == MediaFeatureNames::widthMediaFeature |
168 || mediaFeature == MediaFeatureNames::deviceHeightMediaFeature | 168 || mediaFeature == MediaFeatureNames::deviceHeightMediaFeature |
169 || mediaFeature == MediaFeatureNames::deviceWidthMediaFeature | 169 || mediaFeature == MediaFeatureNames::deviceWidthMediaFeature |
(...skipping 16 matching lines...) Expand all Loading... | |
186 { | 186 { |
187 return m_mediaFeature == MediaFeatureNames::widthMediaFeature | 187 return m_mediaFeature == MediaFeatureNames::widthMediaFeature |
188 || m_mediaFeature == MediaFeatureNames::heightMediaFeature | 188 || m_mediaFeature == MediaFeatureNames::heightMediaFeature |
189 || m_mediaFeature == MediaFeatureNames::minWidthMediaFeature | 189 || m_mediaFeature == MediaFeatureNames::minWidthMediaFeature |
190 || m_mediaFeature == MediaFeatureNames::minHeightMediaFeature | 190 || m_mediaFeature == MediaFeatureNames::minHeightMediaFeature |
191 || m_mediaFeature == MediaFeatureNames::maxWidthMediaFeature | 191 || m_mediaFeature == MediaFeatureNames::maxWidthMediaFeature |
192 || m_mediaFeature == MediaFeatureNames::maxHeightMediaFeature | 192 || m_mediaFeature == MediaFeatureNames::maxHeightMediaFeature |
193 || m_mediaFeature == MediaFeatureNames::orientationMediaFeature | 193 || m_mediaFeature == MediaFeatureNames::orientationMediaFeature |
194 || m_mediaFeature == MediaFeatureNames::aspectRatioMediaFeature | 194 || m_mediaFeature == MediaFeatureNames::aspectRatioMediaFeature |
195 || m_mediaFeature == MediaFeatureNames::minAspectRatioMediaFeature | 195 || m_mediaFeature == MediaFeatureNames::minAspectRatioMediaFeature |
196 || m_mediaFeature == MediaFeatureNames::maxAspectRatioMediaFeature; | 196 || m_mediaFeature == MediaFeatureNames::maxAspectRatioMediaFeature; |
abarth-chromium
2013/07/08 15:12:31
not lgtm
We use AtomicStrings here for two reason
| |
197 } | 197 } |
198 | 198 |
199 MediaQueryExp::MediaQueryExp(const AtomicString& mediaFeature, PassRefPtr<CSSVal ue> value) | 199 MediaQueryExp::MediaQueryExp(const String& mediaFeature, PassRefPtr<CSSValue> va lue) |
200 : m_mediaFeature(mediaFeature) | 200 : m_mediaFeature(mediaFeature) |
201 , m_value(value) | 201 , m_value(value) |
202 { | 202 { |
203 } | 203 } |
204 | 204 |
205 PassOwnPtr<MediaQueryExp> MediaQueryExp::create(const AtomicString& mediaFeature , CSSParserValueList* valueList) | 205 PassOwnPtr<MediaQueryExp> MediaQueryExp::create(const String& mediaFeature, CSSP arserValueList* valueList) |
206 { | 206 { |
207 RefPtr<CSSValue> cssValue; | 207 RefPtr<CSSValue> cssValue; |
208 bool isValid = false; | 208 bool isValid = false; |
209 | 209 |
210 // Create value for media query expression that must have 1 or more values. | 210 // Create value for media query expression that must have 1 or more values. |
211 if (valueList) { | 211 if (valueList) { |
212 if (valueList->size() == 1) { | 212 if (valueList->size() == 1) { |
213 CSSParserValue* value = valueList->current(); | 213 CSSParserValue* value = valueList->current(); |
214 | 214 |
215 if (featureWithCSSValueID(mediaFeature, value)) { | 215 if (featureWithCSSValueID(mediaFeature, value)) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 } | 291 } |
292 | 292 |
293 void MediaQueryExp::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const | 293 void MediaQueryExp::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
294 { | 294 { |
295 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); | 295 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); |
296 info.addMember(m_mediaFeature, "mediaFeature"); | 296 info.addMember(m_mediaFeature, "mediaFeature"); |
297 info.addMember(m_value, "value"); | 297 info.addMember(m_value, "value"); |
298 } | 298 } |
299 | 299 |
300 } // namespace | 300 } // namespace |
OLD | NEW |