OLD | NEW |
---|---|
1 /* | 1 /* |
2 * CSS Media Query Evaluator | 2 * CSS Media Query Evaluator |
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) 2013 Apple Inc. All rights reserved. | 5 * Copyright (C) 2013 Apple Inc. All rights reserved. |
6 * Copyright (C) 2013 Intel Corporation. All rights reserved. | 6 * Copyright (C) 2013 Intel Corporation. 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 22 matching lines...) Expand all Loading... | |
33 #include "CSSValueKeywords.h" | 33 #include "CSSValueKeywords.h" |
34 #include "MediaFeatureNames.h" | 34 #include "MediaFeatureNames.h" |
35 #include "MediaFeatures.h" | 35 #include "MediaFeatures.h" |
36 #include "MediaTypeNames.h" | 36 #include "MediaTypeNames.h" |
37 #include "core/css/CSSAspectRatioValue.h" | 37 #include "core/css/CSSAspectRatioValue.h" |
38 #include "core/css/CSSHelper.h" | 38 #include "core/css/CSSHelper.h" |
39 #include "core/css/CSSPrimitiveValue.h" | 39 #include "core/css/CSSPrimitiveValue.h" |
40 #include "core/css/CSSToLengthConversionData.h" | 40 #include "core/css/CSSToLengthConversionData.h" |
41 #include "core/css/MediaList.h" | 41 #include "core/css/MediaList.h" |
42 #include "core/css/MediaQuery.h" | 42 #include "core/css/MediaQuery.h" |
43 #include "core/css/MediaValues.h" | |
43 #include "core/css/resolver/MediaQueryResult.h" | 44 #include "core/css/resolver/MediaQueryResult.h" |
44 #include "core/dom/NodeRenderStyle.h" | 45 #include "core/dom/NodeRenderStyle.h" |
45 #include "core/frame/FrameHost.h" | 46 #include "core/frame/FrameHost.h" |
46 #include "core/frame/FrameView.h" | 47 #include "core/frame/FrameView.h" |
47 #include "core/frame/LocalFrame.h" | 48 #include "core/frame/LocalFrame.h" |
48 #include "core/frame/Settings.h" | 49 #include "core/frame/Settings.h" |
49 #include "core/inspector/InspectorInstrumentation.h" | 50 #include "core/inspector/InspectorInstrumentation.h" |
50 #include "core/rendering/RenderView.h" | 51 #include "core/rendering/RenderView.h" |
51 #include "core/rendering/compositing/RenderLayerCompositor.h" | 52 #include "core/rendering/compositing/RenderLayerCompositor.h" |
52 #include "core/rendering/style/RenderStyle.h" | 53 #include "core/rendering/style/RenderStyle.h" |
53 #include "platform/PlatformScreen.h" | 54 #include "platform/PlatformScreen.h" |
54 #include "platform/geometry/FloatRect.h" | 55 #include "platform/geometry/FloatRect.h" |
55 #include "wtf/HashMap.h" | 56 #include "wtf/HashMap.h" |
56 | 57 |
57 namespace WebCore { | 58 namespace WebCore { |
58 | 59 |
59 using namespace MediaFeatureNames; | 60 using namespace MediaFeatureNames; |
60 | 61 |
61 enum MediaFeaturePrefix { MinPrefix, MaxPrefix, NoPrefix }; | 62 enum MediaFeaturePrefix { MinPrefix, MaxPrefix, NoPrefix }; |
62 | 63 |
63 typedef bool (*EvalFunc)(CSSValue*, RenderStyle*, LocalFrame*, MediaFeaturePrefi x); | 64 typedef bool (*EvalFunc)(CSSValue*, MediaFeaturePrefix, const MediaValues&); |
64 typedef HashMap<StringImpl*, EvalFunc> FunctionMap; | 65 typedef HashMap<StringImpl*, EvalFunc> FunctionMap; |
65 static FunctionMap* gFunctionMap; | 66 static FunctionMap* gFunctionMap; |
66 | 67 |
67 MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult) | 68 MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult) |
68 : m_frame(0) | 69 : m_expectedResult(mediaFeatureResult) |
69 , m_style(nullptr) | |
70 , m_expResult(mediaFeatureResult) | |
71 { | 70 { |
72 } | 71 } |
73 | 72 |
74 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, bool m ediaFeatureResult) | 73 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, bool m ediaFeatureResult) |
75 : m_mediaType(acceptedMediaType) | 74 : m_mediaType(acceptedMediaType) |
76 , m_frame(0) | 75 , m_expectedResult(mediaFeatureResult) |
77 , m_style(nullptr) | |
78 , m_expResult(mediaFeatureResult) | |
79 { | 76 { |
80 } | 77 } |
81 | 78 |
82 MediaQueryEvaluator::MediaQueryEvaluator(const char* acceptedMediaType, bool med iaFeatureResult) | 79 MediaQueryEvaluator::MediaQueryEvaluator(const char* acceptedMediaType, bool med iaFeatureResult) |
83 : m_mediaType(acceptedMediaType) | 80 : m_mediaType(acceptedMediaType) |
84 , m_frame(0) | 81 , m_expectedResult(mediaFeatureResult) |
85 , m_style(nullptr) | |
86 , m_expResult(mediaFeatureResult) | |
87 { | 82 { |
88 } | 83 } |
89 | 84 |
90 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, LocalF rame* frame, RenderStyle* style) | 85 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, LocalF rame* frame, RenderStyle* style) |
91 : m_mediaType(acceptedMediaType) | 86 : m_mediaType(acceptedMediaType) |
92 , m_frame(frame) | 87 , m_expectedResult(false) // Doesn't matter when we have m_frame and m_style . |
93 , m_style(style) | 88 , m_mediaValues(MediaValues::create(frame, style, MediaValues::DynamicMode)) |
94 , m_expResult(false) // Doesn't matter when we have m_frame and m_style. | |
95 { | 89 { |
96 } | 90 } |
97 | 91 |
92 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, const MediaValues& mediaValues) | |
93 : m_mediaType(acceptedMediaType) | |
94 , m_expectedResult(false) // Doesn't matter when we have mediaValues. | |
95 , m_mediaValues(mediaValues.copy()) | |
96 { | |
97 } | |
98 | |
98 MediaQueryEvaluator::~MediaQueryEvaluator() | 99 MediaQueryEvaluator::~MediaQueryEvaluator() |
99 { | 100 { |
100 } | 101 } |
101 | 102 |
102 bool MediaQueryEvaluator::mediaTypeMatch(const String& mediaTypeToMatch) const | 103 bool MediaQueryEvaluator::mediaTypeMatch(const String& mediaTypeToMatch) const |
103 { | 104 { |
104 return mediaTypeToMatch.isEmpty() | 105 return mediaTypeToMatch.isEmpty() |
105 || equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all) | 106 || equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all) |
106 || equalIgnoringCase(mediaTypeToMatch, m_mediaType); | 107 || equalIgnoringCase(mediaTypeToMatch, m_mediaType); |
107 } | 108 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 for (; j < expressions.size(); ++j) { | 142 for (; j < expressions.size(); ++j) { |
142 bool exprResult = eval(expressions.at(j).get()); | 143 bool exprResult = eval(expressions.at(j).get()); |
143 if (viewportDependentMediaQueryResults && expressions.at(j)->isV iewportDependent()) | 144 if (viewportDependentMediaQueryResults && expressions.at(j)->isV iewportDependent()) |
144 viewportDependentMediaQueryResults->append(adoptRefWillBeNoo p(new MediaQueryResult(*expressions.at(j), exprResult))); | 145 viewportDependentMediaQueryResults->append(adoptRefWillBeNoo p(new MediaQueryResult(*expressions.at(j), exprResult))); |
145 if (!exprResult) | 146 if (!exprResult) |
146 break; | 147 break; |
147 } | 148 } |
148 | 149 |
149 // Assume true if we are at the end of the list, otherwise assume fa lse. | 150 // Assume true if we are at the end of the list, otherwise assume fa lse. |
150 result = applyRestrictor(query->restrictor(), expressions.size() == j); | 151 result = applyRestrictor(query->restrictor(), expressions.size() == j); |
151 } else | 152 } else { |
152 result = applyRestrictor(query->restrictor(), false); | 153 result = applyRestrictor(query->restrictor(), false); |
154 } | |
153 } | 155 } |
154 | 156 |
155 return result; | 157 return result; |
156 } | 158 } |
157 | 159 |
158 template<typename T> | 160 template<typename T> |
159 bool compareValue(T a, T b, MediaFeaturePrefix op) | 161 bool compareValue(T a, T b, MediaFeaturePrefix op) |
160 { | 162 { |
161 switch (op) { | 163 switch (op) { |
162 case MinPrefix: | 164 case MinPrefix: |
(...skipping 19 matching lines...) Expand all Loading... | |
182 static bool numberValue(CSSValue* value, float& result) | 184 static bool numberValue(CSSValue* value, float& result) |
183 { | 185 { |
184 if (value->isPrimitiveValue() | 186 if (value->isPrimitiveValue() |
185 && toCSSPrimitiveValue(value)->isNumber()) { | 187 && toCSSPrimitiveValue(value)->isNumber()) { |
186 result = toCSSPrimitiveValue(value)->getFloatValue(CSSPrimitiveValue::CS S_NUMBER); | 188 result = toCSSPrimitiveValue(value)->getFloatValue(CSSPrimitiveValue::CS S_NUMBER); |
187 return true; | 189 return true; |
188 } | 190 } |
189 return false; | 191 return false; |
190 } | 192 } |
191 | 193 |
192 static bool colorMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame* fra me, MediaFeaturePrefix op) | 194 static bool colorMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) |
193 { | 195 { |
194 int bitsPerComponent = screenDepthPerComponent(frame->view()); | |
195 float number; | 196 float number; |
197 int bitsPerComponent = mediaValues.colorBitsPerComponent(); | |
196 if (value) | 198 if (value) |
197 return numberValue(value, number) && compareValue(bitsPerComponent, stat ic_cast<int>(number), op); | 199 return numberValue(value, number) && compareValue(bitsPerComponent, stat ic_cast<int>(number), op); |
198 | 200 |
199 return bitsPerComponent != 0; | 201 return bitsPerComponent != 0; |
200 } | 202 } |
201 | 203 |
202 static bool colorIndexMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame *, MediaFeaturePrefix op) | 204 static bool colorIndexMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, c onst MediaValues&) |
203 { | 205 { |
204 // FIXME: We currently assume that we do not support indexed displays, as it is unknown | 206 // FIXME: We currently assume that we do not support indexed displays, as it is unknown |
205 // how to retrieve the information if the display mode is indexed. This matc hes Firefox. | 207 // how to retrieve the information if the display mode is indexed. This matc hes Firefox. |
206 if (!value) | 208 if (!value) |
207 return false; | 209 return false; |
208 | 210 |
209 // Acording to spec, if the device does not use a color lookup table, the va lue is zero. | 211 // Acording to spec, if the device does not use a color lookup table, the va lue is zero. |
210 float number; | 212 float number; |
211 return numberValue(value, number) && compareValue(0, static_cast<int>(number ), op); | 213 return numberValue(value, number) && compareValue(0, static_cast<int>(number ), op); |
212 } | 214 } |
213 | 215 |
214 static bool monochromeMediaFeatureEval(CSSValue* value, RenderStyle* style, Loca lFrame* frame, MediaFeaturePrefix op) | 216 static bool monochromeMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, c onst MediaValues& mediaValues) |
215 { | 217 { |
216 if (!screenIsMonochrome(frame->view())) { | 218 if (!mediaValues.monochromeBitsPerComponent()) { |
217 if (value) { | 219 if (value) { |
218 float number; | 220 float number; |
219 return numberValue(value, number) && compareValue(0, static_cast<int >(number), op); | 221 return numberValue(value, number) && compareValue(0, static_cast<int >(number), op); |
220 } | 222 } |
221 return false; | 223 return false; |
222 } | 224 } |
223 | 225 |
224 return colorMediaFeatureEval(value, style, frame, op); | 226 return colorMediaFeatureEval(value, op, mediaValues); |
225 } | 227 } |
226 | 228 |
227 static IntSize viewportSize(FrameView* view) | 229 static bool orientationMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, con st MediaValues& mediaValues) |
228 { | 230 { |
229 return view->layoutSize(IncludeScrollbars); | 231 int width = mediaValues.viewportWidth(); |
230 } | 232 int height = mediaValues.viewportHeight(); |
231 | 233 |
232 static bool orientationMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFram e* frame, MediaFeaturePrefix) | |
233 { | |
234 FrameView* view = frame->view(); | |
235 int width = viewportSize(view).width(); | |
236 int height = viewportSize(view).height(); | |
237 if (value && value->isPrimitiveValue()) { | 234 if (value && value->isPrimitiveValue()) { |
238 const CSSValueID id = toCSSPrimitiveValue(value)->getValueID(); | 235 const CSSValueID id = toCSSPrimitiveValue(value)->getValueID(); |
239 if (width > height) // Square viewport is portrait. | 236 if (width > height) // Square viewport is portrait. |
240 return CSSValueLandscape == id; | 237 return CSSValueLandscape == id; |
241 return CSSValuePortrait == id; | 238 return CSSValuePortrait == id; |
242 } | 239 } |
243 | 240 |
244 // Expression (orientation) evaluates to true if width and height >= 0. | 241 // Expression (orientation) evaluates to true if width and height >= 0. |
245 return height >= 0 && width >= 0; | 242 return height >= 0 && width >= 0; |
246 } | 243 } |
247 | 244 |
248 static bool aspectRatioMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFram e* frame, MediaFeaturePrefix op) | 245 static bool aspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) |
249 { | 246 { |
250 if (value) { | 247 if (value) |
251 FrameView* view = frame->view(); | 248 return compareAspectRatioValue(value, mediaValues.viewportWidth(), media Values.viewportHeight(), op); |
252 return compareAspectRatioValue(value, viewportSize(view).width(), viewpo rtSize(view).height(), op); | |
253 } | |
254 | 249 |
255 // ({,min-,max-}aspect-ratio) | 250 // ({,min-,max-}aspect-ratio) |
256 // assume if we have a device, its aspect ratio is non-zero. | 251 // assume if we have a device, its aspect ratio is non-zero. |
257 return true; | 252 return true; |
258 } | 253 } |
259 | 254 |
260 static bool deviceAspectRatioMediaFeatureEval(CSSValue* value, RenderStyle*, Loc alFrame* frame, MediaFeaturePrefix op) | 255 static bool deviceAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefi x op, const MediaValues& mediaValues) |
261 { | 256 { |
262 if (value) { | 257 if (value) |
263 FloatRect sg = screenRect(frame->view()); | 258 return compareAspectRatioValue(value, mediaValues.deviceWidth(), mediaVa lues.deviceHeight(), op); |
264 return compareAspectRatioValue(value, static_cast<int>(sg.width()), stat ic_cast<int>(sg.height()), op); | |
265 } | |
266 | 259 |
267 // ({,min-,max-}device-aspect-ratio) | 260 // ({,min-,max-}device-aspect-ratio) |
268 // assume if we have a device, its aspect ratio is non-zero. | 261 // assume if we have a device, its aspect ratio is non-zero. |
269 return true; | 262 return true; |
270 } | 263 } |
271 | 264 |
272 static bool evalResolution(CSSValue* value, LocalFrame* frame, MediaFeaturePrefi x op) | 265 static bool evalResolution(CSSValue* value, MediaFeaturePrefix op, const MediaVa lues& mediaValues) |
273 { | 266 { |
274 // According to MQ4, only 'screen', 'print' and 'speech' may match. | 267 // According to MQ4, only 'screen', 'print' and 'speech' may match. |
275 // FIXME: What should speech match? https://www.w3.org/Style/CSS/Tracker/iss ues/348 | 268 // FIXME: What should speech match? https://www.w3.org/Style/CSS/Tracker/iss ues/348 |
276 float actualResolution = 0; | 269 float actualResolution = 0; |
277 | 270 |
278 // This checks the actual media type applied to the document, and we know | 271 // This checks the actual media type applied to the document, and we know |
279 // this method only got called if this media type matches the one defined | 272 // this method only got called if this media type matches the one defined |
280 // in the query. Thus, if if the document's media type is "print", the | 273 // in the query. Thus, if if the document's media type is "print", the |
281 // media type of the query will either be "print" or "all". | 274 // media type of the query will either be "print" or "all". |
282 String mediaType = frame->view()->mediaType(); | 275 if (mediaValues.screenMediaType()) { |
283 if (equalIgnoringCase(mediaType, "screen")) | 276 actualResolution = clampTo<float>(mediaValues.devicePixelRatio()); |
284 actualResolution = clampTo<float>(frame->devicePixelRatio()); | 277 } else if (mediaValues.printMediaType()) { |
285 else if (equalIgnoringCase(mediaType, "print")) { | |
286 // The resolution of images while printing should not depend on the DPI | 278 // The resolution of images while printing should not depend on the DPI |
287 // of the screen. Until we support proper ways of querying this info | 279 // of the screen. Until we support proper ways of querying this info |
288 // we use 300px which is considered minimum for current printers. | 280 // we use 300px which is considered minimum for current printers. |
289 actualResolution = 300 / cssPixelsPerInch; | 281 actualResolution = 300 / cssPixelsPerInch; |
290 } | 282 } |
291 | 283 |
292 if (!value) | 284 if (!value) |
293 return !!actualResolution; | 285 return !!actualResolution; |
294 | 286 |
295 if (!value->isPrimitiveValue()) | 287 if (!value->isPrimitiveValue()) |
(...skipping 14 matching lines...) Expand all Loading... | |
310 // approximates the reference pixel". With that in mind, allowing 2 deci mal | 302 // approximates the reference pixel". With that in mind, allowing 2 deci mal |
311 // point precision seems appropriate. | 303 // point precision seems appropriate. |
312 return compareValue( | 304 return compareValue( |
313 floorf(0.5 + 100 * actualResolution) / 100, | 305 floorf(0.5 + 100 * actualResolution) / 100, |
314 floorf(0.5 + 100 * resolution->getFloatValue(CSSPrimitiveValue::CSS_ DPPX)) / 100, op); | 306 floorf(0.5 + 100 * resolution->getFloatValue(CSSPrimitiveValue::CSS_ DPPX)) / 100, op); |
315 } | 307 } |
316 | 308 |
317 return compareValue(actualResolution, resolution->getFloatValue(CSSPrimitive Value::CSS_DPPX), op); | 309 return compareValue(actualResolution, resolution->getFloatValue(CSSPrimitive Value::CSS_DPPX), op); |
318 } | 310 } |
319 | 311 |
320 static bool devicePixelRatioMediaFeatureEval(CSSValue *value, RenderStyle*, Loca lFrame* frame, MediaFeaturePrefix op) | 312 static bool devicePixelRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) |
321 { | 313 { |
322 UseCounter::count(frame->document(), UseCounter::PrefixedDevicePixelRatioMed iaFeature); | 314 UseCounter::count(mediaValues.document(), UseCounter::PrefixedDevicePixelRat ioMediaFeature); |
323 | 315 |
324 return (!value || toCSSPrimitiveValue(value)->isNumber()) && evalResolution( value, frame, op); | 316 return (!value || toCSSPrimitiveValue(value)->isNumber()) && evalResolution( value, op, mediaValues); |
325 } | 317 } |
326 | 318 |
327 static bool resolutionMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame * frame, MediaFeaturePrefix op) | 319 static bool resolutionMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, c onst MediaValues& MediaValues) |
328 { | 320 { |
329 return (!value || toCSSPrimitiveValue(value)->isResolution()) && evalResolut ion(value, frame, op); | 321 return (!value || toCSSPrimitiveValue(value)->isResolution()) && evalResolut ion(value, op, MediaValues); |
330 } | 322 } |
331 | 323 |
332 static bool gridMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame*, Med iaFeaturePrefix op) | 324 static bool gridMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const M ediaValues&) |
333 { | 325 { |
334 // if output device is bitmap, grid: 0 == true | 326 // if output device is bitmap, grid: 0 == true |
335 // assume we have bitmap device | 327 // assume we have bitmap device |
336 float number; | 328 float number; |
337 if (value && numberValue(value, number)) | 329 if (value && numberValue(value, number)) |
338 return compareValue(static_cast<int>(number), 0, op); | 330 return compareValue(static_cast<int>(number), 0, op); |
339 return false; | 331 return false; |
340 } | 332 } |
341 | 333 |
342 static bool computeLength(CSSValue* value, bool strict, RenderStyle* initialStyl e, int& result) | 334 static bool computeLength(CSSValue* value, bool strict, RenderStyle* initialStyl e, int defaultFontSize, int& result) |
343 { | 335 { |
344 if (!value->isPrimitiveValue()) | 336 if (!value->isPrimitiveValue()) |
345 return false; | 337 return false; |
346 | 338 |
347 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); | 339 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); |
348 | 340 |
349 if (primitiveValue->isNumber()) { | 341 if (primitiveValue->isNumber()) { |
350 result = primitiveValue->getIntValue(); | 342 result = primitiveValue->getIntValue(); |
351 return !strict || !result; | 343 return !strict || !result; |
352 } | 344 } |
353 | 345 |
354 if (primitiveValue->isLength()) { | 346 if (primitiveValue->isLength()) { |
355 // Relative (like EM) and root relative (like REM) units are always reso lved against | 347 if (initialStyle) { |
356 // the initial values for media queries, hence the two initialStyle para meters. | 348 // Relative (like EM) and root relative (like REM) units are always resolved against |
357 // FIXME: We need to plumb viewport unit support down to here. | 349 // the initial values for media queries, hence the two initialStyle parameters. |
358 result = primitiveValue->computeLength<int>(CSSToLengthConversionData(in itialStyle, initialStyle, 0, 1.0 /* zoom */, true /* computingFontSize */)); | 350 // FIXME: We need to plumb viewport unit support down to here. |
351 result = primitiveValue->computeLength<int>(CSSToLengthConversionDat a(initialStyle, initialStyle, 0, 1.0 /* zoom */, true /* computingFontSize */)); | |
352 } else { | |
353 // We're running in a background thread, so RenderStyle is not avail able. | |
354 // Nevertheless, we can evaluate length MQs with em, rem or px units . | |
355 // FIXME: Learn to support more units here, or teach CSSPrimitiveVal ue about MediaValues. | |
356 unsigned short type = primitiveValue->primitiveType(); | |
357 int factor = 0; | |
358 if (type == CSSPrimitiveValue::CSS_EMS || type == CSSPrimitiveValue: :CSS_REMS) { | |
359 if (defaultFontSize > 0) | |
360 factor = defaultFontSize; | |
361 else | |
362 return false; | |
363 } else if (type == CSSPrimitiveValue::CSS_PX) { | |
364 factor = 1; | |
365 } else { | |
366 return false; | |
367 } | |
368 result = roundForImpreciseConversion<int>(primitiveValue->getDoubleV alue()*factor); | |
abarth-chromium
2014/03/27 21:01:55
Should we extract this bit into a separate functio
| |
369 } | |
359 return true; | 370 return true; |
360 } | 371 } |
361 | 372 |
362 return false; | 373 return false; |
363 } | 374 } |
364 | 375 |
365 static bool deviceHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, Lo calFrame* frame, MediaFeaturePrefix op) | 376 static bool deviceHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) |
366 { | 377 { |
367 if (value) { | 378 if (value) { |
368 int length; | 379 int length; |
369 if (!computeLength(value, !frame->document()->inQuirksMode(), style, len gth)) | 380 return computeLength(value, mediaValues.strictMode(), mediaValues.style( ), mediaValues.defaultFontSize(), length) |
370 return false; | 381 && compareValue(static_cast<int>(mediaValues.deviceHeight()), length , op); |
371 int height = static_cast<int>(screenRect(frame->view()).height()); | |
372 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk()) | |
373 height = lroundf(height * frame->host()->deviceScaleFactor()); | |
374 return compareValue(height, length, op); | |
375 } | 382 } |
376 // ({,min-,max-}device-height) | 383 // ({,min-,max-}device-height) |
377 // assume if we have a device, assume non-zero | 384 // assume if we have a device, assume non-zero |
378 return true; | 385 return true; |
379 } | 386 } |
380 | 387 |
381 static bool deviceWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, Loc alFrame* frame, MediaFeaturePrefix op) | 388 static bool deviceWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) |
382 { | 389 { |
383 if (value) { | 390 if (value) { |
384 int length; | 391 int length; |
385 if (!computeLength(value, !frame->document()->inQuirksMode(), style, len gth)) | 392 return computeLength(value, mediaValues.strictMode(), mediaValues.style( ), mediaValues.defaultFontSize(), length) |
386 return false; | 393 && compareValue(static_cast<int>(mediaValues.deviceWidth()), length, op); |
387 int width = static_cast<int>(screenRect(frame->view()).width()); | |
388 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk()) | |
389 width = lroundf(width * frame->host()->deviceScaleFactor()); | |
390 return compareValue(width, length, op); | |
391 } | 394 } |
392 // ({,min-,max-}device-width) | 395 // ({,min-,max-}device-width) |
393 // assume if we have a device, assume non-zero | 396 // assume if we have a device, assume non-zero |
394 return true; | 397 return true; |
395 } | 398 } |
396 | 399 |
397 static bool heightMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFra me* frame, MediaFeaturePrefix op) | 400 static bool heightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) |
398 { | 401 { |
399 FrameView* view = frame->view(); | 402 int height = mediaValues.viewportHeight(); |
400 | |
401 int height = viewportSize(view).height(); | |
402 if (value) { | 403 if (value) { |
403 if (RenderView* renderView = frame->document()->renderView()) | |
404 height = adjustForAbsoluteZoom(height, renderView); | |
405 int length; | 404 int length; |
406 return computeLength(value, !frame->document()->inQuirksMode(), style, l ength) && compareValue(height, length, op); | 405 return computeLength(value, mediaValues.strictMode(), mediaValues.style( ), mediaValues.defaultFontSize(), length) |
406 && compareValue(height, length, op); | |
407 } | 407 } |
408 | 408 |
409 return height; | 409 return height; |
410 } | 410 } |
411 | 411 |
412 static bool widthMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFram e* frame, MediaFeaturePrefix op) | 412 static bool widthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) |
413 { | 413 { |
414 FrameView* view = frame->view(); | 414 int width = mediaValues.viewportWidth(); |
415 | |
416 int width = viewportSize(view).width(); | |
417 if (value) { | 415 if (value) { |
418 if (RenderView* renderView = frame->document()->renderView()) | |
419 width = adjustForAbsoluteZoom(width, renderView); | |
420 int length; | 416 int length; |
421 return computeLength(value, !frame->document()->inQuirksMode(), style, l ength) && compareValue(width, length, op); | 417 return computeLength(value, mediaValues.strictMode(), mediaValues.style( ), mediaValues.defaultFontSize(), length) |
418 && compareValue(width, length, op); | |
422 } | 419 } |
423 | 420 |
424 return width; | 421 return width; |
425 } | 422 } |
426 | 423 |
427 // Rest of the functions are trampolines which set the prefix according to the m edia feature expression used. | 424 // Rest of the functions are trampolines which set the prefix according to the m edia feature expression used. |
428 | 425 |
429 static bool minColorMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalF rame* frame, MediaFeaturePrefix) | 426 static bool minColorMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
430 { | 427 { |
431 return colorMediaFeatureEval(value, style, frame, MinPrefix); | 428 return colorMediaFeatureEval(value, MinPrefix, mediaValues); |
432 } | 429 } |
433 | 430 |
434 static bool maxColorMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalF rame* frame, MediaFeaturePrefix) | 431 static bool maxColorMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
435 { | 432 { |
436 return colorMediaFeatureEval(value, style, frame, MaxPrefix); | 433 return colorMediaFeatureEval(value, MaxPrefix, mediaValues); |
437 } | 434 } |
438 | 435 |
439 static bool minColorIndexMediaFeatureEval(CSSValue* value, RenderStyle* style, L ocalFrame* frame, MediaFeaturePrefix) | 436 static bool minColorIndexMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues) |
440 { | 437 { |
441 return colorIndexMediaFeatureEval(value, style, frame, MinPrefix); | 438 return colorIndexMediaFeatureEval(value, MinPrefix, mediaValues); |
442 } | 439 } |
443 | 440 |
444 static bool maxColorIndexMediaFeatureEval(CSSValue* value, RenderStyle* style, L ocalFrame* frame, MediaFeaturePrefix) | 441 static bool maxColorIndexMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues) |
445 { | 442 { |
446 return colorIndexMediaFeatureEval(value, style, frame, MaxPrefix); | 443 return colorIndexMediaFeatureEval(value, MaxPrefix, mediaValues); |
447 } | 444 } |
448 | 445 |
449 static bool minMonochromeMediaFeatureEval(CSSValue* value, RenderStyle* style, L ocalFrame* frame, MediaFeaturePrefix) | 446 static bool minMonochromeMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues) |
450 { | 447 { |
451 return monochromeMediaFeatureEval(value, style, frame, MinPrefix); | 448 return monochromeMediaFeatureEval(value, MinPrefix, mediaValues); |
452 } | 449 } |
453 | 450 |
454 static bool maxMonochromeMediaFeatureEval(CSSValue* value, RenderStyle* style, L ocalFrame* frame, MediaFeaturePrefix) | 451 static bool maxMonochromeMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues) |
455 { | 452 { |
456 return monochromeMediaFeatureEval(value, style, frame, MaxPrefix); | 453 return monochromeMediaFeatureEval(value, MaxPrefix, mediaValues); |
457 } | 454 } |
458 | 455 |
459 static bool minAspectRatioMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFrame* frame, MediaFeaturePrefix) | 456 static bool minAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
460 { | 457 { |
461 return aspectRatioMediaFeatureEval(value, style, frame, MinPrefix); | 458 return aspectRatioMediaFeatureEval(value, MinPrefix, mediaValues); |
462 } | 459 } |
463 | 460 |
464 static bool maxAspectRatioMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFrame* frame, MediaFeaturePrefix) | 461 static bool maxAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
465 { | 462 { |
466 return aspectRatioMediaFeatureEval(value, style, frame, MaxPrefix); | 463 return aspectRatioMediaFeatureEval(value, MaxPrefix, mediaValues); |
467 } | 464 } |
468 | 465 |
469 static bool minDeviceAspectRatioMediaFeatureEval(CSSValue* value, RenderStyle* s tyle, LocalFrame* frame, MediaFeaturePrefix) | 466 static bool minDeviceAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePr efix, const MediaValues& mediaValues) |
470 { | 467 { |
471 return deviceAspectRatioMediaFeatureEval(value, style, frame, MinPrefix); | 468 return deviceAspectRatioMediaFeatureEval(value, MinPrefix, mediaValues); |
472 } | 469 } |
473 | 470 |
474 static bool maxDeviceAspectRatioMediaFeatureEval(CSSValue* value, RenderStyle* s tyle, LocalFrame* frame, MediaFeaturePrefix) | 471 static bool maxDeviceAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePr efix, const MediaValues& mediaValues) |
475 { | 472 { |
476 return deviceAspectRatioMediaFeatureEval(value, style, frame, MaxPrefix); | 473 return deviceAspectRatioMediaFeatureEval(value, MaxPrefix, mediaValues); |
477 } | 474 } |
478 | 475 |
479 static bool minDevicePixelRatioMediaFeatureEval(CSSValue* value, RenderStyle* st yle, LocalFrame* frame, MediaFeaturePrefix) | 476 static bool minDevicePixelRatioMediaFeatureEval(CSSValue* value, MediaFeaturePre fix, const MediaValues& mediaValues) |
480 { | 477 { |
481 UseCounter::count(frame->document(), UseCounter::PrefixedMinDevicePixelRatio MediaFeature); | 478 UseCounter::count(mediaValues.document(), UseCounter::PrefixedMinDevicePixel RatioMediaFeature); |
482 | 479 |
483 return devicePixelRatioMediaFeatureEval(value, style, frame, MinPrefix); | 480 return devicePixelRatioMediaFeatureEval(value, MinPrefix, mediaValues); |
484 } | 481 } |
485 | 482 |
486 static bool maxDevicePixelRatioMediaFeatureEval(CSSValue* value, RenderStyle* st yle, LocalFrame* frame, MediaFeaturePrefix) | 483 static bool maxDevicePixelRatioMediaFeatureEval(CSSValue* value, MediaFeaturePre fix, const MediaValues& mediaValues) |
487 { | 484 { |
488 UseCounter::count(frame->document(), UseCounter::PrefixedMaxDevicePixelRatio MediaFeature); | 485 UseCounter::count(mediaValues.document(), UseCounter::PrefixedMaxDevicePixel RatioMediaFeature); |
489 | 486 |
490 return devicePixelRatioMediaFeatureEval(value, style, frame, MaxPrefix); | 487 return devicePixelRatioMediaFeatureEval(value, MaxPrefix, mediaValues); |
491 } | 488 } |
492 | 489 |
493 static bool minHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, Local Frame* frame, MediaFeaturePrefix) | 490 static bool minHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
494 { | 491 { |
495 return heightMediaFeatureEval(value, style, frame, MinPrefix); | 492 return heightMediaFeatureEval(value, MinPrefix, mediaValues); |
496 } | 493 } |
497 | 494 |
498 static bool maxHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, Local Frame* frame, MediaFeaturePrefix) | 495 static bool maxHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
499 { | 496 { |
500 return heightMediaFeatureEval(value, style, frame, MaxPrefix); | 497 return heightMediaFeatureEval(value, MaxPrefix, mediaValues); |
501 } | 498 } |
502 | 499 |
503 static bool minWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalF rame* frame, MediaFeaturePrefix) | 500 static bool minWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
504 { | 501 { |
505 return widthMediaFeatureEval(value, style, frame, MinPrefix); | 502 return widthMediaFeatureEval(value, MinPrefix, mediaValues); |
506 } | 503 } |
507 | 504 |
508 static bool maxWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalF rame* frame, MediaFeaturePrefix) | 505 static bool maxWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
509 { | 506 { |
510 return widthMediaFeatureEval(value, style, frame, MaxPrefix); | 507 return widthMediaFeatureEval(value, MaxPrefix, mediaValues); |
511 } | 508 } |
512 | 509 |
513 static bool minDeviceHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFrame* frame, MediaFeaturePrefix) | 510 static bool minDeviceHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
514 { | 511 { |
515 return deviceHeightMediaFeatureEval(value, style, frame, MinPrefix); | 512 return deviceHeightMediaFeatureEval(value, MinPrefix, mediaValues); |
516 } | 513 } |
517 | 514 |
518 static bool maxDeviceHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFrame* frame, MediaFeaturePrefix) | 515 static bool maxDeviceHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
519 { | 516 { |
520 return deviceHeightMediaFeatureEval(value, style, frame, MaxPrefix); | 517 return deviceHeightMediaFeatureEval(value, MaxPrefix, mediaValues); |
521 } | 518 } |
522 | 519 |
523 static bool minDeviceWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFrame* frame, MediaFeaturePrefix) | 520 static bool minDeviceWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
524 { | 521 { |
525 return deviceWidthMediaFeatureEval(value, style, frame, MinPrefix); | 522 return deviceWidthMediaFeatureEval(value, MinPrefix, mediaValues); |
526 } | 523 } |
527 | 524 |
528 static bool maxDeviceWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFrame* frame, MediaFeaturePrefix) | 525 static bool maxDeviceWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
529 { | 526 { |
530 return deviceWidthMediaFeatureEval(value, style, frame, MaxPrefix); | 527 return deviceWidthMediaFeatureEval(value, MaxPrefix, mediaValues); |
531 } | 528 } |
532 | 529 |
533 static bool minResolutionMediaFeatureEval(CSSValue* value, RenderStyle* style, L ocalFrame* frame, MediaFeaturePrefix) | 530 static bool minResolutionMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues) |
534 { | 531 { |
535 return resolutionMediaFeatureEval(value, style, frame, MinPrefix); | 532 return resolutionMediaFeatureEval(value, MinPrefix, mediaValues); |
536 } | 533 } |
537 | 534 |
538 static bool maxResolutionMediaFeatureEval(CSSValue* value, RenderStyle* style, L ocalFrame* frame, MediaFeaturePrefix) | 535 static bool maxResolutionMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues) |
539 { | 536 { |
540 return resolutionMediaFeatureEval(value, style, frame, MaxPrefix); | 537 return resolutionMediaFeatureEval(value, MaxPrefix, mediaValues); |
541 } | 538 } |
542 | 539 |
543 static bool animationMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame* frame, MediaFeaturePrefix op) | 540 static bool animationMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, co nst MediaValues& mediaValues) |
544 { | 541 { |
545 UseCounter::count(frame->document(), UseCounter::PrefixedAnimationMediaFeatu re); | 542 UseCounter::count(mediaValues.document(), UseCounter::PrefixedAnimationMedia Feature); |
546 | 543 |
547 if (value) { | 544 if (value) { |
548 float number; | 545 float number; |
549 return numberValue(value, number) && compareValue(1, static_cast<int>(nu mber), op); | 546 return numberValue(value, number) && compareValue(1, static_cast<int>(nu mber), op); |
550 } | 547 } |
551 return true; | 548 return true; |
552 } | 549 } |
553 | 550 |
554 static bool transform2dMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFram e* frame, MediaFeaturePrefix op) | 551 static bool transform2dMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) |
555 { | 552 { |
556 UseCounter::count(frame->document(), UseCounter::PrefixedTransform2dMediaFea ture); | 553 UseCounter::count(mediaValues.document(), UseCounter::PrefixedTransform2dMed iaFeature); |
557 | 554 |
558 if (value) { | 555 if (value) { |
559 float number; | 556 float number; |
560 return numberValue(value, number) && compareValue(1, static_cast<int>(nu mber), op); | 557 return numberValue(value, number) && compareValue(1, static_cast<int>(nu mber), op); |
561 } | 558 } |
562 return true; | 559 return true; |
563 } | 560 } |
564 | 561 |
565 static bool transform3dMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFram e* frame, MediaFeaturePrefix op) | 562 static bool transform3dMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) |
566 { | 563 { |
567 UseCounter::count(frame->document(), UseCounter::PrefixedTransform3dMediaFea ture); | 564 UseCounter::count(mediaValues.document(), UseCounter::PrefixedTransform3dMed iaFeature); |
568 | 565 |
569 bool returnValueIfNoParameter; | 566 bool returnValueIfNoParameter; |
570 int have3dRendering; | 567 int have3dRendering; |
571 | 568 |
572 bool threeDEnabled = false; | 569 bool threeDEnabled = mediaValues.threeDEnabled(); |
573 if (RenderView* view = frame->contentRenderer()) | |
574 threeDEnabled = view->compositor()->canRender3DTransforms(); | |
575 | 570 |
576 returnValueIfNoParameter = threeDEnabled; | 571 returnValueIfNoParameter = threeDEnabled; |
577 have3dRendering = threeDEnabled ? 1 : 0; | 572 have3dRendering = threeDEnabled ? 1 : 0; |
578 | 573 |
579 if (value) { | 574 if (value) { |
580 float number; | 575 float number; |
581 return numberValue(value, number) && compareValue(have3dRendering, stati c_cast<int>(number), op); | 576 return numberValue(value, number) && compareValue(have3dRendering, stati c_cast<int>(number), op); |
582 } | 577 } |
583 return returnValueIfNoParameter; | 578 return returnValueIfNoParameter; |
584 } | 579 } |
585 | 580 |
586 static bool viewModeMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame* frame, MediaFeaturePrefix) | 581 static bool viewModeMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) |
587 { | 582 { |
588 UseCounter::count(frame->document(), UseCounter::PrefixedViewModeMediaFeatur e); | 583 UseCounter::count(mediaValues.document(), UseCounter::PrefixedViewModeMediaF eature); |
589 | 584 |
590 if (!value) | 585 if (!value) |
591 return true; | 586 return true; |
592 | 587 |
593 return toCSSPrimitiveValue(value)->getValueID() == CSSValueWindowed; | 588 return toCSSPrimitiveValue(value)->getValueID() == CSSValueWindowed; |
594 } | 589 } |
595 | 590 |
596 enum PointerDeviceType { TouchPointer, MousePointer, NoPointer, UnknownPointer } ; | 591 static bool hoverMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const Med iaValues& mediaValues) |
597 | |
598 static PointerDeviceType leastCapablePrimaryPointerDeviceType(LocalFrame* frame) | |
599 { | 592 { |
600 if (frame->settings()->deviceSupportsTouch()) | 593 MediaValues::PointerDeviceType pointer = mediaValues.pointer(); |
601 return TouchPointer; | |
602 | |
603 // FIXME: We should also try to determine if we know we have a mouse. | |
604 // When we do this, we'll also need to differentiate between known not to | |
605 // have mouse or touch screen (NoPointer) and unknown (UnknownPointer). | |
606 // We could also take into account other preferences like accessibility | |
607 // settings to decide which of the available pointers should be considered | |
608 // "primary". | |
609 | |
610 return UnknownPointer; | |
611 } | |
612 | |
613 static bool hoverMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame* fra me, MediaFeaturePrefix) | |
614 { | |
615 PointerDeviceType pointer = leastCapablePrimaryPointerDeviceType(frame); | |
616 | 594 |
617 // If we're on a port that hasn't explicitly opted into providing pointer de vice information | 595 // If we're on a port that hasn't explicitly opted into providing pointer de vice information |
618 // (or otherwise can't be confident in the pointer hardware available), then behave exactly | 596 // (or otherwise can't be confident in the pointer hardware available), then behave exactly |
619 // as if this feature feature isn't supported. | 597 // as if this feature feature isn't supported. |
620 if (pointer == UnknownPointer) | 598 if (pointer == MediaValues::UnknownPointer) |
621 return false; | 599 return false; |
622 | 600 |
623 float number = 1; | 601 float number = 1; |
624 if (value) { | 602 if (value) { |
625 if (!numberValue(value, number)) | 603 if (!numberValue(value, number)) |
626 return false; | 604 return false; |
627 } | 605 } |
628 | 606 |
629 return (pointer == NoPointer && !number) | 607 return (pointer == MediaValues::NoPointer && !number) |
630 || (pointer == TouchPointer && !number) | 608 || (pointer == MediaValues::TouchPointer && !number) |
631 || (pointer == MousePointer && number == 1); | 609 || (pointer == MediaValues::MousePointer && number == 1); |
632 } | 610 } |
633 | 611 |
634 static bool pointerMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame* f rame, MediaFeaturePrefix) | 612 static bool pointerMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const M ediaValues& mediaValues) |
635 { | 613 { |
636 PointerDeviceType pointer = leastCapablePrimaryPointerDeviceType(frame); | 614 MediaValues::PointerDeviceType pointer = mediaValues.pointer(); |
637 | 615 |
638 // If we're on a port that hasn't explicitly opted into providing pointer de vice information | 616 // If we're on a port that hasn't explicitly opted into providing pointer de vice information |
639 // (or otherwise can't be confident in the pointer hardware available), then behave exactly | 617 // (or otherwise can't be confident in the pointer hardware available), then behave exactly |
640 // as if this feature feature isn't supported. | 618 // as if this feature feature isn't supported. |
641 if (pointer == UnknownPointer) | 619 if (pointer == MediaValues::UnknownPointer) |
642 return false; | 620 return false; |
643 | 621 |
644 if (!value) | 622 if (!value) |
645 return pointer != NoPointer; | 623 return pointer != MediaValues::NoPointer; |
646 | 624 |
647 if (!value->isPrimitiveValue()) | 625 if (!value->isPrimitiveValue()) |
648 return false; | 626 return false; |
649 | 627 |
650 const CSSValueID id = toCSSPrimitiveValue(value)->getValueID(); | 628 const CSSValueID id = toCSSPrimitiveValue(value)->getValueID(); |
651 return (pointer == NoPointer && id == CSSValueNone) | 629 return (pointer == MediaValues::NoPointer && id == CSSValueNone) |
652 || (pointer == TouchPointer && id == CSSValueCoarse) | 630 || (pointer == MediaValues::TouchPointer && id == CSSValueCoarse) |
653 || (pointer == MousePointer && id == CSSValueFine); | 631 || (pointer == MediaValues::MousePointer && id == CSSValueFine); |
654 } | 632 } |
655 | 633 |
656 static bool scanMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame* fram e, MediaFeaturePrefix) | 634 static bool scanMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const Medi aValues& mediaValues) |
657 { | 635 { |
658 // Scan only applies to 'tv' media. | 636 if (!mediaValues.scanMediaType()) |
659 if (!equalIgnoringCase(frame->view()->mediaType(), "tv")) | |
660 return false; | 637 return false; |
661 | 638 |
662 if (!value) | 639 if (!value) |
663 return true; | 640 return true; |
664 | 641 |
665 if (!value->isPrimitiveValue()) | 642 if (!value->isPrimitiveValue()) |
666 return false; | 643 return false; |
667 | 644 |
668 // If a platform interface supplies progressive/interlace info for TVs in th e | 645 // If a platform interface supplies progressive/interlace info for TVs in th e |
669 // future, it needs to be handled here. For now, assume a modern TV with | 646 // future, it needs to be handled here. For now, assume a modern TV with |
670 // progressive display. | 647 // progressive display. |
671 return toCSSPrimitiveValue(value)->getValueID() == CSSValueProgressive; | 648 return toCSSPrimitiveValue(value)->getValueID() == CSSValueProgressive; |
672 } | 649 } |
673 | 650 |
674 static void createFunctionMap() | 651 static void createFunctionMap() |
675 { | 652 { |
676 // Create the table. | 653 // Create the table. |
677 gFunctionMap = new FunctionMap; | 654 gFunctionMap = new FunctionMap; |
678 #define ADD_TO_FUNCTIONMAP(name) \ | 655 #define ADD_TO_FUNCTIONMAP(name) \ |
679 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval); | 656 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval); |
680 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP); | 657 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP); |
681 #undef ADD_TO_FUNCTIONMAP | 658 #undef ADD_TO_FUNCTIONMAP |
682 } | 659 } |
683 | 660 |
684 bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const | 661 bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const |
685 { | 662 { |
686 if (!m_frame || !m_style) | 663 if (!m_mediaValues) |
687 return m_expResult; | 664 return m_expectedResult; |
688 | 665 |
689 if (!gFunctionMap) | 666 if (!gFunctionMap) |
690 createFunctionMap(); | 667 createFunctionMap(); |
691 | 668 |
692 // Call the media feature evaluation function. Assume no prefix and let | 669 // Call the media feature evaluation function. Assume no prefix and let |
693 // trampoline functions override the prefix if prefix is used. | 670 // trampoline functions override the prefix if prefix is used. |
694 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); | 671 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); |
695 if (func) | 672 if (func) |
696 return func(expr->value(), m_style.get(), m_frame, NoPrefix); | 673 return func(expr->value(), NoPrefix, *m_mediaValues); |
697 | 674 |
698 return false; | 675 return false; |
699 } | 676 } |
700 | 677 |
701 } // namespace | 678 } // namespace |
OLD | NEW |